summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/IR/Metadata.h4
-rw-r--r--llvm/lib/IR/LLVMContextImpl.cpp18
-rw-r--r--llvm/lib/IR/Metadata.cpp12
3 files changed, 10 insertions, 24 deletions
diff --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h
index 1f327f6bdb3..cc193df4323 100644
--- a/llvm/include/llvm/IR/Metadata.h
+++ b/llvm/include/llvm/IR/Metadata.h
@@ -722,7 +722,7 @@ protected:
/// resolveCycles() is called).
UniquableMDNode(LLVMContext &C, unsigned ID, ArrayRef<Metadata *> Vals,
bool AllowRAUW);
- ~UniquableMDNode();
+ ~UniquableMDNode() {}
void storeDistinctInContext();
@@ -767,7 +767,7 @@ class MDTuple : public UniquableMDNode {
MDTuple(LLVMContext &C, ArrayRef<Metadata *> Vals, bool AllowRAUW)
: UniquableMDNode(C, MDTupleKind, Vals, AllowRAUW) {}
- ~MDTuple();
+ ~MDTuple() { dropAllReferences(); }
void setHash(unsigned Hash) { MDNodeSubclassData = Hash; }
void recalculateHash();
diff --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp
index a9268b46488..c78b76021da 100644
--- a/llvm/lib/IR/LLVMContextImpl.cpp
+++ b/llvm/lib/IR/LLVMContextImpl.cpp
@@ -135,18 +135,16 @@ LLVMContextImpl::~LLVMContextImpl() {
for (auto &Pair : ValuesAsMetadata)
delete Pair.second;
- // Destroy MDNodes. ~MDNode can move and remove nodes between the MDTuples
- // and the DistinctMDNodes sets, so copy the values out first.
- SmallVector<UniquableMDNode *, 8> Uniquables;
- Uniquables.reserve(MDTuples.size() + DistinctMDNodes.size());
- Uniquables.append(MDTuples.begin(), MDTuples.end());
- Uniquables.append(DistinctMDNodes.begin(), DistinctMDNodes.end());
- for (UniquableMDNode *I : Uniquables)
+ // Destroy MDNodes.
+ for (auto *I : DistinctMDNodes)
I->dropAllReferences();
- for (UniquableMDNode *I : Uniquables)
+ for (auto *I : MDTuples)
+ I->dropAllReferences();
+
+ for (UniquableMDNode *I : DistinctMDNodes)
delete cast<MDTuple>(I);
- assert(MDTuples.empty() && DistinctMDNodes.empty() &&
- "Destroying all MDNodes didn't empty the Context's sets.");
+ for (MDTuple *I : MDTuples)
+ delete I;
// Destroy MDStrings.
MDStringCache.clear();
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index 9088a75156e..fa1f302568f 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -427,13 +427,6 @@ UniquableMDNode::UniquableMDNode(LLVMContext &C, unsigned ID,
SubclassData32 = NumUnresolved;
}
-UniquableMDNode::~UniquableMDNode() {
- if (isStoredDistinctInContext())
- getContext().pImpl->DistinctMDNodes.erase(this);
-
- dropAllReferences();
-}
-
void UniquableMDNode::resolve() {
assert(!isResolved() && "Expected this to be unresolved");
@@ -481,11 +474,6 @@ void UniquableMDNode::resolveCycles() {
}
}
-MDTuple::~MDTuple() {
- if (!isStoredDistinctInContext())
- getContext().pImpl->MDTuples.erase(this);
-}
-
void MDTuple::recalculateHash() {
setHash(hash_combine_range(op_begin(), op_end()));
#ifndef NDEBUG
OpenPOWER on IntegriCloud