Page MenuHomePhabricator

[ARM64EC 4/?] Add LLVM support for varargs calling convention.
AcceptedPublic

Authored by efriedma on May 11 2022, 1:43 PM.

Details

Reviewers
dpaoliello
Summary

Part of patchset to add initial support for ARM64EC.

The ARM64EC calling convention is the same as ARM64 for non-varargs functions, but for varargs, the convention is significantly different. Basically, only x0-x3 registers are used for passing arguments, and x4 and x5 describe the address/size of the arguments passed in memory. (See https://docs.microsoft.com/en-us/windows/uwp/porting/arm64ec-abi for more details; see https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention for the x64 calling convention rules, which this convention needs to match.)

Diff Detail

Event Timeline

efriedma created this revision.May 11 2022, 1:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 11 2022, 1:43 PM
efriedma requested review of this revision.May 11 2022, 1:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 11 2022, 1:43 PM
apazos added a subscriber: apazos.May 11 2022, 3:39 PM
apazos added inline comments.
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
5904

You might want to add a comment that only x0-x3 are used for passing args

efriedma updated this revision to Diff 429086.May 12 2022, 3:15 PM

Fix comments/formatting. Fix generated code for varargs functions with more than 4 fixed arguments.

efriedma marked an inline comment as done.May 12 2022, 3:16 PM

What about split args (i.e., i128)? It's my understanding that these need to be passed indirect, but LLVM automatically splits them into two i64 args.

dpaoliello added inline comments.Tue, May 31, 10:50 AM
llvm/test/CodeGen/AArch64/arm64ec-varargs.ll
54

Could you please add a test where args are being passed indirectly?

efriedma added inline comments.Tue, May 31, 11:00 AM
llvm/test/CodeGen/AArch64/arm64ec-varargs.ll
54

<2 x double> is getting passed indirectly; the address is passed as an argument. Computed in x8, then stored to the stack.

dpaoliello added inline comments.Tue, May 31, 11:06 AM
llvm/test/CodeGen/AArch64/arm64ec-varargs.ll
54

Ah, I missed that, thanks!

efriedma updated this revision to Diff 433226.Tue, May 31, 4:34 PM

Update to fix fixed arguments to varargs functions, and some more cases involving indirect arguments.

i128 specifically is tricky enough that I'm going to leave it for later. (See https://github.com/llvm/llvm-project/blob/36c1183c787f360e09e9c14128efdd8d12759a4d/llvm/lib/Target/SystemZ/SystemZCallingConv.h#L92 etc.) It's not really relevant for clang, anyway; we explicitly pass arguments indirectly if they're too big to be passed directly.

dpaoliello accepted this revision.Wed, Jun 1, 11:40 AM
This revision is now accepted and ready to land.Wed, Jun 1, 11:40 AM