Skip to content

Commit 461605c

Browse files
committed
[mlir] Add MemRefReinterpretCastOp definition to Standard.
Reuse most code for printing/parsing/verification from SubViewOp. https://llvm.discourse.group/t/rfc-standard-memref-cast-ops/1454/15 Differential Revision: https://https://reviews.llvm.org/D89720
1 parent bb1d702 commit 461605c

File tree

4 files changed

+428
-120
lines changed

4 files changed

+428
-120
lines changed

mlir/include/mlir/Dialect/StandardOps/IR/Ops.td

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,52 @@ def MemRefCastOp : CastOp<"memref_cast", [
22172217
}];
22182218
}
22192219

2220+
2221+
//===----------------------------------------------------------------------===//
2222+
// MemRefReinterpretCastOp
2223+
//===----------------------------------------------------------------------===//
2224+
2225+
def MemRefReinterpretCastOp:
2226+
BaseOpWithOffsetSizesAndStrides<"memref_reinterpret_cast", [
2227+
NoSideEffect, ViewLikeOpInterface
2228+
]> {
2229+
let summary = "memref reinterpret cast operation";
2230+
let description = [{
2231+
Modify offset, sizes and strides of an unranked/ranked memref.
2232+
2233+
Example:
2234+
```mlir
2235+
memref_reinterpret_cast %ranked to
2236+
offset: [0],
2237+
sizes: [%size0, 10],
2238+
strides: [1, %stride1]
2239+
: memref<?x?xf32> to memref<?x10xf32, offset: 0, strides: [1, ?]>
2240+
2241+
memref_reinterpret_cast %unranked to
2242+
offset: [%offset],
2243+
sizes: [%size0, %size1],
2244+
strides: [%stride0, %stride1]
2245+
: memref<*xf32> to memref<?x?xf32, offset: ?, strides: [?, ?]>
2246+
```
2247+
}];
2248+
2249+
let arguments = (ins
2250+
Arg<AnyRankedOrUnrankedMemRef, "", []>:$source,
2251+
Variadic<Index>:$offsets,
2252+
Variadic<Index>:$sizes,
2253+
Variadic<Index>:$strides,
2254+
I64ArrayAttr:$static_offsets,
2255+
I64ArrayAttr:$static_sizes,
2256+
I64ArrayAttr:$static_strides
2257+
);
2258+
let results = (outs AnyMemRef:$result);
2259+
let extraClassDeclaration = extraBaseClassDeclaration # [{
2260+
// The result of the op is always a ranked memref.
2261+
MemRefType getType() { return getResult().getType().cast<MemRefType>(); }
2262+
Value getViewSource() { return source(); }
2263+
}];
2264+
}
2265+
22202266
//===----------------------------------------------------------------------===//
22212267
// MemRefReshapeOp
22222268
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)