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]

Dead and duplicated code in register elimination


The patch below cleans up the register elimination code a bit more.  Since
the caller-save code no longer calls eliminate_regs, we do not use the
max_offset value anymore, so the code to compute it can go away.
Also, there is code in set_initial_elim_offsets and in reload_as_needed
which is identical except that the code in reload_as_needed assumes that
when ELIMINABLE_REGS isn't defined, INITIAL_FRAME_POINTER_OFFSET must be
defined.  I've changed the code in set_initial_elim_offsets to assume this
as well, and reload_as_needed to call it.

I'd like to move the whole register elimination code into a separate file,
and add some functionality that can be used from flow.c/global.c/local-alloc.c
as well as any other places that need it.  Should I send a patch for this?

Bernd

	* reload1.c (struct elim_table): Delete MAX_OFFSET member.
	(update_eliminable_offsets): Don't compute it.
	(set_initial_elim_offsets): Don't initialize it.
	Break out some code into set_initial_label_offsets so the rest of
	this function can be called from reload_as_needed.
	Assume that INITIAL_FRAME_POINTER_OFFSET is defeined when
	ELIMINABLE_REGS isn't.
	(set_initial_label_offsets): New function, broken out of
	set_initial_elim_offsets.
	(set_offsets_for_label): New function, broken out of set_label_offsets
	and reload_as_needed.
	(reload): Call the two new functions.
	(reload_as_needed): Call set_initial_elim_offsets instead of
	duplicating the code.  Likewise for set_offsets_for_label.

Index: reload1.c
===================================================================
RCS file: /usr/local/cvs/gcs/gcc/reload1.c,v
retrieving revision 1.1.1.51
diff -u -p -r1.1.1.51 reload1.c
--- reload1.c	1998/10/23 15:17:24	1.1.1.51
+++ reload1.c	1998/10/25 10:22:01
@@ -316,7 +316,6 @@ static struct elim_table
   int can_eliminate_previous;	/* Value of CAN_ELIMINATE in previous scan over
 				   insns made by reload.  */
   int offset;			/* Current offset between the two regs.  */
-  int max_offset;		/* Maximum offset between the two regs.  */
   int previous_offset;		/* Offset at end of previous insn.  */
   int ref_outside_mem;		/* "to" has been referenced outside a MEM.  */
   rtx from_rtx;			/* REG rtx for the register to be eliminated.
@@ -387,6 +386,8 @@ static int eliminate_regs_in_insn	PROTO(
 static void update_eliminable_offsets	PROTO((void));
 static void mark_not_eliminable		PROTO((rtx, rtx));
 static void set_initial_elim_offsets	PROTO((void));
+static void set_initial_label_offsets	PROTO((void));
+static void set_offsets_for_label	PROTO((rtx));
 static void init_elim_table		PROTO((void));
 static void update_eliminables		PROTO((HARD_REG_SET *));
 static int spill_hard_reg		PROTO((int, int, FILE *, int));
@@ -957,7 +958,8 @@ reload (first, global, dumpfile)
       starting_frame_size = get_frame_size ();
 
       set_initial_elim_offsets ();
-      
+      set_initial_label_offsets ();
+
       /* For each pseudo register that has an equivalent location defined,
 	 try to eliminate any eliminable registers (such as the frame pointer)
 	 assuming initial offsets for the replacement register, which
@@ -2761,19 +2763,7 @@ set_label_offsets (x, insn, initial_p)
       else if (x == insn
 	       && (tem = prev_nonnote_insn (insn)) != 0
 	       && GET_CODE (tem) == BARRIER)
-	{
-	  num_not_at_initial_offset = 0;
-	  for (i = 0; i < NUM_ELIMINABLE_REGS; i++)
-	    {
-	      reg_eliminate[i].offset = reg_eliminate[i].previous_offset
-		= offsets_at[CODE_LABEL_NUMBER (x)][i];
-	      if (reg_eliminate[i].can_eliminate
-		  && (reg_eliminate[i].offset
-		      != reg_eliminate[i].initial_offset))
-		num_not_at_initial_offset++;
-	    }
-	}
-
+	set_offsets_for_label (insn);
       else
 	/* If neither of the above cases is true, compare each offset
 	   with those previously recorded and suppress any eliminations
@@ -3693,12 +3683,6 @@ update_eliminable_offsets ()
       ep->previous_offset = ep->offset;
       if (ep->can_eliminate && ep->offset != ep->initial_offset)
 	num_not_at_initial_offset++;
-
-#ifdef STACK_GROWS_DOWNWARD
-      ep->max_offset = MAX (ep->max_offset, ep->offset);
-#else
-      ep->max_offset = MIN (ep->max_offset, ep->offset);
-#endif
     }
 }
 
@@ -3749,43 +3733,59 @@ mark_not_eliminable (dest, x)
 static void
 set_initial_elim_offsets ()
 {
-  rtx x;
+  struct elim_table *ep = reg_eliminate;
 
 #ifdef ELIMINABLE_REGS
-  struct elim_table *ep;
-
-  for (ep = reg_eliminate; ep < &reg_eliminate[NUM_ELIMINABLE_REGS]; ep++)
+  for (; ep < &reg_eliminate[NUM_ELIMINABLE_REGS]; ep++)
     {
       INITIAL_ELIMINATION_OFFSET (ep->from, ep->to, ep->initial_offset);
-      ep->previous_offset = ep->offset
-	= ep->max_offset = ep->initial_offset;
+      ep->previous_offset = ep->offset = ep->initial_offset;
     }
-#else
-#ifdef INITIAL_FRAME_POINTER_OFFSET
-  INITIAL_FRAME_POINTER_OFFSET (reg_eliminate[0].initial_offset);
 #else
-  if (!FRAME_POINTER_REQUIRED)
-    abort ();
-  reg_eliminate[0].initial_offset = 0;
+  INITIAL_FRAME_POINTER_OFFSET (ep->initial_offset);
+  ep->previous_offset = ep->offset = ep->initial_offset;
 #endif
-  reg_eliminate[0].previous_offset = reg_eliminate[0].max_offset
-    = reg_eliminate[0].offset = reg_eliminate[0].initial_offset;
-#endif
 
   num_not_at_initial_offset = 0;
+}
 
-  bzero ((char *) &offsets_known_at[get_first_label_num ()], num_labels);
+/* Initialize the known label offsets.
+   Set a known offset for each forced label to be at the initial offset
+   of each elimination.  We do this because we assume that all
+   computed jumps occur from a location where each elimination is
+   at its initial offset.
+   For all other labels, show that we don't know the offsets.  */
 
