@@ -580,8 +580,10 @@ void DataAggregator::processProfile(BinaryContext &BC) {
580580 }
581581 }
582582
583- for (auto &FuncBranches : NamesToBranches)
583+ for (auto &FuncBranches : NamesToBranches) {
584584 llvm::stable_sort (FuncBranches.second .Data );
585+ llvm::stable_sort (FuncBranches.second .EntryData );
586+ }
585587
586588 for (auto &MemEvents : NamesToMemEvents)
587589 llvm::stable_sort (MemEvents.second .Data );
@@ -733,8 +735,10 @@ bool DataAggregator::doBranch(uint64_t From, uint64_t To, uint64_t Count,
733735 // corresponds to a return (if \p IsFrom) or a call continuation (otherwise).
734736 auto handleAddress = [&](uint64_t &Addr, bool IsFrom) {
735737 BinaryFunction *Func = getBinaryFunctionContainingAddress (Addr);
736- if (!Func)
738+ if (!Func) {
739+ Addr = 0 ;
737740 return std::pair{Func, false };
741+ }
738742
739743 Addr -= Func->getAddress ();
740744
@@ -972,7 +976,7 @@ bool DataAggregator::recordExit(BinaryFunction &BF, uint64_t From, bool Mispred,
972976 return true ;
973977}
974978
975- ErrorOr<LBREntry> DataAggregator::parseLBREntry () {
979+ ErrorOr<DataAggregator:: LBREntry> DataAggregator::parseLBREntry () {
976980 LBREntry Res;
977981 ErrorOr<StringRef> FromStrRes = parseString (' /' );
978982 if (std::error_code EC = FromStrRes.getError ())
@@ -1430,54 +1434,16 @@ void DataAggregator::parseLBRSample(const PerfBranchSample &Sample,
14301434 const uint64_t TraceTo = NextLBR->From ;
14311435 const BinaryFunction *TraceBF =
14321436 getBinaryFunctionContainingAddress (TraceFrom);
1433- if (opts::HeatmapMode == opts::HeatmapModeKind::HM_Exclusive) {
1434- FTInfo &Info = FallthroughLBRs[ Trace (TraceFrom, TraceTo)];
1437+ FTInfo &Info = FallthroughLBRs[ Trace (TraceFrom, TraceTo)];
1438+ if (TraceBF && TraceBF-> containsAddress (LBR. From ))
14351439 ++Info.InternCount ;
1436- } else if (TraceBF && TraceBF->containsAddress (TraceTo)) {
1437- FTInfo &Info = FallthroughLBRs[Trace (TraceFrom, TraceTo)];
1438- if (TraceBF->containsAddress (LBR.From ))
1439- ++Info.InternCount ;
1440- else
1441- ++Info.ExternCount ;
1442- } else {
1443- const BinaryFunction *ToFunc =
1444- getBinaryFunctionContainingAddress (TraceTo);
1445- if (TraceBF && ToFunc) {
1446- LLVM_DEBUG ({
1447- dbgs () << " Invalid trace starting in " << TraceBF->getPrintName ()
1448- << formatv (" @ {0:x}" , TraceFrom - TraceBF->getAddress ())
1449- << formatv (" and ending @ {0:x}\n " , TraceTo);
1450- });
1451- ++NumInvalidTraces;
1452- } else {
1453- LLVM_DEBUG ({
1454- dbgs () << " Out of range trace starting in "
1455- << (TraceBF ? TraceBF->getPrintName () : " None" )
1456- << formatv (" @ {0:x}" ,
1457- TraceFrom - (TraceBF ? TraceBF->getAddress () : 0 ))
1458- << " and ending in "
1459- << (ToFunc ? ToFunc->getPrintName () : " None" )
1460- << formatv (" @ {0:x}\n " ,
1461- TraceTo - (ToFunc ? ToFunc->getAddress () : 0 ));
1462- });
1463- ++NumLongRangeTraces;
1464- }
1465- }
1440+ else
1441+ ++Info.ExternCount ;
14661442 ++NumTraces;
14671443 }
14681444 NextLBR = &LBR;
14691445
1470- // Record branches outside binary functions for heatmap.
1471- if (opts::HeatmapMode == opts::HeatmapModeKind::HM_Exclusive) {
1472- TakenBranchInfo &Info = BranchLBRs[Trace (LBR.From , LBR.To )];
1473- ++Info.TakenCount ;
1474- continue ;
1475- }
1476- uint64_t From = getBinaryFunctionContainingAddress (LBR.From ) ? LBR.From : 0 ;
1477- uint64_t To = getBinaryFunctionContainingAddress (LBR.To ) ? LBR.To : 0 ;
1478- if (!From && !To)
1479- continue ;
1480- TakenBranchInfo &Info = BranchLBRs[Trace (From, To)];
1446+ TakenBranchInfo &Info = BranchLBRs[Trace (LBR.From , LBR.To )];
14811447 ++Info.TakenCount ;
14821448 Info.MispredCount += LBR.Mispred ;
14831449 }
@@ -2398,16 +2364,10 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,
23982364
23992365void DataAggregator::dump () const { DataReader::dump (); }
24002366
2401- void DataAggregator::dump (const LBREntry &LBR) const {
2402- Diag << " From: " << Twine::utohexstr (LBR.From )
2403- << " To: " << Twine::utohexstr (LBR.To ) << " Mispred? " << LBR.Mispred
2404- << " \n " ;
2405- }
2406-
24072367void DataAggregator::dump (const PerfBranchSample &Sample) const {
24082368 Diag << " Sample LBR entries: " << Sample.LBR .size () << " \n " ;
24092369 for (const LBREntry &LBR : Sample.LBR )
2410- dump ( LBR) ;
2370+ Diag << LBR << ' \n ' ;
24112371}
24122372
24132373void DataAggregator::dump (const PerfMemSample &Sample) const {
0 commit comments