Hello, I want to traverse CallGraph code segment: virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired<CallGraph>(); } virtual bool runOnModule(Module &F) { CallGraph &g = getAnalysis<CallGraph>(); for ( CallGraph::iterator i = g.begin(); i != g.end(); i++) { errs()<<"-----------------\n"; errs()<<i->second->getFunction()->getName()<<"\n"; } return false; } Compile: g++ -fPIC -shared `llvm-config --cxxflags` -o MPIAnalysis.so MPIAnalysis.cpp, when I use following command to run: opt -load ./MPIAnalysis.so -hello < main it shows the error: ----------------- 0 opt 0x085cddc8 Stack dump: 0. Program arguments: opt -load ./MPIAnalysis.so -hello 1. Running pass 'Hello World Pass' on module '<stdin>'. Segmentation Error I found similar Problem in http://lists.cs.uiuc.edu/pipermail/llvmdev/2010-July/033133.html But all function are defined in single binary IR file 'main', none of them are external. Why could not print the name of CallGraphNode's function name?
On Fri, Aug 17, 2012 at 4:23 PM, Jianfei Hu <hujianfei258 at gmail.com> wrote:> Hello, > I want to traverse CallGraph > > code segment: > > > virtual void getAnalysisUsage(AnalysisUsage &AU) const > { > AU.addRequired<CallGraph>(); > } > > virtual bool runOnModule(Module &F) > { > CallGraph &g = getAnalysis<CallGraph>(); > for ( CallGraph::iterator i = g.begin(); i != g.end(); i++) > { > errs()<<"-----------------\n";You may try something like this: if (CallGraphNode *CGN = i->second) ... CGN->getFunction()->getName() ...> errs()<<i->second->getFunction()->getName()<<"\n"; > } > return false; > } > > Compile: > g++ -fPIC -shared `llvm-config --cxxflags` -o MPIAnalysis.so MPIAnalysis.cpp, > > when I use following command to run: > opt -load ./MPIAnalysis.so -hello < main > it shows the error: > > ----------------- > 0 opt 0x085cddc8 > Stack dump: > 0. Program arguments: opt -load ./MPIAnalysis.so -hello > 1. Running pass 'Hello World Pass' on module '<stdin>'. > Segmentation Error > > I found similar Problem in > http://lists.cs.uiuc.edu/pipermail/llvmdev/2010-July/033133.html > But all function are defined in single binary IR file 'main', none of > them are external. > > Why could not print the name of CallGraphNode's function name? > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
This is what you need: #include "llvm/InitializePasses.h" PassRegistry &Registry = *PassRegistry::getPassRegistry(); initializeBasicCallGraphPass(Registry); -Welson On Fri, Aug 17, 2012 at 1:36 AM, Hongbin Zheng <etherzhhb at gmail.com> wrote:> On Fri, Aug 17, 2012 at 4:23 PM, Jianfei Hu <hujianfei258 at gmail.com> > wrote: > > Hello, > > I want to traverse CallGraph > > > > code segment: > > > > > > virtual void getAnalysisUsage(AnalysisUsage &AU) const > > { > > AU.addRequired<CallGraph>(); > > } > > > > virtual bool runOnModule(Module &F) > > { > > CallGraph &g = getAnalysis<CallGraph>(); > > for ( CallGraph::iterator i = g.begin(); i !> g.end(); i++) > > { > > errs()<<"-----------------\n"; > You may try something like this: > if (CallGraphNode *CGN = i->second) > ... CGN->getFunction()->getName() ... > > > errs()<<i->second->getFunction()->getName()<<"\n"; > > } > > return false; > > } > > > > Compile: > > g++ -fPIC -shared `llvm-config --cxxflags` -o MPIAnalysis.so > MPIAnalysis.cpp, > > > > when I use following command to run: > > opt -load ./MPIAnalysis.so -hello < main > > it shows the error: > > > > ----------------- > > 0 opt 0x085cddc8 > > Stack dump: > > 0. Program arguments: opt -load ./MPIAnalysis.so -hello > > 1. Running pass 'Hello World Pass' on module '<stdin>'. > > Segmentation Error > > > > I found similar Problem in > > http://lists.cs.uiuc.edu/pipermail/llvmdev/2010-July/033133.html > > But all function are defined in single binary IR file 'main', none of > > them are external. > > > > Why could not print the name of CallGraphNode's function name? > > _______________________________________________ > > LLVM Developers mailing list > > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-- Welson Phone: (408) 418-8385 Email: welson.sun at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120817/8b5ec4e2/attachment.html>
Well, I read http://lists.cs.uiuc.edu/pipermail/llvmdev/2010-July/033133.html again and consult the information about "external node" in CallGraph. http://llvm.org/docs/doxygen/html/CallGraph_8h_source.html CallGraph would build an external nodes, and it linked to all funtions in module. But the node itself does not stand for any function. i->second->getFunction() would return NULL. I should read previous message more carefully. Sorry for the my spam. :-( 2012/8/17 Hongbin Zheng <etherzhhb at gmail.com>:> On Fri, Aug 17, 2012 at 4:23 PM, Jianfei Hu <hujianfei258 at gmail.com> wrote: >> Hello, >> I want to traverse CallGraph >> >> code segment: >> >> >> virtual void getAnalysisUsage(AnalysisUsage &AU) const >> { >> AU.addRequired<CallGraph>(); >> } >> >> virtual bool runOnModule(Module &F) >> { >> CallGraph &g = getAnalysis<CallGraph>(); >> for ( CallGraph::iterator i = g.begin(); i != g.end(); i++) >> { >> errs()<<"-----------------\n"; > You may try something like this: > if (CallGraphNode *CGN = i->second) > ... CGN->getFunction()->getName() ... >> errs()<<i->second->getFunction()->getName()<<"\n"; >> } >> return false; >> } >> >> Compile: >> g++ -fPIC -shared `llvm-config --cxxflags` -o MPIAnalysis.so MPIAnalysis.cpp, >> >> when I use following command to run: >> opt -load ./MPIAnalysis.so -hello < main >> it shows the error: >> >> ----------------- >> 0 opt 0x085cddc8 >> Stack dump: >> 0. Program arguments: opt -load ./MPIAnalysis.so -hello >> 1. Running pass 'Hello World Pass' on module '<stdin>'. >> Segmentation Error >> >> I found similar Problem in >> http://lists.cs.uiuc.edu/pipermail/llvmdev/2010-July/033133.html >> But all function are defined in single binary IR file 'main', none of >> them are external. >> >> Why could not print the name of CallGraphNode's function name? >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev