Skip to content

Commit

Permalink
[CSSPGO] Skip reporting staleness metrics for imported functions
Browse files Browse the repository at this point in the history
Accumulating the staleness metrics from per-link is less accurate than doing it from post-link time(assuming we use the offline profile mismatch as baseline), the reason is that there are some duplicated reports for the same functions, for example, one template function could be included in multiple TUs, but in post thin link time, only one function are kept(linkonce_odr) and others are marked as available-externally function. Hence, this change skips reporting the metrics for imported functions(available-externally).

I saw the post-link number is now very close to the offline number(dump the mismatched functions and count the metrics offline based on the entire profile), sightly smaller than offline number due to some missing inlined functions.

Reviewed By: hoy, wenlei

Differential Revision: https://reviews.llvm.org/D156725
  • Loading branch information
wlei-llvm committed Aug 31, 2023
1 parent 3365cd4 commit 4bb6bbb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion llvm/lib/Transforms/IPO/SampleProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2415,7 +2415,9 @@ void SampleProfileMatcher::runOnFunction(const Function &F) {
findProfileAnchors(*FSFlattened, ProfileAnchors);

// Detect profile mismatch for profile staleness metrics report.
if (ReportProfileStaleness || PersistProfileStaleness) {
// Skip reporting the metrics for imported functions.
if (!GlobalValue::isAvailableExternallyLinkage(F.getLinkage()) &&
(ReportProfileStaleness || PersistProfileStaleness)) {
// Use top-level nested FS for counting profile mismatch metrics since
// currently once a callsite is mismatched, all its children profiles are
// dropped.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ main:6822:0
!CFGChecksum: 1125988587804525
bar:2401:2401
1: 2401
!CFGChecksum: 4294967295
# Orignal CFGChecksum is 4294967295
!CFGChecksum: 123
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; REQUIRES: x86_64-linux
; RUN: opt < %S/pseudo-probe-stale-profile-matching-lto.ll -passes='thinlto<O2>' -pgo-kind=pgo-sample-use-pipeline -sample-profile-file=%S/Inputs/pseudo-probe-stale-profile-matching-lto.prof -report-profile-staleness -persist-profile-staleness -S 2>%t -o %t.ll
; RUN: FileCheck %s --input-file %t
; RUN: FileCheck %s --input-file %t.ll -check-prefix=CHECK-MD

; CHECK: (1/1) of functions' profile are invalid and (6822/6822) of samples are discarded due to function hash mismatch.
; CHECK: (4/4) of callsites' profile are invalid and (5026/5026) of samples are discarded due to callsite location mismatch.


; CHECK-MD: ![[#]] = !{!"NumMismatchedFuncHash", i64 1, !"TotalProfiledFunc", i64 1, !"MismatchedFuncHashSamples", i64 6822, !"TotalFuncHashSamples", i64 6822, !"NumMismatchedCallsites", i64 4, !"TotalProfiledCallsites", i64 4, !"MismatchedCallsiteSamples", i64 5026, !"TotalCallsiteSamples", i64 5026}

0 comments on commit 4bb6bbb

Please sign in to comment.