diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp index 8da11c83a0383..4022212bcf1b6 100644 --- a/bolt/lib/Profile/DataAggregator.cpp +++ b/bolt/lib/Profile/DataAggregator.cpp @@ -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; } diff --git a/bolt/test/X86/pre-aggregated-perf.test b/bolt/test/X86/pre-aggregated-perf.test index b0af4b96058f4..c4f5b8f2ea445 100644 --- a/bolt/test/X86/pre-aggregated-perf.test +++ b/bolt/test/X86/pre-aggregated-perf.test @@ -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