2002-01-31 07:20:39 +08:00
|
|
|
//===- llvm/PassManager.h - Container for Passes -----------------*- C++ -*--=//
|
|
|
|
//
|
|
|
|
// This file defines the PassManager class. This class is used to hold,
|
|
|
|
// maintain, and optimize execution of Pass's. The PassManager class ensures
|
|
|
|
// that analysis results are available before a pass runs, and that Pass's are
|
|
|
|
// destroyed when the PassManager is destroyed.
|
|
|
|
//
|
|
|
|
// The PassManagerT template is instantiated three times to do its job.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_PASSMANAGER_H
|
|
|
|
#define LLVM_PASSMANAGER_H
|
|
|
|
|
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PMDebug class - a set of debugging functions that are enabled when compiling
|
|
|
|
// with -g on. If compiling at -O, all functions are inlined noops.
|
|
|
|
//
|
|
|
|
struct PMDebug {
|
|
|
|
#ifdef NDEBUG
|
|
|
|
inline static void PrintPassStructure(Pass *) {}
|
|
|
|
inline static void PrintPassInformation(unsigned,const char*,Pass*,Value*) {}
|
2002-02-01 02:32:27 +08:00
|
|
|
inline static void PrintAnalysisSetInfo(unsigned,const char*,Pass *P,
|
2002-01-31 07:20:39 +08:00
|
|
|
const Pass::AnalysisSet &) {}
|
|
|
|
#else
|
|
|
|
// If compiled in debug mode, these functions can be enabled by setting
|
|
|
|
// -debug-pass on the command line of the tool being used.
|
|
|
|
//
|
|
|
|
static void PrintPassStructure(Pass *P);
|
|
|
|
static void PrintPassInformation(unsigned,const char*,Pass *, Value *);
|
2002-02-01 02:32:27 +08:00
|
|
|
static void PrintAnalysisSetInfo(unsigned,const char*,Pass *P,
|
|
|
|
const Pass::AnalysisSet&);
|
2002-01-31 07:20:39 +08:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Declare the PassManagerTraits which will be specialized...
|
|
|
|
//
|
|
|
|
template<class UnitType> class PassManagerTraits; // Do not define.
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PassManagerT - Container object for passes. The PassManagerT destructor
|
|
|
|
// deletes all passes contained inside of the PassManagerT, so you shouldn't
|
|
|
|
// delete passes manually, and all passes should be dynamically allocated.
|
|
|
|
//
|
|
|
|
template<typename UnitType>
|
|
|
|
class PassManagerT : public PassManagerTraits<UnitType>,public AnalysisResolver{
|
|
|
|
typedef typename PassManagerTraits<UnitType>::PassClass PassClass;
|
|
|
|
typedef typename PassManagerTraits<UnitType>::SubPassClass SubPassClass;
|
|
|
|
typedef typename PassManagerTraits<UnitType>::BatcherClass BatcherClass;
|
|
|
|
typedef typename PassManagerTraits<UnitType>::ParentClass ParentClass;
|
|
|
|
typedef PassManagerTraits<UnitType> Traits;
|
|
|
|
|
|
|
|
friend typename PassManagerTraits<UnitType>::PassClass;
|
|
|
|
friend typename PassManagerTraits<UnitType>::SubPassClass;
|
|
|
|
friend class PassManagerTraits<UnitType>;
|
|
|
|
|
|
|
|
std::vector<PassClass*> Passes; // List of pass's to run
|
|
|
|
|
|
|
|
// The parent of this pass manager...
|
2002-02-01 02:32:27 +08:00
|
|
|
ParentClass * const Parent;
|
2002-01-31 07:20:39 +08:00
|
|
|
|
|
|
|
// The current batcher if one is in use, or null
|
|
|
|
BatcherClass *Batcher;
|
|
|
|
|
|
|
|
// CurrentAnalyses - As the passes are being run, this map contains the
|
|
|
|
// analyses that are available to the current pass for use. This is accessed
|
|
|
|
// through the getAnalysis() function in this class and in Pass.
|
|
|
|
//
|
|
|
|
std::map<AnalysisID, Pass*> CurrentAnalyses;
|
|
|
|
|
2002-02-01 02:32:27 +08:00
|
|
|
// LastUseOf - This map keeps track of the last usage in our pipeline of a
|
|
|
|
// particular pass. When executing passes, the memory for .first is free'd
|
|
|
|
// after .second is run.
|
|
|
|
//
|
|
|
|
std::map<Pass*, Pass*> LastUseOf;
|
|
|
|
|
2002-01-31 07:20:39 +08:00
|
|
|
public:
|
|
|
|
PassManagerT(ParentClass *Par = 0) : Parent(Par), Batcher(0) {}
|
|
|
|
~PassManagerT() {
|
|
|
|
// Delete all of the contained passes...
|
|
|
|
for (std::vector<PassClass*>::iterator I = Passes.begin(), E = Passes.end();
|
|
|
|
I != E; ++I)
|
|
|
|
delete *I;
|
|
|
|
}
|
|
|
|
|
|
|
|
// run - Run all of the queued passes on the specified module in an optimal
|
|
|
|
// way.
|
|
|
|
virtual bool runOnUnit(UnitType *M) {
|
|
|
|
bool MadeChanges = false;
|
|
|
|
closeBatcher();
|
|
|
|
CurrentAnalyses.clear();
|
|
|
|
|
2002-02-01 02:32:27 +08:00
|
|
|
// LastUserOf - This contains the inverted LastUseOfMap...
|
|
|
|
std::map<Pass *, std::vector<Pass*> > LastUserOf;
|
|
|
|
for (std::map<Pass*, Pass*>::iterator I = LastUseOf.begin(),
|
|
|
|
E = LastUseOf.end(); I != E; ++I)
|
|
|
|
LastUserOf[I->second].push_back(I->first);
|
|
|
|
|
|
|
|
|
2002-01-31 07:20:39 +08:00
|
|
|
// Output debug information...
|
|
|
|
if (Parent == 0) PMDebug::PrintPassStructure(this);
|
|
|
|
|
|
|
|
// Run all of the passes
|
|
|
|
for (unsigned i = 0, e = Passes.size(); i < e; ++i) {
|
|
|
|
PassClass *P = Passes[i];
|
|
|
|
|
|
|
|
PMDebug::PrintPassInformation(getDepth(), "Executing Pass", P, (Value*)M);
|
|
|
|
|
|
|
|
// Get information about what analyses the pass uses...
|
|
|
|
std::vector<AnalysisID> Required, Destroyed, Provided;
|
|
|
|
P->getAnalysisUsageInfo(Required, Destroyed, Provided);
|
|
|
|
|
2002-02-01 02:32:27 +08:00
|
|
|
PMDebug::PrintAnalysisSetInfo(getDepth(), "Required", P, Required);
|
2002-01-31 07:20:39 +08:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
// All Required analyses should be available to the pass as it runs!
|
|
|
|
for (Pass::AnalysisSet::iterator I = Required.begin(),
|
|
|
|
E = Required.end(); I != E; ++I) {
|
|
|
|
assert(getAnalysisOrNullUp(*I) && "Analysis used but not available!");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Run the sub pass!
|
2002-02-01 12:53:36 +08:00
|
|
|
bool Changed = Traits::runPass(P, M);
|
|
|
|
MadeChanges |= Changed;
|
2002-01-31 07:20:39 +08:00
|
|
|
|
2002-02-01 12:53:36 +08:00
|
|
|
if (Changed)
|
|
|
|
PMDebug::PrintPassInformation(getDepth()+1, "Made Modification", P,
|
|
|
|
(Value*)M);
|
2002-02-01 02:32:27 +08:00
|
|
|
PMDebug::PrintAnalysisSetInfo(getDepth(), "Destroyed", P, Destroyed);
|
|
|
|
PMDebug::PrintAnalysisSetInfo(getDepth(), "Provided", P, Provided);
|
2002-01-31 07:20:39 +08:00
|
|
|
|
|
|
|
// Erase all analyses in the destroyed set...
|
|
|
|
for (Pass::AnalysisSet::iterator I = Destroyed.begin(),
|
|
|
|
E = Destroyed.end(); I != E; ++I)
|
|
|
|
CurrentAnalyses.erase(*I);
|
|
|
|
|
|
|
|
// Add all analyses in the provided set...
|
|
|
|
for (Pass::AnalysisSet::iterator I = Provided.begin(),
|
|
|
|
E = Provided.end(); I != E; ++I)
|
|
|
|
CurrentAnalyses[*I] = P;
|
|
|
|
|
2002-02-01 02:32:27 +08:00
|
|
|
// Free memory for any passes that we are the last use of...
|
|
|
|
std::vector<Pass*> &DeadPass = LastUserOf[P];
|
|
|
|
for (std::vector<Pass*>::iterator I = DeadPass.begin(),E = DeadPass.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
PMDebug::PrintPassInformation(getDepth()+1, "Freeing Pass", *I,
|
|
|
|
(Value*)M);
|
|
|
|
(*I)->releaseMemory();
|
|
|
|
}
|
2002-01-31 07:20:39 +08:00
|
|
|
}
|
2002-02-01 02:32:27 +08:00
|
|
|
return MadeChanges;
|
2002-01-31 07:20:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
// dumpPassStructure - Implement the -debug-passes=PassStructure option
|
|
|
|
virtual void dumpPassStructure(unsigned Offset = 0) {
|
2002-02-01 02:32:27 +08:00
|
|
|
std::cerr << std::string(Offset*2, ' ') << Traits::getPMName()
|
|
|
|
<< " Pass Manager\n";
|
2002-01-31 07:20:39 +08:00
|
|
|
for (std::vector<PassClass*>::iterator I = Passes.begin(), E = Passes.end();
|
2002-02-01 02:32:27 +08:00
|
|
|
I != E; ++I) {
|
|
|
|
PassClass *P = *I;
|
|
|
|
P->dumpPassStructure(Offset+1);
|
|
|
|
|
|
|
|
// Loop through and see which classes are destroyed after this one...
|
|
|
|
for (std::map<Pass*, Pass*>::iterator I = LastUseOf.begin(),
|
|
|
|
E = LastUseOf.end(); I != E; ++I) {
|
|
|
|
if (P == I->second) {
|
|
|
|
std::cerr << "Fr" << std::string(Offset*2, ' ');
|
|
|
|
I->first->dumpPassStructure(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-01-31 07:20:39 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-02-01 02:32:27 +08:00
|
|
|
Pass *getAnalysisOrNullDown(AnalysisID ID) const {
|
|
|
|
std::map<AnalysisID, Pass*>::const_iterator I = CurrentAnalyses.find(ID);
|
2002-01-31 07:20:39 +08:00
|
|
|
if (I == CurrentAnalyses.end()) {
|
|
|
|
if (Batcher)
|
|
|
|
return ((AnalysisResolver*)Batcher)->getAnalysisOrNullDown(ID);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return I->second;
|
|
|
|
}
|
|
|
|
|
2002-02-01 02:32:27 +08:00
|
|
|
Pass *getAnalysisOrNullUp(AnalysisID ID) const {
|
|
|
|
std::map<AnalysisID, Pass*>::const_iterator I = CurrentAnalyses.find(ID);
|
2002-01-31 07:20:39 +08:00
|
|
|
if (I == CurrentAnalyses.end()) {
|
|
|
|
if (Parent)
|
2002-02-01 02:32:27 +08:00
|
|
|
return Parent->getAnalysisOrNullUp(ID);
|
2002-01-31 07:20:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return I->second;
|
|
|
|
}
|
|
|
|
|
2002-02-01 02:32:27 +08:00
|
|
|
// markPassUsed - Inform higher level pass managers (and ourselves)
|
|
|
|
// that these analyses are being used by this pass. This is used to
|
|
|
|
// make sure that analyses are not free'd before we have to use
|
|
|
|
// them...
|
|
|
|
//
|
|
|
|
void markPassUsed(AnalysisID P, Pass *User) {
|
|
|
|
std::map<AnalysisID, Pass*>::iterator I = CurrentAnalyses.find(P);
|
|
|
|
if (I != CurrentAnalyses.end()) {
|
|
|
|
LastUseOf[I->second] = User; // Local pass, extend the lifetime
|
|
|
|
} else {
|
|
|
|
// Pass not in current available set, must be a higher level pass
|
|
|
|
// available to us, propogate to parent pass manager... We tell the
|
|
|
|
// parent that we (the passmanager) are using the analysis so that it
|
|
|
|
// frees the analysis AFTER this pass manager runs.
|
|
|
|
//
|
2002-03-18 05:16:01 +08:00
|
|
|
assert(Parent != 0 && "Pass available but not found! "
|
|
|
|
"Did your analysis pass 'Provide' itself?");
|
2002-02-01 02:32:27 +08:00
|
|
|
Parent->markPassUsed(P, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the number of parent PassManagers that exist
|
2002-01-31 07:20:39 +08:00
|
|
|
virtual unsigned getDepth() const {
|
|
|
|
if (Parent == 0) return 0;
|
2002-02-01 02:32:27 +08:00
|
|
|
return 1 + Parent->getDepth();
|
|
|
|
}
|
|
|
|
|
|
|
|
// add - Add a pass to the queue of passes to run. This passes ownership of
|
|
|
|
// the Pass to the PassManager. When the PassManager is destroyed, the pass
|
|
|
|
// will be destroyed as well, so there is no need to delete the pass. This
|
|
|
|
// implies that all passes MUST be new'd.
|
|
|
|
//
|
|
|
|
void add(PassClass *P) {
|
|
|
|
// Get information about what analyses the pass uses...
|
|
|
|
std::vector<AnalysisID> Required, Destroyed, Provided;
|
|
|
|
P->getAnalysisUsageInfo(Required, Destroyed, Provided);
|
|
|
|
|
|
|
|
// Loop over all of the analyses used by this pass,
|
|
|
|
for (std::vector<AnalysisID>::iterator I = Required.begin(),
|
|
|
|
E = Required.end(); I != E; ++I) {
|
|
|
|
if (getAnalysisOrNullDown(*I) == 0)
|
|
|
|
add((PassClass*)I->createPass());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tell the pass to add itself to this PassManager... the way it does so
|
|
|
|
// depends on the class of the pass, and is critical to laying out passes in
|
|
|
|
// an optimal order..
|
|
|
|
//
|
|
|
|
P->addToPassManager(this, Required, Destroyed, Provided);
|
2002-01-31 07:20:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// addPass - These functions are used to implement the subclass specific
|
|
|
|
// behaviors present in PassManager. Basically the add(Pass*) method ends up
|
|
|
|
// reflecting its behavior into a Pass::addToPassManager call. Subclasses of
|
|
|
|
// Pass override it specifically so that they can reflect the type
|
|
|
|
// information inherent in "this" back to the PassManager.
|
|
|
|
//
|
|
|
|
// For generic Pass subclasses (which are interprocedural passes), we simply
|
|
|
|
// add the pass to the end of the pass list and terminate any accumulation of
|
|
|
|
// MethodPasses that are present.
|
|
|
|
//
|
2002-02-01 02:32:27 +08:00
|
|
|
void addPass(PassClass *P, Pass::AnalysisSet &Required,
|
|
|
|
Pass::AnalysisSet &Destroyed, Pass::AnalysisSet &Provided) {
|
2002-01-31 07:20:39 +08:00
|
|
|
// Providers are analysis classes which are forbidden to modify the module
|
|
|
|
// they are operating on, so they are allowed to be reordered to before the
|
|
|
|
// batcher...
|
|
|
|
//
|
|
|
|
if (Batcher && Provided.empty())
|
|
|
|
closeBatcher(); // This pass cannot be batched!
|
|
|
|
|
|
|
|
// Set the Resolver instance variable in the Pass so that it knows where to
|
|
|
|
// find this object...
|
|
|
|
//
|
|
|
|
setAnalysisResolver(P, this);
|
|
|
|
Passes.push_back(P);
|
|
|
|
|
2002-02-01 02:32:27 +08:00
|
|
|
// Inform higher level pass managers (and ourselves) that these analyses are
|
|
|
|
// being used by this pass. This is used to make sure that analyses are not
|
|
|
|
// free'd before we have to use them...
|
|
|
|
//
|
|
|
|
for (std::vector<AnalysisID>::iterator I = Required.begin(),
|
|
|
|
E = Required.end(); I != E; ++I)
|
|
|
|
markPassUsed(*I, P); // Mark *I as used by P
|
|
|
|
|
2002-01-31 07:20:39 +08:00
|
|
|
// Erase all analyses in the destroyed set...
|
|
|
|
for (std::vector<AnalysisID>::iterator I = Destroyed.begin(),
|
|
|
|
E = Destroyed.end(); I != E; ++I)
|
|
|
|
CurrentAnalyses.erase(*I);
|
|
|
|
|
|
|
|
// Add all analyses in the provided set...
|
|
|
|
for (std::vector<AnalysisID>::iterator I = Provided.begin(),
|
|
|
|
E = Provided.end(); I != E; ++I)
|
|
|
|
CurrentAnalyses[*I] = P;
|
2002-02-01 02:32:27 +08:00
|
|
|
|
|
|
|
// For now assume that our results are never used...
|
|
|
|
LastUseOf[P] = P;
|
2002-01-31 07:20:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// For MethodPass subclasses, we must be sure to batch the MethodPasses
|
|
|
|
// together in a MethodPassBatcher object so that all of the analyses are run
|
|
|
|
// together a method at a time.
|
|
|
|
//
|
2002-02-01 02:32:27 +08:00
|
|
|
void addPass(SubPassClass *MP, Pass::AnalysisSet &Required,
|
|
|
|
Pass::AnalysisSet &Destroyed, Pass::AnalysisSet &Provided) {
|
2002-01-31 07:20:39 +08:00
|
|
|
if (Batcher == 0) // If we don't have a batcher yet, make one now.
|
|
|
|
Batcher = new BatcherClass(this);
|
|
|
|
// The Batcher will queue them passes up
|
2002-02-01 02:32:27 +08:00
|
|
|
MP->addToPassManager(Batcher, Required, Destroyed, Provided);
|
2002-01-31 07:20:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// closeBatcher - Terminate the batcher that is being worked on.
|
|
|
|
void closeBatcher() {
|
|
|
|
if (Batcher) {
|
|
|
|
Passes.push_back(Batcher);
|
|
|
|
Batcher = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PassManagerTraits<BasicBlock> Specialization
|
|
|
|
//
|
|
|
|
// This pass manager is used to group together all of the BasicBlockPass's
|
|
|
|
// into a single unit.
|
|
|
|
//
|
|
|
|
template<> struct PassManagerTraits<BasicBlock> : public BasicBlockPass {
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
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...
|
2002-03-24 06:51:58 +08:00
|
|
|
typedef PassManagerT<Function> ParentClass;
|
2002-01-31 07:20:39 +08:00
|
|
|
|
2002-01-31 08:40:44 +08:00
|
|
|
// PMType - The type of the passmanager that subclasses this class
|
|
|
|
typedef PassManagerT<BasicBlock> PMType;
|
|
|
|
|
2002-01-31 07:20:39 +08:00
|
|
|
// runPass - Specify how the pass should be run on the UnitType
|
|
|
|
static bool runPass(PassClass *P, BasicBlock *M) {
|
|
|
|
// todo, init and finalize
|
|
|
|
return P->runOnBasicBlock(M);
|
|
|
|
}
|
|
|
|
|
2002-02-01 02:32:27 +08:00
|
|
|
// getPMName() - Return the name of the unit the PassManager operates on for
|
|
|
|
// debugging.
|
|
|
|
const char *getPMName() const { return "BasicBlock"; }
|
|
|
|
|
2002-01-31 08:40:44 +08:00
|
|
|
// Implement the BasicBlockPass interface...
|
|
|
|
virtual bool doInitialization(Module *M);
|
2002-01-31 07:20:39 +08:00
|
|
|
virtual bool runOnBasicBlock(BasicBlock *BB);
|
2002-01-31 08:40:44 +08:00
|
|
|
virtual bool doFinalization(Module *M);
|
2002-01-31 07:20:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2002-03-24 06:51:58 +08:00
|
|
|
// PassManagerTraits<Function> Specialization
|
2002-01-31 07:20:39 +08:00
|
|
|
//
|
|
|
|
// This pass manager is used to group together all of the MethodPass's
|
|
|
|
// into a single unit.
|
|
|
|
//
|
2002-03-24 06:51:58 +08:00
|
|
|
template<> struct PassManagerTraits<Function> : public MethodPass {
|
2002-01-31 07:20:39 +08:00
|
|
|
// PassClass - The type of passes tracked by this PassManager
|
|
|
|
typedef MethodPass PassClass;
|
|
|
|
|
|
|
|
// SubPassClass - The types of classes that should be collated together
|
|
|
|
typedef BasicBlockPass SubPassClass;
|
|
|
|
|
|
|
|
// BatcherClass - The type to use for collation of subtypes...
|
|
|
|
typedef PassManagerT<BasicBlock> BatcherClass;
|
|
|
|
|
|
|
|
// ParentClass - The type of the parent PassManager...
|
|
|
|
typedef PassManagerT<Module> ParentClass;
|
|
|
|
|
|
|
|
// PMType - The type of the passmanager that subclasses this class
|
2002-03-24 06:51:58 +08:00
|
|
|
typedef PassManagerT<Function> PMType;
|
2002-01-31 07:20:39 +08:00
|
|
|
|
|
|
|
// runPass - Specify how the pass should be run on the UnitType
|
2002-03-24 06:51:58 +08:00
|
|
|
static bool runPass(PassClass *P, Function *M) {
|
2002-01-31 07:20:39 +08:00
|
|
|
return P->runOnMethod(M);
|
|
|
|
}
|
|
|
|
|
2002-02-01 02:32:27 +08:00
|
|
|
// getPMName() - Return the name of the unit the PassManager operates on for
|
|
|
|
// debugging.
|
2002-03-24 06:51:58 +08:00
|
|
|
const char *getPMName() const { return "Function"; }
|
2002-02-01 02:32:27 +08:00
|
|
|
|
2002-01-31 07:20:39 +08:00
|
|
|
// Implement the MethodPass interface...
|
|
|
|
virtual bool doInitialization(Module *M);
|
2002-03-24 06:51:58 +08:00
|
|
|
virtual bool runOnMethod(Function *M);
|
2002-01-31 07:20:39 +08:00
|
|
|
virtual bool doFinalization(Module *M);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PassManagerTraits<Module> Specialization
|
|
|
|
//
|
|
|
|
// This is the top level PassManager implementation that holds generic passes.
|
|
|
|
//
|
|
|
|
template<> struct PassManagerTraits<Module> : public Pass {
|
|
|
|
// PassClass - The type of passes tracked by this PassManager
|
|
|
|
typedef Pass PassClass;
|
|
|
|
|
|
|
|
// SubPassClass - The types of classes that should be collated together
|
|
|
|
typedef MethodPass SubPassClass;
|
|
|
|
|
|
|
|
// BatcherClass - The type to use for collation of subtypes...
|
2002-03-24 06:51:58 +08:00
|
|
|
typedef PassManagerT<Function> BatcherClass;
|
2002-01-31 07:20:39 +08:00
|
|
|
|
|
|
|
// ParentClass - The type of the parent PassManager...
|
2002-02-01 02:32:27 +08:00
|
|
|
typedef AnalysisResolver ParentClass;
|
2002-01-31 07:20:39 +08:00
|
|
|
|
|
|
|
// runPass - Specify how the pass should be run on the UnitType
|
|
|
|
static bool runPass(PassClass *P, Module *M) { return P->run(M); }
|
|
|
|
|
2002-02-01 02:32:27 +08:00
|
|
|
// getPMName() - Return the name of the unit the PassManager operates on for
|
|
|
|
// debugging.
|
|
|
|
const char *getPMName() const { return "Module"; }
|
|
|
|
|
2002-01-31 07:20:39 +08:00
|
|
|
// run - Implement the Pass interface...
|
|
|
|
virtual bool run(Module *M) {
|
|
|
|
return ((PassManagerT<Module>*)this)->runOnUnit(M);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PassManagerTraits Method Implementations
|
|
|
|
//
|
|
|
|
|
|
|
|
// PassManagerTraits<BasicBlock> Implementations
|
|
|
|
//
|
2002-01-31 08:40:44 +08:00
|
|
|
inline bool PassManagerTraits<BasicBlock>::doInitialization(Module *M) {
|
|
|
|
bool Changed = false;
|
|
|
|
for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
|
|
|
|
((PMType*)this)->Passes[i]->doInitialization(M);
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2002-01-31 07:20:39 +08:00
|
|
|
inline bool PassManagerTraits<BasicBlock>::runOnBasicBlock(BasicBlock *BB) {
|
2002-01-31 08:40:44 +08:00
|
|
|
return ((PMType*)this)->runOnUnit(BB);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool PassManagerTraits<BasicBlock>::doFinalization(Module *M) {
|
|
|
|
bool Changed = false;
|
|
|
|
for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
|
|
|
|
((PMType*)this)->Passes[i]->doFinalization(M);
|
|
|
|
return Changed;
|
2002-01-31 07:20:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-24 06:51:58 +08:00
|
|
|
// PassManagerTraits<Function> Implementations
|
2002-01-31 07:20:39 +08:00
|
|
|
//
|
2002-03-24 06:51:58 +08:00
|
|
|
inline bool PassManagerTraits<Function>::doInitialization(Module *M) {
|
2002-01-31 07:20:39 +08:00
|
|
|
bool Changed = false;
|
|
|
|
for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
|
|
|
|
((PMType*)this)->Passes[i]->doInitialization(M);
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2002-03-24 06:51:58 +08:00
|
|
|
inline bool PassManagerTraits<Function>::runOnMethod(Function *M) {
|
2002-01-31 07:20:39 +08:00
|
|
|
return ((PMType*)this)->runOnUnit(M);
|
|
|
|
}
|
|
|
|
|
2002-03-24 06:51:58 +08:00
|
|
|
inline bool PassManagerTraits<Function>::doFinalization(Module *M) {
|
2002-01-31 07:20:39 +08:00
|
|
|
bool Changed = false;
|
|
|
|
for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
|
|
|
|
((PMType*)this)->Passes[i]->doFinalization(M);
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|