xref: /llvm-project/llvm/test/CodeGen/SPIRV/transcoding/spirv-types.ll (revision f9c98068c852c1bb1ec029c2c8df8ace9605f16f)
1;; Test SPIR-V opaque types
2
3; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
4; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
5
6; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
7; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
8
9; CHECK-SPIRV-DAG: OpCapability Float16
10; CHECK-SPIRV-DAG: OpCapability ImageReadWrite
11; CHECK-SPIRV-DAG: OpCapability Pipes
12; CHECK-SPIRV-DAG: OpCapability DeviceEnqueue
13
14; CHECK-SPIRV-DAG: %[[#VOID:]] = OpTypeVoid
15; CHECK-SPIRV-DAG: %[[#INT:]] = OpTypeInt 32 0
16; CHECK-SPIRV-DAG: %[[#HALF:]] = OpTypeFloat 16
17; CHECK-SPIRV-DAG: %[[#FLOAT:]] = OpTypeFloat 32
18; CHECK-SPIRV-DAG: %[[#PIPE_RD:]] = OpTypePipe ReadOnly
19; CHECK-SPIRV-DAG: %[[#PIPE_WR:]] = OpTypePipe WriteOnly
20; CHECK-SPIRV-DAG: %[[#IMG1D_RD:]] = OpTypeImage %[[#VOID]] 1D 0 0 0 0 Unknown ReadOnly
21; CHECK-SPIRV-DAG: %[[#IMG2D_RD:]] = OpTypeImage %[[#INT]] 2D 0 0 0 0 Unknown ReadOnly
22; CHECK-SPIRV-DAG: %[[#IMG3D_RD:]] = OpTypeImage %[[#INT]] 3D 0 0 0 0 Unknown ReadOnly
23; CHECK-SPIRV-DAG: %[[#IMG2DD_RD:]] = OpTypeImage %[[#FLOAT]] 2D 1 0 0 0 Unknown ReadOnly
24; CHECK-SPIRV-DAG: %[[#IMG2DA_RD:]] = OpTypeImage %[[#HALF]] 2D 0 1 0 0 Unknown ReadOnly
25; CHECK-SPIRV-DAG: %[[#IMG1DB_RD:]] = OpTypeImage %[[#FLOAT]] Buffer 0 0 0 0 Unknown ReadOnly
26; CHECK-SPIRV-DAG: %[[#IMG1D_WR:]] = OpTypeImage %[[#VOID]] 1D 0 0 0 0 Unknown WriteOnly
27; CHECK-SPIRV-DAG: %[[#IMG2D_RW:]] = OpTypeImage %[[#VOID]] 2D 0 0 0 0 Unknown ReadWrite
28; CHECK-SPIRV-DAG: %[[#DEVEVENT:]] = OpTypeDeviceEvent
29; CHECK-SPIRV-DAG: %[[#EVENT:]] = OpTypeEvent
30; CHECK-SPIRV-DAG: %[[#QUEUE:]] = OpTypeQueue
31; CHECK-SPIRV-DAG: %[[#RESID:]] = OpTypeReserveId
32; CHECK-SPIRV-DAG: %[[#SAMP:]] = OpTypeSampler
33; CHECK-SPIRV-DAG: %[[#SAMPIMG:]] = OpTypeSampledImage %[[#IMG2DD_RD]]
34
35; CHECK-SPIRV: OpFunction
36; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#PIPE_RD]]
37; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#PIPE_WR]]
38; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#IMG1D_RD]]
39; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#IMG2D_RD]]
40; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#IMG3D_RD]]
41; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#IMG2DA_RD]]
42; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#IMG1DB_RD]]
43; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#IMG1D_WR]]
44; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#IMG2D_RW]]
45
46define spir_kernel void @foo(
47  target("spirv.Pipe", 0) %a,
48  target("spirv.Pipe", 1) %b,
49  target("spirv.Image", void, 0, 0, 0, 0, 0, 0, 0) %c1,
50  target("spirv.Image", i32, 1, 0, 0, 0, 0, 0, 0) %d1,
51  target("spirv.Image", i32, 2, 0, 0, 0, 0, 0, 0) %e1,
52  target("spirv.Image", half, 1, 0, 1, 0, 0, 0, 0) %f1,
53  target("spirv.Image", float, 5, 0, 0, 0, 0, 0, 0) %g1,
54  target("spirv.Image", void, 0, 0, 0, 0, 0, 0, 1) %c2,
55  target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 2) %d3) {
56entry:
57  ret void
58}
59
60; CHECK-SPIRV: OpFunction
61; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#DEVEVENT]]
62; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#EVENT]]
63; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#QUEUE]]
64; CHECK-SPIRV: %[[#]] = OpFunctionParameter %[[#RESID]]
65
66define spir_func void @bar(
67  target("spirv.DeviceEvent") %a,
68  target("spirv.Event") %b,
69  target("spirv.Queue") %c,
70  target("spirv.ReserveId") %d) {
71  ret void
72}
73
74; CHECK-SPIRV: OpFunction
75; CHECK-SPIRV: %[[#IMG_ARG:]] = OpFunctionParameter %[[#IMG2DD_RD]]
76; CHECK-SPIRV: %[[#SAMP_ARG:]] = OpFunctionParameter %[[#SAMP]]
77; CHECK-SPIRV: %[[#SAMPIMG_VAR:]] = OpSampledImage %[[#SAMPIMG]] %[[#IMG_ARG]] %[[#SAMP_ARG]]
78; CHECK-SPIRV: %[[#]] = OpImageSampleExplicitLod %[[#]] %[[#SAMPIMG_VAR]]
79
80define spir_func void @test_sampler(target("spirv.Image", float, 1, 1, 0, 0, 0, 0, 0) %srcimg.coerce,
81                                    target("spirv.Sampler") %s.coerce) {
82  %1 = tail call spir_func target("spirv.Image", float, 1, 1, 0, 0, 0, 0, 0) @_Z20__spirv_SampledImagePU3AS1K34__spirv_Image__float_1_1_0_0_0_0_0PU3AS1K15__spirv_Sampler(target("spirv.Image", float, 1, 1, 0, 0, 0, 0, 0) %srcimg.coerce, target("spirv.Sampler") %s.coerce)
83  %2 = tail call spir_func <4 x float> @_Z38__spirv_ImageSampleExplicitLod_Rfloat4PU3AS120__spirv_SampledImageDv4_iif(target("spirv.Image", float, 1, 1, 0, 0, 0, 0, 0) %1, <4 x i32> zeroinitializer, i32 2, float 1.000000e+00)
84  ret void
85}
86
87declare spir_func target("spirv.Image", float, 1, 1, 0, 0, 0, 0, 0) @_Z20__spirv_SampledImagePU3AS1K34__spirv_Image__float_1_1_0_0_0_0_0PU3AS1K15__spirv_Sampler(target("spirv.Image", float, 1, 1, 0, 0, 0, 0, 0), target("spirv.Sampler"))
88
89declare spir_func <4 x float> @_Z38__spirv_ImageSampleExplicitLod_Rfloat4PU3AS120__spirv_SampledImageDv4_iif(target("spirv.Image", float, 1, 1, 0, 0, 0, 0, 0), <4 x i32>, i32, float)
90