diff mbox

[gimple-classes,committed,72/92] Concretize gimple_cond_set_code

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

Commit Message

David Malcolm Oct. 27, 2014, 8:41 p.m. UTC
This corresponds to:
  [PATCH 74/89] Concretize gimple_cond_set_code
  https://gcc.gnu.org/ml/gcc-patches/2014-04/msg01209.html
from the original 89-patch kit

That earlier patch was approved by Jeff:
> Fine once prerequisites go in.
in https://gcc.gnu.org/ml/gcc-patches/2014-05/msg00849.html

gcc/
	* gimple.h (gimple_cond_set_code): Require a gimple_cond.

	* tree-complex.c (expand_complex_comparison): Add a checked cast to
	gimple_cond within "case GIMPLE_COND".

	* tree-ssa-loop-ivcanon.c (create_canonical_iv): Convert local "cond"
	to a gimple_cond, adding a checked cast.  The existing code requires
	that the last statement before the exit edge have code GIMPLE_COND,
	though it's not clear to me where this is verified.

	* tree-ssa-loop-ivopts.c (rewrite_use_compare): Add a checked cast
	to gimple_cond on "use->stmt".

	* tree-ssa-loop-manip.c (tree_transform_and_unroll_loop): Convert
	local "exit_if" to gimple_cond, adding a checked cast.  It's not
	clear to me exactly where the GIMPLE_COND-ness of this is
	established, but the existing code requires it.
	(canonicalize_loop_ivs): Similarly for "stmt".

	* tree-ssa-propagate.c (propagate_tree_value_into_stmt): Replace
	a check against GIMPLE_COND with a dyn_cast<gimple_cond>.
---
 gcc/ChangeLog.gimple-classes | 26 ++++++++++++++++++++++++++
 gcc/gimple.h                 |  3 +--
 gcc/tree-complex.c           |  9 ++++++---
 gcc/tree-ssa-loop-ivcanon.c  |  4 ++--
 gcc/tree-ssa-loop-ivopts.c   |  7 ++++---
 gcc/tree-ssa-loop-manip.c    |  8 ++++----
 gcc/tree-ssa-propagate.c     |  8 ++++----
 7 files changed, 47 insertions(+), 18 deletions(-)
diff mbox

Patch

diff --git a/gcc/ChangeLog.gimple-classes b/gcc/ChangeLog.gimple-classes
index 2bff31c..503fd44 100644
--- a/gcc/ChangeLog.gimple-classes
+++ b/gcc/ChangeLog.gimple-classes
@@ -1,5 +1,31 @@ 
 2014-10-24  David Malcolm  <dmalcolm@redhat.com>
 
+	Concretize gimple_cond_set_code
+
+	* gimple.h (gimple_cond_set_code): Require a gimple_cond.
+
+	* tree-complex.c (expand_complex_comparison): Add a checked cast to
+	gimple_cond within "case GIMPLE_COND".
+
+	* tree-ssa-loop-ivcanon.c (create_canonical_iv): Convert local "cond"
+	to a gimple_cond, adding a checked cast.  The existing code requires
+	that the last statement before the exit edge have code GIMPLE_COND,
+	though it's not clear to me where this is verified.
+
+	* tree-ssa-loop-ivopts.c (rewrite_use_compare): Add a checked cast
+	to gimple_cond on "use->stmt".
+
+	* tree-ssa-loop-manip.c (tree_transform_and_unroll_loop): Convert
+	local "exit_if" to gimple_cond, adding a checked cast.  It's not
+	clear to me exactly where the GIMPLE_COND-ness of this is
+	established, but the existing code requires it.
+	(canonicalize_loop_ivs): Similarly for "stmt".
+
+	* tree-ssa-propagate.c (propagate_tree_value_into_stmt): Replace
+	a check against GIMPLE_COND with a dyn_cast<gimple_cond>.
+
+2014-10-24  David Malcolm  <dmalcolm@redhat.com>
+
 	Concretize gimple_cond_{true|false}_label
 
 	* gimple.h (gimple_cond_true_label): Require a const_gimple_cond
diff --git a/gcc/gimple.h b/gcc/gimple.h
index 94f3416..1639579 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -3008,9 +3008,8 @@  gimple_cond_code (const_gimple gs)
 /* Set CODE to be the predicate code for the conditional statement GS.  */
 
 static inline void
-gimple_cond_set_code (gimple gs, enum tree_code code)
+gimple_cond_set_code (gimple_cond gs, enum tree_code code)
 {
-  GIMPLE_CHECK (gs, GIMPLE_COND);
   gs->subcode = code;
 }
 
