[llvm] ba0407b - [llvm] Use range-based for loops (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 7 00:16:48 PDT 2022
Author: Kazu Hirata
Date: 2022-08-07T00:16:21-07:00
New Revision: ba0407ba86d0a87f01e1a676f9dc23bae3e9c169
URL: https://github.com/llvm/llvm-project/commit/ba0407ba86d0a87f01e1a676f9dc23bae3e9c169
DIFF: https://github.com/llvm/llvm-project/commit/ba0407ba86d0a87f01e1a676f9dc23bae3e9c169.diff
LOG: [llvm] Use range-based for loops (NFC)
Added:
Modified:
llvm/include/llvm/Analysis/LoopInfoImpl.h
llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
llvm/include/llvm/Bitstream/BitstreamReader.h
llvm/include/llvm/Bitstream/BitstreamWriter.h
llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
llvm/lib/Target/X86/X86CmovConversion.cpp
llvm/lib/Target/X86/X86FrameLowering.cpp
llvm/lib/Target/X86/X86InstrInfo.cpp
llvm/lib/Target/X86/X86VZeroUpper.cpp
llvm/lib/Transforms/IPO/GlobalOpt.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/LoopInfoImpl.h b/llvm/include/llvm/Analysis/LoopInfoImpl.h
index a96a698f3afbc..ffe5617bbae8d 100644
--- a/llvm/include/llvm/Analysis/LoopInfoImpl.h
+++ b/llvm/include/llvm/Analysis/LoopInfoImpl.h
@@ -292,17 +292,12 @@ void LoopBase<BlockT, LoopT>::verifyLoop() const {
getExitBlocks(ExitBBs);
df_iterator_default_set<BlockT *> VisitSet;
VisitSet.insert(ExitBBs.begin(), ExitBBs.end());
- df_ext_iterator<BlockT *, df_iterator_default_set<BlockT *>>
- BI = df_ext_begin(getHeader(), VisitSet),
- BE = df_ext_end(getHeader(), VisitSet);
// Keep track of the BBs visited.
SmallPtrSet<BlockT *, 8> VisitedBBs;
// Check the individual blocks.
- for (; BI != BE; ++BI) {
- BlockT *BB = *BI;
-
+ for (BlockT *BB : depth_first_ext(getHeader(), VisitSet)) {
assert(std::any_of(GraphTraits<BlockT *>::child_begin(BB),
GraphTraits<BlockT *>::child_end(BB),
[&](BlockT *B) { return contains(B); }) &&
diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
index 55b3b53a19a88..1364e7ab9fb32 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -50,8 +50,8 @@ class TargetTransformInfoImplBase {
TTI::TargetCostKind CostKind) const {
// In the basic model, we just assume that all-constant GEPs will be folded
// into their uses via addressing modes.
- for (unsigned Idx = 0, Size = Operands.size(); Idx != Size; ++Idx)
- if (!isa<Constant>(Operands[Idx]))
+ for (const Value *Operand : Operands)
+ if (!isa<Constant>(Operand))
return TTI::TCC_Basic;
return TTI::TCC_Free;
diff --git a/llvm/include/llvm/Bitstream/BitstreamReader.h b/llvm/include/llvm/Bitstream/BitstreamReader.h
index 10a0a4e0039e8..420a9e98bb8a1 100644
--- a/llvm/include/llvm/Bitstream/BitstreamReader.h
+++ b/llvm/include/llvm/Bitstream/BitstreamReader.h
@@ -55,10 +55,9 @@ class BitstreamBlockInfo {
if (!BlockInfoRecords.empty() && BlockInfoRecords.back().BlockID == BlockID)
return &BlockInfoRecords.back();
- for (unsigned i = 0, e = static_cast<unsigned>(BlockInfoRecords.size());
- i != e; ++i)
- if (BlockInfoRecords[i].BlockID == BlockID)
- return &BlockInfoRecords[i];
+ for (const BlockInfo &BI : BlockInfoRecords)
+ if (BI.BlockID == BlockID)
+ return &BI;
return nullptr;
}
diff --git a/llvm/include/llvm/Bitstream/BitstreamWriter.h b/llvm/include/llvm/Bitstream/BitstreamWriter.h
index 143f9ba17afef..1475c3272dad6 100644
--- a/llvm/include/llvm/Bitstream/BitstreamWriter.h
+++ b/llvm/include/llvm/Bitstream/BitstreamWriter.h
@@ -267,10 +267,9 @@ class BitstreamWriter {
if (!BlockInfoRecords.empty() && BlockInfoRecords.back().BlockID == BlockID)
return &BlockInfoRecords.back();
- for (unsigned i = 0, e = static_cast<unsigned>(BlockInfoRecords.size());
- i != e; ++i)
- if (BlockInfoRecords[i].BlockID == BlockID)
- return &BlockInfoRecords[i];
+ for (BlockInfo &BI : BlockInfoRecords)
+ if (BI.BlockID == BlockID)
+ return &BI;
return nullptr;
}
diff --git a/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h b/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
index f09ee0efa5b20..74e92797f15ce 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
@@ -270,8 +270,8 @@ template <> struct CustomMappingTraits<TypeIdSummaryMapTy> {
V.insert({GlobalValue::getGUID(Key), {std::string(Key), TId}});
}
static void output(IO &io, TypeIdSummaryMapTy &V) {
- for (auto TidIter = V.begin(); TidIter != V.end(); TidIter++)
- io.mapRequired(TidIter->second.first.c_str(), TidIter->second.second);
+ for (auto &TidIter : V)
+ io.mapRequired(TidIter.second.first.c_str(), TidIter.second.second);
}
};
diff --git a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
index 4ac901daa5c83..e75c4eba52962 100644
--- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
+++ b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
@@ -659,9 +659,8 @@ void MCJIT::notifyObjectLoaded(const object::ObjectFile &Obj,
static_cast<uint64_t>(reinterpret_cast<uintptr_t>(Obj.getData().data()));
std::lock_guard<sys::Mutex> locked(lock);
MemMgr->notifyObjectLoaded(this, Obj);
- for (unsigned I = 0, S = EventListeners.size(); I < S; ++I) {
- EventListeners[I]->notifyObjectLoaded(Key, Obj, L);
- }
+ for (JITEventListener *EL : EventListeners)
+ EL->notifyObjectLoaded(Key, Obj, L);
}
void MCJIT::notifyFreeingObject(const object::ObjectFile &Obj) {
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index 02384e38f6d4a..0f4c77838763b 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -2209,8 +2209,8 @@ SIInstrInfo::expandMovDPP64(MachineInstr &MI) const {
}
}
- for (unsigned I = 3; I < MI.getNumExplicitOperands(); ++I)
- MovDPP.addImm(MI.getOperand(I).getImm());
+ for (const MachineOperand &MO : llvm::drop_begin(MI.explicit_operands(), 3))
+ MovDPP.addImm(MO.getImm());
Split[Part] = MovDPP;
++Part;
diff --git a/llvm/lib/Target/X86/X86CmovConversion.cpp b/llvm/lib/Target/X86/X86CmovConversion.cpp
index 8016960681966..765ff5abf0477 100644
--- a/llvm/lib/Target/X86/X86CmovConversion.cpp
+++ b/llvm/lib/Target/X86/X86CmovConversion.cpp
@@ -437,8 +437,7 @@ bool X86CmovConverterPass::checkForProfitableCmovCandidates(
// Depth-Diff[i]:
// Number of cycles saved in first 'i` iterations by optimizing the loop.
//===--------------------------------------------------------------------===//
- for (unsigned I = 0; I < LoopIterations; ++I) {
- DepthInfo &MaxDepth = LoopDepth[I];
+ for (DepthInfo &MaxDepth : LoopDepth) {
for (auto *MBB : Blocks) {
// Clear physical registers Def map.
RegDefMaps[PhyRegType].clear();
diff --git a/llvm/lib/Target/X86/X86FrameLowering.cpp b/llvm/lib/Target/X86/X86FrameLowering.cpp
index d524090f902e7..a4e27a6416e7d 100644
--- a/llvm/lib/Target/X86/X86FrameLowering.cpp
+++ b/llvm/lib/Target/X86/X86FrameLowering.cpp
@@ -1097,9 +1097,9 @@ void X86FrameLowering::emitStackProbeInlineWindowsCoreCLR64(
for (MachineInstr &MI : *LoopMBB) {
MI.setFlag(MachineInstr::FrameSetup);
}
- for (MachineBasicBlock::iterator CMBBI = ContinueMBB->begin();
- CMBBI != ContinueMBBI; ++CMBBI) {
- CMBBI->setFlag(MachineInstr::FrameSetup);
+ for (MachineInstr &MI :
+ llvm::make_range(ContinueMBB->begin(), ContinueMBBI)) {
+ MI.setFlag(MachineInstr::FrameSetup);
}
}
}
diff --git a/llvm/lib/Target/X86/X86InstrInfo.cpp b/llvm/lib/Target/X86/X86InstrInfo.cpp
index 4904e79f98703..81db055305987 100644
--- a/llvm/lib/Target/X86/X86InstrInfo.cpp
+++ b/llvm/lib/Target/X86/X86InstrInfo.cpp
@@ -9425,8 +9425,8 @@ namespace {
}
// Visit the children of this block in the dominator tree.
- for (auto I = Node->begin(), E = Node->end(); I != E; ++I) {
- Changed |= VisitNode(*I, TLSBaseAddrReg);
+ for (auto &I : *Node) {
+ Changed |= VisitNode(I, TLSBaseAddrReg);
}
return Changed;
diff --git a/llvm/lib/Target/X86/X86VZeroUpper.cpp b/llvm/lib/Target/X86/X86VZeroUpper.cpp
index 59b5dc111ce34..17fa942a66b23 100644
--- a/llvm/lib/Target/X86/X86VZeroUpper.cpp
+++ b/llvm/lib/Target/X86/X86VZeroUpper.cpp
@@ -299,9 +299,8 @@ bool VZeroUpperInserter::runOnMachineFunction(MachineFunction &MF) {
bool YmmOrZmmUsed = FnHasLiveInYmmOrZmm;
for (auto *RC : {&X86::VR256RegClass, &X86::VR512_0_15RegClass}) {
if (!YmmOrZmmUsed) {
- for (TargetRegisterClass::iterator i = RC->begin(), e = RC->end(); i != e;
- i++) {
- if (!MRI.reg_nodbg_empty(*i)) {
+ for (MCPhysReg R : *RC) {
+ if (!MRI.reg_nodbg_empty(R)) {
YmmOrZmmUsed = true;
break;
}
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 6df0409256bbd..2a48b44795288 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -140,9 +140,7 @@ static bool isLeakCheckerRoot(GlobalVariable *GV) {
case Type::StructTyID: {
StructType *STy = cast<StructType>(Ty);
if (STy->isOpaque()) return true;
- for (StructType::element_iterator I = STy->element_begin(),
- E = STy->element_end(); I != E; ++I) {
- Type *InnerTy = *I;
+ for (Type *InnerTy : STy->elements()) {
if (isa<PointerType>(InnerTy)) return true;
if (isa<StructType>(InnerTy) || isa<ArrayType>(InnerTy) ||
isa<VectorType>(InnerTy))
More information about the llvm-commits
mailing list