[LLVMdev] Alloca Instruction

Nick Lewycky nicholas at mxc.ca
Sat Jul 4 12:19:13 PDT 2009

kapil anand wrote:
> Hi all,
> I was reading the description of run-time stack and alloca instructions 
> in LLVM IR and have a question about the same. Do LLVM alloca 
> instructions allow the processing on stack across some alloca blocks?
> For example, is following code valid?

Yes, it's valid. Alloca, like the other non-PHI instructions, only 
requires that all uses be dominated by the definition.

There's a couple things to know about alloca. One is that you can't free 
an alloca, so you may want to avoid using them in loops. The other is 
that the -mem2reg pass will only look for a contiguous list of alloca's 
at the beginning of the first block which is why nearly all the LLVM IR 
you'll see puts them together at the top.


More information about the llvm-dev mailing list