Remove special cases for more opcodes.
[oota-llvm.git] / include / llvm / Value.h
index f9edba116b5fcbe0a48febf21f9ad098b7735dca..a38d8cb8d9846a895a210827b7ec217575453f37 100644 (file)
@@ -34,9 +34,12 @@ class InlineAsm;
 class ValueSymbolTable;
 class TypeSymbolTable;
 template<typename ValueTy> class StringMapEntry;
+template <typename ValueTy = Value>
+class AssertingVH;
 typedef StringMapEntry<Value*> ValueName;
 class raw_ostream;
 class AssemblyAnnotationWriter;
+class ValueHandleBase;
 
 //===----------------------------------------------------------------------===//
 //                                 Value Class
@@ -50,10 +53,14 @@ class AssemblyAnnotationWriter;
 /// automatically updates the module's symbol table.
 ///
 /// Every value has a "use list" that keeps track of which other Values are
-/// using this Value.
+/// using this Value.  A Value can also have an arbitrary number of ValueHandle
+/// objects that watch it and listen to RAUW and Destroy events see
+/// llvm/Support/ValueHandle.h for details.
+///
 /// @brief LLVM Value Representation
 class Value {
-  const unsigned short SubclassID;   // Subclass identifier (for isa/dyn_cast)
+  const unsigned char SubclassID;   // Subclass identifier (for isa/dyn_cast)
+  unsigned char HasValueHandle : 1; // Has a ValueHandle pointing to this?
 protected:
   /// SubclassData - This member is defined by this class, but is not used for
   /// anything.  Subclasses can use it to hold whatever state they find useful.
@@ -65,6 +72,7 @@ private:
 
   friend class ValueSymbolTable; // Allow ValueSymbolTable to directly mod Name.
   friend class SymbolTable;      // Allow SymbolTable to directly poke Name.
+  friend class ValueHandleBase;
   ValueName *Name;
 
   void operator=(const Value &);     // Do not implement
@@ -195,13 +203,15 @@ public:
     ConstantStructVal,        // This is an instance of ConstantStruct
     ConstantVectorVal,        // This is an instance of ConstantVector
     ConstantPointerNullVal,   // This is an instance of ConstantPointerNull
+    MDStringVal,              // This is an instance of MDString
+    MDNodeVal,                // This is an instance of MDNode
     InlineAsmVal,             // This is an instance of InlineAsm
     PseudoSourceValueVal,     // This is an instance of PseudoSourceValue
     InstructionVal,           // This is an instance of Instruction
     
     // Markers:
     ConstantFirstVal = FunctionVal,
-    ConstantLastVal  = ConstantPointerNullVal
+    ConstantLastVal  = MDNodeVal
   };
 
   /// getValueID - Return an ID for the concrete type of this object.  This is
@@ -228,11 +238,31 @@ public:
 
   /// stripPointerCasts - This method strips off any unneeded pointer
   /// casts from the specified value, returning the original uncasted value.
-  /// Note that the returned value is guaranteed to have pointer type.
+  /// Note that the returned value has pointer type if the specified value does.
   Value *stripPointerCasts();
   const Value *stripPointerCasts() const {
     return const_cast<Value*>(this)->stripPointerCasts();
   }
+
+  /// getUnderlyingObject - This method strips off any GEP address adjustments
+  /// and pointer casts from the specified value, returning the original object
+  /// being addressed.  Note that the returned value has pointer type if the
+  /// specified value does.
+  Value *getUnderlyingObject();
+  const Value *getUnderlyingObject() const {
+    return const_cast<Value*>(this)->getUnderlyingObject();
+  }
+  
+  /// DoPHITranslation - If this value is a PHI node with CurBB as its parent,
+  /// return the value in the PHI node corresponding to PredBB.  If not, return
+  /// ourself.  This is useful if you want to know the value something has in a
+  /// predecessor block.
+  Value *DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB);
+
+  const Value *DoPHITranslation(const BasicBlock *CurBB,
+                                const BasicBlock *PredBB) const{
+    return const_cast<Value*>(this)->DoPHITranslation(CurBB, PredBB);
+  }
 };
 
 inline std::ostream &operator<<(std::ostream &OS, const Value &V) {
@@ -244,11 +274,6 @@ inline raw_ostream &operator<<(raw_ostream &OS, const Value &V) {
   return OS;
 }
   
-void Use::init(Value *V, User *) {
-  Val = V;
-  if (V) V->addUse(*this);
-}
-
 void Use::set(Value *V) {
   if (Val) removeFromList();
   Val = V;
@@ -285,8 +310,22 @@ template <> inline bool isa_impl<GlobalAlias, Value>(const Value &Val) {
   return Val.getValueID() == Value::GlobalAliasVal;
 }
 template <> inline bool isa_impl<GlobalValue, Value>(const Value &Val) {
-  return isa<GlobalVariable>(Val) || isa<Function>(Val) || isa<GlobalAlias>(Val);
+  return isa<GlobalVariable>(Val) || isa<Function>(Val) ||
+         isa<GlobalAlias>(Val);
 }
+  
+  
+// Value* is only 4-byte aligned.
+template<>
+class PointerLikeTypeTraits<Value*> {
+  typedef Value* PT;
+public:
+  static inline void *getAsVoidPointer(PT P) { return P; }
+  static inline PT getFromVoidPointer(void *P) {
+    return static_cast<PT>(P);
+  }
+  enum { NumLowBitsAvailable = 2 };
+};
 
 } // End llvm namespace