<div dir="ltr">Hi Tim,<div>Thanks for your reply. My goal is to do some optimizations on the final assembly code. I want to do register renaming in the code hotspot and I need to spill some registers before entering some loops. And later, reload them after exiting the loop. </div><div>So I guess I don't want it to be in the SelectionDAG, it's after register allocation and everything and before emitting the instructions. </div><div>My target architecture is ARM. I have a sample code like this:</div><div><br></div><div>str<span class="" style="white-space:pre">   </span>r2, [sp, #8]            @ 4-byte Spill</div><div>ldrb<span class="" style="white-space:pre">   </span>r2, [r4, r12]!</div><div><br></div><div>and in another code</div><div>str<span class="" style="white-space:pre">       </span>r1, [sp, #52]           @ 4-byte Spill<br></div><div><br></div><div>and both of them are the first spills in the code. so why #8 in one and #52 in the other?</div><div><br></div><div>Now assume I want to spill some variable at the end of some basic blocks in a program, I should create a store and give it an offset, but how to decide what it should be. </div><div>Thanks again,</div><div>Fateme</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 5, 2016 at 10:21 PM, Tim Northover <span dir="ltr"><<a href="mailto:t.p.northover@gmail.com" target="_blank">t.p.northover@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Fateme,<br>
<br>
On 5 May 2016 at 19:10, fateme Hoseini via llvm-dev<br>
<span class=""><<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
> Is it possible to add a spill code (a pair of store /load ) to the<br>
> machinecode in a pass before the instruction emitter?<br>
<br>
</span>Do you mean during the SelectionDAG phase? If so, the very rough<br>
outline would be something like:<br>
<br>
  MachineFrameInfo *MFI = MF.getFrameInfo();<br>
  int Idx = MFI->CreateStackObject(Size, Align);<br>
  SDValue FI = DAG.getFrameIndex(Idx, PtrVT);<br>
  DAG.getStore(Chain, DL, WhateverVal, FI);<br>
<br>
The keyword to grep for in the existing code is probably<br>
"CreateStackObject", possibly also "CreateFixedObject" (see later).<br>
Various backends to something along those lines for arguments that get<br>
passed in on the stack and so on.<br>
<span class=""><br>
> If so, how can I calculate the address (offset to the sp) for the spill store/load<br>
> instructions?<br>
<br>
</span>The offset to SP during the function's execution isn't decided until<br>
much later (LLVM may need more or less stack space depending on how<br>
many spills *it* decides is necessary). For things that don't need to<br>
have a fixed location, you usually don't need to know it early either<br>
so you'd just use instructions referencing the FrameIndex. Later<br>
passes will then fill in the offsets properly.<br>
<br>
If you really, really want to you can use CreateFixedObject, which<br>
will have a set position relative to SP immediately on function entry,<br>
but you'd have to be aware of and handle that in XYZFrameLowering too,<br>
I expect.<br>
<br>
Cheers.<br>
<span class="HOEnZb"><font color="#888888"><br>
Tim.<br>
</font></span></blockquote></div><br></div>