-  /* Set a known offset for each forced label to be at the initial offset
-     of each elimination.  We do this because we assume that all
-     computed jumps occur from a location where each elimination is
-     at its initial offset.  */
+static void
+set_initial_label_offsets ()
+{
+  rtx x;
+  bzero ((char *) &offsets_known_at[get_first_label_num ()], num_labels);
 
   for (x = forced_labels; x; x = XEXP (x, 1))
     if (XEXP (x, 0))
       set_label_offsets (XEXP (x, 0), NULL_RTX, 1);
 }
 
+/* Set all elimination offsets to the known values for the code label given
+   by INSN.  */
+static void
+set_offsets_for_label (insn)
+     rtx insn;
+{
+  int i;
+  int label_nr = CODE_LABEL_NUMBER (insn);
+  struct elim_table *ep;
+
+  num_not_at_initial_offset = 0;
+  for (i = 0, ep = reg_eliminate; i < NUM_ELIMINABLE_REGS; ep++, i++)
+    {
+      ep->offset = ep->previous_offset = offsets_at[label_nr][i];
+      if (ep->can_eliminate && ep->offset != ep->initial_offset)
+	num_not_at_initial_offset++;
+    }
+}
+
 /* See if anything that happened changes which eliminations are valid.
    For example, on the Sparc, whether or not the frame pointer can
    be eliminated can depend on what registers have been used.  We need
@@ -4236,23 +4236,8 @@ reload_as_needed (live_known)
   bzero ((char *) reg_last_reload_reg, max_regno * sizeof (rtx));
   reg_has_output_reload = (char *) alloca (max_regno);
   CLEAR_HARD_REG_SET (reg_reloaded_valid);
-
-  /* Reset all offsets on eliminable registers to their initial values.  */
-#ifdef ELIMINABLE_REGS
-  for (i = 0; i < (int) NUM_ELIMINABLE_REGS; i++)
-    {
-      INITIAL_ELIMINATION_OFFSET (reg_eliminate[i].from, reg_eliminate[i].to,
-				  reg_eliminate[i].initial_offset);
-      reg_eliminate[i].previous_offset
-	= reg_eliminate[i].offset = reg_eliminate[i].initial_offset;
-    }
-#else
-  INITIAL_FRAME_POINTER_OFFSET (reg_eliminate[0].initial_offset);
-  reg_eliminate[0].previous_offset
-    = reg_eliminate[0].offset = reg_eliminate[0].initial_offset;
-#endif
 
-  num_not_at_initial_offset = 0;
+  set_initial_elim_offsets ();
 
   /* Order the spilled regs, so that allocate_reload_regs can guarantee to
      pack registers with group needs.  */
@@ -4272,18 +4257,7 @@ reload_as_needed (live_known)
       /* If we pass a label, copy the offsets from the label information
 	 into the current offsets of each elimination.  */
       if (GET_CODE (insn) == CODE_LABEL)
-	{
-	  num_not_at_initial_offset = 0;
-	  for (i = 0; i < (int) NUM_ELIMINABLE_REGS; i++)
-	    {
-	      reg_eliminate[i].offset = reg_eliminate[i].previous_offset
-		= offsets_at[CODE_LABEL_NUMBER (insn)][i];
-	      if (reg_eliminate[i].can_eliminate
-		  && (reg_eliminate[i].offset
-		      != reg_eliminate[i].initial_offset))
-		num_not_at_initial_offset++;
-	    }
-	}
+	set_offsets_for_label (insn);
 
       else if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
 	{



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