summaryrefslogtreecommitdiff
path: root/lib/VMCore/Constants.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2012-01-23 08:52:32 +0000
committerChris Lattner <sabre@nondot.org>2012-01-23 08:52:32 +0000
commit3755615411713b2b27b1b2ffd3886584295843d1 (patch)
treeca55634b6aa11c5ef0b9579f2e1f808c10f58794 /lib/VMCore/Constants.cpp
parent300a263d93ba4bb320ae303ca5a388dc9800b112 (diff)
downloadllvm-3755615411713b2b27b1b2ffd3886584295843d1.tar.gz
llvm-3755615411713b2b27b1b2ffd3886584295843d1.tar.bz2
llvm-3755615411713b2b27b1b2ffd3886584295843d1.tar.xz
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/Constants.cpp')
-rw-r--r--lib/VMCore/Constants.cpp39
1 files changed, 35 insertions, 4 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index d04298f149..f2d8794284 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();
}