diff mbox

[gimple-classes,committed,3/3] Strengthen remaining gimple_try_ accessors to require a gtry *

Message ID 1414591325-29630-4-git-send-email-dmalcolm@redhat.com
State New
Headers show

Commit Message

David Malcolm Oct. 29, 2014, 2:02 p.m. UTC
gcc/ChangeLog.gimple-classes:
	* gimple.h (gimple_try_kind): Strengthen param from const_gimple
	to const gtry *.
	(gimple_try_catch_is_cleanup): Likewise.
	(gimple_try_eval_ptr): Strengthen param from gimple gtry *.
	(gimple_try_eval): Likewise.
	(gimple_try_cleanup_ptr): Likewise.
	(gimple_try_cleanup): Likewise.
	* gimple-low.c (lower_stmt): Introduce new local gtry *try_stmt
	via a checked cast, using it in place of stmt for typesafety.
	(lower_try_catch): Strengthen local "stmt" from gimple to gtry *.
	(gimple_stmt_may_fallthru): Within case GIMPLE_TRY, introduce new
	local gtry *try_stmt via a checked cast, using it in place of stmt
	for typesafety.
	* gimple-walk.c (walk_gimple_stmt): Likewise.
	* omp-low.c (lower_omp_1): Likewise.
	* tree-cfg.c (verify_gimple_in_seq_2): Likewise.
	(do_warn_unused_result): Likewise.
	* tree-eh.c (collect_finally_tree): Likewise.
	(replace_goto_queue_1): Likewise.
	(honor_protect_cleanup_actions): Replace check against GIMPLE_TRY
	with a dyn_cast <gtry *>, introducing new local "try_stmt", using it
	in place of "stmt".
	(optimize_double_finally): Strengthen local "oneh" from gimple to
	gtry *, via a dyn_cast.
	(refactor_eh_r): Within case GIMPLE_TRY, introduce new local
	gtry *try_stmt via a checked cast, using it in place of stmt for
	typesafety.
	* tree-inline.c (remap_gimple_stmt): Likewise.
	(estimate_num_insns): Likewise.
---
 gcc/ChangeLog.gimple-classes | 32 ++++++++++++++++++
 gcc/gimple-low.c             | 78 ++++++++++++++++++++++++--------------------
 gcc/gimple-walk.c            | 21 +++++++-----
 gcc/gimple.h                 | 19 +++++------
 gcc/omp-low.c                |  7 ++--
 gcc/tree-cfg.c               | 14 +++++---
 gcc/tree-eh.c                | 67 +++++++++++++++++++++----------------
 gcc/tree-inline.c            | 17 +++++++---
 8 files changed, 161 insertions(+), 94 deletions(-)
diff mbox

Patch

diff --git a/gcc/ChangeLog.gimple-classes b/gcc/ChangeLog.gimple-classes
index 50b87b9..10c3957 100644
--- a/gcc/ChangeLog.gimple-classes
+++ b/gcc/ChangeLog.gimple-classes
@@ -1,5 +1,37 @@ 
 2014-10-28  David Malcolm  <dmalcolm@redhat.com>
 
