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 const char *getOpcodeName() const = 0;
49 unsigned getOpcode() const { return iType; }
51 // getInstType is deprecated, use getOpcode() instead.
52 unsigned getInstType() const { return iType; }
54 inline bool isTerminator() const { // Instance of TerminatorInst?
55 return iType >= FirstTermOp && iType < NumTermOps;
57 inline bool isDefinition() const { return !isTerminator(); }
58 inline bool isUnaryOp() const {
59 return iType >= FirstUnaryOp && iType < NumUnaryOps;
61 inline bool isBinaryOp() const {
62 return iType >= FirstBinaryOp && iType < NumBinaryOps;
65 // isPHINode() - This is used frequently enough to allow it to exist
66 inline bool isPHINode() const { return iType == PHINode; }
69 //----------------------------------------------------------------------
70 // Exported enumerations...
72 enum TermOps { // These terminate basic blocks
75 NumTermOps // Must remain at end of enum
79 FirstUnaryOp = NumTermOps,
80 Not = NumTermOps, // Binary inverse
82 NumUnaryOps // Must remain at end of enum
86 // Standard binary operators...
87 FirstBinaryOp = NumUnaryOps,
88 Add = NumUnaryOps, Sub, Mul, Div, Rem,
90 // Logical operators...
93 // Binary comparison operators...
94 SetEQ, SetNE, SetLE, SetGE, SetLT, SetGT,
100 FirstMemoryOp = NumBinaryOps,
101 Malloc = NumBinaryOps, Free, // Heap management instructions
102 Alloca, // Stack management instruction
104 Load, Store, // Memory manipulation instructions.
105 GetElementPtr, // Get addr of Structure or Array element
111 FirstOtherOp = NumMemoryOps,
112 PHINode = NumMemoryOps, // PHI node instruction
113 Cast, // Type cast...
114 Call, // Call a function
116 Shl, Shr, // Shift operations...
118 NumOps, // Must be the last 'op' defined.
119 UserOp1, UserOp2 // May be used internally to a pass...