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]

[gomp] fix gcc.dg/gomp/block-7.c


We need to gimplify the OMP_FOR_INIT/COND/INCR expressions in order
that we've got something that we can actually scan later, since we
could just as easily wind up with non-GENERIC tree codes in there.

But doing that and nothing else results in code being moved from
within the structured block to outside the structured block.  While
I'm not sure I can write a conforming test case that can tell the
difference, I still think it's wrong.

Thus the addition of the OMP_FOR_PRE_BODY operand to store stmts
that are logically part of the structured block, but should be 
evaluated before we actually enter the loop.


r~


        * tree.def (OMP_FOR): Increase size.
        * tree.h (OMP_FOR_PRE_BODY): New.
        * gimplify.c (gimplify_omp_for): Use OMP_FOR_PRE_BODY for pre-queue
        for the INIT, COND, or INCR expressions.
        * omp-low.c (scan_omp_for): Scan OMP_FOR_PRE_BODY.
        (scan_omp_nested): Likewise.
        (expand_omp_for_1): Expand OMP_FOR_PRE_BODY.
        (diagnose_sb_1, diagnose_sb_2): Scan all OMP_FOR fields.
        * tree-pretty-print.c (dump_generic_node) <OMP_FOR>: Handle
        printing OMP_FOR_PRE_BODY.

Index: gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gimplify.c,v
retrieving revision 2.135.4.34
diff -u -p -d -r2.135.4.34 gimplify.c
--- gimplify.c	20 Oct 2005 09:02:08 -0000	2.135.4.34
+++ gimplify.c	22 Oct 2005 00:28:16 -0000
@@ -4547,14 +4547,14 @@ 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), pre_p, NULL,
-			is_gimple_val, fb_rvalue);
+  ret |= gimplify_expr (&TREE_OPERAND (t, 1), &OMP_FOR_PRE_BODY (for_stmt),
+			NULL, is_gimple_val, fb_rvalue);
 
   t = OMP_FOR_COND (for_stmt);
   gcc_assert (COMPARISON_CLASS_P (t));
   gcc_assert (TREE_OPERAND (t, 0) == decl);
-  ret |= gimplify_expr (&TREE_OPERAND (t, 1), pre_p, NULL,
-			is_gimple_val, fb_rvalue);
+  ret |= gimplify_expr (&TREE_OPERAND (t, 1), &OMP_FOR_PRE_BODY (for_stmt),
+			NULL, is_gimple_val, fb_rvalue);
 
   t = OMP_FOR_INCR (for_stmt);
   switch (TREE_CODE (t))
@@ -4591,8 +4591,9 @@ gimplify_omp_for (tree *expr_p, tree *pr
 	default:
 	  gcc_unreachable ();
 	}
-      ret |= gimplify_expr (&TREE_OPERAND (t, 1), pre_p, NULL,
-			    is_gimple_val, fb_rvalue);
+      ret |= gimplify_expr (&TREE_OPERAND (t, 1),
+			    &OMP_FOR_PRE_BODY (for_stmt),
+			    NULL, is_gimple_val, fb_rvalue);
       break;
 
     default:
@@ -4600,7 +4601,6 @@ gimplify_omp_for (tree *expr_p, tree *pr
     }
 
   gimplify_to_stmt_list (&OMP_FOR_BODY (for_stmt));
-
   gimplify_reconstruct_omp_clauses (&OMP_FOR_CLAUSES (for_stmt));
 
   return ret == GS_ALL_DONE ? GS_ALL_DONE : GS_ERROR;
Index: omp-low.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/omp-low.c,v
retrieving revision 1.1.2.34
diff -u -p -d -r1.1.2.34 omp-low.c
--- omp-low.c	21 Oct 2005 23:56:52 -0000	1.1.2.34
+++ omp-low.c	22 Oct 2005 00:28:17 -0000
@@ -720,6 +720,7 @@ scan_omp_for (tree *stmt_p, omp_context 
       install_var_private (iter, pctx);
     }
 
+  scan_omp (&OMP_FOR_PRE_BODY (stmt), ctx);
   scan_omp (&OMP_FOR_INIT (stmt), ctx);
   scan_omp (&OMP_FOR_COND (stmt), ctx);
   scan_omp (&OMP_FOR_INCR (stmt), ctx);
