eliminate dynamic_cast from the pass manager.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94060 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2010-01-21 02:07:07 +00:00
parent ed1a4c7eab
commit ac8b4bf66b

View File

@@ -19,15 +19,13 @@
#ifndef LLVM_PASS_ANALYSIS_SUPPORT_H #ifndef LLVM_PASS_ANALYSIS_SUPPORT_H
#define LLVM_PASS_ANALYSIS_SUPPORT_H #define LLVM_PASS_ANALYSIS_SUPPORT_H
#include <vector>
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringRef.h"
#include <vector>
namespace llvm { namespace llvm {
class StringRef;
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// AnalysisUsage - Represent the analysis usage information of a pass. This // AnalysisUsage - Represent the analysis usage information of a pass. This
// tracks analyses that the pass REQUIRES (must be available when the pass // tracks analyses that the pass REQUIRES (must be available when the pass
@@ -192,8 +190,15 @@ AnalysisType *Pass::getAnalysisIfAvailable() const {
const PassInfo *PI = getClassPassInfo<AnalysisType>(); const PassInfo *PI = getClassPassInfo<AnalysisType>();
if (PI == 0) return 0; if (PI == 0) return 0;
return dynamic_cast<AnalysisType*>
(Resolver->getAnalysisIfAvailable(PI, true)); Pass *ResultPass = Resolver->getAnalysisIfAvailable(PI, true);
if (ResultPass == 0) return 0;
// Because the AnalysisType may not be a subclass of pass (for
// AnalysisGroups), we use getAdjustedAnalysisPointer here to potentially
// adjust the return pointer (because the class may multiply inherit, once
// from pass, once from AnalysisType).
return (AnalysisType*)ResultPass->getAdjustedAnalysisPointer(PI);
} }
/// getAnalysis<AnalysisType>() - This function is used by subclasses to get /// getAnalysis<AnalysisType>() - This function is used by subclasses to get
@@ -202,8 +207,7 @@ AnalysisType *Pass::getAnalysisIfAvailable() const {
/// ///
template<typename AnalysisType> template<typename AnalysisType>
AnalysisType &Pass::getAnalysis() const { AnalysisType &Pass::getAnalysis() const {
assert(Resolver &&"Pass has not been inserted into a PassManager object!"); assert(Resolver && "Pass has not been inserted into a PassManager object!");
return getAnalysisID<AnalysisType>(getClassPassInfo<AnalysisType>()); return getAnalysisID<AnalysisType>(getClassPassInfo<AnalysisType>());
} }
@@ -220,13 +224,10 @@ AnalysisType &Pass::getAnalysisID(const PassInfo *PI) const {
"'required' by pass!"); "'required' by pass!");
// Because the AnalysisType may not be a subclass of pass (for // Because the AnalysisType may not be a subclass of pass (for
// AnalysisGroups), we must use dynamic_cast here to potentially adjust the // AnalysisGroups), we use getAdjustedAnalysisPointer here to potentially
// return pointer (because the class may multiply inherit, once from pass, // adjust the return pointer (because the class may multiply inherit, once
// once from AnalysisType). // from pass, once from AnalysisType).
// return *(AnalysisType*)ResultPass->getAdjustedAnalysisPointer(PI);
AnalysisType *Result = dynamic_cast<AnalysisType*>(ResultPass);
assert(Result && "Pass does not implement interface required!");
return *Result;
} }
/// getAnalysis<AnalysisType>() - This function is used by subclasses to get /// getAnalysis<AnalysisType>() - This function is used by subclasses to get
@@ -248,16 +249,13 @@ AnalysisType &Pass::getAnalysisID(const PassInfo *PI, Function &F) {
// should be a small number, we just do a linear search over a (dense) // should be a small number, we just do a linear search over a (dense)
// vector. // vector.
Pass *ResultPass = Resolver->findImplPass(this, PI, F); Pass *ResultPass = Resolver->findImplPass(this, PI, F);
assert (ResultPass && "Unable to find requested analysis info"); assert(ResultPass && "Unable to find requested analysis info");
// Because the AnalysisType may not be a subclass of pass (for // Because the AnalysisType may not be a subclass of pass (for
// AnalysisGroups), we must use dynamic_cast here to potentially adjust the // AnalysisGroups), we use getAdjustedAnalysisPointer here to potentially
// return pointer (because the class may multiply inherit, once from pass, // adjust the return pointer (because the class may multiply inherit, once
// once from AnalysisType). // from pass, once from AnalysisType).
// return *(AnalysisType*)ResultPass->getAdjustedAnalysisPointer(PI);
AnalysisType *Result = dynamic_cast<AnalysisType*>(ResultPass);
assert(Result && "Pass does not implement interface required!");
return *Result;
} }
} // End llvm namespace } // End llvm namespace