On Sat, Oct 2, 2010 at 12:59 PM, nicolas geoffray <span dir="ltr"><<a href="mailto:nicolas.geoffray@gmail.com">nicolas.geoffray@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Hi Talin,<div><br></div><div>You are not doing something wrong, it is just that the LLVM optimizers consider llvm.gcroot like a regular function call. The alloca is moved in the first block most probably because the inliner anticipates another optimization pass (the mem2reg).</div>

</blockquote><div><br></div><div>OK, well, is there anything that can be done? </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><br></div><div>Cheers,</div><div>Nicolas</div><div><br><div class="gmail_quote"><div><div></div><div class="h5">On Sat, Oct 2, 2010 at 8:28 PM, Talin <span dir="ltr"><<a href="mailto:viridia@gmail.com" target="_blank">viridia@gmail.com</a>></span> wrote:<br>


</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div class="h5">I'm still putting the final touches on my stack crawler, and I've run into a problem having to do with function inlining and local stack roots.<div>


<br></div><div>As you know, all local roots must be initialized before you can make any call to a function which might crawl the stack. My compiler ensures that all local variables of a function are allocated, declared as root, and initialized in the first block.</div>




<div><br></div><div>However, the function inlining pass does not seem to preserve these constraints. For example, say I have a function F:</div><div><br></div><div>   void F() {</div><div>     f1();</div><div>     f2();</div>




<div>   }</div><div><br></div><div>Let's say that f1() causes a stack crawl (perhaps by triggering a collection cycle), and that f2() declares a stack root 'a'. If the optimizer decides to inline f2, then by the time the GCPrinter is called the resulting code looks like this:</div>




<div><ul><li>a = alloca</li><li>call f1</li><li>call llvm.gcroot(a)</li><li>store null, a</li></ul><div><div><div><div>The inliner moved the alloca instruction to the top of the function, but not the call to llvm.gcroot or the initialization of the variable. In other words, the initialization of the root occurs *after* the call to f1. This means that the stack crawler is seeing garbage and therefore crashes hard. (Also, I've observed that the call to llvm.gcroot and the initialization might not even be in the first block anymore.)</div>




<div><br></div><div>As per usual, I'm not sure if this is a bug in LLVM or my doing something wrong...</div><div><br>-- <br>-- Talin<br>
</div></div></div></div></div>
<br></div></div>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br><br clear="all"><br>-- <br>-- Talin<br>