// Iterate over the original function, only adding insts to the worklist
// if they actually need to be revisited. This avoids having to pre-init
// the worklist with the entire function's worth of instructions.
- for (inst_iterator FI = inst_begin(F), FE = inst_end(F); FI != FE;) {
- Instruction *I = &*FI;
- ++FI;
-
+ for (Instruction &I : llvm::make_early_inc_range(instructions(F))) {
// We're visiting this instruction now, so make sure it's not in the
// worklist from an earlier visit.
- if (!WorkList.count(I))
- MadeChange |= DCEInstruction(I, WorkList, TLI);
+ if (!WorkList.count(&I))
+ MadeChange |= DCEInstruction(&I, WorkList, TLI);
}
while (!WorkList.empty()) {
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void GVN::dump(DenseMap<uint32_t, Value*>& d) const {
errs() << "{\n";
- for (DenseMap<uint32_t, Value*>::iterator I = d.begin(),
- E = d.end(); I != E; ++I) {
- errs() << I->first << "\n";
- I->second->dump();
+ for (auto &I : d) {
+ errs() << I.first << "\n";
+ I.second->dump();
}
errs() << "}\n";
}
MD->getNonLocalCallDependency(Call);
// Check to see if the Call has no function local clobber.
- for (unsigned i = 0; i < deps.size(); i++) {
- if (deps[i].getResult().isNonFuncLocal())
+ for (const NonLocalDepEntry &D : deps) {
+ if (D.getResult().isNonFuncLocal())
return true;
}
return false;
// Walk through the value number scope to make sure the instruction isn't
// ferreted away in it.
- for (DenseMap<uint32_t, LeaderTableEntry>::const_iterator
- I = LeaderTable.begin(), E = LeaderTable.end(); I != E; ++I) {
- const LeaderTableEntry *Node = &I->second;
+ for (const auto &I : LeaderTable) {
+ const LeaderTableEntry *Node = &I.second;
assert(Node->Val != Inst && "Inst still in value numbering scope!");
while (Node->Next) {
// invariant instructions, and then walk their operands to re-establish
// LCSSA. That will eliminate creating PHI nodes just to nuke them when
// sinking bottom-up.
- for (User::op_iterator OI = New->op_begin(), OE = New->op_end(); OI != OE;
- ++OI)
- if (Instruction *OInst = dyn_cast<Instruction>(*OI))
+ for (Use &Op : New->operands())
+ if (Instruction *OInst = dyn_cast<Instruction>(Op))
if (Loop *OLoop = LI->getLoopFor(OInst->getParent()))
if (!OLoop->contains(&PN)) {
PHINode *OpPN =
OInst->getName() + ".lcssa", &ExitBlock.front());
for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)
OpPN->addIncoming(OInst, PN.getIncomingBlock(i));
- *OI = OpPN;
+ Op = OpPN;
}
return New;
}
assert(!NewI->mayHaveSideEffects() &&
"Moving instructions with side-effects may change behavior of "
"the loop nest!");
- for (auto UI = WorkList[i]->use_begin(), UE = WorkList[i]->use_end();
- UI != UE;) {
- Use &U = *UI++;
+ for (Use &U : llvm::make_early_inc_range(WorkList[i]->uses())) {
Instruction *UserI = cast<Instruction>(U.getUser());
if (!InnerLoop->contains(UserI->getParent()) ||
UserI->getParent() == NewLatch || UserI == InductionPHI)
}
// We also want to collect single-user "feeder" values.
- for (User::op_iterator OI = I->op_begin(),
- OIE = I->op_end(); OI != OIE; ++OI) {
- if (Instruction *Op = dyn_cast<Instruction>(*OI))
+ for (Use &U : I->operands()) {
+ if (Instruction *Op = dyn_cast<Instruction>(U))
if (Op->hasOneUse() && L->contains(Op) && !Exclude.count(Op) &&
!Final.count(Op))
Queue.push_back(Op);
// Clone unswitched values info:
// for new loop switches we clone info about values that was
// already unswitched and has redundant successors.
- for (UnswitchedValsIt I = Insts.begin(); I != Insts.end(); ++I) {
- const SwitchInst *OldInst = I->first;
+ for (const auto &I : Insts) {
+ const SwitchInst *OldInst = I.first;
Value *NewI = VMap.lookup(OldInst);
const SwitchInst *NewInst = cast_or_null<SwitchInst>(NewI);
assert(NewInst && "All instructions that are in SrcBB must be in VMap.");
ToRemove.push_back(Inst);
Value *Flattened = nullptr;
- for (auto I = Inst->use_begin(), E = Inst->use_end(); I != E;) {
- Use &U = *I++;
+ for (Use &U : llvm::make_early_inc_range(Inst->uses())) {
if (ShapeMap.find(U.getUser()) == ShapeMap.end()) {
if (!Flattened)
Flattened = Matrix.embedInVector(Builder);
SmallVector<WeakTrackingVH, 16> DeadInsts;
for (const auto Node : depth_first(DT)) {
BasicBlock *BB = Node->getBlock();
- for (auto I = BB->begin(); I != BB->end(); ++I) {
- Instruction *OrigI = &*I;
+ for (Instruction &OrigI : *BB) {
const SCEV *OrigSCEV = nullptr;
- if (Instruction *NewI = tryReassociate(OrigI, OrigSCEV)) {
+ if (Instruction *NewI = tryReassociate(&OrigI, OrigSCEV)) {
Changed = true;
- OrigI->replaceAllUsesWith(NewI);
+ OrigI.replaceAllUsesWith(NewI);
// Add 'OrigI' to the list of dead instructions.
- DeadInsts.push_back(WeakTrackingVH(OrigI));
+ DeadInsts.push_back(WeakTrackingVH(&OrigI));
// Add the rewritten instruction to SeenExprs; the original
// instruction is deleted.
const SCEV *NewSCEV = SE->getSCEV(NewI);
if (NewSCEV != OrigSCEV)
SeenExprs[OrigSCEV].push_back(WeakTrackingVH(NewI));
} else if (OrigSCEV)
- SeenExprs[OrigSCEV].push_back(WeakTrackingVH(OrigI));
+ SeenExprs[OrigSCEV].push_back(WeakTrackingVH(&OrigI));
}
}
// Delete all dead instructions from 'DeadInsts'.
assert(!isa<Constant>(Invariant) && "Why are we unswitching on a constant?");
// Replace uses of LIC in the loop with the given constant.
- for (auto UI = Invariant->use_begin(), UE = Invariant->use_end(); UI != UE;) {
- // Grab the use and walk past it so we can clobber it in the use list.
- Use *U = &*UI++;
- Instruction *UserI = dyn_cast<Instruction>(U->getUser());
+ // We use make_early_inc_range as set invalidates the iterator.
+ for (Use &U : llvm::make_early_inc_range(Invariant->uses())) {
+ Instruction *UserI = dyn_cast<Instruction>(U.getUser());
// Replace this use within the loop body.
if (UserI && L.contains(UserI))
- U->set(&Replacement);
+ U.set(&Replacement);
}
}
Direction ? ConstantInt::getFalse(BI->getContext())
: ConstantInt::getTrue(BI->getContext());
for (Value *Invariant : Invariants)
- for (auto UI = Invariant->use_begin(), UE = Invariant->use_end();
- UI != UE;) {
- // Grab the use and walk past it so we can clobber it in the use list.
- Use *U = &*UI++;
- Instruction *UserI = dyn_cast<Instruction>(U->getUser());
+ // Use make_early_inc_range here as set invalidates the iterator.
+ for (Use &U : llvm::make_early_inc_range(Invariant->uses())) {
+ Instruction *UserI = dyn_cast<Instruction>(U.getUser());
if (!UserI)
continue;
// Replace it with the 'continue' side if in the main loop body, and the
// unswitched if in the cloned blocks.
if (DT.dominates(LoopPH, UserI->getParent()))
- U->set(ContinueReplacement);
+ U.set(ContinueReplacement);
else if (ReplaceUnswitched &&
DT.dominates(ClonedPH, UserI->getParent()))
- U->set(UnswitchedReplacement);
+ U.set(UnswitchedReplacement);
}
}
BasicBlock *OldExit = SubRegion->getExit();
BasicBlock *Dominator = nullptr;
- // Find all the edges from the sub region to the exit
- for (auto BBI = pred_begin(OldExit), E = pred_end(OldExit); BBI != E;) {
- // Incrememt BBI before mucking with BB's terminator.
- BasicBlock *BB = *BBI++;
-
+ // Find all the edges from the sub region to the exit.
+ // We use make_early_inc_range here because we modify BB's terminator.
+ for (BasicBlock *BB : llvm::make_early_inc_range(predecessors(OldExit))) {
if (!SubRegion->contains(BB))
continue;
for (BasicBlock *BB : ParentRegion->blocks())
for (Instruction &I : *BB) {
bool Initialized = false;
- // We may modify the use list as we iterate over it, so be careful to
- // compute the next element in the use list at the top of the loop.
- for (auto UI = I.use_begin(), E = I.use_end(); UI != E;) {
- Use &U = *UI++;
+ // We may modify the use list as we iterate over it, so we use
+ // make_early_inc_range.
+ for (Use &U : llvm::make_early_inc_range(I.uses())) {
Instruction *User = cast<Instruction>(U.getUser());
if (User->getParent() == BB) {
continue;