MLIR 23.0.0git
MemoryAccessOpInterfaces.cpp
Go to the documentation of this file.
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
11#include "mlir/IR/Operation.h"
12#include "mlir/IR/Value.h"
13
14//===----------------------------------------------------------------------===//
15// IndexedAccessOpInterface and IndexedMemCpyOpInterface
16//===----------------------------------------------------------------------===//
17
18namespace mlir::memref {
19#include "mlir/Dialect/MemRef/IR/MemoryAccessOpInterfaces.cpp.inc"
20
22 auto iface = dyn_cast<IndexedAccessOpInterface>(op);
23 if (!iface)
24 return failure();
25
26 TypedValue<MemRefType> memref = iface.getAccessedMemref();
27 if (!memref) {
28 // Some operations can carry tensors, this is fine.
29 return success();
30 }
31 if (memref.getType().getRank() !=
32 static_cast<int64_t>(iface.getIndices().size()))
33 return op->emitOpError(
34 "invalid number of indices for accessed memref, expected ")
35 << memref.getType().getRank() << " but got "
36 << iface.getIndices().size();
37 return success();
38}
39
41 auto iface = dyn_cast<IndexedMemCopyOpInterface>(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 have memref arguments.
49 return success();
50 }
51 if (src.getType().getRank() !=
52 static_cast<int64_t>(iface.getSrcIndices().size()))
53 return op->emitOpError(
54 "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 "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
return success()
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
InFlightDiagnostic emitOpError(const Twine &message={})
Emit an error with the op name prefixed, like "'dim' op " which is convenient for verifiers.
LogicalResult verifyIndexedMemCopyOpInterface(Operation *op)
LogicalResult verifyIndexedAccessOpInterface(Operation *op)
std::conditional_t< std::is_same_v< Ty, mlir::Type >, mlir::Value, detail::TypedValue< Ty > > TypedValue
If Ty is mlir::Type this will select Value instead of having a wrapper around it.
Definition Value.h:497