From bee555a25494d76fa0cd414c18d6a42376592ec1 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Mon, 16 Dec 2013 16:15:18 -0500
Subject: [PATCH 34/89] Introduce gimple_omp_atomic_load

gcc/
	* coretypes.h (gimple_omp_atomic_load): New typedef.
	(const_gimple_omp_atomic_load): New typedef.

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

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

	* gimple.c (gimple_build_omp_atomic_load): Return a
	gimple_omp_atomic_load rather than a plain gimple.

	* gimple.h (gimple_statement_base::as_a_gimple_omp_atomic_load):
	New.
	(gimple_build_omp_atomic_load): Return a gimple_omp_atomic_load
	rather than a plain gimple.
	(gimple_omp_atomic_load_set_lhs): Require a
	gimple_omp_atomic_load rather than a plain gimple.
	(gimple_omp_atomic_load_lhs_ptr): Likewise.
	(gimple_omp_atomic_load_set_rhs): Likewise.
	(gimple_omp_atomic_load_rhs_ptr): Likewise.
	(gimple_omp_atomic_load_lhs): Require a
	const_gimple_omp_atomic_load rather than a plain const_gimple.
	(gimple_omp_atomic_load_rhs): Likewise.

	* gimplify-me.c (gimple_regimplify_operands): Add a checked cast
	to gimple_omp_atomic_load within GIMPLE_OMP_ATOMIC_LOAD case of
	switch statement.

	* omp-low.c (expand_omp_atomic): Strengthen type of local "load"
	from gimple to gimple_omp_atomic_load.
	(lower_omp_1): Add a checked cast to gimple_omp_atomic_load within
	GIMPLE_OMP_ATOMIC_LOAD case of switch statement.
---
 gcc/coretypes.h           |  5 +++++
 gcc/gimple-pretty-print.c |  8 ++++----
 gcc/gimple-walk.c         | 19 +++++++++++--------
 gcc/gimple.c              |  5 +++--
 gcc/gimple.h              | 44 +++++++++++++++++++-------------------------
 gcc/gimplify-me.c         |  5 +++--
 gcc/omp-low.c             |  7 +++++--
 7 files changed, 50 insertions(+), 43 deletions(-)

diff --git a/gcc/coretypes.h b/gcc/coretypes.h
index 6d5c363..2fb510f 100644
--- a/gcc/coretypes.h
+++ b/gcc/coretypes.h
@@ -145,6 +145,11 @@ struct gimple_statement_try;
 typedef struct gimple_statement_try *gimple_try;
 typedef const struct gimple_statement_try *const_gimple_try;
 
+struct gimple_statement_omp_atomic_load;
+typedef struct gimple_statement_omp_atomic_load *gimple_omp_atomic_load;
+typedef const struct gimple_statement_omp_atomic_load *
+  const_gimple_omp_atomic_load;
+
 union section;
 typedef union section section;
 struct gcc_options;
diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c
index f2525f4..bf0d73c 100644
--- a/gcc/gimple-pretty-print.c
+++ b/gcc/gimple-pretty-print.c
@@ -1961,8 +1961,8 @@ dump_gimple_omp_task (pretty_printer *buffer, gimple gs, int spc,
    in dumpfile.h).  */
 
 static void
