aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmir Ayupov <aaupov@fb.com>2024-05-21 18:54:15 -0700
committerGitHub <noreply@github.com>2024-05-21 18:54:15 -0700
commita9b67490b2baaa311100a64191792186ea5f2c1e (patch)
tree3b48b7bc13e84556aa5d9b52e720ad7f32eb86af
parentf0d1ae83b046ff0eeffc72a103f7c8b01ad33787 (diff)
downloadllvm-a9b67490b2baaa311100a64191792186ea5f2c1e.zip
llvm-a9b67490b2baaa311100a64191792186ea5f2c1e.tar.gz
llvm-a9b67490b2baaa311100a64191792186ea5f2c1e.tar.bz2
[BOLT] Report adjusted program stats from perf2bolt in BAT mode (#91683)
-rw-r--r--bolt/include/bolt/Passes/BinaryPasses.h6
-rw-r--r--bolt/lib/Passes/BinaryPasses.cpp12
-rw-r--r--bolt/lib/Profile/DataAggregator.cpp3
-rw-r--r--bolt/test/X86/bolt-address-translation-yaml.test5
4 files changed, 22 insertions, 4 deletions
diff --git a/bolt/include/bolt/Passes/BinaryPasses.h b/bolt/include/bolt/Passes/BinaryPasses.h
index 5d76925..a07c913 100644
--- a/bolt/include/bolt/Passes/BinaryPasses.h
+++ b/bolt/include/bolt/Passes/BinaryPasses.h
@@ -16,6 +16,7 @@
#include "bolt/Core/BinaryContext.h"
#include "bolt/Core/BinaryFunction.h"
#include "bolt/Core/DynoStats.h"
+#include "bolt/Profile/BoltAddressTranslation.h"
#include "llvm/Support/CommandLine.h"
#include <atomic>
#include <set>
@@ -399,8 +400,11 @@ public:
/// Prints a list of the top 100 functions sorted by a set of
/// dyno stats categories.
class PrintProgramStats : public BinaryFunctionPass {
+ BoltAddressTranslation *BAT = nullptr;
+
public:
- explicit PrintProgramStats() : BinaryFunctionPass(false) {}
+ explicit PrintProgramStats(BoltAddressTranslation *BAT = nullptr)
+ : BinaryFunctionPass(false), BAT(BAT) {}
const char *getName() const override { return "print-stats"; }
bool shouldPrint(const BinaryFunction &) const override { return false; }
diff --git a/bolt/lib/Passes/BinaryPasses.cpp b/bolt/lib/Passes/BinaryPasses.cpp
index 298ba29..11e22de 100644
--- a/bolt/lib/Passes/BinaryPasses.cpp
+++ b/bolt/lib/Passes/BinaryPasses.cpp
@@ -1390,9 +1390,19 @@ Error PrintProgramStats::runOnFunctions(BinaryContext &BC) {
if (Function.isPLTFunction())
continue;
+ // Adjustment for BAT mode: the profile for BOLT split fragments is combined
+ // so only count the hot fragment.
+ const uint64_t Address = Function.getAddress();
+ bool IsHotParentOfBOLTSplitFunction = !Function.getFragments().empty() &&
+ BAT && BAT->isBATFunction(Address) &&
+ !BAT->fetchParentAddress(Address);
+
++NumRegularFunctions;
- if (!Function.isSimple()) {
+ // In BOLTed binaries split functions are non-simple (due to non-relocation
+ // mode), but the original function is known to be simple and we have a
+ // valid profile for it.
+ if (!Function.isSimple() && !IsHotParentOfBOLTSplitFunction) {
if (Function.hasProfile())
++NumNonSimpleProfiledFunctions;
continue;
diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp
index f55caa7..efda493 100644
--- a/bolt/lib/Profile/DataAggregator.cpp
+++ b/bolt/lib/Profile/DataAggregator.cpp
@@ -613,7 +613,8 @@ Error DataAggregator::readProfile(BinaryContext &BC) {
if (std::error_code EC = writeBATYAML(BC, opts::SaveProfile))
report_error("cannot create output data file", EC);
}
- BC.logBOLTErrorsAndQuitOnFatal(PrintProgramStats().runOnFunctions(BC));
+ PrintProgramStats PPS(BAT);
+ BC.logBOLTErrorsAndQuitOnFatal(PPS.runOnFunctions(BC));
}
return Error::success();
diff --git a/bolt/test/X86/bolt-address-translation-yaml.test b/bolt/test/X86/bolt-address-translation-yaml.test
index e21513b..9f2c2ef 100644
--- a/bolt/test/X86/bolt-address-translation-yaml.test
+++ b/bolt/test/X86/bolt-address-translation-yaml.test
@@ -31,7 +31,8 @@ RUN: perf2bolt %t.out --pa -p %p/Inputs/blarge_new_bat.preagg.txt -w %t.yaml -o
RUN: 2>&1 | FileCheck --check-prefix READ-BAT-CHECK %s
RUN: FileCheck --input-file %t.yaml --check-prefix YAML-BAT-CHECK %s
# Check that YAML converted from fdata matches YAML created directly with BAT.
-RUN: llvm-bolt %t.exe -data %t.fdata -w %t.yaml-fdata -o /dev/null
+RUN: llvm-bolt %t.exe -data %t.fdata -w %t.yaml-fdata -o /dev/null \
+RUN: 2>&1 | FileCheck --check-prefix READ-BAT-FDATA-CHECK %s
RUN: FileCheck --input-file %t.yaml-fdata --check-prefix YAML-BAT-CHECK %s
# 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
READ-BAT-CHECK-NOT: BOLT-ERROR: unable to save profile in YAML format for input file processed by BOLT
READ-BAT-CHECK: BOLT-INFO: Parsed 5 BAT entries
READ-BAT-CHECK: PERF2BOLT: read 79 aggregated LBR entries
+READ-BAT-CHECK: BOLT-INFO: 5 out of 21 functions in the binary (23.8%) have non-empty execution profile
+READ-BAT-FDATA-CHECK: BOLT-INFO: 5 out of 16 functions in the binary (31.2%) have non-empty execution profile
YAML-BAT-CHECK: functions:
# Function not covered by BAT - has insns in basic block