This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel][CallLowering] Delay outgoing register assignments to last.
ClosedPublic

Authored by aemerson on Sep 27 2021, 10:04 PM.

Details

Summary

The delayed stack protector feature which is currently used for SDAG (and thus
allows for more commonly generating tail calls) depends on being able to extract
the tail call into a separate return block. To do this it also has to extract
the vreg->physreg copies that set up the call's arguments, since if it doesn't
then the call inst ends up using undefined physregs in it's new spliced block.

SelectionDAG implementations can do this because they delay emitting register moves
for until *after* the stores for stack arguments are set up. GISel however
just processes and emits the arguments in IR order, so stack arguments always
end up last, and thus this breaks the code that looks for any register arg
copies that precede the call instruction.

This patch adds a thunk argument to the assignValueToReg() and custom assignment
hooks. For outgoing arguments, register assignments use this return param to
return a thunk that does the actual generating of the copies. We collect these
until all the outgoing stack assignments have been done and then execute them,
so that the copies (and perhaps some artifacts like G_SEXTs) are placed after
any stores.

Diff Detail

Event Timeline

aemerson created this revision.Sep 27 2021, 10:04 PM
aemerson requested review of this revision.Sep 27 2021, 10:04 PM

SelectionDAG implementations can do this because they delay emitting stores for stack arguments until *after* the register arguments are set up.

This should say the inverse. The stores are emitted first, and all the other arguments are emitted after.

aemerson edited the summary of this revision. (Show Details)Sep 28 2021, 3:13 PM
paquette accepted this revision.Oct 4 2021, 9:59 AM

I think this makes sense.

This revision is now accepted and ready to land.Oct 4 2021, 9:59 AM
This revision was landed with ongoing or failed builds.Oct 4 2021, 12:33 PM
This revision was automatically updated to reflect the committed changes.