diff options
author | Devang Patel <dpatel@apple.com> | 2009-08-11 06:31:57 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2009-08-11 06:31:57 +0000 |
commit | 9d3627ea27195534242ec8026a9b8c888b85bbba (patch) | |
tree | cfbc47e0f4462daf0716deab7ac4b906dcd905a9 /lib/VMCore/LLVMContext.cpp | |
parent | 8c54a620618a77f18af4bb5a0fb48dc741044b91 (diff) |
Remove dead metadata.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78651 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/LLVMContext.cpp')
-rw-r--r-- | lib/VMCore/LLVMContext.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
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; +} |