[LLVMdev] register scavenger

Reed Kotler rkotler at mips.com
Sat Nov 10 14:17:27 PST 2012


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