From 66cd2e0f9a7ae3a966451d1868769947c72164d8 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sat, 13 Jul 2024 13:29:47 -0700 Subject: [PATCH] [CodeGen] Use range-based for loops (NFC) (#98706) --- llvm/lib/CodeGen/MachinePipeliner.cpp | 16 ++++++++-------- llvm/lib/CodeGen/RegAllocGreedy.cpp | 4 ++-- llvm/lib/CodeGen/SelectOptimize.cpp | 4 ++-- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 4 ++-- llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp | 4 ++-- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 4 +--- llvm/lib/CodeGen/StackSlotColoring.cpp | 13 +++++-------- 7 files changed, 22 insertions(+), 27 deletions(-) diff --git a/llvm/lib/CodeGen/MachinePipeliner.cpp b/llvm/lib/CodeGen/MachinePipeliner.cpp index 2488f81fee228a..497e282bb97682 100644 --- a/llvm/lib/CodeGen/MachinePipeliner.cpp +++ b/llvm/lib/CodeGen/MachinePipeliner.cpp @@ -999,8 +999,8 @@ void SwingSchedulerDAG::updatePhiDependences() { RemoveDeps.push_back(PI); } } - for (int i = 0, e = RemoveDeps.size(); i != e; ++i) - I.removePred(RemoveDeps[i]); + for (const SDep &D : RemoveDeps) + I.removePred(D); } } @@ -1041,18 +1041,18 @@ void SwingSchedulerDAG::changeDependences() { for (const SDep &P : I.Preds) if (P.getSUnit() == DefSU) Deps.push_back(P); - for (int i = 0, e = Deps.size(); i != e; i++) { - Topo.RemovePred(&I, Deps[i].getSUnit()); - I.removePred(Deps[i]); + for (const SDep &D : Deps) { + Topo.RemovePred(&I, D.getSUnit()); + I.removePred(D); } // Remove the chain dependence between the instructions. Deps.clear(); for (auto &P : LastSU->Preds) if (P.getSUnit() == &I && P.getKind() == SDep::Order) Deps.push_back(P); - for (int i = 0, e = Deps.size(); i != e; i++) { - Topo.RemovePred(LastSU, Deps[i].getSUnit()); - LastSU->removePred(Deps[i]); + for (const SDep &D : Deps) { + Topo.RemovePred(LastSU, D.getSUnit()); + LastSU->removePred(D); } // Add a dependence between the new instruction and the instruction diff --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp index 048b855058328b..310050d92d7443 100644 --- a/llvm/lib/CodeGen/RegAllocGreedy.cpp +++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp @@ -1664,8 +1664,8 @@ unsigned RAGreedy::tryLocalSplit(const LiveInterval &VirtReg, // Remove any gaps with regmask clobbers. if (Matrix->checkRegMaskInterference(VirtReg, PhysReg)) - for (unsigned I = 0, E = RegMaskGaps.size(); I != E; ++I) - GapWeight[RegMaskGaps[I]] = huge_valf; + for (unsigned Gap : RegMaskGaps) + GapWeight[Gap] = huge_valf; // Try to find the best sequence of gaps to close. // The new spill weight must be larger than any gap interference. diff --git a/llvm/lib/CodeGen/SelectOptimize.cpp b/llvm/lib/CodeGen/SelectOptimize.cpp index 0a5f0a861d48ba..61341e1f2d04ce 100644 --- a/llvm/lib/CodeGen/SelectOptimize.cpp +++ b/llvm/lib/CodeGen/SelectOptimize.cpp @@ -1071,8 +1071,8 @@ void SelectOptimizeImpl::getExclBackwardsSlice(Instruction *I, Slice.push(II); // Explore all the operands of the current instruction to expand the slice. - for (unsigned k = 0; k < II->getNumOperands(); ++k) - if (auto *OpI = dyn_cast(II->getOperand(k))) + for (Value *Op : II->operand_values()) + if (auto *OpI = dyn_cast(Op)) Worklist.push(OpI); } } diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 428cdda21cd41d..cece76f6583077 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -20544,8 +20544,8 @@ bool DAGCombiner::checkMergeStoreCandidatesForDependencies( // * (Op 3) -> Represents the pre or post-indexing offset (or undef for // non-indexed stores). Not constant on all targets (e.g. ARM) // and so can participate in a cycle. - for (unsigned j = 0; j < N->getNumOperands(); ++j) - Worklist.push_back(N->getOperand(j).getNode()); + for (const SDValue &Op : N->op_values()) + Worklist.push_back(Op.getNode()); } // Search through DAG. We can stop early if we find a store node. for (unsigned i = 0; i < NumStores; ++i) diff --git a/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp b/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp index 36738961382ef5..4ce92e156cf85e 100644 --- a/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp @@ -1182,8 +1182,8 @@ EmitMachineNode(SDNode *Node, bool IsClone, bool IsCloned, append_range(UsedRegs, MCID.implicit_uses()); // In addition to declared implicit uses, we must also check for // direct RegisterSDNode operands. - for (unsigned i = 0, e = F->getNumOperands(); i != e; ++i) - if (RegisterSDNode *R = dyn_cast(F->getOperand(i))) { + for (const SDValue &Op : F->op_values()) + if (RegisterSDNode *R = dyn_cast(Op)) { Register Reg = R->getReg(); if (Reg.isPhysical()) UsedRegs.push_back(Reg); diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index 1be93276b69613..9f515739ee0481 100644 --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -5608,10 +5608,8 @@ void SelectionDAGLegalize::PromoteNode(SDNode *Node) { MVT MidVT = getPromotedVectorElementType(TLI, EltVT, NewEltVT); SmallVector NewOps; - for (unsigned I = 0, E = Node->getNumOperands(); I != E; ++I) { - SDValue Op = Node->getOperand(I); + for (const SDValue &Op : Node->op_values()) NewOps.push_back(DAG.getNode(ISD::BITCAST, SDLoc(Op), MidVT, Op)); - } SDLoc SL(Node); SDValue Concat = diff --git a/llvm/lib/CodeGen/StackSlotColoring.cpp b/llvm/lib/CodeGen/StackSlotColoring.cpp index 638ae51bc73340..df06577e14e77d 100644 --- a/llvm/lib/CodeGen/StackSlotColoring.cpp +++ b/llvm/lib/CodeGen/StackSlotColoring.cpp @@ -224,13 +224,10 @@ void StackSlotColoring::ScanForSpillSlotRefs(MachineFunction &MF) { li.incrementWeight( LiveIntervals::getSpillWeight(false, true, MBFI, MI)); } - for (MachineInstr::mmo_iterator MMOI = MI.memoperands_begin(), - EE = MI.memoperands_end(); - MMOI != EE; ++MMOI) { - MachineMemOperand *MMO = *MMOI; + for (MachineMemOperand *MMO : MI.memoperands()) { if (const FixedStackPseudoSourceValue *FSV = - dyn_cast_or_null( - MMO->getPseudoValue())) { + dyn_cast_or_null( + MMO->getPseudoValue())) { int FI = FSV->getFrameIndex(); if (FI >= 0) SSRefs[FI].push_back(MMO); @@ -552,8 +549,8 @@ bool StackSlotColoring::runOnMachineFunction(MachineFunction &MF) { Next = -1; SSIntervals.clear(); - for (unsigned i = 0, e = SSRefs.size(); i != e; ++i) - SSRefs[i].clear(); + for (auto &RefMMOs : SSRefs) + RefMMOs.clear(); SSRefs.clear(); OrigAlignments.clear(); OrigSizes.clear();