From f6bce30cf9490265de9b5227df2af46b62564675 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sat, 20 Nov 2021 18:42:10 -0800 Subject: [PATCH] [llvm] Use range-based for loops (NFC) --- llvm/lib/Analysis/IntervalPartition.cpp | 16 +++++++-------- llvm/lib/Analysis/MemoryDependenceAnalysis.cpp | 6 +++--- llvm/lib/Analysis/ScalarEvolution.cpp | 12 +++++------ llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp | 4 ++-- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 9 ++++----- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 28 ++++++++++++-------------- llvm/lib/Bitcode/Writer/ValueEnumerator.cpp | 4 ++-- llvm/lib/CodeGen/AggressiveAntiDepBreaker.cpp | 17 ++++++---------- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 11 +++++----- 9 files changed, 49 insertions(+), 58 deletions(-) diff --git a/llvm/lib/Analysis/IntervalPartition.cpp b/llvm/lib/Analysis/IntervalPartition.cpp index 23ff4fd..d9620fd 100644 --- a/llvm/lib/Analysis/IntervalPartition.cpp +++ b/llvm/lib/Analysis/IntervalPartition.cpp @@ -36,16 +36,16 @@ INITIALIZE_PASS(IntervalPartition, "intervals", // releaseMemory - Reset state back to before function was analyzed void IntervalPartition::releaseMemory() { - for (unsigned i = 0, e = Intervals.size(); i != e; ++i) - delete Intervals[i]; + for (Interval *I : Intervals) + delete I; IntervalMap.clear(); Intervals.clear(); RootInterval = nullptr; } void IntervalPartition::print(raw_ostream &O, const Module*) const { - for(unsigned i = 0, e = Intervals.size(); i != e; ++i) - Intervals[i]->print(O); + for (const Interval *I : Intervals) + I->print(O); } // addIntervalToPartition - Add an interval to the internal list of intervals, @@ -87,8 +87,8 @@ bool IntervalPartition::runOnFunction(Function &F) { // Now that we know all of the successor information, propagate this to the // predecessors for each block. - for (unsigned i = 0, e = Intervals.size(); i != e; ++i) - updatePredecessors(Intervals[i]); + for (Interval *I : Intervals) + updatePredecessors(I); return false; } @@ -113,6 +113,6 @@ IntervalPartition::IntervalPartition(IntervalPartition &IP, bool) // Now that we know all of the successor information, propagate this to the // predecessors for each block. - for (unsigned i = 0, e = Intervals.size(); i != e; ++i) - updatePredecessors(Intervals[i]); + for (Interval *I : Intervals) + updatePredecessors(I); } diff --git a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp index b44d15e7..da6bb4c 100644 --- a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp +++ b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp @@ -1481,11 +1481,11 @@ void MemoryDependenceResults::removeCachedNonLocalPointerDependencies( // instructions from the reverse map. NonLocalDepInfo &PInfo = It->second.NonLocalDeps; - for (unsigned i = 0, e = PInfo.size(); i != e; ++i) { - Instruction *Target = PInfo[i].getResult().getInst(); + for (const NonLocalDepEntry &DE : PInfo) { + Instruction *Target = DE.getResult().getInst(); if (!Target) continue; // Ignore non-local dep results. - assert(Target->getParent() == PInfo[i].getBB()); + assert(Target->getParent() == DE.getBB()); // Eliminating the dirty entry from 'Cache', so update the reverse info. RemoveFromReverseMap(ReverseNonLocalPtrDeps, Target, P); diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index f7c22cf..f08601d 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -2915,8 +2915,8 @@ ScalarEvolution::getOrCreateAddRecExpr(ArrayRef Ops, const Loop *L, SCEV::NoWrapFlags Flags) { FoldingSetNodeID ID; ID.AddInteger(scAddRecExpr); - for (unsigned i = 0, e = Ops.size(); i != e; ++i) - ID.AddPointer(Ops[i]); + for (const SCEV *Op : Ops) + ID.AddPointer(Op); ID.AddPointer(L); void *IP = nullptr; SCEVAddRecExpr *S = @@ -2939,8 +2939,8 @@ ScalarEvolution::getOrCreateMulExpr(ArrayRef Ops, SCEV::NoWrapFlags Flags) { FoldingSetNodeID ID; ID.AddInteger(scMulExpr); - for (unsigned i = 0, e = Ops.size(); i != e; ++i) - ID.AddPointer(Ops[i]); + for (const SCEV *Op : Ops) + ID.AddPointer(Op); void *IP = nullptr; SCEVMulExpr *S = static_cast(UniqueSCEVs.FindNodeOrInsertPos(ID, IP)); @@ -3708,8 +3708,8 @@ SCEV *ScalarEvolution::findExistingSCEVInCache(SCEVTypes SCEVType, ArrayRef Ops) { FoldingSetNodeID ID; ID.AddInteger(SCEVType); - for (unsigned i = 0, e = Ops.size(); i != e; ++i) - ID.AddPointer(Ops[i]); + for (const SCEV *Op : Ops) + ID.AddPointer(Op); void *IP = nullptr; return UniqueSCEVs.FindNodeOrInsertPos(ID, IP); } diff --git a/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp b/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp index 2723105..d7bcb0d 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp @@ -957,8 +957,8 @@ Error BitcodeAnalyzer::parseBlock(unsigned BlockID, unsigned IndentLevel, O->OS.write_escaped(Blob, /*hex=*/true) << "'"; } else { bool BlobIsPrintable = true; - for (unsigned i = 0, e = Blob.size(); i != e; ++i) - if (!isPrint(static_cast(Blob[i]))) { + for (char C : Blob) + if (!isPrint(static_cast(C))) { BlobIsPrintable = false; break; } diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index c568461..993cb1d 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -3996,8 +3996,8 @@ Error BitcodeReader::parseFunctionBody(Function *F) { // See if anything took the address of blocks in this function. auto BBFRI = BasicBlockFwdRefs.find(F); if (BBFRI == BasicBlockFwdRefs.end()) { - for (unsigned i = 0, e = FunctionBBs.size(); i != e; ++i) - FunctionBBs[i] = BasicBlock::Create(Context, "", F); + for (BasicBlock *&BB : FunctionBBs) + BB = BasicBlock::Create(Context, "", F); } else { auto &BBRefs = BBFRI->second; // Check for invalid basic block references. @@ -4605,9 +4605,8 @@ Error BitcodeReader::parseFunctionBody(Function *F) { CaseVals.push_back(ConstantInt::get(Context, Low)); } BasicBlock *DestBB = getBasicBlock(Record[CurIdx++]); - for (SmallVector::iterator cvi = CaseVals.begin(), - cve = CaseVals.end(); cvi != cve; ++cvi) - SI->addCase(*cvi, DestBB); + for (ConstantInt *Cst : CaseVals) + SI->addCase(Cst, DestBB); } I = SI; break; diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 1e9a919..e2354c4 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -596,10 +596,10 @@ static void writeStringRecord(BitstreamWriter &Stream, unsigned Code, SmallVector Vals; // Code: [strchar x N] - for (unsigned i = 0, e = Str.size(); i != e; ++i) { - if (AbbrevToUse && !BitCodeAbbrevOp::isChar6(Str[i])) + for (char C : Str) { + if (AbbrevToUse && !BitCodeAbbrevOp::isChar6(C)) AbbrevToUse = 0; - Vals.push_back(Str[i]); + Vals.push_back(C); } // Emit the finished record. @@ -914,8 +914,7 @@ void ModuleBitcodeWriter::writeTypeTable() { TypeVals.clear(); // Loop over all of the types, emitting each in turn. - for (unsigned i = 0, e = TypeList.size(); i != e; ++i) { - Type *T = TypeList[i]; + for (Type *T : TypeList) { int AbbrevToUse = 0; unsigned Code = 0; @@ -3343,19 +3342,18 @@ void ModuleBitcodeWriter::writeFunction( DILocation *LastDL = nullptr; // Finally, emit all the instructions, in order. - for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) - for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); - I != E; ++I) { - writeInstruction(*I, InstID, Vals); + for (const BasicBlock &BB : F) + for (const Instruction &I : BB) { + writeInstruction(I, InstID, Vals); - if (!I->getType()->isVoidTy()) + if (!I.getType()->isVoidTy()) ++InstID; // If the instruction has metadata, write a metadata attachment later. - NeedsMetadataAttachment |= I->hasMetadataOtherThanDebugLoc(); + NeedsMetadataAttachment |= I.hasMetadataOtherThanDebugLoc(); // If the instruction has a debug location, emit it. - DILocation *DL = I->getDebugLoc(); + DILocation *DL = I.getDebugLoc(); if (!DL) continue; @@ -4429,9 +4427,9 @@ void ModuleBitcodeWriter::write() { // Emit function bodies. DenseMap FunctionToBitcodeIndex; - for (Module::const_iterator F = M.begin(), E = M.end(); F != E; ++F) - if (!F->isDeclaration()) - writeFunction(*F, FunctionToBitcodeIndex); + for (const Function &F : M) + if (!F.isDeclaration()) + writeFunction(F, FunctionToBitcodeIndex); // Need to write after the above call to WriteFunction which populates // the summary information in the index. diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp index 9465a3b..07e0708 100644 --- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -1148,8 +1148,8 @@ void ValueEnumerator::purgeFunction() { ValueMap.erase(Values[i].first); for (unsigned i = NumModuleMDs, e = MDs.size(); i != e; ++i) MetadataMap.erase(MDs[i]); - for (unsigned i = 0, e = BasicBlocks.size(); i != e; ++i) - ValueMap.erase(BasicBlocks[i]); + for (const BasicBlock *BB : BasicBlocks) + ValueMap.erase(BB); Values.resize(NumModuleValues); MDs.resize(NumModuleMDs); diff --git a/llvm/lib/CodeGen/AggressiveAntiDepBreaker.cpp b/llvm/lib/CodeGen/AggressiveAntiDepBreaker.cpp index 87a3ced..ca8bb63 100644 --- a/llvm/lib/CodeGen/AggressiveAntiDepBreaker.cpp +++ b/llvm/lib/CodeGen/AggressiveAntiDepBreaker.cpp @@ -762,11 +762,8 @@ unsigned AggressiveAntiDepBreaker::BreakAntiDependencies( // ...need a map from MI to SUnit. std::map MISUnitMap; - for (unsigned i = 0, e = SUnits.size(); i != e; ++i) { - const SUnit *SU = &SUnits[i]; - MISUnitMap.insert(std::pair(SU->getInstr(), - SU)); - } + for (const SUnit &SU : SUnits) + MISUnitMap.insert(std::make_pair(SU.getInstr(), &SU)); // Track progress along the critical path through the SUnit graph as // we walk the instructions. This is needed for regclasses that only @@ -774,12 +771,11 @@ unsigned AggressiveAntiDepBreaker::BreakAntiDependencies( const SUnit *CriticalPathSU = nullptr; MachineInstr *CriticalPathMI = nullptr; if (CriticalPathSet.any()) { - for (unsigned i = 0, e = SUnits.size(); i != e; ++i) { - const SUnit *SU = &SUnits[i]; + for (const SUnit &SU : SUnits) { if (!CriticalPathSU || - ((SU->getDepth() + SU->Latency) > + ((SU.getDepth() + SU.Latency) > (CriticalPathSU->getDepth() + CriticalPathSU->Latency))) { - CriticalPathSU = SU; + CriticalPathSU = &SU; } } assert(CriticalPathSU && "Failed to find SUnit critical path"); @@ -839,8 +835,7 @@ unsigned AggressiveAntiDepBreaker::BreakAntiDependencies( // but don't cause any anti-dependence breaking themselves) if (!MI.isKill()) { // Attempt to break each anti-dependency... - for (unsigned i = 0, e = Edges.size(); i != e; ++i) { - const SDep *Edge = Edges[i]; + for (const SDep *Edge : Edges) { SUnit *NextSU = Edge->getSUnit(); if ((Edge->getKind() != SDep::Anti) && diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index cc848d2..66771a3 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -809,9 +809,9 @@ void AsmPrinter::emitFunctionHeader() { // so that we don't get references to undefined symbols. std::vector DeadBlockSyms; MMI->takeDeletedSymbolsForFunction(&F, DeadBlockSyms); - for (unsigned i = 0, e = DeadBlockSyms.size(); i != e; ++i) { + for (MCSymbol *DeadBlockSym : DeadBlockSyms) { OutStreamer->AddComment("Address taken block that was later removed"); - OutStreamer->emitLabel(DeadBlockSyms[i]); + OutStreamer->emitLabel(DeadBlockSym); } if (CurrentFnBegin) { @@ -2150,8 +2150,7 @@ void AsmPrinter::emitJumpTableInfo() { SmallPtrSet EmittedSets; const TargetLowering *TLI = MF->getSubtarget().getTargetLowering(); const MCExpr *Base = TLI->getPICJumpTableRelocBaseExpr(MF,JTI,OutContext); - for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) { - const MachineBasicBlock *MBB = JTBBs[ii]; + for (const MachineBasicBlock *MBB : JTBBs) { if (!EmittedSets.insert(MBB).second) continue; @@ -2177,8 +2176,8 @@ void AsmPrinter::emitJumpTableInfo() { MCSymbol* JTISymbol = GetJTISymbol(JTI); OutStreamer->emitLabel(JTISymbol); - for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) - emitJumpTableEntry(MJTI, JTBBs[ii], JTI); + for (const MachineBasicBlock *MBB : JTBBs) + emitJumpTableEntry(MJTI, MBB, JTI); } if (!JTInDiffSection) OutStreamer->emitDataRegion(MCDR_DataRegionEnd); -- 2.7.4