[ADT] Allow llvm::enumerate to enumerate over multiple ranges

This does not work by a mere composition of `enumerate` and `zip_equal`,
because C++17 does not allow for recursive expansion of structured
bindings.

This implementation uses `zippy` to manage the iteratees and adds the
stream of indices as the first zipped range. Because we have an upfront
assertion that all input ranges are of the same length, we only need to
check if the second range has ended during iteration.

As a consequence of using `zippy`, `enumerate` will now follow the
reference and lifetime semantics of the `zip*` family of functions. The
main difference is that `enumerate` exposes each tuple of references
through a new tuple-like type `enumerate_result`, with the familiar
`.index()` and `.value()` member functions.

Because the `enumerate_result` returned on dereference is a
temporary, enumeration result can no longer be used through an
lvalue ref.

Reviewed By: dblaikie, zero9178

Differential Revision: https://reviews.llvm.org/D144503
This commit is contained in:
Jakub Kuderski
2023-03-15 19:34:21 -04:00
parent ac1d143b0e
commit a0a76804c4
15 changed files with 331 additions and 141 deletions

View File

@@ -1148,10 +1148,9 @@ public:
desc.setSpecifier(newSpec);
// Fills in slice information.
for (const auto &it : llvm::enumerate(llvm::zip(
op.getMixedOffsets(), op.getMixedSizes(), op.getMixedStrides()))) {
Dimension dim = it.index();
auto [offset, size, stride] = it.value();
for (auto [idx, offset, size, stride] : llvm::enumerate(
op.getMixedOffsets(), op.getMixedSizes(), op.getMixedStrides())) {
Dimension dim = idx;
Value offsetV = getValueOrCreateConstantIndexOp(rewriter, loc, offset);
Value sizeV = getValueOrCreateConstantIndexOp(rewriter, loc, size);