[LLVMdev] Stack-based vs. register-based variables and other optimizations

David Blaikie dblaikie at gmail.com
Sat Jan 19 23:42:07 PST 2013


On Sat, Jan 19, 2013 at 9:03 PM, Rick Mann <rmann at latencyzero.com> wrote:
> Implementing my little language I'm using clang and the CPP back-end as a guide for a lot of things. One thing I see is that clang always uses Alloca and stores parameters on the stack.
>
> Are there LLVM passes that figure this out and put things in registers, skipping the stack allocations and loads/stores?
>
> Similarly, if I use Alloca to make room for a pointer on the stack, store a value in it, later load that value and pass it as an argument in a call, can LLVM choose to optimize that stack allocation away and use a register?

Yep, you might want to look at the bitcode before & after running the
optimizers - it should be easy to observe LLVM doing this. (if you're
curious about where/how it happens, see the mem2reg pass)

>
> I'm mostly talking about x86 here.
>
> On the other hand, if I just stuck the result of one function call in as an argument to another function call, or tried to use a parameter value directly (assuming appropriate casts), will LLVM create intermediate stack-based space if required?
>
> I'm very unfamiliar with calling conventions on x86 (as compared to PowerPC or ARM), so I'm hoping I don't have to worry about that stuff much.
>
>
>
> --
> Rick
>
>
>
>
> _______________________________________________
> 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