[PATCH] D121825: [BOLT] LongJmp speedup refactoring

Vladislav Khmelevsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 16 09:48:44 PDT 2022


yota9 created this revision.
yota9 added reviewers: maksfb, rafauler, Amir.
Herald added a subscriber: ayermolo.
Herald added a project: All.
yota9 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Run tentativeLayoutRelocMode twice only if UseOldText option was passed.
Refactor BF loop to break on condtition met.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121825

Files:
  bolt/lib/Passes/LongJmp.cpp


Index: bolt/lib/Passes/LongJmp.cpp
===================================================================
--- bolt/lib/Passes/LongJmp.cpp
+++ bolt/lib/Passes/LongJmp.cpp
@@ -322,14 +322,20 @@
   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,22 @@
   }
 
   // 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);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121825.415880.patch
Type: text/x-patch
Size: 1862 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220316/76a4af06/attachment.bin>


More information about the llvm-commits mailing list