[llvm-branch-commits] [llvm-branch] r226091 - Merging r226044:
Duncan P. N. Exon Smith
dexonsmith at apple.com
Wed Jan 14 19:59:09 PST 2015
Author: dexonsmith
Date: Wed Jan 14 21:59:09 2015
New Revision: 226091
URL: http://llvm.org/viewvc/llvm-project?rev=226091&view=rev
Log:
Merging r226044:
------------------------------------------------------------------------
r226044 | dexonsmith | 2015-01-14 13:58:17 -0800 (Wed, 14 Jan 2015) | 15 lines
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.
------------------------------------------------------------------------
Modified:
llvm/branches/release_36/ (props changed)
llvm/branches/release_36/include/llvm/IR/Metadata.h
llvm/branches/release_36/lib/IR/LLVMContextImpl.cpp
Propchange: llvm/branches/release_36/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jan 14 21:59:09 2015
@@ -1,3 +1,3 @@
/llvm/branches/Apple/Pertwee:110850,110961
/llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,226023,226029
+/llvm/trunk:155241,226023,226029,226044
Modified: llvm/branches/release_36/include/llvm/IR/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_36/include/llvm/IR/Metadata.h?rev=226091&r1=226090&r2=226091&view=diff
==============================================================================
--- llvm/branches/release_36/include/llvm/IR/Metadata.h (original)
+++ llvm/branches/release_36/include/llvm/IR/Metadata.h Wed Jan 14 21:59:09 2015
@@ -115,6 +115,9 @@ class MetadataAsValue : public Value {
MetadataAsValue(Type *Ty, Metadata *MD);
~MetadataAsValue();
+ /// \brief Drop use of metadata (during teardown).
+ void dropUse() { MD = nullptr; }
+
public:
static MetadataAsValue *get(LLVMContext &Context, Metadata *MD);
static MetadataAsValue *getIfExists(LLVMContext &Context, Metadata *MD);
@@ -185,6 +188,11 @@ class ValueAsMetadata : public Metadata,
Value *V;
+ /// \brief Drop users without RAUW (during teardown).
+ void dropUsers() {
+ ReplaceableMetadataImpl::resolveAllUses(/* ResolveUsers */ false);
+ }
+
protected:
ValueAsMetadata(unsigned ID, Value *V)
: Metadata(ID), V(V) {
Modified: llvm/branches/release_36/lib/IR/LLVMContextImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_36/lib/IR/LLVMContextImpl.cpp?rev=226091&r1=226090&r2=226091&view=diff
==============================================================================
--- llvm/branches/release_36/lib/IR/LLVMContextImpl.cpp (original)
+++ llvm/branches/release_36/lib/IR/LLVMContextImpl.cpp Wed Jan 14 21:59:09 2015
@@ -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();
}
More information about the llvm-branch-commits
mailing list