From 9c56d039e9b8ed6eab44f59f81eebf29bbc207de Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Fri, 12 Feb 2021 23:44:33 -0800 Subject: [PATCH] [CodeGen] Use range-based for loops (NFC) --- lib/CodeGen/CriticalAntiDepBreaker.cpp | 31 ++++++++++------------ lib/CodeGen/DeadMachineInstructionElim.cpp | 6 ++--- lib/CodeGen/EdgeBundles.cpp | 10 +++---- lib/CodeGen/ExpandPostRAPseudos.cpp | 5 ++-- lib/CodeGen/GCRootLowering.cpp | 6 ++--- lib/CodeGen/GlobalISel/CSEInfo.cpp | 3 +-- lib/CodeGen/HardwareLoops.cpp | 4 +-- 7 files changed, 27 insertions(+), 38 deletions(-) diff --git a/lib/CodeGen/CriticalAntiDepBreaker.cpp b/lib/CodeGen/CriticalAntiDepBreaker.cpp index 7ae42b01026..c56c8c87734 100644 --- a/lib/CodeGen/CriticalAntiDepBreaker.cpp +++ b/lib/CodeGen/CriticalAntiDepBreaker.cpp @@ -65,9 +65,8 @@ void CriticalAntiDepBreaker::StartBlock(MachineBasicBlock *BB) { bool IsReturnBlock = BB->isReturnBlock(); // Examine the live-in regs of all successors. - for (MachineBasicBlock::succ_iterator SI = BB->succ_begin(), - SE = BB->succ_end(); SI != SE; ++SI) - for (const auto &LI : (*SI)->liveins()) { + for (const MachineBasicBlock *Succ : BB->successors()) + for (const auto &LI : Succ->liveins()) { for (MCRegAliasIterator AI(LI.PhysReg, TRI, true); AI.isValid(); ++AI) { unsigned Reg = *AI; Classes[Reg] = reinterpret_cast(-1); @@ -143,17 +142,16 @@ static const SDep *CriticalPathStep(const SUnit *SU) { const SDep *Next = nullptr; unsigned NextDepth = 0; // Find the predecessor edge with the greatest depth. - for (SUnit::const_pred_iterator P = SU->Preds.begin(), PE = SU->Preds.end(); - P != PE; ++P) { - const SUnit *PredSU = P->getSUnit(); - unsigned PredLatency = P->getLatency(); + for (const SDep &P : SU->Preds) { + const SUnit *PredSU = P.getSUnit(); + unsigned PredLatency = P.getLatency(); unsigned PredTotalLatency = PredSU->getDepth() + PredLatency; // In the case of a latency tie, prefer an anti-dependency edge over // other types of edges. if (NextDepth < PredTotalLatency || - (NextDepth == PredTotalLatency && P->getKind() == SDep::Anti)) { + (NextDepth == PredTotalLatency && P.getKind() == SDep::Anti)) { NextDepth = PredTotalLatency; - Next = &*P; + Next = &P; } } return Next; @@ -426,9 +424,8 @@ findSuitableFreeRegister(RegRefIter RegRefBegin, continue; // If NewReg overlaps any of the forbidden registers, we can't use it. bool Forbidden = false; - for (SmallVectorImpl::iterator it = Forbid.begin(), - ite = Forbid.end(); it != ite; ++it) - if (TRI->regsOverlap(NewReg, *it)) { + for (unsigned R : Forbid) + if (TRI->regsOverlap(NewReg, R)) { Forbidden = true; break; } @@ -582,11 +579,11 @@ BreakAntiDependencies(const std::vector &SUnits, // Also, if there are dependencies on other SUnits with the // same register as the anti-dependency, don't attempt to // break it. - for (SUnit::const_pred_iterator P = CriticalPathSU->Preds.begin(), - PE = CriticalPathSU->Preds.end(); P != PE; ++P) - if (P->getSUnit() == NextSU ? - (P->getKind() != SDep::Anti || P->getReg() != AntiDepReg) : - (P->getKind() == SDep::Data && P->getReg() == AntiDepReg)) { + for (const SDep &P : CriticalPathSU->Preds) + if (P.getSUnit() == NextSU + ? (P.getKind() != SDep::Anti || P.getReg() != AntiDepReg) + : (P.getKind() == SDep::Data && + P.getReg() == AntiDepReg)) { AntiDepReg = 0; break; } diff --git a/lib/CodeGen/DeadMachineInstructionElim.cpp b/lib/CodeGen/DeadMachineInstructionElim.cpp index 93467e9d09b..6e7db95b5c2 100644 --- a/lib/CodeGen/DeadMachineInstructionElim.cpp +++ b/lib/CodeGen/DeadMachineInstructionElim.cpp @@ -132,10 +132,8 @@ bool DeadMachineInstructionElim::eliminateDeadMI(MachineFunction &MF) { // Add live-ins from successors to LivePhysRegs. Normally, physregs are not // live across blocks, but some targets (x86) can have flags live out of a // block. - for (MachineBasicBlock::succ_iterator S = MBB->succ_begin(), - E = MBB->succ_end(); - S != E; S++) - for (const auto &LI : (*S)->liveins()) + for (const MachineBasicBlock *Succ : MBB->successors()) + for (const auto &LI : Succ->liveins()) LivePhysRegs.set(LI.PhysReg); // Now scan the instructions and delete dead ones, tracking physreg diff --git a/lib/CodeGen/EdgeBundles.cpp b/lib/CodeGen/EdgeBundles.cpp index 0b2ffda50a3..67922e93a52 100644 --- a/lib/CodeGen/EdgeBundles.cpp +++ b/lib/CodeGen/EdgeBundles.cpp @@ -46,9 +46,8 @@ bool EdgeBundles::runOnMachineFunction(MachineFunction &mf) { for (const auto &MBB : *MF) { unsigned OutE = 2 * MBB.getNumber() + 1; // Join the outgoing bundle with the ingoing bundles of all successors. - for (MachineBasicBlock::const_succ_iterator SI = MBB.succ_begin(), - SE = MBB.succ_end(); SI != SE; ++SI) - EC.join(OutE, 2 * (*SI)->getNumber()); + for (const MachineBasicBlock *Succ : MBB.successors()) + EC.join(OutE, 2 * Succ->getNumber()); } EC.compress(); if (ViewEdgeBundles) @@ -86,10 +85,9 @@ raw_ostream &WriteGraph<>(raw_ostream &O, const EdgeBundles &G, << "\"\n" << "\t\"" << printMBBReference(MBB) << "\" -> " << G.getBundle(BB, true) << '\n'; - for (MachineBasicBlock::const_succ_iterator SI = MBB.succ_begin(), - SE = MBB.succ_end(); SI != SE; ++SI) + for (const MachineBasicBlock *Succ : MBB.successors()) O << "\t\"" << printMBBReference(MBB) << "\" -> \"" - << printMBBReference(**SI) << "\" [ color=lightgray ]\n"; + << printMBBReference(*Succ) << "\" [ color=lightgray ]\n"; } O << "}\n"; return O; diff --git a/lib/CodeGen/ExpandPostRAPseudos.cpp b/lib/CodeGen/ExpandPostRAPseudos.cpp index 842211c0913..d909d6aa5b0 100644 --- a/lib/CodeGen/ExpandPostRAPseudos.cpp +++ b/lib/CodeGen/ExpandPostRAPseudos.cpp @@ -188,9 +188,8 @@ bool ExpandPostRA::runOnMachineFunction(MachineFunction &MF) { bool MadeChange = false; - for (MachineFunction::iterator mbbi = MF.begin(), mbbe = MF.end(); - mbbi != mbbe; ++mbbi) { - for (MachineBasicBlock::iterator mi = mbbi->begin(), me = mbbi->end(); + for (MachineBasicBlock &MBB : MF) { + for (MachineBasicBlock::iterator mi = MBB.begin(), me = MBB.end(); mi != me;) { MachineInstr &MI = *mi; // Advance iterator here because MI may be erased. diff --git a/lib/CodeGen/GCRootLowering.cpp b/lib/CodeGen/GCRootLowering.cpp index e2ee0c97f94..ead34be9ea2 100644 --- a/lib/CodeGen/GCRootLowering.cpp +++ b/lib/CodeGen/GCRootLowering.cpp @@ -105,9 +105,9 @@ void LowerIntrinsics::getAnalysisUsage(AnalysisUsage &AU) const { bool LowerIntrinsics::doInitialization(Module &M) { GCModuleInfo *MI = getAnalysisIfAvailable(); assert(MI && "LowerIntrinsics didn't require GCModuleInfo!?"); - for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) - if (!I->isDeclaration() && I->hasGC()) - MI->getFunctionInfo(*I); // Instantiate the GC strategy. + for (Function &F : M) + if (!F.isDeclaration() && F.hasGC()) + MI->getFunctionInfo(F); // Instantiate the GC strategy. return false; } diff --git a/lib/CodeGen/GlobalISel/CSEInfo.cpp b/lib/CodeGen/GlobalISel/CSEInfo.cpp index 2fa208fbfaa..3012a42d417 100644 --- a/lib/CodeGen/GlobalISel/CSEInfo.cpp +++ b/lib/CodeGen/GlobalISel/CSEInfo.cpp @@ -278,8 +278,7 @@ Error GISelCSEInfo::verify() { // For every node in the CSEMap, make sure that the InstrMapping // points to it. - for (auto It = CSEMap.begin(), End = CSEMap.end(); It != End; ++It) { - const UniqueMachineInstr &UMI = *It; + for (const UniqueMachineInstr &UMI : CSEMap) { if (!InstrMapping.count(UMI.MI)) return createStringError(std::errc::not_supported, "Node in CSE without InstrMapping", UMI.MI); diff --git a/lib/CodeGen/HardwareLoops.cpp b/lib/CodeGen/HardwareLoops.cpp index 810b10c9c82..61392186f7c 100644 --- a/lib/CodeGen/HardwareLoops.cpp +++ b/lib/CodeGen/HardwareLoops.cpp @@ -232,11 +232,9 @@ bool HardwareLoops::runOnFunction(Function &F) { AC = &getAnalysis().getAssumptionCache(F); M = F.getParent(); - for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I) { - Loop *L = *I; + for (Loop *L : *LI) if (L->isOutermost()) TryConvertLoop(L); - } return MadeChange; }