[llvm] c23ebf1 - [llvm] Use range-based for loops (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 8 20:35:50 PST 2021
Author: Kazu Hirata
Date: 2021-12-08T20:35:39-08:00
New Revision: c23ebf17140cc4fd42117f3bfb8cb045279d0c4d
URL: https://github.com/llvm/llvm-project/commit/c23ebf17140cc4fd42117f3bfb8cb045279d0c4d
DIFF: https://github.com/llvm/llvm-project/commit/c23ebf17140cc4fd42117f3bfb8cb045279d0c4d.diff
LOG: [llvm] Use range-based for loops (NFC)
Added:
Modified:
llvm/lib/CodeGen/UnreachableBlockElim.cpp
llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp
llvm/lib/ExecutionEngine/MCJIT/MCJIT.h
llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
llvm/lib/IR/AsmWriter.cpp
llvm/lib/IR/BasicBlock.cpp
llvm/lib/IR/ConstantFold.cpp
llvm/lib/IR/Constants.cpp
llvm/lib/IR/DIBuilder.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/UnreachableBlockElim.cpp b/llvm/lib/CodeGen/UnreachableBlockElim.cpp
index c9a19948ff2f0..3426a03b6083e 100644
--- a/llvm/lib/CodeGen/UnreachableBlockElim.cpp
+++ b/llvm/lib/CodeGen/UnreachableBlockElim.cpp
@@ -144,23 +144,22 @@ bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) {
}
// Actually remove the blocks now.
- for (unsigned i = 0, e = DeadBlocks.size(); i != e; ++i) {
+ for (MachineBasicBlock *BB : DeadBlocks) {
// Remove any call site information for calls in the block.
- for (auto &I : DeadBlocks[i]->instrs())
+ for (auto &I : BB->instrs())
if (I.shouldUpdateCallSiteInfo())
- DeadBlocks[i]->getParent()->eraseCallSiteInfo(&I);
+ BB->getParent()->eraseCallSiteInfo(&I);
- DeadBlocks[i]->eraseFromParent();
+ BB->eraseFromParent();
}
// Cleanup PHI nodes.
- for (MachineFunction::iterator I = F.begin(), E = F.end(); I != E; ++I) {
- MachineBasicBlock *BB = &*I;
+ for (MachineBasicBlock &BB : F) {
// Prune unneeded PHI entries.
- SmallPtrSet<MachineBasicBlock*, 8> preds(BB->pred_begin(),
- BB->pred_end());
- MachineBasicBlock::iterator phi = BB->begin();
- while (phi != BB->end() && phi->isPHI()) {
+ SmallPtrSet<MachineBasicBlock*, 8> preds(BB.pred_begin(),
+ BB.pred_end());
+ MachineBasicBlock::iterator phi = BB.begin();
+ while (phi != BB.end() && phi->isPHI()) {
for (unsigned i = phi->getNumOperands() - 1; i >= 2; i-=2)
if (!preds.count(phi->getOperand(i).getMBB())) {
phi->RemoveOperand(i);
@@ -189,7 +188,7 @@ bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) {
// insert a COPY instead of simply replacing the output
// with the input.
const TargetInstrInfo *TII = F.getSubtarget().getInstrInfo();
- BuildMI(*BB, BB->getFirstNonPHI(), phi->getDebugLoc(),
+ BuildMI(BB, BB.getFirstNonPHI(), phi->getDebugLoc(),
TII->get(TargetOpcode::COPY), OutputReg)
.addReg(InputReg, getRegState(Input), InputSub);
}
diff --git a/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp b/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp
index fd9a0deb54d60..f9e67014477e5 100644
--- a/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp
@@ -518,8 +518,8 @@ SymbolCache::findLineTable(uint16_t Modi) const {
const std::vector<LineTableEntry> &RHS) {
return LHS[0].Addr < RHS[0].Addr;
});
- for (size_t I = 0; I < EntryList.size(); ++I)
- llvm::append_range(ModuleLineTable, EntryList[I]);
+ for (std::vector<LineTableEntry> &I : EntryList)
+ llvm::append_range(ModuleLineTable, I);
return ModuleLineTable;
}
diff --git a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h
index 52e7eda903100..a5dd420c9132c 100644
--- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h
+++ b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h
@@ -151,12 +151,8 @@ class MCJIT : public ExecutionEngine {
}
void markAllLoadedModulesAsFinalized() {
- for (ModulePtrSet::iterator I = LoadedModules.begin(),
- E = LoadedModules.end();
- I != E; ++I) {
- Module *M = *I;
+ for (Module *M : LoadedModules)
FinalizedModules.insert(M);
- }
LoadedModules.clear();
}
@@ -167,10 +163,8 @@ class MCJIT : public ExecutionEngine {
void freeModulePtrSet(ModulePtrSet& MPS) {
// Go through the module set and delete everything.
- for (ModulePtrSet::iterator I = MPS.begin(), E = MPS.end(); I != E; ++I) {
- Module *M = *I;
+ for (Module *M : MPS)
delete M;
- }
MPS.clear();
}
};
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
index f16c6bdbfa4fd..3f38d26869d47 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
@@ -124,8 +124,10 @@ void RuntimeDyldImpl::resolveRelocations() {
std::lock_guard<sys::Mutex> locked(lock);
// Print out the sections prior to relocation.
- LLVM_DEBUG(for (int i = 0, e = Sections.size(); i != e; ++i)
- dumpSectionMemory(Sections[i], "before relocations"););
+ LLVM_DEBUG({
+ for (SectionEntry &S : Sections)
+ dumpSectionMemory(S, "before relocations");
+ });
// First, resolve relocations associated with external symbols.
if (auto Err = resolveExternalSymbols()) {
@@ -136,21 +138,23 @@ void RuntimeDyldImpl::resolveRelocations() {
resolveLocalRelocations();
// Print out sections after relocation.
- LLVM_DEBUG(for (int i = 0, e = Sections.size(); i != e; ++i)
- dumpSectionMemory(Sections[i], "after relocations"););
+ LLVM_DEBUG({
+ for (SectionEntry &S : Sections)
+ dumpSectionMemory(S, "after relocations");
+ });
}
void RuntimeDyldImpl::resolveLocalRelocations() {
// Iterate over all outstanding relocations
- for (auto it = Relocations.begin(), e = Relocations.end(); it != e; ++it) {
+ for (const auto &Rel : Relocations) {
// The Section here (Sections[i]) refers to the section in which the
// symbol for the relocation is located. The SectionID in the relocation
// entry provides the section to which the relocation will be applied.
- unsigned Idx = it->first;
+ unsigned Idx = Rel.first;
uint64_t Addr = getSectionLoadAddress(Idx);
LLVM_DEBUG(dbgs() << "Resolving relocations Section #" << Idx << "\t"
<< format("%p", (uintptr_t)Addr) << "\n");
- resolveRelocationList(it->second, Addr);
+ resolveRelocationList(Rel.second, Addr);
}
Relocations.clear();
}
@@ -457,9 +461,9 @@ static uint64_t
computeAllocationSizeForSections(std::vector<uint64_t> &SectionSizes,
uint64_t Alignment) {
uint64_t TotalSize = 0;
- for (size_t Idx = 0, Cnt = SectionSizes.size(); Idx < Cnt; Idx++) {
+ for (uint64_t SectionSize : SectionSizes) {
uint64_t AlignedSize =
- (SectionSizes[Idx] + Alignment - 1) / Alignment * Alignment;
+ (SectionSize + Alignment - 1) / Alignment * Alignment;
TotalSize += AlignedSize;
}
return TotalSize;
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index c9748e1387eb1..9a62e6dabeb03 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -512,10 +512,8 @@ void TypePrinting::incorporateTypes() {
// the unnamed ones out to a numbering and remove the anonymous structs.
unsigned NextNumber = 0;
- std::vector<StructType*>::iterator NextToUse = NamedTypes.begin(), I, E;
- for (I = NamedTypes.begin(), E = NamedTypes.end(); I != E; ++I) {
- StructType *STy = *I;
-
+ std::vector<StructType *>::iterator NextToUse = NamedTypes.begin();
+ for (StructType *STy : NamedTypes) {
// Ignore anonymous types.
if (STy->isLiteral())
continue;
@@ -1583,11 +1581,9 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
Out << ", ";
}
- if (CE->hasIndices()) {
- ArrayRef<unsigned> Indices = CE->getIndices();
- for (unsigned i = 0, e = Indices.size(); i != e; ++i)
- Out << ", " << Indices[i];
- }
+ if (CE->hasIndices())
+ for (unsigned I : CE->getIndices())
+ Out << ", " << I;
if (CE->isCast()) {
Out << " to ";
@@ -3637,13 +3633,13 @@ void AssemblyWriter::printTypeIdentities() {
}
auto &NamedTypes = TypePrinter.getNamedTypes();
- for (unsigned I = 0, E = NamedTypes.size(); I != E; ++I) {
- PrintLLVMName(Out, NamedTypes[I]->getName(), LocalPrefix);
+ for (StructType *NamedType : NamedTypes) {
+ PrintLLVMName(Out, NamedType->getName(), LocalPrefix);
Out << " = type ";
// Make sure we print out at least one level of the type structure, so
// that we do not get %FILE = type %FILE
- TypePrinter.printStructBody(NamedTypes[I], Out);
+ TypePrinter.printStructBody(NamedType, Out);
Out << '\n';
}
}
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index ed1956e0f7e9a..7beafc485d097 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -450,8 +450,8 @@ BasicBlock *BasicBlock::splitBasicBlockBefore(iterator I, const Twine &BBName) {
void BasicBlock::replacePhiUsesWith(BasicBlock *Old, BasicBlock *New) {
// N.B. This might not be a complete BasicBlock, so don't assume
// that it ends with a non-phi instruction.
- for (iterator II = begin(), IE = end(); II != IE; ++II) {
- PHINode *PN = dyn_cast<PHINode>(II);
+ for (Instruction &I : *this) {
+ PHINode *PN = dyn_cast<PHINode>(&I);
if (!PN)
break;
PN->replaceIncomingBlockWith(Old, New);
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 437fd05584473..ae48d0333d67c 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -2215,9 +2215,8 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C,
if (C->isNullValue()) {
bool isNull = true;
- for (unsigned i = 0, e = Idxs.size(); i != e; ++i)
- if (!isa<UndefValue>(Idxs[i]) &&
- !cast<Constant>(Idxs[i])->isNullValue()) {
+ for (Value *Idx : Idxs)
+ if (!isa<UndefValue>(Idx) && !cast<Constant>(Idx)->isNullValue()) {
isNull = false;
break;
}
@@ -2233,8 +2232,8 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C,
// The GEP returns a vector of pointers when one of more of
// its arguments is a vector.
- for (unsigned i = 0, e = Idxs.size(); i != e; ++i) {
- if (auto *VT = dyn_cast<VectorType>(Idxs[i]->getType())) {
+ for (Value *Idx : Idxs) {
+ if (auto *VT = dyn_cast<VectorType>(Idx->getType())) {
assert((!isa<VectorType>(GEPTy) || isa<ScalableVectorType>(GEPTy) ==
isa<ScalableVectorType>(VT)) &&
"Mismatched GEPTy vector types");
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index c66cfb6e9ac12..a118f4dfc59df 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -1296,9 +1296,10 @@ Constant *ConstantArray::getImpl(ArrayType *Ty, ArrayRef<Constant*> V) {
if (V.empty())
return ConstantAggregateZero::get(Ty);
- for (unsigned i = 0, e = V.size(); i != e; ++i) {
- assert(V[i]->getType() == Ty->getElementType() &&
+ for (Constant *C : V) {
+ assert(C->getType() == Ty->getElementType() &&
"Wrong type in array element initializer");
+ (void)C;
}
// If this is an all-zero array, return a ConstantAggregateZero object. If
@@ -1364,12 +1365,12 @@ Constant *ConstantStruct::get(StructType *ST, ArrayRef<Constant*> V) {
isZero = V[0]->isNullValue();
// PoisonValue inherits UndefValue, so its check is not necessary.
if (isUndef || isZero) {
- for (unsigned i = 0, e = V.size(); i != e; ++i) {
- if (!V[i]->isNullValue())
+ for (Constant *C : V) {
+ if (!C->isNullValue())
isZero = false;
- if (!isa<PoisonValue>(V[i]))
+ if (!isa<PoisonValue>(C))
isPoison = false;
- if (isa<PoisonValue>(V[i]) || !isa<UndefValue>(V[i]))
+ if (isa<PoisonValue>(C) || !isa<UndefValue>(C))
isUndef = false;
}
}
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 548962bd6a98c..35af22034a120 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -671,11 +671,11 @@ DIBuilder::getOrCreateMacroArray(ArrayRef<Metadata *> Elements) {
DITypeRefArray DIBuilder::getOrCreateTypeArray(ArrayRef<Metadata *> Elements) {
SmallVector<llvm::Metadata *, 16> Elts;
- for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
- if (Elements[i] && isa<MDNode>(Elements[i]))
- Elts.push_back(cast<DIType>(Elements[i]));
+ for (Metadata *E : Elements) {
+ if (isa_and_nonnull<MDNode>(E))
+ Elts.push_back(cast<DIType>(E));
else
- Elts.push_back(Elements[i]);
+ Elts.push_back(E);
}
return DITypeRefArray(MDNode::get(VMContext, Elts));
}
More information about the llvm-commits
mailing list