Skip to content

Commit

Permalink
interpreter: (pdl) add the implementation of type interpretation (#3498)
Browse files Browse the repository at this point in the history
  • Loading branch information
qaco authored Nov 22, 2024
1 parent 421792a commit 020cae7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/filecheck/transforms/apply-pdl/apply_pdl_build_type.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// RUN: xdsl-opt %s -p apply-pdl | filecheck %s

%x = "test.op"() : () -> (i32)

pdl.pattern : benefit(1) {
%in_type = pdl.type: i32
%root = pdl.operation "test.op" -> (%in_type: !pdl.type)
pdl.rewrite %root {
%out_type = pdl.type: i64
%new_op = pdl.operation "test.op" -> (%out_type: !pdl.type)
pdl.replace %root with %new_op
}
}

// CHECK: builtin.module {
// CHECK-NEXT: %x = "test.op"() : () -> i64
// CHECK-NEXT: pdl.pattern : benefit(1) {
// CHECK-NEXT: %in_type = pdl.type : i32
// CHECK-NEXT: %root = pdl.operation "test.op" -> (%in_type : !pdl.type)
// CHECK-NEXT: pdl.rewrite %root {
// CHECK-NEXT: %out_type = pdl.type : i64
// CHECK-NEXT: %new_op = pdl.operation "test.op" -> (%out_type : !pdl.type)
// CHECK-NEXT: pdl.replace %root with %new_op
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT:
7 changes: 7 additions & 0 deletions xdsl/interpreters/pdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,10 @@ def run_erase(
(old,) = interpreter.get_values((op.op_value,))
self.rewriter.erase_op(old)
return ()

@impl(pdl.TypeOp)
def run_type(
self, interpreter: Interpreter, op: pdl.TypeOp, args: tuple[Any, ...]
) -> tuple[Any, ...]:
assert isinstance(op.constantType, Attribute)
return (op.constantType,)

0 comments on commit 020cae7

Please sign in to comment.