[PATCH 65/89] Concretize three gimple_try_set_ accessors

David Malcolm dmalcolm@redhat.com
Mon Apr 21 16:56:00 GMT 2014


gcc/
	* gimple.c (gimple_copy): Add checked casts to gimple_try.

	* gimple.h (gimple_statement_base::dyn_cast_gimple_try): New.
	(gimple_try_set_kind): Require a gimple_try.
	(gimple_try_set_eval): Likewise.
	(gimple_try_set_cleanup): Likewise.

	* tree-eh.c (optimize_double_finally): Require a pair of gimple_try
	statements.
	(refactor_eh_r): Convert code comparisons to dynamic casts.
---
 gcc/gimple.c  | 12 ++++++++----
 gcc/gimple.h  | 19 +++++++++++--------
 gcc/tree-eh.c | 15 +++++++--------
 3 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/gcc/gimple.c b/gcc/gimple.c
index e02d24a..01cdc33 100644
--- a/gcc/gimple.c
+++ b/gcc/gimple.c
@@ -1687,10 +1687,14 @@ gimple_copy (gimple stmt)
 	  break;
 
 	case GIMPLE_TRY:
-	  new_seq = gimple_seq_copy (gimple_try_eval (stmt));
-	  gimple_try_set_eval (copy, new_seq);
-	  new_seq = gimple_seq_copy (gimple_try_cleanup (stmt));
-	  gimple_try_set_cleanup (copy, new_seq);
+	  {
+	    gimple_try try_stmt = stmt->as_a_gimple_try ();
+	    gimple_try try_copy = copy->as_a_gimple_try ();
+	    new_seq = gimple_seq_copy (gimple_try_eval (try_stmt));
+	    gimple_try_set_eval (try_copy, new_seq);
+	    new_seq = gimple_seq_copy (gimple_try_cleanup (try_stmt));
+	    gimple_try_set_cleanup (try_copy, new_seq);
+	  }
 	  break;
 
 	case GIMPLE_OMP_FOR:
diff --git a/gcc/gimple.h b/gcc/gimple.h
index 3335dee..788e8c7 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -488,6 +488,12 @@ public:
     return dyn_cast <gimple_statement_phi> (this);
   }
 
+  inline gimple_try
+  dyn_cast_gimple_try ()
+  {
+    return dyn_cast <gimple_statement_try> (this);
+  }
+
   inline gimple_omp_critical
   dyn_cast_gimple_omp_critical ()
   {
@@ -3983,9 +3989,8 @@ gimple_try_kind (const_gimple gs)
 /* Set the kind of try block represented by GIMPLE_TRY GS.  */
 
 static inline void
-gimple_try_set_kind (gimple gs, enum gimple_try_flags kind)
+gimple_try_set_kind (gimple_try gs, enum gimple_try_flags kind)
 {
-  GIMPLE_CHECK (gs, GIMPLE_TRY);
   gcc_gimple_checking_assert (kind == GIMPLE_TRY_CATCH
 			      || kind == GIMPLE_TRY_FINALLY);
   if (gimple_try_kind (gs) != kind)
@@ -4058,23 +4063,21 @@ gimple_try_set_catch_is_cleanup (gimple_try g, bool catch_is_cleanup)
 
 
 /* Set EVAL to be the sequence of statements to use as the body for
-   GIMPLE_TRY GS.  */
+   GIMPLE_TRY TRY_STMT.  */
 
 static inline void
-gimple_try_set_eval (gimple gs, gimple_seq eval)
+gimple_try_set_eval (gimple_try try_stmt, gimple_seq eval)
 {
-  gimple_statement_try *try_stmt = as_a <gimple_statement_try> (gs);
   try_stmt->eval = eval;
 }
 
 
 /* Set CLEANUP to be the sequence of statements to use as the cleanup
-   body for GIMPLE_TRY GS.  */
+   body for GIMPLE_TRY TRY_STMT.  */
 
 static inline void
-gimple_try_set_cleanup (gimple gs, gimple_seq cleanup)
+gimple_try_set_cleanup (gimple_try try_stmt, gimple_seq cleanup)
 {
-  gimple_statement_try *try_stmt = as_a <gimple_statement_try> (gs);
   try_stmt->cleanup = cleanup;
 }
 
diff --git a/gcc/tree-eh.c b/gcc/tree-eh.c
index 412e79a..aad6da3 100644
--- a/gcc/tree-eh.c
+++ b/gcc/tree-eh.c
@@ -3054,7 +3054,7 @@ same_handler_p (gimple_seq oneh, gimple_seq twoh)
    temporary used in the initializer for A.  */
 
 static void
-optimize_double_finally (gimple one, gimple two)
+optimize_double_finally (gimple_try one, gimple_try two)
 {
   gimple oneh;
   gimple_stmt_iterator gsi;
@@ -3101,13 +3101,12 @@ refactor_eh_r (gimple_seq seq)
 	two = NULL;
       else
 	two = gsi_stmt (gsi);
-      if (one
-	  && two
-	  && gimple_code (one) == GIMPLE_TRY
-	  && gimple_code (two) == GIMPLE_TRY
-	  && gimple_try_kind (one) == GIMPLE_TRY_FINALLY
-	  && gimple_try_kind (two) == GIMPLE_TRY_FINALLY)
-	optimize_double_finally (one, two);
+      if (one && two)
+	if (gimple_try try_one = one->dyn_cast_gimple_try ())
+	  if (gimple_try try_two = two->dyn_cast_gimple_try ())
+	    if (gimple_try_kind (try_one) == GIMPLE_TRY_FINALLY
+		&& gimple_try_kind (try_two) == GIMPLE_TRY_FINALLY)
+	      optimize_double_finally (try_one, try_two);
       if (one)
 	switch (gimple_code (one))
 	  {
-- 
1.8.5.3



More information about the Gcc-patches mailing list