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 LLVM instructions.
6 //===----------------------------------------------------------------------===//
8 #ifndef LLVM_INSTRUCTION_H
9 #define LLVM_INSTRUCTION_H
11 #include "llvm/User.h"
12 template<typename SC> struct ilist_traits;
13 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
14 typename SubClass> class SymbolTableListTraits;
16 class Instruction : public User {
18 Instruction *Prev, *Next; // Next and Prev links for our intrusive linked list
20 void setNext(Instruction *N) { Next = N; }
21 void setPrev(Instruction *N) { Prev = N; }
23 friend class SymbolTableListTraits<Instruction, BasicBlock, Function,
24 ilist_traits<Instruction> >;
25 void setParent(BasicBlock *P);
27 unsigned iType; // InstructionType: The opcode of the instruction
29 Instruction(const Type *Ty, unsigned iType, const std::string &Name = "");
30 virtual ~Instruction() {
31 assert(Parent == 0 && "Instruction still embedded in basic block!");
34 // Specialize setName to handle symbol table majik...
35 virtual void setName(const std::string &name, SymbolTable *ST = 0);
37 /// clone() - Create a copy of 'this' instruction that is identical in all
38 /// ways except the following:
39 /// * The instruction has no parent
40 /// * The instruction has no name
42 virtual Instruction *clone() const = 0;
44 // Accessor methods...
46 inline const BasicBlock *getParent() const { return Parent; }
47 inline BasicBlock *getParent() { return Parent; }
49 // getNext/Prev - Return the next or previous instruction in the list. The
50 // last node in the list is a terminator instruction.
51 Instruction *getNext() { return Next; }
52 const Instruction *getNext() const { return Next; }
53 Instruction *getPrev() { return Prev; }
54 const Instruction *getPrev() const { return Prev; }
56 virtual bool hasSideEffects() const { return false; } // Memory & Call insts
58 // ---------------------------------------------------------------------------
59 /// Subclass classification... getOpcode() returns a member of
60 /// one of the enums that is coming soon (down below)...
62 unsigned getOpcode() const { return iType; }
63 virtual const char *getOpcodeName() const {
64 return getOpcodeName(getOpcode());
66 static const char* getOpcodeName(unsigned OpCode);
68 inline bool isTerminator() const { // Instance of TerminatorInst?
69 return iType >= FirstTermOp && iType < NumTermOps;
71 inline bool isBinaryOp() const {
72 return iType >= FirstBinaryOp && iType < NumBinaryOps;
75 virtual void print(std::ostream &OS) const;
77 /// Methods for support type inquiry through isa, cast, and dyn_cast:
78 static inline bool classof(const Instruction *I) { return true; }
79 static inline bool classof(const Value *V) {
80 return V->getValueType() == Value::InstructionVal;
83 //----------------------------------------------------------------------
84 // Exported enumerations...
86 enum TermOps { // These terminate basic blocks
87 #define FIRST_TERM_INST(N) FirstTermOp = N,
88 #define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
89 #define LAST_TERM_INST(N) NumTermOps = N+1,
90 #include "llvm/Instruction.def"
94 #define FIRST_BINARY_INST(N) FirstBinaryOp = N,
95 #define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
96 #define LAST_BINARY_INST(N) NumBinaryOps = N+1,
97 #include "llvm/Instruction.def"
101 #define FIRST_MEMORY_INST(N) FirstMemoryOp = N,
102 #define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
103 #define LAST_MEMORY_INST(N) NumMemoryOps = N+1,
104 #include "llvm/Instruction.def"
108 #define FIRST_OTHER_INST(N) FirstOtherOp = N,
109 #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
110 #define LAST_OTHER_INST(N) NumOtherOps = N+1,
111 #include "llvm/Instruction.def"