Re: [gomp4 3/6] Initial support for OpenACC memory mapping semantics.

2014-11-13 Thread Thomas Schwinge
Hi!

On Tue, 14 Jan 2014 16:10:05 +0100, I wrote:
 --- gcc/gimplify.c
 +++ gcc/gimplify.c
 @@ -69,7 +69,13 @@ enum gimplify_omp_var_data

 +  /* Force a specific behavior (or else, a run-time error).  */
 +  GOVD_MAP_FORCE = 16384,

 @@ -86,7 +92,11 @@ enum omp_region_type

 +  /* Default to GOVD_MAP_FORCE for implicit mappings in this region.  */
 +  ORT_TARGET_MAP_FORCE = 64
  };

 @@ -6135,9 +6197,14 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, void 
 *data)
  OMP_CLAUSE_PRIVATE_OUTER_REF (clause) = 1;
else if (code == OMP_CLAUSE_MAP)
  {
 -  OMP_CLAUSE_MAP_KIND (clause) = flags  GOVD_MAP_TO_ONLY
 -  ? OMP_CLAUSE_MAP_TO
 -  : OMP_CLAUSE_MAP_TOFROM;
 +  unsigned map_kind;
 +  map_kind = (flags  GOVD_MAP_TO_ONLY
 +   ? OMP_CLAUSE_MAP_TO
 +   : OMP_CLAUSE_MAP_TOFROM);
 +  if (flags  GOVD_MAP_FORCE)
 + map_kind |= OMP_CLAUSE_MAP_FORCE;
 +  OMP_CLAUSE_MAP_KIND (clause) = (enum omp_clause_map_kind) map_kind;
 +
if (DECL_SIZE (decl)
  TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
   {
 @@ -6389,9 +6456,10 @@ gimplify_oacc_parallel (tree *expr_p, gimple_seq 
 *pre_p)
tree expr = *expr_p;
gimple g;
gimple_seq body = NULL;
 +  enum omp_region_type ort =
 +(enum omp_region_type) (ORT_TARGET | ORT_TARGET_MAP_FORCE);
  
 -  gimplify_scan_omp_clauses (OACC_PARALLEL_CLAUSES (expr), pre_p,
 -  ORT_TARGET);
 +  gimplify_scan_omp_clauses (OACC_PARALLEL_CLAUSES (expr), pre_p, ort);
  
push_gimplify_context ();

I don't remember what I have been thinking when implementing this -- per
the OpenACC specification's rules for implicitly determined data
attributes, it should be present_or_copy (that is, OpenMP's tofrom,
without force semantics), and firstprivate/copy for scalar variables
for the parallel/kernels constructs, respectively (which is still to be
implemented, for now not considering scalar variables different from
non-scalar ones).  Committed to gomp-4_0-branch in r217482:

commit 7058203891bd6e1696763603673090f161e172b8
Author: tschwinge tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4
Date:   Thu Nov 13 12:18:34 2014 +

Middle end: Don't use mapping kinds with force semantics for OpenACC.

..., which is the wrong thing to do.  Also extend libgomp to actually
distinguish between non-force/force semantics.

gcc/
* gimplify.c (gimplify_omp_workshare) OACC_DATA, OACC_KERNELS,
OACC_PARALLEL: Don't request ORT_TARGET_MAP_FORCE.
(enum gimplify_omp_var_data, enum omp_region_type): Remove
GOVD_MAP_FORCE, and ORT_TARGET_MAP_FORCE, respectively.  Update
all users.
include/
* gomp-constants.h: Define _GOMP_MAP_FLAG_SPECIAL and
_GOMP_MAP_FLAG_FORCE.
libgomp/
* target.c (gomp_map_vars_existing): Error out if force
semantics.
(gomp_map_vars): Actually pass kinds to gomp_map_vars_existing.
Remove FIXMEs.
* testsuite/libgomp.oacc-c-c++-common/data-already-1.c: New file.
* testsuite/libgomp.oacc-c-c++-common/data-already-2.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/data-already-3.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/data-already-4.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/data-already-5.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/data-already-6.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/data-already-7.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/data-already-8.c: Likewise.
* testsuite/libgomp.oacc-fortran/data-already-1.f: Likewise.
* testsuite/libgomp.oacc-fortran/data-already-2.f: Likewise.
* testsuite/libgomp.oacc-fortran/data-already-3.f: Likewise.
* testsuite/libgomp.oacc-fortran/data-already-4.f: Likewise.
* testsuite/libgomp.oacc-fortran/data-already-5.f: Likewise.
* testsuite/libgomp.oacc-fortran/data-already-6.f: Likewise.
* testsuite/libgomp.oacc-fortran/data-already-7.f: Likewise.
* testsuite/libgomp.oacc-fortran/data-already-8.f: Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@217482 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog.gomp |  6 ++
 gcc/gimplify.c | 65 +++---
 include/ChangeLog.gomp |  4 ++
 include/gomp-constants.h   |  3 +
 libgomp/ChangeLog.gomp | 23 
 libgomp/target.c   | 21 ---
 .../libgomp.oacc-c-c++-common/data-already-1.c | 19 +++
 .../libgomp.oacc-c-c++-common/data-already-2.c | 16 ++
 .../libgomp.oacc-c-c++-common/data-already-3.c | 17 ++
 .../libgomp.oacc-c-c++-common/data-already-4.c | 17 ++
 

Re: [gomp4 3/6] Initial support for OpenACC memory mapping semantics.

2014-11-13 Thread Jakub Jelinek
On Thu, Nov 13, 2014 at 01:19:55PM +0100, Thomas Schwinge wrote:
 --- include/gomp-constants.h
 +++ include/gomp-constants.h
 @@ -28,6 +28,9 @@
  /* Enumerated variable mapping types used to communicate between GCC and
 libgomp.  These values are used for both OpenMP and OpenACC.  */
  
 +#define _GOMP_MAP_FLAG_SPECIAL   (1  2)
 +#define _GOMP_MAP_FLAG_FORCE (1  3)

I'm worried about reserved namespace issues if you use _ followed by
capital letter.  Can't it be just GOMP_MAP_FLAG_* ?

Jakub


Re: [gomp4 3/6] Initial support for OpenACC memory mapping semantics.

2014-02-21 Thread Thomas Schwinge
Hi!

On Tue, 14 Jan 2014 16:10:05 +0100, I wrote:
 --- gcc/gimplify.c
 +++ gcc/gimplify.c
 @@ -86,7 +92,11 @@ enum omp_region_type
ORT_UNTIED_TASK = 5,
ORT_TEAMS = 8,
ORT_TARGET_DATA = 16,
 -  ORT_TARGET = 32
 +  ORT_TARGET = 32,
 +
 +  /* Flags for ORT_TARGET.  */
 +  /* Default to GOVD_MAP_FORCE for implicit mappings in this region.  */
 +  ORT_TARGET_MAP_FORCE = 64
  };

Continuing on that route, I have now applied the following to
gomp-4_0-branch in r208014:

commit dee2965ae547af0bc90d618e7fa40fbf2f5292b4
Author: tschwinge tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4
Date:   Fri Feb 21 19:45:12 2014 +

Gimplification: New flag ORT_TARGET_OFFLOAD replaces !ORT_TARGET_DATA.

gcc/
* gimplify.c (enum omp_region_type): Make ORT_TARGET_OFFLOAD a
flag for ORT_TARGET, in its negation replacing ORT_TARGET_DATA.
Update all users.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@208014 
138bc75d-0d04-0410-961f-82ee72b054a4

diff --git gcc/ChangeLog.gomp gcc/ChangeLog.gomp
index 1ce952d..bf8ec96 100644
--- gcc/ChangeLog.gomp
+++ gcc/ChangeLog.gomp
@@ -1,5 +1,9 @@
 2014-02-21  Thomas Schwinge  tho...@codesourcery.com
 
+   * gimplify.c (enum omp_region_type): Make ORT_TARGET_OFFLOAD a
+   flag for ORT_TARGET, in its negation replacing ORT_TARGET_DATA.
+   Update all users.
+
* omp-low.c (gimple_code_is_oacc): Move to...
* gimple.h (is_gimple_omp_oacc_specifically): ... here.  Update
users, and also use it in more places where currently we've only
diff --git gcc/gimplify.c gcc/gimplify.c
index 51a1b73..9aa9301c 100644
--- gcc/gimplify.c
+++ gcc/gimplify.c
@@ -100,10 +100,11 @@ enum omp_region_type
   ORT_TASK = 4,
   ORT_UNTIED_TASK = 5,
   ORT_TEAMS = 8,
-  ORT_TARGET_DATA = 16,
-  ORT_TARGET = 32,
+  ORT_TARGET = 16,
 
   /* Flags for ORT_TARGET.  */
+  /* Prepare this region for offloading.  */
+  ORT_TARGET_OFFLOAD = 32,
   /* Default to GOVD_MAP_FORCE for implicit mappings in this region.  */
   ORT_TARGET_MAP_FORCE = 64
 };
@@ -2202,7 +2203,7 @@ gimplify_arg (tree *arg_p, gimple_seq *pre_p, location_t 
call_location)
   return gimplify_expr (arg_p, pre_p, NULL, test, fb);
 }
 
