-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[BOLT] Ignore returns in DataAggregator #90807
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
[BOLT] Ignore returns in DataAggregator #90807
Conversation
Created using spr 1.3.4 [skip ci]
Created using spr 1.3.4
@llvm/pr-subscribers-bolt Author: Amir Ayupov (aaupov) ChangesReturns are ignored in perf/pre-aggregated/fdata profile reader (see To make returns ignored for YAML produced in BAT mode, we can:
The first option is prone to profile staleness issue, where the profiled The second option is more robust but requires disassembling the Test Plan: Updated bolt-address-translation-yaml.test Full diff: https://github.com/llvm/llvm-project/pull/90807.diff 2 Files Affected:
diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp
index 5108392c824c10..0fd6579517e8f6 100644
--- a/bolt/lib/Profile/DataAggregator.cpp
+++ b/bolt/lib/Profile/DataAggregator.cpp
@@ -773,9 +773,13 @@ bool DataAggregator::doInterBranch(BinaryFunction *FromFunc,
bool DataAggregator::doBranch(uint64_t From, uint64_t To, uint64_t Count,
uint64_t Mispreds) {
+ bool IsReturn = false;
auto handleAddress = [&](uint64_t &Addr, bool IsFrom) -> BinaryFunction * {
if (BinaryFunction *Func = getBinaryFunctionContainingAddress(Addr)) {
Addr -= Func->getAddress();
+ if (Func->hasInstructions())
+ if (const MCInst *Inst = Func->getInstructionAtOffset(Addr))
+ IsReturn = BC->MIB->isReturn(*Inst);
if (BAT)
Addr = BAT->translate(Func->getAddress(), Addr, IsFrom);
@@ -792,6 +796,9 @@ bool DataAggregator::doBranch(uint64_t From, uint64_t To, uint64_t Count,
};
BinaryFunction *FromFunc = handleAddress(From, /*IsFrom=*/true);
+ // Ignore returns.
+ if (IsReturn)
+ return true;
BinaryFunction *ToFunc = handleAddress(To, /*IsFrom=*/false);
if (!FromFunc && !ToFunc)
return false;
diff --git a/bolt/test/X86/bolt-address-translation-yaml.test b/bolt/test/X86/bolt-address-translation-yaml.test
index af24c3d84a0f15..b3d8a88394503c 100644
--- a/bolt/test/X86/bolt-address-translation-yaml.test
+++ b/bolt/test/X86/bolt-address-translation-yaml.test
@@ -13,7 +13,7 @@ RUN: llvm-bolt %t.exe -data %t.fdata -w %t.yaml-fdata -o /dev/null
RUN: FileCheck --input-file %t.yaml-fdata --check-prefix YAML-BAT-CHECK %s
# Test resulting YAML profile with the original binary (no-stale mode)
-RUN: llvm-bolt %t.exe -data %t.yaml -o %t.null -dyno-stats \
+RUN: llvm-bolt %t.exe -data %t.yaml -o %t.null -dyno-stats 2>&1 \
RUN: | FileCheck --check-prefix CHECK-BOLT-YAML %s
WRITE-BAT-CHECK: BOLT-INFO: Wrote 5 BAT maps
@@ -63,7 +63,8 @@ YAML-BAT-CHECK-NEXT: blocks:
YAML-BAT-CHECK: - bid: 1
YAML-BAT-CHECK-NEXT: insns: [[#]]
YAML-BAT-CHECK-NEXT: hash: 0xD70DC695320E0010
-YAML-BAT-CHECK-NEXT: succ: {{.*}} { bid: 2, cnt: [[#]] }
+YAML-BAT-CHECK-NEXT: succ: {{.*}} { bid: 2, cnt: [[#]]
CHECK-BOLT-YAML: pre-processing profile using YAML profile reader
CHECK-BOLT-YAML-NEXT: 5 out of 16 functions in the binary (31.2%) have non-empty execution profile
+CHECK-BOLT-YAML-NOT: invalid (possibly stale) profile
|
Created using spr 1.3.4 [skip ci]
Created using spr 1.3.4
Created using spr 1.3.4
Created using spr 1.3.4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address the nits. Otherwise - good to go.
bolt/lib/Core/BinaryFunction.cpp
Outdated
@@ -1167,6 +1167,21 @@ void BinaryFunction::handleAArch64IndirectCall(MCInst &Instruction, | |||
} | |||
} | |||
|
|||
std::optional<MCInst> | |||
BinaryFunction::disassembleInstructionAtOffset(uint64_t Offset) const { | |||
assert(CurrentState == State::Empty); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add message.
bolt/lib/Core/BinaryFunction.cpp
Outdated
std::optional<MCInst> | ||
BinaryFunction::disassembleInstructionAtOffset(uint64_t Offset) const { | ||
assert(CurrentState == State::Empty); | ||
assert(Offset < MaxSize && "invalid offset"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: capitalize the message.
bolt/lib/Core/BinaryFunction.cpp
Outdated
assert(CurrentState == State::Empty); | ||
assert(Offset < MaxSize && "invalid offset"); | ||
ErrorOr<ArrayRef<unsigned char>> FunctionData = getData(); | ||
assert(FunctionData && "cannot get function as data"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: ditto.
Created using spr 1.3.4
Created using spr 1.3.4
Returns are ignored in perf/pre-aggregated/fdata profile reader (see
DataReader::convertBranchData). They are also omitted in
YAMLProfileWriter by virtue of not having the profile attached to them
in the reader, and YAMLProfileWriter converting the profile attached to
BinaryFunctions. Thus, return profile is universally ignored across all
profile types except BAT YAML.
To make returns ignored for YAML produced in BAT mode, we can:
The first option is prone to profile staleness issue, where the profiled
binary doesn't match the one to be optimized, and thus returns in the
profile can no longer be reliably detected (as we don't distinguish them
from calls in the profile).
The second option is robust to staleness but requires disassembling the
branch source instruction.
Test Plan: Updated bolt-address-translation-yaml.test