From a710ac40db8e544f2452c10139210f6b1942a172 Mon Sep 17 00:00:00 2001 From: Mathieu Fehr Date: Mon, 19 Aug 2024 04:19:39 +0100 Subject: [PATCH] Add transfer dialect for experiments --- xdsl_pdl/dialects/transfer.py | 14 ++++++++++++++ xdsl_pdl/passes/pdl_to_irdl.py | 5 ++++- xdsl_pdl/tools/analyze_irdl_invariants.py | 2 ++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 xdsl_pdl/dialects/transfer.py diff --git a/xdsl_pdl/dialects/transfer.py b/xdsl_pdl/dialects/transfer.py new file mode 100644 index 0000000..2a662d3 --- /dev/null +++ b/xdsl_pdl/dialects/transfer.py @@ -0,0 +1,14 @@ +from xdsl.ir import ParametrizedAttribute, TypeAttribute, Dialect + +from xdsl.irdl import ( + irdl_attr_definition, + ParametrizedAttribute, +) + + +@irdl_attr_definition +class IntegerType(ParametrizedAttribute, TypeAttribute): + name = "transfer.integer" + + +Transfer = Dialect("transfer", [], [IntegerType]) diff --git a/xdsl_pdl/passes/pdl_to_irdl.py b/xdsl_pdl/passes/pdl_to_irdl.py index d80b81b..8eb434e 100644 --- a/xdsl_pdl/passes/pdl_to_irdl.py +++ b/xdsl_pdl/passes/pdl_to_irdl.py @@ -10,7 +10,7 @@ RewritePattern, op_type_rewrite_pattern, ) - +from xdsl_pdl.dialects import transfer from xdsl.dialects.pdl import ( ApplyNativeConstraintOp, ApplyNativeRewriteOp, @@ -201,6 +201,9 @@ def match_and_rewrite(self, op: TypeOp, rewriter: PatternRewriter, /): if op.constantType is None: rewriter.replace_matched_op(irdl.AnyOp()) return + if op.constantType == transfer.IntegerType(): + rewriter.replace_matched_op(irdl.BaseOp("!builtin.integer_type")) + return rewriter.replace_matched_op(irdl.IsOp(op.constantType)) diff --git a/xdsl_pdl/tools/analyze_irdl_invariants.py b/xdsl_pdl/tools/analyze_irdl_invariants.py index a681614..018ab08 100644 --- a/xdsl_pdl/tools/analyze_irdl_invariants.py +++ b/xdsl_pdl/tools/analyze_irdl_invariants.py @@ -12,6 +12,7 @@ from xdsl.rewriter import InsertPoint, Rewriter from xdsl_pdl.analysis.check_subset_to_z3 import check_subset_to_z3 from xdsl_pdl.dialects.irdl_extension import IRDLExtension +from xdsl_pdl.dialects.transfer import Transfer from xdsl.dialects.builtin import ( Builtin, @@ -39,6 +40,7 @@ def main(): ctx.load_dialect(IRDL) ctx.load_dialect(IRDLExtension) ctx.load_dialect(PDL) + ctx.load_dialect(Transfer) # Parse the input program with open(args.input_file) as f: