[llvm] r225696 - IR: Stop erasing MDNodes from uniquing sets during teardown

Duncan P. N. Exon Smith dexonsmith at apple.com
Mon Jan 12 12:50:26 PST 2015


Author: dexonsmith
Date: Mon Jan 12 14:50:25 2015
New Revision: 225696

URL: http://llvm.org/viewvc/llvm-project?rev=225696&view=rev
Log:
IR: Stop erasing MDNodes from uniquing sets during teardown

Stop erasing `MDNode`s from the uniquing sets in `LLVMContextImpl`
during teardown (in particular, during
`UniquableMDNode::~UniquableMDNode()`).  Although it's currently
feasible, there isn't any clear benefit and it may not be feasible for
other subclasses (which don't explicitly store the lookup hash).

Modified:
    llvm/trunk/include/llvm/IR/Metadata.h
    llvm/trunk/lib/IR/LLVMContextImpl.cpp
    llvm/trunk/lib/IR/Metadata.cpp

Modified: llvm/trunk/include/llvm/IR/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Metadata.h?rev=225696&r1=225695&r2=225696&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Metadata.h (original)
+++ llvm/trunk/include/llvm/IR/Metadata.h Mon Jan 12 14:50:25 2015
@@ -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();

Modified: llvm/trunk/lib/IR/LLVMContextImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContextImpl.cpp?rev=225696&r1=225695&r2=225696&view=diff
==============================================================================
--- llvm/trunk/lib/IR/LLVMContextImpl.cpp (original)
+++ llvm/trunk/lib/IR/LLVMContextImpl.cpp Mon Jan 12 14:50:25 2015
@@ -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();

Modified: llvm/trunk/lib/IR/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Metadata.cpp?rev=225696&r1=225695&r2=225696&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Metadata.cpp (original)
+++ llvm/trunk/lib/IR/Metadata.cpp Mon Jan 12 14:50:25 2015
@@ -427,13 +427,6 @@ UniquableMDNode::UniquableMDNode(LLVMCon
   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





More information about the llvm-commits mailing list