diff options
author | Teresa Johnson <tejohnson@google.com> | 2022-10-11 14:00:37 -0700 |
---|---|---|
committer | Teresa Johnson <tejohnson@google.com> | 2022-11-15 06:45:12 -0800 |
commit | 47459455009db4790ffc3765a2ec0f8b4934c2a4 (patch) | |
tree | a0a2cdb04b5514eb45f5ba5291a49f0c0806c104 /llvm/lib/LTO/LTO.cpp | |
parent | a8673b722989c209ca41f02ab09150362bf1afd4 (diff) | |
download | llvm-47459455009db4790ffc3765a2ec0f8b4934c2a4.zip llvm-47459455009db4790ffc3765a2ec0f8b4934c2a4.tar.gz llvm-47459455009db4790ffc3765a2ec0f8b4934c2a4.tar.bz2 |
[MemProf] ThinLTO summary support
Implements the ThinLTO summary support for memprof related metadata.
This includes support for the assembly format, and for building the
summary from IR during ModuleSummaryAnalysis.
To reduce space in both the bitcode format and the in memory index,
we do 2 things:
1. We keep a single vector of all uniq stack id hashes, and record the
index into this vector in the callsite and allocation memprof
summaries.
2. When building the combined index during the LTO link, the callsite
and allocation memprof summaries are only kept on the FunctionSummary
of the prevailing copy.
Differential Revision: https://reviews.llvm.org/D135714
Diffstat (limited to 'llvm/lib/LTO/LTO.cpp')
-rw-r--r-- | llvm/lib/LTO/LTO.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index dc28b68..9bfbabc 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -911,9 +911,25 @@ Error LTO::linkRegularLTO(RegularLTOState::AddedModule Mod, Error LTO::addThinLTO(BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms, const SymbolResolution *&ResI, const SymbolResolution *ResE) { + const SymbolResolution *ResITmp = ResI; + for (const InputFile::Symbol &Sym : Syms) { + assert(ResITmp != ResE); + SymbolResolution Res = *ResITmp++; + + if (!Sym.getIRName().empty()) { + auto GUID = GlobalValue::getGUID(GlobalValue::getGlobalIdentifier( + Sym.getIRName(), GlobalValue::ExternalLinkage, "")); + if (Res.Prevailing) + ThinLTO.PrevailingModuleForGUID[GUID] = BM.getModuleIdentifier(); + } + } + if (Error Err = BM.readSummary(ThinLTO.CombinedIndex, BM.getModuleIdentifier(), - ThinLTO.ModuleMap.size())) + ThinLTO.ModuleMap.size(), [&](GlobalValue::GUID GUID) { + return ThinLTO.PrevailingModuleForGUID[GUID] == + BM.getModuleIdentifier(); + })) return Err; for (const InputFile::Symbol &Sym : Syms) { @@ -924,7 +940,8 @@ Error LTO::addThinLTO(BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms, auto GUID = GlobalValue::getGUID(GlobalValue::getGlobalIdentifier( Sym.getIRName(), GlobalValue::ExternalLinkage, "")); if (Res.Prevailing) { - ThinLTO.PrevailingModuleForGUID[GUID] = BM.getModuleIdentifier(); + assert(ThinLTO.PrevailingModuleForGUID[GUID] == + BM.getModuleIdentifier()); // For linker redefined symbols (via --wrap or --defsym) we want to // switch the linkage to `weak` to prevent IPOs from happening. @@ -1454,6 +1471,7 @@ ThinBackend lto::createWriteIndexesThinBackend( Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache, const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols) { + ThinLTO.CombinedIndex.releaseTemporaryMemory(); timeTraceProfilerBegin("ThinLink", StringRef("")); auto TimeTraceScopeExit = llvm::make_scope_exit([]() { if (llvm::timeTraceProfilerEnabled()) |