diff --git a/gcc/tree-complex.c b/gcc/tree-complex.c
index a7cbceb..6f6fef5 100644
--- a/gcc/tree-complex.c
+++ b/gcc/tree-complex.c
@@ -1405,9 +1405,12 @@  expand_complex_comparison (gimple_stmt_iterator *gsi, tree ar, tree ai,
       break;
 
     case GIMPLE_COND:
-      gimple_cond_set_code (stmt, EQ_EXPR);
-      gimple_cond_set_lhs (stmt, cc);
-      gimple_cond_set_rhs (stmt, boolean_true_node);
+      {
+	gimple_cond cond_stmt = as_a <gimple_cond> (stmt);
+	gimple_cond_set_code (cond_stmt, EQ_EXPR);
+	gimple_cond_set_lhs (cond_stmt, cc);
+	gimple_cond_set_rhs (cond_stmt, boolean_true_node);
+      }
       break;
 
     default:
diff --git a/gcc/tree-ssa-loop-ivcanon.c b/gcc/tree-ssa-loop-ivcanon.c
index 6715caa..a07d3a1 100644
--- a/gcc/tree-ssa-loop-ivcanon.c
+++ b/gcc/tree-ssa-loop-ivcanon.c
@@ -89,7 +89,7 @@  create_canonical_iv (struct loop *loop, edge exit, tree niter)
 {
   edge in;
   tree type, var;
-  gimple cond;
+  gimple_cond cond;
   gimple_stmt_iterator incr_at;
   enum tree_code cmp;
 
@@ -100,7 +100,7 @@  create_canonical_iv (struct loop *loop, edge exit, tree niter)
       fprintf (dump_file, " iterations.\n");
     }
 
-  cond = last_stmt (exit->src);
+  cond = as_a <gimple_cond> (last_stmt (exit->src));
   in = EDGE_SUCC (exit->src, 0);
   if (in == exit)
     in = EDGE_SUCC (exit->src, 1);
diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index 57b63dc..76dc7d8 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -6480,9 +6480,10 @@  rewrite_use_compare (struct ivopts_data *data,
 		loop_preheader_edge (data->current_loop),
 		stmts);
 
-      gimple_cond_set_lhs (use->stmt, var);
-      gimple_cond_set_code (use->stmt, compare);
-      gimple_cond_set_rhs (use->stmt, op);
+      gimple_cond cond_stmt = as_a <gimple_cond> (use->stmt);
+      gimple_cond_set_lhs (cond_stmt, var);
+      gimple_cond_set_code (cond_stmt, compare);
+      gimple_cond_set_rhs (cond_stmt, op);
       return;
     }
 
diff --git a/gcc/tree-ssa-loop-manip.c b/gcc/tree-ssa-loop-manip.c
index 9bd1a3b..bb3da81 100644
--- a/gcc/tree-ssa-loop-manip.c
+++ b/gcc/tree-ssa-loop-manip.c
@@ -1020,7 +1020,7 @@  tree_transform_and_unroll_loop (struct loop *loop, unsigned factor,
 				transform_callback transform,
 				void *data)
 {
-  gimple exit_if;
+  gimple_cond exit_if;
   tree ctr_before, ctr_after;
   tree enter_main_cond, exit_base, exit_step, exit_bound;
   enum tree_code exit_cmp;
@@ -1217,7 +1217,7 @@  tree_transform_and_unroll_loop (struct loop *loop, unsigned factor,
   /* Finally create the new counter for number of iterations and add the new
      exit instruction.  */
   bsi = gsi_last_nondebug_bb (exit_bb);
-  exit_if = gsi_stmt (bsi);
+  exit_if = as_a <gimple_cond> (gsi_stmt (bsi));
   create_iv (exit_base, exit_step, NULL_TREE, loop,
 	     &bsi, false, &ctr_before, &ctr_after);
   gimple_cond_set_code (exit_if, exit_cmp);
@@ -1328,7 +1328,7 @@  canonicalize_loop_ivs (struct loop *loop, tree *nit, bool bump_in_latch)
   tree type, var_before;
   gimple_stmt_iterator gsi;
   gimple_phi_iterator psi;
-  gimple stmt;
+  gimple_cond stmt;
   edge exit = single_dom_exit (loop);
   gimple_seq stmts;
   enum machine_mode mode;
@@ -1379,7 +1379,7 @@  canonicalize_loop_ivs (struct loop *loop, tree *nit, bool bump_in_latch)
 
   rewrite_all_phi_nodes_with_iv (loop, var_before);
 
-  stmt = last_stmt (exit->src);
+  stmt = as_a <gimple_cond> (last_stmt (exit->src));
   /* Make the loop exit if the control condition is not satisfied.  */
   if (exit->flags & EDGE_TRUE_VALUE)
     {
diff --git a/gcc/tree-ssa-propagate.c b/gcc/tree-ssa-propagate.c
index 08482fd..200ee80 100644
--- a/gcc/tree-ssa-propagate.c
+++ b/gcc/tree-ssa-propagate.c
@@ -1445,14 +1445,14 @@  propagate_tree_value_into_stmt (gimple_stmt_iterator *gsi, tree val)
       propagate_tree_value (&expr, val);
       gimple_assign_set_rhs_from_tree (gsi, expr);
     }
-  else if (gimple_code (stmt) == GIMPLE_COND)
+  else if (gimple_cond cond_stmt = dyn_cast <gimple_cond> (stmt))
     {
       tree lhs = NULL_TREE;
       tree rhs = build_zero_cst (TREE_TYPE (val));
       propagate_tree_value (&lhs, val);
-      gimple_cond_set_code (stmt, NE_EXPR);
-      gimple_cond_set_lhs (stmt, lhs);
-      gimple_cond_set_rhs (stmt, rhs);
+      gimple_cond_set_code (cond_stmt, NE_EXPR);
+      gimple_cond_set_lhs (cond_stmt, lhs);
+      gimple_cond_set_rhs (cond_stmt, rhs);
     }
   else if (is_gimple_call (stmt)
            && gimple_call_lhs (stmt) != NULL_TREE)