Skip to content

Commit 6ab9973

Browse files
[NFC][Test]Add a test case for aarch64 jump table sections
1 parent 659d1fe commit 6ab9973

File tree

1 file changed

+243
-0
lines changed

1 file changed

+243
-0
lines changed
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
; -stats requires asserts
2+
; REQUIRES: asserts
3+
4+
; Stop after 'finalize-isel' for simpler MIR.
5+
; Override 'aarch64-enable-atomic-cfg-tidy' to false to turn off simplifycfg
6+
; pass, which can simplify away switch instructions before isel lowers switch
7+
; into jump tables.
8+
; Override 'aarch64-min-jump-table-entries' so 'switch' needs fewer cases to
9+
; generate a jump table.
10+
; RUN: llc -mtriple=aarch64-unknown-linux-gnu -stop-after=finalize-isel -aarch64-enable-atomic-cfg-tidy=false -aarch64-min-jump-table-entries=2 %s -o %t.mir
11+
; RUN: llc -mtriple=aarch64-unknown-linux-gnu --run-pass=static-data-splitter -stats -x mir %t.mir -o - 2>&1 | FileCheck %s --check-prefix=STAT
12+
13+
; @foo has 2 hot and 2 cold jump tables.
14+
; The two jump tables with unknown hotness come from @func_without_profile and
15+
; @bar respectively.
16+
; STAT: 2 static-data-splitter - Number of cold jump tables seen
17+
; STAT: 2 static-data-splitter - Number of hot jump tables seen
18+
; STAT: 2 static-data-splitter - Number of jump tables with unknown hotness
19+
20+
; RUN: llc -mtriple=aarch64-unknown-linux-gnu -enable-split-machine-functions \
21+
; RUN: -partition-static-data-sections=true -function-sections=true \
22+
; RUN: -aarch64-enable-atomic-cfg-tidy=false -aarch64-min-jump-table-entries=2 \
23+
; RUN: -unique-section-names=false %s -o - 2>&1 | FileCheck %s --check-prefixes=NUM,JT
24+
25+
; Section names will optionally have `.<func>` if -function-sections is enabled.
26+
; RUN: llc -mtriple=aarch64-unknown-linux-gnu -enable-split-machine-functions \
27+
; RUN: -partition-static-data-sections=true -function-sections=true \
28+
; RUN: -aarch64-enable-atomic-cfg-tidy=false -aarch64-min-jump-table-entries=2 \
29+
; RUN: %s -o - 2>&1 | FileCheck %s --check-prefixes=FUNC,JT
30+
31+
; RUN: llc -mtriple=aarch64-unknown-linux-gnu -enable-split-machine-functions \
32+
; RUN: -partition-static-data-sections=true -function-sections=false \
33+
; RUN: -aarch64-enable-atomic-cfg-tidy=false -aarch64-min-jump-table-entries=2 \
34+
; RUN: %s -o - 2>&1 | FileCheck %s --check-prefixes=FUNCLESS,JT
35+
36+
; A function's section prefix is used for all jump tables of this function.
37+
; @foo is hot so its jump table data section has a hot prefix.
38+
; NUM: .section .rodata.hot.,"a",@progbits,unique,2
39+
; FUNC: .section .rodata.hot.foo,"a",@progbits
40+
; FUNCLESS: .section .rodata.hot.,"a",@progbits
41+
; JT: .LJTI0_0:
42+
; JT: .LJTI0_1:
43+
; JT: .LJTI0_2:
44+
; JT: .LJTI0_3:
45+
46+
; func_without_profile doesn't have profiles, so its jumptable doesn't have
47+
; hotness-based prefix.
48+
; NUM: .section .rodata,"a",@progbits,unique,4
49+
; FUNC: .section .rodata.func_without_profile,"a",@progbits
50+
; FUNCLESS: .section .rodata,"a",@progbits
51+
; JT: .LJTI1_0:
52+
53+
; @bar doesn't have profile information and it has a section prefix.
54+
; Tests that its jump tables are placed in sections with function prefixes.
55+
; NUM: .section .rodata.bar_prefix.,"a",@progbits,unique,
56+
; FUNC: .section .rodata.bar_prefix.bar
57+
; FUNCLESS: .section .rodata.bar_prefix.,"a"
58+
; JT: .LJTI2_0
59+
60+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
61+
target triple = "aarch64-unknown-linux-gnu"
62+
63+
@str.9 = private constant [7 x i8] c".str.9\00"
64+
@str.10 = private constant [8 x i8] c".str.10\00"
65+
@str.11 = private constant [8 x i8] c".str.11\00"
66+
67+
@case2 = private constant [7 x i8] c"case 2\00"
68+
@case1 = private constant [7 x i8] c"case 1\00"
69+
@default = private constant [8 x i8] c"default\00"
70+
@jt3 = private constant [4 x i8] c"jt3\00"
71+
72+
; jt0 and jt2 are hot. jt1 and jt3 are cold.
73+
define i32 @foo(i32 %num) !prof !13 {
74+
entry:
75+
%mod3 = sdiv i32 %num, 3
76+
switch i32 %mod3, label %jt0.default [
77+
i32 1, label %jt0.bb1
78+
i32 2, label %jt0.bb2
79+
], !prof !14
80+
81+
jt0.bb1:
82+
call i32 @puts(ptr @case1)
83+
br label %jt0.epilog
84+
85+
jt0.bb2:
86+
call i32 @puts(ptr @case2)
87+
br label %jt0.epilog
88+
89+
jt0.default:
90+
call i32 @puts(ptr @default)
91+
br label %jt0.epilog
92+
93+
jt0.epilog:
94+
%zero = icmp eq i32 %num, 0
95+
br i1 %zero, label %hot, label %cold, !prof !17
96+
97+
hot:
98+
%c2 = call i32 @transform(i32 %num)
99+
switch i32 %c2, label %jt2.default [
100+
i32 1, label %jt2.bb1
101+
i32 2, label %jt2.bb2
102+
], !prof !14
103+
104+
jt2.bb1:
105+
call i32 @puts(ptr @case1)
106+
br label %jt1.epilog
107+
108+
jt2.bb2:
109+
call i32 @puts(ptr @case2)
110+
br label %jt1.epilog
111+
112+
jt2.default:
113+
call i32 @puts(ptr @default)
114+
br label %jt2.epilog
115+
116+
jt2.epilog:
117+
%c2cmp = icmp ne i32 %c2, 0
118+
br i1 %c2cmp, label %return, label %jt3.prologue, !prof !18
119+
120+
cold:
121+
%c1 = call i32 @compute(i32 %num)
122+
switch i32 %c1, label %jt1.default [
123+
i32 1, label %jt1.bb1
124+
i32 2, label %jt1.bb2
125+
], !prof !14
126+
127+
jt1.bb1:
128+
call i32 @puts(ptr @case1)
129+
br label %jt1.epilog
130+
131+
jt1.bb2:
132+
call i32 @puts(ptr @case2)
133+
br label %jt1.epilog
134+
135+
jt1.default:
136+
call i32 @puts(ptr @default)
137+
br label %jt1.epilog
138+
139+
jt1.epilog:
140+
br label %return
141+
142+
jt3.prologue:
143+
%c3 = call i32 @cleanup(i32 %num)
144+
switch i32 %c3, label %jt3.default [
145+
i32 1, label %jt3.bb1
146+
i32 2, label %jt3.bb2
147+
], !prof !14
148+
149+
jt3.bb1:
150+
call i32 @puts(ptr @case1)
151+
br label %jt3.epilog
152+
153+
jt3.bb2:
154+
call i32 @puts(ptr @case2)
155+
br label %jt3.epilog
156+
157+
jt3.default:
158+
call i32 @puts(ptr @default)
159+
br label %jt3.epilog
160+
161+
jt3.epilog:
162+
call i32 @puts(ptr @jt3)
163+
br label %return
164+
165+
return:
166+
ret i32 %mod3
167+
}
168+
169+
define void @func_without_profile(i32 %num) {
170+
entry:
171+
switch i32 %num, label %sw.default [
172+
i32 1, label %sw.bb
173+
i32 2, label %sw.bb1
174+
]
175+
176+
sw.bb:
177+
call i32 @puts(ptr @str.10)
178+
br label %sw.epilog
179+
180+
sw.bb1:
181+
call i32 @puts(ptr @str.9)
182+
br label %sw.epilog
183+
184+
sw.default:
185+
call i32 @puts(ptr @str.11)
186+
br label %sw.epilog
187+
188+
sw.epilog:
189+
ret void
190+
}
191+
192+
define void @bar(i32 %num) !section_prefix !20 {
193+
entry:
194+
switch i32 %num, label %sw.default [
195+
i32 1, label %sw.bb
196+
i32 2, label %sw.bb1
197+
]
198+
199+
sw.bb:
200+
call i32 @puts(ptr @str.10)
201+
br label %sw.epilog
202+
203+
sw.bb1:
204+
call i32 @puts(ptr @str.9)
205+
br label %sw.epilog
206+
207+
sw.default:
208+
call i32 @puts(ptr @str.11)
209+
br label %sw.epilog
210+
211+
sw.epilog:
212+
ret void
213+
}
214+
215+
declare i32 @puts(ptr)
216+
declare i32 @printf(ptr, ...)
217+
declare i32 @compute(i32)
218+
declare i32 @transform(i32)
219+
declare i32 @cleanup(i32)
220+
221+
!llvm.module.flags = !{!0}
222+
223+
!0 = !{i32 1, !"ProfileSummary", !1}
224+
!1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
225+
!2 = !{!"ProfileFormat", !"InstrProf"}
226+
!3 = !{!"TotalCount", i64 230002}
227+
!4 = !{!"MaxCount", i64 100000}
228+
!5 = !{!"MaxInternalCount", i64 50000}
229+
!6 = !{!"MaxFunctionCount", i64 100000}
230+
!7 = !{!"NumCounts", i64 14}
231+
!8 = !{!"NumFunctions", i64 3}
232+
!9 = !{!"DetailedSummary", !10}
233+
!10 = !{!11, !12}
234+
!11 = !{i32 990000, i64 10000, i32 7}
235+
!12 = !{i32 999999, i64 1, i32 9}
236+
!13 = !{!"function_entry_count", i64 100000}
237+
!14 = !{!"branch_weights", i32 60000, i32 20000, i32 20000}
238+
!15 = !{!"function_entry_count", i64 1}
239+
!16 = !{!"branch_weights", i32 1, i32 0, i32 0, i32 0, i32 0, i32 0}
240+
!17 = !{!"branch_weights", i32 99999, i32 1}
241+
!18 = !{!"branch_weights", i32 99998, i32 1}
242+
!19 = !{!"branch_weights", i32 97000, i32 1000, i32 1000, i32 1000}
243+
!20 = !{!"function_section_prefix", !"bar_prefix"}

0 commit comments

Comments
 (0)