revert enough of devang's recent patches to get the tree basically working again
authorChris Lattner <sabre@nondot.org>
Wed, 2 May 2007 04:25:31 +0000 (04:25 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 2 May 2007 04:25:31 +0000 (04:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36638 91177308-0d34-0410-b5e6-96231b3b80d8

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

index d678df6430b9da06f789268e9ed10f0df43ab175..b82e4b31c525ffe06b9fd1ee9092bae79fb208c4 100644 (file)
@@ -34,8 +34,8 @@
 #include <deque>
 #include <map>
 #include <iosfwd>
+#include <typeinfo>
 #include <cassert>
-#include <stdint.h>
 
 namespace llvm {
 
@@ -77,7 +77,7 @@ typedef enum PassManagerType PassManagerType;
 ///
 class Pass {
   AnalysisResolver *Resolver;  // Used to resolve analysis
-  intptr_t PassID;
+  const PassInfo *PassInfoCache;
 
   // AnalysisImpls - This keeps track of which passes implement the interfaces
   // that are required by the current pass (to implement getAnalysis()).
@@ -87,7 +87,7 @@ class Pass {
   void operator=(const Pass&);  // DO NOT IMPLEMENT
   Pass(const Pass &);           // DO NOT IMPLEMENT
 public:
-  Pass(intptr_t pid) : Resolver(0), PassID(pid) {}
+  Pass(intptr_t pid = 0) : Resolver(0), PassInfoCache(0) {}
   virtual ~Pass();
 
   /// getPassName - Return a nice clean name for a pass.  This usually
@@ -163,12 +163,12 @@ public:
 
   template<typename AnalysisClass>
   static const PassInfo *getClassPassInfo() {
-    return lookupPassInfo((intptr_t)&AnalysisClass::ID);
+    return lookupPassInfo(typeid(AnalysisClass));
   }
 
   // lookupPassInfo - Return the pass info object for the specified pass class,
   // or null if it is not known.
-  static const PassInfo *lookupPassInfo(intptr_t TI);
+  static const PassInfo *lookupPassInfo(const std::type_info &TI);
 
   /// getAnalysisToUpdate<AnalysisType>() - This function is used by subclasses
   /// to get to the analysis information that might be around that needs to be
@@ -274,7 +274,7 @@ public:
 class FunctionPass : public Pass {
 public:
   FunctionPass(intptr_t pid) : Pass(pid) {}
-
+  
   /// doInitialization - Virtual method overridden by subclasses to do
   /// any necessary per-module initialization.
   ///
@@ -325,7 +325,7 @@ public:
 class BasicBlockPass : public Pass {
 public:
   BasicBlockPass(intptr_t pid) : Pass(pid) {}
-
+  
   /// doInitialization - Virtual method overridden by subclasses to do
   /// any necessary per-module initialization.
   ///
index f594d45f1522b83cd73d288662cf226131ae2b9c..7c3c4a9d660376d9d268b2492f29eaf83b39c939 100644 (file)
@@ -37,19 +37,19 @@ class TargetMachine;
 class PassInfo {
   const char           *PassName;      // Nice name for Pass
   const char           *PassArgument;  // Command Line argument to run this pass
-  intptr_t             PassID;      
+  const std::type_info &TypeInfo;      // type_info object for this Pass class
   bool IsCFGOnlyPass;                  // Pass only looks at the CFG.
   bool IsAnalysisGroup;                // True if an analysis group.
   std::vector<const PassInfo*> ItfImpl;// Interfaces implemented by this pass
 
-  Pass *(*NormalCtor)();
+  Pass *(*NormalCtor)();               // No argument ctor
 
 public:
   /// PassInfo ctor - Do not call this directly, this should only be invoked
   /// through RegisterPass.
-  PassInfo(const char *name, const char *arg, intptr_t pi,
+  PassInfo(const char *name, const char *arg, const std::type_info &ti,
            Pass *(*normal)() = 0, bool isCFGOnly = false)
-    : PassName(name), PassArgument(arg), PassID(pi), 
+    : PassName(name), PassArgument(arg), TypeInfo(ti), 
       IsCFGOnlyPass(isCFGOnly), IsAnalysisGroup(false), NormalCtor(normal) {
   }
 
@@ -65,8 +65,8 @@ public:
   const char *getPassArgument() const { return PassArgument; }
 
   /// getTypeInfo - Return the type_info object for the pass...
-  /// TODO : Rename
-  intptr_t getTypeInfo() const { return PassID; }
+  ///
+  const std::type_info &getTypeInfo() const { return TypeInfo; }
 
   /// isAnalysisGroup - Return true if this is an analysis group, not a normal
   /// pass.
@@ -139,12 +139,12 @@ struct RegisterPassBase {
 
   typedef Pass* (*NormalCtor_t)();
   
-  RegisterPassBase(const char *Name, const char *Arg, intptr_t TI,
+  RegisterPassBase(const char *Name, const char *Arg, const std::type_info &TI,
                    NormalCtor_t NormalCtor = 0, bool CFGOnly = false)
     : PIObj(Name, Arg, TI, NormalCtor, CFGOnly) {
     registerPass();
   }
-  RegisterPassBase(intptr_t TI)
+  RegisterPassBase(const std::type_info &TI)
     : PIObj("", "", TI) {
     // This ctor may only be used for analysis groups: it does not auto-register
     // the pass.
@@ -165,7 +165,7 @@ struct RegisterPass : public RegisterPassBase {
 
   // Register Pass using default constructor...
   RegisterPass(const char *PassArg, const char *Name, bool CFGOnly = false)
-    : RegisterPassBase(Name, PassArg, (intptr_t)&PassName::ID,
+  : RegisterPassBase(Name, PassArg, typeid(PassName),
                      (RegisterPassBase::NormalCtor_t)callDefaultCtor<PassName>, CFGOnly) {
   }
 };
@@ -195,8 +195,8 @@ class RegisterAGBase : public RegisterPassBase {
   const PassInfo *ImplementationInfo;
   bool isDefaultImplementation;
 protected:
-  explicit RegisterAGBase(intptr_t InterfaceID,
-                          intptr_t PassID = 0,
+  explicit RegisterAGBase(const std::type_info &Interface,
+                          const std::type_info *Pass = 0,
                           bool isDefault = false);
   void setGroupName(const char *Name);
 };
@@ -204,12 +204,12 @@ protected:
 template<typename Interface, bool Default = false>
 struct RegisterAnalysisGroup : public RegisterAGBase {
   explicit RegisterAnalysisGroup(RegisterPassBase &RPB)
-    : RegisterAGBase((intptr_t) &Interface::ID, RPB.getPassInfo()->getTypeInfo(),
+    : RegisterAGBase(typeid(Interface), &RPB.getPassInfo()->getTypeInfo(), 
                      Default) {
   }
 
   explicit RegisterAnalysisGroup(const char *Name)
-    : RegisterAGBase((intptr_t) &Interface::ID) {
+  : RegisterAGBase(typeid(Interface)) {
     setGroupName(Name);
   }
 };
index b45f427cbcfdadfa12fb3bbf2bfbe6ee1d3761af..e6b31b302a952dd52ffb694df6b865cd95f87bd3 100644 (file)
@@ -133,7 +133,7 @@ namespace {
 class PassRegistrar {
   /// PassInfoMap - Keep track of the passinfo object for each registered llvm
   /// pass.
-  std::map<intptr_t, PassInfo*> PassInfoMap;
+  std::map<TypeInfo, PassInfo*> PassInfoMap;
   
   /// AnalysisGroupInfo - Keep track of information for each analysis group.
   struct AnalysisGroupInfo {
@@ -147,19 +147,19 @@ class PassRegistrar {
 
 public:
   
-  const PassInfo *GetPassInfo(intptr_t TI) const {
-    std::map<intptr_t, PassInfo*>::const_iterator I = PassInfoMap.find(TI);
+  const PassInfo *GetPassInfo(const std::type_info &TI) const {
+    std::map<TypeInfo, PassInfo*>::const_iterator I = PassInfoMap.find(TI);
     return I != PassInfoMap.end() ? I->second : 0;
   }
   
   void RegisterPass(PassInfo &PI) {
     bool Inserted =
-      PassInfoMap.insert(std::make_pair(PI.getTypeInfo(),&PI)).second;
-    //assert(Inserted && "Pass registered multiple times!");
+      PassInfoMap.insert(std::make_pair(TypeInfo(PI.getTypeInfo()),&PI)).second;
+    assert(Inserted && "Pass registered multiple times!");
   }
   
   void UnregisterPass(PassInfo &PI) {
-    std::map<intptr_t, PassInfo*>::iterator I =
+    std::map<TypeInfo, PassInfo*>::iterator I =
       PassInfoMap.find(PI.getTypeInfo());
     assert(I != PassInfoMap.end() && "Pass registered but not in map!");
     
@@ -168,7 +168,7 @@ public:
   }
   
   void EnumerateWith(PassRegistrationListener *L) {
-    for (std::map<intptr_t, PassInfo*>::const_iterator I = PassInfoMap.begin(),
+    for (std::map<TypeInfo, PassInfo*>::const_iterator I = PassInfoMap.begin(),
          E = PassInfoMap.end(); I != E; ++I)
       L->passEnumerate(I->second);
   }
@@ -210,10 +210,11 @@ static PassRegistrar *getPassRegistrar() {
 // getPassInfo - Return the PassInfo data structure that corresponds to this
 // pass...
 const PassInfo *Pass::getPassInfo() const {
-  return lookupPassInfo(PassID);
+  if (PassInfoCache) return PassInfoCache;
+  return lookupPassInfo(typeid(*this));
 }
 
-const PassInfo *Pass::lookupPassInfo(intptr_t TI) {
+const PassInfo *Pass::lookupPassInfo(const std::type_info &TI) {
   return getPassRegistrar()->GetPassInfo(TI);
 }
 
@@ -237,12 +238,12 @@ void RegisterPassBase::unregisterPass() {
 
 // RegisterAGBase implementation
 //
-RegisterAGBase::RegisterAGBase(intptr_t InterfaceID,
-                               intptr_t PassID, bool isDefault)
-  : RegisterPassBase(InterfaceID),
+RegisterAGBase::RegisterAGBase(const std::type_info &Interface,
+                               const std::type_info *Pass, bool isDefault)
+  : RegisterPassBase(Interface),
     ImplementationInfo(0), isDefaultImplementation(isDefault) {
 
-  InterfaceInfo = const_cast<PassInfo*>(Pass::lookupPassInfo(InterfaceID));
+  InterfaceInfo = const_cast<PassInfo*>(Pass::lookupPassInfo(Interface));
   if (InterfaceInfo == 0) {
     // First reference to Interface, register it now.
     registerPass();
@@ -251,8 +252,8 @@ RegisterAGBase::RegisterAGBase(intptr_t InterfaceID,
   assert(PIObj.isAnalysisGroup() &&
          "Trying to join an analysis group that is a normal pass!");
 
-  if (PassID) {
-    ImplementationInfo = Pass::lookupPassInfo(PassID);
+  if (Pass) {
+    ImplementationInfo = Pass::lookupPassInfo(*Pass);
     assert(ImplementationInfo &&
            "Must register pass before adding to AnalysisGroup!");