blob: 186c85007ed3c46417fea613a0e6905f1a6538f5 [file] [log] [blame]
Chris Lattner00950542001-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 Lattner7e583cf2001-07-21 20:58:30 +000011#include "llvm/CodeGen/MachineInstr.h"
Chris Lattner00950542001-06-06 20:29:01 +000012
Chris Lattner697954c2002-01-20 22:54:45 +000013Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name)
Chris Lattnerf9be9a92001-07-21 20:09:07 +000014 : User(ty, Value::InstructionVal, Name),
15 machineInstrVec(new MachineCodeForVMInstr) {
Chris Lattner00950542001-06-06 20:29:01 +000016 Parent = 0;
17 iType = it;
18}
19
20Instruction::~Instruction() {
Vikram S. Adve33446152001-07-20 21:05:02 +000021 assert(getParent() == 0 && "Instruction still embedded in basic block!");
22 delete machineInstrVec;
Chris Lattner00950542001-06-06 20:29:01 +000023}
24
25// Specialize setName to take care of symbol table majik
Chris Lattner697954c2002-01-20 22:54:45 +000026void Instruction::setName(const std::string &name, SymbolTable *ST) {
Chris Lattner00950542001-06-06 20:29:01 +000027 BasicBlock *P = 0; Method *PP = 0;
Chris Lattnere05bf2f2001-09-07 16:47:03 +000028 assert((ST == 0 || !getParent() || !getParent()->getParent() ||
29 ST == getParent()->getParent()->getSymbolTable()) &&
30 "Invalid symtab argument!");
Chris Lattner00950542001-06-06 20:29:01 +000031 if ((P = getParent()) && (PP = P->getParent()) && hasName())
32 PP->getSymbolTable()->remove(this);
33 Value::setName(name);
34 if (PP && hasName()) PP->getSymbolTableSure()->insert(this);
35}
Vikram S. Adve33446152001-07-20 21:05:02 +000036
Chris Lattnerf9be9a92001-07-21 20:09:07 +000037void Instruction::addMachineInstruction(MachineInstr* minstr) {
Vikram S. Adve33446152001-07-20 21:05:02 +000038 machineInstrVec->push_back(minstr);
39}
40
Chris Lattnercfad5df2001-07-21 20:04:10 +000041#if 0
Vikram S. Adve33446152001-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//
Chris Lattner697954c2002-01-20 22:54:45 +000047const std::vector<Value*> &Instruction::getTempValuesForMachineCode() const {
Vikram S. Adve33446152001-07-20 21:05:02 +000048 return machineInstrVec->getTempValues();
49}
Chris Lattnercfad5df2001-07-21 20:04:10 +000050#endif
Vikram S. Adve33446152001-07-20 21:05:02 +000051
Chris Lattnerf9be9a92001-07-21 20:09:07 +000052void Instruction::dropAllReferences() {
Vikram S. Adve33446152001-07-20 21:05:02 +000053 machineInstrVec->dropAllReferences();
54 User::dropAllReferences();
55}