diff mbox

Patch 3/9: create some more small helper functions

Message ID 4C1B7D5B.6060803@codesourcery.com
State New
Headers show

Commit Message

Bernd Schmidt June 18, 2010, 2:06 p.m. UTC
This is purely a cleanup patch that creates small helper functions for some
ugly if statements with side effects that occur in several places.  None of
the subsequent patches depend on this, but I think it's a useful cleanup.

	* ira-int.h (ira_parent_allocno, ira_parent_or_cap_allocno): Declare.
	* ira-build.c (ira_parent_allocno, ira_parent_or_cap_allocno): New
	functions.
	(ira_flattening): Use ira_parent_allocno.
	* ira-conflicts.c (process_regs_for_copy, propagate_copies)
	build_allocno_conflicts): Use ira_parent_or_cap_allocno.

(Index: gcc/ira-build.c

Comments

Jeff Law June 18, 2010, 7:07 p.m. UTC | #1
On 06/18/10 08:06, Bernd Schmidt wrote:
>     * ira-int.h (ira_parent_allocno, ira_parent_or_cap_allocno): Declare.
>     * ira-build.c (ira_parent_allocno, ira_parent_or_cap_allocno): New
>     functions.
>     (ira_flattening): Use ira_parent_allocno.
>     * ira-conflicts.c (process_regs_for_copy, propagate_copies)
>     build_allocno_conflicts): Use ira_parent_or_cap_allocno.
I agree the original code was rather confusing.  It wasn't trivial to 
verify that the code would work the same before/after your changes, 
primarily due to the convoluted way some of the original code was written.

Thanks.  Please install,

Jeff
diff mbox

Patch

===================================================================
--- gcc.orig/ira-build.c
+++ gcc/ira-build.c
@@ -2416,6 +2416,34 @@  create_caps (void)
    IR with one region.  */
 static ira_allocno_t *regno_top_level_allocno_map;
 
