Added a representation of the machine instructions generated

for a VM instruction.

llvm-svn: 220
This commit is contained in:
Vikram S. Adve 2001-07-20 21:05:02 +00:00
parent 85090922f4
commit 3e2394cdad
2 changed files with 51 additions and 6 deletions

View File

@ -8,16 +8,20 @@
#ifndef LLVM_INSTRUCTION_H #ifndef LLVM_INSTRUCTION_H
#define LLVM_INSTRUCTION_H #define LLVM_INSTRUCTION_H
#include <vector>
#include "llvm/User.h" #include "llvm/User.h"
class Type; class Type;
class BasicBlock; class BasicBlock;
class Method; class Method;
class MachineInstr; // do not include header file MachineInstr.h
class MachineCodeForVMInstr;
class Instruction : public User { class Instruction : public User {
BasicBlock *Parent; BasicBlock *Parent;
unsigned iType; // InstructionType unsigned iType; // InstructionType
MachineCodeForVMInstr* machineInstrVec;
friend class ValueHolder<Instruction,BasicBlock,Method>; friend class ValueHolder<Instruction,BasicBlock,Method>;
inline void setParent(BasicBlock *P) { Parent = P; } inline void setParent(BasicBlock *P) { Parent = P; }
@ -27,20 +31,28 @@ public:
// Specialize setName to handle symbol table majik... // Specialize setName to handle symbol table majik...
virtual void setName(const string &name); virtual void setName(const string &name);
// clone() - Create a copy of 'this' instruction that is identical in all ways // clone() - Create a copy of 'this' instruction that is identical in all ways
// except the following: // except the following:
// * The instruction has no parent // * The instruction has no parent
// * The instruction has no name // * The instruction has no name
// //
virtual Instruction *clone() const = 0; virtual Instruction *clone() const = 0;
// Add a machine instruction used to implement this instruction
//
void addMachineInstruction(MachineInstr* minstr);
// Accessor methods... // Accessor methods...
// //
inline const BasicBlock *getParent() const { return Parent; } inline const BasicBlock *getParent() const { return Parent; }
inline BasicBlock *getParent() { return Parent; } inline BasicBlock *getParent() { return Parent; }
virtual bool hasSideEffects() const { return false; } // Memory & Call insts virtual bool hasSideEffects() const { return false; } // Memory & Call insts
inline MachineCodeForVMInstr&
getMachineInstrVec() { return *machineInstrVec; }
const vector<Value*>&
getTempValuesForMachineCode() const;
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Subclass classification... getInstType() returns a member of // Subclass classification... getInstType() returns a member of
// one of the enums that is coming soon (down below)... // one of the enums that is coming soon (down below)...
@ -65,7 +77,13 @@ public:
// isPHINode() - This is used frequently enough to allow it to exist // isPHINode() - This is used frequently enough to allow it to exist
inline bool isPHINode() const { return iType == PHINode; } inline bool isPHINode() const { return iType == PHINode; }
// dropAllReferences() - This function is in charge of "letting go" of all
// objects that this Instruction refers to. This first lets go of all
// references to hidden values generated code for this instruction,
// and then drops all references to its operands.
//
void dropAllReferences();
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Exported enumerations... // Exported enumerations...
// //

View File

@ -8,15 +8,19 @@
#include "llvm/BasicBlock.h" #include "llvm/BasicBlock.h"
#include "llvm/Method.h" #include "llvm/Method.h"
#include "llvm/SymbolTable.h" #include "llvm/SymbolTable.h"
#include "llvm/Codegen/MachineInstr.h"
Instruction::Instruction(const Type *ty, unsigned it, const string &Name) Instruction::Instruction(const Type *ty, unsigned it, const string &Name)
: User(ty, Value::InstructionVal, Name) { : User(ty, Value::InstructionVal, Name),
machineInstrVec(new MachineCodeForVMInstr)
{
Parent = 0; Parent = 0;
iType = it; iType = it;
} }
Instruction::~Instruction() { Instruction::~Instruction() {
assert(getParent() == 0 && "Instruction still embeded in basic block!"); assert(getParent() == 0 && "Instruction still embedded in basic block!");
delete machineInstrVec;
} }
// Specialize setName to take care of symbol table majik // Specialize setName to take care of symbol table majik
@ -27,3 +31,26 @@ void Instruction::setName(const string &name) {
Value::setName(name); Value::setName(name);
if (PP && hasName()) PP->getSymbolTableSure()->insert(this); if (PP && hasName()) PP->getSymbolTableSure()->insert(this);
} }
void
Instruction::addMachineInstruction(MachineInstr* minstr)
{
machineInstrVec->push_back(minstr);
}
// Dont make this inline because you would need to include
// MachineInstr.h in Instruction.h, which creates a circular
// sequence of forward declarations. Trying to fix that will
// cause a serious circularity in link order.
//
const vector<Value*>&
Instruction::getTempValuesForMachineCode() const
{
return machineInstrVec->getTempValues();
}
void
Instruction::dropAllReferences() {
machineInstrVec->dropAllReferences();
User::dropAllReferences();
}