1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

eliminate a bunch of dynamic_cast's.

llvm-svn: 94155
This commit is contained in:
Chris Lattner 2010-01-22 05:24:46 +00:00
parent 997ad42b6d
commit 1bd9c3ec88
5 changed files with 32 additions and 8 deletions

View File

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

View File

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

View File

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

View File

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

View File

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