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] builtin_frame_address(0) and omit-frame-pointer


Hi,

> On Fri, Jan 14, 2005 at 01:21:01PM +0100, Andreas Krebbel1 wrote:
>> It works only for s390 because the frame pointer
>> is always eliminated to hard frame pointer without any offset.

> Why do you think this is required?  It's a pointer to "The Frame",
> and "The Frame" is whatever we define it to be.  A rather useless
> definition, true, but I defy you to get any useful meaning out of
> it in the first place.

An offset of zero between hard_frame_pointer_rtx and
frame_pointer_rtx is necessary to make builtin_frame_address (n)
(and b.t.w. builtin_return_addr (n))
work for n > 0. In such cases the builtin has to unwind the backchain to 
find the address. In order to do that it would dereference the
initial pointer. When this initial pointer is changed from 
hard frame pointer to frame pointer and they do not represent the
same value then we would dereference a random value (most probably
one of the auto variables). Hence replacing hard_frame_pointer_rtx
by frame_pointer_rtx would break builtin_frame_address (n) n>0 on
all platforms where frame_pointer_rtx is not eliminated to 
hard_frame_pointer_rtx without any offset.

The attached patch introduces a macro to be used by the back ends to 
specify what the initial pointer should be. On s390 we would use
this in order to calculate the position where the last backchain
pointer was stored without using the hard frame pointer. Hence
builtin_frame_address (0) would work with -fomit-frame-pointer. I
think for i386 and co similiar solutions can be found.

This patch fixes the pass45-frag.c regression on s390 (31bit).

Bootstrapped and regtested on i386, s390, s390x.

OK? If yes I will resubmit it with the respective changes to gcc documentation.

Bye,

-Andreas-


2005-01-17  Andreas Krebbel  <krebbel1@de.ibm.com>

	* gcc/builtins.c (expand_builtin_return_addr): Remove tem parameter.
	tem becomes a local variable which is set to the value of the 
	back end defined INITIAL_FRAME_ADDRESS macro.
	(expand_builtin_frame_address): Omit the base parameter to 
	expand_builtin_return_addr.
	* config/s390/s390.h (INITIAL_FRAME_ADDRESS_RTX): Define new macro.
	(DYNAMIC_CHAIN_ADDRESS): Remove the case for the initial frame.


Index: gcc/builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.c,v
retrieving revision 1.412
diff -p -c -r1.412 builtins.c
*** gcc/builtins.c	11 Jan 2005 09:51:12 -0000	1.412
--- gcc/builtins.c	14 Jan 2005 16:23:52 -0000
*************** builtin_save_expr (tree exp)
*** 452,462 ****
     address located within it (depending on FNDECL_CODE).  */
  
  static rtx
! expand_builtin_return_addr (enum built_in_function fndecl_code, int count,
! 			    rtx tem)
  {
    int i;
  
    /* Some machines need special handling before we can access
       arbitrary frames.  For example, on the sparc, we must first flush
       all register windows to the stack.  */
--- 452,467 ----
     address located within it (depending on FNDECL_CODE).  */
  
  static rtx
! expand_builtin_return_addr (enum built_in_function fndecl_code, int count)
  {
    int i;
  
+ #ifdef INITIAL_FRAME_ADDRESS_RTX
+   rtx tem = INITIAL_FRAME_ADDRESS_RTX;
+ #else
+   rtx tem = hard_frame_pointer_rtx;
+ #endif
+ 
    /* Some machines need special handling before we can access
       arbitrary frames.  For example, on the sparc, we must first flush
       all register windows to the stack.  */
*************** expand_builtin_frame_address (tree fndec
*** 4146,4156 ****
        return const0_rtx;
      }
    else
!     {
        rtx tem
  	= expand_builtin_return_addr (DECL_FUNCTION_CODE (fndecl),
! 				      tree_low_cst (TREE_VALUE (arglist), 1),
! 				      hard_frame_pointer_rtx);
  
        /* Some ports cannot access arbitrary stack frames.  */
        if (tem == NULL)
--- 4151,4160 ----
        return const0_rtx;
      }
    else
!     { 
        rtx tem
  	= expand_builtin_return_addr (DECL_FUNCTION_CODE (fndecl),
! 				      tree_low_cst (TREE_VALUE (arglist), 1));
  
        /* Some ports cannot access arbitrary stack frames.  */
        if (tem == NULL)
*************** expand_builtin_profile_func (bool exitp)
*** 4760,4766 ****
  
    emit_library_call (which, LCT_NORMAL, VOIDmode, 2, this, Pmode,
  		     expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
! 						 0, hard_frame_pointer_rtx),
  		     Pmode);
  
    return const0_rtx;
--- 4764,4770 ----
  
    emit_library_call (which, LCT_NORMAL, VOIDmode, 2, this, Pmode,
  		     expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
! 						 0),
  		     Pmode);
  
    return const0_rtx;
Index: gcc/config/s390/s390.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/s390/s390.h,v
retrieving revision 1.131
diff -p -c -r1.131 s390.h
*** gcc/config/s390/s390.h	30 Dec 2004 03:08:05 -0000	1.131
--- gcc/config/s390/s390.h	14 Jan 2005 16:23:52 -0000
*************** extern int current_function_outgoing_arg
*** 612,617 ****
--- 612,622 ----
     the argument area.  */
  #define FIRST_PARM_OFFSET(FNDECL) 0
  
+ #define INITIAL_FRAME_ADDRESS_RTX                                               \
+   (TARGET_PACKED_STACK ?                                                        \
+    plus_constant (arg_pointer_rtx, -UNITS_PER_WORD) :                           \
+    plus_constant (arg_pointer_rtx, -STACK_POINTER_OFFSET))
+ 
  /* The return address of the current frame is retrieved
     from the initial value of register RETURN_REGNUM.
     For frames farther back, we use the stack slot where
*************** extern int current_function_outgoing_arg
*** 619,629 ****
  
  #define DYNAMIC_CHAIN_ADDRESS(FRAME)                                            \
    (TARGET_PACKED_STACK ?                                                        \
!     ((FRAME) != hard_frame_pointer_rtx ?                                        \
!      plus_constant ((FRAME), STACK_POINTER_OFFSET - UNITS_PER_WORD) :           \
!      plus_constant (arg_pointer_rtx, -UNITS_PER_WORD)) :                        \
!      ((FRAME) != hard_frame_pointer_rtx ? (FRAME) :				\
!       plus_constant (arg_pointer_rtx, -STACK_POINTER_OFFSET)))
  
  #define RETURN_ADDR_RTX(COUNT, FRAME)						\
    s390_return_addr_rtx ((COUNT), DYNAMIC_CHAIN_ADDRESS ((FRAME)))
--- 624,630 ----
  
  #define DYNAMIC_CHAIN_ADDRESS(FRAME)                                            \
    (TARGET_PACKED_STACK ?                                                        \
!    plus_constant ((FRAME), STACK_POINTER_OFFSET - UNITS_PER_WORD) : (FRAME))
  
  #define RETURN_ADDR_RTX(COUNT, FRAME)						\
    s390_return_addr_rtx ((COUNT), DYNAMIC_CHAIN_ADDRESS ((FRAME)))


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