[NFC][mlir][memref] refine debug message about memref::SubViewOp. (#145470)

This commit is contained in:
long.chen
2025-06-27 18:34:45 +08:00
committed by GitHub
parent c3e08c9b89
commit aed8f1992a
2 changed files with 14 additions and 9 deletions

View File

@@ -2929,27 +2929,32 @@ static bool haveCompatibleStrides(MemRefType t1, MemRefType t2,
}
static LogicalResult produceSubViewErrorMsg(SliceVerificationResult result,
Operation *op, Type expectedType) {
SubViewOp op, Type expectedType) {
auto memrefType = llvm::cast<ShapedType>(expectedType);
switch (result) {
case SliceVerificationResult::Success:
return success();
case SliceVerificationResult::RankTooLarge:
return op->emitError("expected result rank to be smaller or equal to ")
<< "the source rank. ";
<< "the source rank, but got " << op.getType();
case SliceVerificationResult::SizeMismatch:
return op->emitError("expected result type to be ")
<< expectedType
<< " or a rank-reduced version. (mismatch of result sizes) ";
<< " or a rank-reduced version. (mismatch of result sizes), but got "
<< op.getType();
case SliceVerificationResult::ElemTypeMismatch:
return op->emitError("expected result element type to be ")
<< memrefType.getElementType();
<< memrefType.getElementType() << ", but got " << op.getType();
case SliceVerificationResult::MemSpaceMismatch:
return op->emitError("expected result and source memory spaces to match.");
return op->emitError(
"expected result and source memory spaces to match, but got ")
<< op.getType();
case SliceVerificationResult::LayoutMismatch:
return op->emitError("expected result type to be ")
<< expectedType
<< " or a rank-reduced version. (mismatch of result layout) ";
<< " or a rank-reduced version. (mismatch of result layout), but "
"got "
<< op.getType();
}
llvm_unreachable("unexpected subview verification result");
}

View File

@@ -713,7 +713,7 @@ func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) {
func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) {
%0 = memref.alloc() : memref<8x16x4xf32>
// expected-error@+1 {{expected result element type to be 'f32'}}
// expected-error@+1 {{expected result element type to be 'f32', but got 'memref<8x16x4xi32>'}}
%1 = memref.subview %0[0, 0, 0][8, 16, 4][1, 1, 1]
: memref<8x16x4xf32> to
memref<8x16x4xi32>
@@ -724,10 +724,10 @@ func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) {
func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) {
%0 = memref.alloc() : memref<8x16x4xf32>
// expected-error@+1 {{expected result rank to be smaller or equal to the source rank.}}
// expected-error@+1 {{expected result rank to be smaller or equal to the source rank, but got 'memref<8x16x4x3xf32>'}}
%1 = memref.subview %0[0, 0, 0][8, 16, 4][1, 1, 1]
: memref<8x16x4xf32> to
memref<8x16x4x3xi32>
memref<8x16x4x3xf32>
return
}