Skip to content

Commit fb74e1e

Browse files
[Transforms/Scalar] Use range-based for loops (NFC)
1 parent 5438e07 commit fb74e1e

File tree

7 files changed

+20
-28
lines changed

7 files changed

+20
-28
lines changed

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -776,16 +776,16 @@ memoryIsNotModifiedBetween(Instruction *FirstI, Instruction *SecondI, AATy &AA,
776776
if (B != FirstBB) {
777777
assert(B != &FirstBB->getParent()->getEntryBlock() &&
778778
"Should not hit the entry block because SI must be dominated by LI");
779-
for (auto PredI = pred_begin(B), PE = pred_end(B); PredI != PE; ++PredI) {
779+
for (BasicBlock *Pred : predecessors(B)) {
780780
PHITransAddr PredAddr = Addr;
781781
if (PredAddr.NeedsPHITranslationFromBlock(B)) {
782782
if (!PredAddr.IsPotentiallyPHITranslatable())
783783
return false;
784-
if (PredAddr.PHITranslateValue(B, *PredI, DT, false))
784+
if (PredAddr.PHITranslateValue(B, Pred, DT, false))
785785
return false;
786786
}
787787
Value *TranslatedPtr = PredAddr.getAddr();
788-
auto Inserted = Visited.insert(std::make_pair(*PredI, TranslatedPtr));
788+
auto Inserted = Visited.insert(std::make_pair(Pred, TranslatedPtr));
789789
if (!Inserted.second) {
790790
// We already visited this block before. If it was with a different
791791
// address - bail out!
@@ -794,7 +794,7 @@ memoryIsNotModifiedBetween(Instruction *FirstI, Instruction *SecondI, AATy &AA,
794794
// ... otherwise just skip it.
795795
continue;
796796
}
797-
WorkList.push_back(std::make_pair(*PredI, PredAddr));
797+
WorkList.push_back(std::make_pair(Pred, PredAddr));
798798
}
799799
}
800800
}
@@ -805,8 +805,7 @@ memoryIsNotModifiedBetween(Instruction *FirstI, Instruction *SecondI, AATy &AA,
805805
/// them to F.
806806
static void findUnconditionalPreds(SmallVectorImpl<BasicBlock *> &Blocks,
807807
BasicBlock *BB, DominatorTree *DT) {
808-
for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I) {
809-
BasicBlock *Pred = *I;
808+
for (BasicBlock *Pred : predecessors(BB)) {
810809
if (Pred == BB) continue;
811810
Instruction *PredTI = Pred->getTerminator();
812811
if (PredTI->getNumSuccessors() != 1)

llvm/lib/Transforms/Scalar/GVN.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,9 +2795,7 @@ void GVN::addDeadBlock(BasicBlock *BB) {
27952795

27962796
// For the dead blocks' live successors, update their phi nodes by replacing
27972797
// the operands corresponding to dead blocks with UndefVal.
2798-
for(SmallSetVector<BasicBlock *, 4>::iterator I = DF.begin(), E = DF.end();
2799-
I != E; I++) {
2800-
BasicBlock *B = *I;
2798+
for (BasicBlock *B : DF) {
28012799
if (DeadBlocks.count(B))
28022800
continue;
28032801

llvm/lib/Transforms/Scalar/LoopUnswitch.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,8 @@ bool LUAnalysisCache::countLoop(const Loop *L, const TargetTransformInfo &TTI,
310310
// consideration code simplification opportunities and code that can
311311
// be shared by the resultant unswitched loops.
312312
CodeMetrics Metrics;
313-
for (Loop::block_iterator I = L->block_begin(), E = L->block_end(); I != E;
314-
++I)
315-
Metrics.analyzeBasicBlock(*I, TTI, EphValues);
313+
for (BasicBlock *BB : L->blocks())
314+
Metrics.analyzeBasicBlock(BB, TTI, EphValues);
316315

317316
Props.SizeEstimation = Metrics.NumInsts;
318317
Props.CanBeUnswitchedCount = MaxSize / (Props.SizeEstimation);
@@ -1132,9 +1131,9 @@ static bool isTrivialLoopExitBlockHelper(Loop *L, BasicBlock *BB,
11321131
}
11331132

11341133
// Otherwise, this is an unvisited intra-loop node. Check all successors.
1135-
for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI) {
1134+
for (BasicBlock *Succ : successors(BB)) {
11361135
// Check to see if the successor is a trivial loop exit.
1137-
if (!isTrivialLoopExitBlockHelper(L, *SI, ExitBB, Visited))
1136+
if (!isTrivialLoopExitBlockHelper(L, Succ, ExitBB, Visited))
11381137
return false;
11391138
}
11401139

@@ -1628,9 +1627,7 @@ void LoopUnswitch::unswitchNontrivialCondition(
16281627
PHINode *PN = PHINode::Create(LPad->getType(), 0, "",
16291628
&*ExitSucc->getFirstInsertionPt());
16301629

1631-
for (pred_iterator I = pred_begin(ExitSucc), E = pred_end(ExitSucc);
1632-
I != E; ++I) {
1633-
BasicBlock *BB = *I;
1630+
for (BasicBlock *BB : predecessors(ExitSucc)) {
16341631
LandingPadInst *LPI = BB->getLandingPadInst();
16351632
LPI->replaceAllUsesWith(PN);
16361633
PN->addIncoming(LPI, BB);

llvm/lib/Transforms/Scalar/MergeICmps.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,7 @@ BCECmpChain::BCECmpChain(const std::vector<BasicBlock *> &Blocks, PHINode &Phi,
440440
// Now look inside blocks to check for BCE comparisons.
441441
std::vector<BCECmpBlock> Comparisons;
442442
BaseIdentifier BaseId;
443-
for (size_t BlockIdx = 0; BlockIdx < Blocks.size(); ++BlockIdx) {
444-
BasicBlock *const Block = Blocks[BlockIdx];
443+
for (BasicBlock *const Block : Blocks) {
445444
assert(Block && "invalid block");
446445
BCECmpBlock Comparison = visitCmpBlock(Phi.getIncomingValueForBlock(Block),
447446
Block, Phi.getParent(), BaseId);

llvm/lib/Transforms/Scalar/NaryReassociate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ NaryReassociatePass::tryReassociateGEPAtIndex(GetElementPtrInst *GEP,
364364
// Look for GEP's closest dominator that has the same SCEV as GEP except that
365365
// the I-th index is replaced with LHS.
366366
SmallVector<const SCEV *, 4> IndexExprs;
367-
for (auto Index = GEP->idx_begin(); Index != GEP->idx_end(); ++Index)
368-
IndexExprs.push_back(SE->getSCEV(*Index));
367+
for (Use &Index : GEP->indices())
368+
IndexExprs.push_back(SE->getSCEV(Index));
369369
// Replace the I-th index with LHS.
370370
IndexExprs[I] = SE->getSCEV(LHS);
371371
if (isKnownNonNegative(LHS, *DL, 0, AC, GEP, DT) &&

llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ bool StraightLineStrengthReduce::isFoldable(const Candidate &C,
312312
// Returns true if GEP has zero or one non-zero index.
313313
static bool hasOnlyOneNonZeroIndex(GetElementPtrInst *GEP) {
314314
unsigned NumNonZeroIndices = 0;
315-
for (auto I = GEP->idx_begin(); I != GEP->idx_end(); ++I) {
316-
ConstantInt *ConstIdx = dyn_cast<ConstantInt>(*I);
315+
for (Use &Idx : GEP->indices()) {
316+
ConstantInt *ConstIdx = dyn_cast<ConstantInt>(Idx);
317317
if (ConstIdx == nullptr || !ConstIdx->isZero())
318318
++NumNonZeroIndices;
319319
}
@@ -533,8 +533,8 @@ void StraightLineStrengthReduce::allocateCandidatesAndFindBasisForGEP(
533533
return;
534534

535535
SmallVector<const SCEV *, 4> IndexExprs;
536-
for (auto I = GEP->idx_begin(); I != GEP->idx_end(); ++I)
537-
IndexExprs.push_back(SE->getSCEV(*I));
536+
for (Use &Idx : GEP->indices())
537+
IndexExprs.push_back(SE->getSCEV(Idx));
538538

539539
gep_type_iterator GTI = gep_type_begin(GEP);
540540
for (unsigned I = 1, E = GEP->getNumOperands(); I != E; ++I, ++GTI) {

llvm/lib/Transforms/Scalar/StructurizeCFG.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,8 @@ void StructurizeCFG::killTerminator(BasicBlock *BB) {
677677
if (!Term)
678678
return;
679679

680-
for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB);
681-
SI != SE; ++SI)
682-
delPhiValues(BB, *SI);
680+
for (BasicBlock *Succ : successors(BB))
681+
delPhiValues(BB, Succ);
683682

684683
if (DA)
685684
DA->removeValue(Term);

0 commit comments

Comments
 (0)