Definition of the Bytecode Handler interface. Subclasses can override just
[oota-llvm.git] / include / llvm / Instruction.h
index ca01e30fe54776a5ba98b5beeade4acfcf122d73..86f2a056cb975df4055ed6213d559536375f174a 100644 (file)
@@ -1,4 +1,11 @@
 //===-- llvm/Instruction.h - Instruction class definition -------*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
 //
 // This file contains the declaration of the Instruction class, which is the
 // base class for all of the LLVM instructions.
 #define LLVM_INSTRUCTION_H
 
 #include "llvm/User.h"
+#include "Support/Annotation.h"
+
+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
 
@@ -23,14 +36,19 @@ 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:
-  virtual ~Instruction() {
-    assert(Parent == 0 && "Instruction still embedded in basic block!");
+
+  ~Instruction() {
+    assert(Parent == 0 && "Instruction still linked in the program!");
   }
 
   // Specialize setName to handle symbol table majik...
@@ -55,7 +73,9 @@ public:
         Instruction *getPrev()       { return Prev; }
   const Instruction *getPrev() const { return Prev; }
 
-  virtual bool hasSideEffects() const { return false; }  // Memory & Call insts
+  /// mayWriteToMemory - Return true if this instruction may modify memory.
+  ///
+  virtual bool mayWriteToMemory() const { return false; }
 
   // ---------------------------------------------------------------------------
   /// Subclass classification... getOpcode() returns a member of 
@@ -67,16 +87,21 @@ 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;
   }
 
   /// isAssociative - Return true if the instruction is associative:
   ///
-  ///   Associative operators satisfy:  x op (y op z) === (x op y) op z)
+  ///   Associative operators satisfy:  x op (y op z) === (x op y) op z
   ///
   /// In LLVM, the Add, Mul, And, Or, and Xor operators are associative, when
   /// not applied to floating point types.
@@ -86,7 +111,7 @@ public:
 
   /// isCommutative - Return true if the instruction is commutative:
   ///
-  ///   Commutative operators satistify: (x op y) === (y op x)
+  ///   Commutative operators satisfy: (x op y) === (y op x)
   ///
   /// In LLVM, these are the associative operators, plus SetEQ and SetNE, when
   /// applied to any type.
@@ -94,8 +119,21 @@ 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);
+
 
-  virtual void print(std::ostream &OS) const;
+  /// isTrappingInstruction - Return true if the instruction may trap.
+  ///
+  bool isTrapping() const {
+    return isTrapping(getOpcode()); 
+  }
+  static bool isTrapping(unsigned op);
+  
+  virtual void print(std::ostream &OS) const { print(OS, 0); }
+  void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const;
 
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const Instruction *I) { return true; }
@@ -135,4 +173,6 @@ public:
   };
 };
 
+} // End llvm namespace
+
 #endif