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

Owen Anderson resistor at mac.com
Thu Jul 23 17:36:27 PDT 2009


Author: resistor
Date: Thu Jul 23 19:36:24 2009
New Revision: 76922

URL: http://llvm.org/viewvc/llvm-project?rev=76922&view=rev
Log:
Privatize the ConstantVector tables.

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

Modified: llvm/trunk/include/llvm/Constants.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Constants.h?rev=76922&r1=76921&r2=76922&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Constants.h (original)
+++ llvm/trunk/include/llvm/Constants.h Thu Jul 23 19:36:24 2009
@@ -390,9 +390,6 @@
 protected:
   ConstantVector(const VectorType *T, const std::vector<Constant*> &Val);
 public:
-  /// get() - Static factory methods - Return objects of the specified value
-  static Constant *get(const VectorType *T, const std::vector<Constant*> &);
-  
   /// Transparently provide more efficient getOperand methods.
   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
 

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

==============================================================================
--- llvm/trunk/include/llvm/LLVMContext.h (original)
+++ llvm/trunk/include/llvm/LLVMContext.h Thu Jul 23 19:36:24 2009
@@ -276,6 +276,7 @@
   void erase(ConstantAggregateZero *Z);
   void erase(ConstantArray *Z);
   void erase(ConstantStruct *S);
+  void erase(ConstantVector *V);
   
   // RAUW helpers
   Constant *replaceUsesOfWithOnConstant(ConstantArray *CA,

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

==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Thu Jul 23 19:36:24 2009
@@ -1107,66 +1107,11 @@
   destroyConstantImpl();
 }
 
-//---- ConstantVector::get() implementation...
-//
-namespace llvm {
-  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.
-    }
-  };
-}
-
-static std::vector<Constant*> getValType(ConstantVector *CP) {
-  std::vector<Constant*> Elements;
-  Elements.reserve(CP->getNumOperands());
-  for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
-    Elements.push_back(CP->getOperand(i));
-  return Elements;
-}
-
-static ManagedStatic<ValueMap<std::vector<Constant*>, VectorType,
-                              ConstantVector> > VectorConstants;
-
-Constant *ConstantVector::get(const VectorType *Ty,
-                              const std::vector<Constant*> &V) {
-  assert(!V.empty() && "Vectors can't be empty");
-  // If this is an all-undef or alll-zero vector, return a
-  // ConstantAggregateZero or UndefValue.
-  Constant *C = V[0];
-  bool isZero = C->isNullValue();
-  bool isUndef = isa<UndefValue>(C);
-
-  if (isZero || isUndef) {
-    for (unsigned i = 1, e = V.size(); i != e; ++i)
-      if (V[i] != C) {
-        isZero = isUndef = false;
-        break;
-      }
-  }
-  
-  if (isZero)
-    return Ty->getContext().getConstantAggregateZero(Ty);
-  if (isUndef)
-    return UndefValue::get(Ty);
-    
-  // Implicitly locked.
-  return VectorConstants->getOrCreate(Ty, V);
-}
-
 // destroyConstant - Remove the constant from the constant table...
 //
 void ConstantVector::destroyConstant() {
   // Implicitly locked.
-  VectorConstants->remove(this);
+  getType()->getContext().erase(this);
   destroyConstantImpl();
 }
 
@@ -2099,7 +2044,8 @@
     Values.push_back(Val);
   }
   
-  Constant *Replacement = ConstantVector::get(getType(), Values);
+  Constant *Replacement =
+    getType()->getContext().getConstantVector(getType(), Values);
   assert(Replacement != this && "I didn't contain From!");
   
   // Everyone using this now uses the replacement.

Modified: llvm/trunk/lib/VMCore/LLVMContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContext.cpp?rev=76922&r1=76921&r2=76922&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContext.cpp (original)
+++ llvm/trunk/lib/VMCore/LLVMContext.cpp Thu Jul 23 19:36:24 2009
@@ -531,7 +531,7 @@
 // ConstantVector accessors.
 Constant* LLVMContext::getConstantVector(const VectorType* T,
                             const std::vector<Constant*>& V) {
-  return ConstantVector::get(T, V);
+  return pImpl->getConstantVector(T, V);
 }
 
 Constant* LLVMContext::getConstantVector(const std::vector<Constant*>& V) {
@@ -662,6 +662,10 @@
   pImpl->erase(S);
 }
 
