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

Wang, Phoebe via llvm-dev llvm-dev at lists.llvm.org
Thu Dec 23 06:02:10 PST 2021


Not sure if there’s a better solution, anyway we can achieve it by script like:

$ cat t.sh
#!/bin/bash

for f in $(grep -r define $1 | cut -d @ -f 2 | cut -d '(' -f 1)
do
  echo "Function: $f"
  llvm-extract -S $1 --func=$f | opt -S -enable-new-pm=0 -instcount -stats > /dev/null
done

$ source t.sh llvm/test/CodeGen/X86/add.ll

Thanks
Phoebe

From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Shane Lin via llvm-dev
Sent: Thursday, December 23, 2021 4:24 PM
To: llvm-dev at lists.llvm.org
Subject: [llvm-dev] How to get the instruction counts of each function of llvm IR?

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/2a1af9d2/attachment-0001.html>


More information about the llvm-dev mailing list