@@ -829,6 +830,7 @@ scan_omp_nested (tree *stmt_p, omp_conte
 
   if (TREE_CODE (stmt) == OMP_FOR)
     {
+      scan_omp (&OMP_FOR_PRE_BODY (stmt), ctx);
       scan_omp (&OMP_FOR_INIT (stmt), ctx);
       scan_omp (&OMP_FOR_COND (stmt), ctx);
       scan_omp (&OMP_FOR_INCR (stmt), ctx);
@@ -2215,6 +2217,9 @@ expand_omp_for_1 (tree *stmt_p, omp_cont
 
   expand_rec_input_clauses (OMP_FOR_CLAUSES (fd.for_stmt), &fd.pre, ctx);
 
+  expand_omp (&OMP_FOR_PRE_BODY (fd.for_stmt), ctx);
+  append_to_statement_list (OMP_FOR_PRE_BODY (fd.for_stmt), &fd.pre);
+
   if (sched_kind == OMP_CLAUSE_SCHEDULE_STATIC && !have_ordered)
     {
       if (fd.chunk_size == NULL)
@@ -2908,7 +2913,6 @@ diagnose_sb_1 (tree *tp, int *walk_subtr
   switch (TREE_CODE (t))
     {
     case OMP_PARALLEL:
-    case OMP_FOR:
     case OMP_SECTIONS:
     case OMP_SINGLE:
       walk_tree (&OMP_CLAUSES (t), diagnose_sb_1, wi, NULL);
@@ -2924,6 +2928,17 @@ diagnose_sb_1 (tree *tp, int *walk_subtr
       wi->info = context;
       break;
 
+    case OMP_FOR:
+      walk_tree (&OMP_FOR_CLAUSES (t), diagnose_sb_1, wi, NULL);
+      wi->info = t;
+      walk_tree (&OMP_FOR_INIT (t), diagnose_sb_1, wi, NULL);
+      walk_tree (&OMP_FOR_COND (t), diagnose_sb_1, wi, NULL);
+      walk_tree (&OMP_FOR_INCR (t), diagnose_sb_1, wi, NULL);
+      walk_stmts (wi, &OMP_FOR_PRE_BODY (t));
+      walk_stmts (wi, &OMP_FOR_BODY (t));
+      wi->info = context;
+      break;
+
     case LABEL_EXPR:
       splay_tree_insert (all_labels, (splay_tree_key) LABEL_EXPR_LABEL (t),
 			 (splay_tree_value) context);
@@ -2951,7 +2966,6 @@ diagnose_sb_2 (tree *tp, int *walk_subtr
   switch (TREE_CODE (t))
     {
     case OMP_PARALLEL:
-    case OMP_FOR:
     case OMP_SECTIONS:
     case OMP_SINGLE:
       walk_tree (&OMP_CLAUSES (t), diagnose_sb_2, wi, NULL);
@@ -2965,6 +2979,17 @@ diagnose_sb_2 (tree *tp, int *walk_subtr
       wi->info = context;
       break;
 
+    case OMP_FOR:
+      walk_tree (&OMP_FOR_CLAUSES (t), diagnose_sb_2, wi, NULL);
+      wi->info = t;
+      walk_tree (&OMP_FOR_INIT (t), diagnose_sb_2, wi, NULL);
+      walk_tree (&OMP_FOR_COND (t), diagnose_sb_2, wi, NULL);
+      walk_tree (&OMP_FOR_INCR (t), diagnose_sb_2, wi, NULL);
+      walk_stmts (wi, &OMP_FOR_PRE_BODY (t));
+      walk_stmts (wi, &OMP_FOR_BODY (t));
+      wi->info = context;
+      break;
+
     case GOTO_EXPR:
       {
 	tree lab = GOTO_DESTINATION (t);
Index: tree-pretty-print.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-pretty-print.c,v
retrieving revision 2.61.4.19
diff -u -p -d -r2.61.4.19 tree-pretty-print.c
--- tree-pretty-print.c	20 Oct 2005 09:58:17 -0000	2.61.4.19
+++ tree-pretty-print.c	22 Oct 2005 00:28:17 -0000
@@ -1675,6 +1675,15 @@ dump_generic_node (pretty_printer *buffe
     case OMP_FOR:
       pp_string (buffer, "#pragma omp for ");
       dump_omp_clauses (buffer, OMP_FOR_CLAUSES (node), spc, flags);
+      if (OMP_FOR_PRE_BODY (node))
+	{
+	  newline_and_indent (buffer, spc + 2);
+	  pp_character (buffer, '{');
+	  spc += 4;
+	  newline_and_indent (buffer, spc);
+	  dump_generic_node (buffer, OMP_FOR_PRE_BODY (node),
+			     spc, flags, false);
+	}
       newline_and_indent (buffer, spc);
       pp_string (buffer, "for (");
       dump_generic_node (buffer, OMP_FOR_INIT (node), spc, flags, false);
@@ -1683,7 +1692,20 @@ dump_generic_node (pretty_printer *buffe
       pp_string (buffer, "; ");
       dump_generic_node (buffer, OMP_FOR_INCR (node), spc, flags, false);
       pp_string (buffer, ")");
-      goto dump_omp_body;
+      newline_and_indent (buffer, spc + 2);
+      pp_character (buffer, '{');
+      newline_and_indent (buffer, spc + 4);
+      dump_generic_node (buffer, OMP_FOR_BODY (node), spc + 4, flags, false);
+      newline_and_indent (buffer, spc + 2);
+      pp_character (buffer, '}');
+      if (OMP_FOR_PRE_BODY (node))
+	{
+	  spc -= 4;
+	  newline_and_indent (buffer, spc + 2);
+	  pp_character (buffer, '}');
+	}
+      is_expr = false;
+      break;
 
     case OMP_SECTIONS:
       pp_string (buffer, "#pragma omp sections ");
Index: tree.def
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.def,v
retrieving revision 1.116.4.20
diff -u -p -d -r1.116.4.20 tree.def
--- tree.def	20 Oct 2005 09:02:08 -0000	1.116.4.20
+++ tree.def	22 Oct 2005 00:28:17 -0000
@@ -963,13 +963,17 @@ DEFTREECODE (OMP_PARALLEL, "omp_parallel
                              	VAR { <, >, <=, >= } N2.
    Operand 4: OMP_FOR_INCR: Loop index increment of the form
 			     	VAR { +=, -= } INCR.
+   Operand 5: OMP_FOR_PRE_BODY: Filled by the gimplifier with things
+	from INIT, COND, and INCR that are technically part of the
+	OMP_FOR structured block, but are evaluated before the loop
+	body begins.
 
    VAR must be a signed integer variable, which is implicitly thread
    private.  N1, N2 and INCR are required to be loop invariant integer
    expressions that are evaluated without any synchronization.
    The evaluation order, frequency of evaluation and side-effects are
    unspecified by the standard.  */
-DEFTREECODE (OMP_FOR, "omp_for", tcc_statement, 5)
+DEFTREECODE (OMP_FOR, "omp_for", tcc_statement, 6)
 
 /* OpenMP - #pragma omp sections [clause1 ... clauseN]
    Operand 0: OMP_SECTIONS_BODY: Sections body.
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.735.4.23
diff -u -p -d -r1.735.4.23 tree.h
--- tree.h	20 Oct 2005 09:02:09 -0000	1.735.4.23
+++ tree.h	22 Oct 2005 00:28:18 -0000
@@ -1404,6 +1404,7 @@ struct tree_constructor GTY(())
 #define OMP_FOR_INIT(NODE)	   TREE_OPERAND (OMP_FOR_CHECK (NODE), 2)
 #define OMP_FOR_COND(NODE)	   TREE_OPERAND (OMP_FOR_CHECK (NODE), 3)
 #define OMP_FOR_INCR(NODE)	   TREE_OPERAND (OMP_FOR_CHECK (NODE), 4)
+#define OMP_FOR_PRE_BODY(NODE)	   TREE_OPERAND (OMP_FOR_CHECK (NODE), 5)
 
 #define OMP_SECTIONS_BODY(NODE)    TREE_OPERAND (OMP_SECTIONS_CHECK (NODE), 0)
 #define OMP_SECTIONS_CLAUSES(NODE) TREE_OPERAND (OMP_SECTIONS_CHECK (NODE), 1)


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