+void LLVMContext::erase(ConstantVector *V) {
+  pImpl->erase(V);
+}
+
 Constant *LLVMContext::replaceUsesOfWithOnConstant(ConstantArray *CA,
                                                Value *From, Value *To, Use *U) {
   return pImpl->replaceUsesOfWithOnConstant(CA, From, To, U);

Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.cpp?rev=76922&r1=76921&r2=76922&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.cpp (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.cpp Thu Jul 23 19:36:24 2009
@@ -37,6 +37,14 @@
   return Elements;
 }
 
+static std::vector<Constant*> getValType(ConstantVector *CP) {
+  std::vector<Constant*> Elements;
+  Elements.reserve(CP->getNumOperands());
+  for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
+    Elements.push_back(CP->getOperand(i));
+  return Elements;
+}
+
 namespace llvm {
 template<typename T, typename Alloc>
 struct VISIBILITY_HIDDEN ConstantTraits< std::vector<T, Alloc> > {
@@ -106,6 +114,20 @@
     OldC->destroyConstant();    // This constant is now dead, destroy it.
   }
 };
+
+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 = OldC->getContext().getConstantVector(NewTy, C);
+    assert(New != OldC && "Didn't replace constant??");
+    OldC->uncheckedReplaceAllUsesWith(New);
+    OldC->destroyConstant();    // This constant is now dead, destroy it.
+  }
+};
 }
   
 template<class ValType, class TypeClass, class ConstantClass,
@@ -348,12 +370,14 @@
   AggZeroConstants = new ValueMap<char, Type, ConstantAggregateZero>();
   ArrayConstants = new ArrayConstantsTy();
   StructConstants = new StructConstantsTy();
+  VectorConstants = new VectorConstantsTy();
 }
 
 LLVMContextImpl::~LLVMContextImpl() {
   delete AggZeroConstants;
   delete ArrayConstants;
   delete StructConstants;
+  delete VectorConstants;
 }
 
 // Get a ConstantInt from an APInt. Note that the value stored in the DenseMap 
@@ -492,6 +516,32 @@
   return Context.getConstantAggregateZero(Ty);
 }
 
+Constant *LLVMContextImpl::getConstantVector(const VectorType *Ty,
+                              const std::vector<Constant*> &V) {
+  assert(!V.empty() && "Vectors can't be empty");
+  // If this is an all-undef or alll-zero vector, return a
+  // ConstantAggregateZero or UndefValue.
+  Constant *C = V[0];
+  bool isZero = C->isNullValue();
+  bool isUndef = isa<UndefValue>(C);
+
+  if (isZero || isUndef) {
+    for (unsigned i = 1, e = V.size(); i != e; ++i)
+      if (V[i] != C) {
+        isZero = isUndef = false;
+        break;
+      }
+  }
+  
+  if (isZero)
+    return Context.getConstantAggregateZero(Ty);
+  if (isUndef)
+    return Context.getUndef(Ty);
+    
+  // Implicitly locked.
+  return VectorConstants->getOrCreate(Ty, V);
+}
+
 // *** erase methods ***
 
 void LLVMContextImpl::erase(MDString *M) {
@@ -517,6 +567,10 @@
   StructConstants->remove(S);
 }
 
+void LLVMContextImpl::erase(ConstantVector *V) {
+  VectorConstants->remove(V);
+}
+
 // *** RAUW helpers ***
 
 Constant *LLVMContextImpl::replaceUsesOfWithOnConstant(ConstantArray *CA,
@@ -659,4 +713,4 @@
   assert(Replacement != CS && "I didn't contain From!");
   
   return Replacement;
-}
\ No newline at end of file
+}

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

==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.h (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.h Thu Jul 23 19:36:24 2009
@@ -122,6 +122,10 @@
                    ConstantStruct, true /*largekey*/> StructConstantsTy;
   StructConstantsTy *StructConstants;
   
+  typedef ValueMap<std::vector<Constant*>, VectorType,
+                   ConstantVector> VectorConstantsTy;
+  VectorConstantsTy *VectorConstants;
+  
   LLVMContext &Context;
   ConstantInt *TheTrueVal;
   ConstantInt *TheFalseVal;
@@ -150,6 +154,9 @@
   Constant *getConstantStruct(const StructType *Ty, 
                               const std::vector<Constant*> &V);
   
+  Constant *getConstantVector(const VectorType *Ty,
+                              const std::vector<Constant*> &V);
+  
   ConstantInt *getTrue() {
     if (TheTrueVal)
       return TheTrueVal;
@@ -169,6 +176,7 @@
   void erase(ConstantAggregateZero *Z);
   void erase(ConstantArray *C);
   void erase(ConstantStruct *S);
+  void erase(ConstantVector *V);
   
   // RAUW helpers
   





More information about the llvm-commits mailing list