[llvm] Use make_early_inc_range (NFC)

This commit is contained in:
Kazu Hirata 2021-11-05 19:39:06 -07:00
parent ca1a8be06b
commit 87e53a0ad8
9 changed files with 29 additions and 50 deletions

View File

@ -1135,11 +1135,7 @@ void MemorySSAUpdater::applyInsertUpdates(ArrayRef<CFGUpdate> Updates,
if (auto DefsList = MSSA->getWritableBlockDefs(BlockWithDefsToReplace)) { if (auto DefsList = MSSA->getWritableBlockDefs(BlockWithDefsToReplace)) {
for (auto &DefToReplaceUses : *DefsList) { for (auto &DefToReplaceUses : *DefsList) {
BasicBlock *DominatingBlock = DefToReplaceUses.getBlock(); BasicBlock *DominatingBlock = DefToReplaceUses.getBlock();
Value::use_iterator UI = DefToReplaceUses.use_begin(), for (Use &U : llvm::make_early_inc_range(DefToReplaceUses.uses())) {
E = DefToReplaceUses.use_end();
for (; UI != E;) {
Use &U = *UI;
++UI;
MemoryAccess *Usr = cast<MemoryAccess>(U.getUser()); MemoryAccess *Usr = cast<MemoryAccess>(U.getUser());
if (MemoryPhi *UsrPhi = dyn_cast<MemoryPhi>(Usr)) { if (MemoryPhi *UsrPhi = dyn_cast<MemoryPhi>(Usr)) {
BasicBlock *DominatedBlock = UsrPhi->getIncomingBlock(U); BasicBlock *DominatedBlock = UsrPhi->getIncomingBlock(U);

View File

@ -341,9 +341,8 @@ void InlineSpiller::collectRegsToSpill() {
if (Original == Reg) if (Original == Reg)
return; return;
for (MachineRegisterInfo::reg_instr_iterator for (MachineInstr &MI :
RI = MRI.reg_instr_begin(Reg), E = MRI.reg_instr_end(); RI != E; ) { llvm::make_early_inc_range(MRI.reg_instructions(Reg))) {
MachineInstr &MI = *RI++;
Register SnipReg = isFullCopyOf(MI, Reg); Register SnipReg = isFullCopyOf(MI, Reg);
if (!isSibling(SnipReg)) if (!isSibling(SnipReg))
continue; continue;

View File

@ -196,10 +196,8 @@ void FastISel::flushLocalValueMap() {
EmitStartPt ? MachineBasicBlock::reverse_iterator(EmitStartPt) EmitStartPt ? MachineBasicBlock::reverse_iterator(EmitStartPt)
: FuncInfo.MBB->rend(); : FuncInfo.MBB->rend();
MachineBasicBlock::reverse_iterator RI(LastLocalValue); MachineBasicBlock::reverse_iterator RI(LastLocalValue);
for (; RI != RE;) { for (MachineInstr &LocalMI :
MachineInstr &LocalMI = *RI; llvm::make_early_inc_range(llvm::make_range(RI, RE))) {
// Increment before erasing what it points to.
++RI;
Register DefReg = findLocalRegDef(LocalMI); Register DefReg = findLocalRegDef(LocalMI);
if (!DefReg) if (!DefReg)
continue; continue;

View File

@ -9819,21 +9819,20 @@ unsigned SelectionDAG::AssignTopologicalOrder() {
// before SortedPos will contain the topological sort index, and the // before SortedPos will contain the topological sort index, and the
// Node Id fields for nodes At SortedPos and after will contain the // Node Id fields for nodes At SortedPos and after will contain the
// count of outstanding operands. // count of outstanding operands.
for (allnodes_iterator I = allnodes_begin(),E = allnodes_end(); I != E; ) { for (SDNode &N : llvm::make_early_inc_range(allnodes())) {
SDNode *N = &*I++; checkForCycles(&N, this);
checkForCycles(N, this); unsigned Degree = N.getNumOperands();
unsigned Degree = N->getNumOperands();
if (Degree == 0) { if (Degree == 0) {
// A node with no uses, add it to the result array immediately. // A node with no uses, add it to the result array immediately.
N->setNodeId(DAGSize++); N.setNodeId(DAGSize++);
allnodes_iterator Q(N); allnodes_iterator Q(&N);
if (Q != SortedPos) if (Q != SortedPos)
SortedPos = AllNodes.insert(SortedPos, AllNodes.remove(Q)); SortedPos = AllNodes.insert(SortedPos, AllNodes.remove(Q));
assert(SortedPos != AllNodes.end() && "Overran node list"); assert(SortedPos != AllNodes.end() && "Overran node list");
++SortedPos; ++SortedPos;
} else { } else {
// Temporarily use the Node Id as scratch space for the degree count. // Temporarily use the Node Id as scratch space for the degree count.
N->setNodeId(Degree); N.setNodeId(Degree);
} }
} }

View File

@ -447,8 +447,7 @@ bool llvm::stripDebugInfo(Function &F) {
DenseMap<MDNode *, MDNode *> LoopIDsMap; DenseMap<MDNode *, MDNode *> LoopIDsMap;
for (BasicBlock &BB : F) { for (BasicBlock &BB : F) {
for (auto II = BB.begin(), End = BB.end(); II != End;) { for (Instruction &I : llvm::make_early_inc_range(BB)) {
Instruction &I = *II++; // We may delete the instruction, increment now.
if (isa<DbgInfoIntrinsic>(&I)) { if (isa<DbgInfoIntrinsic>(&I)) {
I.eraseFromParent(); I.eraseFromParent();
Changed = true; Changed = true;

View File

@ -546,9 +546,7 @@ void Value::replaceUsesWithIf(Value *New,
SmallVector<TrackingVH<Constant>, 8> Consts; SmallVector<TrackingVH<Constant>, 8> Consts;
SmallPtrSet<Constant *, 8> Visited; SmallPtrSet<Constant *, 8> Visited;
for (use_iterator UI = use_begin(), E = use_end(); UI != E;) { for (Use &U : llvm::make_early_inc_range(uses())) {
Use &U = *UI;
++UI;
if (!ShouldReplace(U)) if (!ShouldReplace(U))
continue; continue;
// Must handle Constants specially, we cannot call replaceUsesOfWith on a // Must handle Constants specially, we cannot call replaceUsesOfWith on a

View File

@ -485,20 +485,14 @@ bool ModuleLinker::run() {
// Alias have to go first, since we are not able to find their comdats // Alias have to go first, since we are not able to find their comdats
// otherwise. // otherwise.
for (auto I = DstM.alias_begin(), E = DstM.alias_end(); I != E;) { for (GlobalAlias &GV : llvm::make_early_inc_range(DstM.aliases()))
GlobalAlias &GV = *I++;
dropReplacedComdat(GV, ReplacedDstComdats); dropReplacedComdat(GV, ReplacedDstComdats);
}
for (auto I = DstM.global_begin(), E = DstM.global_end(); I != E;) { for (GlobalVariable &GV : llvm::make_early_inc_range(DstM.globals()))
GlobalVariable &GV = *I++;
dropReplacedComdat(GV, ReplacedDstComdats); dropReplacedComdat(GV, ReplacedDstComdats);
}
for (auto I = DstM.begin(), E = DstM.end(); I != E;) { for (Function &GV : llvm::make_early_inc_range(DstM))
Function &GV = *I++;
dropReplacedComdat(GV, ReplacedDstComdats); dropReplacedComdat(GV, ReplacedDstComdats);
}
for (GlobalVariable &GV : SrcM->globals()) for (GlobalVariable &GV : SrcM->globals())
if (GV.hasLinkOnceLinkage()) if (GV.hasLinkOnceLinkage())

View File

@ -523,23 +523,20 @@ Function *IROutliner::createFunction(Module &M, OutlinableGroup &Group,
/// \param [out] NewEnds - The return blocks of the new overall function. /// \param [out] NewEnds - The return blocks of the new overall function.
static void moveFunctionData(Function &Old, Function &New, static void moveFunctionData(Function &Old, Function &New,
DenseMap<Value *, BasicBlock *> &NewEnds) { DenseMap<Value *, BasicBlock *> &NewEnds) {
Function::iterator CurrBB, NextBB, FinalBB; for (BasicBlock &CurrBB : llvm::make_early_inc_range(Old)) {
for (CurrBB = Old.begin(), FinalBB = Old.end(); CurrBB != FinalBB; CurrBB.removeFromParent();
CurrBB = NextBB) { CurrBB.insertInto(&New);
NextBB = std::next(CurrBB); Instruction *I = CurrBB.getTerminator();
CurrBB->removeFromParent();
CurrBB->insertInto(&New);
Instruction *I = CurrBB->getTerminator();
// For each block we find a return instruction is, it is a potential exit // For each block we find a return instruction is, it is a potential exit
// path for the function. We keep track of each block based on the return // path for the function. We keep track of each block based on the return
// value here. // value here.
if (ReturnInst *RI = dyn_cast<ReturnInst>(I)) if (ReturnInst *RI = dyn_cast<ReturnInst>(I))
NewEnds.insert(std::make_pair(RI->getReturnValue(), &(*CurrBB))); NewEnds.insert(std::make_pair(RI->getReturnValue(), &CurrBB));
std::vector<Instruction *> DebugInsts; std::vector<Instruction *> DebugInsts;
for (Instruction &Val : *CurrBB) { for (Instruction &Val : CurrBB) {
// We must handle the scoping of called functions differently than // We must handle the scoping of called functions differently than
// other outlined instructions. // other outlined instructions.
if (!isa<CallInst>(&Val)) { if (!isa<CallInst>(&Val)) {

View File

@ -786,14 +786,13 @@ bool ReduceCrashingInstructions::TestInsts(
for (Module::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) for (Module::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI)
for (Function::iterator FI = MI->begin(), FE = MI->end(); FI != FE; ++FI) for (Function::iterator FI = MI->begin(), FE = MI->end(); FI != FE; ++FI)
for (BasicBlock::iterator I = FI->begin(), E = FI->end(); I != E;) { for (Instruction &Inst : llvm::make_early_inc_range(*FI)) {
Instruction *Inst = &*I++; if (!Instructions.count(&Inst) && !Inst.isTerminator() &&
if (!Instructions.count(Inst) && !Inst->isTerminator() && !Inst.isEHPad() && !Inst.getType()->isTokenTy() &&
!Inst->isEHPad() && !Inst->getType()->isTokenTy() && !Inst.isSwiftError()) {
!Inst->isSwiftError()) { if (!Inst.getType()->isVoidTy())
if (!Inst->getType()->isVoidTy()) Inst.replaceAllUsesWith(UndefValue::get(Inst.getType()));
Inst->replaceAllUsesWith(UndefValue::get(Inst->getType())); Inst.eraseFromParent();
Inst->eraseFromParent();
} }
} }