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
11 #include "llvm/User.h"
17 class Instruction : public User {
19 unsigned iType; // InstructionType
21 friend class ValueHolder<Instruction,BasicBlock>;
22 inline void setParent(BasicBlock *P) { Parent = P; }
25 Instruction(const Type *Ty, unsigned iType, const string &Name = "");
26 virtual ~Instruction(); // Virtual dtor == good.
28 // Specialize setName to handle symbol table majik...
29 virtual void setName(const string &name);
31 // clone() - Create a copy of 'this' instruction that is identical in all ways
32 // except the following:
33 // * The instruction has no parent
34 // * The instruction has no name
36 virtual Instruction *clone() const = 0;
38 // Accessor methods...
40 inline const BasicBlock *getParent() const { return Parent; }
41 inline BasicBlock *getParent() { return Parent; }
42 bool hasSideEffects() const { return false; } // Memory & Call insts = true
44 // ---------------------------------------------------------------------------
45 // Subclass classification... getInstType() returns a member of
46 // one of the enums that is coming soon (down below)...
48 virtual string getOpcode() const = 0;
50 unsigned getInstType() const { return iType; }
51 inline bool isTerminator() const { // Instance of TerminatorInst?
52 return iType >= FirstTermOp && iType < NumTermOps;
54 inline bool isDefinition() const { return !isTerminator(); }
55 inline bool isUnaryOp() const {
56 return iType >= FirstUnaryOp && iType < NumUnaryOps;
58 inline bool isBinaryOp() const {
59 return iType >= FirstBinaryOp && iType < NumBinaryOps;
62 // isPHINode() - This is used frequently enough to allow it to exist
63 inline bool isPHINode() const { return iType == PHINode; }
66 //----------------------------------------------------------------------
67 // Exported enumerations...
69 enum TermOps { // These terminate basic blocks
72 NumTermOps // Must remain at end of enum
76 FirstUnaryOp = NumTermOps,
77 Neg = NumTermOps, Not,
79 // Type conversions...
81 ToUByteTy , ToSByteTy, ToUShortTy, ToShortTy,
82 ToUInt , ToInt, ToULongTy , ToLongTy,
84 ToFloatTy , ToDoubleTy, ToArrayTy , ToPointerTy,
86 NumUnaryOps // Must remain at end of enum
90 // Standard binary operators...
91 FirstBinaryOp = NumUnaryOps,
92 Add = NumUnaryOps, Sub, Mul, Div, Rem,
94 // Logical operators...
97 // Binary comparison operators...
98 SetEQ, SetNE, SetLE, SetGE, SetLT, SetGT,
104 FirstMemoryOp = NumBinaryOps,
105 Malloc = NumBinaryOps, Free, // Heap management instructions
106 Alloca, // Stack management instruction
108 Load, Store, // Memory manipulation instructions.
110 GetField, PutField, // Structure manipulation instructions
116 FirstOtherOp = NumMemoryOps,
117 PHINode = NumMemoryOps, // PHI node instruction
118 Call, // Call a function
120 Shl, Shr, // Shift operations...
122 NumOps, // Must be the last 'op' defined.
123 UserOp1, UserOp2 // May be used internally to a pass...