[llvm-dev] DFS traversal on CallGraph

Ketan Patil via llvm-dev llvm-dev at lists.llvm.org
Wed Jul 5 00:19:34 PDT 2017

I want to do the DFS traversal on the call graph starting from the main
method or the root node present in the CallGraph.
I have written the following module pass.
I am constructing the call graph for the module. And then dumping it onto
the console, it shows the correct Call graph onto the console. It gives me
the root of the call graph. And all the called functions from the root are
the nodes in the next level. And so on.
But now I want to traverse it. There is no way to get the root of the
CallGraph because it is the private member.
In the following code, I am first obtaining the node corresponding to the
'main' method by 3rd and 4th line of code. But then I am unable to traverse
further. There is nothing to obtain the nodes which are the successor of
the node corresponding to main method.

bool runOnModule(Module &M) override

        CallGraph cg = CallGraph(M);  //generate the call graph of the
module M
        cg.dump(); //print the call graph on the console
        Function *f = M.getFunction("main");
        CallGraphNode &cgn = *cg.operator[](f);
         for(CallGraphNode::iterator itr =  cgn->begin(); itr!=

              //the following 2 statements always gives the segmentation
              const Value * V = itr->first;
              CallGraphNode* calleeNode =  itr->second;

              //how to traverse further????


Thanks and regards
-Ketan Patil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170705/68455b43/attachment.html>

More information about the llvm-dev mailing list