From b4bed1cb245b04ed6ed50b5d68d928e9e9f216f7 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 28 Feb 2021 10:59:23 -0800 Subject: [PATCH] [IR] Use range-based for loops (NFC) --- llvm/include/llvm/IR/LegacyPassManagers.h | 9 ++++----- llvm/lib/IR/AsmWriter.cpp | 14 ++++++-------- llvm/lib/IR/DebugInfo.cpp | 12 ++++-------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/llvm/include/llvm/IR/LegacyPassManagers.h b/llvm/include/llvm/IR/LegacyPassManagers.h index f4fae18..0bcb408 100644 --- a/llvm/include/llvm/IR/LegacyPassManagers.h +++ b/llvm/include/llvm/IR/LegacyPassManagers.h @@ -335,8 +335,8 @@ public: /// Initialize available analysis information. void initializeAnalysisInfo() { AvailableAnalysis.clear(); - for (unsigned i = 0; i < PMT_Last; ++i) - InheritedAnalysis[i] = nullptr; + for (auto &IA : InheritedAnalysis) + IA = nullptr; } // Return true if P preserves high level analysis used by other @@ -392,9 +392,8 @@ public: // Collect AvailableAnalysis from all the active Pass Managers. void populateInheritedAnalysis(PMStack &PMS) { unsigned Index = 0; - for (PMStack::iterator I = PMS.begin(), E = PMS.end(); - I != E; ++I) - InheritedAnalysis[Index++] = (*I)->getAvailableAnalysis(); + for (PMDataManager *PMDM : PMS) + InheritedAnalysis[Index++] = PMDM->getAvailableAnalysis(); } /// Set the initial size of the module if the user has specified that they diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index 642ecc9..43aba4e 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -1088,9 +1088,8 @@ int SlotTracker::processIndex() { // Start numbering the TypeIds after the GUIDs. TypeIdNext = GUIDNext; - for (auto TidIter = TheIndex->typeIds().begin(); - TidIter != TheIndex->typeIds().end(); TidIter++) - CreateTypeIdSlot(TidIter->second.first); + for (const auto &TID : TheIndex->typeIds()) + CreateTypeIdSlot(TID.second.first); ST_DEBUG("end processIndex!\n"); return TypeIdNext; @@ -4028,8 +4027,8 @@ void AssemblyWriter::printInstruction(const Instruction &I) { Out << ' '; writeOperand(I.getOperand(0), true); Out << ", "; writeOperand(I.getOperand(1), true); - for (const unsigned *i = IVI->idx_begin(), *e = IVI->idx_end(); i != e; ++i) - Out << ", " << *i; + for (unsigned i : IVI->indices()) + Out << ", " << i; } else if (const LandingPadInst *LPI = dyn_cast(&I)) { Out << ' '; TypePrinter.print(I.getType(), Out); @@ -4431,9 +4430,8 @@ void AssemblyWriter::writeAllAttributeGroups() { std::vector> asVec; asVec.resize(Machine.as_size()); - for (SlotTracker::as_iterator I = Machine.as_begin(), E = Machine.as_end(); - I != E; ++I) - asVec[I->second] = *I; + for (auto &I : llvm::make_range(Machine.as_begin(), Machine.as_end())) + asVec[I.second] = I; for (const auto &I : asVec) Out << "attributes #" << I.second << " = { " diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 3413447..fec98f5 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -353,16 +353,12 @@ bool llvm::stripDebugInfo(Function &F) { bool llvm::StripDebugInfo(Module &M) { bool Changed = false; - for (Module::named_metadata_iterator NMI = M.named_metadata_begin(), - NME = M.named_metadata_end(); NMI != NME;) { - NamedMDNode *NMD = &*NMI; - ++NMI; - + for (NamedMDNode &NMD : llvm::make_early_inc_range(M.named_metadata())) { // We're stripping debug info, and without them, coverage information // doesn't quite make sense. - if (NMD->getName().startswith("llvm.dbg.") || - NMD->getName() == "llvm.gcov") { - NMD->eraseFromParent(); + if (NMD.getName().startswith("llvm.dbg.") || + NMD.getName() == "llvm.gcov") { + NMD.eraseFromParent(); Changed = true; } } -- 2.7.4