Skip to content

Commit a9b6749

Browse files
authored
[BOLT] Report adjusted program stats from perf2bolt in BAT mode (llvm#91683)
1 parent f0d1ae8 commit a9b6749

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

bolt/include/bolt/Passes/BinaryPasses.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "bolt/Core/BinaryContext.h"
1717
#include "bolt/Core/BinaryFunction.h"
1818
#include "bolt/Core/DynoStats.h"
19+
#include "bolt/Profile/BoltAddressTranslation.h"
1920
#include "llvm/Support/CommandLine.h"
2021
#include <atomic>
2122
#include <set>
@@ -399,8 +400,11 @@ class PrintProfileStats : public BinaryFunctionPass {
399400
/// Prints a list of the top 100 functions sorted by a set of
400401
/// dyno stats categories.
401402
class PrintProgramStats : public BinaryFunctionPass {
403+
BoltAddressTranslation *BAT = nullptr;
404+
402405
public:
403-
explicit PrintProgramStats() : BinaryFunctionPass(false) {}
406+
explicit PrintProgramStats(BoltAddressTranslation *BAT = nullptr)
407+
: BinaryFunctionPass(false), BAT(BAT) {}
404408

405409
const char *getName() const override { return "print-stats"; }
406410
bool shouldPrint(const BinaryFunction &) const override { return false; }

bolt/lib/Passes/BinaryPasses.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1390,9 +1390,19 @@ Error PrintProgramStats::runOnFunctions(BinaryContext &BC) {
13901390
if (Function.isPLTFunction())
13911391
continue;
13921392

1393+
// Adjustment for BAT mode: the profile for BOLT split fragments is combined
1394+
// so only count the hot fragment.
1395+
const uint64_t Address = Function.getAddress();
1396+
bool IsHotParentOfBOLTSplitFunction = !Function.getFragments().empty() &&
1397+
BAT && BAT->isBATFunction(Address) &&
1398+
!BAT->fetchParentAddress(Address);
1399+
13931400
++NumRegularFunctions;
13941401

1395-
if (!Function.isSimple()) {
1402+
// In BOLTed binaries split functions are non-simple (due to non-relocation
1403+
// mode), but the original function is known to be simple and we have a
1404+
// valid profile for it.
1405+
if (!Function.isSimple() && !IsHotParentOfBOLTSplitFunction) {
13961406
if (Function.hasProfile())
13971407
++NumNonSimpleProfiledFunctions;
13981408
continue;

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,8 @@ Error DataAggregator::readProfile(BinaryContext &BC) {
613613
if (std::error_code EC = writeBATYAML(BC, opts::SaveProfile))
614614
report_error("cannot create output data file", EC);
615615
}
616-
BC.logBOLTErrorsAndQuitOnFatal(PrintProgramStats().runOnFunctions(BC));
616+
PrintProgramStats PPS(BAT);
617+
BC.logBOLTErrorsAndQuitOnFatal(PPS.runOnFunctions(BC));
617618
}
618619

619620
return Error::success();

bolt/test/X86/bolt-address-translation-yaml.test

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ RUN: perf2bolt %t.out --pa -p %p/Inputs/blarge_new_bat.preagg.txt -w %t.yaml -o
3131
RUN: 2>&1 | FileCheck --check-prefix READ-BAT-CHECK %s
3232
RUN: FileCheck --input-file %t.yaml --check-prefix YAML-BAT-CHECK %s
3333
# Check that YAML converted from fdata matches YAML created directly with BAT.
34-
RUN: llvm-bolt %t.exe -data %t.fdata -w %t.yaml-fdata -o /dev/null
34+
RUN: llvm-bolt %t.exe -data %t.fdata -w %t.yaml-fdata -o /dev/null \
35+
RUN: 2>&1 | FileCheck --check-prefix READ-BAT-FDATA-CHECK %s
3536
RUN: FileCheck --input-file %t.yaml-fdata --check-prefix YAML-BAT-CHECK %s
3637

3738
# Test resulting YAML profile with the original binary (no-stale mode)
@@ -45,6 +46,8 @@ WRITE-BAT-CHECK: BOLT-INFO: BAT section size (bytes): 384
4546
READ-BAT-CHECK-NOT: BOLT-ERROR: unable to save profile in YAML format for input file processed by BOLT
4647
READ-BAT-CHECK: BOLT-INFO: Parsed 5 BAT entries
4748
READ-BAT-CHECK: PERF2BOLT: read 79 aggregated LBR entries
49+
READ-BAT-CHECK: BOLT-INFO: 5 out of 21 functions in the binary (23.8%) have non-empty execution profile
50+
READ-BAT-FDATA-CHECK: BOLT-INFO: 5 out of 16 functions in the binary (31.2%) have non-empty execution profile
4851

4952
YAML-BAT-CHECK: functions:
5053
# Function not covered by BAT - has insns in basic block

0 commit comments

Comments
 (0)