Skip to content

Commit be4c99a

Browse files
[AArch64AsmPrinter]Place jump tables into hot/unlikely-prefixed data sections for aarch64 (#126018)
This is a follow-up patch of #125993 to port jump table partitions for aarch64. --------- Co-authored-by: Ellis Hoag <[email protected]>
1 parent 202cd7b commit be4c99a

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,10 +1297,18 @@ void AArch64AsmPrinter::emitJumpTableImpl(const MachineJumpTableInfo &MJTI,
12971297
if (JumpTableIndices.empty())
12981298
return;
12991299
const TargetLoweringObjectFile &TLOF = getObjFileLowering();
1300-
MCSection *ReadOnlySec = TLOF.getSectionForJumpTable(MF->getFunction(), TM);
1300+
const auto &F = MF->getFunction();
1301+
ArrayRef<MachineJumpTableEntry> JT = MJTI.getJumpTables();
1302+
1303+
MCSection *ReadOnlySec = nullptr;
1304+
if (TM.Options.EnableStaticDataPartitioning) {
1305+
ReadOnlySec =
1306+
TLOF.getSectionForJumpTable(F, TM, &JT[JumpTableIndices.front()]);
1307+
} else {
1308+
ReadOnlySec = TLOF.getSectionForJumpTable(F, TM);
1309+
}
13011310
OutStreamer->switchSection(ReadOnlySec);
13021311

1303-
const std::vector<MachineJumpTableEntry> &JT = MJTI.getJumpTables();
13041312
auto AFI = MF->getInfo<AArch64FunctionInfo>();
13051313
for (unsigned JTI : JumpTableIndices) {
13061314
const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;

llvm/test/CodeGen/AArch64/jump-table-partition.ll

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,17 @@ target triple = "aarch64-unknown-linux-gnu"
5252
@default = private constant [8 x i8] c"default\00"
5353
@jt3 = private constant [4 x i8] c"jt3\00"
5454

55-
; A function's section prefix is used for all jump tables of this function.
56-
; @foo is hot so its jump table data section has a hot prefix.
55+
; In function @foo, the 2 switch instructions to jt0.* and jt1.* are placed in
56+
; hot-prefixed sections, and the 2 switch instructions to jt2.* and jt3.* are
57+
; placed in cold-prefixed sections.
5758
; NUM: .section .rodata.hot.,"a",@progbits,unique,2
5859
; FUNC: .section .rodata.hot.foo,"a",@progbits
5960
; FUNCLESS: .section .rodata.hot.,"a",@progbits
6061
; JT: .LJTI0_0:
6162
; JT: .LJTI0_2:
62-
; NUM: .section .rodata.hot.,"a",@progbits,unique,3
63-
; FUNC-NOT: .section .rodata.hot.foo
64-
; FUNCLESS-NOT: .section .rodata.hot.,"a",@progbits
63+
; NUM: .section .rodata.unlikely.,"a",@progbits,unique,3
64+
; FUNC: .section .rodata.unlikely.foo
65+
; FUNCLESS: .section .rodata.unlikely.,"a",@progbits
6566
; JT: .LJTI0_1:
6667
; JT: .LJTI0_3:
6768

0 commit comments

Comments
 (0)