diff options
Diffstat (limited to 'mlir/lib/Interfaces/ViewLikeInterface.cpp')
-rw-r--r-- | mlir/lib/Interfaces/ViewLikeInterface.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/mlir/lib/Interfaces/ViewLikeInterface.cpp b/mlir/lib/Interfaces/ViewLikeInterface.cpp index 3112da9..0cddf65 100644 --- a/mlir/lib/Interfaces/ViewLikeInterface.cpp +++ b/mlir/lib/Interfaces/ViewLikeInterface.cpp @@ -94,6 +94,32 @@ SliceBoundsVerificationResult mlir::verifyInBoundsSlice( LogicalResult mlir::detail::verifyOffsetSizeAndStrideOp(OffsetSizeAndStrideOpInterface op) { + // A dynamic size is represented as ShapedType::kDynamic in `static_sizes`. + // Its corresponding Value appears in `sizes`. Thus, the number of dynamic + // dimensions in `static_sizes` must equal the rank of `sizes`. + // The same applies to strides and offsets. + size_t numDynamicDims = + llvm::count_if(op.getStaticSizes(), ShapedType::isDynamic); + if (op.getSizes().size() != numDynamicDims) { + return op->emitError("expected the number of 'sizes' to match the number " + "of dynamic entries in 'static_sizes' (") + << op.getSizes().size() << " vs " << numDynamicDims << ")"; + } + size_t numDynamicStrides = + llvm::count_if(op.getStaticStrides(), ShapedType::isDynamic); + if (op.getStrides().size() != numDynamicStrides) { + return op->emitError("expected the number of 'strides' to match the number " + "of dynamic entries in 'static_strides' (") + << op.getStrides().size() << " vs " << numDynamicStrides << ")"; + } + size_t numDynamicOffsets = + llvm::count_if(op.getStaticOffsets(), ShapedType::isDynamic); + if (op.getOffsets().size() != numDynamicOffsets) { + return op->emitError("expected the number of 'offsets' to match the number " + "of dynamic entries in 'static_offsets' (") + << op.getOffsets().size() << " vs " << numDynamicOffsets << ")"; + } + std::array<unsigned, 3> maxRanks = op.getArrayAttrMaxRanks(); // Offsets can come in 2 flavors: // 1. Either single entry (when maxRanks == 1). |