#include "llvm/ModuleProvider.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/TypeInfo.h"
+#include <algorithm>
#include <set>
using namespace llvm;
// Pass Implementation
//
+// Force out-of-line virtual method.
+Pass::~Pass() {
+ delete Resolver;
+}
+
// Force out-of-line virtual method.
ModulePass::~ModulePass() { }
const char *Pass::getPassName() const {
if (const PassInfo *PI = getPassInfo())
return PI->getPassName();
- return typeid(*this).name();
+ return "Unnamed pass: implement Pass::getPassName()";
}
// print - Print out the internal state of the pass. This is called by Analyze
class PassRegistrar {
/// PassInfoMap - Keep track of the passinfo object for each registered llvm
/// pass.
- std::map<TypeInfo, PassInfo*> PassInfoMap;
+ std::map<intptr_t, PassInfo*> PassInfoMap;
/// AnalysisGroupInfo - Keep track of information for each analysis group.
struct AnalysisGroupInfo {
public:
- const PassInfo *GetPassInfo(const std::type_info &TI) const {
- std::map<TypeInfo, PassInfo*>::const_iterator I = PassInfoMap.find(TI);
+ const PassInfo *GetPassInfo(intptr_t TI) const {
+ std::map<intptr_t, 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(TypeInfo(PI.getTypeInfo()),&PI)).second;
+ PassInfoMap.insert(std::make_pair(PI.getTypeInfo(),&PI)).second;
assert(Inserted && "Pass registered multiple times!");
}
void UnregisterPass(PassInfo &PI) {
- std::map<TypeInfo, PassInfo*>::iterator I =
+ std::map<intptr_t, PassInfo*>::iterator I =
PassInfoMap.find(PI.getTypeInfo());
assert(I != PassInfoMap.end() && "Pass registered but not in map!");
}
void EnumerateWith(PassRegistrationListener *L) {
- for (std::map<TypeInfo, PassInfo*>::const_iterator I = PassInfoMap.begin(),
+ for (std::map<intptr_t, PassInfo*>::const_iterator I = PassInfoMap.begin(),
E = PassInfoMap.end(); I != E; ++I)
L->passEnumerate(I->second);
}
};
}
-static ManagedStatic<PassRegistrar> PassRegistrarObj;
static std::vector<PassRegistrationListener*> *Listeners = 0;
+// FIXME: This should use ManagedStatic to manage the pass registrar.
+// Unfortunately, we can't do this, because passes are registered with static
+// ctors, and having llvm_shutdown clear this map prevents successful
+// ressurection after llvm_shutdown is run.
+static PassRegistrar *getPassRegistrar() {
+ static PassRegistrar *PassRegistrarObj = 0;
+ if (!PassRegistrarObj)
+ PassRegistrarObj = new PassRegistrar();
+ return PassRegistrarObj;
+}
+
// getPassInfo - Return the PassInfo data structure that corresponds to this
// pass...
const PassInfo *Pass::getPassInfo() const {
- if (PassInfoCache) return PassInfoCache;
- return lookupPassInfo(typeid(*this));
+ return lookupPassInfo(PassID);
}
-const PassInfo *Pass::lookupPassInfo(const std::type_info &TI) {
- return PassRegistrarObj->GetPassInfo(TI);
+const PassInfo *Pass::lookupPassInfo(intptr_t TI) {
+ return getPassRegistrar()->GetPassInfo(TI);
}
void RegisterPassBase::registerPass() {
- PassRegistrarObj->RegisterPass(PIObj);
+ getPassRegistrar()->RegisterPass(PIObj);
// Notify any listeners.
if (Listeners)
}
void RegisterPassBase::unregisterPass() {
- PassRegistrarObj->UnregisterPass(PIObj);
+ getPassRegistrar()->UnregisterPass(PIObj);
}
//===----------------------------------------------------------------------===//
// RegisterAGBase implementation
//
-RegisterAGBase::RegisterAGBase(const std::type_info &Interface,
- const std::type_info *Pass, bool isDefault)
- : RegisterPassBase(Interface),
+RegisterAGBase::RegisterAGBase(intptr_t InterfaceID,
+ intptr_t PassID, bool isDefault)
+ : RegisterPassBase(InterfaceID),
ImplementationInfo(0), isDefaultImplementation(isDefault) {
- InterfaceInfo = const_cast<PassInfo*>(Pass::lookupPassInfo(Interface));
+ InterfaceInfo = const_cast<PassInfo*>(Pass::lookupPassInfo(InterfaceID));
if (InterfaceInfo == 0) {
// First reference to Interface, register it now.
registerPass();
assert(PIObj.isAnalysisGroup() &&
"Trying to join an analysis group that is a normal pass!");
- if (Pass) {
- ImplementationInfo = Pass::lookupPassInfo(*Pass);
+ if (PassID) {
+ ImplementationInfo = Pass::lookupPassInfo(PassID);
assert(ImplementationInfo &&
"Must register pass before adding to AnalysisGroup!");
PassInfo *IIPI = const_cast<PassInfo*>(ImplementationInfo);
IIPI->addInterfaceImplemented(InterfaceInfo);
- PassRegistrarObj->RegisterAnalysisGroup(InterfaceInfo, IIPI, isDefault);
+ getPassRegistrar()->RegisterAnalysisGroup(InterfaceInfo, IIPI, isDefault);
}
}
// passEnumerate callback on each PassInfo object.
//
void PassRegistrationListener::enumeratePasses() {
- PassRegistrarObj->EnumerateWith(this);
+ getPassRegistrar()->EnumerateWith(this);
}
//===----------------------------------------------------------------------===//