[LLVMdev] Alloca instructions in NON-entry block?

Eric Christopher
Thu, 29 Mar 2012 17:10:12 -0000

On Mar 29, 2012, at 9:45 AM, John Criswell <criswell at illinois.edu>
wrote:

> 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).

Correct :)

-eric