diff mbox

[gimple-classes,committed,07/92] Introduce gimple_phi and use it in various places

Message ID 1414442490-14841-8-git-send-email-dmalcolm@redhat.com
State New
Headers show

Commit Message

David Malcolm Oct. 27, 2014, 8:40 p.m. UTC
This corresponds to:
  [PATCH 08/89] Introduce gimple_phi and use it in various places
  https://gcc.gnu.org/ml/gcc-patches/2014-04/msg01211.html
from the original 89-patch kit

That earlier patch was approved by Jeff:
> Same as prior patches in this set. Just get the const/renaming stuff
> addressed and it's good to go.
in https://gcc.gnu.org/ml/gcc-patches/2014-05/msg00618.html

gcc/
	* coretypes.h (gimple_phi): New typedef.
	(const_gimple_phi): New typedef.

	* gdbhooks.py (build_pretty_printer): Add gimple_phi and its
	variants, using the gimple printer.

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

	* gimple.h (gimple_phi_capacity): Use const_gimple_phi typedef
	rather than spelling out the full type.
	(gimple_phi_num_args): Likewise.
	(gimple_phi_result): Likewise.
	(gimple_phi_result_ptr): Use gimple_phi typedef.
	(gimple_phi_set_result): Likewise.
	(gimple_phi_arg): Likewise.
	(gimple_phi_set_arg): Likewise.
	* 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 gimple_phi
	rather than just a gimple.
	* tree-into-ssa.c (mark_phi_for_rewrite): Likewise.

	* tree-phinodes.c (make_phi_node): Return a gimple_phi 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<gimple_phi> >.

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

	* gimple-pretty-print.c (pp_gimple_stmt_1): Add checked cast to
	gimple_phi in regions where a stmt is known to have code
	GIMPLE_PHI.
	* tree-into-ssa.c (mark_use_interesting): Likewise.
---
 gcc/ChangeLog.gimple-classes | 55 ++++++++++++++++++++++++++++++++++++++++++++
 gcc/coretypes.h              |  4 ++++
 gcc/gdbhooks.py              |  4 +++-
 gcc/gimple-pretty-print.c    |  6 ++---
 gcc/gimple.h                 | 24 ++++++++-----------
 gcc/trans-mem.c              |  2 +-
 gcc/tree-into-ssa.c          | 16 ++++++-------
 gcc/tree-phinodes.c          | 28 +++++++++++-----------
 gcc/tree-phinodes.h          |  2 +-
 9 files changed, 98 insertions(+), 43 deletions(-)
diff mbox

Patch

diff --git a/gcc/ChangeLog.gimple-classes b/gcc/ChangeLog.gimple-classes
index ec16551..7c2b168 100644
--- a/gcc/ChangeLog.gimple-classes
+++ b/gcc/ChangeLog.gimple-classes
@@ -1,5 +1,60 @@ 
 2014-10-24  David Malcolm  <dmalcolm@redhat.com>
 
