Index: lib/Transforms/IPO/FunctionImport.cpp =================================================================== --- lib/Transforms/IPO/FunctionImport.cpp +++ lib/Transforms/IPO/FunctionImport.cpp @@ -295,9 +295,6 @@ ModuleToFunctionsToImportMap, Index, ModuleLoaderCache); assert(Worklist.empty() && "Worklist hasn't been flushed in GetImportList"); - StringMap>> - ModuleToTempMDValsMap; - // Do the actual import of functions now, one Module at a time for (auto &FunctionsToImportPerModule : ModuleToFunctionsToImportMap) { // Get the module for the import @@ -310,30 +307,24 @@ // Save the mapping of value ids to temporary metadata created when // importing this function. If we have already imported from this module, // add new temporary metadata to the existing mapping. - auto &TempMDVals = ModuleToTempMDValsMap[SrcModule->getModuleIdentifier()]; - if (!TempMDVals) - TempMDVals = llvm::make_unique>(); + DenseMap TempMDVals; // Link in the specified functions. if (TheLinker.linkInModule(std::move(SrcModule), Linker::Flags::None, - &Index, &FunctionsToImport, TempMDVals.get())) + &Index, &FunctionsToImport, &TempMDVals)) report_fatal_error("Function Import: link error"); ImportedCount += FunctionsToImport.size(); - } - // Now link in metadata for all modules from which we imported functions. - for (StringMapEntry>> &SME : - ModuleToTempMDValsMap) { - // Load the specified source module. - auto &SrcModule = ModuleLoaderCache(SME.getKey()); + // Now link in metadata + // The modules were created with lazy metadata loading. Materialize it // now, before linking it. - SrcModule.materializeMetadata(); - UpgradeDebugInfo(SrcModule); + SrcModule->materializeMetadata(); + UpgradeDebugInfo(*SrcModule); // Link in all necessary metadata from this module. - if (TheLinker.linkInMetadata(SrcModule, SME.getValue().get())) + if (TheLinker.linkInMetadata(*SrcModule, &TempMDVals)) return false; }