Skip to content

Commit 5057463

Browse files
authored
[BOLT][NFC] Make BAT methods const (#91823)
1 parent dfc6a19 commit 5057463

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

bolt/include/bolt/Profile/BoltAddressTranslation.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class BoltAddressTranslation {
9090
std::error_code parse(raw_ostream &OS, StringRef Buf);
9191

9292
/// Dump the parsed address translation tables
93-
void dump(raw_ostream &OS);
93+
void dump(raw_ostream &OS) const;
9494

9595
/// If the maps are loaded in memory, perform the lookup to translate LBR
9696
/// addresses in function located at \p FuncAddress.
@@ -137,7 +137,8 @@ class BoltAddressTranslation {
137137
/// emitted for the start of the BB. More entries may be emitted to cover
138138
/// the location of calls or any instruction that may change control flow.
139139
void writeEntriesForBB(MapTy &Map, const BinaryBasicBlock &BB,
140-
uint64_t FuncInputAddress, uint64_t FuncOutputAddress);
140+
uint64_t FuncInputAddress,
141+
uint64_t FuncOutputAddress) const;
141142

142143
/// Write the serialized address translation table for a function.
143144
template <bool Cold>
@@ -152,7 +153,7 @@ class BoltAddressTranslation {
152153

153154
/// Returns the bitmask with set bits corresponding to indices of BRANCHENTRY
154155
/// entries in function address translation map.
155-
APInt calculateBranchEntriesBitMask(MapTy &Map, size_t EqualElems);
156+
APInt calculateBranchEntriesBitMask(MapTy &Map, size_t EqualElems) const;
156157

157158
/// Calculate the number of equal offsets (output = input - skew) in the
158159
/// beginning of the function.

bolt/lib/Profile/BoltAddressTranslation.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ namespace bolt {
2020

2121
const char *BoltAddressTranslation::SECTION_NAME = ".note.bolt_bat";
2222

23-
void BoltAddressTranslation::writeEntriesForBB(MapTy &Map,
24-
const BinaryBasicBlock &BB,
25-
uint64_t FuncInputAddress,
26-
uint64_t FuncOutputAddress) {
23+
void BoltAddressTranslation::writeEntriesForBB(
24+
MapTy &Map, const BinaryBasicBlock &BB, uint64_t FuncInputAddress,
25+
uint64_t FuncOutputAddress) const {
2726
const uint64_t BBOutputOffset =
2827
BB.getOutputAddressRange().first - FuncOutputAddress;
2928
const uint32_t BBInputOffset = BB.getInputOffset();
@@ -138,8 +137,8 @@ void BoltAddressTranslation::write(const BinaryContext &BC, raw_ostream &OS) {
138137
<< " basic block hashes\n";
139138
}
140139

141-
APInt BoltAddressTranslation::calculateBranchEntriesBitMask(MapTy &Map,
142-
size_t EqualElems) {
140+
APInt BoltAddressTranslation::calculateBranchEntriesBitMask(
141+
MapTy &Map, size_t EqualElems) const {
143142
APInt BitMask(alignTo(EqualElems, 8), 0);
144143
size_t Index = 0;
145144
for (std::pair<const uint32_t, uint32_t> &KeyVal : Map) {
@@ -422,7 +421,7 @@ void BoltAddressTranslation::parseMaps(std::vector<uint64_t> &HotFuncs,
422421
}
423422
}
424423

425-
void BoltAddressTranslation::dump(raw_ostream &OS) {
424+
void BoltAddressTranslation::dump(raw_ostream &OS) const {
426425
const size_t NumTables = Maps.size();
427426
OS << "BAT tables for " << NumTables << " functions:\n";
428427
for (const auto &MapEntry : Maps) {
@@ -447,11 +446,15 @@ void BoltAddressTranslation::dump(raw_ostream &OS) {
447446
OS << formatv(" hash: {0:x}", BBHashMap.getBBHash(Val));
448447
OS << "\n";
449448
}
450-
if (IsHotFunction)
451-
OS << "NumBlocks: " << NumBasicBlocksMap[Address] << '\n';
452-
if (SecondaryEntryPointsMap.count(Address)) {
449+
if (IsHotFunction) {
450+
auto NumBasicBlocksIt = NumBasicBlocksMap.find(Address);
451+
assert(NumBasicBlocksIt != NumBasicBlocksMap.end());
452+
OS << "NumBlocks: " << NumBasicBlocksIt->second << '\n';
453+
}
454+
auto SecondaryEntryPointsIt = SecondaryEntryPointsMap.find(Address);
455+
if (SecondaryEntryPointsIt != SecondaryEntryPointsMap.end()) {
453456
const std::vector<uint32_t> &SecondaryEntryPoints =
454-
SecondaryEntryPointsMap[Address];
457+
SecondaryEntryPointsIt->second;
455458
OS << SecondaryEntryPoints.size() << " secondary entry points:\n";
456459
for (uint32_t EntryPointOffset : SecondaryEntryPoints)
457460
OS << formatv("{0:x}\n", EntryPointOffset);

0 commit comments

Comments
 (0)