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]

MIPS PATCH: profiling fixes


This patch fixes some problems relating to profiling on MIPS, specifically for the mips*-sde-elf* target. Without this patch, profiling is pretty much completely busted due to lossage of $ra on the call to _mcount. The other two pieces of this patch are necessary for -mips16 support. I ran the gcc testsuite with -pg on after installing this patch, and found that it seems to fix everything except for one test that bangs on __builtin_return_address.

This patch obviously doesn't address the issue of library or gprof support. MTI's SDE libraries do support a real version of _mcount, but
I tested this in a newlib-based configuration with a dummy definition of _mcount added to keep the linker happy, which is sufficient for checking that the compiler is generating code that works.


-Sandra


2007-09-07 Sandra Loosemore <sandra@codesourcery.com> Nigel Stephens <nigel@mips.com> David Ung <davidu@mips.com>

        gcc/
        * config/mips/mips.c (mips_save_reg_p):  Save $ra when profiling
        since it's clobbered by the call to _mcount.
        * config/mips/mips.h (NO_PROFILE_COUNTERS): Define.
        (ASM_OUTPUT_REG_PUSH): Replace {d}subu with {d}addiu and a negative
        immediate such that it works with MIPS16 instructions.

Index: gcc/config/mips/mips.c
===================================================================
*** gcc/config/mips/mips.c	(revision 128207)
--- gcc/config/mips/mips.c	(working copy)
*************** mips_save_reg_p (unsigned int regno)
*** 6939,6944 ****
--- 6939,6948 ----
    if (regno == GP_REG_FIRST + 31 && df_regs_ever_live_p (regno))
      return true;
  
+   /* The return address will be clobbered when profiling.  */
+   if (regno == GP_REG_FIRST + 31 && current_function_profile)
+     return true;
+ 
    if (TARGET_MIPS16)
      {
        /* $18 is a special case in mips16 code.  It may be used to call
Index: gcc/config/mips/mips.h
===================================================================
*** gcc/config/mips/mips.h	(revision 128207)
--- gcc/config/mips/mips.h	(working copy)
*************** typedef struct mips_args {
*** 2092,2097 ****
--- 2092,2100 ----
  #define EXPAND_BUILTIN_VA_START(valist, nextarg) \
    mips_va_start (valist, nextarg)
  
+ /* Tell final.c that we don't need a label passed to mcount.  */
+ #define NO_PROFILE_COUNTERS 1
+ 
  /* Output assembler code to FILE to increment profiler label # LABELNO
     for profiling a function entry.  */
  
*************** do {									\
*** 2754,2761 ****
  #define ASM_OUTPUT_REG_PUSH(STREAM,REGNO)				\
  do									\
    {									\
!     fprintf (STREAM, "\t%s\t%s,%s,8\n\t%s\t%s,0(%s)\n",			\
! 	     TARGET_64BIT ? "dsubu" : "subu",				\
  	     reg_names[STACK_POINTER_REGNUM],				\
  	     reg_names[STACK_POINTER_REGNUM],				\
  	     TARGET_64BIT ? "sd" : "sw",				\
--- 2757,2764 ----
  #define ASM_OUTPUT_REG_PUSH(STREAM,REGNO)				\
  do									\
    {									\
!     fprintf (STREAM, "\t%s\t%s,%s,-8\n\t%s\t%s,0(%s)\n",		\
! 	     TARGET_64BIT ? "daddiu" : "addiu",				\
  	     reg_names[STACK_POINTER_REGNUM],				\
  	     reg_names[STACK_POINTER_REGNUM],				\
  	     TARGET_64BIT ? "sd" : "sw",				\

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