From 6fca22eb3bfe6201a15c0caaa4e3fe052376f863 Mon Sep 17 00:00:00 2001
From: Richard Henderson <rth@gcc.gnu.org>
Date: Thu, 8 Feb 2001 11:15:37 -0800
Subject: [PATCH] i386.c (ix86_frame_pointer_required): New.

        * config/i386/i386.c (ix86_frame_pointer_required): New.
        (ix86_setup_frame_addresses): New.
        (struct machine_funciton): Add accesses_prev_frame.
        * config/i386/i386.h (FRAME_POINTER_REQUIRED): Call
        ix86_frame_pointer_required.
        (SUBTARGET_FRAME_POINTER_REQUIRED): New.
        (SETUP_FRAME_ADDRESSES): New.
        * config/i386/i386-protos.h: Update.
        * config/i386/sco5.h (SUBTARGET_FRAME_POINTER_REQUIRED): Rename
        from FRAME_POINTER_REQUIRED.
        * config/i386/svr3gas.h: Likewise.
        * config/i386/sysv3.h: Likewise.
        * config/i386/v3gas.h: Likewise.

From-SVN: r39545
---
 gcc/ChangeLog                 | 120 +++++++++++++++++++---------------
 gcc/config/i386/i386-protos.h |   2 +
 gcc/config/i386/i386.c        |  35 ++++++++++
 gcc/config/i386/i386.h        |  11 +++-
 gcc/config/i386/sco5.h        |   4 +-
 gcc/config/i386/svr3gas.h     |   4 +-
 gcc/config/i386/sysv3.h       |   4 +-
 gcc/config/i386/v3gas.h       |   4 +-
 8 files changed, 123 insertions(+), 61 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b2d50401335f..64633565eb46 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,19 @@
+2001-02-08  Richard Henderson  <rth@redhat.com>
+
+	* config/i386/i386.c (ix86_frame_pointer_required): New.
+	(ix86_setup_frame_addresses): New.
+	(struct machine_funciton): Add accesses_prev_frame.
+	* config/i386/i386.h (FRAME_POINTER_REQUIRED): Call
+	ix86_frame_pointer_required.
+	(SUBTARGET_FRAME_POINTER_REQUIRED): New.
+	(SETUP_FRAME_ADDRESSES): New.
+	* config/i386/i386-protos.h: Update.
+	* config/i386/sco5.h (SUBTARGET_FRAME_POINTER_REQUIRED): Rename
+	from FRAME_POINTER_REQUIRED.
+	* config/i386/svr3gas.h: Likewise.
+	* config/i386/sysv3.h: Likewise.
+	* config/i386/v3gas.h: Likewise.
+
 2001-02-08  Richard Henderson  <rth@redhat.com>
 
 	* config/sparc/sparc.c (function_arg_record_value_3): Fix
@@ -91,19 +107,19 @@ Thu Feb  8 11:21:28 2001  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>
 
 2001-01-30  Bruce Korb  <bkorb@gnu.org>
 
-        fixinc/fixincl.c(process):  Emit error message only if appropriate :)
-        (load_file): do not rely on load_file_data() to close file pointer
-        fixinc/fixlib.c(load_file_data): do not close passed in file pointer
+	fixinc/fixincl.c(process):  Emit error message only if appropriate :)
+	(load_file): do not rely on load_file_data() to close file pointer
+	fixinc/fixlib.c(load_file_data): do not close passed in file pointer
 	fixinc/inclhack.def(irix_limits_const): add test_text
 
 2001-02-06  Neil Booth  <neil@daikokuya.demon.co.uk>
 
-        * cppexp.c (parse_defined): Improve diagnostics for invalid
-        syntax.
+	* cppexp.c (parse_defined): Improve diagnostics for invalid
+	syntax.
 
 2001-02-06  Neil Booth  <neil@daikokuya.demon.co.uk>
 
-        * cppmacro.c (cpp_get_token): Avoid pasting after a builtin.
+	* cppmacro.c (cpp_get_token): Avoid pasting after a builtin.
 
 2001-02-06  Mark Mitchell  <mark@codesourcery.com>
 