-/* Don't fold STMT inside ORT_TARGET, because it can break code by adding decl
+/* Don't fold inside offloading regsion: it can break code by adding decl
references that weren't in the source.  We'll do it during omplower pass
instead.  */
 
@@ -2211,7 +2212,8 @@ maybe_fold_stmt (gimple_stmt_iterator *gsi)
 {
   struct gimplify_omp_ctx *ctx;
   for (ctx = gimplify_omp_ctxp; ctx; ctx = ctx-outer_context)
-if (ctx-region_type  ORT_TARGET)
+if (ctx-region_type  ORT_TARGET
+ctx-region_type  ORT_TARGET_OFFLOAD)
   return false;
   return fold_stmt (gsi);
 }
@@ -5388,10 +5390,12 @@ omp_firstprivatize_variable (struct gimplify_omp_ctx 
*ctx, tree decl)
return;
}
   else if (ctx-region_type  ORT_TARGET)
-   omp_add_variable (ctx, decl, GOVD_MAP | GOVD_MAP_TO_ONLY);
+   {
+ if (ctx-region_type  ORT_TARGET_OFFLOAD)
+   omp_add_variable (ctx, decl, GOVD_MAP | GOVD_MAP_TO_ONLY);
+   }
   else if (ctx-region_type != ORT_WORKSHARE
-   ctx-region_type != ORT_SIMD
-   ctx-region_type != ORT_TARGET_DATA)
+   ctx-region_type != ORT_SIMD)
omp_add_variable (ctx, decl, GOVD_FIRSTPRIVATE);
 
   ctx = ctx-outer_context;
