[llvm-dev] Get root node of CallGraph

Kevin Hu via llvm-dev llvm-dev at lists.llvm.org
Tue Dec 8 12:03:22 PST 2015


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

On Tue, Dec 8, 2015, 10:39 Riyad Parvez via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hi,
>
> There is a "Root" private member in CallGraph
> <http://llvm.org/docs/doxygen/html/CallGraph_8h_source.html#l00192> 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
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151208/4c073efd/attachment.html>


More information about the llvm-dev mailing list