[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:
Manman Ren
2015-01-20 19:24:59 +00:00
parent 3a70d07f51
commit dab999d54f
4 changed files with 37 additions and 1 deletions

View File

@@ -1721,7 +1721,9 @@ void Linker::deleteModule() {
bool Linker::linkInModule(Module *Src) {
ModuleLinker TheLinker(Composite, IdentifiedStructTypes, Src,
DiagnosticHandler);
return TheLinker.run();
bool RetCode = TheLinker.run();
Composite->dropTriviallyDeadConstantArrays();
return RetCode;
}
//===----------------------------------------------------------------------===//