[mlir][pdl] OperationOp should not be side-effect free

Unbound OperationOp in the matcher (i.e. one with no uses) is already disallowed by the verifier. However, an OperationOp in the rewriter is not side-effect free -- it's creating an op!

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117825
This commit is contained in:
Mogball 2022-01-20 20:17:26 +00:00
parent d0cace5087
commit 7c471b56f2
3 changed files with 29 additions and 2 deletions

View File

@ -268,8 +268,7 @@ def PDL_OperandsOp
// pdl::OperationOp
//===----------------------------------------------------------------------===//
def PDL_OperationOp
: PDL_Op<"operation", [AttrSizedOperandSegments, NoSideEffect]> {
def PDL_OperationOp : PDL_Op<"operation", [AttrSizedOperandSegments]> {
let summary = "Define an operation within a pattern";
let description = [{
`pdl.operation` operations define operation nodes within a pattern. Within

View File

@ -202,3 +202,21 @@ module @apply_native_rewrite {
}
}
}
// -----
// CHECK-LABEL: module @unbound_rewrite_op
module @unbound_rewrite_op {
// CHECK: module @rewriters
// CHECK: func @pdl_generated_rewriter()
// CHECK: %[[UNUSED:.*]] = pdl_interp.create_operation "bar.op"
// CHECK: pdl_interp.finalize
pdl.pattern : benefit(1) {
%root = pdl.operation "foo.op"
pdl.rewrite %root {
%unused = pdl.operation "bar.op"
}
}
}
// -----

View File

@ -0,0 +1,10 @@
// RUN: mlir-opt -canonicalize %s | FileCheck %s
pdl.pattern @operation_op : benefit(1) {
%root = pdl.operation "foo.op"
pdl.rewrite %root {
// CHECK: pdl.operation "bar.unused"
%unused_rewrite = pdl.operation "bar.unused"
pdl.erase %root
}
}