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"
16 class Instruction : public User {
19 friend class ValueHolder<Instruction,BasicBlock,Method>;
20 inline void setParent(BasicBlock *P) { Parent = P; }
22 unsigned iType; // InstructionType
24 Instruction(const Type *Ty, unsigned iType, const std::string &Name = "");
25 virtual ~Instruction() {
26 assert(Parent == 0 && "Instruction still embedded in basic block!");
29 // Specialize setName to handle symbol table majik...
30 virtual void setName(const std::string &name, SymbolTable *ST = 0);
32 // clone() - Create a copy of 'this' instruction that is identical in all ways
33 // except the following:
34 // * The instruction has no parent
35 // * The instruction has no name
37 virtual Instruction *clone() const = 0;
39 // Accessor methods...
41 inline const BasicBlock *getParent() const { return Parent; }
42 inline BasicBlock *getParent() { return Parent; }
43 virtual bool hasSideEffects() const { return false; } // Memory & Call insts
45 // ---------------------------------------------------------------------------
46 // Subclass classification... getInstType() returns a member of
47 // one of the enums that is coming soon (down below)...
49 virtual const char *getOpcodeName() const = 0;
50 unsigned getOpcode() const { return iType; }
52 // getInstType is deprecated, use getOpcode() instead.
53 unsigned getInstType() const { return iType; }
55 inline bool isTerminator() const { // Instance of TerminatorInst?
56 return iType >= FirstTermOp && iType < NumTermOps;
58 inline bool isDefinition() const { return !isTerminator(); }
59 inline bool isUnaryOp() const {
60 return iType >= FirstUnaryOp && iType < NumUnaryOps;
62 inline bool isBinaryOp() const {
63 return iType >= FirstBinaryOp && iType < NumBinaryOps;
66 // Methods for support type inquiry through isa, cast, and dyn_cast:
67 static inline bool classof(const Instruction *I) { return true; }
68 static inline bool classof(const Value *V) {
69 return V->getValueType() == Value::InstructionVal;
72 //----------------------------------------------------------------------
73 // Exported enumerations...
75 enum TermOps { // These terminate basic blocks
76 #define FIRST_TERM_INST(N) FirstTermOp = N,
77 #define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
78 #define LAST_TERM_INST(N) NumTermOps = N+1,
79 #include "llvm/Instruction.def"
83 #define FIRST_UNARY_INST(N) FirstUnaryOp = N,
84 #define HANDLE_UNARY_INST(N, OPC, CLASS) OPC = N,
85 #define LAST_UNARY_INST(N) NumUnaryOps = N+1,
86 #include "llvm/Instruction.def"
90 #define FIRST_BINARY_INST(N) FirstBinaryOp = N,
91 #define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
92 #define LAST_BINARY_INST(N) NumBinaryOps = N+1,
93 #include "llvm/Instruction.def"
97 #define FIRST_MEMORY_INST(N) FirstMemoryOp = N,
98 #define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
99 #define LAST_MEMORY_INST(N) NumMemoryOps = N+1,
100 #include "llvm/Instruction.def"
104 #define FIRST_OTHER_INST(N) FirstOtherOp = N,
105 #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
106 #define LAST_OTHER_INST(N) NumOtherOps = N+1,
107 #include "llvm/Instruction.def"