Skip to content

Commit 3279943

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

File tree

2 files changed

+52
-74
lines changed

2 files changed

+52
-74
lines changed

llvm/lib/CodeGen/MachinePipeliner.cpp

Lines changed: 44 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -949,10 +949,9 @@ void SwingSchedulerDAG::changeDependences() {
949949

950950
// Remove the dependence. The value now depends on a prior iteration.
951951
SmallVector<SDep, 4> Deps;
952-
for (SUnit::pred_iterator P = I.Preds.begin(), E = I.Preds.end(); P != E;
953-
++P)
954-
if (P->getSUnit() == DefSU)
955-
Deps.push_back(*P);
952+
for (const SDep &P : I.Preds)
953+
if (P.getSUnit() == DefSU)
954+
Deps.push_back(P);
956955
for (int i = 0, e = Deps.size(); i != e; i++) {
957956
Topo.RemovePred(&I, Deps[i].getSUnit());
958957
I.removePred(Deps[i]);
@@ -1203,12 +1202,10 @@ static void swapAntiDependences(std::vector<SUnit> &SUnits) {
12031202
DepsAdded.push_back(std::make_pair(SU, *IP));
12041203
}
12051204
}
1206-
for (SmallVector<std::pair<SUnit *, SDep>, 8>::iterator I = DepsAdded.begin(),
1207-
E = DepsAdded.end();
1208-
I != E; ++I) {
1205+
for (std::pair<SUnit *, SDep> &P : DepsAdded) {
12091206
// Remove this anti dependency and add one in the reverse direction.
1210-
SUnit *SU = I->first;
1211-
SDep &D = I->second;
1207+
SUnit *SU = P.first;
1208+
SDep &D = P.second;
12121209
SUnit *TargetSU = D.getSUnit();
12131210
unsigned Reg = D.getReg();
12141211
unsigned Lat = D.getLatency();
@@ -1447,22 +1444,18 @@ void SwingSchedulerDAG::computeNodeFunctions(NodeSetType &NodeSets) {
14471444
ScheduleInfo.resize(SUnits.size());
14481445

14491446
LLVM_DEBUG({
1450-
for (ScheduleDAGTopologicalSort::const_iterator I = Topo.begin(),
1451-
E = Topo.end();
1452-
I != E; ++I) {
1453-
const SUnit &SU = SUnits[*I];
1447+
for (int I : Topo) {
1448+
const SUnit &SU = SUnits[I];
14541449
dumpNode(SU);
14551450
}
14561451
});
14571452

14581453
int maxASAP = 0;
14591454
// Compute ASAP and ZeroLatencyDepth.
1460-
for (ScheduleDAGTopologicalSort::const_iterator I = Topo.begin(),
1461-
E = Topo.end();
1462-
I != E; ++I) {
1455+
for (int I : Topo) {
14631456
int asap = 0;
14641457
int zeroLatencyDepth = 0;
1465-
SUnit *SU = &SUnits[*I];
1458+
SUnit *SU = &SUnits[I];
14661459
for (SUnit::const_pred_iterator IP = SU->Preds.begin(),
14671460
EP = SU->Preds.end();
14681461
IP != EP; ++IP) {
@@ -1476,8 +1469,8 @@ void SwingSchedulerDAG::computeNodeFunctions(NodeSetType &NodeSets) {
14761469
getDistance(pred, SU, *IP) * MII));
14771470
}
14781471
maxASAP = std::max(maxASAP, asap);
1479-
ScheduleInfo[*I].ASAP = asap;
1480-
ScheduleInfo[*I].ZeroLatencyDepth = zeroLatencyDepth;
1472+
ScheduleInfo[I].ASAP = asap;
1473+
ScheduleInfo[I].ZeroLatencyDepth = zeroLatencyDepth;
14811474
}
14821475

14831476
// Compute ALAP, ZeroLatencyHeight, and MOV.
@@ -1531,25 +1524,22 @@ static bool pred_L(SetVector<SUnit *> &NodeOrder,
15311524
Preds.clear();
15321525
for (SetVector<SUnit *>::iterator I = NodeOrder.begin(), E = NodeOrder.end();
15331526
I != E; ++I) {
1534-
for (SUnit::pred_iterator PI = (*I)->Preds.begin(), PE = (*I)->Preds.end();
1535-
PI != PE; ++PI) {
1536-
if (S && S->count(PI->getSUnit()) == 0)
1527+
for (const SDep &Pred : (*I)->Preds) {
1528+
if (S && S->count(Pred.getSUnit()) == 0)
15371529
continue;
1538-
if (ignoreDependence(*PI, true))
1530+
if (ignoreDependence(Pred, true))
15391531
continue;
1540-
if (NodeOrder.count(PI->getSUnit()) == 0)
1541-
Preds.insert(PI->getSUnit());
1532+
if (NodeOrder.count(Pred.getSUnit()) == 0)
1533+
Preds.insert(Pred.getSUnit());
15421534
}
15431535
// Back-edges are predecessors with an anti-dependence.
1544-
for (SUnit::const_succ_iterator IS = (*I)->Succs.begin(),
1545-
ES = (*I)->Succs.end();
1546-
IS != ES; ++IS) {
1547-
if (IS->getKind() != SDep::Anti)
1536+
for (const SDep &Succ : (*I)->Succs) {
1537+
if (Succ.getKind() != SDep::Anti)
15481538
continue;
1549-
if (S && S->count(IS->getSUnit()) == 0)
1539+
if (S && S->count(Succ.getSUnit()) == 0)
15501540
continue;
1551-
if (NodeOrder.count(IS->getSUnit()) == 0)
1552-
Preds.insert(IS->getSUnit());
1541+
if (NodeOrder.count(Succ.getSUnit()) == 0)
1542+
Preds.insert(Succ.getSUnit());
15531543
}
15541544
}
15551545
return !Preds.empty();
@@ -1564,24 +1554,21 @@ static bool succ_L(SetVector<SUnit *> &NodeOrder,
15641554
Succs.clear();
15651555
for (SetVector<SUnit *>::iterator I = NodeOrder.begin(), E = NodeOrder.end();
15661556
I != E; ++I) {
1567-
for (SUnit::succ_iterator SI = (*I)->Succs.begin(), SE = (*I)->Succs.end();
1568-
SI != SE; ++SI) {
1569-
if (S && S->count(SI->getSUnit()) == 0)
1557+
for (SDep &Succ : (*I)->Succs) {
1558+
if (S && S->count(Succ.getSUnit()) == 0)
15701559
continue;
1571-
if (ignoreDependence(*SI, false))
1560+
if (ignoreDependence(Succ, false))
15721561
continue;
1573-
if (NodeOrder.count(SI->getSUnit()) == 0)
1574-
Succs.insert(SI->getSUnit());
1562+
if (NodeOrder.count(Succ.getSUnit()) == 0)
1563+
Succs.insert(Succ.getSUnit());
15751564
}
1576-
for (SUnit::const_pred_iterator PI = (*I)->Preds.begin(),
1577-
PE = (*I)->Preds.end();
1578-
PI != PE; ++PI) {
1579-
if (PI->getKind() != SDep::Anti)
1565+
for (SDep &Pred : (*I)->Preds) {
1566+
if (Pred.getKind() != SDep::Anti)
15801567
continue;
1581-
if (S && S->count(PI->getSUnit()) == 0)
1568+
if (S && S->count(Pred.getSUnit()) == 0)
15821569
continue;
1583-
if (NodeOrder.count(PI->getSUnit()) == 0)
1584-
Succs.insert(PI->getSUnit());
1570+
if (NodeOrder.count(Pred.getSUnit()) == 0)
1571+
Succs.insert(Pred.getSUnit());
15851572
}
15861573
}
15871574
return !Succs.empty();
@@ -1807,11 +1794,10 @@ void SwingSchedulerDAG::groupRemainingNodes(NodeSetType &NodeSets) {
18071794

18081795
// Create new nodes sets with the connected nodes any remaining node that
18091796
// has no predecessor.
1810-
for (unsigned i = 0; i < SUnits.size(); ++i) {
1811-
SUnit *SU = &SUnits[i];
1812-
if (NodesAdded.count(SU) == 0) {
1797+
for (SUnit &SU : SUnits) {
1798+
if (NodesAdded.count(&SU) == 0) {
18131799
NewSet.clear();
1814-
addConnectedNodes(SU, NewSet, NodesAdded);
1800+
addConnectedNodes(&SU, NewSet, NodesAdded);
18151801
if (!NewSet.empty())
18161802
NodeSets.push_back(NewSet);
18171803
}
@@ -1858,9 +1844,8 @@ void SwingSchedulerDAG::fuseRecs(NodeSetType &NodeSets) {
18581844
if (NI.getNode(0)->NodeNum == NJ.getNode(0)->NodeNum) {
18591845
if (NJ.compareRecMII(NI) > 0)
18601846
NI.setRecMII(NJ.getRecMII());
1861-
for (NodeSet::iterator NII = J->begin(), ENI = J->end(); NII != ENI;
1862-
++NII)
1863-
I->insert(*NII);
1847+
for (SUnit *SU : *J)
1848+
I->insert(SU);
18641849
NodeSets.erase(J);
18651850
E = NodeSets.end();
18661851
} else {
@@ -2404,14 +2389,12 @@ bool SMSchedule::insert(SUnit *SU, int StartCycle, int EndCycle, int II) {
24042389
checkCycle <= LastCycle; checkCycle += II) {
24052390
std::deque<SUnit *> &cycleInstrs = ScheduledInstrs[checkCycle];
24062391

2407-
for (std::deque<SUnit *>::iterator I = cycleInstrs.begin(),
2408-
E = cycleInstrs.end();
2409-
I != E; ++I) {
2410-
if (ST.getInstrInfo()->isZeroCost((*I)->getInstr()->getOpcode()))
2392+
for (SUnit *CI : cycleInstrs) {
2393+
if (ST.getInstrInfo()->isZeroCost(CI->getInstr()->getOpcode()))
24112394
continue;
2412-
assert(ProcItinResources.canReserveResources(*(*I)->getInstr()) &&
2395+
assert(ProcItinResources.canReserveResources(*CI->getInstr()) &&
24132396
"These instructions have already been scheduled.");
2414-
ProcItinResources.reserveResources(*(*I)->getInstr());
2397+
ProcItinResources.reserveResources(*CI->getInstr());
24152398
}
24162399
}
24172400
if (ST.getInstrInfo()->isZeroCost(SU->getInstr()->getOpcode()) ||
@@ -2742,8 +2725,7 @@ bool SMSchedule::isLoopCarriedDefOfUse(SwingSchedulerDAG *SSD,
27422725
// different stage than the definition. The pipeliner does not handle
27432726
// physical register values that may cross a basic block boundary.
27442727
bool SMSchedule::isValidSchedule(SwingSchedulerDAG *SSD) {
2745-
for (int i = 0, e = SSD->SUnits.size(); i < e; ++i) {
2746-
SUnit &SU = SSD->SUnits[i];
2728+
for (SUnit &SU : SSD->SUnits) {
27472729
if (!SU.hasPhysRegDefs)
27482730
continue;
27492731
int StageDef = stageScheduled(&SU);
@@ -2939,14 +2921,12 @@ void SMSchedule::finalizeSchedule(SwingSchedulerDAG *SSD) {
29392921
for (int Cycle = getFirstCycle(), E = getFinalCycle(); Cycle <= E; ++Cycle) {
29402922
std::deque<SUnit *> &cycleInstrs = ScheduledInstrs[Cycle];
29412923
std::deque<SUnit *> newOrderPhi;
2942-
for (unsigned i = 0, e = cycleInstrs.size(); i < e; ++i) {
2943-
SUnit *SU = cycleInstrs[i];
2924+
for (SUnit *SU : cycleInstrs) {
29442925
if (SU->getInstr()->isPHI())
29452926
newOrderPhi.push_back(SU);
29462927
}
29472928
std::deque<SUnit *> newOrderI;
2948-
for (unsigned i = 0, e = cycleInstrs.size(); i < e; ++i) {
2949-
SUnit *SU = cycleInstrs[i];
2929+
for (SUnit *SU : cycleInstrs) {
29502930
if (!SU->getInstr()->isPHI())
29512931
orderDependence(SSD, SU, newOrderI);
29522932
}

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -927,8 +927,8 @@ void ScheduleDAGMI::placeDebugValues() {
927927

928928
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
929929
LLVM_DUMP_METHOD void ScheduleDAGMI::dumpSchedule() const {
930-
for (MachineBasicBlock::iterator MI = begin(), ME = end(); MI != ME; ++MI) {
931-
if (SUnit *SU = getSUnit(&(*MI)))
930+
for (MachineInstr &MI : *this) {
931+
if (SUnit *SU = getSUnit(&MI))
932932
dumpNode(*SU);
933933
else
934934
dbgs() << "Missing SUnit\n";
@@ -1927,17 +1927,15 @@ void CopyConstrain::constrainLocalCopy(SUnit *CopySU, ScheduleDAGMILive *DAG) {
19271927
}
19281928
LLVM_DEBUG(dbgs() << "Constraining copy SU(" << CopySU->NodeNum << ")\n");
19291929
// Add the weak edges.
1930-
for (SmallVectorImpl<SUnit*>::const_iterator
1931-
I = LocalUses.begin(), E = LocalUses.end(); I != E; ++I) {
1932-
LLVM_DEBUG(dbgs() << " Local use SU(" << (*I)->NodeNum << ") -> SU("
1930+
for (SUnit *LU : LocalUses) {
1931+
LLVM_DEBUG(dbgs() << " Local use SU(" << LU->NodeNum << ") -> SU("
19331932
<< GlobalSU->NodeNum << ")\n");
1934-
DAG->addEdge(GlobalSU, SDep(*I, SDep::Weak));
1933+
DAG->addEdge(GlobalSU, SDep(LU, SDep::Weak));
19351934
}
1936-
for (SmallVectorImpl<SUnit*>::const_iterator
1937-
I = GlobalUses.begin(), E = GlobalUses.end(); I != E; ++I) {
1938-
LLVM_DEBUG(dbgs() << " Global use SU(" << (*I)->NodeNum << ") -> SU("
1935+
for (SUnit *GU : GlobalUses) {
1936+
LLVM_DEBUG(dbgs() << " Global use SU(" << GU->NodeNum << ") -> SU("
19391937
<< FirstLocalSU->NodeNum << ")\n");
1940-
DAG->addEdge(FirstLocalSU, SDep(*I, SDep::Weak));
1938+
DAG->addEdge(FirstLocalSU, SDep(GU, SDep::Weak));
19411939
}
19421940
}
19431941

0 commit comments

Comments
 (0)