@@ -155,13 +171,13 @@ Mon Feb  5 21:56:16 2001  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>
 2001-02-05  Chandrakala Chavva  <cchavva@redhat.com>
 
 	* final.c: Move the declaration of profile_label_no to ...
-        * output.h: ... here.
-        * function.c (expand_function_start): Call PROFILE_HOOK.
-        * config/rs6000/aix.h: Define PROFILE_HOOK.
-        * config/rs6000/rs6000-protos.h: output_profile_hook new.
-        * config/rs6000/rs6000.c (output_profile_hook): Define.
-        (output_prolog): Do nothing for ABI_AIX as it is taken care by
-        output_profile_hook.
+	* output.h: ... here.
+	* function.c (expand_function_start): Call PROFILE_HOOK.
+	* config/rs6000/aix.h: Define PROFILE_HOOK.
+	* config/rs6000/rs6000-protos.h: output_profile_hook new.
+	* config/rs6000/rs6000.c (output_profile_hook): Define.
+	(output_prolog): Do nothing for ABI_AIX as it is taken care by
+	output_profile_hook.
 	tm.texi : Explain new macro PROFILE_HOOK.
 
 2001-02-06  Hans-Peter Nilsson  <hp@axis.com>
@@ -176,7 +192,7 @@ Mon Feb  5 21:56:16 2001  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>
 	* Makefile.in (gcc_gxx_target_include_dir): Use $(target_alias).
 
 2001-02-05  Franz Sirl  <Franz.Sirl-kernel@lauterbach.com>
-            David Edelsohn  <edelsohn@gnu.org>
+	    David Edelsohn  <edelsohn@gnu.org>
 
 	* config/rs6000/rs6000.c (rs6000_return_addr): Use PIC 
 	code for AIX, even without flag_pic.
@@ -317,13 +333,13 @@ Sun Feb  4 15:52:44 2001  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>
 
 2001-02-03  Neil Booth  <neil@daikokuya.demon.co.uk>
 
-        * cpphash.h: Rename _ALIGN POOL_ALIGN.
-        * cpplex.c (new_chunk, _cpp_pool_reserve): Update.  
+	* cpphash.h: Rename _ALIGN POOL_ALIGN.
+	* cpplex.c (new_chunk, _cpp_pool_reserve): Update.  
 
 2001-02-03  Neil Booth  <neil@daikokuya.demon.co.uk>
 
-        * cpphash.h: Rename ALIGN _ALIGN.
-        * cpplex.c (new_chunk, _cpp_pool_reserve): Update.  
+	* cpphash.h: Rename ALIGN _ALIGN.
+	* cpplex.c (new_chunk, _cpp_pool_reserve): Update.  
 
 Fri Feb  2 23:15:29 2001  Christopher Faylor <cgf@cygnus.com>
 
@@ -433,16 +449,16 @@ Fri Feb  2 20:03:50 2001  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>
 
 2001-02-01  Neil Booth  <neil@daikokuya.demon.co.uk>
 
-        * cpphash.h (struct cpp_buffer): Move saved_flags from cpp_reader.
-        * cpplex.c (_cpp_lex_token): New token picks up the saved flags,
-        and AVOID_LPASTE is cleared on meeting an unescaped newline.
-        * cppmacro.c (builtin_macro): Set builtin flags here.
-        (paste_all_tokens): Preserve AVOID_LPASTE on pasted token.
-        (replace_args): Clarify intent.
-        (cpp_get_token): Macro expansion tokens get the saved flags.
-        Update.
-        * cppmain.c (scan_buffer): Remove now-redundant print.printed
-        check.
+	* cpphash.h (struct cpp_buffer): Move saved_flags from cpp_reader.
+	* cpplex.c (_cpp_lex_token): New token picks up the saved flags,
+	and AVOID_LPASTE is cleared on meeting an unescaped newline.
+	* cppmacro.c (builtin_macro): Set builtin flags here.
+	(paste_all_tokens): Preserve AVOID_LPASTE on pasted token.
+	(replace_args): Clarify intent.
+	(cpp_get_token): Macro expansion tokens get the saved flags.
+	Update.
+	* cppmain.c (scan_buffer): Remove now-redundant print.printed
+	check.
 
 2001-02-01  Jeffrey Oldham  <oldham@codesourcery.com>
 
