Skip to content
13 changes: 10 additions & 3 deletions bolt/lib/Passes/ProfileQualityStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ void printCFGContinuityStats(raw_ostream &OS,
FractionECUnreachables.push_back(FractionECUnreachable);
}

if (FractionECUnreachables.empty())
if (FractionECUnreachables.empty()) {
OS << "function CFG discontinuity 0.00%; ";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is due to single-BB functions, right? Can we just assume the discontinuity is 0 for them, instead of skipping in L94-95? And apply a similar logic to other metrics.

return;
}

llvm::sort(FractionECUnreachables);
const int Rank = int(FractionECUnreachables.size() *
Expand Down Expand Up @@ -251,8 +253,10 @@ void printCallGraphFlowConservationStats(
}
}

if (CallGraphGaps.empty())
if (CallGraphGaps.empty()) {
OS << "call graph flow conservation gap 0.00%; ";
return;
}

llvm::sort(CallGraphGaps);
const int Rank =
Expand Down Expand Up @@ -340,8 +344,11 @@ void printCFGFlowConservationStats(raw_ostream &OS,
}
}

if (CFGGapsWeightedAvg.empty())
if (CFGGapsWeightedAvg.empty()) {
OS << "CFG flow conservation gap 0.00% (weighted) 0.00% (worst)\n";
return;
}

llvm::sort(CFGGapsWeightedAvg);
const int RankWA = int(CFGGapsWeightedAvg.size() *
opts::PercentileForProfileQualityCheck / 100);
Expand Down
35 changes: 35 additions & 0 deletions bolt/test/X86/profile-quality-reporting-small-binary.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Test that BOLT-INFO is correctly formatted after profile quality reporting for
## a small binary.

# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %s -o %t.o
# RUN: link_fdata %s %t.o %t.fdata
# RUN: llvm-strip --strip-unneeded %t.o
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
# RUN: llvm-bolt %t.exe -o %t.bolt --data=%t.fdata \
# RUN: 2>&1 | FileCheck %s

# CHECK: BOLT-INFO: profile quality metrics for the hottest 2 functions (reporting top 5% values): function CFG discontinuity 0.00%; call graph flow conservation gap 0.00%; CFG flow conservation gap 0.00% (weighted) 0.00% (worst)
# CHECK-NEXT: BOLT-INFO:

.text
.globl func
.type func, @function
func:
pushq %rbp
ret
LLfunc_end:
.size func, LLfunc_end-func


.globl main
.type main, @function
main:
pushq %rbp
movq %rsp, %rbp
LLmain_func:
call func
# FDATA: 1 main #LLmain_func# 1 func 0 0 500
movl $4, %edi
retq
.Lmain_end:
.size main, .Lmain_end-main