switch UndefValue and ConstantPointerNull over to DenseMap's for uniquing.
llvm-svn: 148693
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp
index d04298f..f2d8794 100644
--- a/llvm/lib/VMCore/Constants.cpp
+++ b/llvm/lib/VMCore/Constants.cpp
@@ -1127,13 +1127,29 @@
//
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 @@
//
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();
}