Skip to content

Commit fb2e048

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

File tree

1 file changed

+248
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)