Skip to content

[BOLT][NFCI] Skip validation in parseLBRSample #143288

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 8 additions & 44 deletions bolt/lib/Profile/DataAggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,10 @@ bool DataAggregator::doBranch(uint64_t From, uint64_t To, uint64_t Count,
// corresponds to a return (if \p IsFrom) or a call continuation (otherwise).
auto handleAddress = [&](uint64_t &Addr, bool IsFrom) {
BinaryFunction *Func = getBinaryFunctionContainingAddress(Addr);
if (!Func)
if (!Func) {
Addr = 0;
return std::pair{Func, false};
}

Addr -= Func->getAddress();

Expand Down Expand Up @@ -1432,54 +1434,16 @@ void DataAggregator::parseLBRSample(const PerfBranchSample &Sample,
const uint64_t TraceTo = NextLBR->From;
const BinaryFunction *TraceBF =
getBinaryFunctionContainingAddress(TraceFrom);
if (opts::HeatmapMode == opts::HeatmapModeKind::HM_Exclusive) {
FTInfo &Info = FallthroughLBRs[Trace(TraceFrom, TraceTo)];
FTInfo &Info = FallthroughLBRs[Trace(TraceFrom, TraceTo)];
if (TraceBF && TraceBF->containsAddress(LBR.From))
++Info.InternCount;
} else if (TraceBF && TraceBF->containsAddress(TraceTo)) {
FTInfo &Info = FallthroughLBRs[Trace(TraceFrom, TraceTo)];
if (TraceBF->containsAddress(LBR.From))
++Info.InternCount;
else
++Info.ExternCount;
} else {
const BinaryFunction *ToFunc =
getBinaryFunctionContainingAddress(TraceTo);
if (TraceBF && ToFunc) {
LLVM_DEBUG({
dbgs() << "Invalid trace starting in " << TraceBF->getPrintName()
<< formatv(" @ {0:x}", TraceFrom - TraceBF->getAddress())
<< formatv(" and ending @ {0:x}\n", TraceTo);
});
++NumInvalidTraces;
} else {
LLVM_DEBUG({
dbgs() << "Out of range trace starting in "
<< (TraceBF ? TraceBF->getPrintName() : "None")
<< formatv(" @ {0:x}",
TraceFrom - (TraceBF ? TraceBF->getAddress() : 0))
<< " and ending in "
<< (ToFunc ? ToFunc->getPrintName() : "None")
<< formatv(" @ {0:x}\n",
TraceTo - (ToFunc ? ToFunc->getAddress() : 0));
});
++NumLongRangeTraces;
}
}
else
++Info.ExternCount;
++NumTraces;
}
NextLBR = &LBR;

// Record branches outside binary functions for heatmap.
if (opts::HeatmapMode == opts::HeatmapModeKind::HM_Exclusive) {
TakenBranchInfo &Info = BranchLBRs[Trace(LBR.From, LBR.To)];
++Info.TakenCount;
continue;
}
uint64_t From = getBinaryFunctionContainingAddress(LBR.From) ? LBR.From : 0;
uint64_t To = getBinaryFunctionContainingAddress(LBR.To) ? LBR.To : 0;
if (!From && !To)
continue;
TakenBranchInfo &Info = BranchLBRs[Trace(From, To)];
TakenBranchInfo &Info = BranchLBRs[Trace(LBR.From, LBR.To)];
++Info.TakenCount;
Info.MispredCount += LBR.Mispred;
}
Expand Down
6 changes: 3 additions & 3 deletions bolt/test/X86/pre-aggregated-perf.test
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ CHECK-BASIC-NL: no_lbr cycles

PERF2BOLT: 1 frame_dummy/1 1e 1 frame_dummy/1 0 0 1
PERF2BOLT-NEXT: 1 main 451 1 SolveCubic 0 0 2
PERF2BOLT-NEXT: 1 main 490 0 [unknown] 4005f0 0 1
PERF2BOLT-NEXT: 1 main 537 0 [unknown] 400610 0 1
PERF2BOLT-NEXT: 0 [unknown] 7f36d18d60c0 1 main 53c 0 2
PERF2BOLT-NEXT: 1 main 490 0 [unknown] 0 0 1
PERF2BOLT-NEXT: 1 main 537 0 [unknown] 0 0 1
PERF2BOLT-NEXT: 0 [unknown] 0 1 main 53c 0 2
PERF2BOLT-NEXT: 1 usqrt a 1 usqrt 10 0 22
PERF2BOLT-NEXT: 1 usqrt 30 1 usqrt 32 0 22
PERF2BOLT-NEXT: 1 usqrt 30 1 usqrt 39 4 33
Expand Down
Loading