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]

SH PIC clean-ups


This patch simplifies immensely the handling of the PIC register on
the SH.  I've realized that, whenever we set
current_function_uses_pic_offset_table, we end up with
regs_ever_live[PIC_REG] set, except in cases in which the use of the
PIC register is eliminated.  Well, if all uses of the PIC register are
eliminated, we don't need to set it.

The only case in which we'd have
current_function_uses_pic_offset_table set without an explicit use of
the PIC register was in FINALIZE_PIC, that would set it if profiling
was enabled.  It turned out that profiling will perform function
calls, so we'll get the PIC register set anyway.  We don't need this
extraneous setting.

While I was at it, I've removed LEGITIMATE_PIC_OPERAND_P, that was not
used anywhere.  I recall it was used in the past, but it no longer is.

Since we can now reliably detect whether the PIC register is in use,
we don't need any special cases for PIC_REG in prologue/epilogue
sequences: if we don't set it as call_used, even if flag_pic, the
special handling of it can be eliminated, since calc_live_regs will do
The Right Thing (TM).

Tested on sh-elf, same variants as the call-site patch.  In fact, my
last round of tests had them both installed.  Ok to install?

Index: gcc/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* config/sh/sh.md (GOTaddr2picreg, symGOT2reg, symGOTOFF2reg,
	symPLT_label2reg, call, call_value): Don't set
	current_function_uses_pic_offset_table.
	* config/sh/sh.h (CONDITIONAL_REGISTER_USAGE): Don't mark
	PIC_OFFSET_TABLE_REGNUM as call_used, so that calc_live_regs
	takes it into account.
	(FINALIZE_PIC): Delete, useless.
	(LEGITIMATE_CONSTANT_P): Delete, unused.
	* config/sh/sh.c (sh_expand_prologue): Don't use
	current_function_uses_pic_offset_table.  Don't special-case
	PIC_OFFSET_TABLE_REGNUM.  Initialize it if it's ever live and
	PIC is enabled.
	(sh_expand_epilogue, initial_elimination_offset): Don't
	special case PIC_OFFSET_TABLE_REGNUM.

Index: gcc/config/sh/sh.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/sh/sh.c,v
retrieving revision 1.75
diff -u -p -r1.75 sh.c
--- gcc/config/sh/sh.c 2000/11/23 06:37:23 1.75
+++ gcc/config/sh/sh.c 2000/11/23 12:55:36
@@ -3956,29 +3956,11 @@ sh_expand_prologue ()
      that already happens to be at the function start into the prologue.  */
   if (target_flags != save_flags)
     emit_insn (gen_toggle_sz ());
-  if (flag_pic && (current_function_uses_pic_offset_table
-		   || regs_ever_live[PIC_OFFSET_TABLE_REGNUM]))
-    {
-      if ((live_regs_mask & (1 << PIC_OFFSET_TABLE_REGNUM)) != 0)
-	abort ();
-      d += UNITS_PER_WORD;
-      live_regs_mask |= (1 << PIC_OFFSET_TABLE_REGNUM);
-    }
+    
   push_regs (live_regs_mask, live_regs_mask2);
 
-  if (flag_pic && (current_function_uses_pic_offset_table
-		   || regs_ever_live[PIC_OFFSET_TABLE_REGNUM]))
-    {
-      rtx insn = get_last_insn ();
-      rtx insn_end = emit_insn (gen_GOTaddr2picreg ());
-      while (insn != insn_end)
-	{
-	  insn = NEXT_INSN (insn);
-	  REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
-						const0_rtx,
-						REG_NOTES (insn));
-	}
-    }
+  if (flag_pic && regs_ever_live[PIC_OFFSET_TABLE_REGNUM])
+    emit_insn (gen_GOTaddr2picreg ());
 
   if (target_flags != save_flags)
     emit_insn (gen_toggle_sz ());
@@ -4004,14 +3986,6 @@ sh_expand_epilogue ()
 
   live_regs_mask = calc_live_regs (&d, &live_regs_mask2);
 
-  if (flag_pic && current_function_uses_pic_offset_table)
-    {
-      if ((live_regs_mask & (1 << PIC_OFFSET_TABLE_REGNUM)) != 0)
-	abort ();
-      live_regs_mask |= (1 << PIC_OFFSET_TABLE_REGNUM);
-      d += UNITS_PER_WORD;
-    }
-
   frame_size = rounded_frame_size (d);
 
   if (frame_pointer_needed)
@@ -4442,11 +4416,6 @@ initial_elimination_offset (from, to)
 
   int live_regs_mask, live_regs_mask2;
   live_regs_mask = calc_live_regs (&regs_saved, &live_regs_mask2);
-  if (flag_pic && current_function_uses_pic_offset_table)
-    {
-      regs_saved++;
-      live_regs_mask |= (1 << PIC_OFFSET_TABLE_REGNUM);
-    }
   total_auto_space = rounded_frame_size (regs_saved);
   target_flags = save_flags;
 
