Skip to content

Commit ceba3a3

Browse files
authored
[BOLT] Add number of basic blocks to BAT
YAML profile reader checks the number of basic blocks in regular, no-stale-matching mode. Add it to BAT. This increases the size of BAT section to: - large binary: 39583080 bytes (1.02x of the original), - medium binary: 3816492 bytes (0.64x), - small binary: 920 bytes (0.64x, no change due to alignment). Test Plan: Updated bolt-address-translation-yaml.test Reviewers: rafaelauler, ayermolo, maksfb, dcci Reviewed By: rafaelauler Pull Request: #86045
1 parent cb300c3 commit ceba3a3

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

bolt/docs/BAT.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Hot indices are delta encoded, implicitly starting at zero.
7979
| `Address` | Continuous, Delta, ULEB128 | Function address in the output binary |
8080
| `HotIndex` | Delta, ULEB128 | Cold functions only: index of corresponding hot function in hot functions table |
8181
| `FuncHash` | 8b | Hot functions only: function hash for input function |
82+
| `NumBlocks` | ULEB128 | Hot functions only: number of basic blocks in the original function |
8283
| `NumEntries` | ULEB128 | Number of address translation entries for a function |
8384
| `EqualElems` | ULEB128 | Hot functions only: number of equal offsets in the beginning of a function |
8485
| `BranchEntries` | Bitmask, `alignTo(EqualElems, 8)` bits | Hot functions only: if `EqualElems` is non-zero, bitmask denoting entries with `BRANCHENTRY` bit |

bolt/include/bolt/Profile/BoltAddressTranslation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ class BoltAddressTranslation {
162162
using BBHashMap = std::unordered_map<uint32_t, std::pair<unsigned, size_t>>;
163163
std::unordered_map<uint64_t, std::pair<size_t, BBHashMap>> FuncHashes;
164164

165+
/// Map a function to its basic blocks count
166+
std::unordered_map<uint64_t, size_t> NumBasicBlocksMap;
167+
165168
/// Links outlined cold bocks to their original function
166169
std::map<uint64_t, uint64_t> ColdPartSource;
167170

bolt/lib/Profile/BoltAddressTranslation.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ void BoltAddressTranslation::writeMaps(std::map<uint64_t, MapTy> &Maps,
196196
// Function hash
197197
LLVM_DEBUG(dbgs() << "Hash: " << formatv("{0:x}\n", FuncHashPair.first));
198198
OS.write(reinterpret_cast<char *>(&FuncHashPair.first), 8);
199+
// Number of basic blocks
200+
size_t NumBasicBlocks = FuncHashPair.second.size();
201+
LLVM_DEBUG(dbgs() << "Basic blocks: " << NumBasicBlocks << '\n');
202+
encodeULEB128(NumBasicBlocks, OS);
199203
}
200204
encodeULEB128(NumEntries, OS);
201205
// For hot fragments only: encode the number of equal offsets
@@ -293,6 +297,12 @@ void BoltAddressTranslation::parseMaps(std::vector<uint64_t> &HotFuncs,
293297
const size_t FuncHash = DE.getU64(&Offset, &Err);
294298
FuncHashes[Address].first = FuncHash;
295299
LLVM_DEBUG(dbgs() << formatv("{0:x}: hash {1:x}\n", Address, FuncHash));
300+
// Number of basic blocks
301+
const size_t NumBasicBlocks = DE.getULEB128(&Offset, &Err);
302+
NumBasicBlocksMap.emplace(Address, NumBasicBlocks);
303+
LLVM_DEBUG(dbgs() << formatv("{0:x}: #bbs {1}, {2} bytes\n", Address,
304+
NumBasicBlocks,
305+
getULEB128Size(NumBasicBlocks)));
296306
}
297307
const uint32_t NumEntries = DE.getULEB128(&Offset, &Err);
298308
// Equal offsets, hot fragments only.

bolt/test/X86/bolt-address-translation-yaml.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ RUN: | FileCheck --check-prefix CHECK-BOLT-YAML %s
1818

1919
WRITE-BAT-CHECK: BOLT-INFO: Wrote 5 BAT maps
2020
WRITE-BAT-CHECK: BOLT-INFO: Wrote 4 function and 22 basic block hashes
21-
WRITE-BAT-CHECK: BOLT-INFO: BAT section size (bytes): 376
21+
WRITE-BAT-CHECK: BOLT-INFO: BAT section size (bytes): 380
2222

2323
READ-BAT-CHECK-NOT: BOLT-ERROR: unable to save profile in YAML format for input file processed by BOLT
2424
READ-BAT-CHECK: BOLT-INFO: Parsed 5 BAT entries

0 commit comments

Comments
 (0)