[LLVMdev] Is alloca instruction allowed within the cycle?
Reid Kleckner
reid.kleckner at gmail.com
Fri Jun 18 18:28:21 PDT 2010
Because that is the meaning of the alloca instruction, allocate more
stack space. It would do the same if you called alloca() in C in a
loop.
The expected way for frontends to implement local variables is to keep
inserting alloca instructions into the entry block as you encounter
new variables. I don't think mem2reg will even work on allocas not in
the entry block.
Reid
On Fri, Jun 18, 2010 at 6:20 PM, Yuri <yuri at rawbw.com> wrote:
> I am running this code in JIT on x86 (32 bit).
> It crashes when 'alloca %object' instruction is within the body of the
> cycle, and it finishes successfully when this instruction is in the
> beginning of main (outside the cycle). Crash occurs in the middle of the
> cycle after few hundreds of thousands iterations.
>
> What is wrong? Does alloca inside the cycle forces it to allocate it on
> stack for every iteration instead of only once?
> If this is the case why verify doesn't complain?
>
> Yuri
>
>
> --- code ---
>
> %object = type { i8, i8, i8}
> @str2 = private constant [1 x i8] zeroinitializer
>
> define void @main() {
> for.init:
> %i = alloca i32
> store i32 0, i32* %i
> br label %for.end
>
> for.body:
> %obj = alloca %object
> %str = getelementptr inbounds [1 x i8]* @str2, i32 0, i32 0
> call void @obj_constr(%object* noalias sret %obj, i8* %str)
> call void @obj_destr(%object* %obj)
> br label %for.incr
>
> for.incr:
> %incr = load i32* %i
> %incr3 = add i32 %incr,
> store i32 %incr3, i32* %i
> br label %for.end
>
> for.end:
> %iload = load i32* %i
> %xcmp = icmp sge i32 %iload, 100000000
> br i1 %xcmp, label %xend, label %for.body
>
> xend:
> ret void
> }
>
> _______________________________________________
> 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