memory-ops-to-llvm.mlir
8.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// RUN: mlir-opt -convert-spirv-to-llvm %s | FileCheck %s
//===----------------------------------------------------------------------===//
// spv.AccessChain
//===----------------------------------------------------------------------===//
// CHECK-LABEL: @access_chain
spv.func @access_chain() "None" {
// CHECK: %[[ONE:.*]] = llvm.mlir.constant(1 : i32) : !llvm.i32
%0 = spv.constant 1: i32
%1 = spv.Variable : !spv.ptr<!spv.struct<f32, !spv.array<4xf32>>, Function>
// CHECK: %[[ZERO:.*]] = llvm.mlir.constant(0 : i32) : !llvm.i32
// CHECK: llvm.getelementptr %{{.*}}[%[[ZERO]], %[[ONE]], %[[ONE]]] : (!llvm.ptr<struct<packed (float, array<4 x float>)>>, !llvm.i32, !llvm.i32, !llvm.i32) -> !llvm.ptr<float>
%2 = spv.AccessChain %1[%0, %0] : !spv.ptr<!spv.struct<f32, !spv.array<4xf32>>, Function>, i32, i32
spv.Return
}
// CHECK-LABEL: @access_chain_array
spv.func @access_chain_array(%arg0 : i32) "None" {
%0 = spv.Variable : !spv.ptr<!spv.array<4x!spv.array<4xf32>>, Function>
// CHECK: %[[ZERO:.*]] = llvm.mlir.constant(0 : i32) : !llvm.i32
// CHECK: llvm.getelementptr %{{.*}}[%[[ZERO]], %{{.*}}] : (!llvm.ptr<array<4 x array<4 x float>>>, !llvm.i32, !llvm.i32) -> !llvm.ptr<array<4 x float>>
%1 = spv.AccessChain %0[%arg0] : !spv.ptr<!spv.array<4x!spv.array<4xf32>>, Function>, i32
%2 = spv.Load "Function" %1 ["Volatile"] : !spv.array<4xf32>
spv.Return
}
//===----------------------------------------------------------------------===//
// spv.globalVariable and spv._address_of
//===----------------------------------------------------------------------===//
spv.module Logical GLSL450 {
// CHECK: llvm.mlir.global external constant @var() : !llvm.float
spv.globalVariable @var : !spv.ptr<f32, Input>
}
spv.module Logical GLSL450 {
// CHECK: llvm.mlir.global private @struct() : !llvm.struct<packed (float, array<10 x float>)>
// CHECK-LABEL: @func
// CHECK: llvm.mlir.addressof @struct : !llvm.ptr<struct<packed (float, array<10 x float>)>>
spv.globalVariable @struct : !spv.ptr<!spv.struct<f32, !spv.array<10xf32>>, Private>
spv.func @func() "None" {
%0 = spv._address_of @struct : !spv.ptr<!spv.struct<f32, !spv.array<10xf32>>, Private>
spv.Return
}
}
spv.module Logical GLSL450 {
// CHECK: llvm.mlir.global external @bar_descriptor_set0_binding0() : !llvm.i32
// CHECK-LABEL: @foo
// CHECK: llvm.mlir.addressof @bar_descriptor_set0_binding0 : !llvm.ptr<i32>
spv.globalVariable @bar bind(0, 0) : !spv.ptr<i32, StorageBuffer>
spv.func @foo() "None" {
%0 = spv._address_of @bar : !spv.ptr<i32, StorageBuffer>
spv.Return
}
}
spv.module @name Logical GLSL450 {
// CHECK: llvm.mlir.global external @name_bar_descriptor_set0_binding0() : !llvm.i32
// CHECK-LABEL: @foo
// CHECK: llvm.mlir.addressof @name_bar_descriptor_set0_binding0 : !llvm.ptr<i32>
spv.globalVariable @bar bind(0, 0) : !spv.ptr<i32, StorageBuffer>
spv.func @foo() "None" {
%0 = spv._address_of @bar : !spv.ptr<i32, StorageBuffer>
spv.Return
}
}
//===----------------------------------------------------------------------===//
// spv.Load
//===----------------------------------------------------------------------===//
// CHECK-LABEL: @load
spv.func @load() "None" {
%0 = spv.Variable : !spv.ptr<f32, Function>
// CHECK: llvm.load %{{.*}} : !llvm.ptr<float>
%1 = spv.Load "Function" %0 : f32
spv.Return
}
// CHECK-LABEL: @load_none
spv.func @load_none() "None" {
%0 = spv.Variable : !spv.ptr<f32, Function>
// CHECK: llvm.load %{{.*}} : !llvm.ptr<float>
%1 = spv.Load "Function" %0 ["None"] : f32
spv.Return
}
// CHECK-LABEL: @load_with_alignment
spv.func @load_with_alignment() "None" {
%0 = spv.Variable : !spv.ptr<f32, Function>
// CHECK: llvm.load %{{.*}} {alignment = 4 : i64} : !llvm.ptr<float>
%1 = spv.Load "Function" %0 ["Aligned", 4] : f32
spv.Return
}
// CHECK-LABEL: @load_volatile
spv.func @load_volatile() "None" {
%0 = spv.Variable : !spv.ptr<f32, Function>
// CHECK: llvm.load volatile %{{.*}} : !llvm.ptr<float>
%1 = spv.Load "Function" %0 ["Volatile"] : f32
spv.Return
}
// CHECK-LABEL: @load_nontemporal
spv.func @load_nontemporal() "None" {
%0 = spv.Variable : !spv.ptr<f32, Function>
// CHECK: llvm.load %{{.*}} {nontemporal} : !llvm.ptr<float>
%1 = spv.Load "Function" %0 ["Nontemporal"] : f32
spv.Return
}
//===----------------------------------------------------------------------===//
// spv.Store
//===----------------------------------------------------------------------===//
// CHECK-LABEL: @store
spv.func @store(%arg0 : f32) "None" {
%0 = spv.Variable : !spv.ptr<f32, Function>
// CHECK: llvm.store %{{.*}}, %{{.*}} : !llvm.ptr<float>
spv.Store "Function" %0, %arg0 : f32
spv.Return
}
// CHECK-LABEL: @store_composite
spv.func @store_composite(%arg0 : !spv.struct<f64>) "None" {
%0 = spv.Variable : !spv.ptr<!spv.struct<f64>, Function>
// CHECK: llvm.store %{{.*}}, %{{.*}} : !llvm.ptr<struct<packed (double)>>
spv.Store "Function" %0, %arg0 : !spv.struct<f64>
spv.Return
}
// CHECK-LABEL: @store_with_alignment
spv.func @store_with_alignment(%arg0 : f32) "None" {
%0 = spv.Variable : !spv.ptr<f32, Function>
// CHECK: llvm.store %{{.*}}, %{{.*}} {alignment = 4 : i64} : !llvm.ptr<float>
spv.Store "Function" %0, %arg0 ["Aligned", 4] : f32
spv.Return
}
// CHECK-LABEL: @store_volatile
spv.func @store_volatile(%arg0 : f32) "None" {
%0 = spv.Variable : !spv.ptr<f32, Function>
// CHECK: llvm.store volatile %{{.*}}, %{{.*}} : !llvm.ptr<float>
spv.Store "Function" %0, %arg0 ["Volatile"] : f32
spv.Return
}
// CHECK-LABEL: @store_nontemporal
spv.func @store_nontemporal(%arg0 : f32) "None" {
%0 = spv.Variable : !spv.ptr<f32, Function>
// CHECK: llvm.store %{{.*}}, %{{.*}} {nontemporal} : !llvm.ptr<float>
spv.Store "Function" %0, %arg0 ["Nontemporal"] : f32
spv.Return
}
//===----------------------------------------------------------------------===//
// spv.Variable
//===----------------------------------------------------------------------===//
// CHECK-LABEL: @variable_scalar
spv.func @variable_scalar() "None" {
// CHECK: %[[SIZE1:.*]] = llvm.mlir.constant(1 : i32) : !llvm.i32
// CHECK: llvm.alloca %[[SIZE1]] x !llvm.float : (!llvm.i32) -> !llvm.ptr<float>
%0 = spv.Variable : !spv.ptr<f32, Function>
// CHECK: %[[SIZE2:.*]] = llvm.mlir.constant(1 : i32) : !llvm.i32
// CHECK: llvm.alloca %[[SIZE2]] x !llvm.i8 : (!llvm.i32) -> !llvm.ptr<i8>
%1 = spv.Variable : !spv.ptr<i8, Function>
spv.Return
}
// CHECK-LABEL: @variable_scalar_with_initialization
spv.func @variable_scalar_with_initialization() "None" {
// CHECK: %[[VALUE:.*]] = llvm.mlir.constant(0 : i64) : !llvm.i64
// CHECK: %[[SIZE:.*]] = llvm.mlir.constant(1 : i32) : !llvm.i32
// CHECK: %[[ALLOCATED:.*]] = llvm.alloca %[[SIZE]] x !llvm.i64 : (!llvm.i32) -> !llvm.ptr<i64>
// CHECK: llvm.store %[[VALUE]], %[[ALLOCATED]] : !llvm.ptr<i64>
%c = spv.constant 0 : i64
%0 = spv.Variable init(%c) : !spv.ptr<i64, Function>
spv.Return
}
// CHECK-LABEL: @variable_vector
spv.func @variable_vector() "None" {
// CHECK: %[[SIZE:.*]] = llvm.mlir.constant(1 : i32) : !llvm.i32
// CHECK: llvm.alloca %[[SIZE]] x !llvm.vec<3 x float> : (!llvm.i32) -> !llvm.ptr<vec<3 x float>>
%0 = spv.Variable : !spv.ptr<vector<3xf32>, Function>
spv.Return
}
// CHECK-LABEL: @variable_vector_with_initialization
spv.func @variable_vector_with_initialization() "None" {
// CHECK: %[[VALUE:.*]] = llvm.mlir.constant(dense<false> : vector<3xi1>) : !llvm.vec<3 x i1>
// CHECK: %[[SIZE:.*]] = llvm.mlir.constant(1 : i32) : !llvm.i32
// CHECK: %[[ALLOCATED:.*]] = llvm.alloca %[[SIZE]] x !llvm.vec<3 x i1> : (!llvm.i32) -> !llvm.ptr<vec<3 x i1>>
// CHECK: llvm.store %[[VALUE]], %[[ALLOCATED]] : !llvm.ptr<vec<3 x i1>>
%c = spv.constant dense<false> : vector<3xi1>
%0 = spv.Variable init(%c) : !spv.ptr<vector<3xi1>, Function>
spv.Return
}
// CHECK-LABEL: @variable_array
spv.func @variable_array() "None" {
// CHECK: %[[SIZE:.*]] = llvm.mlir.constant(1 : i32) : !llvm.i32
// CHECK: llvm.alloca %[[SIZE]] x !llvm.array<10 x i32> : (!llvm.i32) -> !llvm.ptr<array<10 x i32>>
%0 = spv.Variable : !spv.ptr<!spv.array<10 x i32>, Function>
spv.Return
}