Patchwork [lra] patch from Richard Sandiford's review of lra-lives.c

login
register
mail settings
Submitter Vladimir Makarov
Date Oct. 10, 2012, 7:05 p.m.
Message ID <5075C6E5.8050100@redhat.com>
Download mbox | patch
Permalink /patch/190747/
State New
Headers show

Comments

Vladimir Makarov - Oct. 10, 2012, 7:05 p.m.
The following patch implements Richard's proposals from lra-lives.c review.

The patch was successfully bootstrapped and tested on x86/x86-64.

Committed as rev. 192326.

2012-10-10  Vladimir Makarov  <vmakarov@redhat.com>

         * lra-int.h (lra_live_range_in_p): Remove.
         * lra-lives.c (lra_copy_live_range_list): Simplify the code.
         (lra_merge_live_ranges): Remove unnecessary code.
         Add comments and assert.
         (lra_live_range_in_p): Remove.
         (make_hard_regno_dead): Move assert above.
Richard Sandiford - Oct. 10, 2012, 7:26 p.m.
Vladimir Makarov <vmakarov@redhat.com> writes:
> The following patch implements Richard's proposals from lra-lives.c review.
>
> The patch was successfully bootstrapped and tested on x86/x86-64.
>
> Committed as rev. 192326.
>
> 2012-10-10  Vladimir Makarov  <vmakarov@redhat.com>
>
>          * lra-int.h (lra_live_range_in_p): Remove.
>          * lra-lives.c (lra_copy_live_range_list): Simplify the code.
>          (lra_merge_live_ranges): Remove unnecessary code.
>          Add comments and assert.
>          (lra_live_range_in_p): Remove.
>          (make_hard_regno_dead): Move assert above.

Thanks, looks good.

Richard

Patch

Index: lra-int.h
===================================================================
--- lra-int.h	(revision 192264)
+++ lra-int.h	(working copy)
@@ -325,7 +325,6 @@  extern lra_live_range_t lra_merge_live_r
 					       lra_live_range_t);
 extern bool lra_intersected_live_ranges_p (lra_live_range_t,
 					   lra_live_range_t);
-extern bool lra_live_range_in_p (lra_live_range_t, lra_live_range_t);
 extern void lra_print_live_range_list (FILE *, lra_live_range_t);
 extern void lra_debug_live_range_list (lra_live_range_t);
 extern void lra_debug_pseudo_live_ranges (int);
Index: lra-lives.c
===================================================================
--- lra-lives.c	(revision 192183)
+++ lra-lives.c	(working copy)
@@ -147,25 +147,22 @@  copy_live_range (lra_live_range_t r)
 lra_live_range_t
 lra_copy_live_range_list (lra_live_range_t r)
 {
-  lra_live_range_t p, first, last;
+  lra_live_range_t p, first, *chain;
 
-  if (r == NULL)
-    return NULL;
-  for (first = last = NULL; r != NULL; r = r->next)
+  first = NULL;
+  for (chain = &first; r != NULL; r = r->next)
     {
       p = copy_live_range (r);
-      if (first == NULL)
-	first = p;
-      else
-	last->next = p;
-      last = p;
+      *chain = p;
+      chain = &p->next;
     }
   return first;
 }
 
-/* Merge ranges R1 and R2 and returns the result.  The function
-   maintains the order of ranges and tries to minimize size of the
-   result range list.  */
+/* Merge *non-intersected* ranges R1 and R2 and returns the result.
+   The function maintains the order of ranges and tries to minimize
+   size of the result range list.  Ranges R1 and R2 may not be used
+   after the call.  */
 lra_live_range_t 
 lra_merge_live_ranges (lra_live_range_t r1, lra_live_range_t r2)
 {
@@ -183,24 +180,17 @@  lra_merge_live_ranges (lra_live_range_t
 	  r1 = r2;
 	  r2 = temp;
 	}
-      if (r1->start <= r2->finish + 1)
+      if (r1->start == r2->finish + 1)
 	{
-	  /* Intersected ranges: merge r1 and r2 into r1.  */
+	  /* Joint ranges: merge r1 and r2 into r1.  */
 	  r1->start = r2->start;
-	  if (r1->finish < r2->finish)
-	    r1->finish = r2->finish;
 	  temp = r2;
 	  r2 = r2->next;
 	  pool_free (live_range_pool, temp);
-	  if (r2 == NULL)
-	    {
-	      /* To try to merge with subsequent ranges in r1.	*/
-	      r2 = r1->next;
-	      r1->next = NULL;
-	    }
 	}
       else
 	{
+	  gcc_assert (r2->finish + 1 < r1->start);
 	  /* Add r1 to the result.  */
 	  if (first == NULL)
 	    first = last = r1;
@@ -210,12 +200,6 @@  lra_merge_live_ranges (lra_live_range_t
 	      last = r1;
 	    }
 	  r1 = r1->next;
-	  if (r1 == NULL)
-	    {
-	      /* To try to merge with subsequent ranges in r2.	*/
-	      r1 = r2->next;
-	      r2->next = NULL;
-	    }
 	}
     }
   if (r1 != NULL)
@@ -224,19 +208,14 @@  lra_merge_live_ranges (lra_live_range_t
 	first = r1;
       else
 	last->next = r1;
-      lra_assert (r1->next == NULL);
     }
-  else if (r2 != NULL)
+  else
     {
+      lra_assert (r2 != NULL);
       if (first == NULL)
 	first = r2;
       else
 	last->next = r2;
-      lra_assert (r2->next == NULL);
-    }
-  else
-    {
-      lra_assert (last->next == NULL);
     }
   return first;
 }
@@ -258,30 +237,6 @@  lra_intersected_live_ranges_p (lra_live_
   return false;
 }
 
-/* Return TRUE if live range R1 is in R2.  */
-bool
-lra_live_range_in_p (lra_live_range_t r1, lra_live_range_t r2)
-{
-  /* Remember the live ranges are always kept ordered.	*/
-  while (r1 != NULL && r2 != NULL)
-    {
-      /* R1's element is in R2's element.  */
-      if (r2->start <= r1->start && r1->finish <= r2->finish)
-	r1 = r1->next;
-      /* Intersection: R1's start is in R2.  */
-      else if (r2->start <= r1->start && r1->start <= r2->finish)
-	return false;
-      /* Intersection: R1's finish is in R2.  */
-      else if (r2->start <= r1->finish && r1->finish <= r2->finish)
-	return false;
-      else if (r1->start > r2->finish)
-	return false; /* No covering R2's element for R1's one.	 */
-      else
-	r2 = r2->next;
-    }
-  return r1 == NULL;
-}
-
 /* The function processing birth of hard register REGNO.  It updates
    living hard regs, conflict hard regs for living pseudos, and
    START_LIVING.  */
@@ -305,10 +260,10 @@  make_hard_regno_born (int regno)
 static void
 make_hard_regno_dead (int regno)
 {
+  lra_assert (regno < FIRST_PSEUDO_REGISTER);
   if (TEST_HARD_REG_BIT (lra_no_alloc_regs, regno)
       || ! TEST_HARD_REG_BIT (hard_regs_live, regno))
     return;
-  lra_assert (regno < FIRST_PSEUDO_REGISTER);
   sparseset_set_bit (start_dying, regno);
   CLEAR_HARD_REG_BIT (hard_regs_live, regno);
 }