@@ -520,14 +536,14 @@ Thu Feb  1 07:22:41 2001  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>
 
 2001-01-31  Neil Booth  <neil@daikokuya.demon.co.uk>
 
-        * cpplib.c (T_ELIF): Move to STDC89, not that it matters.
-        (_cpp_handle_directive): Suggest not using #elif with -Wtraditional.
+	* cpplib.c (T_ELIF): Move to STDC89, not that it matters.
+	(_cpp_handle_directive): Suggest not using #elif with -Wtraditional.
 
 2001-01-31  Neil Booth  <neil@daikokuya.demon.co.uk>
 
-        * cpphash.h (struct cpp_reader): New saved_flags.
-        * cppmacro.c (cpp_get_token): Use saved_flags to remember
-        to avoid a paste after a pasted token.
+	* cpphash.h (struct cpp_reader): New saved_flags.
+	* cppmacro.c (cpp_get_token): Use saved_flags to remember
+	to avoid a paste after a pasted token.
 	  
 2001-01-31  Alexandre Oliva  <aoliva@redhat.com>
 
@@ -568,10 +584,10 @@ Thu Feb  1 07:22:41 2001  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>
 
 2001-01-30  Neil Booth  <neil@daikokuya.demon.co.uk>
 
-        * c-decl.c (c_expand_body): Check TYPE_SIZE_UNIT (ret_type)
-        is not NULL.
-        * toplev.c (decode_W_option): Update warn_larger_than
-        unconditionally for each processed switch.
+	* c-decl.c (c_expand_body): Check TYPE_SIZE_UNIT (ret_type)
+	is not NULL.
+	* toplev.c (decode_W_option): Update warn_larger_than
+	unconditionally for each processed switch.
 
 2001-01-30  John David Anglin  <dave@hiauly1.hia.nrc.ca>
 
@@ -585,7 +601,7 @@ Thu Feb  1 07:22:41 2001  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>
 
 2001-01-29  lars brinkhoff  <lars@nocrew.org>
 
-        * tm.texi (PUSH_ROUNDING): Remove duplicate lines.
+	* tm.texi (PUSH_ROUNDING): Remove duplicate lines.
 
 2001-01-29  John David Anglin  <dave@hiauly1.hia.nrc.ca>
 	    Jeff Law <law@redhat.com>
@@ -632,8 +648,8 @@ Mon Jan 29 20:38:19 2001  Christopher Faylor <cgf@cygnus.com>
 
 2001-01-29  Neil Booth  <neil@daikokuya.demon.co.uk>
 
-        * cpplib.c (T_BAD_DIRECTIVE): Remove.
-        (_cpp_init_stacks): Loop from 0 to N_DIRECTIVES - 1.
+	* cpplib.c (T_BAD_DIRECTIVE): Remove.
+	(_cpp_init_stacks): Loop from 0 to N_DIRECTIVES - 1.
 
 2001-01-29  Joseph S. Myers  <jsm28@cam.ac.uk>
 
@@ -668,18 +684,18 @@ Mon Jan 29 20:38:19 2001  Christopher Faylor <cgf@cygnus.com>
 
 2001-01-28  Neil Booth  <neil@daikokuya.demon.co.uk>
 
