Skip to content

Commit acc8b97

Browse files
[mlir][Transforms][NFC] Move rollback tests to separate file (#151809)
Move dialect conversion tests that require a rollback to a separate file. This is in preparation of the One-Shot Dialect Conversion refactoring, which does no longer support rollbacks. Also add a few more `CHECK:`.
1 parent 8346215 commit acc8b97

File tree

4 files changed

+233
-216
lines changed

4 files changed

+233
-216
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// RUN: mlir-opt -allow-unregistered-dialect -test-legalize-patterns="test-legalize-mode=full" -split-input-file -verify-diagnostics %s
2+
3+
// Test that region inlining can be properly undone.
4+
5+
// CHECK-LABEL: func @test_undo_region_inline() {
6+
// CHECK: "test.region"() ({
7+
// CHECK: ^{{.*}}(%[[arg0:.*]]: i64):
8+
// CHECK: cf.br ^[[bb1:.*]](%[[arg0]] : i64)
9+
// CHECK: ^[[bb1]](%[[arg1:.*]]: i64):
10+
// CHECK: "test.invalid"(%[[arg1]]) : (i64) -> ()
11+
// CHECK: }) : () -> ()
12+
// CHECK: "test.return"() : () -> ()
13+
// CHECK: }
14+
15+
// expected-remark@+1 {{applyFullConversion failed}}
16+
builtin.module {
17+
func.func @test_undo_region_inline() {
18+
"test.region"() ({
19+
^bb1(%i0: i64):
20+
// expected-error@+1 {{failed to legalize operation 'cf.br'}}
21+
cf.br ^bb2(%i0 : i64)
22+
^bb2(%i1: i64):
23+
"test.invalid"(%i1) : (i64) -> ()
24+
}) {} : () -> ()
25+
26+
"test.return"() : () -> ()
27+
}
28+
}
29+
30+
// -----
31+
32+
// Test that multiple block erases can be properly undone.
33+
34+
// CHECK-LABEL: func @test_undo_block_erase() {
35+
// CHECK: "test.region"() ({
36+
// CHECK: ^{{.*}}(%[[arg0:.*]]: i64):
37+
// CHECK: cf.br ^[[bb2:.*]](%[[arg0]] : i64)
38+
// CHECK: ^[[bb1:.*]](%[[arg1:.*]]: i64):
39+
// CHECK: "test.invalid"(%[[arg1]]) : (i64) -> ()
40+
// CHECK: ^[[bb2]](%[[arg2:.*]]: i64):
41+
// CHECK: cf.br ^[[bb1]](%[[arg2]] : i64)
42+
// CHECK: }) {legalizer.erase_old_blocks, legalizer.should_clone} : () -> ()
43+
// CHECK: "test.return"() : () -> ()
44+
// CHECK: }
45+
46+
// expected-remark@+1 {{applyFullConversion failed}}
47+
builtin.module {
48+
func.func @test_undo_block_erase() {
49+
// expected-error@+1 {{failed to legalize operation 'test.region'}}
50+
"test.region"() ({
51+
^bb1(%i0: i64):
52+
cf.br ^bb3(%i0 : i64)
53+
^bb2(%i1: i64):
54+
"test.invalid"(%i1) : (i64) -> ()
55+
^bb3(%i2: i64):
56+
cf.br ^bb2(%i2 : i64)
57+
}) {legalizer.should_clone, legalizer.erase_old_blocks} : () -> ()
58+
"test.return"() : () -> ()
59+
}
60+
}

mlir/test/Transforms/test-legalizer-full.mlir

Lines changed: 10 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ func.func @multi_level_mapping() {
99
"test.return"() : () -> ()
1010
}
1111

12+
// -----
13+
1214
// Test that operations that are erased don't need to be legalized.
1315
// CHECK-LABEL: func @dropped_region_with_illegal_ops
1416
func.func @dropped_region_with_illegal_ops() {
@@ -19,6 +21,9 @@ func.func @dropped_region_with_illegal_ops() {
1921
}) : () -> ()
2022
"test.return"() : () -> ()
2123
}
24+
25+
// -----
26+
2227
// CHECK-LABEL: func @replace_non_root_illegal_op
2328
func.func @replace_non_root_illegal_op() {
2429
// CHECK-NEXT: "test.legal_op_b"
@@ -30,15 +35,20 @@ func.func @replace_non_root_illegal_op() {
3035
// -----
3136

3237
// Test that children of recursively legal operations are ignored.
38+
39+
// CHECK-LABEL: func @recursively_legal_invalid_op
3340
func.func @recursively_legal_invalid_op() {
3441
/// Operation that is statically legal.
3542
builtin.module attributes {test.recursively_legal} {
43+
// CHECK: "test.illegal_op_f"
3644
%ignored = "test.illegal_op_f"() : () -> (i32)
3745
}
3846
/// Operation that is dynamically legal, i.e. the function has a pattern
3947
/// applied to legalize the argument type before it becomes recursively legal.
4048
builtin.module {
49+
// CHECK: func @dynamic_func(%{{.*}}: f64)
4150
func.func @dynamic_func(%arg: i64) attributes {test.recursively_legal} {
51+
// CHECK: "test.illegal_op_f"
4252
%ignored = "test.illegal_op_f"() : () -> (i32)
4353
"test.return"() : () -> ()
4454
}
@@ -49,25 +59,6 @@ func.func @recursively_legal_invalid_op() {
4959

5060
// -----
5161

52-
// expected-remark@+1 {{applyFullConversion failed}}
53-
builtin.module {
54-
55-
// Test that region cloning can be properly undone.
56-
func.func @test_undo_region_clone() {
57-
"test.region"() ({
58-
^bb1(%i0: i64):
59-
"test.invalid"(%i0) : (i64) -> ()
60-
}) {legalizer.should_clone} : () -> ()
61-
62-
// expected-error@+1 {{failed to legalize operation 'test.illegal_op_f'}}
63-
%ignored = "test.illegal_op_f"() : () -> (i32)
64-
"test.return"() : () -> ()
65-
}
66-
67-
}
68-
69-
// -----
70-
7162
// expected-remark@+1 {{applyFullConversion failed}}
7263
builtin.module {
7364

@@ -81,58 +72,3 @@ builtin.module {
8172
}
8273

8374
}
84-
85-
// -----
86-
87-
// expected-remark@+1 {{applyFullConversion failed}}
88-
builtin.module {
89-
90-
// Test that region inlining can be properly undone.
91-
func.func @test_undo_region_inline() {
92-
"test.region"() ({
93-
^bb1(%i0: i64):
94-
// expected-error@+1 {{failed to legalize operation 'cf.br'}}
95-
cf.br ^bb2(%i0 : i64)
96-
^bb2(%i1: i64):
97-
"test.invalid"(%i1) : (i64) -> ()
98-
}) {} : () -> ()
99-
100-
"test.return"() : () -> ()
101-
}
102-
103-
}
104-
105-
// -----
106-
107-
// expected-remark@+1 {{applyFullConversion failed}}
108-
builtin.module {
109-
110-
// Test that multiple block erases can be properly undone.
111-
func.func @test_undo_block_erase() {
112-
// expected-error@+1 {{failed to legalize operation 'test.region'}}
113-
"test.region"() ({
114-
^bb1(%i0: i64):
115-
cf.br ^bb3(%i0 : i64)
116-
^bb2(%i1: i64):
117-
"test.invalid"(%i1) : (i64) -> ()
118-
^bb3(%i2: i64):
119-
cf.br ^bb2(%i2 : i64)
120-
}) {legalizer.should_clone, legalizer.erase_old_blocks} : () -> ()
121-
122-
"test.return"() : () -> ()
123-
}
124-
125-
}
126-
127-
// -----
128-
129-
// expected-remark@+1 {{applyFullConversion failed}}
130-
builtin.module {
131-
132-
func.func @create_unregistered_op_in_pattern() -> i32 {
133-
// expected-error@+1 {{failed to legalize operation 'test.illegal_op_g'}}
134-
%0 = "test.illegal_op_g"() : () -> (i32)
135-
"test.return"(%0) : (i32) -> ()
136-
}
137-
138-
}
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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

Comments
 (0)