blob: d5fe1c68e3e1b1dd06d7ea560068f985fba26a7a [file] [log] [blame]
Chris Lattner2f7c9632001-06-06 20:29:01 +00001//===-- Instruction.cpp - Implement the Instruction class --------*- C++ -*--=//
2//
3// This file implements the Instruction class for the VMCore library.
4//
5//===----------------------------------------------------------------------===//
6
7#include "llvm/Instruction.h"
8#include "llvm/BasicBlock.h"
9#include "llvm/Method.h"
10#include "llvm/SymbolTable.h"
Vikram S. Adve3e2394c2001-07-20 21:05:02 +000011#include "llvm/Codegen/MachineInstr.h"
Chris Lattner2f7c9632001-06-06 20:29:01 +000012
13Instruction::Instruction(const Type *ty, unsigned it, const string &Name)
Vikram S. Adve3e2394c2001-07-20 21:05:02 +000014 : User(ty, Value::InstructionVal, Name),
15 machineInstrVec(new MachineCodeForVMInstr)
16{
Chris Lattner2f7c9632001-06-06 20:29:01 +000017 Parent = 0;
18 iType = it;
19}
20
21Instruction::~Instruction() {
Vikram S. Adve3e2394c2001-07-20 21:05:02 +000022 assert(getParent() == 0 && "Instruction still embedded in basic block!");
23 delete machineInstrVec;
Chris Lattner2f7c9632001-06-06 20:29:01 +000024}
25
26// Specialize setName to take care of symbol table majik
27void Instruction::setName(const string &name) {
28 BasicBlock *P = 0; Method *PP = 0;
29 if ((P = getParent()) && (PP = P->getParent()) && hasName())
30 PP->getSymbolTable()->remove(this);
31 Value::setName(name);
32 if (PP && hasName()) PP->getSymbolTableSure()->insert(this);
33}
Vikram S. Adve3e2394c2001-07-20 21:05:02 +000034
35void
36Instruction::addMachineInstruction(MachineInstr* minstr)
37{
38 machineInstrVec->push_back(minstr);
39}
40
Chris Lattner93547c32001-07-21 20:04:10 +000041#if 0
Vikram S. Adve3e2394c2001-07-20 21:05:02 +000042// Dont make this inline because you would need to include
43// MachineInstr.h in Instruction.h, which creates a circular
44// sequence of forward declarations. Trying to fix that will
45// cause a serious circularity in link order.
46//
47const vector<Value*>&
48Instruction::getTempValuesForMachineCode() const
49{
50 return machineInstrVec->getTempValues();
51}
Chris Lattner93547c32001-07-21 20:04:10 +000052#endif
Vikram S. Adve3e2394c2001-07-20 21:05:02 +000053
54void
55Instruction::dropAllReferences() {
56 machineInstrVec->dropAllReferences();
57 User::dropAllReferences();
58}