<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div class="">I think that the “one spill” case might be a little less restrictive than that. If you have N spills, but the live ranges for the spills do not overlap then you could just spill to Y instead of the stack.</div>
<div class=""><br class="">
</div>
<div class="">-Daniel</div>
<div class=""><br class="">
</div>
<br class="">
<div>
<blockquote type="cite" class="">
<div class="">On May 1, 2017, at 2:19 AM, Bruce Hoult via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">Why not do it the other way around?
<div class=""><br class="">
</div>
<div class="">Mark Y as reserved, and then at the end of the function if there was exactly one spill then put that variable in Y instead.</div>
<div class=""><br class="">
</div>
<div class="">If there were no spills then you lost nothing by reserving Y. If there were more than one then you need Y for this stack adjustment. So exactly one spill is the only case where you lost anything by reserving Y.</div>
<div class=""><br class="">
</div>
<div class="">Which is probably pretty rare, to be honest.</div>
</div>
<div class="gmail_extra"><br class="">
<div class="gmail_quote">On Mon, May 1, 2017 at 6:27 AM, Dylan McKay via llvm-dev
<span dir="ltr" class=""><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>></span> wrote:<br class="">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr" class="">Hey all,
<div class=""><br class="">
</div>
<div class="">I'm attempting to rewrite something that the AVR backend used to support (through an extremely dirty hack that was reverted before the upstreaming of the target).</div>
<div class=""><br class="">
</div>
<div class="">The removal of the hack can be seen on GitHub</div>
<div class=""><br class="">
</div>
<div class=""><a href="https://github.com/avr-llvm/llvm/pull/226/files" target="_blank" class="">https://github.com/avr-llvm/<wbr class="">llvm/pull/226/files</a><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">On the AVR architecture, the stack pointer is not in a standard register, but rather it is a special register which can only be accessed via I/O instructions. In order to implement stack spilling/restoring we need to adjust the stack pointer,
 which is a problem because we need the value of SP to be in a general purpose register for us to perform arithmetic on it.</div>
<div class=""><br class="">
</div>
<div class="">In AVR-GCC, a frame pointer (the 'Y' register) is reserved if there are any spills in a method. This works fine because we can easily perform arithmetic on it and then save it into the real stack pointer via IO instructions.</div>
<div class=""><br class="">
</div>
<div class="">I would like to do the same for LLVM. This is tricky however, because we don't know if we need a frame pointer until we've finished register allocation and we've seen a spill.</div>
<div class=""><br class="">
</div>
<div class="">In the event that we do see a spill, it is likely that the 'Y' register has already been allocated to some other variable, and so we somehow need to deallocate it and then rewind the regalloc. That is what the old hack above does.</div>
<div class=""><br class="">
</div>
<div class="">Is there any way today I can deallocate a register and rewind allocation upon spilling?</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
</div>
<br class="">
______________________________<wbr class="">_________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/<wbr class="">mailman/listinfo/llvm-dev</a><br class="">
<br class="">
</blockquote>
</div>
<br class="">
</div>
_______________________________________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class="">
</div>
</blockquote>
</div>
<br class="">
</body>
</html>