public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Haley <aph@redhat.com>
To: gcc-help@gcc.gnu.org
Subject: Re: When will gcc assign local variables to registers?
Date: Tue, 10 Nov 2020 15:24:24 +0000	[thread overview]
Message-ID: <f98c7d14-0960-ee79-a888-087f9ec8a53b@redhat.com> (raw)
In-Reply-To: <SL2PR02MB35968C6DE34B614513F5E57C83E90@SL2PR02MB3596.apcprd02.prod.outlook.com>

On 10/11/2020 11:27, visitor x via Gcc-help wrote:
> I got that compilers will assign some local variable to registers rather than stack for performance reason, while which variable depends on the compiler. I also found there is a calling convention on x64 that the first six arguments are passed to register (when the class is INTEGER).
> 
> However, I got almost nothing about the rest of the case. I am aware that compilers are free to arrange variables in both stack and registers, but what pricinple or specification will they follow?

None, really. Optimizing compilers don't really care about variables
once the initial transalation has been done, but about values.
https://en.wikipedia.org/wiki/Static_single_assignment_form may help.

> Is there any materials about gcc's behavior on deciding which variables should be kept in registers? Or any other hint to find variables stored in register from a bianry?

It's more complicated than that. Not only can local variables be assigned
to registers, then can be assigned to different registers at differentt
times. Not only that, but local variables can be eliminated completely or
split into multiple copies in different registers.

-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671


  reply	other threads:[~2020-11-10 15:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-10 11:27 visitor x
2020-11-10 15:24 ` Andrew Haley [this message]
     [not found] <SL2PR02MB3596DBDC06124B066570F3D383E80@SL2PR02MB3596.apcprd02.prod.outlook.com>
2020-11-12  5:04 ` visitor x
2020-11-12  6:54   ` Henri Cloetens
2020-11-12 11:43     ` x visitor

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=f98c7d14-0960-ee79-a888-087f9ec8a53b@redhat.com \
    --to=aph@redhat.com \
    --cc=gcc-help@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).