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 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 &JT = MJTI.getJumpTables(); auto AFI = MF->getInfo(); for (unsigned JTI : JumpTableIndices) { const std::vector &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",@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: