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] Fix -pg on PA for large executables/libs


The call_profiler pattern on pa is hardcoded to use b,l, which imposes a size
limitation on the size of executables/libraries that can be built with
profiling enabled. The following patch uses the generalized call pattern
to emit the call to _mcount to get rid of this limitation.

Bootstraped on hppa-linux with no regressions.

randolph
-- 
Randolph Chung
Debian GNU/Linux Developer, hppa/ia64 ports
http://www.tausq.org/


2003-11-25  Randolph Chung  <tausq@debian.org>
	    John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>

	* pa.c (hppa_profile_hook): Split gen_call_profiler into separate 
	insns to load the arguments and use the regular call pattern.
	* pa.md (call_profiler): Delete.
	(load_offset_label_address): New insn. Load function address for 
	profiler.
	(lcla1, lcla2): New insns. Output a code label and load its address.

Index: gcc/config/pa/pa.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/pa/pa.c,v
retrieving revision 1.232
diff -u -p -r1.232 pa.c
--- gcc/config/pa/pa.c	8 Nov 2003 20:36:27 -0000	1.232
+++ gcc/config/pa/pa.c	26 Nov 2003 05:46:24 -0000
@@ -4039,7 +4039,7 @@ hppa_pic_save_rtx (void)
 void
 hppa_profile_hook (int label_no)
 {
-  rtx begin_label_rtx, call_insn;
+  rtx begin_label_rtx, call_insn, reg, label_rtx;
   char begin_label_name[16];
 
   ASM_GENERATE_INTERNAL_LABEL (begin_label_name, FUNC_BEGIN_PROLOG_LABEL,
@@ -4053,6 +4053,17 @@ hppa_profile_hook (int label_no)
 
   emit_move_insn (gen_rtx_REG (word_mode, 26), gen_rtx_REG (word_mode, 2));
 
+  label_rtx = gen_label_rtx ();
+  reg = gen_reg_rtx (SImode);
+
+  if (TARGET_PA_20)
+    emit_insn (gen_lcla2 (reg, label_rtx));
+  else
+    emit_insn (gen_lcla1 (reg, label_rtx));
+
+  emit_insn (gen_load_offset_label_address (gen_rtx_REG (SImode, 25), 
+			                    reg, begin_label_rtx, label_rtx));
+
 #ifndef NO_PROFILE_COUNTERS
   {
     rtx count_label_rtx, addr, r24;
@@ -4065,21 +4076,24 @@ hppa_profile_hook (int label_no)
     r24 = gen_rtx_REG (Pmode, 24);
     emit_move_insn (r24, addr);
 
-    /* %r25 is set from within the output pattern.  */
     call_insn =
-      emit_call_insn (gen_call_profiler (gen_rtx_SYMBOL_REF (Pmode, "_mcount"),
-					 GEN_INT (TARGET_64BIT ? 24 : 12),
-					 begin_label_rtx));
+      emit_call_insn (gen_call (gen_rtx_SYMBOL_REF (Pmode, "_mcount"),
+			        GEN_INT (TARGET_64BIT ? 24 : 12)));
 
     use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), r24);
   }
 #else
-    /* %r25 is set from within the output pattern.  */
+
   call_insn =
-    emit_call_insn (gen_call_profiler (gen_rtx_SYMBOL_REF (Pmode, "_mcount"),
-				       GEN_INT (TARGET_64BIT ? 16 : 8),
-				       begin_label_rtx));
+    emit_call_insn (gen_call (gen_rtx_MEM (Pmode, 
+				           gen_rtx_SYMBOL_REF (Pmode, 
+						               "_mcount")),
+			      GEN_INT (TARGET_64BIT ? 16 : 8)));
+
 #endif
+
+  use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), gen_rtx_REG (SImode, 25));
+  use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), gen_rtx_REG (SImode, 26));
 
   /* Indicate the _mcount call cannot throw, nor will it execute a
      non-local goto.  */
Index: gcc/config/pa/pa.md
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/pa/pa.md,v
retrieving revision 1.134
diff -u -p -r1.134 pa.md
--- gcc/config/pa/pa.md	8 Nov 2003 20:36:29 -0000	1.134
+++ gcc/config/pa/pa.md	26 Nov 2003 05:46:27 -0000
@@ -6152,34 +6152,47 @@
   DONE;
 }")
 
-;; Special because we use the value placed in %r2 by the bl instruction
-;; from within its delay slot to set the value for the 2nd parameter to
-;; the call.
-(define_insn "call_profiler"
-  [(call (mem:SI (match_operand 0 "call_operand_address" ""))
-	 (match_operand 1 "" ""))
-   (use (match_operand 2 "" ""))
-   (use (reg:SI 25))
-   (use (reg:SI 26))
-   (clobber (reg:SI 2))]
+; Used by hppa_profile_hook to load the starting address of the current
+; function; operand 1 contains the address of the label in operand 3
+(define_insn "load_offset_label_address"
+  [(set (match_operand:SI 0 "register_operand" "=r")
+        (plus (match_operand:SI 1 "register_operand" "r")
+   	      (minus:SI (match_operand 2 "" "")
+	                (label_ref (match_operand 3 "" "")))))]
   ""
+  "ldo %2-%l3(%1),%0"
+  [(set_attr "type" "multi")
+   (set_attr "length" "4")])
+
+; Output a code label and load its address.
+(define_insn "lcla1"
+  [(set (match_operand:SI 0 "register_operand" "=r")
+        (label_ref (match_operand 1 "" "")))
+   (const_int 0)]
+  "!TARGET_PA_20"
   "*
 {
-  rtx xoperands[3];
-
-  output_arg_descriptor (insn);
-
-  xoperands[0] = operands[0];
-  xoperands[1] = operands[2];
-  xoperands[2] = gen_label_rtx ();
-  output_asm_insn (\"{bl|b,l} %0,%%r2\;ldo %1-%2(%%r2),%%r25\", xoperands);
-
+  output_asm_insn (\"bl .+8,%0\;depi 0,31,2,%0\", operands);
   (*targetm.asm_out.internal_label) (asm_out_file, \"L\",
-			     CODE_LABEL_NUMBER (xoperands[2]));
+                                     CODE_LABEL_NUMBER (operands[1]));
   return \"\";
 }"
   [(set_attr "type" "multi")
    (set_attr "length" "8")])
+
+(define_insn "lcla2"
+  [(set (match_operand:SI 0 "register_operand" "=r")
+        (label_ref (match_operand 1 "" "")))
+   (const_int 0)]
+  "TARGET_PA_20"
+  "*
+{
+  (*targetm.asm_out.internal_label) (asm_out_file, \"L\",
+                                     CODE_LABEL_NUMBER (operands[1]));
+  return \"mfia %0\";
+}"
+  [(set_attr "type" "move")
+   (set_attr "length" "4")])
 
 (define_insn "blockage"
   [(unspec_volatile [(const_int 2)] 0)]


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