[llvm-commits] [llvm] r148691 - in /llvm/trunk/lib/VMCore: Constants.cpp ConstantsContext.h LLVMContextImpl.cpp LLVMContextImpl.h

Chris Lattner sabre at nondot.org
Mon Jan 23 00:42:38 PST 2012


Author: lattner
Date: Mon Jan 23 02:42:38 2012
New Revision: 148691

URL: http://llvm.org/viewvc/llvm-project?rev=148691&view=rev
Log:
Replace a use of ConstantUniqueMap for CAZ constants with a simple DenseMap.
Now that the type system rewrite has landed, there is no need for its
complexity and std::map'ness.

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

Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=148691&r1=148690&r2=148691&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Mon Jan 23 02:42:38 2012
@@ -993,18 +993,33 @@
 //===----------------------------------------------------------------------===//
 //                      Factory Function Implementation
 
-ConstantAggregateZero* ConstantAggregateZero::get(Type* Ty) {
+ConstantAggregateZero *ConstantAggregateZero::get(Type *Ty) {
   assert((Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy()) &&
          "Cannot create an aggregate zero of non-aggregate type!");
   
-  LLVMContextImpl *pImpl = Ty->getContext().pImpl;
-  return pImpl->AggZeroConstants.getOrCreate(Ty, 0);
+  OwningPtr<ConstantAggregateZero> &Entry =
+    Ty->getContext().pImpl->CAZConstants[Ty];
+  if (Entry == 0)
+    Entry.reset(new ConstantAggregateZero(Ty));
+  
+  return Entry.get();
 }
 
 /// destroyConstant - Remove the constant from the constant table...
 ///
 void ConstantAggregateZero::destroyConstant() {
-  getType()->getContext().pImpl->AggZeroConstants.remove(this);
+  // Drop ownership of the CAZ object before removing the entry so that it
+  // doesn't get double deleted.
+  LLVMContextImpl::CAZMapTy &CAZConstants = getContext().pImpl->CAZConstants;
+  LLVMContextImpl::CAZMapTy::iterator I = CAZConstants.find(getType());
+  assert(I != CAZConstants.end() && "CAZ object not in uniquing map");
+  I->second.take();
+  
+  // Actually remove the entry from the DenseMap now, which won't free the
+  // constant.
+  CAZConstants.erase(I);
+  
+  // Free the constant and any dangling references to it.
   destroyConstantImpl();
 }
 

Modified: llvm/trunk/lib/VMCore/ConstantsContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ConstantsContext.h?rev=148691&r1=148690&r2=148691&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/ConstantsContext.h (original)
+++ llvm/trunk/lib/VMCore/ConstantsContext.h Mon Jan 23 02:42:38 2012
@@ -477,13 +477,6 @@
   }
 };
 
-// ConstantAggregateZero does not take extra "value" argument...
-template<class ValType>
-struct ConstantCreator<ConstantAggregateZero, Type, ValType> {
-  static ConstantAggregateZero *create(Type *Ty, const ValType &V){
-    return new ConstantAggregateZero(Ty);
-  }
-};
 
 template<>
 struct ConstantKeyData<ConstantVector> {
@@ -498,14 +491,6 @@
 };
 
 template<>
-struct ConstantKeyData<ConstantAggregateZero> {
-  typedef char ValType;
-  static ValType getValType(ConstantAggregateZero *C) {
-    return 0;
-  }
-};
-
-template<>
 struct ConstantKeyData<ConstantArray> {
   typedef std::vector<Constant*> ValType;
   static ValType getValType(ConstantArray *CA) {

Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.cpp?rev=148691&r1=148690&r2=148691&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.cpp (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.cpp Mon Jan 23 02:42:38 2012
@@ -70,7 +70,7 @@
   ArrayConstants.freeConstants();
   StructConstants.freeConstants();
   VectorConstants.freeConstants();
-  AggZeroConstants.freeConstants();
+  CAZConstants.clear();
   NullPtrConstants.freeConstants();
   UndefValueConstants.freeConstants();
   InlineAsms.freeConstants();

Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.h?rev=148691&r1=148690&r2=148691&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.h (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.h Mon Jan 23 02:42:38 2012
@@ -27,6 +27,7 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/OwningPtr.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/StringMap.h"
 #include <vector>
@@ -138,7 +139,8 @@
   // on Context destruction.
   SmallPtrSet<MDNode*, 1> NonUniquedMDNodes;
   
-  ConstantUniqueMap<char, char, Type, ConstantAggregateZero> AggZeroConstants;
+  typedef DenseMap<Type*, OwningPtr<ConstantAggregateZero> > CAZMapTy;
+  CAZMapTy CAZConstants;
 
   typedef ConstantUniqueMap<std::vector<Constant*>, ArrayRef<Constant*>,
     ArrayType, ConstantArray, true /*largekey*/> ArrayConstantsTy;





More information about the llvm-commits mailing list