[llvm-dev] How to count instructions in a function?

Zubin Pahuja via llvm-dev llvm-dev at lists.llvm.org
Thu Nov 30 12:02:42 PST 2017


Thanks so much John! That works :)

Previously I wrote a pass that inherited from CallGraphWrapperPass and used
its getCallGraph() function within runOnModule() which resulted in
segmentation faults for me. Not sure why that happened, perhaps callgraph
wasn't setup by the time runOnModule() was called internally. If you know
why, kindly enlighten me and perhaps document the behavior for the benefit
of others.

Your email was the best thing to happen to me all day. I really appreciate
you taking out the time to help.

Sincerely,
Zubin

On Thu, Nov 30, 2017 at 11:33 AM, John Criswell <jtcriswel at gmail.com> wrote:

> Dear Zubin,
>
> If I were you, I would write a ModulePass that uses the CallGraph analysis
> to get a call graph.  I would then iterate over the nodes in the call graph
> and propagate information from callees to callers.
>
> Regards,
>
> John Criswell
>
>
> On 11/29/17 4:02 PM, Zubin Pahuja via llvm-dev wrote:
>
> Hello,
>
> I am trying to count IR instructions in a function for static analysis
> using llvm pass. In contrast with existing examples, I am trying to include
> instruction counts of all the callees of the function.
>
> Counting the instructions of a function is easy using passes, but
> iterating through the module's CallGraph is proving to be confusing. I
> believe I have to use CallGraphWrapperPass to get both module pass and its
> CallGraph. How do I iterate through the CallGraph in runOnModule()? A
> simple print callee names example would be highly appreciated.
>
> Thanks,
> Zubin
>
>
> _______________________________________________
> LLVM Developers mailing listllvm-dev at lists.llvm.orghttp://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
>
> --
> John Criswell
> Assistant Professor
> Department of Computer Science, University of Rochesterhttp://www.cs.rochester.edu/u/criswell
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171130/71c4ea7b/attachment.html>


More information about the llvm-dev mailing list