This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][GlobalISel] Support lowering variadic musttail calls
ClosedPublic

Authored by paquette on Sep 25 2019, 11:46 AM.

Details

Summary

This adds support for lowering variadic musttail calls. To do this, we have to...

  • Detect a musttail call in a variadic function before attempting to lower the call's formal arguments. This is done in the IRTranslator.
  • Compute forwarded registers in lowerFormalArguments, and add copies for those registers.
  • Restore the forwarded registers in lowerTailCall.

Because there doesn't seem to be any nice way to wrap these up into the outgoing argument handler, the restore code in lowerTailCall is done separately.

Also, irritatingly, you have to make sure that the registers don't overlap with any passed parameters. Otherwise, the scheduler doesn't know what to do with the extra copies and asserts.

Add call-translator-variadic-musttail.ll to test this. This is pretty much the same as the X86 musttail-varargs.ll test. We didn't have as nice of a test to base this off of, but the idea is the same.

Diff Detail

Repository
rL LLVM

Event Timeline

paquette created this revision.Sep 25 2019, 11:46 AM
aemerson added inline comments.Sep 26 2019, 2:42 PM
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
2266 ↗(On Diff #221814)

Can we extract this into a helper function?

llvm/lib/Target/AArch64/AArch64CallLowering.cpp
868 ↗(On Diff #221814)

Not sure what this means. The forwarded physregs could clobber the argument copies, or vice versa? How?

paquette marked 2 inline comments as done.Sep 26 2019, 2:54 PM
paquette added inline comments.
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
2266 ↗(On Diff #221814)

Sure

llvm/lib/Target/AArch64/AArch64CallLowering.cpp
868 ↗(On Diff #221814)

The forwarded physregs can clobber the argument copies because we restore argument registers.

But now that I look at this again, I think we can just create the copies in the second if block rather than creating them here.

paquette updated this revision to Diff 222216.Sep 27 2019, 11:24 AM

Refactor forwarding code, and factor out IRTranslator changes into a helper.

aemerson accepted this revision.Sep 30 2019, 12:51 AM

LGTM with nit.

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
2193 ↗(On Diff #222216)

Can't we just return this instead of using an output parameter?

This revision is now accepted and ready to land.Sep 30 2019, 12:51 AM
This revision was automatically updated to reflect the committed changes.