Skip to content

Commit dbc2a47

Browse files
committed
[Delinearization] Modernize loops (NFC)
1 parent 7f223d1 commit dbc2a47

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

llvm/lib/Analysis/Delinearization.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -349,24 +349,22 @@ void llvm::computeAccessFunctions(ScalarEvolution &SE, const SCEV *Expr,
349349
return;
350350

351351
const SCEV *Res = Expr;
352-
int Last = Sizes.size() - 1;
353-
for (int i = Last; i >= 0; i--) {
352+
for (const auto &[Idx, Sz] : enumerate(reverse(Sizes))) {
354353
const SCEV *Q, *R;
355-
SCEVDivision::divide(SE, Res, Sizes[i], &Q, &R);
354+
SCEVDivision::divide(SE, Res, Sz, &Q, &R);
356355

357356
LLVM_DEBUG({
358357
dbgs() << "Res: " << *Res << "\n";
359-
dbgs() << "Sizes[i]: " << *Sizes[i] << "\n";
358+
dbgs() << "Sizes[i]: " << *Sz << "\n";
360359
dbgs() << "Res divided by Sizes[i]:\n";
361360
dbgs() << "Quotient: " << *Q << "\n";
362361
dbgs() << "Remainder: " << *R << "\n";
363362
});
364363

365364
Res = Q;
366365

367-
// Do not record the last subscript corresponding to the size of elements in
368-
// the array.
369-
if (i == Last) {
366+
// Do not record the last subscript.
367+
if (Idx == 0) {
370368

371369
// Bail out if the byte offset is non-zero.
372370
if (!R->isZero()) {
@@ -489,9 +487,9 @@ bool llvm::getIndexExpressionsFromGEP(ScalarEvolution &SE,
489487
assert(GEP && "getIndexExpressionsFromGEP called with a null GEP");
490488
Type *Ty = nullptr;
491489
bool DroppedFirstDim = false;
492-
for (unsigned i = 1; i < GEP->getNumOperands(); i++) {
493-
const SCEV *Expr = SE.getSCEV(GEP->getOperand(i));
494-
if (i == 1) {
490+
for (const auto [Idx, Op] : drop_begin(enumerate(GEP->operands()))) {
491+
const SCEV *Expr = SE.getSCEV(Op);
492+
if (Idx == 1) {
495493
Ty = GEP->getSourceElementType();
496494
if (auto *Const = dyn_cast<SCEVConstant>(Expr))
497495
if (Const->getValue()->isZero()) {
@@ -510,7 +508,7 @@ bool llvm::getIndexExpressionsFromGEP(ScalarEvolution &SE,
510508
}
511509

512510
Subscripts.push_back(Expr);
513-
if (!(DroppedFirstDim && i == 2))
511+
if (!(DroppedFirstDim && Idx == 2))
514512
Sizes.push_back(ArrayTy->getNumElements());
515513

516514
Ty = ArrayTy->getElementType();
@@ -596,13 +594,13 @@ void printDelinearization(raw_ostream &O, Function *F, LoopInfo *LI,
596594
O << "Base offset: " << *BasePointer << "\n";
597595
O << "ArrayDecl[UnknownSize]";
598596
int Size = Subscripts.size();
599-
for (int i = 0; i < Size - 1; i++)
600-
O << "[" << *Sizes[i] << "]";
597+
for (const SCEV *Sz : drop_end(Sizes))
598+
O << "[" << *Sz << "]";
601599
O << " with elements of " << *Sizes[Size - 1] << " bytes.\n";
602600

603601
O << "ArrayRef";
604-
for (int i = 0; i < Size; i++)
605-
O << "[" << *Subscripts[i] << "]";
602+
for (const SCEV *Sub : Subscripts)
603+
O << "[" << *Sub << "]";
606604
O << "\n";
607605
}
608606
}

0 commit comments

Comments
 (0)