remove DebugLoc from MCInst and eliminate "Comment printing" from
[oota-llvm.git] / include / llvm / Metadata.h
index 8533efddb0f2cbe075991043406095b740d27d4f..0844006396d8a0e2f7b56d7ace1be4d47fa6f2e0 100644 (file)
@@ -19,7 +19,9 @@
 #include "llvm/User.h"
 #include "llvm/Type.h"
 #include "llvm/OperandTraits.h"
+#include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/ilist_node.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ValueHandle.h"
@@ -27,8 +29,6 @@
 namespace llvm {
 class Constant;
 class LLVMContext;
-template<class ConstantClass, class TypeClass, class ValType>
-struct ConstantCreator;
 
 //===----------------------------------------------------------------------===//
 // MetadataBase  - A base class for MDNode, MDString and NamedMDNode.
@@ -44,12 +44,6 @@ protected:
 
   void resizeOperands(unsigned NumOps);
 public:
-  /// getType() specialization - Type is always MetadataTy.
-  ///
-  inline const Type *getType() const {
-    return Type::MetadataTy;
-  }
-
   /// isNullValue - Return true if this is the value that would be returned by
   /// getNullValue.  This always returns false because getNullValue will never
   /// produce metadata.
@@ -76,8 +70,8 @@ class MDString : public MetadataBase {
 
   StringRef Str;
 protected:
-  explicit MDString(const char *begin, unsigned l)
-    : MetadataBase(Type::MetadataTy, Value::MDStringVal), Str(begin, l) {}
+  explicit MDString(LLVMContext &C, const char *begin, unsigned l)
+    : MetadataBase(Type::getMetadataTy(C), Value::MDStringVal), Str(begin, l) {}
 
 public:
   // Do not allocate any space for operands.
@@ -109,17 +103,34 @@ public:
 /// MDNode - a tuple of other values.
 /// These contain a list of the values that represent the metadata. 
 /// MDNode is always unnamed.
-class MDNode : public MetadataBase {
+class MDNode : public MetadataBase, public FoldingSetNode {
   MDNode(const MDNode &);                // DO NOT IMPLEMENT
   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
   // getNumOperands - Make this only available for private uses.
   unsigned getNumOperands() { return User::getNumOperands();  }
 
-  SmallVector<WeakVH, 4> Node;
-  
-  friend struct ConstantCreator<MDNode, Type, std::vector<Value*> >;
+  friend class ElementVH;
+  // Use CallbackVH to hold MDNOde elements.
+  struct ElementVH : public CallbackVH {
+    MDNode *Parent;
+    ElementVH(Value *V, MDNode *P) : CallbackVH(V), Parent(P) {}
+    ~ElementVH() {}
+
+    virtual void deleted() {
+      Parent->replaceElement(this->operator Value*(), 0);
+    }
+
+    virtual void allUsesReplacedWith(Value *NV) {
+      Parent->replaceElement(this->operator Value*(), NV);
+    }
+  };
+  // Replace each instance of F from the element list of this node with T.
+  void replaceElement(Value *F, Value *T);
+
+  SmallVector<ElementVH, 4> Node;
+
 protected:
-  explicit MDNode(Value*const* Vals, unsigned NumVals);
+  explicit MDNode(LLVMContext &C, Value*const* Vals, unsigned NumVals);
 public:
   // Do not allocate any space for operands.
   void *operator new(size_t s) {
@@ -147,8 +158,8 @@ public:
   }
 
   // Element access
-  typedef SmallVectorImpl<WeakVH>::const_iterator const_elem_iterator;
-  typedef SmallVectorImpl<WeakVH>::iterator elem_iterator;
+  typedef SmallVectorImpl<ElementVH>::const_iterator const_elem_iterator;
+  typedef SmallVectorImpl<ElementVH>::iterator elem_iterator;
   /// elem_empty - Return true if MDNode is empty.
   bool elem_empty() const                { return Node.empty(); }
   const_elem_iterator elem_begin() const { return Node.begin(); }
@@ -156,12 +167,6 @@ public:
   elem_iterator elem_begin()             { return Node.begin(); }
   elem_iterator elem_end()               { return Node.end();   }
 
-  /// getType() specialization - Type is always MetadataTy.
-  ///
-  inline const Type *getType() const {
-    return Type::MetadataTy;
-  }
-
   /// isNullValue - Return true if this is the value that would be returned by
   /// getNullValue.  This always returns false because getNullValue will never
   /// produce metadata.
@@ -169,6 +174,10 @@ public:
     return false;
   }
 
+  /// Profile - calculate a unique identifier for this MDNode to collapse
+  /// duplicates
+  void Profile(FoldingSetNodeID &ID) const;
+
   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) {
     llvm_unreachable("This should never be called because MDNodes have no ops");
   }
@@ -217,16 +226,17 @@ class NamedMDNode : public MetadataBase, public ilist_node<NamedMDNode> {
   typedef SmallVectorImpl<WeakMetadataVH>::iterator elem_iterator;
 
 protected:
-  explicit NamedMDNode(const Twine &N, MetadataBase*const* Vals, 
+  explicit NamedMDNode(LLVMContext &C, const Twine &N, MetadataBase*const* Vals, 
                        unsigned NumVals, Module *M = 0);
 public:
   // Do not allocate any space for operands.
   void *operator new(size_t s) {
     return User::operator new(s, 0);
   }
-  static NamedMDNode *Create(const Twine &N, MetadataBase*const*MDs, 
+  static NamedMDNode *Create(LLVMContext &C, const Twine &N, 
+                             MetadataBase*const*MDs, 
                              unsigned NumMDs, Module *M = 0) {
-    return new NamedMDNode(N, MDs, NumMDs, M);
+    return new NamedMDNode(C, N, MDs, NumMDs, M);
   }
 
   static NamedMDNode *Create(const NamedMDNode *NMD, Module *M = 0);
@@ -271,12 +281,6 @@ public:
   elem_iterator elem_begin()             { return Node.begin(); }
   elem_iterator elem_end()               { return Node.end();   }
 
-  /// getType() specialization - Type is always MetadataTy.
-  ///
-  inline const Type *getType() const {
-    return Type::MetadataTy;
-  }
-
   /// isNullValue - Return true if this is the value that would be returned by
   /// getNullValue.  This always returns false because getNullValue will never
   /// produce metadata.