1 // RUN: mlir-opt -split-input-file -convert-memref-to-spirv -canonicalize -verify-diagnostics %s -o - | FileCheck %s
3 module attributes {spirv.target_env = #spirv.target_env<#spirv.vce<v1.3, [Shader], []>, #spirv.resource_limits<>>} {
4 func.func @alloc_function_variable(%arg0 : index, %arg1 : index) {
5 %0 = memref.alloca() : memref<4x5xf32, #spirv.storage_class<Function>>
6 %1 = memref.load %0[%arg0, %arg1] : memref<4x5xf32, #spirv.storage_class<Function>>
7 memref.store %1, %0[%arg0, %arg1] : memref<4x5xf32, #spirv.storage_class<Function>>
12 // CHECK-LABEL: func @alloc_function_variable
13 // CHECK: %[[VAR:.+]] = spirv.Variable : !spirv.ptr<!spirv.struct<(!spirv.array<20 x f32>)>, Function>
14 // CHECK: %[[LOADPTR:.+]] = spirv.AccessChain %[[VAR]]
15 // CHECK: %[[VAL:.+]] = spirv.Load "Function" %[[LOADPTR]] : f32
16 // CHECK: %[[STOREPTR:.+]] = spirv.AccessChain %[[VAR]]
17 // CHECK: spirv.Store "Function" %[[STOREPTR]], %[[VAL]] : f32
21 module attributes {spirv.target_env = #spirv.target_env<#spirv.vce<v1.3, [Shader], []>, #spirv.resource_limits<>>} {
22 func.func @two_allocs() {
23 %0 = memref.alloca() : memref<4x5xf32, #spirv.storage_class<Function>>
24 %1 = memref.alloca() : memref<2x3xi32, #spirv.storage_class<Function>>
29 // CHECK-LABEL: func @two_allocs
30 // CHECK-DAG: spirv.Variable : !spirv.ptr<!spirv.struct<(!spirv.array<6 x i32>)>, Function>
31 // CHECK-DAG: spirv.Variable : !spirv.ptr<!spirv.struct<(!spirv.array<20 x f32>)>, Function>
35 module attributes {spirv.target_env = #spirv.target_env<#spirv.vce<v1.3, [Shader], []>, #spirv.resource_limits<>>} {
36 func.func @two_allocs_vector() {
37 %0 = memref.alloca() : memref<4xvector<4xf32>, #spirv.storage_class<Function>>
38 %1 = memref.alloca() : memref<2xvector<2xi32>, #spirv.storage_class<Function>>
43 // CHECK-LABEL: func @two_allocs_vector
44 // CHECK-DAG: spirv.Variable : !spirv.ptr<!spirv.struct<(!spirv.array<2 x vector<2xi32>>)>, Function>
45 // CHECK-DAG: spirv.Variable : !spirv.ptr<!spirv.struct<(!spirv.array<4 x vector<4xf32>>)>, Function>
50 module attributes {spirv.target_env = #spirv.target_env<#spirv.vce<v1.3, [Shader], []>, #spirv.resource_limits<>>} {
51 // CHECK-LABEL: func @alloc_dynamic_size
52 func.func @alloc_dynamic_size(%arg0 : index) -> f32 {
53 // CHECK: memref.alloca
54 %0 = memref.alloca(%arg0) : memref<4x?xf32, #spirv.storage_class<Function>>
55 %1 = memref.load %0[%arg0, %arg0] : memref<4x?xf32, #spirv.storage_class<Function>>
62 module attributes {spirv.target_env = #spirv.target_env<#spirv.vce<v1.3, [Shader], []>, #spirv.resource_limits<>>} {
63 // CHECK-LABEL: func @alloc_unsupported_memory_space
64 func.func @alloc_unsupported_memory_space(%arg0: index) -> f32 {
65 // CHECK: memref.alloca
66 %0 = memref.alloca() : memref<4x5xf32>
67 %1 = memref.load %0[%arg0, %arg0] : memref<4x5xf32>
74 module attributes {spirv.target_env = #spirv.target_env<#spirv.vce<v1.3, [Shader], []>, #spirv.resource_limits<>>} {
75 func.func @zero_size() {
76 %0 = memref.alloca() : memref<0xf32, #spirv.storage_class<Function>>
81 // Zero-sized allocations are not handled yet. Just make sure we do not crash.
82 // CHECK-LABEL: func @zero_size