Debian Codegraph @

llvm-project/llvm/projects/llvm-spirv/test/transcoding/OpenCL/atomic_legacy.cl

raw
1 // RUN: %clang_cc1 %s -triple spir -cl-std=CL1.2 -emit-llvm-bc -fdeclare-opencl-builtins -o %t.bc
2 // RUN: llvm-spirv %t.bc -o %t.spv
3 // RUN: spirv-val %t.spv
4 // RUN: llvm-spirv %t.spv -to-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV
5 // RUN: llvm-spirv %t.spv -r --spirv-target-env=CL1.2 -o - | llvm-dis -o - | FileCheck %s --check-prefix=CHECK-LLVM
6
7 // This test checks that the translator is capable to correctly translate
8 // legacy atomic OpenCL C 1.2 built-in functions [1] into corresponding SPIR-V
9 // instruction and vice-versa.
10
11 __kernel void test_legacy_atomics(__global int *p, int val) {
12 atom_add(p, val); // from cl_khr_global_int32_base_atomics
13 atomic_add(p, val); // from OpenCL C 1.1
14 }
15
16 // CHECK-SPIRV: Name [[TEST:[0-9]+]] "test_legacy_atomics"
17 // CHECK-SPIRV-DAG: TypeInt [[UINT:[0-9]+]] 32 0
18 // CHECK-SPIRV-DAG: TypePointer [[UINT_PTR:[0-9]+]] 5 [[UINT]]
19 //
20 // In SPIR-V, atomic_add is represented as OpAtomicIAdd [2], which also includes
21 // memory scope and memory semantic arguments. The translator applies a default
22 // memory scope and memory order for it and therefore, constants below include
23 // a bit more information than original source
24 //
25 // 0x2 Workgroup
26 // CHECK-SPIRV-DAG: Constant [[UINT]] [[WORKGROUP_SCOPE:[0-9]+]] 2
27 //
28 // 0x0 Relaxed
29 // CHECK-SPIRV-DAG: Constant [[UINT]] [[RELAXED:[0-9]+]] 0
30 //
31 // CHECK-SPIRV: Function {{[0-9]+}} [[TEST]]
32 // CHECK-SPIRV: FunctionParameter [[UINT_PTR]] [[PTR:[0-9]+]]
33 // CHECK-SPIRV: FunctionParameter [[UINT]] [[VAL:[0-9]+]]
34 // CHECK-SPIRV: AtomicIAdd [[UINT]] {{[0-9]+}} [[PTR]] [[WORKGROUP_SCOPE]] [[RELAXED]] [[VAL]]
35 // CHECK-SPIRV: AtomicIAdd [[UINT]] {{[0-9]+}} [[PTR]] [[WORKGROUP_SCOPE]] [[RELAXED]] [[VAL]]
36 //
37 //
38 // CHECK-LLVM-LABEL: define spir_kernel void @test_legacy_atomics
39 // Note: the translator generates the OpenCL C 1.1 function name exclusively!
40 // CHECK-LLVM: call spir_func i32 @_Z10atomic_addPU3AS1Vii(
41 // CHECK-LLVM: call spir_func i32 @_Z10atomic_addPU3AS1Vii(
42
43 // References:
44 // [1]: https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_C.html#atomic-legacy
45 // [2]: https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#OpAtomicIAdd