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

core: (rewriting) Fix recursive type conversion in block arguments for nested regions #2871

Merged
merged 3 commits into from
Jul 10, 2024
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
35 changes: 35 additions & 0 deletions tests/pattern_rewriter/test_pattern_rewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,41 @@ def convert_type(self, typ: IntegerType) -> IndexType | None:
)


def test_recursive_type_conversion_in_regions():

prog = """\
"builtin.module"() ({
"func.func"() <{"function_type" = (memref<2x4xui16>) -> (), "sym_name" = "main", "sym_visibility" = "private"}> ({
^bb0(%arg0 : memref<2x4xui16>):
"func.return"() : () -> ()
}) : () -> ()
}) : () -> ()
"""
expected_prog = """\
"builtin.module"() ({
"func.func"() <{"function_type" = (memref<2x4xindex>) -> (), "sym_name" = "main", "sym_visibility" = "private"}> ({
^0(%arg0 : memref<2x4xindex>):
"func.return"() : () -> ()
}) : () -> ()
}) : () -> ()
"""

class IndexConversion(TypeConversionPattern):

@attr_type_rewrite_pattern
def convert_type(self, typ: IntegerType) -> IndexType:
return IndexType()

rewrite_and_compare(
prog,
expected_prog,
PatternRewriteWalker(IndexConversion(recursive=True)),
op_inserted=1,
op_removed=1,
op_replaced=1,
)


def test_no_change():
"""Test that doing nothing successfully does not report doing something."""

Expand Down
2 changes: 1 addition & 1 deletion xdsl/pattern_rewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def match_and_rewrite(self, op: Operation, rewriter: PatternRewriter):
for region in op.regions:
for block in region.blocks:
for arg in block.args:
converted = self.convert_type(arg.type)
converted = self._convert_type_rec(arg.type)
if converted is not None and converted != arg.type:
rewriter.modify_block_argument_type(arg, converted)
if changed:
Expand Down
Loading