This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gimple-classes, committed 05/10] Make all gimple_omp_return_ accessors typesafe


gcc/ChangeLog.gimple-classes:
	* gimple.h (struct gimple_statement_omp_return): Rename to...
	(struct gomp_return): ...this.
	(is_a_helper <gimple_statement_omp_return *>::test): Rename to...
	(is_a_helper <gomp_return *>::test): ...this.
	(is_a_helper <const gimple_statement_omp_return *>::test): Rename to...
	(is_a_helper <const gomp_return *>::test): ...this.
	(gimple_build_omp_return): Strengthen return type from gimple to
	gomp_return *.
	(gimple_omp_return_set_nowait): Likewise for param.
	(gimple_omp_return_set_lhs): Likewise.
	(gimple_omp_return_lhs_ptr): Likewise.
	(gimple_omp_return_nowait_p): Strengthen param from const_gimple
	to const gomp_return *.
	(gimple_omp_return_lhs): Likewise.

	* gimple-pretty-print.c (dump_gimple_omp_return): Strengthen param
	from gimple to gomp_return *.
	(pp_gimple_stmt_1): Add checked cast.
	* gimple-walk.c (walk_gimple_op): Likewise.
	* gimple.c (gimple_build_omp_return): Strengthen return type and
	local "p" from gimple to gomp_return *.
	* omp-low.c (remove_exit_barrier): Replace check against
	GIMPLE_OMP_RETURN with a dyn_cast, introducing local
	"omp_return_stmt" and using it in place of "stmt".
	(expand_omp_for_generic): Introduce local "omp_return_stmt" via a
	checked cast, using it in place of "gsi_stmt (gsi)".
	(expand_omp_for_static_nochunk): Likewise.
	(expand_omp_for_static_chunk): Likewise.
	(expand_omp_sections): Introduce local "omp_return_stmt" via a
	checked cast, using it in place of "gsi_stmt (si)".
	(expand_omp_single): Likewise.
	(maybe_add_implicit_barrier_cancel): Strengthen local "omp_return"
	from gimple to gomp_return * via a checked cast.
---
 gcc/ChangeLog.gimple-classes | 36 ++++++++++++++++++++++++++++++++++++
 gcc/gimple-pretty-print.c    |  5 +++--
 gcc/gimple-walk.c            |  5 +++--
 gcc/gimple.c                 |  4 ++--
 gcc/gimple.h                 | 27 +++++++++------------------
 gcc/omp-low.c                | 44 +++++++++++++++++++++++++-------------------
 6 files changed, 78 insertions(+), 43 deletions(-)

diff --git a/gcc/ChangeLog.gimple-classes b/gcc/ChangeLog.gimple-classes
index 469c009..d85abcd 100644
--- a/gcc/ChangeLog.gimple-classes
+++ b/gcc/ChangeLog.gimple-classes
@@ -1,5 +1,41 @@
 2014-10-29  David Malcolm  <dmalcolm@redhat.com>
 
+	* gimple.h (struct gimple_statement_omp_return): Rename to...
+	(struct gomp_return): ...this.
+	(is_a_helper <gimple_statement_omp_return *>::test): Rename to...
+	(is_a_helper <gomp_return *>::test): ...this.
+	(is_a_helper <const gimple_statement_omp_return *>::test): Rename to...
+	(is_a_helper <const gomp_return *>::test): ...this.
+	(gimple_build_omp_return): Strengthen return type from gimple to
+	gomp_return *.
+	(gimple_omp_return_set_nowait): Likewise for param.
+	(gimple_omp_return_set_lhs): Likewise.
+	(gimple_omp_return_lhs_ptr): Likewise.
+	(gimple_omp_return_nowait_p): Strengthen param from const_gimple
+	to const gomp_return *.
+	(gimple_omp_return_lhs): Likewise.
+
+	* gimple-pretty-print.c (dump_gimple_omp_return): Strengthen param
+	from gimple to gomp_return *.
+	(pp_gimple_stmt_1): Add checked cast.
+	* gimple-walk.c (walk_gimple_op): Likewise.
+	* gimple.c (gimple_build_omp_return): Strengthen return type and
+	local "p" from gimple to gomp_return *.
+	* omp-low.c (remove_exit_barrier): Replace check against
+	GIMPLE_OMP_RETURN with a dyn_cast, introducing local
+	"omp_return_stmt" and using it in place of "stmt".
+	(expand_omp_for_generic): Introduce local "omp_return_stmt" via a
+	checked cast, using it in place of "gsi_stmt (gsi)".
+	(expand_omp_for_static_nochunk): Likewise.
+	(expand_omp_for_static_chunk): Likewise.
+	(expand_omp_sections): Introduce local "omp_return_stmt" via a
+	checked cast, using it in place of "gsi_stmt (si)".
+	(expand_omp_single): Likewise.
+	(maybe_add_implicit_barrier_cancel): Strengthen local "omp_return"
+	from gimple to gomp_return * via a checked cast.
+
+2014-10-29  David Malcolm  <dmalcolm@redhat.com>
+
 	* gimple.h (gimple_omp_sections_clauses): Strengthen param from
 	const_gimple to const gomp_sections *.
 	(gimple_omp_sections_control): Likewise.
diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c
index e0bbb5c..864f636 100644
--- a/gcc/gimple-pretty-print.c
+++ b/gcc/gimple-pretty-print.c
@@ -1502,7 +1502,8 @@ dump_gimple_omp_critical (pretty_printer *buffer, gomp_critical *gs,
 /* Dump a GIMPLE_OMP_RETURN tuple on the pretty_printer BUFFER.  */
 
 static void
-dump_gimple_omp_return (pretty_printer *buffer, gimple gs, int spc, int flags)
+dump_gimple_omp_return (pretty_printer *buffer, gomp_return *gs, int spc,
+			int flags)
 {
   if (flags & TDF_RAW)
     {
@@ -2191,7 +2192,7 @@ pp_gimple_stmt_1 (pretty_printer *buffer, gimple gs, int spc, int flags)
       break;
 
     case GIMPLE_OMP_RETURN:
-      dump_gimple_omp_return (buffer, gs, spc, flags);
+      dump_gimple_omp_return (buffer, as_a <gomp_return *> (gs), spc, flags);
       break;
 
     case GIMPLE_OMP_SECTIONS:
diff --git a/gcc/gimple-walk.c b/gcc/gimple-walk.c
index b802c95..ce78bea 100644
--- a/gcc/gimple-walk.c
+++ b/gcc/gimple-walk.c
@@ -474,8 +474,9 @@ walk_gimple_op (gimple stmt, walk_tree_fn callback_op,
       break;
 
     case GIMPLE_OMP_RETURN:
-      ret = walk_tree (gimple_omp_return_lhs_ptr (stmt), callback_op, wi,
-		       pset);
+      ret = walk_tree (gimple_omp_return_lhs_ptr (
+			 as_a <gomp_return *> (stmt)),
+		       callback_op, wi, pset);
       if (ret)
 	return ret;
       break;
diff --git a/gcc/gimple.c b/gcc/gimple.c
index b34ac10..1421afe 100644
--- a/gcc/gimple.c
+++ b/gcc/gimple.c
@@ -1001,10 +1001,10 @@ gimple_build_omp_ordered (gimple_seq body)
 /* Build a GIMPLE_OMP_RETURN statement.
    WAIT_P is true if this is a non-waiting return.  */
 
-gimple
+gomp_return *
 gimple_build_omp_return (bool wait_p)
 {
-  gimple p = gimple_alloc (GIMPLE_OMP_RETURN, 0);
+  gomp_return *p = as_a <gomp_return *> (gimple_alloc (GIMPLE_OMP_RETURN, 0));
   if (wait_p)
     gimple_omp_return_set_nowait (p);
 
diff --git a/gcc/gimple.h b/gcc/gimple.h
index 723c2f5..6355d96 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -711,8 +711,7 @@ struct GTY((tag("GSS_OMP_ATOMIC_STORE_LAYOUT")))
 };
 
 struct GTY((tag("GSS_OMP_ATOMIC_STORE_LAYOUT")))
-  gimple_statement_omp_return :
-    public gimple_statement_omp_atomic_store_layout
+  gomp_return : public gimple_statement_omp_atomic_store_layout
 {
     /* No extra fields; adds invariant:
          stmt->code == GIMPLE_OMP_RETURN.  */
@@ -966,7 +965,7 @@ is_a_helper <gomp_atomic_store *>::test (gimple gs)
 template <>
 template <>
 inline bool
-is_a_helper <gimple_statement_omp_return *>::test (gimple gs)
+is_a_helper <gomp_return *>::test (gimple gs)
 {
   return gs->code == GIMPLE_OMP_RETURN;
 }
@@ -1174,7 +1173,7 @@ is_a_helper <const gomp_atomic_store *>::test (const_gimple gs)
 template <>
 template <>
 inline bool
-is_a_helper <const gimple_statement_omp_return *>::test (const_gimple gs)
+is_a_helper <const gomp_return *>::test (const_gimple gs)
 {
   return gs->code == GIMPLE_OMP_RETURN;
 }
@@ -1340,7 +1339,7 @@ gimple gimple_build_omp_master (gimple_seq);
 gimple gimple_build_omp_taskgroup (gimple_seq);
 gomp_continue *gimple_build_omp_continue (tree, tree);
 gimple gimple_build_omp_ordered (gimple_seq);
-gimple gimple_build_omp_return (bool);
+gomp_return *gimple_build_omp_return (bool);
 gomp_sections *gimple_build_omp_sections (gimple_seq, tree);
 gimple gimple_build_omp_sections_switch (void);
 gomp_single *gimple_build_omp_single (gimple_seq, tree);
@@ -2030,9 +2029,8 @@ gimple_omp_set_subcode (gimple s, unsigned int subcode)
 /* Set the nowait flag on OMP_RETURN statement S.  */
 
 static inline void
-gimple_omp_return_set_nowait (gimple s)
+gimple_omp_return_set_nowait (gomp_return *s)
 {
-  GIMPLE_CHECK (s, GIMPLE_OMP_RETURN);
   s->subcode |= GF_OMP_RETURN_NOWAIT;
 }
 
@@ -2041,9 +2039,8 @@ gimple_omp_return_set_nowait (gimple s)
    flag set.  */
 
 static inline bool
-gimple_omp_return_nowait_p (const_gimple g)
+gimple_omp_return_nowait_p (const gomp_return *g)
 {
-  GIMPLE_CHECK (g, GIMPLE_OMP_RETURN);
   return (gimple_omp_subcode (g) & GF_OMP_RETURN_NOWAIT) != 0;
 }
 
@@ -2051,10 +2048,8 @@ gimple_omp_return_nowait_p (const_gimple g)
 /* Set the LHS of OMP return.  */
 
 static inline void
-gimple_omp_return_set_lhs (gimple g, tree lhs)
+gimple_omp_return_set_lhs (gomp_return *omp_return_stmt, tree lhs)
 {
-  gimple_statement_omp_return *omp_return_stmt =
-    as_a <gimple_statement_omp_return *> (g);
   omp_return_stmt->val = lhs;
 }
 
@@ -2062,10 +2057,8 @@ gimple_omp_return_set_lhs (gimple g, tree lhs)
 /* Get the LHS of OMP return.  */
 
 static inline tree
-gimple_omp_return_lhs (const_gimple g)
+gimple_omp_return_lhs (const gomp_return *omp_return_stmt)
 {
-  const gimple_statement_omp_return *omp_return_stmt =
-    as_a <const gimple_statement_omp_return *> (g);
   return omp_return_stmt->val;
 }
 
@@ -2073,10 +2066,8 @@ gimple_omp_return_lhs (const_gimple g)
 /* Return a pointer to the LHS of OMP return.  */
 
 static inline tree *
-gimple_omp_return_lhs_ptr (gimple g)
+gimple_omp_return_lhs_ptr (gomp_return *omp_return_stmt)
 {
-  gimple_statement_omp_return *omp_return_stmt =
-    as_a <gimple_statement_omp_return *> (g);
   return &omp_return_stmt->val;
 }
 
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 509f3f8..07eed83 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -4739,8 +4739,9 @@ remove_exit_barrier (struct omp_region *region)
       if (gsi_end_p (gsi))
 	continue;
       stmt = gsi_stmt (gsi);
-      if (gimple_code (stmt) == GIMPLE_OMP_RETURN
-	  && !gimple_omp_return_nowait_p (stmt))
+      gomp_return *omp_return_stmt = dyn_cast <gomp_return *> (stmt);
+      if (omp_return_stmt
+	  && !gimple_omp_return_nowait_p (omp_return_stmt))
 	{
 	  /* OpenMP 3.0 tasks unfortunately prevent this optimization
 	     in many cases.  If there could be tasks queued, the barrier
@@ -4784,7 +4785,7 @@ remove_exit_barrier (struct omp_region *region)
 		}
 	    }
 	  if (!any_addressable_vars)
-	    gimple_omp_return_set_nowait (stmt);
+	    gimple_omp_return_set_nowait (omp_return_stmt);
 	}
     }
 }
@@ -5929,15 +5930,16 @@ expand_omp_for_generic (struct omp_region *region,
 
   /* Add the loop cleanup function.  */
   gsi = gsi_last_bb (exit_bb);
-  if (gimple_omp_return_nowait_p (gsi_stmt (gsi)))
+  gomp_return *omp_return_stmt = as_a <gomp_return *> (gsi_stmt (gsi));
+  if (gimple_omp_return_nowait_p (omp_return_stmt))
     t = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_END_NOWAIT);
-  else if (gimple_omp_return_lhs (gsi_stmt (gsi)))
+  else if (gimple_omp_return_lhs (omp_return_stmt))
     t = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_END_CANCEL);
   else
     t = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_END);
   gcall *call_stmt = gimple_build_call (t, 0);
-  if (gimple_omp_return_lhs (gsi_stmt (gsi)))
-    gimple_call_set_lhs (call_stmt, gimple_omp_return_lhs (gsi_stmt (gsi)));
+  if (gimple_omp_return_lhs (omp_return_stmt))
+    gimple_call_set_lhs (call_stmt, gimple_omp_return_lhs (omp_return_stmt));
   gsi_insert_after (&gsi, call_stmt, GSI_SAME_STMT);
   gsi_remove (&gsi, true);
 
@@ -6336,9 +6338,10 @@ expand_omp_for_static_nochunk (struct omp_region *region,
 
   /* Replace the GIMPLE_OMP_RETURN with a barrier, or nothing.  */
   gsi = gsi_last_bb (exit_bb);
-  if (!gimple_omp_return_nowait_p (gsi_stmt (gsi)))
+  gomp_return *omp_return_stmt = as_a <gomp_return *> (gsi_stmt (gsi));
+  if (!gimple_omp_return_nowait_p (omp_return_stmt))
     {
-      t = gimple_omp_return_lhs (gsi_stmt (gsi));
+      t = gimple_omp_return_lhs (omp_return_stmt);
       gsi_insert_after (&gsi, build_omp_barrier (t), GSI_SAME_STMT);
     }
   gsi_remove (&gsi, true);
@@ -6734,9 +6737,10 @@ expand_omp_for_static_chunk (struct omp_region *region,
 
   /* Replace the GIMPLE_OMP_RETURN with a barrier, or nothing.  */
   gsi = gsi_last_bb (exit_bb);
-  if (!gimple_omp_return_nowait_p (gsi_stmt (gsi)))
+  gomp_return *omp_return_stmt = as_a <gomp_return *> (gsi_stmt (gsi));
+  if (!gimple_omp_return_nowait_p (omp_return_stmt))
     {
-      t = gimple_omp_return_lhs (gsi_stmt (gsi));
+      t = gimple_omp_return_lhs (omp_return_stmt);
       gsi_insert_after (&gsi, build_omp_barrier (t), GSI_SAME_STMT);
     }
   gsi_remove (&gsi, true);
@@ -7630,15 +7634,16 @@ expand_omp_sections (struct omp_region *region)
 
   /* Cleanup function replaces GIMPLE_OMP_RETURN in EXIT_BB.  */
   si = gsi_last_bb (l2_bb);
-  if (gimple_omp_return_nowait_p (gsi_stmt (si)))
+  gomp_return *omp_return_stmt = as_a <gomp_return *> (gsi_stmt (si));
+  if (gimple_omp_return_nowait_p (omp_return_stmt))
     t = builtin_decl_explicit (BUILT_IN_GOMP_SECTIONS_END_NOWAIT);
-  else if (gimple_omp_return_lhs (gsi_stmt (si)))
+  else if (gimple_omp_return_lhs (omp_return_stmt))
     t = builtin_decl_explicit (BUILT_IN_GOMP_SECTIONS_END_CANCEL);
   else
     t = builtin_decl_explicit (BUILT_IN_GOMP_SECTIONS_END);
   stmt = gimple_build_call (t, 0);
-  if (gimple_omp_return_lhs (gsi_stmt (si)))
-    gimple_call_set_lhs (stmt, gimple_omp_return_lhs (gsi_stmt (si)));
+  if (gimple_omp_return_lhs (omp_return_stmt))
+    gimple_call_set_lhs (stmt, gimple_omp_return_lhs (omp_return_stmt));
   gsi_insert_after (&si, stmt, GSI_SAME_STMT);
   gsi_remove (&si, true);
 
@@ -7664,9 +7669,10 @@ expand_omp_single (struct omp_region *region)
   single_succ_edge (entry_bb)->flags = EDGE_FALLTHRU;
 
   si = gsi_last_bb (exit_bb);
-  if (!gimple_omp_return_nowait_p (gsi_stmt (si)))
+  gomp_return *omp_return_stmt = as_a <gomp_return *> (gsi_stmt (si));
+  if (!gimple_omp_return_nowait_p (omp_return_stmt))
     {
-      tree t = gimple_omp_return_lhs (gsi_stmt (si));
+      tree t = gimple_omp_return_lhs (omp_return_stmt);
       gsi_insert_after (&si, build_omp_barrier (t), GSI_SAME_STMT);
     }
   gsi_remove (&si, true);
@@ -8885,8 +8891,8 @@ make_pass_expand_omp (gcc::context *ctxt)
 static void
 maybe_add_implicit_barrier_cancel (omp_context *ctx, gimple_seq *body)
 {
-  gimple omp_return = gimple_seq_last_stmt (*body);
-  gcc_assert (gimple_code (omp_return) == GIMPLE_OMP_RETURN);
+  gomp_return *omp_return =
+    as_a <gomp_return *> (gimple_seq_last_stmt (*body));
   if (gimple_omp_return_nowait_p (omp_return))
     return;
   if (ctx->outer
-- 
1.7.11.7


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]