From 7fb39dfa7c4d9997d967d6daaae2d65cfa7af2ef Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Tue, 25 Sep 2018 20:14:40 +0000 Subject: [ThinLTO] Efficiency fix for writing type id records in per-module indexes Summary: In D49565/r337503, the type id record writing was fixed so that only referenced type ids were emitted into each per-module index for ThinLTO distributed builds. However, this still left an efficiency issue: each per-module index checked all type ids for membership in the referenced set, yielding O(M*N) performance (M indexes and N type ids). Change the TypeIdMap in the summary to be indexed by GUID, to facilitate correlating with type identifier GUIDs referenced in the function summary TypeIdInfo structures. This allowed simplifying other places where a map from type id GUID to type id map entry was previously being used to aid this correlation. Also fix AsmWriter code to handle the rare case of type id GUID collision. For a large internal application, this reduced the thin link time by almost 15%. Reviewers: pcc, vitalybuka Subscribers: mehdi_amini, inglorion, steven_wu, dexonsmith, llvm-commits Differential Revision: https://reviews.llvm.org/D51330 llvm-svn: 343021 --- llvm/lib/LTO/LTO.cpp | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) (limited to 'llvm/lib/LTO/LTO.cpp') diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index 68d210c..50d0075 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -56,12 +56,6 @@ static cl::opt DumpThinCGSCCs("dump-thin-cg-sccs", cl::init(false), cl::Hidden, cl::desc("Dump the SCCs in the ThinLTO index's callgraph")); -// The values are (type identifier, summary) pairs. -typedef DenseMap< - GlobalValue::GUID, - TinyPtrVector *>> - TypeIdSummariesByGuidTy; - // Returns a unique hash for the Module considering the current list of // export/import and other global analysis results. // The hash is produced in \p Key. @@ -71,7 +65,6 @@ static void computeCacheKey( const FunctionImporter::ExportSetTy &ExportList, const std::map &ResolvedODR, const GVSummaryMapTy &DefinedGlobals, - const TypeIdSummariesByGuidTy &TypeIdSummariesByGuid, const std::set &CfiFunctionDefs, const std::set &CfiFunctionDecls) { // Compute the unique hash for this entry. @@ -255,10 +248,9 @@ static void computeCacheKey( // Include the hash for all type identifiers used by this module. for (GlobalValue::GUID TId : UsedTypeIds) { - auto SummariesI = TypeIdSummariesByGuid.find(TId); - if (SummariesI != TypeIdSummariesByGuid.end()) - for (auto *Summary : SummariesI->second) - AddTypeIdSummary(Summary->first, Summary->second); + auto TidIter = Index.typeIds().equal_range(TId); + for (auto It = TidIter.first; It != TidIter.second; ++It) + AddTypeIdSummary(It->second.first, It->second.second); } AddUnsigned(UsedCfiDefs.size()); @@ -917,7 +909,6 @@ class InProcessThinBackend : public ThinBackendProc { ThreadPool BackendThreadPool; AddStreamFn AddStream; NativeObjectCache Cache; - TypeIdSummariesByGuidTy TypeIdSummariesByGuid; std::set CfiFunctionDefs; std::set CfiFunctionDecls; @@ -933,12 +924,6 @@ public: : ThinBackendProc(Conf, CombinedIndex, ModuleToDefinedGVSummaries), BackendThreadPool(ThinLTOParallelismLevel), AddStream(std::move(AddStream)), Cache(std::move(Cache)) { - // Create a mapping from type identifier GUIDs to type identifier summaries. - // This allows backends to use the type identifier GUIDs stored in the - // function summaries to determine which type identifier summaries affect - // each function without needing to compute GUIDs in each backend. - for (auto &TId : CombinedIndex.typeIds()) - TypeIdSummariesByGuid[GlobalValue::getGUID(TId.first)].push_back(&TId); for (auto &Name : CombinedIndex.cfiFunctionDefs()) CfiFunctionDefs.insert( GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Name))); @@ -954,8 +939,7 @@ public: const FunctionImporter::ExportSetTy &ExportList, const std::map &ResolvedODR, const GVSummaryMapTy &DefinedGlobals, - MapVector &ModuleMap, - const TypeIdSummariesByGuidTy &TypeIdSummariesByGuid) { + MapVector &ModuleMap) { auto RunThinBackend = [&](AddStreamFn AddStream) { LTOLLVMContext BackendContext(Conf); Expected> MOrErr = BM.parseModule(BackendContext); @@ -978,8 +962,8 @@ public: SmallString<40> Key; // The module may be cached, this helps handling it. computeCacheKey(Key, Conf, CombinedIndex, ModuleID, ImportList, ExportList, - ResolvedODR, DefinedGlobals, TypeIdSummariesByGuid, - CfiFunctionDefs, CfiFunctionDecls); + ResolvedODR, DefinedGlobals, CfiFunctionDefs, + CfiFunctionDecls); if (AddStreamFn CacheAddStream = Cache(Task, Key)) return RunThinBackend(CacheAddStream); @@ -1003,11 +987,10 @@ public: const std::map &ResolvedODR, const GVSummaryMapTy &DefinedGlobals, - MapVector &ModuleMap, - const TypeIdSummariesByGuidTy &TypeIdSummariesByGuid) { + MapVector &ModuleMap) { Error E = runThinLTOBackendThread( AddStream, Cache, Task, BM, CombinedIndex, ImportList, ExportList, - ResolvedODR, DefinedGlobals, ModuleMap, TypeIdSummariesByGuid); + ResolvedODR, DefinedGlobals, ModuleMap); if (E) { std::unique_lock L(ErrMu); if (Err) @@ -1017,8 +1000,7 @@ public: } }, BM, std::ref(CombinedIndex), std::ref(ImportList), std::ref(ExportList), - std::ref(ResolvedODR), std::ref(DefinedGlobals), std::ref(ModuleMap), - std::ref(TypeIdSummariesByGuid)); + std::ref(ResolvedODR), std::ref(DefinedGlobals), std::ref(ModuleMap)); return Error::success(); } -- cgit v1.1