Skip to content

Linker: Remove dropTriviallyDeadConstantArrays(). #137081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions llvm/include/llvm/IR/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -877,15 +877,6 @@ class LLVM_ABI Module {
}
/// @}

/// 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
/// @{

Expand Down
27 changes: 0 additions & 27 deletions llvm/lib/IR/LLVMContextImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,33 +147,6 @@ LLVMContextImpl::~LLVMContextImpl() {
delete Pair.second;
}

void LLVMContextImpl::dropTriviallyDeadConstantArrays() {
SmallSetVector<ConstantArray *, 4> WorkList;

// When ArrayConstants are of substantial size and only a few in them are
// dead, starting WorkList with all elements of ArrayConstants can be
// wasteful. Instead, starting WorkList with only elements that have empty
// uses.
for (ConstantArray *C : ArrayConstants)
if (C->use_empty())
WorkList.insert(C);

while (!WorkList.empty()) {
ConstantArray *C = WorkList.pop_back_val();
if (C->use_empty()) {
for (const Use &Op : C->operands()) {
if (auto *COp = dyn_cast<ConstantArray>(Op))
WorkList.insert(COp);
}
C->destroyConstant();
}
}
}

void Module::dropTriviallyDeadConstantArrays() {
Context.pImpl->dropTriviallyDeadConstantArrays();
}

namespace llvm {

/// Make MDOperand transparent for hashing.
Expand Down
3 changes: 0 additions & 3 deletions llvm/lib/IR/LLVMContextImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1808,9 +1808,6 @@ class LLVMContextImpl {
LLVMContextImpl(LLVMContext &C);
~LLVMContextImpl();

/// Destroy the ConstantArrays if they are not used.
void dropTriviallyDeadConstantArrays();

mutable OptPassGate *OPG = nullptr;

/// Access the object which can disable optional passes and individual
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/Linker/IRMover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,5 @@ Error IRMover::move(std::unique_ptr<Module> Src,
IRLinker TheIRLinker(Composite, SharedMDs, IdentifiedStructTypes,
std::move(Src), ValuesToLink, std::move(AddLazyFor),
IsPerformingImport);
Error E = TheIRLinker.run();
Composite.dropTriviallyDeadConstantArrays();
return E;
return TheIRLinker.run();
}
Loading