[committed] Defer emission of profile counters on PA

John David Anglin dave@hiauly1.hia.nrc.ca
Mon Oct 24 17:04:00 GMT 2005


The enclosed patch fixes a problem that I noticed working on DWARF2
EH support for hppa2.0w-hp-hpux11.11.  Profile counters were being
emitted after the text of a function had started.  This effectively
caused a function to be split into two subspaces (sections).  This
could cause a variety problems (e.g., stubs in a function).  It also
makes it impossible to do label differences when using GAS.

Tested on hppa2.0w-hp-hpux11.11 and committed to trunk.

Dave
-- 
J. David Anglin                                  dave.anglin@nrc-cnrc.gc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6602)

2005-10-24  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>

	* pa-linux.h (NO_PROFILE_COUNTERS): Delete define.
	(NO_DEFERRED_PROFILE_COUNTERS): Define.
	* pa.h (NO_PROFILE_COUNTERS): Define.
	* pa.c (NO_DEFERRED_PROFILE_COUNTERS): Define if not defined.
	(funcdef_nos): New vector to hold label numbers of deferred profile
	counters.
	(output_deferred_profile_counters): New function.
	(hppa_profile_hook): Push label number onto funcdef_nos.
	(pa_hpux_file_end): Call output_deferred_profile_counters if
	NO_DEFERRED_PROFILE_COUNTERS is false.

Index: config/pa/pa-linux.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/pa/pa-linux.h,v
retrieving revision 1.39
diff -u -3 -p -r1.39 pa-linux.h
--- config/pa/pa-linux.h	25 Jun 2005 01:21:52 -0000	1.39
+++ config/pa/pa-linux.h	24 Oct 2005 14:43:44 -0000
@@ -92,7 +59,7 @@ Boston, MA 02110-1301, USA.  */
       %{static:-static}}"
 
 /* glibc's profiling functions don't need gcc to allocate counters.  */
-#define NO_PROFILE_COUNTERS 1
+#define NO_DEFERRED_PROFILE_COUNTERS 1
 
 /* Define the strings used for the special svr4 .type and .size directives.
    These strings generally do not vary from one system running svr4 to
Index: config/pa/pa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/pa/pa.c,v
retrieving revision 1.309
diff -u -3 -p -r1.309 pa.c
--- config/pa/pa.c	24 Oct 2005 02:38:25 -0000	1.309
+++ config/pa/pa.c	24 Oct 2005 14:43:49 -0000
@@ -137,6 +137,7 @@ static void pa_linux_file_start (void) A
 static void pa_hpux64_gas_file_start (void) ATTRIBUTE_UNUSED;
 static void pa_hpux64_hpas_file_start (void) ATTRIBUTE_UNUSED;
 static void output_deferred_plabels (void);
+static void output_deferred_profile_counters (void) ATTRIBUTE_UNUSED;
 #ifdef ASM_OUTPUT_EXTERNAL_REAL
 static void pa_hpux_file_end (void);
 #endif
@@ -4141,6 +4116,40 @@ hppa_pic_save_rtx (void)
   return get_hard_reg_initial_val (word_mode, PIC_OFFSET_TABLE_REGNUM);
 }
 
+#ifndef NO_DEFERRED_PROFILE_COUNTERS
+#define NO_DEFERRED_PROFILE_COUNTERS 0
+#endif
+
+/* Define heap vector type for funcdef numbers.  */
+DEF_VEC_I(int);
+DEF_VEC_ALLOC_I(int,heap);
+
+/* Vector of funcdef numbers.  */
+static VEC(int,heap) *funcdef_nos;
+
+/* Output deferred profile counters.  */
+static void
+output_deferred_profile_counters (void)
+{
+  unsigned int i;
+  int align, n;
+
+  if (VEC_empty (int, funcdef_nos))
+   return;
+
+  data_section ();
+  align = MIN (BIGGEST_ALIGNMENT, LONG_TYPE_SIZE);
+  ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
+
+  for (i = 0; VEC_iterate (int, funcdef_nos, i, n); i++)
+    {
+      targetm.asm_out.internal_label (asm_out_file, "LP", n);
+      assemble_integer (const0_rtx, LONG_TYPE_SIZE / BITS_PER_UNIT, align, 1);
+    }
+
+  VEC_free (int, heap, funcdef_nos);
+}
+
 void
 hppa_profile_hook (int label_no)
 {
@@ -4175,11 +4184,12 @@ hppa_profile_hook (int label_no)
   emit_insn (gen_load_offset_label_address (gen_rtx_REG (SImode, 25), 
 					    reg, begin_label_rtx, label_rtx));
 
-#ifndef NO_PROFILE_COUNTERS
+#if !NO_DEFERRED_PROFILE_COUNTERS
   {
     rtx count_label_rtx, addr, r24;
     char count_label_name[16];
 
+    VEC_safe_push (int, heap, funcdef_nos, label_no);
     ASM_GENERATE_INTERNAL_LABEL (count_label_name, "LP", label_no);
     count_label_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (count_label_name));
 
@@ -9158,6 +9168,9 @@ pa_hpux_file_end (void)
   unsigned int i;
   extern_symbol *p;
 
+  if (!NO_DEFERRED_PROFILE_COUNTERS)
+    output_deferred_profile_counters ();
+
   output_deferred_plabels ();
 
   for (i = 0; VEC_iterate (extern_symbol, extern_symbols, i, p); i++)
Index: config/pa/pa.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/pa/pa.h,v
retrieving revision 1.252
diff -u -3 -p -r1.252 pa.h
--- config/pa/pa.h	6 Aug 2005 13:26:14 -0000	1.252
+++ config/pa/pa.h	24 Oct 2005 14:43:49 -0000
@@ -769,6 +812,11 @@ void hppa_profile_hook (int label_no);
 /* The profile counter if emitted must come before the prologue.  */
 #define PROFILE_BEFORE_PROLOGUE 1
 
+/* We never want final.c to emit profile counters.  When profile
+   counters are required, we have to defer emitting them to the end
+   of the current file.  */
+#define NO_PROFILE_COUNTERS 1
+
 /* EXIT_IGNORE_STACK should be nonzero if, when returning from a function,
    the stack pointer does not matter.  The value is tested only in
    functions that have frame pointers.



More information about the Gcc-patches mailing list