[llvm] r222714 - unique_ptrify LLVMContextImpl::CAZConstants

David Blaikie dblaikie at gmail.com
Mon Nov 24 18:13:54 PST 2014


Author: dblaikie
Date: Mon Nov 24 20:13:54 2014
New Revision: 222714

URL: http://llvm.org/viewvc/llvm-project?rev=222714&view=rev
Log:
unique_ptrify LLVMContextImpl::CAZConstants

Modified:
    llvm/trunk/lib/IR/Constants.cpp
    llvm/trunk/lib/IR/LLVMContextImpl.cpp
    llvm/trunk/lib/IR/LLVMContextImpl.h

Modified: llvm/trunk/lib/IR/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Constants.cpp?rev=222714&r1=222713&r2=222714&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Constants.cpp (original)
+++ llvm/trunk/lib/IR/Constants.cpp Mon Nov 24 20:13:54 2014
@@ -1330,12 +1330,12 @@ bool ConstantFP::isValueValidForType(Typ
 ConstantAggregateZero *ConstantAggregateZero::get(Type *Ty) {
   assert((Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy()) &&
          "Cannot create an aggregate zero of non-aggregate type!");
-  
-  ConstantAggregateZero *&Entry = Ty->getContext().pImpl->CAZConstants[Ty];
+
+  auto &Entry = Ty->getContext().pImpl->CAZConstants[Ty];
   if (!Entry)
-    Entry = new ConstantAggregateZero(Ty);
+    Entry.reset(new ConstantAggregateZero(Ty));
 
-  return Entry;
+  return Entry.get();
 }
 
 /// destroyConstant - Remove the constant from the constant table.

Modified: llvm/trunk/lib/IR/LLVMContextImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContextImpl.cpp?rev=222714&r1=222713&r2=222714&view=diff
==============================================================================
--- llvm/trunk/lib/IR/LLVMContextImpl.cpp (original)
+++ llvm/trunk/lib/IR/LLVMContextImpl.cpp Mon Nov 24 20:13:54 2014
@@ -87,7 +87,7 @@ LLVMContextImpl::~LLVMContextImpl() {
   ArrayConstants.freeConstants();
   StructConstants.freeConstants();
   VectorConstants.freeConstants();
-  DeleteContainerSeconds(CAZConstants);
+  CAZConstants.clear();
   DeleteContainerSeconds(CPNConstants);
   DeleteContainerSeconds(UVConstants);
   InlineAsms.freeConstants();

Modified: llvm/trunk/lib/IR/LLVMContextImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContextImpl.h?rev=222714&r1=222713&r2=222714&view=diff
==============================================================================
--- llvm/trunk/lib/IR/LLVMContextImpl.h (original)
+++ llvm/trunk/lib/IR/LLVMContextImpl.h Mon Nov 24 20:13:54 2014
@@ -299,7 +299,10 @@ public:
   // on Context destruction.
   SmallPtrSet<GenericMDNode *, 1> NonUniquedMDNodes;
 
-  DenseMap<Type*, ConstantAggregateZero*> CAZConstants;
+  // Value is indirected through pointer to keep pointer validity over mutations
+  // of this map. Replace if/when we have an efficient map that guarantees
+  // pointer validity over mutations.
+  DenseMap<Type*, std::unique_ptr<ConstantAggregateZero>> CAZConstants;
 
   typedef ConstantUniqueMap<ConstantArray> ArrayConstantsTy;
   ArrayConstantsTy ArrayConstants;





More information about the llvm-commits mailing list