Skip to content
12 changes: 10 additions & 2 deletions llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 6 additions & 5 deletions llvm/test/CodeGen/AArch64/jump-table-partition.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
Loading