Skip to content

Commit f659946

Browse files
authored
[SYCL][NFC] Optimize getKernelNamesUsingAssert (#5196)
Now it traverses reversed call graph by BFS algorithm from __devicelib_assert_fail function up to SPIR kernels.
1 parent 2cb9e90 commit f659946

File tree

5 files changed

+112
-151
lines changed

5 files changed

+112
-151
lines changed

llvm/test/tools/sycl-post-link/assert-indirect-with-split-2.ll

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
; marked as using asserts.
1010

1111
; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.table
12-
; RUN: FileCheck %s -input-file=%t_0.prop
12+
; RUN: FileCheck %s -input-file=%t_0.prop -check-prefix=PRESENCE-CHECK
13+
; RUN: FileCheck %s -input-file=%t_0.prop -check-prefix=ABSENCE-CHECK
1314

1415
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
1516
target triple = "spir64-unknown-linux"
@@ -22,9 +23,9 @@ target triple = "spir64-unknown-linux"
2223
@__spirv_BuiltInLocalInvocationId = external dso_local local_unnamed_addr addrspace(1) constant <3 x i64>, align 32
2324
@_ZL10assert_fmt = internal addrspace(2) constant [85 x i8] c"%s:%d: %s: global id: [%lu,%lu,%lu], local id: [%lu,%lu,%lu] Assertion `%s` failed.\0A\00", align 1
2425

25-
; CHECK: [SYCL/assert used]
26+
; PRESENCE-CHECK: [SYCL/assert used]
2627

27-
; CHECK-DAG: main_TU1_kernel1
28+
; PRESENCE-CHECK-DAG: main_TU1_kernel1
2829
define dso_local spir_kernel void @main_TU1_kernel1() #2 {
2930
entry:
3031
call spir_func void @foo()
@@ -38,14 +39,20 @@ entry:
3839
ret void
3940
}
4041

42+
; ABSENCE-CHECK-NOT: empty_kernel
43+
define dso_local spir_kernel void @empty_kernel() {
44+
%1 = ptrtoint void ()* @bar to i64
45+
ret void
46+
}
47+
4148
define dso_local spir_func void @bar() #2 {
4249
entry:
4350
call spir_func void @_Z3foov() ; call assert
4451
call spir_func void @_Z4foo2v() ; indirectly called
4552
ret void
4653
}
4754

48-
; CHECK-DAG: main_TU0_kernel0
55+
; PRESENCE-CHECK-DAG: main_TU0_kernel0
4956
define dso_local spir_kernel void @main_TU0_kernel0() #0 {
5057
entry:
5158
call spir_func void @_Z3foov() ; call assert
@@ -63,13 +70,6 @@ entry:
6370
ret void
6471
}
6572

66-
; CHECK-NOT: main_TU0_kernel1
67-
define dso_local spir_kernel void @main_TU0_kernel1() #0 {
68-
entry:
69-
call spir_func void @_Z4foo1v()
70-
ret void
71-
}
72-
7373
; Function Attrs: nounwind
7474
define dso_local spir_func void @_Z4foo1v() {
7575
entry:
@@ -78,13 +78,19 @@ entry:
7878
ret void
7979
}
8080

81-
; CHECK-DAG: main_TU1_kernel0
81+
; PRESENCE-CHECK-DAG: main_TU1_kernel0
8282
define dso_local spir_kernel void @main_TU1_kernel0() #2 {
8383
entry:
8484
call spir_func void @_Z3foov() ; call assert
8585
ret void
8686
}
8787

88+
; ABSENCE-CHECK-NOT: main_TU0_kernel1
89+
define dso_local spir_kernel void @main_TU0_kernel1() #0 {
90+
entry:
91+
call spir_func void @_Z4foo1v()
92+
ret void
93+
}
8894

8995
; This function is marked with "referenced-indirectly", but it doesn't call an assert
9096
; Function Attrs: nounwind

llvm/test/tools/sycl-post-link/assert-property-1.ll

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
; graph.
44

55
; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.table
6-
; RUN: FileCheck %s -input-file=%t_0.prop
6+
; RUN: FileCheck %s -input-file=%t_0.prop -check-prefix=PRESENCE-CHECK
7+
; RUN: FileCheck %s -input-file=%t_0.prop -check-prefix=ABSENCE-CHECK
78

