Skip to content

Commit 63bb97d

Browse files
rafaelaulergithub-actions[bot]
authored andcommitted
Automerge: Revert "[BOLT][NFC] Register profiled functions once (#150622)" (#152597)
In perf2bolt, we are observing sporadic crashes in the recently added registerProfiledFunctions from #150622. Addresses provided by the hardware (from LBR) might be -1, which clashes with what LLVM uses in DenseSet as empty tombstones records. This causes DenseSet to assert with "can't insert empty tombstone into map" when ingesting this data. Revert this change for now to unbreak perf2bolt.
2 parents d787d40 + 47f54e4 commit 63bb97d

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

bolt/include/bolt/Profile/DataAggregator.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,6 @@ class DataAggregator : public DataReader {
502502
/// entries).
503503
void imputeFallThroughs();
504504

505-
/// Register profiled functions for lite mode.
506-
void registerProfiledFunctions();
507-
508505
/// Debugging dump methods
509506
void dump() const;
510507
void dump(const PerfBranchSample &Sample) const;

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -581,26 +581,6 @@ 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-
604584
Error DataAggregator::preprocessProfile(BinaryContext &BC) {
605585
this->BC = &BC;
606586

@@ -623,7 +603,6 @@ Error DataAggregator::preprocessProfile(BinaryContext &BC) {
623603
exit(0);
624604
}
625605

626-
registerProfiledFunctions();
627606
return Error::success();
628607
}
629608

@@ -1368,6 +1347,10 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
13681347
}
13691348

13701349
const uint64_t FromOffset = Addr[0]->Offset;
1350+
BinaryFunction *FromFunc = getBinaryFunctionContainingAddress(FromOffset);
1351+
if (FromFunc)
1352+
FromFunc->setHasProfileAvailable();
1353+
13711354
int64_t Count = Counters[0];
13721355
int64_t Mispreds = Counters[1];
13731356

@@ -1378,6 +1361,11 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
13781361
return std::error_code();
13791362
}
13801363

1364+
const uint64_t ToOffset = Addr[1]->Offset;
1365+
BinaryFunction *ToFunc = getBinaryFunctionContainingAddress(ToOffset);
1366+
if (ToFunc)
1367+
ToFunc->setHasProfileAvailable();
1368+
13811369
/// For fall-through types, adjust locations to match Trace container.
13821370
if (Type == FT || Type == FT_EXTERNAL_ORIGIN || Type == FT_EXTERNAL_RETURN) {
13831371
Addr[2] = Location(Addr[1]->Offset); // Trace To
@@ -1625,6 +1613,9 @@ std::error_code DataAggregator::parseBranchEvents() {
16251613
Traces.reserve(TraceMap.size());
16261614
for (const auto &[Trace, Info] : TraceMap) {
16271615
Traces.emplace_back(Trace, Info);
1616+
for (const uint64_t Addr : {Trace.Branch, Trace.From})
1617+
if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Addr))
1618+
BF->setHasProfileAvailable();
16281619
}
16291620
clear(TraceMap);
16301621

@@ -1685,6 +1676,9 @@ std::error_code DataAggregator::parseBasicEvents() {
16851676
continue;
16861677
++NumTotalSamples;
16871678

1679+
if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Sample->PC))
1680+
BF->setHasProfileAvailable();
1681+
16881682
++BasicSamples[Sample->PC];
16891683
EventNames.insert(Sample->EventName);
16901684
}
@@ -1722,6 +1716,9 @@ std::error_code DataAggregator::parseMemEvents() {
17221716
if (std::error_code EC = Sample.getError())
17231717
return EC;
17241718

1719+
if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Sample->PC))
1720+
BF->setHasProfileAvailable();
1721+
17251722
MemSamples.emplace_back(std::move(Sample.get()));
17261723
}
17271724

0 commit comments

Comments
 (0)