[llvm-commits] [llvm] r94155 - in /llvm/trunk: include/llvm/Analysis/LoopPass.h include/llvm/Pass.h include/llvm/PassManagers.h lib/Analysis/IPA/CallGraphSCCPass.cpp lib/VMCore/PassManager.cpp
Chris Lattner
sabre at nondot.org
Thu Jan 21 21:24:53 PST 2010
Author: lattner
Date: Thu Jan 21 23:24:46 2010
New Revision: 94155
URL: http://llvm.org/viewvc/llvm-project?rev=94155&view=rev
Log:
eliminate a bunch of dynamic_cast's.
Modified:
llvm/trunk/include/llvm/Analysis/LoopPass.h
llvm/trunk/include/llvm/Pass.h
llvm/trunk/include/llvm/PassManagers.h
llvm/trunk/lib/Analysis/IPA/CallGraphSCCPass.cpp
llvm/trunk/lib/VMCore/PassManager.cpp
Modified: llvm/trunk/include/llvm/Analysis/LoopPass.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopPass.h?rev=94155&r1=94154&r2=94155&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LoopPass.h (original)
+++ llvm/trunk/include/llvm/Analysis/LoopPass.h Thu Jan 21 23:24:46 2010
@@ -94,6 +94,9 @@
return "Loop Pass Manager";
}
+ virtual PMDataManager *getAsPMDataManager() { return this; }
+ virtual Pass *getAsPass() { return this; }
+
/// Print passes managed by this manager
void dumpPassStructure(unsigned Offset);
Modified: llvm/trunk/include/llvm/Pass.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Pass.h?rev=94155&r1=94154&r2=94155&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Pass.h (original)
+++ llvm/trunk/include/llvm/Pass.h Thu Jan 21 23:24:46 2010
@@ -153,6 +153,7 @@
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.
Modified: llvm/trunk/include/llvm/PassManagers.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/PassManagers.h?rev=94155&r1=94154&r2=94155&view=diff
==============================================================================
--- llvm/trunk/include/llvm/PassManagers.h (original)
+++ llvm/trunk/include/llvm/PassManagers.h Thu Jan 21 23:24:46 2010
@@ -273,6 +273,8 @@
}
virtual ~PMDataManager();
+
+ virtual Pass *getAsPass() = 0;
/// Augment AvailableAnalysis by adding analysis made available by pass P.
void recordAvailableAnalysis(Pass *P);
@@ -413,7 +415,6 @@
/// function.
class FPPassManager : public ModulePass, public PMDataManager {
-
public:
static char ID;
explicit FPPassManager(int Depth)
@@ -435,6 +436,9 @@
///
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();
Modified: llvm/trunk/lib/Analysis/IPA/CallGraphSCCPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IPA/CallGraphSCCPass.cpp?rev=94155&r1=94154&r2=94155&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/IPA/CallGraphSCCPass.cpp (original)
+++ llvm/trunk/lib/Analysis/IPA/CallGraphSCCPass.cpp Thu Jan 21 23:24:46 2010
@@ -57,6 +57,9 @@
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";
Modified: llvm/trunk/lib/VMCore/PassManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/PassManager.cpp?rev=94155&r1=94154&r2=94155&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/PassManager.cpp (original)
+++ llvm/trunk/lib/VMCore/PassManager.cpp Thu Jan 21 23:24:46 2010
@@ -127,6 +127,9 @@
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 @@
///
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 @@
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 @@
}
}
+ 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 @@
/// 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 @@
// 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 @@
// 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::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::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");
More information about the llvm-commits
mailing list