Skip to content

Commit d5dafb2

Browse files
committed
[clang-sycl-linker] Migrate tests from Driver/ to Tooling/ and use LLVM IR input
Replace the C++ source test that required compiling with %clangxx with self-contained .ll tests using split-file. This removes the host compiler dependency and makes the tests faster and more portable. Split the test into two files: - clang-sycl-linker.ll: basic tool behavior (link, dev libs, AOT, errors) - clang-sycl-linker-split-mode.ll: device code split mode handling Co-Authored-By: Claude
1 parent f50fbc4 commit d5dafb2

4 files changed

Lines changed: 140 additions & 122 deletions

File tree

clang/test/Driver/Inputs/SYCL/two-kernels.ll

Lines changed: 0 additions & 23 deletions
This file was deleted.

clang/test/Driver/clang-sycl-linker-test.cpp

Lines changed: 0 additions & 99 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
; Tests the clang-sycl-linker tool: device code splitting.
2+
;
3+
; REQUIRES: spirv-registered-target
4+
;
5+
; RUN: llvm-as %s -o %t.bc
6+
;
7+
; Test that an invalid split mode is rejected.
8+
; RUN: not clang-sycl-linker --dry-run -triple=spirv64 --module-split-mode=bogus %t.bc -o a.out 2>&1 \
9+
; RUN: | FileCheck %s --check-prefix=SPLIT-INVALID
10+
; SPLIT-INVALID: module-split-mode value isn't recognized: bogus
11+
;
12+
; Test per-kernel split: a module with two SPIR_KERNEL functions produces two
13+
; device images.
14+
; RUN: clang-sycl-linker --dry-run -v -triple=spirv64 --module-split-mode=kernel %t.bc -o %t/split-kernel.out 2>&1 \
15+
; RUN: | FileCheck %s --check-prefix=SPLIT-KERNEL
16+
; SPLIT-KERNEL: sycl-device-link: inputs: {{.*}}.bc libfiles: output: [[LLVMLINKOUT:.*]].bc
17+
; SPLIT-KERNEL-NEXT: sycl-module-split: input: [[LLVMLINKOUT]].bc, output: [[SPLIT0:.*]].bc, [[SPLIT1:.*]].bc, mode: kernel
18+
; SPLIT-KERNEL-NEXT: LLVM backend: input: [[SPLIT0]].bc, output: {{.*}}_0.spv
19+
; SPLIT-KERNEL-NEXT: LLVM backend: input: [[SPLIT1]].bc, output: {{.*}}_1.spv
20+
21+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64-G1"
22+
target triple = "spirv64"
23+
24+
define spir_func i32 @helper_shared(i32 %a) {
25+
entry:
26+
%r = add nsw i32 %a, 1
27+
ret i32 %r
28+
}
29+
30+
define spir_kernel void @kernel_a(ptr addrspace(1) %out, i32 %a) {
31+
entry:
32+
%r = tail call spir_func i32 @helper_shared(i32 %a)
33+
store i32 %r, ptr addrspace(1) %out, align 4
34+
ret void
35+
}
36+
37+
define spir_kernel void @kernel_b(ptr addrspace(1) %out, i32 %a, i32 %b) {
38+
entry:
39+
%h = tail call spir_func i32 @helper_shared(i32 %a)
40+
%r = mul nsw i32 %h, %b
41+
store i32 %r, ptr addrspace(1) %out, align 4
42+
ret void
43+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
; Tests the clang-sycl-linker tool.
2+
;
3+
; REQUIRES: spirv-registered-target
4+
;
5+
; RUN: rm -rf %t && split-file %s %t
6+
; RUN: llvm-as %t/input1.ll -o %t/input1.bc
7+
; RUN: llvm-as %t/input2.ll -o %t/input2.bc
8+
;
9+
; Test the dry run of a simple case to link two input files.
10+
; RUN: clang-sycl-linker --dry-run -v -triple=spirv64 %t/input1.bc %t/input2.bc -o %t/spirv.out 2>&1 \
11+
; RUN: | FileCheck %s --check-prefix=SIMPLE-FO
12+
; SIMPLE-FO: sycl-device-link: inputs: {{.*}}.bc, {{.*}}.bc libfiles: output: [[LLVMLINKOUT:.*]].bc
13+
; SIMPLE-FO-NEXT: sycl-module-split: input: [[LLVMLINKOUT]].bc, output: [[LLVMLINKOUT]].bc, mode: none
14+
; SIMPLE-FO-NEXT: LLVM backend: input: [[LLVMLINKOUT]].bc, output: {{.*}}_0.spv
15+
;
16+
; Test that IMG_SPIRV image kind is set for non-AOT compilation.
17+
; RUN: llvm-objdump --offloading %t/spirv.out | FileCheck %s --check-prefix=IMAGE-KIND-SPIRV
18+
; IMAGE-KIND-SPIRV: kind spir-v
19+
;
20+
; Test the dry run of a simple case with device library files specified.
21+
; RUN: mkdir -p %t/libs
22+
; RUN: touch %t/libs/lib1.bc
23+
; RUN: touch %t/libs/lib2.bc
24+
; RUN: clang-sycl-linker --dry-run -v -triple=spirv64 %t/input1.bc %t/input2.bc --library-path=%t/libs --device-libs=lib1.bc,lib2.bc -o a.spv 2>&1 \
25+
; RUN: | FileCheck %s --check-prefix=DEVLIBS
26+
; DEVLIBS: sycl-device-link: inputs: {{.*}}.bc libfiles: {{.*}}lib1.bc, {{.*}}lib2.bc output: [[LLVMLINKOUT:.*]].bc
27+
; DEVLIBS-NEXT: sycl-module-split: input: [[LLVMLINKOUT]].bc, output: [[LLVMLINKOUT]].bc, mode: none
28+
; DEVLIBS-NEXT: LLVM backend: input: [[LLVMLINKOUT]].bc, output: a_0.spv
29+
;
30+
; Test a simple case with a random file (not bitcode) as input.
31+
; RUN: touch %t/dummy.o
32+
; RUN: not clang-sycl-linker -triple=spirv64 %t/dummy.o -o a.spv 2>&1 \
33+
; RUN: | FileCheck %s --check-prefix=FILETYPEERROR
34+
; FILETYPEERROR: Unsupported file type
35+
;
36+
; Test to see if device library related errors are emitted.
37+
; RUN: not clang-sycl-linker --dry-run -triple=spirv64 %t/input1.bc %t/input2.bc --library-path=%t/libs --device-libs= -o a.spv 2>&1 \
38+
; RUN: | FileCheck %s --check-prefix=DEVLIBSERR1
39+
; DEVLIBSERR1: Number of device library files cannot be zero
40+
; RUN: not clang-sycl-linker --dry-run -triple=spirv64 %t/input1.bc %t/input2.bc --library-path=%t/libs --device-libs=lib1.bc,lib2.bc,lib3.bc -o a.spv 2>&1 \
41+
; RUN: | FileCheck %s --check-prefix=DEVLIBSERR2
42+
; DEVLIBSERR2: '{{.*}}lib3.bc' SYCL device library file is not found
43+
;
44+
; Test AOT compilation for an Intel GPU.
45+
; RUN: clang-sycl-linker --dry-run -v -triple=spirv64 -arch=bmg_g21 %t/input1.bc %t/input2.bc -o %t/aot-gpu.out 2>&1 \
46+
; RUN: --ocloc-options="-a -b" \
47+
; RUN: | FileCheck %s --check-prefix=AOT-INTEL-GPU
48+
; AOT-INTEL-GPU: sycl-device-link: inputs: {{.*}}.bc, {{.*}}.bc libfiles: output: [[LLVMLINKOUT:.*]].bc
49+
; AOT-INTEL-GPU-NEXT: sycl-module-split: input: [[LLVMLINKOUT]].bc, output: [[LLVMLINKOUT]].bc, mode: none
50+
; AOT-INTEL-GPU-NEXT: LLVM backend: input: [[LLVMLINKOUT]].bc, output: [[SPIRVTRANSLATIONOUT:.*]]_0.spv
51+
; AOT-INTEL-GPU-NEXT: "{{.*}}ocloc{{.*}}" {{.*}}-device bmg_g21 -a -b {{.*}}-output [[SPIRVTRANSLATIONOUT]]_0.out -file [[SPIRVTRANSLATIONOUT]]_0.spv
52+
;
53+
; Test that IMG_Object image kind is set for AOT compilation (Intel GPU).
54+
; RUN: llvm-objdump --offloading %t/aot-gpu.out | FileCheck %s --check-prefix=IMAGE-KIND-OBJECT
55+
; IMAGE-KIND-OBJECT: kind elf
56+
;
57+
; Test AOT compilation for an Intel CPU.
58+
; RUN: clang-sycl-linker --dry-run -v -triple=spirv64 -arch=graniterapids %t/input1.bc %t/input2.bc -o %t/aot-cpu.out 2>&1 \
59+
; RUN: --opencl-aot-options="-a -b" \
60+
; RUN: | FileCheck %s --check-prefix=AOT-INTEL-CPU
61+
; AOT-INTEL-CPU: sycl-device-link: inputs: {{.*}}.bc, {{.*}}.bc libfiles: output: [[LLVMLINKOUT:.*]].bc
62+
; AOT-INTEL-CPU-NEXT: sycl-module-split: input: [[LLVMLINKOUT]].bc, output: [[LLVMLINKOUT]].bc, mode: none
63+
; AOT-INTEL-CPU-NEXT: LLVM backend: input: [[LLVMLINKOUT]].bc, output: [[SPIRVTRANSLATIONOUT:.*]]_0.spv
64+
; AOT-INTEL-CPU-NEXT: "{{.*}}opencl-aot{{.*}}" {{.*}}--device=cpu -a -b {{.*}}-o [[SPIRVTRANSLATIONOUT]]_0.out [[SPIRVTRANSLATIONOUT]]_0.spv
65+
;
66+
; Test that IMG_Object image kind is set for AOT compilation (Intel CPU).
67+
; RUN: llvm-objdump --offloading %t/aot-cpu.out | FileCheck %s --check-prefix=IMAGE-KIND-OBJECT
68+
;
69+
; Check that the output file must be specified.
70+
; RUN: not clang-sycl-linker --dry-run %t/input1.bc %t/input2.bc 2>&1 \
71+
; RUN: | FileCheck %s --check-prefix=NOOUTPUT
72+
; NOOUTPUT: Output file must be specified
73+
;
74+
; Check that the target triple must be specified.
75+
; RUN: not clang-sycl-linker --dry-run %t/input1.bc %t/input2.bc -o a.out 2>&1 \
76+
; RUN: | FileCheck %s --check-prefix=NOTARGET
77+
; NOTARGET: Target triple must be specified
78+
79+
;--- input1.ll
80+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64-G1"
81+
target triple = "spirv64"
82+
83+
define spir_kernel void @kernel_a() #0 {
84+
ret void
85+
}
86+
87+
attributes #0 = { "sycl-module-id"="TU1.cpp" }
88+
89+
;--- input2.ll
90+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64-G1"
91+
target triple = "spirv64"
92+
93+
define spir_kernel void @kernel_b() #0 {
94+
ret void
95+
}
96+
97+
attributes #0 = { "sycl-module-id"="TU2.cpp" }

0 commit comments

Comments
 (0)