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