1013 lines · plain
1// RUN: mlir-opt -allow-unregistered-dialect -split-input-file -verify-diagnostics %s | FileCheck %s2 3//===----------------------------------------------------------------------===//4// spirv.mlir.addressof5//===----------------------------------------------------------------------===//6 7spirv.module Logical GLSL450 {8 spirv.GlobalVariable @var1 : !spirv.ptr<!spirv.struct<(f32, !spirv.array<4xf32>)>, Input>9 spirv.func @access_chain() -> () "None" {10 %0 = spirv.Constant 1: i3211 // CHECK: [[VAR1:%.*]] = spirv.mlir.addressof @var1 : !spirv.ptr<!spirv.struct<(f32, !spirv.array<4 x f32>)>, Input>12 // CHECK-NEXT: spirv.AccessChain [[VAR1]][{{.*}}, {{.*}}] : !spirv.ptr<!spirv.struct<(f32, !spirv.array<4 x f32>)>, Input>13 %1 = spirv.mlir.addressof @var1 : !spirv.ptr<!spirv.struct<(f32, !spirv.array<4xf32>)>, Input>14 %2 = spirv.AccessChain %1[%0, %0] : !spirv.ptr<!spirv.struct<(f32, !spirv.array<4xf32>)>, Input>, i32, i32 -> !spirv.ptr<f32, Input>15 spirv.Return16 }17}18 19// -----20 21// Allow taking address of global variables in other module-like ops22spirv.GlobalVariable @var : !spirv.ptr<!spirv.struct<(f32, !spirv.array<4xf32>)>, Input>23func.func @addressof() -> () {24 // CHECK: spirv.mlir.addressof @var25 %1 = spirv.mlir.addressof @var : !spirv.ptr<!spirv.struct<(f32, !spirv.array<4xf32>)>, Input>26 return27}28 29// -----30 31spirv.module Logical GLSL450 {32 spirv.GlobalVariable @var1 : !spirv.ptr<!spirv.struct<(f32, !spirv.array<4xf32>)>, Input>33 spirv.func @foo() -> () "None" {34 // expected-error @+1 {{expected spirv.GlobalVariable symbol}}35 %0 = spirv.mlir.addressof @var2 : !spirv.ptr<!spirv.struct<(f32, !spirv.array<4xf32>)>, Input>36 }37}38 39// -----40 41spirv.module Logical GLSL450 {42 spirv.GlobalVariable @var1 : !spirv.ptr<!spirv.struct<(f32, !spirv.array<4xf32>)>, Input>43 spirv.func @foo() -> () "None" {44 // expected-error @+1 {{result type mismatch with the referenced global variable's type}}45 %0 = spirv.mlir.addressof @var1 : !spirv.ptr<f32, Input>46 }47}48 49// -----50 51//===----------------------------------------------------------------------===//52// spirv.Constant53//===----------------------------------------------------------------------===//54 55func.func @const() -> () {56 // CHECK: spirv.Constant true57 // CHECK: spirv.Constant 42 : i3258 // CHECK: spirv.Constant 5.000000e-01 : f3259 // CHECK: spirv.Constant dense<[2, 3]> : vector<2xi32>60 // CHECK: spirv.Constant [dense<3.000000e+00> : vector<2xf32>] : !spirv.array<1 x vector<2xf32>>61 // CHECK: spirv.Constant dense<1> : tensor<2x3xi32> : !spirv.array<2 x !spirv.array<3 x i32>>62 // CHECK: spirv.Constant dense<1.000000e+00> : tensor<2x3xf32> : !spirv.array<2 x !spirv.array<3 x f32>>63 // CHECK: spirv.Constant dense<{{\[}}[1, 2, 3], [4, 5, 6]]> : tensor<2x3xi32> : !spirv.array<2 x !spirv.array<3 x i32>>64 // CHECK: spirv.Constant dense<{{\[}}[1.000000e+00, 2.000000e+00, 3.000000e+00], [4.000000e+00, 5.000000e+00, 6.000000e+00]]> : tensor<2x3xf32> : !spirv.array<2 x !spirv.array<3 x f32>>65 // CHECK: spirv.Constant dense<0.000000e+00> : !spirv.coopmatrix<16x16xf32, Subgroup, MatrixAcc>66 // CHECK: spirv.Constant dense<4.200000e+00> : !spirv.coopmatrix<16x16xf32, Subgroup, MatrixAcc>67 // CHECK: spirv.Constant dense<0> : !spirv.coopmatrix<16x16xi8, Subgroup, MatrixAcc>68 // CHECK: spirv.Constant dense<4> : !spirv.coopmatrix<16x16xi8, Subgroup, MatrixAcc>69 70 %0 = spirv.Constant true71 %1 = spirv.Constant 42 : i3272 %2 = spirv.Constant 0.5 : f3273 %3 = spirv.Constant dense<[2, 3]> : vector<2xi32>74 %4 = spirv.Constant [dense<3.0> : vector<2xf32>] : !spirv.array<1xvector<2xf32>>75 %5 = spirv.Constant dense<1> : tensor<2x3xi32> : !spirv.array<2 x !spirv.array<3 x i32>>76 %6 = spirv.Constant dense<1.0> : tensor<2x3xf32> : !spirv.array<2 x !spirv.array<3 x f32>>77 %7 = spirv.Constant dense<[[1, 2, 3], [4, 5, 6]]> : tensor<2x3xi32> : !spirv.array<2 x !spirv.array<3 x i32>>78 %8 = spirv.Constant dense<[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]> : tensor<2x3xf32> : !spirv.array<2 x !spirv.array<3 x f32>>79 %9 = spirv.Constant [[dense<3.0> : vector<2xf32>]] : !spirv.array<1 x !spirv.array<1xvector<2xf32>>>80 %10 = spirv.Constant dense<0.000000e+00> : !spirv.coopmatrix<16x16xf32, Subgroup, MatrixAcc>81 %11 = spirv.Constant dense<4.200000e+00> : !spirv.coopmatrix<16x16xf32, Subgroup, MatrixAcc>82 %12 = spirv.Constant dense<0> : !spirv.coopmatrix<16x16xi8, Subgroup, MatrixAcc>83 %13 = spirv.Constant dense<4> : !spirv.coopmatrix<16x16xi8, Subgroup, MatrixAcc>84 return85}86 87// -----88 89func.func @unaccepted_std_attr() -> () {90 // expected-error @+1 {{cannot have attribute: unit}}91 %0 = spirv.Constant unit : none92 return93}94 95// -----96 97func.func @array_constant() -> () {98 // expected-error @+1 {{result or element type ('vector<2xf32>') does not match value type ('vector<2xi32>')}}99 %0 = spirv.Constant [dense<3.0> : vector<2xf32>, dense<4> : vector<2xi32>] : !spirv.array<2xvector<2xf32>>100 return101}102 103// -----104 105func.func @array_constant() -> () {106 // expected-error @+1 {{must have spirv.array result type for array value}}107 %0 = spirv.Constant [dense<3.0> : vector<2xf32>] : !spirv.rtarray<vector<2xf32>>108 return109}110 111// -----112 113func.func @non_nested_array_constant() -> () {114 // expected-error @+1 {{only support nested array result type}}115 %0 = spirv.Constant dense<3.0> : tensor<2x2xf32> : !spirv.array<2xvector<2xf32>>116 return117}118 119// -----120 121func.func @value_result_type_mismatch() -> () {122 // expected-error @+1 {{result or element type ('vector<4xi32>') does not match value type ('tensor<4xi32>')}}123 %0 = "spirv.Constant"() {value = dense<0> : tensor<4xi32>} : () -> (vector<4xi32>)124}125 126// -----127 128func.func @value_result_type_mismatch() -> () {129 // expected-error @+1 {{result element type ('i32') does not match value element type ('f32')}}130 %0 = spirv.Constant dense<1.0> : tensor<2x3xf32> : !spirv.array<2 x !spirv.array<3 x i32>>131}132 133// -----134 135func.func @value_result_num_elements_mismatch() -> () {136 // expected-error @+1 {{result number of elements (6) does not match value number of elements (4)}}137 %0 = spirv.Constant dense<1.0> : tensor<2x2xf32> : !spirv.array<2 x !spirv.array<3 x f32>>138 return139}140 141// -----142 143func.func @coop_matrix_const_non_splat() -> () {144 // expected-error @+1 {{expected a splat dense attribute for cooperative matrix constant, but found}}145 %0 = spirv.Constant dense<[[1.0, 2.0], [3.0, 4.0]]> : !spirv.coopmatrix<2x2xf32, Subgroup, MatrixAcc>146 return147}148 149// -----150 151func.func @coop_matrix_const_non_dense() -> () {152 // expected-error @+2 {{floating point value not valid for specified type}}153 %0 = spirv.Constant 0.000000e+00 : !spirv.coopmatrix<16x16xf32, Subgroup, MatrixAcc>154 return155}156 157// -----158 159func.func @coop_matrix_const_wrong_type() -> () {160 // expected-error @below {{unexpected decimal integer literal for a floating point value}}161 // expected-note @+1 {{add a trailing dot to make the literal a float}}162 %0 = spirv.Constant dense<4> : !spirv.coopmatrix<16x16xf32, Subgroup, MatrixAcc>163 return164}165 166// -----167 168//===----------------------------------------------------------------------===//169// spirv.EXT.ConstantCompositeReplicate170//===----------------------------------------------------------------------===//171 172func.func @ccr_result_not_composite() -> () {173 // expected-error @+1 {{op result #0 must be vector of bool or 8/16/32/64-bit integer or 16/32/64-bit float or BFloat16 values of length 2/3/4/8/16 or any SPIR-V array type or any SPIR-V runtime array type or any SPIR-V struct type or any SPIR-V cooperative matrix type or any SPIR-V matrix type or any SPIR-V tensorArm type, but got 'i32'}}174 %0 = spirv.EXT.ConstantCompositeReplicate [1 : i32] : i32175 return176}177 178// -----179 180func.func @ccr_wrong_splat_type() -> () {181 // expected-error @+1 {{expected value attribute type 'f32', but got: 'i32'}}182 %0 = spirv.EXT.ConstantCompositeReplicate [1 : i32] : vector<2xf32>183 return184}185 186// -----187 188func.func @ccr_wrong_splat_type() -> () {189 // expected-error @+1 {{expected value attribute type '!spirv.array<3 x i32>' or 'i32', but got: 'vector<2xi32>'}}190 %0 = spirv.EXT.ConstantCompositeReplicate [dense<[1, 2]> : vector<2xi32>] : !spirv.array<2 x !spirv.array<3 x i32>>191 return192}193 194// -----195 196func.func @ccr_wrong_splat_type() -> () {197 // expected-error @+1 {{expected value attribute type 'f32', but got: 'i32'}}198 %0 = spirv.EXT.ConstantCompositeReplicate [1 : i32] : !spirv.arm.tensor<2x3xf32>199 return200}201 202// -----203 204func.func @ccr_wrong_splat_type() -> () {205 // expected-error @+1 {{expected value attribute type 'vector<3xi32>' or 'i32', but got: 'vector<2xi32>'}}206 %0 = spirv.EXT.ConstantCompositeReplicate [dense<[1, 2]> : vector<2xi32>] : !spirv.array<2 x vector<3xi32>>207 return208}209 210 211// -----212 213//===----------------------------------------------------------------------===//214// spirv.EntryPoint215//===----------------------------------------------------------------------===//216 217spirv.module Logical GLSL450 {218 spirv.func @do_nothing() -> () "None" {219 spirv.Return220 }221 // CHECK: spirv.EntryPoint "GLCompute" @do_nothing222 spirv.EntryPoint "GLCompute" @do_nothing223}224 225spirv.module Logical GLSL450 {226 spirv.GlobalVariable @var2 : !spirv.ptr<f32, Input>227 spirv.GlobalVariable @var3 : !spirv.ptr<f32, Output>228 spirv.func @do_something(%arg0 : !spirv.ptr<f32, Input>, %arg1 : !spirv.ptr<f32, Output>) -> () "None" {229 %1 = spirv.Load "Input" %arg0 : f32230 spirv.Store "Output" %arg1, %1 : f32231 spirv.Return232 }233 // CHECK: spirv.EntryPoint "GLCompute" @do_something, @var2, @var3234 spirv.EntryPoint "GLCompute" @do_something, @var2, @var3235}236 237// -----238 239spirv.module Logical GLSL450 {240 spirv.func @do_nothing() -> () "None" {241 spirv.Return242 }243 // expected-error @+1 {{invalid kind of attribute specified}}244 spirv.EntryPoint "GLCompute" "do_nothing"245}246 247// -----248 249spirv.module Logical GLSL450 {250 spirv.func @do_nothing() -> () "None" {251 spirv.Return252 }253 // expected-error @+1 {{function 'do_something' not found in 'spirv.module'}}254 spirv.EntryPoint "GLCompute" @do_something255}256 257/// TODO: Add a test that verifies an error is thrown258/// when interface entries of EntryPointOp are not259/// spirv.Variables. There is currently no other op that has a spirv.ptr260/// return type261 262// -----263 264spirv.module Logical GLSL450 {265 spirv.func @do_nothing() -> () "None" {266 // expected-error @+1 {{op must appear in a module-like op's block}}267 spirv.EntryPoint "GLCompute" @do_something268 }269}270 271// -----272 273spirv.module Logical GLSL450 {274 spirv.func @do_nothing() -> () "None" {275 spirv.Return276 }277 spirv.EntryPoint "GLCompute" @do_nothing278 // expected-error @+1 {{duplicate of a previous EntryPointOp}}279 spirv.EntryPoint "GLCompute" @do_nothing280}281 282// -----283 284spirv.module Logical GLSL450 {285 spirv.func @do_nothing() -> () "None" {286 spirv.Return287 }288 spirv.EntryPoint "GLCompute" @do_nothing289 // expected-error @+1 {{'spirv.EntryPoint' invalid execution_model attribute specification: "ContractionOff"}}290 spirv.EntryPoint "ContractionOff" @do_nothing291}292 293// -----294 295//===----------------------------------------------------------------------===//296// spirv.ExecutionMode297//===----------------------------------------------------------------------===//298 299spirv.module Logical GLSL450 {300 spirv.func @do_nothing() -> () "None" {301 spirv.Return302 }303 spirv.EntryPoint "GLCompute" @do_nothing304 // CHECK: spirv.ExecutionMode {{@.*}} "ContractionOff"305 spirv.ExecutionMode @do_nothing "ContractionOff"306}307 308spirv.module Logical GLSL450 {309 spirv.func @do_nothing() -> () "None" {310 spirv.Return311 }312 spirv.EntryPoint "GLCompute" @do_nothing313 // CHECK: spirv.ExecutionMode {{@.*}} "LocalSizeHint", 3, 4, 5314 spirv.ExecutionMode @do_nothing "LocalSizeHint", 3, 4, 5315}316 317// -----318 319spirv.module Logical GLSL450 {320 spirv.func @do_nothing() -> () "None" {321 spirv.Return322 }323 spirv.EntryPoint "GLCompute" @do_nothing324 // expected-error @+1 {{custom op 'spirv.ExecutionMode' invalid execution_mode attribute specification: "GLCompute"}}325 spirv.ExecutionMode @do_nothing "GLCompute", 3, 4, 5326}327 328// -----329 330//===----------------------------------------------------------------------===//331// spirv.func332//===----------------------------------------------------------------------===//333 334// CHECK: spirv.func @foo() "None"335spirv.func @foo() "None"336 337// CHECK: spirv.func @bar(%{{.+}}: i32) -> i32 "Inline|Pure" {338spirv.func @bar(%arg: i32) -> (i32) "Inline|Pure" {339 // CHECK-NEXT: spirv.340 spirv.ReturnValue %arg: i32341// CHECK-NEXT: }342}343 344// CHECK: spirv.func @baz(%{{.+}}: i32) "DontInline" attributes {additional_stuff = 64 : i64}345spirv.func @baz(%arg: i32) "DontInline" attributes {346 additional_stuff = 64347} { spirv.Return }348 349// -----350 351spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader, Linkage], []> {352 // CHECK: linkage_attributes = #spirv.linkage_attributes<linkage_name = "outside.func", linkage_type = <Import>>353 spirv.func @outside.func.with.linkage(%arg0 : i8) -> () "Pure" attributes {354 linkage_attributes=#spirv.linkage_attributes<355 linkage_name="outside.func",356 linkage_type=<Import>357 >358 }359 spirv.func @inside.func() -> () "Pure" attributes {} {spirv.Return}360}361// -----362 363spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader, Linkage], []> { 364 // expected-error @+1 {{'spirv.module' cannot contain external functions without 'Import' linkage_attributes (LinkageAttributes)}}365 spirv.func @outside.func.without.linkage(%arg0 : i8) -> () "Pure"366 spirv.func @inside.func() -> () "Pure" attributes {} {spirv.Return}367}368 369// -----370 371// expected-error @+1 {{expected function_control attribute specified as string}}372spirv.func @missing_function_control() { spirv.Return }373 374// -----375 376// expected-error @+1 {{cannot have more than one result}}377spirv.func @cannot_have_more_than_one_result(%arg: i32) -> (i32, i32) "None"378 379// -----380 381// expected-error @+1 {{expected SSA identifier}}382spirv.func @cannot_have_variadic_arguments(%arg: i32, ...) "None"383 384// -----385 386// Nested function387spirv.module Logical GLSL450 {388 spirv.func @outer_func() -> () "None" {389 // expected-error @+1 {{must appear in a module-like op's block}}390 spirv.func @inner_func() -> () "None" {391 spirv.Return392 }393 spirv.Return394 }395}396 397// -----398 399//===----------------------------------------------------------------------===//400// spirv.GlobalVariable401//===----------------------------------------------------------------------===//402 403spirv.module Logical GLSL450 {404 // CHECK: spirv.GlobalVariable @var0 : !spirv.ptr<f32, Input>405 spirv.GlobalVariable @var0 : !spirv.ptr<f32, Input>406}407 408// TODO: Fix test case after initialization with normal constant is addressed409// spirv.module Logical GLSL450 {410// %0 = spirv.Constant 4.0 : f32411// COM: CHECK: spirv.Variable init(%0) : !spirv.ptr<f32, Private>412// spirv.GlobalVariable @var1 init(%0) : !spirv.ptr<f32, Private>413// }414 415// -----416 417spirv.module Logical GLSL450 {418 spirv.SpecConstant @sc = 4.0 : f32419 // CHECK: spirv.GlobalVariable @var initializer(@sc) : !spirv.ptr<f32, Private>420 spirv.GlobalVariable @var initializer(@sc) : !spirv.ptr<f32, Private>421}422 423// -----424 425// Allow initializers coming from other module-like ops426spirv.SpecConstant @sc = 4.0 : f32427// CHECK: spirv.GlobalVariable @var initializer(@sc)428spirv.GlobalVariable @var initializer(@sc) : !spirv.ptr<f32, Private>429 430 431// -----432// Allow SpecConstantComposite as initializer433 spirv.module Logical GLSL450 {434 spirv.SpecConstant @sc1 = 1 : i8435 spirv.SpecConstant @sc2 = 2 : i8436 spirv.SpecConstant @sc3 = 3 : i8437 spirv.SpecConstantComposite @scc (@sc1, @sc2, @sc3) : !spirv.array<3 x i8>438 439 // CHECK: spirv.GlobalVariable @var initializer(@scc) : !spirv.ptr<!spirv.array<3 x i8>, Private>440 spirv.GlobalVariable @var initializer(@scc) : !spirv.ptr<!spirv.array<3 x i8>, Private>441}442 443// -----444 445spirv.module Logical GLSL450 {446 // CHECK: spirv.GlobalVariable @var0 bind(1, 2) : !spirv.ptr<f32, Uniform>447 spirv.GlobalVariable @var0 bind(1, 2) : !spirv.ptr<f32, Uniform>448}449 450// TODO: Fix test case after initialization with constant is addressed451// spirv.module Logical GLSL450 {452// %0 = spirv.Constant 4.0 : f32453// COM: CHECK: spirv.GlobalVariable @var1 initializer(%0) {binding = 5 : i32} : !spirv.ptr<f32, Private>454// spirv.GlobalVariable @var1 initializer(%0) {binding = 5 : i32} : !spirv.ptr<f32, Private>455// }456 457// -----458 459spirv.module Logical GLSL450 {460 // CHECK: spirv.GlobalVariable @var1 built_in("GlobalInvocationID") : !spirv.ptr<vector<3xi32>, Input>461 spirv.GlobalVariable @var1 built_in("GlobalInvocationID") : !spirv.ptr<vector<3xi32>, Input>462 // CHECK: spirv.GlobalVariable @var2 built_in("GlobalInvocationID") : !spirv.ptr<vector<3xi32>, Input>463 spirv.GlobalVariable @var2 {built_in = "GlobalInvocationID"} : !spirv.ptr<vector<3xi32>, Input>464}465 466// -----467 468// Allow in other module-like ops469module {470 // CHECK: spirv.GlobalVariable471 spirv.GlobalVariable @var0 : !spirv.ptr<f32, Input>472}473 474// -----475 476spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader, Linkage], []> {477 // CHECK: linkage_attributes = #spirv.linkage_attributes<linkage_name = "outSideGlobalVar1", linkage_type = <Import>>478 spirv.GlobalVariable @var1 {479 linkage_attributes=#spirv.linkage_attributes<480 linkage_name="outSideGlobalVar1", 481 linkage_type=<Import>482 >483 } : !spirv.ptr<f32, Private>484}485 486 487// -----488 489spirv.module Logical GLSL450 {490 // expected-error @+1 {{expected spirv.ptr type}}491 spirv.GlobalVariable @var0 : f32492}493 494// -----495 496spirv.module Logical GLSL450 {497 // expected-error @+1 {{result must be of a !spv.ptr type}}498 "spirv.GlobalVariable"() {sym_name = "var0", type = none} : () -> ()499}500 501// -----502 503spirv.module Logical GLSL450 {504 // expected-error @+1 {{op initializer must be result of a spirv.SpecConstant or spirv.SpecConstantCompositeOp op}}505 spirv.GlobalVariable @var0 initializer(@var1) : !spirv.ptr<f32, Private>506}507 508// -----509 510spirv.module Logical GLSL450 {511 // expected-error @+1 {{storage class cannot be 'Generic'}}512 spirv.GlobalVariable @var0 : !spirv.ptr<f32, Generic>513}514 515// -----516 517spirv.module Logical GLSL450 {518 // expected-error @+1 {{storage class cannot be 'Function'}}519 spirv.GlobalVariable @var0 : !spirv.ptr<f32, Function>520}521 522// -----523 524spirv.module Logical GLSL450 {525 spirv.func @foo() "None" {526 // expected-error @+1 {{op must appear in a module-like op's block}}527 spirv.GlobalVariable @var0 : !spirv.ptr<f32, Input>528 spirv.Return529 }530}531 532// -----533 534//===----------------------------------------------------------------------===//535// spirv.module536//===----------------------------------------------------------------------===//537 538// Module without capability and extension539// CHECK: spirv.module Logical GLSL450540spirv.module Logical GLSL450 { }541 542// Module with a name543// CHECK: spirv.module @{{.*}} Logical GLSL450544spirv.module @name Logical GLSL450 { }545 546// Module with (version, capabilities, extensions) triple547// CHECK: spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], [SPV_KHR_16bit_storage]>548spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], [SPV_KHR_16bit_storage]> { }549 550// Module with additional attributes551// CHECK: spirv.module Logical GLSL450 attributes {foo = "bar"}552spirv.module Logical GLSL450 attributes {foo = "bar"} { }553 554// Module with VCE triple and additional attributes555// CHECK: spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], [SPV_KHR_16bit_storage]> attributes {foo = "bar"}556spirv.module Logical GLSL450557 requires #spirv.vce<v1.0, [Shader], [SPV_KHR_16bit_storage]>558 attributes {foo = "bar"} { }559 560// Module with function561// CHECK: spirv.module562spirv.module Logical GLSL450 {563 spirv.func @do_nothing() -> () "None" {564 spirv.Return565 }566}567 568// -----569 570// Missing addressing model571// expected-error@+1 {{'spirv.module' expected valid keyword}}572spirv.module { }573 574// -----575 576// Wrong addressing model577// expected-error@+1 {{'spirv.module' invalid addressing_model attribute specification: Physical}}578spirv.module Physical { }579 580// -----581 582// Missing memory model583// expected-error@+1 {{'spirv.module' expected valid keyword}}584spirv.module Logical { }585 586// -----587 588// Wrong memory model589// expected-error@+1 {{'spirv.module' invalid memory_model attribute specification: Bla}}590spirv.module Logical Bla { }591 592// -----593 594// Module with multiple blocks595// expected-error @+1 {{expects region #0 to have 0 or 1 blocks}}596spirv.module Logical GLSL450 {597^first:598 spirv.Return599^second:600 spirv.Return601}602 603// -----604 605// Use non SPIR-V op inside module606spirv.module Logical GLSL450 {607 // expected-error @+1 {{'spirv.module' can only contain spirv.* ops}}608 "dialect.op"() : () -> ()609}610 611// -----612 613// Use non SPIR-V op inside function614spirv.module Logical GLSL450 {615 spirv.func @do_nothing() -> () "None" {616 // expected-error @+1 {{functions in 'spirv.module' can only contain spirv.* ops}}617 "dialect.op"() : () -> ()618 }619}620 621// -----622 623// Use external function624spirv.module Logical GLSL450 {625 // expected-error @+1 {{'spirv.module' cannot contain external functions}}626 spirv.func @extern() -> () "None"627}628 629// -----630 631//===----------------------------------------------------------------------===//632// spirv.mlir.referenceof633//===----------------------------------------------------------------------===//634 635spirv.module Logical GLSL450 {636 spirv.SpecConstant @sc1 = false637 spirv.SpecConstant @sc2 = 42 : i64638 spirv.SpecConstant @sc3 = 1.5 : f32639 640 spirv.SpecConstantComposite @scc (@sc1, @sc2, @sc3) : !spirv.struct<(i1, i64, f32)>641 642 // CHECK-LABEL: @reference643 spirv.func @reference() -> i1 "None" {644 // CHECK: spirv.mlir.referenceof @sc1 : i1645 %0 = spirv.mlir.referenceof @sc1 : i1646 spirv.ReturnValue %0 : i1647 }648 649 // CHECK-LABEL: @reference_composite650 spirv.func @reference_composite() -> i1 "None" {651 // CHECK: spirv.mlir.referenceof @scc : !spirv.struct<(i1, i64, f32)>652 %0 = spirv.mlir.referenceof @scc : !spirv.struct<(i1, i64, f32)>653 %1 = spirv.CompositeExtract %0[0 : i32] : !spirv.struct<(i1, i64, f32)>654 spirv.ReturnValue %1 : i1655 }656 657 // CHECK-LABEL: @initialize658 spirv.func @initialize() -> i64 "None" {659 // CHECK: spirv.mlir.referenceof @sc2 : i64660 %0 = spirv.mlir.referenceof @sc2 : i64661 %1 = spirv.Variable init(%0) : !spirv.ptr<i64, Function>662 %2 = spirv.Load "Function" %1 : i64663 spirv.ReturnValue %2 : i64664 }665 666 // CHECK-LABEL: @compute667 spirv.func @compute() -> f32 "None" {668 // CHECK: spirv.mlir.referenceof @sc3 : f32669 %0 = spirv.mlir.referenceof @sc3 : f32670 %1 = spirv.Constant 6.0 : f32671 %2 = spirv.FAdd %0, %1 : f32672 spirv.ReturnValue %2 : f32673 }674}675 676// -----677 678// Allow taking reference of spec constant in other module-like ops679spirv.SpecConstant @sc = 5 : i32680func.func @reference_of() {681 // CHECK: spirv.mlir.referenceof @sc682 %0 = spirv.mlir.referenceof @sc : i32683 return684}685 686// -----687 688spirv.SpecConstant @sc = 5 : i32689spirv.SpecConstantComposite @scc (@sc) : !spirv.array<1 x i32>690 691func.func @reference_of_composite() {692 // CHECK: spirv.mlir.referenceof @scc : !spirv.array<1 x i32>693 %0 = spirv.mlir.referenceof @scc : !spirv.array<1 x i32>694 %1 = spirv.CompositeExtract %0[0 : i32] : !spirv.array<1 x i32>695 return696}697 698// -----699 700spirv.module Logical GLSL450 {701 spirv.func @foo() -> () "None" {702 // expected-error @+1 {{expected spirv.SpecConstant or spirv.SpecConstantComposite symbol}}703 %0 = spirv.mlir.referenceof @sc : i32704 spirv.Return705 }706}707 708// -----709 710spirv.module Logical GLSL450 {711 spirv.SpecConstant @sc = 42 : i32712 spirv.func @foo() -> () "None" {713 // expected-error @+1 {{result type mismatch with the referenced specialization constant's type}}714 %0 = spirv.mlir.referenceof @sc : f32715 spirv.Return716 }717}718 719// -----720 721spirv.module Logical GLSL450 {722 spirv.SpecConstant @sc = 42 : i32723 spirv.SpecConstantComposite @scc (@sc) : !spirv.array<1 x i32>724 spirv.func @foo() -> () "None" {725 // expected-error @+1 {{result type mismatch with the referenced specialization constant's type}}726 %0 = spirv.mlir.referenceof @scc : f32727 spirv.Return728 }729}730 731// -----732 733//===----------------------------------------------------------------------===//734// spirv.SpecConstant735//===----------------------------------------------------------------------===//736 737spirv.module Logical GLSL450 {738 // CHECK: spirv.SpecConstant @sc1 = false739 spirv.SpecConstant @sc1 = false740 // CHECK: spirv.SpecConstant @sc2 spec_id(5) = 42 : i64741 spirv.SpecConstant @sc2 spec_id(5) = 42 : i64742 // CHECK: spirv.SpecConstant @sc3 = 1.500000e+00 : f32743 spirv.SpecConstant @sc3 = 1.5 : f32744}745 746// -----747 748spirv.module Logical GLSL450 {749 // expected-error @+1 {{SpecId cannot be negative}}750 spirv.SpecConstant @sc2 spec_id(-5) = 42 : i64751}752 753// -----754 755spirv.module Logical GLSL450 {756 // expected-error @+1 {{default value bitwidth disallowed}}757 spirv.SpecConstant @sc = 15 : i4758}759 760// -----761 762spirv.module Logical GLSL450 {763 // expected-error @+1 {{default value can only be a bool, integer, or float scalar}}764 spirv.SpecConstant @sc = dense<[2, 3]> : vector<2xi32>765}766 767// -----768 769func.func @use_in_function() -> () {770 // expected-error @+1 {{op must appear in a module-like op's block}}771 spirv.SpecConstant @sc = false772 return773}774 775// -----776 777//===----------------------------------------------------------------------===//778// spirv.SpecConstantComposite779//===----------------------------------------------------------------------===//780 781spirv.module Logical GLSL450 {782 // expected-error @+1 {{result type must be a composite type}}783 spirv.SpecConstantComposite @scc2 (@sc1, @sc2, @sc3) : i32784}785 786//===----------------------------------------------------------------------===//787// spirv.SpecConstantComposite (spirv.array)788//===----------------------------------------------------------------------===//789 790// -----791 792spirv.module Logical GLSL450 {793 spirv.SpecConstant @sc1 = 1.5 : f32794 spirv.SpecConstant @sc2 = 2.5 : f32795 spirv.SpecConstant @sc3 = 3.5 : f32796 // CHECK: spirv.SpecConstantComposite @scc (@sc1, @sc2, @sc3) : !spirv.array<3 x f32>797 spirv.SpecConstantComposite @scc (@sc1, @sc2, @sc3) : !spirv.array<3 x f32>798}799 800// -----801 802spirv.module Logical GLSL450 {803 spirv.SpecConstant @sc1 = false804 spirv.SpecConstant @sc2 spec_id(5) = 42 : i64805 spirv.SpecConstant @sc3 = 1.5 : f32806 // expected-error @+1 {{has incorrect number of operands: expected 4, but provided 3}}807 spirv.SpecConstantComposite @scc (@sc1, @sc2, @sc3) : !spirv.array<4 x f32>808 809}810 811// -----812 813spirv.module Logical GLSL450 {814 spirv.SpecConstant @sc1 = 1 : i32815 spirv.SpecConstant @sc2 = 2.5 : f32816 spirv.SpecConstant @sc3 = 3.5 : f32817 // expected-error @+1 {{has incorrect types of operands: expected 'f32', but provided 'i32'}}818 spirv.SpecConstantComposite @scc (@sc1, @sc2, @sc3) : !spirv.array<3 x f32>819}820 821//===----------------------------------------------------------------------===//822// spirv.SpecConstantComposite (spirv.struct)823//===----------------------------------------------------------------------===//824 825// -----826 827spirv.module Logical GLSL450 {828 spirv.SpecConstant @sc1 = 1 : i32829 spirv.SpecConstant @sc2 = 2.5 : f32830 spirv.SpecConstant @sc3 = 3.5 : f32831 // CHECK: spirv.SpecConstantComposite @scc (@sc1, @sc2, @sc3) : !spirv.struct<(i32, f32, f32)>832 spirv.SpecConstantComposite @scc (@sc1, @sc2, @sc3) : !spirv.struct<(i32, f32, f32)>833}834 835// -----836 837spirv.module Logical GLSL450 {838 spirv.SpecConstant @sc1 = 1 : i32839 spirv.SpecConstant @sc2 = 2.5 : f32840 spirv.SpecConstant @sc3 = 3.5 : f32841 // expected-error @+1 {{has incorrect number of operands: expected 2, but provided 3}}842 spirv.SpecConstantComposite @scc (@sc1, @sc2, @sc3) : !spirv.struct<(i32, f32)>843}844 845// -----846 847spirv.module Logical GLSL450 {848 spirv.SpecConstant @sc1 = 1.5 : f32849 spirv.SpecConstant @sc2 = 2.5 : f32850 spirv.SpecConstant @sc3 = 3.5 : f32851 // expected-error @+1 {{has incorrect types of operands: expected 'i32', but provided 'f32'}}852 spirv.SpecConstantComposite @scc (@sc1, @sc2, @sc3) : !spirv.struct<(i32, f32, f32)>853}854 855//===----------------------------------------------------------------------===//856// spirv.SpecConstantComposite (vector)857//===----------------------------------------------------------------------===//858 859// -----860 861spirv.module Logical GLSL450 {862 spirv.SpecConstant @sc1 = 1.5 : f32863 spirv.SpecConstant @sc2 = 2.5 : f32864 spirv.SpecConstant @sc3 = 3.5 : f32865 // CHECK: spirv.SpecConstantComposite @scc (@sc1, @sc2, @sc3) : vector<3xf32>866 spirv.SpecConstantComposite @scc (@sc1, @sc2, @sc3) : vector<3 x f32>867}868 869// -----870 871spirv.module Logical GLSL450 {872 spirv.SpecConstant @sc1 = false873 spirv.SpecConstant @sc2 spec_id(5) = 42 : i64874 spirv.SpecConstant @sc3 = 1.5 : f32875 // expected-error @+1 {{has incorrect number of operands: expected 4, but provided 3}}876 spirv.SpecConstantComposite @scc (@sc1, @sc2, @sc3) : vector<4xf32>877 878}879 880// -----881 882spirv.module Logical GLSL450 {883 spirv.SpecConstant @sc1 = 1 : i32884 spirv.SpecConstant @sc2 = 2.5 : f32885 spirv.SpecConstant @sc3 = 3.5 : f32886 // expected-error @+1 {{has incorrect types of operands: expected 'f32', but provided 'i32'}}887 spirv.SpecConstantComposite @scc (@sc1, @sc2, @sc3) : vector<3xf32>888}889 890//===----------------------------------------------------------------------===//891// spirv.SpecConstantComposite (spirv.KHR.coopmatrix)892//===----------------------------------------------------------------------===//893 894// -----895 896spirv.module Logical GLSL450 {897 spirv.SpecConstant @sc1 = 1.5 : f32898 // expected-error @+1 {{unsupported composite type}}899 spirv.SpecConstantComposite @scc (@sc1) : !spirv.coopmatrix<8x16xf32, Device, MatrixA>900}901 902//===----------------------------------------------------------------------===//903// spirv.EXT.SpecConstantCompositeReplicate904//===----------------------------------------------------------------------===//905 906// -----907 908spirv.module Logical GLSL450 {909 // expected-error @+1 {{result type must be a composite type, but provided 'i32'}}910 spirv.EXT.SpecConstantCompositeReplicate @sccr (@sc_i32_1) : i32911}912 913// -----914 915spirv.module Logical GLSL450 {916 // expected-error @+1 {{splat spec constant reference defining constituent not found}}917 spirv.EXT.SpecConstantCompositeReplicate @sccr (@sc_f32_1) : !spirv.array<3 x i32>918}919 920// -----921 922spirv.module Logical GLSL450 {923 spirv.SpecConstant @sc_f32_1 = 1.0 : f32924 // expected-error @+1 {{constituent has incorrect type: expected 'i32', but provided 'f32'}}925 spirv.EXT.SpecConstantCompositeReplicate @sccr (@sc_f32_1) : !spirv.array<3 x i32>926}927 928// -----929 930spirv.module Logical GLSL450 {931 spirv.SpecConstant @sc_f32_1 = 1.0 : f32932 // expected-error @+1 {{constituent has incorrect type: expected 'i32', but provided 'f32'}}933 spirv.EXT.SpecConstantCompositeReplicate @sccr (@sc_f32_1) : !spirv.struct<(i32, i32, i32)>934}935 936// -----937 938spirv.module Logical GLSL450 {939 spirv.SpecConstant @sc_f32_1 = 1.0 : f32940 // expected-error @+1 {{constituent has incorrect type: expected 'i32', but provided 'f32'}}941 spirv.EXT.SpecConstantCompositeReplicate @sccr (@sc_f32_1) : !spirv.arm.tensor<2x3xi32>942}943 944//===----------------------------------------------------------------------===//945// spirv.SpecConstantOperation946//===----------------------------------------------------------------------===//947 948// -----949 950spirv.module Logical GLSL450 {951 spirv.func @foo() -> i32 "None" {952 // CHECK: [[LHS:%.*]] = spirv.Constant953 %0 = spirv.Constant 1: i32954 // CHECK: [[RHS:%.*]] = spirv.Constant955 %1 = spirv.Constant 1: i32956 957 // CHECK: spirv.SpecConstantOperation wraps "spirv.IAdd"([[LHS]], [[RHS]]) : (i32, i32) -> i32958 %2 = spirv.SpecConstantOperation wraps "spirv.IAdd"(%0, %1) : (i32, i32) -> i32959 960 spirv.ReturnValue %2 : i32961 }962}963 964// -----965 966spirv.module Logical GLSL450 {967 spirv.SpecConstant @sc = 42 : i32968 969 spirv.func @foo() -> i32 "None" {970 // CHECK: [[SC:%.*]] = spirv.mlir.referenceof @sc971 %0 = spirv.mlir.referenceof @sc : i32972 // CHECK: spirv.SpecConstantOperation wraps "spirv.ISub"([[SC]], [[SC]]) : (i32, i32) -> i32973 %1 = spirv.SpecConstantOperation wraps "spirv.ISub"(%0, %0) : (i32, i32) -> i32974 spirv.ReturnValue %1 : i32975 }976}977 978// -----979 980spirv.module Logical GLSL450 {981 spirv.func @foo() -> i32 "None" {982 %0 = spirv.Constant 1: i32983 // expected-error @+1 {{op expects parent op 'spirv.SpecConstantOperation'}}984 spirv.mlir.yield %0 : i32985 }986}987 988// -----989 990spirv.module Logical GLSL450 {991 spirv.func @foo() -> () "None" {992 %0 = spirv.Variable : !spirv.ptr<i32, Function>993 994 // expected-error @+1 {{invalid enclosed op}}995 %1 = spirv.SpecConstantOperation wraps "spirv.Load"(%0) {memory_access = #spirv.memory_access<None>} : (!spirv.ptr<i32, Function>) -> i32996 spirv.Return997 }998}999 1000// -----1001 1002spirv.module Logical GLSL450 {1003 spirv.func @foo() -> () "None" {1004 %0 = spirv.Variable : !spirv.ptr<i32, Function>1005 %1 = spirv.Load "Function" %0 : i321006 1007 // expected-error @+1 {{invalid operand, must be defined by a constant operation}}1008 %2 = spirv.SpecConstantOperation wraps "spirv.IAdd"(%1, %1) : (i32, i32) -> i321009 1010 spirv.Return1011 }1012}1013