File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -773,6 +773,7 @@ void Generator::generate(pdl_interp::ApplyConstraintOp op,
773
773
" expected index for constraint function" );
774
774
writer.append (OpCode::ApplyConstraint, constraintToMemIndex[op.getName ()]);
775
775
writer.appendPDLValueList (op.getArgs ());
776
+ writer.append (ByteCodeField (op.getIsNegated ()));
776
777
writer.append (op.getSuccessors ());
777
778
}
778
779
void Generator::generate (pdl_interp::ApplyRewriteOp op,
@@ -1413,10 +1414,16 @@ void ByteCodeExecutor::executeApplyConstraint(PatternRewriter &rewriter) {
1413
1414
LLVM_DEBUG ({
1414
1415
llvm::dbgs () << " * Arguments: " ;
1415
1416
llvm::interleaveComma (args, llvm::dbgs ());
1417
+ llvm::dbgs () << " \n " ;
1416
1418
});
1417
1419
1420
+ ByteCodeField isNegated = read ();
1421
+ LLVM_DEBUG ({
1422
+ llvm::dbgs () << " * isNegated: " << isNegated << " \n " ;
1423
+ llvm::interleaveComma (args, llvm::dbgs ());
1424
+ });
1418
1425
// Invoke the constraint and jump to the proper destination.
1419
- selectJump (succeeded (constraintFn (rewriter, args)));
1426
+ selectJump (isNegated != succeeded (constraintFn (rewriter, args)));
1420
1427
}
1421
1428
1422
1429
LogicalResult ByteCodeExecutor::executeApplyRewrite (PatternRewriter &rewriter) {
Original file line number Diff line number Diff line change @@ -72,6 +72,44 @@ module @ir attributes { test.apply_constraint_2 } {
72
72
73
73
// -----
74
74
75
+ // Test support for negated constraints.
76
+ module @patterns {
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
81
+
82
+ ^pat :
83
+ pdl_interp.apply_constraint " single_entity_constraint" (%root : !pdl.operation ) {isNegated = true } -> ^pat1 , ^end
84
+
85
+ ^pat1 :
86
+ pdl_interp.record_match @rewriters ::@success (%root : !pdl.operation ) : benefit (1 ), loc ([%root ]) -> ^end
87
+
88
+ ^end :
89
+ pdl_interp.finalize
90
+ }
91
+
92
+ module @rewriters {
93
+ pdl_interp.func @success (%root : !pdl.operation ) {
94
+ %op = pdl_interp.create_operation " test.replaced_by_pattern"
95
+ pdl_interp.erase %root
96
+ pdl_interp.finalize
97
+ }
98
+ }
99
+ }
100
+
101
+ // CHECK-LABEL: test.apply_constraint_3
102
+ // CHECK-NEXT: "test.replaced_by_pattern"
103
+ // CHECK-NOT: "test.replaced_by_pattern"
104
+
105
+ module @ir attributes { test.apply_constraint_3 } {
106
+ " test.foo" () { test_attr } : () -> ()
107
+ " test.op" () { test_attr } : () -> ()
108
+ }
109
+
110
+ // -----
111
+
112
+
75
113
//===----------------------------------------------------------------------===//
76
114
// pdl_interp::ApplyRewriteOp
77
115
//===----------------------------------------------------------------------===//
You can’t perform that action at this time.
0 commit comments