xref: /llvm-project/llvm/test/CodeGen/SPIRV/transcoding/cl-types.ll (revision 83c1d003118a2cb8136fe49e2ec43958c93d9d6b)
1;; Test CL opaque types
2;;
3;; // cl-types.cl
4;; // CL source code for generating LLVM IR.
5;; // Command for compilation:
6;; //  clang -cc1 -x cl -cl-std=CL2.0 -triple spir-unknown-unknown -emit-llvm cl-types.cl
7;; void kernel foo(
8;;  read_only pipe int a,
9;;  write_only pipe int b,
10;;  read_only image1d_t c1,
11;;  read_only image2d_t d1,
12;;  read_only image3d_t e1,
13;;  read_only image2d_array_t f1,
14;;  read_only image1d_buffer_t g1,
15;;  write_only image1d_t c2,
16;;  read_write image2d_t d3,
17;;  sampler_t s
18;; ) {
19;; }
20
21; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
22; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
23
24; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
25; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
26
27; CHECK-SPIRV-DAG: OpCapability Sampled1D
28; CHECK-SPIRV-DAG: OpCapability SampledBuffer
29; CHECK-SPIRV-DAG: %[[#VOID:]] = OpTypeVoid
30; CHECK-SPIRV-DAG: %[[#PIPE_RD:]] = OpTypePipe ReadOnly
31; CHECK-SPIRV-DAG: %[[#PIPE_WR:]] = OpTypePipe WriteOnly
32; CHECK-SPIRV-DAG: %[[#IMG1D_RD:]] = OpTypeImage %[[#VOID]] 1D 0 0 0 0 Unknown ReadOnly
33; CHECK-SPIRV-DAG: %[[#IMG2D_RD:]] = OpTypeImage %[[#VOID]] 2D 0 0 0 0 Unknown ReadOnly
34; CHECK-SPIRV-DAG: %[[#IMG3D_RD:]] = OpTypeImage %[[#VOID]] 3D 0 0 0 0 Unknown ReadOnly
35; CHECK-SPIRV-DAG: %[[#IMG2DA_RD:]] = OpTypeImage %[[#VOID]] 2D 0 1 0 0 Unknown ReadOnly
36; CHECK-SPIRV-DAG: %[[#IMG1DB_RD:]] = OpTypeImage %[[#VOID]] Buffer 0 0 0 0 Unknown ReadOnly
37; CHECK-SPIRV-DAG: %[[#IMG1D_WR:]] = OpTypeImage %[[#VOID]] 1D 0 0 0 0 Unknown WriteOnly
38; CHECK-SPIRV-DAG: %[[#IMG2D_RW:]] = OpTypeImage %[[#VOID]] 2D 0 0 0 0 Unknown ReadWrite
39; CHECK-SPIRV-DAG: %[[#SAMP:]] = OpTypeSampler
40; CHECK-SPIRV-DAG: %[[#SAMPIMG:]] = OpTypeSampledImage %[[#IMG2D_RD]]
41
42; CHECK-SPIRV-DAG: %[[#SAMP_CONST:]] = OpConstantSampler %[[#SAMP]] None 0 Linear
43
44; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#PIPE_RD]]
45; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#PIPE_WR]]
46; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#IMG1D_RD]]
47; CHECK-SPIRV: %[[#IMG_ARG:]] = OpFunctionParameter %[[#IMG2D_RD]]
48; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#IMG3D_RD]]
49; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#IMG2DA_RD]]
50; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#IMG1DB_RD]]
51; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#IMG1D_WR]]
52; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#IMG2D_RW]]
53; CHECK-SPIRV: %[[#SAMP_ARG:]] = OpFunctionParameter %[[#SAMP]]
54
55define spir_kernel void @foo(
56  target("spirv.Pipe", 0) %a,
57  target("spirv.Pipe", 1) %b,
58  target("spirv.Image", void, 0, 0, 0, 0, 0, 0, 0) %c1,
59  target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %d1,
60  target("spirv.Image", void, 2, 0, 0, 0, 0, 0, 0) %e1,
61  target("spirv.Image", void, 1, 0, 1, 0, 0, 0, 0) %f1,
62  target("spirv.Image", void, 5, 0, 0, 0, 0, 0, 0) %g1,
63  target("spirv.Image", void, 0, 0, 0, 0, 0, 0, 1) %c2,
64  target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 2) %d3,
65  target("spirv.Sampler") %s) {
66entry:
67; CHECK-SPIRV: %[[#SAMPIMG_VAR1:]] = OpSampledImage %[[#SAMPIMG]] %[[#IMG_ARG]] %[[#SAMP_ARG]]
68; CHECK-SPIRV: %[[#]] = OpImageSampleExplicitLod %[[#]] %[[#SAMPIMG_VAR1]]
69  %.tmp = call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv4_if(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %d1, target("spirv.Sampler") %s, <4 x i32> zeroinitializer, float 1.000000e+00)
70
71; CHECK-SPIRV: %[[#SAMPIMG_VAR2:]] = OpSampledImage %[[#SAMPIMG]] %[[#IMG_ARG]] %[[#SAMP_CONST]]
72; CHECK-SPIRV: %[[#]] = OpImageSampleExplicitLod %[[#]] %[[#SAMPIMG_VAR2]]
73  %0 = call target("spirv.Sampler") @__translate_sampler_initializer(i32 32)
74  %.tmp2 = call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv4_if(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %d1, target("spirv.Sampler") %0, <4 x i32> zeroinitializer, float 1.000000e+00)
75  ret void
76}
77
78declare spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv4_if(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0), target("spirv.Sampler"), <4 x i32>, float)
79
80declare target("spirv.Sampler") @__translate_sampler_initializer(i32)
81