diff options
author | Jeffrey Yasskin <jyasskin@google.com> | 2010-03-07 18:46:57 +0000 |
---|---|---|
committer | Jeffrey Yasskin <jyasskin@google.com> | 2010-03-07 18:46:57 +0000 |
commit | 92ce42f9fc8758ff83da3ebf7cd0a60bdaec3c58 (patch) | |
tree | 236a928be7dc781322bd7e10bf5551bf452737b5 /lib/VMCore/LLVMContextImpl.h | |
parent | 9467f0e3bd2b0fece0d50a6d92f996b4f3952096 (diff) |
Reapply r97788 to free MDNodes when the LLVMContext is destroyed. It
bootstraps llvm-gcc this time.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97918 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/LLVMContextImpl.h')
-rw-r--r-- | lib/VMCore/LLVMContextImpl.h | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h index 9887f28821..9978f40ed0 100644 --- a/lib/VMCore/LLVMContextImpl.h +++ b/lib/VMCore/LLVMContextImpl.h @@ -105,6 +105,11 @@ public: StringMap<MDString*> MDStringCache; FoldingSet<MDNode> MDNodeSet; + // MDNodes may be uniqued or not uniqued. When they're not uniqued, they + // aren't in the MDNodeSet, but they're still shared between objects, so no + // one object can destroy them. This set allows us to at least destroy them + // on Context destruction. + SmallPtrSet<MDNode*, 1> NonUniquedMDNodes; ConstantUniqueMap<char, Type, ConstantAggregateZero> AggZeroConstants; @@ -235,17 +240,21 @@ public: (*I)->AbstractTypeUsers.clear(); delete *I; } - // Destroy MDNode operands first. + // Destroy MDNodes. ~MDNode can move and remove nodes between the MDNodeSet + // and the NonUniquedMDNodes sets, so copy the values out first. + SmallVector<MDNode*, 8> MDNodes; + MDNodes.reserve(MDNodeSet.size() + NonUniquedMDNodes.size()); for (FoldingSetIterator<MDNode> I = MDNodeSet.begin(), E = MDNodeSet.end(); - I != E;) { - MDNode *N = &(*I); - ++I; - N->replaceAllOperandsWithNull(); + I != E; ++I) { + MDNodes.push_back(&*I); } - while (!MDNodeSet.empty()) { - MDNode *N = &(*MDNodeSet.begin()); - N->destroy(); + MDNodes.append(NonUniquedMDNodes.begin(), NonUniquedMDNodes.end()); + for (SmallVector<MDNode*, 8>::iterator I = MDNodes.begin(), + E = MDNodes.end(); I != E; ++I) { + (*I)->destroy(); } + assert(MDNodeSet.empty() && NonUniquedMDNodes.empty() && + "Destroying all MDNodes didn't empty the Context's sets."); // Destroy MDStrings. for (StringMap<MDString*>::iterator I = MDStringCache.begin(), E = MDStringCache.end(); I != E; ++I) { |