[LLVMdev] Accounting for code size

Chris Lattner sabre at nondot.org
Fri Sep 28 10:41:52 PDT 2007


On Sep 28, 2007, at 10:27 AM, Sandro Magi wrote:

> In my quest to account for memory, I've now come to the in-memory IR,
> and the generated code. I want to book the generated code memory
> against the agent that is generating the code.
>
> I see that LLVM's Function class [1] has a size function; what does
> this represent and can I use it to account for the space used by the
> in-memory IR?

It returns the number of basic blocks in the function.  Size on a  
basic block returns the number of instructions in it.

> As for generated code, the JIT [2] class simply returns a "void *"
> when generating code for that function, with no size information that
> I can see.

Right.  If you pass -debug-only=jit to lli (before the bc file) it  
will print out the size of each function as it is compiled.

> MachineCodeEmitter [3] is obtainable from the JIT class, and it
> contains "BufferBegin", "BufferEnd", and "CurBufferPtr" as protected
> members; if they were available, determining the generated code size
> might be possible via some pointer arithmetic. Is there another way I
> might be missing? Or would I have to subclass JITEmitter and add a
> method to perform this calculation?

You could do that, it will tell you the size of all of the machine  
code jit'd.

> Finally, can I free the memory used by the in-memory IR after the code
> is generated?

Yes, you can call F->deleteBody() after JIT'ing F.

-Chris

> Sandro
>
> [1] http://llvm.org/doxygen/classllvm_1_1Function.html#a27
> [2] http://llvm.org/doxygen/classllvm_1_1JIT.html
> [3] http://llvm.org/doxygen/classllvm_1_1MachineCodeEmitter.html
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list