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] tree-phinodes.c: Add a new function phi_reverse.


Hi,

Attached is a patch to add a new function phi_reverse.

Various places tries to reverse a PHI chain.  The patch merges those
into one place, phi_reverse.

Tested on i686-pc-linux-gnu.  OK to apply?

Kazu Hirata

2004-11-09  Kazu Hirata  <kazu@cs.umass.edu>

	* tree-phinodes.c (phi_reverse): New.
	* tree-cfg.c (tree_make_forwarder_block, tree_duplicate_bb):
	Use it.
	* tree-flow.h: Add a prototype for phi_reverse.

Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-cfg.c,v
retrieving revision 2.103
diff -u -d -p -r2.103 tree-cfg.c
--- tree-cfg.c	8 Nov 2004 22:41:40 -0000	2.103
+++ tree-cfg.c	8 Nov 2004 22:49:45 -0000
@@ -3655,7 +3655,7 @@ tree_make_forwarder_block (edge fallthru
   edge e;
   edge_iterator ei;
   basic_block dummy, bb;
-  tree phi, new_phi, var, prev, next;
+  tree phi, new_phi, var;
 
   dummy = fallthru->src;
   bb = fallthru->dest;
@@ -3675,14 +3675,7 @@ tree_make_forwarder_block (edge fallthru
     }
 
   /* Ensure that the PHI node chain is in the same order.  */
-  prev = NULL;
-  for (phi = phi_nodes (bb); phi; phi = next)
-    {
-      next = PHI_CHAIN (phi);
-      PHI_CHAIN (phi) = prev;
-      prev = phi;
-    }
-  set_phi_nodes (bb, prev);
+  set_phi_nodes (bb, phi_reverse (phi_nodes (bb)));
 
   /* Add the arguments we have stored on edges.  */
   FOR_EACH_EDGE (e, ei, bb->preds)
@@ -4281,7 +4274,7 @@ tree_duplicate_bb (basic_block bb)
       mark_for_rewrite (PHI_RESULT (phi));
       create_phi_node (PHI_RESULT (phi), new_bb);
     }
-  set_phi_nodes (new_bb, nreverse (phi_nodes (new_bb)));
+  set_phi_nodes (new_bb, phi_reverse (phi_nodes (new_bb)));
 
   bsi_tgt = bsi_start (new_bb);
   for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
Index: tree-flow.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-flow.h,v
retrieving revision 2.60
diff -u -d -p -r2.60 tree-flow.h
--- tree-flow.h	8 Nov 2004 22:34:18 -0000	2.60
+++ tree-flow.h	8 Nov 2004 22:49:45 -0000
@@ -516,6 +516,7 @@ extern void remove_phi_arg (tree, basic_
 extern void remove_phi_arg_num (tree, int);
 extern void remove_phi_node (tree, tree, basic_block);
 extern void remove_all_phi_nodes_for (bitmap);
+extern tree phi_reverse (tree);
 extern void dump_dfa_stats (FILE *);
 extern void debug_dfa_stats (void);
 extern void debug_referenced_vars (void);
Index: tree-phinodes.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-phinodes.c,v
retrieving revision 2.20
diff -u -d -p -r2.20 tree-phinodes.c
--- tree-phinodes.c	6 Nov 2004 15:14:11 -0000	2.20
+++ tree-phinodes.c	8 Nov 2004 22:49:45 -0000
@@ -491,6 +491,21 @@ remove_all_phi_nodes_for (bitmap vars)
     }
 }
 
+/* Reverse the order of PHI nodes in the chain PHI.
+   Return the new head of the chain (old last PHI node).  */
+
+tree
+phi_reverse (tree phi)
+{
+  tree prev = NULL_TREE, next;
+  for (; phi; phi = next)
+    {
+      next = PHI_CHAIN (phi);
+      PHI_CHAIN (phi) = prev;
+      prev = phi;
+    }
+  return prev;
+}
 
 #include "gt-tree-phinodes.h"
 


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