From 1ebfc6176442a3b0b3947dd04a8d218dbf067338 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Tue, 13 May 2014 17:26:56 -0400
Subject: [PATCH 10/29] Introduce gimple_phi and use it in various places

This corresponds to:
  "[PATCH 08/89] Introduce gimple_phi and use it in various places"
     http://gcc.gnu.org/ml/gcc-patches/2014-04/msg01211.html
from v1 of the patch series.

gcc/
	* coretypes.h (gphi): Add forward declaration.

	* gdbhooks.py (build_pretty_printer): Add "gphi *" and
	"const gphi *", using the gimple printer.

	* gimple.h (gimple_vec): Eliminate this typedef in the hope of using
	vecs of more concrete gimple subclasses as appropriate; also the
	comment is about to become misleading.

	* tree-phinodes.c (allocate_phi_node): Likewise.
	(resize_phi_node): Likewise.
	(reserve_phi_args_for_new_edge): Likewise.
	(remove_phi_arg_num): Likewise.

	* gimple-pretty-print.c (dump_gimple_phi): Require a gphi
	rather than just a gimple.
	* tree-into-ssa.c (mark_phi_for_rewrite): Likewise.

	* tree-phinodes.c (make_phi_node): Return a gphi rather than
	just a gimple.
	(create_phi_node): Likewise.
	* tree-phinodes.h (create_phi_node): Likewise.

	* trans-mem.c (struct struct tm_log_entry): Replace use of
	now-removed gimple_vec with a plain vec<gimple *>.

	* tree-into-ssa.c (phis_to_rewrite): Strengthen from a
	vec<gimple_vec> to a vec< vec<gphi *> >.

	* tree-into-ssa.c (insert_phi_nodes_for): Update local to be a
	gphi.
	* tree-into-ssa.c (rewrite_update_phi_arguments): Strengthen local
	"phis" from a gimple_vec to a vec<gphi *>, and local "phi" to
	a gphi.
	* tree-into-ssa.c (delete_update_ssa): Strengthen local
	"phis" from a gimple_vec to a vec<gphi *>.

	* gimple-pretty-print.c (pp_gimple_stmt_1): Add checked cast to
	gphi in regions where a stmt is known to have code
	GIMPLE_PHI.
	* tree-into-ssa.c (mark_use_interesting): Likewise.
---
 gcc/coretypes.h           |  1 +
 gcc/gdbhooks.py           |  3 ++-
 gcc/gimple-pretty-print.c |  6 +++---
 gcc/gimple.h              |  4 ----
 gcc/trans-mem.c           |  2 +-
 gcc/tree-into-ssa.c       | 16 ++++++++--------
 gcc/tree-phinodes.c       |  6 +++---
 gcc/tree-phinodes.h       |  2 +-
 8 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/gcc/coretypes.h b/gcc/coretypes.h
index 26fae44..09171d6 100644
--- a/gcc/coretypes.h
+++ b/gcc/coretypes.h
@@ -76,6 +76,7 @@ class glabel;
 class gswitch;
 class gassign;
 class gbind;
+class gphi;
 
 union section;
 typedef union section section;
diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py
index f3a3d97..76cc2ea 100644
--- a/gcc/gdbhooks.py
+++ b/gcc/gdbhooks.py
@@ -461,7 +461,8 @@ def build_pretty_printer():
                               'glabel *', 'const glabel *',
                               'gswitch *', 'const gswitch *',
                               'gassign *', 'const gassign *',
