diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-14 21:58:17 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-14 21:58:17 +0000 |
commit | e16d58751510fe3eefa95d0fbb6ec5f2cc4bc63f (patch) | |
tree | 39a3bd4801e4f365f26c727f59d893725a1cf6ac /llvm/lib/IR/LLVMContextImpl.cpp | |
parent | e5f997e551f62cbaa88333259c4d8f0c9272207f (diff) | |
download | llvm-e16d58751510fe3eefa95d0fbb6ec5f2cc4bc63f.zip llvm-e16d58751510fe3eefa95d0fbb6ec5f2cc4bc63f.tar.gz llvm-e16d58751510fe3eefa95d0fbb6ec5f2cc4bc63f.tar.bz2 |
IR: Drop metadata references more aggressively during teardown
Sometimes teardown happens before the debug info graph is complete
(e.g., when clang throws an error). In that case, `MDNode`s will still
have RAUW, so deleting constants that the `MDNode`s point at will be
relatively expensive -- it'll cause re-uniquing all up the chain (what
I've been referring to as "teardown madness").
So, drop references *before* deleting constants. We need to drop a few
more references now: the metadata side of the metadata/value bridges
needs to be dropped off the cliff along with the rest of it (previously,
the bridges were cleaned before we did anything with the `MDNode`s).
There's no real functionality change here -- state before and after
`LLVMContextImpl::~LLVMContextImpl()` is unchanged -- so no testcase.
llvm-svn: 226044
Diffstat (limited to 'llvm/lib/IR/LLVMContextImpl.cpp')
-rw-r--r-- | llvm/lib/IR/LLVMContextImpl.cpp | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp index 1fa080b..01a0e6c 100644 --- a/llvm/lib/IR/LLVMContextImpl.cpp +++ b/llvm/lib/IR/LLVMContextImpl.cpp @@ -72,7 +72,30 @@ LLVMContextImpl::~LLVMContextImpl() { // the container. Avoid iterators during this operation: while (!OwnedModules.empty()) delete *OwnedModules.begin(); - + + // Drop references for MDNodes. Do this before Values get deleted to avoid + // unnecessary RAUW when nodes are still unresolved. + for (auto *I : DistinctMDNodes) + I->dropAllReferences(); + for (auto *I : MDTuples) + I->dropAllReferences(); + for (auto *I : MDLocations) + I->dropAllReferences(); + + // Also drop references that come from the Value bridges. + for (auto &Pair : ValuesAsMetadata) + Pair.second->dropUsers(); + for (auto &Pair : MetadataAsValues) + Pair.second->dropUse(); + + // Destroy MDNodes. + for (UniquableMDNode *I : DistinctMDNodes) + I->deleteAsSubclass(); + for (MDTuple *I : MDTuples) + delete I; + for (MDLocation *I : MDLocations) + delete I; + // 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(), @@ -135,21 +158,6 @@ LLVMContextImpl::~LLVMContextImpl() { for (auto &Pair : ValuesAsMetadata) delete Pair.second; - // Destroy MDNodes. - for (auto *I : DistinctMDNodes) - I->dropAllReferences(); - for (auto *I : MDTuples) - I->dropAllReferences(); - for (auto *I : MDLocations) - I->dropAllReferences(); - - for (UniquableMDNode *I : DistinctMDNodes) - I->deleteAsSubclass(); - for (MDTuple *I : MDTuples) - delete I; - for (MDLocation *I : MDLocations) - delete I; - // Destroy MDStrings. MDStringCache.clear(); } |