Skip to content

Commit 867bac6

Browse files
committed
cleanup
Created using spr 1.3.4
1 parent 370dd77 commit 867bac6

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

bolt/include/bolt/Profile/DataAggregator.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,27 +101,26 @@ class DataAggregator : public DataReader {
101101

102102
/// Container for the unit of branch data.
103103
/// Backwards compatible with legacy use for branches and fall-throughs:
104-
/// - if \p Branch is FT_ONLY or FT_EXTERNAL_ORIGIN, the trace only contains
105-
/// fall-through data,
106-
/// - if \p To is EXTERNAL, the trace only contains branch data.
104+
/// - if \p Branch is FT_ONLY or FT_EXTERNAL_ORIGIN, the trace only
105+
/// contains fall-through data,
106+
/// - if \p To is BR_ONLY, the trace only contains branch data.
107107
struct Trace {
108108
static constexpr const uint64_t EXTERNAL = 0ULL;
109+
static constexpr const uint64_t BR_ONLY = -1ULL;
109110
static constexpr const uint64_t FT_ONLY = -1ULL;
110111
static constexpr const uint64_t FT_EXTERNAL_ORIGIN = -2ULL;
111112

112113
uint64_t Branch;
113114
uint64_t From;
114115
uint64_t To;
115-
bool operator==(const Trace &Other) const {
116-
return Branch == Other.Branch && From == Other.From && To == Other.To;
117-
}
116+
auto tie() const { return std::tie(Branch, From, To); }
117+
bool operator==(const Trace &Other) const { return tie() == Other.tie(); }
118+
bool operator<(const Trace &Other) const { return tie() < Other.tie(); }
118119
};
119120
friend raw_ostream &operator<<(raw_ostream &OS, const Trace &);
120121

121122
struct TraceHash {
122-
size_t operator()(const Trace &L) const {
123-
return llvm::hash_combine(L.Branch, L.From, L.To);
124-
}
123+
size_t operator()(const Trace &L) const { return hash_combine(L.tie()); }
125124
};
126125

127126
struct TakenBranchInfo {
@@ -531,7 +530,7 @@ inline raw_ostream &operator<<(raw_ostream &OS,
531530
OS << Twine::utohexstr(T.Branch) << " -> ";
532531
}
533532
OS << Twine::utohexstr(T.From);
534-
if (T.To)
533+
if (T.To != DataAggregator::Trace::BR_ONLY)
535534
OS << " ... " << Twine::utohexstr(T.To);
536535
return OS;
537536
}

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,10 @@ Error DataAggregator::preprocessProfile(BinaryContext &BC) {
514514
deleteTempFiles();
515515

516516
heatmap:
517+
// Sort parsed traces for faster processing.
518+
if (!opts::BasicAggregation)
519+
llvm::sort(Traces, llvm::less_first());
520+
517521
if (!opts::HeatmapMode)
518522
return Error::success();
519523

@@ -1283,15 +1287,15 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
12831287
}
12841288

12851289
if (Type == BRANCH) {
1286-
Addr[2] = Location(Trace::EXTERNAL);
1290+
Addr[2] = Location(Trace::BR_ONLY);
12871291
}
12881292

12891293
Trace T{Addr[0]->Offset, Addr[1]->Offset, Addr[2]->Offset};
12901294
TakenBranchInfo TI{(uint64_t)Count, (uint64_t)Mispreds};
12911295

12921296
Traces.emplace_back(T, TI);
12931297

1294-
if (Addr[2]->Offset)
1298+
if (Addr[2]->Offset != Trace::BR_ONLY)
12951299
NumTraces += Count;
12961300
NumTotalSamples += Count;
12971301

@@ -1305,7 +1309,7 @@ bool DataAggregator::ignoreKernelInterrupt(LBREntry &LBR) const {
13051309

13061310
std::error_code DataAggregator::printLBRHeatMap() {
13071311
outs() << "PERF2BOLT: parse branch events...\n";
1308-
NamedRegionTimer T("parseBranch", "Parsing branch events", TimerGroupName,
1312+
NamedRegionTimer T("buildHeatmap", "Building heatmap", TimerGroupName,
13091313
TimerGroupDesc, opts::TimeAggregator);
13101314

13111315
if (BC->IsLinuxKernel) {
@@ -1342,7 +1346,7 @@ std::error_code DataAggregator::printLBRHeatMap() {
13421346
for (const auto &[PC, Hits] : BasicSamples)
13431347
HM.registerAddress(PC, Hits);
13441348
for (const auto &[Trace, Info] : Traces)
1345-
if (Trace.To)
1349+
if (Trace.To != Trace::BR_ONLY)
13461350
HM.registerAddressRange(Trace.From, Trace.To, Info.TakenCount);
13471351

13481352
if (HM.getNumInvalidRanges())
@@ -1540,7 +1544,7 @@ void DataAggregator::processBranchEvents() {
15401544
TimerGroupName, TimerGroupDesc, opts::TimeAggregator);
15411545

15421546
for (const auto &[Trace, Info] : Traces) {
1543-
if (Trace.To)
1547+
if (Trace.To != Trace::BR_ONLY)
15441548
doTrace(Trace, Info.TakenCount);
15451549
if (Trace.Branch != Trace::FT_ONLY &&
15461550
Trace.Branch != Trace::FT_EXTERNAL_ORIGIN)

0 commit comments

Comments
 (0)