[llvm-commits] [llvm] r78651 - in /llvm/trunk: include/llvm/LLVMContext.h lib/Transforms/IPO/GlobalDCE.cpp lib/VMCore/ConstantsContext.h lib/VMCore/LLVMContext.cpp lib/VMCore/LLVMContextImpl.h

Devang Patel dpatel at apple.com
Mon Aug 10 23:31:59 PDT 2009


Author: dpatel
Date: Tue Aug 11 01:31:57 2009
New Revision: 78651

URL: http://llvm.org/viewvc/llvm-project?rev=78651&view=rev
Log:
Remove dead metadata.

Modified:
    llvm/trunk/include/llvm/LLVMContext.h
    llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp
    llvm/trunk/lib/VMCore/ConstantsContext.h
    llvm/trunk/lib/VMCore/LLVMContext.cpp
    llvm/trunk/lib/VMCore/LLVMContextImpl.h

Modified: llvm/trunk/include/llvm/LLVMContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LLVMContext.h?rev=78651&r1=78650&r2=78651&view=diff

==============================================================================
--- llvm/trunk/include/llvm/LLVMContext.h (original)
+++ llvm/trunk/include/llvm/LLVMContext.h Tue Aug 11 01:31:57 2009
@@ -30,7 +30,7 @@
 /// to have one context per thread.
 struct LLVMContext {
   LLVMContextImpl* pImpl;
-  
+  bool RemoveDeadMetadata();
   LLVMContext();
   ~LLVMContext();
 };

Modified: llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp?rev=78651&r1=78650&r2=78651&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp Tue Aug 11 01:31:57 2009
@@ -148,6 +148,9 @@
 
   // Make sure that all memory is released
   AliveGlobals.clear();
+
+  // Remove dead metadata.
+  Changed |= M.getContext().RemoveDeadMetadata();
   return Changed;
 }
 

Modified: llvm/trunk/lib/VMCore/ConstantsContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ConstantsContext.h?rev=78651&r1=78650&r2=78651&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/ConstantsContext.h (original)
+++ llvm/trunk/lib/VMCore/ConstantsContext.h Tue Aug 11 01:31:57 2009
@@ -572,6 +572,7 @@
 public:
   // NOTE: This function is not locked.  It is the caller's responsibility
   // to enforce proper synchronization.
+  typename MapTy::iterator map_begin() { return Map.begin(); }
   typename MapTy::iterator map_end() { return Map.end(); }
     
   /// InsertOrGetItem - Return an iterator for the specified element.

Modified: llvm/trunk/lib/VMCore/LLVMContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContext.cpp?rev=78651&r1=78650&r2=78651&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContext.cpp (original)
+++ llvm/trunk/lib/VMCore/LLVMContext.cpp Tue Aug 11 01:31:57 2009
@@ -20,6 +20,7 @@
 #include "llvm/Support/ManagedStatic.h"
 #include "LLVMContextImpl.h"
 #include <cstdarg>
+#include <set>
 
 using namespace llvm;
 
@@ -44,3 +45,27 @@
   for (unsigned i = 0, E = IdxList.size(); i != E; ++i)
     OperandList[i+1] = IdxList[i];
 }
+
+bool LLVMContext::RemoveDeadMetadata() {
+  std::vector<const MDNode *> DeadMDNodes;
+  bool Changed = false;
+  while (1) {
+
+    for (LLVMContextImpl::MDNodeMapTy::MapTy::iterator
+           I = pImpl->MDNodes.map_begin(),
+           E = pImpl->MDNodes.map_end(); I != E; ++I) {
+      const MDNode *N = cast<MDNode>(I->second);
+      if (N->use_empty()) 
+        DeadMDNodes.push_back(N);
+    }
+    
+    if (DeadMDNodes.empty())
+      return Changed;
+
+    while (!DeadMDNodes.empty()) {
+      const MDNode *N = DeadMDNodes.back(); DeadMDNodes.pop_back();
+      delete N;
+    }
+  }
+  return Changed;
+}

Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.h?rev=78651&r1=78650&r2=78651&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.h (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.h Tue Aug 11 01:31:57 2009
@@ -105,7 +105,10 @@
   
   ValueMap<char, Type, ConstantAggregateZero> AggZeroConstants;
 
-  ValueMap<std::vector<Value*>, Type, MDNode, true /*largekey*/> MDNodes;
+  typedef ValueMap<std::vector<Value*>, Type, MDNode, true /*largekey*/> 
+  MDNodeMapTy;
+
+  MDNodeMapTy MDNodes;
   
   typedef ValueMap<std::vector<Constant*>, ArrayType, 
     ConstantArray, true /*largekey*/> ArrayConstantsTy;





More information about the llvm-commits mailing list