[llvm] be4c99a - [AArch64AsmPrinter]Place jump tables into hot/unlikely-prefixed data sections for aarch64 (#126018)

via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 14 12:58:01 PDT 2025


Author: Mingming Liu
Date: 2025-04-14T12:57:58-07:00
New Revision: be4c99ae112f572695c3e187f4ef4ac4cd592783

URL: https://github.com/llvm/llvm-project/commit/be4c99ae112f572695c3e187f4ef4ac4cd592783
DIFF: https://github.com/llvm/llvm-project/commit/be4c99ae112f572695c3e187f4ef4ac4cd592783.diff

LOG: [AArch64AsmPrinter]Place jump tables into hot/unlikely-prefixed data sections for aarch64 (#126018)

This is a follow-up patch of
https://github.com/llvm/llvm-project/pull/125993 to port jump table
partitions for aarch64.

---------

Co-authored-by: Ellis Hoag <ellis.sparky.hoag at gmail.com>

Added: 
    

Modified: 
    llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
    llvm/test/CodeGen/AArch64/jump-table-partition.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index 132e962a065e3..870df4c387ca4 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -1297,10 +1297,18 @@ void AArch64AsmPrinter::emitJumpTableImpl(const MachineJumpTableInfo &MJTI,
   if (JumpTableIndices.empty())
     return;
   const TargetLoweringObjectFile &TLOF = getObjFileLowering();
-  MCSection *ReadOnlySec = TLOF.getSectionForJumpTable(MF->getFunction(), TM);
+  const auto &F = MF->getFunction();
+  ArrayRef<MachineJumpTableEntry> JT = MJTI.getJumpTables();
+
+  MCSection *ReadOnlySec = nullptr;
+  if (TM.Options.EnableStaticDataPartitioning) {
+    ReadOnlySec =
+        TLOF.getSectionForJumpTable(F, TM, &JT[JumpTableIndices.front()]);
+  } else {
+    ReadOnlySec = TLOF.getSectionForJumpTable(F, TM);
+  }
   OutStreamer->switchSection(ReadOnlySec);
 
-  const std::vector<MachineJumpTableEntry> &JT = MJTI.getJumpTables();
   auto AFI = MF->getInfo<AArch64FunctionInfo>();
   for (unsigned JTI : JumpTableIndices) {
     const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;

diff  --git a/llvm/test/CodeGen/AArch64/jump-table-partition.ll b/llvm/test/CodeGen/AArch64/jump-table-partition.ll
index 14717d718c146..47a7aa5306f41 100644
--- a/llvm/test/CodeGen/AArch64/jump-table-partition.ll
+++ b/llvm/test/CodeGen/AArch64/jump-table-partition.ll
@@ -52,16 +52,17 @@ target triple = "aarch64-unknown-linux-gnu"
 @default = private constant [8 x i8] c"default\00"
 @jt3 = private constant [4 x i8] c"jt3\00"
 
-; A function's section prefix is used for all jump tables of this function.
-; @foo is hot so its jump table data section has a hot prefix.
+; In function @foo, the 2 switch instructions to jt0.* and jt1.* are placed in
+; hot-prefixed sections, and the 2 switch instructions to jt2.* and jt3.* are
+; placed in cold-prefixed sections.
 ; NUM:          .section .rodata.hot.,"a", at progbits,unique,2
 ; FUNC:         .section .rodata.hot.foo,"a", at progbits
 ; FUNCLESS:     .section .rodata.hot.,"a", at progbits
 ; JT:           .LJTI0_0:
 ; JT:           .LJTI0_2:
-; NUM:          .section	.rodata.hot.,"a", at progbits,unique,3
-; FUNC-NOT:     .section .rodata.hot.foo
-; FUNCLESS-NOT: .section .rodata.hot.,"a", at progbits
+; NUM:          .section .rodata.unlikely.,"a", at progbits,unique,3
+; FUNC:         .section .rodata.unlikely.foo
+; FUNCLESS:     .section .rodata.unlikely.,"a", at progbits
 ; JT:           .LJTI0_1:
 ; JT:           .LJTI0_3:
 


        


More information about the llvm-commits mailing list