Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 14, 2025

Conversation

mingmingl-llvm
Copy link
Contributor

This is a follow-up patch of #125993 to port jump table partitions for aarch64.

@mingmingl-llvm
Copy link
Contributor Author

cc @Colibrow

@llvmbot
Copy link
Member

llvmbot commented Feb 6, 2025

@llvm/pr-subscribers-backend-aarch64

Author: Mingming Liu (mingmingl-llvm)

Changes

This is a follow-up patch of #125993 to port jump table partitions for aarch64.


Full diff: https://github.com/llvm/llvm-project/pull/126018.diff

2 Files Affected:

  • (modified) llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp (+10-2)
  • (modified) llvm/test/CodeGen/AArch64/jump-table-partition.ll (+7-6)
diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index c92c203f247954..0593c1cd2b14d2 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -1280,10 +1280,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();
+  const std::vector<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 e0525d0384a978..d282c366578d70 100644
--- a/llvm/test/CodeGen/AArch64/jump-table-partition.ll
+++ b/llvm/test/CodeGen/AArch64/jump-table-partition.ll
@@ -35,16 +35,17 @@
 ; RUN:     -aarch64-enable-atomic-cfg-tidy=false -aarch64-min-jump-table-entries=2 \
 ; RUN:     %s -o - 2>&1 | FileCheck %s --check-prefixes=FUNCLESS,JT
 
-; 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.
-; NUM:      .section .rodata.hot.,"a",@progbits,unique,2
+; 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",@progbits,unique,2
 ; FUNC:     .section .rodata.hot.foo,"a",@progbits
 ; FUNCLESS: .section .rodata.hot.,"a",@progbits
 ; JT: .LJTI0_0:
 ; JT: .LJTI0_2:
-; NUM:            .section	.rodata.hot.,"a",@progbits,unique,3
-; FUNC-NOT:       .section .rodata.hot.foo
-; FUNCLESS-NOT:   .section .rodata.hot.,"a",@progbits
+; NUM:        .section .rodata.unlikely.,"a",@progbits,unique,3
+; FUNC:       .section .rodata.unlikely.foo,
+; FUNCLESS:   .section .rodata.unlikely.,"a",@progbits
 ; JT: .LJTI0_1:
 ; JT: .LJTI0_3:
 

@mingmingl-llvm
Copy link
Contributor Author

Hi folks, a reminder about this change when you have a moment :) thanks!

Copy link
Collaborator

@davemgreen davemgreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

mingmingl-llvm added a commit that referenced this pull request Apr 14, 2025
…e for jump table partitions on aarch64 (#125993)

With
3feb724,
AsmPrinter can place jump table entries into `.hot` or `.unlikely`
prefixed data sections. This change refactors AsmPrinter and
AArch64AsmPrinter to prepare for the aarch64 port.

* Before this patch, the AsmPrinter class exposes `emitJumpTableInfo` as
a virtual method, and AArch64AsmPrinter overrides `emitJumpTableInfo`
for jump table emission.
* After this patch, both AsmPrinter and AArch64AsmPrinter shares
`AsmPrinter::emitJumpTableInfo`, and class-specific code are moved
inside each class's `emitJumpTableImpl` respectively.

This is a follow-up of #125987,
and #126018 implements the port
for aarch64.
Base automatically changed from users/mingmingl-llvm/spr/nfc to main April 14, 2025 18:08
@mingmingl-llvm mingmingl-llvm changed the base branch from main to users/mingmingl-llvm/spr/nfc April 14, 2025 18:33
@mingmingl-llvm mingmingl-llvm changed the base branch from users/mingmingl-llvm/spr/nfc to main April 14, 2025 18:42
@mingmingl-llvm
Copy link
Contributor Author

Sorry for the spam! I forgot the change the base branch after merging the main branch.

llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Apr 14, 2025
…r to prepare for jump table partitions on aarch64 (#125993)

With
llvm/llvm-project@3feb724,
AsmPrinter can place jump table entries into `.hot` or `.unlikely`
prefixed data sections. This change refactors AsmPrinter and
AArch64AsmPrinter to prepare for the aarch64 port.

* Before this patch, the AsmPrinter class exposes `emitJumpTableInfo` as
a virtual method, and AArch64AsmPrinter overrides `emitJumpTableInfo`
for jump table emission.
* After this patch, both AsmPrinter and AArch64AsmPrinter shares
`AsmPrinter::emitJumpTableInfo`, and class-specific code are moved
inside each class's `emitJumpTableImpl` respectively.

This is a follow-up of llvm/llvm-project#125987,
and llvm/llvm-project#126018 implements the port
for aarch64.
@mingmingl-llvm mingmingl-llvm merged commit be4c99a into main Apr 14, 2025
15 of 23 checks passed
@mingmingl-llvm mingmingl-llvm deleted the users/mingmingl-llvm/spr/aarch64jumptables branch April 14, 2025 19:58
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
…e for jump table partitions on aarch64 (llvm#125993)

With
llvm@3feb724,
AsmPrinter can place jump table entries into `.hot` or `.unlikely`
prefixed data sections. This change refactors AsmPrinter and
AArch64AsmPrinter to prepare for the aarch64 port.

* Before this patch, the AsmPrinter class exposes `emitJumpTableInfo` as
a virtual method, and AArch64AsmPrinter overrides `emitJumpTableInfo`
for jump table emission.
* After this patch, both AsmPrinter and AArch64AsmPrinter shares
`AsmPrinter::emitJumpTableInfo`, and class-specific code are moved
inside each class's `emitJumpTableImpl` respectively.

This is a follow-up of llvm#125987,
and llvm#126018 implements the port
for aarch64.
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
…sections for aarch64 (llvm#126018)

This is a follow-up patch of
llvm#125993 to port jump table
partitions for aarch64.

---------

Co-authored-by: Ellis Hoag <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants