Skip to content

Commit 87e53a0

Browse files
[llvm] Use make_early_inc_range (NFC)
1 parent ca1a8be commit 87e53a0

File tree

9 files changed

+29
-50
lines changed

9 files changed

+29
-50
lines changed

llvm/lib/Analysis/MemorySSAUpdater.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,11 +1135,7 @@ void MemorySSAUpdater::applyInsertUpdates(ArrayRef<CFGUpdate> Updates,
11351135
if (auto DefsList = MSSA->getWritableBlockDefs(BlockWithDefsToReplace)) {
11361136
for (auto &DefToReplaceUses : *DefsList) {
11371137
BasicBlock *DominatingBlock = DefToReplaceUses.getBlock();
1138-
Value::use_iterator UI = DefToReplaceUses.use_begin(),
1139-
E = DefToReplaceUses.use_end();
1140-
for (; UI != E;) {
1141-
Use &U = *UI;
1142-
++UI;
1138+
for (Use &U : llvm::make_early_inc_range(DefToReplaceUses.uses())) {
11431139
MemoryAccess *Usr = cast<MemoryAccess>(U.getUser());
11441140
if (MemoryPhi *UsrPhi = dyn_cast<MemoryPhi>(Usr)) {
11451141
BasicBlock *DominatedBlock = UsrPhi->getIncomingBlock(U);

llvm/lib/CodeGen/InlineSpiller.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,8 @@ void InlineSpiller::collectRegsToSpill() {
341341
if (Original == Reg)
342342
return;
343343

344-
for (MachineRegisterInfo::reg_instr_iterator
345-
RI = MRI.reg_instr_begin(Reg), E = MRI.reg_instr_end(); RI != E; ) {
346-
MachineInstr &MI = *RI++;
344+
for (MachineInstr &MI :
345+
llvm::make_early_inc_range(MRI.reg_instructions(Reg))) {
347346
Register SnipReg = isFullCopyOf(MI, Reg);
348347
if (!isSibling(SnipReg))
349348
continue;

llvm/lib/CodeGen/SelectionDAG/FastISel.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,8 @@ void FastISel::flushLocalValueMap() {
196196
EmitStartPt ? MachineBasicBlock::reverse_iterator(EmitStartPt)
197197
: FuncInfo.MBB->rend();
198198
MachineBasicBlock::reverse_iterator RI(LastLocalValue);
199-
for (; RI != RE;) {
200-
MachineInstr &LocalMI = *RI;
201-
// Increment before erasing what it points to.
202-
++RI;
199+
for (MachineInstr &LocalMI :
200+
llvm::make_early_inc_range(llvm::make_range(RI, RE))) {
203201
Register DefReg = findLocalRegDef(LocalMI);
204202
if (!DefReg)
205203
continue;

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9819,21 +9819,20 @@ unsigned SelectionDAG::AssignTopologicalOrder() {
98199819
// before SortedPos will contain the topological sort index, and the
98209820
// Node Id fields for nodes At SortedPos and after will contain the
98219821
// count of outstanding operands.
9822-
for (allnodes_iterator I = allnodes_begin(),E = allnodes_end(); I != E; ) {
9823-
SDNode *N = &*I++;
9824-
checkForCycles(N, this);
9825-
unsigned Degree = N->getNumOperands();
9822+
for (SDNode &N : llvm::make_early_inc_range(allnodes())) {
9823+
checkForCycles(&N, this);
9824+
unsigned Degree = N.getNumOperands();
98269825
if (Degree == 0) {
98279826
// A node with no uses, add it to the result array immediately.
9828-
N->setNodeId(DAGSize++);
9829-
allnodes_iterator Q(N);
9827+
N.setNodeId(DAGSize++);
9828+
allnodes_iterator Q(&N);
98309829
if (Q != SortedPos)
98319830
SortedPos = AllNodes.insert(SortedPos, AllNodes.remove(Q));
98329831
assert(SortedPos != AllNodes.end() && "Overran node list");
98339832
++SortedPos;
98349833
} else {
98359834
// Temporarily use the Node Id as scratch space for the degree count.
9836-
N->setNodeId(Degree);
9835+
N.setNodeId(Degree);
98379836
}
98389837
}
98399838

llvm/lib/IR/DebugInfo.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,7 @@ bool llvm::stripDebugInfo(Function &F) {
447447

448448
DenseMap<MDNode *, MDNode *> LoopIDsMap;
449449
for (BasicBlock &BB : F) {
450-
for (auto II = BB.begin(), End = BB.end(); II != End;) {
451-
Instruction &I = *II++; // We may delete the instruction, increment now.
450+
for (Instruction &I : llvm::make_early_inc_range(BB)) {
452451
if (isa<DbgInfoIntrinsic>(&I)) {
453452
I.eraseFromParent();
454453
Changed = true;

llvm/lib/IR/Value.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,7 @@ void Value::replaceUsesWithIf(Value *New,
546546
SmallVector<TrackingVH<Constant>, 8> Consts;
547547
SmallPtrSet<Constant *, 8> Visited;
548548

549-
for (use_iterator UI = use_begin(), E = use_end(); UI != E;) {
550-
Use &U = *UI;
551-
++UI;
549+
for (Use &U : llvm::make_early_inc_range(uses())) {
552550
if (!ShouldReplace(U))
553551
continue;
554552
// Must handle Constants specially, we cannot call replaceUsesOfWith on a

llvm/lib/Linker/LinkModules.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -485,20 +485,14 @@ bool ModuleLinker::run() {
485485

486486
// Alias have to go first, since we are not able to find their comdats
487487
// otherwise.
488-
for (auto I = DstM.alias_begin(), E = DstM.alias_end(); I != E;) {
489-
GlobalAlias &GV = *I++;
488+
for (GlobalAlias &GV : llvm::make_early_inc_range(DstM.aliases()))
490489
dropReplacedComdat(GV, ReplacedDstComdats);
491-
}
492490

493-
for (auto I = DstM.global_begin(), E = DstM.global_end(); I != E;) {
494-
GlobalVariable &GV = *I++;
491+
for (GlobalVariable &GV : llvm::make_early_inc_range(DstM.globals()))
495492
dropReplacedComdat(GV, ReplacedDstComdats);
496-
}
497493

498-
for (auto I = DstM.begin(), E = DstM.end(); I != E;) {
499-
Function &GV = *I++;
494+
for (Function &GV : llvm::make_early_inc_range(DstM))
500495
dropReplacedComdat(GV, ReplacedDstComdats);
501-
}
502496

503497
for (GlobalVariable &GV : SrcM->globals())
504498
if (GV.hasLinkOnceLinkage())

llvm/lib/Transforms/IPO/IROutliner.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -523,23 +523,20 @@ Function *IROutliner::createFunction(Module &M, OutlinableGroup &Group,
523523
/// \param [out] NewEnds - The return blocks of the new overall function.
524524
static void moveFunctionData(Function &Old, Function &New,
525525
DenseMap<Value *, BasicBlock *> &NewEnds) {
526-
Function::iterator CurrBB, NextBB, FinalBB;
527-
for (CurrBB = Old.begin(), FinalBB = Old.end(); CurrBB != FinalBB;
528-
CurrBB = NextBB) {
529-
NextBB = std::next(CurrBB);
530-
CurrBB->removeFromParent();
531-
CurrBB->insertInto(&New);
532-
Instruction *I = CurrBB->getTerminator();
526+
for (BasicBlock &CurrBB : llvm::make_early_inc_range(Old)) {
527+
CurrBB.removeFromParent();
528+
CurrBB.insertInto(&New);
529+
Instruction *I = CurrBB.getTerminator();
533530

534531
// For each block we find a return instruction is, it is a potential exit
535532
// path for the function. We keep track of each block based on the return
536533
// value here.
537534
if (ReturnInst *RI = dyn_cast<ReturnInst>(I))
538-
NewEnds.insert(std::make_pair(RI->getReturnValue(), &(*CurrBB)));
535+
NewEnds.insert(std::make_pair(RI->getReturnValue(), &CurrBB));
539536

540537
std::vector<Instruction *> DebugInsts;
541538

542-
for (Instruction &Val : *CurrBB) {
539+
for (Instruction &Val : CurrBB) {
543540
// We must handle the scoping of called functions differently than
544541
// other outlined instructions.
545542
if (!isa<CallInst>(&Val)) {

llvm/tools/bugpoint/CrashDebugger.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -786,14 +786,13 @@ bool ReduceCrashingInstructions::TestInsts(
786786

787787
for (Module::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI)
788788
for (Function::iterator FI = MI->begin(), FE = MI->end(); FI != FE; ++FI)
789-
for (BasicBlock::iterator I = FI->begin(), E = FI->end(); I != E;) {
790-
Instruction *Inst = &*I++;
791-
if (!Instructions.count(Inst) && !Inst->isTerminator() &&
792-
!Inst->isEHPad() && !Inst->getType()->isTokenTy() &&
793-
!Inst->isSwiftError()) {
794-
if (!Inst->getType()->isVoidTy())
795-
Inst->replaceAllUsesWith(UndefValue::get(Inst->getType()));
796-
Inst->eraseFromParent();
789+
for (Instruction &Inst : llvm::make_early_inc_range(*FI)) {
790+
if (!Instructions.count(&Inst) && !Inst.isTerminator() &&
791+
!Inst.isEHPad() && !Inst.getType()->isTokenTy() &&
792+
!Inst.isSwiftError()) {
793+
if (!Inst.getType()->isVoidTy())
794+
Inst.replaceAllUsesWith(UndefValue::get(Inst.getType()));
795+
Inst.eraseFromParent();
797796
}
798797
}
799798

0 commit comments

Comments
 (0)