summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2009-08-11 06:31:57 +0000
committerDevang Patel <dpatel@apple.com>2009-08-11 06:31:57 +0000
commit9d3627ea27195534242ec8026a9b8c888b85bbba (patch)
treecfbc47e0f4462daf0716deab7ac4b906dcd905a9
parent8c54a620618a77f18af4bb5a0fb48dc741044b91 (diff)
downloadllvm-9d3627ea27195534242ec8026a9b8c888b85bbba.tar.gz
llvm-9d3627ea27195534242ec8026a9b8c888b85bbba.tar.bz2
llvm-9d3627ea27195534242ec8026a9b8c888b85bbba.tar.xz
Remove dead metadata.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78651 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/LLVMContext.h2
-rw-r--r--lib/Transforms/IPO/GlobalDCE.cpp3
-rw-r--r--lib/VMCore/ConstantsContext.h1
-rw-r--r--lib/VMCore/LLVMContext.cpp25
-rw-r--r--lib/VMCore/LLVMContextImpl.h5
5 files changed, 34 insertions, 2 deletions
diff --git a/include/llvm/LLVMContext.h b/include/llvm/LLVMContext.h
index f5916c47a0..d74fa11f3f 100644
--- a/include/llvm/LLVMContext.h
+++ b/include/llvm/LLVMContext.h
@@ -30,7 +30,7 @@ struct LLVMContextImpl;
/// to have one context per thread.
struct LLVMContext {
LLVMContextImpl* pImpl;
-
+ bool RemoveDeadMetadata();
LLVMContext();
~LLVMContext();
};
diff --git a/lib/Transforms/IPO/GlobalDCE.cpp b/lib/Transforms/IPO/GlobalDCE.cpp
index 8e57768570..09f9e7c4f6 100644
--- a/lib/Transforms/IPO/GlobalDCE.cpp
+++ b/lib/Transforms/IPO/GlobalDCE.cpp
@@ -148,6 +148,9 @@ bool GlobalDCE::runOnModule(Module &M) {
// Make sure that all memory is released
AliveGlobals.clear();
+
+ // Remove dead metadata.
+ Changed |= M.getContext().RemoveDeadMetadata();
return Changed;
}
diff --git a/lib/VMCore/ConstantsContext.h b/lib/VMCore/ConstantsContext.h
index 2868f87fa4..f1d4b25e1b 100644
--- a/lib/VMCore/ConstantsContext.h
+++ b/lib/VMCore/ConstantsContext.h
@@ -572,6 +572,7 @@ private:
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.
diff --git a/lib/VMCore/LLVMContext.cpp b/lib/VMCore/LLVMContext.cpp
index 22882711a0..3ca1b0afca 100644
--- a/lib/VMCore/LLVMContext.cpp
+++ b/lib/VMCore/LLVMContext.cpp
@@ -20,6 +20,7 @@
#include "llvm/Support/ManagedStatic.h"
#include "LLVMContextImpl.h"
#include <cstdarg>
+#include <set>
using namespace llvm;
@@ -44,3 +45,27 @@ GetElementPtrConstantExpr::GetElementPtrConstantExpr
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;
+}
diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h
index 3d1f3b26a5..245aa4a704 100644
--- a/lib/VMCore/LLVMContextImpl.h
+++ b/lib/VMCore/LLVMContextImpl.h
@@ -105,7 +105,10 @@ struct LLVMContextImpl {
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;