xref: /llvm-project/llvm/test/CodeGen/SPIRV/EnqueueEmptyKernel.ll (revision f8a21dff70cc5d20db731b3af1858c5a2ae96d30)
1ec7baca1SMichal Paszkowski; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
2748922b3SIlia Diachkov
3*f8a21dffSNatalie Chouinard; TODO(#60133): Requires updates following opaque pointer migration.
4*f8a21dffSNatalie Chouinard; XFAIL: *
5*f8a21dffSNatalie Chouinard
6748922b3SIlia Diachkov;; This test checks that Invoke parameter of OpEnueueKernel instruction meet the
7748922b3SIlia Diachkov;; following specification requirements in case of enqueueing empty block:
8748922b3SIlia Diachkov;; "Invoke must be an OpFunction whose OpTypeFunction operand has:
9748922b3SIlia Diachkov;; - Result Type must be OpTypeVoid.
10748922b3SIlia Diachkov;; - The first parameter must have a type of OpTypePointer to an 8-bit OpTypeInt.
11748922b3SIlia Diachkov;; - An optional list of parameters, each of which must have a type of OpTypePointer to the Workgroup Storage Class.
12748922b3SIlia Diachkov;; ... "
13748922b3SIlia Diachkov;; __kernel void test_enqueue_empty() {
14748922b3SIlia Diachkov;;   enqueue_kernel(get_default_queue(),
15748922b3SIlia Diachkov;;                  CLK_ENQUEUE_FLAGS_WAIT_KERNEL,
16748922b3SIlia Diachkov;;                  ndrange_1D(1),
17748922b3SIlia Diachkov;;                  0, NULL, NULL,
18748922b3SIlia Diachkov;;                  ^(){});
19748922b3SIlia Diachkov;; }
20748922b3SIlia Diachkov
21748922b3SIlia Diachkov%struct.ndrange_t = type { i32, [3 x i64], [3 x i64], [3 x i64] }
22748922b3SIlia Diachkov%opencl.queue_t = type opaque
23748922b3SIlia Diachkov%opencl.clk_event_t = type opaque
24748922b3SIlia Diachkov
25748922b3SIlia Diachkov@__block_literal_global = internal addrspace(1) constant { i32, i32 } { i32 8, i32 4 }, align 4
26748922b3SIlia Diachkov
27748922b3SIlia Diachkov; CHECK-SPIRV: OpName %[[#Block:]] "__block_literal_global"
28748922b3SIlia Diachkov; CHECK-SPIRV: %[[#Void:]] = OpTypeVoid
29748922b3SIlia Diachkov; CHECK-SPIRV: %[[#Int8:]] = OpTypeInt 8
30748922b3SIlia Diachkov; CHECK-SPIRV: %[[#Int8PtrGen:]] = OpTypePointer Generic %[[#Int8]]
31748922b3SIlia Diachkov; CHECK-SPIRV: %[[#Int8Ptr:]] = OpTypePointer CrossWorkgroup %[[#Int8]]
32748922b3SIlia Diachkov; CHECK-SPIRV: %[[#Block]] = OpVariable %[[#]]
33748922b3SIlia Diachkov
34748922b3SIlia Diachkovdefine spir_kernel void @test_enqueue_empty() {
35748922b3SIlia Diachkoventry:
36748922b3SIlia Diachkov  %tmp = alloca %struct.ndrange_t, align 8
37748922b3SIlia Diachkov  %call = call spir_func %opencl.queue_t* @_Z17get_default_queuev()
38748922b3SIlia Diachkov  call spir_func void @_Z10ndrange_1Dm(%struct.ndrange_t* sret(%struct.ndrange_t*) %tmp, i64 1)
39748922b3SIlia Diachkov  %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)*))
40748922b3SIlia Diachkov  ret void
41748922b3SIlia Diachkov; CHECK-SPIRV: %[[#Int8PtrBlock:]] = OpBitcast %[[#Int8Ptr]] %[[#Block]]
42748922b3SIlia Diachkov; CHECK-SPIRV: %[[#Int8PtrGenBlock:]] = OpPtrCastToGeneric %[[#Int8PtrGen]] %[[#Int8PtrBlock]]
43748922b3SIlia Diachkov; CHECK-SPIRV: %[[#]] = OpEnqueueKernel %[[#]] %[[#]] %[[#]] %[[#]] %[[#]] %[[#]] %[[#]] %[[#Invoke:]] %[[#Int8PtrGenBlock]] %[[#]] %[[#]]
44748922b3SIlia Diachkov}
45748922b3SIlia Diachkov
46748922b3SIlia Diachkovdeclare spir_func %opencl.queue_t* @_Z17get_default_queuev()
47748922b3SIlia Diachkov
48748922b3SIlia Diachkovdeclare spir_func void @_Z10ndrange_1Dm(%struct.ndrange_t* sret(%struct.ndrange_t*), i64)
49748922b3SIlia Diachkov
50748922b3SIlia Diachkovdefine internal spir_func void @__test_enqueue_empty_block_invoke(i8 addrspace(4)* %.block_descriptor) {
51748922b3SIlia Diachkoventry:
52748922b3SIlia Diachkov  %.block_descriptor.addr = alloca i8 addrspace(4)*, align 8
53748922b3SIlia Diachkov  store i8 addrspace(4)* %.block_descriptor, i8 addrspace(4)** %.block_descriptor.addr, align 8
54748922b3SIlia Diachkov  %block = bitcast i8 addrspace(4)* %.block_descriptor to <{ i32, i32 }> addrspace(4)*
55748922b3SIlia Diachkov  ret void
56748922b3SIlia Diachkov}
57748922b3SIlia Diachkov
58748922b3SIlia Diachkovdefine internal spir_kernel void @__test_enqueue_empty_block_invoke_kernel(i8 addrspace(4)*) {
59748922b3SIlia Diachkoventry:
60748922b3SIlia Diachkov  call void @__test_enqueue_empty_block_invoke(i8 addrspace(4)* %0)
61748922b3SIlia Diachkov  ret void
62748922b3SIlia Diachkov}
63748922b3SIlia Diachkov
64748922b3SIlia Diachkovdeclare 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)*)
65748922b3SIlia Diachkov
66748922b3SIlia Diachkov; CHECK-SPIRV:      %[[#Invoke]] = OpFunction %[[#Void]] None %[[#]]
67748922b3SIlia Diachkov; CHECK-SPIRV-NEXT: %[[#]] = OpFunctionParameter %[[#Int8PtrGen]]
68