Rename the intrinsic enum values for llvm.va_* from Intrinsic::va_* to
[oota-llvm.git] / include / llvm / Instruction.h
1 //===-- llvm/Instruction.h - Instruction class definition -------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the declaration of the Instruction class, which is the
11 // base class for all of the LLVM instructions.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_INSTRUCTION_H
16 #define LLVM_INSTRUCTION_H
17
18 #include "llvm/User.h"
19 #include "Support/Annotation.h"
20
21 namespace llvm {
22
23 class AssemblyAnnotationWriter;
24
25 template<typename SC> struct ilist_traits;
26 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
27          typename SubClass> class SymbolTableListTraits;
28
29 class Instruction : public User, public Annotable {
30   BasicBlock *Parent;
31   Instruction *Prev, *Next; // Next and Prev links for our intrusive linked list
32
33   void setNext(Instruction *N) { Next = N; }
34   void setPrev(Instruction *N) { Prev = N; }
35
36   friend class SymbolTableListTraits<Instruction, BasicBlock, Function,
37                                      ilist_traits<Instruction> >;
38   void setParent(BasicBlock *P);
39 protected:
40   unsigned iType;      // InstructionType: The opcode of the instruction
41
42   Instruction(const Type *Ty, unsigned iType, const std::string &Name = "",
43               Instruction *InsertBefore = 0);
44 public:
45
46   // Specialize setName to handle symbol table majik...
47   virtual void setName(const std::string &name, SymbolTable *ST = 0);
48   
49   /// clone() - Create a copy of 'this' instruction that is identical in all
50   /// ways except the following:
51   ///   * The instruction has no parent
52   ///   * The instruction has no name
53   ///
54   virtual Instruction *clone() const = 0;
55   
56   // Accessor methods...
57   //
58   inline const BasicBlock *getParent() const { return Parent; }
59   inline       BasicBlock *getParent()       { return Parent; }
60
61   // getNext/Prev - Return the next or previous instruction in the list.  The
62   // last node in the list is a terminator instruction.
63         Instruction *getNext()       { return Next; }
64   const Instruction *getNext() const { return Next; }
65         Instruction *getPrev()       { return Prev; }
66   const Instruction *getPrev() const { return Prev; }
67
68   /// mayWriteToMemory - Return true if this instruction may modify memory.
69   ///
70   virtual bool mayWriteToMemory() const { return false; }
71
72   // ---------------------------------------------------------------------------
73   /// Subclass classification... getOpcode() returns a member of 
74   /// one of the enums that is coming soon (down below)...
75   ///
76   unsigned getOpcode() const { return iType; }
77   virtual const char *getOpcodeName() const {
78     return getOpcodeName(getOpcode());
79   }
80   static const char* getOpcodeName(unsigned OpCode);
81
82   inline bool isTerminator() const {   // Instance of TerminatorInst?
83     return iType >= TermOpsBegin && iType < TermOpsEnd;
84   }
85   inline bool isBinaryOp() const {
86     return iType >= BinaryOpsBegin && iType < BinaryOpsEnd;
87   }
88
89   /// isAssociative - Return true if the instruction is associative:
90   ///
91   ///   Associative operators satisfy:  x op (y op z) === (x op y) op z
92   ///
93   /// In LLVM, the Add, Mul, And, Or, and Xor operators are associative, when
94   /// not applied to floating point types.
95   ///
96   bool isAssociative() const { return isAssociative(getOpcode(), getType()); }
97   static bool isAssociative(unsigned op, const Type *Ty);
98
99   /// isCommutative - Return true if the instruction is commutative:
100   ///
101   ///   Commutative operators satisfy: (x op y) === (y op x)
102   ///
103   /// In LLVM, these are the associative operators, plus SetEQ and SetNE, when
104   /// applied to any type.
105   ///
106   bool isCommutative() const { return isCommutative(getOpcode()); }
107   static bool isCommutative(unsigned op);
108
109   /// isRelational - Return true if the instruction is a Set* instruction:
110   ///
111   bool isRelational() const { return isRelational(getOpcode()); }
112   static bool isRelational(unsigned op);
113
114
115   /// isTrappingInstruction - Return true if the instruction may trap.
116   ///
117   bool isTrapping() const {
118     return isTrapping(getOpcode()); 
119   }
120   static bool isTrapping(unsigned op);
121   
122   virtual void print(std::ostream &OS) const { print(OS, 0); }
123   void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const;
124
125   /// Methods for support type inquiry through isa, cast, and dyn_cast:
126   static inline bool classof(const Instruction *I) { return true; }
127   static inline bool classof(const Value *V) {
128     return V->getValueType() == Value::InstructionVal;
129   }
130   
131   //----------------------------------------------------------------------
132   // Exported enumerations...
133   //
134   enum TermOps {       // These terminate basic blocks
135 #define  FIRST_TERM_INST(N)             TermOpsBegin = N,
136 #define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
137 #define   LAST_TERM_INST(N)             TermOpsEnd = N+1,
138 #include "llvm/Instruction.def"
139   };
140
141   enum BinaryOps {
142 #define  FIRST_BINARY_INST(N)             BinaryOpsBegin = N,
143 #define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
144 #define   LAST_BINARY_INST(N)             BinaryOpsEnd = N+1,
145 #include "llvm/Instruction.def"
146   };
147
148   enum MemoryOps {
149 #define  FIRST_MEMORY_INST(N)             MemoryOpsBegin = N,
150 #define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
151 #define   LAST_MEMORY_INST(N)             MemoryOpsEnd = N+1,
152 #include "llvm/Instruction.def"
153   };
154
155   enum OtherOps {
156 #define  FIRST_OTHER_INST(N)             OtherOpsBegin = N,
157 #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
158 #define   LAST_OTHER_INST(N)             OtherOpsEnd = N+1,
159 #include "llvm/Instruction.def"
160   };
161 };
162
163 } // End llvm namespace
164
165 #endif