[llvm] [BOLT][RISCV] Improve relocations, jump tables, and split-function handling (PR #213919)

via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 4 05:11:32 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp -- bolt/include/bolt/Core/BinaryContext.h bolt/include/bolt/Core/JumpTable.h bolt/include/bolt/Core/MCPlusBuilder.h bolt/include/bolt/Core/Relocation.h bolt/include/bolt/Rewrite/RewriteInstance.h bolt/lib/Core/BinaryContext.cpp bolt/lib/Core/BinaryFunction.cpp bolt/lib/Core/BinarySection.cpp bolt/lib/Core/JumpTable.cpp bolt/lib/Core/Relocation.cpp bolt/lib/Passes/FixRISCVCallsPass.cpp bolt/lib/Passes/IndirectCallPromotion.cpp bolt/lib/Passes/LongJmp.cpp bolt/lib/Rewrite/BinaryPassManager.cpp bolt/lib/Rewrite/RewriteInstance.cpp bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp bolt/lib/Target/X86/X86MCPlusBuilder.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/bolt/include/bolt/Core/MCPlusBuilder.h b/bolt/include/bolt/Core/MCPlusBuilder.h
index 77def0b4f..cd4270e16 100644
--- a/bolt/include/bolt/Core/MCPlusBuilder.h
+++ b/bolt/include/bolt/Core/MCPlusBuilder.h
@@ -1157,9 +1157,10 @@ public:
   /// Retarget the reference used by the jump-table dispatch at the end of
   /// \p InstrWindow from \p OldTarget to \p NewTarget. Targets that need
   /// architecture-specific multi-instruction matching can override this hook.
-  virtual bool replaceJumpTableReference(
-      MutableArrayRef<MCInst> InstrWindow, const MCSymbol *OldTarget,
-      const MCSymbol *NewTarget, MCContext *Ctx) const {
+  virtual bool replaceJumpTableReference(MutableArrayRef<MCInst> InstrWindow,
+                                         const MCSymbol *OldTarget,
+                                         const MCSymbol *NewTarget,
+                                         MCContext *Ctx) const {
     return false;
   }
 
diff --git a/bolt/include/bolt/Rewrite/RewriteInstance.h b/bolt/include/bolt/Rewrite/RewriteInstance.h
index 53e173fce..96e5deb1f 100644
--- a/bolt/include/bolt/Rewrite/RewriteInstance.h
+++ b/bolt/include/bolt/Rewrite/RewriteInstance.h
@@ -564,8 +564,8 @@ private:
       {".plt"}, {".plt.got"}, {".iplt"}, {nullptr}};
 
   /// RISCV PLT sections.
-  const PLTSectionInfo RISCV_PLTSections[3] = {{".plt"}, {".iplt", 16},
-                                               {nullptr}};
+  const PLTSectionInfo RISCV_PLTSections[3] = {
+      {".plt"}, {".iplt", 16}, {nullptr}};
 
   /// Return PLT information for a section with \p SectionName or nullptr
   /// if the section is not PLT.
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 488a7ef38..94c6d5e03 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -4303,8 +4303,8 @@ void BinaryFunction::disambiguateJumpTables(
             BC.duplicateJumpTable(*this, JT, OldJTLabel);
 
         MutableArrayRef<MCInst> InstrWindow(&*BB->begin(), &Inst + 1);
-        if (!BC.MIB->replaceJumpTableReference(
-                InstrWindow, OldJTLabel, NewJTLabel, BC.Ctx.get())) {
+        if (!BC.MIB->replaceJumpTableReference(InstrWindow, OldJTLabel,
+                                               NewJTLabel, BC.Ctx.get())) {
           BC.errs() << "BOLT-ERROR: failed to retarget duplicated RISC-V jump "
                        "table in function "
                     << *this << '\n';
diff --git a/bolt/lib/Core/BinarySection.cpp b/bolt/lib/Core/BinarySection.cpp
index 920552366..2e8dc277f 100644
--- a/bolt/lib/Core/BinarySection.cpp
+++ b/bolt/lib/Core/BinarySection.cpp
@@ -209,8 +209,8 @@ void BinarySection::flushPendingRelocations(raw_fd_ostream &OS,
     Value = Relocation::encodeValue(Reloc.Type, Value,
                                     SectionAddress + Reloc.Offset, OldValue);
 
-    safePWrite(OS, reinterpret_cast<const char *>(&Value),
-               RelocSize, SectionFileOffset + Reloc.Offset);
+    safePWrite(OS, reinterpret_cast<const char *>(&Value), RelocSize,
+               SectionFileOffset + Reloc.Offset);
 
     LLVM_DEBUG(
         dbgs() << "BOLT-DEBUG: writing value 0x" << Twine::utohexstr(Value)
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index ad2ab39f5..e7d59d9aa 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -5671,8 +5671,8 @@ void RewriteInstance::updateELFSymbolTable(
     // marker-specific path below handle them; otherwise addExtraSymbols()
     // creates invalid split names such as "$xrv64i...cold.0".
     auto IsMarkerSymbol = [&]() {
-      return BC->getMarkerType(Symbol.getType(), Symbol.st_size,
-                               *SymbolName) != MarkerSymType::NONE;
+      return BC->getMarkerType(Symbol.getType(), Symbol.st_size, *SymbolName) !=
+             MarkerSymType::NONE;
     };
     if (Function && IsMarkerSymbol())
       Function = nullptr;
diff --git a/bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp b/bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp
index 5465306c3..ecc31e6d0 100644
--- a/bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp
+++ b/bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp
@@ -276,10 +276,9 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
   }
 
   bool replaceJumpTableSymbol(MCInst &Inst, const MCSymbol *OldTarget,
-                              const MCSymbol *NewTarget,
-                              MCContext *Ctx) const {
-    for (unsigned OpIndex = 0;
-         OpIndex < MCPlus::getNumPrimeOperands(Inst); ++OpIndex) {
+                              const MCSymbol *NewTarget, MCContext *Ctx) const {
+    for (unsigned OpIndex = 0; OpIndex < MCPlus::getNumPrimeOperands(Inst);
+         ++OpIndex) {
       MCOperand &Operand = Inst.getOperand(OpIndex);
       if (!Operand.isExpr())
         continue;
@@ -621,9 +620,10 @@ public:
     return IndirectBranchType::POSSIBLE_JUMP_TABLE;
   }
 
-  bool replaceJumpTableReference(
-      MutableArrayRef<MCInst> InstrWindow, const MCSymbol *OldTarget,
-      const MCSymbol *NewTarget, MCContext *Ctx) const override {
+  bool replaceJumpTableReference(MutableArrayRef<MCInst> InstrWindow,
+                                 const MCSymbol *OldTarget,
+                                 const MCSymbol *NewTarget,
+                                 MCContext *Ctx) const override {
     for (MCInst &Inst : llvm::reverse(InstrWindow)) {
       switch (Inst.getOpcode()) {
       default:

``````````

</details>


https://github.com/llvm/llvm-project/pull/213919


More information about the llvm-commits mailing list