1 // RUN: mlir-opt %s -test-pdl-bytecode-pass -split-input-file | FileCheck %s
3 // Note: Tests here are written using the PDL Interpreter dialect to avoid
4 // unnecessarily testing unnecessary aspects of the pattern compilation
5 // pipeline. These tests are written such that we can focus solely on the
6 // lowering/execution of the bytecode itself.
8 //===----------------------------------------------------------------------===//
9 // pdl_interp::ApplyConstraintOp
10 //===----------------------------------------------------------------------===//
13 pdl_interp.func @matcher(%root : !pdl.operation) {
14 pdl_interp.apply_constraint "multi_entity_constraint"(%root, %root : !pdl.operation, !pdl.operation) -> ^pat, ^end
17 pdl_interp.apply_constraint "single_entity_constraint"(%root : !pdl.operation) -> ^pat2, ^end
20 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
27 pdl_interp.func @success(%root : !pdl.operation) {
28 %op = pdl_interp.create_operation "test.replaced_by_pattern"
29 pdl_interp.erase %root
35 // CHECK-LABEL: test.apply_constraint_1
36 // CHECK: "test.replaced_by_pattern"
37 module @ir attributes { test.apply_constraint_1 } {
38 "test.op"() { test_attr } : () -> ()
44 pdl_interp.func @matcher(%root : !pdl.operation) {
45 %results = pdl_interp.get_results of %root : !pdl.range<value>
46 %types = pdl_interp.get_value_type of %results : !pdl.range<type>
47 pdl_interp.apply_constraint "multi_entity_var_constraint"(%results, %types : !pdl.range<value>, !pdl.range<type>) -> ^pat, ^end
50 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
57 pdl_interp.func @success(%root : !pdl.operation) {
58 %op = pdl_interp.create_operation "test.replaced_by_pattern"
59 pdl_interp.erase %root
65 // CHECK-LABEL: test.apply_constraint_2
66 // CHECK-NOT: "test.replaced_by_pattern"
67 // CHECK: "test.replaced_by_pattern"
68 module @ir attributes { test.apply_constraint_2 } {
69 "test.failure_op"() { test_attr } : () -> ()
70 "test.success_op"() : () -> (i32, i64)
75 // Test support for negated constraints.
77 pdl_interp.func @matcher(%root : !pdl.operation) {
78 %test_attr = pdl_interp.create_attribute unit
79 %attr = pdl_interp.get_attribute "test_attr" of %root
80 pdl_interp.are_equal %test_attr, %attr : !pdl.attribute -> ^pat, ^end
83 pdl_interp.apply_constraint "single_entity_constraint"(%root : !pdl.operation) {isNegated = true} -> ^pat1, ^end
86 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
93 pdl_interp.func @success(%root : !pdl.operation) {
94 %op = pdl_interp.create_operation "test.replaced_by_pattern"
95 pdl_interp.erase %root
101 // CHECK-LABEL: test.apply_constraint_3
102 // CHECK-NEXT: "test.replaced_by_pattern"
103 // CHECK-NOT: "test.replaced_by_pattern"
105 module @ir attributes { test.apply_constraint_3 } {
106 "test.foo"() { test_attr } : () -> ()
107 "test.op"() { test_attr } : () -> ()
112 // Test returning a type from a native constraint.
114 pdl_interp.func @matcher(%root : !pdl.operation) {
115 pdl_interp.check_operation_name of %root is "test.success_op" -> ^pat, ^end
118 %new_type = pdl_interp.apply_constraint "op_constr_return_type"(%root : !pdl.operation) : !pdl.type -> ^pat2, ^end
121 pdl_interp.record_match @rewriters::@success(%root, %new_type : !pdl.operation, !pdl.type) : benefit(1), loc([%root]) -> ^end
128 pdl_interp.func @success(%root : !pdl.operation, %new_type : !pdl.type) {
129 %op = pdl_interp.create_operation "test.replaced_by_pattern" -> (%new_type : !pdl.type)
130 pdl_interp.erase %root
136 // CHECK-LABEL: test.apply_constraint_4
137 // CHECK-NOT: "test.replaced_by_pattern"
138 // CHECK: "test.replaced_by_pattern"() : () -> f32
139 module @ir attributes { test.apply_constraint_4 } {
140 "test.failure_op"() : () -> ()
141 "test.success_op"() : () -> ()
146 // Test success and failure cases of native constraints with pdl.range results.
148 pdl_interp.func @matcher(%root : !pdl.operation) {
149 pdl_interp.check_operation_name of %root is "test.success_op" -> ^pat, ^end
152 %num_results = pdl_interp.create_attribute 2 : i32
153 %types = pdl_interp.apply_constraint "op_constr_return_type_range"(%root, %num_results : !pdl.operation, !pdl.attribute) : !pdl.range<type> -> ^pat1, ^end
156 pdl_interp.record_match @rewriters::@success(%root, %types : !pdl.operation, !pdl.range<type>) : benefit(1), loc([%root]) -> ^end
163 pdl_interp.func @success(%root : !pdl.operation, %types : !pdl.range<type>) {
164 %op = pdl_interp.create_operation "test.replaced_by_pattern" -> (%types : !pdl.range<type>)
165 pdl_interp.erase %root
171 // CHECK-LABEL: test.apply_constraint_5
172 // CHECK-NOT: "test.replaced_by_pattern"
173 // CHECK: "test.replaced_by_pattern"() : () -> (f32, f32)
174 module @ir attributes { test.apply_constraint_5 } {
175 "test.failure_op"() : () -> ()
176 "test.success_op"() : () -> ()
181 //===----------------------------------------------------------------------===//
182 // pdl_interp::ApplyRewriteOp
183 //===----------------------------------------------------------------------===//
186 pdl_interp.func @matcher(%root : !pdl.operation) {
187 pdl_interp.check_operation_name of %root is "test.op" -> ^pat, ^end
190 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
197 pdl_interp.func @success(%root : !pdl.operation) {
198 %operand = pdl_interp.get_operand 0 of %root
199 pdl_interp.apply_rewrite "rewriter"(%root, %operand : !pdl.operation, !pdl.value)
205 // CHECK-LABEL: test.apply_rewrite_1
206 // CHECK: %[[INPUT:.*]] = "test.op_input"
207 // CHECK-NOT: "test.op"
208 // CHECK: "test.success"(%[[INPUT]])
209 module @ir attributes { test.apply_rewrite_1 } {
210 %input = "test.op_input"() : () -> i32
211 "test.op"(%input) : (i32) -> ()
217 pdl_interp.func @matcher(%root : !pdl.operation) {
218 pdl_interp.check_operation_name of %root is "test.op" -> ^pat, ^end
221 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
228 pdl_interp.func @success(%root : !pdl.operation) {
229 %op = pdl_interp.apply_rewrite "creator"(%root : !pdl.operation) : !pdl.operation
230 pdl_interp.erase %root
236 // CHECK-LABEL: test.apply_rewrite_2
237 // CHECK: "test.success"
238 module @ir attributes { test.apply_rewrite_2 } {
239 "test.op"() : () -> ()
245 pdl_interp.func @matcher(%root : !pdl.operation) {
246 pdl_interp.check_operation_name of %root is "test.op" -> ^pat, ^end
249 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
256 pdl_interp.func @success(%root : !pdl.operation) {
257 %operands, %types = pdl_interp.apply_rewrite "var_creator"(%root : !pdl.operation) : !pdl.range<value>, !pdl.range<type>
258 %op = pdl_interp.create_operation "test.success"(%operands : !pdl.range<value>) -> (%types : !pdl.range<type>)
259 pdl_interp.replace %root with (%operands : !pdl.range<value>)
265 // CHECK-LABEL: test.apply_rewrite_3
266 // CHECK: %[[OPERAND:.*]] = "test.producer"
267 // CHECK: "test.success"(%[[OPERAND]]) : (i32) -> i32
268 // CHECK: "test.consumer"(%[[OPERAND]])
269 module @ir attributes { test.apply_rewrite_3 } {
270 %first_operand = "test.producer"() : () -> (i32)
271 %operand = "test.op"(%first_operand) : (i32) -> (i32)
272 "test.consumer"(%operand) : (i32) -> ()
278 pdl_interp.func @matcher(%root : !pdl.operation) {
279 pdl_interp.check_operation_name of %root is "test.op" -> ^pat, ^end
282 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
289 pdl_interp.func @success(%root : !pdl.operation) {
290 %attr = pdl_interp.apply_rewrite "str_creator" : !pdl.attribute
291 %type = pdl_interp.apply_rewrite "type_creator" : !pdl.type
292 %newOp = pdl_interp.create_operation "test.success" {"attr" = %attr} -> (%type : !pdl.type)
293 pdl_interp.erase %root
299 // CHECK-LABEL: test.apply_rewrite_4
300 // CHECK: "test.success"() {attr = "test.str"} : () -> f32
301 module @ir attributes { test.apply_rewrite_4 } {
302 "test.op"() : () -> ()
307 //===----------------------------------------------------------------------===//
308 // pdl_interp::AreEqualOp
309 //===----------------------------------------------------------------------===//
312 pdl_interp.func @matcher(%root : !pdl.operation) {
313 %test_attr = pdl_interp.create_attribute unit
314 %attr = pdl_interp.get_attribute "test_attr" of %root
315 pdl_interp.are_equal %test_attr, %attr : !pdl.attribute -> ^pat, ^end
318 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
325 pdl_interp.func @success(%root : !pdl.operation) {
326 %op = pdl_interp.create_operation "test.success"
327 pdl_interp.erase %root
333 // CHECK-LABEL: test.are_equal_1
334 // CHECK: "test.success"
335 module @ir attributes { test.are_equal_1 } {
336 "test.op"() { test_attr } : () -> ()
342 pdl_interp.func @matcher(%root : !pdl.operation) {
343 %const_types = pdl_interp.create_types [i32, i64]
344 %results = pdl_interp.get_results of %root : !pdl.range<value>
345 %result_types = pdl_interp.get_value_type of %results : !pdl.range<type>
346 pdl_interp.are_equal %result_types, %const_types : !pdl.range<type> -> ^pat, ^end
349 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
356 pdl_interp.func @success(%root : !pdl.operation) {
357 %op = pdl_interp.create_operation "test.success"
358 pdl_interp.erase %root
364 // CHECK-LABEL: test.are_equal_2
365 // CHECK: "test.not_equal"
366 // CHECK: "test.success"
367 // CHECK-NOT: "test.op"
368 module @ir attributes { test.are_equal_2 } {
369 "test.not_equal"() : () -> (i32)
370 "test.op"() : () -> (i32, i64)
375 //===----------------------------------------------------------------------===//
376 // pdl_interp::BranchOp
377 //===----------------------------------------------------------------------===//
380 pdl_interp.func @matcher(%root : !pdl.operation) {
381 pdl_interp.check_operation_name of %root is "test.op" -> ^pat1, ^end
384 pdl_interp.branch ^pat2
387 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(2), loc([%root]) -> ^end
394 pdl_interp.func @success(%root : !pdl.operation) {
395 %op = pdl_interp.create_operation "test.success"
396 pdl_interp.erase %root
402 // CHECK-LABEL: test.branch_1
403 // CHECK: "test.success"
404 module @ir attributes { test.branch_1 } {
405 "test.op"() : () -> ()
410 //===----------------------------------------------------------------------===//
411 // pdl_interp::CheckAttributeOp
412 //===----------------------------------------------------------------------===//
415 pdl_interp.func @matcher(%root : !pdl.operation) {
416 %attr = pdl_interp.get_attribute "test_attr" of %root
417 pdl_interp.check_attribute %attr is unit -> ^pat, ^end
420 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
427 pdl_interp.func @success(%root : !pdl.operation) {
428 %op = pdl_interp.create_operation "test.success"
429 pdl_interp.erase %root
435 // CHECK-LABEL: test.check_attribute_1
436 // CHECK: "test.success"
437 module @ir attributes { test.check_attribute_1 } {
438 "test.op"() { test_attr } : () -> ()
443 //===----------------------------------------------------------------------===//
444 // pdl_interp::CheckOperandCountOp
445 //===----------------------------------------------------------------------===//
448 pdl_interp.func @matcher(%root : !pdl.operation) {
449 pdl_interp.check_operand_count of %root is at_least 1 -> ^exact_check, ^end
452 pdl_interp.check_operand_count of %root is 2 -> ^pat, ^end
455 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
462 pdl_interp.func @success(%root : !pdl.operation) {
463 %op = pdl_interp.create_operation "test.success"
464 pdl_interp.erase %root
470 // CHECK-LABEL: test.check_operand_count_1
471 // CHECK: "test.op"() : () -> i32
472 // CHECK: "test.success"
473 module @ir attributes { test.check_operand_count_1 } {
474 %operand = "test.op"() : () -> i32
475 "test.op"(%operand, %operand) : (i32, i32) -> ()
480 //===----------------------------------------------------------------------===//
481 // pdl_interp::CheckOperationNameOp
482 //===----------------------------------------------------------------------===//
485 pdl_interp.func @matcher(%root : !pdl.operation) {
486 pdl_interp.check_operation_name of %root is "test.op" -> ^pat, ^end
489 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
496 pdl_interp.func @success(%root : !pdl.operation) {
497 %op = pdl_interp.create_operation "test.success"
498 pdl_interp.erase %root
504 // CHECK-LABEL: test.check_operation_name_1
505 // CHECK: "test.success"
506 module @ir attributes { test.check_operation_name_1 } {
507 "test.op"() : () -> ()
512 //===----------------------------------------------------------------------===//
513 // pdl_interp::CheckResultCountOp
514 //===----------------------------------------------------------------------===//
517 pdl_interp.func @matcher(%root : !pdl.operation) {
518 pdl_interp.check_result_count of %root is at_least 1 -> ^exact_check, ^end
521 pdl_interp.check_result_count of %root is 2 -> ^pat, ^end
524 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
531 pdl_interp.func @success(%root : !pdl.operation) {
532 %op = pdl_interp.create_operation "test.success"
533 pdl_interp.erase %root
539 // CHECK-LABEL: test.check_result_count_1
540 // CHECK: "test.op"() : () -> i32
541 // CHECK: "test.success"() : () -> ()
542 // CHECK-NOT: "test.op"() : () -> (i32, i32)
543 module @ir attributes { test.check_result_count_1 } {
544 "test.op"() : () -> i32
545 "test.op"() : () -> (i32, i32)
550 //===----------------------------------------------------------------------===//
551 // pdl_interp::CheckTypeOp
552 //===----------------------------------------------------------------------===//
555 pdl_interp.func @matcher(%root : !pdl.operation) {
556 %attr = pdl_interp.get_attribute "test_attr" of %root
557 pdl_interp.is_not_null %attr : !pdl.attribute -> ^pat1, ^end
560 %type = pdl_interp.get_attribute_type of %attr
561 pdl_interp.check_type %type is i32 -> ^pat2, ^end
564 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
571 pdl_interp.func @success(%root : !pdl.operation) {
572 %op = pdl_interp.create_operation "test.success"
573 pdl_interp.erase %root
579 // CHECK-LABEL: test.check_type_1
580 // CHECK: "test.success"
581 module @ir attributes { test.check_type_1 } {
582 "test.op"() { test_attr = 10 : i32 } : () -> ()
587 //===----------------------------------------------------------------------===//
588 // pdl_interp::CheckTypesOp
589 //===----------------------------------------------------------------------===//
592 pdl_interp.func @matcher(%root : !pdl.operation) {
593 %results = pdl_interp.get_results of %root : !pdl.range<value>
594 %result_types = pdl_interp.get_value_type of %results : !pdl.range<type>
595 pdl_interp.check_types %result_types are [i32] -> ^pat2, ^end
598 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
605 pdl_interp.func @success(%root : !pdl.operation) {
606 %op = pdl_interp.create_operation "test.success"
607 pdl_interp.erase %root
613 // CHECK-LABEL: test.check_types_1
614 // CHECK: "test.op"() : () -> (i32, i64)
615 // CHECK: "test.success"
616 // CHECK-NOT: "test.op"() : () -> i32
617 module @ir attributes { test.check_types_1 } {
618 "test.op"() : () -> (i32, i64)
619 "test.op"() : () -> i32
624 //===----------------------------------------------------------------------===//
625 // pdl_interp::ContinueOp
626 //===----------------------------------------------------------------------===//
628 // Fully tested within the tests for other operations.
630 //===----------------------------------------------------------------------===//
631 // pdl_interp::CreateAttributeOp
632 //===----------------------------------------------------------------------===//
634 // Fully tested within the tests for other operations.
636 //===----------------------------------------------------------------------===//
637 // pdl_interp::CreateOperationOp
638 //===----------------------------------------------------------------------===//
640 // Unused operation to force loading the `arithmetic` dialect for the
641 // test of type inferrence.
644 // Test support for inferring the types of an operation.
646 pdl_interp.func @matcher(%root : !pdl.operation) {
647 pdl_interp.check_operation_name of %root is "test.op" -> ^pat, ^end
650 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
657 pdl_interp.func @success(%root : !pdl.operation) {
658 %attr = pdl_interp.create_attribute true
659 %cst = pdl_interp.create_operation "arith.constant" {"value" = %attr} -> <inferred>
660 %cstResults = pdl_interp.get_results of %cst : !pdl.range<value>
661 %op = pdl_interp.create_operation "test.success"(%cstResults : !pdl.range<value>)
662 pdl_interp.erase %root
668 // CHECK-LABEL: test.create_op_infer_results
669 // CHECK: %[[CST:.*]] = arith.constant true
670 // CHECK: "test.success"(%[[CST]])
671 module @ir attributes { test.create_op_infer_results } {
672 %results:2 = "test.op"() : () -> (i64, i64)
677 //===----------------------------------------------------------------------===//
678 // pdl_interp::CreateRangeOp
679 //===----------------------------------------------------------------------===//
682 pdl_interp.func @matcher(%root : !pdl.operation) {
683 pdl_interp.check_operand_count of %root is 2 -> ^pat1, ^end
686 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
693 pdl_interp.func @success(%root: !pdl.operation) {
694 %rootOperand = pdl_interp.get_operand 0 of %root
695 %rootOperands = pdl_interp.get_operands of %root : !pdl.range<value>
696 %operandRange = pdl_interp.create_range %rootOperand, %rootOperands : !pdl.value, !pdl.range<value>
698 %operandType = pdl_interp.get_value_type of %rootOperand : !pdl.type
699 %operandTypes = pdl_interp.get_value_type of %rootOperands : !pdl.range<type>
700 %typeRange = pdl_interp.create_range %operandType, %operandTypes : !pdl.type, !pdl.range<type>
702 %op = pdl_interp.create_operation "test.success"(%operandRange : !pdl.range<value>) -> (%typeRange : !pdl.range<type>)
703 pdl_interp.erase %root
709 // CHECK-LABEL: test.create_range_1
710 // CHECK: %[[INPUTS:.*]]:2 = "test.input"()
711 // CHECK: "test.success"(%[[INPUTS]]#0, %[[INPUTS]]#0, %[[INPUTS]]#1) : (i32, i32, i32) -> (i32, i32, i32)
712 module @ir attributes { test.create_range_1 } {
713 %values:2 = "test.input"() : () -> (i32, i32)
714 "test.op"(%values#0, %values#1) : (i32, i32) -> ()
719 //===----------------------------------------------------------------------===//
720 // pdl_interp::CreateTypeOp
721 //===----------------------------------------------------------------------===//
724 pdl_interp.func @matcher(%root : !pdl.operation) {
725 %attr = pdl_interp.get_attribute "test_attr" of %root
726 pdl_interp.is_not_null %attr : !pdl.attribute -> ^pat1, ^end
729 %test_type = pdl_interp.create_type i32
730 %type = pdl_interp.get_attribute_type of %attr
731 pdl_interp.are_equal %type, %test_type : !pdl.type -> ^pat2, ^end
734 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
741 pdl_interp.func @success(%root : !pdl.operation) {
742 %op = pdl_interp.create_operation "test.success"
743 pdl_interp.erase %root
749 // CHECK-LABEL: test.create_type_1
750 // CHECK: "test.success"
751 module @ir attributes { test.create_type_1 } {
752 "test.op"() { test_attr = 0 : i32 } : () -> ()
757 //===----------------------------------------------------------------------===//
758 // pdl_interp::CreateTypesOp
759 //===----------------------------------------------------------------------===//
761 // Fully tested within the tests for other operations.
763 //===----------------------------------------------------------------------===//
764 // pdl_interp::EraseOp
765 //===----------------------------------------------------------------------===//
767 // Fully tested within the tests for other operations.
769 //===----------------------------------------------------------------------===//
770 // pdl_interp::ExtractOp
771 //===----------------------------------------------------------------------===//
774 pdl_interp.func @matcher(%root : !pdl.operation) {
775 %val = pdl_interp.get_result 0 of %root
776 %ops = pdl_interp.get_users of %val : !pdl.value
777 %op1 = pdl_interp.extract 1 of %ops : !pdl.operation
778 pdl_interp.is_not_null %op1 : !pdl.operation -> ^success, ^end
780 pdl_interp.record_match @rewriters::@success(%op1 : !pdl.operation) : benefit(1), loc([%root]) -> ^end
786 pdl_interp.func @success(%matched : !pdl.operation) {
787 %op = pdl_interp.create_operation "test.success"
788 pdl_interp.erase %matched
794 // CHECK-LABEL: test.extract_op
795 // CHECK: "test.success"
796 // CHECK: %[[OPERAND:.*]] = "test.op"
797 // CHECK: "test.op"(%[[OPERAND]])
798 module @ir attributes { test.extract_op } {
799 %operand = "test.op"() : () -> i32
800 "test.op"(%operand) : (i32) -> (i32)
801 "test.op"(%operand, %operand) : (i32, i32) -> (i32)
807 pdl_interp.func @matcher(%root : !pdl.operation) {
808 %vals = pdl_interp.get_results of %root : !pdl.range<value>
809 %types = pdl_interp.get_value_type of %vals : !pdl.range<type>
810 %type1 = pdl_interp.extract 1 of %types : !pdl.type
811 pdl_interp.is_not_null %type1 : !pdl.type -> ^success, ^end
813 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
819 pdl_interp.func @success(%matched : !pdl.operation) {
820 %op = pdl_interp.create_operation "test.success"
821 pdl_interp.erase %matched
827 // CHECK-LABEL: test.extract_type
828 // CHECK: %[[OPERAND:.*]] = "test.op"
829 // CHECK: "test.success"
830 // CHECK: "test.op"(%[[OPERAND]])
831 module @ir attributes { test.extract_type } {
832 %operand = "test.op"() : () -> i32
833 "test.op"(%operand) : (i32) -> (i32, i32)
834 "test.op"(%operand) : (i32) -> (i32)
840 pdl_interp.func @matcher(%root : !pdl.operation) {
841 %vals = pdl_interp.get_results of %root : !pdl.range<value>
842 %val1 = pdl_interp.extract 1 of %vals : !pdl.value
843 pdl_interp.is_not_null %val1 : !pdl.value -> ^success, ^end
845 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
851 pdl_interp.func @success(%matched : !pdl.operation) {
852 %op = pdl_interp.create_operation "test.success"
853 pdl_interp.erase %matched
859 // CHECK-LABEL: test.extract_value
860 // CHECK: %[[OPERAND:.*]] = "test.op"
861 // CHECK: "test.success"
862 // CHECK: "test.op"(%[[OPERAND]])
863 module @ir attributes { test.extract_value } {
864 %operand = "test.op"() : () -> i32
865 "test.op"(%operand) : (i32) -> (i32, i32)
866 "test.op"(%operand) : (i32) -> (i32)
871 //===----------------------------------------------------------------------===//
872 // pdl_interp::FinalizeOp
873 //===----------------------------------------------------------------------===//
875 // Fully tested within the tests for other operations.
877 //===----------------------------------------------------------------------===//
878 // pdl_interp::ForEachOp
879 //===----------------------------------------------------------------------===//
882 pdl_interp.func @matcher(%root : !pdl.operation) {
883 %val1 = pdl_interp.get_result 0 of %root
884 %ops1 = pdl_interp.get_users of %val1 : !pdl.value
885 pdl_interp.foreach %op1 : !pdl.operation in %ops1 {
886 %val2 = pdl_interp.get_result 0 of %op1
887 %ops2 = pdl_interp.get_users of %val2 : !pdl.value
888 pdl_interp.foreach %op2 : !pdl.operation in %ops2 {
889 pdl_interp.record_match @rewriters::@success(%op2 : !pdl.operation) : benefit(1), loc([%root]) -> ^cont
901 pdl_interp.func @success(%matched : !pdl.operation) {
902 %op = pdl_interp.create_operation "test.success"
903 pdl_interp.erase %matched
909 // CHECK-LABEL: test.foreach
910 // CHECK: "test.success"
911 // CHECK: "test.success"
912 // CHECK: "test.success"
913 // CHECK: "test.success"
914 // CHECK: %[[ROOT:.*]] = "test.op"
915 // CHECK: %[[VALA:.*]] = "test.op"(%[[ROOT]])
916 // CHECK: %[[VALB:.*]] = "test.op"(%[[ROOT]])
917 module @ir attributes { test.foreach } {
918 %root = "test.op"() : () -> i32
919 %valA = "test.op"(%root) : (i32) -> (i32)
920 "test.op"(%valA) : (i32) -> (i32)
921 "test.op"(%valA) : (i32) -> (i32)
922 %valB = "test.op"(%root) : (i32) -> (i32)
923 "test.op"(%valB) : (i32) -> (i32)
924 "test.op"(%valB) : (i32) -> (i32)
929 //===----------------------------------------------------------------------===//
930 // pdl_interp::GetUsersOp
931 //===----------------------------------------------------------------------===//
934 pdl_interp.func @matcher(%root : !pdl.operation) {
935 %val = pdl_interp.get_result 0 of %root
936 %ops = pdl_interp.get_users of %val : !pdl.value
937 pdl_interp.foreach %op : !pdl.operation in %ops {
938 pdl_interp.record_match @rewriters::@success(%op : !pdl.operation) : benefit(1), loc([%root]) -> ^cont
947 pdl_interp.func @success(%matched : !pdl.operation) {
948 %op = pdl_interp.create_operation "test.success"
949 pdl_interp.erase %matched
955 // CHECK-LABEL: test.get_users_of_value
956 // CHECK: "test.success"
957 // CHECK: "test.success"
958 // CHECK: %[[OPERAND:.*]] = "test.op"
959 module @ir attributes { test.get_users_of_value } {
960 %operand = "test.op"() : () -> i32
961 "test.op"(%operand) : (i32) -> (i32)
962 "test.op"(%operand, %operand) : (i32, i32) -> (i32)
968 pdl_interp.func @matcher(%root : !pdl.operation) {
969 pdl_interp.check_result_count of %root is at_least 2 -> ^next, ^end
971 %vals = pdl_interp.get_results of %root : !pdl.range<value>
972 %ops = pdl_interp.get_users of %vals : !pdl.range<value>
973 pdl_interp.foreach %op : !pdl.operation in %ops {
974 pdl_interp.record_match @rewriters::@success(%op : !pdl.operation) : benefit(1), loc([%root]) -> ^cont
983 pdl_interp.func @success(%matched : !pdl.operation) {
984 %op = pdl_interp.create_operation "test.success"
985 pdl_interp.erase %matched
991 // CHECK-LABEL: test.get_all_users_of_range
992 // CHECK: "test.success"
993 // CHECK: "test.success"
994 // CHECK: %[[OPERANDS:.*]]:2 = "test.op"
995 module @ir attributes { test.get_all_users_of_range } {
996 %operands:2 = "test.op"() : () -> (i32, i32)
997 "test.op"(%operands#0) : (i32) -> (i32)
998 "test.op"(%operands#1) : (i32) -> (i32)
1004 pdl_interp.func @matcher(%root : !pdl.operation) {
1005 pdl_interp.check_result_count of %root is at_least 2 -> ^next, ^end
1007 %vals = pdl_interp.get_results of %root : !pdl.range<value>
1008 %val = pdl_interp.extract 0 of %vals : !pdl.value
1009 %ops = pdl_interp.get_users of %val : !pdl.value
1010 pdl_interp.foreach %op : !pdl.operation in %ops {
1011 pdl_interp.record_match @rewriters::@success(%op : !pdl.operation) : benefit(1), loc([%root]) -> ^cont
1020 pdl_interp.func @success(%matched : !pdl.operation) {
1021 %op = pdl_interp.create_operation "test.success"
1022 pdl_interp.erase %matched
1028 // CHECK-LABEL: test.get_first_users_of_range
1029 // CHECK: "test.success"
1030 // CHECK: %[[OPERANDS:.*]]:2 = "test.op"
1032 module @ir attributes { test.get_first_users_of_range } {
1033 %operands:2 = "test.op"() : () -> (i32, i32)
1034 "test.op"(%operands#0) : (i32) -> (i32)
1035 "test.op"(%operands#1) : (i32) -> (i32)
1040 //===----------------------------------------------------------------------===//
1041 // pdl_interp::GetAttributeOp
1042 //===----------------------------------------------------------------------===//
1044 // Fully tested within the tests for other operations.
1046 //===----------------------------------------------------------------------===//
1047 // pdl_interp::GetAttributeTypeOp
1048 //===----------------------------------------------------------------------===//
1050 // Fully tested within the tests for other operations.
1052 //===----------------------------------------------------------------------===//
1053 // pdl_interp::GetDefiningOpOp
1054 //===----------------------------------------------------------------------===//
1057 pdl_interp.func @matcher(%root : !pdl.operation) {
1058 pdl_interp.check_operand_count of %root is 5 -> ^pat1, ^end
1061 %operand0 = pdl_interp.get_operand 0 of %root
1062 %operand4 = pdl_interp.get_operand 4 of %root
1063 %defOp0 = pdl_interp.get_defining_op of %operand0 : !pdl.value
1064 %defOp4 = pdl_interp.get_defining_op of %operand4 : !pdl.value
1065 pdl_interp.are_equal %defOp0, %defOp4 : !pdl.operation -> ^pat2, ^end
1068 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
1075 pdl_interp.func @success(%root : !pdl.operation) {
1076 %op = pdl_interp.create_operation "test.success"
1077 pdl_interp.erase %root
1083 // CHECK-LABEL: test.get_defining_op_1
1084 // CHECK: %[[OPERAND0:.*]] = "test.op"
1085 // CHECK: %[[OPERAND1:.*]] = "test.op"
1086 // CHECK: "test.success"
1087 // CHECK: "test.op"(%[[OPERAND0]], %[[OPERAND0]], %[[OPERAND0]], %[[OPERAND0]], %[[OPERAND1]])
1088 module @ir attributes { test.get_defining_op_1 } {
1089 %operand = "test.op"() : () -> i32
1090 %other_operand = "test.op"() : () -> i32
1091 "test.op"(%operand, %operand, %operand, %operand, %operand) : (i32, i32, i32, i32, i32) -> ()
1092 "test.op"(%operand, %operand, %operand, %operand, %other_operand) : (i32, i32, i32, i32, i32) -> ()
1097 //===----------------------------------------------------------------------===//
1098 // pdl_interp::GetOperandOp
1099 //===----------------------------------------------------------------------===//
1101 // Fully tested within the tests for other operations.
1103 //===----------------------------------------------------------------------===//
1104 // pdl_interp::GetOperandsOp
1105 //===----------------------------------------------------------------------===//
1108 pdl_interp.func @matcher(%root : !pdl.operation) {
1109 pdl_interp.check_operand_count of %root is 2 -> ^pat1, ^end
1112 %operands = pdl_interp.get_operands 0 of %root : !pdl.range<value>
1113 %full_operands = pdl_interp.get_operands of %root : !pdl.range<value>
1114 pdl_interp.are_equal %operands, %full_operands : !pdl.range<value> -> ^pat2, ^end
1117 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
1124 pdl_interp.func @success(%root : !pdl.operation) {
1125 %op = pdl_interp.create_operation "test.success"
1126 pdl_interp.erase %root
1132 // CHECK-LABEL: test.get_operands_1
1133 // CHECK: "test.success"
1134 module @ir attributes { test.get_operands_1 } {
1135 %inputs:2 = "test.producer"() : () -> (i32, i32)
1136 "test.op"(%inputs#0, %inputs#1) : (i32, i32) -> ()
1141 // Test all of the various combinations related to `AttrSizedOperandSegments`.
1143 pdl_interp.func @matcher(%root : !pdl.operation) {
1144 pdl_interp.check_operation_name of %root is "test.attr_sized_operands" -> ^pat1, ^end
1147 %operands_0 = pdl_interp.get_operands 0 of %root : !pdl.range<value>
1148 pdl_interp.is_not_null %operands_0 : !pdl.range<value> -> ^pat2, ^end
1151 %operands_0_single = pdl_interp.get_operands 0 of %root : !pdl.value
1152 pdl_interp.is_not_null %operands_0_single : !pdl.value -> ^end, ^pat3
1155 %operands_1 = pdl_interp.get_operands 1 of %root : !pdl.range<value>
1156 pdl_interp.is_not_null %operands_1 : !pdl.range<value> -> ^pat4, ^end
1159 %operands_1_single = pdl_interp.get_operands 1 of %root : !pdl.value
1160 pdl_interp.is_not_null %operands_1_single : !pdl.value -> ^end, ^pat5
1163 %operands_2 = pdl_interp.get_operands 2 of %root : !pdl.range<value>
1164 pdl_interp.is_not_null %operands_2 : !pdl.range<value> -> ^pat6, ^end
1167 %operands_2_single = pdl_interp.get_operands 2 of %root : !pdl.value
1168 pdl_interp.is_not_null %operands_2_single : !pdl.value -> ^pat7, ^end
1171 %invalid_operands = pdl_interp.get_operands 50 of %root : !pdl.value
1172 pdl_interp.is_not_null %invalid_operands : !pdl.value -> ^end, ^pat8
1175 pdl_interp.record_match @rewriters::@success(%root, %operands_0, %operands_1, %operands_2, %operands_2_single : !pdl.operation, !pdl.range<value>, !pdl.range<value>, !pdl.range<value>, !pdl.value) : benefit(1), loc([%root]) -> ^end
1183 pdl_interp.func @success(%root: !pdl.operation, %operands_0: !pdl.range<value>, %operands_1: !pdl.range<value>, %operands_2: !pdl.range<value>, %operands_2_single: !pdl.value) {
1184 %op0 = pdl_interp.create_operation "test.success"(%operands_0 : !pdl.range<value>)
1185 %op1 = pdl_interp.create_operation "test.success"(%operands_1 : !pdl.range<value>)
1186 %op2 = pdl_interp.create_operation "test.success"(%operands_2 : !pdl.range<value>)
1187 %op3 = pdl_interp.create_operation "test.success"(%operands_2_single : !pdl.value)
1188 pdl_interp.erase %root
1194 // CHECK-LABEL: test.get_operands_2
1195 // CHECK-NEXT: %[[INPUTS:.*]]:5 = "test.producer"() : () -> (i32, i32, i32, i32, i32)
1196 // CHECK-NEXT: "test.success"() : () -> ()
1197 // CHECK-NEXT: "test.success"(%[[INPUTS]]#0, %[[INPUTS]]#1, %[[INPUTS]]#2, %[[INPUTS]]#3) : (i32, i32, i32, i32) -> ()
1198 // CHECK-NEXT: "test.success"(%[[INPUTS]]#4) : (i32) -> ()
1199 // CHECK-NEXT: "test.success"(%[[INPUTS]]#4) : (i32) -> ()
1200 module @ir attributes { test.get_operands_2 } {
1201 %inputs:5 = "test.producer"() : () -> (i32, i32, i32, i32, i32)
1202 "test.attr_sized_operands"(%inputs#0, %inputs#1, %inputs#2, %inputs#3, %inputs#4) {operandSegmentSizes = array<i32: 0, 4, 1, 0>} : (i32, i32, i32, i32, i32) -> ()
1207 //===----------------------------------------------------------------------===//
1208 // pdl_interp::GetResultOp
1209 //===----------------------------------------------------------------------===//
1212 pdl_interp.func @matcher(%root : !pdl.operation) {
1213 pdl_interp.check_result_count of %root is 5 -> ^pat1, ^end
1216 %result0 = pdl_interp.get_result 0 of %root
1217 %result4 = pdl_interp.get_result 4 of %root
1218 %result0_type = pdl_interp.get_value_type of %result0 : !pdl.type
1219 %result4_type = pdl_interp.get_value_type of %result4 : !pdl.type
1220 pdl_interp.are_equal %result0_type, %result4_type : !pdl.type -> ^pat2, ^end
1223 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
1230 pdl_interp.func @success(%root : !pdl.operation) {
1231 %op = pdl_interp.create_operation "test.success"
1232 pdl_interp.erase %root
1238 // CHECK-LABEL: test.get_result_1
1239 // CHECK: "test.success"
1240 // CHECK: "test.op"() : () -> (i32, i32, i32, i32, i64)
1241 module @ir attributes { test.get_result_1 } {
1242 %a:5 = "test.op"() : () -> (i32, i32, i32, i32, i32)
1243 %b:5 = "test.op"() : () -> (i32, i32, i32, i32, i64)
1248 //===----------------------------------------------------------------------===//
1249 // pdl_interp::GetResultsOp
1250 //===----------------------------------------------------------------------===//
1253 pdl_interp.func @matcher(%root : !pdl.operation) {
1254 pdl_interp.check_result_count of %root is 5 -> ^pat1, ^end
1257 %results = pdl_interp.get_results 0 of %root : !pdl.range<value>
1258 %full_results = pdl_interp.get_results of %root : !pdl.range<value>
1259 pdl_interp.are_equal %results, %full_results : !pdl.range<value> -> ^pat2, ^end
1262 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
1269 pdl_interp.func @success(%root : !pdl.operation) {
1270 %op = pdl_interp.create_operation "test.success"
1271 pdl_interp.erase %root
1277 // CHECK-LABEL: test.get_results_1
1278 // CHECK: "test.success"
1279 module @ir attributes { test.get_results_1 } {
1280 %a:5 = "test.producer"() : () -> (i32, i32, i32, i32, i32)
1285 // Test all of the various combinations related to `AttrSizedResultSegments`.
1287 pdl_interp.func @matcher(%root : !pdl.operation) {
1288 pdl_interp.check_operation_name of %root is "test.attr_sized_results" -> ^pat1, ^end
1291 %results_0 = pdl_interp.get_results 0 of %root : !pdl.range<value>
1292 pdl_interp.is_not_null %results_0 : !pdl.range<value> -> ^pat2, ^end
1295 %results_0_single = pdl_interp.get_results 0 of %root : !pdl.value
1296 pdl_interp.is_not_null %results_0_single : !pdl.value -> ^end, ^pat3
1299 %results_1 = pdl_interp.get_results 1 of %root : !pdl.range<value>
1300 pdl_interp.is_not_null %results_1 : !pdl.range<value> -> ^pat4, ^end
1303 %results_1_single = pdl_interp.get_results 1 of %root : !pdl.value
1304 pdl_interp.is_not_null %results_1_single : !pdl.value -> ^end, ^pat5
1307 %results_2 = pdl_interp.get_results 2 of %root : !pdl.range<value>
1308 pdl_interp.is_not_null %results_2 : !pdl.range<value> -> ^pat6, ^end
1311 %results_2_single = pdl_interp.get_results 2 of %root : !pdl.value
1312 pdl_interp.is_not_null %results_2_single : !pdl.value -> ^pat7, ^end
1315 %invalid_results = pdl_interp.get_results 50 of %root : !pdl.value
1316 pdl_interp.is_not_null %invalid_results : !pdl.value -> ^end, ^pat8
1319 pdl_interp.record_match @rewriters::@success(%root, %results_0, %results_1, %results_2, %results_2_single : !pdl.operation, !pdl.range<value>, !pdl.range<value>, !pdl.range<value>, !pdl.value) : benefit(1), loc([%root]) -> ^end
1327 pdl_interp.func @success(%root: !pdl.operation, %results_0: !pdl.range<value>, %results_1: !pdl.range<value>, %results_2: !pdl.range<value>, %results_2_single: !pdl.value) {
1328 %results_0_types = pdl_interp.get_value_type of %results_0 : !pdl.range<type>
1329 %results_1_types = pdl_interp.get_value_type of %results_1 : !pdl.range<type>
1330 %results_2_types = pdl_interp.get_value_type of %results_2 : !pdl.range<type>
1331 %results_2_single_types = pdl_interp.get_value_type of %results_2_single : !pdl.type
1333 %op0 = pdl_interp.create_operation "test.success" -> (%results_0_types : !pdl.range<type>)
1334 %op1 = pdl_interp.create_operation "test.success" -> (%results_1_types : !pdl.range<type>)
1335 %op2 = pdl_interp.create_operation "test.success" -> (%results_2_types : !pdl.range<type>)
1336 %op3 = pdl_interp.create_operation "test.success" -> (%results_2_single_types : !pdl.type)
1338 %new_results_0 = pdl_interp.get_results of %op0 : !pdl.range<value>
1339 %new_results_1 = pdl_interp.get_results of %op1 : !pdl.range<value>
1340 %new_results_2 = pdl_interp.get_results of %op2 : !pdl.range<value>
1342 pdl_interp.replace %root with (%new_results_0, %new_results_1, %new_results_2 : !pdl.range<value>, !pdl.range<value>, !pdl.range<value>)
1348 // CHECK-LABEL: test.get_results_2
1349 // CHECK: "test.success"() : () -> ()
1350 // CHECK: %[[RESULTS_1:.*]]:4 = "test.success"() : () -> (i32, i32, i32, i32)
1351 // CHECK: %[[RESULTS_2:.*]] = "test.success"() : () -> i32
1352 // CHECK: %[[RESULTS_2_SINGLE:.*]] = "test.success"() : () -> i32
1353 // CHECK: "test.consumer"(%[[RESULTS_1]]#0, %[[RESULTS_1]]#1, %[[RESULTS_1]]#2, %[[RESULTS_1]]#3, %[[RESULTS_2]]) : (i32, i32, i32, i32, i32) -> ()
1354 module @ir attributes { test.get_results_2 } {
1355 %results:5 = "test.attr_sized_results"() {resultSegmentSizes = array<i32: 0, 4, 1, 0>} : () -> (i32, i32, i32, i32, i32)
1356 "test.consumer"(%results#0, %results#1, %results#2, %results#3, %results#4) : (i32, i32, i32, i32, i32) -> ()
1361 //===----------------------------------------------------------------------===//
1362 // pdl_interp::GetValueTypeOp
1363 //===----------------------------------------------------------------------===//
1365 // Fully tested within the tests for other operations.
1367 //===----------------------------------------------------------------------===//
1368 // pdl_interp::IsNotNullOp
1369 //===----------------------------------------------------------------------===//
1371 // Fully tested within the tests for other operations.
1373 //===----------------------------------------------------------------------===//
1374 // pdl_interp::RecordMatchOp
1375 //===----------------------------------------------------------------------===//
1377 // Check that the highest benefit pattern is selected.
1379 pdl_interp.func @matcher(%root : !pdl.operation) {
1380 pdl_interp.check_operation_name of %root is "test.op" -> ^pat1, ^end
1383 pdl_interp.record_match @rewriters::@failure(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^pat2
1386 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(2), loc([%root]) -> ^end
1393 pdl_interp.func @failure(%root : !pdl.operation) {
1394 pdl_interp.erase %root
1397 pdl_interp.func @success(%root : !pdl.operation) {
1398 %op = pdl_interp.create_operation "test.success"
1399 pdl_interp.erase %root
1405 // CHECK-LABEL: test.record_match_1
1406 // CHECK: "test.success"
1407 module @ir attributes { test.record_match_1 } {
1408 "test.op"() : () -> ()
1413 // Check that ranges are properly forwarded to the result.
1415 pdl_interp.func @matcher(%root : !pdl.operation) {
1416 pdl_interp.check_operation_name of %root is "test.op" -> ^pat1, ^end
1419 %operands = pdl_interp.get_operands of %root : !pdl.range<value>
1420 %results = pdl_interp.get_results of %root : !pdl.range<value>
1421 %types = pdl_interp.get_value_type of %results : !pdl.range<type>
1422 pdl_interp.record_match @rewriters::@success(%operands, %types, %root : !pdl.range<value>, !pdl.range<type>, !pdl.operation) : benefit(1), loc([%root]) -> ^end
1429 pdl_interp.func @success(%operands: !pdl.range<value>, %types: !pdl.range<type>, %root: !pdl.operation) {
1430 %op = pdl_interp.create_operation "test.success"(%operands : !pdl.range<value>) -> (%types : !pdl.range<type>)
1431 %results = pdl_interp.get_results of %op : !pdl.range<value>
1432 pdl_interp.replace %root with (%results : !pdl.range<value>)
1438 // CHECK-LABEL: test.record_match_2
1439 // CHECK: %[[OPERAND:.*]] = "test.producer"() : () -> i32
1440 // CHECK: %[[RESULTS:.*]]:2 = "test.success"(%[[OPERAND]]) : (i32) -> (i64, i32)
1441 // CHECK: "test.consumer"(%[[RESULTS]]#0, %[[RESULTS]]#1) : (i64, i32) -> ()
1442 module @ir attributes { test.record_match_2 } {
1443 %input = "test.producer"() : () -> i32
1444 %results:2 = "test.op"(%input) : (i32) -> (i64, i32)
1445 "test.consumer"(%results#0, %results#1) : (i64, i32) -> ()
1450 //===----------------------------------------------------------------------===//
1451 // pdl_interp::ReplaceOp
1452 //===----------------------------------------------------------------------===//
1455 pdl_interp.func @matcher(%root : !pdl.operation) {
1456 pdl_interp.check_operation_name of %root is "test.op" -> ^pat, ^end
1459 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
1466 pdl_interp.func @success(%root : !pdl.operation) {
1467 %operand = pdl_interp.get_operand 0 of %root
1468 pdl_interp.replace %root with (%operand : !pdl.value)
1474 // CHECK-LABEL: test.replace_op_1
1475 // CHECK: %[[INPUT:.*]] = "test.op_input"
1476 // CHECK-NOT: "test.op"
1477 // CHECK: "test.op_consumer"(%[[INPUT]])
1478 module @ir attributes { test.replace_op_1 } {
1479 %input = "test.op_input"() : () -> i32
1480 %result = "test.op"(%input) : (i32) -> i32
1481 "test.op_consumer"(%result) : (i32) -> ()
1486 //===----------------------------------------------------------------------===//
1487 // pdl_interp::SwitchAttributeOp
1488 //===----------------------------------------------------------------------===//
1491 pdl_interp.func @matcher(%root : !pdl.operation) {
1492 %attr = pdl_interp.get_attribute "test_attr" of %root
1493 pdl_interp.switch_attribute %attr to [0, unit](^end, ^pat) -> ^end
1496 %attr_2 = pdl_interp.get_attribute "test_attr_2" of %root
1497 pdl_interp.switch_attribute %attr_2 to [0, unit](^end, ^end) -> ^pat2
1500 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
1507 pdl_interp.func @success(%root : !pdl.operation) {
1508 %op = pdl_interp.create_operation "test.success"
1509 pdl_interp.erase %root
1515 // CHECK-LABEL: test.switch_attribute_1
1516 // CHECK: "test.success"
1517 module @ir attributes { test.switch_attribute_1 } {
1518 "test.op"() { test_attr } : () -> ()
1523 //===----------------------------------------------------------------------===//
1524 // pdl_interp::SwitchOperandCountOp
1525 //===----------------------------------------------------------------------===//
1528 pdl_interp.func @matcher(%root : !pdl.operation) {
1529 pdl_interp.switch_operand_count of %root to dense<[0, 1]> : vector<2xi32>(^end, ^pat) -> ^end
1532 pdl_interp.switch_operand_count of %root to dense<[0, 2]> : vector<2xi32>(^end, ^end) -> ^pat2
1535 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
1542 pdl_interp.func @success(%root : !pdl.operation) {
1543 %op = pdl_interp.create_operation "test.success"
1544 pdl_interp.erase %root
1550 // CHECK-LABEL: test.switch_operand_1
1551 // CHECK: "test.success"
1552 module @ir attributes { test.switch_operand_1 } {
1553 %input = "test.op_input"() : () -> i32
1554 "test.op"(%input) : (i32) -> ()
1559 //===----------------------------------------------------------------------===//
1560 // pdl_interp::SwitchOperationNameOp
1561 //===----------------------------------------------------------------------===//
1564 pdl_interp.func @matcher(%root : !pdl.operation) {
1565 pdl_interp.switch_operation_name of %root to ["foo.op", "test.op"](^end, ^pat1) -> ^end
1568 pdl_interp.switch_operation_name of %root to ["foo.op", "bar.op"](^end, ^end) -> ^pat2
1571 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
1578 pdl_interp.func @success(%root : !pdl.operation) {
1579 %op = pdl_interp.create_operation "test.success"
1580 pdl_interp.erase %root
1586 // CHECK-LABEL: test.switch_operation_name_1
1587 // CHECK: "test.success"
1588 module @ir attributes { test.switch_operation_name_1 } {
1589 "test.op"() : () -> ()
1594 //===----------------------------------------------------------------------===//
1595 // pdl_interp::SwitchResultCountOp
1596 //===----------------------------------------------------------------------===//
1599 pdl_interp.func @matcher(%root : !pdl.operation) {
1600 pdl_interp.switch_result_count of %root to dense<[0, 1]> : vector<2xi32>(^end, ^pat) -> ^end
1603 pdl_interp.switch_result_count of %root to dense<[0, 2]> : vector<2xi32>(^end, ^end) -> ^pat2
1606 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
1613 pdl_interp.func @success(%root : !pdl.operation) {
1614 %op = pdl_interp.create_operation "test.success"
1615 pdl_interp.erase %root
1621 // CHECK-LABEL: test.switch_result_1
1622 // CHECK: "test.success"
1623 module @ir attributes { test.switch_result_1 } {
1624 "test.op"() : () -> i32
1629 //===----------------------------------------------------------------------===//
1630 // pdl_interp::SwitchTypeOp
1631 //===----------------------------------------------------------------------===//
1634 pdl_interp.func @matcher(%root : !pdl.operation) {
1635 %attr = pdl_interp.get_attribute "test_attr" of %root
1636 pdl_interp.is_not_null %attr : !pdl.attribute -> ^pat1, ^end
1639 %type = pdl_interp.get_attribute_type of %attr
1640 pdl_interp.switch_type %type to [i32, i64](^pat2, ^end) -> ^end
1643 pdl_interp.switch_type %type to [i16, i64](^end, ^end) -> ^pat3
1646 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
1653 pdl_interp.func @success(%root : !pdl.operation) {
1654 %op = pdl_interp.create_operation "test.success"
1655 pdl_interp.erase %root
1661 // CHECK-LABEL: test.switch_type_1
1662 // CHECK: "test.success"
1663 module @ir attributes { test.switch_type_1 } {
1664 "test.op"() { test_attr = 10 : i32 } : () -> ()
1669 //===----------------------------------------------------------------------===//
1670 // pdl_interp::SwitchTypesOp
1671 //===----------------------------------------------------------------------===//
1674 pdl_interp.func @matcher(%root : !pdl.operation) {
1675 %results = pdl_interp.get_results of %root : !pdl.range<value>
1676 %types = pdl_interp.get_value_type of %results : !pdl.range<type>
1677 pdl_interp.switch_types %types to [[i64, i64], [i32]](^pat2, ^end) -> ^end
1680 pdl_interp.switch_types %types to [[i32], [i64, i32]](^end, ^end) -> ^pat3
1683 pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
1690 pdl_interp.func @success(%root : !pdl.operation) {
1691 %op = pdl_interp.create_operation "test.success"
1692 pdl_interp.erase %root
1698 // CHECK-LABEL: test.switch_types_1
1699 // CHECK: "test.success"
1700 module @ir attributes { test.switch_types_1 } {
1701 %results:2 = "test.op"() : () -> (i64, i64)