Skip to content

Commit 03bbd04

Browse files
authored
[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
1 parent dcd2ac7 commit 03bbd04

File tree

2 files changed

+11
-47
lines changed

2 files changed

+11
-47
lines changed

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,10 @@ bool DataAggregator::doBranch(uint64_t From, uint64_t To, uint64_t Count,
735735
// corresponds to a return (if \p IsFrom) or a call continuation (otherwise).
736736
auto handleAddress = [&](uint64_t &Addr, bool IsFrom) {
737737
BinaryFunction *Func = getBinaryFunctionContainingAddress(Addr);
738-
if (!Func)
738+
if (!Func) {
739+
Addr = 0;
739740
return std::pair{Func, false};
741+
}
740742

741743
Addr -= Func->getAddress();
742744

@@ -1432,54 +1434,16 @@ void DataAggregator::parseLBRSample(const PerfBranchSample &Sample,
14321434
const uint64_t TraceTo = NextLBR->From;
14331435
const BinaryFunction *TraceBF =
14341436
getBinaryFunctionContainingAddress(TraceFrom);
1435-
if (opts::HeatmapMode == opts::HeatmapModeKind::HM_Exclusive) {
1436-
FTInfo &Info = FallthroughLBRs[Trace(TraceFrom, TraceTo)];
1437+
FTInfo &Info = FallthroughLBRs[Trace(TraceFrom, TraceTo)];
1438+
if (TraceBF && TraceBF->containsAddress(LBR.From))
14371439
++Info.InternCount;
1438-
} else if (TraceBF && TraceBF->containsAddress(TraceTo)) {
1439-
FTInfo &Info = FallthroughLBRs[Trace(TraceFrom, TraceTo)];
1440-
if (TraceBF->containsAddress(LBR.From))
1441-
++Info.InternCount;
1442-
else
1443-
++Info.ExternCount;
1444-
} else {
1445-
const BinaryFunction *ToFunc =
1446-
getBinaryFunctionContainingAddress(TraceTo);
1447-
if (TraceBF && ToFunc) {
1448-
LLVM_DEBUG({
1449-
dbgs() << "Invalid trace starting in " << TraceBF->getPrintName()
1450-
<< formatv(" @ {0:x}", TraceFrom - TraceBF->getAddress())
1451-
<< formatv(" and ending @ {0:x}\n", TraceTo);
1452-
});
1453-
++NumInvalidTraces;
1454-
} else {
1455-
LLVM_DEBUG({
1456-
dbgs() << "Out of range trace starting in "
1457-
<< (TraceBF ? TraceBF->getPrintName() : "None")
1458-
<< formatv(" @ {0:x}",
1459-
TraceFrom - (TraceBF ? TraceBF->getAddress() : 0))
1460-
<< " and ending in "
1461-
<< (ToFunc ? ToFunc->getPrintName() : "None")
1462-
<< formatv(" @ {0:x}\n",
1463-
TraceTo - (ToFunc ? ToFunc->getAddress() : 0));
1464-
});
1465-
++NumLongRangeTraces;
1466-
}
1467-
}
1440+
else
1441+
++Info.ExternCount;
14681442
++NumTraces;
14691443
}
14701444
NextLBR = &LBR;
14711445

1472-
// Record branches outside binary functions for heatmap.
1473-
if (opts::HeatmapMode == opts::HeatmapModeKind::HM_Exclusive) {
1474-
TakenBranchInfo &Info = BranchLBRs[Trace(LBR.From, LBR.To)];
1475-
++Info.TakenCount;
1476-
continue;
1477-
}
1478-
uint64_t From = getBinaryFunctionContainingAddress(LBR.From) ? LBR.From : 0;
1479-
uint64_t To = getBinaryFunctionContainingAddress(LBR.To) ? LBR.To : 0;
1480-
if (!From && !To)
1481-
continue;
1482-
TakenBranchInfo &Info = BranchLBRs[Trace(From, To)];
1446+
TakenBranchInfo &Info = BranchLBRs[Trace(LBR.From, LBR.To)];
14831447
++Info.TakenCount;
14841448
Info.MispredCount += LBR.Mispred;
14851449
}

bolt/test/X86/pre-aggregated-perf.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ CHECK-BASIC-NL: no_lbr cycles
6969

7070
PERF2BOLT: 1 frame_dummy/1 1e 1 frame_dummy/1 0 0 1
7171
PERF2BOLT-NEXT: 1 main 451 1 SolveCubic 0 0 2
72-
PERF2BOLT-NEXT: 1 main 490 0 [unknown] 4005f0 0 1
73-
PERF2BOLT-NEXT: 1 main 537 0 [unknown] 400610 0 1
74-
PERF2BOLT-NEXT: 0 [unknown] 7f36d18d60c0 1 main 53c 0 2
72+
PERF2BOLT-NEXT: 1 main 490 0 [unknown] 0 0 1
73+
PERF2BOLT-NEXT: 1 main 537 0 [unknown] 0 0 1
74+
PERF2BOLT-NEXT: 0 [unknown] 0 1 main 53c 0 2
7575
PERF2BOLT-NEXT: 1 usqrt a 1 usqrt 10 0 22
7676
PERF2BOLT-NEXT: 1 usqrt 30 1 usqrt 32 0 22
7777
PERF2BOLT-NEXT: 1 usqrt 30 1 usqrt 39 4 33

0 commit comments

Comments
 (0)