[llvm] [Analysis] Use range-based for loops (NFC) (PR #96587)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 24 20:26:49 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/96587.diff
7 Files Affected:
- (modified) llvm/include/llvm/Analysis/CFGPrinter.h (+2-4)
- (modified) llvm/lib/Analysis/CallGraph.cpp (+3-5)
- (modified) llvm/lib/Analysis/ConstraintSystem.cpp (+6-6)
- (modified) llvm/lib/Analysis/LoopAccessAnalysis.cpp (+7-10)
- (modified) llvm/lib/Analysis/PHITransAddr.cpp (+2-2)
- (modified) llvm/lib/Analysis/ScalarEvolution.cpp (+14-16)
- (modified) llvm/lib/Analysis/TargetTransformInfo.cpp (+2-2)
``````````diff
diff --git a/llvm/include/llvm/Analysis/CFGPrinter.h b/llvm/include/llvm/Analysis/CFGPrinter.h
index 3e5b57195b9ea..590b4f064b1ee 100644
--- a/llvm/include/llvm/Analysis/CFGPrinter.h
+++ b/llvm/include/llvm/Analysis/CFGPrinter.h
@@ -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(
diff --git a/llvm/lib/Analysis/CallGraph.cpp b/llvm/lib/Analysis/CallGraph.cpp
index 20efa2b4ff64c..ed9cd84bb8e9b 100644
--- a/llvm/lib/Analysis/CallGraph.cpp
+++ b/llvm/lib/Analysis/CallGraph.cpp
@@ -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())
diff --git a/llvm/lib/Analysis/ConstraintSystem.cpp b/llvm/lib/Analysis/ConstraintSystem.cpp
index 1a9c7c21e9ced..e4c9dcc7544e9 100644
--- a/llvm/lib/Analysis/ConstraintSystem.cpp
+++ b/llvm/lib/Analysis/ConstraintSystem.cpp
@@ -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;
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index 5cc6ce4c90054..0d59217f846b9 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -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";
}
}
@@ -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";
}
}
}
diff --git a/llvm/lib/Analysis/PHITransAddr.cpp b/llvm/lib/Analysis/PHITransAddr.cpp
index 5ec1964c4cb60..e42113db42781 100644
--- a/llvm/lib/Analysis/PHITransAddr.cpp
+++ b/llvm/lib/Analysis/PHITransAddr.cpp
@@ -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);
}
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index b2cb672e305c3..3982f5b1b8148 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -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 =
@@ -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
@@ -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)
@@ -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)
@@ -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.
diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp
index 7e721cbc87f3f..e6a4a2e1f6110 100644
--- a/llvm/lib/Analysis/TargetTransformInfo.cpp
+++ b/llvm/lib/Analysis/TargetTransformInfo.cpp
@@ -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,
``````````
</details>
https://github.com/llvm/llvm-project/pull/96587
More information about the llvm-commits
mailing list