Skip to content

Commit ba0407b

Browse files
[llvm] Use range-based for loops (NFC)
1 parent 54199d8 commit ba0407b

File tree

12 files changed

+24
-36
lines changed

12 files changed

+24
-36
lines changed

llvm/include/llvm/Analysis/LoopInfoImpl.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,12 @@ void LoopBase<BlockT, LoopT>::verifyLoop() const {
292292
getExitBlocks(ExitBBs);
293293
df_iterator_default_set<BlockT *> VisitSet;
294294
VisitSet.insert(ExitBBs.begin(), ExitBBs.end());
295-
df_ext_iterator<BlockT *, df_iterator_default_set<BlockT *>>
296-
BI = df_ext_begin(getHeader(), VisitSet),
297-
BE = df_ext_end(getHeader(), VisitSet);
298295

299296
// Keep track of the BBs visited.
300297
SmallPtrSet<BlockT *, 8> VisitedBBs;
301298

302299
// Check the individual blocks.
303-
for (; BI != BE; ++BI) {
304-
BlockT *BB = *BI;
305-
300+
for (BlockT *BB : depth_first_ext(getHeader(), VisitSet)) {
306301
assert(std::any_of(GraphTraits<BlockT *>::child_begin(BB),
307302
GraphTraits<BlockT *>::child_end(BB),
308303
[&](BlockT *B) { return contains(B); }) &&

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ class TargetTransformInfoImplBase {
5050
TTI::TargetCostKind CostKind) const {
5151
// In the basic model, we just assume that all-constant GEPs will be folded
5252
// into their uses via addressing modes.
53-
for (unsigned Idx = 0, Size = Operands.size(); Idx != Size; ++Idx)
54-
if (!isa<Constant>(Operands[Idx]))
53+
for (const Value *Operand : Operands)
54+
if (!isa<Constant>(Operand))
5555
return TTI::TCC_Basic;
5656

5757
return TTI::TCC_Free;

llvm/include/llvm/Bitstream/BitstreamReader.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ class BitstreamBlockInfo {
5555
if (!BlockInfoRecords.empty() && BlockInfoRecords.back().BlockID == BlockID)
5656
return &BlockInfoRecords.back();
5757

58-
for (unsigned i = 0, e = static_cast<unsigned>(BlockInfoRecords.size());
59-
i != e; ++i)
60-
if (BlockInfoRecords[i].BlockID == BlockID)
61-
return &BlockInfoRecords[i];
58+
for (const BlockInfo &BI : BlockInfoRecords)
59+
if (BI.BlockID == BlockID)
60+
return &BI;
6261
return nullptr;
6362
}
6463

llvm/include/llvm/Bitstream/BitstreamWriter.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,9 @@ class BitstreamWriter {
267267
if (!BlockInfoRecords.empty() && BlockInfoRecords.back().BlockID == BlockID)
268268
return &BlockInfoRecords.back();
269269

270-
for (unsigned i = 0, e = static_cast<unsigned>(BlockInfoRecords.size());
271-
i != e; ++i)
272-
if (BlockInfoRecords[i].BlockID == BlockID)
273-
return &BlockInfoRecords[i];
270+
for (BlockInfo &BI : BlockInfoRecords)
271+
if (BI.BlockID == BlockID)
272+
return &BI;
274273
return nullptr;
275274
}
276275

llvm/include/llvm/IR/ModuleSummaryIndexYAML.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ template <> struct CustomMappingTraits<TypeIdSummaryMapTy> {
270270
V.insert({GlobalValue::getGUID(Key), {std::string(Key), TId}});
271271
}
272272
static void output(IO &io, TypeIdSummaryMapTy &V) {
273-
for (auto TidIter = V.begin(); TidIter != V.end(); TidIter++)
274-
io.mapRequired(TidIter->second.first.c_str(), TidIter->second.second);
273+
for (auto &TidIter : V)
274+
io.mapRequired(TidIter.second.first.c_str(), TidIter.second.second);
275275
}
276276
};
277277

llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,8 @@ void MCJIT::notifyObjectLoaded(const object::ObjectFile &Obj,
659659
static_cast<uint64_t>(reinterpret_cast<uintptr_t>(Obj.getData().data()));
660660
std::lock_guard<sys::Mutex> locked(lock);
661661
MemMgr->notifyObjectLoaded(this, Obj);
662-
for (unsigned I = 0, S = EventListeners.size(); I < S; ++I) {
663-
EventListeners[I]->notifyObjectLoaded(Key, Obj, L);
664-
}
662+
for (JITEventListener *EL : EventListeners)
663+
EL->notifyObjectLoaded(Key, Obj, L);
665664
}
666665

667666
void MCJIT::notifyFreeingObject(const object::ObjectFile &Obj) {

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,8 +2209,8 @@ SIInstrInfo::expandMovDPP64(MachineInstr &MI) const {
22092209
}
22102210
}
22112211

2212-
for (unsigned I = 3; I < MI.getNumExplicitOperands(); ++I)
2213-
MovDPP.addImm(MI.getOperand(I).getImm());
2212+
for (const MachineOperand &MO : llvm::drop_begin(MI.explicit_operands(), 3))
2213+
MovDPP.addImm(MO.getImm());
22142214

22152215
Split[Part] = MovDPP;
22162216
++Part;

llvm/lib/Target/X86/X86CmovConversion.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,7 @@ bool X86CmovConverterPass::checkForProfitableCmovCandidates(
437437
// Depth-Diff[i]:
438438
// Number of cycles saved in first 'i` iterations by optimizing the loop.
439439
//===--------------------------------------------------------------------===//
440-
for (unsigned I = 0; I < LoopIterations; ++I) {
441-
DepthInfo &MaxDepth = LoopDepth[I];
440+
for (DepthInfo &MaxDepth : LoopDepth) {
442441
for (auto *MBB : Blocks) {
443442
// Clear physical registers Def map.
444443
RegDefMaps[PhyRegType].clear();

llvm/lib/Target/X86/X86FrameLowering.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,9 +1097,9 @@ void X86FrameLowering::emitStackProbeInlineWindowsCoreCLR64(
10971097
for (MachineInstr &MI : *LoopMBB) {
10981098
MI.setFlag(MachineInstr::FrameSetup);
10991099
}
1100-
for (MachineBasicBlock::iterator CMBBI = ContinueMBB->begin();
1101-
CMBBI != ContinueMBBI; ++CMBBI) {
1102-
CMBBI->setFlag(MachineInstr::FrameSetup);
1100+
for (MachineInstr &MI :
1101+
llvm::make_range(ContinueMBB->begin(), ContinueMBBI)) {
1102+
MI.setFlag(MachineInstr::FrameSetup);
11031103
}
11041104
}
11051105
}

llvm/lib/Target/X86/X86InstrInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9425,8 +9425,8 @@ namespace {
94259425
}
94269426

94279427
// Visit the children of this block in the dominator tree.
9428-
for (auto I = Node->begin(), E = Node->end(); I != E; ++I) {
9429-
Changed |= VisitNode(*I, TLSBaseAddrReg);
9428+
for (auto &I : *Node) {
9429+
Changed |= VisitNode(I, TLSBaseAddrReg);
94309430
}
94319431

94329432
return Changed;

llvm/lib/Target/X86/X86VZeroUpper.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,8 @@ bool VZeroUpperInserter::runOnMachineFunction(MachineFunction &MF) {
299299
bool YmmOrZmmUsed = FnHasLiveInYmmOrZmm;
300300
for (auto *RC : {&X86::VR256RegClass, &X86::VR512_0_15RegClass}) {
301301
if (!YmmOrZmmUsed) {
302-
for (TargetRegisterClass::iterator i = RC->begin(), e = RC->end(); i != e;
303-
i++) {
304-
if (!MRI.reg_nodbg_empty(*i)) {
302+
for (MCPhysReg R : *RC) {
303+
if (!MRI.reg_nodbg_empty(R)) {
305304
YmmOrZmmUsed = true;
306305
break;
307306
}

llvm/lib/Transforms/IPO/GlobalOpt.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,7 @@ static bool isLeakCheckerRoot(GlobalVariable *GV) {
140140
case Type::StructTyID: {
141141
StructType *STy = cast<StructType>(Ty);
142142
if (STy->isOpaque()) return true;
143-
for (StructType::element_iterator I = STy->element_begin(),
144-
E = STy->element_end(); I != E; ++I) {
145-
Type *InnerTy = *I;
143+
for (Type *InnerTy : STy->elements()) {
146144
if (isa<PointerType>(InnerTy)) return true;
147145
if (isa<StructType>(InnerTy) || isa<ArrayType>(InnerTy) ||
148146
isa<VectorType>(InnerTy))

0 commit comments

Comments
 (0)