+	Introduce gimple_phi and use it in various places
+
+	* coretypes.h (gimple_phi): New typedef.
+	(const_gimple_phi): New typedef.
+
+	* gdbhooks.py (build_pretty_printer): Add gimple_phi and its
+	variants, using the gimple printer.
+
+	* gimple.h (gimple_vec): Eliminate thie typedef in the hope of using
+	vecs of more concrete gimple subclasses as appropriate; also the
+	comment is about to become misleading.
+
+	* gimple.h (gimple_phi_capacity): Use const_gimple_phi typedef
+	rather than spelling out the full type.
+	(gimple_phi_num_args): Likewise.
+	(gimple_phi_result): Likewise.
+	(gimple_phi_result_ptr): Use gimple_phi typedef.
+	(gimple_phi_set_result): Likewise.
+	(gimple_phi_arg): Likewise.
+	(gimple_phi_set_arg): Likewise.
+	* 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 gimple_phi
+	rather than just a gimple.
+	* tree-into-ssa.c (mark_phi_for_rewrite): Likewise.
+
+	* tree-phinodes.c (make_phi_node): Return a gimple_phi 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<gimple_phi> >.
+
+	* tree-into-ssa.c (insert_phi_nodes_for): Update local to be a
+	gimple_phi.
+	* tree-into-ssa.c (rewrite_update_phi_arguments): Strengthen local
+	"phis" from a gimple_vec to a vec<gimple_phi>, and local "phi" to
+	a gimple_phi.
+	* tree-into-ssa.c (delete_update_ssa): Strengthen local
+	"phis" from a gimple_vec to a vec<gimple_phi>.
+
+	* gimple-pretty-print.c (pp_gimple_stmt_1): Add checked cast to
+	gimple_phi in regions where a stmt is known to have code
+	GIMPLE_PHI.
+	* tree-into-ssa.c (mark_use_interesting): Likewise.
+
+2014-10-24  David Malcolm  <dmalcolm@redhat.com>
+
 	Introduce gimple_debug and use it in a few places
 
 	* coretypes.h (gimple_debug): New typedef.
diff --git a/gcc/coretypes.h b/gcc/coretypes.h
index a338599..9b5a007 100644
--- a/gcc/coretypes.h
+++ b/gcc/coretypes.h
@@ -114,6 +114,10 @@  struct gimple_statement_bind;
 typedef struct gimple_statement_bind *gimple_bind;
 typedef const struct gimple_statement_bind *const_gimple_bind;
 
+struct gimple_statement_phi;
+typedef struct gimple_statement_phi *gimple_phi;
+typedef const struct gimple_statement_phi *const_gimple_phi;
+
 union section;
 typedef union section section;
 struct gcc_options;
diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py
index 455fa5c..a74e712 100644
--- a/gcc/gdbhooks.py
+++ b/gcc/gdbhooks.py
@@ -469,7 +469,9 @@  def build_pretty_printer():
                               'gimple_assign', 'const_gimple_assign',
                               'gimple_statement_assign *',
                               'gimple_bind', 'const_gimple_bind',
-                              'gimple_statement_bind *'],
+                              'gimple_statement_bind *',
+                              'gimple_phi', 'const_gimple_phi',
+                              'gimple_statement_phi *'],
 
                              'gimple',
                              GimplePrinter)
diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c
index 4ab8673..51754c3 100644
--- a/gcc/gimple-pretty-print.c
+++ b/gcc/gimple-pretty-print.c
@@ -1812,7 +1812,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, gimple_phi phi, int spc, bool comment,
 		 int flags)
 {
   size_t i;
@@ -2129,7 +2129,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 <gimple_phi> (gs), spc, false, flags);
       break;
 
     case GIMPLE_OMP_PARALLEL:
@@ -2305,7 +2305,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 <gimple_phi> (phi), indent, true, flags);
           pp_newline (buffer);
         }
     }
diff --git a/gcc/gimple.h b/gcc/gimple.h
index 8e5b42a..de0fae4 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"
@@ -3888,8 +3884,8 @@  gimple_wce_set_cleanup_eh_only (gimple gs, bool eh_only_p)
 static inline unsigned
 gimple_phi_capacity (const_gimple gs)
 {
-  const gimple_statement_phi *phi_stmt =
-    as_a <const gimple_statement_phi *> (gs);
+  const_gimple_phi phi_stmt =
+    as_a <const_gimple_phi> (gs);
   return phi_stmt->capacity;
 }
 
@@ -3901,8 +3897,8 @@  gimple_phi_capacity (const_gimple gs)
 static inline unsigned
 gimple_phi_num_args (const_gimple gs)
 {
-  const gimple_statement_phi *phi_stmt =
-    as_a <const gimple_statement_phi *> (gs);
+  const_gimple_phi phi_stmt =
+    as_a <const_gimple_phi> (gs);
   return phi_stmt->nargs;
 }
 
