diff options
author | Chris Lattner <sabre@nondot.org> | 2012-01-23 08:52:32 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2012-01-23 08:52:32 +0000 |
commit | 3755615411713b2b27b1b2ffd3886584295843d1 (patch) | |
tree | ca55634b6aa11c5ef0b9579f2e1f808c10f58794 /lib/VMCore | |
parent | 300a263d93ba4bb320ae303ca5a388dc9800b112 (diff) | |
download | external_llvm-3755615411713b2b27b1b2ffd3886584295843d1.zip external_llvm-3755615411713b2b27b1b2ffd3886584295843d1.tar.gz external_llvm-3755615411713b2b27b1b2ffd3886584295843d1.tar.bz2 |
switch UndefValue and ConstantPointerNull over to DenseMap's for uniquing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148693 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Constants.cpp | 39 | ||||
-rw-r--r-- | lib/VMCore/ConstantsContext.h | 31 | ||||
-rw-r--r-- | lib/VMCore/LLVMContextImpl.cpp | 6 | ||||
-rw-r--r-- | lib/VMCore/LLVMContextImpl.h | 8 |
4 files changed, 44 insertions, 40 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index d04298f..f2d8794 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -1127,13 +1127,29 @@ Constant *ConstantVector::getSplatValue() const { // ConstantPointerNull *ConstantPointerNull::get(PointerType *Ty) { - return Ty->getContext().pImpl->NullPtrConstants.getOrCreate(Ty, 0); + OwningPtr<ConstantPointerNull> &Entry = + Ty->getContext().pImpl->CPNConstants[Ty]; + if (Entry == 0) + Entry.reset(new ConstantPointerNull(Ty)); + + return Entry.get(); } // destroyConstant - Remove the constant from the constant table... // void ConstantPointerNull::destroyConstant() { - getType()->getContext().pImpl->NullPtrConstants.remove(this); + // 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. destroyConstantImpl(); } @@ -1142,13 +1158,28 @@ void ConstantPointerNull::destroyConstant() { // UndefValue *UndefValue::get(Type *Ty) { - return Ty->getContext().pImpl->UndefValueConstants.getOrCreate(Ty, 0); + OwningPtr<UndefValue> &Entry = Ty->getContext().pImpl->UVConstants[Ty]; + if (Entry == 0) + Entry.reset(new UndefValue(Ty)); + + return Entry.get(); } // destroyConstant - Remove the constant from the constant table. // void UndefValue::destroyConstant() { - getType()->getContext().pImpl->UndefValueConstants.remove(this); + // 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. destroyConstantImpl(); } diff --git a/lib/VMCore/ConstantsContext.h b/lib/VMCore/ConstantsContext.h index fec2be5..4bdeaa7 100644 --- a/lib/VMCore/ConstantsContext.h +++ b/lib/VMCore/ConstantsContext.h @@ -514,37 +514,6 @@ struct ConstantKeyData<ConstantStruct> { } }; -// ConstantPointerNull does not take extra "value" argument... -template<class ValType> -struct ConstantCreator<ConstantPointerNull, PointerType, ValType> { - static ConstantPointerNull *create(PointerType *Ty, const ValType &V){ - return new ConstantPointerNull(Ty); - } -}; - -template<> -struct ConstantKeyData<ConstantPointerNull> { - typedef char ValType; - static ValType getValType(ConstantPointerNull *C) { - return 0; - } -}; - -// UndefValue does not take extra "value" argument... -template<class ValType> -struct ConstantCreator<UndefValue, Type, ValType> { - static UndefValue *create(Type *Ty, const ValType &V) { - return new UndefValue(Ty); - } -}; - -template<> -struct ConstantKeyData<UndefValue> { - typedef char ValType; - static ValType getValType(UndefValue *C) { - return 0; - } -}; template<> struct ConstantCreator<InlineAsm, PointerType, InlineAsmKeyType> { diff --git a/lib/VMCore/LLVMContextImpl.cpp b/lib/VMCore/LLVMContextImpl.cpp index 7ab3cce..de851ee 100644 --- a/lib/VMCore/LLVMContextImpl.cpp +++ b/lib/VMCore/LLVMContextImpl.cpp @@ -58,6 +58,8 @@ LLVMContextImpl::~LLVMContextImpl() { std::vector<Module*> 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(), @@ -71,8 +73,8 @@ LLVMContextImpl::~LLVMContextImpl() { StructConstants.freeConstants(); VectorConstants.freeConstants(); CAZConstants.clear(); - NullPtrConstants.freeConstants(); - UndefValueConstants.freeConstants(); + CPNConstants.clear(); + UVConstants.clear(); InlineAsms.freeConstants(); DeleteContainerSeconds(IntConstants); DeleteContainerSeconds(FPConstants); diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h index f963f63..9d8722b 100644 --- a/lib/VMCore/LLVMContextImpl.h +++ b/lib/VMCore/LLVMContextImpl.h @@ -154,9 +154,11 @@ public: VectorType, ConstantVector> VectorConstantsTy; VectorConstantsTy VectorConstants; - ConstantUniqueMap<char, char, PointerType, ConstantPointerNull> - NullPtrConstants; - ConstantUniqueMap<char, char, Type, UndefValue> UndefValueConstants; + typedef DenseMap<PointerType*, OwningPtr<ConstantPointerNull> > CPNMapTy; + CPNMapTy CPNConstants; + + typedef DenseMap<Type*, OwningPtr<UndefValue> > UVMapTy; + UVMapTy UVConstants; DenseMap<std::pair<Function*, BasicBlock*> , BlockAddress*> BlockAddresses; ConstantUniqueMap<ExprMapKeyType, const ExprMapKeyType&, Type, ConstantExpr> |