Skip to content

Commit 142cedc

Browse files
[SampleProf][Inliner] Add an option to turn off inliner in sample-profile pass.
Use case is offline evaluation (for inliner effectiveness) or debugging. Differential Revision: https://reviews.llvm.org/D120344
1 parent 5e1ae3a commit 142cedc

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

llvm/lib/Transforms/IPO/SampleProfile.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ static cl::opt<bool> ProfileSizeInline(
183183
cl::desc("Inline cold call sites in profile loader if it's beneficial "
184184
"for code size."));
185185

186+
static cl::opt<bool> DisableSampleLoaderInlining(
187+
"disable-sample-loader-inlining", cl::Hidden, cl::init(false),
188+
cl::desc("If true, turn off inliner in sample profile loader. Used for "
189+
"evaluation or debugging."));
190+
186191
cl::opt<int> ProfileInlineGrowthLimit(
187192
"sample-profile-inline-growth-limit", cl::Hidden, cl::init(12),
188193
cl::desc("The size growth ratio limit for proirity-based sample profile "
@@ -1124,6 +1129,8 @@ void SampleProfileLoader::findExternalInlineCandidate(
11241129
/// \returns True if there is any inline happened.
11251130
bool SampleProfileLoader::inlineHotFunctions(
11261131
Function &F, DenseSet<GlobalValue::GUID> &InlinedGUIDs) {
1132+
if (DisableSampleLoaderInlining)
1133+
return false;
11271134
// ProfAccForSymsInList is used in callsiteIsHot. The assertion makes sure
11281135
// Profile symbol list is ignored when profile-sample-accurate is on.
11291136
assert((!ProfAccForSymsInList ||
@@ -1400,7 +1407,8 @@ SampleProfileLoader::shouldInlineCandidate(InlineCandidate &Candidate) {
14001407

14011408
bool SampleProfileLoader::inlineHotFunctionsWithPriority(
14021409
Function &F, DenseSet<GlobalValue::GUID> &InlinedGUIDs) {
1403-
1410+
if (DisableSampleLoaderInlining)
1411+
return false;
14041412
// ProfAccForSymsInList is used in callsiteIsHot. The assertion makes sure
14051413
// Profile symbol list is ignored when profile-sample-accurate is on.
14061414
assert((!ProfAccForSymsInList ||

llvm/test/Transforms/SampleProfile/profile-context-tracker.ll

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,20 @@
1717
; _Z5funcAi:1 @ _Z8funcLeafi
1818
; _Z5funcBi:1 @ _Z8funcLeafi
1919

20+
; Test the functions won't be inlined as a result of sampled profile if `disable-sample-loader-inlining` is true.
21+
;
22+
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/profile-context-tracker.prof -sample-profile-inline-size -sample-profile-prioritized-inline=0 -profile-sample-accurate -disable-sample-loader-inlining -S | FileCheck %s --check-prefix=INLINE-NONE
23+
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%t -sample-profile-inline-size -sample-profile-prioritized-inline=0 -profile-sample-accurate -disable-sample-loader-inlining -S | FileCheck %s --check-prefix=INLINE-NONE
24+
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/profile-context-tracker.prof -sample-profile-inline-size -sample-profile-cold-inline-threshold=200 -profile-sample-accurate -disable-sample-loader-inlining -S | FileCheck %s --check-prefix=INLINE-NONE
25+
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%t -sample-profile-inline-size -sample-profile-cold-inline-threshold=200 -profile-sample-accurate -disable-sample-loader-inlining -S | FileCheck %s --check-prefix=INLINE-NONE
26+
2027

2128
@factor = dso_local global i32 3, align 4, !dbg !0
2229

2330
define dso_local i32 @main() local_unnamed_addr #0 !dbg !18 {
2431
; INLINE-ALL: @main{{.*}}!prof ![[MAIN_PROF:[0-9]+]]
2532
; INLINE-HOT: @main{{.*}}!prof ![[MAIN_PROF:[0-9]+]]
33+
; INLINE-NONE: @main{{.*}}!prof ![[MAIN_PROF:[0-9]+]]
2634
entry:
2735
br label %for.body, !dbg !25
2836

@@ -36,10 +44,16 @@ for.body: ; preds = %for.body, %entry
3644
; _Z5funcBi is marked noinline
3745
; INLINE-ALL: call i32 @_Z5funcBi
3846
; INLINE-HOT: call i32 @_Z5funcBi
47+
;
48+
; _Z5funcBi isn't inlined since disable-sample-loader-inlining is true.
49+
; INLINE-NONE: call i32 @_Z5funcBi
3950
%add = add nuw nsw i32 %x.011, 1, !dbg !31
4051
%call1 = tail call i32 @_Z5funcAi(i32 %add), !dbg !28
4152
; INLINE-ALL-NOT: call i32 @_Z5funcAi
4253
; INLINE-HOT: call i32 @_Z5funcAi
54+
;
55+
; _Z5funcAi is not inlined since `disable-sample-loader-inlining` is true.
56+
; INLINE-NONE: call i32 @_Z5funcAi
4357
%add2 = add i32 %call, %r.010, !dbg !34
4458
%add3 = add i32 %add2, %call1, !dbg !35
4559
%dec = add nsw i32 %x.011, -1, !dbg !36
@@ -51,13 +65,17 @@ define dso_local i32 @_Z5funcAi(i32 %x) local_unnamed_addr #1 !dbg !40 {
5165
; _Z5funcAi is inlined, so outline remainder should have zero counts
5266
; INLINE-ALL: @_Z5funcAi{{.*}}!prof ![[FUNCA_PROF:[0-9]+]]
5367
; INLINE-HOT: @_Z5funcAi{{.*}}!prof ![[FUNCA_PROF:[0-9]+]]
68+
; INLINE-NONE: @_Z5funcAi{{.*}}!prof ![[FUNCA_PROF:[0-9]+]]
5469
entry:
5570
%add = add nsw i32 %x, 100000, !dbg !44
5671
; _Z8funcLeafi is already inlined on main->_Z5funcAi->_Z8funcLeafi,
5772
; so it should not be inlined on _Z5funcAi->_Z8funcLeafi based on updated
5873
; (merged and promoted) context profile
5974
; INLINE-ALL: call i32 @_Z8funcLeafi
6075
; INLINE-HOT-NOT: call i32 @_Z8funcLeafi
76+
;
77+
; `_Z8funcLeafi` isn't inlined if `disable-sample-loader-inlining` is true.
78+
; INLINE-NONE: call i32 @_Z8funcLeafi
6179
%call = tail call i32 @_Z8funcLeafi(i32 %add), !dbg !45
6280
ret i32 %call, !dbg !46
6381
}
@@ -67,6 +85,9 @@ define dso_local i32 @_Z8funcLeafi(i32 %x) local_unnamed_addr #1 !dbg !54 {
6785
; inlined, so outline remainder should have empty profile
6886
; INLINE-ALL: @_Z8funcLeafi{{.*}}!prof ![[LEAF_PROF:[0-9]+]]
6987
; INLINE-HOT: @_Z8funcLeafi{{.*}}!prof ![[LEAF_PROF:[0-9]+]]
88+
;
89+
; _Z8funcLeafi won't be inlined if `disable-sample-loader-inlining` is true.
90+
; INLINE-NONE: @_Z8funcLeafi{{.*}}!prof ![[LEAF_PROF:[0-9]+]]
7091
entry:
7192
%cmp = icmp sgt i32 %x, 0, !dbg !57
7293
br i1 %cmp, label %while.body, label %while.cond2.preheader, !dbg !59
@@ -100,13 +121,17 @@ define dso_local i32 @_Z5funcBi(i32 %x) local_unnamed_addr #0 !dbg !47 {
100121
; _Z5funcBi is marked noinline, so outline remainder has promoted context profile
101122
; INLINE-ALL: @_Z5funcBi{{.*}}!prof ![[FUNCB_PROF:[0-9]+]]
102123
; INLINE-HOT: @_Z5funcBi{{.*}}!prof ![[FUNCB_PROF:[0-9]+]]
124+
; _Z5funcBi won't be inlined since `disable-sample-loader-inlining` is true.
125+
; INLINE-NONE: @_Z5funcBi{{.*}}!prof ![[FUNCB_PROF:[0-9]+]]
103126
entry:
104127
%sub = add nsw i32 %x, -100000, !dbg !51
105128
%call = tail call i32 @_Z8funcLeafi(i32 %sub), !dbg !52
106129
; _Z5funcBi is not inlined into main, so we main->_Z5funcBi->_Z8funcLeafi
107130
; should be inlined based on promoted context profile
108131
; INLINE-ALL-NOT: call i32 @_Z8funcLeafi
109132
; INLINE-HOT-NOT: call i32 @_Z8funcLeafi
133+
;
134+
; INLINE-NONE: call i32 @_Z8funcLeafi
110135
ret i32 %call, !dbg !53
111136
}
112137

@@ -120,6 +145,11 @@ entry:
120145
; INLINE-HOT-DAG-SAME: [[LEAF_PROF]] = !{!"function_entry_count", i64 0}
121146
; INLINE-HOT-DAG: [[FUNCB_PROF]] = !{!"function_entry_count", i64 13}
122147

148+
; INLINE-NONE: [[MAIN_PROF]] = !{!"function_entry_count", i64 1}
149+
; INLINE-NONE: [[FUNCA_PROF]] = !{!"function_entry_count", i64 24}
150+
; INLINE-NONE-DAG-SAME: [[LEAF_PROF]] = !{!"function_entry_count", i64 22}
151+
; INLINE-NONE-DAG: [[FUNCB_PROF]] = !{!"function_entry_count", i64 32}
152+
123153
declare i32 @_Z3fibi(i32)
124154

125155
attributes #0 = { nofree noinline norecurse nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" "use-sample-profile" }

0 commit comments

Comments
 (0)