diff mbox

[74/89] Concretize gimple_cond_set_code

Message ID 1398099480-49147-75-git-send-email-dmalcolm@redhat.com
State New
Headers show

Commit Message

David Malcolm April 21, 2014, 4:57 p.m. UTC
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/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 ++++----
 6 files changed, 21 insertions(+), 18 deletions(-)

Comments

Jeff Law May 12, 2014, 7:22 p.m. UTC | #1
On 04/21/14 10:57, David Malcolm wrote:
> 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.
> ---
Fine once prerequisites go in.
Jeff
diff mbox

Patch

diff --git a/gcc/gimple.h b/gcc/gimple.h
index 9e60c4f..bb8c3c1 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -3286,9 +3286,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 fb2db1a..425fcbe 100644
--- a/gcc/tree-complex.c
+++ b/gcc/tree-complex.c
@@ -1406,9 +1406,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 = stmt->as_a_gimple_cond ();
+	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 cbef59b..c0087e3 100644
--- a/gcc/tree-ssa-loop-ivcanon.c
+++ b/gcc/tree-ssa-loop-ivcanon.c
@@ -88,7 +88,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;
 
@@ -99,7 +99,7 @@  create_canonical_iv (struct loop *loop, edge exit, tree niter)
       fprintf (dump_file, " iterations.\n");
     }
 
-  cond = last_stmt (exit->src);
+  cond = last_stmt (exit->src)->as_a_gimple_cond ();
   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 eba5b0f..2be1a6d 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -6477,9 +6477,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 = use->stmt->as_a_gimple_cond ();
+      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 d74250f..fe63700 100644
--- a/gcc/tree-ssa-loop-manip.c
+++ b/gcc/tree-ssa-loop-manip.c
@@ -1031,7 +1031,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;
@@ -1228,7 +1228,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 = gsi_stmt (bsi)->as_a_gimple_cond ();
   create_iv (exit_base, exit_step, NULL_TREE, loop,
 	     &bsi, false, &ctr_before, &ctr_after);
   gimple_cond_set_code (exit_if, exit_cmp);
@@ -1339,7 +1339,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;
@@ -1390,7 +1390,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 = last_stmt (exit->src)->as_a_gimple_cond ();
   /* 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 dd8fad4..522eecd 100644
--- a/gcc/tree-ssa-propagate.c
+++ b/gcc/tree-ssa-propagate.c
@@ -1431,14 +1431,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 = stmt->dyn_cast_gimple_cond ())
     {
       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)