Skip to content

[BOLT] Report input staleness #79496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions bolt/lib/Passes/BinaryPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1417,26 +1417,28 @@ void PrintProgramStats::runOnFunctions(BinaryContext &BC) {
<< (NumNonSimpleProfiledFunctions == 1 ? "" : "s")
<< " with profile could not be optimized\n";
}
if (NumStaleProfileFunctions) {
if (NumAllStaleFunctions) {
const float PctStale =
NumStaleProfileFunctions / (float)NumAllProfiledFunctions * 100.0f;
NumAllStaleFunctions / (float)NumAllProfiledFunctions * 100.0f;
auto printErrorOrWarning = [&]() {
if (PctStale > opts::StaleThreshold)
errs() << "BOLT-ERROR: ";
else
errs() << "BOLT-WARNING: ";
};
printErrorOrWarning();
errs() << NumStaleProfileFunctions
errs() << NumAllStaleFunctions
<< format(" (%.1f%% of all profiled)", PctStale) << " function"
<< (NumStaleProfileFunctions == 1 ? "" : "s")
<< (NumAllStaleFunctions == 1 ? "" : "s")
<< " have invalid (possibly stale) profile."
" Use -report-stale to see the list.\n";
if (TotalSampleCount > 0) {
printErrorOrWarning();
errs() << StaleSampleCount << " out of " << TotalSampleCount
<< " samples in the binary ("
<< format("%.1f", ((100.0f * StaleSampleCount) / TotalSampleCount))
errs() << (StaleSampleCount + InferredSampleCount) << " out of "
<< TotalSampleCount << " samples in the binary ("
<< format("%.1f",
((100.0f * (StaleSampleCount + InferredSampleCount)) /
TotalSampleCount))
<< "%) belong to functions with invalid"
" (possibly stale) profile.\n";
}
Expand Down
9 changes: 9 additions & 0 deletions bolt/test/X86/reader-stale-yaml.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

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

CHECK0: BOLT-INFO: 2 out of 7 functions in the binary (28.6%) have non-empty execution profile
CHECK0: BOLT-WARNING: 2 (100.0% of all profiled) functions have invalid (possibly stale) profile
CHECK0: BOLT-WARNING: 1192 out of 1192 samples in the binary (100.0%) belong to functions with invalid (possibly stale) profile

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


Expand Down