public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Henderson <rth@redhat.com>
To: redriver jiang <jiang.redriver@gmail.com>
Cc: gcc@gcc.gnu.org
Subject: Re: About "STARTING_FRAME_OFFSET" definition
Date: Tue, 23 Mar 2010 19:21:00 -0000	[thread overview]
Message-ID: <4BA9086D.5050104@redhat.com> (raw)
In-Reply-To: <714984df1003230555l61261442ubdfdea009254a5b9@mail.gmail.com>

On 03/23/2010 05:55 AM, redriver jiang wrote:
> Hi all,
> 
> Can this "STARTING_FRAME_OFFSET" macro be defined to be a non-constant
> value ( changes with the "current_function_args_size")?
> 
> As the target process has "FP+offset" with postive "offset"( stack
> grows upward, and parameters in stack grows downward), for example,
> 
> call foo( arg1, arg2, arg3,arg4), after foo's prologue, the stack is like this:
> 
>                                              <---- low address
>          |--------------------------------|
> 	 |     Incoming arg4       | <-------------FP
>          |--------------------------------|
> 	 |      Incoming arg3      |
>          |--------------------------------|
> 	 |     Incoming arg2       |
> 	 |--------------------------------|
> 	 |     Incoming arg1       | <---------------ARG
> 	 |--------------------------------|
> 	 |	return PC of foo   |
> 	 |--------------------------------|
> 	 |		saved regs  |
> 	 |--------------------------------|
> 	 |		old FP        |
> 	 |--------------------------------|
> 	 |         local var0         |
> 	 |--------------------------------|
> 			                    <---- high address
> 
>  "STARTING_FRAME_OFFSET" means the offset between FP and the first
> local variable, in this situation,
> 
> STARTING_FRAME_OFFSE = current_function_args_size+ size(PC in stack) +
> size(saved regs) + size(old FP).
> 
> so, "STARTING_FRAME_OFFSET" depends on the
> "current_function_args_size", which is a GCC internal variable.
> 
> Is this stack layout suitable?

It's possible to create this stack layout, yes.

STARTING_FRAME_OFFSET doesn't really ought not enter into it, I don't think.

What you'll want instead is to have a separate "soft" frame_pointer_rtx
and hard_frame_pointer_rtx.  Then during register allocation you eliminate
from the soft frame pointer to the hard frame pointer with an offset you
calculate at that point.  There are many examples of this in existing ports,
including the i386 port.

The reason why you want to handle this via elimination rather than a fixed
offset during initial rtl generation is your "saved regs" field there, which
of course will vary in size depending on what registers get spilled.

So I would begin with STARTING_FRAME_OFFSET=0 and have the soft frame pointer
point to "local var0" in your picture.  Then your INITIAL_ELIMINATION_OFFSET
function would map:

  ARG_POINTER_REGNUM	HARD_FRAME_POINTER_REGNUM
  = -current_function_args_size

  FRAME_POINTER_REGNUM	HARD_FRAME_POINTER_REGNUM
  = -(sizeof(saved_regs) + sizeof(FP) + sizeof(return PC) + current_function_args_size)



r~

  reply	other threads:[~2010-03-23 18:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-23 17:56 redriver jiang
2010-03-23 19:21 ` Richard Henderson [this message]
2010-03-24 18:33   ` redriver jiang

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=4BA9086D.5050104@redhat.com \
    --to=rth@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=jiang.redriver@gmail.com \
    /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).