1 // RUN: mlir-opt -split-input-file -convert-memref-to-spirv -canonicalize -verify-diagnostics %s -o - | FileCheck %s
4 spv.target_env = #spv.target_env<
5 #spv.vce<v1.0, [Shader], [SPV_KHR_storage_buffer_storage_class]>, {}>
8 func @alloc_dealloc_workgroup_mem(%arg0 : index, %arg1 : index) {
9 %0 = memref.alloc() : memref<4x5xf32, 3>
10 %1 = memref.load %0[%arg0, %arg1] : memref<4x5xf32, 3>
11 memref.store %1, %0[%arg0, %arg1] : memref<4x5xf32, 3>
12 memref.dealloc %0 : memref<4x5xf32, 3>
16 // CHECK: spv.GlobalVariable @[[VAR:.+]] : !spv.ptr<!spv.struct<(!spv.array<20 x f32, stride=4>)>, Workgroup>
17 // CHECK: func @alloc_dealloc_workgroup_mem
18 // CHECK-NOT: memref.alloc
19 // CHECK: %[[PTR:.+]] = spv.mlir.addressof @[[VAR]]
20 // CHECK: %[[LOADPTR:.+]] = spv.AccessChain %[[PTR]]
21 // CHECK: %[[VAL:.+]] = spv.Load "Workgroup" %[[LOADPTR]] : f32
22 // CHECK: %[[STOREPTR:.+]] = spv.AccessChain %[[PTR]]
23 // CHECK: spv.Store "Workgroup" %[[STOREPTR]], %[[VAL]] : f32
24 // CHECK-NOT: memref.dealloc
29 spv.target_env = #spv.target_env<
30 #spv.vce<v1.0, [Shader], [SPV_KHR_storage_buffer_storage_class]>, {}>
33 func @alloc_dealloc_workgroup_mem(%arg0 : index, %arg1 : index) {
34 %0 = memref.alloc() : memref<4x5xi16, 3>
35 %1 = memref.load %0[%arg0, %arg1] : memref<4x5xi16, 3>
36 memref.store %1, %0[%arg0, %arg1] : memref<4x5xi16, 3>
37 memref.dealloc %0 : memref<4x5xi16, 3>
42 // CHECK: spv.GlobalVariable @__workgroup_mem__{{[0-9]+}}
43 // CHECK-SAME: !spv.ptr<!spv.struct<(!spv.array<20 x i32, stride=4>)>, Workgroup>
44 // CHECK_LABEL: spv.func @alloc_dealloc_workgroup_mem
45 // CHECK: %[[VAR:.+]] = spv.mlir.addressof @__workgroup_mem__0
46 // CHECK: %[[LOC:.+]] = spv.SDiv
47 // CHECK: %[[PTR:.+]] = spv.AccessChain %[[VAR]][%{{.+}}, %[[LOC]]]
48 // CHECK: %{{.+}} = spv.Load "Workgroup" %[[PTR]] : i32
49 // CHECK: %[[LOC:.+]] = spv.SDiv
50 // CHECK: %[[PTR:.+]] = spv.AccessChain %[[VAR]][%{{.+}}, %[[LOC]]]
51 // CHECK: %{{.+}} = spv.AtomicAnd "Workgroup" "AcquireRelease" %[[PTR]], %{{.+}} : !spv.ptr<i32, Workgroup>
52 // CHECK: %{{.+}} = spv.AtomicOr "Workgroup" "AcquireRelease" %[[PTR]], %{{.+}} : !spv.ptr<i32, Workgroup>
58 spv.target_env = #spv.target_env<
59 #spv.vce<v1.0, [Shader], [SPV_KHR_storage_buffer_storage_class]>, {}>
63 %0 = memref.alloc() : memref<4x5xf32, 3>
64 %1 = memref.alloc() : memref<2x3xi32, 3>
69 // CHECK-DAG: spv.GlobalVariable @__workgroup_mem__{{[0-9]+}}
70 // CHECK-SAME: !spv.ptr<!spv.struct<(!spv.array<6 x i32, stride=4>)>, Workgroup>
71 // CHECK-DAG: spv.GlobalVariable @__workgroup_mem__{{[0-9]+}}
72 // CHECK-SAME: !spv.ptr<!spv.struct<(!spv.array<20 x f32, stride=4>)>, Workgroup>
73 // CHECK: func @two_allocs()
78 spv.target_env = #spv.target_env<
79 #spv.vce<v1.0, [Shader], [SPV_KHR_storage_buffer_storage_class]>, {}>
82 func @two_allocs_vector() {
83 %0 = memref.alloc() : memref<4xvector<4xf32>, 3>
84 %1 = memref.alloc() : memref<2xvector<2xi32>, 3>
89 // CHECK-DAG: spv.GlobalVariable @__workgroup_mem__{{[0-9]+}}
90 // CHECK-SAME: !spv.ptr<!spv.struct<(!spv.array<2 x vector<2xi32>, stride=8>)>, Workgroup>
91 // CHECK-DAG: spv.GlobalVariable @__workgroup_mem__{{[0-9]+}}
92 // CHECK-SAME: !spv.ptr<!spv.struct<(!spv.array<4 x vector<4xf32>, stride=16>)>, Workgroup>
93 // CHECK: func @two_allocs_vector()
99 spv.target_env = #spv.target_env<
100 #spv.vce<v1.0, [Shader], [SPV_KHR_storage_buffer_storage_class]>, {}>
103 func @alloc_dealloc_dynamic_workgroup_mem(%arg0 : index) {
104 // expected-error @+1 {{unhandled allocation type}}
105 %0 = memref.alloc(%arg0) : memref<4x?xf32, 3>
113 spv.target_env = #spv.target_env<
114 #spv.vce<v1.0, [Shader], [SPV_KHR_storage_buffer_storage_class]>, {}>
117 func @alloc_dealloc_mem() {
118 // expected-error @+1 {{unhandled allocation type}}
119 %0 = memref.alloc() : memref<4x5xf32>
128 spv.target_env = #spv.target_env<
129 #spv.vce<v1.0, [Shader], [SPV_KHR_storage_buffer_storage_class]>, {}>
132 func @alloc_dealloc_dynamic_workgroup_mem(%arg0 : memref<4x?xf32, 3>) {
133 // expected-error @+1 {{unhandled deallocation type}}
134 memref.dealloc %arg0 : memref<4x?xf32, 3>
142 spv.target_env = #spv.target_env<
143 #spv.vce<v1.0, [Shader], [SPV_KHR_storage_buffer_storage_class]>, {}>
146 func @alloc_dealloc_mem(%arg0 : memref<4x5xf32>) {
147 // expected-error @+1 {{unhandled deallocation type}}
148 memref.dealloc %arg0 : memref<4x5xf32>