[Mlir-commits] [mlir] 88a3dc0 - [mlir] fail gracefull in CallOpSignatureConversion

Alex Zinenko llvmlistbot at llvm.org
Fri Jan 27 01:04:11 PST 2023


Author: Alex Zinenko
Date: 2023-01-27T09:04:04Z
New Revision: 88a3dc0ee88009a145e8daa875235650f07554c9

URL: https://github.com/llvm/llvm-project/commit/88a3dc0ee88009a145e8daa875235650f07554c9
DIFF: https://github.com/llvm/llvm-project/commit/88a3dc0ee88009a145e8daa875235650f07554c9.diff

LOG: [mlir] fail gracefull in CallOpSignatureConversion

Previously, the CallOpSignatureConversion pattern would assert if
function signature change affected the number of results. Fail the
pattern instead and let the caller propagate failure.

Fixes #60186.

Reviewed By: mehdi_amini

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

Added: 
    

Modified: 
    mlir/lib/Dialect/Func/Transforms/FuncConversions.cpp
    mlir/test/Transforms/test-legalizer.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Func/Transforms/FuncConversions.cpp b/mlir/lib/Dialect/Func/Transforms/FuncConversions.cpp
index aec86abe9fb1f..a69bc775fc1b5 100644
--- a/mlir/lib/Dialect/Func/Transforms/FuncConversions.cpp
+++ b/mlir/lib/Dialect/Func/Transforms/FuncConversions.cpp
@@ -29,6 +29,11 @@ struct CallOpSignatureConversion : public OpConversionPattern<CallOp> {
                                            convertedResults)))
       return failure();
 
+    // If this isn't a one-to-one type mapping, we don't know how to aggregate
+    // the results.
+    if (callOp->getNumResults() != convertedResults.size())
+      return failure();
+
     // Substitute with the new result types from the corresponding FuncType
     // conversion.
     rewriter.replaceOpWithNewOp<CallOp>(

diff  --git a/mlir/test/Transforms/test-legalizer.mlir b/mlir/test/Transforms/test-legalizer.mlir
index 45960a6757bf9..06bd5b6ae4984 100644
--- a/mlir/test/Transforms/test-legalizer.mlir
+++ b/mlir/test/Transforms/test-legalizer.mlir
@@ -317,3 +317,16 @@ func.func @typemismatch(%arg: f32) -> i32 {
   %0 = "test.passthrough_fold"(%arg) : (f32) -> (i32)
   "test.return"(%0) : (i32) -> ()
 }
+
+// -----
+
+// expected-remark @below {{applyPartialConversion failed}}
+module {
+  func.func private @callee(%0 : f32) -> f32
+
+  func.func @caller( %arg: f32) {
+    // expected-error @below {{failed to legalize}}
+    %1 = func.call @callee(%arg) : (f32) -> f32
+    return
+  }
+}


        


More information about the Mlir-commits mailing list