[PATCH] D79662: [mlir] Revisit std.subview handling of static information.
Uday Bondhugula via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat May 9 00:29:40 PDT 2020
bondhugula added inline comments.
================
Comment at: mlir/include/mlir/Dialect/StandardOps/IR/Ops.td:2601
+
+ // Return the rank of the result MemRefType.
+ unsigned getRank() { return getType().getRank(); }
----------------
/// doc comment here.
================
Comment at: mlir/lib/Dialect/StandardOps/IR/Ops.cpp:2128
-// Returns a MemRefType with dynamic sizes and offset and the same stride as the
-// `memRefType` passed as argument.
-// TODO(andydavis,ntv) Evolve to a more powerful inference that can also keep
-// sizes and offset static.
-static Type inferSubViewResultType(MemRefType memRefType) {
- auto rank = memRefType.getRank();
- int64_t offset;
- SmallVector<int64_t, 4> strides;
- auto res = getStridesAndOffset(memRefType, strides, offset);
+// Print a list with either (1) the static integer value in `arrayAttr` if
+// `isDynamic` evaluates to false or (2) the next value otherwise.
----------------
/// doc style comment here. We are using /// comments for local methods as well everywhere or at least that's the style AFAIU.
================
Comment at: mlir/lib/Dialect/StandardOps/IR/Ops.cpp:2147
+
+// Parse a mixed list with either (1) static integer values or (2) SSA values.
+// Fill `result` with the integer ArrayAttr named `attrName` where `dynVal`
----------------
Likewise.
================
Comment at: mlir/lib/Dialect/StandardOps/IR/Ops.cpp:2408
- // Verify that the result memref type has a strided layout map.
- int64_t subViewOffset;
- SmallVector<int64_t, 4> subViewStrides;
- if (failed(getStridesAndOffset(subViewType, subViewStrides, subViewOffset)))
- return op.emitError("result type ") << subViewType << " is not strided";
-
- // Num offsets should either be zero or rank of memref.
- if (op.getNumOffsets() != 0 && op.getNumOffsets() != subViewType.getRank()) {
- return op.emitError("expected number of dynamic offsets specified to match "
- "the rank of the result type ")
- << subViewType;
- }
-
- // Num sizes should either be zero or rank of memref.
- if (op.getNumSizes() != 0 && op.getNumSizes() != subViewType.getRank()) {
- return op.emitError("expected number of dynamic sizes specified to match "
- "the rank of the result type ")
- << subViewType;
- }
-
- // Num strides should either be zero or rank of memref.
- if (op.getNumStrides() != 0 && op.getNumStrides() != subViewType.getRank()) {
- return op.emitError("expected number of dynamic strides specified to match "
- "the rank of the result type ")
- << subViewType;
- }
-
- // Verify that if the shape of the subview type is static, then sizes are not
- // dynamic values, and vice versa.
- if ((subViewType.hasStaticShape() && op.getNumSizes() != 0) ||
- (op.getNumSizes() == 0 && !subViewType.hasStaticShape())) {
- return op.emitError("invalid to specify dynamic sizes when subview result "
- "type is statically shaped and viceversa");
- }
-
- // Verify that if dynamic sizes are specified, then the result memref type
- // have full dynamic dimensions.
- if (op.getNumSizes() > 0) {
- if (llvm::any_of(subViewType.getShape(), [](int64_t dim) {
- return dim != ShapedType::kDynamicSize;
- })) {
- // TODO: This is based on the assumption that number of size arguments are
- // either 0, or the rank of the result type. It is possible to have more
- // fine-grained verification where only particular dimensions are
- // dynamic. That probably needs further changes to the shape op
- // specification.
- return op.emitError("expected shape of result type to be fully dynamic "
- "when sizes are specified");
- }
- }
+ /// Verify static attributes offsets/sizes/strides.
+ if (failed(verifySubViewOpPart(
----------------
Nit: /// -> //
================
Comment at: mlir/lib/Dialect/StandardOps/IR/Ops.cpp:2423
- // For now, verify that if dynamic strides are specified, then all the result
- // memref type have dynamic strides.
- if (op.getNumStrides() > 0) {
- if (llvm::any_of(subViewStrides, [](int64_t stride) {
- return stride != MemRefType::getDynamicStrideOrOffset();
- })) {
- return op.emitError("expected result type to have dynamic strides");
- }
- }
+ /// Verify result type against inferred type.
+ auto expectedType = inferSubViewResultType(
----------------
Likewise.
================
Comment at: mlir/test/IR/core-ops.mlir:17
// CHECK-DAG: #[[BASE_MAP3:map[0-9]+]] = affine_map<(d0, d1, d2)[s0, s1, s2, s3] -> (d0 * s1 + s0 + d1 * s2 + d2 * s3)>
-// CHECK-DAG: #[[SUBVIEW_MAP0:map[0-9]+]] = affine_map<(d0, d1, d2)[s0, s1, s2, s3] -> (d0 * s1 + d1 * s2 + d2 * s3 + s0)>
+// C_HECK-DAG: #[[SUBVIEW_MAP0:map[0-9]+]] = affine_map<(d0, d1, d2)[s0, s1, s2, s3] -> (d0 * s1 + s0 + d1 * s2 + d2 * s3)>
----------------
Typo: C_HECK
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D79662/new/
https://reviews.llvm.org/D79662
More information about the llvm-commits
mailing list