640 lines · plain
1// RUN: mlir-opt %s --irdl-file=%S/testd.irdl.mlir -split-input-file -verify-diagnostics | FileCheck %s2 3//===----------------------------------------------------------------------===//4// Type or attribute constraint5//===----------------------------------------------------------------------===//6 7func.func @typeFitsType() {8 // CHECK: "testd.any"() : () -> !testd.parametric<i32>9 "testd.any"() : () -> !testd.parametric<i32>10 return11}12 13// -----14 15func.func @attrDoesntFitType() {16 "testd.any"() : () -> !testd.parametric<"foo">17 return18}19 20// -----21 22func.func @attrFitsAttr() {23 // CHECK: "testd.any"() : () -> !testd.attr_in_type_out<"foo">24 "testd.any"() : () -> !testd.attr_in_type_out<"foo">25 return26}27 28// -----29 30func.func @typeFitsAttr() {31 // CHECK: "testd.any"() : () -> !testd.attr_in_type_out<i32>32 "testd.any"() : () -> !testd.attr_in_type_out<i32>33 return34}35 36// -----37 38//===----------------------------------------------------------------------===//39// Equality constraint40//===----------------------------------------------------------------------===//41 42func.func @succeededEqConstraint() {43 // CHECK: "testd.eq"() : () -> i3244 "testd.eq"() : () -> i3245 return46}47 48// -----49 50func.func @failedEqConstraint() {51 // expected-error@+1 {{expected 'i32' but got 'i64'}}52 "testd.eq"() : () -> i6453 return54}55 56// -----57 58//===----------------------------------------------------------------------===//59// AnyOf constraint60//===----------------------------------------------------------------------===//61 62func.func @succeededAnyOfConstraint() {63 // CHECK: "testd.anyof"() : () -> i3264 "testd.anyof"() : () -> i3265 // CHECK: "testd.anyof"() : () -> i6466 "testd.anyof"() : () -> i6467 return68}69 70// -----71 72func.func @failedAnyOfConstraint() {73 // expected-error@+1 {{'i1' does not satisfy the constraint}}74 "testd.anyof"() : () -> i175 return76}77 78// -----79 80//===----------------------------------------------------------------------===//81// AllOf constraint82//===----------------------------------------------------------------------===//83 84func.func @succeededAllOfConstraint() {85 // CHECK: "testd.all_of"() : () -> i6486 "testd.all_of"() : () -> i6487 return88}89 90// -----91 92func.func @failedAllOfConstraint1() {93 // expected-error@+1 {{'i1' does not satisfy the constraint}}94 "testd.all_of"() : () -> i195 return96}97 98// -----99 100func.func @failedAllOfConstraint2() {101 // expected-error@+1 {{expected 'i64' but got 'i32'}}102 "testd.all_of"() : () -> i32103 return104}105 106// -----107 108//===----------------------------------------------------------------------===//109// Any constraint110//===----------------------------------------------------------------------===//111 112func.func @succeededAnyConstraint() {113 // CHECK: "testd.any"() : () -> i32114 "testd.any"() : () -> i32115 // CHECK: "testd.any"() : () -> i64116 "testd.any"() : () -> i64117 return118}119 120// -----121 122//===----------------------------------------------------------------------===//123// Base constraints124//===----------------------------------------------------------------------===//125 126func.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>} : () -> ()137 return138}139 140// -----141 142func.func @failedDynTypeBaseConstraint() {143 // expected-error@+1 {{expected base type 'testd.parametric' but got 'builtin.integer'}}144 "testd.dyn_type_base"() : () -> i32145 return146}147 148// -----149 150func.func @failedDynAttrBaseConstraintNotType() {151 // expected-error@+1 {{expected base attribute 'testd.parametric_attr' but got 'builtin.type'}}152 "testd.dyn_attr_base"() {attr1 = i32}: () -> ()153 return154}155 156// -----157 158 159func.func @succeededNamedBaseConstraint() {160 // CHECK: "testd.named_type_base"() : () -> i32161 "testd.named_type_base"() : () -> i32162 // CHECK: "testd.named_type_base"() : () -> i64163 "testd.named_type_base"() : () -> i64164 // 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} : () -> ()168 return169}170 171// -----172 173func.func @failedNamedTypeBaseConstraint() {174 // expected-error@+1 {{expected base type 'builtin.integer' but got 'builtin.vector'}}175 "testd.named_type_base"() : () -> vector<i32>176 return177}178 179// -----180 181func.func @failedDynAttrBaseConstraintNotType() {182 // expected-error@+1 {{expected base attribute 'builtin.integer' but got 'builtin.type'}}183 "testd.named_attr_base"() {attr1 = i32}: () -> ()184 return185}186 187// -----188 189//===----------------------------------------------------------------------===//190// Dynamic parameters constraint191//===----------------------------------------------------------------------===//192 193func.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>198 return199}200 201// -----202 203func.func @failedDynParamsConstraintBase() {204 // expected-error@+1 {{expected base type 'testd.parametric' but got 'i32'}}205 "testd.dynparams"() : () -> i32206 return207}208 209// -----210 211func.func @failedDynParamsConstraintParam() {212 // expected-error@+1 {{'i1' does not satisfy the constraint}}213 "testd.dynparams"() : () -> !testd.parametric<i1>214 return215}216 217// -----218 219//===----------------------------------------------------------------------===//220// Constraint variables221//===----------------------------------------------------------------------===//222 223func.func @succeededConstraintVars() {224 // CHECK: "testd.constraint_vars"() : () -> (i32, i32)225 "testd.constraint_vars"() : () -> (i32, i32)226 return227}228 229// -----230 231func.func @succeededConstraintVars2() {232 // CHECK: "testd.constraint_vars"() : () -> (i64, i64)233 "testd.constraint_vars"() : () -> (i64, i64)234 return235}236 237// -----238 239func.func @failedConstraintVars() {240 // expected-error@+1 {{expected 'i64' but got 'i32'}}241 "testd.constraint_vars"() : () -> (i64, i32)242 return243}244 245// -----246 247//===----------------------------------------------------------------------===//248// Constraint attributes249//===----------------------------------------------------------------------===//250 251func.func @succeededAttrs() {252 // CHECK: "testd.attrs"() {attr1 = i32, attr2 = i64} : () -> ()253 "testd.attrs"() {attr1 = i32, attr2 = i64} : () -> ()254 return255}256 257// -----258 259func.func @failedAttrsMissingAttr() {260 // expected-error@+1 {{attribute "attr2" is expected but not provided}}261 "testd.attrs"() {attr1 = i32} : () -> ()262 return263}264 265// -----266 267func.func @failedAttrsConstraint() {268 // expected-error@+1 {{expected 'i32' but got 'i64'}}269 "testd.attrs"() {attr1 = i64, attr2 = i64} : () -> ()270 return271}272 273// -----274 275func.func @failedAttrsConstraint2() {276 // expected-error@+1 {{expected 'i64' but got 'i32'}}277 "testd.attrs"() {attr1 = i32, attr2 = i32} : () -> ()278 return279}280 281// -----282 283//===----------------------------------------------------------------------===//284// Regions285//===----------------------------------------------------------------------===//286 287// CHECK: func.func @succeededRegions288func.func @succeededRegions() {289 "testd.regions"() (290 {291 ^bb1:292 llvm.unreachable293 },294 {295 ^bb1(%arg0: i32, %arg1: i64):296 llvm.unreachable297 },298 {299 ^bb1:300 cf.br ^bb3301 ^bb2:302 cf.br ^bb3303 ^bb3:304 llvm.unreachable305 },306 {307 ^bb1:308 llvm.unreachable309 }) : () -> ()310 311 return312}313// -----314 315// CHECK: func.func @succeededRegionWithNoConstraints316func.func @succeededRegionWithNoConstraints() {317 "testd.regions"() (318 {319 ^bb1(%arg0: i32, %arg1: i64, %arg2 : f64):320 llvm.unreachable321 ^bb2(%arg3: i32, %arg4: i64, %arg5 : f64):322 llvm.unreachable323 ^bb3(%arg6: i32, %arg7: i64, %arg8 : f64):324 llvm.unreachable325 ^bb4(%arg9: i32, %arg10: i64, %arg11 : f64):326 llvm.unreachable327 ^bb5(%arg12: i32, %arg13: i64, %arg14 : f64):328 llvm.unreachable329 },330 {331 ^bb1(%arg0: i32, %arg1: i64):332 llvm.unreachable333 },334 {335 ^bb1:336 cf.br ^bb3337 ^bb2:338 cf.br ^bb3339 ^bb3:340 llvm.unreachable341 },342 {343 ^bb1:344 llvm.unreachable345 }) : () -> ()346 347 return348}349 350// -----351 352func.func @failedRegionArgsLessThanNeeded() {353 // expected-note@+1 {{see the operation}}354 "testd.regions"() (355 {356 ^bb1:357 llvm.unreachable358 },359 {360 // expected-error@+1 {{expected region 1 to have 2 arguments but got 1}}361 ^bb1(%arg0: i32):362 llvm.unreachable363 },364 {365 ^bb1:366 cf.br ^bb3367 ^bb2:368 cf.br ^bb3369 ^bb3:370 llvm.unreachable371 },372 {373 ^bb1:374 llvm.unreachable375 }) : () -> ()376 377 return378}379 380// -----381 382func.func @failedRegionArgsMoreThanNeeded() {383 // expected-note@+1 {{see the operation}}384 "testd.regions"() (385 {386 ^bb1:387 llvm.unreachable388 },389 {390 // expected-error@+1 {{expected region 1 to have 2 arguments but got 3}}391 ^bb1(%arg0: i32, %arg1: i64, %arg2 : f64):392 llvm.unreachable393 },394 {395 ^bb1:396 cf.br ^bb3397 ^bb2:398 cf.br ^bb3399 ^bb3:400 llvm.unreachable401 },402 {403 ^bb1:404 llvm.unreachable405 }) : () -> ()406 407 return408}409 410// -----411 412func.func @failedRegionArgsEmptyButRequired() {413 // expected-error@+1 {{expected region 1 to have 2 arguments but got 0}}414 "testd.regions"() (415 {416 ^bb1:417 llvm.unreachable418 },419 {420 ^bb1():421 llvm.unreachable422 },423 {424 ^bb1:425 cf.br ^bb3426 ^bb2:427 cf.br ^bb3428 ^bb3:429 llvm.unreachable430 },431 {432 ^bb1:433 llvm.unreachable434 }) : () -> ()435 436 return437}438 439// -----440 441func.func @faIledRegionArgsConstraint() {442 // expected-note@+1 {{see the operation}}443 "testd.regions"() (444 {445 ^bb1:446 llvm.unreachable447 },448 {449 // expected-error@+1 {{expected 'i64' but got 'f64'}}450 ^bb1(%arg0: i32, %arg1: f64):451 llvm.unreachable452 },453 {454 ^bb1:455 cf.br ^bb3456 ^bb2:457 cf.br ^bb3458 ^bb3:459 llvm.unreachable460 },461 {462 ^bb1:463 llvm.unreachable464 }) : () -> ()465 466 return467}468 469// -----470 471func.func @failedRegionBlocksCountLessThanNeeded() {472 // expected-error@+1 {{expected region 2 to have 3 block(s) but got 2}}473 "testd.regions"() (474 {475 ^bb1:476 llvm.unreachable477 },478 {479 ^bb1(%arg0: i32, %arg1: i64):480 llvm.unreachable481 },482 {483 ^bb1:484 cf.br ^bb3485 ^bb3:486 llvm.unreachable487 },488 {489 ^bb1:490 llvm.unreachable491 }) : () -> ()492 493 return494}495 496// -----497 498func.func @failedRegionBlocksCountMoreThanNeeded() {499 // expected-error@+1 {{expected region 2 to have 3 block(s) but got 4}}500 "testd.regions"() (501 {502 ^bb1:503 llvm.unreachable504 },505 {506 ^bb1(%arg0: i32, %arg1: i64):507 llvm.unreachable508 },509 {510 ^bb1:511 cf.br ^bb3512 ^bb2:513 cf.br ^bb3514 ^bb4:515 cf.br ^bb3516 ^bb3:517 llvm.unreachable518 },519 {520 ^bb1:521 llvm.unreachable522 }) : () -> ()523 524 return525}526 527// -----528 529func.func @failedRegionWithEmptyArgs() {530 // expected-note@+1 {{see the operation}}531 "testd.regions"() (532 {533 ^bb1:534 llvm.unreachable535 },536 {537 ^bb1(%arg0: i32, %arg1: i64):538 llvm.unreachable539 },540 {541 ^bb1:542 cf.br ^bb3543 ^bb2:544 cf.br ^bb3545 ^bb3:546 llvm.unreachable547 },548 {549 // expected-error@+1 {{expected region 3 to have 0 arguments but got 2}}550 ^bb1(%arg0: i32, %arg1: i64):551 llvm.unreachable552 }) : () -> ()553 554 return555}556 557// -----558 559func.func @failedRegionWithLessBlocksThanNeeded() {560 // expected-error@+1 {{'testd.regions' op unexpected number of regions: expected 4 but got 3}}561 "testd.regions"() (562 {563 ^bb1:564 llvm.unreachable565 },566 {567 ^bb1:568 cf.br ^bb3569 ^bb2:570 cf.br ^bb3571 ^bb3:572 llvm.unreachable573 },574 {575 ^bb1:576 llvm.unreachable577 }) : () -> ()578 579 return580}581 582// -----583 584func.func @failedRegionWithMoreBlocksThanNeeded() {585 // expected-error@+1 {{'testd.regions' op unexpected number of regions: expected 4 but got 5}}586 "testd.regions"() (587 {588 ^bb1:589 llvm.unreachable590 },591 {592 ^bb1(%arg0: i32, %arg1: i64):593 llvm.unreachable594 },595 {596 ^bb1:597 cf.br ^bb3598 ^bb2:599 cf.br ^bb3600 ^bb3:601 llvm.unreachable602 },603 {604 ^bb1(%arg0: i32, %arg1: i64):605 llvm.unreachable606 },607 {608 ^bb1(%arg0: i32, %arg1: i64):609 llvm.unreachable610 }) : () -> ()611 612 return613}614 615// -----616 617func.func @successReuseConstraintBetweenRegionAndOperand() {618 %0 = arith.constant 42 : i32619 "testd.region_and_operand"(%0) ({620 ^bb(%1: i32):621 llvm.unreachable622 }) : (i32) -> ()623 624 return625}626 627// -----628 629func.func @failedReuseConstraintBetweenRegionAndOperand() {630 %0 = arith.constant 42 : i32631 // expected-note@+1 {{see the operation}}632 "testd.region_and_operand"(%0) ({633 // expected-error@+1 {{expected 'i32' but got 'i64'}}634 ^bb(%1: i64):635 llvm.unreachable636 }) : (i32) -> ()637 638 return639}640