forked from OSchip/llvm-project
Code refactoring. Move common code into CommonPassManagerImpl :)
llvm-svn: 31667
This commit is contained in:
parent
a98445962d
commit
8cad70de14
|
@ -50,12 +50,27 @@ public:
|
||||||
/// Remove dead passes
|
/// Remove dead passes
|
||||||
void removeDeadPasses() { /* TODO : Implement */ }
|
void removeDeadPasses() { /* TODO : Implement */ }
|
||||||
|
|
||||||
|
/// Add pass P into the PassVector. Update RequiredAnalysis and
|
||||||
|
/// AvailableAnalysis appropriately
|
||||||
|
void addPassToManager (Pass *P);
|
||||||
|
|
||||||
|
inline std::vector<Pass *>::iterator passVectorBegin() {
|
||||||
|
return PassVector.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::vector<Pass *>::iterator passVectorEnd() {
|
||||||
|
return PassVector.end();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Analysis required by the passes managed by this manager
|
// Analysis required by the passes managed by this manager
|
||||||
std::vector<AnalysisID> RequiredAnalysis;
|
std::vector<AnalysisID> RequiredAnalysis;
|
||||||
|
|
||||||
// set of available Analysis
|
// set of available Analysis
|
||||||
std::set<AnalysisID> AvailableAnalysis;
|
std::set<AnalysisID> AvailableAnalysis;
|
||||||
|
|
||||||
|
// Collection of pass that are managed by this manager
|
||||||
|
std::vector<Pass *> PassVector;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// BasicBlockPassManager_New manages BasicBlockPass. It batches all the
|
/// BasicBlockPassManager_New manages BasicBlockPass. It batches all the
|
||||||
|
@ -74,8 +89,6 @@ public:
|
||||||
bool runOnFunction(Function &F);
|
bool runOnFunction(Function &F);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Collection of pass that are managed by this manager
|
|
||||||
std::vector<Pass *> PassVector;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// FunctionPassManagerImpl_New manages FunctionPasses and BasicBlockPassManagers.
|
/// FunctionPassManagerImpl_New manages FunctionPasses and BasicBlockPassManagers.
|
||||||
|
@ -106,9 +119,6 @@ public:
|
||||||
bool runOnModule(Module &M);
|
bool runOnModule(Module &M);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Collection of pass that are manged by this manager
|
|
||||||
std::vector<Pass *> PassVector;
|
|
||||||
|
|
||||||
// Active Pass Managers
|
// Active Pass Managers
|
||||||
BasicBlockPassManager_New *activeBBPassManager;
|
BasicBlockPassManager_New *activeBBPassManager;
|
||||||
};
|
};
|
||||||
|
@ -129,9 +139,6 @@ public:
|
||||||
bool runOnModule(Module &M);
|
bool runOnModule(Module &M);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Collection of pass that are managed by this manager
|
|
||||||
std::vector<Pass *> PassVector;
|
|
||||||
|
|
||||||
// Active Pass Manager
|
// Active Pass Manager
|
||||||
FunctionPassManagerImpl_New *activeFunctionPassManager;
|
FunctionPassManagerImpl_New *activeFunctionPassManager;
|
||||||
};
|
};
|
||||||
|
@ -163,9 +170,6 @@ private:
|
||||||
// Collection of pass managers
|
// Collection of pass managers
|
||||||
std::vector<ModulePassManager_New *> PassManagers;
|
std::vector<ModulePassManager_New *> PassManagers;
|
||||||
|
|
||||||
// Collection of pass that are not yet scheduled
|
|
||||||
std::vector<Pass *> PassVector;
|
|
||||||
|
|
||||||
// Active Pass Manager
|
// Active Pass Manager
|
||||||
ModulePassManager_New *activeManager;
|
ModulePassManager_New *activeManager;
|
||||||
};
|
};
|
||||||
|
@ -243,7 +247,6 @@ void CommonPassManagerImpl::removeNotPreservedAnalysis(Pass *P) {
|
||||||
|
|
||||||
for (std::set<AnalysisID>::iterator I = AvailableAnalysis.begin(),
|
for (std::set<AnalysisID>::iterator I = AvailableAnalysis.begin(),
|
||||||
E = AvailableAnalysis.end(); I != E; ++I ) {
|
E = AvailableAnalysis.end(); I != E; ++I ) {
|
||||||
AnalysisID AID = *I;
|
|
||||||
if (std::find(PreservedSet.begin(), PreservedSet.end(), *I) ==
|
if (std::find(PreservedSet.begin(), PreservedSet.end(), *I) ==
|
||||||
PreservedSet.end()) {
|
PreservedSet.end()) {
|
||||||
// Remove this analysis
|
// Remove this analysis
|
||||||
|
@ -253,6 +256,21 @@ void CommonPassManagerImpl::removeNotPreservedAnalysis(Pass *P) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add pass P into the PassVector. Update RequiredAnalysis and
|
||||||
|
/// AvailableAnalysis appropriately
|
||||||
|
void CommonPassManagerImpl::addPassToManager (Pass *P) {
|
||||||
|
|
||||||
|
// Take a note of analysis required and made available by this pass
|
||||||
|
noteDownRequiredAnalysis(P);
|
||||||
|
noteDownAvailableAnalysis(P);
|
||||||
|
|
||||||
|
// Add pass
|
||||||
|
PassVector.push_back(P);
|
||||||
|
|
||||||
|
// Remove the analysis not preserved by this pass
|
||||||
|
removeNotPreservedAnalysis(P);
|
||||||
|
}
|
||||||
|
|
||||||
/// BasicBlockPassManager implementation
|
/// BasicBlockPassManager implementation
|
||||||
|
|
||||||
/// Add pass P into PassVector and return true. If this pass is not
|
/// Add pass P into PassVector and return true. If this pass is not
|
||||||
|
@ -269,15 +287,7 @@ BasicBlockPassManager_New::addPass(Pass *P) {
|
||||||
if (!manageablePass(P))
|
if (!manageablePass(P))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Take a note of analysis required and made available by this pass
|
addPassToManager (BP);
|
||||||
noteDownRequiredAnalysis(P);
|
|
||||||
noteDownAvailableAnalysis(P);
|
|
||||||
|
|
||||||
// Add pass
|
|
||||||
PassVector.push_back(BP);
|
|
||||||
|
|
||||||
// Remove the analysis not preserved by this pass
|
|
||||||
removeNotPreservedAnalysis(P);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -290,8 +300,8 @@ BasicBlockPassManager_New::runOnFunction(Function &F) {
|
||||||
|
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
|
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
|
||||||
for (std::vector<Pass *>::iterator itr = PassVector.begin(),
|
for (std::vector<Pass *>::iterator itr = passVectorBegin(),
|
||||||
e = PassVector.end(); itr != e; ++itr) {
|
e = passVectorEnd(); itr != e; ++itr) {
|
||||||
Pass *P = *itr;
|
Pass *P = *itr;
|
||||||
BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
|
BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
|
||||||
Changed |= BP->runOnBasicBlock(*I);
|
Changed |= BP->runOnBasicBlock(*I);
|
||||||
|
@ -340,8 +350,7 @@ FunctionPassManagerImpl_New::addPass(Pass *P) {
|
||||||
|| !activeBBPassManager->addPass(BP)) {
|
|| !activeBBPassManager->addPass(BP)) {
|
||||||
|
|
||||||
activeBBPassManager = new BasicBlockPassManager_New();
|
activeBBPassManager = new BasicBlockPassManager_New();
|
||||||
|
addPassToManager(activeBBPassManager);
|
||||||
PassVector.push_back(activeBBPassManager);
|
|
||||||
if (!activeBBPassManager->addPass(BP))
|
if (!activeBBPassManager->addPass(BP))
|
||||||
assert(0 && "Unable to add Pass");
|
assert(0 && "Unable to add Pass");
|
||||||
}
|
}
|
||||||
|
@ -357,15 +366,7 @@ FunctionPassManagerImpl_New::addPass(Pass *P) {
|
||||||
if (!manageablePass(P))
|
if (!manageablePass(P))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Take a note of analysis required and made available by this pass
|
addPassToManager (FP);
|
||||||
noteDownRequiredAnalysis(P);
|
|
||||||
noteDownAvailableAnalysis(P);
|
|
||||||
|
|
||||||
PassVector.push_back(FP);
|
|
||||||
|
|
||||||
// Remove the analysis not preserved by this pass
|
|
||||||
removeNotPreservedAnalysis(P);
|
|
||||||
|
|
||||||
activeBBPassManager = NULL;
|
activeBBPassManager = NULL;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -378,8 +379,8 @@ FunctionPassManagerImpl_New::runOnModule(Module &M) {
|
||||||
|
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
||||||
for (std::vector<Pass *>::iterator itr = PassVector.begin(),
|
for (std::vector<Pass *>::iterator itr = passVectorBegin(),
|
||||||
e = PassVector.end(); itr != e; ++itr) {
|
e = passVectorEnd(); itr != e; ++itr) {
|
||||||
Pass *P = *itr;
|
Pass *P = *itr;
|
||||||
FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
|
FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
|
||||||
Changed |= FP->runOnFunction(*I);
|
Changed |= FP->runOnFunction(*I);
|
||||||
|
@ -405,8 +406,7 @@ ModulePassManager_New::addPass(Pass *P) {
|
||||||
|| !activeFunctionPassManager->addPass(P)) {
|
|| !activeFunctionPassManager->addPass(P)) {
|
||||||
|
|
||||||
activeFunctionPassManager = new FunctionPassManagerImpl_New();
|
activeFunctionPassManager = new FunctionPassManagerImpl_New();
|
||||||
|
addPassToManager(activeFunctionPassManager);
|
||||||
PassVector.push_back(activeFunctionPassManager);
|
|
||||||
if (!activeFunctionPassManager->addPass(FP))
|
if (!activeFunctionPassManager->addPass(FP))
|
||||||
assert(0 && "Unable to add pass");
|
assert(0 && "Unable to add pass");
|
||||||
}
|
}
|
||||||
|
@ -422,15 +422,7 @@ ModulePassManager_New::addPass(Pass *P) {
|
||||||
if (!manageablePass(P))
|
if (!manageablePass(P))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Take a note of analysis required and made available by this pass
|
addPassToManager(MP);
|
||||||
noteDownRequiredAnalysis(P);
|
|
||||||
noteDownAvailableAnalysis(P);
|
|
||||||
|
|
||||||
PassVector.push_back(MP);
|
|
||||||
|
|
||||||
// Remove the analysis not preserved by this pass
|
|
||||||
removeNotPreservedAnalysis(P);
|
|
||||||
|
|
||||||
activeFunctionPassManager = NULL;
|
activeFunctionPassManager = NULL;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -442,8 +434,8 @@ ModulePassManager_New::addPass(Pass *P) {
|
||||||
bool
|
bool
|
||||||
ModulePassManager_New::runOnModule(Module &M) {
|
ModulePassManager_New::runOnModule(Module &M) {
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
for (std::vector<Pass *>::iterator itr = PassVector.begin(),
|
for (std::vector<Pass *>::iterator itr = passVectorBegin(),
|
||||||
e = PassVector.end(); itr != e; ++itr) {
|
e = passVectorEnd(); itr != e; ++itr) {
|
||||||
Pass *P = *itr;
|
Pass *P = *itr;
|
||||||
ModulePass *MP = dynamic_cast<ModulePass*>(P);
|
ModulePass *MP = dynamic_cast<ModulePass*>(P);
|
||||||
Changed |= MP->runOnModule(M);
|
Changed |= MP->runOnModule(M);
|
||||||
|
|
Loading…
Reference in New Issue