[llvm-commits] [llvm] r77748 - in /llvm/trunk: include/llvm/LLVMContext.h lib/VMCore/Constants.cpp lib/VMCore/LLVMContextImpl.h

Owen Anderson resistor at mac.com
Fri Jul 31 15:45:43 PDT 2009


Author: resistor
Date: Fri Jul 31 17:45:43 2009
New Revision: 77748

URL: http://llvm.org/viewvc/llvm-project?rev=77748&view=rev
Log:
Privatize all but one of the remaining constant tables.

Modified:
    llvm/trunk/include/llvm/LLVMContext.h
    llvm/trunk/lib/VMCore/Constants.cpp
    llvm/trunk/lib/VMCore/LLVMContextImpl.h

Modified: llvm/trunk/include/llvm/LLVMContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LLVMContext.h?rev=77748&r1=77747&r2=77748&view=diff

==============================================================================
--- llvm/trunk/include/llvm/LLVMContext.h (original)
+++ llvm/trunk/include/llvm/LLVMContext.h Fri Jul 31 17:45:43 2009
@@ -63,6 +63,9 @@
   friend class ConstantAggregateZero;
   friend class MDNode;
   friend class MDString;
+  friend class ConstantPointerNull;
+  friend class UndefValue;
+  friend class ConstantExpr;
 public:
   LLVMContext();
   ~LLVMContext();

Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=77748&r1=77747&r2=77748&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Fri Jul 31 17:45:43 2009
@@ -40,9 +40,6 @@
 //                              Constant Class
 //===----------------------------------------------------------------------===//
 
-// Becomes a no-op when multithreading is disabled.
-ManagedStatic<sys::SmartRWMutex<true> > ConstantsLock;
-
 // Constructor to create a '0' constant of arbitrary type...
 static const uint64_t zero[2] = {0, 0};
 Constant* Constant::getNullValue(const Type* Ty) {
@@ -1208,30 +1205,6 @@
 //---- ConstantPointerNull::get() implementation...
 //
 
-namespace llvm {
-  // ConstantPointerNull does not take extra "value" argument...
-  template<class ValType>
-  struct ConstantCreator<ConstantPointerNull, PointerType, ValType> {
-    static ConstantPointerNull *create(const PointerType *Ty, const ValType &V){
-      return new ConstantPointerNull(Ty);
-    }
-  };
-
-  template<>
-  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);
-      assert(New != OldC && "Didn't replace constant??");
-      OldC->uncheckedReplaceAllUsesWith(New);
-      OldC->destroyConstant();     // This constant is now dead, destroy it.
-    }
-  };
-}
-
-static ManagedStatic<ValueMap<char, PointerType, 
-                              ConstantPointerNull> > NullPtrConstants;
-
 static char getValType(ConstantPointerNull *) {
   return 0;
 }
@@ -1239,14 +1212,14 @@
 
 ConstantPointerNull *ConstantPointerNull::get(const PointerType *Ty) {
   // Implicitly locked.
-  return NullPtrConstants->getOrCreate(Ty, 0);
+  return Ty->getContext().pImpl->NullPtrConstants.getOrCreate(Ty, 0);
 }
 
 // destroyConstant - Remove the constant from the constant table...
 //
 void ConstantPointerNull::destroyConstant() {
   // Implicitly locked.
-  NullPtrConstants->remove(this);
+  getType()->getContext().pImpl->NullPtrConstants.remove(this);
   destroyConstantImpl();
 }
 
@@ -1254,44 +1227,20 @@
 //---- UndefValue::get() implementation...
 //
 
-namespace llvm {
-  // UndefValue does not take extra "value" argument...
-  template<class ValType>
-  struct ConstantCreator<UndefValue, Type, ValType> {
-    static UndefValue *create(const Type *Ty, const ValType &V) {
-      return new UndefValue(Ty);
-    }
-  };
-
-  template<>
-  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);
-      assert(New != OldC && "Didn't replace constant??");
-      OldC->uncheckedReplaceAllUsesWith(New);
-      OldC->destroyConstant();     // This constant is now dead, destroy it.
-    }
-  };
-}
-
-static ManagedStatic<ValueMap<char, Type, UndefValue> > UndefValueConstants;
-
 static char getValType(UndefValue *) {
   return 0;
 }
 
