[LLVMdev] register scavenger
Reed Kotler
rkotler at mips.com
Sat Nov 10 16:01:07 PST 2012
I think I answered my own question.
When you use the scavenged register, you set it to kill and now it's
available as a free register for further needs , until it has to be
restored.
So that is the reason for chosing the register needed the furthest away
from the original place; because no further emergency slot
manimupatation will be needed as long as possible.
On 11/10/2012 02:17 PM, Reed Kotler wrote:
> I'm confused as to the logic used in the register scavenger when it
> cannot find a free register.
>
> I would think that it would want to free up the emergency spill slot
> immediately after it's use, because otherwise there is a chance of
> needing to use the emergency slot again and not be able to.
>
> Instead it tries to restore it only right before register it is freeing up.
>
> Maybe I'm misunderstanding this code.
>
> // If the target knows how to save/restore the register, let it do so;
> // otherwise, use the emergency stack spill slot.
> if (!TRI->saveScavengerRegister(*MBB, I, UseMI, RC, SReg)) {
> // Spill the scavenged register before I.
> assert(ScavengingFrameIndex >= 0 &&
> "Cannot scavenge register without an emergency spill slot!");
> TII->storeRegToStackSlot(*MBB, I, SReg, true, ScavengingFrameIndex,
> RC,TRI);
> MachineBasicBlock::iterator II = prior(I);
> TRI->eliminateFrameIndex(II, SPAdj, this);
>
> // Restore the scavenged register before its use (or first
> terminator).
> TII->loadRegFromStackSlot(*MBB, UseMI, SReg, ScavengingFrameIndex,
> RC, TRI);
> II = prior(UseMI);
> TRI->eliminateFrameIndex(II, SPAdj, this);
> }
More information about the llvm-dev
mailing list