[LLVMdev] Kinda noob questions
John McCall
rjmccall at apple.com
Mon Mar 14 18:49:12 PDT 2011
On Mar 14, 2011, at 6:44 PM, Judison wrote:
> Thank you John and John :P
>
> these optimizations (mem2reg and the "few additional" ones) I have to enable then or something like this?? (I compile the .ll to .o with the sequence llvm-as, llc, as)
Look into 'opt'.
> Yet about dynamic stack allocation, what is (generally) better? to pre alloc everything at start, or let it be?
>
> Imagine this pseudo-code
>
> while (x) {
> int b = 0;
> ...
> }
>
> using alloca where b is declared, it will grow the stack dynamically, but it will shrink it at } or in llvm's words in the end of a block where b is not accessible anymore? Can I force its deallocation??
Unless you're actually reliant on dynamic allocation — e.g. you don't know the size statically, or you're intending to repeatedly allocate memory — you should always allocate in the entry block. LLVM is reasonably good at re-using stack slots when it can.
John.
More information about the llvm-dev
mailing list