Skip to content

[Analysis] Use range-based for loops (NFC) #96587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions llvm/include/llvm/Analysis/CFGPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,8 @@ struct DOTGraphTraits<DOTFuncInfo *> : public DefaultDOTGraphTraits {
// Prepend label name
Node.printAsOperand(OS, false);
OS << ":\n";
for (auto J = Node.begin(), JE = Node.end(); J != JE; ++J) {
const Instruction *Inst = &*J;
OS << *Inst << "\n";
}
for (const Instruction &Inst : Node)
OS << Inst << "\n";
}

static std::string getCompleteNodeLabel(
Expand Down
8 changes: 3 additions & 5 deletions llvm/lib/Analysis/CallGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,13 @@ PreservedAnalyses CallGraphSCCsPrinterPass::run(Module &M,
const std::vector<CallGraphNode *> &nextSCC = *SCCI;
OS << "\nSCC #" << ++sccNum << ": ";
bool First = true;
for (std::vector<CallGraphNode *>::const_iterator I = nextSCC.begin(),
E = nextSCC.end();
I != E; ++I) {
for (CallGraphNode *CGN : nextSCC) {
if (First)
First = false;
else
OS << ", ";
OS << ((*I)->getFunction() ? (*I)->getFunction()->getName()
: "external node");
OS << (CGN->getFunction() ? CGN->getFunction()->getName()
: "external node");
}

if (nextSCC.size() == 1 && SCCI.hasCycle())
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/Analysis/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@ void ConstraintSystem::dump() const {
SmallVector<std::string> Names = getVarNamesList();
for (const auto &Row : Constraints) {
SmallVector<std::string, 16> Parts;
for (unsigned I = 0, S = Row.size(); I < S; ++I) {
if (Row[I].Id >= NumVariables)
for (const Entry &E : Row) {
if (E.Id >= NumVariables)
break;
if (Row[I].Id == 0)
if (E.Id == 0)
continue;
std::string Coefficient;
if (Row[I].Coefficient != 1)
Coefficient = std::to_string(Row[I].Coefficient) + " * ";
Parts.push_back(Coefficient + Names[Row[I].Id - 1]);
if (E.Coefficient != 1)
Coefficient = std::to_string(E.Coefficient) + " * ";
Parts.push_back(Coefficient + Names[E.Id - 1]);
}
// assert(!Parts.empty() && "need to have at least some parts");
int64_t ConstPart = 0;
Expand Down
17 changes: 7 additions & 10 deletions llvm/lib/Analysis/LoopAccessAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,12 +612,12 @@ void RuntimePointerChecking::printChecks(
OS.indent(Depth) << "Check " << N++ << ":\n";

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

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

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

OS.indent(Depth) << "Grouped accesses:\n";
for (unsigned I = 0; I < CheckingGroups.size(); ++I) {
const auto &CG = CheckingGroups[I];

for (const auto &CG : CheckingGroups) {
OS.indent(Depth + 2) << "Group " << &CG << ":\n";
OS.indent(Depth + 4) << "(Low: " << *CG.Low << " High: " << *CG.High
<< ")\n";
for (unsigned J = 0; J < CG.Members.size(); ++J) {
OS.indent(Depth + 6) << "Member: " << *Pointers[CG.Members[J]].Expr
<< "\n";
for (unsigned Member : CG.Members) {
OS.indent(Depth + 6) << "Member: " << *Pointers[Member].Expr << "\n";
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/PHITransAddr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ Value *PHITransAddr::translateSubExpr(Value *V, BasicBlock *CurBB,
if (Value *V = simplifyGEPInst(GEP->getSourceElementType(), GEPOps[0],
ArrayRef<Value *>(GEPOps).slice(1),
GEP->getNoWrapFlags(), {DL, TLI, DT, AC})) {
for (unsigned i = 0, e = GEPOps.size(); i != e; ++i)
RemoveInstInputs(GEPOps[i], InstInputs);
for (Value *Op : GEPOps)
RemoveInstInputs(Op, InstInputs);

return addAsInput(V);
}
Expand Down
30 changes: 14 additions & 16 deletions llvm/lib/Analysis/ScalarEvolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2615,16 +2615,16 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl<const SCEV *> &Ops,
bool Ok = true;
// Check all the operands to see if they can be represented in the
// source type of the truncate.
for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
if (const SCEVTruncateExpr *T = dyn_cast<SCEVTruncateExpr>(Ops[i])) {
for (const SCEV *Op : Ops) {
if (const SCEVTruncateExpr *T = dyn_cast<SCEVTruncateExpr>(Op)) {
if (T->getOperand()->getType() != SrcType) {
Ok = false;
break;
}
LargeOps.push_back(T->getOperand());
} else if (const SCEVConstant *C = dyn_cast<SCEVConstant>(Ops[i])) {
} else if (const SCEVConstant *C = dyn_cast<SCEVConstant>(Op)) {
LargeOps.push_back(getAnyExtendExpr(C, SrcType));
} else if (const SCEVMulExpr *M = dyn_cast<SCEVMulExpr>(Ops[i])) {
} else if (const SCEVMulExpr *M = dyn_cast<SCEVMulExpr>(Op)) {
SmallVector<const SCEV *, 8> LargeMulOps;
for (unsigned j = 0, f = M->getNumOperands(); j != f && Ok; ++j) {
if (const SCEVTruncateExpr *T =
Expand Down Expand Up @@ -3668,13 +3668,13 @@ ScalarEvolution::getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands,
if (Operands.size() == 1) return Operands[0];
#ifndef NDEBUG
Type *ETy = getEffectiveSCEVType(Operands[0]->getType());
for (unsigned i = 1, e = Operands.size(); i != e; ++i) {
assert(getEffectiveSCEVType(Operands[i]->getType()) == ETy &&
for (const SCEV *Op : llvm::drop_begin(Operands)) {
assert(getEffectiveSCEVType(Op->getType()) == ETy &&
"SCEVAddRecExpr operand types don't match!");
assert(!Operands[i]->getType()->isPointerTy() && "Step must be integer");
assert(!Op->getType()->isPointerTy() && "Step must be integer");
}
for (unsigned i = 0, e = Operands.size(); i != e; ++i)
assert(isAvailableAtLoopEntry(Operands[i], L) &&
for (const SCEV *Op : Operands)
assert(isAvailableAtLoopEntry(Op, L) &&
"SCEVAddRecExpr operand is not available at loop entry!");
#endif

Expand Down Expand Up @@ -3958,8 +3958,8 @@ const SCEV *ScalarEvolution::getMinMaxExpr(SCEVTypes Kind,
// already have one, otherwise create a new one.
FoldingSetNodeID ID;
ID.AddInteger(Kind);
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
ID.AddPointer(Ops[i]);
for (const SCEV *Op : Ops)
ID.AddPointer(Op);
void *IP = nullptr;
const SCEV *ExistingSCEV = UniqueSCEVs.FindNodeOrInsertPos(ID, IP);
if (ExistingSCEV)
Expand Down Expand Up @@ -4345,8 +4345,8 @@ ScalarEvolution::getSequentialMinMaxExpr(SCEVTypes Kind,
// already have one, otherwise create a new one.
FoldingSetNodeID ID;
ID.AddInteger(Kind);
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
ID.AddPointer(Ops[i]);
for (const SCEV *Op : Ops)
ID.AddPointer(Op);
void *IP = nullptr;
const SCEV *ExistingSCEV = UniqueSCEVs.FindNodeOrInsertPos(ID, IP);
if (ExistingSCEV)
Expand Down Expand Up @@ -8785,9 +8785,7 @@ ScalarEvolution::computeBackedgeTakenCount(const Loop *L,
// Compute the ExitLimit for each loop exit. Use this to populate ExitCounts
// and compute maxBECount.
// Do a union of all the predicates here.
for (unsigned i = 0, e = ExitingBlocks.size(); i != e; ++i) {
BasicBlock *ExitBB = ExitingBlocks[i];

for (BasicBlock *ExitBB : ExitingBlocks) {
// We canonicalize untaken exits to br (constant), ignore them so that
// proving an exit untaken doesn't negatively impact our ability to reason
// about the loop as whole.
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/TargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ IntrinsicCostAttributes::IntrinsicCostAttributes(Intrinsic::ID Id, Type *Ty,

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

IntrinsicCostAttributes::IntrinsicCostAttributes(Intrinsic::ID Id, Type *RTy,
Expand Down
Loading