89
; SYCL source:
910
; void foo() {
@@ -48,7 +49,7 @@ target triple = "spir64_x86_64-unknown-unknown"
4849
@__spirv_BuiltInLocalInvocationId = external dso_local addrspace(1) constant <3 x i64>, align 32
4950
@_ZL10assert_fmt = internal addrspace(2) constant [85 x i8] c"%s:%d: %s: global id: [%lu,%lu,%lu], local id: [%lu,%lu,%lu] Assertion `%s` failed.\0A\00", align 1
5051

51-
; CHECK: [SYCL/assert used]
52+
; PRESENCE-CHECK: [SYCL/assert used]
5253

5354
; Function Attrs: convergent norecurse nounwind mustprogress
5455
define dso_local spir_func void @_Z3foov() {
@@ -57,7 +58,7 @@ entry:
5758
ret void
5859
}
5960

60-
; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE9TheKernel
61+
; PRESENCE-CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE9TheKernel
6162
; Function Attrs: convergent norecurse
6263
define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE9TheKernel"() #0 {
6364
entry:
@@ -71,7 +72,7 @@ entry:
7172
ret void
7273
}
7374

74-
; CHECK-NOT: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE10TheKernel2
75+
; ABSENCE-CHECK-NOT: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE10TheKernel2
7576
; Function Attrs: norecurse
7677
define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE10TheKernel2"() #1 {
7778
entry:
@@ -94,7 +95,7 @@ entry:
9495
ret void
9596
}
9697

97-
; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE10TheKernel3
98+
; PRESENCE-CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE10TheKernel3
9899
; Function Attrs: convergent norecurse
99100
define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE10TheKernel3"() #0 {
100101
entry:

llvm/test/tools/sycl-post-link/assert-property-2.ll

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
; graph.
44

55
; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.table
6-
; RUN: FileCheck %s -input-file=%t_0.prop
6+
; RUN: FileCheck %s -input-file=%t_0.prop -check-prefix=PRESENCE-CHECK
7+
; RUN: FileCheck %s -input-file=%t_0.prop -check-prefix=ABSENCE-CHECK
78

89
; SYCL source:
910
; void assert_func() {
@@ -105,7 +106,7 @@ target triple = "spir64_x86_64-unknown-unknown"
105106
@__PRETTY_FUNCTION__._Z11assert_funcv = private unnamed_addr addrspace(1) constant [19 x i8] c"void assert_func()\00", align 1
106107
@_ZL10assert_fmt = internal addrspace(2) constant [85 x i8] c"%s:%d: %s: global id: [%lu,%lu,%lu], local id: [%lu,%lu,%lu] Assertion `%s` failed.\0A\00", align 1
107108

108-
; CHECK: [SYCL/assert used]
109+
; PRESENCE-CHECK: [SYCL/assert used]
109110

110111
; Function Attrs: convergent noinline norecurse optnone mustprogress
111112
define dso_local spir_func void @_Z1Jv() #3 {
@@ -122,15 +123,15 @@ entry:
122123
ret void
123124
}
124125

125-
; CHECK: _ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E7Kernel9
126+
; PRESENCE-CHECK-DAG: _ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E7Kernel9
126127
; Function Attrs: convergent noinline norecurse mustprogress
127128
define weak_odr dso_local spir_kernel void @_ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E7Kernel9() #0 {
128129
entry:
129130
call spir_func void @_Z1Jv()
130131
ret void
131132
}
132133

133-
; CHECK: _ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E8Kernel10
134+
; PRESENCE-CHECK-DAG: _ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E8Kernel10
134135
; Function Attrs: convergent noinline norecurse optnone mustprogress
135136
define weak_odr dso_local spir_kernel void @_ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E8Kernel10() #0 {
136137
entry:
@@ -164,7 +165,7 @@ entry:
164165
ret void
165166
}
166167

167-
; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE6Kernel
168+
; PRESENCE-CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE6Kernel
168169
; Function Attrs: convergent norecurse mustprogress
169170
define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE6Kernel"() local_unnamed_addr #0 {
170171
entry:
@@ -186,7 +187,7 @@ entry:
186187
ret void
187188
}
188189

189-
; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel2
190+
; PRESENCE-CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel2
190191
; Function Attrs: convergent norecurse mustprogress
191192
define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel2"() local_unnamed_addr #0 {
192193
entry:
@@ -216,7 +217,7 @@ entry:
216217
ret void
217218
}
218219

219-
; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel3
220+
; PRESENCE-CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel3
220221
; Function Attrs: convergent norecurse mustprogress
221222
define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel3"() local_unnamed_addr #0 {
222223
entry:
@@ -244,15 +245,15 @@ entry:
244245
ret void
245246
}
246247

247-
; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel4
248+
; PRESENCE-CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel4
248249
; Function Attrs: convergent norecurse mustprogress
249250
define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel4"() local_unnamed_addr #0 {
250251
entry:
251252
call spir_func void @_Z7common2v()
252253
ret void
253254
}
254255

