Skip to content

Commit

Permalink
Update mlir to d401987fe349a87c53fe25829215b080b70c0c1a (#3310)
Browse files Browse the repository at this point in the history
Updates mlir.

Fixes #3298 
Fixes #3297 
Fixes #3296

---------

Co-authored-by: Sasha Lopoukhine <[email protected]>
  • Loading branch information
alexarice and superlopuh authored Oct 22, 2024
1 parent 8522415 commit a08d1f8
Show file tree
Hide file tree
Showing 62 changed files with 1,176 additions and 801 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-mlir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

env:
LLVM_SYMBOLIZER_PATH: /usr/lib/llvm-11/bin/llvm-symbolizer
MLIR-Version: 98e674c9f16d677d95c67bc130e267fae331e43c
MLIR-Version: d401987fe349a87c53fe25829215b080b70c0c1a
steps:
- uses: actions/checkout@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pip install xdsl

*Note:* This version of xDSL is validated against a specific MLIR version,
interoperability with other versions may result in problems. The supported
MLIR version is commit `98e674c9f16d677d95c67bc130e267fae331e43c`.
MLIR version is commit `d401987fe349a87c53fe25829215b080b70c0c1a`.

### Subprojects With Extra Dependencies

Expand Down
4 changes: 2 additions & 2 deletions docs/irdl.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1476,11 +1476,11 @@
"Operation does not verify: result at position 0 does not verify:\n",
"attribute i32 expected from variable 'T', but got i64\n",
"\n",
"%0 = \"arith.addi\"(%1, %1) : (i32, i32) -> i64\n",
"%0 = \"arith.addi\"(%1, %1) <{\"overflowFlags\" = #arith.overflow<none>}> : (i32, i32) -> i64\n",
"\n",
"\n",
"\n",
"%0 = \"arith.addi\"(%1, %1) : (i32, i32) -> i64\n",
"%0 = \"arith.addi\"(%1, %1) <{\"overflowFlags\" = #arith.overflow<none>}> : (i32, i32) -> i64\n",
"\n",
"\n"
]
Expand Down
2 changes: 1 addition & 1 deletion docs/mlir_interoperation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"\"builtin.module\"() ({\r\n",
" %0 = \"arith.constant\"() <{value = 1 : i32}> : () -> i32\r\n",
" %1 = \"arith.constant\"() <{value = 2 : i32}> : () -> i32\r\n",
" %2 = \"arith.addi\"(%0, %1) : (i32, i32) -> i32\r\n",
" %2 = \"arith.addi\"(%0, %1) <{overflowFlags = #arith.overflow<none>}> : (i32, i32) -> i32\r\n",
"}) : () -> ()\r\n",
"\r\n"
]
Expand Down
2 changes: 1 addition & 1 deletion docs/mlir_interoperation.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ mlir-opt --convert-scf-to-cf --convert-cf-to-llvm --convert-func-to-llvm \
The generated `tmp.ll` file contains LLVM IR, so it can be directly passed to
the clang compiler. Notice that a `main` function is required for clang to
build. The functionality is tested with the MLIR git commit hash:
98e674c9f16d677d95c67bc130e267fae331e43c
d401987fe349a87c53fe25829215b080b70c0c1a
4 changes: 2 additions & 2 deletions tests/dialects/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_call():
"builtin.module"() ({
"func.func"() <{"sym_name" = "func0", "function_type" = (i32, i32) -> i32}> ({
^0(%0 : i32, %1 : i32):
%2 = "arith.addi"(%0, %1) : (i32, i32) -> i32
%2 = "arith.addi"(%0, %1) <{"overflowFlags" = #arith.overflow<none>}> : (i32, i32) -> i32
"func.return"(%2) : (i32) -> ()
}) : () -> ()
%0 = "arith.constant"() <{"value" = 1 : i32}> : () -> i32
Expand Down Expand Up @@ -248,7 +248,7 @@ def test_call_II():
"builtin.module"() ({
"func.func"() <{"sym_name" = "func1", "function_type" = (i32) -> i32}> ({
^0(%0 : i32):
%1 = "arith.addi"(%0, %0) : (i32, i32) -> i32
%1 = "arith.addi"(%0, %0) <{"overflowFlags" = #arith.overflow<none>}> : (i32, i32) -> i32
"func.return"(%1) : (i32) -> ()
}) : () -> ()
%0 = "arith.constant"() <{"value" = 1 : i32}> : () -> i32
Expand Down
8 changes: 7 additions & 1 deletion tests/dialects/test_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,16 @@ def test_launch():
assert launch.blockSizeX is ten.result
assert launch.blockSizeY is ten.result
assert launch.blockSizeZ is ten.result
assert launch.clusterSizeX is None
assert launch.clusterSizeY is None
assert launch.clusterSizeZ is None
assert launch.asyncToken is None
assert launch.asyncDependencies == tuple()
assert launch.dynamicSharedMemorySize is None

body2 = Region()

nd_launch = LaunchOp(body2, gridSize, blockSize, True, [], ten)
nd_launch = LaunchOp(body2, gridSize, blockSize, [], True, [], ten)

assert isinstance(launch, LaunchOp)
assert nd_launch.body is body2
Expand All @@ -277,6 +280,9 @@ def test_launch():
assert nd_launch.blockSizeX is ten.result
assert nd_launch.blockSizeY is ten.result
assert nd_launch.blockSizeZ is ten.result
assert nd_launch.clusterSizeX is None
assert nd_launch.clusterSizeY is None
assert nd_launch.clusterSizeZ is None
assert nd_launch.asyncToken is not None
assert nd_launch.asyncToken.type == AsyncTokenType()
assert nd_launch.asyncDependencies == tuple()
Expand Down
103 changes: 29 additions & 74 deletions tests/dialects/test_scf.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,14 @@ def test_parallel_block_arg_indextype():
si = Constant.from_int_and_width(1, IndexType())

b = Block(arg_types=[IndexType()])
b.add_op(Yield())
b.add_op(ReduceOp())

body = Region(b)
p = ParallelOp([lbi], [ubi], [si], body)
p.verify()

b2 = Block(arg_types=[i32])
b2.add_op(Yield())
b2.add_op(ReduceOp())
body2 = Region(b2)
p2 = ParallelOp([lbi], [ubi], [si], body2)
with pytest.raises(VerifyException):
Expand All @@ -245,8 +245,7 @@ def test_parallel_verify_reduction_and_block_type():
reduce_block = Block(arg_types=[i32, i32])
reduce_block.add_ops([reduce_constant, rro])

b.add_op(ReduceOp(init_val, reduce_block))
b.add_op(Yield())
b.add_op(ReduceOp((init_val,), (Region(reduce_block),)))

body = Region(b)
p = ParallelOp([lbi], [ubi], [si], body, initVals)
Expand All @@ -270,76 +269,28 @@ def test_parallel_verify_reduction_and_block_type_fails():
reduce_block = Block(arg_types=[i32, i32])
reduce_block.add_ops([reduce_constant, rro])

b.add_op(ReduceOp(init_val, reduce_block))
b.add_op(Yield())
b.add_op(ReduceOp((init_val,), (Region(reduce_block),)))

body = Region(b)
p = ParallelOp([lbi], [ubi], [si], body, initVals)
with pytest.raises(VerifyException):
p.verify()


def test_parallel_verify_yield_zero_ops():
lbi = Constant.from_int_and_width(0, IndexType())
ubi = Constant.from_int_and_width(10, IndexType())
si = Constant.from_int_and_width(1, IndexType())

val = Constant.from_int_and_width(10, i64)

b = Block(arg_types=[IndexType()])
b.add_op(Yield(val))
body = Region(b)
p = ParallelOp([lbi], [ubi], [si], body)
with pytest.raises(
VerifyException,
match="Single-block region terminator scf.yield has 1 operands "
"but 0 expected inside an scf.parallel",
):
p.verify()

b2 = Block(arg_types=[IndexType()])
b2.add_op(Yield())
body2 = Region(b2)
p2 = ParallelOp([lbi], [ubi], [si], body2)
# Should verify as yield is empty
p2.verify()


def test_parallel_test_count_number_reduction_ops():
@Builder.implicit_region
def body():
for i in range(10):
init_val = Constant.from_int_and_width(i, i32)
ReduceOp(init_val, Block())

p = ParallelOp([], [], [], body)
assert p.count_number_reduction_ops() == 10


def test_parallel_get_arg_type_of_nth_reduction_op():
@Builder.implicit_region
def body():
init_val1 = Constant.from_int_and_width(10, i32)
init_val2 = Constant.from_int_and_width(10, i64)
for i in range(10):
ReduceOp(init_val1 if i % 2 == 0 else init_val2, Block())

p = ParallelOp([], [], [], body)
assert p.count_number_reduction_ops() == 10
for i in range(10):
assert p.get_arg_type_of_nth_reduction_op(i) == i32 if i % 2 == 0 else i64


def test_reduce_op():
init_val = Constant.from_int_and_width(10, i32)

reduce_op = ReduceOp(init_val, Block(arg_types=[i32, i32]))
reduce_op = ReduceOp((init_val,), (Region(Block(arg_types=[i32, i32])),))

assert reduce_op.argument is init_val.results[0]
assert reduce_op.argument.type is i32
assert len(reduce_op.body.blocks) == 1
assert len(reduce_op.body.block.args) == 2
assert reduce_op.body.block.args[0].type == reduce_op.body.block.args[0].type == i32
assert reduce_op.args[0] is init_val.results[0]
assert reduce_op.args[0].type is i32
assert len(reduce_op.reductions[0].blocks) == 1
assert len(reduce_op.reductions[0].block.args) == 2
assert (
reduce_op.reductions[0].block.args[0].type
== reduce_op.reductions[0].block.args[0].type
== i32
)


def test_reduce_op_num_block_args():
Expand All @@ -351,21 +302,23 @@ def test_reduce_op_num_block_args():
match="scf.reduce block must have exactly two arguments, but ",
):
rro = ReduceReturnOp(reduce_constant)
ReduceOp(init_val, Block([rro], arg_types=[i32, i32, i32])).verify()
ReduceOp(
(init_val,), (Region(Block([rro], arg_types=[i32, i32, i32])),)
).verify()

with pytest.raises(
VerifyException,
match="scf.reduce block must have exactly two arguments, but ",
):
rro = ReduceReturnOp(reduce_constant)
ReduceOp(init_val, Block([rro], arg_types=[i32])).verify()
ReduceOp((init_val,), (Region(Block([rro], arg_types=[i32])),)).verify()

with pytest.raises(
VerifyException,
match="scf.reduce block must have exactly two arguments, but ",
):
rro = ReduceReturnOp(reduce_constant)
ReduceOp(init_val, Block([rro], arg_types=[])).verify()
ReduceOp((init_val,), (Region(Block([rro], arg_types=[])),)).verify()


def test_reduce_op_num_block_arg_types():
Expand All @@ -377,21 +330,21 @@ def test_reduce_op_num_block_arg_types():
match="scf.reduce block argument types must be the same but have",
):
rro = ReduceReturnOp(reduce_constant)
ReduceOp(init_val, Block([rro], arg_types=[i32, i64])).verify()
ReduceOp((init_val,), (Region(Block([rro], arg_types=[i32, i64])),)).verify()

with pytest.raises(
VerifyException,
match="scf.reduce block argument types must be the same but have",
):
rro = ReduceReturnOp(reduce_constant)
ReduceOp(init_val, Block([rro], arg_types=[i64, i32])).verify()
ReduceOp((init_val,), (Region(Block([rro], arg_types=[i64, i32])),)).verify()


def test_reduce_op_num_block_arg_types_match_operand_type():
init_val = Constant.from_int_and_width(10, i32)

with pytest.raises(VerifyException):
ReduceOp(init_val, Block(arg_types=[i64, i64])).verify()
ReduceOp((init_val,), (Region(Block(arg_types=[i64, i64])),)).verify()


def test_reduce_return_op_at_end():
Expand All @@ -401,13 +354,15 @@ def test_reduce_return_op_at_end():
reduce_block.add_ops([reduce_constant, rro])

init_val = Constant.from_int_and_width(10, i32)
ReduceOp(init_val, reduce_block).verify()
ReduceOp((init_val,), (Region(reduce_block),)).verify()

with pytest.raises(
VerifyException,
match="Block inside scf.reduce must terminate with an scf.reduce.return",
match="'scf.reduce' terminates with operation test.termop instead of scf.reduce.return",
):
ReduceOp(init_val, Block([TestTermOp.create()], arg_types=[i32, i32])).verify()
ReduceOp(
(init_val,), (Region(Block([TestTermOp.create()], arg_types=[i32, i32])),)
).verify()


def test_reduce_return_type_is_arg_type():
Expand All @@ -418,7 +373,7 @@ def test_reduce_return_type_is_arg_type():

init_val = Constant.from_int_and_width(10, i64)
with pytest.raises(VerifyException):
ReduceOp(init_val, reduce_block).verify()
ReduceOp((init_val,), (Region(reduce_block),)).verify()


def test_reduce_return_op():
Expand All @@ -441,7 +396,7 @@ def test_reduce_return_type_is_operand_type():
VerifyException,
match="scf.reduce.return result type at end of scf.reduce block must",
):
ReduceOp(init_val, reduce_block).verify()
ReduceOp((init_val,), (Region(reduce_block),)).verify()


def test_empty_else():
Expand Down
4 changes: 2 additions & 2 deletions tests/dialects/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def test_get_result():
target = test.TestOp(result_types=[transform.AnyOpType()]).results[0]
result_number = 0
assert_print_op(
transform.GetResultOp(target=target, result_number=result_number),
"""%0 = "transform.get_result"(%1) <{"result_number" = 0 : i64}> : (!transform.any_op) -> !transform.any_value""",
transform.GetResultOp(target=target, raw_position_list=[result_number]),
"""%0 = "transform.get_result"(%1) <{"raw_position_list" = array<i64: 0>}> : (!transform.any_op) -> !transform.any_value""",
None,
)

Expand Down
4 changes: 4 additions & 0 deletions tests/filecheck/dialects/arith/arith_ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@

// CHECK-NEXT: %cmpf = arith.cmpf ogt, %lhsf32, %rhsf32 : f32

%cmpf_fm = "arith.cmpf"(%lhsf32, %rhsf32) {"predicate" = 2 : i64, "fastmath" = #arith.fastmath<fast>} : (f32, f32) -> i1

// CHECK-NEXT: %cmpf_fm = arith.cmpf ogt, %lhsf32, %rhsf32 fastmath<fast> : f32

%selecti = "arith.select"(%lhsi1, %lhsi32, %rhsi32) : (i1, i32, i32) -> i32
%selectf = "arith.select"(%lhsi1, %lhsf32, %rhsf32) : (i1, f32, f32) -> f32

Expand Down
2 changes: 1 addition & 1 deletion tests/filecheck/dialects/csl/ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ csl.func @builtins() {
// CHECK-GENERIC-NEXT: %variable_with_default = "csl.variable"() <{"default" = 42 : i32}> : () -> !csl.var<i32>
// CHECK-GENERIC-NEXT: %variable = "csl.variable"() : () -> !csl.var<i32>
// CHECK-GENERIC-NEXT: %value = "csl.load_var"(%variable_with_default) : (!csl.var<i32>) -> i32
// CHECK-GENERIC-NEXT: %new_value = "arith.addi"(%value, %one) : (i32, i32) -> i32
// CHECK-GENERIC-NEXT: %new_value = "arith.addi"(%value, %one) <{"overflowFlags" = #arith.overflow<none>}> : (i32, i32) -> i32
// CHECK-GENERIC-NEXT: "csl.store_var"(%variable_with_default, %new_value) : (!csl.var<i32>, i32) -> ()
// CHECK-GENERIC-NEXT: "csl.store_var"(%variable, %new_value) : (!csl.var<i32>, i32) -> ()
// CHECK-GENERIC-NEXT: "csl.return"() : () -> ()
Expand Down
6 changes: 3 additions & 3 deletions tests/filecheck/dialects/gpu/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
}) {"op" = #gpu<all_reduce_op add>} : (index) -> index
%final = "arith.muli"(%sum, %one) : (index, index) -> index
"gpu.terminator"() : () -> ()
}) {"operandSegmentSizes" = array<i32: 0, 1, 1, 1, 1, 1, 1, 0>} : (index, index, index, index, index, index) -> ()
}) {"operandSegmentSizes" = array<i32: 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0>} : (index, index, index, index, index, index) -> ()
"gpu.module_end"() : () -> ()
}) {"sym_name" = "gpu"} : () -> ()
}) {} : () -> ()
Expand All @@ -108,7 +108,7 @@
%one = "arith.constant"() {"value" = 1 : index} : () -> index

"gpu.launch"(%one, %one, %n, %one, %one, %one) ({})
{"operandSegmentSizes" = array<i32: 0, 1, 1, 1, 1, 1, 1, 0>} : (index, index, index, index, index, index) -> ()
{"operandSegmentSizes" = array<i32: 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0>} : (index, index, index, index, index, index) -> ()
"gpu.module_end"() : () -> ()
}) {"sym_name" = "gpu"} : () -> ()
}) {} : () -> ()
Expand Down Expand Up @@ -136,7 +136,7 @@
}) {} : () -> ()
}) {} : () -> ()

// CHECK: attribute sym_name expected
// CHECK: property sym_name expected

// -----

Expand Down
Loading

0 comments on commit a08d1f8

Please sign in to comment.