[gomp] fix type mapping and nested function problems

Richard Henderson rth@redhat.com
Tue Nov 1 01:22:00 GMT 2005


On Mon, Oct 31, 2005 at 05:58:42PM -0500, Jakub Jelinek wrote:
> subroutine foo (e, n)
>     integer omp_get_thread_num
>     integer :: n
>     integer, dimension (2, 3:5, n) :: e
>     logical :: l
>     integer :: p, q, r
>     l = .false.
> !$omp parallel default (none) firstprivate (e) &
> !$omp & reduction (.or.:l) num_threads (6) &
> !$omp private (p, q, r)
>     do 100, p = 1, 2
>       do 100, q = 3, 7
>         do 100, r = 1, 7
>           if (q .lt. 6) l = l .or. e(p, q, r) .ne. 5 + p + q + 2 * r
> 100 continue
> !$omp end parallel
>     if (l) call abort
> end subroutine foo

Hum.  I'd have thought that just the gimplify.c hunk here would have
done the job, but it turns out that some of the parameters havn't
been gimplified.  Fixing that with the function.c hunks reveals that
the Fortran front end is using variables in the type definitions, and
these variables aren't defined at the point the parameters are
processed.

My guess is that Fortran should avoid creating its own variables 
in type parameters, and instead rely on SAVE_EXPRs.


r~



Index: function.c
===================================================================
--- function.c	(revision 106309)
+++ function.c	(working copy)
@@ -3058,30 +3058,6 @@ assign_parms (tree fndecl)
     }
 }
 
-/* A subroutine of gimplify_parameters, invoked via walk_tree.
-   For all seen types, gimplify their sizes.  */
-
-static tree
-gimplify_parm_type (tree *tp, int *walk_subtrees, void *data)
-{
-  tree t = *tp;
-
-  *walk_subtrees = 0;
-  if (TYPE_P (t))
-    {
-      if (POINTER_TYPE_P (t))
-	*walk_subtrees = 1;
-      else if (TYPE_SIZE (t) && !TREE_CONSTANT (TYPE_SIZE (t))
-	       && !TYPE_SIZES_GIMPLIFIED (t))
-	{
-	  gimplify_type_sizes (t, (tree *) data);
-	  *walk_subtrees = 1;
-	}
-    }
-
-  return NULL;
-}
-
 /* Gimplify the parameter list for current_function_decl.  This involves
    evaluating SAVE_EXPRs of variable sized parameters and generating code
    to implement callee-copies reference parameters.  Returns a list of
@@ -3116,8 +3092,8 @@ gimplify_parameters (void)
 	 SAVE_EXPRs (amongst others) onto a pending sizes list.  This
 	 turned out to be less than manageable in the gimple world.
 	 Now we have to hunt them down ourselves.  */
-      walk_tree_without_duplicates (&data.passed_type,
-				    gimplify_parm_type, &stmts);
+      gimplify_type_sizes (data.nominal_type, &stmts);
+      gimplify_type_sizes (data.passed_type, &stmts);
 
       if (!TREE_CONSTANT (DECL_SIZE (parm)))
 	{
Index: gimplify.c
===================================================================
--- gimplify.c	(revision 106309)
+++ gimplify.c	(working copy)
@@ -4256,7 +4256,6 @@ omp_add_variable (struct gimplify_omp_ct
 
       /* Add all of the variable and type parameters (which should have
 	 been gimplified to a formal temporary) as FIRSTPRIVATE.  */
-      nflags = flags & GOVD_SHARED ? 0 : GOVD_SEEN;
       omp_firstprivatize_variable (ctx, DECL_SIZE_UNIT (decl));
       omp_firstprivatize_variable (ctx, DECL_SIZE (decl));
       omp_firstprivatize_type_sizes (ctx, TREE_TYPE (decl));
@@ -4274,6 +4273,20 @@ omp_add_variable (struct gimplify_omp_ct
       else
 	omp_notice_variable (ctx, TYPE_SIZE_UNIT (TREE_TYPE (decl)), true);
     }
+  else if (lang_hooks.decls.omp_privatize_by_reference (decl))
+    {
+      gcc_assert ((flags & GOVD_LOCAL) == 0);
+      omp_firstprivatize_type_sizes (ctx, TREE_TYPE (decl));
+
+      /* Similar to the direct variable sized case above, we'll need the
+	 size of references being privatized.  */
+      if ((flags & GOVD_SHARED) == 0)
+	{
+	  t = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl)));
+	  if (!TREE_CONSTANT (t))
+	    omp_notice_variable (ctx, t, true);
+	}
+    }
 
   splay_tree_insert (ctx->variables, (splay_tree_key)decl, flags);
 }



More information about the Fortran mailing list