[tuples] openmp: fix COND_EXPR stmts

Aldy Hernandez aldyh@redhat.com
Sat Apr 5 11:33:00 GMT 2008


There were all these COND_EXPRs being built, that could've been
GIMPLE_COND directly instead of passing through the gimplifier.  I've
fixed them.

I also set the static call chain in gimplify_call_expr.  I noticed we
were ignoring this argument.

Tested on x86-64 with no regressions.  Committed to branch.

	* omp-low.c (gimple_build_cond_empty): New.
	(expand_parallel_call): Convert COND_EXPR to GIMPLE_COND.
	(expand_omp_for_generic): Same.
	(expand_omp_for_static_nochunk): Same. 
	(expand_omp_for_static_chunk): Same.
	(expand_omp_atomic_pipeline): Same.
	* gimplify.c (gimplify_call_expr): Set static call chain.

Index: omp-low.c
===================================================================
--- omp-low.c	(revision 133880)
+++ omp-low.c	(working copy)
@@ -2232,6 +2232,21 @@ lower_send_shared_vars (gimple_seq *ilis
     }
 }
 
+
+/* A convenience function to build an empty GIMPLE_COND with just the
+   condition.  */
+
+static gimple
+gimple_build_cond_empty (tree cond)
+{
+  enum tree_code pred_code;
+  tree lhs, rhs;
+
+  gimple_cond_get_ops_from_tree (cond, &pred_code, &lhs, &rhs);
+  return gimple_build_cond (pred_code, lhs, rhs, NULL_TREE, NULL_TREE);
+}
+
+
 /* Build the function calls to GOMP_parallel_start etc to actually 
    generate the parallel operation.  REGION is the parallel region
    being expanded.  BB is the block where to insert the code.  WS_ARGS
@@ -2298,10 +2313,9 @@ expand_parallel_call (struct omp_region 
 			   build_int_cst (TREE_TYPE (cond), 0));
       else
 	{
-	  gimple_seq seq = NULL;
 	  basic_block cond_bb, then_bb, else_bb;
 	  edge e, e_then, e_else;
-	  tree t, tmp_then, tmp_else, tmp_join, tmp_var;
+	  tree tmp_then, tmp_else, tmp_join, tmp_var;
 
 	  tmp_var = create_tmp_var (TREE_TYPE (val), NULL);
 	  if (gimple_in_ssa_p (cfun))
@@ -2327,12 +2341,9 @@ expand_parallel_call (struct omp_region 
 	  set_immediate_dominator (CDI_DOMINATORS, then_bb, cond_bb);
 	  set_immediate_dominator (CDI_DOMINATORS, else_bb, cond_bb);
 
-	  t = build3 (COND_EXPR, void_type_node,
-		      cond, NULL_TREE, NULL_TREE);
-
+	  stmt = gimple_build_cond_empty (cond);
 	  gsi = gsi_start_bb (cond_bb);
-	  gimplify_and_add (t, &seq);
-	  gsi_insert_seq_after (&gsi, seq, GSI_CONTINUE_LINKING);
+	  gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING);
 
 	  gsi = gsi_start_bb (then_bb);
 	  stmt = gimple_build_assign (tmp_then, val);
@@ -2876,12 +2887,7 @@ expand_omp_for_generic (struct omp_regio
     }
   t = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE,
 			       	true, GSI_SAME_STMT);
-  t = build3 (COND_EXPR, void_type_node, t, NULL_TREE, NULL_TREE);
-    {
-      gimple_seq seq = NULL;
-      gimplify_and_add (t, &seq);
-      gsi_insert_after (&gsi, seq, GSI_SAME_STMT);
-    }
+  gsi_insert_after (&gsi, gimple_build_cond_empty (t), GSI_SAME_STMT);
 
   /* Remove the GIMPLE_OMP_FOR statement.  */
   gsi_remove (&gsi, true);
@@ -2919,8 +2925,8 @@ expand_omp_for_generic (struct omp_regio
 	SSA_NAME_DEF_STMT (vback) = stmt;
   
       t = build2 (fd->cond_code, boolean_type_node, vback, iend);
-      t = build3 (COND_EXPR, void_type_node, t, NULL_TREE, NULL_TREE);
-      gsi_insert_before (&si, t, GSI_SAME_STMT);
+      stmt = gimple_build_cond_empty (t);
+      gsi_insert_before (&si, stmt, GSI_SAME_STMT);
 
       /* Remove GIMPLE_OMP_CONTINUE.  */
       gsi_remove (&si, true);
@@ -2933,8 +2939,8 @@ expand_omp_for_generic (struct omp_regio
 			   build_fold_addr_expr (iend0));
       t = force_gimple_operand_gsi (&si, t, true, NULL_TREE,
 				    false, GSI_CONTINUE_LINKING);
-      t = build3 (COND_EXPR, void_type_node, t, NULL_TREE, NULL_TREE);
-      gsi_insert_after (&si, t, GSI_CONTINUE_LINKING);
+      stmt = gimple_build_cond_empty (t);
+      gsi_insert_after (&si, stmt, GSI_CONTINUE_LINKING);
     }
 
   /* Add the loop cleanup function.  */
