summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Conversion/StandardToLLVM
diff options
context:
space:
mode:
authorAlex Zinenko <zinenko@google.com>2019-12-03 06:22:31 -0800
committerA. Unique TensorFlower <gardener@tensorflow.org>2019-12-03 06:23:04 -0800
commit993e79e9bd132d344f4b79d44055c6d49f072a00 (patch)
treee10062b13cd933debda18b7e698ee19f8408fcde /mlir/lib/Conversion/StandardToLLVM
parent330d1ff00ea85363125ca9b7e42dca50f6ea4ebe (diff)
downloadbcm5719-llvm-993e79e9bd132d344f4b79d44055c6d49f072a00.tar.gz
bcm5719-llvm-993e79e9bd132d344f4b79d44055c6d49f072a00.zip
Fix ViewOp to have at most one offset operand
As described in the documentation, ViewOp is expected to take an optional dynamic offset followed by a list of dynamic sizes. However, the ViewOp parser did not include a check for the offset being a single value and accepeted a list of values instead. Furthermore, several tests have been exercising the wrong syntax of a ViewOp, passing multiple values to the dyanmic stride list, which was not caught by the parser. The trailing values could have been erronously interpreted as dynamic sizes. This is likely due to resyntaxing of the ViewOp, with the previous syntax taking the list of sizes before the offset. Update the tests to use the syntax with the offset preceding the sizes. Worse, the conversion of ViewOp to the LLVM dialect assumed the wrong order of operands with offset in the trailing position, and erronously relied on the permissive parsing that interpreted trailing dynamic offset values as leading dynamic sizes. Fix the lowering to use the correct order of operands. PiperOrigin-RevId: 283532506
Diffstat (limited to 'mlir/lib/Conversion/StandardToLLVM')
-rw-r--r--mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp b/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp
index 0d932208893..793997e9045 100644
--- a/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp
+++ b/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp
@@ -1663,13 +1663,14 @@ struct ViewOpLowering : public LLVMLegalizationPattern<ViewOp> {
// Field 3: Copy the offset in aligned pointer.
unsigned numDynamicSizes = llvm::size(viewOp.getDynamicSizes());
(void)numDynamicSizes;
+ bool hasDynamicOffset = offset == MemRefType::getDynamicStrideOrOffset();
auto sizeAndOffsetOperands = adaptor.operands();
- assert(llvm::size(sizeAndOffsetOperands) == numDynamicSizes + 1 ||
- offset != MemRefType::getDynamicStrideOrOffset());
- Value *baseOffset = (offset != MemRefType::getDynamicStrideOrOffset())
+ assert(llvm::size(sizeAndOffsetOperands) ==
+ numDynamicSizes + (hasDynamicOffset ? 1 : 0));
+ Value *baseOffset = !hasDynamicOffset
? createIndexConstant(rewriter, loc, offset)
// TODO(ntv): better adaptor.
- : sizeAndOffsetOperands.back();
+ : sizeAndOffsetOperands.front();
targetMemRef.setOffset(rewriter, loc, baseOffset);
// Early exit for 0-D corner case.
@@ -1681,10 +1682,14 @@ struct ViewOpLowering : public LLVMLegalizationPattern<ViewOp> {
return op->emitWarning("cannot cast to non-contiguous shape"),
matchFailure();
Value *stride = nullptr, *nextSize = nullptr;
+ // Drop the dynamic stride from the operand list, if present.
+ ArrayRef<Value *> sizeOperands(sizeAndOffsetOperands);
+ if (hasDynamicOffset)
+ sizeOperands = sizeOperands.drop_front();
for (int i = viewMemRefType.getRank() - 1; i >= 0; --i) {
// Update size.
- Value *size = getSize(rewriter, loc, viewMemRefType.getShape(),
- sizeAndOffsetOperands, i);
+ Value *size =
+ getSize(rewriter, loc, viewMemRefType.getShape(), sizeOperands, i);
targetMemRef.setSize(rewriter, loc, i, size);
// Update stride.
stride = getStride(rewriter, loc, strides, nextSize, stride, i);
OpenPOWER on IntegriCloud