From 95889fa9c31779c9ef3e71d633b8d9146648bc97 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 23 Jan 2012 15:09:44 +0000 Subject: [PATCH] revert r148691 and 148693 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148698 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/Constants.cpp | 62 +++++----------------------------- lib/VMCore/ConstantsContext.h | 46 +++++++++++++++++++++++++ lib/VMCore/LLVMContextImpl.cpp | 8 ++--- lib/VMCore/LLVMContextImpl.h | 12 +++---- 4 files changed, 61 insertions(+), 67 deletions(-) diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index f2d87942848..9657cd28c1f 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -993,33 +993,18 @@ bool ConstantFP::isValueValidForType(Type *Ty, const APFloat& Val) { //===----------------------------------------------------------------------===// // 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!"); - OwningPtr &Entry = - Ty->getContext().pImpl->CAZConstants[Ty]; - if (Entry == 0) - Entry.reset(new ConstantAggregateZero(Ty)); - - return Entry.get(); + LLVMContextImpl *pImpl = Ty->getContext().pImpl; + return pImpl->AggZeroConstants.getOrCreate(Ty, 0); } /// destroyConstant - Remove the constant from the constant table... /// void ConstantAggregateZero::destroyConstant() { - // 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. + getType()->getContext().pImpl->AggZeroConstants.remove(this); destroyConstantImpl(); } @@ -1127,29 +1112,13 @@ Constant *ConstantVector::getSplatValue() const { // ConstantPointerNull *ConstantPointerNull::get(PointerType *Ty) { - OwningPtr &Entry = - Ty->getContext().pImpl->CPNConstants[Ty]; - if (Entry == 0) - Entry.reset(new ConstantPointerNull(Ty)); - - return Entry.get(); + return Ty->getContext().pImpl->NullPtrConstants.getOrCreate(Ty, 0); } // destroyConstant - Remove the constant from the constant table... // void ConstantPointerNull::destroyConstant() { - // Drop ownership of the CPN object before removing the entry so that it - // doesn't get double deleted. - LLVMContextImpl::CPNMapTy &CPNConstants = getContext().pImpl->CPNConstants; - LLVMContextImpl::CPNMapTy::iterator I = CPNConstants.find(getType()); - assert(I != CPNConstants.end() && "CPN object not in uniquing map"); - I->second.take(); - - // Actually remove the entry from the DenseMap now, which won't free the - // constant. - CPNConstants.erase(I); - - // Free the constant and any dangling references to it. + getType()->getContext().pImpl->NullPtrConstants.remove(this); destroyConstantImpl(); } @@ -1158,28 +1127,13 @@ void ConstantPointerNull::destroyConstant() { // UndefValue *UndefValue::get(Type *Ty) { - OwningPtr &Entry = Ty->getContext().pImpl->UVConstants[Ty]; - if (Entry == 0) - Entry.reset(new UndefValue(Ty)); - - return Entry.get(); + return Ty->getContext().pImpl->UndefValueConstants.getOrCreate(Ty, 0); } // destroyConstant - Remove the constant from the constant table. // void UndefValue::destroyConstant() { - // Drop ownership of the object before removing the entry so that it - // doesn't get double deleted. - LLVMContextImpl::UVMapTy &UVConstants = getContext().pImpl->UVConstants; - LLVMContextImpl::UVMapTy::iterator I = UVConstants.find(getType()); - assert(I != UVConstants.end() && "UV object not in uniquing map"); - I->second.take(); - - // Actually remove the entry from the DenseMap now, which won't free the - // constant. - UVConstants.erase(I); - - // Free the constant and any dangling references to it. + getType()->getContext().pImpl->UndefValueConstants.remove(this); destroyConstantImpl(); } diff --git a/lib/VMCore/ConstantsContext.h b/lib/VMCore/ConstantsContext.h index 4bdeaa78302..4ee4296d448 100644 --- a/lib/VMCore/ConstantsContext.h +++ b/lib/VMCore/ConstantsContext.h @@ -477,6 +477,13 @@ struct ConstantKeyData { } }; +// ConstantAggregateZero does not take extra "value" argument... +template +struct ConstantCreator { + static ConstantAggregateZero *create(Type *Ty, const ValType &V){ + return new ConstantAggregateZero(Ty); + } +}; template<> struct ConstantKeyData { @@ -490,6 +497,14 @@ struct ConstantKeyData { } }; +template<> +struct ConstantKeyData { + typedef char ValType; + static ValType getValType(ConstantAggregateZero *C) { + return 0; + } +}; + template<> struct ConstantKeyData { typedef std::vector ValType; @@ -514,6 +529,37 @@ struct ConstantKeyData { } }; +// ConstantPointerNull does not take extra "value" argument... +template +struct ConstantCreator { + static ConstantPointerNull *create(PointerType *Ty, const ValType &V){ + return new ConstantPointerNull(Ty); + } +}; + +template<> +struct ConstantKeyData { + typedef char ValType; + static ValType getValType(ConstantPointerNull *C) { + return 0; + } +}; + +// UndefValue does not take extra "value" argument... +template +struct ConstantCreator { + static UndefValue *create(Type *Ty, const ValType &V) { + return new UndefValue(Ty); + } +}; + +template<> +struct ConstantKeyData { + typedef char ValType; + static ValType getValType(UndefValue *C) { + return 0; + } +}; template<> struct ConstantCreator { diff --git a/lib/VMCore/LLVMContextImpl.cpp b/lib/VMCore/LLVMContextImpl.cpp index de851ee4bb2..b0dd680926d 100644 --- a/lib/VMCore/LLVMContextImpl.cpp +++ b/lib/VMCore/LLVMContextImpl.cpp @@ -58,8 +58,6 @@ LLVMContextImpl::~LLVMContextImpl() { std::vector Modules(OwnedModules.begin(), OwnedModules.end()); DeleteContainerPointers(Modules); - // Free the constants. This is important to do here to ensure that they are - // freed before the LeakDetector is torn down. std::for_each(ExprConstants.map_begin(), ExprConstants.map_end(), DropReferences()); std::for_each(ArrayConstants.map_begin(), ArrayConstants.map_end(), @@ -72,9 +70,9 @@ LLVMContextImpl::~LLVMContextImpl() { ArrayConstants.freeConstants(); StructConstants.freeConstants(); VectorConstants.freeConstants(); - CAZConstants.clear(); - CPNConstants.clear(); - UVConstants.clear(); + AggZeroConstants.freeConstants(); + NullPtrConstants.freeConstants(); + UndefValueConstants.freeConstants(); InlineAsms.freeConstants(); DeleteContainerSeconds(IntConstants); DeleteContainerSeconds(FPConstants); diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h index 9d8722b2722..30f9d469878 100644 --- a/lib/VMCore/LLVMContextImpl.h +++ b/lib/VMCore/LLVMContextImpl.h @@ -27,7 +27,6 @@ #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 @@ -139,8 +138,7 @@ public: // on Context destruction. SmallPtrSet NonUniquedMDNodes; - typedef DenseMap > CAZMapTy; - CAZMapTy CAZConstants; + ConstantUniqueMap AggZeroConstants; typedef ConstantUniqueMap, ArrayRef, ArrayType, ConstantArray, true /*largekey*/> ArrayConstantsTy; @@ -154,11 +152,9 @@ public: VectorType, ConstantVector> VectorConstantsTy; VectorConstantsTy VectorConstants; - typedef DenseMap > CPNMapTy; - CPNMapTy CPNConstants; - - typedef DenseMap > UVMapTy; - UVMapTy UVConstants; + ConstantUniqueMap + NullPtrConstants; + ConstantUniqueMap UndefValueConstants; DenseMap , BlockAddress*> BlockAddresses; ConstantUniqueMap