1// RUN: mlir-opt %s -split-input-file -verify-diagnostics 2 3//===----------------------------------------------------------------------===// 4// pdl::ApplyConstraintOp 5//===----------------------------------------------------------------------===// 6 7pdl.pattern : benefit(1) { 8 %op = pdl.operation "foo.op" 9 10 // expected-error@below {{expected at least one argument}} 11 "pdl.apply_constraint"() {name = "foo", params = []} : () -> () 12 pdl.rewrite %op with "rewriter" 13} 14 15// ----- 16 17//===----------------------------------------------------------------------===// 18// pdl::AttributeOp 19//===----------------------------------------------------------------------===// 20 21pdl.pattern : benefit(1) { 22 %type = pdl.type 23 24 // expected-error@below {{expected only one of [`type`, `value`] to be set}} 25 %attr = pdl.attribute : %type 10 26 27 %op, %result = pdl.operation "foo.op" {"attr" = %attr} -> %type 28 pdl.rewrite %op with "rewriter" 29} 30 31// ----- 32 33pdl.pattern : benefit(1) { 34 %op = pdl.operation "foo.op" 35 pdl.rewrite %op { 36 %type = pdl.type 37 38 // expected-error@below {{expected constant value when specified within a `pdl.rewrite`}} 39 %attr = pdl.attribute : %type 40 } 41} 42 43// ----- 44 45pdl.pattern : benefit(1) { 46 %op = pdl.operation "foo.op" 47 pdl.rewrite %op { 48 // expected-error@below {{expected constant value when specified within a `pdl.rewrite`}} 49 %attr = pdl.attribute 50 } 51} 52 53// ----- 54 55pdl.pattern : benefit(1) { 56 // expected-error@below {{expected a bindable (i.e. `pdl.operation`) user when defined in the matcher body of a `pdl.pattern`}} 57 %unused = pdl.attribute 58 59 %op = pdl.operation "foo.op" 60 pdl.rewrite %op with "rewriter" 61} 62 63// ----- 64 65//===----------------------------------------------------------------------===// 66// pdl::InputOp 67//===----------------------------------------------------------------------===// 68 69pdl.pattern : benefit(1) { 70 // expected-error@below {{expected a bindable (i.e. `pdl.operation`) user when defined in the matcher body of a `pdl.pattern`}} 71 %unused = pdl.input 72 73 %op = pdl.operation "foo.op" 74 pdl.rewrite %op with "rewriter" 75} 76 77// ----- 78 79//===----------------------------------------------------------------------===// 80// pdl::OperationOp 81//===----------------------------------------------------------------------===// 82 83pdl.pattern : benefit(1) { 84 %op = pdl.operation "foo.op" 85 pdl.rewrite %op { 86 // expected-error@below {{must have an operation name when nested within a `pdl.rewrite`}} 87 %newOp = pdl.operation 88 } 89} 90 91// ----- 92 93pdl.pattern : benefit(1) { 94 // expected-error@below {{expected the same number of attribute values and attribute names, got 1 names and 0 values}} 95 %op = "pdl.operation"() { 96 attributeNames = ["attr"], 97 operand_segment_sizes = dense<0> : vector<3xi32> 98 } : () -> (!pdl.operation) 99 pdl.rewrite %op with "rewriter" 100} 101 102// ----- 103 104pdl.pattern : benefit(1) { 105 %op = pdl.operation "foo.op"() 106 pdl.rewrite %op { 107 %type = pdl.type 108 109 // expected-error@below {{op must have inferable or constrained result types when nested within `pdl.rewrite`}} 110 // expected-note@below {{result type #0 was not constrained}} 111 %newOp, %result = pdl.operation "foo.op" -> %type 112 } 113} 114 115// ----- 116 117pdl.pattern : benefit(1) { 118 // expected-error@below {{expected a bindable (i.e. `pdl.operation` or `pdl.rewrite`) user when defined in the matcher body of a `pdl.pattern`}} 119 %unused = pdl.operation "foo.op" 120 121 %op = pdl.operation "foo.op" 122 pdl.rewrite %op with "rewriter" 123} 124 125// ----- 126 127//===----------------------------------------------------------------------===// 128// pdl::PatternOp 129//===----------------------------------------------------------------------===// 130 131// expected-error@below {{expected body to terminate with `pdl.rewrite`}} 132pdl.pattern : benefit(1) { 133 // expected-note@below {{see terminator defined here}} 134 return 135} 136 137// ----- 138 139// expected-error@below {{expected only `pdl` operations within the pattern body}} 140pdl.pattern : benefit(1) { 141 // expected-note@below {{see non-`pdl` operation defined here}} 142 "foo.other_op"() : () -> () 143 144 %root = pdl.operation "foo.op" 145 pdl.rewrite %root with "foo" 146} 147 148// ----- 149 150//===----------------------------------------------------------------------===// 151// pdl::ReplaceOp 152//===----------------------------------------------------------------------===// 153 154pdl.pattern : benefit(1) { 155 %root = pdl.operation "foo.op" 156 pdl.rewrite %root { 157 %type = pdl.type : i32 158 %newOp, %newResult = pdl.operation "foo.op" -> %type 159 160 // expected-error@below {{to have the same number of results as the replacement operation}} 161 pdl.replace %root with %newOp 162 } 163} 164 165// ----- 166 167pdl.pattern : benefit(1) { 168 %type = pdl.type : i32 169 %root, %oldResult = pdl.operation "foo.op" -> %type 170 pdl.rewrite %root { 171 %newOp, %newResult = pdl.operation "foo.op" -> %type 172 173 // expected-error@below {{expected no replacement values to be provided when the replacement operation is present}} 174 "pdl.replace"(%root, %newOp, %newResult) { 175 operand_segment_sizes = dense<1> : vector<3xi32> 176 } : (!pdl.operation, !pdl.operation, !pdl.value) -> () 177 } 178} 179 180// ----- 181 182pdl.pattern : benefit(1) { 183 %root = pdl.operation "foo.op" 184 pdl.rewrite %root { 185 %type = pdl.type : i32 186 %newOp, %newResult = pdl.operation "foo.op" -> %type 187 188 // expected-error@below {{to have the same number of results as the provided replacement values}} 189 pdl.replace %root with (%newResult) 190 } 191} 192 193// ----- 194 195//===----------------------------------------------------------------------===// 196// pdl::RewriteOp 197//===----------------------------------------------------------------------===// 198 199pdl.pattern : benefit(1) { 200 %op = pdl.operation "foo.op" 201 202 // expected-error@below {{expected rewrite region to be non-empty if external name is not specified}} 203 "pdl.rewrite"(%op) ({}) : (!pdl.operation) -> () 204} 205 206// ----- 207 208pdl.pattern : benefit(1) { 209 %op = pdl.operation "foo.op" 210 211 // expected-error@below {{expected no external arguments when the rewrite is specified inline}} 212 "pdl.rewrite"(%op, %op) ({ 213 ^bb1: 214 pdl.rewrite_end 215 }) : (!pdl.operation, !pdl.operation) -> () 216} 217 218// ----- 219 220pdl.pattern : benefit(1) { 221 %op = pdl.operation "foo.op" 222 223 // expected-error@below {{expected no external constant parameters when the rewrite is specified inline}} 224 "pdl.rewrite"(%op) ({ 225 ^bb1: 226 pdl.rewrite_end 227 }) {externalConstParams = []} : (!pdl.operation) -> () 228} 229 230// ----- 231 232pdl.pattern : benefit(1) { 233 %op = pdl.operation "foo.op" 234 235 // expected-error@below {{expected rewrite region to be empty when rewrite is external}} 236 "pdl.rewrite"(%op) ({ 237 ^bb1: 238 pdl.rewrite_end 239 }) {name = "foo"} : (!pdl.operation) -> () 240} 241 242// ----- 243 244//===----------------------------------------------------------------------===// 245// pdl::TypeOp 246//===----------------------------------------------------------------------===// 247 248pdl.pattern : benefit(1) { 249 // expected-error@below {{expected a bindable (i.e. `pdl.attribute`, `pdl.input`, or `pdl.operation`) user when defined in the matcher body of a `pdl.pattern`}} 250 %unused = pdl.type 251 252 %op = pdl.operation "foo.op" 253 pdl.rewrite %op with "rewriter" 254} 255