337 lines · plain
1// RUN: mlir-opt %s -split-input-file -verify-diagnostics2 3//===----------------------------------------------------------------------===//4// pdl::ApplyNativeConstraintOp5//===----------------------------------------------------------------------===//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::ApplyNativeRewriteOp19//===----------------------------------------------------------------------===//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::AttributeOp33//===----------------------------------------------------------------------===//34 35pdl.pattern : benefit(1) {36 %type = type37 38 // expected-error@below {{expected only one of [`type`, `value`] to be set}}39 %attr = attribute : %type = 1040 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 = type51 52 // expected-error@below {{expected constant value when specified within a `pdl.rewrite`}}53 %attr = attribute : %type54 }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 = attribute64 }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 = attribute72 73 %op = operation "foo.op"74 rewrite %op with "rewriter"75}76 77// -----78 79//===----------------------------------------------------------------------===//80// pdl::OperandOp81//===----------------------------------------------------------------------===//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 = operand86 87 %op = operation "foo.op"88 rewrite %op with "rewriter"89}90 91// -----92 93//===----------------------------------------------------------------------===//94// pdl::OperandsOp95//===----------------------------------------------------------------------===//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 = operands100 101 %op = operation "foo.op"102 rewrite %op with "rewriter"103}104 105// -----106 107//===----------------------------------------------------------------------===//108// pdl::OperationOp109//===----------------------------------------------------------------------===//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 = operation116 }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 attributeValueNames = ["attr"],125 operandSegmentSizes = array<i32: 0, 0, 0>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 = type136 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::PatternOp171//===----------------------------------------------------------------------===//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 %op2203 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 = type210 %op1 = operation "foo.op" -> (%type : !pdl.type)211 %val = result 0 of %op1212 %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 %op1217 erase %op2218 erase %op3219 }220}221 222// -----223 224pdl.pattern : benefit(1) {225 %type = type : i32226 %root = operation "foo.op" -> (%type : !pdl.type)227 rewrite %root {228 %newOp = operation "foo.op" -> (%type : !pdl.type)229 %newResult = result 0 of %newOp230 231 // expected-error@below {{expected no replacement values to be provided when the replacement operation is present}}232 "pdl.replace"(%root, %newOp, %newResult) {233 operandSegmentSizes = array<i32: 1, 1, 1>234 } : (!pdl.operation, !pdl.operation, !pdl.value) -> ()235 }236}237 238// -----239 240//===----------------------------------------------------------------------===//241// pdl::RangeOp242//===----------------------------------------------------------------------===//243 244pdl.pattern : benefit(1) {245 %operand = pdl.operand246 %resultType = pdl.type247 %root = pdl.operation "baz.op"(%operand : !pdl.value) -> (%resultType : !pdl.type)248 249 rewrite %root {250 // expected-error @below {{expected operand to have element type '!pdl.value', but got '!pdl.type'}}251 %range = pdl.range %operand, %resultType : !pdl.value, !pdl.type252 }253}254 255// -----256 257//===----------------------------------------------------------------------===//258// pdl::ResultsOp259//===----------------------------------------------------------------------===//260 261pdl.pattern : benefit(1) {262 %root = operation "foo.op"263 // expected-error@below {{expected `pdl.range<value>` result type when no index is specified, but got: '!pdl.value'}}264 %results = "pdl.results"(%root) : (!pdl.operation) -> !pdl.value265 rewrite %root with "rewriter"266}267 268// -----269 270//===----------------------------------------------------------------------===//271// pdl::RewriteOp272//===----------------------------------------------------------------------===//273 274pdl.pattern : benefit(1) {275 %op = operation "foo.op"276 277 // expected-error@below {{expected rewrite region to be non-empty if external name is not specified}}278 "pdl.rewrite"(%op) ({}) {279 operandSegmentSizes = array<i32: 1,0>280 } : (!pdl.operation) -> ()281}282 283// -----284 285pdl.pattern : benefit(1) {286 %op = operation "foo.op"287 288 // expected-error@below {{expected no external arguments when the rewrite is specified inline}}289 "pdl.rewrite"(%op, %op) ({290 ^bb1:291 }) {292 operandSegmentSizes = array<i32: 1, 1>293 }: (!pdl.operation, !pdl.operation) -> ()294}295 296// -----297 298pdl.pattern : benefit(1) {299 %op = operation "foo.op"300 301 // expected-error@below {{expected rewrite region to be empty when rewrite is external}}302 "pdl.rewrite"(%op) ({303 ^bb1:304 }) {305 name = "foo",306 operandSegmentSizes = array<i32: 1,0>307 } : (!pdl.operation) -> ()308}309 310// -----311 312//===----------------------------------------------------------------------===//313// pdl::TypeOp314//===----------------------------------------------------------------------===//315 316pdl.pattern : benefit(1) {317 // expected-error@below {{expected a bindable user when defined in the matcher body of a `pdl.pattern`}}318 %unused = type319 320 %op = operation "foo.op"321 rewrite %op with "rewriter"322}323 324// -----325 326//===----------------------------------------------------------------------===//327// pdl::TypesOp328//===----------------------------------------------------------------------===//329 330pdl.pattern : benefit(1) {331 // expected-error@below {{expected a bindable user when defined in the matcher body of a `pdl.pattern`}}332 %unused = types333 334 %op = operation "foo.op"335 rewrite %op with "rewriter"336}337