[llvm-dev] How to get the instruction counts of each function of llvm IR?

Shane Lin via llvm-dev llvm-dev at lists.llvm.org
Thu Dec 23 00:23:40 PST 2021


I’m trying to get the instruction counts of each function in a single llvm IR.

I try the command below:

opt -enable-new-pm=0 -instcount -stats source_IR.ll

and I get the result like:

----------------------------------------------------------------------------------------------------------------

===-------------------------------------------------------------------------===
                          ... Statistics Collected ...
===-------------------------------------------------------------------------===

 3 instcount - Number of Add insts
 2 instcount - Number of And insts
10 instcount - Number of Br insts
 1 instcount - Number of Call insts
10 instcount - Number of FAdd insts
11 instcount - Number of FDiv insts
 7 instcount - Number of FMul insts
 5 instcount - Number of ICmp insts
 2 instcount - Number of Or insts
10 instcount - Number of PHI insts
 2 instcount - Number of Ret insts
 6 instcount - Number of UIToFP insts
12 instcount - Number of basic blocks
 2 instcount - Number of non-external functions
69 instcount - Number of instructions (of all types)
 ———————————————————————————————————————————————————————————————


But this is the instruction count of whole program. I want to get the instruction counts of each function in this IR.

I try the command below:

opt -enable-new-pm=0 -instcount -stats source_IR.ll -analyze


and I get the result:

Printing analysis 'Counts the various types of Instructions' for function 'main':
Printing analysis 'Counts the various types of Instructions' for function 'compute_pi_baseline':
===-------------------------------------------------------------------------===
                          ... Statistics Collected ...
===-------------------------------------------------------------------------===

 3 instcount - Number of Add insts
 2 instcount - Number of And insts
10 instcount - Number of Br insts
 1 instcount - Number of Call insts
10 instcount - Number of FAdd insts
11 instcount - Number of FDiv insts
 7 instcount - Number of FMul insts
 5 instcount - Number of ICmp insts
 2 instcount - Number of Or insts
10 instcount - Number of PHI insts
 2 instcount - Number of Ret insts
 6 instcount - Number of UIToFP insts
12 instcount - Number of basic blocks
 2 instcount - Number of non-external functions
69 instcount - Number of instructions (of all types)


there is nothing after the Printing line.

How could I get the instruction counts of each function by using llvm command?

I prefer not to write the pass by myself first
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20211223/b61aea2c/attachment-0001.html>


More information about the llvm-dev mailing list