-
 UndefValue *UndefValue::get(const Type *Ty) {
   // Implicitly locked.
-  return UndefValueConstants->getOrCreate(Ty, 0);
+  return Ty->getContext().pImpl->UndefValueConstants.getOrCreate(Ty, 0);
 }
 
 // destroyConstant - Remove the constant from the constant table.
 //
 void UndefValue::destroyConstant() {
   // Implicitly locked.
-  UndefValueConstants->remove(this);
+  getType()->getContext().pImpl->UndefValueConstants.remove(this);
   destroyConstantImpl();
 }
 

Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.h?rev=77748&r1=77747&r2=77748&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.h (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.h Fri Jul 31 17:45:43 2009
@@ -71,6 +71,20 @@
 };
 
 template<>
+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;
+    for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i)
+      C.push_back(cast<Constant>(OldC->getOperand(i)));
+    Constant *New = ConstantVector::get(NewTy, C);
+    assert(New != OldC && "Didn't replace constant??");
+    OldC->uncheckedReplaceAllUsesWith(New);
+    OldC->destroyConstant();    // This constant is now dead, destroy it.
+  }
+};
+
+template<>
 struct ConvertConstantType<ConstantAggregateZero, Type> {
   static void convert(ConstantAggregateZero *OldC, const Type *NewTy) {
     // Make everyone now use a constant of the new type...
@@ -110,17 +124,41 @@
   }
 };
 
+// ConstantPointerNull does not take extra "value" argument...
+template<class ValType>
+struct ConstantCreator<ConstantPointerNull, PointerType, ValType> {
+  static ConstantPointerNull *create(const PointerType *Ty, const ValType &V){
+    return new ConstantPointerNull(Ty);
+  }
+};
+
 template<>
-struct ConvertConstantType<ConstantVector, VectorType> {
-  static void convert(ConstantVector *OldC, const VectorType *NewTy) {
+struct ConvertConstantType<ConstantPointerNull, PointerType> {
+  static void convert(ConstantPointerNull *OldC, const PointerType *NewTy) {
     // Make everyone now use a constant of the new type...
-    std::vector<Constant*> C;
-    for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i)
-      C.push_back(cast<Constant>(OldC->getOperand(i)));
-    Constant *New = ConstantVector::get(NewTy, C);
+    Constant *New = ConstantPointerNull::get(NewTy);
     assert(New != OldC && "Didn't replace constant??");
     OldC->uncheckedReplaceAllUsesWith(New);
-    OldC->destroyConstant();    // This constant is now dead, destroy it.
+    OldC->destroyConstant();     // This constant is now dead, destroy it.
+  }
+};
+
+// UndefValue does not take extra "value" argument...
+template<class ValType>
+struct ConstantCreator<UndefValue, Type, ValType> {
+  static UndefValue *create(const Type *Ty, const ValType &V) {
+    return new UndefValue(Ty);
+  }
+};
+
+template<>
+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);
+    assert(New != OldC && "Didn't replace constant??");
+    OldC->uncheckedReplaceAllUsesWith(New);
+    OldC->destroyConstant();     // This constant is now dead, destroy it.
   }
 };
 
@@ -449,6 +487,10 @@
                    ConstantVector> VectorConstantsTy;
   VectorConstantsTy VectorConstants;
   
+  ValueMap<char, PointerType, ConstantPointerNull> NullPtrConstants;
+  
+  ValueMap<char, Type, UndefValue> UndefValueConstants;
+  
   LLVMContext &Context;
   ConstantInt *TheTrueVal;
   ConstantInt *TheFalseVal;
@@ -464,6 +506,8 @@
   friend class ConstantAggregateZero;
   friend class MDNode;
   friend class MDString;
+  friend class ConstantPointerNull;
+  friend class UndefValue;
 public:
   LLVMContextImpl(LLVMContext &C);
 };





More information about the llvm-commits mailing list