- Eliminate the need for analyses to expose an ::ID member.
authorChris Lattner <sabre@nondot.org>
Wed, 21 Aug 2002 17:08:37 +0000 (17:08 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 21 Aug 2002 17:08:37 +0000 (17:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3414 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Pass.h
include/llvm/PassAnalysisSupport.h
lib/VMCore/Pass.cpp

index edd7e738c8d657a5d29824f81b44bfe1856766b5..5b55e0dba1207c944578014d86082e33432953ed 100644 (file)
@@ -25,6 +25,7 @@
 #include <vector>
 #include <map>
 #include <iosfwd>
+#include <typeinfo>
 class Value;
 class BasicBlock;
 class Function;
@@ -108,20 +109,33 @@ 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);
+
   // getAnalysis<AnalysisType>() - This function is used by subclasses to get to
   // the analysis information that they claim to use by overriding the
   // getAnalysisUsage function.
   //
   template<typename AnalysisType>
   AnalysisType &getAnalysis() {
-    assert(Resolver && "Pass not resident in a PassManager object!");
-    return *(AnalysisType*)Resolver->getAnalysis(AnalysisType::ID);
+    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);
   }
 
   template<typename AnalysisType>
   AnalysisType &getAnalysisID(const PassInfo *PI) {
-    assert(Resolver && "Pass not resident in a PassManager object!");
+    assert(Resolver && "Pass has not been inserted into a PassManager object!");
+    assert(PI && "getAnalysis for unregistered pass!");
     return *(AnalysisType*)Resolver->getAnalysis(PI);
   }
 
@@ -134,7 +148,9 @@ protected:
   template<typename AnalysisType>
   AnalysisType *getAnalysisToUpdate() {
     assert(Resolver && "Pass not resident in a PassManager object!");
-    return (AnalysisType*)Resolver->getAnalysisToUpdate(AnalysisType::ID);
+    const PassInfo *PI = getClassPassInfo<AnalysisType>();
+    if (PI == 0) return 0;
+    return (AnalysisType*)Resolver->getAnalysisToUpdate(PI);
   }
 
 
index f04b4a6b468ce8e0fb0d562185ad36168cae376e..43c353d4d9e02cff973036c3520fae0320ff80a9 100644 (file)
@@ -39,7 +39,7 @@ public:
   }
   template<class PassClass>
   AnalysisUsage &addRequired() {
-    Required.push_back(PassClass::ID);
+    Required.push_back(Pass::getClassPassInfo<PassClass>());
     return *this;
   }
 
@@ -53,7 +53,7 @@ public:
 
   template<class PassClass>
   AnalysisUsage &addPreserved() {
-    Preserved.push_back(PassClass::ID);
+    Preserved.push_back(Pass::getClassPassInfo<PassClass>());
     return *this;
   }
 
index 1c54a1b2d19ec7f2f3dc1b5fc78ae4a381cf4568..b6f855d017e7e09371844a361e036e1667518d57 100644 (file)
@@ -11,7 +11,6 @@
 #include "llvm/Module.h"
 #include "Support/STLExtras.h"
 #include "Support/TypeInfo.h"
-#include <typeinfo>
 #include <stdio.h>
 #include <sys/resource.h>
 #include <sys/unistd.h>
@@ -371,8 +370,12 @@ static std::vector<PassRegistrationListener*> *Listeners = 0;
 // pass...
 const PassInfo *Pass::getPassInfo() const {
   if (PassInfoCache) return PassInfoCache;
+  return lookupPassInfo(typeid(*this));
+}
+
+const PassInfo *Pass::lookupPassInfo(const std::type_info &TI) {
   if (PassInfoMap == 0) return 0;
-  std::map<TypeInfo, PassInfo*>::iterator I = PassInfoMap->find(typeid(*this));
+  std::map<TypeInfo, PassInfo*>::iterator I = PassInfoMap->find(TI);
   return (I != PassInfoMap->end()) ? I->second : 0;
 }