[PATCH] D121392: [BOLT] Set cold sections alignment explicitly

Vladislav Khmelevsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 10 10:51:16 PST 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.

The cold text section alignment is set using the maximum alignment value
passed to the emitCodeAlignment. In order to calculate tentetive layout
right we will set the alignment of such sections to the maximum possible
function alignment explicitly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121392

Files:
  bolt/include/bolt/Utils/CommandLineOpts.h
  bolt/lib/Core/BinaryEmitter.cpp
  bolt/lib/Passes/Aligner.cpp
  bolt/lib/Passes/LongJmp.cpp
  bolt/lib/Utils/CommandLineOpts.cpp


Index: bolt/lib/Utils/CommandLineOpts.cpp
===================================================================
--- bolt/lib/Utils/CommandLineOpts.cpp
+++ bolt/lib/Utils/CommandLineOpts.cpp
@@ -42,6 +42,11 @@
   cl::Hidden,
   cl::cat(BoltCategory));
 
+cl::opt<unsigned> AlignFunctions(
+    "align-functions",
+    cl::desc("align functions at a given value (relocation mode)"),
+    cl::init(64), cl::ZeroOrMore, cl::cat(BoltOptCategory));
+
 cl::opt<bool>
 AggregateOnly("aggregate-only",
   cl::desc("exit after writing aggregated data file"),
Index: bolt/lib/Passes/LongJmp.cpp
===================================================================
--- bolt/lib/Passes/LongJmp.cpp
+++ bolt/lib/Passes/LongJmp.cpp
@@ -11,7 +11,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "bolt/Passes/LongJmp.h"
-#include "llvm/Support/Alignment.h"
 
 #define DEBUG_TYPE "longjmp"
 
@@ -19,7 +18,7 @@
 
 namespace opts {
 extern cl::OptionCategory BoltOptCategory;
-
+extern cl::opt<unsigned> AlignFunctions;
 extern cl::opt<bool> UseOldText;
 extern cl::opt<bool> HotFunctionsAtEnd;
 
@@ -295,6 +294,7 @@
 uint64_t LongJmpPass::tentativeLayoutRelocColdPart(
     const BinaryContext &BC, std::vector<BinaryFunction *> &SortedFunctions,
     uint64_t DotAddress) {
+  DotAddress = alignTo(DotAddress, llvm::Align(opts::AlignFunctions));
   for (BinaryFunction *Func : SortedFunctions) {
     if (!Func->isSplit())
       continue;
Index: bolt/lib/Passes/Aligner.cpp
===================================================================
--- bolt/lib/Passes/Aligner.cpp
+++ bolt/lib/Passes/Aligner.cpp
@@ -23,6 +23,7 @@
 
 extern cl::opt<bool> AlignBlocks;
 extern cl::opt<bool> PreserveBlocksAlignment;
+extern cl::opt<unsigned> AlignFunctions;
 
 cl::opt<unsigned>
 AlignBlocksMinSize("align-blocks-min-size",
@@ -43,13 +44,6 @@
   cl::Hidden,
   cl::cat(BoltOptCategory));
 
-cl::opt<unsigned>
-AlignFunctions("align-functions",
-  cl::desc("align functions at a given value (relocation mode)"),
-  cl::init(64),
-  cl::ZeroOrMore,
-  cl::cat(BoltOptCategory));
-
 cl::opt<unsigned>
 AlignFunctionsMaxBytes("align-functions-max-bytes",
   cl::desc("maximum number of bytes to use to align functions"),
Index: bolt/lib/Core/BinaryEmitter.cpp
===================================================================
--- bolt/lib/Core/BinaryEmitter.cpp
+++ bolt/lib/Core/BinaryEmitter.cpp
@@ -291,6 +291,12 @@
   BC.Ctx->addGenDwarfSection(Section);
 
   if (BC.HasRelocations) {
+    // Set section alignment to the maximum possible object alignment.
+    // We need this to support LongJmp and other passes that calculates
+    // tentative layout.
+    if (Section->getAlignment() == 1)
+      Section->setAlignment(Align(opts::AlignFunctions));
+
     Streamer.emitCodeAlignment(BinaryFunction::MinAlign, &*BC.STI);
     uint16_t MaxAlignBytes = EmitColdPart ? Function.getMaxColdAlignmentBytes()
                                           : Function.getMaxAlignmentBytes();
Index: bolt/include/bolt/Utils/CommandLineOpts.h
===================================================================
--- bolt/include/bolt/Utils/CommandLineOpts.h
+++ bolt/include/bolt/Utils/CommandLineOpts.h
@@ -30,6 +30,7 @@
 extern llvm::cl::OptionCategory HeatmapCategory;
 
 extern llvm::cl::opt<unsigned> AlignText;
+extern llvm::cl::opt<unsigned> AlignFunctions;
 extern llvm::cl::opt<bool> AggregateOnly;
 extern llvm::cl::opt<unsigned> BucketsPerLine;
 extern llvm::cl::opt<bool> DiffOnly;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121392.414429.patch
Type: text/x-patch
Size: 3507 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220310/2acc7228/attachment-0001.bin>


More information about the llvm-commits mailing list