1 // RUN: mlir-opt %s --irdl-file=%S/testd.irdl.mlir -split-input-file -verify-diagnostics | FileCheck %s
3 //===----------------------------------------------------------------------===//
4 // Type or attribute constraint
5 //===----------------------------------------------------------------------===//
7 func.func @typeFitsType() {
8 // CHECK: "testd.any"() : () -> !testd.parametric<i32>
9 "testd.any"() : () -> !testd.parametric<i32>
15 func.func @attrDoesntFitType() {
16 "testd.any"() : () -> !testd.parametric<"foo">
22 func.func @attrFitsAttr() {
23 // CHECK: "testd.any"() : () -> !testd.attr_in_type_out<"foo">
24 "testd.any"() : () -> !testd.attr_in_type_out<"foo">
30 func.func @typeFitsAttr() {
31 // CHECK: "testd.any"() : () -> !testd.attr_in_type_out<i32>
32 "testd.any"() : () -> !testd.attr_in_type_out<i32>
38 //===----------------------------------------------------------------------===//
39 // Equality constraint
40 //===----------------------------------------------------------------------===//
42 func.func @succeededEqConstraint() {
43 // CHECK: "testd.eq"() : () -> i32
44 "testd.eq"() : () -> i32
50 func.func @failedEqConstraint() {
51 // expected-error@+1 {{expected 'i32' but got 'i64'}}
52 "testd.eq"() : () -> i64
58 //===----------------------------------------------------------------------===//
60 //===----------------------------------------------------------------------===//
62 func.func @succeededAnyOfConstraint() {
63 // CHECK: "testd.anyof"() : () -> i32
64 "testd.anyof"() : () -> i32
65 // CHECK: "testd.anyof"() : () -> i64
66 "testd.anyof"() : () -> i64
72 func.func @failedAnyOfConstraint() {
73 // expected-error@+1 {{'i1' does not satisfy the constraint}}
74 "testd.anyof"() : () -> i1
80 //===----------------------------------------------------------------------===//
82 //===----------------------------------------------------------------------===//
84 func.func @succeededAllOfConstraint() {
85 // CHECK: "testd.all_of"() : () -> i64
86 "testd.all_of"() : () -> i64
92 func.func @failedAllOfConstraint1() {
93 // expected-error@+1 {{'i1' does not satisfy the constraint}}
94 "testd.all_of"() : () -> i1
100 func.func @failedAllOfConstraint2() {
101 // expected-error@+1 {{expected 'i64' but got 'i32'}}
102 "testd.all_of"() : () -> i32
108 //===----------------------------------------------------------------------===//
110 //===----------------------------------------------------------------------===//
112 func.func @succeededAnyConstraint() {
113 // CHECK: "testd.any"() : () -> i32
114 "testd.any"() : () -> i32
115 // CHECK: "testd.any"() : () -> i64
116 "testd.any"() : () -> i64
122 //===----------------------------------------------------------------------===//
124 //===----------------------------------------------------------------------===//
126 func.func @succeededDynBaseConstraint() {
127 // CHECK: "testd.dyn_type_base"() : () -> !testd.parametric<i32>
128 "testd.dyn_type_base"() : () -> !testd.parametric<i32>
129 // CHECK: "testd.dyn_type_base"() : () -> !testd.parametric<i64>
130 "testd.dyn_type_base"() : () -> !testd.parametric<i64>
131 // CHECK: "testd.dyn_type_base"() : () -> !testd.parametric<!testd.parametric<i64>>
132 "testd.dyn_type_base"() : () -> !testd.parametric<!testd.parametric<i64>>
133 // CHECK: "testd.dyn_attr_base"() {attr1 = #testd.parametric_attr<i32>} : () -> ()
134 "testd.dyn_attr_base"() {attr1 = #testd.parametric_attr<i32>} : () -> ()
135 // CHECK: "testd.dyn_attr_base"() {attr1 = #testd.parametric_attr<i64>} : () -> ()
136 "testd.dyn_attr_base"() {attr1 = #testd.parametric_attr<i64>} : () -> ()
142 func.func @failedDynTypeBaseConstraint() {
143 // expected-error@+1 {{expected base type 'testd.parametric' but got 'builtin.integer'}}
144 "testd.dyn_type_base"() : () -> i32
150 func.func @failedDynAttrBaseConstraintNotType() {
151 // expected-error@+1 {{expected base attribute 'testd.parametric_attr' but got 'builtin.type'}}
152 "testd.dyn_attr_base"() {attr1 = i32}: () -> ()
159 func.func @succeededNamedBaseConstraint() {
160 // CHECK: "testd.named_type_base"() : () -> i32
161 "testd.named_type_base"() : () -> i32
162 // CHECK: "testd.named_type_base"() : () -> i64
163 "testd.named_type_base"() : () -> i64
164 // CHECK: "testd.named_attr_base"() {attr1 = 0 : i32} : () -> ()
165 "testd.named_attr_base"() {attr1 = 0 : i32} : () -> ()
166 // CHECK: "testd.named_attr_base"() {attr1 = 0 : i64} : () -> ()
167 "testd.named_attr_base"() {attr1 = 0 : i64} : () -> ()
173 func.func @failedNamedTypeBaseConstraint() {
174 // expected-error@+1 {{expected base type 'builtin.integer' but got 'builtin.vector'}}
175 "testd.named_type_base"() : () -> vector<i32>
181 func.func @failedDynAttrBaseConstraintNotType() {
182 // expected-error@+1 {{expected base attribute 'builtin.integer' but got 'builtin.type'}}
183 "testd.named_attr_base"() {attr1 = i32}: () -> ()
189 //===----------------------------------------------------------------------===//
190 // Dynamic parameters constraint
191 //===----------------------------------------------------------------------===//
193 func.func @succeededDynParamsConstraint() {
194 // CHECK: "testd.dynparams"() : () -> !testd.parametric<i32>
195 "testd.dynparams"() : () -> !testd.parametric<i32>
196 // CHECK: "testd.dynparams"() : () -> !testd.parametric<i64>
197 "testd.dynparams"() : () -> !testd.parametric<i64>
203 func.func @failedDynParamsConstraintBase() {
204 // expected-error@+1 {{expected base type 'testd.parametric' but got 'i32'}}
205 "testd.dynparams"() : () -> i32
211 func.func @failedDynParamsConstraintParam() {
212 // expected-error@+1 {{'i1' does not satisfy the constraint}}
213 "testd.dynparams"() : () -> !testd.parametric<i1>
219 //===----------------------------------------------------------------------===//
220 // Constraint variables
221 //===----------------------------------------------------------------------===//
223 func.func @succeededConstraintVars() {
224 // CHECK: "testd.constraint_vars"() : () -> (i32, i32)
225 "testd.constraint_vars"() : () -> (i32, i32)
231 func.func @succeededConstraintVars2() {
232 // CHECK: "testd.constraint_vars"() : () -> (i64, i64)
233 "testd.constraint_vars"() : () -> (i64, i64)
239 func.func @failedConstraintVars() {
240 // expected-error@+1 {{expected 'i64' but got 'i32'}}
241 "testd.constraint_vars"() : () -> (i64, i32)
247 //===----------------------------------------------------------------------===//
248 // Constraint attributes
249 //===----------------------------------------------------------------------===//
251 func.func @succeededAttrs() {
252 // CHECK: "testd.attrs"() {attr1 = i32, attr2 = i64} : () -> ()
253 "testd.attrs"() {attr1 = i32, attr2 = i64} : () -> ()
259 func.func @failedAttrsMissingAttr() {
260 // expected-error@+1 {{attribute "attr2" is expected but not provided}}
261 "testd.attrs"() {attr1 = i32} : () -> ()
267 func.func @failedAttrsConstraint() {
268 // expected-error@+1 {{expected 'i32' but got 'i64'}}
269 "testd.attrs"() {attr1 = i64, attr2 = i64} : () -> ()
275 func.func @failedAttrsConstraint2() {
276 // expected-error@+1 {{expected 'i64' but got 'i32'}}
277 "testd.attrs"() {attr1 = i32, attr2 = i32} : () -> ()
283 //===----------------------------------------------------------------------===//
285 //===----------------------------------------------------------------------===//
287 // CHECK: func.func @succeededRegions
288 func.func @succeededRegions() {
295 ^bb1(%arg0: i32, %arg1: i64):
315 // CHECK: func.func @succeededRegionWithNoConstraints
316 func.func @succeededRegionWithNoConstraints() {
319 ^bb1(%arg0: i32, %arg1: i64, %arg2 : f64):
321 ^bb2(%arg3: i32, %arg4: i64, %arg5 : f64):
323 ^bb3(%arg6: i32, %arg7: i64, %arg8 : f64):
325 ^bb4(%arg9: i32, %arg10: i64, %arg11 : f64):
327 ^bb5(%arg12: i32, %arg13: i64, %arg14 : f64):
331 ^bb1(%arg0: i32, %arg1: i64):
352 func.func @failedRegionArgsLessThanNeeded() {
353 // expected-note@+1 {{see the operation}}
360 // expected-error@+1 {{expected region 1 to have 2 arguments but got 1}}
382 func.func @failedRegionArgsMoreThanNeeded() {
383 // expected-note@+1 {{see the operation}}
390 // expected-error@+1 {{expected region 1 to have 2 arguments but got 3}}
391 ^bb1(%arg0: i32, %arg1: i64, %arg2 : f64):
412 func.func @failedRegionArgsEmptyButRequired() {
413 // expected-error@+1 {{expected region 1 to have 2 arguments but got 0}}
441 func.func @faIledRegionArgsConstraint() {
442 // expected-note@+1 {{see the operation}}
449 // expected-error@+1 {{expected 'i64' but got 'f64'}}
450 ^bb1(%arg0: i32, %arg1: f64):
471 func.func @failedRegionBlocksCountLessThanNeeded() {
472 // expected-error@+1 {{expected region 2 to have 3 block(s) but got 2}}
479 ^bb1(%arg0: i32, %arg1: i64):
498 func.func @failedRegionBlocksCountMoreThanNeeded() {
499 // expected-error@+1 {{expected region 2 to have 3 block(s) but got 4}}
506 ^bb1(%arg0: i32, %arg1: i64):
529 func.func @failedRegionWithEmptyArgs() {
530 // expected-note@+1 {{see the operation}}
537 ^bb1(%arg0: i32, %arg1: i64):
549 // expected-error@+1 {{expected region 3 to have 0 arguments but got 2}}
550 ^bb1(%arg0: i32, %arg1: i64):
559 func.func @failedRegionWithLessBlocksThanNeeded() {
560 // expected-error@+1 {{'testd.regions' op unexpected number of regions: expected 4 but got 3}}
584 func.func @failedRegionWithMoreBlocksThanNeeded() {
585 // expected-error@+1 {{'testd.regions' op unexpected number of regions: expected 4 but got 5}}
592 ^bb1(%arg0: i32, %arg1: i64):
604 ^bb1(%arg0: i32, %arg1: i64):
608 ^bb1(%arg0: i32, %arg1: i64):
617 func.func @successReuseConstraintBetweenRegionAndOperand() {
618 %0 = arith.constant 42 : i32
619 "testd.region_and_operand"(%0) ({
629 func.func @failedReuseConstraintBetweenRegionAndOperand() {
630 %0 = arith.constant 42 : i32
631 // expected-note@+1 {{see the operation}}
632 "testd.region_and_operand"(%0) ({
633 // expected-error@+1 {{expected 'i32' but got 'i64'}}