[tuples] fortran changes

Aldy Hernandez aldyh@redhat.com
Fri Nov 3 19:43:00 GMT 2006


Hi folks!

Here are the changes required for the fortran front-end.

Apart from the obvious changes, fortran's openmp implementation forced me to
touch a few other places, as gfc_add_modify_expr() was making MODIFY_EXPRs
after gimplification.

With this patch, fortran plays nicely with tuples and has no regressions
compared to mainline.

Committed to branch.

Aldy

	* gimplify.c (gimplify_omp_for): Allow gimple statements.
	* tree-outof-ssa.c (check_replaceable): Use PROTECTED_TREE_OPERAND.
	* fold-const.c (fold_binary): Allow gimple statements.
	(fold): Same.
	* fortran/trans-array.c (gfc_conv_descriptor_data_set_internal):
	Rename from gfc_conv_descriptor_data_set.
	Call gfc_add_modify instead of gfc_add_modify_expr.
	* fortran/trans-array.h (gfc_conv_descriptor_data_set_internal):
	Rename from gfc_conv_descriptor_data_set.
	(gfc_conv_descriptor_data_set): New macro.
	(gfc_conv_descriptor_data_set_tuples): New macros.
	* fortran/trans-openmp.c (gfc_omp_clause_default_ctor): Call
	gfc_conv_descriptor_data_set_tuples.
	* fortran/trans.c (gfc_add_modify): Rename from gfc_add_modify_expr.
	Generate GIMPLE_MODIFY_STMT when appropriate.
	* fortran/trans.h (gfc_add_modify): Rename from gfc_add_modify_expr.
	(gfc_add_modify_expr): New macro.
	(gfc_add_modify_stmt): New macro.
	* fortran/f95-lang.c (lang_tree_node): Handle gimple statements.

Index: gimplify.c
===================================================================
--- gimplify.c	(revision 118382)
+++ gimplify.c	(working copy)
@@ -4940,8 +4940,9 @@ gimplify_omp_for (tree *expr_p, tree *pr
   gimplify_scan_omp_clauses (&OMP_FOR_CLAUSES (for_stmt), pre_p, false, false);
 
   t = OMP_FOR_INIT (for_stmt);
-  gcc_assert (TREE_CODE (t) == MODIFY_EXPR);
-  decl = TREE_OPERAND (t, 0);
+  gcc_assert (TREE_CODE (t) == MODIFY_EXPR
+	      || TREE_CODE (t) == GIMPLE_MODIFY_STMT);
+  decl = PROTECTED_TREE_OPERAND (t, 0);
   gcc_assert (DECL_P (decl));
   gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (decl)));
 
