summaryrefslogtreecommitdiff
path: root/lib/VMCore/Constants.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2012-01-23 08:42:38 +0000
committerChris Lattner <sabre@nondot.org>2012-01-23 08:42:38 +0000
commit2a82d82936729b02fe1bbdcbfe764a61b8999be1 (patch)
tree747863478da8a0d7e7987f58bfa2876c2e5cd0cb /lib/VMCore/Constants.cpp
parentcef39256986150d6e7d6d87ea36077452f045c50 (diff)
downloadllvm-2a82d82936729b02fe1bbdcbfe764a61b8999be1.tar.gz
llvm-2a82d82936729b02fe1bbdcbfe764a61b8999be1.tar.bz2
llvm-2a82d82936729b02fe1bbdcbfe764a61b8999be1.tar.xz
Replace a use of ConstantUniqueMap for CAZ constants with a simple DenseMap.
Now that the type system rewrite has landed, there is no need for its complexity and std::map'ness. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148691 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Constants.cpp')
-rw-r--r--lib/VMCore/Constants.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 9657cd28c1..d04298f149 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -993,18 +993,33 @@ 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!");
- LLVMContextImpl *pImpl = Ty->getContext().pImpl;
- return pImpl->AggZeroConstants.getOrCreate(Ty, 0);
+ OwningPtr<ConstantAggregateZero> &Entry =
+ Ty->getContext().pImpl->CAZConstants[Ty];
+ if (Entry == 0)
+ Entry.reset(new ConstantAggregateZero(Ty));
+
+ return Entry.get();
}
/// destroyConstant - Remove the constant from the constant table...
///
void ConstantAggregateZero::destroyConstant() {
- getType()->getContext().pImpl->AggZeroConstants.remove(this);
+ // 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.
destroyConstantImpl();
}