Skip to content

Commit e06d6ed

Browse files
authored
[SamplePGO] Handle FS discriminators in SampleProfileMatcher (#90858)
Currently the code uses FunctionSamples::getCallSiteIdentifier which will sometimes incorrectly guess that FSAFDO discriminators are probe based and will convert them incorrectly. This change doesn't affect builds which don't use FSAFDO, it only fixes sample profile matching with FS discriminators. The test for this is manually updated to use discriminator value 15, which is a perfectly valid base discriminator in the FS world, but satisfies `isPseudoProbeDiscriminator`, so `getBaseDiscriminatorFromDiscriminator` will incorrectly extract the probe index from it. Note: this change only affects how the base discriminators will be extracted when doing stale profile matching in the IR-level sample profile loader. It doesn't add stale profile matching to the MIR-level FS profile loader pass.
1 parent 5445a35 commit e06d6ed

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ void SampleProfileMatcher::findIRAnchors(
3737
DIL = DIL->getInlinedAt();
3838
} while (DIL->getInlinedAt());
3939

40-
LineLocation Callsite = FunctionSamples::getCallSiteIdentifier(DIL);
40+
LineLocation Callsite = FunctionSamples::getCallSiteIdentifier(
41+
DIL, FunctionSamples::ProfileIsFS);
4142
StringRef CalleeName = PrevDIL->getSubprogramLinkageName();
4243
return std::make_pair(Callsite, CalleeName);
4344
};
@@ -82,7 +83,8 @@ void SampleProfileMatcher::findIRAnchors(
8283
if (DIL->getInlinedAt()) {
8384
IRAnchors.emplace(FindTopLevelInlinedCallsite(DIL));
8485
} else {
85-
LineLocation Callsite = FunctionSamples::getCallSiteIdentifier(DIL);
86+
LineLocation Callsite = FunctionSamples::getCallSiteIdentifier(
87+
DIL, FunctionSamples::ProfileIsFS);
8688
StringRef CalleeName = GetCanonicalCalleeName(dyn_cast<CallBase>(&I));
8789
IRAnchors.emplace(Callsite, CalleeName);
8890
}

llvm/test/Transforms/SampleProfile/Inputs/non-probe-stale-profile-matching.prof

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ main:9229397:0
1010
7: 0
1111
2: foo:1479916
1212
1: 47663
13-
1.1: 46683 bar:43238
13+
1.15: 46683 bar:43238
1414
2: 4519 bar:4932
1515
3: 48723
1616
4: foo:1505537
1717
1: 48604
18-
1.1: 46965 bar:44479
18+
1.15: 46965 bar:44479
1919
2: 4613 bar:4967
2020
3: 49087
2121
bar:2333388:196222

llvm/test/Transforms/SampleProfile/non-probe-stale-profile-matching.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; REQUIRES: x86_64-linux
22
; REQUIRES: asserts
3-
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/non-probe-stale-profile-matching.prof --salvage-stale-profile -S --debug-only=sample-profile,sample-profile-matcher,sample-profile-impl 2>&1 | FileCheck %s
3+
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/non-probe-stale-profile-matching.prof --salvage-stale-profile -S --debug-only=sample-profile,sample-profile-matcher,sample-profile-impl -profile-isfs 2>&1 | FileCheck %s
44

55
; The profiled source code:
66

@@ -51,7 +51,7 @@
5151
; CHECK: Run stale profile matching for bar
5252

5353
; CHECK: Run stale profile matching for foo
54-
; CHECK: Callsite with callee:bar is matched from 1.1 to 1.1
54+
; CHECK: Callsite with callee:bar is matched from 1.15 to 1.15
5555
; CHECK: Callsite with callee:bar is matched from 2 to 2
5656

5757
; CHECK: Run stale profile matching for main
@@ -183,7 +183,7 @@ attributes #3 = { mustprogress nocallback nofree nosync nounwind willreturn memo
183183
!15 = !DILocation(line: 7, column: 9, scope: !14)
184184
!16 = !DILocation(line: 7, column: 7, scope: !14)
185185
!17 = !DILocation(line: 7, column: 23, scope: !18)
186-
!18 = !DILexicalBlockFile(scope: !14, file: !10, discriminator: 2)
186+
!18 = !DILexicalBlockFile(scope: !14, file: !10, discriminator: 15)
187187
!19 = !DILocation(line: 7, column: 15, scope: !18)
188188
!20 = !DILocation(line: 8, column: 21, scope: !14)
189189
!21 = !DILocation(line: 8, column: 15, scope: !14)
@@ -201,7 +201,7 @@ attributes #3 = { mustprogress nocallback nofree nosync nounwind willreturn memo
201201
!33 = !DILocation(line: 14, column: 8, scope: !25)
202202
!34 = !DILocation(line: 14, scope: !25)
203203
!35 = !DILocation(line: 14, column: 21, scope: !36)
204-
!36 = !DILexicalBlockFile(scope: !25, file: !10, discriminator: 2)
204+
!36 = !DILexicalBlockFile(scope: !25, file: !10, discriminator: 15)
205205
!37 = !DILocation(line: 14, column: 3, scope: !36)
206206
!38 = !DILocation(line: 14, column: 3, scope: !39)
207207
!39 = !DILexicalBlockFile(scope: !25, file: !10, discriminator: 4)

0 commit comments

Comments
 (0)