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, ARM] Allow profiling of nested functions on Thumb-1


Hi,

This patch fixes compiling code using nested functions with profiling
enabled for Thumb-1. The ASM_OUTPUT_REG_{PUSH,POP} macros try to push
STATIC_CHAIN_REGNUM, and Thumb-1 cannot do that directly. The problem
is solved (rather dirtily) by pushing r7 first, then using it as a
scratch register. (Those macros aren't used for anything non-profiling
related.)

Regtested with cross to ARM Linux. OK to apply?

Julian

ChangeLog

    gcc/
    * config/arm/arm.h (ASM_OUTPUT_REG_PUSH): Handle
    STATIC_CHAIN_REGNUM specially for Thumb-1.
    (ASM_OUTPUT_REG_POP): Likewise.
commit c484c85b01c4bc5484e02de8d52e7d1ec385e976
Author: Julian Brown <julian@verona.codesourcery.com>
Date:   Thu Oct 29 11:27:00 2009 -0700

    [ARM] Allow profiling of nested functions on Thumb-1

diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h
index 9272ca5..02d7703 100644
--- a/gcc/config/arm/arm.h
+++ b/gcc/config/arm/arm.h
@@ -2290,6 +2290,19 @@ extern int making_const_table;
       if (TARGET_ARM)					\
 	asm_fprintf (STREAM,"\tstmfd\t%r!,{%r}\n",	\
 		     STACK_POINTER_REGNUM, REGNO);	\
+      else if (TARGET_THUMB1				\
+	       && (REGNO) == STATIC_CHAIN_REGNUM)	\
+	{						\
+	  /* We can't push STATIC_CHAIN_REGNUM (r12) directly with Thumb-1.
+	     We know that ASM_OUTPUT_REG_PUSH will be matched with
+	     ASM_OUTPUT_REG_POP, and that r7 isn't used by the function
+	     profiler, so we can use it as a scratch reg.  WARNING: This isn't
+	     safe in the general case!  It may be sensitive to future changes
+	     in final.c:profile_function.  */		\
+	  asm_fprintf (STREAM, "\tpush\t{r7}\n");	\
+	  asm_fprintf (STREAM, "\tmov\tr7, %r\n", REGNO);\
+	  asm_fprintf (STREAM, "\tpush\t{r7}\n");	\
+	}						\
       else						\
 	asm_fprintf (STREAM, "\tpush {%r}\n", REGNO);	\
     } while (0)
@@ -2301,6 +2314,14 @@ extern int making_const_table;
       if (TARGET_ARM)					\
 	asm_fprintf (STREAM, "\tldmfd\t%r!,{%r}\n",	\
 		     STACK_POINTER_REGNUM, REGNO);	\
+      else if (TARGET_THUMB1				\
+	       && (REGNO) == STATIC_CHAIN_REGNUM)	\
+	{						\
+	  /* See comment in ASM_OUTPUT_REG_PUSH.  */	\
+	  asm_fprintf (STREAM, "\tpop\t{r7}\n");	\
+	  asm_fprintf (STREAM, "\tmov\t%r, r7\n", REGNO);\
+	  asm_fprintf (STREAM, "\tpop\t{r7}\n");	\
+	}						\
       else						\
 	asm_fprintf (STREAM, "\tpop {%r}\n", REGNO);	\
     } while (0)

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