[llvm] [BOLT][NFC] Make BAT methods const (PR #91823)
Amir Ayupov via llvm-commits
llvm-commits at lists.llvm.org
Fri May 10 15:52:16 PDT 2024
https://github.com/aaupov created https://github.com/llvm/llvm-project/pull/91823
None
>From 470c1fbb39e98fc76b2d641b85aa5c424344a1a7 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Fri, 10 May 2024 15:02:28 -0700
Subject: [PATCH] [BOLT][NFC] Make BAT methods const
---
.../bolt/Profile/BoltAddressTranslation.h | 7 +++---
bolt/lib/Profile/BoltAddressTranslation.cpp | 25 +++++++++++--------
2 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/bolt/include/bolt/Profile/BoltAddressTranslation.h b/bolt/include/bolt/Profile/BoltAddressTranslation.h
index 68b993ee363cc..a1f4b504b6ee9 100644
--- a/bolt/include/bolt/Profile/BoltAddressTranslation.h
+++ b/bolt/include/bolt/Profile/BoltAddressTranslation.h
@@ -90,7 +90,7 @@ class BoltAddressTranslation {
std::error_code parse(raw_ostream &OS, StringRef Buf);
/// Dump the parsed address translation tables
- void dump(raw_ostream &OS);
+ void dump(raw_ostream &OS) const;
/// If the maps are loaded in memory, perform the lookup to translate LBR
/// addresses in function located at \p FuncAddress.
@@ -132,7 +132,8 @@ class BoltAddressTranslation {
/// emitted for the start of the BB. More entries may be emitted to cover
/// the location of calls or any instruction that may change control flow.
void writeEntriesForBB(MapTy &Map, const BinaryBasicBlock &BB,
- uint64_t FuncInputAddress, uint64_t FuncOutputAddress);
+ uint64_t FuncInputAddress,
+ uint64_t FuncOutputAddress) const;
/// Write the serialized address translation table for a function.
template <bool Cold>
@@ -147,7 +148,7 @@ class BoltAddressTranslation {
/// Returns the bitmask with set bits corresponding to indices of BRANCHENTRY
/// entries in function address translation map.
- APInt calculateBranchEntriesBitMask(MapTy &Map, size_t EqualElems);
+ APInt calculateBranchEntriesBitMask(MapTy &Map, size_t EqualElems) const;
/// Calculate the number of equal offsets (output = input - skew) in the
/// beginning of the function.
diff --git a/bolt/lib/Profile/BoltAddressTranslation.cpp b/bolt/lib/Profile/BoltAddressTranslation.cpp
index 7cfb9c132c2c6..9fc9de729b568 100644
--- a/bolt/lib/Profile/BoltAddressTranslation.cpp
+++ b/bolt/lib/Profile/BoltAddressTranslation.cpp
@@ -20,10 +20,9 @@ namespace bolt {
const char *BoltAddressTranslation::SECTION_NAME = ".note.bolt_bat";
-void BoltAddressTranslation::writeEntriesForBB(MapTy &Map,
- const BinaryBasicBlock &BB,
- uint64_t FuncInputAddress,
- uint64_t FuncOutputAddress) {
+void BoltAddressTranslation::writeEntriesForBB(
+ MapTy &Map, const BinaryBasicBlock &BB, uint64_t FuncInputAddress,
+ uint64_t FuncOutputAddress) const {
const uint64_t BBOutputOffset =
BB.getOutputAddressRange().first - FuncOutputAddress;
const uint32_t BBInputOffset = BB.getInputOffset();
@@ -138,8 +137,8 @@ void BoltAddressTranslation::write(const BinaryContext &BC, raw_ostream &OS) {
<< " basic block hashes\n";
}
-APInt BoltAddressTranslation::calculateBranchEntriesBitMask(MapTy &Map,
- size_t EqualElems) {
+APInt BoltAddressTranslation::calculateBranchEntriesBitMask(
+ MapTy &Map, size_t EqualElems) const {
APInt BitMask(alignTo(EqualElems, 8), 0);
size_t Index = 0;
for (std::pair<const uint32_t, uint32_t> &KeyVal : Map) {
@@ -422,7 +421,7 @@ void BoltAddressTranslation::parseMaps(std::vector<uint64_t> &HotFuncs,
}
}
-void BoltAddressTranslation::dump(raw_ostream &OS) {
+void BoltAddressTranslation::dump(raw_ostream &OS) const {
const size_t NumTables = Maps.size();
OS << "BAT tables for " << NumTables << " functions:\n";
for (const auto &MapEntry : Maps) {
@@ -447,11 +446,15 @@ void BoltAddressTranslation::dump(raw_ostream &OS) {
OS << formatv(" hash: {0:x}", BBHashMap.getBBHash(Val));
OS << "\n";
}
- if (IsHotFunction)
- OS << "NumBlocks: " << NumBasicBlocksMap[Address] << '\n';
- if (SecondaryEntryPointsMap.count(Address)) {
+ if (IsHotFunction) {
+ auto NumBasicBlocksIt = NumBasicBlocksMap.find(Address);
+ assert(NumBasicBlocksIt != NumBasicBlocksMap.end());
+ OS << "NumBlocks: " << NumBasicBlocksIt->second << '\n';
+ }
+ auto SecondaryEntryPointsIt = SecondaryEntryPointsMap.find(Address);
+ if (SecondaryEntryPointsIt != SecondaryEntryPointsMap.end()) {
const std::vector<uint32_t> &SecondaryEntryPoints =
- SecondaryEntryPointsMap[Address];
+ SecondaryEntryPointsIt->second;
OS << SecondaryEntryPoints.size() << " secondary entry points:\n";
for (uint32_t EntryPointOffset : SecondaryEntryPoints)
OS << formatv("{0:x}\n", EntryPointOffset);
More information about the llvm-commits
mailing list