@@ -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
@@ -1347,10 +1368,6 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
13471368 }
13481369
13491370 const uint64_t FromOffset = Addr[0 ]->Offset ;
1350- BinaryFunction *FromFunc = getBinaryFunctionContainingAddress (FromOffset);
1351- if (FromFunc)
1352- FromFunc->setHasProfileAvailable ();
1353-
13541371 int64_t Count = Counters[0 ];
13551372 int64_t Mispreds = Counters[1 ];
13561373
@@ -1361,11 +1378,6 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
13611378 return std::error_code ();
13621379 }
13631380
1364- const uint64_t ToOffset = Addr[1 ]->Offset ;
1365- BinaryFunction *ToFunc = getBinaryFunctionContainingAddress (ToOffset);
1366- if (ToFunc)
1367- ToFunc->setHasProfileAvailable ();
1368-
13691381 // / For fall-through types, adjust locations to match Trace container.
13701382 if (Type == FT || Type == FT_EXTERNAL_ORIGIN || Type == FT_EXTERNAL_RETURN) {
13711383 Addr[2 ] = Location (Addr[1 ]->Offset ); // Trace To
@@ -1613,9 +1625,6 @@ std::error_code DataAggregator::parseBranchEvents() {
16131625 Traces.reserve (TraceMap.size ());
16141626 for (const auto &[Trace, Info] : TraceMap) {
16151627 Traces.emplace_back (Trace, Info);
1616- for (const uint64_t Addr : {Trace.Branch , Trace.From })
1617- if (BinaryFunction *BF = getBinaryFunctionContainingAddress (Addr))
1618- BF->setHasProfileAvailable ();
16191628 }
16201629 clear (TraceMap);
16211630
@@ -1676,9 +1685,6 @@ std::error_code DataAggregator::parseBasicEvents() {
16761685 continue ;
16771686 ++NumTotalSamples;
16781687
1679- if (BinaryFunction *BF = getBinaryFunctionContainingAddress (Sample->PC ))
1680- BF->setHasProfileAvailable ();
1681-
16821688 ++BasicSamples[Sample->PC ];
16831689 EventNames.insert (Sample->EventName );
16841690 }
@@ -1716,9 +1722,6 @@ std::error_code DataAggregator::parseMemEvents() {
17161722 if (std::error_code EC = Sample.getError ())
17171723 return EC;
17181724
1719- if (BinaryFunction *BF = getBinaryFunctionContainingAddress (Sample->PC ))
1720- BF->setHasProfileAvailable ();
1721-
17221725 MemSamples.emplace_back (std::move (Sample.get ()));
17231726 }
17241727
0 commit comments