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 sharing-1.c and sharing-1.C (take 2)


On Tue, Oct 18, 2005 at 10:17:08AM -0700, Richard Henderson wrote:
> On Tue, Oct 18, 2005 at 01:02:29PM -0400, Jakub Jelinek wrote:
> > Well, I haven't changed the code in that regard.  is_global_var
> > TREE_READONLY vars will not be in the shared clause, local ones will be
> > as before.  Now I think we have 3 options what to do about TREE_READONLY
> > locals: 1) special case them already on the omp_notice_* level and put them
> > immediately as firstprivate 2) in gimplify_reconstruct_omp_clauses_1
> > put TREE_READONLY shared vars into firstprivate rather than shared clause
> > 3) handle OMP_CLAUSE_SHARED with TREE_READONLY var as
> > OMP_CLAUSE_FIRSTPRIVATE
> > 
> > I think 2) is easiest.
> 
> const int *p;
> int main()
> {
>   const int x = 1;
>   p = &x;
>   #pragma omp parallel
>     {
>       if (p != &x)
> 	abort ();
>     }
>   return 0;
> }

Ok.  Also, it turned out to be better to do this in omp-low.c instead
(as we e.g. shouldn't do that for Fortran references which are usually
const pointers or const references, but firstprivate would pass them
through indirection).

The following updated patch uses get_base_address instead of the loop
I had in as well.

Possible DECL_INITIAL games can be dealt with as a separate change IMHO.

Together with the patch I'll post right away we are down to 0 failures
in g{cc,++}.dg/gomp/ and only 2 in gfortran.dg/gomp/ (plus some still in
libgomp).

Ok for gomp?

2005-10-18  Jakub Jelinek  <jakub@redhat.com>

	* langhooks.h (struct lang_hooks_for_decls): Add
	omp_predetermined_sharing hook.
	* langhooks.c (lhd_omp_predetermined_sharing): New function.
	* langhooks-def.h (lhd_omp_predetermined_sharing): New prototype.
	(LANG_HOOKS_OMP_PREDETERMINED_SHARING): Define.
	(LANG_HOOKS_DECLS): Add LANG_HOOKS_OMP_PREDETERMINED_SHARING.
	* gimplify.c (omp_notice_variable): Only return immediately
	if a global var is DECL_THREAD_LOCAL_P.  Use
	omp_predetermined_sharing langhook.
	(gimplify_reconstruct_omp_clauses_1): Do not add global vars
	into OMP_CLAUSE_SHARED clause.
	* c-common.h (c_omp_predetermined_sharing): New prototype.
	* c-objc-common.h (LANG_HOOKS_OMP_PREDETERMINED_SHARING): Redefine.
	* c-omp.c (c_omp_predetermined_sharing): New function.
	* omp-low.c (scan_sharing_clauses): Handle const shared scalar
	vars as if they were firstprivate.
cp/
	* semantics.c (cxx_omp_predetermined_sharing): New function.
	* cp-tree.h (cxx_omp_predetermined_sharing): New prototype.
	* cp-objcp-common.h (LANG_HOOKS_OMP_PREDETERMINED_SHARING): Redefine.

