1// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -verify-diagnostics | FileCheck %s 2// Verify that extensible dialects can register dynamic operations and types. 3 4//===----------------------------------------------------------------------===// 5// Dynamic type 6//===----------------------------------------------------------------------===// 7 8// CHECK-LABEL: func @succeededDynamicTypeVerifier 9func.func @succeededDynamicTypeVerifier() { 10 // CHECK: %{{.*}} = "unregistered_op"() : () -> !test.dynamic_singleton 11 "unregistered_op"() : () -> !test.dynamic_singleton 12 // CHECK-NEXT: "unregistered_op"() : () -> !test.dynamic_pair<i32, f64> 13 "unregistered_op"() : () -> !test.dynamic_pair<i32, f64> 14 // CHECK-NEXT: %{{.*}} = "unregistered_op"() : () -> !test.dynamic_pair<!test.dynamic_pair<i32, f64>, !test.dynamic_singleton> 15 "unregistered_op"() : () -> !test.dynamic_pair<!test.dynamic_pair<i32, f64>, !test.dynamic_singleton> 16 return 17} 18 19// ----- 20 21func.func @failedDynamicTypeVerifier() { 22 // expected-error@+1 {{expected 0 type arguments, but had 1}} 23 "unregistered_op"() : () -> !test.dynamic_singleton<f64> 24 return 25} 26 27// ----- 28 29func.func @failedDynamicTypeVerifier2() { 30 // expected-error@+1 {{expected 2 type arguments, but had 1}} 31 "unregistered_op"() : () -> !test.dynamic_pair<f64> 32 return 33} 34 35// ----- 36 37// CHECK-LABEL: func @customTypeParserPrinter 38func.func @customTypeParserPrinter() { 39 // CHECK: "unregistered_op"() : () -> !test.dynamic_custom_assembly_format<f32:f64> 40 "unregistered_op"() : () -> !test.dynamic_custom_assembly_format<f32 : f64> 41 return 42} 43 44// ----- 45 46//===----------------------------------------------------------------------===// 47// Dynamic attribute 48//===----------------------------------------------------------------------===// 49 50// CHECK-LABEL: func @succeededDynamicAttributeVerifier 51func.func @succeededDynamicAttributeVerifier() { 52 // CHECK: "unregistered_op"() {test_attr = #test.dynamic_singleton} : () -> () 53 "unregistered_op"() {test_attr = #test.dynamic_singleton} : () -> () 54 // CHECK-NEXT: "unregistered_op"() {test_attr = #test.dynamic_pair<3 : i32, 5 : i32>} : () -> () 55 "unregistered_op"() {test_attr = #test.dynamic_pair<3 : i32, 5 : i32>} : () -> () 56 // CHECK-NEXT: "unregistered_op"() {test_attr = #test.dynamic_pair<#test.dynamic_pair<3 : i32, 5 : i32>, f64>} : () -> () 57 "unregistered_op"() {test_attr = #test.dynamic_pair<#test.dynamic_pair<3 : i32, 5 : i32>, f64>} : () -> () 58 return 59} 60 61// ----- 62 63func.func @failedDynamicAttributeVerifier() { 64 // expected-error@+1 {{expected 0 attribute arguments, but had 1}} 65 "unregistered_op"() {test_attr = #test.dynamic_singleton<f64>} : () -> () 66 return 67} 68 69// ----- 70 71func.func @failedDynamicAttributeVerifier2() { 72 // expected-error@+1 {{expected 2 attribute arguments, but had 1}} 73 "unregistered_op"() {test_attr = #test.dynamic_pair<f64>} : () -> () 74 return 75} 76 77// ----- 78 79// CHECK-LABEL: func @customAttributeParserPrinter 80func.func @customAttributeParserPrinter() { 81 // CHECK: "unregistered_op"() {test_attr = #test.dynamic_custom_assembly_format<f32:f64>} : () -> () 82 "unregistered_op"() {test_attr = #test.dynamic_custom_assembly_format<f32:f64>} : () -> () 83 return 84} 85 86//===----------------------------------------------------------------------===// 87// Dynamic op 88//===----------------------------------------------------------------------===// 89 90// ----- 91 92// CHECK-LABEL: func @succeededDynamicOpVerifier 93func.func @succeededDynamicOpVerifier(%a: f32) { 94 // CHECK: "test.dynamic_generic"() : () -> () 95 // CHECK-NEXT: %{{.*}} = "test.dynamic_generic"(%{{.*}}) : (f32) -> f64 96 // CHECK-NEXT: %{{.*}}:2 = "test.dynamic_one_operand_two_results"(%{{.*}}) : (f32) -> (f64, f64) 97 "test.dynamic_generic"() : () -> () 98 "test.dynamic_generic"(%a) : (f32) -> f64 99 "test.dynamic_one_operand_two_results"(%a) : (f32) -> (f64, f64) 100 return 101} 102 103// ----- 104 105func.func @failedDynamicOpVerifier() { 106 // expected-error@+1 {{expected 1 operand, but had 0}} 107 "test.dynamic_one_operand_two_results"() : () -> (f64, f64) 108 return 109} 110 111// ----- 112 113func.func @failedDynamicOpVerifier2(%a: f32) { 114 // expected-error@+1 {{expected 2 results, but had 0}} 115 "test.dynamic_one_operand_two_results"(%a) : (f32) -> () 116 return 117} 118 119// ----- 120 121// CHECK-LABEL: func @customOpParserPrinter 122func.func @customOpParserPrinter() { 123 // CHECK: test.dynamic_custom_parser_printer custom_keyword 124 test.dynamic_custom_parser_printer custom_keyword 125 return 126} 127 128//===----------------------------------------------------------------------===// 129// Dynamic dialect 130//===----------------------------------------------------------------------===// 131 132// ----- 133 134// Check that the verifier of a dynamic operation in a dynamic dialect 135// can fail. This shows that the dialect is correctly registered. 136 137func.func @failedDynamicDialectOpVerifier() { 138 // expected-error@+1 {{expected a single result, no operands and no regions}} 139 "test_dyn.one_result"() : () -> () 140 return 141} 142