1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
|
// RUN: mlir-opt %s --test-transform-dialect-interpreter -allow-unregistered-dialect --split-input-file --verify-diagnostics
// expected-remark @below {{applying transformation}}
transform.test_transform_op
// -----
%0 = transform.test_produce_param_or_forward_operand 42 { foo = "bar" }
// expected-remark @below {{succeeded}}
transform.test_consume_operand_if_matches_param_or_fail %0[42]
// -----
%0 = transform.test_produce_param_or_forward_operand 42 { foo = "bar" }
// expected-error @below {{expected the operand to be associated with 21 got 42}}
transform.test_consume_operand_if_matches_param_or_fail %0[21]
// -----
// expected-error @below {{operation tracked by two handles}}
%0 = transform.test_produce_param_or_forward_operand 42
// expected-note @below {{handle}}
%1 = transform.test_produce_param_or_forward_operand from %0
// expected-note @below {{handle}}
%2 = transform.test_produce_param_or_forward_operand from %0
transform.test_consume_operand_if_matches_param_or_fail %1[42]
transform.test_consume_operand_if_matches_param_or_fail %2[42]
// -----
transform.sequence {
^bb0(%arg0: !pdl.operation):
sequence %arg0 {
^bb0(%arg1: !pdl.operation):
// expected-remark @below {{applying transformation "a"}}
test_transform_op "a"
// expected-remark @below {{applying transformation "b"}}
test_transform_op "b"
// expected-remark @below {{applying transformation "c"}}
test_transform_op "c"
}
// expected-remark @below {{applying transformation "d"}}
test_transform_op "d"
// expected-remark @below {{applying transformation "e"}}
test_transform_op "e"
}
// -----
transform.sequence {
^bb0(%arg0: !pdl.operation):
%0 = test_produce_param_or_forward_operand 42
sequence %0 {
^bb0(%arg1: !pdl.operation):
// expected-remark @below {{succeeded}}
test_consume_operand_if_matches_param_or_fail %arg1[42]
}
}
// -----
transform.sequence {
^bb0(%arg0: !pdl.operation):
%0 = sequence %arg0 {
^bb0(%arg1: !pdl.operation):
%1 = test_produce_param_or_forward_operand 42
yield %1 : !pdl.operation
} : !pdl.operation
// expected-remark @below {{succeeded}}
test_consume_operand_if_matches_param_or_fail %0[42]
}
// -----
transform.with_pdl_patterns {
^bb0(%arg0: !pdl.operation):
sequence %arg0 {
^bb0(%arg1: !pdl.operation):
%0 = pdl_match @some in %arg1
test_print_remark_at_operand %0, "matched"
}
pdl.pattern @some : benefit(1) {
%0 = pdl.operation "test.some_op"
pdl.rewrite %0 with "transform.dialect"
}
pdl.pattern @other : benefit(1) {
%0 = pdl.operation "test.other_op"
pdl.rewrite %0 with "transform.dialect"
}
}
// expected-remark @below {{matched}}
"test.some_op"() : () -> ()
"test.other_op"() : () -> ()
// expected-remark @below {{matched}}
"test.some_op"() : () -> ()
// -----
// expected-remark @below {{parent function}}
func.func @foo() {
%0 = arith.constant 0 : i32
return
}
// expected-remark @below {{parent function}}
func.func @bar() {
%0 = arith.constant 0 : i32
%1 = arith.constant 1 : i32
return
}
transform.with_pdl_patterns {
^bb0(%arg0: !pdl.operation):
pdl.pattern @const : benefit(1) {
%r = pdl.types
%0 = pdl.operation "arith.constant" -> (%r : !pdl.range<type>)
pdl.rewrite %0 with "transform.dialect"
}
transform.sequence %arg0 {
^bb1(%arg1: !pdl.operation):
%f = pdl_match @const in %arg1
// CHECK: %{{.+}} = get_closest_isolated_parent %{{.+}}
%m = get_closest_isolated_parent %f
test_print_remark_at_operand %m, "parent function"
}
}
// -----
func.func @foo() {
%0 = arith.constant 0 : i32
return
}
transform.with_pdl_patterns {
^bb0(%arg0: !pdl.operation):
pdl.pattern @match_func : benefit(1) {
%0 = pdl.operands
%1 = pdl.types
%2 = pdl.operation "func.func"(%0 : !pdl.range<value>) -> (%1 : !pdl.range<type>)
pdl.rewrite %2 with "transform.dialect"
}
transform.sequence %arg0 {
^bb1(%arg1: !pdl.operation):
// This is necessary to run the transformation on something other than the
// top-level module, "alternatives" cannot be run on that.
%0 = pdl_match @match_func in %arg1
transform.alternatives %0 {
^bb2(%arg2: !pdl.operation):
%1 = transform.test_produce_param_or_forward_operand 42
// This operation fails, which triggers the next alternative without
// reporting the error.
transform.test_consume_operand_if_matches_param_or_fail %1[43]
}, {
^bb2(%arg2: !pdl.operation):
%1 = transform.test_produce_param_or_forward_operand 42
// expected-remark @below {{succeeded}}
transform.test_consume_operand_if_matches_param_or_fail %1[42]
}
}
}
// -----
func.func private @bar()
func.func @foo() {
call @bar() : () -> ()
return
}
transform.with_pdl_patterns {
^bb0(%arg0: !pdl.operation):
pdl.pattern @match_call : benefit(1) {
%0 = pdl.operands
%1 = pdl.types
%2 = pdl.operation "func.call"(%0 : !pdl.range<value>) -> (%1 : !pdl.range<type>)
pdl.rewrite %2 with "transform.dialect"
}
transform.sequence %arg0 {
^bb1(%arg1: !pdl.operation):
%0 = pdl_match @match_call in %arg1
%1 = get_closest_isolated_parent %0
// expected-error @below {{all alternatives failed}}
transform.alternatives %1 {
^bb2(%arg2: !pdl.operation):
%2 = transform.pdl_match @match_call in %arg2
// expected-remark @below {{applying}}
transform.test_emit_remark_and_erase_operand %2, "applying" {fail_after_erase}
}
}
}
// -----
func.func private @bar()
func.func @foo() {
// expected-remark @below {{still here}}
call @bar() : () -> ()
return
}
transform.with_pdl_patterns {
^bb0(%arg0: !pdl.operation):
pdl.pattern @match_call : benefit(1) {
%0 = pdl.operands
%1 = pdl.types
%2 = pdl.operation "func.call"(%0 : !pdl.range<value>) -> (%1 : !pdl.range<type>)
pdl.rewrite %2 with "transform.dialect"
}
transform.sequence %arg0 {
^bb1(%arg1: !pdl.operation):
%0 = pdl_match @match_call in %arg1
%1 = get_closest_isolated_parent %0
transform.alternatives %1 {
^bb2(%arg2: !pdl.operation):
%2 = transform.pdl_match @match_call in %arg2
// expected-remark @below {{applying}}
transform.test_emit_remark_and_erase_operand %2, "applying" {fail_after_erase}
}, {
^bb2(%arg2: !pdl.operation):
%2 = transform.pdl_match @match_call in %arg2
transform.test_print_remark_at_operand %2, "still here"
// This alternative succeeds.
}, {
^bb2(%arg2: !pdl.operation):
// This alternative is never run, so we must not have a remark here.
%2 = transform.pdl_match @match_call in %arg2
transform.test_emit_remark_and_erase_operand %2, "should not happen" {fail_after_erase}
}
}
}
// -----
func.func private @bar()
// CHECK-LABEL: @erase_call
func.func @erase_call() {
// CHECK-NOT: call @bar
call @bar() : () -> ()
return
}
transform.with_pdl_patterns {
^bb0(%arg0: !pdl.operation):
pdl.pattern @match_call : benefit(1) {
%0 = pdl.operands
%1 = pdl.types
%2 = pdl.operation "func.call"(%0 : !pdl.range<value>) -> (%1 : !pdl.range<type>)
pdl.rewrite %2 with "transform.dialect"
}
transform.sequence %arg0 {
^bb1(%arg1: !pdl.operation):
%0 = pdl_match @match_call in %arg1
%1 = get_closest_isolated_parent %0
transform.alternatives %1 {
^bb2(%arg2: !pdl.operation):
%2 = transform.pdl_match @match_call in %arg2
// expected-remark @below {{applying}}
transform.test_emit_remark_and_erase_operand %2, "applying" {fail_after_erase}
}, {
^bb2(%arg2: !pdl.operation):
%2 = transform.pdl_match @match_call in %arg2
// expected-remark @below {{applying second time}}
transform.test_emit_remark_and_erase_operand %2, "applying second time"
}
}
}
// -----
func.func private @bar()
func.func @foo() {
call @bar() : () -> ()
return
}
transform.with_pdl_patterns {
^bb0(%arg0: !pdl.operation):
pdl.pattern @match_call : benefit(1) {
%0 = pdl.operands
%1 = pdl.types
%2 = pdl.operation "func.call"(%0 : !pdl.range<value>) -> (%1 : !pdl.range<type>)
pdl.rewrite %2 with "transform.dialect"
}
transform.sequence %arg0 {
^bb1(%arg1: !pdl.operation):
%0 = pdl_match @match_call in %arg1
%1 = get_closest_isolated_parent %0
%2 = transform.alternatives %1 -> !pdl.operation {
^bb2(%arg2: !pdl.operation):
%3 = transform.pdl_match @match_call in %arg2
// expected-remark @below {{applying}}
transform.test_emit_remark_and_erase_operand %3, "applying" {fail_after_erase}
%4 = transform.test_produce_param_or_forward_operand 43
transform.yield %4 : !pdl.operation
}, {
^bb2(%arg2: !pdl.operation):
%4 = transform.test_produce_param_or_forward_operand 42
transform.yield %4 : !pdl.operation
}
// The first alternative failed, so the returned value is taken from the
// second alternative.
// expected-remark @below {{succeeded}}
transform.test_consume_operand_if_matches_param_or_fail %2[42]
}
}
// -----
// expected-note @below {{scope}}
module {
func.func @foo() {
%0 = arith.constant 0 : i32
return
}
func.func @bar() {
%0 = arith.constant 0 : i32
%1 = arith.constant 1 : i32
return
}
transform.sequence {
^bb1(%arg1: !pdl.operation):
// expected-error @below {{scope must not contain the transforms being applied}}
transform.alternatives %arg1 {
^bb2(%arg2: !pdl.operation):
%0 = transform.test_produce_param_or_forward_operand 42
transform.test_consume_operand_if_matches_param_or_fail %0[43]
}, {
^bb2(%arg2: !pdl.operation):
%0 = transform.test_produce_param_or_forward_operand 42
transform.test_consume_operand_if_matches_param_or_fail %0[42]
}
}
}
// -----
func.func @foo(%arg0: index, %arg1: index, %arg2: index) {
// expected-note @below {{scope}}
scf.for %i = %arg0 to %arg1 step %arg2 {
%0 = arith.constant 0 : i32
}
return
}
transform.with_pdl_patterns {
^bb0(%arg0: !pdl.operation):
pdl.pattern @match_const : benefit(1) {
%0 = pdl.operands
%1 = pdl.types
%2 = pdl.operation "arith.constant"(%0 : !pdl.range<value>) -> (%1 : !pdl.range<type>)
pdl.rewrite %2 with "transform.dialect"
}
sequence %arg0 {
^bb1(%arg1: !pdl.operation):
%0 = transform.pdl_match @match_const in %arg1
%1 = transform.loop.get_parent_for %0
// expected-error @below {{only isolated-from-above ops can be alternative scopes}}
alternatives %1 {
^bb2(%arg2: !pdl.operation):
}
}
}
// -----
func.func @foo() {
// expected-note @below {{when applied to this op}}
"op" () : () -> ()
return
}
transform.with_pdl_patterns {
^bb0(%arg0: !pdl.operation):
pdl.pattern @some : benefit(1) {
%0 = pdl.operands
%1 = pdl.types
%2 = pdl.operation "op"(%0 : !pdl.range<value>) -> (%1 : !pdl.range<type>)
pdl.rewrite %2 with "transform.dialect"
}
transform.sequence %arg0 {
^bb0(%arg1: !pdl.operation):
%0 = pdl_match @some in %arg1
// expected-error @below {{applications of transform.test_wrong_number_of_results expected to produce 3 results (actually produced 1).}}
// expected-note @below {{If you need variadic results, consider a generic `apply` instead of the specialized `applyToOne`.}}
// expected-note @below {{Producing 3 null results is allowed if the use case warrants it.}}
transform.test_wrong_number_of_results %0
}
}
// -----
func.func @foo() {
"op" () : () -> ()
// expected-note @below {{when applied to this op}}
"op" () : () -> ()
return
}
transform.with_pdl_patterns {
^bb0(%arg0: !pdl.operation):
pdl.pattern @some : benefit(1) {
%0 = pdl.operands
%1 = pdl.types
%2 = pdl.operation "op"(%0 : !pdl.range<value>) -> (%1 : !pdl.range<type>)
pdl.rewrite %2 with "transform.dialect"
}
transform.sequence %arg0 {
^bb0(%arg1: !pdl.operation):
%0 = pdl_match @some in %arg1
// expected-error @below {{applications of transform.test_wrong_number_of_multi_results expected to produce 1 results (actually produced 0)}}
// expected-note @below {{If you need variadic results, consider a generic `apply` instead of the specialized `applyToOne`.}}
// expected-note @below {{Producing 1 null results is allowed if the use case warrants it.}}
transform.test_wrong_number_of_multi_results %0
}
}
// -----
func.func @foo() {
"op" () : () -> ()
"op" () : () -> ()
"op" () : () -> ()
return
}
transform.with_pdl_patterns {
^bb0(%arg0: !pdl.operation):
pdl.pattern @some : benefit(1) {
%0 = pdl.operands
%1 = pdl.types
%2 = pdl.operation "op"(%0 : !pdl.range<value>) -> (%1 : !pdl.range<type>)
pdl.rewrite %2 with "transform.dialect"
}
transform.sequence %arg0 {
^bb0(%arg1: !pdl.operation):
%0 = pdl_match @some in %arg1
// Transform matches 3 ops and produces 2 results.
%1:2 = transform.test_correct_number_of_multi_results %0
}
}
// -----
func.func @foo() {
"wrong_op_name" () : () -> ()
return
}
transform.with_pdl_patterns {
^bb0(%arg0: !pdl.operation):
pdl.pattern @some : benefit(1) {
%0 = pdl.operands
%1 = pdl.types
%2 = pdl.operation "op"(%0 : !pdl.range<value>) -> (%1 : !pdl.range<type>)
pdl.rewrite %2 with "transform.dialect"
}
transform.sequence %arg0 {
^bb0(%arg1: !pdl.operation):
%0 = pdl_match @some in %arg1
// Transform fails to match any but still produces 2 results.
%1:2 = transform.test_correct_number_of_multi_results %0
}
}
// -----
func.func @foo() {
// expected-note @below {{when applied to this op}}
"op" () : () -> ()
return
}
transform.with_pdl_patterns {
^bb0(%arg0: !pdl.operation):
pdl.pattern @some : benefit(1) {
%0 = pdl.operands
%1 = pdl.types
%2 = pdl.operation "op"(%0 : !pdl.range<value>) -> (%1 : !pdl.range<type>)
pdl.rewrite %2 with "transform.dialect"
}
transform.sequence %arg0 {
^bb0(%arg1: !pdl.operation):
%0 = pdl_match @some in %arg1
// expected-error @below {{unexpected application of transform.test_mixed_null_and_non_null_results produces both null and non null results.}}
transform.test_mixed_null_and_non_null_results %0
}
}
// -----
// Expecting to match all operations by merging the handles that matched addi
// and subi separately.
func.func @foo(%arg0: index) {
// expected-remark @below {{matched}}
%0 = arith.addi %arg0, %arg0 : index
// expected-remark @below {{matched}}
%1 = arith.subi %arg0, %arg0 : index
// expected-remark @below {{matched}}
%2 = arith.addi %0, %1 : index
return
}
transform.with_pdl_patterns {
^bb0(%arg0: !pdl.operation):
pdl.pattern @addi : benefit(1) {
%0 = pdl.operands
%1 = pdl.types
%2 = pdl.operation "arith.addi"(%0 : !pdl.range<value>) -> (%1 : !pdl.range<type>)
pdl.rewrite %2 with "transform.dialect"
}
pdl.pattern @subi : benefit(1) {
%0 = pdl.operands
%1 = pdl.types
%2 = pdl.operation "arith.subi"(%0 : !pdl.range<value>) -> (%1 : !pdl.range<type>)
pdl.rewrite %2 with "transform.dialect"
}
transform.sequence %arg0 {
^bb0(%arg1: !pdl.operation):
%0 = pdl_match @addi in %arg1
%1 = pdl_match @subi in %arg1
%2 = merge_handles %0, %1
test_print_remark_at_operand %2, "matched"
}
}
// -----
func.func @foo() {
"op" () { target_me } : () -> ()
"op" () : () -> ()
return
}
transform.with_pdl_patterns {
^bb0(%arg0: !pdl.operation):
pdl.pattern @some : benefit(1) {
%0 = pdl.operands
%1 = pdl.types
%2 = pdl.operation "op"(%0 : !pdl.range<value>) -> (%1 : !pdl.range<type>)
pdl.rewrite %2 with "transform.dialect"
}
transform.sequence %arg0 {
^bb0(%arg1: !pdl.operation):
%0 = pdl_match @some in %arg1
transform.test_mixed_sucess_and_silenceable %0
}
}
// -----
module {
func.func private @foo()
func.func private @bar()
transform.with_pdl_patterns {
^bb0(%arg0: !pdl.operation):
pdl.pattern @func : benefit(1) {
%0 = pdl.operands
%1 = pdl.types
%2 = pdl.operation "func.func"(%0 : !pdl.range<value>) -> (%1 : !pdl.range<type>)
pdl.rewrite %2 with "transform.dialect"
}
transform.sequence %arg0 {
^bb0(%arg1: !pdl.operation):
%0 = pdl_match @func in %arg1
%1 = replicate num(%0) %arg1
// expected-remark @below {{2}}
test_print_number_of_associated_payload_ir_ops %1
%2 = replicate num(%0) %1
// expected-remark @below {{4}}
test_print_number_of_associated_payload_ir_ops %2
}
}
}
// -----
func.func @bar() {
// expected-remark @below {{transform applied}}
%0 = arith.constant 0 : i32
// expected-remark @below {{transform applied}}
%1 = arith.constant 1 : i32
return
}
transform.with_pdl_patterns {
^bb0(%arg0: !pdl.operation):
pdl.pattern @const : benefit(1) {
%r = pdl.types
%0 = pdl.operation "arith.constant" -> (%r : !pdl.range<type>)
pdl.rewrite %0 with "transform.dialect"
}
transform.sequence %arg0 {
^bb1(%arg1: !pdl.operation):
%f = pdl_match @const in %arg1
transform.foreach %f {
^bb2(%arg2: !pdl.operation):
// expected-remark @below {{1}}
transform.test_print_number_of_associated_payload_ir_ops %arg2
transform.test_print_remark_at_operand %arg2, "transform applied"
}
}
}
|