From 6fb2e18047d77d9f3e9609786fc58a48fb620a64 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Tue, 17 Dec 2013 10:25:47 -0500
Subject: [PATCH 37/88] Introduce gimple_omp_parallel

gcc/
	* coretypes.h (gimple_omp_parallel): New typedef.
	(const_gimple_omp_parallel): New typedef.

	* cgraphbuild.c (build_cgraph_edges): Convert check of code
	against GIMPLE_OMP_PARALLEL to a dyn_cast <gimple_omp_parallel>
	and new local.

	* gimple-pretty-print.c (dump_gimple_omp_parallel): Require a
	gimple_omp_parallel rather than a plain gimple.
	(pp_gimple_stmt_1): Add a checked cast to gimple_omp_parallel
	within GIMPLE_OMP_PARALLEL case of switch statement.

	* gimple-walk.c (walk_gimple_op): Likewise, introducing a local.

	* gimple.c (gimple_build_omp_parallel): Return a
	gimple_omp_parallel rather than a plain gimple.
	(gimple_copy): Add checked casts to gimple_omp_parallel within
	GIMPLE_OMP_PARALLEL case of switch statement, introducing locals.

	* gimple.h (gimple_build_omp_parallel): Return a
	gimple_omp_parallel rather than a plain gimple.
	(gimple_omp_parallel_clauses_ptr): Require a gimple_omp_parallel
	rather than a plain gimple.
	(gimple_omp_parallel_set_clauses): Likewise.
	(gimple_omp_parallel_data_arg_ptr): Likewise.
	(gimple_omp_parallel_set_data_arg): Likewise.
	(gimple_omp_parallel_child_fn_ptr): Likewise.
	(gimple_omp_parallel_set_child_fn): Likewise.
	(gimple_omp_parallel_child_fn): Require a
	const_gimple_omp_parallel rather than a plain const_gimple.
	(gimple_omp_parallel_data_arg): Likewise.

	* omp-low.c (scan_omp_parallel): Strengthen local "stmt" from
	gimple to gimple_omp_parallel.
	(expand_parallel_call): Require a gimple_omp_parallel for
	"entry_stmt" rather than a plain gimple.
	(remove_exit_barrier):  Strengthen local "parallel_stmt" from
	gimple to gimple_omp_parallel.
	(expand_omp_taskreg): Add checked casts to gimple_omp_parallel.

	* tree-inline.c (remap_gimple_stmt): Add a checked cast to
	gimple_omp_parallel within GIMPLE_OMP_PARALLEL case of switch
	statement, introducing local.
---
 gcc/cgraphbuild.c         |  6 +++---
 gcc/coretypes.h           |  4 ++++
 gcc/gimple-pretty-print.c |  7 +++---
 gcc/gimple-walk.c         | 27 +++++++++++++-----------
 gcc/gimple.c              | 23 +++++++++++++-------
 gcc/gimple.h              | 54 ++++++++++++++++++-----------------------------
 gcc/omp-low.c             | 19 +++++++++++------
 gcc/tree-inline.c         | 16 ++++++++------
 8 files changed, 83 insertions(+), 73 deletions(-)

diff --git a/gcc/cgraphbuild.c b/gcc/cgraphbuild.c
index 96d7015..be3e866 100644
--- a/gcc/cgraphbuild.c
+++ b/gcc/cgraphbuild.c
@@ -352,10 +352,10 @@ pass_build_cgraph_edges::execute (function *fun)
 					    bb->count, freq);
 	    }
 	  node->record_stmt_references (stmt);
-	  if (gimple_code (stmt) == GIMPLE_OMP_PARALLEL
-	      && gimple_omp_parallel_child_fn (stmt))
+	  if (gimple_omp_parallel omp_par_stmt =
+	      dyn_cast <gimple_omp_parallel> (stmt))
 	    {
-	      tree fn = gimple_omp_parallel_child_fn (stmt);
+	      tree fn = gimple_omp_parallel_child_fn (omp_par_stmt);
 	      node->create_reference (cgraph_node::get_create (fn),
 				      IPA_REF_ADDR, stmt);
 	    }