-dump_gimple_omp_atomic_load (pretty_printer *buffer, gimple gs, int spc,
-                             int flags)
+dump_gimple_omp_atomic_load (pretty_printer *buffer, gimple_omp_atomic_load gs,
+			     int spc, int flags)
 {
   if (flags & TDF_RAW)
     {
@@ -2150,8 +2150,8 @@ pp_gimple_stmt_1 (pretty_printer *buffer, gimple gs, int spc, int flags)
       break;
 
     case GIMPLE_OMP_ATOMIC_LOAD:
-      dump_gimple_omp_atomic_load (buffer, gs, spc, flags);
-
+      dump_gimple_omp_atomic_load (buffer, gs->as_a_gimple_omp_atomic_load (),
+				   spc, flags);
       break;
 
     case GIMPLE_OMP_ATOMIC_STORE:
diff --git a/gcc/gimple-walk.c b/gcc/gimple-walk.c
index c247210..bbfc20b 100644
--- a/gcc/gimple-walk.c
+++ b/gcc/gimple-walk.c
@@ -419,15 +419,18 @@ walk_gimple_op (gimple stmt, walk_tree_fn callback_op,
       break;
 
     case GIMPLE_OMP_ATOMIC_LOAD:
-      ret = walk_tree (gimple_omp_atomic_load_lhs_ptr (stmt), callback_op, wi,
-		       pset);
-      if (ret)
-	return ret;
+      {
+	gimple_omp_atomic_load omp_stmt = stmt->as_a_gimple_omp_atomic_load ();
+	ret = walk_tree (gimple_omp_atomic_load_lhs_ptr (omp_stmt),
+			 callback_op, wi, pset);
+	if (ret)
+	  return ret;
 
-      ret = walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt), callback_op, wi,
-		       pset);
-      if (ret)
-	return ret;
+	ret = walk_tree (gimple_omp_atomic_load_rhs_ptr (omp_stmt),
+			 callback_op, wi, pset);
+	if (ret)
+	  return ret;
+      }
       break;
 
     case GIMPLE_OMP_ATOMIC_STORE:
diff --git a/gcc/gimple.c b/gcc/gimple.c
index e74fad3..797726b 100644
--- a/gcc/gimple.c
+++ b/gcc/gimple.c
@@ -1079,10 +1079,11 @@ gimple_build_omp_teams (gimple_seq body, tree clauses)
 
 /* Build a GIMPLE_OMP_ATOMIC_LOAD statement.  */
 
-gimple
+gimple_omp_atomic_load
 gimple_build_omp_atomic_load (tree lhs, tree rhs)
 {
-  gimple p = gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD, 0);
+  gimple_omp_atomic_load p =
+    gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD, 0)->as_a_gimple_omp_atomic_load ();
   gimple_omp_atomic_load_set_lhs (p, lhs);
   gimple_omp_atomic_load_set_rhs (p, rhs);
   return p;
diff --git a/gcc/gimple.h b/gcc/gimple.h
index 931503c..f255ff0 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -336,6 +336,12 @@ public:
     return as_a <gimple_statement_try> (this);
   }
 
+  inline gimple_omp_atomic_load
+  as_a_gimple_omp_atomic_load ()
+  {
+    return as_a <gimple_statement_omp_atomic_load> (this);
+  }
+
   /* Dynamic casting methods, where the cast returns NULL if the
      stmt is not of the required kind.
 
@@ -1579,7 +1585,7 @@ gimple gimple_build_omp_sections_switch (void);
 gimple gimple_build_omp_single (gimple_seq, tree);
 gimple gimple_build_omp_target (gimple_seq, int, tree);
 gimple gimple_build_omp_teams (gimple_seq, tree);
-gimple gimple_build_omp_atomic_load (tree, tree);
+gimple_omp_atomic_load gimple_build_omp_atomic_load (tree, tree);
 gimple gimple_build_omp_atomic_store (tree);
 gimple_transaction gimple_build_transaction (gimple_seq, tree);
 gimple gimple_build_predict (enum br_predictor, enum prediction);
@@ -5589,66 +5595,54 @@ gimple_omp_atomic_store_val_ptr (gimple g)
 /* Set the LHS of an atomic load.  */
 
 static inline void
-gimple_omp_atomic_load_set_lhs (gimple g, tree lhs)
+gimple_omp_atomic_load_set_lhs (gimple_omp_atomic_load load_stmt, tree lhs)
 {
-  gimple_statement_omp_atomic_load *omp_atomic_load_stmt =
-    as_a <gimple_statement_omp_atomic_load> (g);
-  omp_atomic_load_stmt->lhs = lhs;
+  load_stmt->lhs = lhs;
 }
 
 
 /* Get the LHS of an atomic load.  */
 
 static inline tree
-gimple_omp_atomic_load_lhs (const_gimple g)
+gimple_omp_atomic_load_lhs (const_gimple_omp_atomic_load load_stmt)
 {
-  const gimple_statement_omp_atomic_load *omp_atomic_load_stmt =
-    as_a <const gimple_statement_omp_atomic_load> (g);
-  return omp_atomic_load_stmt->lhs;
+  return load_stmt->lhs;
 }
 
 
 /* Return a pointer to the LHS of an atomic load.  */
 
 static inline tree *
