<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
On 3/14/11 7:52 PM, Judison wrote:
<blockquote
cite="mid:AANLkTik_oKkAUH2bKqeBiT54cQVkZfoKzP+EJomDwGuR@mail.gmail.com"
type="cite">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>
</blockquote>
<br>
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.<br>
<br>
<blockquote
cite="mid:AANLkTik_oKkAUH2bKqeBiT54cQVkZfoKzP+EJomDwGuR@mail.gmail.com"
type="cite">
<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>
</blockquote>
<br>
I suspect that mem2reg plus a few additional optimizations will do
this for you.<br>
<br>
-- John T.<br>
<br>
<blockquote
cite="mid:AANLkTik_oKkAUH2bKqeBiT54cQVkZfoKzP+EJomDwGuR@mail.gmail.com"
type="cite"><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 moz-do-not-send="true" 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>
</blockquote>
<br>
</body>
</html>