[llvm] r257171 - [ThinLTO] Delay metadata materializtion in function importer
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 8 06:17:41 PST 2016
Author: tejohnson
Date: Fri Jan 8 08:17:41 2016
New Revision: 257171
URL: http://llvm.org/viewvc/llvm-project?rev=257171&view=rev
Log:
[ThinLTO] Delay metadata materializtion in function importer
The function importer was still materializing metadata when modules were
loaded for function importing. We only want to materialize it when we
are going to invoke the metadata linking postpass. Materializing it
before function importing is not only unnecessary, but also causes
metadata referenced by imported functions to be mapped in early, and
then not connected to the rest of the module level metadata when it is
ultimately linked in.
Augmented the test case to specifically check for the metadata being
properly connected, which it wasn't before this fix.
Modified:
llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
llvm/trunk/test/Transforms/FunctionImport/funcimport_debug.ll
Modified: llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp?rev=257171&r1=257170&r2=257171&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp Fri Jan 8 08:17:41 2016
@@ -41,15 +41,16 @@ static std::unique_ptr<Module> loadFile(
LLVMContext &Context) {
SMDiagnostic Err;
DEBUG(dbgs() << "Loading '" << FileName << "'\n");
- std::unique_ptr<Module> Result = getLazyIRFileModule(FileName, Err, Context);
+ // Metadata isn't loaded or linked until after all functions are
+ // imported, after which it will be materialized and linked.
+ std::unique_ptr<Module> Result =
+ getLazyIRFileModule(FileName, Err, Context,
+ /* ShouldLazyLoadMetadata = */ true);
if (!Result) {
Err.print("function-import", errs());
return nullptr;
}
- Result->materializeMetadata();
- UpgradeDebugInfo(*Result);
-
return Result;
}
@@ -324,6 +325,10 @@ bool FunctionImporter::importFunctions(M
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()))
Modified: llvm/trunk/test/Transforms/FunctionImport/funcimport_debug.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionImport/funcimport_debug.ll?rev=257171&r1=257170&r2=257171&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/FunctionImport/funcimport_debug.ll (original)
+++ llvm/trunk/test/Transforms/FunctionImport/funcimport_debug.ll Fri Jan 8 08:17:41 2016
@@ -7,8 +7,18 @@
; RUN: opt -function-import -summary-file %t3.thinlto.bc %s -S | FileCheck %s
; CHECK: define available_externally void @func()
-; CHECK: distinct !DISubprogram(name: "main"
-; CHECK: distinct !DISubprogram(name: "func"
+
+; Check that we have exactly two subprograms (that func's subprogram wasn't
+; linked more than once for example), and that they are connected to
+; the subprogram list on a compute unit.
+; CHECK: !{{[0-9]+}} = distinct !DICompileUnit({{.*}} subprograms: ![[SPs1:[0-9]+]]
+; CHECK: ![[SPs1]] = !{![[MAINSP:[0-9]+]]}
+; CHECK: ![[MAINSP]] = distinct !DISubprogram(name: "main"
+; CHECK: !{{[0-9]+}} = distinct !DICompileUnit({{.*}} subprograms: ![[SPs2:[0-9]+]]
+; CHECK-NOT: ![[SPs2]] = !{{{.*}}null{{.*}}}
+; CHECK: ![[SPs2]] = !{![[FUNCSP:[0-9]+]]}
+; CHECK: ![[FUNCSP]] = distinct !DISubprogram(name: "func"
+; CHECK-NOT: distinct !DISubprogram
; ModuleID = 'funcimport_debug.o'
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
More information about the llvm-commits
mailing list