Skip to content

Commit 5c457ff

Browse files
committed
add tests
1 parent bf50d70 commit 5c457ff

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

mlir/test/Conversion/PDLToPDLInterp/pdl-to-pdl-interp-matcher.mlir

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@ module @constraint_with_result_multiple {
130130

131131
// -----
132132

133+
// CHECK-LABEL: module @negated_constraint
134+
module @negated_constraint {
135+
// CHECK: func @matcher(%[[ROOT:.*]]: !pdl.operation)
136+
// CHECK: pdl_interp.apply_constraint "constraint"(%[[ROOT]] : !pdl.operation) {isNegated = true}
137+
// CHECK: pdl_interp.record_match @rewriters::@pdl_generated_rewriter(%[[ROOT]] : !pdl.operation)
138+
pdl.pattern : benefit(1) {
139+
%root = operation
140+
pdl.apply_native_constraint "constraint"(%root : !pdl.operation) {isNegated = true}
141+
rewrite %root with "rewriter"
142+
}
143+
}
144+
145+
// -----
146+
133147
// CHECK-LABEL: module @inputs
134148
module @inputs {
135149
// CHECK: func @matcher(%[[ROOT:.*]]: !pdl.operation)

mlir/test/Rewrite/pdl-bytecode.mlir

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,38 @@ module @ir attributes { test.apply_constraint_3 } {
103103

104104
// -----
105105

106+
// Test support for negated constraints.
107+
module @patterns {
108+
pdl_interp.func @matcher(%root : !pdl.operation) {
109+
pdl_interp.apply_constraint "single_entity_constraint"(%root : !pdl.operation) {isNegated = true} -> ^pat, ^end
110+
111+
^pat:
112+
pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end
113+
114+
^end:
115+
pdl_interp.finalize
116+
}
117+
118+
module @rewriters {
119+
pdl_interp.func @success(%root : !pdl.operation) {
120+
%op = pdl_interp.create_operation "test.replaced_by_pattern"
121+
pdl_interp.erase %root
122+
pdl_interp.finalize
123+
}
124+
}
125+
}
126+
127+
// CHECK-LABEL: test.apply_constraint_4
128+
// CHECK-NOT: "test.replaced_by_pattern"
129+
// CHECK: "test.replaced_by_pattern"
130+
131+
module @ir attributes { test.apply_constraint_4 } {
132+
"test.op"() : () -> ()
133+
"test.foo"() : () -> ()
134+
}
135+
136+
// -----
137+
106138
//===----------------------------------------------------------------------===//
107139
// pdl_interp::ApplyRewriteOp
108140
//===----------------------------------------------------------------------===//

mlir/test/mlir-pdll/CodeGen/MLIR/expr.pdll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ Pattern TestExternalCall => replace root: Op with TestRewrite(root);
3636

3737
// -----
3838

39+
// CHECK: pdl.pattern @TestExternalNegatedCall
40+
// CHECK: %[[ROOT:.*]] = operation
41+
// CHECK: apply_native_constraint "TestConstraint"(%[[ROOT]] : !pdl.operation) {isNegated = true}
42+
// CHECK: rewrite %[[ROOT]]
43+
// CHECK: erase %[[ROOT]]
44+
Constraint TestConstraint(op: Op);
45+
Pattern TestExternalNegatedCall with benefit(1) {
46+
let root = op : Op;
47+
!TestConstraint(root);
48+
erase root;
49+
}
50+
51+
// -----
52+
3953
//===----------------------------------------------------------------------===//
4054
// MemberAccessExpr
4155
//===----------------------------------------------------------------------===//

mlir/test/mlir-pdll/Parser/expr.pdll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Pattern {
9090
!checkOp(inputOp);
9191
erase inputOp;
9292
}
93+
9394
// -----
9495

9596
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)