[LLVMdev] Kinda noob questions

John Criswell criswell at illinois.edu
Mon Mar 14 17:56:58 PDT 2011


On 3/14/11 7:52 PM, Judison wrote:
> Hi all,
>
> I have 2 simple questions...
>
> First, just for you to know, I'm making a compiler (kinda obvious) and 
> the language definition is mine, so there is no much constraint for 
> me, it's written in Java (it generates a .ll file as output) and it's 
> just for fun by now, maybe a serious project after I learn all the 
> stuff needed...
>
> and sorry bad english
>
> 1) I want to know if when I do this kind of thing:
>
> entry:
> %x = alloca i32
> %y = alloca i32
> ... normal instructions...
> other_block:
> %z = alloca i32
> ....
> br .... label %other_block
>
> the stack "grows" when alloca is "called", or its the same as putting 
> "%z = alloca" in the beggining?
> or... if alloca is in a loop, the stack grows every time it iterates??

Yes, you can have alloca's instead of loops, and they will grow the size 
of the stack frame each time they are executed dynamically.

>
>
>
> 2) does the LLVM optimizes this:
>
> ; this code (arg -> var) is very similar to what gcc generates
> define void @foo(i32 %arg0) {
> entry:
>     %var0 = alloca i32
>     store i32 %arg0, i32* var0
>     ...
>     %x = load i32* %var0
>     ....
>     ; never more stores to %var0 or pass it to any function
> }
>
> to something like:
>
> define void @foo(i32 arg0) {
> entry:
>     ; no alloca
>     ....
>     %x = %arg0
>    ....
> }
>
> does it???

I suspect that mem2reg plus a few additional optimizations will do this 
for you.

-- John T.

>
> I'm asking because I can check in my compiler if some arg is only 
> readed or if its used as a var before generate the IR, an then only 
> create (alloca) a %var if the arg is used for read-write :P (my 
> language is "safe" (no pointers))
> If LLVM optimizes it, I'll let it... if not, I'll do this optimization
>
> Thanks in advance :P
>
> -- 
> Judison
> judison at gmail.com <mailto:judison at gmail.com>
>
> "A wise man first thinks and then speaks and a fool speaks first and 
> then thinks." Imam Ali (as)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110314/9f8aabda/attachment.html>


More information about the llvm-dev mailing list