mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-07 12:28:24 +00:00
Speedup and simplify pass registration by the observation that there is
exactly one PassInfo object per RegisterPass object and that their lifetimes are the same. As such, there is no reason for the RegisterPass object to dynamically allocate the PassInfo object at compiler startup time: just inline the object by-value. This should reduce codesize, heap size, and startup time. Yaay. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25521 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -50,7 +50,7 @@ public:
|
|||||||
/// AnalysisGroup flag with others.
|
/// AnalysisGroup flag with others.
|
||||||
///
|
///
|
||||||
enum {
|
enum {
|
||||||
Analysis = 1, Optimization = 2, LLC = 4, AnalysisGroup = 8
|
Analysis = 1, Optimization = 2, AnalysisGroup = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
/// PassInfo ctor - Do not call this directly, this should only be invoked
|
/// PassInfo ctor - Do not call this directly, this should only be invoked
|
||||||
@@ -149,17 +149,31 @@ public:
|
|||||||
struct RegisterPassBase {
|
struct RegisterPassBase {
|
||||||
/// getPassInfo - Get the pass info for the registered class...
|
/// getPassInfo - Get the pass info for the registered class...
|
||||||
///
|
///
|
||||||
const PassInfo *getPassInfo() const { return PIObj; }
|
const PassInfo *getPassInfo() const { return &PIObj; }
|
||||||
|
|
||||||
RegisterPassBase() : PIObj(0) {}
|
RegisterPassBase(const char *Name, const char *Arg, const std::type_info &TI,
|
||||||
~RegisterPassBase() { // Intentionally non-virtual...
|
unsigned char PT, Pass *(*Normal)() = 0,
|
||||||
if (PIObj) unregisterPass(PIObj);
|
Pass *(*TargetCtor)(TargetMachine &) = 0)
|
||||||
|
: PIObj(Name, Arg, TI, PT, Normal, TargetCtor) {
|
||||||
|
registerPass();
|
||||||
|
}
|
||||||
|
RegisterPassBase(const std::type_info &TI, unsigned char PT)
|
||||||
|
: PIObj("", "", TI, PT, 0, 0) {
|
||||||
|
// This ctor may only be used for analysis groups: it does not auto-register
|
||||||
|
// the pass.
|
||||||
|
assert(PT == PassInfo::AnalysisGroup && "Not an AnalysisGroup!");
|
||||||
|
}
|
||||||
|
|
||||||
|
~RegisterPassBase() { // Intentionally non-virtual.
|
||||||
|
// Analysis groups are registered/unregistered by their dtor.
|
||||||
|
if (PIObj.getPassType() != PassInfo::AnalysisGroup)
|
||||||
|
unregisterPass();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PassInfo *PIObj; // The PassInfo object for this pass
|
PassInfo PIObj; // The PassInfo object for this pass
|
||||||
void registerPass(PassInfo *);
|
void registerPass();
|
||||||
void unregisterPass(PassInfo *);
|
void unregisterPass();
|
||||||
|
|
||||||
/// setOnlyUsesCFG - Notice that this pass only depends on the CFG, so
|
/// setOnlyUsesCFG - Notice that this pass only depends on the CFG, so
|
||||||
/// transformations that do not modify the CFG do not invalidate this pass.
|
/// transformations that do not modify the CFG do not invalidate this pass.
|
||||||
@@ -174,30 +188,26 @@ template<typename PassName>
|
|||||||
struct RegisterPass : public RegisterPassBase {
|
struct RegisterPass : public RegisterPassBase {
|
||||||
|
|
||||||
// Register Pass using default constructor...
|
// Register Pass using default constructor...
|
||||||
RegisterPass(const char *PassArg, const char *Name, unsigned char PassTy = 0){
|
RegisterPass(const char *PassArg, const char *Name, unsigned char PassTy = 0)
|
||||||
registerPass(new PassInfo(Name, PassArg, typeid(PassName), PassTy,
|
: RegisterPassBase(Name, PassArg, typeid(PassName), PassTy,
|
||||||
callDefaultCtor<PassName>));
|
callDefaultCtor<PassName>) {}
|
||||||
}
|
|
||||||
|
|
||||||
// Register Pass using default constructor explicitly...
|
// Register Pass using default constructor explicitly...
|
||||||
RegisterPass(const char *PassArg, const char *Name, unsigned char PassTy,
|
RegisterPass(const char *PassArg, const char *Name, unsigned char PassTy,
|
||||||
Pass *(*ctor)()) {
|
Pass *(*ctor)())
|
||||||
registerPass(new PassInfo(Name, PassArg, typeid(PassName), PassTy, ctor));
|
: RegisterPassBase(Name, PassArg, typeid(PassName), PassTy, ctor) {}
|
||||||
}
|
|
||||||
|
|
||||||
// Register Pass using TargetMachine constructor...
|
// Register Pass using TargetMachine constructor...
|
||||||
RegisterPass(const char *PassArg, const char *Name, unsigned char PassTy,
|
RegisterPass(const char *PassArg, const char *Name, unsigned char PassTy,
|
||||||
Pass *(*targetctor)(TargetMachine &)) {
|
Pass *(*targetctor)(TargetMachine &))
|
||||||
registerPass(new PassInfo(Name, PassArg, typeid(PassName), PassTy,
|
: RegisterPassBase(Name, PassArg, typeid(PassName), PassTy,
|
||||||
0, targetctor));
|
0, targetctor) {}
|
||||||
}
|
|
||||||
|
|
||||||
// Generic constructor version that has an unknown ctor type...
|
// Generic constructor version that has an unknown ctor type...
|
||||||
template<typename CtorType>
|
template<typename CtorType>
|
||||||
RegisterPass(const char *PassArg, const char *Name, unsigned char PassTy,
|
RegisterPass(const char *PassArg, const char *Name, unsigned char PassTy,
|
||||||
CtorType *Fn) {
|
CtorType *Fn)
|
||||||
registerPass(new PassInfo(Name, PassArg, typeid(PassName), PassTy, 0));
|
: RegisterPassBase(Name, PassArg, typeid(PassName), PassTy, 0) {}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// RegisterOpt - Register something that is to show up in Opt, this is just a
|
/// RegisterOpt - Register something that is to show up in Opt, this is just a
|
||||||
@@ -205,38 +215,36 @@ struct RegisterPass : public RegisterPassBase {
|
|||||||
///
|
///
|
||||||
template<typename PassName>
|
template<typename PassName>
|
||||||
struct RegisterOpt : public RegisterPassBase {
|
struct RegisterOpt : public RegisterPassBase {
|
||||||
RegisterOpt(const char *PassArg, const char *Name, bool CFGOnly = false) {
|
RegisterOpt(const char *PassArg, const char *Name, bool CFGOnly = false)
|
||||||
registerPass(new PassInfo(Name, PassArg, typeid(PassName),
|
: RegisterPassBase(Name, PassArg, typeid(PassName), PassInfo::Optimization,
|
||||||
PassInfo::Optimization,
|
callDefaultCtor<PassName>) {
|
||||||
callDefaultCtor<PassName>));
|
|
||||||
if (CFGOnly) setOnlyUsesCFG();
|
if (CFGOnly) setOnlyUsesCFG();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register Pass using default constructor explicitly...
|
/// Register Pass using default constructor explicitly...
|
||||||
///
|
///
|
||||||
RegisterOpt(const char *PassArg, const char *Name, Pass *(*ctor)(),
|
RegisterOpt(const char *PassArg, const char *Name, Pass *(*ctor)(),
|
||||||
bool CFGOnly = false) {
|
bool CFGOnly = false)
|
||||||
registerPass(new PassInfo(Name, PassArg, typeid(PassName),
|
: RegisterPassBase(Name, PassArg, typeid(PassName),
|
||||||
PassInfo::Optimization, ctor));
|
PassInfo::Optimization, ctor) {
|
||||||
if (CFGOnly) setOnlyUsesCFG();
|
if (CFGOnly) setOnlyUsesCFG();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register FunctionPass using default constructor explicitly...
|
/// Register FunctionPass using default constructor explicitly...
|
||||||
///
|
///
|
||||||
RegisterOpt(const char *PassArg, const char *Name, FunctionPass *(*ctor)(),
|
RegisterOpt(const char *PassArg, const char *Name, FunctionPass *(*ctor)(),
|
||||||
bool CFGOnly = false) {
|
bool CFGOnly = false)
|
||||||
registerPass(new PassInfo(Name, PassArg, typeid(PassName),
|
: RegisterPassBase(Name, PassArg, typeid(PassName), PassInfo::Optimization,
|
||||||
PassInfo::Optimization,
|
static_cast<Pass*(*)()>(ctor)) {
|
||||||
static_cast<Pass*(*)()>(ctor)));
|
|
||||||
if (CFGOnly) setOnlyUsesCFG();
|
if (CFGOnly) setOnlyUsesCFG();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register Pass using TargetMachine constructor...
|
/// Register Pass using TargetMachine constructor...
|
||||||
///
|
///
|
||||||
RegisterOpt(const char *PassArg, const char *Name,
|
RegisterOpt(const char *PassArg, const char *Name,
|
||||||
Pass *(*targetctor)(TargetMachine &), bool CFGOnly = false) {
|
Pass *(*targetctor)(TargetMachine &), bool CFGOnly = false)
|
||||||
registerPass(new PassInfo(Name, PassArg, typeid(PassName),
|
: RegisterPassBase(Name, PassArg, typeid(PassName),
|
||||||
PassInfo::Optimization, 0, targetctor));
|
PassInfo::Optimization, 0, targetctor) {
|
||||||
if (CFGOnly) setOnlyUsesCFG();
|
if (CFGOnly) setOnlyUsesCFG();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,10 +252,9 @@ struct RegisterOpt : public RegisterPassBase {
|
|||||||
///
|
///
|
||||||
RegisterOpt(const char *PassArg, const char *Name,
|
RegisterOpt(const char *PassArg, const char *Name,
|
||||||
FunctionPass *(*targetctor)(TargetMachine &),
|
FunctionPass *(*targetctor)(TargetMachine &),
|
||||||
bool CFGOnly = false) {
|
bool CFGOnly = false)
|
||||||
registerPass(new PassInfo(Name, PassArg, typeid(PassName),
|
: RegisterPassBase(Name, PassArg, typeid(PassName), PassInfo::Optimization, 0,
|
||||||
PassInfo::Optimization, 0,
|
static_cast<Pass*(*)(TargetMachine&)>(targetctor)) {
|
||||||
static_cast<Pass*(*)(TargetMachine&)>(targetctor)));
|
|
||||||
if (CFGOnly) setOnlyUsesCFG();
|
if (CFGOnly) setOnlyUsesCFG();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -261,41 +268,13 @@ struct RegisterOpt : public RegisterPassBase {
|
|||||||
template<typename PassName>
|
template<typename PassName>
|
||||||
struct RegisterAnalysis : public RegisterPassBase {
|
struct RegisterAnalysis : public RegisterPassBase {
|
||||||
RegisterAnalysis(const char *PassArg, const char *Name,
|
RegisterAnalysis(const char *PassArg, const char *Name,
|
||||||
bool CFGOnly = false) {
|
bool CFGOnly = false)
|
||||||
registerPass(new PassInfo(Name, PassArg, typeid(PassName),
|
: RegisterPassBase(Name, PassArg, typeid(PassName), PassInfo::Analysis,
|
||||||
PassInfo::Analysis,
|
callDefaultCtor<PassName>) {
|
||||||
callDefaultCtor<PassName>));
|
|
||||||
if (CFGOnly) setOnlyUsesCFG();
|
if (CFGOnly) setOnlyUsesCFG();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// RegisterLLC - Register something that is to show up in LLC, this is just a
|
|
||||||
/// shortcut for specifying RegisterPass...
|
|
||||||
///
|
|
||||||
template<typename PassName>
|
|
||||||
struct RegisterLLC : public RegisterPassBase {
|
|
||||||
RegisterLLC(const char *PassArg, const char *Name) {
|
|
||||||
registerPass(new PassInfo(Name, PassArg, typeid(PassName),
|
|
||||||
PassInfo::LLC,
|
|
||||||
callDefaultCtor<PassName>));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Register Pass using default constructor explicitly...
|
|
||||||
///
|
|
||||||
RegisterLLC(const char *PassArg, const char *Name, Pass *(*ctor)()) {
|
|
||||||
registerPass(new PassInfo(Name, PassArg, typeid(PassName),
|
|
||||||
PassInfo::LLC, ctor));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Register Pass using TargetMachine constructor...
|
|
||||||
///
|
|
||||||
RegisterLLC(const char *PassArg, const char *Name,
|
|
||||||
Pass *(*datactor)(TargetMachine &)) {
|
|
||||||
registerPass(new PassInfo(Name, PassArg, typeid(PassName),
|
|
||||||
PassInfo::LLC));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/// RegisterAnalysisGroup - Register a Pass as a member of an analysis _group_.
|
/// RegisterAnalysisGroup - Register a Pass as a member of an analysis _group_.
|
||||||
/// Analysis groups are used to define an interface (which need not derive from
|
/// Analysis groups are used to define an interface (which need not derive from
|
||||||
|
@@ -38,7 +38,7 @@ static std::vector<const PassInfo*> &getCFGOnlyAnalyses() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RegisterPassBase::setOnlyUsesCFG() {
|
void RegisterPassBase::setOnlyUsesCFG() {
|
||||||
getCFGOnlyAnalyses().push_back(PIObj);
|
getCFGOnlyAnalyses().push_back(&PIObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@@ -332,26 +332,25 @@ const PassInfo *Pass::lookupPassInfo(const std::type_info &TI) {
|
|||||||
return (I != PassInfoMap->end()) ? I->second : 0;
|
return (I != PassInfoMap->end()) ? I->second : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterPassBase::registerPass(PassInfo *PI) {
|
void RegisterPassBase::registerPass() {
|
||||||
if (PassInfoMap == 0)
|
if (PassInfoMap == 0)
|
||||||
PassInfoMap = new std::map<TypeInfo, PassInfo*>();
|
PassInfoMap = new std::map<TypeInfo, PassInfo*>();
|
||||||
|
|
||||||
assert(PassInfoMap->find(PI->getTypeInfo()) == PassInfoMap->end() &&
|
assert(PassInfoMap->find(PIObj.getTypeInfo()) == PassInfoMap->end() &&
|
||||||
"Pass already registered!");
|
"Pass already registered!");
|
||||||
PIObj = PI;
|
PassInfoMap->insert(std::make_pair(TypeInfo(PIObj.getTypeInfo()), &PIObj));
|
||||||
PassInfoMap->insert(std::make_pair(TypeInfo(PI->getTypeInfo()), PI));
|
|
||||||
|
|
||||||
// Notify any listeners...
|
// Notify any listeners...
|
||||||
if (Listeners)
|
if (Listeners)
|
||||||
for (std::vector<PassRegistrationListener*>::iterator
|
for (std::vector<PassRegistrationListener*>::iterator
|
||||||
I = Listeners->begin(), E = Listeners->end(); I != E; ++I)
|
I = Listeners->begin(), E = Listeners->end(); I != E; ++I)
|
||||||
(*I)->passRegistered(PI);
|
(*I)->passRegistered(&PIObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterPassBase::unregisterPass(PassInfo *PI) {
|
void RegisterPassBase::unregisterPass() {
|
||||||
assert(PassInfoMap && "Pass registered but not in map!");
|
assert(PassInfoMap && "Pass registered but not in map!");
|
||||||
std::map<TypeInfo, PassInfo*>::iterator I =
|
std::map<TypeInfo, PassInfo*>::iterator I =
|
||||||
PassInfoMap->find(PI->getTypeInfo());
|
PassInfoMap->find(PIObj.getTypeInfo());
|
||||||
assert(I != PassInfoMap->end() && "Pass registered but not in map!");
|
assert(I != PassInfoMap->end() && "Pass registered but not in map!");
|
||||||
|
|
||||||
// Remove pass from the map...
|
// Remove pass from the map...
|
||||||
@@ -365,10 +364,7 @@ void RegisterPassBase::unregisterPass(PassInfo *PI) {
|
|||||||
if (Listeners)
|
if (Listeners)
|
||||||
for (std::vector<PassRegistrationListener*>::iterator
|
for (std::vector<PassRegistrationListener*>::iterator
|
||||||
I = Listeners->begin(), E = Listeners->end(); I != E; ++I)
|
I = Listeners->begin(), E = Listeners->end(); I != E; ++I)
|
||||||
(*I)->passUnregistered(PI);
|
(*I)->passUnregistered(&PIObj);
|
||||||
|
|
||||||
// Delete the PassInfo object itself...
|
|
||||||
delete PI;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@@ -387,14 +383,14 @@ static std::map<const PassInfo *, AnalysisGroupInfo> *AnalysisGroupInfoMap = 0;
|
|||||||
//
|
//
|
||||||
RegisterAGBase::RegisterAGBase(const std::type_info &Interface,
|
RegisterAGBase::RegisterAGBase(const std::type_info &Interface,
|
||||||
const std::type_info *Pass, bool isDefault)
|
const std::type_info *Pass, bool isDefault)
|
||||||
: ImplementationInfo(0), isDefaultImplementation(isDefault) {
|
: RegisterPassBase(Interface, PassInfo::AnalysisGroup),
|
||||||
|
ImplementationInfo(0), isDefaultImplementation(isDefault) {
|
||||||
|
|
||||||
InterfaceInfo = const_cast<PassInfo*>(Pass::lookupPassInfo(Interface));
|
InterfaceInfo = const_cast<PassInfo*>(Pass::lookupPassInfo(Interface));
|
||||||
if (InterfaceInfo == 0) { // First reference to Interface, add it now.
|
if (InterfaceInfo == 0) {
|
||||||
InterfaceInfo = // Create the new PassInfo for the interface...
|
// First reference to Interface, register it now.
|
||||||
new PassInfo("", "", Interface, PassInfo::AnalysisGroup, 0, 0);
|
registerPass();
|
||||||
registerPass(InterfaceInfo);
|
InterfaceInfo = &PIObj;
|
||||||
PIObj = 0;
|
|
||||||
}
|
}
|
||||||
assert(InterfaceInfo->getPassType() == PassInfo::AnalysisGroup &&
|
assert(InterfaceInfo->getPassType() == PassInfo::AnalysisGroup &&
|
||||||
"Trying to join an analysis group that is a normal pass!");
|
"Trying to join an analysis group that is a normal pass!");
|
||||||
@@ -455,10 +451,11 @@ RegisterAGBase::~RegisterAGBase() {
|
|||||||
delete AnalysisGroupInfoMap;
|
delete AnalysisGroupInfoMap;
|
||||||
AnalysisGroupInfoMap = 0;
|
AnalysisGroupInfoMap = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unregisterPass(InterfaceInfo);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (InterfaceInfo == &PIObj)
|
||||||
|
unregisterPass();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user