eliminate a bunch of dynamic_cast's.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94155 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2010-01-22 05:24:46 +00:00
parent 5e664b8f7c
commit 3660ecabbb
5 changed files with 32 additions and 8 deletions

View File

@ -94,6 +94,9 @@ public:
return "Loop Pass Manager";
}
virtual PMDataManager *getAsPMDataManager() { return this; }
virtual Pass *getAsPass() { return this; }
/// Print passes managed by this manager
void dumpPassStructure(unsigned Offset);

View File

@ -153,6 +153,7 @@ public:
return this;
}
virtual ImmutablePass *getAsImmutablePass() { return 0; }
virtual PMDataManager *getAsPMDataManager() { return 0; }
/// verifyAnalysis() - This member can be implemented by a analysis pass to
/// check state of analysis information.

View File

@ -273,6 +273,8 @@ public:
}
virtual ~PMDataManager();
virtual Pass *getAsPass() = 0;
/// Augment AvailableAnalysis by adding analysis made available by pass P.
void recordAvailableAnalysis(Pass *P);
@ -413,7 +415,6 @@ private:
/// function.
class FPPassManager : public ModulePass, public PMDataManager {
public:
static char ID;
explicit FPPassManager(int Depth)
@ -435,6 +436,9 @@ public:
///
bool doFinalization(Module &M);
virtual PMDataManager *getAsPMDataManager() { return this; }
virtual Pass *getAsPass() { return this; }
/// Pass Manager itself does not invalidate any analysis info.
void getAnalysisUsage(AnalysisUsage &Info) const {
Info.setPreservesAll();

View File

@ -57,6 +57,9 @@ public:
return "CallGraph Pass Manager";
}
virtual PMDataManager *getAsPMDataManager() { return this; }
virtual Pass *getAsPass() { return this; }
// Print passes managed by this manager
void dumpPassStructure(unsigned Offset) {
errs().indent(Offset*2) << "Call Graph SCC Pass Manager\n";

View File

@ -127,6 +127,9 @@ public:
bool doFinalization(Module &M);
bool doFinalization(Function &F);
virtual PMDataManager *getAsPMDataManager() { return this; }
virtual Pass *getAsPass() { return this; }
virtual const char *getPassName() const {
return "BasicBlock Pass Manager";
}
@ -196,6 +199,10 @@ public:
///
bool doFinalization(Module &M);
virtual PMDataManager *getAsPMDataManager() { return this; }
virtual Pass *getAsPass() { return this; }
/// Pass Manager itself does not invalidate any analysis info.
void getAnalysisUsage(AnalysisUsage &Info) const {
Info.setPreservesAll();
@ -269,6 +276,9 @@ public:
return "Module Pass Manager";
}
virtual PMDataManager *getAsPMDataManager() { return this; }
virtual Pass *getAsPass() { return this; }
// Print passes managed by this manager
void dumpPassStructure(unsigned Offset) {
llvm::dbgs() << std::string(Offset*2, ' ') << "ModulePass Manager\n";
@ -344,6 +354,9 @@ public:
}
}
virtual PMDataManager *getAsPMDataManager() { return this; }
virtual Pass *getAsPass() { return this; }
MPPassManager *getContainedManager(unsigned N) {
assert(N < PassManagers.size() && "Pass number out of range!");
MPPassManager *MP = static_cast<MPPassManager *>(PassManagers[N]);
@ -387,7 +400,7 @@ public:
/// passStarted - This method creates a timer for the given pass if it doesn't
/// already have one, and starts the timer.
Timer *passStarted(Pass *P) {
if (dynamic_cast<PMDataManager *>(P))
if (P->getAsPMDataManager())
return 0;
sys::SmartScopedLock<true> Lock(*TimingInfoMutex);
@ -581,11 +594,11 @@ void PMTopLevelManager::dumpPasses() const {
// Every class that derives from PMDataManager also derives from Pass
// (sometimes indirectly), but there's no inheritance relationship
// between PMDataManager and Pass, so we have to dynamic_cast to get
// between PMDataManager and Pass, so we have to getAsPass to get
// from a PMDataManager* to a Pass*.
for (SmallVector<PMDataManager *, 8>::const_iterator I = PassManagers.begin(),
E = PassManagers.end(); I != E; ++I)
dynamic_cast<Pass *>(*I)->dumpPassStructure(1);
(*I)->getAsPass()->dumpPassStructure(1);
}
void PMTopLevelManager::dumpArguments() const {
@ -851,12 +864,12 @@ void PMDataManager::add(Pass *P, bool ProcessAnalysis) {
// Set P as P's last user until someone starts using P.
// However, if P is a Pass Manager then it does not need
// to record its last user.
if (!dynamic_cast<PMDataManager *>(P))
if (P->getAsPMDataManager() == 0)
LastUses.push_back(P);
TPM->setLastUser(LastUses, P);
if (!TransferLastUses.empty()) {
Pass *My_PM = dynamic_cast<Pass *>(this);
Pass *My_PM = getAsPass();
TPM->setLastUser(TransferLastUses, My_PM);
TransferLastUses.clear();
}
@ -965,7 +978,7 @@ void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{
void PMDataManager::dumpPassArguments() const {
for (SmallVector<Pass *, 8>::const_iterator I = PassVector.begin(),
E = PassVector.end(); I != E; ++I) {
if (PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I))
if (PMDataManager *PMD = (*I)->getAsPMDataManager())
PMD->dumpPassArguments();
else
if (const PassInfo *PI = (*I)->getPassInfo())
@ -1583,7 +1596,7 @@ void PMStack::push(PMDataManager *PM) {
void PMStack::dump() {
for (std::deque<PMDataManager *>::iterator I = S.begin(),
E = S.end(); I != E; ++I)
printf("%s ", dynamic_cast<Pass *>(*I)->getPassName());
printf("%s ", (*I)->getAsPass()->getPassName());
if (!S.empty())
printf("\n");