Use CallbackVH, instead of WeakVH, to hold MDNode elements. 
Use FoldingSetNode to unique MDNodes in a context.
Use CallbackVH hooks to update context's MDNodeSet appropriately.

llvm-svn: 80839
diff --git a/llvm/lib/VMCore/ConstantsContext.h b/llvm/lib/VMCore/ConstantsContext.h
index f4a2cde..718470a 100644
--- a/llvm/lib/VMCore/ConstantsContext.h
+++ b/llvm/lib/VMCore/ConstantsContext.h
@@ -16,7 +16,6 @@
 #define LLVM_CONSTANTSCONTEXT_H
 
 #include "llvm/Instructions.h"
-#include "llvm/Metadata.h"
 #include "llvm/Operator.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -341,7 +340,7 @@
 };
 
 template<class ConstantClass, class TypeClass>
-struct ConvertConstant {
+struct ConvertConstantType {
   static void convert(ConstantClass *OldC, const TypeClass *NewTy) {
     llvm_unreachable("This type cannot be converted!");
   }
@@ -392,7 +391,7 @@
 };
 
 template<>
-struct ConvertConstant<ConstantExpr, Type> {
+struct ConvertConstantType<ConstantExpr, Type> {
   static void convert(ConstantExpr *OldC, const Type *NewTy) {
     Constant *New;
     switch (OldC->getOpcode()) {
@@ -445,14 +444,7 @@
 };
 
 template<>
-struct ConstantCreator<MDNode, Type, std::vector<Value*> > {
-  static MDNode *create(const Type* Ty, const std::vector<Value*> &V) {
-    return new MDNode(Ty->getContext(), &V[0], V.size());
-  }
-};
-
-template<>
-struct ConvertConstant<ConstantVector, VectorType> {
+struct ConvertConstantType<ConstantVector, VectorType> {
   static void convert(ConstantVector *OldC, const VectorType *NewTy) {
     // Make everyone now use a constant of the new type...
     std::vector<Constant*> C;
@@ -466,7 +458,7 @@
 };
 
 template<>
-struct ConvertConstant<ConstantAggregateZero, Type> {
+struct ConvertConstantType<ConstantAggregateZero, Type> {
   static void convert(ConstantAggregateZero *OldC, const Type *NewTy) {
     // Make everyone now use a constant of the new type...
     Constant *New = ConstantAggregateZero::get(NewTy);
@@ -477,7 +469,7 @@
 };
 
 template<>
-struct ConvertConstant<ConstantArray, ArrayType> {
+struct ConvertConstantType<ConstantArray, ArrayType> {
   static void convert(ConstantArray *OldC, const ArrayType *NewTy) {
     // Make everyone now use a constant of the new type...
     std::vector<Constant*> C;
@@ -491,7 +483,7 @@
 };
 
 template<>
-struct ConvertConstant<ConstantStruct, StructType> {
+struct ConvertConstantType<ConstantStruct, StructType> {
   static void convert(ConstantStruct *OldC, const StructType *NewTy) {
     // Make everyone now use a constant of the new type...
     std::vector<Constant*> C;
@@ -514,7 +506,7 @@
 };
 
 template<>
-struct ConvertConstant<ConstantPointerNull, PointerType> {
+struct ConvertConstantType<ConstantPointerNull, PointerType> {
   static void convert(ConstantPointerNull *OldC, const PointerType *NewTy) {
     // Make everyone now use a constant of the new type...
     Constant *New = ConstantPointerNull::get(NewTy);
@@ -533,7 +525,7 @@
 };
 
 template<>
-struct ConvertConstant<UndefValue, Type> {
+struct ConvertConstantType<UndefValue, Type> {
   static void convert(UndefValue *OldC, const Type *NewTy) {
     // Make everyone now use a constant of the new type.
     Constant *New = UndefValue::get(NewTy);
@@ -548,8 +540,8 @@
 class ValueMap : public AbstractTypeUser {
 public:
   typedef std::pair<const Type*, ValType> MapKey;
-  typedef std::map<MapKey, Value *> MapTy;
-  typedef std::map<Value*, typename MapTy::iterator> InverseMapTy;
+  typedef std::map<MapKey, Constant *> MapTy;
+  typedef std::map<Constant*, typename MapTy::iterator> InverseMapTy;
   typedef std::map<const Type*, typename MapTy::iterator> AbstractTypeMapTy;
 private:
   /// Map - This is the main map from the element descriptor to the Constants.
@@ -767,7 +759,8 @@
     // leaving will remove() itself, causing the AbstractTypeMapEntry to be
     // eliminated eventually.
     do {
-      ConvertConstant<ConstantClass, TypeClass>::convert(
+      ConvertConstantType<ConstantClass,
+                          TypeClass>::convert(
                               static_cast<ConstantClass *>(I->second->second),
                                               cast<TypeClass>(NewTy));