public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "elver at google dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/110899] New: RFE: Attributes preserve_most and preserve_all
Date: Fri, 04 Aug 2023 13:57:30 +0000	[thread overview]
Message-ID: <bug-110899-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110899

            Bug ID: 110899
           Summary: RFE: Attributes preserve_most and preserve_all
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: elver at google dot com
  Target Milestone: ---

Clang/LLVM implements the function attributes "preserve_most" and
"preserve_all":

[1] preserve_most: "On X86-64 and AArch64 targets, this attribute changes the
calling convention of a function. The preserve_most calling convention attempts
to make the code in the caller as unintrusive as possible. This convention
behaves identically to the C calling convention on how arguments and return
values are passed, but it uses a different set of caller/callee-saved
registers. This alleviates the burden of saving and recovering a large register
set before and after the call in the caller. If the arguments are passed in
callee-saved registers, then they will be preserved by the callee across the
call. This doesn’t apply for values returned in callee-saved registers.

- On X86-64 the callee preserves all general purpose registers, except for R11.
R11 can be used as a scratch register. Floating-point registers (XMMs/YMMs) are
not preserved and need to be saved by the caller.

- On AArch64 the callee preserve all general purpose registers, except X0-X8
and X16-X18."

[2] preserve_all: "On X86-64 and AArch64 targets, this attribute changes the
calling convention of a function. The preserve_all calling convention attempts
to make the code in the caller even less intrusive than the preserve_most
calling convention. This calling convention also behaves identical to the C
calling convention on how arguments and return values are passed, but it uses a
different set of caller/callee-saved registers. This removes the burden of
saving and recovering a large register set before and after the call in the
caller. If the arguments are passed in callee-saved registers, then they will
be preserved by the callee across the call. This doesn’t apply for values
returned in callee-saved registers.

- On X86-64 the callee preserves all general purpose registers, except for R11.
R11 can be used as a scratch register. Furthermore it also preserves all
floating-point registers (XMMs/YMMs).

- On AArch64 the callee preserve all general purpose registers, except X0-X8
and X16-X18. Furthermore it also preserves lower 128 bits of V8-V31 SIMD -
floating point registers."

[1] https://clang.llvm.org/docs/AttributeReference.html#preserve-most
[2] https://clang.llvm.org/docs/AttributeReference.html#preserve-all


These attributes, esp. preserve_most, provides a convenient way to optimize the
generated code for calls to rarely taken slow paths, such as error-reporting
functions. Recently, we're looking to make use of this in the Linux kernel [3],
with potentially additional usecases being discussed.

[3] https://lkml.kernel.org/r/20230804090621.400-1-elver@google.com

             reply	other threads:[~2023-08-04 13:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-04 13:57 elver at google dot com [this message]
2023-08-04 14:19 ` [Bug target/110899] " pinskia at gcc dot gnu.org
2023-08-07  8:38 ` rguenth at gcc dot gnu.org
2023-08-07 12:28 ` fw at gcc dot gnu.org
2023-08-07 12:55 ` matz at gcc dot gnu.org
2023-08-07 12:59 ` matz at gcc dot gnu.org
2023-08-07 13:42 ` fw at gcc dot gnu.org
2023-08-07 13:55 ` hubicka at gcc dot gnu.org
2023-08-07 15:34 ` matz at gcc dot gnu.org
2023-08-07 16:19 ` fw at gcc dot gnu.org
2023-08-07 16:24 ` matz at gcc dot gnu.org
2023-08-08  8:59 ` fw at gcc dot gnu.org
2023-08-08 12:47 ` matz at gcc dot gnu.org
2023-12-25 11:04 ` sjames at gcc dot gnu.org
2023-12-28 21:26 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-110899-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).