Skip to content

Commit b0fede3

Browse files
authored
[ThinLTO] Don't convert functions to declarations if force-import-all is enabled (#134541)
On one hand, we intend to force import all functions when the option is enabled. On the other hand, we currently drop definitions of some functions and convert them to declarations, which contradicts this intent. With this PR, functions will no longer be converted to declarations when `force-import-all` is enabled.
1 parent 5f744cc commit b0fede3

File tree

5 files changed

+52
-5
lines changed

5 files changed

+52
-5
lines changed

llvm/lib/LTO/LTO.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ static cl::opt<bool>
7575

7676
extern cl::opt<bool> CodeGenDataThinLTOTwoRounds;
7777

78+
extern cl::opt<bool> ForceImportAll;
79+
7880
namespace llvm {
7981
/// Enable global value internalization in LTO.
8082
cl::opt<bool> EnableLTOInternalization(
@@ -406,8 +408,11 @@ static void thinLTOResolvePrevailingGUID(
406408
Visibility = S->getVisibility();
407409
}
408410
// Alias and aliasee can't be turned into available_externally.
411+
// When force-import-all is used, it indicates that object linking is not
412+
// supported by the target. In this case, we can't change the linkage as
413+
// well in case the global is converted to declaration.
409414
else if (!isa<AliasSummary>(S.get()) &&
410-
!GlobalInvolvedWithAlias.count(S.get()))
415+
!GlobalInvolvedWithAlias.count(S.get()) && !ForceImportAll)
411416
S->setLinkage(GlobalValue::AvailableExternallyLinkage);
412417

413418
// For ELF, set visibility to the computed visibility from summaries. We

llvm/lib/Transforms/IPO/FunctionImport.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ STATISTIC(NumImportedModules, "Number of modules imported from");
7171
STATISTIC(NumDeadSymbols, "Number of dead stripped symbols in index");
7272
STATISTIC(NumLiveSymbols, "Number of live symbols in index");
7373

74+
cl::opt<bool>
75+
ForceImportAll("force-import-all", cl::init(false), cl::Hidden,
76+
cl::desc("Import functions with noinline attribute"));
77+
7478
/// Limit on instruction count of imported functions.
7579
static cl::opt<unsigned> ImportInstrLimit(
7680
"import-instr-limit", cl::init(100), cl::Hidden, cl::value_desc("N"),
@@ -80,10 +84,6 @@ static cl::opt<int> ImportCutoff(
8084
"import-cutoff", cl::init(-1), cl::Hidden, cl::value_desc("N"),
8185
cl::desc("Only import first N functions if N>=0 (default -1)"));
8286

83-
static cl::opt<bool>
84-
ForceImportAll("force-import-all", cl::init(false), cl::Hidden,
85-
cl::desc("Import functions with noinline attribute"));
86-
8787
static cl::opt<float>
8888
ImportInstrFactor("import-instr-evolution-factor", cl::init(0.7),
8989
cl::Hidden, cl::value_desc("x"),
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
define void @f1(ptr %v) #0 {
2+
entry:
3+
call void @weak_common(ptr %v)
4+
ret void
5+
}
6+
7+
define weak hidden void @weak_common(ptr %v) #0 {
8+
entry:
9+
store i32 12345, ptr %v
10+
ret void
11+
}
12+
13+
attributes #0 = { noinline }
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; RUN: opt -mtriple=amdgcn-amd-amdhsa -module-summary %s -o %t.main.bc
2+
; RUN: opt -mtriple=amdgcn-amd-amdhsa -module-summary %p/Inputs/in-f1.ll -o %t.in.bc
3+
; RUN: llvm-lto -thinlto-action=run -force-import-all %t.main.bc %t.in.bc --thinlto-save-temps=%t.2.
4+
; RUN: llvm-dis %t.2.0.3.imported.bc -o - | FileCheck --check-prefix=MOD1 %s
5+
; RUN: llvm-dis %t.2.1.3.imported.bc -o - | FileCheck --check-prefix=MOD2 %s
6+
7+
define void @f0(ptr %p) #0 {
8+
entry:
9+
call void @f1(ptr %p)
10+
ret void
11+
}
12+
13+
define weak hidden void @weak_common(ptr %v) #0 {
14+
entry:
15+
store i32 12345, ptr %v
16+
ret void
17+
}
18+
19+
declare void @f1(ptr)
20+
21+
attributes #0 = { noinline }
22+
23+
; MOD1: define weak hidden void @weak_common
24+
; MOD1: define available_externally void @f1
25+
26+
; MOD2: define void @f1
27+
; MOD2: define weak hidden void @weak_common
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if not "AMDGPU" in config.root.targets:
2+
config.unsupported = True

0 commit comments

Comments
 (0)