From dab999d54f39af3ebb6a23e850dbc9742016fac8 Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Tue, 20 Jan 2015 19:24:59 +0000 Subject: [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 --- llvm/lib/IR/LLVMContextImpl.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'llvm/lib/IR/LLVMContextImpl.cpp') 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. /// -- cgit v1.1