diff options
Diffstat (limited to 'llvm/lib/LTO/LTO.cpp')
-rw-r--r-- | llvm/lib/LTO/LTO.cpp | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index 1e345e7dd89e..297b11de17a9 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -29,6 +29,7 @@ #include "llvm/LTO/SummaryBasedOptimizations.h" #include "llvm/Linker/IRMover.h" #include "llvm/Object/IRObjectFile.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Error.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" @@ -146,9 +147,11 @@ void llvm::computeLTOCacheKey( // Include the hash for the current module auto ModHash = Index.getModuleHash(ModuleID); Hasher.update(ArrayRef<uint8_t>((uint8_t *)&ModHash[0], sizeof(ModHash))); - for (auto F : ExportList) + for (const auto &VI : ExportList) { + auto GUID = VI.getGUID(); // The export list can impact the internalization, be conservative here - Hasher.update(ArrayRef<uint8_t>((uint8_t *)&F, sizeof(F))); + Hasher.update(ArrayRef<uint8_t>((uint8_t *)&GUID, sizeof(GUID))); + } // Include the hash for every module we import functions from. The set of // imported symbols for each module may affect code generation and is @@ -383,12 +386,11 @@ static bool isWeakObjectWithRWAccess(GlobalValueSummary *GVS) { } static void thinLTOInternalizeAndPromoteGUID( - GlobalValueSummaryList &GVSummaryList, GlobalValue::GUID GUID, - function_ref<bool(StringRef, GlobalValue::GUID)> isExported, + ValueInfo VI, function_ref<bool(StringRef, ValueInfo)> isExported, function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing) { - for (auto &S : GVSummaryList) { - if (isExported(S->modulePath(), GUID)) { + for (auto &S : VI.getSummaryList()) { + if (isExported(S->modulePath(), VI)) { if (GlobalValue::isLocalLinkage(S->linkage())) S->setLinkage(GlobalValue::ExternalLinkage); } else if (EnableLTOInternalization && @@ -396,7 +398,7 @@ static void thinLTOInternalizeAndPromoteGUID( // doesn't resolve them. !GlobalValue::isLocalLinkage(S->linkage()) && (!GlobalValue::isInterposableLinkage(S->linkage()) || - isPrevailing(GUID, S.get())) && + isPrevailing(VI.getGUID(), S.get())) && S->linkage() != GlobalValue::AppendingLinkage && // We can't internalize available_externally globals because this // can break function pointer equality. @@ -415,11 +417,11 @@ static void thinLTOInternalizeAndPromoteGUID( // as external and non-exported values as internal. void llvm::thinLTOInternalizeAndPromoteInIndex( ModuleSummaryIndex &Index, - function_ref<bool(StringRef, GlobalValue::GUID)> isExported, + function_ref<bool(StringRef, ValueInfo)> isExported, function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing) { for (auto &I : Index) - thinLTOInternalizeAndPromoteGUID(I.second.SummaryList, I.first, isExported, + thinLTOInternalizeAndPromoteGUID(Index.getValueInfo(I), isExported, isPrevailing); } @@ -465,7 +467,7 @@ BitcodeModule &InputFile::getSingleBitcodeModule() { } LTO::RegularLTOState::RegularLTOState(unsigned ParallelCodeGenParallelismLevel, - Config &Conf) + const Config &Conf) : ParallelCodeGenParallelismLevel(ParallelCodeGenParallelismLevel), Ctx(Conf), CombinedModule(std::make_unique<Module>("ld-temp.o", Ctx)), Mover(std::make_unique<IRMover>(*CombinedModule)) {} @@ -1027,12 +1029,12 @@ ArrayRef<const char*> LTO::getRuntimeLibcallSymbols() { /// This class defines the interface to the ThinLTO backend. class lto::ThinBackendProc { protected: - Config &Conf; + const Config &Conf; ModuleSummaryIndex &CombinedIndex; const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries; public: - ThinBackendProc(Config &Conf, ModuleSummaryIndex &CombinedIndex, + ThinBackendProc(const Config &Conf, ModuleSummaryIndex &CombinedIndex, const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries) : Conf(Conf), CombinedIndex(CombinedIndex), ModuleToDefinedGVSummaries(ModuleToDefinedGVSummaries) {} @@ -1060,7 +1062,7 @@ class InProcessThinBackend : public ThinBackendProc { public: InProcessThinBackend( - Config &Conf, ModuleSummaryIndex &CombinedIndex, + const Config &Conf, ModuleSummaryIndex &CombinedIndex, unsigned ThinLTOParallelismLevel, const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries, AddStreamFn AddStream, NativeObjectCache Cache) @@ -1158,7 +1160,7 @@ public: } // end anonymous namespace ThinBackend lto::createInProcessThinBackend(unsigned ParallelismLevel) { - return [=](Config &Conf, ModuleSummaryIndex &CombinedIndex, + return [=](const Config &Conf, ModuleSummaryIndex &CombinedIndex, const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries, AddStreamFn AddStream, NativeObjectCache Cache) { return std::make_unique<InProcessThinBackend>( @@ -1196,7 +1198,7 @@ class WriteIndexesThinBackend : public ThinBackendProc { public: WriteIndexesThinBackend( - Config &Conf, ModuleSummaryIndex &CombinedIndex, + const Config &Conf, ModuleSummaryIndex &CombinedIndex, const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries, std::string OldPrefix, std::string NewPrefix, bool ShouldEmitImportsFiles, raw_fd_ostream *LinkedObjectsFile, lto::IndexWriteCallback OnWrite) @@ -1248,7 +1250,7 @@ public: ThinBackend lto::createWriteIndexesThinBackend( std::string OldPrefix, std::string NewPrefix, bool ShouldEmitImportsFiles, raw_fd_ostream *LinkedObjectsFile, IndexWriteCallback OnWrite) { - return [=](Config &Conf, ModuleSummaryIndex &CombinedIndex, + return [=](const Config &Conf, ModuleSummaryIndex &CombinedIndex, const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries, AddStreamFn AddStream, NativeObjectCache Cache) { return std::make_unique<WriteIndexesThinBackend>( @@ -1262,7 +1264,8 @@ Error LTO::runThinLTO(AddStreamFn AddStream, NativeObjectCache Cache, if (ThinLTO.ModuleMap.empty()) return Error::success(); - if (Conf.CombinedIndexHook && !Conf.CombinedIndexHook(ThinLTO.CombinedIndex)) + if (Conf.CombinedIndexHook && + !Conf.CombinedIndexHook(ThinLTO.CombinedIndex, GUIDPreservedSymbols)) return Error::success(); // Collect for each module the list of function it defines (GUID -> @@ -1330,11 +1333,10 @@ Error LTO::runThinLTO(AddStreamFn AddStream, NativeObjectCache Cache, ExportedGUIDs.insert( GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Def))); - auto isExported = [&](StringRef ModuleIdentifier, GlobalValue::GUID GUID) { + auto isExported = [&](StringRef ModuleIdentifier, ValueInfo VI) { const auto &ExportList = ExportLists.find(ModuleIdentifier); - return (ExportList != ExportLists.end() && - ExportList->second.count(GUID)) || - ExportedGUIDs.count(GUID); + return (ExportList != ExportLists.end() && ExportList->second.count(VI)) || + ExportedGUIDs.count(VI.getGUID()); }; // Update local devirtualized targets that were exported by cross-module @@ -1380,8 +1382,12 @@ lto::setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename, StringRef RemarksPasses, StringRef RemarksFormat, bool RemarksWithHotness, int Count) { std::string Filename = RemarksFilename; + // For ThinLTO, file.opt.<format> becomes + // file.opt.<format>.thin.<num>.<format>. if (!Filename.empty() && Count != -1) - Filename += ".thin." + llvm::utostr(Count) + ".yaml"; + Filename = + (Twine(Filename) + ".thin." + llvm::utostr(Count) + "." + RemarksFormat) + .str(); auto ResultOrErr = llvm::setupOptimizationRemarks( Context, Filename, RemarksPasses, RemarksFormat, RemarksWithHotness); |