xref: /llvm-project/mlir/test/Conversion/PDLToPDLInterp/use-constraint-result.mlir (revision 8ec28af8eaff5acd0df3e53340159c034f08533d)
1// RUN: mlir-opt -split-input-file -convert-pdl-to-pdl-interp %s | FileCheck %s
2
3// Ensuse that the dependency between add & less
4// causes them to be in the correct order.
5// CHECK-LABEL: matcher
6// CHECK: apply_constraint "return_attr_constraint"
7// CHECK: apply_constraint "use_attr_constraint"
8
9module {
10  pdl.pattern : benefit(1) {
11    %0 = attribute
12    %1 = types
13    %2 = operation "tosa.mul" {"shift" = %0} -> (%1 : !pdl.range<type>)
14    %3 = attribute = 0 : i32
15    %4 = attribute = 1 : i32
16    %5 = apply_native_constraint "return_attr_constraint"(%3, %4 : !pdl.attribute, !pdl.attribute) : !pdl.attribute
17    apply_native_constraint "use_attr_constraint"(%0, %5 : !pdl.attribute, !pdl.attribute)
18    rewrite %2 with "rewriter"
19  }
20}
21
22// -----
23
24// CHECK-LABEL: matcher
25// CHECK: %[[ATTR:.*]] = pdl_interp.get_attribute "attr" of
26// CHECK: %[[CONSTRAINT:.*]] = pdl_interp.apply_constraint "return_attr_constraint"
27// CHECK: pdl_interp.are_equal %[[ATTR:.*]], %[[CONSTRAINT:.*]]
28
29pdl.pattern : benefit(1) {
30    %inputOp = operation
31    %result = result 0 of %inputOp
32    %attr = pdl.apply_native_constraint "return_attr_constraint"(%inputOp : !pdl.operation) : !pdl.attribute
33    %root = operation(%result : !pdl.value) {"attr" = %attr}
34    rewrite %root with "rewriter"(%attr : !pdl.attribute)
35}
36
37// -----
38
39// CHECK-LABEL: matcher
40// CHECK: %[[CONSTRAINT:.*]] = pdl_interp.apply_constraint "return_value_constr"
41// CHECK: %[[VALUE:.*]] = pdl_interp.get_operand 0
42// CHECK: pdl_interp.are_equal %[[VALUE:.*]], %[[CONSTRAINT:.*]]
43
44pdl.pattern : benefit(1) {
45    %attr = attribute = 10
46    %value = pdl.apply_native_constraint "return_value_constr"(%attr: !pdl.attribute) : !pdl.value
47    %root = operation(%value : !pdl.value)
48    rewrite %root with "rewriter"
49}
50
51// -----
52
53// CHECK-LABEL: matcher
54// CHECK: %[[CONSTRAINT:.*]] = pdl_interp.apply_constraint "return_type_constr"
55// CHECK: %[[TYPE:.*]] = pdl_interp.get_value_type of
56// CHECK: pdl_interp.are_equal %[[TYPE:.*]], %[[CONSTRAINT:.*]]
57
58pdl.pattern : benefit(1) {
59    %attr = attribute = 10
60    %type = pdl.apply_native_constraint "return_type_constr"(%attr: !pdl.attribute) : !pdl.type
61    %root = operation -> (%type : !pdl.type)
62    rewrite %root with "rewriter"
63}
64
65// -----
66
67// CHECK-LABEL: matcher
68// CHECK: %[[CONSTRAINT:.*]] = pdl_interp.apply_constraint "return_type_range_constr"
69// CHECK: %[[TYPE:.*]] = pdl_interp.get_value_type of
70// CHECK: pdl_interp.are_equal %[[TYPE:.*]], %[[CONSTRAINT:.*]]
71
72pdl.pattern : benefit(1) {
73    %attr = attribute = 10
74    %types = pdl.apply_native_constraint "return_type_range_constr"(%attr: !pdl.attribute) : !pdl.range<type>
75    %root = operation -> (%types : !pdl.range<type>)
76    rewrite %root with "rewriter"
77}
78