[llvm] r307902 - [PM] Use range-based for loops in LegacyPassManager.cpp (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 13 03:52:01 PDT 2017
Author: fhahn
Date: Thu Jul 13 03:52:00 2017
New Revision: 307902
URL: http://llvm.org/viewvc/llvm-project?rev=307902&view=rev
Log:
[PM] Use range-based for loops in LegacyPassManager.cpp (NFC).
Summary:
This patch replaces a bunch of iterator-based for loops with range-based
for loops. There are 2 iterator-based loops left in this file in
removeNotPreservedAnalysis, but I think those cannot be replaced by
range-based for loops as they modify the container they are iterating
over.
Unless I missed something, this schould be a NFC and I would appreciate
if someone could have a quick look to confirm that.
Reviewers: chandlerc, pcc, jhenderson
Reviewed By: jhenderson
Subscribers: llvm-commits, mehdi_amini
Differential Revision: https://reviews.llvm.org/D35310
Modified:
llvm/trunk/lib/IR/LegacyPassManager.cpp
Modified: llvm/trunk/lib/IR/LegacyPassManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LegacyPassManager.cpp?rev=307902&r1=307901&r2=307902&view=diff
==============================================================================
--- llvm/trunk/lib/IR/LegacyPassManager.cpp (original)
+++ llvm/trunk/lib/IR/LegacyPassManager.cpp Thu Jul 13 03:52:00 2017
@@ -625,21 +625,21 @@ void PMTopLevelManager::schedulePass(Pas
checkAnalysis = false;
const AnalysisUsage::VectorType &RequiredSet = AnUsage->getRequiredSet();
- for (AnalysisUsage::VectorType::const_iterator I = RequiredSet.begin(),
- E = RequiredSet.end(); I != E; ++I) {
+ for (const AnalysisID ID : RequiredSet) {
- Pass *AnalysisPass = findAnalysisPass(*I);
+ Pass *AnalysisPass = findAnalysisPass(ID);
if (!AnalysisPass) {
- const PassInfo *PI = findAnalysisPassInfo(*I);
+ const PassInfo *PI = findAnalysisPassInfo(ID);
if (!PI) {
// Pass P is not in the global PassRegistry
dbgs() << "Pass '" << P->getPassName() << "' is not initialized." << "\n";
dbgs() << "Verify if there is a pass dependency cycle." << "\n";
dbgs() << "Required Passes:" << "\n";
- for (AnalysisUsage::VectorType::const_iterator I2 = RequiredSet.begin(),
- E = RequiredSet.end(); I2 != E && I2 != I; ++I2) {
- Pass *AnalysisPass2 = findAnalysisPass(*I2);
+ for (const AnalysisID ID2 : RequiredSet) {
+ if (ID == ID2)
+ break;
+ Pass *AnalysisPass2 = findAnalysisPass(ID2);
if (AnalysisPass2) {
dbgs() << "\t" << AnalysisPass2->getPassName() << "\n";
} else {
@@ -1070,17 +1070,15 @@ void PMDataManager::collectRequiredAndUs
void PMDataManager::initializeAnalysisImpl(Pass *P) {
AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
- for (AnalysisUsage::VectorType::const_iterator
- I = AnUsage->getRequiredSet().begin(),
- E = AnUsage->getRequiredSet().end(); I != E; ++I) {
- Pass *Impl = findAnalysisPass(*I, true);
+ for (const AnalysisID ID : AnUsage->getRequiredSet()) {
+ Pass *Impl = findAnalysisPass(ID, true);
if (!Impl)
// This may be analysis pass that is initialized on the fly.
// If that is not the case then it will raise an assert when it is used.
continue;
AnalysisResolver *AR = P->getResolver();
assert(AR && "Analysis Resolver is not set");
- AR->addAnalysisImplsPair(*I, Impl);
+ AR->addAnalysisImplsPair(ID, Impl);
}
}
@@ -1112,21 +1110,19 @@ void PMDataManager::dumpLastUses(Pass *P
TPM->collectLastUses(LUses, P);
- for (SmallVectorImpl<Pass *>::iterator I = LUses.begin(),
- E = LUses.end(); I != E; ++I) {
+ for (Pass *P : LUses) {
dbgs() << "--" << std::string(Offset*2, ' ');
- (*I)->dumpPassStructure(0);
+ P->dumpPassStructure(0);
}
}
void PMDataManager::dumpPassArguments() const {
- for (SmallVectorImpl<Pass *>::const_iterator I = PassVector.begin(),
- E = PassVector.end(); I != E; ++I) {
- if (PMDataManager *PMD = (*I)->getAsPMDataManager())
+ for (Pass *P : PassVector) {
+ if (PMDataManager *PMD = P->getAsPMDataManager())
PMD->dumpPassArguments();
else
if (const PassInfo *PI =
- TPM->findAnalysisPassInfo((*I)->getPassID()))
+ TPM->findAnalysisPassInfo(P->getPassID()))
if (!PI->isAnalysisGroup())
dbgs() << " -" << PI->getPassArgument();
}
@@ -1255,9 +1251,8 @@ Pass *PMDataManager::getOnTheFlyPass(Pas
// Destructor
PMDataManager::~PMDataManager() {
- for (SmallVectorImpl<Pass *>::iterator I = PassVector.begin(),
- E = PassVector.end(); I != E; ++I)
- delete *I;
+ for (Pass *P : PassVector)
+ delete P;
}
//===----------------------------------------------------------------------===//
@@ -1284,35 +1279,35 @@ bool BBPassManager::runOnFunction(Functi
bool Changed = doInitialization(F);
- for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
+ for (BasicBlock &BB : F)
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
BasicBlockPass *BP = getContainedPass(Index);
bool LocalChanged = false;
- dumpPassInfo(BP, EXECUTION_MSG, ON_BASICBLOCK_MSG, I->getName());
+ dumpPassInfo(BP, EXECUTION_MSG, ON_BASICBLOCK_MSG, BB.getName());
dumpRequiredSet(BP);
initializeAnalysisImpl(BP);
{
// If the pass crashes, remember this.
- PassManagerPrettyStackEntry X(BP, *I);
+ PassManagerPrettyStackEntry X(BP, BB);
TimeRegion PassTimer(getPassTimer(BP));
- LocalChanged |= BP->runOnBasicBlock(*I);
+ LocalChanged |= BP->runOnBasicBlock(BB);
}
Changed |= LocalChanged;
if (LocalChanged)
dumpPassInfo(BP, MODIFICATION_MSG, ON_BASICBLOCK_MSG,
- I->getName());
+ BB.getName());
dumpPreservedSet(BP);
dumpUsedSet(BP);
verifyPreservedAnalysis(BP);
removeNotPreservedAnalysis(BP);
recordAvailableAnalysis(BP);
- removeDeadPasses(BP, I->getName(), ON_BASICBLOCK_MSG);
+ removeDeadPasses(BP, BB.getName(), ON_BASICBLOCK_MSG);
}
return doFinalization(F) || Changed;
More information about the llvm-commits
mailing list