@@ -4951,16 +4952,18 @@ gimplify_omp_for (tree *expr_p, tree *pr
   else
     omp_add_variable (gimplify_omp_ctxp, decl, GOVD_PRIVATE | GOVD_SEEN);
 
-  ret |= gimplify_expr (&TREE_OPERAND (t, 1), &OMP_FOR_PRE_BODY (for_stmt),
+  ret |= gimplify_expr (&PROTECTED_TREE_OPERAND (t, 1),
+			&OMP_FOR_PRE_BODY (for_stmt),
 			NULL, is_gimple_val, fb_rvalue);
 
   tree_to_gimple_tuple (&OMP_FOR_INIT (for_stmt));
 
   t = OMP_FOR_COND (for_stmt);
   gcc_assert (COMPARISON_CLASS_P (t));
-  gcc_assert (TREE_OPERAND (t, 0) == decl);
+  gcc_assert (PROTECTED_TREE_OPERAND (t, 0) == decl);
 
-  ret |= gimplify_expr (&TREE_OPERAND (t, 1), &OMP_FOR_PRE_BODY (for_stmt),
+  ret |= gimplify_expr (&PROTECTED_TREE_OPERAND (t, 1),
+			&OMP_FOR_PRE_BODY (for_stmt),
 			NULL, is_gimple_val, fb_rvalue);
 
   tree_to_gimple_tuple (&OMP_FOR_INCR (for_stmt));
Index: tree-outof-ssa.c
===================================================================
--- tree-outof-ssa.c	(revision 118179)
+++ tree-outof-ssa.c	(working copy)
@@ -1574,7 +1574,8 @@ check_replaceable (temp_expr_table_p tab
     return false;
 
   /* Float expressions must go through memory if float-store is on.  */
-  if (flag_float_store && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (stmt, 1))))
+  if (flag_float_store && FLOAT_TYPE_P (TREE_TYPE
+					(PROTECTED_TREE_OPERAND (stmt, 1))))
     return false;
 
   /* Calls to functions with side-effects cannot be replaced.  */
Index: fold-const.c
===================================================================
--- fold-const.c	(revision 118382)
+++ fold-const.c	(working copy)
@@ -8433,7 +8433,8 @@ fold_binary (enum tree_code code, tree t
   tree arg0, arg1, tem;
   tree t1 = NULL_TREE;
 
-  gcc_assert (IS_EXPR_CODE_CLASS (kind)
+  gcc_assert ((IS_EXPR_CODE_CLASS (kind)
+	       || IS_GIMPLE_STMT_CODE_CLASS (kind))
 	      && TREE_CODE_LENGTH (code) == 2
 	      && op0 != NULL_TREE
 	      && op1 != NULL_TREE);
@@ -11534,7 +11535,8 @@ fold (tree expr)
   if (kind == tcc_constant)
     return t;
 
-  if (IS_EXPR_CODE_CLASS (kind))
+  if (IS_EXPR_CODE_CLASS (kind)
+      || IS_GIMPLE_STMT_CODE_CLASS (kind))
     {
       tree type = TREE_TYPE (t);
       tree op0, op1, op2;
Index: fortran/trans-array.c
===================================================================
--- fortran/trans-array.c	(revision 118382)
+++ fortran/trans-array.c	(working copy)
@@ -156,10 +156,18 @@ gfc_conv_descriptor_data_get (tree desc)
   return t;
 }
 
-/* This provides WRITE access to the data field.  */
+/* This provides WRITE access to the data field.
+
+   TUPLES_P is true if we are generating tuples.
+   
+   This function gets called through the following macros:
+     gfc_conv_descriptor_data_set
+     gfc_conv_descriptor_data_set_tuples.  */
 
 void
-gfc_conv_descriptor_data_set (stmtblock_t *block, tree desc, tree value)
+gfc_conv_descriptor_data_set_internal (stmtblock_t *block,
+				       tree desc, tree value,
+				       bool tuples_p)
 {
   tree field, type, t;
 
@@ -170,7 +178,7 @@ gfc_conv_descriptor_data_set (stmtblock_
   gcc_assert (DATA_FIELD == 0);
 
   t = build3 (COMPONENT_REF, TREE_TYPE (field), desc, field, NULL_TREE);
-  gfc_add_modify_expr (block, t, fold_convert (TREE_TYPE (field), value));
+  gfc_add_modify (block, t, fold_convert (TREE_TYPE (field), value), tuples_p);
 }
 
 
Index: fortran/trans-array.h
===================================================================
--- fortran/trans-array.h	(revision 118382)
+++ fortran/trans-array.h	(working copy)
@@ -118,7 +118,11 @@ tree gfc_conv_array_ubound (tree, int);
 
 /* Build expressions for accessing components of an array descriptor.  */
 tree gfc_conv_descriptor_data_get (tree);
-void gfc_conv_descriptor_data_set (stmtblock_t *, tree, tree);
+void gfc_conv_descriptor_data_set_internal (stmtblock_t *, tree, tree, bool);
+#define gfc_conv_descriptor_data_set(BLOCK, T1, T2)			\
+  gfc_conv_descriptor_data_set_internal ((BLOCK), (T1), (T2), false)
+#define gfc_conv_descriptor_data_set_tuples(BLOCK, T1, T2)		\
+  gfc_conv_descriptor_data_set_internal ((BLOCK), (T1), (T2), true)
 tree gfc_conv_descriptor_data_addr (tree);
 tree gfc_conv_descriptor_offset (tree);
 tree gfc_conv_descriptor_dtype (tree);
Index: fortran/trans-openmp.c
===================================================================
--- fortran/trans-openmp.c	(revision 118382)
+++ fortran/trans-openmp.c	(working copy)
@@ -111,7 +111,7 @@ gfc_omp_clause_default_ctor (tree clause
      "not currently allocated" allocation status.  */
   gfc_init_block (&block);
 
-  gfc_conv_descriptor_data_set (&block, decl, null_pointer_node);
+  gfc_conv_descriptor_data_set_tuples (&block, decl, null_pointer_node);
 
   return gfc_finish_block (&block);
 }
@@ -832,7 +832,7 @@ gfc_trans_omp_atomic (gfc_code *code)
 	  tree accum = gfc_create_var (TREE_TYPE (rse.expr), NULL);
 	  gfc_actual_arglist *arg;
 
-	  gfc_add_modify_expr (&block, accum, rse.expr);
+	  gfc_add_modify_stmt (&block, accum, rse.expr);
 	  for (arg = expr2->value.function.actual->next->next; arg;
 	       arg = arg->next)
 	    {
@@ -840,7 +840,7 @@ gfc_trans_omp_atomic (gfc_code *code)
 	      gfc_conv_expr (&rse, arg->expr);
 	      gfc_add_block_to_block (&block, &rse.pre);
 	      x = fold_build2 (op, TREE_TYPE (accum), accum, rse.expr);
-	      gfc_add_modify_expr (&block, accum, x);
+	      gfc_add_modify_stmt (&block, accum, x);
 	    }
 
 	  rse.expr = accum;
@@ -957,11 +957,11 @@ gfc_trans_omp_do (gfc_code *code, stmtbl
   /* Loop body.  */
   if (simple)
     {
-      init = build2_v (MODIFY_EXPR, dovar, from);
+      init = build2_v (GIMPLE_MODIFY_STMT, dovar, from);
       cond = build2 (simple > 0 ? LE_EXPR : GE_EXPR, boolean_type_node,
 		     dovar, to);
       incr = fold_build2 (PLUS_EXPR, type, dovar, step);
-      incr = fold_build2 (MODIFY_EXPR, type, dovar, incr);
+      incr = fold_build2 (GIMPLE_MODIFY_STMT, type, dovar, incr);
       if (pblock != &block)
 	{
 	  pushlevel (0);
@@ -983,10 +983,10 @@ gfc_trans_omp_do (gfc_code *code, stmtbl
       tmp = fold_build2 (TRUNC_DIV_EXPR, type, tmp, step);
       tmp = gfc_evaluate_now (tmp, pblock);
       count = gfc_create_var (type, "count");
-      init = build2_v (MODIFY_EXPR, count, build_int_cst (type, 0));
+      init = build2_v (GIMPLE_MODIFY_STMT, count, build_int_cst (type, 0));
       cond = build2 (LT_EXPR, boolean_type_node, count, tmp);
       incr = fold_build2 (PLUS_EXPR, type, count, build_int_cst (type, 1));
-      incr = fold_build2 (MODIFY_EXPR, type, count, incr);
+      incr = fold_build2 (GIMPLE_MODIFY_STMT, type, count, incr);
 
       if (pblock != &block)
 	{
@@ -998,7 +998,7 @@ gfc_trans_omp_do (gfc_code *code, stmtbl
       /* Initialize DOVAR.  */
       tmp = fold_build2 (MULT_EXPR, type, count, step);
       tmp = build2 (PLUS_EXPR, type, from, tmp);
-      gfc_add_modify_expr (&body, dovar, tmp);
+      gfc_add_modify_stmt (&body, dovar, tmp);
     }
 
   if (!dovar_found)
Index: fortran/trans.c
===================================================================
--- fortran/trans.c	(revision 118382)
+++ fortran/trans.c	(working copy)
@@ -140,11 +140,13 @@ gfc_evaluate_now (tree expr, stmtblock_t
 }
 
 
-/* Build a MODIFY_EXPR node and add it to a given statement block PBLOCK.
-   A MODIFY_EXPR is an assignment: LHS <- RHS.  */
+/* Build a MODIFY_EXPR (or GIMPLE_MODIFY_STMT) node and add it to a
+   given statement block PBLOCK.  A MODIFY_EXPR is an assignment:
+   LHS <- RHS.  */
 
 void
-gfc_add_modify_expr (stmtblock_t * pblock, tree lhs, tree rhs)
+gfc_add_modify (stmtblock_t * pblock, tree lhs, tree rhs,
+		bool tuples_p)
 {
   tree tmp;
 
@@ -157,7 +159,8 @@ gfc_add_modify_expr (stmtblock_t * pbloc
 	      || AGGREGATE_TYPE_P (TREE_TYPE (lhs)));
 #endif
 
-  tmp = fold_build2 (MODIFY_EXPR, void_type_node, lhs, rhs);
+  tmp = fold_build2 (tuples_p ? GIMPLE_MODIFY_STMT : MODIFY_EXPR,
+		     void_type_node, lhs, rhs);
   gfc_add_expr_to_block (pblock, tmp);
 }
 
Index: fortran/trans.h
===================================================================
--- fortran/trans.h	(revision 118382)
+++ fortran/trans.h	(working copy)
@@ -334,8 +334,12 @@ void gfc_trans_vla_type_sizes (gfc_symbo
 void gfc_add_expr_to_block (stmtblock_t *, tree);
 /* Add a block to the end of a block.  */
 void gfc_add_block_to_block (stmtblock_t *, stmtblock_t *);
-/* Add a MODIFY_EXPR to a block.  */
-void gfc_add_modify_expr (stmtblock_t *, tree, tree);
+/* Add a MODIFY_EXPR or a GIMPLE_MODIFY_STMT to a block.  */
+void gfc_add_modify (stmtblock_t *, tree, tree, bool);
+#define gfc_add_modify_expr(BLOCK, LHS, RHS) \
+       gfc_add_modify ((BLOCK), (LHS), (RHS), false)
+#define gfc_add_modify_stmt(BLOCK, LHS, RHS) \
+       gfc_add_modify ((BLOCK), (LHS), (RHS), true)
 
 /* Initialize a statement block.  */
 void gfc_init_block (stmtblock_t *);
Index: fortran/f95-lang.c
===================================================================
--- fortran/f95-lang.c	(revision 118382)
+++ fortran/f95-lang.c	(working copy)
@@ -62,7 +62,8 @@ GTY(())
 
 union lang_tree_node
 GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
-     chain_next ("(union lang_tree_node *)TREE_CHAIN (&%h.generic)")))
+     chain_next ("(GIMPLE_STMT_P (&%h.generic) ? (union lang_tree_node *) 0 : (union lang_tree_node *)TREE_CHAIN (&%h.generic))")))
+
 {
   union tree_node GTY((tag ("0"),
 		       desc ("tree_node_structure (&%h)"))) generic;



More information about the Gcc-patches mailing list