Index: gcc/config/sh/sh.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/sh/sh.h,v
retrieving revision 1.84
diff -u -p -r1.84 sh.h
--- gcc/config/sh/sh.h 2000/11/23 06:37:23 1.84
+++ gcc/config/sh/sh.h 2000/11/23 12:55:38
@@ -81,10 +81,7 @@ extern int code_for_indirect_jump_scratc
 	}								\
     }									\
   if (flag_pic)								\
-    {									\
-      fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1;				\
-      call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1;			\
-    }									\
+    fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1;				\
   /* Hitachi saves and restores mac registers on call.  */		\
   if (TARGET_HITACHI && ! TARGET_NOMACSAVE)				\
     {									\
@@ -1763,16 +1760,6 @@ do									\
   }									\
 while (0)
 
-#define FINALIZE_PIC							\
-  current_function_uses_pic_offset_table |= profile_flag | profile_block_flag
-
-/* We can't directly access anything that contains a symbol,
-   nor can we indirect via the constant pool.  */
-#define LEGITIMATE_PIC_OPERAND_P(X)				\
-	(! nonpic_symbol_mentioned_p (X)			\
-	 && (! CONSTANT_POOL_ADDRESS_P (X)			\
-	     || ! nonpic_symbol_mentioned_p (get_pool_constant (X))))
-
 #define SYMBOLIC_CONST_P(X)	\
 ((GET_CODE (X) == SYMBOL_REF || GET_CODE (X) == LABEL_REF)	\
   && nonpic_symbol_mentioned_p (X))
Index: gcc/config/sh/sh.md
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/sh/sh.md,v
retrieving revision 1.59
diff -u -p -r1.59 sh.md
--- gcc/config/sh/sh.md 2000/11/23 06:37:23 1.59
+++ gcc/config/sh/sh.md 2000/11/23 12:55:41
@@ -3432,7 +3493,6 @@
       && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF)
     {
       emit_call_insn (gen_call_pcrel (XEXP (operands[0], 0), operands[1]));
-      current_function_uses_pic_offset_table = 1;
       DONE;
     }
   else
@@ -3459,7 +3513,6 @@
     {
       emit_call_insn (gen_call_value_pcrel (operands[0], XEXP (operands[1], 0),
 					    operands[2]));
-      current_function_uses_pic_offset_table = 1;
       DONE;
     }
   else
@@ -3588,7 +3635,6 @@
   "" "
 {
   operands[0] = pic_offset_table_rtx;
-  current_function_uses_pic_offset_table = 1;
   operands[1] = gen_rtx_SYMBOL_REF (VOIDmode, GOT_SYMBOL_NAME);
 }
 ")
@@ -3612,7 +3667,6 @@
   "
 {
   operands[2] = pic_offset_table_rtx;
-  current_function_uses_pic_offset_table = 1;
 }")
 
 (define_expand "symGOTOFF2reg"
@@ -3623,7 +3677,6 @@
   "
 {
   operands[2] = pic_offset_table_rtx;
-  current_function_uses_pic_offset_table = 1;
 }")
 
 (define_expand "symPLT_label2reg"
@@ -3633,25 +3686,22 @@
 			(unspec [(match_operand:SI 1 "" "")] UNSPEC_PLT)
 			(pc)))
 		(const (plus:SI
 			(match_operand:SI 2 "" "")
 			(const_int 2))))))
-   (use (match_dup 3))]
-  ;; Even though the PIC register is not really used by the call
-  ;; sequence in which this is expanded, the PLT code assumes the PIC
-  ;; register is set, so we must not skip its initialization.  Since
-  ;; we only use this expand as part of calling sequences, and never
-  ;; to take the address of a function, this is the best point to
-  ;; insert the (use).  Using the PLT to take the address of a
-  ;; function would be wrong, not only because the PLT entry could
-  ;; then be called from a function that doesn't initialize the PIC
-  ;; register to the proper GOT, but also because pointers to the same
-  ;; function might not compare equal, should they be set by different
-  ;; shared libraries.
-  "" "
-{
-  operands[3] = pic_offset_table_rtx;
-  current_function_uses_pic_offset_table = 1;
-}")
+   ;; Even though the PIC register is not really used by the call
+   ;; sequence in which this is expanded, the PLT code assumes the PIC
+   ;; register is set, so we must not skip its initialization.  Since
+   ;; we only use this expand as part of calling sequences, and never
+   ;; to take the address of a function, this is the best point to
+   ;; insert the (use).  Using the PLT to take the address of a
+   ;; function would be wrong, not only because the PLT entry could
+   ;; then be called from a function that doesn't initialize the PIC
+   ;; register to the proper GOT, but also because pointers to the
+   ;; same function might not compare equal, should they be set by
+   ;; different shared libraries.
+   (use (reg:SI PIC_REG))]
+  ""
+  "")
 
 ;; case instruction for switch statements.
 

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

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