Skip to content

Commit daf3079

Browse files
[ThinLTO] Add metedata 'thinlto_src_module' and 'thinlto_src_file' (#83110)
Originally, when `EnableImportMetadata` enabled, `SourceFileName` will be recorded as `thinlto_src_module`. Now `SourceFileName` will be recorded as `thinlto_src_file` and `ModuleIdentifier` will be recorded as `thinlto_src_module`.
1 parent 265e49d commit daf3079

File tree

5 files changed

+35
-21
lines changed

5 files changed

+35
-21
lines changed

llvm/lib/Transforms/IPO/FunctionImport.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ static cl::opt<bool> ComputeDead("compute-dead", cl::init(true), cl::Hidden,
125125

126126
static cl::opt<bool> EnableImportMetadata(
127127
"enable-import-metadata", cl::init(false), cl::Hidden,
128-
cl::desc("Enable import metadata like 'thinlto_src_module'"));
128+
cl::desc("Enable import metadata like 'thinlto_src_module' and "
129+
"'thinlto_src_file'"));
129130

130131
/// Summary file to use for function importing when using -function-import from
131132
/// the command line.
@@ -1643,9 +1644,15 @@ Expected<bool> FunctionImporter::importFunctions(
16431644
if (Error Err = F.materialize())
16441645
return std::move(Err);
16451646
if (EnableImportMetadata) {
1646-
// Add 'thinlto_src_module' metadata for statistics and debugging.
1647+
// Add 'thinlto_src_module' and 'thinlto_src_file' metadata for
1648+
// statistics and debugging.
16471649
F.setMetadata(
16481650
"thinlto_src_module",
1651+
MDNode::get(DestModule.getContext(),
1652+
{MDString::get(DestModule.getContext(),
1653+
SrcModule->getModuleIdentifier())}));
1654+
F.setMetadata(
1655+
"thinlto_src_file",
16491656
MDNode::get(DestModule.getContext(),
16501657
{MDString::get(DestModule.getContext(),
16511658
SrcModule->getSourceFileName())}));
@@ -1687,9 +1694,15 @@ Expected<bool> FunctionImporter::importFunctions(
16871694
<< GO->getName() << " from "
16881695
<< SrcModule->getSourceFileName() << "\n");
16891696
if (EnableImportMetadata) {
1690-
// Add 'thinlto_src_module' metadata for statistics and debugging.
1697+
// Add 'thinlto_src_module' and 'thinlto_src_file' metadata for
1698+
// statistics and debugging.
16911699
Fn->setMetadata(
16921700
"thinlto_src_module",
1701+
MDNode::get(DestModule.getContext(),
1702+
{MDString::get(DestModule.getContext(),
1703+
SrcModule->getModuleIdentifier())}));
1704+
Fn->setMetadata(
1705+
"thinlto_src_file",
16931706
MDNode::get(DestModule.getContext(),
16941707
{MDString::get(DestModule.getContext(),
16951708
SrcModule->getSourceFileName())}));

llvm/test/ThinLTO/X86/visibility-elf.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ declare void @ext(ptr)
3636
;; Currently the visibility is not propagated onto an unimported function,
3737
;; because we don't have summaries for declarations.
3838
; CHECK: declare extern_weak void @not_imported()
39-
; CHECK: define available_externally hidden void @hidden_def_ref() !thinlto_src_module !0
40-
; CHECK: define available_externally hidden void @hidden_def_weak_ref() !thinlto_src_module !0
39+
; CHECK: define available_externally hidden void @hidden_def_ref() !thinlto_src_module !0 !thinlto_src_file !1
40+
; CHECK: define available_externally hidden void @hidden_def_weak_ref() !thinlto_src_module !0 !thinlto_src_file !1
4141
;; This can be hidden, but we cannot communicate the declaration's visibility
4242
;; to other modules because declarations don't have summaries, and the IRLinker
4343
;; overrides it when importing the protected def.
44-
; CHECK: define available_externally protected void @protected_def_hidden_ref() !thinlto_src_module !0
44+
; CHECK: define available_externally protected void @protected_def_hidden_ref() !thinlto_src_module !0 !thinlto_src_file !1
4545

4646
; CHECK2: define hidden i32 @hidden_def_weak_def()
4747
; CHECK2: define protected void @protected_def_weak_def()

llvm/test/ThinLTO/X86/visibility-macho.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ declare void @ext(ptr)
3030
;; Currently the visibility is not propagated onto an unimported function,
3131
;; because we don't have summaries for declarations.
3232
; CHECK: declare extern_weak dso_local void @not_imported()
33-
; CHECK: define available_externally hidden void @hidden_def_ref() !thinlto_src_module !0
34-
; CHECK: define available_externally hidden void @hidden_def_weak_ref() !thinlto_src_module !0
33+
; CHECK: define available_externally hidden void @hidden_def_ref() !thinlto_src_module !0 !thinlto_src_file !1
34+
; CHECK: define available_externally hidden void @hidden_def_weak_ref() !thinlto_src_module !0 !thinlto_src_file !1
3535

3636
; CHECK2: define hidden i32 @hidden_def_weak_def()
3737
; CHECK2: define hidden void @hidden_def_ref()

llvm/test/Transforms/FunctionImport/funcimport.ll

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ declare void @linkoncealias(...) #1
5757
; CHECK-DAG: define available_externally void @linkoncealias()
5858

5959
; INSTLIMDEF-DAG: Import referencestatics
60-
; INSTLIMDEF-DAG: define available_externally i32 @referencestatics(i32 %i) !thinlto_src_module !0 {
60+
; INSTLIMDEF-DAG: define available_externally i32 @referencestatics(i32 %i) !thinlto_src_module !0 !thinlto_src_file !1 {
6161
; INSTLIM5-DAG: declare i32 @referencestatics(...)
6262
declare i32 @referencestatics(...) #1
6363

@@ -66,27 +66,27 @@ declare i32 @referencestatics(...) #1
6666
; Ensure that the call is to the properly-renamed function.
6767
; INSTLIMDEF-DAG: Import staticfunc
6868
; INSTLIMDEF-DAG: %call = call i32 @staticfunc.llvm.
69-
; INSTLIMDEF-DAG: define available_externally hidden i32 @staticfunc.llvm.{{.*}} !thinlto_src_module !0 {
69+
; INSTLIMDEF-DAG: define available_externally hidden i32 @staticfunc.llvm.{{.*}} !thinlto_src_module !0 !thinlto_src_file !1 {
7070

7171
; INSTLIMDEF-DAG: Import referenceglobals
72-
; CHECK-DAG: define available_externally i32 @referenceglobals(i32 %i) !thinlto_src_module !0 {
72+
; CHECK-DAG: define available_externally i32 @referenceglobals(i32 %i) !thinlto_src_module !0 !thinlto_src_file !1 {
7373
declare i32 @referenceglobals(...) #1
7474

7575
; The import of referenceglobals will expose call to globalfunc1 that
7676
; should in turn be imported.
7777
; INSTLIMDEF-DAG: Import globalfunc1
78-
; CHECK-DAG: define available_externally void @globalfunc1() !thinlto_src_module !0
78+
; CHECK-DAG: define available_externally void @globalfunc1() !thinlto_src_module !0 !thinlto_src_file !1
7979

8080
; INSTLIMDEF-DAG: Import referencecommon
81-
; CHECK-DAG: define available_externally i32 @referencecommon(i32 %i) !thinlto_src_module !0 {
81+
; CHECK-DAG: define available_externally i32 @referencecommon(i32 %i) !thinlto_src_module !0 !thinlto_src_file !1 {
8282
declare i32 @referencecommon(...) #1
8383

8484
; INSTLIMDEF-DAG: Import setfuncptr
85-
; CHECK-DAG: define available_externally void @setfuncptr() !thinlto_src_module !0 {
85+
; CHECK-DAG: define available_externally void @setfuncptr() !thinlto_src_module !0 !thinlto_src_file !1 {
8686
declare void @setfuncptr(...) #1
8787

8888
; INSTLIMDEF-DAG: Import callfuncptr
89-
; CHECK-DAG: define available_externally void @callfuncptr() !thinlto_src_module !0 {
89+
; CHECK-DAG: define available_externally void @callfuncptr() !thinlto_src_module !0 !thinlto_src_file !1 {
9090
declare void @callfuncptr(...) #1
9191

9292
; Ensure that all uses of local variable @P which has used in setfuncptr
@@ -97,7 +97,7 @@ declare void @callfuncptr(...) #1
9797

9898
; Ensure that @referencelargelinkonce definition is pulled in, but later we
9999
; also check that the linkonceodr function is not.
100-
; CHECK-DAG: define available_externally void @referencelargelinkonce() !thinlto_src_module !0 {
100+
; CHECK-DAG: define available_externally void @referencelargelinkonce() !thinlto_src_module !0 !thinlto_src_file !1 {
101101
; INSTLIM5-DAG: declare void @linkonceodr()
102102
declare void @referencelargelinkonce(...)
103103

@@ -110,13 +110,13 @@ declare void @weakfunc(...) #1
110110
declare void @linkoncefunc2(...) #1
111111

112112
; INSTLIMDEF-DAG: Import funcwithpersonality
113-
; INSTLIMDEF-DAG: define available_externally hidden void @funcwithpersonality.llvm.{{.*}}() personality ptr @__gxx_personality_v0 !thinlto_src_module !0 {
113+
; INSTLIMDEF-DAG: define available_externally hidden void @funcwithpersonality.llvm.{{.*}}() personality ptr @__gxx_personality_v0 !thinlto_src_module !0 !thinlto_src_file !1 {
114114
; INSTLIM5-DAG: declare hidden void @funcwithpersonality.llvm.{{.*}}()
115115

116116
; We can import variadic functions without a va_start, since the inliner
117117
; can handle them.
118118
; INSTLIMDEF-DAG: Import variadic_no_va_start
119-
; CHECK-DAG: define available_externally void @variadic_no_va_start(...) !thinlto_src_module !0 {
119+
; CHECK-DAG: define available_externally void @variadic_no_va_start(...) !thinlto_src_module !0 !thinlto_src_file !1 {
120120
declare void @variadic_no_va_start(...)
121121

122122
; We can import variadic functions with a va_start, since the inliner
@@ -128,7 +128,8 @@ declare void @variadic_va_start(...)
128128
; INSTLIMDEF-DAG: 15 function-import - Number of functions imported
129129
; INSTLIMDEF-DAG: 4 function-import - Number of global variables imported
130130

131-
; CHECK-DAG: !0 = !{!"{{.*}}/Inputs/funcimport.ll"}
131+
; CHECK-DAG: !0 = !{!"{{.*}}.bc"}
132+
; CHECK-DAG: !1 = !{!"{{.*}}/Inputs/funcimport.ll"}
132133

133134
; The actual GUID values will depend on path to test.
134135
; GUID-DAG: GUID {{.*}} is weakalias

llvm/test/Transforms/Inline/inline_stats.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ define void @internal3() {
4444

4545
declare void @external_decl()
4646

47-
define void @external1() alwaysinline !thinlto_src_module !0 {
47+
define void @external1() alwaysinline !thinlto_src_module !0 !thinlto_src_file !1 {
4848
call fastcc void @internal2()
4949
call fastcc void @external2();
5050
call void @external_decl();
@@ -87,7 +87,7 @@ define void @external_big() noinline !thinlto_src_module !1 {
8787
}
8888

8989
; It should not be imported, but it should not break anything.
90-
define void @external_notcalled() !thinlto_src_module !0 {
90+
define void @external_notcalled() !thinlto_src_module !0 !thinlto_src_file !1 {
9191
call void @external_notcalled()
9292
ret void
9393
}

0 commit comments

Comments
 (0)