summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2010-07-20 23:41:56 +0000
committerOwen Anderson <resistor@mac.com>2010-07-20 23:41:56 +0000
commit539673579ec79b75a95ef9daefc6a8b2fc8552f5 (patch)
treec4f78678bea14baa763cce7dd1a2fad6140b7fe0
parent1154f426d72ea7b2d9de93f9af5874d7d9b5a3d5 (diff)
downloadllvm-539673579ec79b75a95ef9daefc6a8b2fc8552f5.tar.gz
llvm-539673579ec79b75a95ef9daefc6a8b2fc8552f5.tar.bz2
llvm-539673579ec79b75a95ef9daefc6a8b2fc8552f5.tar.xz
Move the handling of PassRegistrationListener's to PassRegistry.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108966 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/PassRegistry.h11
-rw-r--r--include/llvm/PassSupport.h8
-rw-r--r--lib/VMCore/Pass.cpp40
-rw-r--r--lib/VMCore/PassRegistry.cpp25
4 files changed, 39 insertions, 45 deletions
diff --git a/include/llvm/PassRegistry.h b/include/llvm/PassRegistry.h
index 1f627d8bfc..7b1b6fc703 100644
--- a/include/llvm/PassRegistry.h
+++ b/include/llvm/PassRegistry.h
@@ -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 @@ class PassRegistry {
std::set<const PassInfo *> Implementations;
};
std::map<const PassInfo*, AnalysisGroupInfo> AnalysisGroupInfoMap;
+
+ std::vector<PassRegistrationListener*> Listeners;
public:
static PassRegistry *getPassRegistry();
@@ -60,6 +63,8 @@ public:
bool isDefault);
void enumerateWith(PassRegistrationListener *L);
+ void addRegistrationListener(PassRegistrationListener* L);
+ void removeRegistrationListener(PassRegistrationListener *L);
};
}
diff --git a/include/llvm/PassSupport.h b/include/llvm/PassSupport.h
index b018351338..4bbafdb855 100644
--- a/include/llvm/PassSupport.h
+++ b/include/llvm/PassSupport.h
@@ -22,6 +22,7 @@
#define LLVM_PASS_SUPPORT_H
#include "Pass.h"
+#include "llvm/PassRegistry.h"
namespace llvm {
@@ -57,7 +58,7 @@ public:
: 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 @@ public:
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 @@ struct RegisterPass : public PassInfo {
: PassInfo(Name, PassArg, intptr_t(&passName::ID),
PassInfo::NormalCtor_t(callDefaultCtor<passName>),
CFGOnly, is_analysis) {
+
}
};
diff --git a/lib/VMCore/Pass.cpp b/lib/VMCore/Pass.cpp
index 255be38cd6..75ee17cd5a 100644
--- a/lib/VMCore/Pass.cpp
+++ b/lib/VMCore/Pass.cpp
@@ -234,13 +234,6 @@ PassManagerType BasicBlockPass::getPotentialPassManagerType() const {
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 @@ const PassInfo *Pass::lookupPassInfo(StringRef Arg) {
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 @@ RegisterAGBase::RegisterAGBase(const char *Name, intptr_t InterfaceID,
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 @@ RegisterAGBase::RegisterAGBase(const char *Name, intptr_t InterfaceID,
// 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
diff --git a/lib/VMCore/PassRegistry.cpp b/lib/VMCore/PassRegistry.cpp
index 18a8cca56f..140719e12b 100644
--- a/lib/VMCore/PassRegistry.cpp
+++ b/lib/VMCore/PassRegistry.cpp
@@ -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 @@ const PassInfo *PassRegistry::getPassInfo(StringRef Arg) const {
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 @@ void PassRegistry::registerAnalysisGroup(PassInfo *InterfaceInfo,
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);
+}