From 3660ecabbb85b31308f38938ce3f56f0a330a84b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 22 Jan 2010 05:24:46 +0000 Subject: [PATCH] eliminate a bunch of dynamic_cast's. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94155 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/LoopPass.h | 3 +++ include/llvm/Pass.h | 1 + include/llvm/PassManagers.h | 6 +++++- lib/Analysis/IPA/CallGraphSCCPass.cpp | 3 +++ lib/VMCore/PassManager.cpp | 27 ++++++++++++++++++++------- 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/include/llvm/Analysis/LoopPass.h b/include/llvm/Analysis/LoopPass.h index 2dceccbd307..25488da4579 100644 --- a/include/llvm/Analysis/LoopPass.h +++ b/include/llvm/Analysis/LoopPass.h @@ -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); diff --git a/include/llvm/Pass.h b/include/llvm/Pass.h index 0a53cbf8d08..7bc6295432a 100644 --- a/include/llvm/Pass.h +++ b/include/llvm/Pass.h @@ -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. diff --git a/include/llvm/PassManagers.h b/include/llvm/PassManagers.h index dffc24a41ca..443a9e02d2a 100644 --- a/include/llvm/PassManagers.h +++ b/include/llvm/PassManagers.h @@ -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(); diff --git a/lib/Analysis/IPA/CallGraphSCCPass.cpp b/lib/Analysis/IPA/CallGraphSCCPass.cpp index 5504b9be33a..bb2a2cc8c3c 100644 --- a/lib/Analysis/IPA/CallGraphSCCPass.cpp +++ b/lib/Analysis/IPA/CallGraphSCCPass.cpp @@ -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"; diff --git a/lib/VMCore/PassManager.cpp b/lib/VMCore/PassManager.cpp index 7aa8cb3b010..7b02c933591 100644 --- a/lib/VMCore/PassManager.cpp +++ b/lib/VMCore/PassManager.cpp @@ -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(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(P)) + if (P->getAsPMDataManager()) return 0; sys::SmartScopedLock 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::const_iterator I = PassManagers.begin(), E = PassManagers.end(); I != E; ++I) - dynamic_cast(*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(P)) + if (P->getAsPMDataManager() == 0) LastUses.push_back(P); TPM->setLastUser(LastUses, P); if (!TransferLastUses.empty()) { - Pass *My_PM = dynamic_cast(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::const_iterator I = PassVector.begin(), E = PassVector.end(); I != E; ++I) { - if (PMDataManager *PMD = dynamic_cast(*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::iterator I = S.begin(), E = S.end(); I != E; ++I) - printf("%s ", dynamic_cast(*I)->getPassName()); + printf("%s ", (*I)->getAsPass()->getPassName()); if (!S.empty()) printf("\n");