forked from OSchip/llvm-project
parent
b39a5aa794
commit
c5aa8c6d29
|
@ -30,7 +30,7 @@ struct LLVMContextImpl;
|
||||||
/// to have one context per thread.
|
/// to have one context per thread.
|
||||||
struct LLVMContext {
|
struct LLVMContext {
|
||||||
LLVMContextImpl* pImpl;
|
LLVMContextImpl* pImpl;
|
||||||
|
bool RemoveDeadMetadata();
|
||||||
LLVMContext();
|
LLVMContext();
|
||||||
~LLVMContext();
|
~LLVMContext();
|
||||||
};
|
};
|
||||||
|
|
|
@ -148,6 +148,9 @@ bool GlobalDCE::runOnModule(Module &M) {
|
||||||
|
|
||||||
// Make sure that all memory is released
|
// Make sure that all memory is released
|
||||||
AliveGlobals.clear();
|
AliveGlobals.clear();
|
||||||
|
|
||||||
|
// Remove dead metadata.
|
||||||
|
Changed |= M.getContext().RemoveDeadMetadata();
|
||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -572,6 +572,7 @@ private:
|
||||||
public:
|
public:
|
||||||
// NOTE: This function is not locked. It is the caller's responsibility
|
// NOTE: This function is not locked. It is the caller's responsibility
|
||||||
// to enforce proper synchronization.
|
// to enforce proper synchronization.
|
||||||
|
typename MapTy::iterator map_begin() { return Map.begin(); }
|
||||||
typename MapTy::iterator map_end() { return Map.end(); }
|
typename MapTy::iterator map_end() { return Map.end(); }
|
||||||
|
|
||||||
/// InsertOrGetItem - Return an iterator for the specified element.
|
/// InsertOrGetItem - Return an iterator for the specified element.
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "llvm/Support/ManagedStatic.h"
|
#include "llvm/Support/ManagedStatic.h"
|
||||||
#include "LLVMContextImpl.h"
|
#include "LLVMContextImpl.h"
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
|
@ -44,3 +45,27 @@ GetElementPtrConstantExpr::GetElementPtrConstantExpr
|
||||||
for (unsigned i = 0, E = IdxList.size(); i != E; ++i)
|
for (unsigned i = 0, E = IdxList.size(); i != E; ++i)
|
||||||
OperandList[i+1] = IdxList[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;
|
||||||
|
}
|
||||||
|
|
|
@ -105,7 +105,10 @@ struct LLVMContextImpl {
|
||||||
|
|
||||||
ValueMap<char, Type, ConstantAggregateZero> AggZeroConstants;
|
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,
|
typedef ValueMap<std::vector<Constant*>, ArrayType,
|
||||||
ConstantArray, true /*largekey*/> ArrayConstantsTy;
|
ConstantArray, true /*largekey*/> ArrayConstantsTy;
|
||||||
|
|
Loading…
Reference in New Issue