blob: ca9469df3554053939524e8029d09dab93bdd418 [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"
Chris Lattnerdd511762001-07-21 20:58:30 +000011#include "llvm/CodeGen/MachineInstr.h"
Chris Lattner2f7c9632001-06-06 20:29:01 +000012
13Instruction::Instruction(const Type *ty, unsigned it, const string &Name)
Chris Lattner7f95c9e2001-07-21 20:09:07 +000014 : User(ty, Value::InstructionVal, Name),
15 machineInstrVec(new MachineCodeForVMInstr) {
Chris Lattner2f7c9632001-06-06 20:29:01 +000016 Parent = 0;
17 iType = it;
18}
19
20Instruction::~Instruction() {
Vikram S. Adve3e2394c2001-07-20 21:05:02 +000021 assert(getParent() == 0 && "Instruction still embedded in basic block!");
22 delete machineInstrVec;
Chris Lattner2f7c9632001-06-06 20:29:01 +000023}
24
25// Specialize setName to take care of symbol table majik
26void Instruction::setName(const string &name) {
27 BasicBlock *P = 0; Method *PP = 0;
28 if ((P = getParent()) && (PP = P->getParent()) && hasName())
29 PP->getSymbolTable()->remove(this);
30 Value::setName(name);
31 if (PP && hasName()) PP->getSymbolTableSure()->insert(this);
32}
Vikram S. Adve3e2394c2001-07-20 21:05:02 +000033
Chris Lattner7f95c9e2001-07-21 20:09:07 +000034void Instruction::addMachineInstruction(MachineInstr* minstr) {
Vikram S. Adve3e2394c2001-07-20 21:05:02 +000035 machineInstrVec->push_back(minstr);
36}
37
Chris Lattner93547c32001-07-21 20:04:10 +000038#if 0
Vikram S. Adve3e2394c2001-07-20 21:05:02 +000039// Dont make this inline because you would need to include
40// MachineInstr.h in Instruction.h, which creates a circular
41// sequence of forward declarations. Trying to fix that will
42// cause a serious circularity in link order.
43//
Chris Lattner7f95c9e2001-07-21 20:09:07 +000044const vector<Value*> &Instruction::getTempValuesForMachineCode() const {
Vikram S. Adve3e2394c2001-07-20 21:05:02 +000045 return machineInstrVec->getTempValues();
46}
Chris Lattner93547c32001-07-21 20:04:10 +000047#endif
Vikram S. Adve3e2394c2001-07-20 21:05:02 +000048
Chris Lattner7f95c9e2001-07-21 20:09:07 +000049void Instruction::dropAllReferences() {
Vikram S. Adve3e2394c2001-07-20 21:05:02 +000050 machineInstrVec->dropAllReferences();
51 User::dropAllReferences();
52}