mirror of
https://github.com/RPCS3/llvm.git
synced 2025-04-11 18:42:01 +00:00
Patch #6's in Saem's refactor-the-passmanager patch series. From him:
This sanitises the world, blows away the specialisations and adds traits per passmanager type -- seemed most natural. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25085 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
51d6e76ff4
commit
7f7b730d79
@ -44,7 +44,10 @@ class Module;
|
|||||||
class AnalysisUsage;
|
class AnalysisUsage;
|
||||||
class PassInfo;
|
class PassInfo;
|
||||||
class ImmutablePass;
|
class ImmutablePass;
|
||||||
template<class UnitType> class PassManagerT;
|
template<class Trait> class PassManagerT;
|
||||||
|
class BasicBlockPassManager;
|
||||||
|
class FunctionPassManagerT;
|
||||||
|
class ModulePassManager;
|
||||||
struct AnalysisResolver;
|
struct AnalysisResolver;
|
||||||
|
|
||||||
// AnalysisID - Use the PassInfo to identify a pass...
|
// AnalysisID - Use the PassInfo to identify a pass...
|
||||||
@ -197,9 +200,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class PassManagerT<Module>;
|
template<typename Trait> friend class PassManagerT;
|
||||||
friend class PassManagerT<Function>;
|
friend class ModulePassManager;
|
||||||
friend class PassManagerT<BasicBlock>;
|
friend class FunctionPassManagerT;
|
||||||
|
friend class BasicBlockPassManager;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::ostream &operator<<(std::ostream &OS, const Pass &P) {
|
inline std::ostream &operator<<(std::ostream &OS, const Pass &P) {
|
||||||
@ -220,7 +224,7 @@ public:
|
|||||||
virtual bool runPass(Module &M) { return runOnModule(M); }
|
virtual bool runPass(Module &M) { return runOnModule(M); }
|
||||||
virtual bool runPass(BasicBlock&) { return false; }
|
virtual bool runPass(BasicBlock&) { return false; }
|
||||||
|
|
||||||
virtual void addToPassManager(PassManagerT<Module> *PM, AnalysisUsage &AU);
|
virtual void addToPassManager(ModulePassManager *PM, AnalysisUsage &AU);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -244,8 +248,9 @@ public:
|
|||||||
virtual bool runOnModule(Module &M) { return false; }
|
virtual bool runOnModule(Module &M) { return false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class PassManagerT<Module>;
|
template<typename Trait> friend class PassManagerT;
|
||||||
virtual void addToPassManager(PassManagerT<Module> *PM, AnalysisUsage &AU);
|
friend class ModulePassManager;
|
||||||
|
virtual void addToPassManager(ModulePassManager *PM, AnalysisUsage &AU);
|
||||||
};
|
};
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@ -286,11 +291,12 @@ public:
|
|||||||
bool run(Function &F);
|
bool run(Function &F);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class PassManagerT<Module>;
|
template<typename Trait> friend class PassManagerT;
|
||||||
friend class PassManagerT<Function>;
|
friend class ModulePassManager;
|
||||||
friend class PassManagerT<BasicBlock>;
|
friend class FunctionPassManagerT;
|
||||||
virtual void addToPassManager(PassManagerT<Module> *PM, AnalysisUsage &AU);
|
friend class BasicBlockPassManager;
|
||||||
virtual void addToPassManager(PassManagerT<Function> *PM, AnalysisUsage &AU);
|
virtual void addToPassManager(ModulePassManager *PM, AnalysisUsage &AU);
|
||||||
|
virtual void addToPassManager(FunctionPassManagerT *PM, AnalysisUsage &AU);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -344,10 +350,11 @@ struct BasicBlockPass : public FunctionPass {
|
|||||||
virtual bool runPass(BasicBlock &BB);
|
virtual bool runPass(BasicBlock &BB);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class PassManagerT<Function>;
|
template<typename Trait> friend class PassManagerT;
|
||||||
friend class PassManagerT<BasicBlock>;
|
friend class FunctionPassManagerT;
|
||||||
virtual void addToPassManager(PassManagerT<Function> *PM, AnalysisUsage &AU);
|
friend class BasicBlockPassManager;
|
||||||
virtual void addToPassManager(PassManagerT<BasicBlock> *PM,AnalysisUsage &AU);
|
virtual void addToPassManager(FunctionPassManagerT *PM, AnalysisUsage &AU);
|
||||||
|
virtual void addToPassManager(BasicBlockPassManager *PM,AnalysisUsage &AU);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// If the user specifies the -time-passes argument on an LLVM tool command line
|
/// If the user specifies the -time-passes argument on an LLVM tool command line
|
||||||
|
@ -23,10 +23,12 @@ class Pass;
|
|||||||
class ModulePass;
|
class ModulePass;
|
||||||
class Module;
|
class Module;
|
||||||
class ModuleProvider;
|
class ModuleProvider;
|
||||||
template<class UnitType> class PassManagerT;
|
class ModulePassManager;
|
||||||
|
class FunctionPassManagerT;
|
||||||
|
class BasicBlockPassManager;
|
||||||
|
|
||||||
class PassManager {
|
class PassManager {
|
||||||
PassManagerT<Module> *PM; // This is a straightforward Pimpl class
|
ModulePassManager *PM; // This is a straightforward Pimpl class
|
||||||
public:
|
public:
|
||||||
PassManager();
|
PassManager();
|
||||||
~PassManager();
|
~PassManager();
|
||||||
@ -49,7 +51,7 @@ class ImmutablePass;
|
|||||||
class Function;
|
class Function;
|
||||||
|
|
||||||
class FunctionPassManager {
|
class FunctionPassManager {
|
||||||
PassManagerT<Function> *PM; // This is a straightforward Pimpl class
|
FunctionPassManagerT *PM; // This is a straightforward Pimpl class
|
||||||
ModuleProvider *MP;
|
ModuleProvider *MP;
|
||||||
public:
|
public:
|
||||||
FunctionPassManager(ModuleProvider *P);
|
FunctionPassManager(ModuleProvider *P);
|
||||||
|
@ -78,7 +78,7 @@ void AnalysisUsage::setPreservesCFG() {
|
|||||||
// PassManager implementation - The PassManager class is a simple Pimpl class
|
// PassManager implementation - The PassManager class is a simple Pimpl class
|
||||||
// that wraps the PassManagerT template.
|
// that wraps the PassManagerT template.
|
||||||
//
|
//
|
||||||
PassManager::PassManager() : PM(new PassManagerT<Module>()) {}
|
PassManager::PassManager() : PM(new ModulePassManager()) {}
|
||||||
PassManager::~PassManager() { delete PM; }
|
PassManager::~PassManager() { delete PM; }
|
||||||
void PassManager::add(Pass *P) {
|
void PassManager::add(Pass *P) {
|
||||||
ModulePass *MP = dynamic_cast<ModulePass*>(P);
|
ModulePass *MP = dynamic_cast<ModulePass*>(P);
|
||||||
@ -93,7 +93,7 @@ bool PassManager::run(Module &M) { return PM->runOnModule(M); }
|
|||||||
// is like PassManager, but only deals in FunctionPasses.
|
// is like PassManager, but only deals in FunctionPasses.
|
||||||
//
|
//
|
||||||
FunctionPassManager::FunctionPassManager(ModuleProvider *P) :
|
FunctionPassManager::FunctionPassManager(ModuleProvider *P) :
|
||||||
PM(new PassManagerT<Function>()), MP(P) {}
|
PM(new FunctionPassManagerT()), MP(P) {}
|
||||||
FunctionPassManager::~FunctionPassManager() { delete PM; }
|
FunctionPassManager::~FunctionPassManager() { delete PM; }
|
||||||
void FunctionPassManager::add(FunctionPass *P) { PM->add(P); }
|
void FunctionPassManager::add(FunctionPass *P) { PM->add(P); }
|
||||||
void FunctionPassManager::add(ImmutablePass *IP) { PM->add(IP); }
|
void FunctionPassManager::add(ImmutablePass *IP) { PM->add(IP); }
|
||||||
@ -194,7 +194,7 @@ void PMDebug::PrintAnalysisSetInfo(unsigned Depth, const char *Msg,
|
|||||||
// Pass Implementation
|
// Pass Implementation
|
||||||
//
|
//
|
||||||
|
|
||||||
void ModulePass::addToPassManager(PassManagerT<Module> *PM, AnalysisUsage &AU) {
|
void ModulePass::addToPassManager(ModulePassManager *PM, AnalysisUsage &AU) {
|
||||||
PM->addPass(this, AU);
|
PM->addPass(this, AU);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +231,7 @@ void Pass::dump() const {
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// ImmutablePass Implementation
|
// ImmutablePass Implementation
|
||||||
//
|
//
|
||||||
void ImmutablePass::addToPassManager(PassManagerT<Module> *PM,
|
void ImmutablePass::addToPassManager(ModulePassManager *PM,
|
||||||
AnalysisUsage &AU) {
|
AnalysisUsage &AU) {
|
||||||
PM->addPass(this, AU);
|
PM->addPass(this, AU);
|
||||||
}
|
}
|
||||||
@ -264,12 +264,12 @@ bool FunctionPass::run(Function &F) {
|
|||||||
return Changed | doFinalization(*F.getParent());
|
return Changed | doFinalization(*F.getParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FunctionPass::addToPassManager(PassManagerT<Module> *PM,
|
void FunctionPass::addToPassManager(ModulePassManager *PM,
|
||||||
AnalysisUsage &AU) {
|
AnalysisUsage &AU) {
|
||||||
PM->addPass(this, AU);
|
PM->addPass(this, AU);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FunctionPass::addToPassManager(PassManagerT<Function> *PM,
|
void FunctionPass::addToPassManager(FunctionPassManagerT *PM,
|
||||||
AnalysisUsage &AU) {
|
AnalysisUsage &AU) {
|
||||||
PM->addPass(this, AU);
|
PM->addPass(this, AU);
|
||||||
}
|
}
|
||||||
@ -302,12 +302,12 @@ bool BasicBlockPass::runPass(BasicBlock &BB) {
|
|||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasicBlockPass::addToPassManager(PassManagerT<Function> *PM,
|
void BasicBlockPass::addToPassManager(FunctionPassManagerT *PM,
|
||||||
AnalysisUsage &AU) {
|
AnalysisUsage &AU) {
|
||||||
PM->addPass(this, AU);
|
PM->addPass(this, AU);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasicBlockPass::addToPassManager(PassManagerT<BasicBlock> *PM,
|
void BasicBlockPass::addToPassManager(BasicBlockPassManager *PM,
|
||||||
AnalysisUsage &AU) {
|
AnalysisUsage &AU) {
|
||||||
PM->addPass(this, AU);
|
PM->addPass(this, AU);
|
||||||
}
|
}
|
||||||
|
@ -123,10 +123,70 @@ public:
|
|||||||
|
|
||||||
static TimingInfo *TheTimeInfo;
|
static TimingInfo *TheTimeInfo;
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
// FIXME:I'm not sure if this is the best way, but this was the only way I
|
||||||
// Declare the PassManagerTraits which will be specialized...
|
// could get around the recursive template issues. -- Saem
|
||||||
|
struct BBTraits {
|
||||||
|
typedef BasicBlock UnitType;
|
||||||
|
|
||||||
|
// PassClass - The type of passes tracked by this PassManager
|
||||||
|
typedef BasicBlockPass PassClass;
|
||||||
|
|
||||||
|
// SubPassClass - The types of classes that should be collated together
|
||||||
|
// This is impossible to match, so BasicBlock instantiations of PassManagerT
|
||||||
|
// do not collate.
|
||||||
//
|
//
|
||||||
template<class UnitType> class PassManagerTraits; // Do not define.
|
typedef BasicBlockPassManager SubPassClass;
|
||||||
|
|
||||||
|
// BatcherClass - The type to use for collation of subtypes... This class is
|
||||||
|
// never instantiated for the PassManager<BasicBlock>, but it must be an
|
||||||
|
// instance of PassClass to typecheck.
|
||||||
|
//
|
||||||
|
typedef PassClass BatcherClass;
|
||||||
|
|
||||||
|
// ParentClass - The type of the parent PassManager...
|
||||||
|
typedef FunctionPassManagerT ParentClass;
|
||||||
|
|
||||||
|
// PMType - The type of this passmanager
|
||||||
|
typedef BasicBlockPassManager PMType;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FTraits {
|
||||||
|
typedef Function UnitType;
|
||||||
|
|
||||||
|
// PassClass - The type of passes tracked by this PassManager
|
||||||
|
typedef FunctionPass PassClass;
|
||||||
|
|
||||||
|
// SubPassClass - The types of classes that should be collated together
|
||||||
|
typedef BasicBlockPass SubPassClass;
|
||||||
|
|
||||||
|
// BatcherClass - The type to use for collation of subtypes...
|
||||||
|
typedef BasicBlockPassManager BatcherClass;
|
||||||
|
|
||||||
|
// ParentClass - The type of the parent PassManager...
|
||||||
|
typedef ModulePassManager ParentClass;
|
||||||
|
|
||||||
|
// PMType - The type of this passmanager
|
||||||
|
typedef FunctionPassManagerT PMType;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MTraits {
|
||||||
|
typedef Module UnitType;
|
||||||
|
|
||||||
|
// PassClass - The type of passes tracked by this PassManager
|
||||||
|
typedef ModulePass PassClass;
|
||||||
|
|
||||||
|
// SubPassClass - The types of classes that should be collated together
|
||||||
|
typedef FunctionPass SubPassClass;
|
||||||
|
|
||||||
|
// BatcherClass - The type to use for collation of subtypes...
|
||||||
|
typedef FunctionPassManagerT BatcherClass;
|
||||||
|
|
||||||
|
// ParentClass - The type of the parent PassManager...
|
||||||
|
typedef AnalysisResolver ParentClass;
|
||||||
|
|
||||||
|
// PMType - The type of this passmanager
|
||||||
|
typedef ModulePassManager PMType;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@ -134,25 +194,19 @@ template<class UnitType> class PassManagerTraits; // Do not define.
|
|||||||
// deletes all passes contained inside of the PassManagerT, so you shouldn't
|
// deletes all passes contained inside of the PassManagerT, so you shouldn't
|
||||||
// delete passes manually, and all passes should be dynamically allocated.
|
// delete passes manually, and all passes should be dynamically allocated.
|
||||||
//
|
//
|
||||||
template<typename UnitType>
|
template<typename Trait> class PassManagerT : public AnalysisResolver {
|
||||||
class PassManagerT : public PassManagerTraits<UnitType>,public AnalysisResolver{
|
|
||||||
// TODO:Edit these to reflect changes for world sanitisation
|
typedef typename Trait::PassClass PassClass;
|
||||||
typedef PassManagerTraits<UnitType> Traits;
|
typedef typename Trait::UnitType UnitType;
|
||||||
typedef typename Traits::PassClass PassClass;
|
typedef typename Trait::ParentClass ParentClass;
|
||||||
typedef typename Traits::SubPassClass SubPassClass;
|
typedef typename Trait::SubPassClass SubPassClass;
|
||||||
typedef typename Traits::BatcherClass BatcherClass;
|
typedef typename Trait::BatcherClass BatcherClass;
|
||||||
typedef typename Traits::ParentClass ParentClass;
|
typedef typename Trait::PMType PMType;
|
||||||
|
|
||||||
|
friend class ModulePass;
|
||||||
|
friend class FunctionPass;
|
||||||
|
friend class BasicBlockPass;
|
||||||
|
|
||||||
#if defined(_MSC_VER) || defined(__INTEL_COMPILER) || defined(__HP_aCC)
|
|
||||||
friend PassClass;
|
|
||||||
friend SubPassClass;
|
|
||||||
#else
|
|
||||||
// TODO:Redefine when sanitising
|
|
||||||
friend class PassManagerTraits<UnitType>::PassClass;
|
|
||||||
friend class PassManagerTraits<UnitType>::SubPassClass;
|
|
||||||
#endif
|
|
||||||
// TODO:Redefine this when santising
|
|
||||||
friend class PassManagerTraits<UnitType>;
|
|
||||||
friend class ImmutablePass;
|
friend class ImmutablePass;
|
||||||
|
|
||||||
friend class BasicBlockPassManager;
|
friend class BasicBlockPassManager;
|
||||||
@ -181,6 +235,18 @@ class PassManagerT : public PassManagerTraits<UnitType>,public AnalysisResolver{
|
|||||||
std::map<Pass*, Pass*> LastUseOf;
|
std::map<Pass*, Pass*> LastUseOf;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
// getPMName() - Return the name of the unit the PassManager operates on for
|
||||||
|
// debugging.
|
||||||
|
virtual const char *getPMName() const =0;
|
||||||
|
|
||||||
|
virtual const char *getPassName() const =0;
|
||||||
|
|
||||||
|
virtual bool runPass(PassClass *P, UnitType *M) =0;
|
||||||
|
|
||||||
|
// TODO:Figure out what pure virtuals remain.
|
||||||
|
|
||||||
|
|
||||||
PassManagerT(ParentClass *Par = 0) : Parent(Par), Batcher(0) {}
|
PassManagerT(ParentClass *Par = 0) : Parent(Par), Batcher(0) {}
|
||||||
virtual ~PassManagerT() {
|
virtual ~PassManagerT() {
|
||||||
// Delete all of the contained passes...
|
// Delete all of the contained passes...
|
||||||
@ -221,7 +287,7 @@ public:
|
|||||||
LastUserOf[I->second].push_back(I->first);
|
LastUserOf[I->second].push_back(I->first);
|
||||||
|
|
||||||
// Output debug information...
|
// Output debug information...
|
||||||
if (Parent == 0) PMDebug::PerformPassStartupStuff(this);
|
if (Parent == 0) PMDebug::PerformPassStartupStuff((dynamic_cast<PassClass*>(this)));
|
||||||
|
|
||||||
// Run all of the passes
|
// Run all of the passes
|
||||||
for (unsigned i = 0, e = Passes.size(); i < e; ++i) {
|
for (unsigned i = 0, e = Passes.size(); i < e; ++i) {
|
||||||
@ -337,7 +403,7 @@ public:
|
|||||||
for (unsigned i = 0, e = ImmutablePasses.size(); i != e; ++i)
|
for (unsigned i = 0, e = ImmutablePasses.size(); i != e; ++i)
|
||||||
ImmutablePasses[i]->dumpPassStructure(0);
|
ImmutablePasses[i]->dumpPassStructure(0);
|
||||||
|
|
||||||
std::cerr << std::string(Offset*2, ' ') << Traits::getPMName()
|
std::cerr << std::string(Offset*2, ' ') << this->getPMName()
|
||||||
<< " Pass Manager\n";
|
<< " Pass Manager\n";
|
||||||
for (typename std::vector<PassClass*>::iterator
|
for (typename std::vector<PassClass*>::iterator
|
||||||
I = Passes.begin(), E = Passes.end(); I != E; ++I) {
|
I = Passes.begin(), E = Passes.end(); I != E; ++I) {
|
||||||
@ -425,7 +491,7 @@ public:
|
|||||||
// frees the analysis AFTER this pass manager runs.
|
// frees the analysis AFTER this pass manager runs.
|
||||||
//
|
//
|
||||||
if (Parent) {
|
if (Parent) {
|
||||||
Parent->markPassUsed(P, this);
|
Parent->markPassUsed(P, dynamic_cast<Pass*>(this));
|
||||||
} else {
|
} else {
|
||||||
assert(getAnalysisOrNullUp(P) &&
|
assert(getAnalysisOrNullUp(P) &&
|
||||||
dynamic_cast<ImmutablePass*>(getAnalysisOrNullUp(P)) &&
|
dynamic_cast<ImmutablePass*>(getAnalysisOrNullUp(P)) &&
|
||||||
@ -473,7 +539,7 @@ public:
|
|||||||
// depends on the class of the pass, and is critical to laying out passes in
|
// depends on the class of the pass, and is critical to laying out passes in
|
||||||
// an optimal order..
|
// an optimal order..
|
||||||
//
|
//
|
||||||
P->addToPassManager(this, AnUsage);
|
P->addToPassManager(dynamic_cast<PMType*>(this), AnUsage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add - H4x0r an ImmutablePass into a PassManager that might not be
|
// add - H4x0r an ImmutablePass into a PassManager that might not be
|
||||||
@ -573,7 +639,7 @@ private:
|
|||||||
//
|
//
|
||||||
void addPass(SubPassClass *MP, AnalysisUsage &AnUsage) {
|
void addPass(SubPassClass *MP, AnalysisUsage &AnUsage) {
|
||||||
if (Batcher == 0) // If we don't have a batcher yet, make one now.
|
if (Batcher == 0) // If we don't have a batcher yet, make one now.
|
||||||
Batcher = new BatcherClass(this);
|
Batcher = new BatcherClass((dynamic_cast<PMType*>(this)));
|
||||||
// The Batcher will queue the passes up
|
// The Batcher will queue the passes up
|
||||||
MP->addToPassManager(Batcher, AnUsage);
|
MP->addToPassManager(Batcher, AnUsage);
|
||||||
}
|
}
|
||||||
@ -628,44 +694,29 @@ public:
|
|||||||
IP->initializePass();
|
IP->initializePass();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Once the world has been sanitised, the pure virtuals below can be
|
|
||||||
// brought in.
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// BasicBlockPassManager
|
// BasicBlockPassManager
|
||||||
//
|
//
|
||||||
// This pass manager is used to group together all of the BasicBlockPass's
|
// This pass manager is used to group together all of the BasicBlockPass's
|
||||||
// into a single unit.
|
// into a single unit.
|
||||||
//
|
//
|
||||||
class BasicBlockPassManager {
|
class BasicBlockPassManager : public BasicBlockPass,
|
||||||
|
public BBTraits,
|
||||||
|
public PassManagerT<BBTraits> {
|
||||||
public:
|
public:
|
||||||
// PassClass - The type of passes tracked by this PassManager
|
BasicBlockPassManager(BBTraits::ParentClass* PC) :
|
||||||
typedef BasicBlockPass PassClass;
|
PassManagerT<BBTraits>(PC) {
|
||||||
|
}
|
||||||
// SubPassClass - The types of classes that should be collated together
|
|
||||||
// This is impossible to match, so BasicBlock instantiations of PassManagerT
|
|
||||||
// do not collate.
|
|
||||||
//
|
|
||||||
typedef PassManagerT<Module> SubPassClass;
|
|
||||||
|
|
||||||
// BatcherClass - The type to use for collation of subtypes... This class is
|
|
||||||
// never instantiated for the PassManager<BasicBlock>, but it must be an
|
|
||||||
// instance of PassClass to typecheck.
|
|
||||||
//
|
|
||||||
typedef PassClass BatcherClass;
|
|
||||||
|
|
||||||
// ParentClass - The type of the parent PassManager...
|
|
||||||
typedef PassManagerT<Function> ParentClass;
|
|
||||||
|
|
||||||
// PMType - The type of the passmanager that subclasses this class
|
|
||||||
typedef PassManagerT<BasicBlock> PMType;
|
|
||||||
|
|
||||||
|
BasicBlockPassManager(BasicBlockPassManager* BBPM) :
|
||||||
|
PassManagerT<BBTraits>(BBPM->Parent) {
|
||||||
|
}
|
||||||
|
|
||||||
// runPass - Specify how the pass should be run on the UnitType
|
// runPass - Specify how the pass should be run on the UnitType
|
||||||
static bool runPass(PassClass *P, BasicBlock *M) {
|
virtual bool runPass(BBTraits::PassClass *P, BasicBlock *M) {
|
||||||
// todo, init and finalize
|
// TODO: init and finalize
|
||||||
return P->runOnBasicBlock(*M);
|
return P->runOnBasicBlock(*M);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -688,81 +739,24 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
// PassManagerTraits<BasicBlock> Specialization
|
|
||||||
//
|
|
||||||
// This pass manager is used to group together all of the BasicBlockPass's
|
|
||||||
// into a single unit.
|
|
||||||
//
|
|
||||||
template<> class PassManagerTraits<BasicBlock> : public BasicBlockPass,
|
|
||||||
public BasicBlockPassManager {
|
|
||||||
public:
|
|
||||||
// runPass - Specify how the pass should be run on the UnitType
|
|
||||||
static bool runPass(PassClass *P, BasicBlock *M) {
|
|
||||||
return BasicBlockPassManager::runPass(P,M);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Forwarded
|
|
||||||
virtual bool doInitialization(Module &M) {
|
|
||||||
return BasicBlockPassManager::doInitialization(M);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Forwarded
|
|
||||||
virtual bool doInitialization(Function &F) {
|
|
||||||
return BasicBlockPassManager::doInitialization(F);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Forwarded
|
|
||||||
virtual bool runOnBasicBlock(BasicBlock &BB) {
|
|
||||||
return BasicBlockPassManager::runOnBasicBlock(BB);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Forwarded
|
|
||||||
virtual bool doFinalization(Function &F) {
|
|
||||||
return BasicBlockPassManager::doFinalization(F);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Forwarded
|
|
||||||
virtual bool doFinalization(Module &M) {
|
|
||||||
return BasicBlockPassManager::doFinalization(M);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Forwarded
|
|
||||||
virtual const char *getPassName() const {
|
|
||||||
return BasicBlockPassManager::getPassName();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Forwarded
|
|
||||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
||||||
BasicBlockPassManager::getAnalysisUsage(AU);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// FunctionPassManager
|
// FunctionPassManager
|
||||||
//
|
//
|
||||||
// This pass manager is used to group together all of the FunctionPass's
|
// This pass manager is used to group together all of the FunctionPass's
|
||||||
// into a single unit.
|
// into a single unit.
|
||||||
//
|
//
|
||||||
class FunctionPassManagerT {
|
class FunctionPassManagerT : public FunctionPass,
|
||||||
|
public FTraits,
|
||||||
|
public PassManagerT<FTraits> {
|
||||||
public:
|
public:
|
||||||
// PassClass - The type of passes tracked by this PassManager
|
FunctionPassManagerT() : PassManagerT<FTraits>(0) {}
|
||||||
typedef FunctionPass PassClass;
|
|
||||||
|
|
||||||
// SubPassClass - The types of classes that should be collated together
|
// Parent constructor
|
||||||
typedef BasicBlockPass SubPassClass;
|
FunctionPassManagerT(FTraits::ParentClass* PC) : PassManagerT<FTraits>(PC) {}
|
||||||
|
|
||||||
// BatcherClass - The type to use for collation of subtypes...
|
FunctionPassManagerT(FunctionPassManagerT* FPM) :
|
||||||
typedef PassManagerT<BasicBlock> BatcherClass;
|
PassManagerT<FTraits>(FPM->Parent) {
|
||||||
|
}
|
||||||
// ParentClass - The type of the parent PassManager...
|
|
||||||
typedef PassManagerT<Module> ParentClass;
|
|
||||||
|
|
||||||
// PMType - The type of the passmanager that subclasses this class
|
|
||||||
typedef PassManagerT<Function> PMType;
|
|
||||||
|
|
||||||
virtual ~FunctionPassManagerT() {}
|
virtual ~FunctionPassManagerT() {}
|
||||||
|
|
||||||
@ -783,70 +777,29 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// runPass - Specify how the pass should be run on the UnitType
|
// runPass - Specify how the pass should be run on the UnitType
|
||||||
static bool runPass(PassClass *P, Function *F) {
|
virtual bool runPass(FTraits::PassClass *P, Function *F) {
|
||||||
return P->runOnFunction(*F);
|
return P->runOnFunction(*F);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
// PassManagerTraits<Function> Specialization
|
|
||||||
//
|
|
||||||
// This pass manager is used to group together all of the FunctionPass's
|
|
||||||
// into a single unit.
|
|
||||||
//
|
|
||||||
template<> class PassManagerTraits<Function> : public FunctionPass,
|
|
||||||
public FunctionPassManagerT {
|
|
||||||
public:
|
|
||||||
// runPass - Specify how the pass should be run on the UnitType
|
|
||||||
static bool runPass(PassClass *P, Function *F) {
|
|
||||||
return FunctionPassManagerT::runPass(P,F);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Forwarded
|
|
||||||
virtual bool doInitialization(Module &M) {
|
|
||||||
return FunctionPassManagerT::doInitialization(M);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Forwarded
|
|
||||||
virtual bool runOnFunction(Function &F) {
|
|
||||||
return FunctionPassManagerT::runOnFunction(F);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Forwarded
|
|
||||||
virtual bool doFinalization(Module &M) {
|
|
||||||
return FunctionPassManagerT::doFinalization(M);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Forwarded
|
|
||||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
||||||
FunctionPassManagerT::getAnalysisUsage(AU);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Forwarded
|
|
||||||
virtual const char *getPassName() const {
|
|
||||||
return FunctionPassManagerT::getPassName();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// ModulePassManager
|
// ModulePassManager
|
||||||
//
|
//
|
||||||
// This is the top level PassManager implementation that holds generic passes.
|
// This is the top level PassManager implementation that holds generic passes.
|
||||||
//
|
//
|
||||||
class ModulePassManager {
|
class ModulePassManager : public ModulePass,
|
||||||
|
public MTraits,
|
||||||
|
public PassManagerT<MTraits> {
|
||||||
public:
|
public:
|
||||||
// PassClass - The type of passes tracked by this PassManager
|
ModulePassManager() : PassManagerT<MTraits>(0) {}
|
||||||
typedef ModulePass PassClass;
|
|
||||||
|
|
||||||
// SubPassClass - The types of classes that should be collated together
|
// Batcher Constructor
|
||||||
typedef FunctionPass SubPassClass;
|
ModulePassManager(MTraits::ParentClass* PC) : PassManagerT<MTraits>(PC) {}
|
||||||
|
|
||||||
// BatcherClass - The type to use for collation of subtypes...
|
ModulePassManager(ModulePassManager* MPM) :
|
||||||
typedef PassManagerT<Function> BatcherClass;
|
PassManagerT<MTraits>((MPM->Parent)) {
|
||||||
|
}
|
||||||
// ParentClass - The type of the parent PassManager...
|
|
||||||
typedef AnalysisResolver ParentClass;
|
|
||||||
|
|
||||||
virtual ~ModulePassManager() {}
|
virtual ~ModulePassManager() {}
|
||||||
|
|
||||||
@ -862,36 +815,10 @@ public:
|
|||||||
virtual bool runOnModule(Module &M);
|
virtual bool runOnModule(Module &M);
|
||||||
|
|
||||||
// runPass - Specify how the pass should be run on the UnitType
|
// runPass - Specify how the pass should be run on the UnitType
|
||||||
static bool runPass(PassClass *P, Module *M) { return P->runOnModule(*M); }
|
virtual bool runPass(MTraits::PassClass *P, Module *M) { return P->runOnModule(*M); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
// PassManagerTraits<Module> Specialization
|
|
||||||
//
|
|
||||||
// This is the top level PassManager implementation that holds generic passes.
|
|
||||||
//
|
|
||||||
template<> class PassManagerTraits<Module> : public ModulePass,
|
|
||||||
public ModulePassManager {
|
|
||||||
public:
|
|
||||||
// Forwarded
|
|
||||||
static bool runPass(PassClass *P, Module *M) {
|
|
||||||
return ModulePassManager::runPass(P,M);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Forwarded
|
|
||||||
bool runOnModule(Module &M) {
|
|
||||||
return ModulePassManager::runOnModule(M);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Forwarded
|
|
||||||
virtual const char *getPassName() const {
|
|
||||||
return ModulePassManager::getPassName();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// PassManagerTraits Method Implementations
|
// PassManagerTraits Method Implementations
|
||||||
//
|
//
|
||||||
@ -900,34 +827,34 @@ public:
|
|||||||
//
|
//
|
||||||
|
|
||||||
inline bool BasicBlockPassManager::runOnBasicBlock(BasicBlock &BB) {
|
inline bool BasicBlockPassManager::runOnBasicBlock(BasicBlock &BB) {
|
||||||
return ((PMType*)this)->runOnUnit(&BB);
|
return ((BBTraits::PMType*)this)->runOnUnit(&BB);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool BasicBlockPassManager::doInitialization(Module &M) {
|
inline bool BasicBlockPassManager::doInitialization(Module &M) {
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
|
for (unsigned i = 0, e = ((BBTraits::PMType*)this)->Passes.size(); i != e; ++i)
|
||||||
((PMType*)this)->Passes[i]->doInitialization(M);
|
((BBTraits::PMType*)this)->Passes[i]->doInitialization(M);
|
||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool BasicBlockPassManager::doInitialization(Function &F) {
|
inline bool BasicBlockPassManager::doInitialization(Function &F) {
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
|
for (unsigned i = 0, e = ((BBTraits::PMType*)this)->Passes.size(); i != e; ++i)
|
||||||
((PMType*)this)->Passes[i]->doInitialization(F);
|
((BBTraits::PMType*)this)->Passes[i]->doInitialization(F);
|
||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool BasicBlockPassManager::doFinalization(Function &F) {
|
inline bool BasicBlockPassManager::doFinalization(Function &F) {
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
|
for (unsigned i = 0, e = ((BBTraits::PMType*)this)->Passes.size(); i != e; ++i)
|
||||||
((PMType*)this)->Passes[i]->doFinalization(F);
|
((BBTraits::PMType*)this)->Passes[i]->doFinalization(F);
|
||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool BasicBlockPassManager::doFinalization(Module &M) {
|
inline bool BasicBlockPassManager::doFinalization(Module &M) {
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
|
for (unsigned i=0, e = ((BBTraits::PMType*)this)->Passes.size(); i != e; ++i)
|
||||||
((PMType*)this)->Passes[i]->doFinalization(M);
|
((BBTraits::PMType*)this)->Passes[i]->doFinalization(M);
|
||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -935,20 +862,20 @@ inline bool BasicBlockPassManager::doFinalization(Module &M) {
|
|||||||
//
|
//
|
||||||
|
|
||||||
inline bool FunctionPassManagerT::runOnFunction(Function &F) {
|
inline bool FunctionPassManagerT::runOnFunction(Function &F) {
|
||||||
return ((PMType*)this)->runOnUnit(&F);
|
return ((FTraits::PMType*)this)->runOnUnit(&F);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool FunctionPassManagerT::doInitialization(Module &M) {
|
inline bool FunctionPassManagerT::doInitialization(Module &M) {
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
|
for (unsigned i=0, e = ((FTraits::PMType*)this)->Passes.size(); i != e; ++i)
|
||||||
((PMType*)this)->Passes[i]->doInitialization(M);
|
((FTraits::PMType*)this)->Passes[i]->doInitialization(M);
|
||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool FunctionPassManagerT::doFinalization(Module &M) {
|
inline bool FunctionPassManagerT::doFinalization(Module &M) {
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
|
for (unsigned i=0, e = ((FTraits::PMType*)this)->Passes.size(); i != e; ++i)
|
||||||
((PMType*)this)->Passes[i]->doFinalization(M);
|
((FTraits::PMType*)this)->Passes[i]->doFinalization(M);
|
||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -956,7 +883,7 @@ inline bool FunctionPassManagerT::doFinalization(Module &M) {
|
|||||||
//
|
//
|
||||||
|
|
||||||
bool ModulePassManager::runOnModule(Module &M) {
|
bool ModulePassManager::runOnModule(Module &M) {
|
||||||
return ((PassManagerT<Module>*)this)->runOnUnit(&M);
|
return ((PassManagerT<MTraits>*)this)->runOnUnit(&M);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user