diff options
author | Vladislav Khmelevsky <och95@yandex.ru> | 2022-03-16 19:45:38 +0300 |
---|---|---|
committer | Vladislav Khmelevsky <och95@yandex.ru> | 2022-03-18 16:16:47 +0300 |
commit | 5be5d0f56e25b8f1669df517018f43621f9b7e0f (patch) | |
tree | 4ab585a15c932c3bca972428db733e5bdc5c0e84 /bolt | |
parent | 959e2f00b0f6f535ebdbee9b46a2c3d32f74f06c (diff) |
[BOLT] LongJmp speedup refactoring
Run tentativeLayoutRelocMode twice only if UseOldText option was passed.
Refactor BF loop to break on condtition met.
Differential Revision: https://reviews.llvm.org/D121825
Diffstat (limited to 'bolt')
-rw-r--r-- | bolt/lib/Passes/LongJmp.cpp | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/bolt/lib/Passes/LongJmp.cpp b/bolt/lib/Passes/LongJmp.cpp index fbbe0545c9a2..355f35469982 100644 --- a/bolt/lib/Passes/LongJmp.cpp +++ b/bolt/lib/Passes/LongJmp.cpp @@ -322,14 +322,20 @@ uint64_t LongJmpPass::tentativeLayoutRelocMode( uint32_t CurrentIndex = 0; if (opts::HotFunctionsAtEnd) { for (BinaryFunction *BF : SortedFunctions) { - if (BF->hasValidIndex() && LastHotIndex == -1u) + if (BF->hasValidIndex()) { LastHotIndex = CurrentIndex; + break; + } + ++CurrentIndex; } } else { for (BinaryFunction *BF : SortedFunctions) { - if (!BF->hasValidIndex() && LastHotIndex == -1u) + if (!BF->hasValidIndex()) { LastHotIndex = CurrentIndex; + break; + } + ++CurrentIndex; } } @@ -386,17 +392,23 @@ void LongJmpPass::tentativeLayout( } // Relocation mode - uint64_t EstimatedTextSize = tentativeLayoutRelocMode(BC, SortedFunctions, 0); + uint64_t EstimatedTextSize = 0; + if (opts::UseOldText) { + EstimatedTextSize = tentativeLayoutRelocMode(BC, SortedFunctions, 0); + + // Initial padding + if (EstimatedTextSize <= BC.OldTextSectionSize) { + DotAddress = BC.OldTextSectionAddress; + uint64_t Pad = + offsetToAlignment(DotAddress, llvm::Align(opts::AlignText)); + if (Pad + EstimatedTextSize <= BC.OldTextSectionSize) { + DotAddress += Pad; + } + } + } - // Initial padding - if (opts::UseOldText && EstimatedTextSize <= BC.OldTextSectionSize) { - DotAddress = BC.OldTextSectionAddress; - uint64_t Pad = offsetToAlignment(DotAddress, llvm::Align(opts::AlignText)); - if (Pad + EstimatedTextSize <= BC.OldTextSectionSize) - DotAddress += Pad; - } else { + if (!EstimatedTextSize || EstimatedTextSize > BC.OldTextSectionSize) DotAddress = alignTo(BC.LayoutStartAddress, opts::AlignText); - } tentativeLayoutRelocMode(BC, SortedFunctions, DotAddress); } |