diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp --- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp +++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp @@ -87,10 +87,9 @@ auto shape = m.getType().getShape(); bool allTrue = true; bool allFalse = true; - for (auto pair : llvm::zip(masks, shape)) { - int64_t i = std::get<0>(pair).cast().getInt(); - int64_t u = std::get<1>(pair); - if (i < u) + for (auto [maskIdx, dimSize] : llvm::zip_equal(masks, shape)) { + int64_t i = maskIdx.cast().getInt(); + if (i < dimSize) allTrue = false; if (i > 0) allFalse = false; @@ -1178,10 +1177,10 @@ /// Comparison is on the common prefix (i.e. zip). template bool intersectsWhereNonNegative(const ContainerA &a, const ContainerB &b) { - for (auto it : llvm::zip(a, b)) { - if (std::get<0>(it) < 0 || std::get<0>(it) < 0) + for (auto [elemA, elemB] : llvm::zip(a, b)) { + if (elemA < 0 || elemB < 0) continue; - if (std::get<0>(it) != std::get<1>(it)) + if (elemA != elemB) return false; } return true; @@ -1729,7 +1728,8 @@ int64_t rankDiff = dstShape.size() - srcShape.size(); int64_t dstDim = rankDiff; llvm::SetVector res; - for (auto [s1, s2] : llvm::zip(srcShape, dstShape.drop_front(rankDiff))) { + for (auto [s1, s2] : + llvm::zip_equal(srcShape, dstShape.drop_front(rankDiff))) { if (s1 != s2) { assert(s1 == 1 && "expected dim-1 broadcasting"); res.insert(dstDim); @@ -2391,18 +2391,16 @@ isIntegerArrayAttrConfinedToShape(OpType op, ArrayAttr arrayAttr, ArrayRef shape, StringRef attrName, bool halfOpen = true, int64_t min = 0) { - assert(arrayAttr.size() <= shape.size()); - unsigned index = 0; - for (auto it : llvm::zip(arrayAttr, shape)) { - auto val = std::get<0>(it).cast().getInt(); - auto max = std::get<1>(it); + for (auto [index, attrDimPair] : + llvm::enumerate(llvm::zip_first(arrayAttr, shape))) { + int64_t val = std::get<0>(attrDimPair).cast().getInt(); + int64_t max = std::get<1>(attrDimPair); if (!halfOpen) max += 1; if (val < min || val >= max) return op.emitOpError("expected ") << attrName << " dimension " << index << " to be confined to [" << min << ", " << max << ")"; - ++index; } return success(); } @@ -2417,8 +2415,8 @@ bool halfOpen = true, int64_t min = 1) { assert(arrayAttr1.size() <= shape.size()); assert(arrayAttr2.size() <= shape.size()); - unsigned index = 0; - for (auto it : llvm::zip(arrayAttr1, arrayAttr2, shape)) { + for (auto [index, it] : + llvm::enumerate(llvm::zip(arrayAttr1, arrayAttr2, shape))) { auto val1 = std::get<0>(it).cast().getInt(); auto val2 = std::get<1>(it).cast().getInt(); auto max = std::get<2>(it); @@ -2428,7 +2426,6 @@ return op.emitOpError("expected sum(") << attrName1 << ", " << attrName2 << ") dimension " << index << " to be confined to [" << min << ", " << max << ")"; - ++index; } return success(); } @@ -2969,11 +2966,9 @@ // Compute slice of vector mask region. SmallVector sliceMaskDimSizes; - assert(sliceOffsets.size() == maskDimSizes.size()); - for (auto it : llvm::zip(maskDimSizes, sliceOffsets, sliceSizes)) { - int64_t maskDimSize = std::get<0>(it); - int64_t sliceOffset = std::get<1>(it); - int64_t sliceSize = std::get<2>(it); + sliceMaskDimSizes.reserve(maskDimSizes.size()); + for (auto [maskDimSize, sliceOffset, sliceSize] : + llvm::zip_equal(maskDimSizes, sliceOffsets, sliceSizes)) { int64_t sliceMaskDimSize = std::max( static_cast(0), std::min(sliceOffset + sliceSize, maskDimSize) - sliceOffset); @@ -4243,9 +4238,9 @@ } // Fail if tensor::ExtractSliceOp and tensor::InsertSliceOp sizes differ. - for (const auto &it : - llvm::zip(insertOp.getMixedSizes(), extractOp.getMixedSizes())) { - if (!isEqualConstantIntOrValue(std::get<0>(it), std::get<1>(it))) { + for (auto [insertSize, extractSize] : + llvm::zip_equal(insertOp.getMixedSizes(), extractOp.getMixedSizes())) { + if (!isEqualConstantIntOrValue(insertSize, extractSize)) { return rewriter.notifyMatchFailure( insertOp, "InsertSliceOp and ExtractSliceOp sizes differ"); } @@ -5215,10 +5210,10 @@ // Gather constant mask dimension sizes. SmallVector maskDimSizes; - for (auto it : llvm::zip(createMaskOp.operands(), - createMaskOp.getType().getShape())) { - auto *defOp = std::get<0>(it).getDefiningOp(); - int64_t maxDimSize = std::get<1>(it); + maskDimSizes.reserve(createMaskOp->getNumOperands()); + for (auto [operand, maxDimSize] : llvm::zip_equal( + createMaskOp.operands(), createMaskOp.getType().getShape())) { + Operation *defOp = operand.getDefiningOp(); int64_t dimSize = cast(defOp).value(); dimSize = std::min(dimSize, maxDimSize); // If one of dim sizes is zero, set all dims to zero. @@ -5445,10 +5440,7 @@ if (i != reductionDim) expectedShape.push_back(srcShape[i]); } - if (llvm::any_of(llvm::zip(initialValueShapes, expectedShape), - [](std::tuple s) { - return std::get<0>(s) != std::get<1>(s); - })) { + if (!llvm::equal(initialValueShapes, expectedShape)) { return emitOpError("incompatible input/initial value shapes"); } @@ -5595,8 +5587,8 @@ OpBuilder::InsertionGuard guard(builder); Region *warpRegion = result.addRegion(); Block *block = builder.createBlock(warpRegion); - for (auto it : llvm::zip(blockArgTypes, args)) - block->addArgument(std::get<0>(it), std::get<1>(it).getLoc()); + for (auto [type, arg] : llvm::zip_equal(blockArgTypes, args)) + block->addArgument(type, arg.getLoc()); } /// Helper check if the distributed vector type is consistent with the expanded @@ -5643,16 +5635,16 @@ return emitOpError( "expected same number of yield operands and return values."); int64_t warpSize = getWarpSize(); - for (auto it : llvm::zip(getWarpRegion().getArguments(), getArgs())) { - if (failed(verifyDistributedType(std::get<0>(it).getType(), - std::get<1>(it).getType(), warpSize, - getOperation()))) + for (auto [regionArg, arg] : + llvm::zip_equal(getWarpRegion().getArguments(), getArgs())) { + if (failed(verifyDistributedType(regionArg.getType(), arg.getType(), + warpSize, getOperation()))) return failure(); } - for (auto it : llvm::zip(yield.getOperands(), getResults())) { - if (failed(verifyDistributedType(std::get<0>(it).getType(), - std::get<1>(it).getType(), warpSize, - getOperation()))) + for (auto [yieldOperand, result] : + llvm::zip_equal(yield.getOperands(), getResults())) { + if (failed(verifyDistributedType(yieldOperand.getType(), result.getType(), + warpSize, getOperation()))) return failure(); } return success();