Reapply r138695. Fix PassManager stack depths.

Patch by Xiaoyi Guo!

llvm-svn: 138737
This commit is contained in:
Andrew Trick 2011-08-29 17:07:00 +00:00
parent d6238f4717
commit 0896621a50
8 changed files with 42 additions and 31 deletions

View File

@ -84,7 +84,7 @@ public:
class LPPassManager : public FunctionPass, public PMDataManager { class LPPassManager : public FunctionPass, public PMDataManager {
public: public:
static char ID; static char ID;
explicit LPPassManager(int Depth); explicit LPPassManager();
/// run - Execute all of the passes scheduled for execution. Keep track of /// run - Execute all of the passes scheduled for execution. Keep track of
/// whether any of the passes modifies the module, and if so, return true. /// whether any of the passes modifies the module, and if so, return true.

View File

@ -88,7 +88,7 @@ class RGPassManager : public FunctionPass, public PMDataManager {
public: public:
static char ID; static char ID;
explicit RGPassManager(int Depth); explicit RGPassManager();
/// @brief Execute all of the passes scheduled for execution. /// @brief Execute all of the passes scheduled for execution.
/// ///

View File

@ -156,7 +156,7 @@ namespace {
(void)new llvm::FindUsedTypes(); (void)new llvm::FindUsedTypes();
(void)new llvm::ScalarEvolution(); (void)new llvm::ScalarEvolution();
((llvm::Function*)0)->viewCFGOnly(); ((llvm::Function*)0)->viewCFGOnly();
llvm::RGPassManager RGM(0); llvm::RGPassManager RGM;
((llvm::RegionPass*)0)->runOnRegion((llvm::Region*)0, RGM); ((llvm::RegionPass*)0)->runOnRegion((llvm::Region*)0, RGM);
llvm::AliasSetTracker X(*(llvm::AliasAnalysis*)0); llvm::AliasSetTracker X(*(llvm::AliasAnalysis*)0);
X.add((llvm::Value*)0, 0, 0); // for -print-alias-sets X.add((llvm::Value*)0, 0, 0); // for -print-alias-sets

View File

@ -263,7 +263,7 @@ private:
class PMDataManager { class PMDataManager {
public: public:
explicit PMDataManager(int Depth) : TPM(NULL), Depth(Depth) { explicit PMDataManager() : TPM(NULL), Depth(0) {
initializeAnalysisInfo(); initializeAnalysisInfo();
} }
@ -333,6 +333,7 @@ public:
void setTopLevelManager(PMTopLevelManager *T) { TPM = T; } void setTopLevelManager(PMTopLevelManager *T) { TPM = T; }
unsigned getDepth() const { return Depth; } unsigned getDepth() const { return Depth; }
void setDepth(unsigned newDepth) { Depth = newDepth; }
// Print routines used by debug-pass // Print routines used by debug-pass
void dumpLastUses(Pass *P, unsigned Offset) const; void dumpLastUses(Pass *P, unsigned Offset) const;
@ -408,8 +409,8 @@ private:
class FPPassManager : public ModulePass, public PMDataManager { class FPPassManager : public ModulePass, public PMDataManager {
public: public:
static char ID; static char ID;
explicit FPPassManager(int Depth) explicit FPPassManager()
: ModulePass(ID), PMDataManager(Depth) { } : ModulePass(ID), PMDataManager() { }
/// run - Execute all of the passes scheduled for execution. Keep track of /// run - Execute all of the passes scheduled for execution. Keep track of
/// whether any of the passes modifies the module, and if so, return true. /// whether any of the passes modifies the module, and if so, return true.

View File

@ -44,8 +44,8 @@ namespace {
class CGPassManager : public ModulePass, public PMDataManager { class CGPassManager : public ModulePass, public PMDataManager {
public: public:
static char ID; static char ID;
explicit CGPassManager(int Depth) explicit CGPassManager()
: ModulePass(ID), PMDataManager(Depth) { } : ModulePass(ID), PMDataManager() { }
/// run - Execute all of the passes scheduled for execution. Keep track of /// run - Execute all of the passes scheduled for execution. Keep track of
/// whether any of the passes modifies the module, and if so, return true. /// whether any of the passes modifies the module, and if so, return true.
@ -543,7 +543,7 @@ void CallGraphSCCPass::assignPassManager(PMStack &PMS,
PMDataManager *PMD = PMS.top(); PMDataManager *PMD = PMS.top();
// [1] Create new Call Graph Pass Manager // [1] Create new Call Graph Pass Manager
CGP = new CGPassManager(PMD->getDepth() + 1); CGP = new CGPassManager();
// [2] Set up new manager's top level manager // [2] Set up new manager's top level manager
PMTopLevelManager *TPM = PMD->getTopLevelManager(); PMTopLevelManager *TPM = PMD->getTopLevelManager();

View File

@ -73,8 +73,8 @@ static void createDebugInfoProbe() {
char LPPassManager::ID = 0; char LPPassManager::ID = 0;
LPPassManager::LPPassManager(int Depth) LPPassManager::LPPassManager()
: FunctionPass(ID), PMDataManager(Depth) { : FunctionPass(ID), PMDataManager() {
skipThisLoop = false; skipThisLoop = false;
redoThisLoop = false; redoThisLoop = false;
LI = NULL; LI = NULL;
@ -357,8 +357,8 @@ void LoopPass::assignPassManager(PMStack &PMS,
assert (!PMS.empty() && "Unable to create Loop Pass Manager"); assert (!PMS.empty() && "Unable to create Loop Pass Manager");
PMDataManager *PMD = PMS.top(); PMDataManager *PMD = PMS.top();
// [1] Create new Call Graph Pass Manager // [1] Create new Loop Pass Manager
LPPM = new LPPassManager(PMD->getDepth() + 1); LPPM = new LPPassManager();
LPPM->populateInheritedAnalysis(PMS); LPPM->populateInheritedAnalysis(PMS);
// [2] Set up new manager's top level manager // [2] Set up new manager's top level manager

View File

@ -27,8 +27,8 @@ using namespace llvm;
char RGPassManager::ID = 0; char RGPassManager::ID = 0;
RGPassManager::RGPassManager(int Depth) RGPassManager::RGPassManager()
: FunctionPass(ID), PMDataManager(Depth) { : FunctionPass(ID), PMDataManager() {
skipThisRegion = false; skipThisRegion = false;
redoThisRegion = false; redoThisRegion = false;
RI = NULL; RI = NULL;
@ -250,7 +250,7 @@ void RegionPass::assignPassManager(PMStack &PMS,
PMDataManager *PMD = PMS.top(); PMDataManager *PMD = PMS.top();
// [1] Create new Region Pass Manager // [1] Create new Region Pass Manager
RGPM = new RGPassManager(PMD->getDepth() + 1); RGPM = new RGPassManager();
RGPM->populateInheritedAnalysis(PMS); RGPM->populateInheritedAnalysis(PMS);
// [2] Set up new manager's top level manager // [2] Set up new manager's top level manager

View File

@ -167,8 +167,8 @@ class BBPassManager : public PMDataManager, public FunctionPass {
public: public:
static char ID; static char ID;
explicit BBPassManager(int Depth) explicit BBPassManager()
: PMDataManager(Depth), FunctionPass(ID) {} : PMDataManager(), FunctionPass(ID) {}
/// Execute all of the passes scheduled for execution. Keep track of /// Execute all of the passes scheduled for execution. Keep track of
/// whether any of the passes modifies the function, and if so, return true. /// whether any of the passes modifies the function, and if so, return true.
@ -228,9 +228,9 @@ private:
bool wasRun; bool wasRun;
public: public:
static char ID; static char ID;
explicit FunctionPassManagerImpl(int Depth) : explicit FunctionPassManagerImpl() :
Pass(PT_PassManager, ID), PMDataManager(Depth), Pass(PT_PassManager, ID), PMDataManager(),
PMTopLevelManager(new FPPassManager(1)), wasRun(false) {} PMTopLevelManager(new FPPassManager()), wasRun(false) {}
/// add - Add a pass to the queue of passes to run. This passes ownership of /// add - Add a pass to the queue of passes to run. This passes ownership of
/// the Pass to the PassManager. When the PassManager is destroyed, the pass /// the Pass to the PassManager. When the PassManager is destroyed, the pass
@ -303,8 +303,8 @@ char FunctionPassManagerImpl::ID = 0;
class MPPassManager : public Pass, public PMDataManager { class MPPassManager : public Pass, public PMDataManager {
public: public:
static char ID; static char ID;
explicit MPPassManager(int Depth) : explicit MPPassManager() :
Pass(PT_PassManager, ID), PMDataManager(Depth) { } Pass(PT_PassManager, ID), PMDataManager() { }
// Delete on the fly managers. // Delete on the fly managers.
virtual ~MPPassManager() { virtual ~MPPassManager() {
@ -388,9 +388,9 @@ class PassManagerImpl : public Pass,
public: public:
static char ID; static char ID;
explicit PassManagerImpl(int Depth) : explicit PassManagerImpl() :
Pass(PT_PassManager, ID), PMDataManager(Depth), Pass(PT_PassManager, ID), PMDataManager(),
PMTopLevelManager(new MPPassManager(1)) {} PMTopLevelManager(new MPPassManager()) {}
/// add - Add a pass to the queue of passes to run. This passes ownership of /// add - Add a pass to the queue of passes to run. This passes ownership of
/// the Pass to the PassManager. When the PassManager is destroyed, the pass /// the Pass to the PassManager. When the PassManager is destroyed, the pass
@ -1340,7 +1340,7 @@ bool BBPassManager::doFinalization(Function &F) {
/// Create new Function pass manager /// Create new Function pass manager
FunctionPassManager::FunctionPassManager(Module *m) : M(m) { FunctionPassManager::FunctionPassManager(Module *m) : M(m) {
FPM = new FunctionPassManagerImpl(0); FPM = new FunctionPassManagerImpl();
// FPM is the top level manager. // FPM is the top level manager.
FPM->setTopLevelManager(FPM); FPM->setTopLevelManager(FPM);
@ -1626,7 +1626,7 @@ void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
FunctionPassManagerImpl *FPP = OnTheFlyManagers[P]; FunctionPassManagerImpl *FPP = OnTheFlyManagers[P];
if (!FPP) { if (!FPP) {
FPP = new FunctionPassManagerImpl(0); FPP = new FunctionPassManagerImpl();
// FPP is the top level manager. // FPP is the top level manager.
FPP->setTopLevelManager(FPP); FPP->setTopLevelManager(FPP);
@ -1677,7 +1677,7 @@ bool PassManagerImpl::run(Module &M) {
/// Create new pass manager /// Create new pass manager
PassManager::PassManager() { PassManager::PassManager() {
PM = new PassManagerImpl(0); PM = new PassManagerImpl();
// PM is the top level manager // PM is the top level manager
PM->setTopLevelManager(PM); PM->setTopLevelManager(PM);
} }
@ -1761,13 +1761,23 @@ void PMStack::pop() {
// Push PM on the stack and set its top level manager. // Push PM on the stack and set its top level manager.
void PMStack::push(PMDataManager *PM) { void PMStack::push(PMDataManager *PM) {
assert(PM && "Unable to push. Pass Manager expected"); assert(PM && "Unable to push. Pass Manager expected");
assert(PM->getDepth()==0 && "Pass Manager depth set too early");
if (!this->empty()) { if (!this->empty()) {
assert(PM->getPassManagerType() > this->top()->getPassManagerType()
&& "pushing bad pass manager to PMStack");
PMTopLevelManager *TPM = this->top()->getTopLevelManager(); PMTopLevelManager *TPM = this->top()->getTopLevelManager();
assert(TPM && "Unable to find top level manager"); assert(TPM && "Unable to find top level manager");
TPM->addIndirectPassManager(PM); TPM->addIndirectPassManager(PM);
PM->setTopLevelManager(TPM); PM->setTopLevelManager(TPM);
PM->setDepth(this->top()->getDepth()+1);
}
else {
assert(PM->getPassManagerType() == PMT_ModulePassManager
|| PM->getPassManagerType() == PMT_FunctionPassManager
&& "pushing bad pass manager to PMStack");
PM->setDepth(1);
} }
S.push_back(PM); S.push_back(PM);
@ -1823,7 +1833,7 @@ void FunctionPass::assignPassManager(PMStack &PMS,
PMDataManager *PMD = PMS.top(); PMDataManager *PMD = PMS.top();
// [1] Create new Function Pass Manager // [1] Create new Function Pass Manager
FPP = new FPPassManager(PMD->getDepth() + 1); 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
@ -1860,7 +1870,7 @@ void BasicBlockPass::assignPassManager(PMStack &PMS,
PMDataManager *PMD = PMS.top(); PMDataManager *PMD = PMS.top();
// [1] Create new Basic Block Manager // [1] Create new Basic Block Manager
BBP = new BBPassManager(PMD->getDepth() + 1); BBP = new BBPassManager();
// [2] Set up new manager's top level manager // [2] Set up new manager's top level manager
// Basic Block Pass Manager does not live by itself // Basic Block Pass Manager does not live by itself