Debian Codegraph @

llvm/test/CodeGen/SPIRV/transcoding/OpenCL/barrier.ll

raw
1 ; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
2 ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3
4 ;; This test checks that the backend is capable to correctly translate
5 ;; barrier OpenCL C 1.2 built-in function [1] into corresponding SPIR-V
6 ;; instruction.
7
8 ;; FIXME: Strictly speaking, this flag is not supported by barrier in OpenCL 1.2
9 ;; #define CLK_IMAGE_MEM_FENCE 0x04
10 ;;
11 ;; void __attribute__((overloadable)) __attribute__((convergent)) barrier(cl_mem_fence_flags);
12 ;;
13 ;; __kernel void test_barrier_const_flags() {
14 ;; barrier(CLK_LOCAL_MEM_FENCE);
15 ;; barrier(CLK_GLOBAL_MEM_FENCE);
16 ;; barrier(CLK_IMAGE_MEM_FENCE);
17 ;;
18 ;; barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
19 ;; barrier(CLK_LOCAL_MEM_FENCE | CLK_IMAGE_MEM_FENCE);
20 ;; barrier(CLK_GLOBAL_MEM_FENCE | CLK_LOCAL_MEM_FENCE | CLK_IMAGE_MEM_FENCE);
21 ;; }
22 ;;
23 ;; __kernel void test_barrier_non_const_flags(cl_mem_fence_flags flags) {
24 ;; FIXME: OpenCL spec doesn't require flags to be compile-time known
25 ;; barrier(flags);
26 ;; }
27
28 ; CHECK-SPIRV-DAG: OpName %[[#TEST_CONST_FLAGS:]] "test_barrier_const_flags"
29 ; CHECK-SPIRV-DAG: %[[#UINT:]] = OpTypeInt 32 0
30
31 ;; In SPIR-V, barrier is represented as OpControlBarrier [3] and OpenCL
32 ;; cl_mem_fence_flags are represented as part of Memory Semantics [2], which
33 ;; also includes memory order constraints. The backend applies some default
34 ;; memory order for OpControlBarrier and therefore, constants below include a
35 ;; bit more information than original source
36
37 ;; 0x10 SequentiallyConsistent + 0x100 WorkgroupMemory
38 ; CHECK-SPIRV-DAG: %[[#LOCAL:]] = OpConstant %[[#UINT]] 272{{$}}
39 ;; 0x2 Workgroup
40 ; CHECK-SPIRV-DAG: %[[#WG:]] = OpConstant %[[#UINT]] 2{{$}}
41 ;; 0x10 SequentiallyConsistent + 0x200 CrossWorkgroupMemory
42 ; CHECK-SPIRV-DAG: %[[#GLOBAL:]] = OpConstant %[[#UINT]] 528{{$}}
43 ;; 0x10 SequentiallyConsistent + 0x800 ImageMemory
44 ; CHECK-SPIRV-DAG: %[[#IMAGE:]] = OpConstant %[[#UINT]] 2064{{$}}
45 ;; 0x10 SequentiallyConsistent + 0x100 WorkgroupMemory + 0x200 CrossWorkgroupMemory
46 ; CHECK-SPIRV-DAG: %[[#LOCAL_GLOBAL:]] = OpConstant %[[#UINT]] 784{{$}}
47 ;; 0x10 SequentiallyConsistent + 0x100 WorkgroupMemory + 0x800 ImageMemory
48 ; CHECK-SPIRV-DAG: %[[#LOCAL_IMAGE:]] = OpConstant %[[#UINT]] 2320{{$}}
49 ;; 0x10 SequentiallyConsistent + 0x100 WorkgroupMemory + 0x200 CrossWorkgroupMemory + 0x800 ImageMemory
50 ; CHECK-SPIRV-DAG: %[[#LOCAL_GLOBAL_IMAGE:]] = OpConstant %[[#UINT]] 2832{{$}}
51
52 ; CHECK-SPIRV: %[[#TEST_CONST_FLAGS]] = OpFunction %[[#]]
53 ; CHECK-SPIRV: OpControlBarrier %[[#WG]] %[[#WG]] %[[#LOCAL]]
54 ; CHECK-SPIRV: OpControlBarrier %[[#WG]] %[[#WG]] %[[#GLOBAL]]
55 ; CHECK-SPIRV: OpControlBarrier %[[#WG]] %[[#WG]] %[[#IMAGE]]
56 ; CHECK-SPIRV: OpControlBarrier %[[#WG]] %[[#WG]] %[[#LOCAL_GLOBAL]]
57 ; CHECK-SPIRV: OpControlBarrier %[[#WG]] %[[#WG]] %[[#LOCAL_IMAGE]]
58 ; CHECK-SPIRV: OpControlBarrier %[[#WG]] %[[#WG]] %[[#LOCAL_GLOBAL_IMAGE]]
59
60 define dso_local spir_kernel void @test_barrier_const_flags() local_unnamed_addr {
61 entry:
62 tail call spir_func void @_Z7barrierj(i32 noundef 1)
63 tail call spir_func void @_Z7barrierj(i32 noundef 2)
64 tail call spir_func void @_Z7barrierj(i32 noundef 4)
65 tail call spir_func void @_Z7barrierj(i32 noundef 3)
66 tail call spir_func void @_Z7barrierj(i32 noundef 5)
67 tail call spir_func void @_Z7barrierj(i32 noundef 7)
68 ret void
69 }
70
71 declare spir_func void @_Z7barrierj(i32 noundef) local_unnamed_addr
72
73 define dso_local spir_kernel void @test_barrier_non_const_flags(i32 noundef %flags) local_unnamed_addr {
74 entry:
75 ret void
76 }
77
78 ;; References:
79 ;; [1]: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/barrier.html
80 ;; [2]: https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_memory_semantics__id_a_memory_semantics_lt_id_gt
81 ;; [3]: https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#OpControlBarrier