diff --git a/lib/CodeGen/MachineRegisterInfo.cpp b/lib/CodeGen/MachineRegisterInfo.cpp index 5325eda9d47..b789f9d5670 100644 --- a/lib/CodeGen/MachineRegisterInfo.cpp +++ b/lib/CodeGen/MachineRegisterInfo.cpp @@ -434,8 +434,8 @@ void MachineRegisterInfo::clearKillFlags(Register Reg) const { } bool MachineRegisterInfo::isLiveIn(Register Reg) const { - for (livein_iterator I = livein_begin(), E = livein_end(); I != E; ++I) - if ((Register)I->first == Reg || I->second == Reg) + for (const std::pair &LI : liveins()) + if ((Register)LI.first == Reg || LI.second == Reg) return true; return false; } @@ -443,18 +443,18 @@ bool MachineRegisterInfo::isLiveIn(Register Reg) const { /// getLiveInPhysReg - If VReg is a live-in virtual register, return the /// corresponding live-in physical register. MCRegister MachineRegisterInfo::getLiveInPhysReg(Register VReg) const { - for (livein_iterator I = livein_begin(), E = livein_end(); I != E; ++I) - if (I->second == VReg) - return I->first; + for (const std::pair &LI : liveins()) + if (LI.second == VReg) + return LI.first; return MCRegister(); } /// getLiveInVirtReg - If PReg is a live-in physical register, return the /// corresponding live-in physical register. Register MachineRegisterInfo::getLiveInVirtReg(MCRegister PReg) const { - for (livein_iterator I = livein_begin(), E = livein_end(); I != E; ++I) - if (I->first == PReg) - return I->second; + for (const std::pair &LI : liveins()) + if (LI.first == PReg) + return LI.second; return Register(); } diff --git a/lib/CodeGen/MachineSSAUpdater.cpp b/lib/CodeGen/MachineSSAUpdater.cpp index e6dee31d5c4..71bf755a42a 100644 --- a/lib/CodeGen/MachineSSAUpdater.cpp +++ b/lib/CodeGen/MachineSSAUpdater.cpp @@ -164,9 +164,7 @@ Register MachineSSAUpdater::GetValueInMiddleOfBlock(MachineBasicBlock *BB) { Register SingularValue; bool isFirstPred = true; - for (MachineBasicBlock::pred_iterator PI = BB->pred_begin(), - E = BB->pred_end(); PI != E; ++PI) { - MachineBasicBlock *PredBB = *PI; + for (MachineBasicBlock *PredBB : BB->predecessors()) { Register PredVal = GetValueAtEndOfBlockInternal(PredBB); PredValues.push_back(std::make_pair(PredBB, PredVal)); diff --git a/lib/CodeGen/PHIElimination.cpp b/lib/CodeGen/PHIElimination.cpp index 8148b64d844..b8e2b5701aa 100644 --- a/lib/CodeGen/PHIElimination.cpp +++ b/lib/CodeGen/PHIElimination.cpp @@ -550,9 +550,8 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB, LiveInterval &SrcLI = LIS->getInterval(SrcReg); bool isLiveOut = false; - for (MachineBasicBlock::succ_iterator SI = opBlock.succ_begin(), - SE = opBlock.succ_end(); SI != SE; ++SI) { - SlotIndex startIdx = LIS->getMBBStartIdx(*SI); + for (MachineBasicBlock *Succ : opBlock.successors()) { + SlotIndex startIdx = LIS->getMBBStartIdx(Succ); VNInfo *VNI = SrcLI.getVNInfoAt(startIdx); // Definitions by other PHIs are not truly live-in for our purposes. diff --git a/lib/CodeGen/RDFLiveness.cpp b/lib/CodeGen/RDFLiveness.cpp index 76bf0c28097..9a920ebad94 100644 --- a/lib/CodeGen/RDFLiveness.cpp +++ b/lib/CodeGen/RDFLiveness.cpp @@ -866,8 +866,8 @@ void Liveness::computeLiveIns() { // Dump the liveness map for (MachineBasicBlock &B : MF) { std::vector LV; - for (auto I = B.livein_begin(), E = B.livein_end(); I != E; ++I) - LV.push_back(RegisterRef(I->PhysReg, I->LaneMask)); + for (const MachineBasicBlock::RegisterMaskPair &LI : B.liveins()) + LV.push_back(RegisterRef(LI.PhysReg, LI.LaneMask)); llvm::sort(LV); dbgs() << printMBBReference(B) << "\t rec = {"; for (auto I : LV) @@ -893,16 +893,14 @@ void Liveness::resetLiveIns() { for (auto &B : DFG.getMF()) { // Remove all live-ins. std::vector T; - for (auto I = B.livein_begin(), E = B.livein_end(); I != E; ++I) - T.push_back(I->PhysReg); + for (const MachineBasicBlock::RegisterMaskPair &LI : B.liveins()) + T.push_back(LI.PhysReg); for (auto I : T) B.removeLiveIn(I); // Add the newly computed live-ins. const RegisterAggr &LiveIns = LiveMap[&B]; - for (auto I = LiveIns.rr_begin(), E = LiveIns.rr_end(); I != E; ++I) { - RegisterRef R = *I; + for (const RegisterRef &R : make_range(LiveIns.rr_begin(), LiveIns.rr_end())) B.addLiveIn({MCPhysReg(R.Reg), R.Mask}); - } } } diff --git a/lib/CodeGen/StackColoring.cpp b/lib/CodeGen/StackColoring.cpp index af58204f6db..162f3aab024 100644 --- a/lib/CodeGen/StackColoring.cpp +++ b/lib/CodeGen/StackColoring.cpp @@ -678,9 +678,8 @@ unsigned StackColoring::collectMarkers(unsigned NumSlot) { // to this bb). BitVector BetweenStartEnd; BetweenStartEnd.resize(NumSlot); - for (MachineBasicBlock::const_pred_iterator PI = MBB->pred_begin(), - PE = MBB->pred_end(); PI != PE; ++PI) { - BlockBitVecMap::const_iterator I = SeenStartMap.find(*PI); + for (const MachineBasicBlock *Pred : MBB->predecessors()) { + BlockBitVecMap::const_iterator I = SeenStartMap.find(Pred); if (I != SeenStartMap.end()) { BetweenStartEnd |= I->second; } @@ -819,9 +818,8 @@ void StackColoring::calculateLocalLiveness() { // Compute LiveIn by unioning together the LiveOut sets of all preds. BitVector LocalLiveIn; - for (MachineBasicBlock::const_pred_iterator PI = BB->pred_begin(), - PE = BB->pred_end(); PI != PE; ++PI) { - LivenessMap::const_iterator I = BlockLiveness.find(*PI); + for (MachineBasicBlock *Pred : BB->predecessors()) { + LivenessMap::const_iterator I = BlockLiveness.find(Pred); // PR37130: transformations prior to stack coloring can // sometimes leave behind statically unreachable blocks; these // can be safely skipped here. diff --git a/lib/CodeGen/TailDuplicator.cpp b/lib/CodeGen/TailDuplicator.cpp index 575bf555c48..d8eb51e945b 100644 --- a/lib/CodeGen/TailDuplicator.cpp +++ b/lib/CodeGen/TailDuplicator.cpp @@ -1035,10 +1035,9 @@ void TailDuplicator::removeDeadBlock( MachineFunction *MF = MBB->getParent(); // Update the call site info. - std::for_each(MBB->begin(), MBB->end(), [MF](const MachineInstr &MI) { + for (const MachineInstr &MI : *MBB) if (MI.shouldUpdateCallSiteInfo()) MF->eraseCallSiteInfo(&MI); - }); if (RemovalCallback) (*RemovalCallback)(MBB); diff --git a/lib/CodeGen/WinEHPrepare.cpp b/lib/CodeGen/WinEHPrepare.cpp index 96d256ba57a..36919ca0bfc 100644 --- a/lib/CodeGen/WinEHPrepare.cpp +++ b/lib/CodeGen/WinEHPrepare.cpp @@ -714,16 +714,14 @@ void WinEHPrepare::demotePHIsOnFunclets(Function &F, bool DemoteCatchSwitchPHIOnly) { // Strip PHI nodes off of EH pads. SmallVector PHINodes; - for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE;) { - BasicBlock *BB = &*FI++; - if (!BB->isEHPad()) + for (BasicBlock &BB : make_early_inc_range(F)) { + if (!BB.isEHPad()) continue; - if (DemoteCatchSwitchPHIOnly && !isa(BB->getFirstNonPHI())) + if (DemoteCatchSwitchPHIOnly && !isa(BB.getFirstNonPHI())) continue; - for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE;) { - Instruction *I = &*BI++; - auto *PN = dyn_cast(I); + for (Instruction &I : make_early_inc_range(BB)) { + auto *PN = dyn_cast(&I); // Stop at the first non-PHI. if (!PN) break;