Skip to content

Commit 2809005

Browse files
[sycl-post-link] Do not treat declarations as entry points (#4927)
If declaration is treated as entry point, then we will create a device image which claims that it contains particular kernel, while it actually doesn't - that leads to errors at runtime. Kernel declarations can appear in input modules as a side effect of #4409. The PR postponed removal of `@llvm.used` variable from input modules, which results in kernel declarations left in modules after split between SYCL and ESIMD kernels.
1 parent 5b771a9 commit 2809005

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
; Purpose of this test is to check that sycl-post-link does not treat
2+
; declarations as entry points.
3+
4+
; RUN: sycl-post-link -split=source -symbols -S %s -o %t.table
5+
; RUN: FileCheck %s -input-file=%t.table --check-prefix CHECK-PER-SOURCE-TABLE
6+
; RUN: FileCheck %s -input-file=%t_0.sym --check-prefix CHECK-PER-SOURCE-SYM0
7+
; RUN: FileCheck %s -input-file=%t_1.sym --check-prefix CHECK-PER-SOURCE-SYM1
8+
;
9+
; RUN: sycl-post-link -split=kernel -symbols -S %s -o %t1.table
10+
; RUN: FileCheck %s -input-file=%t1.table --check-prefix CHECK-PER-KERNEL-TABLE
11+
; RUN: FileCheck %s -input-file=%t1_0.sym --check-prefix CHECK-PER-KERNEL-SYM0
12+
; RUN: FileCheck %s -input-file=%t1_1.sym --check-prefix CHECK-PER-KERNEL-SYM1
13+
; RUN: FileCheck %s -input-file=%t1_2.sym --check-prefix CHECK-PER-KERNEL-SYM2
14+
15+
; With per-source split, there should be two device images
16+
; CHECK-PER-SOURCE-TABLE: [Code|Properties|Symbols]
17+
; CHECK-PER-SOURCE-TABLE: {{.*}}_0.ll|{{.*}}_0.prop|{{.*}}_0.sym
18+
; CHECK-PER-SOURCE-TABLE-NEXT: {{.*}}_1.ll|{{.*}}_1.prop|{{.*}}_1.sym
19+
; CHECK-PER-SOURCE-TABLE-EMPTY:
20+
;
21+
; CHECK-PER-SOURCE-SYM0-NOT: _ZTS4mainE10TU1_kernel1
22+
; CHECK-PER-SOURCE-SYM0: _ZTSZ4mainE11TU0_kernel0
23+
; CHECK-PER-SOURCE-SYM0-NEXT: _ZTSZ4mainE11TU0_kernel1
24+
; CHECK-PER-SOURCE-SYM0-EMPTY:
25+
;
26+
; CHECK-PER-SOURCE-SYM1-NOT: _ZTS4mainE10TU1_kernel1
27+
; CHECK-PER-SOURCE-SYM1: _ZTSZ4mainE10TU1_kernel0
28+
; CHECK-PER-SOURCE-SYM1-EMPTY:
29+
30+
; With per-kernel split, there should be three device images
31+
; CHECK-PER-KERNEL-TABLE: [Code|Properties|Symbols]
32+
; CHECK-PER-KERNEL-TABLE: {{.*}}_0.ll|{{.*}}_0.prop|{{.*}}_0.sym
33+
; CHECK-PER-KERNEL-TABLE-NEXT: {{.*}}_1.ll|{{.*}}_1.prop|{{.*}}_1.sym
34+
; CHECK-PER-KERNEL-TABLE-NEXT: {{.*}}_2.ll|{{.*}}_2.prop|{{.*}}_2.sym
35+
; CHECK-PER-KERNEL-TABLE-EMPTY:
36+
;
37+
; CHECK-PER-KERNEL-SYM0-NOT: _ZTS4mainE10TU1_kernel1
38+
; CHECK-PER-KERNEL-SYM0: _ZTSZ4mainE10TU1_kernel0
39+
; CHECK-PER-KERNEL-SYM0-EMPTY:
40+
;
41+
; CHECK-PER-KERNEL-SYM1-NOT: _ZTS4mainE10TU1_kernel1
42+
; CHECK-PER-KERNEL-SYM1: _ZTSZ4mainE11TU0_kernel0
43+
; CHECK-PER-KERNEL-SYM1-EMPTY:
44+
;
45+
; CHECK-PER-KERNEL-SYM2-NOT: _ZTS4mainE10TU1_kernel1
46+
; CHECK-PER-KERNEL-SYM2: _ZTSZ4mainE11TU0_kernel1
47+
; CHECK-PER-KERNEL-SYM2-EMPTY:
48+
49+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
50+
target triple = "spir64-unknown-linux"
51+
52+
define spir_kernel void @_ZTSZ4mainE11TU0_kernel0() #0 {
53+
entry:
54+
ret void
55+
}
56+
57+
define spir_kernel void @_ZTSZ4mainE11TU0_kernel1() #0 {
58+
entry:
59+
ret void
60+
}
61+
62+
define spir_kernel void @_ZTSZ4mainE10TU1_kernel0() #1 {
63+
ret void
64+
}
65+
66+
declare spir_kernel void @_ZTS4mainE10TU1_kernel1() #1
67+
68+
attributes #0 = { "sycl-module-id"="TU1.cpp" }
69+
attributes #1 = { "sycl-module-id"="TU2.cpp" }
70+
71+
!opencl.spir.version = !{!0, !0}
72+
!spirv.Source = !{!1, !1}
73+
!0 = !{i32 1, i32 2}
74+
!1 = !{i32 4, i32 100000}

llvm/tools/sycl-post-link/sycl-post-link.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ bool isSpirvSyclBuiltin(StringRef FName) {
288288
}
289289

290290
bool isEntryPoint(const Function &F) {
291+
// Skip declarations, if any: they should not be included into KernelModuleMap
292+
// or otherwise we will end up with incorrectly generated list of symbols.
293+
if (F.isDeclaration())
294+
return false;
295+
291296
// Kernels are always considered to be entry points
292297
if (CallingConv::SPIR_KERNEL == F.getCallingConv())
293298
return true;

0 commit comments

Comments
 (0)