1 // RUN: mlir-opt -allow-unregistered-dialect -test-legalize-patterns -test-legalize-mode=full -split-input-file -verify-diagnostics %s | FileCheck %s
3 // CHECK-LABEL: func @multi_level_mapping
4 func.func @multi_level_mapping() {
5 // CHECK: "test.type_producer"() : () -> f64
6 // CHECK: "test.type_consumer"(%{{.*}}) : (f64) -> ()
7 %result = "test.type_producer"() : () -> i32
8 "test.type_consumer"(%result) : (i32) -> ()
9 "test.return"() : () -> ()
12 // Test that operations that are erased don't need to be legalized.
13 // CHECK-LABEL: func @dropped_region_with_illegal_ops
14 func.func @dropped_region_with_illegal_ops() {
15 // CHECK-NEXT: test.return
16 "test.drop_region_op"() ({
17 %ignored = "test.illegal_op_f"() : () -> (i32)
18 "test.return"() : () -> ()
20 "test.return"() : () -> ()
22 // CHECK-LABEL: func @replace_non_root_illegal_op
23 func.func @replace_non_root_illegal_op() {
24 // CHECK-NEXT: "test.legal_op_b"
25 // CHECK-NEXT: test.return
26 %result = "test.replace_non_root"() : () -> (i32)
27 "test.return"() : () -> ()
32 // Test that children of recursively legal operations are ignored.
33 func.func @recursively_legal_invalid_op() {
34 /// Operation that is statically legal.
35 builtin.module attributes {test.recursively_legal} {
36 %ignored = "test.illegal_op_f"() : () -> (i32)
38 /// Operation that is dynamically legal, i.e. the function has a pattern
39 /// applied to legalize the argument type before it becomes recursively legal.
41 func.func @dynamic_func(%arg: i64) attributes {test.recursively_legal} {
42 %ignored = "test.illegal_op_f"() : () -> (i32)
43 "test.return"() : () -> ()
47 "test.return"() : () -> ()
52 // expected-remark@+1 {{applyFullConversion failed}}
55 // Test that region cloning can be properly undone.
56 func.func @test_undo_region_clone() {
59 "test.invalid"(%i0) : (i64) -> ()
60 }) {legalizer.should_clone} : () -> ()
62 // expected-error@+1 {{failed to legalize operation 'test.illegal_op_f'}}
63 %ignored = "test.illegal_op_f"() : () -> (i32)
64 "test.return"() : () -> ()
71 // expected-remark@+1 {{applyFullConversion failed}}
74 // Test that unknown operations can be dynamically legal.
75 func.func @test_unknown_dynamically_legal() {
76 "foo.unknown_op"() {test.dynamically_legal} : () -> ()
78 // expected-error@+1 {{failed to legalize operation 'foo.unknown_op'}}
79 "foo.unknown_op"() {} : () -> ()
80 "test.return"() : () -> ()
87 // expected-remark@+1 {{applyFullConversion failed}}
90 // Test that region inlining can be properly undone.
91 func.func @test_undo_region_inline() {
94 // expected-error@+1 {{failed to legalize operation 'cf.br'}}
97 "test.invalid"(%i1) : (i64) -> ()
100 "test.return"() : () -> ()
107 // expected-remark@+1 {{applyFullConversion failed}}
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'}}
115 cf.br ^bb3(%i0 : i64)
117 "test.invalid"(%i1) : (i64) -> ()
119 cf.br ^bb2(%i2 : i64)
120 }) {legalizer.should_clone, legalizer.erase_old_blocks} : () -> ()
122 "test.return"() : () -> ()
129 // expected-remark@+1 {{applyFullConversion failed}}
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) -> ()