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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
|
// RUN: mlir-opt -convert-spirv-to-llvm='use-opaque-pointers=1' %s | FileCheck %s
//===----------------------------------------------------------------------===//
// spirv.AccessChain
//===----------------------------------------------------------------------===//
// CHECK-LABEL: @access_chain
spirv.func @access_chain() "None" {
// CHECK: %[[ONE:.*]] = llvm.mlir.constant(1 : i32) : i32
%0 = spirv.Constant 1: i32
%1 = spirv.Variable : !spirv.ptr<!spirv.struct<(f32, !spirv.array<4xf32>)>, Function>
// CHECK: %[[ZERO:.*]] = llvm.mlir.constant(0 : i32) : i32
// CHECK: llvm.getelementptr %{{.*}}[%[[ZERO]], 1, %[[ONE]]] : (!llvm.ptr, i32, i32) -> !llvm.ptr, !llvm.struct<packed (f32, array<4 x f32>)>
%2 = spirv.AccessChain %1[%0, %0] : !spirv.ptr<!spirv.struct<(f32, !spirv.array<4xf32>)>, Function>, i32, i32
spirv.Return
}
// CHECK-LABEL: @access_chain_array
spirv.func @access_chain_array(%arg0 : i32) "None" {
%0 = spirv.Variable : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>
// CHECK: %[[ZERO:.*]] = llvm.mlir.constant(0 : i32) : i32
// CHECK: llvm.getelementptr %{{.*}}[%[[ZERO]], %{{.*}}] : (!llvm.ptr, i32, i32) -> !llvm.ptr, !llvm.array<4 x array<4 x f32>>
%1 = spirv.AccessChain %0[%arg0] : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>, i32
%2 = spirv.Load "Function" %1 ["Volatile"] : !spirv.array<4xf32>
spirv.Return
}
//===----------------------------------------------------------------------===//
// spirv.GlobalVariable and spirv.mlir.addressof
//===----------------------------------------------------------------------===//
spirv.module Logical GLSL450 {
// CHECK: llvm.mlir.global external constant @var() {addr_space = 0 : i32} : f32
spirv.GlobalVariable @var : !spirv.ptr<f32, Input>
}
spirv.module Logical GLSL450 {
// CHECK: llvm.mlir.global private @struct() {addr_space = 0 : i32} : !llvm.struct<packed (f32, array<10 x f32>)>
// CHECK-LABEL: @func
// CHECK: llvm.mlir.addressof @struct : !llvm.ptr
spirv.GlobalVariable @struct : !spirv.ptr<!spirv.struct<(f32, !spirv.array<10xf32>)>, Private>
spirv.func @func() "None" {
%0 = spirv.mlir.addressof @struct : !spirv.ptr<!spirv.struct<(f32, !spirv.array<10xf32>)>, Private>
spirv.Return
}
}
spirv.module Logical GLSL450 {
// CHECK: llvm.mlir.global external @bar_descriptor_set0_binding0() {addr_space = 0 : i32} : i32
// CHECK-LABEL: @foo
// CHECK: llvm.mlir.addressof @bar_descriptor_set0_binding0 : !llvm.ptr
spirv.GlobalVariable @bar bind(0, 0) : !spirv.ptr<i32, StorageBuffer>
spirv.func @foo() "None" {
%0 = spirv.mlir.addressof @bar : !spirv.ptr<i32, StorageBuffer>
spirv.Return
}
}
spirv.module @name Logical GLSL450 {
// CHECK: llvm.mlir.global external @name_bar_descriptor_set0_binding0() {addr_space = 0 : i32} : i32
// CHECK-LABEL: @foo
// CHECK: llvm.mlir.addressof @name_bar_descriptor_set0_binding0 : !llvm.ptr
spirv.GlobalVariable @bar bind(0, 0) : !spirv.ptr<i32, StorageBuffer>
spirv.func @foo() "None" {
%0 = spirv.mlir.addressof @bar : !spirv.ptr<i32, StorageBuffer>
spirv.Return
}
}
spirv.module Logical GLSL450 {
// CHECK: llvm.mlir.global external @bar() {addr_space = 0 : i32, location = 1 : i32} : i32
// CHECK-LABEL: @foo
spirv.GlobalVariable @bar {location = 1 : i32} : !spirv.ptr<i32, Output>
spirv.func @foo() "None" {
%0 = spirv.mlir.addressof @bar : !spirv.ptr<i32, Output>
spirv.Return
}
}
spirv.module Logical GLSL450 {
// CHECK: llvm.mlir.global external constant @bar() {addr_space = 0 : i32, location = 3 : i32} : f32
// CHECK-LABEL: @foo
spirv.GlobalVariable @bar {descriptor_set = 0 : i32, location = 3 : i32} : !spirv.ptr<f32, UniformConstant>
spirv.func @foo() "None" {
%0 = spirv.mlir.addressof @bar : !spirv.ptr<f32, UniformConstant>
spirv.Return
}
}
//===----------------------------------------------------------------------===//
// spirv.Load
//===----------------------------------------------------------------------===//
// CHECK-LABEL: @load
spirv.func @load() "None" {
%0 = spirv.Variable : !spirv.ptr<f32, Function>
// CHECK: llvm.load %{{.*}} : !llvm.ptr -> f32
%1 = spirv.Load "Function" %0 : f32
spirv.Return
}
// CHECK-LABEL: @load_none
spirv.func @load_none() "None" {
%0 = spirv.Variable : !spirv.ptr<f32, Function>
// CHECK: llvm.load %{{.*}} : !llvm.ptr -> f32
%1 = spirv.Load "Function" %0 ["None"] : f32
spirv.Return
}
// CHECK-LABEL: @load_with_alignment
spirv.func @load_with_alignment() "None" {
%0 = spirv.Variable : !spirv.ptr<f32, Function>
// CHECK: llvm.load %{{.*}} {alignment = 4 : i64} : !llvm.ptr -> f32
%1 = spirv.Load "Function" %0 ["Aligned", 4] : f32
spirv.Return
}
// CHECK-LABEL: @load_volatile
spirv.func @load_volatile() "None" {
%0 = spirv.Variable : !spirv.ptr<f32, Function>
// CHECK: llvm.load volatile %{{.*}} : !llvm.ptr -> f32
%1 = spirv.Load "Function" %0 ["Volatile"] : f32
spirv.Return
}
// CHECK-LABEL: @load_nontemporal
spirv.func @load_nontemporal() "None" {
%0 = spirv.Variable : !spirv.ptr<f32, Function>
// CHECK: llvm.load %{{.*}} {nontemporal} : !llvm.ptr -> f32
%1 = spirv.Load "Function" %0 ["Nontemporal"] : f32
spirv.Return
}
//===----------------------------------------------------------------------===//
// spirv.Store
//===----------------------------------------------------------------------===//
// CHECK-LABEL: @store
spirv.func @store(%arg0 : f32) "None" {
%0 = spirv.Variable : !spirv.ptr<f32, Function>
// CHECK: llvm.store %{{.*}}, %{{.*}} : f32, !llvm.ptr
spirv.Store "Function" %0, %arg0 : f32
spirv.Return
}
// CHECK-LABEL: @store_composite
spirv.func @store_composite(%arg0 : !spirv.struct<(f64)>) "None" {
%0 = spirv.Variable : !spirv.ptr<!spirv.struct<(f64)>, Function>
// CHECK: llvm.store %{{.*}}, %{{.*}} : !llvm.struct<packed (f64)>, !llvm.ptr
spirv.Store "Function" %0, %arg0 : !spirv.struct<(f64)>
spirv.Return
}
// CHECK-LABEL: @store_with_alignment
spirv.func @store_with_alignment(%arg0 : f32) "None" {
%0 = spirv.Variable : !spirv.ptr<f32, Function>
// CHECK: llvm.store %{{.*}}, %{{.*}} {alignment = 4 : i64} : f32, !llvm.ptr
spirv.Store "Function" %0, %arg0 ["Aligned", 4] : f32
spirv.Return
}
// CHECK-LABEL: @store_volatile
spirv.func @store_volatile(%arg0 : f32) "None" {
%0 = spirv.Variable : !spirv.ptr<f32, Function>
// CHECK: llvm.store volatile %{{.*}}, %{{.*}} : f32, !llvm.ptr
spirv.Store "Function" %0, %arg0 ["Volatile"] : f32
spirv.Return
}
// CHECK-LABEL: @store_nontemporal
spirv.func @store_nontemporal(%arg0 : f32) "None" {
%0 = spirv.Variable : !spirv.ptr<f32, Function>
// CHECK: llvm.store %{{.*}}, %{{.*}} {nontemporal} : f32, !llvm.ptr
spirv.Store "Function" %0, %arg0 ["Nontemporal"] : f32
spirv.Return
}
//===----------------------------------------------------------------------===//
// spirv.Variable
//===----------------------------------------------------------------------===//
// CHECK-LABEL: @variable_scalar
spirv.func @variable_scalar() "None" {
// CHECK: %[[SIZE1:.*]] = llvm.mlir.constant(1 : i32) : i32
// CHECK: llvm.alloca %[[SIZE1]] x f32 : (i32) -> !llvm.ptr
%0 = spirv.Variable : !spirv.ptr<f32, Function>
// CHECK: %[[SIZE2:.*]] = llvm.mlir.constant(1 : i32) : i32
// CHECK: llvm.alloca %[[SIZE2]] x i8 : (i32) -> !llvm.ptr
%1 = spirv.Variable : !spirv.ptr<i8, Function>
spirv.Return
}
// CHECK-LABEL: @variable_scalar_with_initialization
spirv.func @variable_scalar_with_initialization() "None" {
// CHECK: %[[VALUE:.*]] = llvm.mlir.constant(0 : i64) : i64
// CHECK: %[[SIZE:.*]] = llvm.mlir.constant(1 : i32) : i32
// CHECK: %[[ALLOCATED:.*]] = llvm.alloca %[[SIZE]] x i64 : (i32) -> !llvm.ptr
// CHECK: llvm.store %[[VALUE]], %[[ALLOCATED]] : i64, !llvm.ptr
%c = spirv.Constant 0 : i64
%0 = spirv.Variable init(%c) : !spirv.ptr<i64, Function>
spirv.Return
}
// CHECK-LABEL: @variable_vector
spirv.func @variable_vector() "None" {
// CHECK: %[[SIZE:.*]] = llvm.mlir.constant(1 : i32) : i32
// CHECK: llvm.alloca %[[SIZE]] x vector<3xf32> : (i32) -> !llvm.ptr
%0 = spirv.Variable : !spirv.ptr<vector<3xf32>, Function>
spirv.Return
}
// CHECK-LABEL: @variable_vector_with_initialization
spirv.func @variable_vector_with_initialization() "None" {
// CHECK: %[[VALUE:.*]] = llvm.mlir.constant(dense<false> : vector<3xi1>) : vector<3xi1>
// CHECK: %[[SIZE:.*]] = llvm.mlir.constant(1 : i32) : i32
// CHECK: %[[ALLOCATED:.*]] = llvm.alloca %[[SIZE]] x vector<3xi1> : (i32) -> !llvm.ptr
// CHECK: llvm.store %[[VALUE]], %[[ALLOCATED]] : vector<3xi1>, !llvm.ptr
%c = spirv.Constant dense<false> : vector<3xi1>
%0 = spirv.Variable init(%c) : !spirv.ptr<vector<3xi1>, Function>
spirv.Return
}
// CHECK-LABEL: @variable_array
spirv.func @variable_array() "None" {
// CHECK: %[[SIZE:.*]] = llvm.mlir.constant(1 : i32) : i32
// CHECK: llvm.alloca %[[SIZE]] x !llvm.array<10 x i32> : (i32) -> !llvm.ptr
%0 = spirv.Variable : !spirv.ptr<!spirv.array<10 x i32>, Function>
spirv.Return
}
|