[ThinLTO] Do metadata linking during batch function importing
Summary: Since we are currently not doing incremental importing there is no need to link metadata as a postpass. The module linker will only link in the imported subroutines due to the functionality added by r256003. (Note that the metadata postpass linking functionalitiy is still used by llvm-link, and may be needed here in the future if a more incremental strategy is adopted.) Reviewers: joker.eph Subscribers: joker.eph, llvm-commits Differential Revision: http://reviews.llvm.org/D16424 llvm-svn: 258458
This commit is contained in:
parent
68b6d5ac42
commit
6cba37ce75
|
@ -137,8 +137,6 @@ public:
|
||||||
// may be exported to another backend compilation.
|
// may be exported to another backend compilation.
|
||||||
if (ImportIndex && !FunctionsToImport)
|
if (ImportIndex && !FunctionsToImport)
|
||||||
HasExportedFunctions = ImportIndex->hasExportedFunctions(SrcM);
|
HasExportedFunctions = ImportIndex->hasExportedFunctions(SrcM);
|
||||||
assert((ValIDToTempMDMap || !FunctionsToImport) &&
|
|
||||||
"Function importing must provide a ValIDToTempMDMap");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool run();
|
bool run();
|
||||||
|
|
|
@ -41,8 +41,8 @@ static std::unique_ptr<Module> loadFile(const std::string &FileName,
|
||||||
LLVMContext &Context) {
|
LLVMContext &Context) {
|
||||||
SMDiagnostic Err;
|
SMDiagnostic Err;
|
||||||
DEBUG(dbgs() << "Loading '" << FileName << "'\n");
|
DEBUG(dbgs() << "Loading '" << FileName << "'\n");
|
||||||
// Metadata isn't loaded or linked until after all functions are
|
// Metadata isn't loaded until functions are imported, to minimize
|
||||||
// imported, after which it will be materialized and linked.
|
// the memory overhead.
|
||||||
std::unique_ptr<Module> Result =
|
std::unique_ptr<Module> Result =
|
||||||
getLazyIRFileModule(FileName, Err, Context,
|
getLazyIRFileModule(FileName, Err, Context,
|
||||||
/* ShouldLazyLoadMetadata = */ true);
|
/* ShouldLazyLoadMetadata = */ true);
|
||||||
|
@ -295,9 +295,6 @@ bool FunctionImporter::importFunctions(Module &DestModule) {
|
||||||
ModuleToFunctionsToImportMap, Index, ModuleLoaderCache);
|
ModuleToFunctionsToImportMap, Index, ModuleLoaderCache);
|
||||||
assert(Worklist.empty() && "Worklist hasn't been flushed in GetImportList");
|
assert(Worklist.empty() && "Worklist hasn't been flushed in GetImportList");
|
||||||
|
|
||||||
StringMap<std::unique_ptr<DenseMap<unsigned, MDNode *>>>
|
|
||||||
ModuleToTempMDValsMap;
|
|
||||||
|
|
||||||
// Do the actual import of functions now, one Module at a time
|
// Do the actual import of functions now, one Module at a time
|
||||||
for (auto &FunctionsToImportPerModule : ModuleToFunctionsToImportMap) {
|
for (auto &FunctionsToImportPerModule : ModuleToFunctionsToImportMap) {
|
||||||
// Get the module for the import
|
// Get the module for the import
|
||||||
|
@ -307,36 +304,19 @@ bool FunctionImporter::importFunctions(Module &DestModule) {
|
||||||
assert(&DestModule.getContext() == &SrcModule->getContext() &&
|
assert(&DestModule.getContext() == &SrcModule->getContext() &&
|
||||||
"Context mismatch");
|
"Context mismatch");
|
||||||
|
|
||||||
// Save the mapping of value ids to temporary metadata created when
|
// If modules were created with lazy metadata loading, materialize it
|
||||||
// importing this function. If we have already imported from this module,
|
// now, before linking it (otherwise this will be a noop).
|
||||||
// add new temporary metadata to the existing mapping.
|
SrcModule->materializeMetadata();
|
||||||
auto &TempMDVals = ModuleToTempMDValsMap[SrcModule->getModuleIdentifier()];
|
UpgradeDebugInfo(*SrcModule);
|
||||||
if (!TempMDVals)
|
|
||||||
TempMDVals = llvm::make_unique<DenseMap<unsigned, MDNode *>>();
|
|
||||||
|
|
||||||
// Link in the specified functions.
|
// Link in the specified functions.
|
||||||
if (TheLinker.linkInModule(std::move(SrcModule), Linker::Flags::None,
|
if (TheLinker.linkInModule(std::move(SrcModule), Linker::Flags::None,
|
||||||
&Index, &FunctionsToImport, TempMDVals.get()))
|
&Index, &FunctionsToImport))
|
||||||
report_fatal_error("Function Import: link error");
|
report_fatal_error("Function Import: link error");
|
||||||
|
|
||||||
ImportedCount += FunctionsToImport.size();
|
ImportedCount += FunctionsToImport.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now link in metadata for all modules from which we imported functions.
|
|
||||||
for (StringMapEntry<std::unique_ptr<DenseMap<unsigned, MDNode *>>> &SME :
|
|
||||||
ModuleToTempMDValsMap) {
|
|
||||||
// Load the specified source module.
|
|
||||||
auto &SrcModule = ModuleLoaderCache(SME.getKey());
|
|
||||||
// The modules were created with lazy metadata loading. Materialize it
|
|
||||||
// now, before linking it.
|
|
||||||
SrcModule.materializeMetadata();
|
|
||||||
UpgradeDebugInfo(SrcModule);
|
|
||||||
|
|
||||||
// Link in all necessary metadata from this module.
|
|
||||||
if (TheLinker.linkInMetadata(SrcModule, SME.getValue().get()))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEBUG(dbgs() << "Imported " << ImportedCount << " functions for Module "
|
DEBUG(dbgs() << "Imported " << ImportedCount << " functions for Module "
|
||||||
<< DestModule.getModuleIdentifier() << "\n");
|
<< DestModule.getModuleIdentifier() << "\n");
|
||||||
return ImportedCount;
|
return ImportedCount;
|
||||||
|
|
Loading…
Reference in New Issue