Skip to content

Commit 9fa59e7

Browse files
committed
[mlir] Use C++17 structured bindings instead of std::tie where applicable. NFCI
1 parent 7d48a9e commit 9fa59e7

File tree

20 files changed

+37
-82
lines changed

20 files changed

+37
-82
lines changed

mlir/include/mlir/ExecutionEngine/MemRefUtils.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ class OwningMemRef {
162162
int64_t nElements = 1;
163163
for (int64_t s : shapeAlloc)
164164
nElements *= s;
165-
T *data, *alignedData;
166-
std::tie(data, alignedData) =
165+
auto [data, alignedData] =
167166
detail::allocAligned<T>(nElements, allocFun, alignment);
168167
descriptor = detail::makeStridedMemRefDescriptor<Rank>(data, alignedData,
169168
shape, shapeAlloc);

mlir/lib/Analysis/DataFlowFramework.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,10 @@ LogicalResult DataFlowSolver::initializeAndRun(Operation *top) {
7272
}
7373

7474
// Run the analysis until fixpoint.
75-
ProgramPoint point;
76-
DataFlowAnalysis *analysis;
77-
7875
do {
7976
// Exhaust the worklist.
8077
while (!worklist.empty()) {
81-
std::tie(point, analysis) = worklist.front();
78+
auto [point, analysis] = worklist.front();
8279
worklist.pop();
8380

8481
DATAFLOW_DEBUG(llvm::dbgs() << "Invoking '" << analysis->debugName

mlir/lib/Analysis/Presburger/IntegerRelation.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1108,8 +1108,7 @@ Optional<uint64_t> IntegerRelation::computeVolume() const {
11081108
bool hasUnboundedVar = false;
11091109
for (unsigned i = 0, e = getNumDimAndSymbolVars(); i < e; ++i) {
11101110
dim[i] = 1;
1111-
MaybeOptimum<int64_t> min, max;
1112-
std::tie(min, max) = simplex.computeIntegerBounds(dim);
1111+
auto [min, max] = simplex.computeIntegerBounds(dim);
11131112
dim[i] = 0;
11141113

11151114
assert((!min.isEmpty() && !max.isEmpty()) &&

mlir/lib/Analysis/Presburger/Simplex.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -1990,9 +1990,7 @@ Optional<SmallVector<int64_t, 8>> Simplex::findIntegerSample() {
19901990
llvm::to_vector<8>(basis.getRow(level));
19911991
basisCoeffs.emplace_back(0);
19921992

1993-
MaybeOptimum<int64_t> minRoundedUp, maxRoundedDown;
1994-
std::tie(minRoundedUp, maxRoundedDown) =
1995-
computeIntegerBounds(basisCoeffs);
1993+
auto [minRoundedUp, maxRoundedDown] = computeIntegerBounds(basisCoeffs);
19961994

19971995
// We don't have any integer values in the range.
19981996
// Pop the stack and return up a level.

mlir/lib/AsmParser/DialectSymbolParser.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ static Symbol parseExtendedSymbol(Parser &p, SymbolAliasMap &aliases,
160160
p.consumeToken();
161161

162162
// Check to see if this is a pretty name.
163-
StringRef dialectName;
164-
StringRef symbolData;
165-
std::tie(dialectName, symbolData) = identifier.split('.');
163+
auto [dialectName, symbolData] = identifier.split('.');
166164
bool isPrettyName = !symbolData.empty() || identifier.back() == '.';
167165

168166
// Check to see if the symbol has trailing data, i.e. has an immediately

mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ static void wrapForExternalCallers(OpBuilder &rewriter, Location loc,
131131
SmallVector<NamedAttribute, 4> attributes;
132132
filterFuncAttributes(funcOp->getAttrs(), /*filterArgAndResAttrs=*/false,
133133
attributes);
134-
Type wrapperFuncType;
135-
bool resultIsNowArg;
136-
std::tie(wrapperFuncType, resultIsNowArg) =
134+
auto [wrapperFuncType, resultIsNowArg] =
137135
typeConverter.convertFunctionTypeCWrapper(type);
138136
if (resultIsNowArg)
139137
prependResAttrsToArgAttrs(rewriter, attributes, funcOp.getNumArguments());
@@ -189,9 +187,7 @@ static void wrapExternalFunction(OpBuilder &builder, Location loc,
189187
LLVM::LLVMFuncOp newFuncOp) {
190188
OpBuilder::InsertionGuard guard(builder);
191189

192-
Type wrapperType;
193-
bool resultIsNowArg;
194-
std::tie(wrapperType, resultIsNowArg) =
190+
auto [wrapperType, resultIsNowArg] =
195191
typeConverter.convertFunctionTypeCWrapper(funcOp.getFunctionType());
196192
// This conversion can only fail if it could not convert one of the argument
197193
// types. But since it has been applied to a non-wrapper function before, it

mlir/lib/Conversion/MemRefToLLVM/AllocLikeConversion.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ LogicalResult AllocLikeOpLLVMLowering::matchAndRewrite(
3939
strides, sizeBytes);
4040

4141
// Allocate the underlying buffer.
42-
Value allocatedPtr;
43-
Value alignedPtr;
44-
std::tie(allocatedPtr, alignedPtr) =
42+
auto [allocatedPtr, alignedPtr] =
4543
this->allocateBuffer(rewriter, loc, sizeBytes, op);
4644

4745
// Create the MemRef descriptor.

mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -458,11 +458,9 @@ ParallelLowering::matchAndRewrite(ParallelOp parallelOp,
458458
ivs.reserve(parallelOp.getNumLoops());
459459
bool first = true;
460460
SmallVector<Value, 4> loopResults(iterArgs);
461-
for (auto loopOperands :
461+
for (auto [iv, lower, upper, step] :
462462
llvm::zip(parallelOp.getInductionVars(), parallelOp.getLowerBound(),
463463
parallelOp.getUpperBound(), parallelOp.getStep())) {
464-
Value iv, lower, upper, step;
465-
std::tie(iv, lower, upper, step) = loopOperands;
466464
ForOp forOp = rewriter.create<ForOp>(loc, lower, upper, step, iterArgs);
467465
ivs.push_back(forOp.getInductionVar());
468466
auto iterRange = forOp.getRegionIterArgs();

mlir/lib/Dialect/Arithmetic/IR/InferIntRangeInterfaceImpls.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,8 @@ widenBitwiseBounds(const ConstantIntRanges &bound) {
368368

369369
void arith::AndIOp::inferResultRanges(ArrayRef<ConstantIntRanges> argRanges,
370370
SetIntRangeFn setResultRange) {
371-
APInt lhsZeros, lhsOnes, rhsZeros, rhsOnes;
372-
std::tie(lhsZeros, lhsOnes) = widenBitwiseBounds(argRanges[0]);
373-
std::tie(rhsZeros, rhsOnes) = widenBitwiseBounds(argRanges[1]);
371+
auto [lhsZeros, lhsOnes] = widenBitwiseBounds(argRanges[0]);
372+
auto [rhsZeros, rhsOnes] = widenBitwiseBounds(argRanges[1]);
374373
auto andi = [](const APInt &a, const APInt &b) -> Optional<APInt> {
375374
return a & b;
376375
};
@@ -385,9 +384,8 @@ void arith::AndIOp::inferResultRanges(ArrayRef<ConstantIntRanges> argRanges,
385384

386385
void arith::OrIOp::inferResultRanges(ArrayRef<ConstantIntRanges> argRanges,
387386
SetIntRangeFn setResultRange) {
388-
APInt lhsZeros, lhsOnes, rhsZeros, rhsOnes;
389-
std::tie(lhsZeros, lhsOnes) = widenBitwiseBounds(argRanges[0]);
390-
std::tie(rhsZeros, rhsOnes) = widenBitwiseBounds(argRanges[1]);
387+
auto [lhsZeros, lhsOnes] = widenBitwiseBounds(argRanges[0]);
388+
auto [rhsZeros, rhsOnes] = widenBitwiseBounds(argRanges[1]);
391389
auto ori = [](const APInt &a, const APInt &b) -> Optional<APInt> {
392390
return a | b;
393391
};
@@ -402,9 +400,8 @@ void arith::OrIOp::inferResultRanges(ArrayRef<ConstantIntRanges> argRanges,
402400

403401
void arith::XOrIOp::inferResultRanges(ArrayRef<ConstantIntRanges> argRanges,
404402
SetIntRangeFn setResultRange) {
405-
APInt lhsZeros, lhsOnes, rhsZeros, rhsOnes;
406-
std::tie(lhsZeros, lhsOnes) = widenBitwiseBounds(argRanges[0]);
407-
std::tie(rhsZeros, rhsOnes) = widenBitwiseBounds(argRanges[1]);
403+
auto [lhsZeros, lhsOnes] = widenBitwiseBounds(argRanges[0]);
404+
auto [rhsZeros, rhsOnes] = widenBitwiseBounds(argRanges[1]);
408405
auto xori = [](const APInt &a, const APInt &b) -> Optional<APInt> {
409406
return a ^ b;
410407
};

mlir/lib/Dialect/GPU/IR/GPUDialect.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -1040,9 +1040,7 @@ LogicalResult gpu::ReturnOp::verify() {
10401040

10411041
for (const auto &pair : llvm::enumerate(
10421042
llvm::zip(function.getFunctionType().getResults(), operands()))) {
1043-
Type type;
1044-
Value operand;
1045-
std::tie(type, operand) = pair.value();
1043+
auto [type, operand] = pair.value();
10461044
if (type != operand.getType())
10471045
return emitOpError() << "unexpected type `" << operand.getType()
10481046
<< "' for operand #" << pair.index();

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,7 @@ tileLinalgOpImpl(RewriterBase &b, LinalgOp op, ArrayRef<OpFoldResult> tileSizes,
415415
if (!shapeSizesToLoopsMap)
416416
return failure();
417417

418-
SmallVector<Range, 4> loopRanges;
419-
LoopIndexToRangeIndexMap loopIndexToRangeIndex;
420-
std::tie(loopRanges, loopIndexToRangeIndex) = makeTiledLoopRanges(
418+
auto [loopRanges, loopIndexToRangeIndex] = makeTiledLoopRanges(
421419
b, op.getLoc(), shapeSizesToLoopsMap, allShapeSizes, tileSizes);
422420

423421
SmallVector<Attribute, 4> iteratorTypes;

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

+8-13
Original file line numberDiff line numberDiff line change
@@ -1741,11 +1741,9 @@ struct ReplaceIfYieldWithConditionOrValue : public OpRewritePattern<IfOp> {
17411741
op.getOperation()->getIterator());
17421742
bool changed = false;
17431743
Type i1Ty = rewriter.getI1Type();
1744-
for (auto tup : llvm::zip(trueYield.getResults(), falseYield.getResults(),
1745-
op.getResults())) {
1746-
Value trueResult, falseResult, opResult;
1747-
std::tie(trueResult, falseResult, opResult) = tup;
1748-
1744+
for (auto [trueResult, falseResult, opResult] :
1745+
llvm::zip(trueYield.getResults(), falseYield.getResults(),
1746+
op.getResults())) {
17491747
if (trueResult == falseResult) {
17501748
if (!opResult.use_empty()) {
17511749
opResult.replaceAllUsesWith(trueResult);
@@ -2315,10 +2313,9 @@ struct CollapseSingleIterationLoops : public OpRewritePattern<ParallelOp> {
23152313
newLowerBounds.reserve(op.getLowerBound().size());
23162314
newUpperBounds.reserve(op.getUpperBound().size());
23172315
newSteps.reserve(op.getStep().size());
2318-
for (auto dim : llvm::zip(op.getLowerBound(), op.getUpperBound(),
2319-
op.getStep(), op.getInductionVars())) {
2320-
Value lowerBound, upperBound, step, iv;
2321-
std::tie(lowerBound, upperBound, step, iv) = dim;
2316+
for (auto [lowerBound, upperBound, step, iv] :
2317+
llvm::zip(op.getLowerBound(), op.getUpperBound(), op.getStep(),
2318+
op.getInductionVars())) {
23222319
// Collect the statically known loop bounds.
23232320
auto lowerBoundConstant =
23242321
dyn_cast_or_null<arith::ConstantIndexOp>(lowerBound.getDefiningOp());
@@ -2823,8 +2820,7 @@ struct RemoveLoopInvariantArgsFromBeforeBlock
28232820
for (const auto &it :
28242821
llvm::enumerate(llvm::zip(op.getOperands(), yieldOpArgs))) {
28252822
auto index = static_cast<unsigned>(it.index());
2826-
Value initVal, yieldOpArg;
2827-
std::tie(initVal, yieldOpArg) = it.value();
2823+
auto [initVal, yieldOpArg] = it.value();
28282824
// If i-th yield operand is equal to the i-th operand of the scf.while,
28292825
// the i-th before block argument is a loop invariant.
28302826
if (yieldOpArg == initVal) {
@@ -2855,8 +2851,7 @@ struct RemoveLoopInvariantArgsFromBeforeBlock
28552851
for (const auto &it :
28562852
llvm::enumerate(llvm::zip(op.getOperands(), yieldOpArgs))) {
28572853
auto index = static_cast<unsigned>(it.index());
2858-
Value initVal, yieldOpArg;
2859-
std::tie(initVal, yieldOpArg) = it.value();
2854+
auto [initVal, yieldOpArg] = it.value();
28602855

28612856
// If i-th yield operand is equal to the i-th operand of the scf.while,
28622857
// the i-th before block argument is a loop invariant.

mlir/lib/Dialect/SCF/Transforms/ParallelLoopTiling.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,10 @@ mlir::scf::tileParallelLoop(ParallelOp op, ArrayRef<int64_t> tileSizes,
8989
SmallVector<Value, 2> newBounds;
9090
newBounds.reserve(op.getUpperBound().size());
9191
bool needInboundCheck = false;
92-
for (auto dim :
92+
for (auto [lowerBound, upperBound, newStep, iv, step, tileSizeConstant] :
9393
llvm::zip(outerLoop.getLowerBound(), outerLoop.getUpperBound(),
9494
outerLoop.getStep(), outerLoop.getInductionVars(),
9595
op.getStep(), tileSizeConstants)) {
96-
Value lowerBound, upperBound, newStep, iv, step, tileSizeConstant;
97-
std::tie(lowerBound, upperBound, newStep, iv, step, tileSizeConstant) = dim;
9896
// Collect the statically known loop bounds
9997
auto lowerBoundConstant =
10098
dyn_cast_or_null<arith::ConstantIndexOp>(lowerBound.getDefiningOp());
@@ -139,11 +137,9 @@ mlir::scf::tileParallelLoop(ParallelOp op, ArrayRef<int64_t> tileSizes,
139137
// Insert in-bound check
140138
Value inbound =
141139
b.create<arith::ConstantIntOp>(op.getLoc(), 1, b.getIntegerType(1));
142-
for (auto dim :
140+
for (auto [outerUpperBound, outerIV, innerIV, innerStep] :
143141
llvm::zip(outerLoop.getUpperBound(), outerLoop.getInductionVars(),
144142
innerLoop.getInductionVars(), innerLoop.getStep())) {
145-
Value outerUpperBound, outerIV, innerIV, innerStep;
146-
std::tie(outerUpperBound, outerIV, innerIV, innerStep) = dim;
147143
// %in_bound = %in_bound &&
148144
// (%inner_iv * %inner_step + %outer_iv < %outer_upper_bound)
149145
Value index = b.create<arith::AddIOp>(

mlir/lib/Dialect/Shape/IR/Shape.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,8 @@ struct AssumingOpRemoveUnusedResults : public OpRewritePattern<AssumingOp> {
292292

293293
// Find used values.
294294
SmallVector<Value, 4> newYieldOperands;
295-
Value opResult, yieldOperand;
296-
for (auto it : llvm::zip(op.getResults(), yieldOp.getOperands())) {
297-
std::tie(opResult, yieldOperand) = it;
295+
for (auto [opResult, yieldOperand] :
296+
llvm::zip(op.getResults(), yieldOp.getOperands())) {
298297
if (!opResult.getUses().empty()) {
299298
newYieldOperands.push_back(yieldOperand);
300299
}

mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@ Optional<SmallVector<int64_t, 4>> mlir::shapeRatio(ArrayRef<int64_t> superShape,
8383
// Starting from the end, compute the integer divisors.
8484
std::vector<int64_t> result;
8585
result.reserve(superShape.size());
86-
int64_t superSize = 0, subSize = 0;
87-
for (auto it :
86+
for (auto [superSize, subSize] :
8887
llvm::zip(llvm::reverse(superShape), llvm::reverse(subShape))) {
89-
std::tie(superSize, subSize) = it;
9088
assert(superSize > 0 && "superSize must be > 0");
9189
assert(subSize > 0 && "subSize must be > 0");
9290

mlir/lib/Support/DebugCounter.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ void DebugCounter::applyCLOptions() {
122122
continue;
123123

124124
// Debug counter arguments are expected to be in the form: `counter=value`.
125-
StringRef counterName, counterValueStr;
126-
std::tie(counterName, counterValueStr) = arg.split('=');
125+
auto [counterName, counterValueStr] = arg.split('=');
127126
if (counterValueStr.empty()) {
128127
llvm::errs() << "error: expected DebugCounter argument to have an `=` "
129128
"separating the counter name and value, but the provided "

mlir/lib/TableGen/Pattern.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,8 @@ void DagNode::print(raw_ostream &os) const {
203203
//===----------------------------------------------------------------------===//
204204

205205
StringRef SymbolInfoMap::getValuePackName(StringRef symbol, int *index) {
206-
StringRef name, indexStr;
207206
int idx = -1;
208-
std::tie(name, indexStr) = symbol.rsplit("__");
207+
auto [name, indexStr] = symbol.rsplit("__");
209208

210209
if (indexStr.consumeInteger(10, idx)) {
211210
// The second part is not an index; we return the whole symbol as-is.

mlir/lib/Tools/PDLL/Parser/Parser.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -846,9 +846,7 @@ void Parser::processTdIncludeRecords(llvm::RecordKeeper &tdRecords,
846846
bool supportsResultTypeInferrence =
847847
op.getTrait("::mlir::InferTypeOpInterface::Trait");
848848

849-
bool inserted = false;
850-
ods::Operation *odsOp = nullptr;
851-
std::tie(odsOp, inserted) = odsContext.insertOperation(
849+
auto [odsOp, inserted] = odsContext.insertOperation(
852850
op.getOperationName(), processDoc(op.getSummary()),
853851
processAndFormatDoc(op.getDescription()), op.getQualCppClassName(),
854852
supportsResultTypeInferrence, op.getLoc().front());

mlir/lib/Transforms/OpStats.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,15 @@ void PrintOpStatsPass::printSummary() {
6666
};
6767

6868
// Compute the largest dialect and operation name.
69-
StringRef dialectName, opName;
7069
size_t maxLenOpName = 0, maxLenDialect = 0;
7170
for (const auto &key : sorted) {
72-
std::tie(dialectName, opName) = splitOperationName(key);
71+
auto [dialectName, opName] = splitOperationName(key);
7372
maxLenDialect = std::max(maxLenDialect, dialectName.size());
7473
maxLenOpName = std::max(maxLenOpName, opName.size());
7574
}
7675

7776
for (const auto &key : sorted) {
78-
std::tie(dialectName, opName) = splitOperationName(key);
77+
auto [dialectName, opName] = splitOperationName(key);
7978

8079
// Left-align the names (aligning on the dialect) and right-align the count
8180
// below. The alignment is for readability and does not affect CSV/FileCheck

mlir/lib/Transforms/Utils/DialectConversion.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -1407,9 +1407,7 @@ void ConversionPatternRewriterImpl::notifyOpReplaced(Operation *op,
14071407
bool resultChanged = false;
14081408

14091409
// Create mappings for each of the new result values.
1410-
Value newValue, result;
1411-
for (auto it : llvm::zip(newValues, op->getResults())) {
1412-
std::tie(newValue, result) = it;
1410+
for (auto [newValue, result] : llvm::zip(newValues, op->getResults())) {
14131411
if (!newValue) {
14141412
resultChanged = true;
14151413
continue;
@@ -2554,9 +2552,7 @@ replaceMaterialization(ConversionPatternRewriterImpl &rewriterImpl,
25542552

25552553
// For each of the materialization results, update the inverse mappings to
25562554
// point to the replacement values.
2557-
for (auto it : llvm::zip(matResults, values)) {
2558-
Value matResult, newValue;
2559-
std::tie(matResult, newValue) = it;
2555+
for (auto [matResult, newValue] : llvm::zip(matResults, values)) {
25602556
auto inverseMapIt = inverseMapping.find(matResult);
25612557
if (inverseMapIt == inverseMapping.end())
25622558
continue;

0 commit comments

Comments
 (0)