Skip to content

Commit 4bb6bbb

Browse files
committed
[CSSPGO] Skip reporting staleness metrics for imported functions
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
1 parent 3365cd4 commit 4bb6bbb

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

llvm/lib/Transforms/IPO/SampleProfile.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2415,7 +2415,9 @@ void SampleProfileMatcher::runOnFunction(const Function &F) {
24152415
findProfileAnchors(*FSFlattened, ProfileAnchors);
24162416

24172417
// Detect profile mismatch for profile staleness metrics report.
2418-
if (ReportProfileStaleness || PersistProfileStaleness) {
2418+
// Skip reporting the metrics for imported functions.
2419+
if (!GlobalValue::isAvailableExternallyLinkage(F.getLinkage()) &&
2420+
(ReportProfileStaleness || PersistProfileStaleness)) {
24192421
// Use top-level nested FS for counting profile mismatch metrics since
24202422
// currently once a callsite is mismatched, all its children profiles are
24212423
// dropped.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ main:6822:0
2323
!CFGChecksum: 1125988587804525
2424
bar:2401:2401
2525
1: 2401
26-
!CFGChecksum: 4294967295
26+
# Orignal CFGChecksum is 4294967295
27+
!CFGChecksum: 123
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; REQUIRES: x86_64-linux
2+
; 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
3+
; RUN: FileCheck %s --input-file %t
4+
; RUN: FileCheck %s --input-file %t.ll -check-prefix=CHECK-MD
5+
6+
; CHECK: (1/1) of functions' profile are invalid and (6822/6822) of samples are discarded due to function hash mismatch.
7+
; CHECK: (4/4) of callsites' profile are invalid and (5026/5026) of samples are discarded due to callsite location mismatch.
8+
9+
10+
; 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 commit comments

Comments
 (0)