This is an archive of the discontinued LLVM Phabricator instance.

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

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

Details

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
6208

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.May 31 2022, 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.May 31 2022, 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.May 31 2022, 11:06 AM
llvm/test/CodeGen/AArch64/arm64ec-varargs.ll
54

Ah, I missed that, thanks!

efriedma updated this revision to Diff 433226.May 31 2022, 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.Jun 1 2022, 11:40 AM
This revision is now accepted and ready to land.Jun 1 2022, 11:40 AM
efriedma updated this revision to Diff 457454.Sep 1 2022, 5:35 PM
efriedma added a reviewer: mstorsjo.

Rebased

I browsed this patch and didn't see anything I'd question or object to, but I can't say I've thoroughly studied it. But +1 from me, and I see that @dpaoliello approved it already earlier.

This revision was landed with ongoing or failed builds.Sep 5 2022, 1:10 PM
This revision was automatically updated to reflect the committed changes.