Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dialects: (func) Add custom syntax for func.return #1168

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions tests/dialects/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_func_rewriting_helpers():
"""
func = FuncOp("test", ((i32, i32, i32), ()))
with ImplicitBuilder(func.body):
Return.get()
Return()

func.replace_argument_type(2, i64)
assert func.function_type.inputs.data[2] is i64
Expand Down Expand Up @@ -143,7 +143,7 @@ def test_func_rewriting_helpers():
def test_func_get_return_op():
func_w_ret = FuncOp("test", ((i32, i32, i32), ()))
with ImplicitBuilder(func_w_ret.body) as (a, _, _):
Return.get(a)
Return(a)

func = FuncOp("test", ((i32, i32, i32), ()))

Expand Down Expand Up @@ -171,7 +171,7 @@ def test_call():
# Create a Addi operation to use the args of the block
c = Addi(block0.args[0], block0.args[1])
# Create a return operation and add it in the block
ret0 = Return.get(c)
ret0 = Return(c)
block0.add_ops([c, ret0])
# Create a region with the block
region = Region(block0)
Expand Down Expand Up @@ -219,7 +219,7 @@ def test_call_II():
# Create a Addi operation to use the args of the block
c = Addi(block0.args[0], block0.args[0])
# Create a return operation and add it in the block
ret0 = Return.get(c)
ret0 = Return(c)
block0.add_ops([c, ret0])
# Create a region with the block
region = Region(block0)
Expand Down Expand Up @@ -259,7 +259,7 @@ def test_return():
c = Constant.from_int_and_width(3, i32)

# Use these operations to create a Return operation
ret0 = Return.get(a, b, c)
ret0 = Return(a, b, c)
assert len(ret0.operands) == 3


Expand Down
3 changes: 1 addition & 2 deletions tests/dialects/test_memref.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from xdsl.ir import Attribute, OpResult
from xdsl.dialects.arith import Constant
from xdsl.dialects.builtin import (
NoneAttr,
StridedLayoutAttr,
i32,
i64,
Expand Down Expand Up @@ -221,7 +220,7 @@ def inner_loop(args: tuple[BlockArgument, ...]):

scf.For.get(lit0, dim_a0, lit1, [], outer_loop)

func.Return.get(out)
func.Return(out)

func.FuncOp(
"matmul",
Expand Down
2 changes: 1 addition & 1 deletion tests/filecheck/dialects/affine/examples.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
%res = "arith.addi"(%sum, %val) : (i32, i32) -> i32
"affine.yield"(%res) : (i32) -> ()
}) {"lower_bound" = 0 : index, "upper_bound" = 256 : index, "step" = 1 : index} : (i32) -> i32
"func.return"(%r) : (i32) -> ()
func.return %r : i32
}) {"sym_name" = "sum_vec", "function_type" = (memref<128xi32>) -> i32, "sym_visibility" = "private"} : () -> ()

// CHECK: "func.func"() ({
Expand Down
4 changes: 2 additions & 2 deletions tests/filecheck/dialects/cf/cf_ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"func.func"() ({
%cond = "arith.constant"() {"value" = true} : () -> i1
"cf.assert"(%cond) {"msg" = "some message"} : (i1) -> ()
"func.return"() : () -> ()
func.return
}) {"sym_name" = "assert", "function_type" = () -> (), "sym_visibility" = "private"} : () -> ()
// CHECK: "func.func"() ({
// CHECK-NEXT: %{{.*}} = "arith.constant"() {"value" = true} : () -> i1
// CHECK-NEXT: "cf.assert"(%cond) {"msg" = "some message"} : (i1) -> ()
// CHECK-NEXT: "func.return"() : () -> ()
// CHECK-NEXT: func.return
// CHECK-NEXT: }) {"sym_name" = "assert", "function_type" = () -> (), "sym_visibility" = "private"} : () -> ()

"func.func"() ({
Expand Down
8 changes: 4 additions & 4 deletions tests/filecheck/dialects/cmath/cmath_ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ builtin.module {
%norm_p = "cmath.norm"(%p) : (!cmath.complex<f32>) -> f32
%norm_q = "cmath.norm"(%q) : (!cmath.complex<f32>) -> f32
%pq = "arith.mulf"(%norm_p, %norm_q) : (f32, f32) -> f32
"func.return"(%pq) : (f32) -> ()
func.return %pq : f32
}

// CHECK: func.func @conorm(%p : !cmath.complex<f32>, %q : !cmath.complex<f32>) -> f32 {
// CHECK-NEXT: %norm_p = "cmath.norm"(%p) : (!cmath.complex<f32>) -> f32
// CHECK-NEXT: %norm_q = "cmath.norm"(%q) : (!cmath.complex<f32>) -> f32
// CHECK-NEXT: %pq = arith.mulf %norm_p, %norm_q : f32
// CHECK-NEXT: "func.return"(%pq) : (f32) -> ()
// CHECK-NEXT: func.return %pq : f32
// CHECK-NEXT: }

func.func @conorm2(%a : !cmath.complex<f32>, %b : !cmath.complex<f32>) -> f32 {
%ab = "cmath.mul"(%a, %b) : (!cmath.complex<f32>, !cmath.complex<f32>) -> !cmath.complex<f32>
%conorm = "cmath.norm"(%ab) : (!cmath.complex<f32>) -> f32
"func.return"(%conorm) : (f32) -> ()
func.return %conorm : f32
}

// CHECK: func.func @conorm2(%a : !cmath.complex<f32>, %b : !cmath.complex<f32>) -> f32 {
// CHECK-NEXT: %ab = "cmath.mul"(%a, %b) : (!cmath.complex<f32>, !cmath.complex<f32>) -> !cmath.complex<f32>
// CHECK-NEXT: %conorm = "cmath.norm"(%ab) : (!cmath.complex<f32>) -> f32
// CHECK-NEXT: "func.return"(%conorm) : (f32) -> ()
// CHECK-NEXT: func.return %conorm : f32
// CHECK-NEXT: }
}
20 changes: 10 additions & 10 deletions tests/filecheck/dialects/func/func_ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,53 @@
builtin.module {

func.func @noarg_void() {
"func.return"() : () -> ()
func.return
}

// CHECK: func.func @noarg_void() {
// CHECK-NEXT: "func.return"() : () -> ()
// CHECK-NEXT: func.return
// CHECK-NEXT: }

func.func @call_void() {
"func.call"() {"callee" = @call_void} : () -> ()
"func.return"() : () -> ()
func.return
}

// CHECK: func.func @call_void() {
// CHECK-NEXT: "func.call"() {"callee" = @call_void} : () -> ()
// CHECK-NEXT: "func.return"() : () -> ()
// CHECK-NEXT: func.return
// CHECK-NEXT: }

func.func @arg_rec(%0 : !test.type<"int">) -> !test.type<"int"> {
%1 = "func.call"(%0) {"callee" = @arg_rec} : (!test.type<"int">) -> !test.type<"int">
"func.return"(%1) : (!test.type<"int">) -> ()
func.return %1 : !test.type<"int">
}

// CHECK: func.func @arg_rec(%0 : !test.type<"int">) -> !test.type<"int"> {
// CHECK-NEXT: %{{.*}} = "func.call"(%{{.*}}) {"callee" = @arg_rec} : (!test.type<"int">) -> !test.type<"int">
// CHECK-NEXT: "func.return"(%{{.*}}) : (!test.type<"int">) -> ()
// CHECK-NEXT: func.return %{{.*}} : !test.type<"int">
// CHECK-NEXT: }

func.func @arg_rec_block(!test.type<"int">) -> !test.type<"int"> {
^0(%2 : !test.type<"int">):
%3 = "func.call"(%2) {"callee" = @arg_rec_block} : (!test.type<"int">) -> !test.type<"int">
"func.return"(%3) : (!test.type<"int">) -> ()
func.return %3 : !test.type<"int">
}

// CHECK: func.func @arg_rec_block(%2 : !test.type<"int">) -> !test.type<"int"> {
// CHECK-NEXT: %3 = "func.call"(%2) {"callee" = @arg_rec_block} : (!test.type<"int">) -> !test.type<"int">
// CHECK-NEXT: "func.return"(%3) : (!test.type<"int">) -> ()
// CHECK-NEXT: func.return %3 : !test.type<"int">
// CHECK-NEXT: }

func.func private @external_fn(i32) -> (i32, i32)
// CHECK: func.func private @external_fn(i32) -> (i32, i32)

func.func @multi_return_body(%a : i32) -> (i32, i32) {
"func.return"(%a, %a) : (i32, i32) -> ()
func.return %a, %a : i32, i32
}

// CHECK: func.func @multi_return_body(%a : i32) -> (i32, i32) {
// CHECK-NEXT: "func.return"(%a, %a) : (i32, i32) -> ()
// CHECK-NEXT: func.return %a, %a : i32, i32
// CHECK-NEXT: }

}
8 changes: 4 additions & 4 deletions tests/filecheck/dialects/scf/scf_ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ builtin.module {
^1(%arg2 : i32):
"scf.yield"(%arg2) : (i32) -> ()
}) : (i32) -> i32
"func.return"() : () -> ()
func.return
}

// CHECK: func.func @while() {
Expand All @@ -65,7 +65,7 @@ builtin.module {
// CHECK-NEXT: ^{{.*}}(%{{.*}} : i32):
// CHECK-NEXT: "scf.yield"(%{{.*}}) : (i32) -> ()
// CHECK-NEXT: }) : (i32) -> i32
// CHECK-NEXT: "func.return"() : () -> ()
// CHECK-NEXT: func.return
// CHECK-NEXT: }

func.func @for() {
Expand All @@ -78,7 +78,7 @@ builtin.module {
%prod_new = arith.muli %prod_iter, %iv : index
"scf.yield"(%prod_new) : (index) -> ()
}) : (index, index, index, index) -> index
"func.return"() : () -> ()
func.return
}

// CHECK-NEXT: func.func @for() {
Expand All @@ -91,7 +91,7 @@ builtin.module {
// CHECK-NEXT: %{{.*}} = arith.muli %{{.*}}, %{{.*}} : index
// CHECK-NEXT: "scf.yield"(%{{.*}}) : (index) -> ()
// CHECK-NEXT: }) : (index, index, index, index) -> index
// CHECK-NEXT: "func.return"() : () -> ()
// CHECK-NEXT: func.return
// CHECK-NEXT: }


Expand Down
4 changes: 2 additions & 2 deletions tests/filecheck/dialects/stencil/hdiff_gpu.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"stencil.return"(%19) : (f64) -> ()
}) : (!stencil.temp<?x?x?xf64>) -> !stencil.temp<?x?x?xf64>
"stencil.store"(%8, %4) {"lb" = #stencil.index<0, 0, 0>, "ub" = #stencil.index<64, 64, 64>} : (!stencil.temp<?x?x?xf64>, !stencil.field<[-4,68]x[-4,68]x[-4,68]xf64>) -> ()
"func.return"() : () -> ()
func.return
}) {"function_type" = (!stencil.field<?x?x?xf64>, !stencil.field<?x?x?xf64>) -> (), "sym_name" = "stencil_hdiff"} : () -> ()
}) : () -> ()

Expand Down Expand Up @@ -90,6 +90,6 @@
// CHECK-NEXT: "memref.store"(%58, %6, %18, %17, %16) : (f64, memref<64x64x64xf64, strided<[5184, 72, 1], offset: 21028>>, index, index, index) -> ()
// CHECK-NEXT: "scf.yield"() : () -> ()
// CHECK-NEXT: }) {"operand_segment_sizes" = array<i32: 3, 3, 3, 0>} : (index, index, index, index, index, index, index, index, index) -> ()
// CHECK-NEXT: "func.return"() : () -> ()
// CHECK-NEXT: func.return
// CHECK-NEXT: }
// CHECK-NEXT: }
16 changes: 8 additions & 8 deletions tests/filecheck/dialects/stencil/stencil_ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ builtin.module {
"stencil.return"(%8) : (!stencil.result<f64>) -> ()
}) : (!stencil.temp<[0,64]x[0,64]x[0,64]xf64>) -> !stencil.temp<[0,64]x[0,64]x[0,64]xf64>
"stencil.store"(%5, %3) {"lb" = #stencil.index<0, 0, 0>, "ub" = #stencil.index<64, 64, 64>} : (!stencil.temp<[0,64]x[0,64]x[0,64]xf64>, !stencil.field<[-4,68]x[-4,68]x[-4,68]xf64>) -> ()
"func.return"() : () -> ()
func.return
}
}

Expand All @@ -28,7 +28,7 @@ builtin.module {
// CHECK-NEXT: "stencil.return"(%8) : (!stencil.result<f64>) -> ()
// CHECK-NEXT: }) : (!stencil.temp<[0,64]x[0,64]x[0,64]xf64>) -> !stencil.temp<[0,64]x[0,64]x[0,64]xf64>
// CHECK-NEXT: "stencil.store"(%5, %3) {"lb" = #stencil.index<0, 0, 0>, "ub" = #stencil.index<64, 64, 64>} : (!stencil.temp<[0,64]x[0,64]x[0,64]xf64>, !stencil.field<[-4,68]x[-4,68]x[-4,68]xf64>) -> ()
// CHECK-NEXT: "func.return"() : () -> ()
// CHECK-NEXT: func.return
// CHECK-NEXT: }
// CHECK-NEXT: }

Expand All @@ -52,7 +52,7 @@ builtin.module {
"stencil.store"(%tip1, %fip1) {"lb" = #stencil.index<0, 0, 0>, "ub" = #stencil.index<50, 80, 40>} : (!stencil.temp<?x?x?xf32>, !stencil.field<[-4,54]x[-4,84]x[-4,44]xf32>) -> ()
"scf.yield"(%fip1, %fi) : (!stencil.field<[-4,54]x[-4,84]x[-4,44]xf32>, !stencil.field<[-4,54]x[-4,84]x[-4,44]xf32>) -> ()
}) : (index, index, index, !stencil.field<[-4,54]x[-4,84]x[-4,44]xf32>, !stencil.field<[-4,54]x[-4,84]x[-4,44]xf32>) -> (!stencil.field<[-4,54]x[-4,84]x[-4,44]xf32>, !stencil.field<[-4,54]x[-4,84]x[-4,44]xf32>)
"func.return"() : () -> ()
func.return
}
}

Expand All @@ -74,7 +74,7 @@ builtin.module {
// CHECK-NEXT: "stencil.store"(%tip1, %fip1) {"lb" = #stencil.index<0, 0, 0>, "ub" = #stencil.index<50, 80, 40>} : (!stencil.temp<?x?x?xf32>, !stencil.field<[-4,54]x[-4,84]x[-4,44]xf32>) -> ()
// CHECK-NEXT: "scf.yield"(%fip1, %fi) : (!stencil.field<[-4,54]x[-4,84]x[-4,44]xf32>, !stencil.field<[-4,54]x[-4,84]x[-4,44]xf32>) -> ()
// CHECK-NEXT: }) : (index, index, index, !stencil.field<[-4,54]x[-4,84]x[-4,44]xf32>, !stencil.field<[-4,54]x[-4,84]x[-4,44]xf32>) -> (!stencil.field<[-4,54]x[-4,84]x[-4,44]xf32>, !stencil.field<[-4,54]x[-4,84]x[-4,44]xf32>)
// CHECK-NEXT: "func.return"() : () -> ()
// CHECK-NEXT: func.return
// CHECK-NEXT: }
// CHECK-NEXT: }

Expand All @@ -101,7 +101,7 @@ builtin.module {
"stencil.return"(%17) : (f64) -> ()
}) : (!stencil.temp<[-1,65]x[-1,65]xf64>) -> !stencil.temp<[0,64]x[0,64]xf64>
"stencil.store"(%5, %3) {"lb" = #stencil.index<0, 0>, "ub" = #stencil.index<64, 64>} : (!stencil.temp<[0,64]x[0,64]xf64>, !stencil.field<[-4,68]x[-4,68]xf64>) -> ()
"func.return"() : () -> ()
func.return
}
}

Expand All @@ -126,7 +126,7 @@ builtin.module {
// CHECK-NEXT: "stencil.return"(%17) : (f64) -> ()
// CHECK-NEXT: }) : (!stencil.temp<[-1,65]x[-1,65]xf64>) -> !stencil.temp<[0,64]x[0,64]xf64>
// CHECK-NEXT: "stencil.store"(%5, %3) {"lb" = #stencil.index<0, 0>, "ub" = #stencil.index<64, 64>} : (!stencil.temp<[0,64]x[0,64]xf64>, !stencil.field<[-4,68]x[-4,68]xf64>) -> ()
// CHECK-NEXT: "func.return"() : () -> ()
// CHECK-NEXT: func.return
// CHECK-NEXT: }
// CHECK-NEXT: }

Expand All @@ -149,7 +149,7 @@ builtin.module {
"stencil.return"(%14) : (f64) -> ()
}) : (!stencil.temp<?xf64>) -> !stencil.temp<?xf64>
"stencil.store"(%12, %1) {"lb" = #stencil.index<0, 0>, "ub" = #stencil.index<64, 64>} : (!stencil.temp<?xf64>, !stencil.field<[-4,68]xf64>) -> ()
"func.return"() : () -> ()
func.return
}
}

Expand All @@ -168,6 +168,6 @@ builtin.module {
// CHECK-NEXT: "stencil.return"(%9) : (f64) -> ()
// CHECK-NEXT: }) : (!stencil.temp<?xf64>) -> !stencil.temp<?xf64>
// CHECK-NEXT: "stencil.store"(%7, %1) {"lb" = #stencil.index<0, 0>, "ub" = #stencil.index<64, 64>} : (!stencil.temp<?xf64>, !stencil.field<[-4,68]xf64>) -> ()
// CHECK-NEXT: "func.return"() : () -> ()
// CHECK-NEXT: func.return
// CHECK-NEXT: }
// CHECK-NEXT: }
8 changes: 4 additions & 4 deletions tests/filecheck/frontend/dialects/affine.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# CHECK-NEXT: ^0(%0 : index):
# CHECK-NEXT: "affine.yield"() : () -> ()
# CHECK-NEXT: }) {"lower_bound" = 0 : index, "upper_bound" = 100 : index, "step" = 1 : index} : () -> ()
# CHECK-NEXT: "func.return"() : () -> ()
# CHECK-NEXT: func.return
# CHECK-NEXT: }

def test_affine_for_I():
Expand All @@ -25,7 +25,7 @@ def test_affine_for_I():
# CHECK-NEXT: ^1(%1 : index):
# CHECK-NEXT: "affine.yield"() : () -> ()
# CHECK-NEXT: }) {"lower_bound" = 10 : index, "upper_bound" = 30 : index, "step" = 1 : index} : () -> ()
# CHECK-NEXT: "func.return"() : () -> ()
# CHECK-NEXT: func.return
# CHECK-NEXT: }
def test_affine_for_II():
for _ in range(10, 30):
Expand All @@ -37,7 +37,7 @@ def test_affine_for_II():
# CHECK-NEXT: ^2(%2 : index):
# CHECK-NEXT: "affine.yield"() : () -> ()
# CHECK-NEXT: }) {"lower_bound" = 1 : index, "upper_bound" = 20 : index, "step" = 5 : index} : () -> ()
# CHECK-NEXT: "func.return"() : () -> ()
# CHECK-NEXT: func.return
# CHECK-NEXT: }
def test_affine_for_III():
for _ in range(1, 20, 5):
Expand All @@ -57,7 +57,7 @@ def test_affine_for_III():
# CHECK-NEXT: }) {"lower_bound" = 0 : index, "upper_bound" = 20 : index, "step" = 1 : index} : () -> ()
# CHECK-NEXT: "affine.yield"() : () -> ()
# CHECK-NEXT: }) {"lower_bound" = 0 : index, "upper_bound" = 10 : index, "step" = 1 : index} : () -> ()
# CHECK-NEXT: "func.return"() : () -> ()
# CHECK-NEXT: func.return
# CHECK-NEXT: }
def test_affine_for_IV():
for _ in range(10):
Expand Down
6 changes: 3 additions & 3 deletions tests/filecheck/frontend/dialects/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
# CHECK: func.func @f1(%{{.*}} : i32) {
# CHECK-NEXT: "symref.declare"() {"sym_name" = "x"} : () -> ()
# CHECK-NEXT: "symref.update"(%{{.*}}) {"symbol" = @x} : (i32) -> ()
# CHECK-NEXT: "func.return"() : () -> ()
# CHECK-NEXT: func.return
# CHECK-NEXT: }
def f1(x: i32):
return

# CHECK: func.func @f2() {
# CHECK-NEXT: "func.return"() : () -> ()
# CHECK-NEXT: func.return
# CHECK-NEXT: }
def f2():
return
Expand All @@ -24,7 +24,7 @@ def f2():
# CHECK-NEXT: "symref.declare"() {"sym_name" = "x"} : () -> ()
# CHECK-NEXT: "symref.update"(%{{.*}}) {"symbol" = @x} : (i32) -> ()
# CHECK-NEXT: %{{.*}} = "symref.fetch"() {"symbol" = @x} : () -> i32
# CHECK-NEXT: "func.return"(%{{.*}}) : (i32) -> ()
# CHECK-NEXT: func.return %{{.*}} : i32
# CHECK-NEXT: }
def f3(x: i32) -> i32:
return x
Expand Down
Loading