brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.7 KiB · 4bcca6b Raw
185 lines · plain
1// RUN: mlir-opt -allow-unregistered-dialect -split-input-file -test-legalize-patterns -verify-diagnostics -profile-actions-to=- %s | FileCheck %s2 3// expected-remark@+1 {{applyPartialConversion failed}}4module {5func.func @fail_to_convert_illegal_op_in_region() {6  // expected-error@+1 {{failed to legalize operation 'test.region_builder'}}7  "test.region_builder"() : () -> ()8  return9}10}11 12// -----13 14// Check that the entry block arguments of a region are untouched in the case15// of failure.16 17// expected-remark@+1 {{applyPartialConversion failed}}18module {19func.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  return29}30}31 32// -----33 34// CHECK-LABEL: @create_illegal_block35func.func @create_illegal_block() {36  // Check that we can undo block creation, i.e. that the block was removed.37  // CHECK: test.create_illegal_block38  // 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  return44}45 46// -----47 48// CHECK-LABEL: @undo_block_arg_replace49// expected-remark@+1{{applyPartialConversion failed}}50module {51func.func @undo_block_arg_replace() {52  "test.legal_op"() ({53  ^bb0(%arg0: i32, %arg1: i16):54    // CHECK: ^bb0(%[[ARG0:.*]]: i32, %[[ARG1:.*]]: i16):55    // CHECK-NEXT: "test.value_replace"(%[[ARG0]], %[[ARG1]]) {trigger_rollback}56    // CHECK-NEXT: "test.return"(%[[ARG0]]) : (i32)57 58    // expected-error@+1{{failed to legalize operation 'test.value_replace' that was explicitly marked illegal}}59    "test.value_replace"(%arg0, %arg1) {trigger_rollback} : (i32, i16) -> ()60    "test.return"(%arg0) : (i32) -> ()61  }) : () -> ()62  return63}64}65 66// -----67 68// The op in this function is rewritten to itself (and thus remains illegal) by69// a pattern that removes its second block after adding an operation into it.70// Check that we can undo block removal successfully.71// CHECK-LABEL: @undo_block_erase72func.func @undo_block_erase() {73  // CHECK: test.undo_block_erase74  "test.undo_block_erase"() ({75    // expected-remark@-1 {{not legalizable}}76    // CHECK: "unregistered.return"()[^[[BB:.*]]]77    "unregistered.return"()[^bb1] : () -> ()78    // expected-remark@-1 {{not legalizable}}79  // CHECK: ^[[BB]]80  ^bb1:81    // CHECK: unregistered.return82    "unregistered.return"() : () -> ()83    // expected-remark@-1 {{not legalizable}}84  }) : () -> ()85}86 87// -----88 89// The op in this function is attempted to be rewritten to another illegal op90// with an attached region containing an invalid terminator. The terminator is91// created before the parent op. The deletion should not crash when deleting92// created ops in the inverse order, i.e. deleting the parent op and then the93// child op.94// CHECK-LABEL: @undo_child_created_before_parent95func.func @undo_child_created_before_parent() {96  // expected-remark@+1 {{is not legalizable}}97  "test.illegal_op_with_region_anchor"() : () -> ()98  // expected-remark@+1 {{op 'func.return' is not legalizable}}99  return100}101 102// -----103 104// expected-remark@+1 {{applyPartialConversion failed}}105builtin.module {106func.func @create_unregistered_op_in_pattern() -> i32 {107  // expected-error@+1 {{failed to legalize operation 'test.illegal_op_g'}}108  %0 = "test.illegal_op_g"() : () -> (i32)109  "test.return"(%0) : (i32) -> ()110}111}112 113// -----114 115// CHECK-LABEL: func @test_move_op_before_rollback()116func.func @test_move_op_before_rollback() {117  // CHECK: "test.one_region_op"()118  // CHECK: "test.hoist_me"()119  "test.one_region_op"() ({120    // expected-remark @below{{'test.hoist_me' is not legalizable}}121    %0 = "test.hoist_me"() : () -> (i32)122    "test.valid"(%0) : (i32) -> ()123  }) : () -> ()124  "test.return"() : () -> ()125}126 127// -----128 129// CHECK-LABEL: func @test_properties_rollback()130func.func @test_properties_rollback() {131  // CHECK: test.with_properties a = 32,132  // expected-remark @below{{op 'test.with_properties' is not legalizable}}133  test.with_properties134      a = 32, b = "foo", c = "bar", flag = true, array = [1, 2, 3, 4], array32 = [5, 6]135      {modify_inplace}136  "test.return"() : () -> ()137}138 139// -----140 141// expected-remark@+1 {{applyPartialConversion failed}}142builtin.module {143// Test that region cloning can be properly undone.144func.func @test_undo_region_clone() {145  "test.region"() ({146    ^bb1(%i0: i64):147      "test.invalid"(%i0) : (i64) -> ()148  }) {legalizer.should_clone} : () -> ()149 150  // expected-error@+1 {{failed to legalize operation 'test.illegal_op_f'}}151  %ignored = "test.illegal_op_f"() : () -> (i32)152  "test.return"() : () -> ()153}154}155 156// -----157 158// expected-remark@+1 {{applyPartialConversion failed}}159builtin.module {160func.func @create_unregistered_op_in_pattern() -> i32 {161  // expected-error@+1 {{failed to legalize operation 'test.illegal_op_g'}}162  %0 = "test.illegal_op_g"() : () -> (i32)163  "test.return"(%0) : (i32) -> ()164}165}166 167// -----168 169// CHECK-LABEL: func @test_failed_preorder_legalization170//       CHECK:   "test.post_order_legalization"() ({171//       CHECK:     %[[r:.*]] = "test.illegal_op_g"() : () -> i32172//       CHECK:     "test.return"(%[[r]]) : (i32) -> ()173//       CHECK:   }) : () -> ()174// expected-remark @+1 {{applyPartialConversion failed}}175module {176func.func @test_failed_preorder_legalization() {177  // expected-error @+1 {{failed to legalize operation 'test.post_order_legalization' that was explicitly marked illegal}}178  "test.post_order_legalization"() ({179    %0 = "test.illegal_op_g"() : () -> (i32)180    "test.return"(%0) : (i32) -> ()181  }) : () -> ()182  return183}184}185