255-
; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel5
256+
; PRESENCE-CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel5
256257
; Function Attrs: convergent norecurse mustprogress
257258
define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel5"() local_unnamed_addr #0 {
258259
entry:
@@ -267,23 +268,14 @@ entry:
267268
ret void
268269
}
269270

270-
; CHECK-NOT: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel
271-
; Function Attrs: convergent norecurse mustprogress
272-
define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6"() local_unnamed_addr #0 {
273-
entry:
274-
call spir_func void @_Z6E_exclv()
275-
call spir_func void @_Z6E_exclv()
276-
ret void
277-
}
278-
279271
; Function Attrs: convergent norecurse nounwind mustprogress
280272
define dso_local spir_func void @_Z6F_inclv() local_unnamed_addr {
281273
entry:
282274
call spir_func void @_Z11assert_funcv()
283275
ret void
284276
}
285277

286-
; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel7
278+
; PRESENCE-CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel7
287279
; Function Attrs: convergent norecurse mustprogress
288280
define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel7"() local_unnamed_addr #0 {
289281
entry:
@@ -328,14 +320,23 @@ entry:
328320
ret void
329321
}
330322

331-
; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel8
323+
; PRESENCE-CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel8
332324
; Function Attrs: convergent norecurse mustprogress
333325
define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel8"() local_unnamed_addr #0 {
334326
call spir_func void @_Z1Gv()
335327
call spir_func void @_Z1Hv()
336328
ret void
337329
}
338330

331+
; ABSENCE-CHECK-NOT: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6
332+
; Function Attrs: convergent norecurse mustprogress
333+
define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6"() local_unnamed_addr #0 {
334+
entry:
335+
call spir_func void @_Z6E_exclv()
336+
call spir_func void @_Z6E_exclv()
337+
ret void
338+
}
339+
339340
; Function Attrs: convergent norecurse mustprogress
340341
define weak dso_local spir_func void @__assert_fail(i8 addrspace(4)* %expr, i8 addrspace(4)* %file, i32 %line, i8 addrspace(4)* %func) local_unnamed_addr {
341342
entry:

llvm/test/tools/sycl-post-link/assert-property-with-split.ll

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
; in their call graph.
44

55
; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.table
6-
; RUN: FileCheck %s -input-file=%t_0.prop
6+
; RUN: FileCheck %s -input-file=%t_0.prop -check-prefix=PRESENCE-CHECK
7+
; RUN: FileCheck %s -input-file=%t_0.prop -check-prefix=ABSENCE-CHECK
78

89
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
910
target triple = "spir64-unknown-linux"
@@ -16,9 +17,9 @@ target triple = "spir64-unknown-linux"
1617
@__spirv_BuiltInLocalInvocationId = external dso_local local_unnamed_addr addrspace(1) constant <3 x i64>, align 32
1718
@_ZL10assert_fmt = internal addrspace(2) constant [85 x i8] c"%s:%d: %s: global id: [%lu,%lu,%lu], local id: [%lu,%lu,%lu] Assertion `%s` failed.\0A\00", align 1
1819

19-
; CHECK: [SYCL/assert used]
20+
; PRESENCE-CHECK: [SYCL/assert used]
2021

21-
; CHECK: _ZTSZ4mainE11TU0_kernel0
22+
; PRESENCE-CHECK-DAG: _ZTSZ4mainE11TU0_kernel0
2223
define dso_local spir_kernel void @_ZTSZ4mainE11TU0_kernel0() #0 {
2324
entry:
2425
call spir_func void @_Z3foov()
@@ -36,7 +37,14 @@ entry:
3637
ret void
3738
}
3839

39-
; CHECK-NOT: _ZTSZ4mainE11TU0_kernel1
40+
; PRESENCE-CHECK-DAG: _ZTSZ4mainE10TU1_kernel
41+
define dso_local spir_kernel void @_ZTSZ4mainE10TU1_kernel() #1 {
42+
entry:
43+
call spir_func void @_Z4foo2v()
44+
ret void
45+
}
46+
47+
; ABSENCE-CHECK-NOT: _ZTSZ4mainE11TU0_kernel1
4048
define dso_local spir_kernel void @_ZTSZ4mainE11TU0_kernel1() #0 {
4149
entry:
4250
call spir_func void @_Z4foo1v()
@@ -51,13 +59,6 @@ entry:
5159
ret void
5260
}
5361

54-
; CHECK: _ZTSZ4mainE10TU1_kernel
55-
define dso_local spir_kernel void @_ZTSZ4mainE10TU1_kernel() #1 {
56-
entry:
57-
call spir_func void @_Z4foo2v()
58-
ret void
59-
}
60-
6162
; Function Attrs: nounwind
6263
define dso_local spir_func void @_Z4foo2v() {
6364
entry:

0 commit comments

Comments
 (0)