[LegacyPassManager] Simplify FunctionPass::assignPassManager

And make it clear the parameter PreferredType is unused for FunctionPass.
This commit is contained in:
Fangrui Song 2019-11-28 14:00:12 -08:00
parent 1abd4c94d7
commit 4adddbd8ad
1 changed files with 9 additions and 13 deletions

View File

@ -1786,36 +1786,32 @@ void ModulePass::assignPassManager(PMStack &PMS,
/// Find appropriate Function Pass Manager or Call Graph Pass Manager /// Find appropriate Function Pass Manager or Call Graph Pass Manager
/// in the PM Stack and add self into that manager. /// in the PM Stack and add self into that manager.
void FunctionPass::assignPassManager(PMStack &PMS, void FunctionPass::assignPassManager(PMStack &PMS,
PassManagerType PreferredType) { PassManagerType /*PreferredType*/) {
// Find Function Pass Manager // Find Function Pass Manager
while (PMS.top()->getPassManagerType() > PMT_FunctionPassManager) PMDataManager *PM;
while (PM = PMS.top(), PM->getPassManagerType() > PMT_FunctionPassManager)
PMS.pop(); PMS.pop();
// Create new Function Pass Manager if needed. // Create new Function Pass Manager if needed.
FPPassManager *FPP; if (PM->getPassManagerType() != PMT_FunctionPassManager) {
if (PMS.top()->getPassManagerType() == PMT_FunctionPassManager) {
FPP = (FPPassManager *)PMS.top();
} else {
PMDataManager *PMD = PMS.top();
// [1] Create new Function Pass Manager // [1] Create new Function Pass Manager
FPP = new FPPassManager(); auto *FPP = new FPPassManager;
FPP->populateInheritedAnalysis(PMS); FPP->populateInheritedAnalysis(PMS);
// [2] Set up new manager's top level manager // [2] Set up new manager's top level manager
PMTopLevelManager *TPM = PMD->getTopLevelManager(); PM->getTopLevelManager()->addIndirectPassManager(FPP);
TPM->addIndirectPassManager(FPP);
// [3] Assign manager to manage this new manager. This may create // [3] Assign manager to manage this new manager. This may create
// and push new managers into PMS // and push new managers into PMS
FPP->assignPassManager(PMS, PMD->getPassManagerType()); FPP->assignPassManager(PMS, PM->getPassManagerType());
// [4] Push new manager into PMS // [4] Push new manager into PMS
PMS.push(FPP); PMS.push(FPP);
PM = FPP;
} }
// Assign FPP as the manager of this pass. // Assign FPP as the manager of this pass.
FPP->add(this); PM->add(this);
} }
PassManagerBase::~PassManagerBase() {} PassManagerBase::~PassManagerBase() {}