[PATCH] D122065: [BOLT] Align constant islands to 8 bytes

Vladislav Khmelevsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 19 04:44:42 PDT 2022


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

AArch64 requires CI to be aligned to 8 bytes due to access instructions
restrictions. E.g. the ldr with imm, where imm must be aligned to 8 bytes.
The test is not provided due to impossibility to link such a test, the linker
won't give to create non-aligned constant island access.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122065

Files:
  bolt/include/bolt/Core/BinaryFunction.h
  bolt/lib/Core/BinaryEmitter.cpp
  bolt/lib/Passes/LongJmp.cpp
  bolt/test/runtime/AArch64/adrrelaxationpass.s


Index: bolt/test/runtime/AArch64/adrrelaxationpass.s
===================================================================
--- bolt/test/runtime/AArch64/adrrelaxationpass.s
+++ bolt/test/runtime/AArch64/adrrelaxationpass.s
@@ -41,9 +41,9 @@
   .word 0xff
 
 # CHECK: <main>:
-# CHECK-NEXT: adr x0, #28
+# CHECK-NEXT: adr x0, #{{[0-9][0-9]*}}
 # CHECK-NEXT: adrp x1, 0x{{[1-8a-f][0-9a-f]*}}
 # CHECK-NEXT: add x1, x1, #{{[1-8a-f][0-9a-f]*}}
 # CHECK-NEXT: adrp x2, 0x{{[1-8a-f][0-9a-f]*}}
 # CHECK-NEXT: add x2, x2, #{{[1-8a-f][0-9a-f]*}}
-# CHECK-NEXT: adr x3, #4
+# CHECK-NEXT: adr x3, #{{[0-9][0-9]*}}
Index: bolt/lib/Passes/LongJmp.cpp
===================================================================
--- bolt/lib/Passes/LongJmp.cpp
+++ bolt/lib/Passes/LongJmp.cpp
@@ -308,7 +308,10 @@
     LLVM_DEBUG(dbgs() << Func->getPrintName() << " cold tentative: "
                       << Twine::utohexstr(DotAddress) << "\n");
     DotAddress += Func->estimateColdSize();
-    DotAddress += Func->estimateConstantIslandSize();
+    if (Func->hasIslandsInfo()) {
+      DotAddress = alignTo(DotAddress, sizeof(uint64_t));
+      DotAddress += Func->estimateConstantIslandSize();
+    }
   }
   return DotAddress;
 }
@@ -364,7 +367,12 @@
       DotAddress += Func->estimateSize();
     else
       DotAddress += Func->estimateHotSize();
-    DotAddress += Func->estimateConstantIslandSize();
+
+    if (Func->hasIslandsInfo()) {
+      DotAddress = alignTo(DotAddress, sizeof(uint64_t));
+      DotAddress += Func->estimateConstantIslandSize();
+    }
+
     ++CurrentIndex;
   }
   // BBs
Index: bolt/lib/Core/BinaryEmitter.cpp
===================================================================
--- bolt/lib/Core/BinaryEmitter.cpp
+++ bolt/lib/Core/BinaryEmitter.cpp
@@ -500,6 +500,10 @@
   if (Islands.DataOffsets.empty() && Islands.Dependency.empty())
     return;
 
+  // AArch64 requires CI to be aligned to 8 bytes due to access instructions
+  // restrictions. E.g. the ldr with imm, where imm must be aligned to 8 bytes.
+  Streamer.emitCodeAlignment(sizeof(uint64_t), &*BC.STI);
+
   if (!OnBehalfOf) {
     if (!EmitColdPart)
       Streamer.emitLabel(BF.getFunctionConstantIslandLabel());
Index: bolt/include/bolt/Core/BinaryFunction.h
===================================================================
--- bolt/include/bolt/Core/BinaryFunction.h
+++ bolt/include/bolt/Core/BinaryFunction.h
@@ -2074,9 +2074,13 @@
       Size += NextMarker - *DataIter;
     }
 
-    if (!OnBehalfOf)
-      for (BinaryFunction *ExternalFunc : Islands->Dependency)
+    if (!OnBehalfOf) {
+      for (BinaryFunction *ExternalFunc : Islands->Dependency) {
+        Size = alignTo(Size, sizeof(uint64_t));
         Size += ExternalFunc->estimateConstantIslandSize(this);
+      }
+    }
+
     return Size;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122065.416685.patch
Type: text/x-patch
Size: 2804 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220319/cce85f16/attachment.bin>


More information about the llvm-commits mailing list