diff --git a/gcc/coretypes.h b/gcc/coretypes.h
index 273ba7e..641658f 100644
--- a/gcc/coretypes.h
+++ b/gcc/coretypes.h
@@ -188,6 +188,10 @@ struct gimple_statement_omp_for;
 typedef struct gimple_statement_omp_for *gimple_omp_for;
 typedef const struct gimple_statement_omp_for *const_gimple_omp_for;
 
+struct gimple_statement_omp_parallel;
+typedef struct gimple_statement_omp_parallel *gimple_omp_parallel;
+typedef const struct gimple_statement_omp_parallel *const_gimple_omp_parallel;
+
 union section;
 typedef union section section;
 struct gcc_options;
diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c
index 69a4b4c..ea788c2 100644
--- a/gcc/gimple-pretty-print.c
+++ b/gcc/gimple-pretty-print.c
@@ -1857,8 +1857,8 @@ dump_gimple_phi (pretty_printer *buffer, gimple_phi phi, int spc, bool comment,
    dumpfile.h).  */
 
 static void
-dump_gimple_omp_parallel (pretty_printer *buffer, gimple gs, int spc,
-                          int flags)
+dump_gimple_omp_parallel (pretty_printer *buffer, gimple_omp_parallel gs,
+			  int spc, int flags)
 {
   if (flags & TDF_RAW)
     {
@@ -2137,7 +2137,8 @@ pp_gimple_stmt_1 (pretty_printer *buffer, gimple gs, int spc, int flags)
       break;
 
     case GIMPLE_OMP_PARALLEL:
-      dump_gimple_omp_parallel (buffer, gs, spc, flags);
+      dump_gimple_omp_parallel (buffer, as_a <gimple_omp_parallel> (gs), spc,
+				flags);
       break;
 
     case GIMPLE_OMP_TASK:
diff --git a/gcc/gimple-walk.c b/gcc/gimple-walk.c
index 8293e0d..2b823ac 100644
--- a/gcc/gimple-walk.c
+++ b/gcc/gimple-walk.c
@@ -347,18 +347,21 @@ walk_gimple_op (gimple stmt, walk_tree_fn callback_op,
       break;
 
     case GIMPLE_OMP_PARALLEL:
-      ret = walk_tree (gimple_omp_parallel_clauses_ptr (stmt), callback_op,
-		       wi, pset);
-      if (ret)
-	return ret;
-      ret = walk_tree (gimple_omp_parallel_child_fn_ptr (stmt), callback_op,
-		       wi, pset);
-      if (ret)
-	return ret;
-      ret = walk_tree (gimple_omp_parallel_data_arg_ptr (stmt), callback_op,
-		       wi, pset);
-      if (ret)
-	return ret;
+      {
+	gimple_omp_parallel omp_par_stmt = as_a <gimple_omp_parallel> (stmt);
+	ret = walk_tree (gimple_omp_parallel_clauses_ptr (omp_par_stmt),
+			 callback_op, wi, pset);
+	if (ret)
+	  return ret;
+	ret = walk_tree (gimple_omp_parallel_child_fn_ptr (omp_par_stmt),
+			 callback_op, wi, pset);
+	if (ret)
+	  return ret;
+	ret = walk_tree (gimple_omp_parallel_data_arg_ptr (omp_par_stmt),
+			 callback_op, wi, pset);
+	if (ret)
+	  return ret;
+      }
       break;
 
     case GIMPLE_OMP_TASK:
diff --git a/gcc/gimple.c b/gcc/gimple.c
index 3d8fd44..26bd509 100644
--- a/gcc/gimple.c
+++ b/gcc/gimple.c
@@ -865,11 +865,12 @@ gimple_build_omp_for (gimple_seq body, int kind, tree clauses, size_t collapse,
    CHILD_FN is the function created for the parallel threads to execute.
    DATA_ARG are the shared data argument(s).  */
 
-gimple
+gimple_omp_parallel
 gimple_build_omp_parallel (gimple_seq body, tree clauses, tree child_fn,
 			   tree data_arg)
 {
-  gimple p = gimple_alloc (GIMPLE_OMP_PARALLEL, 0);
+  gimple_omp_parallel p =
+    as_a <gimple_omp_parallel> (gimple_alloc (GIMPLE_OMP_PARALLEL, 0));
   if (body)
     gimple_omp_set_body (p, body);
   gimple_omp_parallel_set_clauses (p, clauses);
@@ -1730,12 +1731,18 @@ gimple_copy (gimple stmt)
 	  goto copy_omp_body;
 
 	case GIMPLE_OMP_PARALLEL:
-	  t = unshare_expr (gimple_omp_parallel_clauses (stmt));
-	  gimple_omp_parallel_set_clauses (copy, t);
-	  t = unshare_expr (gimple_omp_parallel_child_fn (stmt));
-	  gimple_omp_parallel_set_child_fn (copy, t);
-	  t = unshare_expr (gimple_omp_parallel_data_arg (stmt));
-	  gimple_omp_parallel_set_data_arg (copy, t);
+	  {
+	    gimple_omp_parallel omp_par_stmt =
+	      as_a <gimple_omp_parallel> (stmt);
+	    gimple_omp_parallel omp_par_copy =
+	      as_a <gimple_omp_parallel> (copy);
+	    t = unshare_expr (gimple_omp_parallel_clauses (omp_par_stmt));
+	    gimple_omp_parallel_set_clauses (omp_par_copy, t);
+	    t = unshare_expr (gimple_omp_parallel_child_fn (omp_par_stmt));
+	    gimple_omp_parallel_set_child_fn (omp_par_copy, t);
+	    t = unshare_expr (gimple_omp_parallel_data_arg (omp_par_stmt));
+	    gimple_omp_parallel_set_data_arg (omp_par_copy, t);
+	  }
 	  goto copy_omp_body;
 
 	case GIMPLE_OMP_TASK:
diff --git a/gcc/gimple.h b/gcc/gimple.h
index 3ed5fc9..cc460499 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -1344,7 +1344,7 @@ gimple_debug gimple_build_debug_source_bind_stat (tree, tree, gimple MEM_STAT_DE
   gimple_build_debug_source_bind_stat ((var), (val), (stmt) MEM_STAT_INFO)
 gimple_omp_critical gimple_build_omp_critical (gimple_seq, tree);
 gimple_omp_for gimple_build_omp_for (gimple_seq, int, tree, size_t, gimple_seq);
-gimple gimple_build_omp_parallel (gimple_seq, tree, tree, tree);
+gimple_omp_parallel gimple_build_omp_parallel (gimple_seq, tree, tree, tree);
 gimple gimple_build_omp_task (gimple_seq, tree, tree, tree, tree, tree, tree);
 gimple gimple_build_omp_section (gimple_seq);
 gimple gimple_build_omp_master (gimple_seq);
@@ -4682,92 +4682,78 @@ gimple_omp_parallel_clauses (const_gimple gs)
 }
 
 
-/* Return a pointer to the clauses associated with OMP_PARALLEL GS.  */
+/* Return a pointer to the clauses associated with OMP_PARALLEL_STMT.  */
 
 static inline tree *
-gimple_omp_parallel_clauses_ptr (gimple gs)
+gimple_omp_parallel_clauses_ptr (gimple_omp_parallel omp_parallel_stmt)
 {
-  gimple_statement_omp_parallel *omp_parallel_stmt =
-    as_a <gimple_statement_omp_parallel *> (gs);
   return &omp_parallel_stmt->clauses;
 }
 
 
-/* Set CLAUSES to be the list of clauses associated with OMP_PARALLEL
-   GS.  */
+/* Set CLAUSES to be the list of clauses associated with OMP_PARALLEL_STMT.  */
 
 static inline void
-gimple_omp_parallel_set_clauses (gimple gs, tree clauses)
+gimple_omp_parallel_set_clauses (gimple_omp_parallel omp_parallel_stmt,
+				 tree clauses)
 {
-  gimple_statement_omp_parallel *omp_parallel_stmt =
-    as_a <gimple_statement_omp_parallel *> (gs);
   omp_parallel_stmt->clauses = clauses;
 }
 
 
-/* Return the child function used to hold the body of OMP_PARALLEL GS.  */
+/* Return the child function used to hold the body of OMP_PARALLEL_STMT.  */
 
 static inline tree
-gimple_omp_parallel_child_fn (const_gimple gs)
+gimple_omp_parallel_child_fn (const_gimple_omp_parallel omp_parallel_stmt)
 {
-  const gimple_statement_omp_parallel *omp_parallel_stmt =
-    as_a <const gimple_statement_omp_parallel *> (gs);
   return omp_parallel_stmt->child_fn;
 }
 
 /* Return a pointer to the child function used to hold the body of
-   OMP_PARALLEL GS.  */
+   OMP_PARALLEL_STMT.  */
 
 static inline tree *
-gimple_omp_parallel_child_fn_ptr (gimple gs)
+gimple_omp_parallel_child_fn_ptr (gimple_omp_parallel omp_parallel_stmt)
 {
-  gimple_statement_omp_parallel *omp_parallel_stmt =
-    as_a <gimple_statement_omp_parallel *> (gs);
   return &omp_parallel_stmt->child_fn;
 }
 
 
-/* Set CHILD_FN to be the child function for OMP_PARALLEL GS.  */
+/* Set CHILD_FN to be the child function for OMP_PARALLEL_STMT.  */
 
 static inline void
-gimple_omp_parallel_set_child_fn (gimple gs, tree child_fn)
+gimple_omp_parallel_set_child_fn (gimple_omp_parallel omp_parallel_stmt,
+				  tree child_fn)
 {
-  gimple_statement_omp_parallel *omp_parallel_stmt =
-    as_a <gimple_statement_omp_parallel *> (gs);
   omp_parallel_stmt->child_fn = child_fn;
 }
 
 
 /* Return the artificial argument used to send variables and values
-   from the parent to the children threads in OMP_PARALLEL GS.  */
+   from the parent to the children threads in OMP_PARALLEL_STMT.  */
 
 static inline tree
-gimple_omp_parallel_data_arg (const_gimple gs)
+gimple_omp_parallel_data_arg (const_gimple_omp_parallel omp_parallel_stmt)
 {
-  const gimple_statement_omp_parallel *omp_parallel_stmt =
-    as_a <const gimple_statement_omp_parallel *> (gs);
   return omp_parallel_stmt->data_arg;
 }
 
 
-/* Return a pointer to the data argument for OMP_PARALLEL GS.  */
+/* Return a pointer to the data argument for OMP_PARALLEL_STMT.  */
 
 static inline tree *
-gimple_omp_parallel_data_arg_ptr (gimple gs)
+gimple_omp_parallel_data_arg_ptr (gimple_omp_parallel omp_parallel_stmt)
 {
-  gimple_statement_omp_parallel *omp_parallel_stmt =
-    as_a <gimple_statement_omp_parallel *> (gs);
   return &omp_parallel_stmt->data_arg;
 }
 
 
-/* Set DATA_ARG to be the data argument for OMP_PARALLEL GS.  */
+/* Set DATA_ARG to be the data argument for OMP_PARALLEL_STMT.  */
 
 static inline void
-gimple_omp_parallel_set_data_arg (gimple gs, tree data_arg)
+gimple_omp_parallel_set_data_arg (gimple_omp_parallel omp_parallel_stmt,
+				  tree data_arg)
 {
-  gimple_statement_omp_parallel *omp_parallel_stmt =
-    as_a <gimple_statement_omp_parallel *> (gs);
   omp_parallel_stmt->data_arg = data_arg;
 }
 
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index a40a405..46155d6 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -2049,7 +2049,7 @@ scan_omp_parallel (gimple_stmt_iterator *gsi, omp_context *outer_ctx)
 {
   omp_context *ctx;
   tree name;
-  gimple stmt = gsi_stmt (*gsi);
+  gimple_omp_parallel stmt = as_a <gimple_omp_parallel> (gsi_stmt (*gsi));
 
   /* Ignore parallel directives with empty bodies, unless there
      are copyin clauses.  */
@@ -4363,7 +4363,8 @@ gimple_build_cond_empty (tree cond)
 
 static void
 expand_parallel_call (struct omp_region *region, basic_block bb,
-		      gimple entry_stmt, vec<tree, va_gc> *ws_args)
+		      gimple_omp_parallel entry_stmt,
+		      vec<tree, va_gc> *ws_args)
 {
   tree t, t1, t2, val, cond, c, clauses, flags;
   gimple_stmt_iterator gsi;
@@ -4526,7 +4527,7 @@ expand_parallel_call (struct omp_region *region, basic_block bb,
    ENTRY_STMT into the basic_block BB.  */
 
 static void
-expand_cilk_for_call (basic_block bb, gimple entry_stmt,
+expand_cilk_for_call (basic_block bb, gimple_omp_parallel entry_stmt,
 		      vec <tree, va_gc> *ws_args)
 {
   tree t, t1, t2;
@@ -4719,7 +4720,8 @@ remove_exit_barrier (struct omp_region *region)
 	     of such a variable.  */
 	  if (any_addressable_vars < 0)
 	    {
-	      gimple parallel_stmt = last_stmt (region->entry);
+	      gimple_omp_parallel parallel_stmt =
+		as_a <gimple_omp_parallel> (last_stmt (region->entry));
 	      tree child_fun = gimple_omp_parallel_child_fn (parallel_stmt);
 	      tree local_decls, block, decl;
 	      unsigned ix;
@@ -5119,9 +5121,11 @@ expand_omp_taskreg (struct omp_region *region)
 
   /* Emit a library call to launch the children threads.  */
   if (is_cilk_for)
-    expand_cilk_for_call (new_bb, entry_stmt, ws_args);
+    expand_cilk_for_call (new_bb,
+			  as_a <gimple_omp_parallel> (entry_stmt), ws_args);
   else if (gimple_code (entry_stmt) == GIMPLE_OMP_PARALLEL)
-    expand_parallel_call (region, new_bb, entry_stmt, ws_args);
+    expand_parallel_call (region, new_bb,
+			  as_a <gimple_omp_parallel> (entry_stmt), ws_args);
   else
     expand_task_call (new_bb, entry_stmt);
   if (gimple_in_ssa_p (cfun))
@@ -6877,7 +6881,8 @@ expand_cilk_for (struct omp_region *region, struct omp_for_data *fd)
      comment).  */
 
   tree child_fndecl
-    = gimple_omp_parallel_child_fn (last_stmt (region->outer->entry));
+    = gimple_omp_parallel_child_fn (
+        as_a <gimple_omp_parallel> (last_stmt (region->outer->entry)));
   tree t, low_val = NULL_TREE, high_val = NULL_TREE;
   for (t = DECL_ARGUMENTS (child_fndecl); t; t = TREE_CHAIN (t))
     {
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index b3254e5..a4d5809 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -1362,12 +1362,16 @@ remap_gimple_stmt (gimple stmt, copy_body_data *id)
 	  break;
 
 	case GIMPLE_OMP_PARALLEL:
-	  s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
-	  copy = gimple_build_omp_parallel
-	           (s1,
-		    gimple_omp_parallel_clauses (stmt),
-		    gimple_omp_parallel_child_fn (stmt),
-		    gimple_omp_parallel_data_arg (stmt));
+	  {
+	    gimple_omp_parallel omp_par_stmt =
+	      as_a <gimple_omp_parallel> (stmt);
+	    s1 = remap_gimple_seq (gimple_omp_body (omp_par_stmt), id);
+	    copy = gimple_build_omp_parallel
+	             (s1,
+		      gimple_omp_parallel_clauses (omp_par_stmt),
+		      gimple_omp_parallel_child_fn (omp_par_stmt),
+		      gimple_omp_parallel_data_arg (omp_par_stmt));
+	  }
 	  break;
 
 	case GIMPLE_OMP_TASK:
-- 
1.8.5.3

