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]

[tuples] Fix handling of OpenMP shared variables


Hi!

lower_omp_1 needs to regimplify anything containing VAR_DECLs with
DECL_VALUE_EXPR (primarily shared vars being replaced with
.omp_data->var).  gimple_regimplify_operands doesn't help, because
the gimple operands already satisfy their predicates.  The following
patch fixes it by calling gimple_expr unconditionally on the operands
if we found some VAR_DECL with DECL_HAS_VALUE_EXPR_P among the operands.

Approved on IRC by Aldy.

2008-05-28  Jakub Jelinek  <jakub@redhat.com>

	* gimple.c (gimple_regimplify_operands): Don't call gimple_num_ops
	twice.  Write regimplified operand to the correct operand slot.
	* gimplify.c (rhs_predicate_for): No longer static.
	* tree-gimple.h (rhs_predicate_for): New prototype.
	* omp-low.c (lower_omp_1): Don't call gimple_regimplify_operands,
	instead forcefully gimplify_expr each operand with the right
	predicate.

--- gcc/gimple.c.jj	2008-05-28 16:25:33.000000000 +0200
+++ gcc/gimple.c	2008-05-28 12:03:17.000000000 +0200
@@ -2323,7 +2323,7 @@ gimple_regimplify_operands (gimple stmt,
 {
   size_t i, num_ops = gimple_num_ops (stmt);
 
-  for (i = 0; i < gimple_num_ops (stmt); i++)
+  for (i = 0; i < num_ops; i++)
     {
       /* NOTE: We start gimplifying operands from last to first to
 	 make sure that side-effects on the RHS of calls, assignments
@@ -2339,7 +2339,7 @@ gimple_regimplify_operands (gimple stmt,
 	{
 	  op = force_gimple_operand_gsi (gsi_p, op, true, NULL, true,
 					 GSI_SAME_STMT);
-	  gimple_set_op (stmt, i, op);
+	  gimple_set_op (stmt, num_ops - i - 1, op);
 	}
     }
 }
--- gcc/gimplify.c.jj	2008-05-27 14:34:52.000000000 +0200
+++ gcc/gimplify.c	2008-05-28 16:43:05.000000000 +0200
@@ -3345,7 +3345,7 @@ gimplify_init_ctor_eval (tree object, VE
 
 /* Returns the appropriate RHS predicate for this LHS.  */
 
-static gimple_predicate
+gimple_predicate
 rhs_predicate_for (tree lhs)
 {
   if (is_gimple_formal_tmp_var (lhs))
--- gcc/omp-low.c.jj	2008-05-28 16:24:30.000000000 +0200
+++ gcc/omp-low.c	2008-05-28 23:07:25.000000000 +0200
@@ -5029,7 +5029,7 @@ lower_omp_1 (gimple_stmt_iterator *gsi_p
 	      		 NULL, NULL)
 	      || walk_tree (gimple_cond_rhs_ptr (stmt), lower_omp_regimplify_p,
 			    NULL, NULL)))
-	gimple_regimplify_operands (stmt, gsi_p);
+	goto regimplify;
       break;
     case GIMPLE_CATCH:
       lower_omp (gimple_catch_handler (stmt), ctx);
@@ -5095,21 +5095,34 @@ lower_omp_1 (gimple_stmt_iterator *gsi_p
     default:
       if (ctx && walk_gimple_op (stmt, lower_omp_regimplify_p, NULL))
 	{
-	  /* The gimplifier doesn't gimplify the call chain.
-	     Handle that here.  */
-	  if (gimple_code (stmt) == GIMPLE_CALL
-	      && gimple_call_chain (stmt)
-	      && walk_tree (gimple_call_chain_ptr (stmt),
-			    lower_omp_regimplify_p, NULL, NULL))
+	  size_t i, num_ops;
+
+	regimplify:
+	  /* This is similar to gimple_regimplify_operands, but uses
+	     forcefully uses gimplify_expr with the right predicates
+	     on the operands.  is_gimple_val etc. don't look at
+	     DECL_HAS_VALUE_EXPR_P and all the operands already
+	     satisfy their predicates.  gimplify_expr will replace
+	     VAR_DECLs with DECL_HAS_VALUE_EXPR_P set with their
+	     replacements and regimplify.  */
+	  num_ops = gimple_num_ops (stmt);
+	  for (i = num_ops; i > 0; i--)
 	    {
 	      gimple_seq pre = NULL;
-	      gimplify_expr (gimple_call_chain_ptr (stmt), &pre, NULL,
-			     is_gimple_val, fb_rvalue);
+	      tree op = gimple_op (stmt, i - 1);
+	      if (op == NULL_TREE)
+		continue;
+	      if (i == 1 && (is_gimple_call (stmt) || is_gimple_assign (stmt)))
+		gimplify_expr (&op, &pre, NULL, is_gimple_lvalue, fb_lvalue);
+	      else if (i == 2 && is_gimple_assign (stmt) && num_ops == 2)
+		gimplify_expr (&op, &pre, NULL,
+			       rhs_predicate_for (gimple_op (stmt, 0)), fb_rvalue);
+	      else
+		gimplify_expr (&op, &pre, NULL, is_gimple_val, fb_rvalue);
 	      if (!gimple_seq_empty_p (pre))
 		gsi_insert_seq_before (gsi_p, pre, GSI_SAME_STMT);
+	      gimple_set_op (stmt, i - 1, op);
 	    }
-
-	  gimple_regimplify_operands (stmt, gsi_p);
 	}
       break;
     }
--- gcc/tree-gimple.h.jj	2008-05-27 14:34:51.000000000 +0200
+++ gcc/tree-gimple.h	2008-05-28 16:44:26.000000000 +0200
@@ -157,6 +157,7 @@ extern enum gimplify_status gimplify_va_
 struct gimplify_omp_ctx;
 extern void omp_firstprivatize_variable (struct gimplify_omp_ctx *, tree);
 extern tree gimple_boolify (tree);
+extern gimple_predicate rhs_predicate_for (tree);
 extern tree canonicalize_cond_expr_cond (tree);
 
 /* In omp-low.c.  */

	Jakub


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