-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Transforms] Use range-based for loops (NFC) #138476
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_001_tidy_modernize-loop-convert_llvm_Transforms
May 4, 2025
Merged
[Transforms] Use range-based for loops (NFC) #138476
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_tidy_modernize-loop-convert_llvm_Transforms
May 4, 2025
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
Member
|
@llvm/pr-subscribers-llvm-transforms Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/138476.diff 4 Files Affected:
diff --git a/llvm/lib/Transforms/IPO/ConstantMerge.cpp b/llvm/lib/Transforms/IPO/ConstantMerge.cpp
index a1face0a6a9c3..6cc35d05ceb1a 100644
--- a/llvm/lib/Transforms/IPO/ConstantMerge.cpp
+++ b/llvm/lib/Transforms/IPO/ConstantMerge.cpp
@@ -226,9 +226,7 @@ static bool mergeConstants(Module &M) {
// Now that we have figured out which replacements must be made, do them all
// now. This avoid invalidating the pointers in CMap, which are unneeded
// now.
- for (unsigned i = 0, e = SameContentReplacements.size(); i != e; ++i) {
- GlobalVariable *Old = SameContentReplacements[i].first;
- GlobalVariable *New = SameContentReplacements[i].second;
+ for (const auto &[Old, New] : SameContentReplacements) {
replace(M, Old, New);
++ChangesMade;
++NumIdenticalMerged;
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index c0ae944ee82f2..3005e65f532ce 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -3036,12 +3036,12 @@ bool GVNPass::performScalarPRE(Instruction *CurInst) {
PHINode *Phi = PHINode::Create(CurInst->getType(), PredMap.size(),
CurInst->getName() + ".pre-phi");
Phi->insertBefore(CurrentBlock->begin());
- for (unsigned I = 0, E = PredMap.size(); I != E; ++I) {
- if (Value *V = PredMap[I].first) {
+ for (auto &[V, BB] : PredMap) {
+ if (V) {
// If we use an existing value in this phi, we have to patch the original
// value because the phi will be used to replace a later value.
patchReplacementInstruction(CurInst, V);
- Phi->addIncoming(V, PredMap[I].second);
+ Phi->addIncoming(V, BB);
} else
Phi->addIncoming(PREInstr, PREPred);
}
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp
index a8a11624be63f..97f9829ce54c5 100644
--- a/llvm/lib/Transforms/Scalar/Reassociate.cpp
+++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp
@@ -1115,10 +1115,8 @@ Value *ReassociatePass::RemoveFactorFromExpression(Value *V, Value *Factor,
MadeChange |= LinearizeExprTree(BO, Tree, RedoInsts, Flags);
SmallVector<ValueEntry, 8> Factors;
Factors.reserve(Tree.size());
- for (unsigned i = 0, e = Tree.size(); i != e; ++i) {
- RepeatedValue E = Tree[i];
+ for (const RepeatedValue &E : Tree)
Factors.append(E.second, ValueEntry(getRank(E.first), E.first));
- }
bool FoundFactor = false;
bool NeedsNegate = false;
@@ -1391,8 +1389,8 @@ Value *ReassociatePass::OptimizeXor(Instruction *I,
APInt ConstOpnd(Ty->getScalarSizeInBits(), 0);
// Step 1: Convert ValueEntry to XorOpnd
- for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
- Value *V = Ops[i].Op;
+ for (const ValueEntry &Op : Ops) {
+ Value *V = Op.Op;
const APInt *C;
// TODO: Support non-splat vectors.
if (match(V, m_APInt(C))) {
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 8094697cdd13a..33af582a9e0a9 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -976,8 +976,8 @@ bool SimplifyCFGOpt::simplifyEqualityComparisonWithOnlyPredecessor(
SwitchInstProfUpdateWrapper SI = *cast<SwitchInst>(TI);
// Okay, TI has cases that are statically dead, prune them away.
SmallPtrSet<Constant *, 16> DeadCases;
- for (unsigned i = 0, e = PredCases.size(); i != e; ++i)
- DeadCases.insert(PredCases[i].Value);
+ for (const ValueEqualityComparisonCase &Case : PredCases)
+ DeadCases.insert(Case.Value);
LLVM_DEBUG(dbgs() << "Threading pred instr: " << *Pred->getTerminator()
<< "Through successor TI: " << *TI);
@@ -1307,14 +1307,14 @@ bool SimplifyCFGOpt::performValueComparisonIntoPredecessorFolding(
// Okay, now we know which constants were sent to BB from the
// predecessor. Figure out where they will all go now.
- for (unsigned i = 0, e = BBCases.size(); i != e; ++i)
- if (PTIHandled.count(BBCases[i].Value)) {
+ for (const ValueEqualityComparisonCase &Case : BBCases)
+ if (PTIHandled.count(Case.Value)) {
// If this is one we are capable of getting...
if (PredHasWeights || SuccHasWeights)
- Weights.push_back(WeightsForHandled[BBCases[i].Value]);
- PredCases.push_back(BBCases[i]);
- ++NewSuccessors[BBCases[i].Dest];
- PTIHandled.erase(BBCases[i].Value); // This constant is taken care of
+ Weights.push_back(WeightsForHandled[Case.Value]);
+ PredCases.push_back(Case);
+ ++NewSuccessors[Case.Dest];
+ PTIHandled.erase(Case.Value); // This constant is taken care of
}
// If there are any constants vectored to BB that TI doesn't handle,
@@ -5177,8 +5177,8 @@ bool SimplifyCFGOpt::simplifyBranchOnICmpChain(BranchInst *BI,
SwitchInst *New = Builder.CreateSwitch(CompVal, DefaultBB, Values.size());
// Add all of the 'cases' to the switch instruction.
- for (unsigned i = 0, e = Values.size(); i != e; ++i)
- New->addCase(Values[i], EdgeBB);
+ for (ConstantInt *Val : Values)
+ New->addCase(Val, EdgeBB);
// We added edges from PI to the EdgeBB. As such, if there were any
// PHI nodes in EdgeBB, they need entries to be added corresponding to
@@ -6453,9 +6453,7 @@ SwitchLookupTable::SwitchLookupTable(
// Build up the table contents.
SmallVector<Constant *, 64> TableContents(TableSize);
- for (size_t I = 0, E = Values.size(); I != E; ++I) {
- ConstantInt *CaseVal = Values[I].first;
- Constant *CaseRes = Values[I].second;
+ for (const auto &[CaseVal, CaseRes] : Values) {
assert(CaseRes->getType() == ValueType);
uint64_t Idx = (CaseVal->getValue() - Offset->getValue()).getLimitedValue();
|
shiltian
approved these changes
May 4, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
GeorgeARM
pushed a commit
to GeorgeARM/llvm-project
that referenced
this pull request
May 7, 2025
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.