Questions !!

Thanks a lot Chris.

Regarding basic block size I wish to calculate both:

  • The number of bytecode bytes
  • The number of machine code bytes for some target?

TS

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.

<shameless alpha plug>
If you were compiling on alpha:
objdump -t file |sort |grep -A 1 LBB
then the size of each basic block would be the address of the symbol -
the address of the next symbol (all basic blocks symbols are currently
exported in alpha and start with LBB)
</shameless alpha plug>

Andrew