Get root node of CallGraph

Hi,

There is a “Root” private member in CallGraph class. But there is no way to get access to that member. How can I do that? I can get CallGraphNode of “main” method. But I am curious is there more cleaner way.

Thanks,
Riyad

Howdy Riyad,

The Root pointer in CallGraph represents either the “main” function CallGraph node, or the ExternalCallingNode, when the main function doesn’t exist in the module.

I don’t see a public API to this pointer in the header, but the Callgraph::print function could print out info for the node, including if the Root has a function related to it or it’s null.

If you want to obtain the Root pointer, you can consult the CallGraph::addToCallGraph method.

http://llvm.org/docs/doxygen/html/CallGraph_8cpp_source.html

In short, while it adds the new node it determine if the new node is main function. The Root is pointed to main node if and only if there’s only one main node added to CallGraph. It points to ExternalCallingNode when there are multiple main functions or no main at all.

You can iterate through the CallGraph to get all functions to decide what Root really is. In this way you should get the same results as what LLVM is doing right now.

Hope this helps and point out if I miss something.

Kind regards,
Kevin

Hi,

Hi,

Hi,

There is a "Root" private member in CallGraph
<http://llvm.org/docs/doxygen/html/CallGraph_8h_source.html#l00192&gt; class.
But there is no way to get access to that member. How can I do that? I can
get CallGraphNode of "main" method. But I am curious is there more cleaner
way.

What is your use case? It may be possible to add an accessor.

I want to topologically sort the call graph, just to have a sense of
dependency between functions.