Skip to content

Commit fd7d406

Browse files
[llvm] Use range-based for loops (NFC)
1 parent ace1d0a commit fd7d406

16 files changed

+36
-56
lines changed

llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ MCSymbol *EHStreamer::emitExceptionTable() {
384384
SmallVector<const LandingPadInfo *, 64> LandingPads;
385385
LandingPads.reserve(PadInfos.size());
386386

387-
for (unsigned i = 0, N = PadInfos.size(); i != N; ++i)
388-
LandingPads.push_back(&PadInfos[i]);
387+
for (const LandingPadInfo &LPI : PadInfos)
388+
LandingPads.push_back(&LPI);
389389

390390
// Order landing pads lexicographically by type id.
391391
llvm::sort(LandingPads, [](const LandingPadInfo *L, const LandingPadInfo *R) {

llvm/lib/CodeGen/BranchFolding.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1013,8 +1013,8 @@ bool BranchFolder::TailMergeBlocks(MachineFunction &MF) {
10131013
// If this is a large problem, avoid visiting the same basic blocks
10141014
// multiple times.
10151015
if (MergePotentials.size() == TailMergeThreshold)
1016-
for (unsigned i = 0, e = MergePotentials.size(); i != e; ++i)
1017-
TriedMerging.insert(MergePotentials[i].getBlock());
1016+
for (const MergePotentialsElt &Elt : MergePotentials)
1017+
TriedMerging.insert(Elt.getBlock());
10181018

10191019
// See if we can do any tail merging on those.
10201020
if (MergePotentials.size() >= 2)

llvm/lib/CodeGen/CriticalAntiDepBreaker.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -460,11 +460,10 @@ BreakAntiDependencies(const std::vector<SUnit> &SUnits,
460460

461461
// Find the node at the bottom of the critical path.
462462
const SUnit *Max = nullptr;
463-
for (unsigned i = 0, e = SUnits.size(); i != e; ++i) {
464-
const SUnit *SU = &SUnits[i];
465-
MISUnitMap[SU->getInstr()] = SU;
466-
if (!Max || SU->getDepth() + SU->Latency > Max->getDepth() + Max->Latency)
467-
Max = SU;
463+
for (const SUnit &SU : SUnits) {
464+
MISUnitMap[SU.getInstr()] = &SU;
465+
if (!Max || SU.getDepth() + SU.Latency > Max->getDepth() + Max->Latency)
466+
Max = &SU;
468467
}
469468
assert(Max && "Failed to find bottom of the critical path");
470469

llvm/lib/CodeGen/GlobalMerge.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,7 @@ bool GlobalMerge::doMerge(SmallVectorImpl<GlobalVariable*> &Globals,
399399
// having a single global, but is aggressive enough for any other case.
400400
if (GlobalMergeIgnoreSingleUse) {
401401
BitVector AllGlobals(Globals.size());
402-
for (size_t i = 0, e = UsedGlobalSets.size(); i != e; ++i) {
403-
const UsedGlobalSet &UGS = UsedGlobalSets[e - i - 1];
402+
for (const UsedGlobalSet &UGS : llvm::reverse(UsedGlobalSets)) {
404403
if (UGS.UsageCount == 0)
405404
continue;
406405
if (UGS.Globals.count() > 1)
@@ -418,8 +417,7 @@ bool GlobalMerge::doMerge(SmallVectorImpl<GlobalVariable*> &Globals,
418417
BitVector PickedGlobals(Globals.size());
419418
bool Changed = false;
420419

421-
for (size_t i = 0, e = UsedGlobalSets.size(); i != e; ++i) {
422-
const UsedGlobalSet &UGS = UsedGlobalSets[e - i - 1];
420+
for (const UsedGlobalSet &UGS : llvm::reverse(UsedGlobalSets)) {
423421
if (UGS.UsageCount == 0)
424422
continue;
425423
if (PickedGlobals.anyCommon(UGS.Globals))

llvm/lib/CodeGen/LatencyPriorityQueue.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,9 @@ void LatencyPriorityQueue::push(SUnit *SU) {
7373
// Look at all of the successors of this node. Count the number of nodes that
7474
// this node is the sole unscheduled node for.
7575
unsigned NumNodesBlocking = 0;
76-
for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
77-
I != E; ++I) {
78-
if (getSingleUnscheduledPred(I->getSUnit()) == SU)
76+
for (const SDep &Succ : SU->Succs)
77+
if (getSingleUnscheduledPred(Succ.getSUnit()) == SU)
7978
++NumNodesBlocking;
80-
}
8179
NumNodesSolelyBlocking[SU->NodeNum] = NumNodesBlocking;
8280

8381
Queue.push_back(SU);

llvm/lib/CodeGen/MachinePipeliner.cpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -1455,17 +1455,15 @@ void SwingSchedulerDAG::computeNodeFunctions(NodeSetType &NodeSets) {
14551455
int asap = 0;
14561456
int zeroLatencyDepth = 0;
14571457
SUnit *SU = &SUnits[I];
1458-
for (SUnit::const_pred_iterator IP = SU->Preds.begin(),
1459-
EP = SU->Preds.end();
1460-
IP != EP; ++IP) {
1461-
SUnit *pred = IP->getSUnit();
1462-
if (IP->getLatency() == 0)
1458+
for (const SDep &P : SU->Preds) {
1459+
SUnit *pred = P.getSUnit();
1460+
if (P.getLatency() == 0)
14631461
zeroLatencyDepth =
14641462
std::max(zeroLatencyDepth, getZeroLatencyDepth(pred) + 1);
1465-
if (ignoreDependence(*IP, true))
1463+
if (ignoreDependence(P, true))
14661464
continue;
1467-
asap = std::max(asap, (int)(getASAP(pred) + IP->getLatency() -
1468-
getDistance(pred, SU, *IP) * MII));
1465+
asap = std::max(asap, (int)(getASAP(pred) + P.getLatency() -
1466+
getDistance(pred, SU, P) * MII));
14691467
}
14701468
maxASAP = std::max(maxASAP, asap);
14711469
ScheduleInfo[I].ASAP = asap;

llvm/lib/CodeGen/MachineVerifier.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -3057,9 +3057,9 @@ void MachineVerifier::verifyLiveRangeSegment(const LiveRange &LR,
30573057
SlotIndex PEnd = LiveInts->getMBBEndIdx(Pred);
30583058
// Predecessor of landing pad live-out on last call.
30593059
if (MFI->isEHPad()) {
3060-
for (auto I = Pred->rbegin(), E = Pred->rend(); I != E; ++I) {
3061-
if (I->isCall()) {
3062-
PEnd = Indexes->getInstructionIndex(*I).getBoundaryIndex();
3060+
for (const MachineInstr &MI : llvm::reverse(*Pred)) {
3061+
if (MI.isCall()) {
3062+
PEnd = Indexes->getInstructionIndex(MI).getBoundaryIndex();
30633063
break;
30643064
}
30653065
}

llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,8 @@ void ScheduleDAGSDNodes::dump() const {
706706

707707
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
708708
void ScheduleDAGSDNodes::dumpSchedule() const {
709-
for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
710-
if (SUnit *SU = Sequence[i])
709+
for (const SUnit *SU : Sequence) {
710+
if (SU)
711711
dumpNode(*SU);
712712
else
713713
dbgs() << "**** NOOP ****\n";

llvm/lib/ExecutionEngine/ExecutionEngine.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1256,8 +1256,7 @@ void ExecutionEngine::emitGlobals() {
12561256
// If there are multiple modules, map the non-canonical globals to their
12571257
// canonical location.
12581258
if (!NonCanonicalGlobals.empty()) {
1259-
for (unsigned i = 0, e = NonCanonicalGlobals.size(); i != e; ++i) {
1260-
const GlobalValue *GV = NonCanonicalGlobals[i];
1259+
for (const GlobalValue *GV : NonCanonicalGlobals) {
12611260
const GlobalValue *CGV = LinkedGlobalsMap[std::make_pair(
12621261
std::string(GV->getName()), GV->getType())];
12631262
void *Ptr = getPointerToGlobalIfAvailable(CGV);

llvm/lib/TableGen/TGLexer.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -1017,12 +1017,10 @@ void TGLexer::prepSkipToLineEnd() {
10171017
}
10181018

10191019
bool TGLexer::prepIsProcessingEnabled() {
1020-
for (auto I = PrepIncludeStack.back()->rbegin(),
1021-
E = PrepIncludeStack.back()->rend();
1022-
I != E; ++I) {
1023-
if (!I->IsDefined)
1020+
for (const PreprocessorControlDesc &I :
1021+
llvm::reverse(*PrepIncludeStack.back()))
1022+
if (!I.IsDefined)
10241023
return false;
1025-
}
10261024

10271025
return true;
10281026
}

llvm/lib/Target/AMDGPU/R600MachineScheduler.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,9 @@ SUnit* R600SchedStrategy::pickNode(bool &IsTopNode) {
124124
DAG->dumpNode(*SU);
125125
} else {
126126
dbgs() << "NO NODE \n";
127-
for (unsigned i = 0; i < DAG->SUnits.size(); i++) {
128-
const SUnit &S = DAG->SUnits[i];
127+
for (const SUnit &S : DAG->SUnits)
129128
if (!S.isScheduled)
130129
DAG->dumpNode(S);
131-
}
132130
});
133131

134132
return SU;

llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1720,10 +1720,10 @@ bool HexagonFrameLowering::assignCalleeSavedSpillSlots(MachineFunction &MF,
17201720

17211721
LLVM_DEBUG({
17221722
dbgs() << "CS information: {";
1723-
for (unsigned i = 0, n = CSI.size(); i < n; ++i) {
1724-
int FI = CSI[i].getFrameIdx();
1723+
for (const CalleeSavedInfo &I : CSI) {
1724+
int FI = I.getFrameIdx();
17251725
int Off = MFI.getObjectOffset(FI);
1726-
dbgs() << ' ' << printReg(CSI[i].getReg(), TRI) << ":fi#" << FI << ":sp";
1726+
dbgs() << ' ' << printReg(I.getReg(), TRI) << ":fi#" << FI << ":sp";
17271727
if (Off >= 0)
17281728
dbgs() << '+';
17291729
dbgs() << Off;

llvm/lib/Target/Hexagon/HexagonISelLowering.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,7 @@ HexagonTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
442442
CLI.IsTailCall = IsEligibleForTailCallOptimization(Callee, CallConv,
443443
IsVarArg, IsStructRet, StructAttrFlag, Outs,
444444
OutVals, Ins, DAG);
445-
for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
446-
CCValAssign &VA = ArgLocs[i];
445+
for (const CCValAssign &VA : ArgLocs) {
447446
if (VA.isMemLoc()) {
448447
CLI.IsTailCall = false;
449448
break;

llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -1452,9 +1452,7 @@ class DarwinX86AsmBackend : public X86AsmBackend {
14521452
unsigned NumDefCFAOffsets = 0;
14531453
int MinAbsOffset = std::numeric_limits<int>::max();
14541454

1455-
for (unsigned i = 0, e = Instrs.size(); i != e; ++i) {
1456-
const MCCFIInstruction &Inst = Instrs[i];
1457-
1455+
for (const MCCFIInstruction &Inst : Instrs) {
14581456
switch (Inst.getOperation()) {
14591457
default:
14601458
// Any other CFI directives indicate a frame that we aren't prepared

llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,9 @@ bool llvm::objcarc::CanUse(const Instruction *Inst, const Value *Ptr,
9494
return false;
9595
} else if (const auto *CS = dyn_cast<CallBase>(Inst)) {
9696
// For calls, just check the arguments (and not the callee operand).
97-
for (auto OI = CS->arg_begin(), OE = CS->arg_end(); OI != OE; ++OI) {
98-
const Value *Op = *OI;
97+
for (const Value *Op : CS->args())
9998
if (IsPotentialRetainableObjPtr(Op, *PA.getAA()) && PA.related(Ptr, Op))
10099
return true;
101-
}
102100
return false;
103101
} else if (const StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
104102
// Special-case stores, because we don't care about the stored value, just

llvm/lib/Transforms/Scalar/Reassociate.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -2313,11 +2313,8 @@ void ReassociatePass::ReassociateExpression(BinaryOperator *I) {
23132313
MadeChange |= LinearizeExprTree(I, Tree);
23142314
SmallVector<ValueEntry, 8> Ops;
23152315
Ops.reserve(Tree.size());
2316-
for (unsigned i = 0, e = Tree.size(); i != e; ++i) {
2317-
RepeatedValue E = Tree[i];
2318-
Ops.append(E.second.getZExtValue(),
2319-
ValueEntry(getRank(E.first), E.first));
2320-
}
2316+
for (const RepeatedValue &E : Tree)
2317+
Ops.append(E.second.getZExtValue(), ValueEntry(getRank(E.first), E.first));
23212318

23222319
LLVM_DEBUG(dbgs() << "RAIn:\t"; PrintOps(I, Ops); dbgs() << '\n');
23232320

0 commit comments

Comments
 (0)