This is what you need:<div><div><br></div><div>#include "llvm/InitializePasses.h"</div></div><div><br></div><div><div> PassRegistry &Registry = *PassRegistry::getPassRegistry();</div><div> initializeBasicCallGraphPass(Registry);</div>
<div><br></div><div><br></div><div>-Welson</div><br><div class="gmail_quote">On Fri, Aug 17, 2012 at 1:36 AM, Hongbin Zheng <span dir="ltr"><<a href="mailto:etherzhhb@gmail.com" target="_blank">etherzhhb@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Fri, Aug 17, 2012 at 4:23 PM, Jianfei Hu <<a href="mailto:hujianfei258@gmail.com">hujianfei258@gmail.com</a>> wrote:<br>
> Hello,<br>
> I want to traverse CallGraph<br>
><br>
> code segment:<br>
><br>
><br>
> virtual void getAnalysisUsage(AnalysisUsage &AU) const<br>
> {<br>
> AU.addRequired<CallGraph>();<br>
> }<br>
><br>
> virtual bool runOnModule(Module &F)<br>
> {<br>
> CallGraph &g = getAnalysis<CallGraph>();<br>
> for ( CallGraph::iterator i = g.begin(); i != g.end(); i++)<br>
> {<br>
> errs()<<"-----------------\n";<br>
</div>You may try something like this:<br>
if (CallGraphNode *CGN = i->second)<br>
... CGN->getFunction()->getName() ...<br>
<div class="HOEnZb"><div class="h5">> errs()<<i->second->getFunction()->getName()<<"\n";<br>
> }<br>
> return false;<br>
> }<br>
><br>
> Compile:<br>
> g++ -fPIC -shared `llvm-config --cxxflags` -o MPIAnalysis.so MPIAnalysis.cpp,<br>
><br>
> when I use following command to run:<br>
> opt -load ./MPIAnalysis.so -hello < main<br>
> it shows the error:<br>
><br>
> -----------------<br>
> 0 opt 0x085cddc8<br>
> Stack dump:<br>
> 0. Program arguments: opt -load ./MPIAnalysis.so -hello<br>
> 1. Running pass 'Hello World Pass' on module '<stdin>'.<br>
> Segmentation Error<br>
><br>
> I found similar Problem in<br>
> <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2010-July/033133.html" target="_blank">http://lists.cs.uiuc.edu/pipermail/llvmdev/2010-July/033133.html</a><br>
> But all function are defined in single binary IR file 'main', none of<br>
> them are external.<br>
><br>
> Why could not print the name of CallGraphNode's function name?<br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Welson<div><br></div><div>Phone: (408) 418-8385</div><div>Email: <a href="mailto:welson.sun@gmail.com" target="_blank">welson.sun@gmail.com</a></div>
<div><br></div><br>
</div>