[LLVMdev] Overriding TargetRegisterInfo::hasReservedSpillSlot

William J. Schmidt wschmidt at linux.vnet.ibm.com
Fri Aug 31 09:41:44 PDT 2012


To fix some problems with how condition registers are saved/restored for
PowerPC, I need to override TargetRegisterInfo::hasReservedSpillSlot()
in PPCRegisterInfo.  I've had some difficulties because of the constness
of the function, and I'm wondering what the best way to handle this
would be.

Essentially I need to add a field to PPCRegisterInfo, and modify that
field in hasReservedSpillSlot.  (I need to reserve the spill slot only
if condition registers are to be spilled, and reserve it only once even
if more than one is to be spilled; so I need state that persists across
multiple calls to this function.)  Because hasReservedSpillSlot is
annotated as const, I can't do this directly.

There appear to be several options:
 * Add the field as an int& instead of an int.  This requires it to be
allocated in the constructor's initializer, which is rather ugly:
NewField(*(new int)).
 * Remove the constness from the virtual function in the superclass and
other subclasses (currently only X86).  This is bad if it's const by
design, but OK if it was just const by habit.  It would probably be good
to change the name of the function to indicate potential modification in
that case.
 * Add another target hook that only PowerPC will use initially in order
to set up the reserved spill slot.  This basically would move almost all
the PowerPC logic out of hasReservedSpillSlot() into the new hook in
order to circumvent the const issue.  This works but bothers me a little
since it's a lot of hoop-jumping just to bypass const.

Which of the above, or any other possibilities, would you consider to be
the best approach?

(While I'm on the topic of this function, it's a little bothersome that
the MachineFunction &MF parameter is marked const also.  It makes it
impossible to call MF.getFrameInfo() without casting the constness away.
In such cases, is it best to cast away const, or remove the qualifier
from the parameter?)

Thanks for any help!
Bill
-- 
Bill Schmidt, Ph.D.
IBM Advance Toolchain for PowerLinux
IBM Linux Technology Center
wschmidt at us.ibm.com
wschmidt at linux.vnet.ibm.com









More information about the llvm-dev mailing list