[llvm] [AArch64][SME2] Preserve ZT0 state around function calls (PR #76968)

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 8 06:21:12 PST 2024


https://github.com/sdesmalen-arm requested changes to this pull request.

Hi @kmclaughlin-arm, your patch is mimicking the existing implementation for ZA which itself was based on the previous ACLE attribute keywords. Since these are being changed in https://github.com/ARM-software/acle/pull/276 (with an implementation in #76971), I think it makes sense to create LLVM IR attributes that more closely match the new Clang attributes, even if we don't treat them differently than we do for ZA (for example, we could treat `__arm_in/out/inout/preserves("zt0")` all as "sharing zt0" from an ABI perspective).

The new attributes also make it possible to consider ZA separately from ZT0, so I think we should implement it as such in this pull request as well. Perhaps it helps if I share my understanding of the ACLE/ABI with these new attributes:

If a function has `__arm_in/out/inout/preserved(S)` for S = `"za"` or `"zt0"`, then the function has a Shared-ZA interface. Otherwise it has a Private-ZA interface.

For calls to a "Private ZA" interface:
* If the caller has live ZA state and the callee is a private ZA function, then the caller sets up the lazy-save and restores it after the call.

* If the caller has live ZT0 state and the callee is a Private ZA function, then the caller spills ZT0 and reloads it after the call.

For calls to a "Shared ZA" interface:
* If the caller has live ZA state and the callee is a shared ZA function, but doesn't share ZA, then the caller has to spill ZA and reload it after the call.

* If the caller has live ZT0 state and the callee is a shared ZA function, but doesn't share ZT0, then the caller has to spill ZT0 and reload it after the call.

For functions with new ZA/ZT0 state:
* If a function is a shared ZA function and has a `__arm_new("za")`, then it doesn't have to commit a lazy-save, because it can't be active. It also doesn't have to enable [PSTATE.ZA](http://PSTATE.ZA), because this is already active. It only has to zero ZA. 

* If a function is a shared ZA function and has a `__arm_new("zt0")`, then it doesn't have to enable [PSTATE.ZA](http://PSTATE.ZA), because this is already active. It only has to zero ZT0.

Note that I'm not necessarily suggesting to implementing all the above cases in this one PR, it's fine to do this work incrementally.

https://github.com/llvm/llvm-project/pull/76968


More information about the llvm-commits mailing list