Skip to content

Commit f567524

Browse files
authored
[BOLT] Fix doTrace in BAT mode (llvm#128546)
When processing BOLTed binaries with BAT section, we used to indiscriminately use `BAT->getFallthroughsInTrace` to record fall-throughs, even if the function is not covered by BAT. Fix that by using non-BAT CFG-based `getFallthroughsInTrace` if the function is not in BAT. Test Plan: updated bolt-address-translation-yaml.test
1 parent 3968ebd commit f567524

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,9 +831,10 @@ bool DataAggregator::doTrace(const LBREntry &First, const LBREntry &Second,
831831
ParentFunc = FromFunc;
832832
ParentFunc->SampleCountInBytes += Count * (Second.From - First.To);
833833

834+
const uint64_t FuncAddress = FromFunc->getAddress();
834835
std::optional<BoltAddressTranslation::FallthroughListTy> FTs =
835-
BAT ? BAT->getFallthroughsInTrace(FromFunc->getAddress(), First.To,
836-
Second.From)
836+
BAT && BAT->isBATFunction(FuncAddress)
837+
? BAT->getFallthroughsInTrace(FuncAddress, First.To, Second.From)
837838
: getFallthroughsInTrace(*FromFunc, First, Second, Count);
838839
if (!FTs) {
839840
LLVM_DEBUG(

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ YAML-BAT-CHECK-NEXT: - bid: 0
6161
YAML-BAT-CHECK-NEXT: insns: 26
6262
YAML-BAT-CHECK-NEXT: hash: 0xA900AE79CFD40000
6363
YAML-BAT-CHECK-NEXT: succ: [ { bid: 3, cnt: 0 }, { bid: 1, cnt: 0 } ]
64+
# Check fallthroughs in non-BAT function
65+
YAML-BAT-CHECK-NEXT: - bid: 27
66+
YAML-BAT-CHECK-NEXT: insns: 3
67+
YAML-BAT-CHECK-NEXT: hash: 0x30A1EBA77A903F0
68+
YAML-BAT-CHECK-NEXT: succ: [ { bid: 28, cnt: 1 } ]
6469
# Calls from no-BAT to BAT function
6570
YAML-BAT-CHECK: - bid: 28
6671
YAML-BAT-CHECK-NEXT: insns: 13

0 commit comments

Comments
 (0)