Skip to content

Commit 8e86c0e

Browse files
[Scalar] Use make_early_inc_range (NFC)
1 parent 3a12613 commit 8e86c0e

9 files changed

+28
-41
lines changed

llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,7 @@ static bool doCallSiteSplitting(Function &F, TargetLibraryInfo &TLI,
505505

506506
DomTreeUpdater DTU(&DT, DomTreeUpdater::UpdateStrategy::Lazy);
507507
bool Changed = false;
508-
for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE;) {
509-
BasicBlock &BB = *BI++;
508+
for (BasicBlock &BB : llvm::make_early_inc_range(F)) {
510509
auto II = BB.getFirstNonPHIOrDbg()->getIterator();
511510
auto IE = BB.getTerminator()->getIterator();
512511
// Iterate until we reach the terminator instruction. tryToSplitCallSite

llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,49 +1048,48 @@ static bool runImpl(Function &F, LazyValueInfo *LVI, DominatorTree *DT,
10481048
// blocks.
10491049
for (BasicBlock *BB : depth_first(&F.getEntryBlock())) {
10501050
bool BBChanged = false;
1051-
for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE;) {
1052-
Instruction *II = &*BI++;
1053-
switch (II->getOpcode()) {
1051+
for (Instruction &II : llvm::make_early_inc_range(*BB)) {
1052+
switch (II.getOpcode()) {
10541053
case Instruction::Select:
1055-
BBChanged |= processSelect(cast<SelectInst>(II), LVI);
1054+
BBChanged |= processSelect(cast<SelectInst>(&II), LVI);
10561055
break;
10571056
case Instruction::PHI:
1058-
BBChanged |= processPHI(cast<PHINode>(II), LVI, DT, SQ);
1057+
BBChanged |= processPHI(cast<PHINode>(&II), LVI, DT, SQ);
10591058
break;
10601059
case Instruction::ICmp:
10611060
case Instruction::FCmp:
1062-
BBChanged |= processCmp(cast<CmpInst>(II), LVI);
1061+
BBChanged |= processCmp(cast<CmpInst>(&II), LVI);
10631062
break;
10641063
case Instruction::Load:
10651064
case Instruction::Store:
1066-
BBChanged |= processMemAccess(II, LVI);
1065+
BBChanged |= processMemAccess(&II, LVI);
10671066
break;
10681067
case Instruction::Call:
10691068
case Instruction::Invoke:
1070-
BBChanged |= processCallSite(cast<CallBase>(*II), LVI);
1069+
BBChanged |= processCallSite(cast<CallBase>(II), LVI);
10711070
break;
10721071
case Instruction::SRem:
10731072
case Instruction::SDiv:
1074-
BBChanged |= processSDivOrSRem(cast<BinaryOperator>(II), LVI);
1073+
BBChanged |= processSDivOrSRem(cast<BinaryOperator>(&II), LVI);
10751074
break;
10761075
case Instruction::UDiv:
10771076
case Instruction::URem:
1078-
BBChanged |= processUDivOrURem(cast<BinaryOperator>(II), LVI);
1077+
BBChanged |= processUDivOrURem(cast<BinaryOperator>(&II), LVI);
10791078
break;
10801079
case Instruction::AShr:
1081-
BBChanged |= processAShr(cast<BinaryOperator>(II), LVI);
1080+
BBChanged |= processAShr(cast<BinaryOperator>(&II), LVI);
10821081
break;
10831082
case Instruction::SExt:
1084-
BBChanged |= processSExt(cast<SExtInst>(II), LVI);
1083+
BBChanged |= processSExt(cast<SExtInst>(&II), LVI);
10851084
break;
10861085
case Instruction::Add:
10871086
case Instruction::Sub:
10881087
case Instruction::Mul:
10891088
case Instruction::Shl:
1090-
BBChanged |= processBinOp(cast<BinaryOperator>(II), LVI);
1089+
BBChanged |= processBinOp(cast<BinaryOperator>(&II), LVI);
10911090
break;
10921091
case Instruction::And:
1093-
BBChanged |= processAnd(cast<BinaryOperator>(II), LVI);
1092+
BBChanged |= processAnd(cast<BinaryOperator>(&II), LVI);
10941093
break;
10951094
}
10961095
}

llvm/lib/Transforms/Scalar/GVN.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,10 +2460,8 @@ bool GVN::runImpl(Function &F, AssumptionCache &RunAC, DominatorTree &RunDT,
24602460
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager);
24612461
// Merge unconditional branches, allowing PRE to catch more
24622462
// optimization opportunities.
2463-
for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ) {
2464-
BasicBlock *BB = &*FI++;
2465-
2466-
bool removedBlock = MergeBlockIntoPredecessor(BB, &DTU, LI, MSSAU, MD);
2463+
for (BasicBlock &BB : llvm::make_early_inc_range(F)) {
2464+
bool removedBlock = MergeBlockIntoPredecessor(&BB, &DTU, LI, MSSAU, MD);
24672465
if (removedBlock)
24682466
++NumGVNBlocks;
24692467

llvm/lib/Transforms/Scalar/LICM.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,7 @@ bool llvm::hoistRegion(DomTreeNode *N, AAResults *AA, LoopInfo *LI,
883883
if (!LoopNestMode && inSubLoop(BB, CurLoop, LI))
884884
continue;
885885

886-
for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E;) {
887-
Instruction &I = *II++;
886+
for (Instruction &I : llvm::make_early_inc_range(*BB)) {
888887
// Try constant folding this instruction. If all the operands are
889888
// constants, it is technically hoistable, but it would be better to
890889
// just fold it.

llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ static bool simplifyLoopInst(Loop &L, DominatorTree &DT, LoopInfo &LI,
105105
if (!V || !LI.replacementPreservesLCSSAForm(&I, V))
106106
continue;
107107

108-
for (Value::use_iterator UI = I.use_begin(), UE = I.use_end();
109-
UI != UE;) {
110-
Use &U = *UI++;
108+
for (Use &U : llvm::make_early_inc_range(I.uses())) {
111109
auto *UserI = cast<Instruction>(U.getUser());
112110
U.set(V);
113111

llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,8 +900,7 @@ class LowerMatrixIntrinsics {
900900
// UndefedInsts and then check that we in fact remove them.
901901
SmallSet<Instruction *, 16> UndefedInsts;
902902
for (auto *Inst : reverse(ToRemove)) {
903-
for (auto I = Inst->use_begin(), E = Inst->use_end(); I != E;) {
904-
Use &U = *I++;
903+
for (Use &U : llvm::make_early_inc_range(Inst->uses())) {
905904
if (auto *Undefed = dyn_cast<Instruction>(U.getUser()))
906905
UndefedInsts.insert(Undefed);
907906
U.set(UndefValue::get(Inst->getType()));

llvm/lib/Transforms/Scalar/SCCP.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -539,14 +539,13 @@ bool llvm::runIPSCCP(
539539
DTU.deleteBB(DeadBB);
540540

541541
for (BasicBlock &BB : F) {
542-
for (BasicBlock::iterator BI = BB.begin(), E = BB.end(); BI != E;) {
543-
Instruction *Inst = &*BI++;
544-
if (Solver.getPredicateInfoFor(Inst)) {
545-
if (auto *II = dyn_cast<IntrinsicInst>(Inst)) {
542+
for (Instruction &Inst : llvm::make_early_inc_range(BB)) {
543+
if (Solver.getPredicateInfoFor(&Inst)) {
544+
if (auto *II = dyn_cast<IntrinsicInst>(&Inst)) {
546545
if (II->getIntrinsicID() == Intrinsic::ssa_copy) {
547546
Value *Op = II->getOperand(0);
548-
Inst->replaceAllUsesWith(Op);
549-
Inst->eraseFromParent();
547+
Inst.replaceAllUsesWith(Op);
548+
Inst.eraseFromParent();
550549
}
551550
}
552551
}

llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -873,13 +873,11 @@ static bool runImpl(Function &F, const TargetTransformInfo &TTI,
873873
auto &DL = F.getParent()->getDataLayout();
874874
while (MadeChange) {
875875
MadeChange = false;
876-
for (Function::iterator I = F.begin(); I != F.end();) {
877-
BasicBlock *BB = &*I++;
876+
for (BasicBlock &BB : llvm::make_early_inc_range(F)) {
878877
bool ModifiedDTOnIteration = false;
879-
MadeChange |= optimizeBlock(*BB, ModifiedDTOnIteration, TTI, DL,
878+
MadeChange |= optimizeBlock(BB, ModifiedDTOnIteration, TTI, DL,
880879
DTU.hasValue() ? DTU.getPointer() : nullptr);
881880

882-
883881
// Restart BB iteration if the dominator tree of the Function was changed
884882
if (ModifiedDTOnIteration)
885883
break;

llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,10 +1258,8 @@ bool SeparateConstOffsetFromGEP::reuniteExts(Function &F) {
12581258
DominatingSubs.clear();
12591259
for (const auto Node : depth_first(DT)) {
12601260
BasicBlock *BB = Node->getBlock();
1261-
for (auto I = BB->begin(); I != BB->end(); ) {
1262-
Instruction *Cur = &*I++;
1263-
Changed |= reuniteExts(Cur);
1264-
}
1261+
for (Instruction &I : llvm::make_early_inc_range(*BB))
1262+
Changed |= reuniteExts(&I);
12651263
}
12661264
return Changed;
12671265
}

0 commit comments

Comments
 (0)