Skip to content

Revert "[BOLT][NFC] Register profiled functions once (#150622)" #152597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions bolt/include/bolt/Profile/DataAggregator.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,6 @@ class DataAggregator : public DataReader {
/// entries).
void imputeFallThroughs();

/// Register profiled functions for lite mode.
void registerProfiledFunctions();

/// Debugging dump methods
void dump() const;
void dump(const PerfBranchSample &Sample) const;
Expand Down
39 changes: 18 additions & 21 deletions bolt/lib/Profile/DataAggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,26 +581,6 @@ void DataAggregator::imputeFallThroughs() {
outs() << "BOLT-INFO: imputed " << InferredTraces << " traces\n";
}

void DataAggregator::registerProfiledFunctions() {
DenseSet<uint64_t> Addrs;
for (const auto &Trace : llvm::make_first_range(Traces)) {
if (Trace.Branch != Trace::FT_ONLY &&
Trace.Branch != Trace::FT_EXTERNAL_ORIGIN)
Addrs.insert(Trace.Branch);
Addrs.insert(Trace.From);
}

for (const auto [PC, _] : BasicSamples)
Addrs.insert(PC);

for (const PerfMemSample &MemSample : MemSamples)
Addrs.insert(MemSample.PC);

for (const uint64_t Addr : Addrs)
if (BinaryFunction *Func = getBinaryFunctionContainingAddress(Addr))
Func->setHasProfileAvailable();
}

Error DataAggregator::preprocessProfile(BinaryContext &BC) {
this->BC = &BC;

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

registerProfiledFunctions();
return Error::success();
}

Expand Down Expand Up @@ -1368,6 +1347,10 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
}

const uint64_t FromOffset = Addr[0]->Offset;
BinaryFunction *FromFunc = getBinaryFunctionContainingAddress(FromOffset);
if (FromFunc)
FromFunc->setHasProfileAvailable();

int64_t Count = Counters[0];
int64_t Mispreds = Counters[1];

Expand All @@ -1378,6 +1361,11 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
return std::error_code();
}

const uint64_t ToOffset = Addr[1]->Offset;
BinaryFunction *ToFunc = getBinaryFunctionContainingAddress(ToOffset);
if (ToFunc)
ToFunc->setHasProfileAvailable();

/// For fall-through types, adjust locations to match Trace container.
if (Type == FT || Type == FT_EXTERNAL_ORIGIN || Type == FT_EXTERNAL_RETURN) {
Addr[2] = Location(Addr[1]->Offset); // Trace To
Expand Down Expand Up @@ -1625,6 +1613,9 @@ std::error_code DataAggregator::parseBranchEvents() {
Traces.reserve(TraceMap.size());
for (const auto &[Trace, Info] : TraceMap) {
Traces.emplace_back(Trace, Info);
for (const uint64_t Addr : {Trace.Branch, Trace.From})
if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Addr))
BF->setHasProfileAvailable();
}
clear(TraceMap);

Expand Down Expand Up @@ -1685,6 +1676,9 @@ std::error_code DataAggregator::parseBasicEvents() {
continue;
++NumTotalSamples;

if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Sample->PC))
BF->setHasProfileAvailable();

++BasicSamples[Sample->PC];
EventNames.insert(Sample->EventName);
}
Expand Down Expand Up @@ -1722,6 +1716,9 @@ std::error_code DataAggregator::parseMemEvents() {
if (std::error_code EC = Sample.getError())
return EC;

if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Sample->PC))
BF->setHasProfileAvailable();

MemSamples.emplace_back(std::move(Sample.get()));
}

Expand Down
Loading