Skip to content

Commit 1462605

Browse files
[Analysis] Use range-based for loops (NFC) (#96587)
1 parent c9f083a commit 1462605

File tree

7 files changed

+36
-45
lines changed

7 files changed

+36
-45
lines changed

llvm/include/llvm/Analysis/CFGPrinter.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,8 @@ struct DOTGraphTraits<DOTFuncInfo *> : public DefaultDOTGraphTraits {
208208
// Prepend label name
209209
Node.printAsOperand(OS, false);
210210
OS << ":\n";
211-
for (auto J = Node.begin(), JE = Node.end(); J != JE; ++J) {
212-
const Instruction *Inst = &*J;
213-
OS << *Inst << "\n";
214-
}
211+
for (const Instruction &Inst : Node)
212+
OS << Inst << "\n";
215213
}
216214

217215
static std::string getCompleteNodeLabel(

llvm/lib/Analysis/CallGraph.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,13 @@ PreservedAnalyses CallGraphSCCsPrinterPass::run(Module &M,
319319
const std::vector<CallGraphNode *> &nextSCC = *SCCI;
320320
OS << "\nSCC #" << ++sccNum << ": ";
321321
bool First = true;
322-
for (std::vector<CallGraphNode *>::const_iterator I = nextSCC.begin(),
323-
E = nextSCC.end();
324-
I != E; ++I) {
322+
for (CallGraphNode *CGN : nextSCC) {
325323
if (First)
326324
First = false;
327325
else
328326
OS << ", ";
329-
OS << ((*I)->getFunction() ? (*I)->getFunction()->getName()
330-
: "external node");
327+
OS << (CGN->getFunction() ? CGN->getFunction()->getName()
328+
: "external node");
331329
}
332330

333331
if (nextSCC.size() == 1 && SCCI.hasCycle())

llvm/lib/Analysis/ConstraintSystem.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,15 @@ void ConstraintSystem::dump() const {
163163
SmallVector<std::string> Names = getVarNamesList();
164164
for (const auto &Row : Constraints) {
165165
SmallVector<std::string, 16> Parts;
166-
for (unsigned I = 0, S = Row.size(); I < S; ++I) {
167-
if (Row[I].Id >= NumVariables)
166+
for (const Entry &E : Row) {
167+
if (E.Id >= NumVariables)
168168
break;
169-
if (Row[I].Id == 0)
169+
if (E.Id == 0)
170170
continue;
171171
std::string Coefficient;
172-
if (Row[I].Coefficient != 1)
173-
Coefficient = std::to_string(Row[I].Coefficient) + " * ";
174-
Parts.push_back(Coefficient + Names[Row[I].Id - 1]);
172+
if (E.Coefficient != 1)
173+
Coefficient = std::to_string(E.Coefficient) + " * ";
174+
Parts.push_back(Coefficient + Names[E.Id - 1]);
175175
}
176176
// assert(!Parts.empty() && "need to have at least some parts");
177177
int64_t ConstPart = 0;

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -612,12 +612,12 @@ void RuntimePointerChecking::printChecks(
612612
OS.indent(Depth) << "Check " << N++ << ":\n";
613613

614614
OS.indent(Depth + 2) << "Comparing group (" << Check1 << "):\n";
615-
for (unsigned K = 0; K < First.size(); ++K)
616-
OS.indent(Depth + 2) << *Pointers[First[K]].PointerValue << "\n";
615+
for (unsigned K : First)
616+
OS.indent(Depth + 2) << *Pointers[K].PointerValue << "\n";
617617

618618
OS.indent(Depth + 2) << "Against group (" << Check2 << "):\n";
619-
for (unsigned K = 0; K < Second.size(); ++K)
620-
OS.indent(Depth + 2) << *Pointers[Second[K]].PointerValue << "\n";
619+
for (unsigned K : Second)
620+
OS.indent(Depth + 2) << *Pointers[K].PointerValue << "\n";
621621
}
622622
}
623623

@@ -627,15 +627,12 @@ void RuntimePointerChecking::print(raw_ostream &OS, unsigned Depth) const {
627627
printChecks(OS, Checks, Depth);
628628

629629
OS.indent(Depth) << "Grouped accesses:\n";
630-
for (unsigned I = 0; I < CheckingGroups.size(); ++I) {
631-
const auto &CG = CheckingGroups[I];
632-
630+
for (const auto &CG : CheckingGroups) {
633631
OS.indent(Depth + 2) << "Group " << &CG << ":\n";
634632
OS.indent(Depth + 4) << "(Low: " << *CG.Low << " High: " << *CG.High
635633
<< ")\n";
636-
for (unsigned J = 0; J < CG.Members.size(); ++J) {
637-
OS.indent(Depth + 6) << "Member: " << *Pointers[CG.Members[J]].Expr
638-
<< "\n";
634+
for (unsigned Member : CG.Members) {
635+
OS.indent(Depth + 6) << "Member: " << *Pointers[Member].Expr << "\n";
639636
}
640637
}
641638
}

llvm/lib/Analysis/PHITransAddr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ Value *PHITransAddr::translateSubExpr(Value *V, BasicBlock *CurBB,
216216
if (Value *V = simplifyGEPInst(GEP->getSourceElementType(), GEPOps[0],
217217
ArrayRef<Value *>(GEPOps).slice(1),
218218
GEP->getNoWrapFlags(), {DL, TLI, DT, AC})) {
219-
for (unsigned i = 0, e = GEPOps.size(); i != e; ++i)
220-
RemoveInstInputs(GEPOps[i], InstInputs);
219+
for (Value *Op : GEPOps)
220+
RemoveInstInputs(Op, InstInputs);
221221

222222
return addAsInput(V);
223223
}

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2615,16 +2615,16 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl<const SCEV *> &Ops,
26152615
bool Ok = true;
26162616
// Check all the operands to see if they can be represented in the
26172617
// source type of the truncate.
2618-
for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
2619-
if (const SCEVTruncateExpr *T = dyn_cast<SCEVTruncateExpr>(Ops[i])) {
2618+
for (const SCEV *Op : Ops) {
2619+
if (const SCEVTruncateExpr *T = dyn_cast<SCEVTruncateExpr>(Op)) {
26202620
if (T->getOperand()->getType() != SrcType) {
26212621
Ok = false;
26222622
break;
26232623
}
26242624
LargeOps.push_back(T->getOperand());
2625-
} else if (const SCEVConstant *C = dyn_cast<SCEVConstant>(Ops[i])) {
2625+
} else if (const SCEVConstant *C = dyn_cast<SCEVConstant>(Op)) {
26262626
LargeOps.push_back(getAnyExtendExpr(C, SrcType));
2627-
} else if (const SCEVMulExpr *M = dyn_cast<SCEVMulExpr>(Ops[i])) {
2627+
} else if (const SCEVMulExpr *M = dyn_cast<SCEVMulExpr>(Op)) {
26282628
SmallVector<const SCEV *, 8> LargeMulOps;
26292629
for (unsigned j = 0, f = M->getNumOperands(); j != f && Ok; ++j) {
26302630
if (const SCEVTruncateExpr *T =
@@ -3668,13 +3668,13 @@ ScalarEvolution::getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands,
36683668
if (Operands.size() == 1) return Operands[0];
36693669
#ifndef NDEBUG
36703670
Type *ETy = getEffectiveSCEVType(Operands[0]->getType());
3671-
for (unsigned i = 1, e = Operands.size(); i != e; ++i) {
3672-
assert(getEffectiveSCEVType(Operands[i]->getType()) == ETy &&
3671+
for (const SCEV *Op : llvm::drop_begin(Operands)) {
3672+
assert(getEffectiveSCEVType(Op->getType()) == ETy &&
36733673
"SCEVAddRecExpr operand types don't match!");
3674-
assert(!Operands[i]->getType()->isPointerTy() && "Step must be integer");
3674+
assert(!Op->getType()->isPointerTy() && "Step must be integer");
36753675
}
3676-
for (unsigned i = 0, e = Operands.size(); i != e; ++i)
3677-
assert(isAvailableAtLoopEntry(Operands[i], L) &&
3676+
for (const SCEV *Op : Operands)
3677+
assert(isAvailableAtLoopEntry(Op, L) &&
36783678
"SCEVAddRecExpr operand is not available at loop entry!");
36793679
#endif
36803680

@@ -3958,8 +3958,8 @@ const SCEV *ScalarEvolution::getMinMaxExpr(SCEVTypes Kind,
39583958
// already have one, otherwise create a new one.
39593959
FoldingSetNodeID ID;
39603960
ID.AddInteger(Kind);
3961-
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
3962-
ID.AddPointer(Ops[i]);
3961+
for (const SCEV *Op : Ops)
3962+
ID.AddPointer(Op);
39633963
void *IP = nullptr;
39643964
const SCEV *ExistingSCEV = UniqueSCEVs.FindNodeOrInsertPos(ID, IP);
39653965
if (ExistingSCEV)
@@ -4345,8 +4345,8 @@ ScalarEvolution::getSequentialMinMaxExpr(SCEVTypes Kind,
43454345
// already have one, otherwise create a new one.
43464346
FoldingSetNodeID ID;
43474347
ID.AddInteger(Kind);
4348-
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
4349-
ID.AddPointer(Ops[i]);
4348+
for (const SCEV *Op : Ops)
4349+
ID.AddPointer(Op);
43504350
void *IP = nullptr;
43514351
const SCEV *ExistingSCEV = UniqueSCEVs.FindNodeOrInsertPos(ID, IP);
43524352
if (ExistingSCEV)
@@ -8785,9 +8785,7 @@ ScalarEvolution::computeBackedgeTakenCount(const Loop *L,
87858785
// Compute the ExitLimit for each loop exit. Use this to populate ExitCounts
87868786
// and compute maxBECount.
87878787
// Do a union of all the predicates here.
8788-
for (unsigned i = 0, e = ExitingBlocks.size(); i != e; ++i) {
8789-
BasicBlock *ExitBB = ExitingBlocks[i];
8790-
8788+
for (BasicBlock *ExitBB : ExitingBlocks) {
87918789
// We canonicalize untaken exits to br (constant), ignore them so that
87928790
// proving an exit untaken doesn't negatively impact our ability to reason
87938791
// about the loop as whole.

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ IntrinsicCostAttributes::IntrinsicCostAttributes(Intrinsic::ID Id, Type *Ty,
9898

9999
Arguments.insert(Arguments.begin(), Args.begin(), Args.end());
100100
ParamTys.reserve(Arguments.size());
101-
for (unsigned Idx = 0, Size = Arguments.size(); Idx != Size; ++Idx)
102-
ParamTys.push_back(Arguments[Idx]->getType());
101+
for (const Value *Argument : Arguments)
102+
ParamTys.push_back(Argument->getType());
103103
}
104104

105105
IntrinsicCostAttributes::IntrinsicCostAttributes(Intrinsic::ID Id, Type *RTy,

0 commit comments

Comments
 (0)