-        * cpphash.c (_cpp_cleanup_hashtable, _cpp_lookup_with_hash)
-        : Don't set fe_value.
-        * cpplib.h (AVOID_LPASTE): New flag. 
-        (struct cpp_hashnode): Remove fe_value.
-        * cpplex.c (cpp_avoid_paste): Don't paste '.' with a number.
-        * cppmacro.c (builtin_macro): Don't set flags here.
-        (replace_args): Set AVOID_LPASTE flag on first token of an
-        argument, and the token following it.
-        (cpp_get_token): Set AVOID_LPASTE flag on first token of a
-        macro expansion, and on the token following it.  Do it for
-        builtins too.
-        * cppmain.c (scan_buffer): Avoid pasting only flagged tokens.
+	* cpphash.c (_cpp_cleanup_hashtable, _cpp_lookup_with_hash)
+	: Don't set fe_value.
+	* cpplib.h (AVOID_LPASTE): New flag. 
+	(struct cpp_hashnode): Remove fe_value.
+	* cpplex.c (cpp_avoid_paste): Don't paste '.' with a number.
+	* cppmacro.c (builtin_macro): Don't set flags here.
+	(replace_args): Set AVOID_LPASTE flag on first token of an
+	argument, and the token following it.
+	(cpp_get_token): Set AVOID_LPASTE flag on first token of a
+	macro expansion, and on the token following it.  Do it for
+	builtins too.
+	* cppmain.c (scan_buffer): Avoid pasting only flagged tokens.
 
 2001-01-27  Richard Henderson  <rth@redhat.com>
 
diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h
index e9cb3a88f975..03fa84f37955 100644
--- a/gcc/config/i386/i386-protos.h
+++ b/gcc/config/i386/i386-protos.h
@@ -25,6 +25,8 @@ extern void order_regs_for_local_alloc PARAMS ((void));
 extern void optimization_options PARAMS ((int, int));
 
 extern int ix86_can_use_return_insn_p PARAMS ((void));
+extern int ix86_frame_pointer_required PARAMS ((void));
+extern void ix86_setup_frame_addresses PARAMS ((void));
 
 extern void ix86_asm_file_end PARAMS ((FILE *));
 extern void load_pic_register PARAMS ((void));
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 708e8ee08497..2737b6bccd44 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -331,6 +331,7 @@ struct rtx_def *ix86_compare_op1 = NULL_RTX;
 struct machine_function
 {
   rtx stack_locals[(int) MAX_MACHINE_MODE][MAX_386_STACK_LOCALS];
+  int accesses_prev_frame;
 };
 
 #define ix86_stack_locals (cfun->machine->stack_locals)
@@ -1700,6 +1701,40 @@ ix86_can_use_return_insn_p ()
   tsize = ix86_compute_frame_size (get_frame_size (), &nregs, NULL, NULL);
   return tsize == 0 && nregs == 0;
 }
