Hi all,<br><br>I have 2 simple questions... <br><br>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... <br>
<br>and sorry bad english<br><br>1) I want to know if when I do this kind of thing:<br><br>entry:<br>%x = alloca i32<br>%y = alloca i32<br clear="all">... normal instructions...<br>other_block:<br>%z = alloca i32<br>....<br>
br .... label %other_block<br><br>the stack "grows" when alloca is "called", or its the same as putting "%z = alloca" in the beggining?<br>or... if alloca is in a loop, the stack grows every time it iterates??<br>
<br><br><br>2) does the LLVM optimizes this:<br><br>; this code (arg -> var) is very similar to what gcc generates<br>define void @foo(i32 %arg0) {<br>entry:<br>    %var0 = alloca i32<br>    store i32 %arg0, i32* var0<br>
    ...<br>    %x = load i32* %var0<br>    ....<br>    ; never more stores to %var0 or pass it to any function<br>}<br><br>to something like:<br><br>define void @foo(i32 arg0) {<br>entry:<br>    ; no alloca<br>    ....<br>
    %x = %arg0<br>   ....<br>}<br><br>does it???<br><br>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))<br>
If LLVM optimizes it, I'll let it... if not, I'll do this optimization<br><br>Thanks in advance :P<br><br>-- <br>Judison<br><a href="mailto:judison@gmail.com" target="_blank">judison@gmail.com</a><br><br>"A wise man first thinks and then speaks and a fool
         speaks first and then thinks." Imam Ali (as)<br>