|
| 1 | +// RUN: mlir-opt -allow-unregistered-dialect -split-input-file -test-legalize-patterns -verify-diagnostics -profile-actions-to=- %s | FileCheck %s |
| 2 | + |
| 3 | +// expected-remark@+1 {{applyPartialConversion failed}} |
| 4 | +module { |
| 5 | +func.func @fail_to_convert_illegal_op_in_region() { |
| 6 | + // expected-error@+1 {{failed to legalize operation 'test.region_builder'}} |
| 7 | + "test.region_builder"() : () -> () |
| 8 | + return |
| 9 | +} |
| 10 | +} |
| 11 | + |
| 12 | +// ----- |
| 13 | + |
| 14 | +// Check that the entry block arguments of a region are untouched in the case |
| 15 | +// of failure. |
| 16 | + |
| 17 | +// expected-remark@+1 {{applyPartialConversion failed}} |
| 18 | +module { |
| 19 | +func.func @fail_to_convert_region() { |
| 20 | + // CHECK: "test.region" |
| 21 | + // CHECK-NEXT: ^bb{{.*}}(%{{.*}}: i64): |
| 22 | + "test.region"() ({ |
| 23 | + ^bb1(%i0: i64): |
| 24 | + // expected-error@+1 {{failed to legalize operation 'test.region_builder'}} |
| 25 | + "test.region_builder"() : () -> () |
| 26 | + "test.valid"() : () -> () |
| 27 | + }) : () -> () |
| 28 | + return |
| 29 | +} |
| 30 | +} |
| 31 | + |
| 32 | +// ----- |
| 33 | + |
| 34 | +// CHECK-LABEL: @create_illegal_block |
| 35 | +func.func @create_illegal_block() { |
| 36 | + // Check that we can undo block creation, i.e. that the block was removed. |
| 37 | + // CHECK: test.create_illegal_block |
| 38 | + // CHECK-NOT: ^{{.*}}(%{{.*}}: i32, %{{.*}}: i32): |
| 39 | + // expected-remark@+1 {{op 'test.create_illegal_block' is not legalizable}} |
| 40 | + "test.create_illegal_block"() : () -> () |
| 41 | + |
| 42 | + // expected-remark@+1 {{op 'func.return' is not legalizable}} |
| 43 | + return |
| 44 | +} |
| 45 | + |
| 46 | +// ----- |
| 47 | + |
| 48 | +// CHECK-LABEL: @undo_block_arg_replace |
| 49 | +// expected-remark@+1{{applyPartialConversion failed}} |
| 50 | +module { |
| 51 | +func.func @undo_block_arg_replace() { |
| 52 | + // expected-error@+1{{failed to legalize operation 'test.block_arg_replace' that was explicitly marked illegal}} |
| 53 | + "test.block_arg_replace"() ({ |
| 54 | + ^bb0(%arg0: i32, %arg1: i16): |
| 55 | + // CHECK: ^bb0(%[[ARG0:.*]]: i32, %[[ARG1:.*]]: i16): |
| 56 | + // CHECK-NEXT: "test.return"(%[[ARG0]]) : (i32) |
| 57 | + |
| 58 | + "test.return"(%arg0) : (i32) -> () |
| 59 | + }) {trigger_rollback} : () -> () |
| 60 | + return |
| 61 | +} |
| 62 | +} |
| 63 | + |
| 64 | +// ----- |
| 65 | + |
| 66 | +// The op in this function is rewritten to itself (and thus remains illegal) by |
| 67 | +// a pattern that removes its second block after adding an operation into it. |
| 68 | +// Check that we can undo block removal successfully. |
| 69 | +// CHECK-LABEL: @undo_block_erase |
| 70 | +func.func @undo_block_erase() { |
| 71 | + // CHECK: test.undo_block_erase |
| 72 | + "test.undo_block_erase"() ({ |
| 73 | + // expected-remark@-1 {{not legalizable}} |
| 74 | + // CHECK: "unregistered.return"()[^[[BB:.*]]] |
| 75 | + "unregistered.return"()[^bb1] : () -> () |
| 76 | + // expected-remark@-1 {{not legalizable}} |
| 77 | + // CHECK: ^[[BB]] |
| 78 | + ^bb1: |
| 79 | + // CHECK: unregistered.return |
| 80 | + "unregistered.return"() : () -> () |
| 81 | + // expected-remark@-1 {{not legalizable}} |
| 82 | + }) : () -> () |
| 83 | +} |
| 84 | + |
| 85 | +// ----- |
| 86 | + |
| 87 | +// The op in this function is attempted to be rewritten to another illegal op |
| 88 | +// with an attached region containing an invalid terminator. The terminator is |
| 89 | +// created before the parent op. The deletion should not crash when deleting |
| 90 | +// created ops in the inverse order, i.e. deleting the parent op and then the |
| 91 | +// child op. |
| 92 | +// CHECK-LABEL: @undo_child_created_before_parent |
| 93 | +func.func @undo_child_created_before_parent() { |
| 94 | + // expected-remark@+1 {{is not legalizable}} |
| 95 | + "test.illegal_op_with_region_anchor"() : () -> () |
| 96 | + // expected-remark@+1 {{op 'func.return' is not legalizable}} |
| 97 | + return |
| 98 | +} |
| 99 | + |
| 100 | +// ----- |
| 101 | + |
| 102 | +// expected-remark@+1 {{applyPartialConversion failed}} |
| 103 | +builtin.module { |
| 104 | +func.func @create_unregistered_op_in_pattern() -> i32 { |
| 105 | + // expected-error@+1 {{failed to legalize operation 'test.illegal_op_g'}} |
| 106 | + %0 = "test.illegal_op_g"() : () -> (i32) |
| 107 | + "test.return"(%0) : (i32) -> () |
| 108 | +} |
| 109 | +} |
| 110 | + |
| 111 | +// ----- |
| 112 | + |
| 113 | +// CHECK-LABEL: func @test_move_op_before_rollback() |
| 114 | +func.func @test_move_op_before_rollback() { |
| 115 | + // CHECK: "test.one_region_op"() |
| 116 | + // CHECK: "test.hoist_me"() |
| 117 | + "test.one_region_op"() ({ |
| 118 | + // expected-remark @below{{'test.hoist_me' is not legalizable}} |
| 119 | + %0 = "test.hoist_me"() : () -> (i32) |
| 120 | + "test.valid"(%0) : (i32) -> () |
| 121 | + }) : () -> () |
| 122 | + "test.return"() : () -> () |
| 123 | +} |
| 124 | + |
| 125 | +// ----- |
| 126 | + |
| 127 | +// CHECK-LABEL: func @test_properties_rollback() |
| 128 | +func.func @test_properties_rollback() { |
| 129 | + // CHECK: test.with_properties a = 32, |
| 130 | + // expected-remark @below{{op 'test.with_properties' is not legalizable}} |
| 131 | + test.with_properties |
| 132 | + a = 32, b = "foo", c = "bar", flag = true, array = [1, 2, 3, 4], array32 = [5, 6] |
| 133 | + {modify_inplace} |
| 134 | + "test.return"() : () -> () |
| 135 | +} |
| 136 | + |
| 137 | +// ----- |
| 138 | + |
| 139 | +// expected-remark@+1 {{applyPartialConversion failed}} |
| 140 | +builtin.module { |
| 141 | +// Test that region cloning can be properly undone. |
| 142 | +func.func @test_undo_region_clone() { |
| 143 | + "test.region"() ({ |
| 144 | + ^bb1(%i0: i64): |
| 145 | + "test.invalid"(%i0) : (i64) -> () |
| 146 | + }) {legalizer.should_clone} : () -> () |
| 147 | + |
| 148 | + // expected-error@+1 {{failed to legalize operation 'test.illegal_op_f'}} |
| 149 | + %ignored = "test.illegal_op_f"() : () -> (i32) |
| 150 | + "test.return"() : () -> () |
| 151 | +} |
| 152 | +} |
| 153 | + |
| 154 | +// ----- |
| 155 | + |
| 156 | +// expected-remark@+1 {{applyPartialConversion failed}} |
| 157 | +builtin.module { |
| 158 | +func.func @create_unregistered_op_in_pattern() -> i32 { |
| 159 | + // expected-error@+1 {{failed to legalize operation 'test.illegal_op_g'}} |
| 160 | + %0 = "test.illegal_op_g"() : () -> (i32) |
| 161 | + "test.return"(%0) : (i32) -> () |
| 162 | +} |
| 163 | +} |
0 commit comments