@@ -3082,11 +3088,8 @@ expand_omp_for_static_nochunk (struct om
   t = fold_build2 (MIN_EXPR, type, t, n);
   e0 = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE, true, GSI_SAME_STMT);
 
-  /* FIXME tuples
   t = build2 (GE_EXPR, boolean_type_node, s0, e0);
-  t = build3 (COND_EXPR, void_type_node, t, NULL_TREE, NULL_TREE);
-  gsi_insert_before (&gsi, t, GSI_SAME_STMT);
-  */
+  gsi_insert_before (&gsi, gimple_build_cond_empty (t), GSI_SAME_STMT);
 
   /* Remove the GIMPLE_OMP_FOR statement.  */
   gsi_remove (&gsi, true);
@@ -3126,11 +3129,8 @@ expand_omp_for_static_nochunk (struct om
   if (gimple_in_ssa_p (cfun))
     SSA_NAME_DEF_STMT (vback) = stmt;
 
-  /* FIXME tuples
   t = build2 (fd->cond_code, boolean_type_node, vback, e);
-  t = build3 (COND_EXPR, void_type_node, t, NULL_TREE, NULL_TREE);
-  gsi_insert_before (&si, t, GSI_SAME_STMT);
-  */
+  gsi_insert_before (&gsi, gimple_build_cond_empty (t), GSI_SAME_STMT);
 
   /* Remove the GIMPLE_OMP_CONTINUE statement.  */
   gsi_remove (&gsi, true);
@@ -3302,11 +3302,8 @@ expand_omp_for_static_chunk (struct omp_
   e0 = force_gimple_operand_gsi (&si, t, true, NULL_TREE,
 				 false, GSI_CONTINUE_LINKING);
 
-  /* FIXME tuples
   t = build2 (LT_EXPR, boolean_type_node, s0, n);
-  t = build3 (COND_EXPR, void_type_node, t, NULL_TREE, NULL_TREE);
-  gsi_insert_after (&si, t, GSI_CONTINUE_LINKING);
-  */
+  gsi_insert_after (&si, gimple_build_cond_empty (t), GSI_CONTINUE_LINKING);
 
   /* Setup code for sequential iteration goes in SEQ_START_BB.  */
   si = gsi_start_bb (seq_start_bb);
@@ -3341,11 +3338,8 @@ expand_omp_for_static_chunk (struct omp_
   if (gimple_in_ssa_p (cfun))
     SSA_NAME_DEF_STMT (v_back) = stmt;
 
-  /* FIXME tuples
   t = build2 (fd->cond_code, boolean_type_node, v_back, e);
-  t = build3 (COND_EXPR, void_type_node, t, NULL_TREE, NULL_TREE);
-  gsi_insert_before (&si, t, GSI_SAME_STMT);
-  */
+  gsi_insert_before (&si, gimple_build_cond_empty (t), GSI_SAME_STMT);
   
   /* Remove GIMPLE_OMP_CONTINUE.  */
   gsi_remove (&si, true);
@@ -3953,12 +3947,10 @@ expand_omp_atomic_pipeline (basic_block 
   /* Note that we always perform the comparison as an integer, even for
      floating point.  This allows the atomic operation to properly 
      succeed even with NaNs and -0.0.  */
-  /* FIXME tuples
-  x = build3 (COND_EXPR, void_type_node,
-	      build2 (NE_EXPR, boolean_type_node,
-		      new_storedi, old_vali), NULL_TREE, NULL_TREE);
-  gsi_insert_before (&bsi, x, GSI_SAME_STMT);
-  */
+  stmt = gimple_build_cond_empty
+           (build2 (NE_EXPR, boolean_type_node,
+		    new_storedi, old_vali));
+  gsi_insert_before (&si, stmt, GSI_SAME_STMT);
 
   /* Update cfg.  */
   e = single_succ_edge (store_bb);
Index: gimplify.c
===================================================================
--- gimplify.c	(revision 133880)
+++ gimplify.c	(working copy)
@@ -2368,6 +2368,8 @@ gimplify_call_expr (tree *expr_p, gimple
   /* Now add the GIMPLE call to PRE_P.  If WANT_VALUE is set, we need
      to create the appropriate temporary for the call's LHS.  */
   call = gimple_build_call_vec (fndecl ? fndecl : CALL_EXPR_FN (*expr_p), args);
+  if (CALL_EXPR_STATIC_CHAIN (*expr_p))
+    gimple_call_set_chain (call, CALL_EXPR_STATIC_CHAIN (*expr_p));
   gimplify_seq_add_stmt (pre_p, call);
   if (want_value)
     {



More information about the Gcc-patches mailing list