[Mlir-commits] [mlir] 7c471b5 - [mlir][pdl] OperationOp should not be side-effect free

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Jan 20 12:22:06 PST 2022


Author: Mogball
Date: 2022-01-20T20:22:01Z
New Revision: 7c471b56f2c22b984847100b318b01e31bf5f9cb

URL: https://github.com/llvm/llvm-project/commit/7c471b56f2c22b984847100b318b01e31bf5f9cb
DIFF: https://github.com/llvm/llvm-project/commit/7c471b56f2c22b984847100b318b01e31bf5f9cb.diff

LOG: [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

Added: 
    mlir/test/Dialect/PDL/canonicalize.mlir

Modified: 
    mlir/include/mlir/Dialect/PDL/IR/PDLOps.td
    mlir/test/Conversion/PDLToPDLInterp/pdl-to-pdl-interp-rewriter.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/PDL/IR/PDLOps.td b/mlir/include/mlir/Dialect/PDL/IR/PDLOps.td
index 4a97c17da4ac..258ad41292cc 100644
--- a/mlir/include/mlir/Dialect/PDL/IR/PDLOps.td
+++ b/mlir/include/mlir/Dialect/PDL/IR/PDLOps.td
@@ -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

diff  --git a/mlir/test/Conversion/PDLToPDLInterp/pdl-to-pdl-interp-rewriter.mlir b/mlir/test/Conversion/PDLToPDLInterp/pdl-to-pdl-interp-rewriter.mlir
index d2f135864071..f9415b3c4580 100644
--- a/mlir/test/Conversion/PDLToPDLInterp/pdl-to-pdl-interp-rewriter.mlir
+++ b/mlir/test/Conversion/PDLToPDLInterp/pdl-to-pdl-interp-rewriter.mlir
@@ -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"
+    }
+  }
+}
+
+// -----

diff  --git a/mlir/test/Dialect/PDL/canonicalize.mlir b/mlir/test/Dialect/PDL/canonicalize.mlir
new file mode 100644
index 000000000000..5cb08acd884e
--- /dev/null
+++ b/mlir/test/Dialect/PDL/canonicalize.mlir
@@ -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
+  }
+}


        


More information about the Mlir-commits mailing list