@@ -5580,7 +5584,8 @@ omp_notice_threadprivate_variable (struct 
gimplify_omp_ctx *ctx, tree decl,
   struct gimplify_omp_ctx *octx;
 
   for (octx = ctx; octx; octx = octx-outer_context)
-if (octx-region_type  ORT_TARGET)
+if ((octx-region_type  ORT_TARGET)
+(octx-region_type  ORT_TARGET_OFFLOAD))
   {
gcc_assert (!(octx-region_type  ORT_TARGET_MAP_FORCE));
 
@@ -5643,7 +5648,8 @@ omp_notice_variable (struct gimplify_omp_ctx *ctx, tree 
decl, bool in_code)
 }
 
   n = splay_tree_lookup (ctx-variables, (splay_tree_key)decl);
-  if (ctx-region_type  ORT_TARGET)
+  if ((ctx-region_type  ORT_TARGET)
+   (ctx-region_type  ORT_TARGET_OFFLOAD))
 {
   unsigned map_force;
   if (ctx-region_type  ORT_TARGET_MAP_FORCE)
@@ -5695,7 +5701,8 @@ omp_notice_variable (struct gimplify_omp_ctx *ctx, tree 
decl, bool in_code)
 
   if (ctx-region_type == ORT_WORKSHARE
  || ctx-region_type == ORT_SIMD
- || ctx-region_type == ORT_TARGET_DATA)
+ || ((ctx-region_type  ORT_TARGET)
+  !(ctx-region_type  ORT_TARGET_OFFLOAD)))
goto do_outer;
 
   /* ??? Some compiler-generated variables (like SAVE_EXPRs) could be
@@ -5746,7 +5753,7 @@ omp_notice_variable (struct gimplify_omp_ctx *ctx, tree 
decl, bool in_code)
{
  splay_tree_node n2;
 
- if ((octx-region_type  (ORT_TARGET_DATA | ORT_TARGET)) != 0)
+ if (octx-region_type  ORT_TARGET)
continue;
  n2 =