-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_clang_tidy_modernize_loop_convert_Analysis
Jun 25, 2024
Merged
[Analysis] Use range-based for loops (NFC) #96587
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_clang_tidy_modernize_loop_convert_Analysis
Jun 25, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-llvm-analysis Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/96587.diff 7 Files Affected:
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,
|
MaskRay
approved these changes
Jun 25, 2024
nikic
approved these changes
Jun 25, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
AlexisPerry
pushed a commit
to llvm-project-tlp/llvm-project
that referenced
this pull request
Jul 9, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.