-                              'gbind *', 'const gbind *'],
+                              'gbind *', 'const gbind *',
+                              'gphi *', 'const gphi *'],
                              'gimple',
                              GimplePrinter)
     pp.add_printer_for_types(['basic_block', 'basic_block_def *'],
diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c
index 5183ea1..6e270a8 100644
--- a/gcc/gimple-pretty-print.c
+++ b/gcc/gimple-pretty-print.c
@@ -1785,7 +1785,7 @@ dump_ssaname_info (pretty_printer *buffer, tree node, int spc)
    pretty printer.  If COMMENT is true, print this after #.  */
 
 static void
-dump_gimple_phi (pretty_printer *buffer, gimple *phi, int spc, bool comment,
+dump_gimple_phi (pretty_printer *buffer, gphi *phi, int spc, bool comment,
 		 int flags)
 {
   size_t i;
@@ -2128,7 +2128,7 @@ pp_gimple_stmt_1 (pretty_printer *buffer, gimple *gs, int spc, int flags)
       break;
 
     case GIMPLE_PHI:
-      dump_gimple_phi (buffer, gs, spc, false, flags);
+      dump_gimple_phi (buffer, as_a <gphi *> (gs), spc, false, flags);
       break;
 
     case GIMPLE_OMP_PARALLEL:
@@ -2304,7 +2304,7 @@ dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
       if (!virtual_operand_p (gimple_phi_result (phi)) || (flags & TDF_VOPS))
         {
           INDENT (indent);
-	  dump_gimple_phi (buffer, phi, indent, true, flags);
+	  dump_gimple_phi (buffer, as_a <gphi *> (phi), indent, true, flags);
           pp_newline (buffer);
         }
     }
diff --git a/gcc/gimple.h b/gcc/gimple.h
index 5fd2cd9..5f36d09 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -24,10 +24,6 @@ along with GCC; see the file COPYING3.  If not see
 
 typedef gimple *gimple_seq_node;
 
-/* For each block, the PHI nodes that need to be rewritten are stored into
-   these vectors.  */
-typedef vec<gimple *> gimple_vec;
-
 enum gimple_code {
 #define DEFGSCODE(SYM, STRING, STRUCT)	SYM,
 #include "gimple.def"
diff --git a/gcc/trans-mem.c b/gcc/trans-mem.c
index 9128e7c..5521f9d 100644
--- a/gcc/trans-mem.c
+++ b/gcc/trans-mem.c
@@ -919,7 +919,7 @@ typedef struct tm_log_entry
   /* Entry block for the transaction this address occurs in.  */
   basic_block entry_block;
   /* Dominating statements the store occurs in.  */
-  gimple_vec stmts;
+  vec<gimple *> stmts;
   /* Initially, while we are building the log, we place a nonzero
      value here to mean that this address *will* be saved with a
      save/restore sequence.  Later, when generating the save sequence
diff --git a/gcc/tree-into-ssa.c b/gcc/tree-into-ssa.c
index cb1e6f4..cff9fbb 100644
--- a/gcc/tree-into-ssa.c
+++ b/gcc/tree-into-ssa.c
@@ -118,7 +118,7 @@ static bitmap names_to_release;
 /* vec of vec of PHIs to rewrite in a basic block.  Element I corresponds
    the to basic block with index I.  Allocated once per compilation, *not*
    released between different functions.  */
-static vec<gimple_vec> phis_to_rewrite;
+static vec< vec<gphi *> > phis_to_rewrite;
 
 /* The bitmap of non-NULL elements of PHIS_TO_REWRITE.  */
 static bitmap blocks_with_phis_to_rewrite;
@@ -949,9 +949,9 @@ find_def_blocks_for (tree var)
 /* Marks phi node PHI in basic block BB for rewrite.  */
 
 static void
-mark_phi_for_rewrite (basic_block bb, gimple *phi)
+mark_phi_for_rewrite (basic_block bb, gphi *phi)
 {
-  gimple_vec phis;
+  vec<gphi *> phis;
   unsigned n, idx = bb->index;
 
   if (rewrite_uses_p (phi))
@@ -990,7 +990,7 @@ insert_phi_nodes_for (tree var, bitmap phi_insertion_points, bool update_p)
 {
   unsigned bb_index;
   edge e;
-  gimple *phi;
+  gphi *phi;
   basic_block bb;
   bitmap_iterator bi;
   struct def_blocks_d *def_map = find_def_blocks_for (var);
@@ -1990,8 +1990,8 @@ rewrite_update_phi_arguments (basic_block bb)
 
   FOR_EACH_EDGE (e, ei, bb->succs)
     {
-      gimple *phi;
-      gimple_vec phis;
+      gphi *phi;
+      vec<gphi *> phis;
 
       if (!bitmap_bit_p (blocks_with_phis_to_rewrite, e->dest->index))
 	continue;
@@ -2451,7 +2451,7 @@ mark_use_interesting (tree var, gimple *stmt, basic_block bb, bool insert_phi_p)
   mark_block_for_update (bb);
 
   if (gimple_code (stmt) == GIMPLE_PHI)
-    mark_phi_for_rewrite (def_bb, stmt);
+    mark_phi_for_rewrite (def_bb, as_a <gphi *> (stmt));
   else
     {
       set_rewrite_uses (stmt, true);
@@ -2811,7 +2811,7 @@ delete_update_ssa (void)
   if (blocks_with_phis_to_rewrite)
     EXECUTE_IF_SET_IN_BITMAP (blocks_with_phis_to_rewrite, 0, i, bi)
       {
-	gimple_vec phis = phis_to_rewrite[i];
+	vec<gphi *> phis = phis_to_rewrite[i];
 	phis.release ();
 	phis_to_rewrite[i].create (0);
       }
diff --git a/gcc/tree-phinodes.c b/gcc/tree-phinodes.c
index c23e300..8c78110 100644
--- a/gcc/tree-phinodes.c
+++ b/gcc/tree-phinodes.c
@@ -171,7 +171,7 @@ ideal_phi_node_len (int len)
 
 /* Return a PHI node with LEN argument slots for variable VAR.  */
 
-static gimple *
+static gphi *
 make_phi_node (tree var, int len)
 {
   gphi *phi;
@@ -344,10 +344,10 @@ add_phi_node_to_bb (gimple *phi, basic_block bb)
 
 /* Create a new PHI node for variable VAR at basic block BB.  */
 
-gimple *
+gphi *
 create_phi_node (tree var, basic_block bb)
 {
-  gimple *phi = make_phi_node (var, EDGE_COUNT (bb->preds));
+  gphi *phi = make_phi_node (var, EDGE_COUNT (bb->preds));
 
   add_phi_node_to_bb (phi, bb);
   return phi;
diff --git a/gcc/tree-phinodes.h b/gcc/tree-phinodes.h
index b58a027..6f294aa 100644
--- a/gcc/tree-phinodes.h
+++ b/gcc/tree-phinodes.h
@@ -24,7 +24,7 @@ extern void phinodes_print_statistics (void);
 extern void release_phi_node (gimple *);
 extern void reserve_phi_args_for_new_edge (basic_block);
 extern void add_phi_node_to_bb (gimple *phi, basic_block bb);
-extern gimple *create_phi_node (tree, basic_block);
+extern gphi *create_phi_node (tree, basic_block);
 extern void add_phi_arg (gimple *, tree, edge, source_location);
 extern void remove_phi_args (edge);
 extern void remove_phi_node (gimple_stmt_iterator *, bool);
-- 
1.8.5.3

