[LLVMdev] Alloca instructions in NON-entry block?

John Criswell
Thu, 29 Mar 2012 16:45:53 -0000

On 3/29/12 11:32 AM, Paul J. Lucas wrote:
> The Kaleidoscope example here:
>
> 	http://llvm.org/docs/tutorial/LangImpl7.html#adjustments
>
> defines a CreateEntryBlockAlloca() helper function that "ensures that
the allocas are created in the entry block of the function."
>
> It's kid of implied, but I thought I'd ask explicitly: *must*
alloca instructions be created in the entry block of a function?

I believe that an alloca can occur in any basic block, but I think code
generation is more efficient if the allocas are in the entry block (the
code generator can insert a single instruction to adjust the stack
pointer, thus allocating all stack objects in the entry block with a
single machine instruction).

-- John T.

>
> - Paul
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev