forked from OSchip/llvm-project
[llvm link] Destroy ConstantArrays in LLVMContext if they are not used.
ConstantArrays constructed during linking can cause quadratic memory explosion. An example is the ConstantArrays constructed when linking in GlobalVariables with appending linkage. Releasing all unused constants can cause a 20% LTO compile-time slowdown for a large application. So this commit releases unused ConstantArrays only. rdar://19040716. It reduces memory footprint from 20+G to 6+G. llvm-svn: 226592
This commit is contained in:
parent
3a70d07f51
commit
dab999d54f
|
@ -630,6 +630,15 @@ public:
|
||||||
named_metadata_end());
|
named_metadata_end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Destroy ConstantArrays in LLVMContext if they are not used.
|
||||||
|
/// ConstantArrays constructed during linking can cause quadratic memory
|
||||||
|
/// explosion. Releasing all unused constants can cause a 20% LTO compile-time
|
||||||
|
/// slowdown for a large application.
|
||||||
|
///
|
||||||
|
/// NOTE: Constants are currently owned by LLVMContext. This can then only
|
||||||
|
/// be called where all uses of the LLVMContext are understood.
|
||||||
|
void dropTriviallyDeadConstantArrays();
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
/// @name Utility functions for printing and dumping Module objects
|
/// @name Utility functions for printing and dumping Module objects
|
||||||
/// @{
|
/// @{
|
||||||
|
|
|
@ -163,6 +163,28 @@ LLVMContextImpl::~LLVMContextImpl() {
|
||||||
MDStringCache.clear();
|
MDStringCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LLVMContextImpl::dropTriviallyDeadConstantArrays() {
|
||||||
|
bool Changed;
|
||||||
|
do {
|
||||||
|
Changed = false;
|
||||||
|
|
||||||
|
for (auto I = ArrayConstants.map_begin(), E = ArrayConstants.map_end();
|
||||||
|
I != E; ) {
|
||||||
|
auto *C = I->first;
|
||||||
|
I++;
|
||||||
|
if (C->use_empty()) {
|
||||||
|
Changed = true;
|
||||||
|
C->destroyConstant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (Changed);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Module::dropTriviallyDeadConstantArrays() {
|
||||||
|
Context.pImpl->dropTriviallyDeadConstantArrays();
|
||||||
|
}
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
/// \brief Make MDOperand transparent for hashing.
|
/// \brief Make MDOperand transparent for hashing.
|
||||||
///
|
///
|
||||||
|
|
|
@ -474,6 +474,9 @@ public:
|
||||||
|
|
||||||
LLVMContextImpl(LLVMContext &C);
|
LLVMContextImpl(LLVMContext &C);
|
||||||
~LLVMContextImpl();
|
~LLVMContextImpl();
|
||||||
|
|
||||||
|
/// Destroy the ConstantArrays if they are not used.
|
||||||
|
void dropTriviallyDeadConstantArrays();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1721,7 +1721,9 @@ void Linker::deleteModule() {
|
||||||
bool Linker::linkInModule(Module *Src) {
|
bool Linker::linkInModule(Module *Src) {
|
||||||
ModuleLinker TheLinker(Composite, IdentifiedStructTypes, Src,
|
ModuleLinker TheLinker(Composite, IdentifiedStructTypes, Src,
|
||||||
DiagnosticHandler);
|
DiagnosticHandler);
|
||||||
return TheLinker.run();
|
bool RetCode = TheLinker.run();
|
||||||
|
Composite->dropTriviallyDeadConstantArrays();
|
||||||
|
return RetCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
Loading…
Reference in New Issue