powerpc64 profile option

Alan Modra amodra@bigpond.net.au
Mon Mar 17 23:40:00 GMT 2003


This patch elevates the kernel profiling option from a compile-time
hack (which seems to have bitrotted) to a proper -m option.

	* config/rs6000/linux64.h (MASK_PROFILE_KERNEL): Define.
	(TARGET_PROFILE_KERNEL): Define.
	(SUBTARGET_SWITCHES): Handle -mprofile-kernel.
	(PROFILE_BEFORE_PROLOGUE): Don't define.
	(PROFILE_KERNEL): Remove hacks.
	* config/rs6000/rs6000.c (TARGET_PROFILE_KERNEL): Define default.
	(rs6000_stack_info): No need to save lr if just for profiling when
	TARGET_KERNEL_PROFILE.
	(output_profile_hook): Output nothing when TARGET_KERNEL_PROFILE.
	(output_function_profiler): Localize label generation.  Emit code
	for kernel profiling.

OK mainline?

Index: gcc/config/rs6000/linux64.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/linux64.h,v
retrieving revision 1.34
diff -u -p -r1.34 linux64.h
--- gcc/config/rs6000/linux64.h	17 Mar 2003 03:47:16 -0000	1.34
+++ gcc/config/rs6000/linux64.h	17 Mar 2003 11:41:58 -0000
@@ -63,6 +63,15 @@ Boston, MA 02111-1307, USA.  */
 #undef	TARGET_PROTOTYPE
 #define	TARGET_PROTOTYPE	0
 
+/* Reuse sysv4 mask bits we made available above.  */
+#define	MASK_PROFILE_KERNEL	MASK_EABI
+
+/* Non-standard profiling for kernels, which just saves LR then calls
+   _mcount without worrying about arg saves.  The idea is to change
+   the function prologue as little as possible as it isn't easy to
+   account for arg save/restore code added just for _mcount.  */
+#define TARGET_PROFILE_KERNEL	(target_flags & MASK_PROFILE_KERNEL)
+
 /* Override sysv4.h.  */
 #undef	SUBTARGET_SWITCHES
 #define SUBTARGET_SWITCHES						\
@@ -89,7 +98,11 @@ Boston, MA 02111-1307, USA.  */
   {"regnames",		 MASK_REGNAMES,					\
     N_("Use alternate register names") },				\
   {"no-regnames",	-MASK_REGNAMES,					\
-    N_("Don't use alternate register names") },
+    N_("Don't use alternate register names") },				\
+  {"profile-kernel",	 MASK_PROFILE_KERNEL,				\
+   N_("Call mcount for profiling before a function prologue") },	\
+  {"no-profile-kernel",	-MASK_PROFILE_KERNEL,				\
+   N_("Call mcount for profiling after a function prologue") },
 
 #undef	SUBTARGET_OPTIONS
 #define	SUBTARGET_OPTIONS
@@ -99,19 +112,7 @@ Boston, MA 02111-1307, USA.  */
 
 /* We use glibc _mcount for profiling.  */
 #define NO_PROFILE_COUNTERS 1
-#undef  PROFILE_BEFORE_PROLOGUE
-
-/* Define this for kernel profiling, which just saves LR then calls
-   _mcount without worrying about arg saves.  The idea is to change
-   the function prologue as little as possible as it isn't easy to
-   account for arg save/restore code added just for _mcount.  */
-/* #define PROFILE_KERNEL 1 */
-#if PROFILE_KERNEL
-#define PROFILE_BEFORE_PROLOGUE 1
-#undef  PROFILE_HOOK
-#else
 #define PROFILE_HOOK(LABEL) output_profile_hook (LABEL)
-#endif
 
 /* We don't need to generate entries in .fixup.  */
 #undef RELOCATABLE_NEEDS_FIXUP
Index: gcc/config/rs6000/rs6000.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000.c,v
retrieving revision 1.442
diff -u -p -r1.442 rs6000.c
--- gcc/config/rs6000/rs6000.c	14 Mar 2003 22:58:43 -0000	1.442
+++ gcc/config/rs6000/rs6000.c	17 Mar 2003 12:19:00 -0000
@@ -335,6 +335,9 @@ static const char alt_reg_names[][8] =
 #ifndef MASK_STRICT_ALIGN
 #define MASK_STRICT_ALIGN 0
 #endif
+#ifndef TARGET_PROFILE_KERNEL
+#define TARGET_PROFILE_KERNEL 0
+#endif
 
 /* The VRSAVE bitmask puts bit %v0 as the most significant bit.  */
 #define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO))
@@ -9225,7 +9228,9 @@ rs6000_stack_info ()
 
   /* Determine if we need to save the link register.  */
   if (rs6000_ra_ever_killed ()
-      || (DEFAULT_ABI == ABI_AIX && current_function_profile)
+      || (DEFAULT_ABI == ABI_AIX
+	  && current_function_profile
+	  && !TARGET_PROFILE_KERNEL)
 #ifdef TARGET_RELOCATABLE
       || (TARGET_RELOCATABLE && (get_pool_size () != 0))
 #endif
@@ -12234,6 +12239,9 @@ void
 output_profile_hook (labelno)
      int labelno ATTRIBUTE_UNUSED;
 {
+  if (TARGET_PROFILE_KERNEL)
+    return;
+
   if (DEFAULT_ABI == ABI_AIX)
     {
 #ifdef NO_PROFILE_COUNTERS
@@ -12285,7 +12293,6 @@ output_function_profiler (file, labelno)
   char buf[100];
   int save_lr = 8;
 
-  ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
   switch (DEFAULT_ABI)
     {
     default:
@@ -12301,6 +12308,7 @@ output_function_profiler (file, labelno)
 	  warning ("no profiling of 64-bit code for this ABI");
 	  return;
 	}
+      ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
       fprintf (file, "\tmflr %s\n", reg_names[0]);
       if (flag_pic == 1)
 	{
@@ -12355,7 +12363,29 @@ output_function_profiler (file, labelno)
 
     case ABI_AIX:
     case ABI_DARWIN:
-      /* Don't do anything, done in output_profile_hook ().  */
+      if (!TARGET_PROFILE_KERNEL)
+	{
+	  /* Don't do anything, done in output_profile_hook (). */
+	}
+      else
+	{
+	  if (TARGET_32BIT)
+	    abort ();
+
+	  asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
+	  asm_fprintf (file, "\tstd %s,16(%s)\n", reg_names[0], reg_names[1]);
+
+	  if (current_function_needs_context)
+	    {
+	      asm_fprintf (file, "\tstd %s,24(%s)\n",
+			   reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
+	      fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
+	      asm_fprintf (file, "\tld %s,24(%s)\n",
+			   reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
+	    }
+	  else
+	    fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
+	}
       break;
     }
 }

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre



More information about the Gcc-patches mailing list