[Mlir-commits] [mlir] 749f7f9 - [mlir][transform] Fix apply WithPDLPatternsOp with non-pattern op

Alex Zinenko llvmlistbot at llvm.org
Thu Feb 9 01:03:09 PST 2023


Author: Kohei Yamaguchi
Date: 2023-02-09T10:03:01+01:00
New Revision: 749f7f918d3159e3ed331075408a52a53b8b3c0d

URL: https://github.com/llvm/llvm-project/commit/749f7f918d3159e3ed331075408a52a53b8b3c0d
DIFF: https://github.com/llvm/llvm-project/commit/749f7f918d3159e3ed331075408a52a53b8b3c0d.diff

LOG: [mlir][transform] Fix apply WithPDLPatternsOp with non-pattern op

Fix https://github.com/llvm/llvm-project/issues/60209

Fix crash with segmentation fault when transform::WithPDLPatternsOp is
applied with non-pattern op. Added check for existing transform ops with
pattern op.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D143474

Added: 
    

Modified: 
    mlir/lib/Dialect/Transform/IR/TransformOps.cpp
    mlir/test/Dialect/Transform/ops-invalid.mlir
    mlir/test/Dialect/Transform/ops.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
index bc1ac6d5b0ffe..fed3bd1aea1e5 100644
--- a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
+++ b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
@@ -1048,6 +1048,12 @@ LogicalResult transform::WithPDLPatternsOp::verify() {
     return diag;
   }
 
+  if (!topLevelOp) {
+    InFlightDiagnostic diag = emitOpError()
+                              << "expects at least one non-pattern op";
+    return diag;
+  }
+
   return success();
 }
 

diff  --git a/mlir/test/Dialect/Transform/ops-invalid.mlir b/mlir/test/Dialect/Transform/ops-invalid.mlir
index 500fe61e01481..d2142db6386c8 100644
--- a/mlir/test/Dialect/Transform/ops-invalid.mlir
+++ b/mlir/test/Dialect/Transform/ops-invalid.mlir
@@ -124,6 +124,28 @@ transform.with_pdl_patterns {
   }
 }
 
+// -----
+
+// expected-error @below {{op expects at least one non-pattern op}}
+transform.with_pdl_patterns {
+^bb0(%arg0: !pdl.operation):
+  pdl.pattern @some : benefit(1) {
+    %0 = pdl.operation "test.foo"
+    pdl.rewrite %0 with "transform.dialect"
+  }
+}
+
+// -----
+
+transform.sequence failures(propagate) {
+^bb0(%arg0: !pdl.operation):
+  // expected-error @below {{op expects at least one non-pattern op}}
+  with_pdl_patterns %arg0 : !pdl.operation {
+  ^bb1(%arg1: !pdl.operation):
+  }
+}
+
+
 // -----
 
 // expected-error @below {{expects at least one region}}

diff  --git a/mlir/test/Dialect/Transform/ops.mlir b/mlir/test/Dialect/Transform/ops.mlir
index 73171a8f8cd03..0a2687da2049d 100644
--- a/mlir/test/Dialect/Transform/ops.mlir
+++ b/mlir/test/Dialect/Transform/ops.mlir
@@ -21,16 +21,6 @@ transform.with_pdl_patterns {
   }
 }
 
-// CHECK: transform.sequence
-// CHECK: ^{{.+}}(%[[ARG:.+]]: !pdl.operation):
-transform.sequence failures(propagate) {
-^bb0(%arg0: !pdl.operation):
-  // CHECK: with_pdl_patterns %[[ARG]] : !pdl.operation
-  with_pdl_patterns %arg0 : !pdl.operation {
-  ^bb1(%arg1: !pdl.operation):
-  }
-}
-
 // Using the same value multiple times without consuming it is fine.
 // CHECK: transform.sequence
 // CHECK: %[[V:.+]] = sequence %{{.*}} : !pdl.operation -> !pdl.operation


        


More information about the Mlir-commits mailing list