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 Instruction *InsertBefore = 0);
32 virtual ~Instruction() {
33 assert(Parent == 0 && "Instruction still embedded in basic block!");
36 // Specialize setName to handle symbol table majik...
37 virtual void setName(const std::string &name, SymbolTable *ST = 0);
39 /// clone() - Create a copy of 'this' instruction that is identical in all
40 /// ways except the following:
41 /// * The instruction has no parent
42 /// * The instruction has no name
44 virtual Instruction *clone() const = 0;
46 // Accessor methods...
48 inline const BasicBlock *getParent() const { return Parent; }
49 inline BasicBlock *getParent() { return Parent; }
51 // getNext/Prev - Return the next or previous instruction in the list. The
52 // last node in the list is a terminator instruction.
53 Instruction *getNext() { return Next; }
54 const Instruction *getNext() const { return Next; }
55 Instruction *getPrev() { return Prev; }
56 const Instruction *getPrev() const { return Prev; }
58 virtual bool hasSideEffects() const { return false; } // Memory & Call insts
60 // ---------------------------------------------------------------------------
61 /// Subclass classification... getOpcode() returns a member of
62 /// one of the enums that is coming soon (down below)...
64 unsigned getOpcode() const { return iType; }
65 virtual const char *getOpcodeName() const {
66 return getOpcodeName(getOpcode());
68 static const char* getOpcodeName(unsigned OpCode);
70 inline bool isTerminator() const { // Instance of TerminatorInst?
71 return iType >= FirstTermOp && iType < NumTermOps;
73 inline bool isBinaryOp() const {
74 return iType >= FirstBinaryOp && iType < NumBinaryOps;
77 virtual void print(std::ostream &OS) const;
79 /// Methods for support type inquiry through isa, cast, and dyn_cast:
80 static inline bool classof(const Instruction *I) { return true; }
81 static inline bool classof(const Value *V) {
82 return V->getValueType() == Value::InstructionVal;
85 //----------------------------------------------------------------------
86 // Exported enumerations...
88 enum TermOps { // These terminate basic blocks
89 #define FIRST_TERM_INST(N) FirstTermOp = N,
90 #define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
91 #define LAST_TERM_INST(N) NumTermOps = N+1,
92 #include "llvm/Instruction.def"
96 #define FIRST_BINARY_INST(N) FirstBinaryOp = N,
97 #define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
98 #define LAST_BINARY_INST(N) NumBinaryOps = N+1,
99 #include "llvm/Instruction.def"
103 #define FIRST_MEMORY_INST(N) FirstMemoryOp = N,
104 #define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
105 #define LAST_MEMORY_INST(N) NumMemoryOps = N+1,
106 #include "llvm/Instruction.def"
110 #define FIRST_OTHER_INST(N) FirstOtherOp = N,
111 #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
112 #define LAST_OTHER_INST(N) NumOtherOps = N+1,
113 #include "llvm/Instruction.def"