[llvm-commits] [llvm] r108966 - in /llvm/trunk: include/llvm/PassRegistry.h include/llvm/PassSupport.h lib/VMCore/Pass.cpp lib/VMCore/PassRegistry.cpp

Owen Anderson resistor at mac.com
Tue Jul 20 16:41:56 PDT 2010


Author: resistor
Date: Tue Jul 20 18:41:56 2010
New Revision: 108966

URL: http://llvm.org/viewvc/llvm-project?rev=108966&view=rev
Log:
Move the handling of PassRegistrationListener's to PassRegistry.

Modified:
    llvm/trunk/include/llvm/PassRegistry.h
    llvm/trunk/include/llvm/PassSupport.h
    llvm/trunk/lib/VMCore/Pass.cpp
    llvm/trunk/lib/VMCore/PassRegistry.cpp

Modified: llvm/trunk/include/llvm/PassRegistry.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/PassRegistry.h?rev=108966&r1=108965&r2=108966&view=diff
==============================================================================
--- llvm/trunk/include/llvm/PassRegistry.h (original)
+++ llvm/trunk/include/llvm/PassRegistry.h Tue Jul 20 18:41:56 2010
@@ -17,17 +17,18 @@
 #ifndef LLVM_PASSREGISTRY_H
 #define LLVM_PASSREGISTRY_H
 
-#include "llvm/PassSupport.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/System/DataTypes.h"
 #include "llvm/System/Mutex.h"
 #include <map>
 #include <set>
-
-using namespace llvm;
+#include <vector>
 
 namespace llvm {
 
+class PassInfo;
+struct PassRegistrationListener;
+
 class PassRegistry {
   /// Guards the contents of this class.
   mutable sys::SmartMutex<true> Lock;
@@ -44,6 +45,8 @@
     std::set<const PassInfo *> Implementations;
   };
   std::map<const PassInfo*, AnalysisGroupInfo> AnalysisGroupInfoMap;
+  
+  std::vector<PassRegistrationListener*> Listeners;
 
 public:
   static PassRegistry *getPassRegistry();
@@ -60,6 +63,8 @@
                              bool isDefault);
   
   void enumerateWith(PassRegistrationListener *L);
+  void addRegistrationListener(PassRegistrationListener* L);
+  void removeRegistrationListener(PassRegistrationListener *L);
 };
 
 }

Modified: llvm/trunk/include/llvm/PassSupport.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/PassSupport.h?rev=108966&r1=108965&r2=108966&view=diff
==============================================================================
--- llvm/trunk/include/llvm/PassSupport.h (original)
+++ llvm/trunk/include/llvm/PassSupport.h Tue Jul 20 18:41:56 2010
@@ -22,6 +22,7 @@
 #define LLVM_PASS_SUPPORT_H
 
 #include "Pass.h"
+#include "llvm/PassRegistry.h"
 
 namespace llvm {
 
@@ -57,7 +58,7 @@
     : PassName(name), PassArgument(arg), PassID(pi), 
       IsCFGOnlyPass(isCFGOnly), 
       IsAnalysis(is_analysis), IsAnalysisGroup(false), NormalCtor(normal) {
-    registerPass();
+    PassRegistry::getPassRegistry()->registerPass(*this);
   }
   /// PassInfo ctor - Do not call this directly, this should only be invoked
   /// through RegisterPass. This version is for use by analysis groups; it
@@ -126,10 +127,6 @@
     return ItfImpl;
   }
 
-protected:
-  void registerPass();
-  void unregisterPass();
-
 private:
   void operator=(const PassInfo &); // do not implement
   PassInfo(const PassInfo &);       // do not implement
@@ -165,6 +162,7 @@
     : PassInfo(Name, PassArg, intptr_t(&passName::ID),
                PassInfo::NormalCtor_t(callDefaultCtor<passName>),
                CFGOnly, is_analysis) {
+    
   }
 };
 

Modified: llvm/trunk/lib/VMCore/Pass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Pass.cpp?rev=108966&r1=108965&r2=108966&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Pass.cpp (original)
+++ llvm/trunk/lib/VMCore/Pass.cpp Tue Jul 20 18:41:56 2010
@@ -234,13 +234,6 @@
   return PMT_BasicBlockPassManager; 
 }
 
-//===----------------------------------------------------------------------===//
-// Pass Registration mechanism
-//
-
-static std::vector<PassRegistrationListener*> *Listeners = 0;
-static sys::SmartMutex<true> ListenersLock;
-
 // getPassInfo - Return the PassInfo data structure that corresponds to this
 // pass...
 const PassInfo *Pass::getPassInfo() const {
@@ -255,21 +248,6 @@
   return PassRegistry::getPassRegistry()->getPassInfo(Arg);
 }
 
