Skip to content

Commit

Permalink
[SamplePGO] Handle FS discriminators in SampleProfileMatcher (#90858)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
amharc authored May 2, 2024
1 parent 5445a35 commit e06d6ed
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ void SampleProfileMatcher::findIRAnchors(
DIL = DIL->getInlinedAt();
} while (DIL->getInlinedAt());

LineLocation Callsite = FunctionSamples::getCallSiteIdentifier(DIL);
LineLocation Callsite = FunctionSamples::getCallSiteIdentifier(
DIL, FunctionSamples::ProfileIsFS);
StringRef CalleeName = PrevDIL->getSubprogramLinkageName();
return std::make_pair(Callsite, CalleeName);
};
Expand Down Expand Up @@ -82,7 +83,8 @@ void SampleProfileMatcher::findIRAnchors(
if (DIL->getInlinedAt()) {
IRAnchors.emplace(FindTopLevelInlinedCallsite(DIL));
} else {
LineLocation Callsite = FunctionSamples::getCallSiteIdentifier(DIL);
LineLocation Callsite = FunctionSamples::getCallSiteIdentifier(
DIL, FunctionSamples::ProfileIsFS);
StringRef CalleeName = GetCanonicalCalleeName(dyn_cast<CallBase>(&I));
IRAnchors.emplace(Callsite, CalleeName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ main:9229397:0
7: 0
2: foo:1479916
1: 47663
1.1: 46683 bar:43238
1.15: 46683 bar:43238
2: 4519 bar:4932
3: 48723
4: foo:1505537
1: 48604
1.1: 46965 bar:44479
1.15: 46965 bar:44479
2: 4613 bar:4967
3: 49087
bar:2333388:196222
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; REQUIRES: x86_64-linux
; REQUIRES: asserts
; 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
; 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

; The profiled source code:

Expand Down Expand Up @@ -51,7 +51,7 @@
; CHECK: Run stale profile matching for bar

; CHECK: Run stale profile matching for foo
; CHECK: Callsite with callee:bar is matched from 1.1 to 1.1
; CHECK: Callsite with callee:bar is matched from 1.15 to 1.15
; CHECK: Callsite with callee:bar is matched from 2 to 2

; CHECK: Run stale profile matching for main
Expand Down Expand Up @@ -183,7 +183,7 @@ attributes #3 = { mustprogress nocallback nofree nosync nounwind willreturn memo
!15 = !DILocation(line: 7, column: 9, scope: !14)
!16 = !DILocation(line: 7, column: 7, scope: !14)
!17 = !DILocation(line: 7, column: 23, scope: !18)
!18 = !DILexicalBlockFile(scope: !14, file: !10, discriminator: 2)
!18 = !DILexicalBlockFile(scope: !14, file: !10, discriminator: 15)
!19 = !DILocation(line: 7, column: 15, scope: !18)
!20 = !DILocation(line: 8, column: 21, scope: !14)
!21 = !DILocation(line: 8, column: 15, scope: !14)
Expand All @@ -201,7 +201,7 @@ attributes #3 = { mustprogress nocallback nofree nosync nounwind willreturn memo
!33 = !DILocation(line: 14, column: 8, scope: !25)
!34 = !DILocation(line: 14, scope: !25)
!35 = !DILocation(line: 14, column: 21, scope: !36)
!36 = !DILexicalBlockFile(scope: !25, file: !10, discriminator: 2)
!36 = !DILexicalBlockFile(scope: !25, file: !10, discriminator: 15)
!37 = !DILocation(line: 14, column: 3, scope: !36)
!38 = !DILocation(line: 14, column: 3, scope: !39)
!39 = !DILexicalBlockFile(scope: !25, file: !10, discriminator: 4)
Expand Down

0 comments on commit e06d6ed

Please sign in to comment.