xref: /llvm-project/llvm/test/CodeGen/SPIRV/EnqueueEmptyKernel.ll (revision f8a21dff70cc5d20db731b3af1858c5a2ae96d30)
1; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
2
3; TODO(#60133): Requires updates following opaque pointer migration.
4; XFAIL: *
5
6;; This test checks that Invoke parameter of OpEnueueKernel instruction meet the
7;; following specification requirements in case of enqueueing empty block:
8;; "Invoke must be an OpFunction whose OpTypeFunction operand has:
9;; - Result Type must be OpTypeVoid.
10;; - The first parameter must have a type of OpTypePointer to an 8-bit OpTypeInt.
11;; - An optional list of parameters, each of which must have a type of OpTypePointer to the Workgroup Storage Class.
12;; ... "
13;; __kernel void test_enqueue_empty() {
14;;   enqueue_kernel(get_default_queue(),
15;;                  CLK_ENQUEUE_FLAGS_WAIT_KERNEL,
16;;                  ndrange_1D(1),
17;;                  0, NULL, NULL,
18;;                  ^(){});
19;; }
20
21%struct.ndrange_t = type { i32, [3 x i64], [3 x i64], [3 x i64] }
22%opencl.queue_t = type opaque
23%opencl.clk_event_t = type opaque
24
25@__block_literal_global = internal addrspace(1) constant { i32, i32 } { i32 8, i32 4 }, align 4
26
27; CHECK-SPIRV: OpName %[[#Block:]] "__block_literal_global"
28; CHECK-SPIRV: %[[#Void:]] = OpTypeVoid
29; CHECK-SPIRV: %[[#Int8:]] = OpTypeInt 8
30; CHECK-SPIRV: %[[#Int8PtrGen:]] = OpTypePointer Generic %[[#Int8]]
31; CHECK-SPIRV: %[[#Int8Ptr:]] = OpTypePointer CrossWorkgroup %[[#Int8]]
32; CHECK-SPIRV: %[[#Block]] = OpVariable %[[#]]
33
34define spir_kernel void @test_enqueue_empty() {
35entry:
36  %tmp = alloca %struct.ndrange_t, align 8
37  %call = call spir_func %opencl.queue_t* @_Z17get_default_queuev()
38  call spir_func void @_Z10ndrange_1Dm(%struct.ndrange_t* sret(%struct.ndrange_t*) %tmp, i64 1)
39  %0 = call i32 @__enqueue_kernel_basic_events(%opencl.queue_t* %call, i32 1, %struct.ndrange_t* %tmp, i32 0, %opencl.clk_event_t* addrspace(4)* null, %opencl.clk_event_t* addrspace(4)* null, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*)* @__test_enqueue_empty_block_invoke_kernel to i8*) to i8 addrspace(4)*), i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* @__block_literal_global to i8 addrspace(1)*) to i8 addrspace(4)*))
40  ret void
41; CHECK-SPIRV: %[[#Int8PtrBlock:]] = OpBitcast %[[#Int8Ptr]] %[[#Block]]
42; CHECK-SPIRV: %[[#Int8PtrGenBlock:]] = OpPtrCastToGeneric %[[#Int8PtrGen]] %[[#Int8PtrBlock]]
43; CHECK-SPIRV: %[[#]] = OpEnqueueKernel %[[#]] %[[#]] %[[#]] %[[#]] %[[#]] %[[#]] %[[#]] %[[#Invoke:]] %[[#Int8PtrGenBlock]] %[[#]] %[[#]]
44}
45
46declare spir_func %opencl.queue_t* @_Z17get_default_queuev()
47
48declare spir_func void @_Z10ndrange_1Dm(%struct.ndrange_t* sret(%struct.ndrange_t*), i64)
49
50define internal spir_func void @__test_enqueue_empty_block_invoke(i8 addrspace(4)* %.block_descriptor) {
51entry:
52  %.block_descriptor.addr = alloca i8 addrspace(4)*, align 8
53  store i8 addrspace(4)* %.block_descriptor, i8 addrspace(4)** %.block_descriptor.addr, align 8
54  %block = bitcast i8 addrspace(4)* %.block_descriptor to <{ i32, i32 }> addrspace(4)*
55  ret void
56}
57
58define internal spir_kernel void @__test_enqueue_empty_block_invoke_kernel(i8 addrspace(4)*) {
59entry:
60  call void @__test_enqueue_empty_block_invoke(i8 addrspace(4)* %0)
61  ret void
62}
63
64declare i32 @__enqueue_kernel_basic_events(%opencl.queue_t*, i32, %struct.ndrange_t*, i32, %opencl.clk_event_t* addrspace(4)*, %opencl.clk_event_t* addrspace(4)*, i8 addrspace(4)*, i8 addrspace(4)*)
65
66; CHECK-SPIRV:      %[[#Invoke]] = OpFunction %[[#Void]] None %[[#]]
67; CHECK-SPIRV-NEXT: %[[#]] = OpFunctionParameter %[[#Int8PtrGen]]
68