[LLVMdev] register scavenger

Akira Hatanaka ahatanak at gmail.com
Mon Oct 22 11:52:25 PDT 2012


I have a question about register scavenger.

I am considering using register scavenger for MIPS to free up register AT
which is currently reserved to load large immediates.

All targets which currently use register scavenger to search for a scratch
register (ARM, CellSPU, PowerPC and XCore)
override function processFunctionBeforeCalleeSavedScan and call
RegisterScavenger::setScavengingFrameIndex
if they decide an emergency spill slot is needed. Since
processFunctionBeforeCalleeSavedScan is called before it is known
which callee-saved registers need to be spilled, the targets decide whether
the spill slot is needed without knowing the exact
stack frame size.

It seems to me that it would be better to wait until
calculateFrameObjectOffsets computes the exact stack size
to make the decision and redo the stack size calculation only if the spill
slot is needed.

bool PEI::runOnMachineFunction(MachineFunction &Fn) {
  ...
  TFI->processFunctionBeforeCalleeSavedScan(Fn, RS);
  ...
  calculateCalleeSavedRegisters(Fn);
  ...
  calculateFrameObjectOffsets(Fn);
  ...
  if (target needs spill slot) {
    call setScavengingFrameIndex and reserve spill slot
    calculateFrameObjectOffsets(Fn); // redo calculation.
  }


This seems to be simpler and more efficient since you don't need to write
or run a function like ARM's estimateStackSize to estimate the stack size.

Does this sound reasonable or is there something I am missing?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121022/a9853815/attachment.html>


More information about the llvm-dev mailing list