Skip to content

Commit d5adba1

Browse files
[CodeGen] Use range-based for loops (NFC)
1 parent dfa3ead commit d5adba1

9 files changed

+34
-48
lines changed

llvm/lib/CodeGen/EarlyIfConversion.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,8 @@ bool SSAIfConv::findInsertionPoint() {
410410
if (!LiveRegUnits.empty()) {
411411
LLVM_DEBUG({
412412
dbgs() << "Would clobber";
413-
for (SparseSet<unsigned>::const_iterator
414-
i = LiveRegUnits.begin(), e = LiveRegUnits.end(); i != e; ++i)
415-
dbgs() << ' ' << printRegUnit(*i, TRI);
413+
for (unsigned LRU : LiveRegUnits)
414+
dbgs() << ' ' << printRegUnit(LRU, TRI);
416415
dbgs() << " live before " << *I;
417416
});
418417
continue;

llvm/lib/CodeGen/LatencyPriorityQueue.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ bool latency_sort::operator()(const SUnit *LHS, const SUnit *RHS) const {
5555
/// of SU, return it, otherwise return null.
5656
SUnit *LatencyPriorityQueue::getSingleUnscheduledPred(SUnit *SU) {
5757
SUnit *OnlyAvailablePred = nullptr;
58-
for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
59-
I != E; ++I) {
60-
SUnit &Pred = *I->getSUnit();
58+
for (const SDep &P : SU->Preds) {
59+
SUnit &Pred = *P.getSUnit();
6160
if (!Pred.isScheduled) {
6261
// We found an available, but not scheduled, predecessor. If it's the
6362
// only one we have found, keep track of it... otherwise give up.
@@ -90,10 +89,8 @@ void LatencyPriorityQueue::push(SUnit *SU) {
9089
// single predecessor has a higher priority, since scheduling it will make
9190
// the node available.
9291
void LatencyPriorityQueue::scheduledNode(SUnit *SU) {
93-
for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
94-
I != E; ++I) {
95-
AdjustPriorityOfUnscheduledPreds(I->getSUnit());
96-
}
92+
for (const SDep &Succ : SU->Succs)
93+
AdjustPriorityOfUnscheduledPreds(Succ.getSUnit());
9794
}
9895

9996
/// AdjustPriorityOfUnscheduledPreds - One of the predecessors of SU was just

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3199,10 +3199,10 @@ void InstrRefBasedLDV::initialSetup(MachineFunction &MF) {
31993199
// Compute mappings of block <=> RPO order.
32003200
ReversePostOrderTraversal<MachineFunction *> RPOT(&MF);
32013201
unsigned int RPONumber = 0;
3202-
for (auto RI = RPOT.begin(), RE = RPOT.end(); RI != RE; ++RI) {
3203-
OrderToBB[RPONumber] = *RI;
3204-
BBToOrder[*RI] = RPONumber;
3205-
BBNumToRPO[(*RI)->getNumber()] = RPONumber;
3202+
for (MachineBasicBlock *MBB : RPOT) {
3203+
OrderToBB[RPONumber] = MBB;
3204+
BBToOrder[MBB] = RPONumber;
3205+
BBNumToRPO[MBB->getNumber()] = RPONumber;
32063206
++RPONumber;
32073207
}
32083208
}

llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,9 +1895,9 @@ bool VarLocBasedLDV::ExtendRanges(MachineFunction &MF, TargetPassConfig *TPC) {
18951895

18961896
ReversePostOrderTraversal<MachineFunction *> RPOT(&MF);
18971897
unsigned int RPONumber = 0;
1898-
for (auto RI = RPOT.begin(), RE = RPOT.end(); RI != RE; ++RI) {
1899-
OrderToBB[RPONumber] = *RI;
1900-
BBToOrder[*RI] = RPONumber;
1898+
for (MachineBasicBlock *MBB : RPOT) {
1899+
OrderToBB[RPONumber] = MBB;
1900+
BBToOrder[MBB] = RPONumber;
19011901
Worklist.push(RPONumber);
19021902
++RPONumber;
19031903
}

llvm/lib/CodeGen/LiveDebugVariables.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -732,10 +732,8 @@ bool LDVImpl::handleDebugLabel(MachineInstr &MI, SlotIndex Idx) {
732732

733733
bool LDVImpl::collectDebugValues(MachineFunction &mf) {
734734
bool Changed = false;
735-
for (MachineFunction::iterator MFI = mf.begin(), MFE = mf.end(); MFI != MFE;
736-
++MFI) {
737-
MachineBasicBlock *MBB = &*MFI;
738-
for (MachineBasicBlock::iterator MBBI = MBB->begin(), MBBE = MBB->end();
735+
for (MachineBasicBlock &MBB : mf) {
736+
for (MachineBasicBlock::iterator MBBI = MBB.begin(), MBBE = MBB.end();
739737
MBBI != MBBE;) {
740738
// Use the first debug instruction in the sequence to get a SlotIndex
741739
// for following consecutive debug instructions.
@@ -746,8 +744,8 @@ bool LDVImpl::collectDebugValues(MachineFunction &mf) {
746744
// Debug instructions has no slot index. Use the previous
747745
// non-debug instruction's SlotIndex as its SlotIndex.
748746
SlotIndex Idx =
749-
MBBI == MBB->begin()
750-
? LIS->getMBBStartIdx(MBB)
747+
MBBI == MBB.begin()
748+
? LIS->getMBBStartIdx(&MBB)
751749
: LIS->getInstructionIndex(*std::prev(MBBI)).getRegSlot();
752750
// Handle consecutive debug instructions with the same slot index.
753751
do {
@@ -756,7 +754,7 @@ bool LDVImpl::collectDebugValues(MachineFunction &mf) {
756754
if ((MBBI->isDebugValue() && handleDebugValue(*MBBI, Idx)) ||
757755
(MBBI->isDebugRef() && handleDebugInstrRef(*MBBI, Idx)) ||
758756
(MBBI->isDebugLabel() && handleDebugLabel(*MBBI, Idx))) {
759-
MBBI = MBB->erase(MBBI);
757+
MBBI = MBB.erase(MBBI);
760758
Changed = true;
761759
} else
762760
++MBBI;

llvm/lib/CodeGen/LiveInterval.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,9 +1336,8 @@ unsigned ConnectedVNInfoEqClasses::Classify(const LiveRange &LR) {
13361336
const MachineBasicBlock *MBB = LIS.getMBBFromIndex(VNI->def);
13371337
assert(MBB && "Phi-def has no defining MBB");
13381338
// Connect to values live out of predecessors.
1339-
for (MachineBasicBlock::const_pred_iterator PI = MBB->pred_begin(),
1340-
PE = MBB->pred_end(); PI != PE; ++PI)
1341-
if (const VNInfo *PVNI = LR.getVNInfoBefore(LIS.getMBBEndIdx(*PI)))
1339+
for (MachineBasicBlock *Pred : MBB->predecessors())
1340+
if (const VNInfo *PVNI = LR.getVNInfoBefore(LIS.getMBBEndIdx(Pred)))
13421341
EqClass.join(VNI->id, PVNI->id);
13431342
} else {
13441343
// Normal value defined by an instruction. Check for two-addr redef.

llvm/lib/CodeGen/LivePhysRegs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ void LivePhysRegs::print(raw_ostream &OS) const {
125125
return;
126126
}
127127

128-
for (const_iterator I = begin(), E = end(); I != E; ++I)
129-
OS << " " << printReg(*I, TRI);
128+
for (MCPhysReg R : *this)
129+
OS << " " << printReg(R, TRI);
130130
OS << "\n";
131131
}
132132

llvm/lib/CodeGen/LiveVariables.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ LiveVariables::VarInfo::findKill(const MachineBasicBlock *MBB) const {
6767
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
6868
LLVM_DUMP_METHOD void LiveVariables::VarInfo::dump() const {
6969
dbgs() << " Alive in blocks: ";
70-
for (SparseBitVector<>::iterator I = AliveBlocks.begin(),
71-
E = AliveBlocks.end(); I != E; ++I)
72-
dbgs() << *I << ", ";
70+
for (unsigned AB : AliveBlocks)
71+
dbgs() << AB << ", ";
7372
dbgs() << "\n Killed by:";
7473
if (Kills.empty())
7574
dbgs() << " No instructions.\n";
@@ -173,9 +172,8 @@ void LiveVariables::HandleVirtRegUse(Register Reg, MachineBasicBlock *MBB,
173172
VRInfo.Kills.push_back(&MI);
174173

175174
// Update all dominating blocks to mark them as "known live".
176-
for (MachineBasicBlock::const_pred_iterator PI = MBB->pred_begin(),
177-
E = MBB->pred_end(); PI != E; ++PI)
178-
MarkVirtRegAliveInBlock(VRInfo, MRI->getVRegDef(Reg)->getParent(), *PI);
175+
for (MachineBasicBlock *Pred : MBB->predecessors())
176+
MarkVirtRegAliveInBlock(VRInfo, MRI->getVRegDef(Reg)->getParent(), Pred);
179177
}
180178

181179
void LiveVariables::HandleVirtRegDef(Register Reg, MachineInstr &MI) {
@@ -588,19 +586,16 @@ void LiveVariables::runOnBlock(MachineBasicBlock *MBB, const unsigned NumRegs) {
588586
if (!PHIVarInfo[MBB->getNumber()].empty()) {
589587
SmallVectorImpl<unsigned> &VarInfoVec = PHIVarInfo[MBB->getNumber()];
590588

591-
for (SmallVectorImpl<unsigned>::iterator I = VarInfoVec.begin(),
592-
E = VarInfoVec.end(); I != E; ++I)
589+
for (unsigned I : VarInfoVec)
593590
// Mark it alive only in the block we are representing.
594-
MarkVirtRegAliveInBlock(getVarInfo(*I),MRI->getVRegDef(*I)->getParent(),
591+
MarkVirtRegAliveInBlock(getVarInfo(I), MRI->getVRegDef(I)->getParent(),
595592
MBB);
596593
}
597594

598595
// MachineCSE may CSE instructions which write to non-allocatable physical
599596
// registers across MBBs. Remember if any reserved register is liveout.
600597
SmallSet<unsigned, 4> LiveOuts;
601-
for (MachineBasicBlock::const_succ_iterator SI = MBB->succ_begin(),
602-
SE = MBB->succ_end(); SI != SE; ++SI) {
603-
MachineBasicBlock *SuccMBB = *SI;
598+
for (const MachineBasicBlock *SuccMBB : MBB->successors()) {
604599
if (SuccMBB->isEHPad())
605600
continue;
606601
for (const auto &LI : SuccMBB->liveins()) {
@@ -665,8 +660,8 @@ bool LiveVariables::runOnMachineFunction(MachineFunction &mf) {
665660
// function. If so, it is due to a bug in the instruction selector or some
666661
// other part of the code generator if this happens.
667662
#ifndef NDEBUG
668-
for(MachineFunction::iterator i = MF->begin(), e = MF->end(); i != e; ++i)
669-
assert(Visited.contains(&*i) && "unreachable basic block found");
663+
for (const MachineBasicBlock &MBB : *MF)
664+
assert(Visited.contains(&MBB) && "unreachable basic block found");
670665
#endif
671666

672667
PhysRegDef.clear();
@@ -817,8 +812,8 @@ void LiveVariables::addNewBlock(MachineBasicBlock *BB,
817812
const unsigned NumNew = BB->getNumber();
818813

819814
SparseBitVector<> &BV = LiveInSets[SuccBB->getNumber()];
820-
for (auto R = BV.begin(), E = BV.end(); R != E; R++) {
821-
Register VirtReg = Register::index2VirtReg(*R);
815+
for (unsigned R : BV) {
816+
Register VirtReg = Register::index2VirtReg(R);
822817
LiveVariables::VarInfo &VI = getVarInfo(VirtReg);
823818
VI.AliveBlocks.set(NumNew);
824819
}

llvm/lib/CodeGen/LocalStackSlotAllocation.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,7 @@ void LocalStackSlotPass::AssignProtectedObjSet(
176176
const StackObjSet &UnassignedObjs, SmallSet<int, 16> &ProtectedObjs,
177177
MachineFrameInfo &MFI, bool StackGrowsDown, int64_t &Offset,
178178
Align &MaxAlign) {
179-
for (StackObjSet::const_iterator I = UnassignedObjs.begin(),
180-
E = UnassignedObjs.end(); I != E; ++I) {
181-
int i = *I;
179+
for (int i : UnassignedObjs) {
182180
AdjustStackOffset(MFI, i, Offset, StackGrowsDown, MaxAlign);
183181
ProtectedObjs.insert(i);
184182
}

0 commit comments

Comments
 (0)