Skip to content

Commit 0b417ba

Browse files
[CodeGen] Use range-based for loops (NFC)
1 parent 9e4033b commit 0b417ba

File tree

8 files changed

+39
-49
lines changed

8 files changed

+39
-49
lines changed

llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,8 @@ LegalizeRuleSet &LegalizerInfo::getActionDefinitionsBuilder(
446446
assert(!llvm::empty(Opcodes) && Opcodes.begin() + 1 != Opcodes.end() &&
447447
"Initializer list must have at least two opcodes");
448448

449-
for (auto I = Opcodes.begin() + 1, E = Opcodes.end(); I != E; ++I)
450-
aliasActionDefinitions(Representative, *I);
449+
for (unsigned Op : llvm::drop_begin(Opcodes))
450+
aliasActionDefinitions(Representative, Op);
451451

452452
auto &Return = getActionDefinitionsBuilder(Representative);
453453
Return.setIsAliasedByAnother();

llvm/lib/CodeGen/GlobalISel/Localizer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ bool Localizer::localizeInterBlock(MachineFunction &MF,
8282
// we start doing CSE across blocks.
8383
auto &MBB = MF.front();
8484
auto &TL = *MF.getSubtarget().getTargetLowering();
85-
for (auto RI = MBB.rbegin(), RE = MBB.rend(); RI != RE; ++RI) {
86-
MachineInstr &MI = *RI;
85+
for (MachineInstr &MI : llvm::reverse(MBB)) {
8786
if (!TL.shouldLocalize(MI, TTI))
8887
continue;
8988
LLVM_DEBUG(dbgs() << "Should localize: " << MI);

llvm/lib/CodeGen/LiveVariables.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -774,13 +774,12 @@ void LiveVariables::addNewBlock(MachineBasicBlock *BB,
774774

775775
// Record all vreg defs and kills of all instructions in SuccBB.
776776
for (; BBI != BBE; ++BBI) {
777-
for (MachineInstr::mop_iterator I = BBI->operands_begin(),
778-
E = BBI->operands_end(); I != E; ++I) {
779-
if (I->isReg() && Register::isVirtualRegister(I->getReg())) {
780-
if (I->isDef())
781-
Defs.insert(I->getReg());
782-
else if (I->isKill())
783-
Kills.insert(I->getReg());
777+
for (const MachineOperand &Op : BBI->operands()) {
778+
if (Op.isReg() && Register::isVirtualRegister(Op.getReg())) {
779+
if (Op.isDef())
780+
Defs.insert(Op.getReg());
781+
else if (Op.isKill())
782+
Kills.insert(Op.getReg());
784783
}
785784
}
786785
}

llvm/lib/CodeGen/MachineRegisterInfo.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -531,13 +531,10 @@ bool MachineRegisterInfo::isConstantPhysReg(MCRegister PhysReg) const {
531531
/// deleted during LiveDebugVariables analysis.
532532
void MachineRegisterInfo::markUsesInDebugValueAsUndef(Register Reg) const {
533533
// Mark any DBG_VALUE that uses Reg as undef (but don't delete it.)
534-
MachineRegisterInfo::use_instr_iterator nextI;
535-
for (use_instr_iterator I = use_instr_begin(Reg), E = use_instr_end();
536-
I != E; I = nextI) {
537-
nextI = std::next(I); // I is invalidated by the setReg
538-
MachineInstr *UseMI = &*I;
539-
if (UseMI->isDebugValue())
540-
UseMI->getDebugOperandForReg(Reg)->setReg(0U);
534+
// We use make_early_inc_range because setReg invalidates the iterator.
535+
for (MachineInstr &UseMI : llvm::make_early_inc_range(use_instructions(Reg))) {
536+
if (UseMI.isDebugValue())
537+
UseMI.getDebugOperandForReg(Reg)->setReg(0U);
541538
}
542539
}
543540

llvm/lib/CodeGen/RDFLiveness.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ NodeList Liveness::getAllReachingDefs(RegisterRef RefRR,
238238
[this](auto A, auto B) { return MDT.properlyDominates(A, B); });
239239

240240
std::vector<NodeId> TmpInst;
241-
for (auto I = TmpBB.rbegin(), E = TmpBB.rend(); I != E; ++I) {
242-
auto &Bucket = Blocks[*I];
241+
for (MachineBasicBlock *MBB : llvm::reverse(TmpBB)) {
242+
auto &Bucket = Blocks[MBB];
243243
TmpInst.insert(TmpInst.end(), Bucket.rbegin(), Bucket.rend());
244244
}
245245

@@ -931,13 +931,12 @@ void Liveness::resetKills(MachineBasicBlock *B) {
931931
for (auto SI : B->successors())
932932
CopyLiveIns(SI, Live);
933933

934-
for (auto I = B->rbegin(), E = B->rend(); I != E; ++I) {
935-
MachineInstr *MI = &*I;
936-
if (MI->isDebugInstr())
934+
for (MachineInstr &MI : llvm::reverse(*B)) {
935+
if (MI.isDebugInstr())
937936
continue;
938937

939-
MI->clearKillInfo();
940-
for (auto &Op : MI->operands()) {
938+
MI.clearKillInfo();
939+
for (auto &Op : MI.operands()) {
941940
// An implicit def of a super-register may not necessarily start a
942941
// live range of it, since an implicit use could be used to keep parts
943942
// of it live. Instead of analyzing the implicit operands, ignore
@@ -950,7 +949,7 @@ void Liveness::resetKills(MachineBasicBlock *B) {
950949
for (MCSubRegIterator SR(R, &TRI, true); SR.isValid(); ++SR)
951950
Live.reset(*SR);
952951
}
953-
for (auto &Op : MI->operands()) {
952+
for (auto &Op : MI.operands()) {
954953
if (!Op.isReg() || !Op.isUse() || Op.isUndef())
955954
continue;
956955
Register R = Op.getReg();

llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -896,12 +896,10 @@ static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) {
896896
LLVM_DUMP_METHOD void SelectionDAG::dump() const {
897897
dbgs() << "SelectionDAG has " << AllNodes.size() << " nodes:\n";
898898

899-
for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end();
900-
I != E; ++I) {
901-
const SDNode *N = &*I;
902-
if (!N->hasOneUse() && N != getRoot().getNode() &&
903-
(!shouldPrintInline(*N, this) || N->use_empty()))
904-
DumpNodes(N, 2, this);
899+
for (const SDNode &N : allnodes()) {
900+
if (!N.hasOneUse() && &N != getRoot().getNode() &&
901+
(!shouldPrintInline(N, this) || N.use_empty()))
902+
DumpNodes(&N, 2, this);
905903
}
906904

907905
if (getRoot().getNode()) DumpNodes(getRoot().getNode(), 2, this);

llvm/lib/CodeGen/SplitKit.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ InsertPointAnalysis::computeLastInsertPoint(const LiveInterval &CurLI,
9494
// instructions in the block.
9595
if (ExceptionalSuccessors.empty())
9696
return LIP.first;
97-
for (auto I = MBB.rbegin(), E = MBB.rend(); I != E; ++I) {
98-
if ((EHPadSuccessor && I->isCall()) ||
99-
I->getOpcode() == TargetOpcode::INLINEASM_BR) {
100-
LIP.second = LIS.getInstructionIndex(*I);
97+
for (const MachineInstr &MI : llvm::reverse(MBB)) {
98+
if ((EHPadSuccessor && MI.isCall()) ||
99+
MI.getOpcode() == TargetOpcode::INLINEASM_BR) {
100+
LIP.second = LIS.getInstructionIndex(MI);
101101
break;
102102
}
103103
}
@@ -810,8 +810,8 @@ void SplitEditor::removeBackCopies(SmallVectorImpl<VNInfo*> &Copies) {
810810
RegAssignMap::iterator AssignI;
811811
AssignI.setMap(RegAssign);
812812

813-
for (unsigned i = 0, e = Copies.size(); i != e; ++i) {
814-
SlotIndex Def = Copies[i]->def;
813+
for (const VNInfo *C : Copies) {
814+
SlotIndex Def = C->def;
815815
MachineInstr *MI = LIS.getInstructionFromIndex(Def);
816816
assert(MI && "No instruction for back-copy");
817817

llvm/lib/CodeGen/UnreachableBlockElim.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,33 +114,31 @@ bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) {
114114
// Loop over all dead blocks, remembering them and deleting all instructions
115115
// in them.
116116
std::vector<MachineBasicBlock*> DeadBlocks;
117-
for (MachineFunction::iterator I = F.begin(), E = F.end(); I != E; ++I) {
118-
MachineBasicBlock *BB = &*I;
119-
117+
for (MachineBasicBlock &BB : F) {
120118
// Test for deadness.
121-
if (!Reachable.count(BB)) {
122-
DeadBlocks.push_back(BB);
119+
if (!Reachable.count(&BB)) {
120+
DeadBlocks.push_back(&BB);
123121

124122
// Update dominator and loop info.
125-
if (MLI) MLI->removeBlock(BB);
126-
if (MDT && MDT->getNode(BB)) MDT->eraseNode(BB);
123+
if (MLI) MLI->removeBlock(&BB);
124+
if (MDT && MDT->getNode(&BB)) MDT->eraseNode(&BB);
127125

128-
while (BB->succ_begin() != BB->succ_end()) {
129-
MachineBasicBlock* succ = *BB->succ_begin();
126+
while (BB.succ_begin() != BB.succ_end()) {
127+
MachineBasicBlock* succ = *BB.succ_begin();
130128

131129
MachineBasicBlock::iterator start = succ->begin();
132130
while (start != succ->end() && start->isPHI()) {
133131
for (unsigned i = start->getNumOperands() - 1; i >= 2; i-=2)
134132
if (start->getOperand(i).isMBB() &&
135-
start->getOperand(i).getMBB() == BB) {
133+
start->getOperand(i).getMBB() == &BB) {
136134
start->RemoveOperand(i);
137135
start->RemoveOperand(i-1);
138136
}
139137

140138
start++;
141139
}
142140

143-
BB->removeSuccessor(BB->succ_begin());
141+
BB.removeSuccessor(BB.succ_begin());
144142
}
145143
}
146144
}

0 commit comments

Comments
 (0)