Skip to content

Commit ed10819

Browse files
kazutakahirataAlexisPerry
authored andcommitted
[CodeGen] Use range-based for loops (NFC) (llvm#96855)
1 parent da5a3b9 commit ed10819

File tree

6 files changed

+24
-29
lines changed

6 files changed

+24
-29
lines changed

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3082,9 +3082,9 @@ void CombinerHelper::applyCombineInsertVecElts(
30823082
UndefReg = Builder.buildUndef(DstTy.getScalarType()).getReg(0);
30833083
return UndefReg;
30843084
};
3085-
for (unsigned I = 0; I < MatchInfo.size(); ++I) {
3086-
if (!MatchInfo[I])
3087-
MatchInfo[I] = GetUndef();
3085+
for (Register &Reg : MatchInfo) {
3086+
if (!Reg)
3087+
Reg = GetUndef();
30883088
}
30893089
Builder.buildBuildVector(MI.getOperand(0).getReg(), MatchInfo);
30903090
MI.eraseFromParent();

llvm/lib/CodeGen/MachineInstrBundle.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,26 +177,25 @@ void llvm::finalizeBundle(MachineBasicBlock &MBB,
177177
}
178178
}
179179

180-
for (unsigned i = 0, e = Defs.size(); i != e; ++i) {
181-
MachineOperand &MO = *Defs[i];
182-
Register Reg = MO.getReg();
180+
for (MachineOperand *MO : Defs) {
181+
Register Reg = MO->getReg();
183182
if (!Reg)
184183
continue;
185184

186185
if (LocalDefSet.insert(Reg).second) {
187186
LocalDefs.push_back(Reg);
188-
if (MO.isDead()) {
187+
if (MO->isDead()) {
189188
DeadDefSet.insert(Reg);
190189
}
191190
} else {
192191
// Re-defined inside the bundle, it's no longer killed.
193192
KilledDefSet.erase(Reg);
194-
if (!MO.isDead())
193+
if (!MO->isDead())
195194
// Previously defined but dead.
196195
DeadDefSet.erase(Reg);
197196
}
198197

199-
if (!MO.isDead() && Reg.isPhysical()) {
198+
if (!MO->isDead() && Reg.isPhysical()) {
200199
for (MCPhysReg SubReg : TRI->subregs(Reg)) {
201200
if (LocalDefSet.insert(SubReg).second)
202201
LocalDefs.push_back(SubReg);

llvm/lib/CodeGen/MachineTraceMetrics.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -939,15 +939,15 @@ static unsigned updatePhysDepsUpwards(const MachineInstr &MI, unsigned Height,
939939
}
940940

941941
// Now we know the height of MI. Update any regunits read.
942-
for (size_t I = 0, E = ReadOps.size(); I != E; ++I) {
943-
MCRegister Reg = MI.getOperand(ReadOps[I]).getReg().asMCReg();
942+
for (unsigned Op : ReadOps) {
943+
MCRegister Reg = MI.getOperand(Op).getReg().asMCReg();
944944
for (MCRegUnit Unit : TRI->regunits(Reg)) {
945945
LiveRegUnit &LRU = RegUnits[Unit];
946946
// Set the height to the highest reader of the unit.
947947
if (LRU.Cycle <= Height && LRU.MI != &MI) {
948948
LRU.Cycle = Height;
949949
LRU.MI = &MI;
950-
LRU.Op = ReadOps[I];
950+
LRU.Op = Op;
951951
}
952952
}
953953
}

llvm/lib/CodeGen/RegAllocBasic.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,17 @@ bool RABasic::spillInterferences(const LiveInterval &VirtReg,
226226
assert(!Intfs.empty() && "expected interference");
227227

228228
// Spill each interfering vreg allocated to PhysReg or an alias.
229-
for (unsigned i = 0, e = Intfs.size(); i != e; ++i) {
230-
const LiveInterval &Spill = *Intfs[i];
231-
229+
for (const LiveInterval *Spill : Intfs) {
232230
// Skip duplicates.
233-
if (!VRM->hasPhys(Spill.reg()))
231+
if (!VRM->hasPhys(Spill->reg()))
234232
continue;
235233

236234
// Deallocate the interfering vreg by removing it from the union.
237235
// A LiveInterval instance may not be in a union during modification!
238-
Matrix->unassign(Spill);
236+
Matrix->unassign(*Spill);
239237

240238
// Spill the extracted interval.
241-
LiveRangeEdit LRE(&Spill, SplitVRegs, *MF, *LIS, VRM, this, &DeadRemats);
239+
LiveRangeEdit LRE(Spill, SplitVRegs, *MF, *LIS, VRM, this, &DeadRemats);
242240
spiller().spill(LRE);
243241
}
244242
return true;

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,13 +1455,12 @@ void SelectionDAGISel::reportIPToStateForBlocks(MachineFunction *MF) {
14551455
llvm::WinEHFuncInfo *EHInfo = MF->getWinEHFuncInfo();
14561456
if (!EHInfo)
14571457
return;
1458-
for (auto MBBI = MF->begin(), E = MF->end(); MBBI != E; ++MBBI) {
1459-
MachineBasicBlock *MBB = &*MBBI;
1460-
const BasicBlock *BB = MBB->getBasicBlock();
1458+
for (MachineBasicBlock &MBB : *MF) {
1459+
const BasicBlock *BB = MBB.getBasicBlock();
14611460
int State = EHInfo->BlockToStateMap[BB];
14621461
if (BB->getFirstMayFaultInst()) {
14631462
// Report IP range only for blocks with Faulty inst
1464-
auto MBBb = MBB->getFirstNonPHI();
1463+
auto MBBb = MBB.getFirstNonPHI();
14651464
MachineInstr *MIb = &*MBBb;
14661465
if (MIb->isTerminator())
14671466
continue;
@@ -1470,16 +1469,16 @@ void SelectionDAGISel::reportIPToStateForBlocks(MachineFunction *MF) {
14701469
MCSymbol *BeginLabel = MMI.getContext().createTempSymbol();
14711470
MCSymbol *EndLabel = MMI.getContext().createTempSymbol();
14721471
EHInfo->addIPToStateRange(State, BeginLabel, EndLabel);
1473-
BuildMI(*MBB, MBBb, SDB->getCurDebugLoc(),
1472+
BuildMI(MBB, MBBb, SDB->getCurDebugLoc(),
14741473
TII->get(TargetOpcode::EH_LABEL))
14751474
.addSym(BeginLabel);
1476-
auto MBBe = MBB->instr_end();
1475+
auto MBBe = MBB.instr_end();
14771476
MachineInstr *MIe = &*(--MBBe);
14781477
// insert before (possible multiple) terminators
14791478
while (MIe->isTerminator())
14801479
MIe = &*(--MBBe);
14811480
++MBBe;
1482-
BuildMI(*MBB, MBBe, SDB->getCurDebugLoc(),
1481+
BuildMI(MBB, MBBe, SDB->getCurDebugLoc(),
14831482
TII->get(TargetOpcode::EH_LABEL))
14841483
.addSym(EndLabel);
14851484
}
@@ -2125,8 +2124,8 @@ SelectionDAGISel::FinishBasicBlock() {
21252124
// from the original BB before switch expansion. Note that PHI nodes can
21262125
// occur multiple times in PHINodesToUpdate. We have to be very careful to
21272126
// handle them the right number of times.
2128-
for (unsigned i = 0, e = Succs.size(); i != e; ++i) {
2129-
FuncInfo->MBB = Succs[i];
2127+
for (MachineBasicBlock *Succ : Succs) {
2128+
FuncInfo->MBB = Succ;
21302129
FuncInfo->InsertPt = FuncInfo->MBB->end();
21312130
// FuncInfo->MBB may have been removed from the CFG if a branch was
21322131
// constant folded.

llvm/lib/CodeGen/TailDuplicator.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ bool TailDuplicator::tailDuplicateAndUpdate(
201201

202202
// Update SSA form.
203203
if (!SSAUpdateVRs.empty()) {
204-
for (unsigned i = 0, e = SSAUpdateVRs.size(); i != e; ++i) {
205-
unsigned VReg = SSAUpdateVRs[i];
204+
for (unsigned VReg : SSAUpdateVRs) {
206205
SSAUpdate.Initialize(VReg);
207206

208207
// If the original definition is still around, add it as an available

0 commit comments

Comments
 (0)