Skip to content

Commit 1cc4c87

Browse files
Revert "[NFCI][LTO][lld] Optimize away symbol copies within LTO global resolution in ELF" (#107788)
Reverts #106193 while investigating bot failures https://lab.llvm.org/buildbot/#/builders/169/builds/2989/steps/9/logs/stdio
1 parent 1c4b04c commit 1cc4c87

File tree

5 files changed

+6
-52
lines changed

5 files changed

+6
-52
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,10 +1804,6 @@ void BitcodeFile::parseLazy() {
18041804
auto *sym = symtab.insert(unique_saver().save(irSym.getName()));
18051805
sym->resolve(LazySymbol{*this});
18061806
symbols[i] = sym;
1807-
} else {
1808-
// Keep copies of per-module undefined symbols for LTO::GlobalResolutions
1809-
// usage.
1810-
unique_saver().save(irSym.getName());
18111807
}
18121808
}
18131809

lld/ELF/LTO.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ static lto::Config createConfig() {
135135
config->ltoValidateAllVtablesHaveTypeInfos;
136136
c.AllVtablesHaveTypeInfos = ctx.ltoAllVtablesHaveTypeInfos;
137137
c.AlwaysEmitRegularLTOObj = !config->ltoObjPath.empty();
138-
c.KeepSymbolNameCopies = false;
139138

140139
for (const llvm::StringRef &name : config->thinLTOModulesToCompile)
141140
c.ThinLTOModulesToCompile.emplace_back(name);

llvm/include/llvm/LTO/Config.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ struct Config {
8888
/// want to know a priori all possible output files.
8989
bool AlwaysEmitRegularLTOObj = false;
9090

91-
/// If true, the LTO instance creates copies of the symbol names for LTO::run.
92-
/// The lld linker uses string saver to keep symbol names alive and doesn't
93-
/// need to create copies, so it can set this field to false.
94-
bool KeepSymbolNameCopies = true;
95-
9691
/// Allows non-imported definitions to get the potentially more constraining
9792
/// visibility from the prevailing definition. FromPrevailing is the default
9893
/// because it works for many binary formats. ELF can use the more optimized

llvm/include/llvm/LTO/LTO.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
#ifndef LLVM_LTO_LTO_H
1616
#define LLVM_LTO_LTO_H
1717

18-
#include <memory>
19-
20-
#include "llvm/ADT/DenseMap.h"
2118
#include "llvm/ADT/MapVector.h"
2219
#include "llvm/ADT/StringMap.h"
2320
#include "llvm/Bitcode/BitcodeReader.h"
@@ -26,7 +23,6 @@
2623
#include "llvm/Object/IRSymtab.h"
2724
#include "llvm/Support/Caching.h"
2825
#include "llvm/Support/Error.h"
29-
#include "llvm/Support/StringSaver.h"
3026
#include "llvm/Support/thread.h"
3127
#include "llvm/Transforms/IPO/FunctionAttrs.h"
3228
#include "llvm/Transforms/IPO/FunctionImport.h"
@@ -407,19 +403,10 @@ class LTO {
407403
};
408404
};
409405

410-
// GlobalResolutionSymbolSaver allocator.
411-
std::unique_ptr<llvm::BumpPtrAllocator> Alloc;
412-
413-
// Symbol saver for global resolution map.
414-
std::unique_ptr<llvm::StringSaver> GlobalResolutionSymbolSaver;
415-
416406
// Global mapping from mangled symbol names to resolutions.
417-
// Make this an unique_ptr to guard against accessing after it has been reset
407+
// Make this an optional to guard against accessing after it has been reset
418408
// (to reduce memory after we're done with it).
419-
std::unique_ptr<llvm::DenseMap<StringRef, GlobalResolution>>
420-
GlobalResolutions;
421-
422-
void releaseGlobalResolutionsMemory();
409+
std::optional<StringMap<GlobalResolution>> GlobalResolutions;
423410

424411
void addModuleToGlobalRes(ArrayRef<InputFile::Symbol> Syms,
425412
ArrayRef<SymbolResolution> Res, unsigned Partition,

llvm/lib/LTO/LTO.cpp

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ cl::opt<bool> EnableLTOInternalization(
7777
"enable-lto-internalization", cl::init(true), cl::Hidden,
7878
cl::desc("Enable global value internalization in LTO"));
7979

80-
static cl::opt<bool>
81-
LTOKeepSymbolCopies("lto-keep-symbol-copies", cl::init(false), cl::Hidden,
82-
cl::desc("Keep copies of symbols in LTO indexing"));
83-
8480
/// Indicate we are linking with an allocator that supports hot/cold operator
8581
/// new interfaces.
8682
extern cl::opt<bool> SupportsHotColdNew;
@@ -591,14 +587,8 @@ LTO::LTO(Config Conf, ThinBackend Backend,
591587
: Conf(std::move(Conf)),
592588
RegularLTO(ParallelCodeGenParallelismLevel, this->Conf),
593589
ThinLTO(std::move(Backend)),
594-
GlobalResolutions(
595-
std::make_unique<DenseMap<StringRef, GlobalResolution>>()),
596-
LTOMode(LTOMode) {
597-
if (Conf.KeepSymbolNameCopies || LTOKeepSymbolCopies) {
598-
Alloc = std::make_unique<BumpPtrAllocator>();
599-
GlobalResolutionSymbolSaver = std::make_unique<llvm::StringSaver>(*Alloc);
600-
}
601-
}
590+
GlobalResolutions(std::make_optional<StringMap<GlobalResolution>>()),
591+
LTOMode(LTOMode) {}
602592

603593
// Requires a destructor for MapVector<BitcodeModule>.
604594
LTO::~LTO() = default;
@@ -616,12 +606,7 @@ void LTO::addModuleToGlobalRes(ArrayRef<InputFile::Symbol> Syms,
616606
assert(ResI != ResE);
617607
SymbolResolution Res = *ResI++;
618608

619-
StringRef SymbolName = Sym.getName();
620-
// Keep copies of symbols if the client of LTO says so.
621-
if (GlobalResolutionSymbolSaver && !GlobalResolutions->contains(SymbolName))
622-
SymbolName = GlobalResolutionSymbolSaver->save(SymbolName);
623-
624-
auto &GlobalRes = (*GlobalResolutions)[SymbolName];
609+
auto &GlobalRes = (*GlobalResolutions)[Sym.getName()];
625610
GlobalRes.UnnamedAddr &= Sym.isUnnamedAddr();
626611
if (Res.Prevailing) {
627612
assert(!GlobalRes.Prevailing &&
@@ -675,14 +660,6 @@ void LTO::addModuleToGlobalRes(ArrayRef<InputFile::Symbol> Syms,
675660
}
676661
}
677662

678-
void LTO::releaseGlobalResolutionsMemory() {
679-
// Release GlobalResolutions dense-map itself.
680-
GlobalResolutions.reset();
681-
// Release the string saver memory.
682-
GlobalResolutionSymbolSaver.reset();
683-
Alloc.reset();
684-
}
685-
686663
static void writeToResolutionFile(raw_ostream &OS, InputFile *Input,
687664
ArrayRef<SymbolResolution> Res) {
688665
StringRef Path = Input->getName();
@@ -1794,7 +1771,7 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
17941771
// are no further accesses. We specifically want to do this before computing
17951772
// cross module importing, which adds to peak memory via the computed import
17961773
// and export lists.
1797-
releaseGlobalResolutionsMemory();
1774+
GlobalResolutions.reset();
17981775

17991776
if (Conf.OptLevel > 0)
18001777
ComputeCrossModuleImport(ThinLTO.CombinedIndex, ModuleToDefinedGVSummaries,

0 commit comments

Comments
 (0)