[Mlir-commits] [mlir] 1102489 - [mlir][transform] Fix typo in ApplyConversionPatternsOp

Matthias Springer llvmlistbot at llvm.org
Thu Aug 10 04:59:33 PDT 2023


Author: Matthias Springer
Date: 2023-08-10T13:52:56+02:00
New Revision: 11024898911a2c0d8e3bb70bf570ac27ba55ec23

URL: https://github.com/llvm/llvm-project/commit/11024898911a2c0d8e3bb70bf570ac27ba55ec23
DIFF: https://github.com/llvm/llvm-project/commit/11024898911a2c0d8e3bb70bf570ac27ba55ec23.diff

LOG: [mlir][transform] Fix typo in ApplyConversionPatternsOp

Also add extra test cases for partial/full conversion.

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

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Transform/IR/TransformOps.td
    mlir/test/Dialect/Transform/test-pattern-application.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Transform/IR/TransformOps.td b/mlir/include/mlir/Dialect/Transform/IR/TransformOps.td
index f21e4bf6127e11..e1a7a086fe8b94 100644
--- a/mlir/include/mlir/Dialect/Transform/IR/TransformOps.td
+++ b/mlir/include/mlir/Dialect/Transform/IR/TransformOps.td
@@ -201,7 +201,7 @@ def ApplyConversionPatternsOp : TransformDialectOp<"apply_conversion_patterns",
                        OptionalAttr<StrArrayAttr>:$illegal_ops,
                        OptionalAttr<StrArrayAttr>:$legal_dialects,
                        OptionalAttr<StrArrayAttr>:$illegal_dialects,
-                       UnitAttr:$partialConversion);
+                       UnitAttr:$partial_conversion);
   let results = (outs);
   let regions = (region
       MaxSizedRegion<1>:$patterns,

diff  --git a/mlir/test/Dialect/Transform/test-pattern-application.mlir b/mlir/test/Dialect/Transform/test-pattern-application.mlir
index 14745063270ae2..2a45c9c4182db0 100644
--- a/mlir/test/Dialect/Transform/test-pattern-application.mlir
+++ b/mlir/test/Dialect/Transform/test-pattern-application.mlir
@@ -250,13 +250,63 @@ transform.sequence failures(propagate) {
     transform.apply_conversion_patterns.transform.test_conversion_patterns
   } with type_converter {
     transform.apply_conversion_patterns.transform.test_type_converter
-  } {illegal_ops = ["test.foo"],
-     legal_ops = ["func.func", "func.return", "test.new_op"]}
+  } {legal_ops = ["func.func", "func.return", "test.new_op"]}
+      : !transform.any_op
+}
+
+// -----
+
+// Full dialect conversion fails because test.bar is not replaced and not legal.
+
+// expected-note @below{{target op}}
+func.func @full_dialect_conversion_failed() -> tensor<5xf32> {
+  %0 = "test.foo"() {replace_with_new_op = "test.bar"} : () -> (tensor<5xf32>)
+  // expected-error @below{{failed to legalize operation 'test.bar'}}
+  "test.bar"() : () -> ()
+  return %0 : tensor<5xf32>
+}
+
+transform.sequence failures(propagate) {
+^bb1(%arg1: !transform.any_op):
+  %0 = transform.structured.match ops{["func.func"]} in %arg1 : (!transform.any_op) -> !transform.any_op
+  // expected-error @below{{dialect conversion failed}}
+  transform.apply_conversion_patterns to %0 {
+    transform.apply_conversion_patterns.transform.test_conversion_patterns
+  } with type_converter {
+    transform.apply_conversion_patterns.transform.test_type_converter
+  } {legal_ops = ["func.func", "func.return", "test.new_op"]}
       : !transform.any_op
 }
 
 // -----
 
+// Partial dialect conversion succeeds because test.bar is not explicitly
+// illegal.
+
+// CHECK-LABEL: func @partial_dialect_conversion
+//  CHECK-NEXT:   %[[m:.*]] = "test.new_op"() : () -> memref<5xf32>
+//  CHECK-NEXT:   %[[cast:.*]] = builtin.unrealized_conversion_cast %0 : memref<5xf32> to tensor<5xf32>
+//  CHECK-NEXT:   "test.bar"
+//  CHECK-NEXT:   return %[[cast]]
+func.func @partial_dialect_conversion() -> tensor<5xf32> {
+  %0 = "test.foo"() {replace_with_new_op = "test.bar"} : () -> (tensor<5xf32>)
+  "test.bar"() : () -> ()
+  return %0 : tensor<5xf32>
+}
+
+transform.sequence failures(propagate) {
+^bb1(%arg1: !transform.any_op):
+  %0 = transform.structured.match ops{["func.func"]} in %arg1 : (!transform.any_op) -> !transform.any_op
+  transform.apply_conversion_patterns to %0 {
+    transform.apply_conversion_patterns.transform.test_conversion_patterns
+  } with type_converter {
+    transform.apply_conversion_patterns.transform.test_type_converter
+  } {legal_ops = ["func.func", "func.return", "test.new_op"],
+     partial_conversion} : !transform.any_op
+}
+
+// -----
+
 transform.sequence failures(propagate) {
 ^bb1(%arg1: !transform.any_op):
   %0 = transform.structured.match ops{["func.func"]} in %arg1 : (!transform.any_op) -> !transform.any_op


        


More information about the Mlir-commits mailing list