[PATCH] D77464: [mlir][Toy][LowerToAffineLoops] Handle tensors of rank 0
Djordje Todorovic via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 6 05:55:26 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rGda5fe23e84c8: [mlir][LowerToAffineLoops] Handle tensors of rank 0 (authored by djtodoro).
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D77464/new/
https://reviews.llvm.org/D77464
Files:
mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp
mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp
mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp
Index: mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp
===================================================================
--- mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp
+++ mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp
@@ -155,9 +155,15 @@
// operations.
auto valueShape = memRefType.getShape();
SmallVector<Value, 8> constantIndices;
- for (auto i : llvm::seq<int64_t>(
- 0, *std::max_element(valueShape.begin(), valueShape.end())))
- constantIndices.push_back(rewriter.create<ConstantIndexOp>(loc, i));
+
+ if (!valueShape.empty()) {
+ for (auto i : llvm::seq<int64_t>(
+ 0, *std::max_element(valueShape.begin(), valueShape.end())))
+ constantIndices.push_back(rewriter.create<ConstantIndexOp>(loc, i));
+ } else {
+ // This is the case of a tensor of rank 0.
+ constantIndices.push_back(rewriter.create<ConstantIndexOp>(loc, 0));
+ }
// The constant operation represents a multi-dimensional constant, so we
// will need to generate a store for each of the elements. The following
Index: mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp
===================================================================
--- mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp
+++ mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp
@@ -155,10 +155,15 @@
// operations.
auto valueShape = memRefType.getShape();
SmallVector<Value, 8> constantIndices;
- for (auto i : llvm::seq<int64_t>(
- 0, *std::max_element(valueShape.begin(), valueShape.end())))
- constantIndices.push_back(rewriter.create<ConstantIndexOp>(loc, i));
+ if (!valueShape.empty()) {
+ for (auto i : llvm::seq<int64_t>(
+ 0, *std::max_element(valueShape.begin(), valueShape.end())))
+ constantIndices.push_back(rewriter.create<ConstantIndexOp>(loc, i));
+ } else {
+ // This is the case of a tensor of rank 0.
+ constantIndices.push_back(rewriter.create<ConstantIndexOp>(loc, 0));
+ }
// The constant operation represents a multi-dimensional constant, so we
// will need to generate a store for each of the elements. The following
// functor recursively walks the dimensions of the constant shape,
Index: mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp
===================================================================
--- mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp
+++ mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp
@@ -155,9 +155,15 @@
// operations.
auto valueShape = memRefType.getShape();
SmallVector<Value, 8> constantIndices;
- for (auto i : llvm::seq<int64_t>(
- 0, *std::max_element(valueShape.begin(), valueShape.end())))
- constantIndices.push_back(rewriter.create<ConstantIndexOp>(loc, i));
+
+ if (!valueShape.empty()) {
+ for (auto i : llvm::seq<int64_t>(
+ 0, *std::max_element(valueShape.begin(), valueShape.end())))
+ constantIndices.push_back(rewriter.create<ConstantIndexOp>(loc, i));
+ } else {
+ // This is the case of a tensor of rank 0.
+ constantIndices.push_back(rewriter.create<ConstantIndexOp>(loc, 0));
+ }
// The constant operation represents a multi-dimensional constant, so we
// will need to generate a store for each of the elements. The following
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77464.255304.patch
Type: text/x-patch
Size: 3332 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200406/bbb10ef3/attachment.bin>
More information about the llvm-commits
mailing list