<div dir="ltr">Hi, <div>I am trying to write my own command-line tool which would use alias analysis in a CallGraphSCCPass. <br clear="all"><div><br></div><div>Firstly, I inherit a class AnalysisDriver from CallGraphSCCPass. </div>
<div>Then, I implement my own runOnFunction method which tries to get alias analysis from each function.</div><div><br></div><div>The code is shown as follows:</div><div><br></div><div><div><i>class AnalysisDriver : public CallGraphSCCPass {</i></div>
<div><i> static char Pid;</i></div><div><i> PassManager &passMgr;</i></div><div><i> </i></div><div><i>public:</i></div><div><i> AnalysisDriver(PassManager &pmgr);</i></div><div><i> ~AnalysisDriver();</i></div>
<div><i><br></i></div><div><i> virtual void getAnalysisUsage(AnalysisUsage &AU) const {</i></div><div><i> AU.addRequired<CallGraph>();</i></div><div><i> AU.addRequired<AliasAnalysis>();</i></div><div>
<i> AU.addPreserved<AliasAnalysis>();</i></div><div><i> }</i></div><div><i> </i></div><div><i> bool run(Module &module);</i></div><div><i> virtual bool runOnSCC(CallGraphSCC &scc);</i></div><div><i> virtual bool runOnFunction(Function *f) = 0;</i></div>
<div><i><br></i></div><div><i> virtual const char *getPassName() const {</i></div><div><i> return "AnalysisDriver";</i></div><div><i> }</i></div><div><i> </i></div><div><i>private:</i></div><div><i> void registerDriver();</i></div>
<div><i>};</i></div></div><div><br></div><div><div><i>char AnalysisDriver::Pid;</i></div><div><i><br></i></div><div><i>AnalysisDriver::AnalysisDriver(PassManager &pmgr)</i></div><div><i> : CallGraphSCCPass(Pid), passMgr(pmgr) {</i></div>
<div><i> registerDriver();</i></div><div><i>}</i></div><div><i><br></i></div><div><i>AnalysisDriver::~AnalysisDriver() {}</i></div><div><i><br></i></div><div><i>void AnalysisDriver::registerDriver() {</i></div><div><i> PassRegistry &Registry = *PassRegistry::getPassRegistry();</i></div>
<div><i> </i></div><div><i><font color="#ff0000"> // Register AliasAnalysis and CallGraph pass</font></i></div><div><i><font color="#ff0000"> INITIALIZE_AG_DEPENDENCY(AliasAnalysis);</font></i></div><div><i><font color="#ff0000"> INITIALIZE_AG_DEPENDENCY(CallGraph);</font></i></div>
<div><i><br></i></div><div><i> passMgr.add(this);</i></div><div><i>}</i></div><div><i><br></i></div><div><i>bool AnalysisDriver::run(Module &module) {</i></div><div><i> passMgr.run(module);</i></div><div><i>}</i></div>
<div><i><br></i></div><div><i>bool AnalysisDriver::runOnSCC(CallGraphSCC &scc) {</i></div><div><i> for (CallGraphSCC::iterator i = scc.begin(),</i></div><div><i> e = scc.end(); i != e; ++i) {</i></div>
<div><i> CallGraphNode *cgnode = *i;</i></div><div><i> Function *f = cgnode->getFunction();</i></div><div><i> if (f == NULL || f->isDeclaration())</i></div><div><i> continue;</i></div><div><i><br></i></div>
<div><i> runOnFunction(f);</i></div><div><i> }</i></div><div><i> return false;</i></div><div><i>}</i></div></div><div><i><br></i></div><div><i>bool AnalysisDriver::runOnFunction(Function *f) {</i></div><div><i> <font color="#ff0000">AliasAnalysis &aa = getAnalysis<AliasAnalysis>(*f);</font></i></div>
<div><i> ...</i></div><div><i>}</i></div><div><i><br></i></div><div><i>int main(void) {</i></div><div><i> ...</i></div><div><i> PassManager passMgr;</i></div><div><i> AnalysisDriver *d = new AnalysisDriver(passMgr);</i></div>
<div><i> d->run(module);</i></div><div><i> return 0;</i></div><div><i>}</i></div><div><br></div><div>When I try to get alias analysis, it complains:</div><div>"Unable to find on the fly pass"<br></div><div>
"UNREACHABLE executed at ./llvm/lib/IR/PassManager.cpp:1254!"<br></div><div><br></div><div>The debug pass details:</div><div><div>Pass Arguments: -no-aa -basiccg</div><div>No Alias Analysis (always returns 'may' alias)</div>
<div> ModulePass Manager</div><div> Basic CallGraph Construction</div><div> Call Graph SCC Pass Manager</div><div> AnalysisDriver</div><div>0x1b15dd0 Executing Pass 'Basic CallGraph Construction' on Module 'alias.s'...</div>
<div>0x1b15dd0 Executing Pass 'CallGraph Pass Manager' on Module 'alias.s'...</div><div>0x1b154a0 Required Analyses: Basic CallGraph Construction</div><div>0x1b154c0 Executing Pass 'AnalysisDriver' on Call Graph Nodes 'Call graph node for function: 'f'<<0x1b1b350>> #uses=1</div>
<div><br></div><div>'...</div><div>0x1b106e0 Required Analyses: Basic CallGraph Construction, No Alias Analysis (always returns 'may' alias)</div></div><div><br></div><div>Do I miss something?</div><div>
By the way, how do I use basicaa instead of no-aa?</div><div><br></div><div>Thank you!</div>-- <br>Zhenbo Xu
</div></div>