@@ -45,6 +45,8 @@ void BoltAddressTranslation::writeEntriesForBB(MapTy &Map,
45
45
LLVM_DEBUG (dbgs () << formatv (" Hash: {0:x}\n " ,
46
46
getBBHash (HotFuncAddress, BBInputOffset)));
47
47
(void )HotFuncAddress;
48
+ LLVM_DEBUG (dbgs () << formatv (" Index: {0}\n " ,
49
+ getBBIndex (HotFuncAddress, BBInputOffset)));
48
50
// In case of conflicts (same Key mapping to different Vals), the last
49
51
// update takes precedence. Of course it is not ideal to have conflicts and
50
52
// those happen when we have an empty BB that either contained only
@@ -217,6 +219,7 @@ void BoltAddressTranslation::writeMaps(std::map<uint64_t, MapTy> &Maps,
217
219
}
218
220
size_t Index = 0 ;
219
221
uint64_t InOffset = 0 ;
222
+ size_t PrevBBIndex = 0 ;
220
223
// Output and Input addresses and delta-encoded
221
224
for (std::pair<const uint32_t , uint32_t > &KeyVal : Map) {
222
225
const uint64_t OutputAddress = KeyVal.first + Address;
@@ -226,11 +229,15 @@ void BoltAddressTranslation::writeMaps(std::map<uint64_t, MapTy> &Maps,
226
229
encodeSLEB128 (KeyVal.second - InOffset, OS);
227
230
InOffset = KeyVal.second ; // Keeping InOffset as if BRANCHENTRY is encoded
228
231
if ((InOffset & BRANCHENTRY) == 0 ) {
229
- // Basic block hash
230
- size_t BBHash = FuncHashPair.second [InOffset >> 1 ];
232
+ unsigned BBIndex;
233
+ size_t BBHash;
234
+ std::tie (BBIndex, BBHash) = FuncHashPair.second [InOffset >> 1 ];
231
235
OS.write (reinterpret_cast <char *>(&BBHash), 8 );
232
- LLVM_DEBUG (dbgs () << formatv (" {0:x} -> {1:x} {2:x}\n " , KeyVal.first ,
233
- InOffset >> 1 , BBHash));
236
+ // Basic block index in the input binary
237
+ encodeULEB128 (BBIndex - PrevBBIndex, OS);
238
+ PrevBBIndex = BBIndex;
239
+ LLVM_DEBUG (dbgs () << formatv (" {0:x} -> {1:x} {2:x} {3}\n " , KeyVal.first ,
240
+ InOffset >> 1 , BBHash, BBIndex));
234
241
}
235
242
}
236
243
}
@@ -316,6 +323,7 @@ void BoltAddressTranslation::parseMaps(std::vector<uint64_t> &HotFuncs,
316
323
LLVM_DEBUG (dbgs () << " Parsing " << NumEntries << " entries for 0x"
317
324
<< Twine::utohexstr (Address) << " \n " );
318
325
uint64_t InputOffset = 0 ;
326
+ size_t BBIndex = 0 ;
319
327
for (uint32_t J = 0 ; J < NumEntries; ++J) {
320
328
const uint64_t OutputDelta = DE.getULEB128 (&Offset, &Err);
321
329
const uint64_t OutputAddress = PrevAddress + OutputDelta;
@@ -330,19 +338,25 @@ void BoltAddressTranslation::parseMaps(std::vector<uint64_t> &HotFuncs,
330
338
}
331
339
Map.insert (std::pair<uint32_t , uint32_t >(OutputOffset, InputOffset));
332
340
size_t BBHash = 0 ;
341
+ size_t BBIndexDelta = 0 ;
333
342
const bool IsBranchEntry = InputOffset & BRANCHENTRY;
334
343
if (!IsBranchEntry) {
335
344
BBHash = DE.getU64 (&Offset, &Err);
345
+ BBIndexDelta = DE.getULEB128 (&Offset, &Err);
346
+ BBIndex += BBIndexDelta;
336
347
// Map basic block hash to hot fragment by input offset
337
- FuncHashes[HotAddress].second .emplace (InputOffset >> 1 , BBHash);
348
+ FuncHashes[HotAddress].second .emplace (InputOffset >> 1 ,
349
+ std::pair (BBIndex, BBHash));
338
350
}
339
351
LLVM_DEBUG ({
340
352
dbgs () << formatv (
341
353
" {0:x} -> {1:x} ({2}/{3}b -> {4}/{5}b), {6:x}" , OutputOffset,
342
354
InputOffset, OutputDelta, getULEB128Size (OutputDelta), InputDelta,
343
355
(J < EqualElems) ? 0 : getSLEB128Size (InputDelta), OutputAddress);
344
- if (BBHash)
345
- dbgs () << formatv (" {0:x}" , BBHash);
356
+ if (!IsBranchEntry) {
357
+ dbgs () << formatv (" {0:x} {1}/{2}b" , BBHash, BBIndex,
358
+ getULEB128Size (BBIndexDelta));
359
+ }
346
360
dbgs () << ' \n ' ;
347
361
});
348
362
}
@@ -494,14 +508,19 @@ void BoltAddressTranslation::saveMetadata(BinaryContext &BC) {
494
508
FuncHashes[BF.getAddress ()].first = BF.computeHash ();
495
509
BF.computeBlockHashes ();
496
510
for (const BinaryBasicBlock &BB : BF)
497
- FuncHashes[BF.getAddress ()].second .emplace (BB. getInputOffset (),
498
- BB.getHash ());
511
+ FuncHashes[BF.getAddress ()].second .emplace (
512
+ BB. getInputOffset (), std::pair (BB. getIndex (), BB.getHash () ));
499
513
}
500
514
}
501
515
516
+ unsigned BoltAddressTranslation::getBBIndex (uint64_t FuncOutputAddress,
517
+ uint32_t BBInputOffset) const {
518
+ return FuncHashes.at (FuncOutputAddress).second .at (BBInputOffset).first ;
519
+ }
520
+
502
521
size_t BoltAddressTranslation::getBBHash (uint64_t FuncOutputAddress,
503
522
uint32_t BBInputOffset) const {
504
- return FuncHashes.at (FuncOutputAddress).second .at (BBInputOffset);
523
+ return FuncHashes.at (FuncOutputAddress).second .at (BBInputOffset). second ;
505
524
}
506
525
507
526
size_t BoltAddressTranslation::getBFHash (uint64_t OutputAddress) const {
0 commit comments