1// RUN: mlir-opt %s -split-input-file -verify-diagnostics 2 3//===----------------------------------------------------------------------===// 4// pdl::ApplyNativeConstraintOp 5//===----------------------------------------------------------------------===// 6 7pdl.pattern : benefit(1) { 8 %op = operation "foo.op" 9 10 // expected-error@below {{expected at least one argument}} 11 "pdl.apply_native_constraint"() {name = "foo"} : () -> () 12 rewrite %op with "rewriter" 13} 14 15// ----- 16 17//===----------------------------------------------------------------------===// 18// pdl::ApplyNativeRewriteOp 19//===----------------------------------------------------------------------===// 20 21pdl.pattern : benefit(1) { 22 %op = operation "foo.op" 23 rewrite %op { 24 // expected-error@below {{expected at least one argument}} 25 "pdl.apply_native_rewrite"() {name = "foo"} : () -> () 26 } 27} 28 29// ----- 30 31//===----------------------------------------------------------------------===// 32// pdl::AttributeOp 33//===----------------------------------------------------------------------===// 34 35pdl.pattern : benefit(1) { 36 %type = type 37 38 // expected-error@below {{expected only one of [`type`, `value`] to be set}} 39 %attr = attribute : %type = 10 40 41 %op = operation "foo.op" {"attr" = %attr} -> (%type : !pdl.type) 42 rewrite %op with "rewriter" 43} 44 45// ----- 46 47pdl.pattern : benefit(1) { 48 %op = operation "foo.op" 49 rewrite %op { 50 %type = type 51 52 // expected-error@below {{expected constant value when specified within a `pdl.rewrite`}} 53 %attr = attribute : %type 54 } 55} 56 57// ----- 58 59pdl.pattern : benefit(1) { 60 %op = operation "foo.op" 61 rewrite %op { 62 // expected-error@below {{expected constant value when specified within a `pdl.rewrite`}} 63 %attr = attribute 64 } 65} 66 67// ----- 68 69pdl.pattern : benefit(1) { 70 // expected-error@below {{expected a bindable user when defined in the matcher body of a `pdl.pattern`}} 71 %unused = attribute 72 73 %op = operation "foo.op" 74 rewrite %op with "rewriter" 75} 76 77// ----- 78 79//===----------------------------------------------------------------------===// 80// pdl::OperandOp 81//===----------------------------------------------------------------------===// 82 83pdl.pattern : benefit(1) { 84 // expected-error@below {{expected a bindable user when defined in the matcher body of a `pdl.pattern`}} 85 %unused = operand 86 87 %op = operation "foo.op" 88 rewrite %op with "rewriter" 89} 90 91// ----- 92 93//===----------------------------------------------------------------------===// 94// pdl::OperandsOp 95//===----------------------------------------------------------------------===// 96 97pdl.pattern : benefit(1) { 98 // expected-error@below {{expected a bindable user when defined in the matcher body of a `pdl.pattern`}} 99 %unused = operands 100 101 %op = operation "foo.op" 102 rewrite %op with "rewriter" 103} 104 105// ----- 106 107//===----------------------------------------------------------------------===// 108// pdl::OperationOp 109//===----------------------------------------------------------------------===// 110 111pdl.pattern : benefit(1) { 112 %op = operation "foo.op" 113 rewrite %op { 114 // expected-error@below {{must have an operation name when nested within a `pdl.rewrite`}} 115 %newOp = operation 116 } 117} 118 119// ----- 120 121pdl.pattern : benefit(1) { 122 // expected-error@below {{expected the same number of attribute values and attribute names, got 1 names and 0 values}} 123 %op = "pdl.operation"() { 124 attributeNames = ["attr"], 125 operand_segment_sizes = dense<0> : vector<3xi32> 126 } : () -> (!pdl.operation) 127 rewrite %op with "rewriter" 128} 129 130// ----- 131 132pdl.pattern : benefit(1) { 133 %op = operation "foo.op" 134 rewrite %op { 135 %type = type 136 137 // expected-error@below {{op must have inferable or constrained result types when nested within `pdl.rewrite`}} 138 // expected-note@below {{result type #0 was not constrained}} 139 %newOp = operation "builtin.unrealized_conversion_cast" -> (%type : !pdl.type) 140 } 141} 142 143// ----- 144 145// Unused operation only necessary to ensure the func dialect is loaded. 146func.func private @unusedOpToLoadFuncDialect() 147 148pdl.pattern : benefit(1) { 149 %op = operation "foo.op" 150 rewrite %op { 151 // expected-error@below {{op must have inferable or constrained result types when nested within `pdl.rewrite`}} 152 // expected-note@below {{operation is created in a non-inferrable context, but 'func.constant' does not implement InferTypeOpInterface}} 153 %newOp = operation "func.constant" 154 } 155} 156 157// ----- 158 159pdl.pattern : benefit(1) { 160 // expected-error@below {{expected a bindable user when defined in the matcher body of a `pdl.pattern`}} 161 %unused = operation "foo.op" 162 163 %op = operation "foo.op" 164 rewrite %op with "rewriter" 165} 166 167// ----- 168 169//===----------------------------------------------------------------------===// 170// pdl::PatternOp 171//===----------------------------------------------------------------------===// 172 173// expected-error@below {{expected body to terminate with `pdl.rewrite`}} 174pdl.pattern : benefit(1) { 175 // expected-note@below {{see terminator defined here}} 176 "test.finish" () : () -> () 177} 178 179// ----- 180 181// expected-error@below {{the pattern must contain at least one `pdl.operation`}} 182pdl.pattern : benefit(1) { 183 rewrite with "foo" 184} 185 186// ----- 187// expected-error@below {{expected only `pdl` operations within the pattern body}} 188pdl.pattern : benefit(1) { 189 // expected-note@below {{see non-`pdl` operation defined here}} 190 "test.foo.other_op"() : () -> () 191 192 %root = operation "foo.op" 193 rewrite %root with "foo" 194} 195 196// ----- 197// expected-error@below {{the operations must form a connected component}} 198pdl.pattern : benefit(1) { 199 %op1 = operation "foo.op" 200 %op2 = operation "bar.op" 201 // expected-note@below {{see a disconnected value / operation here}} 202 %val = result 0 of %op2 203 rewrite %op1 with "foo"(%val : !pdl.value) 204} 205 206// ----- 207// expected-error@below {{the operations must form a connected component}} 208pdl.pattern : benefit(1) { 209 %type = type 210 %op1 = operation "foo.op" -> (%type : !pdl.type) 211 %val = result 0 of %op1 212 %op2 = operation "bar.op"(%val : !pdl.value) 213 // expected-note@below {{see a disconnected value / operation here}} 214 %op3 = operation "baz.op" 215 rewrite { 216 erase %op1 217 erase %op2 218 erase %op3 219 } 220} 221 222// ----- 223 224pdl.pattern : benefit(1) { 225 %type = type : i32 226 %root = operation "foo.op" -> (%type : !pdl.type) 227 rewrite %root { 228 %newOp = operation "foo.op" -> (%type : !pdl.type) 229 %newResult = result 0 of %newOp 230 231 // expected-error@below {{expected no replacement values to be provided when the replacement operation is present}} 232 "pdl.replace"(%root, %newOp, %newResult) { 233 operand_segment_sizes = dense<1> : vector<3xi32> 234 } : (!pdl.operation, !pdl.operation, !pdl.value) -> () 235 } 236} 237 238// ----- 239 240//===----------------------------------------------------------------------===// 241// pdl::ResultsOp 242//===----------------------------------------------------------------------===// 243 244pdl.pattern : benefit(1) { 245 %root = operation "foo.op" 246 // expected-error@below {{expected `pdl.range<value>` result type when no index is specified, but got: '!pdl.value'}} 247 %results = "pdl.results"(%root) : (!pdl.operation) -> !pdl.value 248 rewrite %root with "rewriter" 249} 250 251// ----- 252 253//===----------------------------------------------------------------------===// 254// pdl::RewriteOp 255//===----------------------------------------------------------------------===// 256 257pdl.pattern : benefit(1) { 258 %op = operation "foo.op" 259 260 // expected-error@below {{expected rewrite region to be non-empty if external name is not specified}} 261 "pdl.rewrite"(%op) ({}) { 262 operand_segment_sizes = dense<[1,0]> : vector<2xi32> 263 } : (!pdl.operation) -> () 264} 265 266// ----- 267 268pdl.pattern : benefit(1) { 269 %op = operation "foo.op" 270 271 // expected-error@below {{expected no external arguments when the rewrite is specified inline}} 272 "pdl.rewrite"(%op, %op) ({ 273 ^bb1: 274 }) { 275 operand_segment_sizes = dense<1> : vector<2xi32> 276 }: (!pdl.operation, !pdl.operation) -> () 277} 278 279// ----- 280 281pdl.pattern : benefit(1) { 282 %op = operation "foo.op" 283 284 // expected-error@below {{expected rewrite region to be empty when rewrite is external}} 285 "pdl.rewrite"(%op) ({ 286 ^bb1: 287 }) { 288 name = "foo", 289 operand_segment_sizes = dense<[1,0]> : vector<2xi32> 290 } : (!pdl.operation) -> () 291} 292 293// ----- 294 295//===----------------------------------------------------------------------===// 296// pdl::TypeOp 297//===----------------------------------------------------------------------===// 298 299pdl.pattern : benefit(1) { 300 // expected-error@below {{expected a bindable user when defined in the matcher body of a `pdl.pattern`}} 301 %unused = type 302 303 %op = operation "foo.op" 304 rewrite %op with "rewriter" 305} 306 307// ----- 308 309//===----------------------------------------------------------------------===// 310// pdl::TypesOp 311//===----------------------------------------------------------------------===// 312 313pdl.pattern : benefit(1) { 314 // expected-error@below {{expected a bindable user when defined in the matcher body of a `pdl.pattern`}} 315 %unused = types 316 317 %op = operation "foo.op" 318 rewrite %op with "rewriter" 319} 320