@@ -3912,8 +3908,8 @@  gimple_phi_num_args (const_gimple gs)
 static inline tree
 gimple_phi_result (const_gimple gs)
 {
-  const gimple_statement_phi *phi_stmt =
-    as_a <const gimple_statement_phi *> (gs);
+  const_gimple_phi phi_stmt =
+    as_a <const_gimple_phi> (gs);
   return phi_stmt->result;
 }
 
@@ -3922,7 +3918,7 @@  gimple_phi_result (const_gimple gs)
 static inline tree *
 gimple_phi_result_ptr (gimple gs)
 {
-  gimple_statement_phi *phi_stmt = as_a <gimple_statement_phi *> (gs);
+  gimple_phi phi_stmt = as_a <gimple_phi> (gs);
   return &phi_stmt->result;
 }
 
@@ -3931,7 +3927,7 @@  gimple_phi_result_ptr (gimple gs)
 static inline void
 gimple_phi_set_result (gimple gs, tree result)
 {
-  gimple_statement_phi *phi_stmt = as_a <gimple_statement_phi *> (gs);
+  gimple_phi phi_stmt = as_a <gimple_phi> (gs);
   phi_stmt->result = result;
   if (result && TREE_CODE (result) == SSA_NAME)
     SSA_NAME_DEF_STMT (result) = gs;
@@ -3944,7 +3940,7 @@  gimple_phi_set_result (gimple gs, tree result)
 static inline struct phi_arg_d *
 gimple_phi_arg (gimple gs, unsigned index)
 {
-  gimple_statement_phi *phi_stmt = as_a <gimple_statement_phi *> (gs);
+  gimple_phi phi_stmt = as_a <gimple_phi> (gs);
   gcc_gimple_checking_assert (index <= phi_stmt->capacity);
   return &(phi_stmt->args[index]);
 }
@@ -3955,7 +3951,7 @@  gimple_phi_arg (gimple gs, unsigned index)
 static inline void
 gimple_phi_set_arg (gimple gs, unsigned index, struct phi_arg_d * phiarg)
 {
-  gimple_statement_phi *phi_stmt = as_a <gimple_statement_phi *> (gs);
+  gimple_phi phi_stmt = as_a <gimple_phi> (gs);
   gcc_gimple_checking_assert (index <= phi_stmt->nargs);
   phi_stmt->args[index] = *phiarg;
 }
diff --git a/gcc/trans-mem.c b/gcc/trans-mem.c
index 94d896d..883efbb 100644
--- a/gcc/trans-mem.c
+++ b/gcc/trans-mem.c
@@ -918,7 +918,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 01203de..b4c4aab 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<gimple_phi> > phis_to_rewrite;
 
 /* The bitmap of non-NULL elements of PHIS_TO_REWRITE.  */
 static bitmap blocks_with_phis_to_rewrite;
@@ -950,9 +950,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, gimple_phi phi)
 {
-  gimple_vec phis;
+  vec<gimple_phi> phis;
   unsigned n, idx = bb->index;
 
   if (rewrite_uses_p (phi))
@@ -991,7 +991,7 @@  insert_phi_nodes_for (tree var, bitmap phi_insertion_points, bool update_p)
 {
   unsigned bb_index;
   edge e;
-  gimple phi;
+  gimple_phi phi;
   basic_block bb;
   bitmap_iterator bi;
   struct def_blocks_d *def_map = find_def_blocks_for (var);
@@ -1991,8 +1991,8 @@  rewrite_update_phi_arguments (basic_block bb)
 
   FOR_EACH_EDGE (e, ei, bb->succs)
     {
-      gimple phi;
-      gimple_vec phis;
+      gimple_phi phi;
+      vec<gimple_phi> phis;
 
       if (!bitmap_bit_p (blocks_with_phis_to_rewrite, e->dest->index))
 	continue;
@@ -2452,7 +2452,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 <gimple_phi> (stmt));
   else
     {
       set_rewrite_uses (stmt, true);
@@ -2812,7 +2812,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<gimple_phi> 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 5bd8233..c075f98 100644
--- a/gcc/tree-phinodes.c
+++ b/gcc/tree-phinodes.c
@@ -97,10 +97,10 @@  phinodes_print_statistics (void)
    happens to contain a PHI node with LEN arguments or more, return
    that one.  */
 
-static inline gimple_statement_phi *
+static inline gimple_phi
 allocate_phi_node (size_t len)
 {
-  gimple_statement_phi *phi;
+  gimple_phi phi;
   size_t bucket = NUM_BUCKETS - 2;
   size_t size = sizeof (struct gimple_statement_phi)
 	        + (len - 1) * sizeof (struct phi_arg_d);
@@ -123,8 +123,7 @@  allocate_phi_node (size_t len)
     }
   else
     {
-      phi = static_cast <gimple_statement_phi *> (
-	ggc_internal_alloc (size));
+      phi = static_cast <gimple_phi> (ggc_internal_alloc (size));
       if (GATHER_STATISTICS)
 	{
 	  enum gimple_alloc_kind kind = gimple_alloc_kind (GIMPLE_PHI);
@@ -173,10 +172,10 @@  ideal_phi_node_len (int len)
 
 /* Return a PHI node with LEN argument slots for variable VAR.  */
 
-static gimple
+static gimple_phi
 make_phi_node (tree var, int len)
 {
-  gimple_statement_phi *phi;
+  gimple_phi phi;
   int capacity, i;
 
   capacity = ideal_phi_node_len (len);
@@ -241,11 +240,11 @@  release_phi_node (gimple phi)
 /* Resize an existing PHI node.  The only way is up.  Return the
    possibly relocated phi.  */
 
-static gimple_statement_phi *
-resize_phi_node (gimple_statement_phi *phi, size_t len)
+static gimple_phi
+resize_phi_node (gimple_phi phi, size_t len)
 {
   size_t old_size, i;
-  gimple_statement_phi *new_phi;
+  gimple_phi new_phi;
 
   gcc_assert (len > gimple_phi_capacity (phi));
 
@@ -296,12 +295,11 @@  reserve_phi_args_for_new_edge (basic_block bb)
 
   for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      gimple_statement_phi *stmt =
-	as_a <gimple_statement_phi *> (gsi_stmt (gsi));
+      gimple_phi stmt = as_a <gimple_phi> (gsi_stmt (gsi));
 
       if (len > gimple_phi_capacity (stmt))
 	{
-	  gimple_statement_phi *new_phi = resize_phi_node (stmt, cap);
+	  gimple_phi new_phi = resize_phi_node (stmt, cap);
 
 	  /* The result of the PHI is defined by this PHI node.  */
 	  SSA_NAME_DEF_STMT (gimple_phi_result (new_phi)) = new_phi;
@@ -347,10 +345,10 @@  add_phi_node_to_bb (gimple phi, basic_block bb)
 
 /* Create a new PHI node for variable VAR at basic block BB.  */
 
-gimple
+gimple_phi
 create_phi_node (tree var, basic_block bb)
 {
-  gimple phi = make_phi_node (var, EDGE_COUNT (bb->preds));
+  gimple_phi phi = make_phi_node (var, EDGE_COUNT (bb->preds));
 
   add_phi_node_to_bb (phi, bb);
   return phi;
@@ -397,7 +395,7 @@  add_phi_arg (gimple phi, tree def, edge e, source_location locus)
    is consistent with how we remove an edge from the edge vector.  */
 
 static void
-remove_phi_arg_num (gimple_statement_phi *phi, int i)
+remove_phi_arg_num (gimple_phi phi, int i)
 {
   int num_elem = gimple_phi_num_args (phi);
 
diff --git a/gcc/tree-phinodes.h b/gcc/tree-phinodes.h
index 1e5df83..0159d5d 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 gimple_phi 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);