11
11
// ===----------------------------------------------------------------------===//
12
12
13
13
#include " bolt/Passes/LongJmp.h"
14
- #include " bolt/Utils/CommandLineOpts.h"
15
14
16
15
#define DEBUG_TYPE " longjmp"
17
16
@@ -326,7 +325,7 @@ uint64_t LongJmpPass::tentativeLayoutRelocMode(
326
325
const BinaryContext &BC, std::vector<BinaryFunction *> &SortedFunctions,
327
326
uint64_t DotAddress) {
328
327
// Compute hot cold frontier
329
- uint32_t LastHotIndex = -1u ;
328
+ int64_t LastHotIndex = -1u ;
330
329
uint32_t CurrentIndex = 0 ;
331
330
if (opts::HotFunctionsAtEnd) {
332
331
for (BinaryFunction *BF : SortedFunctions) {
@@ -351,23 +350,21 @@ uint64_t LongJmpPass::tentativeLayoutRelocMode(
351
350
// Hot
352
351
CurrentIndex = 0 ;
353
352
bool ColdLayoutDone = false ;
353
+ auto runColdLayout = [&]() {
354
+ DotAddress = tentativeLayoutRelocColdPart (BC, SortedFunctions, DotAddress);
355
+ ColdLayoutDone = true ;
356
+ if (opts::HotFunctionsAtEnd)
357
+ DotAddress = alignTo (DotAddress, opts::AlignText);
358
+ };
354
359
for (BinaryFunction *Func : SortedFunctions) {
355
360
if (!BC.shouldEmit (*Func)) {
356
361
HotAddresses[Func] = Func->getAddress ();
357
- // Don't perform any tentative address estimation of a function's cold
358
- // layout if it won't be emitted, unless we are ignoring a large number of
359
- // functions (ie, on lite mode) and we haven't done such estimation yet.
360
- if (opts::processAllFunctions () || ColdLayoutDone)
361
- continue ;
362
- }
363
- if (!ColdLayoutDone && CurrentIndex >= LastHotIndex) {
364
- DotAddress =
365
- tentativeLayoutRelocColdPart (BC, SortedFunctions, DotAddress);
366
- ColdLayoutDone = true ;
367
- if (opts::HotFunctionsAtEnd)
368
- DotAddress = alignTo (DotAddress, opts::AlignText);
362
+ continue ;
369
363
}
370
364
365
+ if (!ColdLayoutDone && CurrentIndex >= LastHotIndex)
366
+ runColdLayout ();
367
+
371
368
DotAddress = alignTo (DotAddress, Func->getMinAlignment ());
372
369
uint64_t Pad =
373
370
offsetToAlignment (DotAddress, llvm::Align (Func->getAlignment ()));
@@ -386,9 +383,11 @@ uint64_t LongJmpPass::tentativeLayoutRelocMode(
386
383
++CurrentIndex;
387
384
}
388
385
386
+ // Ensure that tentative code layout always runs for cold blocks.
389
387
if (!ColdLayoutDone)
390
- assert (ColdLayoutDone &&
391
- " Did not perform tentative code layout for cold blocks." );
388
+ runColdLayout ();
389
+ assert (ColdLayoutDone &&
390
+ " Did not perform tentative code layout for cold blocks." );
392
391
393
392
// BBs
394
393
for (BinaryFunction *Func : SortedFunctions)
0 commit comments