1 //===-- llvm/Instruction.h - Instruction class definition --------*- C++ -*--=//
3 // This file contains the declaration of the Instruction class, which is the
4 // base class for all of the VM instructions.
6 //===----------------------------------------------------------------------===//
8 #ifndef LLVM_INSTRUCTION_H
9 #define LLVM_INSTRUCTION_H
12 #include "llvm/User.h"
17 class MachineInstr; // do not include header file MachineInstr.h
18 class MachineCodeForVMInstr;
20 class Instruction : public User {
22 unsigned iType; // InstructionType
24 MachineCodeForVMInstr* machineInstrVec;
25 friend class ValueHolder<Instruction,BasicBlock,Method>;
26 inline void setParent(BasicBlock *P) { Parent = P; }
29 Instruction(const Type *Ty, unsigned iType, const string &Name = "");
30 virtual ~Instruction(); // Virtual dtor == good.
32 // Specialize setName to handle symbol table majik...
33 virtual void setName(const string &name);
35 // clone() - Create a copy of 'this' instruction that is identical in all ways
36 // except the following:
37 // * The instruction has no parent
38 // * The instruction has no name
40 virtual Instruction *clone() const = 0;
42 // Add a machine instruction used to implement this instruction
44 void addMachineInstruction(MachineInstr* minstr);
46 // Accessor methods...
48 inline const BasicBlock *getParent() const { return Parent; }
49 inline BasicBlock *getParent() { return Parent; }
50 virtual bool hasSideEffects() const { return false; } // Memory & Call insts
51 inline MachineCodeForVMInstr&
52 getMachineInstrVec() { return *machineInstrVec; }
54 getTempValuesForMachineCode() const;
56 // ---------------------------------------------------------------------------
57 // Subclass classification... getInstType() returns a member of
58 // one of the enums that is coming soon (down below)...
60 virtual const char *getOpcodeName() const = 0;
61 unsigned getOpcode() const { return iType; }
63 // getInstType is deprecated, use getOpcode() instead.
64 unsigned getInstType() const { return iType; }
66 inline bool isTerminator() const { // Instance of TerminatorInst?
67 return iType >= FirstTermOp && iType < NumTermOps;
69 inline bool isDefinition() const { return !isTerminator(); }
70 inline bool isUnaryOp() const {
71 return iType >= FirstUnaryOp && iType < NumUnaryOps;
73 inline bool isBinaryOp() const {
74 return iType >= FirstBinaryOp && iType < NumBinaryOps;
77 // isPHINode() - This is used frequently enough to allow it to exist
78 inline bool isPHINode() const { return iType == PHINode; }
80 // dropAllReferences() - This function is in charge of "letting go" of all
81 // objects that this Instruction refers to. This first lets go of all
82 // references to hidden values generated code for this instruction,
83 // and then drops all references to its operands.
85 void dropAllReferences();
87 //----------------------------------------------------------------------
88 // Exported enumerations...
90 enum TermOps { // These terminate basic blocks
93 NumTermOps // Must remain at end of enum
97 FirstUnaryOp = NumTermOps,
98 Not = NumTermOps, // Binary inverse
100 NumUnaryOps // Must remain at end of enum
104 // Standard binary operators...
105 FirstBinaryOp = NumUnaryOps,
106 Add = NumUnaryOps, Sub, Mul, Div, Rem,
108 // Logical operators...
111 // Binary comparison operators...
112 SetEQ, SetNE, SetLE, SetGE, SetLT, SetGT,
118 FirstMemoryOp = NumBinaryOps,
119 Malloc = NumBinaryOps, Free, // Heap management instructions
120 Alloca, // Stack management instruction
122 Load, Store, // Memory manipulation instructions.
123 GetElementPtr, // Get addr of Structure or Array element
129 FirstOtherOp = NumMemoryOps,
130 PHINode = NumMemoryOps, // PHI node instruction
131 Cast, // Type cast...
132 Call, // Call a function
134 Shl, Shr, // Shift operations...
136 NumOps, // Must be the last 'op' defined.
137 UserOp1, UserOp2 // May be used internally to a pass...