<div dir="ltr">Why not do it the other way around?<div><br></div><div>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><br></div><div>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><br></div><div>Which is probably pretty rare, to be honest.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 1, 2017 at 6:27 AM, Dylan McKay via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hey all,<div><br></div><div>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><br></div><div>The removal of the hack can be seen on GitHub</div><div><br></div><div><a href="https://github.com/avr-llvm/llvm/pull/226/files" target="_blank">https://github.com/avr-llvm/<wbr>llvm/pull/226/files</a><br></div><div><br></div><div>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><br></div><div>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><br></div><div>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><br></div><div>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><br></div><div>Is there any way today I can deallocate a register and rewind allocation upon spilling?</div><div><br></div><div><br></div></div>
<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>