1111// ===----------------------------------------------------------------------===//
1212
1313#include " bolt/Passes/LongJmp.h"
14- #include " bolt/Utils/CommandLineOpts.h"
1514
1615#define DEBUG_TYPE " longjmp"
1716
@@ -326,7 +325,7 @@ uint64_t LongJmpPass::tentativeLayoutRelocMode(
326325 const BinaryContext &BC, std::vector<BinaryFunction *> &SortedFunctions,
327326 uint64_t DotAddress) {
328327 // Compute hot cold frontier
329- uint32_t LastHotIndex = -1u ;
328+ int64_t LastHotIndex = -1u ;
330329 uint32_t CurrentIndex = 0 ;
331330 if (opts::HotFunctionsAtEnd) {
332331 for (BinaryFunction *BF : SortedFunctions) {
@@ -351,23 +350,21 @@ uint64_t LongJmpPass::tentativeLayoutRelocMode(
351350 // Hot
352351 CurrentIndex = 0 ;
353352 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+ };
354359 for (BinaryFunction *Func : SortedFunctions) {
355360 if (!BC.shouldEmit (*Func)) {
356361 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 ;
369363 }
370364
365+ if (!ColdLayoutDone && CurrentIndex >= LastHotIndex)
366+ runColdLayout ();
367+
371368 DotAddress = alignTo (DotAddress, Func->getMinAlignment ());
372369 uint64_t Pad =
373370 offsetToAlignment (DotAddress, llvm::Align (Func->getAlignment ()));
@@ -386,6 +383,12 @@ uint64_t LongJmpPass::tentativeLayoutRelocMode(
386383 ++CurrentIndex;
387384 }
388385
386+ // Ensure that tentative code layout always runs for cold blocks.
387+ if (!ColdLayoutDone)
388+ runColdLayout ();
389+ assert (ColdLayoutDone &&
390+ " Did not perform tentative code layout for cold blocks." );
391+
389392 // BBs
390393 for (BinaryFunction *Func : SortedFunctions)
391394 tentativeBBLayout (*Func);
0 commit comments