[PATCH] D132104: [BOLT][NFC] Move out handleAArch64IndirectCall

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 23 15:39:03 PDT 2022


Amir created this revision.
Herald added subscribers: ayermolo, kristof.beyls.
Herald added a reviewer: rafauler.
Herald added a reviewer: maksfb.
Herald added a project: All.
Amir published this revision for review.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.

Move the large lambda out of BinaryFunction::disassemble, reducing its size from
255 to 233 LoC.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132104

Files:
  bolt/include/bolt/Core/BinaryFunction.h
  bolt/lib/Core/BinaryFunction.cpp


Index: bolt/lib/Core/BinaryFunction.cpp
===================================================================
--- bolt/lib/Core/BinaryFunction.cpp
+++ bolt/lib/Core/BinaryFunction.cpp
@@ -1132,6 +1132,28 @@
   }
 }
 
+void BinaryFunction::handleAArch64IndirectCall(MCInst &Instruction,
+                                               const uint64_t Offset) {
+  auto &MIB = BC.MIB;
+  const uint64_t AbsoluteInstrAddr = getAddress() + Offset;
+  MCInst *TargetHiBits, *TargetLowBits;
+  uint64_t TargetAddress, Count;
+  Count = MIB->matchLinkerVeneer(Instructions.begin(), Instructions.end(),
+                                 AbsoluteInstrAddr, Instruction, TargetHiBits,
+                                 TargetLowBits, TargetAddress);
+  if (Count) {
+    MIB->addAnnotation(Instruction, "AArch64Veneer", true);
+    --Count;
+    for (auto It = std::prev(Instructions.end()); Count != 0;
+         It = std::prev(It), --Count) {
+      MIB->addAnnotation(It->second, "AArch64Veneer", true);
+    }
+
+    BC.addAdrpAddRelocAArch64(*this, *TargetLowBits, *TargetHiBits,
+                              TargetAddress);
+  }
+}
+
 bool BinaryFunction::disassemble() {
   NamedRegionTimer T("disassemble", "Disassemble function", "buildfuncs",
                      "Build Binary Functions", opts::TimeBuild);
@@ -1150,28 +1172,6 @@
   // basic block.
   Labels[0] = Ctx->createNamedTempSymbol("BB0");
 
-  // Check for linker veneers, which lack relocations and need manual
-  // adjustments.
-  auto handleAArch64IndirectCall = [&](MCInst &Instruction, uint64_t Offset) {
-    const uint64_t AbsoluteInstrAddr = getAddress() + Offset;
-    MCInst *TargetHiBits, *TargetLowBits;
-    uint64_t TargetAddress, Count;
-    Count = MIB->matchLinkerVeneer(Instructions.begin(), Instructions.end(),
-                                   AbsoluteInstrAddr, Instruction, TargetHiBits,
-                                   TargetLowBits, TargetAddress);
-    if (Count) {
-      MIB->addAnnotation(Instruction, "AArch64Veneer", true);
-      --Count;
-      for (auto It = std::prev(Instructions.end()); Count != 0;
-           It = std::prev(It), --Count) {
-        MIB->addAnnotation(It->second, "AArch64Veneer", true);
-      }
-
-      BC.addAdrpAddRelocAArch64(*this, *TargetLowBits, *TargetHiBits,
-                                TargetAddress);
-    }
-  };
-
   uint64_t Size = 0; // instruction size
   for (uint64_t Offset = 0; Offset < getSize(); Offset += Size) {
     MCInst Instruction;
Index: bolt/include/bolt/Core/BinaryFunction.h
===================================================================
--- bolt/include/bolt/Core/BinaryFunction.h
+++ bolt/include/bolt/Core/BinaryFunction.h
@@ -2046,6 +2046,10 @@
   void handleIndirectBranch(MCInst &Instruction, uint64_t Size,
                             uint64_t Offset);
 
+  // Check for linker veneers, which lack relocations and need manual
+  // adjustments.
+  void handleAArch64IndirectCall(MCInst &Instruction, const uint64_t Offset);
+
   /// Scan function for references to other functions. In relocation mode,
   /// add relocations for external references.
   ///


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132104.453541.patch
Type: text/x-patch
Size: 3132 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220823/f299db68/attachment.bin>


More information about the llvm-commits mailing list