Skip to content

Commit

Permalink
[mlir] fail gracefull in CallOpSignatureConversion
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ftynse committed Jan 27, 2023
1 parent f7c1982 commit 88a3dc0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mlir/lib/Dialect/Func/Transforms/FuncConversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
Expand Down
13 changes: 13 additions & 0 deletions mlir/test/Transforms/test-legalizer.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 88a3dc0

Please sign in to comment.