Definition of the Bytecode Handler interface. Subclasses can override just
[oota-llvm.git] / include / llvm / Instruction.h
index 264356ca91eaa8572824bedc5c0352a58c568926..86f2a056cb975df4055ed6213d559536375f174a 100644 (file)
 #define LLVM_INSTRUCTION_H
 
 #include "llvm/User.h"
+#include "Support/Annotation.h"
 
-class AssemblyAnnotationWriter;
+namespace llvm {
+
+struct AssemblyAnnotationWriter;
 
 template<typename SC> struct ilist_traits;
 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
          typename SubClass> class SymbolTableListTraits;
 
-class Instruction : public User {
+class Instruction : public User, public Annotable {
   BasicBlock *Parent;
   Instruction *Prev, *Next; // Next and Prev links for our intrusive linked list
 
@@ -33,13 +36,21 @@ class Instruction : public User {
   friend class SymbolTableListTraits<Instruction, BasicBlock, Function,
                                      ilist_traits<Instruction> >;
   void setParent(BasicBlock *P);
+  void init();
+
 protected:
   unsigned iType;      // InstructionType: The opcode of the instruction
 
   Instruction(const Type *Ty, unsigned iType, const std::string &Name = "",
               Instruction *InsertBefore = 0);
+  Instruction(const Type *Ty, unsigned iType, const std::string &Name,
+              BasicBlock *InsertAtEnd);
 public:
 
+  ~Instruction() {
+    assert(Parent == 0 && "Instruction still linked in the program!");
+  }
+
   // Specialize setName to handle symbol table majik...
   virtual void setName(const std::string &name, SymbolTable *ST = 0);
   
@@ -76,9 +87,14 @@ public:
   }
   static const char* getOpcodeName(unsigned OpCode);
 
+  static inline bool isTerminator(unsigned OpCode) {
+    return OpCode >= TermOpsBegin && OpCode < TermOpsEnd;
+  }
+
   inline bool isTerminator() const {   // Instance of TerminatorInst?
-    return iType >= TermOpsBegin && iType < TermOpsEnd;
+    return isTerminator(iType);
   }
+
   inline bool isBinaryOp() const {
     return iType >= BinaryOpsBegin && iType < BinaryOpsEnd;
   }
@@ -103,6 +119,12 @@ public:
   bool isCommutative() const { return isCommutative(getOpcode()); }
   static bool isCommutative(unsigned op);
 
+  /// isRelational - Return true if the instruction is a Set* instruction:
+  ///
+  bool isRelational() const { return isRelational(getOpcode()); }
+  static bool isRelational(unsigned op);
+
+
   /// isTrappingInstruction - Return true if the instruction may trap.
   ///
   bool isTrapping() const {
@@ -151,4 +173,6 @@ public:
   };
 };
 
+} // End llvm namespace
+
 #endif