--- gcc/omp-low.c.jj	2005-10-18 13:06:21.000000000 +0200
+++ gcc/omp-low.c	2005-10-18 19:42:16.000000000 +0200
@@ -516,6 +516,25 @@ scan_sharing_clauses (tree clauses, omp_
 	  install_var_private (decl, ctx);
 	  break;
 
+	case OMP_CLAUSE_SHARED:
+	  gcc_assert (is_parallel_ctx (ctx));
+	  decl = OMP_CLAUSE_DECL (c);
+	  by_ref = use_pointer_for_field (decl, true);
+	  gcc_assert (!is_variable_sized (decl));
+	  if (! TREE_READONLY (decl)
+	      || TREE_ADDRESSABLE (decl)
+	      || by_ref
+	      || is_reference (decl))
+	    {
+	      install_var_field (decl, by_ref, ctx);
+	      install_var_shared (decl, by_ref, ctx);
+	      break;
+	    }
+	  else
+	    /* We don't need to copy const scalar vars back.  */
+	    TREE_SET_CODE (c, OMP_CLAUSE_FIRSTPRIVATE);
+	  /* FALLTHRU */
+
 	case OMP_CLAUSE_FIRSTPRIVATE:
 	case OMP_CLAUSE_LASTPRIVATE:
 	case OMP_CLAUSE_REDUCTION:
@@ -534,15 +553,6 @@ scan_sharing_clauses (tree clauses, omp_
 	  install_var_private (decl, ctx);
 	  break;
 
-	case OMP_CLAUSE_SHARED:
-	  gcc_assert (is_parallel_ctx (ctx));
-	  decl = OMP_CLAUSE_DECL (c);
-	  by_ref = use_pointer_for_field (decl, true);
-	  gcc_assert (!is_variable_sized (decl));
-	  install_var_field (decl, by_ref, ctx);
-	  install_var_shared (decl, by_ref, ctx);
-	  break;
-
 	case OMP_CLAUSE_COPYPRIVATE:
 	  if (ctx->outer)
 	    scan_omp (&OMP_CLAUSE_DECL (c), ctx->outer);
--- gcc/langhooks.h.jj	2005-10-18 08:46:23.000000000 +0200
+++ gcc/langhooks.h	2005-10-18 16:58:29.000000000 +0200
@@ -196,6 +196,10 @@ struct lang_hooks_for_decls
   /* True if OpenMP should privatize what this DECL points to rather
      than the DECL itself.  */
   bool (*omp_privatize_by_reference) (tree);
+
+  /* Return sharing kind if OpenMP sharing attribute of DECL is
+     predetermined, OMP_CLAUSE_DEFAULT_UNSPECIFIED otherwise.  */
+  enum omp_clause_default_kind (*omp_predetermined_sharing) (tree);
 };
 
 /* Language-specific hooks.  See langhooks-def.h for defaults.  */
--- gcc/langhooks.c.jj	2005-10-18 13:11:09.000000000 +0200
+++ gcc/langhooks.c	2005-10-18 17:00:19.000000000 +0200
@@ -550,3 +550,12 @@ lhd_expr_to_decl (tree expr, bool *tc AT
 {
   return expr;
 }
+
+/* Return sharing kind if OpenMP sharing attribute of DECL is
+   predetermined, OMP_CLAUSE_DEFAULT_UNSPECIFIED otherwise.  */
+
+enum omp_clause_default_kind
+lhd_omp_predetermined_sharing (tree decl ATTRIBUTE_UNUSED)
+{
+  return OMP_CLAUSE_DEFAULT_UNSPECIFIED;
+}
--- gcc/gimplify.c.jj	2005-10-18 08:45:34.000000000 +0200
+++ gcc/gimplify.c	2005-10-18 19:37:00.000000000 +0200
@@ -4269,13 +4269,25 @@ omp_notice_variable (struct gimplify_omp
   splay_tree_node n;
   unsigned flags = in_code ? GOVD_SEEN : 0;
 
+  /* Threadprivate variables are predetermined.  */
   if (is_global_var (decl))
-    return;
+    {
+      if (DECL_THREAD_LOCAL_P (decl))
+	return;
+
+      if (DECL_HAS_VALUE_EXPR_P (decl))
+	{
+	  tree value = get_base_address (DECL_VALUE_EXPR (decl));
+
+	  if (value && DECL_P (value) && DECL_THREAD_LOCAL_P (value))
+	    return;
+	}
+    }
 
   n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl);
   if (n == NULL)
     {
-      enum omp_clause_default_kind default_kind;
+      enum omp_clause_default_kind default_kind, kind;
 
       if (!ctx->is_parallel)
 	goto do_outer;
@@ -4286,6 +4298,12 @@ omp_notice_variable (struct gimplify_omp
       default_kind = ctx->default_kind;
       if (DECL_ARTIFICIAL (decl))
 	default_kind = OMP_CLAUSE_DEFAULT_SHARED;
+      else
+	{
+	  kind = lang_hooks.decls.omp_predetermined_sharing (decl);
+	  if (kind != OMP_CLAUSE_DEFAULT_UNSPECIFIED)
+	    default_kind = kind;
+	}
 
       switch (default_kind)
 	{
@@ -4451,7 +4469,11 @@ gimplify_reconstruct_omp_clauses_1 (spla
   if ((flags & GOVD_SEEN) == 0)
     return 0;
   if (flags & GOVD_SHARED)
-    code = OMP_CLAUSE_SHARED;
+    {
+      if (is_global_var (decl))
+	return 0;
+      code = OMP_CLAUSE_SHARED;
+    }
   else if (flags & GOVD_PRIVATE)
     code = OMP_CLAUSE_PRIVATE;
   else if (flags & GOVD_FIRSTPRIVATE)
--- gcc/cp/semantics.c.jj	2005-10-17 09:04:19.000000000 +0200
+++ gcc/cp/semantics.c	2005-10-18 17:27:00.000000000 +0200
@@ -3260,6 +3260,28 @@ finish_omp_parallel (tree clauses, tree 
   return add_stmt (stmt);
 }
 
+/* True if OpenMP sharing attribute of DECL is predetermined.  */
+
+enum omp_clause_default_kind
+cxx_omp_predetermined_sharing (tree decl)
+{
+  enum omp_clause_default_kind kind;
+
+  kind = c_omp_predetermined_sharing (decl);
+  if (kind != OMP_CLAUSE_DEFAULT_UNSPECIFIED)
+    return kind;
+
+  /* Static data members are predetermined as shared.  */
+  if (TREE_STATIC (decl))
+    {
+      tree ctx = CP_DECL_CONTEXT (decl);
+      if (TYPE_P (ctx) && IS_AGGR_TYPE (ctx))
+	return OMP_CLAUSE_DEFAULT_SHARED;
+    }
+
+  return OMP_CLAUSE_DEFAULT_UNSPECIFIED;
+}
+
 /* Perform initialization related to this module.  */
 
 void
--- gcc/cp/cp-tree.h.jj	2005-10-17 09:04:16.000000000 +0200
+++ gcc/cp/cp-tree.h	2005-10-18 17:06:30.000000000 +0200
@@ -4227,6 +4227,7 @@ extern void note_decl_for_pch			(tree);
 extern tree begin_omp_parallel			(void);
 extern tree finish_omp_parallel			(tree, tree);
 extern void finish_omp_threadprivate		(tree);
+extern enum omp_clause_default_kind cxx_omp_predetermined_sharing (tree);
 
 /* in tree.c */
 extern void lang_check_failed			(const char *, int,
--- gcc/cp/cp-objcp-common.h.jj	2005-09-13 15:16:03.000000000 +0200
+++ gcc/cp/cp-objcp-common.h	2005-10-18 17:03:50.000000000 +0200
@@ -151,5 +151,7 @@ extern tree objcp_tsubst_copy_and_build 
 #define LANG_HOOKS_TO_TARGET_CHARSET c_common_to_target_charset
 #undef LANG_HOOKS_GIMPLIFY_EXPR
 #define LANG_HOOKS_GIMPLIFY_EXPR cp_gimplify_expr
+#undef LANG_HOOKS_OMP_PREDETERMINED_SHARING
+#define LANG_HOOKS_OMP_PREDETERMINED_SHARING cxx_omp_predetermined_sharing
 
 #endif /* GCC_CP_OBJCP_COMMON */
--- gcc/c-common.h.jj	2005-10-13 07:47:12.000000000 +0200
+++ gcc/c-common.h	2005-10-18 17:01:03.000000000 +0200
@@ -941,6 +941,7 @@ extern void c_finish_omp_atomic (enum tr
 extern void c_finish_omp_flush (void);
 extern tree c_finish_omp_for (location_t, tree, tree, tree, tree, tree);
 extern void c_split_parallel_clauses (tree, tree *, tree *);
+extern enum omp_clause_default_kind c_omp_predetermined_sharing (tree);
 
 /* Not in c-omp.c; provided by the front end.  */
 extern bool c_omp_sharing_predetermined (tree);
--- gcc/c-objc-common.h.jj	2005-09-13 15:12:33.000000000 +0200
+++ gcc/c-objc-common.h	2005-10-18 16:34:14.000000000 +0200
@@ -134,4 +134,7 @@ extern void c_initialize_diagnostics (di
 #undef LANG_HOOKS_GIMPLIFY_EXPR
 #define LANG_HOOKS_GIMPLIFY_EXPR c_gimplify_expr
 
+#undef LANG_HOOKS_OMP_PREDETERMINED_SHARING
+#define LANG_HOOKS_OMP_PREDETERMINED_SHARING c_omp_predetermined_sharing
+
 #endif /* GCC_C_OBJC_COMMON */
--- gcc/langhooks-def.h.jj	2005-10-18 13:10:54.000000000 +0200
+++ gcc/langhooks-def.h	2005-10-18 16:58:56.000000000 +0200
@@ -88,6 +88,7 @@ extern tree lhd_callgraph_analyze_expr (
 
 /* Declarations for tree gimplification hooks.  */
 extern int lhd_gimplify_expr (tree *, tree *, tree *);
+extern enum omp_clause_default_kind lhd_omp_predetermined_sharing (tree);
 
 #define LANG_HOOKS_NAME			"GNU unknown"
 #define LANG_HOOKS_IDENTIFIER_SIZE	sizeof (struct lang_identifier)
@@ -240,6 +241,7 @@ extern tree lhd_make_node (enum tree_cod
 #define LANG_HOOKS_DECL_OK_FOR_SIBCALL	lhd_decl_ok_for_sibcall
 #define LANG_HOOKS_COMDAT_GROUP lhd_comdat_group
 #define LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE hook_bool_tree_false
+#define LANG_HOOKS_OMP_PREDETERMINED_SHARING lhd_omp_predetermined_sharing
 
 #define LANG_HOOKS_DECLS { \
   LANG_HOOKS_GLOBAL_BINDINGS_P, \
@@ -251,7 +253,8 @@ extern tree lhd_make_node (enum tree_cod
   LANG_HOOKS_PREPARE_ASSEMBLE_VARIABLE, \
   LANG_HOOKS_DECL_OK_FOR_SIBCALL, \
   LANG_HOOKS_COMDAT_GROUP, \
-  LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE \
+  LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE, \
+  LANG_HOOKS_OMP_PREDETERMINED_SHARING \
 }
 
 /* The whole thing.  The structure is defined in langhooks.h.  */
--- gcc/c-omp.c.jj	2005-10-18 13:06:21.000000000 +0200
+++ gcc/c-omp.c	2005-10-18 16:52:20.000000000 +0200
@@ -346,3 +346,16 @@ c_split_parallel_clauses (tree clauses, 
 	}
     }
 }
+
+/* True if OpenMP sharing attribute of DECL is predetermined.  */
+
+enum omp_clause_default_kind
+c_omp_predetermined_sharing (tree decl)
+{
+  /* Variables with const-qualified type having no mutable member
+     are predetermined shared.  */
+  if (TREE_READONLY (decl))
+    return OMP_CLAUSE_DEFAULT_SHARED;
+
+  return OMP_CLAUSE_DEFAULT_UNSPECIFIED;
+}


	Jakub


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