| 1 | //===- MemoryAccessOpInterfaces.cpp ---------------------------------------===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "mlir/Dialect/MemRef/IR/MemoryAccessOpInterfaces.h" |
| 10 | #include "mlir/Dialect/MemRef/IR/MemRef.h" |
| 11 | #include "mlir/IR/Operation.h" |
| 12 | #include "mlir/IR/Value.h" |
| 13 | |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | // IndexedAccessOpInterface and IndexedMemCpyOpInterface |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | |
| 18 | namespace mlir::memref { |
| 19 | #include "mlir/Dialect/MemRef/IR/MemoryAccessOpInterfaces.cpp.inc" |
| 20 | |
| 21 | LogicalResult detail::verifyIndexedAccessOpInterface(Operation *op) { |
| 22 | auto iface = dyn_cast<IndexedAccessOpInterface>(Val: op); |
| 23 | if (!iface) |
| 24 | return failure(); |
| 25 | |
| 26 | TypedValue<MemRefType> memref = iface.getAccessedMemref(); |
| 27 | if (!memref) { |
| 28 | // Some operations do not always access memory through a memref. |
| 29 | return success(); |
| 30 | } |
| 31 | if (memref.getType().getRank() != |
| 32 | static_cast<int64_t>(iface.getIndices().size())) |
| 33 | return op->emitOpError( |
| 34 | message: "invalid number of indices for accessed memref, expected ") |
| 35 | << memref.getType().getRank() << " but got " |
| 36 | << iface.getIndices().size(); |
| 37 | return success(); |
| 38 | } |
| 39 | |
| 40 | LogicalResult detail::verifyIndexedMemCopyOpInterface(Operation *op) { |
| 41 | auto iface = dyn_cast<IndexedMemCopyOpInterface>(Val: op); |
| 42 | if (!iface) |
| 43 | return failure(); |
| 44 | |
| 45 | TypedValue<MemRefType> src = iface.getSrc(); |
| 46 | TypedValue<MemRefType> dst = iface.getDst(); |
| 47 | if (!src || !dst) { |
| 48 | // Allow operations to not always copy between memref arguments. |
| 49 | return success(); |
| 50 | } |
| 51 | if (src.getType().getRank() != |
| 52 | static_cast<int64_t>(iface.getSrcIndices().size())) |
| 53 | return op->emitOpError( |
| 54 | message: "invalid number of indices for source memref, expected "+ |
| 55 | Twine(src.getType().getRank()) + ", got "+ |
| 56 | Twine(iface.getSrcIndices().size())); |
| 57 | if (dst.getType().getRank() != |
| 58 | static_cast<int64_t>(iface.getDstIndices().size())) |
| 59 | return op->emitOpError( |
| 60 | message: "invalid number of indices for destination memref, expected ") |
| 61 | << dst.getType().getRank() << ", got " |
| 62 | << iface.getDstIndices().size(); |
| 63 | return success(); |
| 64 | } |
| 65 | } // namespace mlir::memref |
| 66 |