[BOLT][NFCI] Skip validation in parseLBRSample (#143288)
Parsed branches and fall-throughs are validated in `doBranch` and `doTrace` respectively. Simplify parseLBRSample by omitting the validation. This also speeds up perf data processing as checks are only done once for aggregated branches/fall-throughs and not individual LBR entries. Since invalid/external addresses are no longer sanitized during parsing, sanitize them in `doBranch`. Test Plan: updated X86/pre-aggregated-perf.test
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user