initialization value is not important.</p>
<div class="doc_code"><pre>
- RegisterPass<Hello> X("<i>hello</i>", "<i>Hello World Pass</i>");
+ RegisterPass<Hello> X("<i>hello</i>", "<i>Hello World Pass</i>",
+ false /* Only looks at CFG */,
+ false /* Analysis Pass */);
} <i>// end of anonymous namespace</i>
</pre></div>
<p>Lastly, we <a href="#registration">register our class</a> <tt>Hello</tt>,
giving it a command line
-argument "<tt>hello</tt>", and a name "<tt>Hello World Pass</tt>".</p>
+argument "<tt>hello</tt>", and a name "<tt>Hello World Pass</tt>".
+Last two RegisterPass arguments are optional. Their default value is false.
+If a pass walks CFG without modifying it then third argument is set to true.
+If a pass is an analysis pass, for example dominator tree pass, then true
+is supplied as fourth argument. </p>
<p>As a whole, the <tt>.cpp</tt> file looks like:</p>
static char ID; // Pass ID, replacement for typeid
DominatorTreeBase<BasicBlock>* DT;
- DominatorTree() : FunctionPass(intptr_t(&ID), true) {
+ DominatorTree() : FunctionPass(intptr_t(&ID)) {
DT = new DominatorTreeBase<BasicBlock>(false);
}
public:
DominanceFrontierBase(intptr_t ID, bool isPostDom)
- : FunctionPass(ID, true), IsPostDominators(isPostDom) {}
+ : FunctionPass(ID), IsPostDominators(isPostDom) {}
/// getRoots - Return the root blocks of the current CFG. This may include
/// multiple blocks if we are computing post dominators. For forward
std::set<const Type *> UsedTypes;
public:
static char ID; // Pass identification, replacement for typeid
- FindUsedTypes() : ModulePass((intptr_t)&ID, true) {}
+ FindUsedTypes() : ModulePass((intptr_t)&ID) {}
/// getTypes - After the pass has been run, return the set containing all of
/// the types used in the module.
public:
static char ID; // Pass identification, replacement for typeid
- IntervalPartition() : FunctionPass((intptr_t)&ID, true), RootInterval(0) {}
+ IntervalPartition() : FunctionPass((intptr_t)&ID), RootInterval(0) {}
// run - Calculate the interval partition for this function
virtual bool runOnFunction(Function &F);
public:
static char ID; // Pass identification, replacement for typeid
- LoopInfo() : FunctionPass(intptr_t(&ID), true) {
+ LoopInfo() : FunctionPass(intptr_t(&ID)) {
LI = new LoopInfoBase<BasicBlock>();
}
return LI->isLoopHeader(BB);
}
+ /// isAnalysis - Return true if this pass is implementing an analysis pass.
+ bool isAnalysis() const { return true; }
+
/// runOnFunction - Calculate the natural loop information.
///
virtual bool runOnFunction(Function &F);
class LoopPass : public Pass {
public:
- explicit LoopPass(intptr_t pid, bool AP = false) : Pass(pid, AP) {}
+ explicit LoopPass(intptr_t pid) : Pass(pid) {}
// runOnLoop - This method should be implemented by the subclass to perform
// whatever action is necessary for the specfied Loop.
static Instruction* const Dirty;
static char ID; // Class identification, replacement for typeinfo
- MemoryDependenceAnalysis() : FunctionPass((intptr_t)&ID, true) {}
+ MemoryDependenceAnalysis() : FunctionPass((intptr_t)&ID) {}
/// Pass Implementation stuff. This doesn't do any analysis.
///
static char ID; // Pass identification, replacement for typeid
DominatorTreeBase<BasicBlock>* DT;
- PostDominatorTree() : FunctionPass((intptr_t)&ID, true) {
+ PostDominatorTree() : FunctionPass((intptr_t)&ID) {
DT = new DominatorTreeBase<BasicBlock>(true);
}
void *Impl; // ScalarEvolution uses the pimpl pattern
public:
static char ID; // Pass identification, replacement for typeid
- ScalarEvolution() : FunctionPass((intptr_t)&ID, true), Impl(0) {}
+ ScalarEvolution() : FunctionPass((intptr_t)&ID), Impl(0) {}
/// getSCEV - Return a SCEV expression handle for the full generality of the
/// specified expression.
struct CallGraphSCCPass : public Pass {
- explicit CallGraphSCCPass(intptr_t pid, bool AP = false) : Pass(pid, AP) {}
+ explicit CallGraphSCCPass(intptr_t pid) : Pass(pid) {}
/// doInitialization - This method is called before the SCC's of the program
/// has been processed, allowing the pass to do initialization as necessary.
class Pass {
AnalysisResolver *Resolver; // Used to resolve analysis
intptr_t PassID;
- bool isAnalysisPass; // True if this pass is an analysis pass.
// AnalysisImpls - This keeps track of which passes implement the interfaces
// that are required by the current pass (to implement getAnalysis()).
//
void operator=(const Pass&); // DO NOT IMPLEMENT
Pass(const Pass &); // DO NOT IMPLEMENT
public:
- explicit Pass(intptr_t pid, bool AP = false) : Resolver(0), PassID(pid),
- isAnalysisPass(AP) {}
- explicit Pass(const void *pid, bool AP = false) : Resolver(0),
- PassID((intptr_t)pid),
- isAnalysisPass(AP) {}
+ explicit Pass(intptr_t pid) : Resolver(0), PassID(pid) {}
+ explicit Pass(const void *pid) : Resolver(0),
+ PassID((intptr_t)pid) {}
virtual ~Pass();
- bool isAnalysis() const { return isAnalysisPass; }
/// getPassName - Return a nice clean name for a pass. This usually
/// implemented in terms of the name that is registered by one of the
/// Registration templates, but can be overloaded directly.
return PMT_ModulePassManager;
}
- explicit ModulePass(intptr_t pid, bool AP = false) : Pass(pid, AP) {}
- explicit ModulePass(const void *pid, bool AP = false) : Pass(pid, AP) {}
+ explicit ModulePass(intptr_t pid) : Pass(pid) {}
+ explicit ModulePass(const void *pid) : Pass(pid) {}
// Force out-of-line virtual method.
virtual ~ModulePass();
};
///
bool runOnModule(Module &M) { return false; }
- explicit ImmutablePass(intptr_t pid, bool AP = false) : ModulePass(pid, AP) {}
- explicit ImmutablePass(const void *pid, bool AP = false)
- : ModulePass(pid, AP) {}
+ explicit ImmutablePass(intptr_t pid) : ModulePass(pid) {}
+ explicit ImmutablePass(const void *pid)
+ : ModulePass(pid) {}
// Force out-of-line virtual method.
virtual ~ImmutablePass();
///
class FunctionPass : public Pass {
public:
- explicit FunctionPass(intptr_t pid, bool AP = false) : Pass(pid, AP) {}
- explicit FunctionPass(const void *pid, bool AP = false) : Pass(pid, AP) {}
+ explicit FunctionPass(intptr_t pid) : Pass(pid) {}
+ explicit FunctionPass(const void *pid) : Pass(pid) {}
/// doInitialization - Virtual method overridden by subclasses to do
/// any necessary per-module initialization.
///
class BasicBlockPass : public Pass {
public:
- explicit BasicBlockPass(intptr_t pid, bool AP = false) : Pass(pid, AP) {}
- explicit BasicBlockPass(const void *pid, bool AP = false) : Pass(pid, AP) {}
+ explicit BasicBlockPass(intptr_t pid) : Pass(pid) {}
+ explicit BasicBlockPass(const void *pid) : Pass(pid) {}
/// doInitialization - Virtual method overridden by subclasses to do
/// any necessary per-module initialization.
const char *PassArgument; // Command Line argument to run this pass
intptr_t PassID;
bool IsCFGOnlyPass; // Pass only looks at the CFG.
+ bool IsAnalysis; // True if an analysis pass.
bool IsAnalysisGroup; // True if an analysis group.
std::vector<const PassInfo*> ItfImpl;// Interfaces implemented by this pass
/// PassInfo ctor - Do not call this directly, this should only be invoked
/// through RegisterPass.
PassInfo(const char *name, const char *arg, intptr_t pi,
- Pass *(*normal)() = 0, bool isCFGOnly = false)
+ Pass *(*normal)() = 0, bool isCFGOnly = false, bool isAnalysis = false)
: PassName(name), PassArgument(arg), PassID(pi),
- IsCFGOnlyPass(isCFGOnly), IsAnalysisGroup(false), NormalCtor(normal) {
+ IsCFGOnlyPass(isCFGOnly),
+ IsAnalysis(isAnalysis), IsAnalysisGroup(false), NormalCtor(normal) {
}
/// getPassName - Return the friendly name for the pass, never returns null
/// pass.
///
bool isAnalysisGroup() const { return IsAnalysisGroup; }
+ bool isAnalysis() const { return IsAnalysis; }
void SetIsAnalysisGroup() { IsAnalysisGroup = true; }
/// isCFGOnlyPass - return true if this pass only looks at the CFG for the
typedef Pass* (*NormalCtor_t)();
RegisterPassBase(const char *Name, const char *Arg, intptr_t TI,
- NormalCtor_t NormalCtor = 0, bool CFGOnly = false)
- : PIObj(Name, Arg, TI, NormalCtor, CFGOnly) {
+ NormalCtor_t NormalCtor = 0, bool CFGOnly = false,
+ bool IsAnalysis = false)
+ : PIObj(Name, Arg, TI, NormalCtor, CFGOnly, IsAnalysis) {
registerPass();
}
explicit RegisterPassBase(intptr_t TI)
struct RegisterPass : public RegisterPassBase {
// Register Pass using default constructor...
- RegisterPass(const char *PassArg, const char *Name, bool CFGOnly = false)
+ RegisterPass(const char *PassArg, const char *Name, bool CFGOnly = false,
+ bool IsAnalysis = false)
: RegisterPassBase(Name, PassArg, intptr_t(&PassName::ID),
- RegisterPassBase::NormalCtor_t(callDefaultCtor<PassName>), CFGOnly) {
+ RegisterPassBase::NormalCtor_t(callDefaultCtor<PassName>),
+ CFGOnly, IsAnalysis) {
}
};
Module *M;
public:
static char ID; // Class identification, replacement for typeinfo
- AliasAnalysisCounter() : ModulePass((intptr_t) &ID, true) {
+ AliasAnalysisCounter() : ModulePass((intptr_t) &ID) {
No = May = Must = 0;
NoMR = JustRef = JustMod = MR = 0;
}
char AliasAnalysisCounter::ID = 0;
RegisterPass<AliasAnalysisCounter>
- X("count-aa", "Count Alias Analysis Query Responses");
+ X("count-aa", "Count Alias Analysis Query Responses", true, true);
RegisterAnalysisGroup<AliasAnalysis> Y(X);
}
public:
static char ID; // Pass identification, replacement for typeid
- AAEval() : FunctionPass((intptr_t)&ID, true) {}
+ AAEval() : FunctionPass((intptr_t)&ID) {}
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<AliasAnalysis>();
char AAEval::ID = 0;
RegisterPass<AAEval>
- X("aa-eval", "Exhaustive Alias Analysis Precision Evaluator");
+ X("aa-eval", "Exhaustive Alias Analysis Precision Evaluator", true, true);
}
FunctionPass *llvm::createAAEvalPass() { return new AAEval(); }
public:
static char ID; // Class identification, replacement for typeinfo
- AliasDebugger() : ModulePass((intptr_t)&ID, true) {}
+ AliasDebugger() : ModulePass((intptr_t)&ID) {}
bool runOnModule(Module &M) {
InitializeAliasAnalysis(this); // set up super class
};
char AliasDebugger::ID = 0;
- RegisterPass<AliasDebugger> X("debug-aa", "AA use debugger");
+ RegisterPass<AliasDebugger> X("debug-aa", "AA use debugger", true, true);
RegisterAnalysisGroup<AliasAnalysis> Y(X);
}
AliasSetTracker *Tracker;
public:
static char ID; // Pass identification, replacement for typeid
- AliasSetPrinter() : FunctionPass((intptr_t)&ID, true) {}
+ AliasSetPrinter() : FunctionPass((intptr_t)&ID) {}
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
}
};
char AliasSetPrinter::ID = 0;
- RegisterPass<AliasSetPrinter> X("print-alias-sets", "Alias Set Printer");
+ RegisterPass<AliasSetPrinter> X("print-alias-sets", "Alias Set Printer", true, true);
}
// Register this pass...
char NoAA::ID = 0;
RegisterPass<NoAA>
- U("no-aa", "No Alias Analysis (always returns 'may' alias)");
+ U("no-aa", "No Alias Analysis (always returns 'may' alias)", true, true);
// Declare that we implement the AliasAnalysis interface
RegisterAnalysisGroup<AliasAnalysis> V(U);
// Register this pass...
char BasicAliasAnalysis::ID = 0;
RegisterPass<BasicAliasAnalysis>
- X("basicaa", "Basic Alias Analysis (default AA impl)");
+ X("basicaa", "Basic Alias Analysis (default AA impl)", true, true);
// Declare that we implement the AliasAnalysis interface
RegisterAnalysisGroup<AliasAnalysis, true> Y(X);
namespace {
struct VISIBILITY_HIDDEN CFGViewer : public FunctionPass {
static char ID; // Pass identifcation, replacement for typeid
- CFGViewer() : FunctionPass((intptr_t)&ID, true) {}
+ CFGViewer() : FunctionPass((intptr_t)&ID) {}
virtual bool runOnFunction(Function &F) {
F.viewCFG();
char CFGViewer::ID = 0;
RegisterPass<CFGViewer> V0("view-cfg",
- "View CFG of function");
+ "View CFG of function", true, true);
struct VISIBILITY_HIDDEN CFGOnlyViewer : public FunctionPass {
static char ID; // Pass identifcation, replacement for typeid
- CFGOnlyViewer() : FunctionPass((intptr_t)&ID, true) {}
+ CFGOnlyViewer() : FunctionPass((intptr_t)&ID) {}
virtual bool runOnFunction(Function &F) {
CFGOnly = true;
char CFGOnlyViewer::ID = 0;
RegisterPass<CFGOnlyViewer> V1("view-cfg-only",
- "View CFG of function (with no function bodies)");
+ "View CFG of function (with no function bodies)", true, true);
struct VISIBILITY_HIDDEN CFGPrinter : public FunctionPass {
static char ID; // Pass identification, replacement for typeid
CFGPrinter() : FunctionPass((intptr_t)&ID) {}
- explicit CFGPrinter(intptr_t pid) : FunctionPass(pid, true) {}
+ explicit CFGPrinter(intptr_t pid) : FunctionPass(pid) {}
virtual bool runOnFunction(Function &F) {
std::string Filename = "cfg." + F.getName() + ".dot";
char CFGPrinter::ID = 0;
RegisterPass<CFGPrinter> P1("print-cfg",
- "Print CFG of function to 'dot' file");
+ "Print CFG of function to 'dot' file", true, true);
struct VISIBILITY_HIDDEN CFGOnlyPrinter : public CFGPrinter {
static char ID; // Pass identification, replacement for typeid
char CFGOnlyPrinter::ID = 0;
RegisterPass<CFGOnlyPrinter>
P2("print-cfg-only",
- "Print CFG of function to 'dot' file (with no function bodies)");
+ "Print CFG of function to 'dot' file (with no function bodies)", true, true);
}
/// viewCFG - This function is meant for use from the debugger. You can just
public:
static char ID;
- Andersens() : ModulePass((intptr_t)&ID, true) {}
+ Andersens() : ModulePass((intptr_t)&ID) {}
bool runOnModule(Module &M) {
InitializeAliasAnalysis(this);
char Andersens::ID = 0;
RegisterPass<Andersens> X("anders-aa",
- "Andersen's Interprocedural Alias Analysis");
+ "Andersen's Interprocedural Alias Analysis", true,
+ true);
RegisterAnalysisGroup<AliasAnalysis> Y(X);
// Initialize Timestamp Counter (static).
};
RegisterAnalysisGroup<CallGraph> X("Call Graph");
-RegisterPass<BasicCallGraph> Y("basiccg", "Basic CallGraph Construction");
+RegisterPass<BasicCallGraph> Y("basiccg", "Basic CallGraph Construction", false, true);
RegisterAnalysisGroup<CallGraph, true> Z(Y);
} //End anonymous namespace
char FindUsedTypes::ID = 0;
static RegisterPass<FindUsedTypes>
-X("printusedtypes", "Find Used Types");
+X("printusedtypes", "Find Used Types", true, true);
// IncorporateType - Incorporate one type and all of its subtypes into the
// collection of used types.
public:
static char ID;
- GlobalsModRef() : ModulePass((intptr_t)&ID, true) {}
+ GlobalsModRef() : ModulePass((intptr_t)&ID) {}
bool runOnModule(Module &M) {
InitializeAliasAnalysis(this); // set up super class
char GlobalsModRef::ID = 0;
RegisterPass<GlobalsModRef> X("globalsmodref-aa",
- "Simple mod/ref analysis for globals");
+ "Simple mod/ref analysis for globals", true,
+ true);
RegisterAnalysisGroup<AliasAnalysis> Y(X);
}
}
public:
static char ID; // Pass identification, replacement for typeid
- InstCount() : FunctionPass((intptr_t)&ID, true) {}
+ InstCount() : FunctionPass((intptr_t)&ID) {}
virtual bool runOnFunction(Function &F);
char InstCount::ID = 0;
RegisterPass<InstCount> X("instcount",
- "Counts the various types of Instructions");
+ "Counts the various types of Instructions", true, true);
}
FunctionPass *llvm::createInstCountPass() { return new InstCount(); }
char IntervalPartition::ID = 0;
static RegisterPass<IntervalPartition>
-X("intervals", "Interval Partition Construction", true);
+X("intervals", "Interval Partition Construction", true, true);
//===----------------------------------------------------------------------===//
// IntervalPartition Implementation
// FIXME: This should not be a FunctionPass.
struct VISIBILITY_HIDDEN LoadVN : public FunctionPass, public ValueNumbering {
static char ID; // Class identification, replacement for typeinfo
- LoadVN() : FunctionPass((intptr_t)&ID, true) {}
+ LoadVN() : FunctionPass((intptr_t)&ID) {}
/// Pass Implementation stuff. This doesn't do any analysis.
///
char LoadVN::ID = 0;
// Register this pass...
- RegisterPass<LoadVN> X("load-vn", "Load Value Numbering");
+ RegisterPass<LoadVN> X("load-vn", "Load Value Numbering", true, true);
// Declare that we implement the ValueNumbering interface
RegisterAnalysisGroup<ValueNumbering> Y(X);
char LoopInfo::ID = 0;
static RegisterPass<LoopInfo>
-X("loops", "Natural Loop Construction", true);
+X("loops", "Natural Loop Construction", true, true);
//===----------------------------------------------------------------------===//
// Loop implementation
// Register this pass...
static RegisterPass<MemoryDependenceAnalysis> X("memdep",
- "Memory Dependence Analysis");
+ "Memory Dependence Analysis", true, true);
void MemoryDependenceAnalysis::ping(Instruction *D) {
for (depMapType::iterator I = depGraphLocal.begin(), E = depGraphLocal.end();
char PostDominatorTree::ID = 0;
char PostDominanceFrontier::ID = 0;
static RegisterPass<PostDominatorTree>
-F("postdomtree", "Post-Dominator Tree Construction", true);
+F("postdomtree", "Post-Dominator Tree Construction", true, true);
bool PostDominatorTree::runOnFunction(Function &F) {
DT->recalculate(F);
//===----------------------------------------------------------------------===//
static RegisterPass<PostDominanceFrontier>
-H("postdomfrontier", "Post-Dominance Frontier Construction", true);
+H("postdomfrontier", "Post-Dominance Frontier Construction", true, true);
const DominanceFrontier::DomSetType &
PostDominanceFrontier::calculate(const PostDominatorTree &DT,
char NoProfileInfo::ID = 0;
// Register this pass...
RegisterPass<NoProfileInfo>
- X("no-profile", "No Profile Information");
+ X("no-profile", "No Profile Information", true, true);
// Declare that we implement the ProfileInfo interface
RegisterAnalysisGroup<ProfileInfo, true> Y(X);
public:
static char ID; // Class identification, replacement for typeinfo
explicit LoaderPass(const std::string &filename = "")
- : ModulePass((intptr_t)&ID, true), Filename(filename) {
+ : ModulePass((intptr_t)&ID), Filename(filename) {
if (filename.empty()) Filename = ProfileInfoFilename;
}
char LoaderPass::ID = 0;
RegisterPass<LoaderPass>
- X("profile-loader", "Load profile information from llvmprof.out");
+ X("profile-loader", "Load profile information from llvmprof.out", true, true);
RegisterAnalysisGroup<ProfileInfo> Y(X);
} // End of anonymous namespace
namespace {
RegisterPass<ScalarEvolution>
- R("scalar-evolution", "Scalar Evolution Analysis");
+ R("scalar-evolution", "Scalar Evolution Analysis", true, true);
}
char ScalarEvolution::ID = 0;
char BasicVN::ID = 0;
// Register this pass...
RegisterPass<BasicVN>
- X("basicvn", "Basic Value Numbering (default GVN impl)");
+ X("basicvn", "Basic Value Numbering (default GVN impl)", true, true);
// Declare that we implement the ValueNumbering interface
RegisterAnalysisGroup<ValueNumbering, true> Y(X);
// Handle the Pass registration stuff necessary to use TargetData's.
namespace {
// Register the default SparcV9 implementation...
- RegisterPass<TargetData> X("targetdata", "Target Data Layout");
+ RegisterPass<TargetData> X("targetdata", "Target Data Layout", false,
+ true);
}
char TargetData::ID = 0;
char DominatorTree::ID = 0;
static RegisterPass<DominatorTree>
-E("domtree", "Dominator Tree Construction", true);
+E("domtree", "Dominator Tree Construction", true, true);
bool DominatorTree::runOnFunction(Function &F) {
DT->recalculate(F);
char DominanceFrontier::ID = 0;
static RegisterPass<DominanceFrontier>
-G("domfrontier", "Dominance Frontier Construction", true);
+G("domfrontier", "Dominance Frontier Construction", true, true);
// NewBB is split and now it has one successor. Update dominace frontier to
// reflect this change.
// Give pass a chance to prepare the stage.
P->preparePassManager(activeStack);
+#if 1
// If P is an analysis pass and it is available then do not
// generate the analysis again. Stale analysis info should not be
// available at this point.
- if (P->isAnalysis() && findAnalysisPass(P->getPassInfo()))
+ if (P->getPassInfo() &&
+ P->getPassInfo()->isAnalysis() && findAnalysisPass(P->getPassInfo()))
return;
+#endif
AnalysisUsage AnUsage;
P->getAnalysisUsage(AnUsage);