@@ -581,6 +581,26 @@ void DataAggregator::imputeFallThroughs() {
581581 outs () << " BOLT-INFO: imputed " << InferredTraces << " traces\n " ;
582582}
583583
584+ void DataAggregator::registerProfiledFunctions () {
585+ DenseSet<uint64_t > Addrs;
586+ for (const auto &Trace : llvm::make_first_range (Traces)) {
587+ if (Trace.Branch != Trace::FT_ONLY &&
588+ Trace.Branch != Trace::FT_EXTERNAL_ORIGIN)
589+ Addrs.insert (Trace.Branch );
590+ Addrs.insert (Trace.From );
591+ }
592+
593+ for (const auto [PC, _] : BasicSamples)
594+ Addrs.insert (PC);
595+
596+ for (const PerfMemSample &MemSample : MemSamples)
597+ Addrs.insert (MemSample.PC );
598+
599+ for (const uint64_t Addr : Addrs)
600+ if (BinaryFunction *Func = getBinaryFunctionContainingAddress (Addr))
601+ Func->setHasProfileAvailable ();
602+ }
603+
584604Error DataAggregator::preprocessProfile (BinaryContext &BC) {
585605 this ->BC = &BC;
586606
@@ -603,6 +623,7 @@ Error DataAggregator::preprocessProfile(BinaryContext &BC) {
603623 exit (0 );
604624 }
605625
626+ registerProfiledFunctions ();
606627 return Error::success ();
607628}
608629
@@ -906,11 +927,10 @@ DataAggregator::getFallthroughsInTrace(BinaryFunction &BF, const Trace &Trace,
906927 if (BF.isPseudo ())
907928 return Branches;
908929
909- if (!BF.isSimple ())
930+ // Can only record traces in CFG state
931+ if (!BF.hasCFG ())
910932 return std::nullopt ;
911933
912- assert (BF.hasCFG () && " can only record traces in CFG state" );
913-
914934 const BinaryBasicBlock *FromBB = BF.getBasicBlockContainingOffset (From);
915935 const BinaryBasicBlock *ToBB = BF.getBasicBlockContainingOffset (To);
916936
@@ -1348,10 +1368,6 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
13481368 }
13491369
13501370 const uint64_t FromOffset = Addr[0 ]->Offset ;
1351- BinaryFunction *FromFunc = getBinaryFunctionContainingAddress (FromOffset);
1352- if (FromFunc)
1353- FromFunc->setHasProfileAvailable ();
1354-
13551371 int64_t Count = Counters[0 ];
13561372 int64_t Mispreds = Counters[1 ];
13571373
@@ -1362,11 +1378,6 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
13621378 return std::error_code ();
13631379 }
13641380
1365- const uint64_t ToOffset = Addr[1 ]->Offset ;
1366- BinaryFunction *ToFunc = getBinaryFunctionContainingAddress (ToOffset);
1367- if (ToFunc)
1368- ToFunc->setHasProfileAvailable ();
1369-
13701381 // / For fall-through types, adjust locations to match Trace container.
13711382 if (Type == FT || Type == FT_EXTERNAL_ORIGIN || Type == FT_EXTERNAL_RETURN) {
13721383 Addr[2 ] = Location (Addr[1 ]->Offset ); // Trace To
@@ -1614,9 +1625,6 @@ std::error_code DataAggregator::parseBranchEvents() {
16141625 Traces.reserve (TraceMap.size ());
16151626 for (const auto &[Trace, Info] : TraceMap) {
16161627 Traces.emplace_back (Trace, Info);
1617- for (const uint64_t Addr : {Trace.Branch , Trace.From })
1618- if (BinaryFunction *BF = getBinaryFunctionContainingAddress (Addr))
1619- BF->setHasProfileAvailable ();
16201628 }
16211629 clear (TraceMap);
16221630
@@ -1677,9 +1685,6 @@ std::error_code DataAggregator::parseBasicEvents() {
16771685 continue ;
16781686 ++NumTotalSamples;
16791687
1680- if (BinaryFunction *BF = getBinaryFunctionContainingAddress (Sample->PC ))
1681- BF->setHasProfileAvailable ();
1682-
16831688 ++BasicSamples[Sample->PC ];
16841689 EventNames.insert (Sample->EventName );
16851690 }
@@ -1717,9 +1722,6 @@ std::error_code DataAggregator::parseMemEvents() {
17171722 if (std::error_code EC = Sample.getError ())
17181723 return EC;
17191724
1720- if (BinaryFunction *BF = getBinaryFunctionContainingAddress (Sample->PC ))
1721- BF->setHasProfileAvailable ();
1722-
17231725 MemSamples.emplace_back (std::move (Sample.get ()));
17241726 }
17251727
0 commit comments