Skip to content

Commit e9309b2

Browse files
authored
[BOLT] Report input staleness (#79496)
It's beneficial to have uniform reporting in both `infer-stale-profile` on and off cases, primarily for logging purposes. Without this change, BOLT would report "input" staleness in `infer-stale-profile=0` case (without matching), and "output" staleness in `infer-stale-profile=1` case (after matching). This change makes BOLT report "input" staleness in both cases. "Output" staleness information is printed separately with "BOLT-INFO: inferred profile..."
1 parent 887783e commit e9309b2

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

bolt/lib/Passes/BinaryPasses.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,26 +1417,28 @@ void PrintProgramStats::runOnFunctions(BinaryContext &BC) {
14171417
<< (NumNonSimpleProfiledFunctions == 1 ? "" : "s")
14181418
<< " with profile could not be optimized\n";
14191419
}
1420-
if (NumStaleProfileFunctions) {
1420+
if (NumAllStaleFunctions) {
14211421
const float PctStale =
1422-
NumStaleProfileFunctions / (float)NumAllProfiledFunctions * 100.0f;
1422+
NumAllStaleFunctions / (float)NumAllProfiledFunctions * 100.0f;
14231423
auto printErrorOrWarning = [&]() {
14241424
if (PctStale > opts::StaleThreshold)
14251425
errs() << "BOLT-ERROR: ";
14261426
else
14271427
errs() << "BOLT-WARNING: ";
14281428
};
14291429
printErrorOrWarning();
1430-
errs() << NumStaleProfileFunctions
1430+
errs() << NumAllStaleFunctions
14311431
<< format(" (%.1f%% of all profiled)", PctStale) << " function"
1432-
<< (NumStaleProfileFunctions == 1 ? "" : "s")
1432+
<< (NumAllStaleFunctions == 1 ? "" : "s")
14331433
<< " have invalid (possibly stale) profile."
14341434
" Use -report-stale to see the list.\n";
14351435
if (TotalSampleCount > 0) {
14361436
printErrorOrWarning();
1437-
errs() << StaleSampleCount << " out of " << TotalSampleCount
1438-
<< " samples in the binary ("
1439-
<< format("%.1f", ((100.0f * StaleSampleCount) / TotalSampleCount))
1437+
errs() << (StaleSampleCount + InferredSampleCount) << " out of "
1438+
<< TotalSampleCount << " samples in the binary ("
1439+
<< format("%.1f",
1440+
((100.0f * (StaleSampleCount + InferredSampleCount)) /
1441+
TotalSampleCount))
14401442
<< "%) belong to functions with invalid"
14411443
" (possibly stale) profile.\n";
14421444
}

bolt/test/X86/reader-stale-yaml.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
REQUIRES: asserts
55
RUN: yaml2obj %p/Inputs/blarge.yaml &> %t.exe
6+
RUN: llvm-bolt %t.exe -o %t.null --b %p/Inputs/blarge_profile_stale.yaml \
7+
RUN: --infer-stale-profile=0 --profile-ignore-hash=1 --profile-use-dfs=0 \
8+
RUN: 2>&1 | FileCheck %s -check-prefix=CHECK0
69
# Testing "usqrt"
710
RUN: llvm-bolt %t.exe -o %t.null --b %p/Inputs/blarge_profile_stale.yaml \
811
RUN: --print-cfg --print-only=usqrt --infer-stale-profile=1 \
@@ -12,6 +15,10 @@ RUN: llvm-bolt %t.exe -o %t.null --b %p/Inputs/blarge_profile_stale.yaml \
1215
RUN: --print-cfg --print-only=SolveCubic --infer-stale-profile=1 \
1316
RUN: --profile-ignore-hash=1 --profile-use-dfs=0 --debug-only=bolt-prof 2>&1 | FileCheck %s -check-prefix=CHECK2
1417

18+
CHECK0: BOLT-INFO: 2 out of 7 functions in the binary (28.6%) have non-empty execution profile
19+
CHECK0: BOLT-WARNING: 2 (100.0% of all profiled) functions have invalid (possibly stale) profile
20+
CHECK0: BOLT-WARNING: 1192 out of 1192 samples in the binary (100.0%) belong to functions with invalid (possibly stale) profile
21+
1522
# Function "usqrt" has stale profile, since the number of blocks in the profile
1623
# (nblocks=6) does not match the size of the CFG in the binary. The entry
1724
# block (bid=0) has an incorrect (missing) count, which should be inferred by
@@ -51,6 +58,8 @@ CHECK1: Successors: .Ltmp[[#BB13:]] (mispreds: 0, count: 300), .LFT[[#BB1:]
5158
CHECK1: .LFT[[#BB1:]] (2 instructions, align : 1)
5259
# Check the overall inference stats.
5360
CHECK1: 2 out of 7 functions in the binary (28.6%) have non-empty execution profile
61+
CHECK1: BOLT-WARNING: 2 (100.0% of all profiled) functions have invalid (possibly stale) profile
62+
CHECK1: BOLT-WARNING: 1192 out of 1192 samples in the binary (100.0%) belong to functions with invalid (possibly stale) profile
5463
CHECK1: inferred profile for 2 (100.00% of profiled, 100.00% of stale) functions responsible for {{.*}} samples ({{.*}} out of {{.*}})
5564

5665

0 commit comments

Comments
 (0)