-gimple_omp_atomic_load_lhs_ptr (gimple g)
+gimple_omp_atomic_load_lhs_ptr (gimple_omp_atomic_load load_stmt)
 {
-  gimple_statement_omp_atomic_load *omp_atomic_load_stmt =
-    as_a <gimple_statement_omp_atomic_load> (g);
-  return &omp_atomic_load_stmt->lhs;
+  return &load_stmt->lhs;
 }
 
 
 /* Set the RHS of an atomic load.  */
 
 static inline void
-gimple_omp_atomic_load_set_rhs (gimple g, tree rhs)
+gimple_omp_atomic_load_set_rhs (gimple_omp_atomic_load load_stmt, tree rhs)
 {
-  gimple_statement_omp_atomic_load *omp_atomic_load_stmt =
-    as_a <gimple_statement_omp_atomic_load> (g);
-  omp_atomic_load_stmt->rhs = rhs;
+  load_stmt->rhs = rhs;
 }
 
 
 /* Get the RHS of an atomic load.  */
 
 static inline tree
-gimple_omp_atomic_load_rhs (const_gimple g)
+gimple_omp_atomic_load_rhs (const_gimple_omp_atomic_load load_stmt)
 {
-  const gimple_statement_omp_atomic_load *omp_atomic_load_stmt =
-    as_a <const gimple_statement_omp_atomic_load> (g);
-  return omp_atomic_load_stmt->rhs;
+  return load_stmt->rhs;
 }
 
 
 /* Return a pointer to the RHS of an atomic load.  */
 
 static inline tree *
-gimple_omp_atomic_load_rhs_ptr (gimple g)
+gimple_omp_atomic_load_rhs_ptr (gimple_omp_atomic_load load_stmt)
 {
-  gimple_statement_omp_atomic_load *omp_atomic_load_stmt =
-    as_a <gimple_statement_omp_atomic_load> (g);
-  return &omp_atomic_load_stmt->rhs;
+  return &load_stmt->rhs;
 }
 
 
diff --git a/gcc/gimplify-me.c b/gcc/gimplify-me.c
index 7aaac08..68e7e9d 100644
--- a/gcc/gimplify-me.c
+++ b/gcc/gimplify-me.c
@@ -178,8 +178,9 @@ gimple_regimplify_operands (gimple stmt, gimple_stmt_iterator *gsi_p)
 		     is_gimple_val, fb_rvalue);
       break;
     case GIMPLE_OMP_ATOMIC_LOAD:
-      gimplify_expr (gimple_omp_atomic_load_rhs_ptr (stmt), &pre, NULL,
-		     is_gimple_val, fb_rvalue);
+      gimplify_expr (gimple_omp_atomic_load_rhs_ptr (
+		       stmt->as_a_gimple_omp_atomic_load ()),
+		     &pre, NULL, is_gimple_val, fb_rvalue);
       break;
     case GIMPLE_ASM:
       {
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 5054164..edcd0ec 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -7732,7 +7732,9 @@ static void
 expand_omp_atomic (struct omp_region *region)
 {
   basic_block load_bb = region->entry, store_bb = region->exit;
-  gimple load = last_stmt (load_bb), store = last_stmt (store_bb);
+  gimple_omp_atomic_load load =
+    last_stmt (load_bb)->as_a_gimple_omp_atomic_load ();
+  gimple store = last_stmt (store_bb);
   tree loaded_val = gimple_omp_atomic_load_lhs (load);
   tree addr = gimple_omp_atomic_load_rhs (load);
   tree stored_val = gimple_omp_atomic_store_val (store);
@@ -10068,7 +10070,8 @@ lower_omp_1 (gimple_stmt_iterator *gsi_p, omp_context *ctx)
       break;
     case GIMPLE_OMP_ATOMIC_LOAD:
       if ((ctx || task_shared_vars)
-	  && walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt),
+	  && walk_tree (gimple_omp_atomic_load_rhs_ptr (
+			  stmt->as_a_gimple_omp_atomic_load ()),
 			lower_omp_regimplify_p, ctx ? NULL : &wi, NULL))
 	gimple_regimplify_operands (stmt, gsi_p);
       break;
-- 
1.8.5.3

