Skip to content

Commit cde256b

Browse files
committed
Use flattened profile when sample loading inling is disablede
1 parent 2d4a253 commit cde256b

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

llvm/lib/Transforms/IPO/SampleProfile.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ static cl::opt<bool> ProfileSizeInline(
195195
static cl::opt<bool> DisableSampleLoaderInlining(
196196
"disable-sample-loader-inlining", cl::Hidden, cl::init(false),
197197
cl::desc("If true, artifically skip inline transformation in sample-loader "
198-
"pass, and merge (or scale) profiles (as configured by "
199-
"--sample-profile-merge-inlinee)."));
198+
"pass, and use flattened profiles to emit annotation."));
200199

201200
namespace llvm {
202201
cl::opt<bool>
@@ -1978,6 +1977,13 @@ bool SampleProfileLoader::doInitialization(Module &M,
19781977

19791978
PSL = Reader->getProfileSymbolList();
19801979

1980+
if (DisableSampleLoaderInlining.getNumOccurrences())
1981+
DisableSampleProfileInlining = DisableSampleLoaderInlining;
1982+
1983+
// Use flattened profile if inlining is disabled.
1984+
if (DisableSampleProfileInlining && !Reader->profileIsCS())
1985+
ProfileConverter::flattenProfile(Reader->getProfiles());
1986+
19811987
// While profile-sample-accurate is on, ignore symbol list.
19821988
ProfAccForSymsInList =
19831989
ProfileAccurateForSymsInList && PSL && !ProfileSampleAccurate;
@@ -2006,9 +2012,6 @@ bool SampleProfileLoader::doInitialization(Module &M,
20062012
/*EmitRemarks=*/false, InlineContext{LTOPhase, InlinePass::ReplaySampleProfileInliner});
20072013
}
20082014

2009-
if (DisableSampleLoaderInlining.getNumOccurrences())
2010-
DisableSampleProfileInlining = DisableSampleLoaderInlining;
2011-
20122015
// Apply tweaks if context-sensitive or probe-based profile is available.
20132016
if (Reader->profileIsCS() || Reader->profileIsPreInlined() ||
20142017
Reader->profileIsProbeBased()) {

llvm/test/Transforms/SampleProfile/inline-mergeprof.ll

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
; when the profile uses md5.
1010
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline-mergeprof.md5.prof -sample-profile-merge-inlinee=true -use-profiled-call-graph=0 -S | FileCheck -check-prefix=MERGE %s
1111

12-
; Test we properly merge not inlined profile with '--sample-profile-merge-inlinee' even if '--disable-sample-loader-inlining' is true
13-
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline-mergeprof.md5.prof -sample-profile-merge-inlinee=true --disable-sample-loader-inlining -use-profiled-call-graph=0 -S | FileCheck -check-prefix=MERGE %s
12+
; Test we properly use flattened profile when using '--disable-sample-loader-inlining'.
13+
14+
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline-mergeprof.prof -sample-profile-merge-inlinee=true --disable-sample-loader-inlining -use-profiled-call-graph=0 -S | FileCheck -check-prefix=FLATTEN %s
1415

1516
@.str = private unnamed_addr constant [11 x i8] c"sum is %d\0A\00", align 1
1617

@@ -103,3 +104,10 @@ declare i32 @printf(ptr, ...)
103104
; MERGE: !{!"branch_weights", i32 10}
104105
; MERGE: name: "sub"
105106
; MERGE-NEXT: {!"function_entry_count", i64 3}
107+
108+
; FLATTEN: name: "sum"
109+
; FLATTEN-NEXT: {!"function_entry_count", i64 35}
110+
; FLATTEN: !{!"branch_weights", i32 13, i32 23}
111+
; FLATTEN: !{!"branch_weights", i32 12}
112+
; FLATTEN: name: "sub"
113+
; FLATTEN-NEXT: {!"function_entry_count", i64 3}

0 commit comments

Comments
 (0)