+
+/* Value should be nonzero if functions must have frame pointers.
+   Zero means the frame pointer need not be set up (and parms may
+   be accessed via the stack pointer) in functions that seem suitable.  */
+
+int
+ix86_frame_pointer_required ()
+{
+  /* If we accessed previous frames, then the generated code expects
+     to be able to access the saved ebp value in our frame.  */
+  if (cfun->machine->accesses_prev_frame)
+    return 1;
+  
+  /* Several x86 os'es need a frame pointer for other reasons,
+     usually pertaining to setjmp.  */
+  if (SUBTARGET_FRAME_POINTER_REQUIRED)
+    return 1;
+
+  /* In override_options, TARGET_OMIT_LEAF_FRAME_POINTER turns off
+     the frame pointer by default.  Turn it back on now if we've not
+     got a leaf function.  */
+  if (TARGET_OMIT_LEAF_FRAME_POINTER && ! leaf_function_p ())
+    return 1;
+
+  return 0;
+}
+
+/* Record that the current function accesses previous call frames.  */
+
+void
+ix86_setup_frame_addresses ()
+{
+  cfun->machine->accesses_prev_frame = 1;
+}
 
 static char pic_label_name[32];
 
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 016aac6c31a0..480087241982 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -852,7 +852,16 @@ extern int ix86_arch;
    Zero means the frame pointer need not be set up (and parms
    may be accessed via the stack pointer) in functions that seem suitable.
    This is computed in `reload', in reload1.c.  */
-#define FRAME_POINTER_REQUIRED (TARGET_OMIT_LEAF_FRAME_POINTER && !leaf_function_p ()) 	
+#define FRAME_POINTER_REQUIRED  ix86_frame_pointer_required ()
+
+/* Override this in other tm.h files to cope with various OS losage
+   requiring a frame pointer.  */
+#ifndef SUBTARGET_FRAME_POINTER_REQUIRED
+#define SUBTARGET_FRAME_POINTER_REQUIRED 0
+#endif
+
+/* Make sure we can access arbitrary call frames.  */
+#define SETUP_FRAME_ADDRESSES()  ix86_setup_frame_addresses ()
 
 /* Base register for access to arguments of the function.  */
 #define ARG_POINTER_REGNUM 16
diff --git a/gcc/config/i386/sco5.h b/gcc/config/i386/sco5.h
index b23990bb7997..ae832b91f5f5 100644
--- a/gcc/config/i386/sco5.h
+++ b/gcc/config/i386/sco5.h
@@ -632,8 +632,8 @@ dtors_section ()							\
     }									\
 }
 
-#undef FRAME_POINTER_REQUIRED
-#define FRAME_POINTER_REQUIRED						\
+#undef SUBTARGET_FRAME_POINTER_REQUIRED
+#define SUBTARGET_FRAME_POINTER_REQUIRED				\
   ((TARGET_ELF) ? 0 : 							\
    (current_function_calls_setjmp || current_function_calls_longjmp))
 
diff --git a/gcc/config/i386/svr3gas.h b/gcc/config/i386/svr3gas.h
index d196008f829f..e5bf3db5b4b2 100644
--- a/gcc/config/i386/svr3gas.h
+++ b/gcc/config/i386/svr3gas.h
@@ -37,8 +37,8 @@ Boston, MA 02111-1307, USA.  */
    Since a frame pointer will be required in such a function, it is OK
    that the stack pointer is not restored.  */
 
-#undef FRAME_POINTER_REQUIRED
-#define FRAME_POINTER_REQUIRED \
+#undef SUBTARGET_FRAME_POINTER_REQUIRED
+#define SUBTARGET_FRAME_POINTER_REQUIRED \
   (current_function_calls_setjmp || current_function_calls_longjmp)
 
 /* Modify ASM_OUTPUT_LOCAL slightly to test -msvr3-shlib, adapted to gas  */
diff --git a/gcc/config/i386/sysv3.h b/gcc/config/i386/sysv3.h
index ffcf3bfa4081..9d7350283d2f 100644
--- a/gcc/config/i386/sysv3.h
+++ b/gcc/config/i386/sysv3.h
@@ -78,8 +78,8 @@ Boston, MA 02111-1307, USA.  */
    Since a frame pointer will be required in such a function, it is OK
    that the stack pointer is not restored.  */
 
-#undef FRAME_POINTER_REQUIRED
-#define FRAME_POINTER_REQUIRED \
+#undef SUBTARGET_FRAME_POINTER_REQUIRED
+#define SUBTARGET_FRAME_POINTER_REQUIRED \
   (current_function_calls_setjmp || current_function_calls_longjmp)
 
 /* Modify ASM_OUTPUT_LOCAL slightly to test -msvr3-shlib.  */
diff --git a/gcc/config/i386/v3gas.h b/gcc/config/i386/v3gas.h
index fe558d265b42..a350ab40bcd3 100644
--- a/gcc/config/i386/v3gas.h
+++ b/gcc/config/i386/v3gas.h
@@ -37,8 +37,8 @@ Boston, MA 02111-1307, USA.  */
    Since a frame pointer will be required in such a function, it is OK
    that the stack pointer is not restored.  */
 
-#undef FRAME_POINTER_REQUIRED
-#define FRAME_POINTER_REQUIRED \
+#undef SUBTARGET_FRAME_POINTER_REQUIRED
+#define SUBTARGET_FRAME_POINTER_REQUIRED \
   (current_function_calls_setjmp || current_function_calls_longjmp)
 
 /* Modify ASM_OUTPUT_LOCAL slightly to test -msvr3-shlib, adapted to gas  */
-- 
GitLab