Alloca instructions in NON-entry block?

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?

- Paul

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.

Correct :slight_smile:

-eric