summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Dialect/StandardOps
diff options
context:
space:
mode:
authorNicolas Vasilache <ntv@google.com>2019-11-13 12:09:40 -0800
committerA. Unique TensorFlower <gardener@tensorflow.org>2019-11-13 12:10:09 -0800
commit0bd6390b541e8a95ee4d2fc8abcdcaf1d7c580cb (patch)
treed0a77f2a05fdc0c1cc11f88161120a6e10f7474e /mlir/lib/Dialect/StandardOps
parent40f0c76ee27f4dee3952c8b76678cd10122ebc1b (diff)
downloadbcm5719-llvm-0bd6390b541e8a95ee4d2fc8abcdcaf1d7c580cb.tar.gz
bcm5719-llvm-0bd6390b541e8a95ee4d2fc8abcdcaf1d7c580cb.zip
Deprecate linalg.subview in favor of std.subview
This CL uses the now standard std.subview in linalg. Two shortcuts are currently taken to allow this port: 1. the type resulting from a view is currently degraded to fully dynamic to pass the SubViewOp verifier. 2. indexing into SubViewOp may access out of bounds since lowering to LLVM does not currently enforce it by construction. These will be fixed in subsequent commits after discussions. PiperOrigin-RevId: 280250129
Diffstat (limited to 'mlir/lib/Dialect/StandardOps')
-rw-r--r--mlir/lib/Dialect/StandardOps/Ops.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/mlir/lib/Dialect/StandardOps/Ops.cpp b/mlir/lib/Dialect/StandardOps/Ops.cpp
index f152ccfc50a..e70675e21b6 100644
--- a/mlir/lib/Dialect/StandardOps/Ops.cpp
+++ b/mlir/lib/Dialect/StandardOps/Ops.cpp
@@ -2553,6 +2553,43 @@ void ViewOp::getCanonicalizationPatterns(OwningRewritePatternList &results,
// SubViewOp
//===----------------------------------------------------------------------===//
+// 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;
+ Type elementType = memRefType.getElementType();
+ auto res = getStridesAndOffset(memRefType, strides, offset);
+ assert(succeeded(res) && "SubViewOp expected strided memref type");
+ (void)res;
+
+ // Assume sizes and offset are fully dynamic for now until canonicalization
+ // occurs on the ranges. Typed strides don't change though.
+ offset = MemRefType::getDynamicStrideOrOffset();
+ // Overwrite strides because verifier will not pass.
+ // TODO(b/144419106): don't force degrade the strides to fully dynamic.
+ for (auto &stride : strides)
+ stride = MemRefType::getDynamicStrideOrOffset();
+ auto stridedLayout =
+ makeStridedLinearLayoutMap(strides, offset, memRefType.getContext());
+ SmallVector<int64_t, 4> sizes(rank, ShapedType::kDynamicSize);
+ return MemRefType::get(sizes, elementType, stridedLayout,
+ memRefType.getMemorySpace());
+}
+
+void mlir::SubViewOp::build(Builder *b, OperationState &result, Value *source,
+ ArrayRef<Value *> offsets, ArrayRef<Value *> sizes,
+ ArrayRef<Value *> strides, Type resultType,
+ ArrayRef<NamedAttribute> attrs) {
+ if (!resultType)
+ resultType = inferSubViewResultType(source->getType().cast<MemRefType>());
+ build(b, result, resultType, source, offsets, sizes, strides);
+ result.addAttributes(attrs);
+}
+
static ParseResult parseSubViewOp(OpAsmParser &parser, OperationState &result) {
OpAsmParser::OperandType srcInfo;
SmallVector<OpAsmParser::OperandType, 4> offsetsInfo;
@@ -2634,6 +2671,23 @@ static LogicalResult verify(SubViewOp op) {
return success();
}
+llvm::raw_ostream &mlir::operator<<(llvm::raw_ostream &os,
+ SubViewOp::Range &range) {
+ return os << "range " << *range.offset << ":" << *range.size << ":"
+ << *range.stride;
+}
+
+SmallVector<SubViewOp::Range, 8> SubViewOp::getRanges() {
+ SmallVector<Range, 8> res;
+ unsigned rank = getType().getRank();
+ res.reserve(rank);
+ for (unsigned i = 0; i < rank; ++i)
+ res.emplace_back(Range{*(getDynamicOffsets().begin() + i),
+ *(getDynamicSizes().begin() + i),
+ *(getDynamicStrides().begin() + i)});
+ return res;
+}
+
//===----------------------------------------------------------------------===//
// ZeroExtendIOp
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud