14 changes: 7 additions & 7 deletions mlir/test/Dialect/SPIRV/ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func @u_convert_scalar(%arg0 : i32) -> i64 {
//===----------------------------------------------------------------------===//

spv.module "Logical" "GLSL450" {
func @do_nothing() -> () {
spv.func @do_nothing() -> () "None" {
spv.Return
}
spv.EntryPoint "GLCompute" @do_nothing
Expand All @@ -426,7 +426,7 @@ spv.module "Logical" "GLSL450" {
}

spv.module "Logical" "GLSL450" {
func @do_nothing() -> () {
spv.func @do_nothing() -> () "None" {
spv.Return
}
spv.EntryPoint "GLCompute" @do_nothing
Expand All @@ -437,7 +437,7 @@ spv.module "Logical" "GLSL450" {
// -----

spv.module "Logical" "GLSL450" {
func @do_nothing() -> () {
spv.func @do_nothing() -> () "None" {
spv.Return
}
spv.EntryPoint "GLCompute" @do_nothing
Expand Down Expand Up @@ -642,7 +642,7 @@ func @aligned_load_incorrect_attributes() -> () {
spv.module "Logical" "GLSL450" {
spv.globalVariable @var0 : !spv.ptr<f32, Input>
// CHECK_LABEL: @simple_load
func @simple_load() -> () {
spv.func @simple_load() -> () "None" {
// CHECK: spv.Load "Input" {{%.*}} : f32
%0 = spv._address_of @var0 : !spv.ptr<f32, Input>
%1 = spv.Load "Input" %0 : f32
Expand Down Expand Up @@ -1059,7 +1059,7 @@ func @aligned_store_incorrect_attributes(%arg0 : f32) -> () {

spv.module "Logical" "GLSL450" {
spv.globalVariable @var0 : !spv.ptr<f32, Input>
func @simple_store(%arg0 : f32) -> () {
spv.func @simple_store(%arg0 : f32) -> () "None" {
%0 = spv._address_of @var0 : !spv.ptr<f32, Input>
// CHECK: spv.Store "Input" {{%.*}}, {{%.*}} : f32
spv.Store "Input" %0, %arg0 : f32
Expand Down Expand Up @@ -1132,7 +1132,7 @@ func @variable_init_normal_constant() -> () {

spv.module "Logical" "GLSL450" {
spv.globalVariable @global : !spv.ptr<f32, Workgroup>
func @variable_init_global_variable() -> () {
spv.func @variable_init_global_variable() -> () "None" {
%0 = spv._address_of @global : !spv.ptr<f32, Workgroup>
// CHECK: spv.Variable init({{.*}}) : !spv.ptr<!spv.ptr<f32, Workgroup>, Function>
%1 = spv.Variable init(%0) : !spv.ptr<!spv.ptr<f32, Workgroup>, Function>
Expand All @@ -1148,7 +1148,7 @@ spv.module "Logical" "GLSL450" {
spv.module "Logical" "GLSL450" {
spv.specConstant @sc = 42 : i32
// CHECK-LABEL: @variable_init_spec_constant
func @variable_init_spec_constant() -> () {
spv.func @variable_init_spec_constant() -> () "None" {
%0 = spv._reference_of @sc : i32
// CHECK: spv.Variable init(%0) : !spv.ptr<i32, Function>
%1 = spv.Variable init(%0) : !spv.ptr<i32, Function>
Expand Down
104 changes: 70 additions & 34 deletions mlir/test/Dialect/SPIRV/structure-ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

spv.module "Logical" "GLSL450" {
spv.globalVariable @var1 : !spv.ptr<!spv.struct<f32, !spv.array<4xf32>>, Input>
func @access_chain() -> () {
spv.func @access_chain() -> () "None" {
%0 = spv.constant 1: i32
// CHECK: [[VAR1:%.*]] = spv._address_of @var1 : !spv.ptr<!spv.struct<f32, !spv.array<4 x f32>>, Input>
// CHECK-NEXT: spv.AccessChain [[VAR1]][{{.*}}, {{.*}}] : !spv.ptr<!spv.struct<f32, !spv.array<4 x f32>>, Input>
Expand All @@ -30,7 +30,7 @@ func @address_of() -> () {

spv.module "Logical" "GLSL450" {
spv.globalVariable @var1 : !spv.ptr<!spv.struct<f32, !spv.array<4xf32>>, Input>
func @foo() -> () {
spv.func @foo() -> () "None" {
// expected-error @+1 {{expected spv.globalVariable symbol}}
%0 = spv._address_of @var2 : !spv.ptr<!spv.struct<f32, !spv.array<4xf32>>, Input>
}
Expand All @@ -40,7 +40,7 @@ spv.module "Logical" "GLSL450" {

spv.module "Logical" "GLSL450" {
spv.globalVariable @var1 : !spv.ptr<!spv.struct<f32, !spv.array<4xf32>>, Input>
func @foo() -> () {
spv.func @foo() -> () "None" {
// expected-error @+1 {{result type mismatch with the referenced global variable's type}}
%0 = spv._address_of @var1 : !spv.ptr<f32, Input>
}
Expand Down Expand Up @@ -136,7 +136,7 @@ func @value_result_num_elements_mismatch() -> () {
//===----------------------------------------------------------------------===//

spv.module "Logical" "GLSL450" {
func @do_nothing() -> () {
spv.func @do_nothing() -> () "None" {
spv.Return
}
// CHECK: spv.EntryPoint "GLCompute" @do_nothing
Expand All @@ -146,7 +146,7 @@ spv.module "Logical" "GLSL450" {
spv.module "Logical" "GLSL450" {
spv.globalVariable @var2 : !spv.ptr<f32, Input>
spv.globalVariable @var3 : !spv.ptr<f32, Output>
func @do_something(%arg0 : !spv.ptr<f32, Input>, %arg1 : !spv.ptr<f32, Output>) -> () {
spv.func @do_something(%arg0 : !spv.ptr<f32, Input>, %arg1 : !spv.ptr<f32, Output>) -> () "None" {
%1 = spv.Load "Input" %arg0 : f32
spv.Store "Output" %arg1, %1 : f32
spv.Return
Expand All @@ -158,7 +158,7 @@ spv.module "Logical" "GLSL450" {
// -----

spv.module "Logical" "GLSL450" {
func @do_nothing() -> () {
spv.func @do_nothing() -> () "None" {
spv.Return
}
// expected-error @+1 {{invalid kind of attribute specified}}
Expand All @@ -168,7 +168,7 @@ spv.module "Logical" "GLSL450" {
// -----

spv.module "Logical" "GLSL450" {
func @do_nothing() -> () {
spv.func @do_nothing() -> () "None" {
spv.Return
}
// expected-error @+1 {{function 'do_something' not found in 'spv.module'}}
Expand All @@ -183,7 +183,7 @@ spv.module "Logical" "GLSL450" {
// -----

spv.module "Logical" "GLSL450" {
func @do_nothing() -> () {
spv.func @do_nothing() -> () "None" {
// expected-error @+1 {{op must appear in a module-like op's block}}
spv.EntryPoint "GLCompute" @do_something
}
Expand All @@ -192,7 +192,7 @@ spv.module "Logical" "GLSL450" {
// -----

spv.module "Logical" "GLSL450" {
func @do_nothing() -> () {
spv.func @do_nothing() -> () "None" {
spv.Return
}
spv.EntryPoint "GLCompute" @do_nothing
Expand All @@ -203,7 +203,7 @@ spv.module "Logical" "GLSL450" {
// -----

spv.module "Logical" "GLSL450" {
func @do_nothing() -> () {
spv.func @do_nothing() -> () "None" {
spv.Return
}
spv.EntryPoint "GLCompute" @do_nothing
Expand All @@ -213,6 +213,55 @@ spv.module "Logical" "GLSL450" {

// -----

//===----------------------------------------------------------------------===//
// spv.func
//===----------------------------------------------------------------------===//

// CHECK: spv.func @foo() "None"
spv.func @foo() "None"

// CHECK: spv.func @bar(%{{.+}}: i32) -> i32 "Inline|Pure" {
spv.func @bar(%arg: i32) -> (i32) "Inline|Pure" {
// CHECK-NEXT: spv.
spv.ReturnValue %arg: i32
// CHECK-NEXT: }
}

// CHECK: spv.func @baz(%{{.+}}: i32) "DontInline" attributes {additional_stuff = 64 : i64}
spv.func @baz(%arg: i32) "DontInline" attributes {
additional_stuff = 64
} { spv.Return }

// -----

// expected-error @+1 {{expected function_control attribute specified as string}}
spv.func @missing_function_control() { spv.Return }

// -----

// expected-error @+1 {{cannot have more than one result}}
spv.func @cannot_have_more_than_one_result(%arg: i32) -> (i32, i32) "None"

// -----

// expected-error @+1 {{expected SSA identifier}}
spv.func @cannot_have_variadic_arguments(%arg: i32, ...) "None"

// -----

// Nested function
spv.module "Logical" "GLSL450" {
spv.func @outer_func() -> () "None" {
// expected-error @+1 {{must appear in a module-like op's block}}
spv.func @inner_func() -> () "None" {
spv.Return
}
spv.Return
}
}

// -----

//===----------------------------------------------------------------------===//
// spv.globalVariable
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -299,7 +348,7 @@ spv.module "Logical" "GLSL450" {
// -----

spv.module "Logical" "GLSL450" {
func @foo() {
spv.func @foo() "None" {
// expected-error @+1 {{op must appear in a module-like op's block}}
spv.globalVariable @var0 : !spv.ptr<f32, Input>
spv.Return
Expand Down Expand Up @@ -332,7 +381,7 @@ spv.module "Logical" "GLSL450" {
// Module with function
// CHECK: spv.module
spv.module "Logical" "GLSL450" {
func @do_nothing() -> () {
spv.func @do_nothing() -> () "None" {
spv.Return
}
}
Expand Down Expand Up @@ -383,17 +432,17 @@ spv.module "Logical" "GLSL450" {

// -----

// Use non SPIR-V op inside.module
// Use non SPIR-V op inside module
spv.module "Logical" "GLSL450" {
// expected-error @+1 {{'spv.module' can only contain func and spv.* ops}}
// expected-error @+1 {{'spv.module' can only contain spv.* ops}}
"dialect.op"() : () -> ()
}

// -----

// Use non SPIR-V op inside function
spv.module "Logical" "GLSL450" {
func @do_nothing() -> () {
spv.func @do_nothing() -> () "None" {
// expected-error @+1 {{functions in 'spv.module' can only contain spv.* ops}}
"dialect.op"() : () -> ()
}
Expand All @@ -404,20 +453,7 @@ spv.module "Logical" "GLSL450" {
// Use external function
spv.module "Logical" "GLSL450" {
// expected-error @+1 {{'spv.module' cannot contain external functions}}
func @extern() -> ()
}

// -----

// Module with nested function
spv.module "Logical" "GLSL450" {
func @outer_func() -> () {
// expected-error @+1 {{'spv.module' cannot contain nested functions}}
func @inner_func() -> () {
spv.Return
}
spv.Return
}
spv.func @extern() -> () "None"
}

// -----
Expand Down Expand Up @@ -459,14 +495,14 @@ spv.module "Logical" "GLSL450" {
spv.specConstant @sc3 = 1.5 : f32

// CHECK-LABEL: @reference
func @reference() -> i1 {
spv.func @reference() -> i1 "None" {
// CHECK: spv._reference_of @sc1 : i1
%0 = spv._reference_of @sc1 : i1
spv.ReturnValue %0 : i1
}

// CHECK-LABEL: @initialize
func @initialize() -> i64 {
spv.func @initialize() -> i64 "None" {
// CHECK: spv._reference_of @sc2 : i64
%0 = spv._reference_of @sc2 : i64
%1 = spv.Variable init(%0) : !spv.ptr<i64, Function>
Expand All @@ -475,7 +511,7 @@ spv.module "Logical" "GLSL450" {
}

// CHECK-LABEL: @compute
func @compute() -> f32 {
spv.func @compute() -> f32 "None" {
// CHECK: spv._reference_of @sc3 : f32
%0 = spv._reference_of @sc3 : f32
%1 = spv.constant 6.0 : f32
Expand All @@ -497,7 +533,7 @@ func @reference_of() {
// -----

spv.module "Logical" "GLSL450" {
func @foo() -> () {
spv.func @foo() -> () "None" {
// expected-error @+1 {{expected spv.specConstant symbol}}
%0 = spv._reference_of @sc : i32
spv.Return
Expand All @@ -508,7 +544,7 @@ spv.module "Logical" "GLSL450" {

spv.module "Logical" "GLSL450" {
spv.specConstant @sc = 42 : i32
func @foo() -> () {
spv.func @foo() -> () "None" {
// expected-error @+1 {{result type mismatch with the referenced specialization constant's type}}
%0 = spv._reference_of @sc : f32
spv.Return
Expand Down