Skip to content

Commit 8c258fd

Browse files
committed
[ADT][mlir][NFCI] Do not use non-const lvalue-refs with enumerate
Replace references to enumerate results with either result_pairs (reference wrapper type) or structured bindings. I did not use structured bindings everywhere as it wasn't clear to me it would improve readability. This is in preparation to the switch to zip semantics which won't support non-const lvalue reference to elements: https://reviews.llvm.org/D144503. I chose to use values instead of const lvalue-refs because MLIR is biased towards avoiding `const` local variables. This won't degrade performance because currently `result_pair` is cheap to copy (size_t + iterator), and in the future, the enumerator iterator dereference will return temporaries anyway. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D146006
1 parent bc47a19 commit 8c258fd

File tree

31 files changed

+92
-93
lines changed

31 files changed

+92
-93
lines changed

mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,13 @@ void AbstractSparseDataFlowAnalysis::visitBlock(Block *block) {
191191
dyn_cast<BranchOpInterface>(predecessor->getTerminator())) {
192192
SuccessorOperands operands =
193193
branch.getSuccessorOperands(it.getSuccessorIndex());
194-
for (auto &it : llvm::enumerate(argLattices)) {
195-
if (Value operand = operands[it.index()]) {
196-
join(it.value(), *getLatticeElementFor(block, operand));
194+
for (auto [idx, lattice] : llvm::enumerate(argLattices)) {
195+
if (Value operand = operands[idx]) {
196+
join(lattice, *getLatticeElementFor(block, operand));
197197
} else {
198198
// Conservatively consider internally produced arguments as entry
199199
// points.
200-
setAllToEntryStates(it.value());
200+
setAllToEntryStates(lattice);
201201
}
202202
}
203203
} else {

mlir/lib/Bytecode/Writer/IRNumbering.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ static void groupByDialectPerByte(T range) {
9898
}
9999

100100
// Assign the entry numbers based on the sort order.
101-
for (auto &entry : llvm::enumerate(range))
102-
entry.value()->number = entry.index();
101+
for (auto [idx, value] : llvm::enumerate(range))
102+
value->number = idx;
103103
}
104104

105105
IRNumberingState::IRNumberingState(Operation *op) {
@@ -132,8 +132,8 @@ IRNumberingState::IRNumberingState(Operation *op) {
132132
// found, given that the number of dialects on average is small enough to fit
133133
// within a singly byte (128). If we ever have real world use cases that have
134134
// a huge number of dialects, this could be made more intelligent.
135-
for (auto &it : llvm::enumerate(dialects))
136-
it.value().second->number = it.index();
135+
for (auto [idx, dialect] : llvm::enumerate(dialects))
136+
dialect.second->number = idx;
137137

138138
// Number each of the recorded components within each dialect.
139139

@@ -245,7 +245,7 @@ void IRNumberingState::number(Region &region) {
245245

246246
// Number the blocks within this region.
247247
size_t blockCount = 0;
248-
for (auto &it : llvm::enumerate(region)) {
248+
for (auto it : llvm::enumerate(region)) {
249249
blockIDs.try_emplace(&it.value(), it.index());
250250
number(it.value());
251251
++blockCount;

mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ struct RawBufferOpLowering : public ConvertOpToLLVMPattern<GpuOp> {
200200

201201
// Indexing (voffset)
202202
Value voffset;
203-
for (auto &pair : llvm::enumerate(adaptor.getIndices())) {
203+
for (auto pair : llvm::enumerate(adaptor.getIndices())) {
204204
size_t i = pair.index();
205205
Value index = pair.value();
206206
Value strideOp;

mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static void wrapForExternalCallers(OpBuilder &rewriter, Location loc,
134134

135135
SmallVector<Value, 8> args;
136136
size_t argOffset = resultStructType ? 1 : 0;
137-
for (auto &[index, argType] : llvm::enumerate(type.getInputs())) {
137+
for (auto [index, argType] : llvm::enumerate(type.getInputs())) {
138138
Value arg = wrapperFuncOp.getArgument(index + argOffset);
139139
if (auto memrefType = argType.dyn_cast<MemRefType>()) {
140140
Value loaded = rewriter.create<LLVM::LoadOp>(
@@ -222,11 +222,11 @@ static void wrapExternalFunction(OpBuilder &builder, Location loc,
222222

223223
// Iterate over the inputs of the original function and pack values into
224224
// memref descriptors if the original type is a memref.
225-
for (auto &en : llvm::enumerate(type.getInputs())) {
225+
for (Type input : type.getInputs()) {
226226
Value arg;
227227
int numToDrop = 1;
228-
auto memRefType = en.value().dyn_cast<MemRefType>();
229-
auto unrankedMemRefType = en.value().dyn_cast<UnrankedMemRefType>();
228+
auto memRefType = input.dyn_cast<MemRefType>();
229+
auto unrankedMemRefType = input.dyn_cast<UnrankedMemRefType>();
230230
if (memRefType || unrankedMemRefType) {
231231
numToDrop = memRefType
232232
? MemRefDescriptor::getNumUnpackedValues(memRefType)
@@ -677,9 +677,8 @@ struct ReturnOpLowering : public ConvertOpToLLVMPattern<func::ReturnOp> {
677677
getTypeConverter()->packFunctionResults(op.getOperandTypes());
678678

679679
Value packed = rewriter.create<LLVM::UndefOp>(loc, packedType);
680-
for (auto &it : llvm::enumerate(updatedOperands)) {
681-
packed = rewriter.create<LLVM::InsertValueOp>(loc, packed, it.value(),
682-
it.index());
680+
for (auto [idx, operand] : llvm::enumerate(updatedOperands)) {
681+
packed = rewriter.create<LLVM::InsertValueOp>(loc, packed, operand, idx);
683682
}
684683
rewriter.replaceOpWithNewOp<LLVM::ReturnOp>(op, TypeRange(), packed,
685684
op->getAttrs());

mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,11 @@ Type LLVMTypeConverter::convertFunctionSignature(
228228
? barePtrFuncArgTypeConverter
229229
: structFuncArgTypeConverter;
230230
// Convert argument types one by one and check for errors.
231-
for (auto &en : llvm::enumerate(funcTy.getInputs())) {
232-
Type type = en.value();
231+
for (auto [idx, type] : llvm::enumerate(funcTy.getInputs())) {
233232
SmallVector<Type, 8> converted;
234233
if (failed(funcArgConverter(*this, type, converted)))
235234
return {};
236-
result.addInputs(en.index(), converted);
235+
result.addInputs(idx, converted);
237236
}
238237

239238
// If function does not return anything, create the void result type,

mlir/lib/Conversion/PDLToPDLInterp/PredicateTree.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,20 @@ getTreePredicates(std::vector<PositionalPredicate> &predList, Value val,
185185
if (types.size() == 1 && types[0].getType().isa<pdl::RangeType>()) {
186186
getTreePredicates(predList, types.front(), builder, inputs,
187187
builder.getType(builder.getAllResults(opPos)));
188-
} else {
189-
bool foundVariableLength = false;
190-
for (auto &resultIt : llvm::enumerate(types)) {
191-
bool isVariadic = resultIt.value().getType().isa<pdl::RangeType>();
192-
foundVariableLength |= isVariadic;
188+
return;
189+
}
193190

194-
auto *resultPos =
195-
foundVariableLength
196-
? builder.getResultGroup(pos, resultIt.index(), isVariadic)
197-
: builder.getResult(pos, resultIt.index());
198-
predList.emplace_back(resultPos, builder.getIsNotNull());
199-
getTreePredicates(predList, resultIt.value(), builder, inputs,
200-
builder.getType(resultPos));
201-
}
191+
bool foundVariableLength = false;
192+
for (auto [idx, typeValue] : llvm::enumerate(types)) {
193+
bool isVariadic = typeValue.getType().isa<pdl::RangeType>();
194+
foundVariableLength |= isVariadic;
195+
196+
auto *resultPos = foundVariableLength
197+
? builder.getResultGroup(pos, idx, isVariadic)
198+
: builder.getResult(pos, idx);
199+
predList.emplace_back(resultPos, builder.getIsNotNull());
200+
getTreePredicates(predList, typeValue, builder, inputs,
201+
builder.getType(resultPos));
202202
}
203203
}
204204

mlir/lib/Dialect/Affine/Analysis/Utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ void ComputationSliceState::dump() const {
127127
llvm::errs() << "\t\t" << iv << "\n";
128128

129129
llvm::errs() << "\tLBs:\n";
130-
for (auto &en : llvm::enumerate(lbs)) {
130+
for (auto en : llvm::enumerate(lbs)) {
131131
llvm::errs() << "\t\t" << en.value() << "\n";
132132
llvm::errs() << "\t\tOperands:\n";
133133
for (Value lbOp : lbOperands[en.index()])
134134
llvm::errs() << "\t\t\t" << lbOp << "\n";
135135
}
136136

137137
llvm::errs() << "\tUBs:\n";
138-
for (auto &en : llvm::enumerate(ubs)) {
138+
for (auto en : llvm::enumerate(ubs)) {
139139
llvm::errs() << "\t\t" << en.value() << "\n";
140140
llvm::errs() << "\t\tOperands:\n";
141141
for (Value ubOp : ubOperands[en.index()])

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2438,7 +2438,7 @@ OpFoldResult LLVM::GEPOp::fold(FoldAdaptor adaptor) {
24382438
// Canonicalize any dynamic indices of constant value to constant indices.
24392439
bool changed = false;
24402440
SmallVector<GEPArg> gepArgs;
2441-
for (auto &iter : llvm::enumerate(indices)) {
2441+
for (auto iter : llvm::enumerate(indices)) {
24422442
auto integer = iter.value().dyn_cast_or_null<IntegerAttr>();
24432443
// Constant indices can only be int32_t, so if integer does not fit we
24442444
// are forced to keep it dynamic, despite being a constant.

mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,7 +2462,7 @@ transform::TileOp::apply(TransformResults &transformResults,
24622462
SmallVector<Operation *> tiled;
24632463
SmallVector<SmallVector<Operation *, 4>, 4> loops;
24642464
loops.resize(getLoops().size());
2465-
for (auto &[i, op] : llvm::enumerate(targets)) {
2465+
for (auto [i, op] : llvm::enumerate(targets)) {
24662466
auto tilingInterface = dyn_cast<TilingInterface>(op);
24672467
auto dpsInterface = dyn_cast<DestinationStyleOpInterface>(op);
24682468
if (!tilingInterface || !dpsInterface) {
@@ -2865,7 +2865,7 @@ transform::TileToScfForOp::apply(TransformResults &transformResults,
28652865
SmallVector<Operation *> tiled;
28662866
SmallVector<SmallVector<Operation *, 4>, 4> loops;
28672867
loops.resize(getLoops().size());
2868-
for (auto &en : llvm::enumerate(targets)) {
2868+
for (auto en : llvm::enumerate(targets)) {
28692869
auto tilingInterfaceOp = dyn_cast<TilingInterface>(en.value());
28702870
if (!tilingInterfaceOp) {
28712871
DiagnosedSilenceableFailure diag =

mlir/lib/Dialect/Linalg/Transforms/SplitReduction.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,11 @@ FailureOr<SplitReductionResult> mlir::linalg::splitReduction(
156156
newMaps.push_back(AffineMap::get(oldOutputMap.getNumDims() + 1, 0, outputExpr,
157157
op.getContext()));
158158
SmallVector<utils::IteratorType> newIteratorTypes;
159-
for (auto &it : llvm::enumerate(op.getIteratorTypesArray())) {
160-
if (insertSplitDimension == it.index())
159+
for (auto [index, iteratorType] :
160+
llvm::enumerate(op.getIteratorTypesArray())) {
161+
if (insertSplitDimension == index)
161162
newIteratorTypes.push_back(utils::IteratorType::parallel);
162-
newIteratorTypes.push_back(it.value());
163+
newIteratorTypes.push_back(iteratorType);
163164
}
164165
if (insertSplitDimension == op.getIteratorTypesArray().size()) {
165166
newIteratorTypes.push_back(utils::IteratorType::parallel);

mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void mlir::linalg::transformIndexOps(
8989
RewriterBase &b, LinalgOp op, SmallVectorImpl<Value> &ivs,
9090
const LoopIndexToRangeIndexMap &loopIndexToRangeIndex) {
9191
SmallVector<Value> allIvs(op.getNumLoops(), nullptr);
92-
for (auto &en : enumerate(allIvs)) {
92+
for (auto en : enumerate(allIvs)) {
9393
auto rangeIndex = loopIndexToRangeIndex.find(en.index());
9494
if (rangeIndex == loopIndexToRangeIndex.end())
9595
continue;

mlir/lib/Dialect/Linalg/Transforms/TilingInterfaceImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ struct LinalgOpPartialReductionInterface
314314
AffineMap oldOutputMap =
315315
linalgOp.getMatchingIndexingMap(linalgOp.getDpsInitOperand(0));
316316
SmallVector<AffineExpr> outputExpr;
317-
for (auto &[idx, expr] : llvm::enumerate(oldOutputMap.getResults())) {
317+
for (auto [idx, expr] : llvm::enumerate(oldOutputMap.getResults())) {
318318
if (static_cast<int64_t>(idx) == insertSplitDimension) {
319319
outputExpr.push_back(b.getAffineDimExpr(reductionDims[0]));
320320
}

mlir/lib/Dialect/SCF/IR/SCF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3663,7 +3663,7 @@ LogicalResult scf::IndexSwitchOp::verify() {
36633663

36643664
if (failed(verifyRegion(getDefaultRegion(), "default region")))
36653665
return failure();
3666-
for (auto &[idx, caseRegion] : llvm::enumerate(getCaseRegions()))
3666+
for (auto [idx, caseRegion] : llvm::enumerate(getCaseRegions()))
36673667
if (failed(verifyRegion(caseRegion, "case region #" + Twine(idx))))
36683668
return failure();
36693669

mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,9 @@ struct Sparse2SparseReshapeRewriter : public OpRewritePattern<ReshapeOp> {
377377
ArrayRef<int64_t> dstShape = dstTp.getShape();
378378
genReshapeDstShape(loc, rewriter, dstSizes, srcSizes, dstShape,
379379
op.getReassociationIndices());
380-
for (auto &d : llvm::enumerate(dstShape)) {
381-
if (d.value() == ShapedType::kDynamic)
382-
dstDynSizes.push_back(dstSizes[d.index()]);
380+
for (auto [idx, shape] : llvm::enumerate(dstShape)) {
381+
if (shape == ShapedType::kDynamic)
382+
dstDynSizes.push_back(dstSizes[idx]);
383383
}
384384
}
385385

mlir/lib/Dialect/Tensor/IR/TensorOps.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,7 +2773,7 @@ struct FoldOrthogonalPaddings : public OpRewritePattern<PadOp> {
27732773
// zero-offset and zero-padding tensor::ExtractSliceOp, tensor::PadOp pair
27742774
// exists.
27752775
SmallVector<OpFoldResult> newOffsets(rank, rewriter.getIndexAttr(0));
2776-
for (auto &en : enumerate(newOffsets)) {
2776+
for (auto en : enumerate(newOffsets)) {
27772777
OpFoldResult innerOffset = innerSliceOp.getMixedOffsets()[en.index()];
27782778
OpFoldResult outerOffset = outerSliceOp.getMixedOffsets()[en.index()];
27792779
if (!innerDims.test(en.index()) &&
@@ -2796,7 +2796,7 @@ struct FoldOrthogonalPaddings : public OpRewritePattern<PadOp> {
27962796
// tensor::ExtractSliceOp does not match the size of the padded dimension.
27972797
// Otherwise, take the size of the inner tensor::ExtractSliceOp.
27982798
SmallVector<OpFoldResult> newSizes = innerSliceOp.getMixedSizes();
2799-
for (auto &en : enumerate(newSizes)) {
2799+
for (auto en : enumerate(newSizes)) {
28002800
if (!outerDims.test(en.index()))
28012801
continue;
28022802
OpFoldResult sliceSize = innerSliceOp.getMixedSizes()[en.index()];
@@ -2813,7 +2813,7 @@ struct FoldOrthogonalPaddings : public OpRewritePattern<PadOp> {
28132813

28142814
// Combine the high paddings of the two tensor::PadOps.
28152815
SmallVector<OpFoldResult> newHighPad(rank, rewriter.getIndexAttr(0));
2816-
for (auto &en : enumerate(newHighPad)) {
2816+
for (auto en : enumerate(newHighPad)) {
28172817
if (innerDims.test(en.index()))
28182818
newHighPad[en.index()] = padOp.getMixedHighPad()[en.index()];
28192819
if (outerDims.test(en.index()))

mlir/lib/Dialect/Transform/IR/TransformInterfaces.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ void transform::detail::setApplyToOneResults(
969969
continue;
970970
assert(transformOp->getNumResults() == partialResults.size() &&
971971
"expected as many partial results as op as results");
972-
for (auto &[i, value] : llvm::enumerate(partialResults))
972+
for (auto [i, value] : llvm::enumerate(partialResults))
973973
transposed[i].push_back(value);
974974
}
975975

mlir/lib/Dialect/Vector/Transforms/VectorDistribute.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,10 @@ static WarpExecuteOnLane0Op moveRegionToNewWarpOpAndAppendReturns(
205205
indices.push_back(yieldValues.size() - 1);
206206
} else {
207207
// If the value already exit the region don't create a new output.
208-
for (auto &yieldOperand : llvm::enumerate(yieldValues.getArrayRef())) {
209-
if (yieldOperand.value() == std::get<0>(newRet)) {
210-
indices.push_back(yieldOperand.index());
208+
for (auto [idx, yieldOperand] :
209+
llvm::enumerate(yieldValues.getArrayRef())) {
210+
if (yieldOperand == std::get<0>(newRet)) {
211+
indices.push_back(idx);
211212
break;
212213
}
213214
}

mlir/lib/Dialect/Vector/Transforms/VectorUnroll.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ struct UnrollTransposePattern : public OpRewritePattern<vector::TransposeOp> {
628628
SmallVector<int64_t> permutedOffsets(elementOffsets.size());
629629
SmallVector<int64_t> permutedShape(elementOffsets.size());
630630
// Compute the source offsets and shape.
631-
for (auto &indices : llvm::enumerate(permutation)) {
631+
for (auto indices : llvm::enumerate(permutation)) {
632632
permutedOffsets[indices.value()] = elementOffsets[indices.index()];
633633
permutedShape[indices.value()] = (*targetShape)[indices.index()];
634634
}

mlir/lib/Dialect/X86Vector/Transforms/AVXTranspose.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,9 @@ class TransposeOpLowering : public OpRewritePattern<vector::TransposeOp> {
257257
return rewriter.notifyMatchFailure(op, "Unsupported vector element type");
258258

259259
SmallVector<int64_t> srcGtOneDims;
260-
for (auto &en : llvm::enumerate(srcType.getShape()))
261-
if (en.value() > 1)
262-
srcGtOneDims.push_back(en.index());
260+
for (auto [index, size] : llvm::enumerate(srcType.getShape()))
261+
if (size > 1)
262+
srcGtOneDims.push_back(index);
263263

264264
if (srcGtOneDims.size() != 2)
265265
return rewriter.notifyMatchFailure(op, "Unsupported vector type");

mlir/lib/ExecutionEngine/ExecutionEngine.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,17 @@ static void packFunctionArguments(Module *module) {
196196
llvm::Value *argList = interfaceFunc->arg_begin();
197197
SmallVector<llvm::Value *, 8> args;
198198
args.reserve(llvm::size(func.args()));
199-
for (auto &indexedArg : llvm::enumerate(func.args())) {
199+
for (auto [index, arg] : llvm::enumerate(func.args())) {
200200
llvm::Value *argIndex = llvm::Constant::getIntegerValue(
201-
builder.getInt64Ty(), APInt(64, indexedArg.index()));
201+
builder.getInt64Ty(), APInt(64, index));
202202
llvm::Value *argPtrPtr =
203203
builder.CreateGEP(builder.getInt8PtrTy(), argList, argIndex);
204204
llvm::Value *argPtr =
205205
builder.CreateLoad(builder.getInt8PtrTy(), argPtrPtr);
206-
llvm::Type *argTy = indexedArg.value().getType();
206+
llvm::Type *argTy = arg.getType();
207207
argPtr = builder.CreateBitCast(argPtr, argTy->getPointerTo());
208-
llvm::Value *arg = builder.CreateLoad(argTy, argPtr);
209-
args.push_back(arg);
208+
llvm::Value *load = builder.CreateLoad(argTy, argPtr);
209+
args.push_back(load);
210210
}
211211

212212
// Call the implementation function with the extracted arguments.

mlir/lib/IR/AsmPrinter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3274,9 +3274,9 @@ void OperationPrinter::printValueUsers(Value value) {
32743274
// One value might be used as the operand of an operation more than once.
32753275
// Only print the operations results once in that case.
32763276
SmallPtrSet<Operation *, 1> userSet;
3277-
for (auto &indexedUser : enumerate(value.getUsers())) {
3278-
if (userSet.insert(indexedUser.value()).second)
3279-
printUserIDs(indexedUser.value(), indexedUser.index());
3277+
for (auto [index, user] : enumerate(value.getUsers())) {
3278+
if (userSet.insert(user).second)
3279+
printUserIDs(user, index);
32803280
}
32813281
}
32823282

mlir/lib/Pass/PassStatistics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ static void printResultsAsList(raw_ostream &os, OpPassManager &pm) {
7373
for (Pass::Statistic *it : pass->getStatistics())
7474
passEntry.push_back({it->getName(), it->getDesc(), it->getValue()});
7575
} else {
76-
for (auto &it : llvm::enumerate(pass->getStatistics()))
77-
passEntry[it.index()].value += it.value()->getValue();
76+
for (auto [idx, statistic] : llvm::enumerate(pass->getStatistics()))
77+
passEntry[idx].value += statistic->getValue();
7878
}
7979
#endif
8080
return;

mlir/lib/TableGen/Operator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ void Operator::populateTypeInferenceInfo(
408408

409409
// For all results whose types are buildable, initialize their type inference
410410
// nodes with an edge to themselves. Mark those nodes are fully-inferred.
411-
for (auto &[idx, infer] : llvm::enumerate(inference)) {
411+
for (auto [idx, infer] : llvm::enumerate(inference)) {
412412
if (getResult(idx).constraint.getBuilderCall()) {
413413
infer.sources.emplace_back(InferredResultType::mapResultIndex(idx),
414414
"$_self");

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,7 @@ void mlir::LLVM::detail::connectPHINodes(Region &region,
520520
auto phis = llvmBB->phis();
521521
auto numArguments = bb.getNumArguments();
522522
assert(numArguments == std::distance(phis.begin(), phis.end()));
523-
for (auto &numberedPhiNode : llvm::enumerate(phis)) {
524-
auto &phiNode = numberedPhiNode.value();
525-
unsigned index = numberedPhiNode.index();
523+
for (auto [index, phiNode] : llvm::enumerate(phis)) {
526524
for (auto *pred : bb.getPredecessors()) {
527525
// Find the LLVM IR block that contains the converted terminator
528526
// instruction and use it in the PHI node. Note that this block is not

mlir/lib/Transforms/TopologicalSort.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct TopologicalSortPass
2424
void runOnOperation() override {
2525
// Topologically sort the regions of the operation without SSA dominance.
2626
getOperation()->walk([](RegionKindInterface op) {
27-
for (auto &it : llvm::enumerate(op->getRegions())) {
27+
for (auto it : llvm::enumerate(op->getRegions())) {
2828
if (op.hasSSADominance(it.index()))
2929
continue;
3030
for (Block &block : it.value())

0 commit comments

Comments
 (0)