summaryrefslogtreecommitdiff
path: root/include/llvm/Pass.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-08-21 22:13:33 +0000
committerChris Lattner <sabre@nondot.org>2002-08-21 22:13:33 +0000
commit1d63a167ecf964d00d2865fec182f1d67e7e3f36 (patch)
treefa3552cbcb4587f495647e05207952969c414153 /include/llvm/Pass.h
parentb63b29d9b030beb00df59bc9f0d80f90cdfc6aab (diff)
downloadllvm-1d63a167ecf964d00d2865fec182f1d67e7e3f36.tar.gz
llvm-1d63a167ecf964d00d2865fec182f1d67e7e3f36.tar.bz2
llvm-1d63a167ecf964d00d2865fec182f1d67e7e3f36.tar.xz
- Make Pass::lookupPassInfo a public member
- Fix Pass::getAnalysis<AnalysisType>() to use dynamic_cast instead of a static cast to handle the case where the cast from & two classes are not related via inheritance. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3423 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Pass.h')
-rw-r--r--include/llvm/Pass.h16
1 files changed, 13 insertions, 3 deletions
diff --git a/include/llvm/Pass.h b/include/llvm/Pass.h
index 5b55e0dba1..eaa8fda71c 100644
--- a/include/llvm/Pass.h
+++ b/include/llvm/Pass.h
@@ -38,7 +38,6 @@ struct AnalysisResolver;
// AnalysisID - Use the PassInfo to identify a pass...
typedef const PassInfo* AnalysisID;
-
//===----------------------------------------------------------------------===//
// Pass interface - Implemented by all 'passes'. Subclass this if you are an
// interprocedural optimization or you do not fit into any of the more
@@ -109,17 +108,19 @@ public:
// dumpPassStructure - Implement the -debug-passes=PassStructure option
virtual void dumpPassStructure(unsigned Offset = 0);
+
// getPassInfo - Static method to get the pass information from a class name.
template<typename AnalysisClass>
static const PassInfo *getClassPassInfo() {
return lookupPassInfo(typeid(AnalysisClass));
}
-protected:
// lookupPassInfo - Return the pass info object for the specified pass class,
// or null if it is not known.
static const PassInfo *lookupPassInfo(const std::type_info &TI);
+protected:
+
// getAnalysis<AnalysisType>() - This function is used by subclasses to get to
// the analysis information that they claim to use by overriding the
// getAnalysisUsage function.
@@ -129,7 +130,16 @@ protected:
assert(Resolver && "Pass has not been inserted into a PassManager object!");
const PassInfo *PI = getClassPassInfo<AnalysisType>();
assert(PI && "getAnalysis for unregistered pass!");
- return *(AnalysisType*)Resolver->getAnalysis(PI);
+
+ // Because the AnalysisType may not be a subclass of pass (for
+ // AnalysisGroups), we must use dynamic_cast here to potentially adjust the
+ // return pointer (because the class may multiply inherit, once from pass,
+ // once from AnalysisType).
+ //
+ AnalysisType *Result =
+ dynamic_cast<AnalysisType*>(Resolver->getAnalysis(PI));
+ assert(Result && "Pass does not implement interface required!");
+ return *Result;
}
template<typename AnalysisType>