[LLVMdev] Questions !!

Misha Brukman brukman at uiuc.edu
Fri Apr 8 10:14:23 PDT 2005


On Fri, Apr 08, 2005 at 08:37:03AM -0700, Tanu Sharma wrote:
> Regarding basic block size I wish to calculate both:
>  
> - The number of bytecode bytes

Use the llvm-bcanalyzer tool, it will tell you number of bytes per
function and number of basic blocks.  If you want number of bytes per
basic block, check out what it does, and calculate basic blocks
separately.

> -  The number of machine code bytes for some target?

You have two options

1. Create a native executable, find and extract the code section using
objdump or whatever is applicable to your platform, and analyze the
basic blocks there by finding all branches.

2. Alternatively, the LLVM way:

On a RISC-like machine, instructions are usually 4 bytes, so numInstrs *
4 = numBytes.  On an architecture like X86 with variable-sized
instructions, you will have to calculate the size on a
per-emitted-instruction basis.  We currently do this for the nightly
tests, but it's outputted on a per-program basis, such as:

$ lli -stats eks.bc | grep jit
  4182 jit                   - Number of bytes of machine code compiled

Note that this is only for the _executed_ part of the program, not the
entire program.

Your best bet would be to write a pass that runs after instruction
selection, that loops over all the basic blocks of each function and
calculates how many bytes each instruction would take up.  For a
RISC-like target, again, that's pretty trivial, but harder for a CISC.

-- 
Misha Brukman :: http://misha.brukman.net :: http://llvm.cs.uiuc.edu




More information about the llvm-dev mailing list