+	* gimple.h (gimple_try_kind): Strengthen param from const_gimple
+	to const gtry *.
+	(gimple_try_catch_is_cleanup): Likewise.
+	(gimple_try_eval_ptr): Strengthen param from gimple gtry *.
+	(gimple_try_eval): Likewise.
+	(gimple_try_cleanup_ptr): Likewise.
+	(gimple_try_cleanup): Likewise.
+	* gimple-low.c (lower_stmt): Introduce new local gtry *try_stmt
+	via a checked cast, using it in place of stmt for typesafety.
+	(lower_try_catch): Strengthen local "stmt" from gimple to gtry *.
+	(gimple_stmt_may_fallthru): Within case GIMPLE_TRY, introduce new
+	local gtry *try_stmt via a checked cast, using it in place of stmt
+	for typesafety.
+	* gimple-walk.c (walk_gimple_stmt): Likewise.
+	* omp-low.c (lower_omp_1): Likewise.
+	* tree-cfg.c (verify_gimple_in_seq_2): Likewise.
+	(do_warn_unused_result): Likewise.
+	* tree-eh.c (collect_finally_tree): Likewise.
+	(replace_goto_queue_1): Likewise.
+	(honor_protect_cleanup_actions): Replace check against GIMPLE_TRY
+	with a dyn_cast <gtry *>, introducing new local "try_stmt", using it
+	in place of "stmt".
+	(optimize_double_finally): Strengthen local "oneh" from gimple to
+	gtry *, via a dyn_cast.
+	(refactor_eh_r): Within case GIMPLE_TRY, introduce new local
+	gtry *try_stmt via a checked cast, using it in place of stmt for
+	typesafety.
+	* tree-inline.c (remap_gimple_stmt): Likewise.
+	(estimate_num_insns): Likewise.
+
+2014-10-28  David Malcolm  <dmalcolm@redhat.com>
+
 	* gimple.h (gimple_goto_dest): Strengthen param from const_gimple to
 	const ggoto *.
 	* cfgexpand.c (expand_gimple_stmt_1): Add checked cast to ggoto *
diff --git a/gcc/gimple-low.c b/gcc/gimple-low.c
index ab191a0..0aec000 100644
--- a/gcc/gimple-low.c
+++ b/gcc/gimple-low.c
@@ -271,27 +271,30 @@  lower_stmt (gimple_stmt_iterator *gsi, struct lower_data *data)
       return;
 
     case GIMPLE_TRY:
-      if (gimple_try_kind (stmt) == GIMPLE_TRY_CATCH)
-	lower_try_catch (gsi, data);
-      else
-	{
-	  /* It must be a GIMPLE_TRY_FINALLY.  */
-	  bool cannot_fallthru;
-	  lower_sequence (gimple_try_eval_ptr (stmt), data);
-	  cannot_fallthru = data->cannot_fallthru;
-
-	  /* The finally clause is always executed after the try clause,
-	     so if it does not fall through, then the try-finally will not
-	     fall through.  Otherwise, if the try clause does not fall
-	     through, then when the finally clause falls through it will
-	     resume execution wherever the try clause was going.  So the
-	     whole try-finally will only fall through if both the try
-	     clause and the finally clause fall through.  */
-	  data->cannot_fallthru = false;
-	  lower_sequence (gimple_try_cleanup_ptr (stmt), data);
-	  data->cannot_fallthru |= cannot_fallthru;
-	  gsi_next (gsi);
-	}
+      {
+	gtry *try_stmt = as_a <gtry *> (stmt);
+	if (gimple_try_kind (try_stmt) == GIMPLE_TRY_CATCH)
+	  lower_try_catch (gsi, data);
+	else
+	  {
+	    /* It must be a GIMPLE_TRY_FINALLY.  */
+	    bool cannot_fallthru;
+	    lower_sequence (gimple_try_eval_ptr (try_stmt), data);
+	    cannot_fallthru = data->cannot_fallthru;
+
+	    /* The finally clause is always executed after the try clause,
+	       so if it does not fall through, then the try-finally will not
+	       fall through.  Otherwise, if the try clause does not fall
+	       through, then when the finally clause falls through it will
+	       resume execution wherever the try clause was going.  So the
+	       whole try-finally will only fall through if both the try
+	       clause and the finally clause fall through.  */
+	    data->cannot_fallthru = false;
+	    lower_sequence (gimple_try_cleanup_ptr (try_stmt), data);
+	    data->cannot_fallthru |= cannot_fallthru;
+	    gsi_next (gsi);
+	  }
+      }
       return;
 
     case GIMPLE_EH_ELSE:
@@ -444,7 +447,7 @@  static void
 lower_try_catch (gimple_stmt_iterator *gsi, struct lower_data *data)
 {
   bool cannot_fallthru;
-  gimple stmt = gsi_stmt (*gsi);
+  gtry *stmt = as_a <gtry *> (gsi_stmt (*gsi));
   gimple_stmt_iterator i;
 
   /* We don't handle GIMPLE_TRY_FINALLY.  */
@@ -591,20 +594,23 @@  gimple_stmt_may_fallthru (gimple stmt)
 	       gimple_bind_body (as_a <gbind *> (stmt)));
 
     case GIMPLE_TRY:
-      if (gimple_try_kind (stmt) == GIMPLE_TRY_CATCH)
-        return gimple_try_catch_may_fallthru (as_a <gtry *> (stmt));
-
-      /* It must be a GIMPLE_TRY_FINALLY.  */
-
-      /* The finally clause is always executed after the try clause,
-	 so if it does not fall through, then the try-finally will not
-	 fall through.  Otherwise, if the try clause does not fall
-	 through, then when the finally clause falls through it will
-	 resume execution wherever the try clause was going.  So the
-	 whole try-finally will only fall through if both the try
-	 clause and the finally clause fall through.  */
-      return (gimple_seq_may_fallthru (gimple_try_eval (stmt))
-	      && gimple_seq_may_fallthru (gimple_try_cleanup (stmt)));
+      {
+	gtry *try_stmt = as_a <gtry *> (stmt);
+	if (gimple_try_kind (try_stmt) == GIMPLE_TRY_CATCH)
+	  return gimple_try_catch_may_fallthru (try_stmt);
+
+	/* It must be a GIMPLE_TRY_FINALLY.  */
+
+	/* The finally clause is always executed after the try clause,
+	   so if it does not fall through, then the try-finally will not
+	   fall through.  Otherwise, if the try clause does not fall
+	   through, then when the finally clause falls through it will
+	   resume execution wherever the try clause was going.  So the
+	   whole try-finally will only fall through if both the try
+	   clause and the finally clause fall through.  */
+	return (gimple_seq_may_fallthru (gimple_try_eval (try_stmt))
+		&& gimple_seq_may_fallthru (gimple_try_cleanup (try_stmt)));
+      }
 
     case GIMPLE_EH_ELSE:
       {
diff --git a/gcc/gimple-walk.c b/gcc/gimple-walk.c
index 4aa2201..1248e75 100644
--- a/gcc/gimple-walk.c
+++ b/gcc/gimple-walk.c
@@ -599,15 +599,20 @@  walk_gimple_stmt (gimple_stmt_iterator *gsi, walk_stmt_fn callback_stmt,
       break;
 
     case GIMPLE_TRY:
-      ret = walk_gimple_seq_mod (gimple_try_eval_ptr (stmt), callback_stmt, callback_op,
-	                     wi);
-      if (ret)
-	return wi->callback_result;
+      {
+	gtry *try_stmt = as_a <gtry *> (stmt);
+	ret = walk_gimple_seq_mod (gimple_try_eval_ptr (try_stmt),
+				   callback_stmt, callback_op,
+				   wi);
+	if (ret)
+	  return wi->callback_result;
 
-      ret = walk_gimple_seq_mod (gimple_try_cleanup_ptr (stmt), callback_stmt,
-	                     callback_op, wi);
-      if (ret)
-	return wi->callback_result;
+	ret = walk_gimple_seq_mod (gimple_try_cleanup_ptr (try_stmt),
+				   callback_stmt,
+				   callback_op, wi);
+	if (ret)
+	  return wi->callback_result;
+      }
       break;
 
     case GIMPLE_OMP_FOR:
diff --git a/gcc/gimple.h b/gcc/gimple.h
index a947126..8e82914 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -3672,9 +3672,8 @@  gimple_eh_else_set_e_body (geh_else *eh_else_stmt, gimple_seq seq)
    either GIMPLE_TRY_CATCH or GIMPLE_TRY_FINALLY.  */
 
 static inline enum gimple_try_flags
-gimple_try_kind (const_gimple gs)
+gimple_try_kind (const gtry *gs)
 {
-  GIMPLE_CHECK (gs, GIMPLE_TRY);
   return (enum gimple_try_flags) (gs->subcode & GIMPLE_TRY_KIND);
 }
 
@@ -3694,7 +3693,7 @@  gimple_try_set_kind (gtry *gs, enum gimple_try_flags kind)
 /* Return the GIMPLE_TRY_CATCH_IS_CLEANUP flag.  */
 
 static inline bool
-gimple_try_catch_is_cleanup (const_gimple gs)
+gimple_try_catch_is_cleanup (const gtry *gs)
 {
   gcc_gimple_checking_assert (gimple_try_kind (gs) == GIMPLE_TRY_CATCH);
   return (gs->subcode & GIMPLE_TRY_CATCH_IS_CLEANUP) != 0;
@@ -3702,12 +3701,11 @@  gimple_try_catch_is_cleanup (const_gimple gs)
 
 
 /* Return a pointer to the sequence of statements used as the
-   body for GIMPLE_TRY GS.  */
+   body for GIMPLE_TRY TRY_STMT.  */
 
 static inline gimple_seq *
-gimple_try_eval_ptr (gimple gs)
+gimple_try_eval_ptr (gtry *try_stmt)
 {
-  gtry *try_stmt = as_a <gtry *> (gs);
   return &try_stmt->eval;
 }
 
@@ -3715,19 +3713,18 @@  gimple_try_eval_ptr (gimple gs)
 /* Return the sequence of statements used as the body for GIMPLE_TRY GS.  */
 
 static inline gimple_seq
-gimple_try_eval (gimple gs)
+gimple_try_eval (gtry *gs)
 {
   return *gimple_try_eval_ptr (gs);
 }
 
 
 /* Return a pointer to the sequence of statements used as the cleanup body for
-   GIMPLE_TRY GS.  */
+   GIMPLE_TRY TRY_STMT.  */
 
 static inline gimple_seq *
-gimple_try_cleanup_ptr (gimple gs)
+gimple_try_cleanup_ptr (gtry *try_stmt)
 {
-  gtry *try_stmt = as_a <gtry *> (gs);
   return &try_stmt->cleanup;
 }
 
@@ -3736,7 +3733,7 @@  gimple_try_cleanup_ptr (gimple gs)
    GIMPLE_TRY GS.  */
 
 static inline gimple_seq
-gimple_try_cleanup (gimple gs)
+gimple_try_cleanup (gtry *gs)
 {
   return *gimple_try_cleanup_ptr (gs);
 }
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index d9ac691..0a5de1a 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -10504,8 +10504,11 @@  lower_omp_1 (gimple_stmt_iterator *gsi_p, omp_context *ctx)
       lower_omp (gimple_eh_filter_failure_ptr (stmt), ctx);
       break;
     case GIMPLE_TRY:
-      lower_omp (gimple_try_eval_ptr (stmt), ctx);
-      lower_omp (gimple_try_cleanup_ptr (stmt), ctx);
+      {
+	gtry *try_stmt = as_a <gtry *> (stmt);
+	lower_omp (gimple_try_eval_ptr (try_stmt), ctx);
+	lower_omp (gimple_try_cleanup_ptr (try_stmt), ctx);
+      }
       break;
     case GIMPLE_TRANSACTION:
       lower_omp (gimple_transaction_body_ptr (
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 669f23e..ee3432d 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -4680,8 +4680,11 @@  verify_gimple_in_seq_2 (gimple_seq stmts)
 	  break;
 
 	case GIMPLE_TRY:
-	  err |= verify_gimple_in_seq_2 (gimple_try_eval (stmt));
-	  err |= verify_gimple_in_seq_2 (gimple_try_cleanup (stmt));
+	  {
+	    gtry *try_stmt = as_a <gtry *> (stmt);
+	    err |= verify_gimple_in_seq_2 (gimple_try_eval (try_stmt));
+	    err |= verify_gimple_in_seq_2 (gimple_try_cleanup (try_stmt));
+	  }
 	  break;
 
 	case GIMPLE_EH_FILTER:
@@ -8424,8 +8427,11 @@  do_warn_unused_result (gimple_seq seq)
 	  do_warn_unused_result (gimple_bind_body (as_a <gbind *>(g)));
 	  break;
 	case GIMPLE_TRY:
-	  do_warn_unused_result (gimple_try_eval (g));
-	  do_warn_unused_result (gimple_try_cleanup (g));
+	  {
+	    gtry *try_stmt = as_a <gtry *> (g);
+	    do_warn_unused_result (gimple_try_eval (try_stmt));
+	    do_warn_unused_result (gimple_try_cleanup (try_stmt));
+	  }
 	  break;
 	case GIMPLE_CATCH:
 	  do_warn_unused_result (gimple_catch_handler (
diff --git a/gcc/tree-eh.c b/gcc/tree-eh.c
index 3d601c0..77fb9a2 100644
--- a/gcc/tree-eh.c
+++ b/gcc/tree-eh.c
@@ -258,19 +258,22 @@  collect_finally_tree (gimple stmt, gtry *region)
       break;
 
     case GIMPLE_TRY:
-      if (gimple_try_kind (stmt) == GIMPLE_TRY_FINALLY)
-        {
-          temp.g = stmt;
-          record_in_finally_tree (temp, region);
-          collect_finally_tree_1 (gimple_try_eval (stmt),
-				  as_a <gtry *> (stmt));
-	  collect_finally_tree_1 (gimple_try_cleanup (stmt), region);
-        }
-      else if (gimple_try_kind (stmt) == GIMPLE_TRY_CATCH)
-        {
-          collect_finally_tree_1 (gimple_try_eval (stmt), region);
-          collect_finally_tree_1 (gimple_try_cleanup (stmt), region);
-        }
+      {
+	gtry *try_stmt = as_a <gtry *> (stmt);
+	if (gimple_try_kind (try_stmt) == GIMPLE_TRY_FINALLY)
+	  {
+	    temp.g = try_stmt;
+	    record_in_finally_tree (temp, region);
+	    collect_finally_tree_1 (gimple_try_eval (try_stmt),
+				    try_stmt);
+	    collect_finally_tree_1 (gimple_try_cleanup (try_stmt), region);
+	  }
+	else if (gimple_try_kind (try_stmt) == GIMPLE_TRY_CATCH)
+	  {
+	    collect_finally_tree_1 (gimple_try_eval (try_stmt), region);
+	    collect_finally_tree_1 (gimple_try_cleanup (try_stmt), region);
+	  }
+      }
       break;
 
     case GIMPLE_CATCH:
@@ -531,8 +534,11 @@  replace_goto_queue_1 (gimple stmt, struct leh_tf_state *tf,
       break;
 
     case GIMPLE_TRY:
-      replace_goto_queue_stmt_list (gimple_try_eval_ptr (stmt), tf);
-      replace_goto_queue_stmt_list (gimple_try_cleanup_ptr (stmt), tf);
+      {
+	gtry *try_stmt = as_a <gtry *> (stmt);
+	replace_goto_queue_stmt_list (gimple_try_eval_ptr (try_stmt), tf);
+	replace_goto_queue_stmt_list (gimple_try_cleanup_ptr (try_stmt), tf);
+      }
       break;
     case GIMPLE_CATCH:
       replace_goto_queue_stmt_list (gimple_catch_handler_ptr (
@@ -1042,13 +1048,14 @@  honor_protect_cleanup_actions (struct leh_state *outer_state,
      MUST_NOT_THROW filter.  */
   gsi = gsi_start (finally);
   x = gsi_stmt (gsi);
-  if (gimple_code (x) == GIMPLE_TRY
-      && gimple_try_kind (x) == GIMPLE_TRY_CATCH
-      && gimple_try_catch_is_cleanup (x))
-    {
-      gsi_insert_seq_before (&gsi, gimple_try_eval (x), GSI_SAME_STMT);
-      gsi_remove (&gsi, false);
-    }
+  if (gtry *try_stmt = dyn_cast <gtry *> (x))
+    if (gimple_try_kind (try_stmt) == GIMPLE_TRY_CATCH
+	&& gimple_try_catch_is_cleanup (try_stmt))
+      {
+	gsi_insert_seq_before (&gsi, gimple_try_eval (try_stmt),
+			       GSI_SAME_STMT);
+	gsi_remove (&gsi, false);
+      }
 
   /* Wrap the block with protect_cleanup_actions as the action.  */
   eh_mnt = gimple_build_eh_must_not_throw (protect_cleanup_actions);
@@ -3036,7 +3043,7 @@  same_handler_p (gimple_seq oneh, gimple_seq twoh)
 static void
 optimize_double_finally (gtry *one, gtry *two)
 {
-  gimple oneh;
+  gtry *oneh;
   gimple_stmt_iterator gsi;
   gimple_seq cleanup;
 
@@ -3045,9 +3052,10 @@  optimize_double_finally (gtry *one, gtry *two)
   if (!gsi_one_before_end_p (gsi))
     return;
 
-  oneh = gsi_stmt (gsi);
-  if (gimple_code (oneh) != GIMPLE_TRY
-      || gimple_try_kind (oneh) != GIMPLE_TRY_CATCH)
+  oneh = dyn_cast <gtry *> (gsi_stmt (gsi));
+  if (!oneh)
+    return;
+  if (gimple_try_kind (oneh) != GIMPLE_TRY_CATCH)
     return;
 
   if (same_handler_p (gimple_try_cleanup (oneh), gimple_try_cleanup (two)))
@@ -3091,8 +3099,11 @@  refactor_eh_r (gimple_seq seq)
 	switch (gimple_code (one))
 	  {
 	  case GIMPLE_TRY:
-	    refactor_eh_r (gimple_try_eval (one));
-	    refactor_eh_r (gimple_try_cleanup (one));
+	    {
+	      gtry *try_one = as_a <gtry *> (one);
+	      refactor_eh_r (gimple_try_eval (try_one));
+	      refactor_eh_r (gimple_try_cleanup (try_one));
+	    }
 	    break;
 	  case GIMPLE_CATCH:
 	    refactor_eh_r (gimple_catch_handler (as_a <gcatch *> (one)));
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index fa08c98..0a076ce 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -1359,9 +1359,12 @@  remap_gimple_stmt (gimple stmt, copy_body_data *id)
 	  break;
 
 	case GIMPLE_TRY:
-	  s1 = remap_gimple_seq (gimple_try_eval (stmt), id);
-	  s2 = remap_gimple_seq (gimple_try_cleanup (stmt), id);
-	  copy = gimple_build_try (s1, s2, gimple_try_kind (stmt));
+	  {
+	    gtry *try_stmt = as_a <gtry *> (stmt);
+	    s1 = remap_gimple_seq (gimple_try_eval (try_stmt), id);
+	    s2 = remap_gimple_seq (gimple_try_cleanup (try_stmt), id);
+	    copy = gimple_build_try (s1, s2, gimple_try_kind (try_stmt));
+	  }
 	  break;
 
 	case GIMPLE_WITH_CLEANUP_EXPR:
@@ -4010,8 +4013,12 @@  estimate_num_insns (gimple stmt, eni_weights *weights)
 				     weights);
 
     case GIMPLE_TRY:
-      return (estimate_num_insns_seq (gimple_try_eval (stmt), weights)
-              + estimate_num_insns_seq (gimple_try_cleanup (stmt), weights));
+      {
+	gtry *try_stmt = as_a <gtry *> (stmt);
+	return (estimate_num_insns_seq (gimple_try_eval (try_stmt), weights)
+		+ estimate_num_insns_seq (gimple_try_cleanup (try_stmt),
+					  weights));
+      }
 
     /* OpenMP directives are generally very expensive.  */