-void PassInfo::registerPass() {
-  PassRegistry::getPassRegistry()->registerPass(*this);
-
-  // Notify any listeners.
-  sys::SmartScopedLock<true> Lock(ListenersLock);
-  if (Listeners)
-    for (std::vector<PassRegistrationListener*>::iterator
-           I = Listeners->begin(), E = Listeners->end(); I != E; ++I)
-      (*I)->passRegistered(this);
-}
-
-void PassInfo::unregisterPass() {
-  PassRegistry::getPassRegistry()->unregisterPass(*this);
-}
-
 Pass *PassInfo::createPass() const {
   assert((!isAnalysisGroup() || NormalCtor) &&
          "No default implementation found for analysis group!");
@@ -292,7 +270,7 @@
     const_cast<PassInfo*>(Pass::lookupPassInfo(InterfaceID));
   if (InterfaceInfo == 0) {
     // First reference to Interface, register it now.
-    registerPass();
+    PassRegistry::getPassRegistry()->registerPass(*this);
     InterfaceInfo = this;
   }
   assert(isAnalysisGroup() &&
@@ -320,24 +298,12 @@
 // PassRegistrationListener ctor - Add the current object to the list of
 // PassRegistrationListeners...
 PassRegistrationListener::PassRegistrationListener() {
-  sys::SmartScopedLock<true> Lock(ListenersLock);
-  if (!Listeners) Listeners = new std::vector<PassRegistrationListener*>();
-  Listeners->push_back(this);
+  PassRegistry::getPassRegistry()->addRegistrationListener(this);
 }
 
 // dtor - Remove object from list of listeners...
 PassRegistrationListener::~PassRegistrationListener() {
-  sys::SmartScopedLock<true> Lock(ListenersLock);
-  std::vector<PassRegistrationListener*>::iterator I =
-    std::find(Listeners->begin(), Listeners->end(), this);
-  assert(Listeners && I != Listeners->end() &&
-         "PassRegistrationListener not registered!");
-  Listeners->erase(I);
-
-  if (Listeners->empty()) {
-    delete Listeners;
-    Listeners = 0;
-  }
+  PassRegistry::getPassRegistry()->removeRegistrationListener(this);
 }
 
 // enumeratePasses - Iterate over the registered passes, calling the

Modified: llvm/trunk/lib/VMCore/PassRegistry.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/PassRegistry.cpp?rev=108966&r1=108965&r2=108966&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/PassRegistry.cpp (original)
+++ llvm/trunk/lib/VMCore/PassRegistry.cpp Tue Jul 20 18:41:56 2010
@@ -13,9 +13,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/PassRegistry.h"
+#include "llvm/PassSupport.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ManagedStatic.h"
 
+using namespace llvm;
+
 static PassRegistry *PassRegistryObj = 0;
 PassRegistry *PassRegistry::getPassRegistry() {
   // Use double-checked locking to safely initialize the registrar when
@@ -69,12 +72,21 @@
   return I != PassInfoStringMap.end() ? I->second : 0;
 }
 
+//===----------------------------------------------------------------------===//
+// Pass Registration mechanism
+//
+
 void PassRegistry::registerPass(const PassInfo &PI) {
   sys::SmartScopedLock<true> Guard(Lock);
   bool Inserted =
     PassInfoMap.insert(std::make_pair(PI.getTypeInfo(),&PI)).second;
   assert(Inserted && "Pass registered multiple times!"); Inserted=Inserted;
   PassInfoStringMap[PI.getPassArgument()] = &PI;
+  
+  // Notify any listeners.
+  for (std::vector<PassRegistrationListener*>::iterator
+       I = Listeners.begin(), E = Listeners.end(); I != E; ++I)
+    (*I)->passRegistered(&PI);
 }
 
 void PassRegistry::unregisterPass(const PassInfo &PI) {
@@ -112,3 +124,16 @@
     InterfaceInfo->setNormalCtor(ImplementationInfo->getNormalCtor());
   }
 }
+
+void PassRegistry::addRegistrationListener(PassRegistrationListener *L) {
+  sys::SmartScopedLock<true> Guard(Lock);
+  Listeners.push_back(L);
+}
+
+void PassRegistry::removeRegistrationListener(PassRegistrationListener *L) {
+  sys::SmartScopedLock<true> Guard(Lock);
+  std::vector<PassRegistrationListener*>::iterator I =
+    std::find(Listeners.begin(), Listeners.end(), L);
+  assert(I != Listeners.end() && "PassRegistrationListener not registered!");
+  Listeners.erase(I);
+}





More information about the llvm-commits mailing list