Skip to content

Commit 95795ab

Browse files
authored
Linker: Remove dropTriviallyDeadConstantArrays().
By calling this function after every link, we introduce quadratic behavior during full LTO links that primarily affects links involving large numbers of constant arrays, such as the full LTO part of a ThinLTO link which will involve large numbers of vtable constants. Removing this call resulted in a 1.3x speedup in the indexing phase of a large internal Google binary. This call was originally introduced to reduce memory consumption during full LTO (see commit dab999d), but it doesn't seem to be the case that this helps any more. I ran 3 stage2 links of clang with full LTO and ThinLTO with and without this change and measured the max RSS. The results were as follows (all in KB): ``` FullLTO before 22362512 22383524 22387456 after 22383496 22365356 22364352 ThinLTO before 4391404 4478192 4383468 after 4399220 4363100 4417688 ``` As you can see, any max RSS differences are in the noise. Reviewers: nikic, teresajohnson Reviewed By: teresajohnson, nikic Pull Request: #137081
1 parent 9124e96 commit 95795ab

File tree

4 files changed

+1
-42
lines changed

4 files changed

+1
-42
lines changed

llvm/include/llvm/IR/Module.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -877,15 +877,6 @@ class LLVM_ABI Module {
877877
}
878878
/// @}
879879

880-
/// Destroy ConstantArrays in LLVMContext if they are not used.
881-
/// ConstantArrays constructed during linking can cause quadratic memory
882-
/// explosion. Releasing all unused constants can cause a 20% LTO compile-time
883-
/// slowdown for a large application.
884-
///
885-
/// NOTE: Constants are currently owned by LLVMContext. This can then only
886-
/// be called where all uses of the LLVMContext are understood.
887-
void dropTriviallyDeadConstantArrays();
888-
889880
/// @name Utility functions for printing and dumping Module objects
890881
/// @{
891882

llvm/lib/IR/LLVMContextImpl.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -147,33 +147,6 @@ LLVMContextImpl::~LLVMContextImpl() {
147147
delete Pair.second;
148148
}
149149

150-
void LLVMContextImpl::dropTriviallyDeadConstantArrays() {
151-
SmallSetVector<ConstantArray *, 4> WorkList;
152-
153-
// When ArrayConstants are of substantial size and only a few in them are
154-
// dead, starting WorkList with all elements of ArrayConstants can be
155-
// wasteful. Instead, starting WorkList with only elements that have empty
156-
// uses.
157-
for (ConstantArray *C : ArrayConstants)
158-
if (C->use_empty())
159-
WorkList.insert(C);
160-
161-
while (!WorkList.empty()) {
162-
ConstantArray *C = WorkList.pop_back_val();
163-
if (C->use_empty()) {
164-
for (const Use &Op : C->operands()) {
165-
if (auto *COp = dyn_cast<ConstantArray>(Op))
166-
WorkList.insert(COp);
167-
}
168-
C->destroyConstant();
169-
}
170-
}
171-
}
172-
173-
void Module::dropTriviallyDeadConstantArrays() {
174-
Context.pImpl->dropTriviallyDeadConstantArrays();
175-
}
176-
177150
namespace llvm {
178151

179152
/// Make MDOperand transparent for hashing.

llvm/lib/IR/LLVMContextImpl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,9 +1808,6 @@ class LLVMContextImpl {
18081808
LLVMContextImpl(LLVMContext &C);
18091809
~LLVMContextImpl();
18101810

1811-
/// Destroy the ConstantArrays if they are not used.
1812-
void dropTriviallyDeadConstantArrays();
1813-
18141811
mutable OptPassGate *OPG = nullptr;
18151812

18161813
/// Access the object which can disable optional passes and individual

llvm/lib/Linker/IRMover.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,5 @@ Error IRMover::move(std::unique_ptr<Module> Src,
17531753
IRLinker TheIRLinker(Composite, SharedMDs, IdentifiedStructTypes,
17541754
std::move(Src), ValuesToLink, std::move(AddLazyFor),
17551755
IsPerformingImport);
1756-
Error E = TheIRLinker.run();
1757-
Composite.dropTriviallyDeadConstantArrays();
1758-
return E;
1756+
return TheIRLinker.run();
17591757
}

0 commit comments

Comments
 (0)