[patch] protecting MIPS prologues from scheduling.

Chris G. Demetriou cgd@sibyte.com
Mon Jul 31 17:55:00 GMT 2000


Enclosed below is a patch which provides an option (copied from the
ARM option of the same name) to protect MIPS function prologues from
scheduling.

First, though, a bit of explanation and a couple of questions:

A coworker was having difficulty debugging code (compiled with gcc
2.95.2 and debugging with gdb 4.18) because the first instruction
"after" the prologue had been move into the middle of the set of
prologue instructions which would save regs on the stack, etc.  The
"end of prologue" indicator that gdb was using would also be moved,
and so, for some functions (which had their prologues optimized), when
gdb would break at the function the values that it expected on the
stack wouldn't yet have been written there.

In gcc 2.95.2, i386 and arm targets had flags
("-mno-schedule-prologue", and "-mno-sched-prolog" respectively) which
would disable scheduling of the prologue instructions.

In the current gcc sources, the i386 flag seems to have been removed,
but the arm flag remains and a flag for rs6000 (with the same name but
a slightly different implementation, and no documentation! 8-) has
been added.

So, the questions:

* Is the issue at the root of my coworker's problem considered a
  gcc/optimization issue, or a GDB issue?  Specifically, where
  "should" it be solved (or worked around)?

* Why was the i386 flag removed?  Is this type of flag considered
  undesirable, or was it just part of the i386 code churn that's
  happened since 2.95.2?


Below is the patch, against the current gcc sources.  A few notes
about it:

* I'm not keen on the flag's spelling, but i figured it would be
  better to copy the arm/rs6000 name than to invent a new one.

* The invoke.texi change is copied verbatim from the ARM section.

* I've no clue what's going on with the internationalization stuff,
  so i didn't try to change anything in gcc/po/*

* I've got a slightly different version of this change running (well)
  in 2.95.2, but this was only "tested" in the current gcc sources by
  making sure that it would compile.



chris
===================================================================

2000-07-31  Chris Demetriou  <cgd@sibyte.com>

	* invoke.texi (MIPS Options): add -msched-prolog and
	-mno-sched-prolog.

	* config/mips/mips.h (MASK_NO_SCHED_PRO,
	TARGET_NO_SCHED_PRO): Define.
	(TARGET_SWITCHES): Add -msched-prolog and -mno-sched-prolog.

	* config/mips/mips.c (mips_expand_prologue): Don't allow
	prologue instructions to be scheduled if TARGET_NO_SCHED_PRO
	is set.

===================================================================
Index: invoke.texi
===================================================================
RCS file: /cvs/gcc/egcs/gcc/invoke.texi,v
retrieving revision 1.205
diff -c -r1.205 invoke.texi
*** invoke.texi	2000/07/25 20:17:28	1.205
--- invoke.texi	2000/08/01 00:26:22
***************
*** 361,366 ****
--- 361,367 ----
  -mstats  -EL  -EB  -G @var{num}  -nocpp
  -mabi=32 -mabi=n32 -mabi=64 -mabi=eabi
  -mfix7000 -mno-crt0
+ -msched-prolog -mno-sched-prolog
  
  @emph{i386 Options}
  -mcpu=@var{cpu type}
***************
*** 5915,5920 ****
--- 5916,5932 ----
  
  @item -no-crt0
  Do not include the default crt0.
+ 
+ @item -mno-sched-prolog
+ @kindex -mno-sched-prolog
+ @kindex -msched-prolog
+ Prevent the reordering of instructions in the function prolog, or the
+ merging of those instruction with the instructions in the function's
+ body.  This means that all functions will start with a recognizable set
+ of instructions (or in fact one of a choice from a small set of
+ different function prologues), and this information can be used to
+ locate the start if functions inside an executable piece of code.  The
+ default is @samp{-msched-prolog}.
  @end table
  
  @ifset INTERNALS
Index: config/mips/mips.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/mips/mips.c,v
retrieving revision 1.93
diff -c -r1.93 mips.c
*** mips.c	2000/07/17 13:27:54	1.93
--- mips.c	2000/08/01 00:26:25
***************
*** 7284,7293 ****
  			       gen_rtx_REG (DImode, 25)));
      }
  
!   /* If we are profiling, make sure no instructions are scheduled before
!      the call to mcount.  */
! 
!   if (profile_flag || profile_block_flag)
      emit_insn (gen_blockage ());
  }
  
--- 7284,7292 ----
  			       gen_rtx_REG (DImode, 25)));
      }
  
!   /* If we are profiling (or are explicitly told to do so), make sure no
!      instructions are scheduled before the call to mcount.  */
!   if (profile_flag || profile_block_flag || TARGET_NO_SCHED_PRO)
      emit_insn (gen_blockage ());
  }
  
Index: config/mips/mips.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/mips/mips.h,v
retrieving revision 1.100
diff -c -r1.100 mips.h
*** mips.h	2000/06/27 02:26:22	1.100
--- mips.h	2000/08/01 00:26:27
***************
*** 211,216 ****
--- 211,218 ----
  #define MASK_CHECK_RANGE_DIV 0x08000000	/* divide result range checking */
  #define MASK_UNINIT_CONST_IN_RODATA 0x10000000	/* Store uninitialized
  						   consts in rodata */
+ #define MASK_NO_SCHED_PRO 0x20000000		/* Protect prologue from
+ 						   scheduling */
  
  					/* Dummy switches used only in spec's*/
  #define MASK_MIPS_TFILE	0x00000000	/* flag for mips-tfile usage */
***************
*** 321,326 ****
--- 323,331 ----
  					/* Generate mips16 code */
  #define TARGET_MIPS16		(target_flags & MASK_MIPS16)
  
+ 					/* protect prologue from scheduling */
+ #define TARGET_NO_SCHED_PRO	(target_flags & MASK_NO_SCHED_PRO)
+ 
  /* Macro to define tables used to set the flags.
     This is a list in braces of pairs in braces,
     each pair being { "NAME", VALUE }
***************
*** 433,438 ****
--- 438,447 ----
       N_("Trap on integer divide overflow")},				\
    {"no-check-range-division",-MASK_CHECK_RANGE_DIV,			\
       N_("Don't trap on integer divide overflow")},			\
+   {"no-sched-prolog", MASK_NO_SCHED_PRO,				\
+      N_("Don't allow instructions to be moved into a function's prologue")}, \
+   {"sched-prolog", -MASK_NO_SCHED_PRO,					\
+      N_("Allow instructions to be moved into a function's prologue")},	\
    {"debug",		  MASK_DEBUG,					\
       NULL},								\
    {"debuga",		  MASK_DEBUG_A,					\



More information about the Gcc-patches mailing list