[llvm] 4bb6bbb - [CSSPGO] Skip reporting staleness metrics for imported functions

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 30 18:01:41 PDT 2023


Author: wlei
Date: 2023-08-30T18:00:23-07:00
New Revision: 4bb6bbb9bf76b3314b91e146bcebd32cb0f7b567

URL: https://github.com/llvm/llvm-project/commit/4bb6bbb9bf76b3314b91e146bcebd32cb0f7b567
DIFF: https://github.com/llvm/llvm-project/commit/4bb6bbb9bf76b3314b91e146bcebd32cb0f7b567.diff

LOG: [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

Added: 
    llvm/test/Transforms/SampleProfile/pseudo-probe-profile-mismatch-thinlto.ll

Modified: 
    llvm/lib/Transforms/IPO/SampleProfile.cpp
    llvm/test/Transforms/SampleProfile/Inputs/pseudo-probe-stale-profile-matching-lto.prof

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index 45e2465ee4003f..3af44b28fec3a3 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -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.

diff  --git a/llvm/test/Transforms/SampleProfile/Inputs/pseudo-probe-stale-profile-matching-lto.prof b/llvm/test/Transforms/SampleProfile/Inputs/pseudo-probe-stale-profile-matching-lto.prof
index 9d3388eae0b322..c4b0e6dec74efe 100644
--- a/llvm/test/Transforms/SampleProfile/Inputs/pseudo-probe-stale-profile-matching-lto.prof
+++ b/llvm/test/Transforms/SampleProfile/Inputs/pseudo-probe-stale-profile-matching-lto.prof
@@ -23,4 +23,5 @@ main:6822:0
  !CFGChecksum: 1125988587804525
 bar:2401:2401
  1: 2401
- !CFGChecksum: 4294967295
+# Orignal CFGChecksum is 4294967295
+ !CFGChecksum: 123

diff  --git a/llvm/test/Transforms/SampleProfile/pseudo-probe-profile-mismatch-thinlto.ll b/llvm/test/Transforms/SampleProfile/pseudo-probe-profile-mismatch-thinlto.ll
new file mode 100644
index 00000000000000..29c3a142cc68f8
--- /dev/null
+++ b/llvm/test/Transforms/SampleProfile/pseudo-probe-profile-mismatch-thinlto.ll
@@ -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}


        


More information about the llvm-commits mailing list