This is the mail archive of the gcc@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]

Re: Frame pointer optimization issues



On 20/08/14 16:22, Wilco Dijkstra wrote:
Hi,

Various targets implement -momit-leaf-frame-pointer to avoid using a frame pointer in leaf
functions. Currently the GCC mid-end does not provide a way of doing this, so targets have resorted
to hacks. Typically this involves forcing flag_omit_frame_pointer to be true in the
<arch>_option_override callback. The issue is that this doesn't work as it modifies the actual
option variable. As a result the callback is not idempotent, so option save/restore when using
function attributes fail as the callback is called multiple times on the modified options. Note this
bug exists on all targets which override options in <arch>_option_override (and despite claims to
the contrary in BZ 60580 this bug exists on all targets that implement -fomit-leaf-frame-pointer).

 agree, current gcc don't support finer control of frame pointer.

 currently all three targets i386/aarch64/bfin want finer control
 of frame pointer for leaf function have bug.
for example, for a simple testcase:

     __attribute__ ((optimize("no-omit-frame-pointer")))
     int
     cal (int a)
     {
       int b = a + 0x200;
       foo(&b);
       return a + b + 1;
     }

     __attribute__ ((optimize("omit-frame-pointer")))
     int
     cal1 (int a)
     {
       int b = a + 0x200;
       foo(&b);
       return a + b + 1;
     }

 ./cc1-bfin -O0 hello.c -momit-leaf-frame-pointer

 the attribute for "cal1" doesn't work.

2. Change the mid-end to call <arch>_frame_pointer_required even when !flag_omit_frame_pointer. This
is a generic solution which allows targets to decide when exactly to optimize frame pointers.
However it does mean all implementations of <arch>_frame_pointer_required must be updated (the
trivial safe fix is to add "if (!flag_omit_frame_pointer) return true;" at the start).

 IMHO, this fix make sense, it will let the calculation for frame_pointer_needed to be more
 flexible.

 remove the "! flag_omit_frame_pointer" when initialize frame_pointer_needed, and let frame_pointer_required
 hook to check flag_omit_frame_pointer and any other target frame pointer control flags like omit-leaf-frame-pointer
 etc to decide whether frame pointer needed.

  frame_pointer_needed
    = (! flag_omit_frame_pointer
       || (cfun->calls_alloca && EXIT_IGNORE_STACK)
       /* We need the frame pointer to catch stack overflow exceptions
  ....

  any comments?

  thanks.

 -- Jiong



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