diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index cda03d69522d7..e1aa697a7747f 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1169,7 +1169,7 @@ static void runThinLTOBackend( const clang::TargetOptions &TOpts, const LangOptions &LOpts, std::unique_ptr OS, std::string SampleProfile, std::string ProfileRemapping, BackendAction Action) { - StringMap> + DenseMap> ModuleToDefinedGVSummaries; CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h index 150b31e3e8e40..be85c40983475 100644 --- a/llvm/include/llvm/LTO/LTO.h +++ b/llvm/include/llvm/LTO/LTO.h @@ -196,7 +196,7 @@ class InputFile { /// create a ThinBackend using one of the create*ThinBackend() functions below. using ThinBackend = std::function( const Config &C, ModuleSummaryIndex &CombinedIndex, - StringMap &ModuleToDefinedGVSummaries, + DenseMap &ModuleToDefinedGVSummaries, AddStreamFn AddStream, FileCache Cache)>; /// This ThinBackend runs the individual backend jobs in-process. diff --git a/llvm/include/llvm/Transforms/IPO/FunctionImport.h b/llvm/include/llvm/Transforms/IPO/FunctionImport.h index 3e4b3eb30e77b..559418db05933 100644 --- a/llvm/include/llvm/Transforms/IPO/FunctionImport.h +++ b/llvm/include/llvm/Transforms/IPO/FunctionImport.h @@ -94,8 +94,11 @@ class FunctionImporter { /// The map contains an entry for every module to import from, the key being /// the module identifier to pass to the ModuleLoader. The value is the set of - /// functions to import. - using ImportMapTy = StringMap; + /// functions to import. The module identifier strings must be owned + /// elsewhere, typically by the in-memory ModuleSummaryIndex the importing + /// decisions are made from (the module path for each summary is owned by the + /// index's module path string table). + using ImportMapTy = DenseMap; /// The set contains an entry for every global value the module exports. using ExportSetTy = DenseSet; @@ -147,13 +150,18 @@ class FunctionImportPass : public PassInfoMixin { /// \p ExportLists contains for each Module the set of globals (GUID) that will /// be imported by another module, or referenced by such a function. I.e. this /// is the set of globals that need to be promoted/renamed appropriately. +/// +/// The module identifier strings that are the keys of the above two maps +/// are owned by the in-memory ModuleSummaryIndex the importing decisions +/// are made from (the module path for each summary is owned by the index's +/// module path string table). void ComputeCrossModuleImport( const ModuleSummaryIndex &Index, - const StringMap &ModuleToDefinedGVSummaries, + const DenseMap &ModuleToDefinedGVSummaries, function_ref isPrevailing, - StringMap &ImportLists, - StringMap &ExportLists); + DenseMap &ImportLists, + DenseMap &ExportLists); /// Compute all the imports for the given module using the Index. /// @@ -225,7 +233,7 @@ bool convertToDeclaration(GlobalValue &GV); /// stable order for bitcode emission. void gatherImportedSummariesForModule( StringRef ModulePath, - const StringMap &ModuleToDefinedGVSummaries, + const DenseMap &ModuleToDefinedGVSummaries, const FunctionImporter::ImportMapTy &ImportList, std::map &ModuleToSummariesForIndex); diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index bc8abb751221c..06cf3f294513c 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -178,7 +178,7 @@ void llvm::computeLTOCacheKey( ImportMapIteratorTy ModIt; const ModuleSummaryIndex::ModuleInfo *ModInfo; - StringRef getIdentifier() const { return ModIt->getKey(); } + StringRef getIdentifier() const { return ModIt->getFirst(); } const FunctionImporter::FunctionsToImportTy &getFunctions() const { return ModIt->second; } @@ -191,7 +191,7 @@ void llvm::computeLTOCacheKey( for (ImportMapIteratorTy It = ImportList.begin(); It != ImportList.end(); ++It) { - ImportModulesVector.push_back({It, Index.getModule(It->getKey())}); + ImportModulesVector.push_back({It, Index.getModule(It->getFirst())}); } // Order using module hash, to be both independent of module name and // module order. @@ -1362,14 +1362,15 @@ class lto::ThinBackendProc { protected: const Config &Conf; ModuleSummaryIndex &CombinedIndex; - const StringMap &ModuleToDefinedGVSummaries; + const DenseMap &ModuleToDefinedGVSummaries; lto::IndexWriteCallback OnWrite; bool ShouldEmitImportsFiles; public: - ThinBackendProc(const Config &Conf, ModuleSummaryIndex &CombinedIndex, - const StringMap &ModuleToDefinedGVSummaries, - lto::IndexWriteCallback OnWrite, bool ShouldEmitImportsFiles) + ThinBackendProc( + const Config &Conf, ModuleSummaryIndex &CombinedIndex, + const DenseMap &ModuleToDefinedGVSummaries, + lto::IndexWriteCallback OnWrite, bool ShouldEmitImportsFiles) : Conf(Conf), CombinedIndex(CombinedIndex), ModuleToDefinedGVSummaries(ModuleToDefinedGVSummaries), OnWrite(OnWrite), ShouldEmitImportsFiles(ShouldEmitImportsFiles) {} @@ -1426,7 +1427,7 @@ class InProcessThinBackend : public ThinBackendProc { InProcessThinBackend( const Config &Conf, ModuleSummaryIndex &CombinedIndex, ThreadPoolStrategy ThinLTOParallelism, - const StringMap &ModuleToDefinedGVSummaries, + const DenseMap &ModuleToDefinedGVSummaries, AddStreamFn AddStream, FileCache Cache, lto::IndexWriteCallback OnWrite, bool ShouldEmitIndexFiles, bool ShouldEmitImportsFiles) : ThinBackendProc(Conf, CombinedIndex, ModuleToDefinedGVSummaries, @@ -1548,13 +1549,15 @@ ThinBackend lto::createInProcessThinBackend(ThreadPoolStrategy Parallelism, lto::IndexWriteCallback OnWrite, bool ShouldEmitIndexFiles, bool ShouldEmitImportsFiles) { - return [=](const Config &Conf, ModuleSummaryIndex &CombinedIndex, - const StringMap &ModuleToDefinedGVSummaries, - AddStreamFn AddStream, FileCache Cache) { - return std::make_unique( - Conf, CombinedIndex, Parallelism, ModuleToDefinedGVSummaries, AddStream, - Cache, OnWrite, ShouldEmitIndexFiles, ShouldEmitImportsFiles); - }; + return + [=](const Config &Conf, ModuleSummaryIndex &CombinedIndex, + const DenseMap &ModuleToDefinedGVSummaries, + AddStreamFn AddStream, FileCache Cache) { + return std::make_unique( + Conf, CombinedIndex, Parallelism, ModuleToDefinedGVSummaries, + AddStream, Cache, OnWrite, ShouldEmitIndexFiles, + ShouldEmitImportsFiles); + }; } // Given the original \p Path to an output file, replace any path @@ -1584,7 +1587,7 @@ class WriteIndexesThinBackend : public ThinBackendProc { public: WriteIndexesThinBackend( const Config &Conf, ModuleSummaryIndex &CombinedIndex, - const StringMap &ModuleToDefinedGVSummaries, + const DenseMap &ModuleToDefinedGVSummaries, std::string OldPrefix, std::string NewPrefix, std::string NativeObjectPrefix, bool ShouldEmitImportsFiles, raw_fd_ostream *LinkedObjectsFile, lto::IndexWriteCallback OnWrite) @@ -1632,13 +1635,15 @@ ThinBackend lto::createWriteIndexesThinBackend( std::string OldPrefix, std::string NewPrefix, std::string NativeObjectPrefix, bool ShouldEmitImportsFiles, raw_fd_ostream *LinkedObjectsFile, IndexWriteCallback OnWrite) { - return [=](const Config &Conf, ModuleSummaryIndex &CombinedIndex, - const StringMap &ModuleToDefinedGVSummaries, - AddStreamFn AddStream, FileCache Cache) { - return std::make_unique( - Conf, CombinedIndex, ModuleToDefinedGVSummaries, OldPrefix, NewPrefix, - NativeObjectPrefix, ShouldEmitImportsFiles, LinkedObjectsFile, OnWrite); - }; + return + [=](const Config &Conf, ModuleSummaryIndex &CombinedIndex, + const DenseMap &ModuleToDefinedGVSummaries, + AddStreamFn AddStream, FileCache Cache) { + return std::make_unique( + Conf, CombinedIndex, ModuleToDefinedGVSummaries, OldPrefix, + NewPrefix, NativeObjectPrefix, ShouldEmitImportsFiles, + LinkedObjectsFile, OnWrite); + }; } Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache, @@ -1664,8 +1669,8 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache, // Collect for each module the list of function it defines (GUID -> // Summary). - StringMap - ModuleToDefinedGVSummaries(ThinLTO.ModuleMap.size()); + DenseMap ModuleToDefinedGVSummaries( + ThinLTO.ModuleMap.size()); ThinLTO.CombinedIndex.collectDefinedGVSummariesPerModule( ModuleToDefinedGVSummaries); // Create entries for any modules that didn't have any GV summaries @@ -1682,9 +1687,9 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache, // Synthesize entry counts for functions in the CombinedIndex. computeSyntheticCounts(ThinLTO.CombinedIndex); - StringMap ImportLists( + DenseMap ImportLists( ThinLTO.ModuleMap.size()); - StringMap ExportLists( + DenseMap ExportLists( ThinLTO.ModuleMap.size()); StringMap> ResolvedODR; diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp index 24cd6e1a0b415..942f79dd513de 100644 --- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -634,11 +634,12 @@ std::unique_ptr ThinLTOCodeGenerator::linkCombinedIndex() { namespace { struct IsExported { - const StringMap &ExportLists; + const DenseMap &ExportLists; const DenseSet &GUIDPreservedSymbols; - IsExported(const StringMap &ExportLists, - const DenseSet &GUIDPreservedSymbols) + IsExported( + const DenseMap &ExportLists, + const DenseSet &GUIDPreservedSymbols) : ExportLists(ExportLists), GUIDPreservedSymbols(GUIDPreservedSymbols) {} bool operator()(StringRef ModuleIdentifier, ValueInfo VI) const { @@ -687,7 +688,7 @@ void ThinLTOCodeGenerator::promote(Module &TheModule, ModuleSummaryIndex &Index, auto ModuleIdentifier = TheModule.getModuleIdentifier(); // Collect for each module the list of function it defines (GUID -> Summary). - StringMap ModuleToDefinedGVSummaries; + DenseMap ModuleToDefinedGVSummaries; Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); // Convert the preserved symbols set from string to GUID @@ -705,8 +706,8 @@ void ThinLTOCodeGenerator::promote(Module &TheModule, ModuleSummaryIndex &Index, computePrevailingCopies(Index, PrevailingCopy); // Generate import/export list - StringMap ImportLists(ModuleCount); - StringMap ExportLists(ModuleCount); + DenseMap ImportLists(ModuleCount); + DenseMap ExportLists(ModuleCount); ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, IsPrevailing(PrevailingCopy), ImportLists, ExportLists); @@ -740,7 +741,7 @@ void ThinLTOCodeGenerator::crossModuleImport(Module &TheModule, auto ModuleCount = Index.modulePaths().size(); // Collect for each module the list of function it defines (GUID -> Summary). - StringMap ModuleToDefinedGVSummaries(ModuleCount); + DenseMap ModuleToDefinedGVSummaries(ModuleCount); Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); // Convert the preserved symbols set from string to GUID @@ -757,8 +758,8 @@ void ThinLTOCodeGenerator::crossModuleImport(Module &TheModule, computePrevailingCopies(Index, PrevailingCopy); // Generate import/export list - StringMap ImportLists(ModuleCount); - StringMap ExportLists(ModuleCount); + DenseMap ImportLists(ModuleCount); + DenseMap ExportLists(ModuleCount); ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, IsPrevailing(PrevailingCopy), ImportLists, ExportLists); @@ -780,7 +781,7 @@ void ThinLTOCodeGenerator::gatherImportedSummariesForModule( auto ModuleIdentifier = TheModule.getModuleIdentifier(); // Collect for each module the list of function it defines (GUID -> Summary). - StringMap ModuleToDefinedGVSummaries(ModuleCount); + DenseMap ModuleToDefinedGVSummaries(ModuleCount); Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); // Convert the preserved symbols set from string to GUID @@ -797,8 +798,8 @@ void ThinLTOCodeGenerator::gatherImportedSummariesForModule( computePrevailingCopies(Index, PrevailingCopy); // Generate import/export list - StringMap ImportLists(ModuleCount); - StringMap ExportLists(ModuleCount); + DenseMap ImportLists(ModuleCount); + DenseMap ExportLists(ModuleCount); ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, IsPrevailing(PrevailingCopy), ImportLists, ExportLists); @@ -818,7 +819,7 @@ void ThinLTOCodeGenerator::emitImports(Module &TheModule, StringRef OutputName, auto ModuleIdentifier = TheModule.getModuleIdentifier(); // Collect for each module the list of function it defines (GUID -> Summary). - StringMap ModuleToDefinedGVSummaries(ModuleCount); + DenseMap ModuleToDefinedGVSummaries(ModuleCount); Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); // Convert the preserved symbols set from string to GUID @@ -835,8 +836,8 @@ void ThinLTOCodeGenerator::emitImports(Module &TheModule, StringRef OutputName, computePrevailingCopies(Index, PrevailingCopy); // Generate import/export list - StringMap ImportLists(ModuleCount); - StringMap ExportLists(ModuleCount); + DenseMap ImportLists(ModuleCount); + DenseMap ExportLists(ModuleCount); ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, IsPrevailing(PrevailingCopy), ImportLists, ExportLists); @@ -871,7 +872,7 @@ void ThinLTOCodeGenerator::internalize(Module &TheModule, addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols); // Collect for each module the list of function it defines (GUID -> Summary). - StringMap ModuleToDefinedGVSummaries(ModuleCount); + DenseMap ModuleToDefinedGVSummaries(ModuleCount); Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); // Compute "dead" symbols, we don't want to import/export these! @@ -882,8 +883,8 @@ void ThinLTOCodeGenerator::internalize(Module &TheModule, computePrevailingCopies(Index, PrevailingCopy); // Generate import/export list - StringMap ImportLists(ModuleCount); - StringMap ExportLists(ModuleCount); + DenseMap ImportLists(ModuleCount); + DenseMap ExportLists(ModuleCount); ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, IsPrevailing(PrevailingCopy), ImportLists, ExportLists); @@ -1033,7 +1034,7 @@ void ThinLTOCodeGenerator::run() { auto ModuleCount = Modules.size(); // Collect for each module the list of function it defines (GUID -> Summary). - StringMap ModuleToDefinedGVSummaries(ModuleCount); + DenseMap ModuleToDefinedGVSummaries(ModuleCount); Index->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); // Convert the preserved symbols set from string to GUID, this is needed for @@ -1079,8 +1080,8 @@ void ThinLTOCodeGenerator::run() { // Collect the import/export lists for all modules from the call-graph in the // combined index. - StringMap ImportLists(ModuleCount); - StringMap ExportLists(ModuleCount); + DenseMap ImportLists(ModuleCount); + DenseMap ExportLists(ModuleCount); ComputeCrossModuleImport(*Index, ModuleToDefinedGVSummaries, IsPrevailing(PrevailingCopy), ImportLists, ExportLists); diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp index f635b14cd2a90..f301372b27c46 100644 --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -272,7 +272,7 @@ class GlobalsImporter final { function_ref IsPrevailing; FunctionImporter::ImportMapTy &ImportList; - StringMap *const ExportLists; + DenseMap *const ExportLists; bool shouldImportGlobal(const ValueInfo &VI) { const auto &GVS = DefinedGVSummaries.find(VI.getGUID()); @@ -357,7 +357,7 @@ class GlobalsImporter final { function_ref IsPrevailing, FunctionImporter::ImportMapTy &ImportList, - StringMap *ExportLists) + DenseMap *ExportLists) : Index(Index), DefinedGVSummaries(DefinedGVSummaries), IsPrevailing(IsPrevailing), ImportList(ImportList), ExportLists(ExportLists) {} @@ -403,7 +403,7 @@ static void computeImportForFunction( isPrevailing, SmallVectorImpl &Worklist, GlobalsImporter &GVImporter, FunctionImporter::ImportMapTy &ImportList, - StringMap *ExportLists, + DenseMap *ExportLists, FunctionImporter::ImportThresholdsTy &ImportThresholds) { GVImporter.onImportingSummary(Summary); static int ImportCount = 0; @@ -576,7 +576,7 @@ static void ComputeImportForModule( isPrevailing, const ModuleSummaryIndex &Index, StringRef ModName, FunctionImporter::ImportMapTy &ImportList, - StringMap *ExportLists = nullptr) { + DenseMap *ExportLists = nullptr) { // Worklist contains the list of function imported in this module, for which // we will analyse the callees and may import further down the callgraph. SmallVector Worklist; @@ -671,10 +671,10 @@ static unsigned numGlobalVarSummaries(const ModuleSummaryIndex &Index, #endif #ifndef NDEBUG -static bool -checkVariableImport(const ModuleSummaryIndex &Index, - StringMap &ImportLists, - StringMap &ExportLists) { +static bool checkVariableImport( + const ModuleSummaryIndex &Index, + DenseMap &ImportLists, + DenseMap &ExportLists) { DenseSet FlattenedImports; @@ -702,7 +702,7 @@ checkVariableImport(const ModuleSummaryIndex &Index, for (auto &ExportPerModule : ExportLists) for (auto &VI : ExportPerModule.second) if (!FlattenedImports.count(VI.getGUID()) && - IsReadOrWriteOnlyVarNeedingImporting(ExportPerModule.first(), VI)) + IsReadOrWriteOnlyVarNeedingImporting(ExportPerModule.first, VI)) return false; return true; @@ -712,19 +712,18 @@ checkVariableImport(const ModuleSummaryIndex &Index, /// Compute all the import and export for every module using the Index. void llvm::ComputeCrossModuleImport( const ModuleSummaryIndex &Index, - const StringMap &ModuleToDefinedGVSummaries, + const DenseMap &ModuleToDefinedGVSummaries, function_ref isPrevailing, - StringMap &ImportLists, - StringMap &ExportLists) { + DenseMap &ImportLists, + DenseMap &ExportLists) { // For each module that has function defined, compute the import/export lists. for (const auto &DefinedGVSummaries : ModuleToDefinedGVSummaries) { - auto &ImportList = ImportLists[DefinedGVSummaries.first()]; + auto &ImportList = ImportLists[DefinedGVSummaries.first]; LLVM_DEBUG(dbgs() << "Computing import for Module '" - << DefinedGVSummaries.first() << "'\n"); + << DefinedGVSummaries.first << "'\n"); ComputeImportForModule(DefinedGVSummaries.second, isPrevailing, Index, - DefinedGVSummaries.first(), ImportList, - &ExportLists); + DefinedGVSummaries.first, ImportList, &ExportLists); } // When computing imports we only added the variables and functions being @@ -735,7 +734,7 @@ void llvm::ComputeCrossModuleImport( for (auto &ELI : ExportLists) { FunctionImporter::ExportSetTy NewExports; const auto &DefinedGVSummaries = - ModuleToDefinedGVSummaries.lookup(ELI.first()); + ModuleToDefinedGVSummaries.lookup(ELI.first); for (auto &EI : ELI.second) { // Find the copy defined in the exporting module so that we can mark the // values it references in that specific definition as exported. @@ -783,7 +782,7 @@ void llvm::ComputeCrossModuleImport( LLVM_DEBUG(dbgs() << "Import/Export lists for " << ImportLists.size() << " modules:\n"); for (auto &ModuleImports : ImportLists) { - auto ModName = ModuleImports.first(); + auto ModName = ModuleImports.first; auto &Exports = ExportLists[ModName]; unsigned NumGVS = numGlobalVarSummaries(Index, Exports); LLVM_DEBUG(dbgs() << "* Module " << ModName << " exports " @@ -791,7 +790,7 @@ void llvm::ComputeCrossModuleImport( << " vars. Imports from " << ModuleImports.second.size() << " modules.\n"); for (auto &Src : ModuleImports.second) { - auto SrcModName = Src.first(); + auto SrcModName = Src.first; unsigned NumGVSPerMod = numGlobalVarSummaries(Index, Src.second); LLVM_DEBUG(dbgs() << " - " << Src.second.size() - NumGVSPerMod << " functions imported from " << SrcModName << "\n"); @@ -809,7 +808,7 @@ static void dumpImportListForModule(const ModuleSummaryIndex &Index, LLVM_DEBUG(dbgs() << "* Module " << ModulePath << " imports from " << ImportList.size() << " modules.\n"); for (auto &Src : ImportList) { - auto SrcModName = Src.first(); + auto SrcModName = Src.first; unsigned NumGVSPerMod = numGlobalVarSummaries(Index, Src.second); LLVM_DEBUG(dbgs() << " - " << Src.second.size() - NumGVSPerMod << " functions imported from " << SrcModName << "\n"); @@ -1041,7 +1040,7 @@ void llvm::computeDeadSymbolsWithConstProp( /// \p ModulePath. void llvm::gatherImportedSummariesForModule( StringRef ModulePath, - const StringMap &ModuleToDefinedGVSummaries, + const DenseMap &ModuleToDefinedGVSummaries, const FunctionImporter::ImportMapTy &ImportList, std::map &ModuleToSummariesForIndex) { // Include all summaries from the importing module. @@ -1049,10 +1048,9 @@ void llvm::gatherImportedSummariesForModule( ModuleToDefinedGVSummaries.lookup(ModulePath); // Include summaries for imports. for (const auto &ILI : ImportList) { - auto &SummariesForIndex = - ModuleToSummariesForIndex[std::string(ILI.first())]; + auto &SummariesForIndex = ModuleToSummariesForIndex[std::string(ILI.first)]; const auto &DefinedGVSummaries = - ModuleToDefinedGVSummaries.lookup(ILI.first()); + ModuleToDefinedGVSummaries.lookup(ILI.first); for (const auto &GI : ILI.second) { const auto &DS = DefinedGVSummaries.find(GI); assert(DS != DefinedGVSummaries.end() && @@ -1327,7 +1325,7 @@ Expected FunctionImporter::importFunctions( // Do the actual import of functions now, one Module at a time std::set ModuleNameOrderedList; for (const auto &FunctionsToImportPerModule : ImportList) { - ModuleNameOrderedList.insert(FunctionsToImportPerModule.first()); + ModuleNameOrderedList.insert(FunctionsToImportPerModule.first); } for (const auto &Name : ModuleNameOrderedList) { // Get the module for the import diff --git a/llvm/tools/llvm-link/llvm-link.cpp b/llvm/tools/llvm-link/llvm-link.cpp index 32ab9fa2c963d..a476b50a1ed90 100644 --- a/llvm/tools/llvm-link/llvm-link.cpp +++ b/llvm/tools/llvm-link/llvm-link.cpp @@ -323,6 +323,11 @@ static bool importFunctions(const char *argv0, Module &DestModule) { }; ModuleLazyLoaderCache ModuleLoaderCache(ModuleLoader); + // Owns the filename strings used to key into the ImportList. Normally this is + // constructed from the index and the strings are owned by the index, however, + // since we are synthesizing this data structure from options we need a cache + // to own those strings. + StringSet<> FileNameStringCache; for (const auto &Import : Imports) { // Identify the requested function and its bitcode source file. size_t Idx = Import.find(':'); @@ -360,7 +365,8 @@ static bool importFunctions(const char *argv0, Module &DestModule) { if (Verbose) errs() << "Importing " << FunctionName << " from " << FileName << "\n"; - auto &Entry = ImportList[FileName]; + auto &Entry = + ImportList[FileNameStringCache.insert(FileName).first->getKey()]; Entry.insert(F->getGUID()); } auto CachedModuleLoader = [&](StringRef Identifier) {