This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Don't use callgraph to increase preferred_stack_boundary


On Tue, May 6, 2008 at 6:01 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Tue, May 6, 2008 at 6:24 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>  >
>  > On Mon, May 05, 2008 at 09:40:06PM -0700, H.J. Lu wrote:
>  >  > On Mon, May 5, 2008 at 9:25 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>  >  > >
>  >  > > On Mon, May 5, 2008 at 8:12 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>  >  > >  >
>  >  > >  > On Mon, May 5, 2008 at 5:57 PM, Ye, Joey <joey.ye@intel.com> wrote:
>  >  > >  >  > Jan,
>  >  > >  >  >
>  >  > >  >  > > You can certainly track this with callgraph.  I.e. use case 0 by
>  >  > >  >  >  > default, but case 2 if you know bar is being called only from foos
>  >  > >  >  >  that
>  >  > >  >  >  > will align anyway.
>  >  > >  >  >  > Since we compile in topological order, it all depends on how well you
>  >  > >  >  >  > are able to decide on alignments at tree level or if you want to go
>  >  > >  >  >  down
>  >  > >  >  >  > the road of alternate entry point (so foo can skip alignment prologue
>  >  > >  >  >  if
>  >  > >  >  >  > called from function with proper alignment guaranteed).
>  >  > >  >  >  How about bar is called from other compilation units? Call callgraph
>  >  > >  >  >  track that?
>  >  > >  >  >
>  >  > >  >
>  >  > >  >  As far as I can tell, preferred_incoming_stack_boundary tracked by callgraph
>  >  > >  >  is a best effort approach. There is no guarantee that all callers will satisfy
>  >  > >  >  preferred_incoming_stack_boundary needed by callee. If callee needs strict
>  >  > >  >  alignment, it has to align the stack itself.
>  >  > >  >
>  >  > >  >  With automatic stack alignment, we don't need to collect
>  >  > >  >  preferred_incoming_stack_boundary
>  >  > >  >  in callgraph.  Without automatic stack alignment, we align outgoing stack
>  >  > >  >  to PREFERRED_STACK_BOUNDARY, no more and no less. If
>  >  > >  >  preferred_incoming_stack_boundary > PREFERRED_STACK_BOUNDARY,
>  >  > >  >  we still can't align outgoing stack to preferred_incoming_stack_boundary.
>  >  > >  >
>  >  > >
>  >  > >  Hi Joey,
>  >  > >
>  >  > >  If we know all incoming stack alignments of functions we call, can we optimize
>  >  > >  stack for caller? That is for
>  >  > >
>  >  > >  foo ()
>  >  > >  {
>  >  > >   bar1 ();
>  >  > >  ...
>  >  > >   bar2 ();
>  >  > >  }
>  >  > >
>  >  > >  the required stack boundary of foo will be
>  >  > >
>  >  > >  MAX (LOCAL, MIN (PREFERRED, MAX (INCOMING (bar1), INCOMING (bar2))))
>  >  > >
>  >  > >  We may be able to use less stack in foo if the required stack boundary
>  >  > >  is smaller.
>  >  > >  But it won't affect stack alignment in foo since we won't align
>  >  > >  outgoing stack beyond
>  >  > >  PREFERRED unless we need to put something on stack.
>  >  > >
>  >  >
>  >  > Hi Joey,
>  >  >
>  >  > We don't care about if the caller is a leaf function or not. As long
>  >  > as we know stack alignments of all callees, we can optimize
>  >  > stack usage.
>  >  >
>  >  >
>  >
>  >  I am checking in this patch into stack branch.
>  >
>  >  Thanks.
>  >
>  >  H.J.
>  >  ----
>  >  Index: ChangeLog.stackalign
>  >  ===================================================================
>  >  --- ChangeLog.stackalign        (revision 134915)
>  >  +++ ChangeLog.stackalign        (working copy)
>  >  @@ -1,3 +1,11 @@
>  >  +2008-05-06  Joey Ye  <joey.ye@intel.com>
>  >  +
>  >  +       * calls.c (expand_call): Do calculate preferred stack
>  >  +       boundary according to incoming stack boundary.
>  >  +
>  >  +       * config/i386/i386.c (ix86_internal_arg_pointer): Check
>  >  +       crtl->preferred_stack_boundary instead of PREFERRED_STACK_BOUNDARY.
>  >  +
>  >   2008-04-26  H.J. Lu  <hongjiu.lu@intel.com>
>  >
>
>  Unfortunately, this doesn't work with C++ EH. Jan, does callgraph
>  collect incoming
>  stack alignment for exception? If not, we have to use PREFERRED_STACK_BOUNDARY
>  if there is exception.
>

Hi Jan,

Without automatic stack alignment, we can't increase preferred stack boundary.
With automatic stack alignment, it is unnecessary to increase
preferred stack boundary
since unless we can guarantee that all callers will align the outgoing
stack properly,
callee has to align its stack anyway.

Tested on Linux/ia32 and Linux/Intel64. OK for trunk?

Thanks.

H.J.
----
2008-05-07  H.J. Lu  <hongjiu.lu@intel.com>

        * calls.c (expand_call): Don't use callgraph to increase
        preferred_stack_boundary.

        * cgraph.h (cgraph_rtl_info): Use unsigned on
        preferred_incoming_stack_boundary.

        * final.c (rest_of_clean_state): Use unsigned on
        preferred_stack_boundary.

Attachment: i.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]