+/* Find the allocno that corresponds to A at a level one higher up in the
+   loop tree.  Returns NULL if A is a cap, or if it has no parent.  */
+ira_allocno_t
+ira_parent_allocno (ira_allocno_t a)
+{
+  ira_loop_tree_node_t parent;
+
+  if (ALLOCNO_CAP (a) != NULL)
+    return NULL;
+
+  parent = ALLOCNO_LOOP_TREE_NODE (a)->parent;
+  if (parent == NULL)
+    return NULL;
+
+  return parent->regno_allocno_map[ALLOCNO_REGNO (a)];
+}
+
+/* Find the allocno that corresponds to A at a level one higher up in the
+   loop tree.  If ALLOCNO_CAP is set for A, return that.  */
+ira_allocno_t
+ira_parent_or_cap_allocno (ira_allocno_t a)
+{
+  if (ALLOCNO_CAP (a) != NULL)
+    return ALLOCNO_CAP (a);
+
+  return ira_parent_allocno (a);
+}
+
 /* Process all allocnos originated from pseudo REGNO and copy live
    ranges, hard reg conflicts, and allocno stack reg attributes from
    low level allocnos to final allocnos which are destinations of
@@ -2478,7 +2506,7 @@  ira_flattening (int max_regno_before_emi
   enum reg_class cover_class;
   ira_allocno_t a, parent_a, first, second, node_first, node_second;
   ira_copy_t cp;
-  ira_loop_tree_node_t parent, node;
+  ira_loop_tree_node_t node;
   allocno_live_range_t r;
   ira_allocno_iterator ai;
   ira_copy_iterator ci;
@@ -2513,10 +2541,8 @@  ira_flattening (int max_regno_before_emi
 	  ira_assert (ALLOCNO_CAP_MEMBER (a) == NULL);
 	  if (ALLOCNO_SOMEWHERE_RENAMED_P (a))
 	    new_pseudos_p = true;
-	  if (ALLOCNO_CAP (a) != NULL
-	      || (parent = ALLOCNO_LOOP_TREE_NODE (a)->parent) == NULL
-	      || ((parent_a = parent->regno_allocno_map[ALLOCNO_REGNO (a)])
-		  == NULL))
+	  parent_a = ira_parent_allocno (a);
+	  if (parent_a == NULL)
 	    {
 	      ALLOCNO_COPIES (a) = NULL;
 	      regno_top_level_allocno_map[REGNO (ALLOCNO_REG (a))] = a;
@@ -2564,11 +2590,8 @@  ira_flattening (int max_regno_before_emi
 	      ALLOCNO_COVER_CLASS_COST (parent_a)
 		-= ALLOCNO_COVER_CLASS_COST (a);
 	      ALLOCNO_MEMORY_COST (parent_a) -= ALLOCNO_MEMORY_COST (a);
-	      if (ALLOCNO_CAP (parent_a) != NULL
-		  || (parent
-		      = ALLOCNO_LOOP_TREE_NODE (parent_a)->parent) == NULL
-		  || (parent_a = (parent->regno_allocno_map
-				  [ALLOCNO_REGNO (parent_a)])) == NULL)
+	      parent_a = ira_parent_allocno (parent_a);
+	      if (parent_a == NULL)
 		break;
 	    }
 	  ALLOCNO_COPIES (a) = NULL;
Index: gcc/ira-conflicts.c
===================================================================
--- gcc.orig/ira-conflicts.c
+++ gcc/ira-conflicts.c
@@ -346,7 +346,6 @@  process_regs_for_copy (rtx reg1, rtx reg
   enum reg_class rclass, cover_class;
   enum machine_mode mode;
   ira_copy_t cp;
-  ira_loop_tree_node_t parent;
 
   gcc_assert (REG_SUBREG_P (reg1) && REG_SUBREG_P (reg2));
   only_regs_p = REG_P (reg1) && REG_P (reg2);
@@ -397,7 +396,7 @@  process_regs_for_copy (rtx reg1, rtx reg
     cost = ira_get_register_move_cost (mode, cover_class, rclass) * freq;
   else
     cost = ira_get_register_move_cost (mode, rclass, cover_class) * freq;
-  for (;;)
+  do
     {
       ira_allocate_and_set_costs
 	(&ALLOCNO_HARD_REG_COSTS (a), cover_class,
@@ -408,12 +407,9 @@  process_regs_for_copy (rtx reg1, rtx reg
       ALLOCNO_CONFLICT_HARD_REG_COSTS (a)[index] -= cost;
       if (ALLOCNO_HARD_REG_COSTS (a)[index] < ALLOCNO_COVER_CLASS_COST (a))
 	ALLOCNO_COVER_CLASS_COST (a) = ALLOCNO_HARD_REG_COSTS (a)[index];
-      if (ALLOCNO_CAP (a) != NULL)
-	a = ALLOCNO_CAP (a);
-      else if ((parent = ALLOCNO_LOOP_TREE_NODE (a)->parent) == NULL
-	       || (a = parent->regno_allocno_map[ALLOCNO_REGNO (a)]) == NULL)
-	break;
+      a = ira_parent_or_cap_allocno (a);
     }
+  while (a != NULL);
   return true;
 }
 
@@ -533,7 +529,6 @@  propagate_copies (void)
   ira_copy_t cp;
   ira_copy_iterator ci;
   ira_allocno_t a1, a2, parent_a1, parent_a2;
-  ira_loop_tree_node_t parent;
 
   FOR_EACH_COPY (cp, ci)
     {
@@ -542,11 +537,8 @@  propagate_copies (void)
       if (ALLOCNO_LOOP_TREE_NODE (a1) == ira_loop_tree_root)
 	continue;
       ira_assert ((ALLOCNO_LOOP_TREE_NODE (a2) != ira_loop_tree_root));
-      parent = ALLOCNO_LOOP_TREE_NODE (a1)->parent;
-      if ((parent_a1 = ALLOCNO_CAP (a1)) == NULL)
-	parent_a1 = parent->regno_allocno_map[ALLOCNO_REGNO (a1)];
-      if ((parent_a2 = ALLOCNO_CAP (a2)) == NULL)
-	parent_a2 = parent->regno_allocno_map[ALLOCNO_REGNO (a2)];
+      parent_a1 = ira_parent_or_cap_allocno (a1);
+      parent_a2 = ira_parent_or_cap_allocno (a2);
       ira_assert (parent_a1 != NULL && parent_a2 != NULL);
       if (! CONFLICT_ALLOCNO_P (parent_a1, parent_a2))
 	ira_add_allocno_copy (parent_a1, parent_a2, cp->freq,
@@ -565,7 +557,6 @@  build_allocno_conflicts (ira_allocno_t a
 {
   int i, px, parent_num;
   int conflict_bit_vec_words_num;
-  ira_loop_tree_node_t parent;
   ira_allocno_t parent_a, another_a, another_parent_a;
   ira_allocno_t *vec;
   IRA_INT_TYPE *allocno_conflicts;
@@ -601,13 +592,9 @@  build_allocno_conflicts (ira_allocno_t a
       ALLOCNO_CONFLICT_ALLOCNO_ARRAY_SIZE (a)
 	= conflict_bit_vec_words_num * sizeof (IRA_INT_TYPE);
     }
-  parent = ALLOCNO_LOOP_TREE_NODE (a)->parent;
-  if ((parent_a = ALLOCNO_CAP (a)) == NULL
-      && (parent == NULL
-	  || (parent_a = parent->regno_allocno_map[ALLOCNO_REGNO (a)])
-	  == NULL))
+  parent_a = ira_parent_or_cap_allocno (a);
+  if (parent_a == NULL)
     return;
-  ira_assert (parent != NULL);
   ira_assert (ALLOCNO_COVER_CLASS (a) == ALLOCNO_COVER_CLASS (parent_a));
   parent_num = ALLOCNO_NUM (parent_a);
   FOR_EACH_ALLOCNO_IN_SET (allocno_conflicts,
@@ -616,9 +603,8 @@  build_allocno_conflicts (ira_allocno_t a
       another_a = ira_conflict_id_allocno_map[i];
       ira_assert (ira_reg_classes_intersect_p
 		  [ALLOCNO_COVER_CLASS (a)][ALLOCNO_COVER_CLASS (another_a)]);
-      if ((another_parent_a = ALLOCNO_CAP (another_a)) == NULL
-	  && (another_parent_a = (parent->regno_allocno_map
-				  [ALLOCNO_REGNO (another_a)])) == NULL)
+      another_parent_a = ira_parent_or_cap_allocno (another_a);
+      if (another_parent_a == NULL)
 	continue;
       ira_assert (ALLOCNO_NUM (another_parent_a) >= 0);
       ira_assert (ALLOCNO_COVER_CLASS (another_a)
Index: gcc/ira-int.h
===================================================================
--- gcc.orig/ira-int.h
+++ gcc/ira-int.h
@@ -838,6 +838,8 @@  extern void ira_debug_allocno_copies (ir
 extern void ira_traverse_loop_tree (bool, ira_loop_tree_node_t,
 				    void (*) (ira_loop_tree_node_t),
 				    void (*) (ira_loop_tree_node_t));
+extern ira_allocno_t ira_parent_allocno (ira_allocno_t);
+extern ira_allocno_t ira_parent_or_cap_allocno (ira_allocno_t);
 extern ira_allocno_t ira_create_allocno (int, bool, ira_loop_tree_node_t);
 extern void ira_set_allocno_cover_class (ira_allocno_t, enum reg_class);
 extern bool ira_conflict_vector_profitable_p (ira_allocno_t, int);