aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorManman Ren <manman.ren@gmail.com>2015-01-20 19:24:59 +0000
committerManman Ren <manman.ren@gmail.com>2015-01-20 19:24:59 +0000
commitdab999d54f39af3ebb6a23e850dbc9742016fac8 (patch)
tree36a67ed7114bc57ab553f0436406dd61cad880e9 /llvm/lib
parent3a70d07f5178086c589c67dffcf649c635e35972 (diff)
downloadllvm-dab999d54f39af3ebb6a23e850dbc9742016fac8.zip
llvm-dab999d54f39af3ebb6a23e850dbc9742016fac8.tar.gz
llvm-dab999d54f39af3ebb6a23e850dbc9742016fac8.tar.bz2
[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
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/IR/LLVMContextImpl.cpp22
-rw-r--r--llvm/lib/IR/LLVMContextImpl.h3
-rw-r--r--llvm/lib/Linker/LinkModules.cpp4
3 files changed, 28 insertions, 1 deletions
diff --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp
index aa7242a..880e1c1 100644
--- a/llvm/lib/IR/LLVMContextImpl.cpp
+++ b/llvm/lib/IR/LLVMContextImpl.cpp
@@ -163,6 +163,28 @@ LLVMContextImpl::~LLVMContextImpl() {
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 {
/// \brief Make MDOperand transparent for hashing.
///
diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h
index 4604d9b..3b3be0f 100644
--- a/llvm/lib/IR/LLVMContextImpl.h
+++ b/llvm/lib/IR/LLVMContextImpl.h
@@ -474,6 +474,9 @@ public:
LLVMContextImpl(LLVMContext &C);
~LLVMContextImpl();
+
+ /// Destroy the ConstantArrays if they are not used.
+ void dropTriviallyDeadConstantArrays();
};
}
diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp
index 767d465..dc002d8 100644
--- a/llvm/lib/Linker/LinkModules.cpp
+++ b/llvm/lib/Linker/LinkModules.cpp
@@ -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;
}
//===----------------------------------------------------------------------===//