Skip to content

[mlir][vector][nfc] Replace failure() with notifyMatchFailure() #129278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,22 +549,26 @@ struct Strategy<TransferWriteOp> {
};

template <typename OpTy>
LogicalResult checkPrepareXferOp(OpTy xferOp,
VectorTransferToSCFOptions options) {
static LogicalResult checkPrepareXferOp(OpTy xferOp, PatternRewriter &rewriter,
VectorTransferToSCFOptions options) {
if (xferOp->hasAttr(kPassLabel))
return failure();
return rewriter.notifyMatchFailure(
xferOp, "kPassLabel is present (vector-to-scf lowering in progress)");
if (xferOp.getVectorType().getRank() <= options.targetRank)
return failure();
// Currently the unpacking of the leading dimension into the memref is not
// supported for scalable dimensions.
return rewriter.notifyMatchFailure(
xferOp, "xferOp vector rank <= transformation target rank");
if (xferOp.getVectorType().getScalableDims().front())
return failure();
return rewriter.notifyMatchFailure(
xferOp, "Unpacking of the leading dimension into the memref is not yet "
"supported for scalable dims");
if (isTensorOp(xferOp) && !options.lowerTensors)
return failure();
// Transfer ops that modify the element type are not supported atm.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we retain this comment if it gives additional info?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I just moved the comment inside rewriter.notifyMatchFailure (with some tweaks):

// BEFORE
// Transfer ops that modify the element type are not supported atm.
  if (xferOp.getVectorType().getElementType() !=
      xferOp.getShapedType().getElementType())
    return failure();
// AFTER
  if (xferOp.getVectorType().getElementType() !=
      xferOp.getShapedType().getElementType())
    return rewriter.notifyMatchFailure(
        xferOp, "Mismatching source and destination element types.");

return rewriter.notifyMatchFailure(
xferOp, "Unpacking for tensors has been disabled.");
if (xferOp.getVectorType().getElementType() !=
xferOp.getShapedType().getElementType())
return failure();
return rewriter.notifyMatchFailure(
xferOp, "Mismatching source and destination element types.");

return success();
}

Expand Down Expand Up @@ -597,8 +601,9 @@ struct PrepareTransferReadConversion

LogicalResult matchAndRewrite(TransferReadOp xferOp,
PatternRewriter &rewriter) const override {
if (checkPrepareXferOp(xferOp, options).failed())
return failure();
if (checkPrepareXferOp(xferOp, rewriter, options).failed())
return rewriter.notifyMatchFailure(
xferOp, "checkPrepareXferOp conditions not met!");

auto buffers = allocBuffers(rewriter, xferOp);
auto *newXfer = rewriter.clone(*xferOp.getOperation());
Expand Down Expand Up @@ -646,8 +651,9 @@ struct PrepareTransferWriteConversion

LogicalResult matchAndRewrite(TransferWriteOp xferOp,
PatternRewriter &rewriter) const override {
if (checkPrepareXferOp(xferOp, options).failed())
return failure();
if (checkPrepareXferOp(xferOp, rewriter, options).failed())
return rewriter.notifyMatchFailure(
xferOp, "checkPrepareXferOp conditions not met!");

Location loc = xferOp.getLoc();
auto buffers = allocBuffers(rewriter, xferOp);
Expand Down Expand Up @@ -903,15 +909,17 @@ struct TransferOpConversion : public VectorToSCFPattern<OpTy> {
LogicalResult matchAndRewrite(OpTy xferOp,
PatternRewriter &rewriter) const override {
if (!xferOp->hasAttr(kPassLabel))
return failure();
return rewriter.notifyMatchFailure(
xferOp, "kPassLabel is present (progressing lowering in progress)");

// Find and cast data buffer. How the buffer can be found depends on OpTy.
ImplicitLocOpBuilder locB(xferOp.getLoc(), rewriter);
Value dataBuffer = Strategy<OpTy>::getBuffer(xferOp);
auto dataBufferType = dyn_cast<MemRefType>(dataBuffer.getType());
FailureOr<MemRefType> castedDataType = unpackOneDim(dataBufferType);
if (failed(castedDataType))
return failure();
return rewriter.notifyMatchFailure(xferOp,
"Failed to unpack one vector dim.");

auto castedDataBuffer =
locB.create<vector::TypeCastOp>(*castedDataType, dataBuffer);
Expand Down Expand Up @@ -1294,16 +1302,14 @@ struct UnrollTransferReadConversion
xferOp, "vector rank is less or equal to target rank");
if (failed(checkLowerTensors(xferOp, rewriter)))
return failure();
// Transfer ops that modify the element type are not supported atm.
if (xferOp.getVectorType().getElementType() !=
xferOp.getShapedType().getElementType())
return rewriter.notifyMatchFailure(
xferOp, "not yet supported: element type mismatch");
auto xferVecType = xferOp.getVectorType();
if (xferVecType.getScalableDims()[0]) {
// Cannot unroll a scalable dimension at compile time.
return rewriter.notifyMatchFailure(
xferOp, "scalable dimensions cannot be unrolled");
xferOp, "scalable dimensions cannot be unrolled at compile time");
}

auto insertOp = getInsertOp(xferOp);
Expand Down