Page MenuHomePhabricator

ARM: support mandatory tail calls
ClosedPublic

Authored by t.p.northover on May 17 2021, 4:40 AM.

Details

Reviewers
jroelofs
paquette
Summary

This is obviously mostly for swifttailcc, but it's trivial to being tailcc and fastcc along for the ride so I did those too.

The code is pretty closely modelled on how AArch64 handles this because most RISC backends will need approximately the same behaviour, so there are a few main components:

  • Track how much stack space the callee is expected to restore on return (and do it).
  • In the tail call case arguments might not simply be stored to sp + N, but to an object at a fixed offset from the stack on function entry. We use a fixed frame-index for this, which naturally reserves the space so callee-saved registers won't be placed there.
  • The tail call itself needs to track how much stack space it actually needs (because different tail calls vary this).

Diff Detail

Event Timeline

t.p.northover created this revision.May 17 2021, 4:40 AM
t.p.northover requested review of this revision.May 17 2021, 4:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2021, 4:40 AM
paquette accepted this revision.May 17 2021, 11:35 AM

This looks really similar to the AArch64 code, so I think it's probably good to go.

llvm/lib/Target/ARM/ARMFrameLowering.cpp
2354

Maybe there should be an assert checking that if CalleePopAmount == 0, then Amount == 0?

This revision is now accepted and ready to land.May 17 2021, 11:35 AM
t.p.northover added inline comments.May 19 2021, 2:56 AM
llvm/lib/Target/ARM/ARMFrameLowering.cpp
2354

"Valid" is a difficult predicate to check here (it's essentially canGuaranteeTCO from ISelLowering so depends on CC and TargetMachine::Options).

The point of the comment is that CalleePopAmount != 0 is adequate as a proxy for that check, which is what we really want to have here. So adding an assert later is probably the wrong way to go about improving it.

On reflection the best fix is probably to change the "no interesting callee pop" sentinel from 0 which is also a valid amount to -1. That defines the subtlety away.

Switched to -1 as the sentinel for when the caller manages all argument stack (i.e. normal C calling conv).

t.p.northover closed this revision.Fri, May 28, 3:13 AM

Thanks Jessica, committed as d88f96df (with the -1 sentinel).