aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/LTO/LTO.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/LTO/LTO.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/LTO/LTO.cpp36
1 files changed, 23 insertions, 13 deletions
diff --git a/contrib/llvm-project/llvm/lib/LTO/LTO.cpp b/contrib/llvm-project/llvm/lib/LTO/LTO.cpp
index 05836fd28f52..6a1e53b96998 100644
--- a/contrib/llvm-project/llvm/lib/LTO/LTO.cpp
+++ b/contrib/llvm-project/llvm/lib/LTO/LTO.cpp
@@ -592,7 +592,9 @@ LTO::LTO(Config Conf, ThinBackend Backend,
unsigned ParallelCodeGenParallelismLevel, LTOKind LTOMode)
: Conf(std::move(Conf)),
RegularLTO(ParallelCodeGenParallelismLevel, this->Conf),
- ThinLTO(std::move(Backend)), LTOMode(LTOMode) {}
+ ThinLTO(std::move(Backend)),
+ GlobalResolutions(std::make_optional<StringMap<GlobalResolution>>()),
+ LTOMode(LTOMode) {}
// Requires a destructor for MapVector<BitcodeModule>.
LTO::~LTO() = default;
@@ -610,7 +612,7 @@ void LTO::addModuleToGlobalRes(ArrayRef<InputFile::Symbol> Syms,
assert(ResI != ResE);
SymbolResolution Res = *ResI++;
- auto &GlobalRes = GlobalResolutions[Sym.getName()];
+ auto &GlobalRes = (*GlobalResolutions)[Sym.getName()];
GlobalRes.UnnamedAddr &= Sym.isUnnamedAddr();
if (Res.Prevailing) {
assert(!GlobalRes.Prevailing &&
@@ -1125,7 +1127,7 @@ Error LTO::run(AddStreamFn AddStream, FileCache Cache) {
// Compute "dead" symbols, we don't want to import/export these!
DenseSet<GlobalValue::GUID> GUIDPreservedSymbols;
DenseMap<GlobalValue::GUID, PrevailingType> GUIDPrevailingResolutions;
- for (auto &Res : GlobalResolutions) {
+ for (auto &Res : *GlobalResolutions) {
// Normally resolution have IR name of symbol. We can do nothing here
// otherwise. See comments in GlobalResolution struct for more details.
if (Res.second.IRName.empty())
@@ -1169,6 +1171,8 @@ Error LTO::run(AddStreamFn AddStream, FileCache Cache) {
Error Result = runRegularLTO(AddStream);
if (!Result)
+ // This will reset the GlobalResolutions optional once done with it to
+ // reduce peak memory before importing.
Result = runThinLTO(AddStream, Cache, GUIDPreservedSymbols);
if (StatsFile)
@@ -1273,8 +1277,8 @@ Error LTO::runRegularLTO(AddStreamFn AddStream) {
// This returns true when the name is local or not defined. Locals are
// expected to be handled separately.
auto IsVisibleToRegularObj = [&](StringRef name) {
- auto It = GlobalResolutions.find(name);
- return (It == GlobalResolutions.end() || It->second.VisibleOutsideSummary);
+ auto It = GlobalResolutions->find(name);
+ return (It == GlobalResolutions->end() || It->second.VisibleOutsideSummary);
};
// If allowed, upgrade public vcall visibility metadata to linkage unit
@@ -1291,7 +1295,7 @@ Error LTO::runRegularLTO(AddStreamFn AddStream) {
return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
if (!Conf.CodeGenOnly) {
- for (const auto &R : GlobalResolutions) {
+ for (const auto &R : *GlobalResolutions) {
GlobalValue *GV =
RegularLTO.CombinedModule->getNamedValue(R.second.IRName);
if (!R.second.isPrevailingIRSymbol())
@@ -1708,8 +1712,8 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
// This returns true when the name is local or not defined. Locals are
// expected to be handled separately.
auto IsVisibleToRegularObj = [&](StringRef name) {
- auto It = GlobalResolutions.find(name);
- return (It == GlobalResolutions.end() ||
+ auto It = GlobalResolutions->find(name);
+ return (It == GlobalResolutions->end() ||
It->second.VisibleOutsideSummary);
};
@@ -1739,15 +1743,11 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
ContextDisambiguation.run(ThinLTO.CombinedIndex, isPrevailing);
}
- if (Conf.OptLevel > 0)
- ComputeCrossModuleImport(ThinLTO.CombinedIndex, ModuleToDefinedGVSummaries,
- isPrevailing, ImportLists, ExportLists);
-
// Figure out which symbols need to be internalized. This also needs to happen
// at -O0 because summary-based DCE is implemented using internalization, and
// we must apply DCE consistently with the full LTO module in order to avoid
// undefined references during the final link.
- for (auto &Res : GlobalResolutions) {
+ for (auto &Res : *GlobalResolutions) {
// If the symbol does not have external references or it is not prevailing,
// then not need to mark it as exported from a ThinLTO partition.
if (Res.second.Partition != GlobalResolution::External ||
@@ -1760,6 +1760,16 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
ExportedGUIDs.insert(GUID);
}
+ // Reset the GlobalResolutions to deallocate the associated memory, as there
+ // are no further accesses. We specifically want to do this before computing
+ // cross module importing, which adds to peak memory via the computed import
+ // and export lists.
+ GlobalResolutions.reset();
+
+ if (Conf.OptLevel > 0)
+ ComputeCrossModuleImport(ThinLTO.CombinedIndex, ModuleToDefinedGVSummaries,
+ isPrevailing, ImportLists, ExportLists);
+
// Any functions referenced by the jump table in the regular LTO object must
// be exported.
for (auto &Def : ThinLTO.CombinedIndex.cfiFunctionDefs())