Skip to content

Commit

Permalink
core: always print unregistered ops (xdslproject#3303)
Browse files Browse the repository at this point in the history
`scf.for` prints it's blocks without terminators if there are no
`iter_args`. Unfortunately the check for whether an operation is a
terminator returns true by default for unregistered operations
(presumably so that they don't break verification), and so they don't
get printed.

This change should make it so that these ops always get printed.
  • Loading branch information
alexarice authored and EdmundGoodman committed Dec 6, 2024
1 parent 5666899 commit 82e09ec
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
22 changes: 22 additions & 0 deletions tests/filecheck/dialects/scf/unregistered.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// RUN: xdsl-opt %s --print-op-generic --allow-unregistered-dialect | xdsl-opt --allow-unregistered-dialect | filecheck %s

// CHECK: func.func @for_unregistered() {
// CHECK-NEXT: %lb = arith.constant 0 : index
// CHECK-NEXT: %ub = arith.constant 42 : index
// CHECK-NEXT: %s = arith.constant 3 : index
// CHECK-NEXT: scf.for %iv = %lb to %ub step %s {
// CHECK-NEXT: "unregistered_op"() : () -> ()
// CHECK-NEXT: }
// CHECK-NEXT: func.return
// CHECK-NEXT: }

func.func @for_unregistered() {
%lb = arith.constant 0 : index
%ub = arith.constant 42 : index
%s = arith.constant 3 : index
scf.for %iv = %lb to %ub step %s {
"unregistered_op"() : () -> ()
scf.yield
}
func.return
}
4 changes: 3 additions & 1 deletion xdsl/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ def print_block(

with self.indented():
for op in block.ops:
if not print_block_terminator and op.has_trait(IsTerminator):
if not print_block_terminator and op.has_trait(
IsTerminator, value_if_unregistered=False
):
continue
self._print_new_line()
self.print_op(op)
Expand Down

0 comments on commit 82e09ec

Please sign in to comment.