mirror of
https://github.com/RPCS3/llvm.git
synced 2025-02-10 20:42:32 +00:00
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
This commit is contained in:
parent
1154f426d7
commit
539673579e
@ -17,17 +17,18 @@
|
|||||||
#ifndef LLVM_PASSREGISTRY_H
|
#ifndef LLVM_PASSREGISTRY_H
|
||||||
#define LLVM_PASSREGISTRY_H
|
#define LLVM_PASSREGISTRY_H
|
||||||
|
|
||||||
#include "llvm/PassSupport.h"
|
|
||||||
#include "llvm/ADT/StringMap.h"
|
#include "llvm/ADT/StringMap.h"
|
||||||
#include "llvm/System/DataTypes.h"
|
#include "llvm/System/DataTypes.h"
|
||||||
#include "llvm/System/Mutex.h"
|
#include "llvm/System/Mutex.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <vector>
|
||||||
using namespace llvm;
|
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
|
class PassInfo;
|
||||||
|
struct PassRegistrationListener;
|
||||||
|
|
||||||
class PassRegistry {
|
class PassRegistry {
|
||||||
/// Guards the contents of this class.
|
/// Guards the contents of this class.
|
||||||
mutable sys::SmartMutex<true> Lock;
|
mutable sys::SmartMutex<true> Lock;
|
||||||
@ -44,6 +45,8 @@ class PassRegistry {
|
|||||||
std::set<const PassInfo *> Implementations;
|
std::set<const PassInfo *> Implementations;
|
||||||
};
|
};
|
||||||
std::map<const PassInfo*, AnalysisGroupInfo> AnalysisGroupInfoMap;
|
std::map<const PassInfo*, AnalysisGroupInfo> AnalysisGroupInfoMap;
|
||||||
|
|
||||||
|
std::vector<PassRegistrationListener*> Listeners;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static PassRegistry *getPassRegistry();
|
static PassRegistry *getPassRegistry();
|
||||||
@ -60,6 +63,8 @@ public:
|
|||||||
bool isDefault);
|
bool isDefault);
|
||||||
|
|
||||||
void enumerateWith(PassRegistrationListener *L);
|
void enumerateWith(PassRegistrationListener *L);
|
||||||
|
void addRegistrationListener(PassRegistrationListener* L);
|
||||||
|
void removeRegistrationListener(PassRegistrationListener *L);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#define LLVM_PASS_SUPPORT_H
|
#define LLVM_PASS_SUPPORT_H
|
||||||
|
|
||||||
#include "Pass.h"
|
#include "Pass.h"
|
||||||
|
#include "llvm/PassRegistry.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
@ -57,7 +58,7 @@ public:
|
|||||||
: PassName(name), PassArgument(arg), PassID(pi),
|
: PassName(name), PassArgument(arg), PassID(pi),
|
||||||
IsCFGOnlyPass(isCFGOnly),
|
IsCFGOnlyPass(isCFGOnly),
|
||||||
IsAnalysis(is_analysis), IsAnalysisGroup(false), NormalCtor(normal) {
|
IsAnalysis(is_analysis), IsAnalysisGroup(false), NormalCtor(normal) {
|
||||||
registerPass();
|
PassRegistry::getPassRegistry()->registerPass(*this);
|
||||||
}
|
}
|
||||||
/// PassInfo ctor - Do not call this directly, this should only be invoked
|
/// PassInfo ctor - Do not call this directly, this should only be invoked
|
||||||
/// through RegisterPass. This version is for use by analysis groups; it
|
/// through RegisterPass. This version is for use by analysis groups; it
|
||||||
@ -126,10 +127,6 @@ public:
|
|||||||
return ItfImpl;
|
return ItfImpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
void registerPass();
|
|
||||||
void unregisterPass();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void operator=(const PassInfo &); // do not implement
|
void operator=(const PassInfo &); // do not implement
|
||||||
PassInfo(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(Name, PassArg, intptr_t(&passName::ID),
|
||||||
PassInfo::NormalCtor_t(callDefaultCtor<passName>),
|
PassInfo::NormalCtor_t(callDefaultCtor<passName>),
|
||||||
CFGOnly, is_analysis) {
|
CFGOnly, is_analysis) {
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -234,13 +234,6 @@ PassManagerType BasicBlockPass::getPotentialPassManagerType() const {
|
|||||||
return PMT_BasicBlockPassManager;
|
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
|
// getPassInfo - Return the PassInfo data structure that corresponds to this
|
||||||
// pass...
|
// pass...
|
||||||
const PassInfo *Pass::getPassInfo() const {
|
const PassInfo *Pass::getPassInfo() const {
|
||||||
@ -255,21 +248,6 @@ const PassInfo *Pass::lookupPassInfo(StringRef Arg) {
|
|||||||
return PassRegistry::getPassRegistry()->getPassInfo(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 {
|
Pass *PassInfo::createPass() const {
|
||||||
assert((!isAnalysisGroup() || NormalCtor) &&
|
assert((!isAnalysisGroup() || NormalCtor) &&
|
||||||
"No default implementation found for analysis group!");
|
"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));
|
const_cast<PassInfo*>(Pass::lookupPassInfo(InterfaceID));
|
||||||
if (InterfaceInfo == 0) {
|
if (InterfaceInfo == 0) {
|
||||||
// First reference to Interface, register it now.
|
// First reference to Interface, register it now.
|
||||||
registerPass();
|
PassRegistry::getPassRegistry()->registerPass(*this);
|
||||||
InterfaceInfo = this;
|
InterfaceInfo = this;
|
||||||
}
|
}
|
||||||
assert(isAnalysisGroup() &&
|
assert(isAnalysisGroup() &&
|
||||||
@ -320,24 +298,12 @@ RegisterAGBase::RegisterAGBase(const char *Name, intptr_t InterfaceID,
|
|||||||
// PassRegistrationListener ctor - Add the current object to the list of
|
// PassRegistrationListener ctor - Add the current object to the list of
|
||||||
// PassRegistrationListeners...
|
// PassRegistrationListeners...
|
||||||
PassRegistrationListener::PassRegistrationListener() {
|
PassRegistrationListener::PassRegistrationListener() {
|
||||||
sys::SmartScopedLock<true> Lock(ListenersLock);
|
PassRegistry::getPassRegistry()->addRegistrationListener(this);
|
||||||
if (!Listeners) Listeners = new std::vector<PassRegistrationListener*>();
|
|
||||||
Listeners->push_back(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// dtor - Remove object from list of listeners...
|
// dtor - Remove object from list of listeners...
|
||||||
PassRegistrationListener::~PassRegistrationListener() {
|
PassRegistrationListener::~PassRegistrationListener() {
|
||||||
sys::SmartScopedLock<true> Lock(ListenersLock);
|
PassRegistry::getPassRegistry()->removeRegistrationListener(this);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// enumeratePasses - Iterate over the registered passes, calling the
|
// enumeratePasses - Iterate over the registered passes, calling the
|
||||||
|
@ -13,9 +13,12 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/PassRegistry.h"
|
#include "llvm/PassRegistry.h"
|
||||||
|
#include "llvm/PassSupport.h"
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
#include "llvm/Support/ManagedStatic.h"
|
#include "llvm/Support/ManagedStatic.h"
|
||||||
|
|
||||||
|
using namespace llvm;
|
||||||
|
|
||||||
static PassRegistry *PassRegistryObj = 0;
|
static PassRegistry *PassRegistryObj = 0;
|
||||||
PassRegistry *PassRegistry::getPassRegistry() {
|
PassRegistry *PassRegistry::getPassRegistry() {
|
||||||
// Use double-checked locking to safely initialize the registrar when
|
// 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;
|
return I != PassInfoStringMap.end() ? I->second : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// Pass Registration mechanism
|
||||||
|
//
|
||||||
|
|
||||||
void PassRegistry::registerPass(const PassInfo &PI) {
|
void PassRegistry::registerPass(const PassInfo &PI) {
|
||||||
sys::SmartScopedLock<true> Guard(Lock);
|
sys::SmartScopedLock<true> Guard(Lock);
|
||||||
bool Inserted =
|
bool Inserted =
|
||||||
PassInfoMap.insert(std::make_pair(PI.getTypeInfo(),&PI)).second;
|
PassInfoMap.insert(std::make_pair(PI.getTypeInfo(),&PI)).second;
|
||||||
assert(Inserted && "Pass registered multiple times!"); Inserted=Inserted;
|
assert(Inserted && "Pass registered multiple times!"); Inserted=Inserted;
|
||||||
PassInfoStringMap[PI.getPassArgument()] = &PI;
|
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) {
|
void PassRegistry::unregisterPass(const PassInfo &PI) {
|
||||||
@ -112,3 +124,16 @@ void PassRegistry::registerAnalysisGroup(PassInfo *InterfaceInfo,
|
|||||||
InterfaceInfo->setNormalCtor(ImplementationInfo->getNormalCtor());
|
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);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user