'gomp_map_vars' locking protocol (was: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior - runtime)

2020-05-19 Thread Thomas Schwinge
Hi Jakub, Julian!

Can you please help me understand the following:

On 2018-06-19T10:01:20-0700, Cesar Philippidis  wrote:
> This patch implements the OpenACC 2.5 data clause semantics in libgomp.

(This got committed as r261813, 2018-06-20.  The code has seen some
changes in the mean time, but the underlying issue remains.)

> --- a/libgomp/oacc-mem.c
> +++ b/libgomp/oacc-mem.c

> @@ -347,6 +347,7 @@ acc_map_data (void *h, void *d, size_t s)
>
>tgt = gomp_map_vars (acc_dev, mapnum, , , ,
>  , true, GOMP_MAP_VARS_OPENACC);
> +  tgt->list[0].key->refcount = REFCOUNT_INFINITY;
>  }
>
>gomp_mutex_lock (_dev->lock);

Without 'acc_dev->lock' locked, we here touch the 'refcount' (via
'tgt->list[0].key->refcount'), as returned from 'gomp_map_vars' in the
case when entering a new mapping.

> @@ -483,6 +492,8 @@ present_create_copy (unsigned f, void *h, size_t s)
>
>tgt = gomp_map_vars (acc_dev, mapnum, , NULL, , , 
> true,
>  GOMP_MAP_VARS_OPENACC);
> +  /* Initialize dynamic refcount.  */
> +  tgt->list[0].key->dynamic_refcount = 1;
>
>gomp_mutex_lock (_dev->lock);

Likewise here, for the 'dynamic_refcount' (via
'tgt->list[0].key->dynamic_refcount'), as returned from 'gomp_map_vars'
in the case when entering a new mapping.

By construction, it is safe to assume that 'tgt->list[0].key' is the 'n'
we're looking to modify: this is the case where we're entering a new
mapping.

But: is it safe to access this unlocked?  It may seem so, as the new
mapping has not yet been exposed to user code, so only exists internal in
the respective libgomp functions.  Yet, could still a concurrent
'acc_unmap_data'/'acc_delete'/etc. already "see" it (that is, look it up,
as it already has been entered into the mapping table), and unmap while
we're accessing 'tgt->list[0].key' here?

(Hmm, and actually a similar issue, if we consider the case of two
'gomp_map_vars' running concurrently?)

In that case, I suppose we should change the 'gomp_map_vars' interface
and all callers so that 'gomp_map_vars' always takes the device locked.
That doesn't appear problematic: locking the device is one of the first
things 'gomp_map_vars' does anyway (just not in the 'mapnum == 0' case,
but I suppose it's OK to pessimize that one?), and it remains locked
until the end of the function.


Grüße
 Thomas
-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter


Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior

2019-12-18 Thread Thomas Schwinge
Hi!

On 2018-05-25T13:01:58-0700, Cesar Philippidis  wrote:
> This patch updates GCC's to support OpenACC 2.5's data clause semantics. 

Per  "OpenACC 2.5: 'acc_delete' etc. on
non-present data is a no-op", which this patch didn't address.

I wanted to delay fixing this until I got the intended OpenACC 2.6 ff.
semantics clarified with the OpenACC Technical Committee, but it turned
out that fixing this now would be useful for other reasons, so see
attached "[PR92726, PR92970, PR92984] [OpenACC] Clarify 'acc_delete'
etc. for 'NULL'-in, non-present data, or size zero"; committed to trunk
in r279532.

More C/C++ and also Fortran test cases (that exercises all the different
code paths that we have in 'libgomp/oacc-mem.c:GOACC_enter_exit_data',
related to 'find_pointer' handling etc.) shall then follow later (no
hurry with that).


Grüße
 Thomas


From f7b1686558c2515511917aaeb74269b7e85ae09b Mon Sep 17 00:00:00 2001
From: tschwinge 
Date: Wed, 18 Dec 2019 17:01:11 +
Subject: [PATCH] [PR92726, PR92970, PR92984] [OpenACC] Clarify 'acc_delete'
 etc. for 'NULL'-in, non-present data, or size zero

PR92970 "OpenACC 2.5: 'acc_delete' etc. on non-present data is a no-op" is an
actual bug fix, and the other ones are fall-out, currently undefined behavior.

	libgomp/
	PR libgomp/92726
	PR libgomp/92970
	PR libgomp/92984
	* oacc-mem.c (delete_copyout): No-op behavior if 'lookup_host'
	fails.
	(GOACC_enter_exit_data): Simplify accordingly.
	* testsuite/libgomp.oacc-c-c++-common/pr92970-1.c: New file,
	subsuming...
	* testsuite/libgomp.oacc-c-c++-common/lib-17.c: ... this file...
	* testsuite/libgomp.oacc-c-c++-common/lib-18.c: ..., and this
	file.
	* testsuite/libgomp.oacc-c-c++-common/pr92984-1.c: New file,
	subsuming...
	* testsuite/libgomp.oacc-c-c++-common/lib-21.c: ... this file...
	* testsuite/libgomp.oacc-c-c++-common/lib-29.c: ..., and this
	file.
	* testsuite/libgomp.oacc-c-c++-common/pr92726-1.c: New file,
	subsuming...
	* testsuite/libgomp.oacc-c-c++-common/lib-28.c: ... this file.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@279532 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libgomp/ChangeLog |  20 
 libgomp/oacc-mem.c|  28 ++---
 .../libgomp.oacc-c-c++-common/lib-17.c|  38 ---
 .../libgomp.oacc-c-c++-common/lib-18.c|  38 ---
 .../libgomp.oacc-c-c++-common/lib-21.c|  35 --
 .../libgomp.oacc-c-c++-common/lib-28.c|  32 --
 .../libgomp.oacc-c-c++-common/lib-29.c|  32 --
 .../libgomp.oacc-c-c++-common/pr92726-1.c |  26 +
 .../libgomp.oacc-c-c++-common/pr92970-1.c |  33 ++
 .../libgomp.oacc-c-c++-common/pr92984-1.c | 100 ++
 10 files changed, 190 insertions(+), 192 deletions(-)
 delete mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/lib-17.c
 delete mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/lib-18.c
 delete mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/lib-21.c
 delete mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/lib-28.c
 delete mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/lib-29.c
 create mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/pr92726-1.c
 create mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/pr92970-1.c
 create mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/pr92984-1.c

diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog
index c4283fdfe1d..871a1537c77 100644
--- a/libgomp/ChangeLog
+++ b/libgomp/ChangeLog
@@ -1,5 +1,25 @@
 2019-12-18  Thomas Schwinge  
 
+	PR libgomp/92726
+	PR libgomp/92970
+	PR libgomp/92984
+	* oacc-mem.c (delete_copyout): No-op behavior if 'lookup_host'
+	fails.
+	(GOACC_enter_exit_data): Simplify accordingly.
+	* testsuite/libgomp.oacc-c-c++-common/pr92970-1.c: New file,
+	subsuming...
+	* testsuite/libgomp.oacc-c-c++-common/lib-17.c: ... this file...
+	* testsuite/libgomp.oacc-c-c++-common/lib-18.c: ..., and this
+	file.
+	* testsuite/libgomp.oacc-c-c++-common/pr92984-1.c: New file,
+	subsuming...
+	* testsuite/libgomp.oacc-c-c++-common/lib-21.c: ... this file...
+	* testsuite/libgomp.oacc-c-c++-common/lib-29.c: ..., and this
+	file.
+	* testsuite/libgomp.oacc-c-c++-common/pr92726-1.c: New file,
+	subsuming...
+	* testsuite/libgomp.oacc-c-c++-common/lib-28.c: ... this file.
+
 	* oacc-mem.c (GOACC_enter_exit_data): Simplify 'exit data'
 	'finalize' handling.
 
diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index b21d83c37d8..32bf3656029 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -659,7 +659,9 @@ acc_pcopyin (void *h, size_t s)
 static void
 delete_copyout (unsigned f, void *h, size_t s, int async, const char *libfnname)
 {
-  splay_tree_key n;
+  /* No need to call lazy open, as the data must already have been
+ mapped.  */
+
   struct goacc_thread *thr = goacc_thread ();
   struct gomp_device_descr *acc_dev = thr->dev;
 
@@ -677,16 +679,10 @@ delete_copyout (unsigned f, void *h, size_t s, 

Re: [OpenACC] Elaborate/simplify 'exit data' 'finalize' handling (was: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior)

2019-12-18 Thread Thomas Schwinge
Hi!

On 2019-12-13T23:34:15+, Julian Brown  wrote:
> On Fri, 13 Dec 2019 15:13:53 +0100
> Thomas Schwinge  wrote:
>> Julian, Tobias, regarding the following OpenACC 'exit data' 'finalize'
>> handling:
>> 
>> On 2018-05-25T13:01:58-0700, Cesar Philippidis
>>  wrote:
>> > [...]
>> 
>> ... does the attached patch "[OpenACC] Elaborate/simplify 'exit data'
>> 'finalize' handling" (with "No functional changes") match your
>> understanding of what's going on?
>
> Your patch looks OK to me, FWIW.

Thanks for the review.

See attached "[OpenACC] Elaborate/simplify 'exit data' 'finalize'
handling"; committed to trunk in r279531.


> As you mentioned at some point though,
> it might be good to get rid of this style of finalize handling,
> replacing it with a flag passed to GOACC_exit_data

Actually, as recently discussed in a different context, I'm now steering
into the opposite direction: make all that explicit in the mapping kinds.
The reason is: while it's true that currently the OpenACC 'finalize'
clause applies to all data clauses on the directive, that's not the only
way: it might at some point become a flag for each individual clause
('copyout(finalize: [...])', or something like that) -- like OpenMP
already does, as far as I remember, so we need to support that
per-mapping kind anyway.


> -- presuming that at
> the same time, we separate out the needlessly-dual-purpose
> GOACC_enter_exit_data API entry point into "enter" and "exit" halves.

Indeed -- while that one's not a problem, it's still a bit "uh".  But,
for the sake of backwards compatibility..., it'll stay this way until we
do any other breaking changes.


Grüße
 Thomas


From a4af910c186bab748351f00b9a652c3167fa8da6 Mon Sep 17 00:00:00 2001
From: tschwinge 
Date: Wed, 18 Dec 2019 17:00:51 +
Subject: [PATCH] [OpenACC] Elaborate/simplify 'exit data' 'finalize' handling

No functional changes.

	gcc/
	* gimplify.c (gimplify_omp_target_update): Elaborate 'exit data'
	'finalize' handling.
	gcc/testsuite/
	* c-c++-common/goacc/finalize-1.c: Extend.
	* gfortran.dg/goacc/finalize-1.f: Likewise.
	libgomp/
	* oacc-mem.c (GOACC_enter_exit_data): Simplify 'exit data'
	'finalize' handling.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@279531 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog |  5 
 gcc/gimplify.c| 23 +++
 gcc/testsuite/ChangeLog   |  5 
 gcc/testsuite/c-c++-common/goacc/finalize-1.c | 11 -
 gcc/testsuite/gfortran.dg/goacc/finalize-1.f  | 10 
 libgomp/ChangeLog |  3 +++
 libgomp/oacc-mem.c| 14 +++
 7 files changed, 49 insertions(+), 22 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 642faea1e44..be8dfa3fecf 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2019-12-18  Thomas Schwinge  
+
+	* gimplify.c (gimplify_omp_target_update): Elaborate 'exit data'
+	'finalize' handling.
+
 2019-12-18  Tobias Burnus  
 
 	PR middle-end/86416
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 9073680cb31..60a80cb8098 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -12738,27 +12738,30 @@ gimplify_omp_target_update (tree *expr_p, gimple_seq *pre_p)
 	   && omp_find_clause (OMP_STANDALONE_CLAUSES (expr),
 			   OMP_CLAUSE_FINALIZE))
 {
-  /* Use GOMP_MAP_DELETE/GOMP_MAP_FORCE_FROM to denote that "finalize"
-	 semantics apply to all mappings of this OpenACC directive.  */
-  bool finalize_marked = false;
+  /* Use GOMP_MAP_DELETE/GOMP_MAP_FORCE_FROM to denote "finalize"
+	 semantics.  */
+  bool have_clause = false;
   for (tree c = OMP_STANDALONE_CLAUSES (expr); c; c = OMP_CLAUSE_CHAIN (c))
 	if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
 	  switch (OMP_CLAUSE_MAP_KIND (c))
 	{
 	case GOMP_MAP_FROM:
 	  OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_FORCE_FROM);
-	  finalize_marked = true;
+	  have_clause = true;
 	  break;
 	case GOMP_MAP_RELEASE:
 	  OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_DELETE);
-	  finalize_marked = true;
+	  have_clause = true;
 	  break;
-	default:
-	  /* Check consistency: libgomp relies on the very first data
-		 mapping clause being marked, so make sure we did that before
-		 any other mapping clauses.  */
-	  gcc_assert (finalize_marked);
+	case GOMP_MAP_POINTER:
+	case GOMP_MAP_TO_PSET:
+	  /* TODO PR92929: we may see these here, but they'll always follow
+		 one of the clauses above, and will be handled by libgomp as
+		 one group, so no handling required here.  */
+	  gcc_assert (have_clause);
 	  break;
+	default:
+	  gcc_unreachable ();
 	}
 }
   stmt = gimple_build_omp_target (NULL, kind, OMP_STANDALONE_CLAUSES (expr));
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 942448061cb..f1bf3452243 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 

Re: [OpenACC] Elaborate/simplify 'exit data' 'finalize' handling (was: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior)

2019-12-13 Thread Julian Brown
On Fri, 13 Dec 2019 15:13:53 +0100
Thomas Schwinge  wrote:

> Hi!
> 
> Julian, Tobias, regarding the following OpenACC 'exit data' 'finalize'
> handling:
> 
> On 2018-05-25T13:01:58-0700, Cesar Philippidis
>  wrote:
> > --- a/gcc/gimplify.c
> > +++ b/gcc/gimplify.c  
> 
> > @@ -10859,6 +10849,53 @@ gimplify_omp_target_update (tree *expr_p,
> > gimple_seq *pre_p)  
> 
> > +  else if (TREE_CODE (expr) == OACC_EXIT_DATA
> > +  && omp_find_clause (OMP_STANDALONE_CLAUSES (expr),
> > +  OMP_CLAUSE_FINALIZE))
> > +{
> > +  /* Use GOMP_MAP_DELETE/GOMP_MAP_FORCE_FROM to denote that
> > "finalize"
> > +semantics apply to all mappings of this OpenACC
> > directive.  */
> > +  bool finalize_marked = false;
> > +  for (tree c = OMP_STANDALONE_CLAUSES (expr); c; c =
> > OMP_CLAUSE_CHAIN (c))
> > +   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
> > + switch (OMP_CLAUSE_MAP_KIND (c))
> > +   {
> > +   case GOMP_MAP_FROM:
> > + OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_FORCE_FROM);
> > + finalize_marked = true;
> > + break;
> > +   case GOMP_MAP_RELEASE:
> > + OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_DELETE);
> > + finalize_marked = true;
> > + break;
> > +   default:
> > + /* Check consistency: libgomp relies on the very
> > first data
> > +mapping clause being marked, so make sure we did
> > that before
> > +any other mapping clauses.  */
> > + gcc_assert (finalize_marked);
> > + break;
> > +   }
> > +}  
> 
> > --- a/libgomp/oacc-parallel.c
> > +++ b/libgomp/oacc-parallel.c  
> 
> > @@ -286,6 +360,17 @@ GOACC_enter_exit_data (int device, size_t
> > mapnum,  
> 
> > +  /* Determine whether "finalize" semantics apply to all mappings
> > of this
> > + OpenACC directive.  */
> > +  bool finalize = false;
> > +  if (mapnum > 0)
> > +{
> > +  unsigned char kind = kinds[0] & 0xff;
> > +  if (kind == GOMP_MAP_DELETE
> > + || kind == GOMP_MAP_FORCE_FROM)
> > +   finalize = true;
> > +}
> > +  
> 
> > @@ -360,22 +458,28 @@ GOACC_enter_exit_data (int device, size_t
> > mapnum,  
> 
> > switch (kind)
> >   {
> > - case GOMP_MAP_POINTER:
> > -   gomp_acc_remove_pointer (hostaddrs[i], (kinds[i] &
> > 0xff)
> > -== GOMP_MAP_FORCE_FROM,
> > -async, 1);
> > -   break;
> > + case GOMP_MAP_RELEASE:
> >   case GOMP_MAP_DELETE:
> > -   acc_delete (hostaddrs[i], sizes[i]);
> > +   if (acc_is_present (hostaddrs[i], sizes[i]))
> > + {
> > +   if (finalize)
> > + acc_delete_finalize (hostaddrs[i], sizes[i]);
> > +   else
> > + acc_delete (hostaddrs[i], sizes[i]);
> > + }
> > break;
> > + case GOMP_MAP_FROM:
> >   case GOMP_MAP_FORCE_FROM:
> > -   acc_copyout (hostaddrs[i], sizes[i]);
> > +   if (finalize)
> > + acc_copyout_finalize (hostaddrs[i], sizes[i]);
> > +   else
> > + acc_copyout (hostaddrs[i], sizes[i]);
> > break;
> >   default:
> > gomp_fatal (" GOACC_enter_exit_data UNHANDLED
> > kind 0x%.2x", @@ -385,10 +489,12 @@ GOACC_enter_exit_data (int
> > device, size_t mapnum, }
> > else
> >   {
> > -   gomp_acc_remove_pointer (hostaddrs[i], (kinds[i] &
> > 0xff)
> > -== GOMP_MAP_FORCE_FROM,
> > async, 3); +[...]
> > +   gomp_acc_remove_pointer (hostaddrs[i], sizes[i],
> > copyfrom, async,
> > +finalize, pointer);  
> 
> ... does the attached patch "[OpenACC] Elaborate/simplify 'exit data'
> 'finalize' handling" (with "No functional changes") match your
> understanding of what's going on?

Your patch looks OK to me, FWIW. As you mentioned at some point though,
it might be good to get rid of this style of finalize handling,
replacing it with a flag passed to GOACC_exit_data -- presuming that at
the same time, we separate out the needlessly-dual-purpose
GOACC_enter_exit_data API entry point into "enter" and "exit" halves.

Thanks,

Julian


[OpenACC] Elaborate/simplify 'exit data' 'finalize' handling (was: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior)

2019-12-13 Thread Thomas Schwinge
Hi!

Julian, Tobias, regarding the following OpenACC 'exit data' 'finalize'
handling:

On 2018-05-25T13:01:58-0700, Cesar Philippidis  wrote:
> --- a/gcc/gimplify.c
> +++ b/gcc/gimplify.c

> @@ -10859,6 +10849,53 @@ gimplify_omp_target_update (tree *expr_p, gimple_seq 
> *pre_p)

> +  else if (TREE_CODE (expr) == OACC_EXIT_DATA
> +&& omp_find_clause (OMP_STANDALONE_CLAUSES (expr),
> +OMP_CLAUSE_FINALIZE))
> +{
> +  /* Use GOMP_MAP_DELETE/GOMP_MAP_FORCE_FROM to denote that "finalize"
> +  semantics apply to all mappings of this OpenACC directive.  */
> +  bool finalize_marked = false;
> +  for (tree c = OMP_STANDALONE_CLAUSES (expr); c; c = OMP_CLAUSE_CHAIN 
> (c))
> + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
> +   switch (OMP_CLAUSE_MAP_KIND (c))
> + {
> + case GOMP_MAP_FROM:
> +   OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_FORCE_FROM);
> +   finalize_marked = true;
> +   break;
> + case GOMP_MAP_RELEASE:
> +   OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_DELETE);
> +   finalize_marked = true;
> +   break;
> + default:
> +   /* Check consistency: libgomp relies on the very first data
> +  mapping clause being marked, so make sure we did that before
> +  any other mapping clauses.  */
> +   gcc_assert (finalize_marked);
> +   break;
> + }
> +}

> --- a/libgomp/oacc-parallel.c
> +++ b/libgomp/oacc-parallel.c

> @@ -286,6 +360,17 @@ GOACC_enter_exit_data (int device, size_t mapnum,

> +  /* Determine whether "finalize" semantics apply to all mappings of this
> + OpenACC directive.  */
> +  bool finalize = false;
> +  if (mapnum > 0)
> +{
> +  unsigned char kind = kinds[0] & 0xff;
> +  if (kind == GOMP_MAP_DELETE
> +   || kind == GOMP_MAP_FORCE_FROM)
> + finalize = true;
> +}
> +

> @@ -360,22 +458,28 @@ GOACC_enter_exit_data (int device, size_t mapnum,

>   switch (kind)
> {
> -   case GOMP_MAP_POINTER:
> - gomp_acc_remove_pointer (hostaddrs[i], (kinds[i] & 0xff)
> -  == GOMP_MAP_FORCE_FROM,
> -  async, 1);
> - break;
> +   case GOMP_MAP_RELEASE:
> case GOMP_MAP_DELETE:
> - acc_delete (hostaddrs[i], sizes[i]);
> + if (acc_is_present (hostaddrs[i], sizes[i]))
> +   {
> + if (finalize)
> +   acc_delete_finalize (hostaddrs[i], sizes[i]);
> + else
> +   acc_delete (hostaddrs[i], sizes[i]);
> +   }
>   break;
> +   case GOMP_MAP_FROM:
> case GOMP_MAP_FORCE_FROM:
> - acc_copyout (hostaddrs[i], sizes[i]);
> + if (finalize)
> +   acc_copyout_finalize (hostaddrs[i], sizes[i]);
> + else
> +   acc_copyout (hostaddrs[i], sizes[i]);
>   break;
> default:
>   gomp_fatal (" GOACC_enter_exit_data UNHANDLED kind 0x%.2x",
> @@ -385,10 +489,12 @@ GOACC_enter_exit_data (int device, size_t mapnum,
> }
>   else
> {
> - gomp_acc_remove_pointer (hostaddrs[i], (kinds[i] & 0xff)
> -  == GOMP_MAP_FORCE_FROM, async, 3);
> +[...]
> + gomp_acc_remove_pointer (hostaddrs[i], sizes[i], copyfrom, async,
> +  finalize, pointer);

... does the attached patch "[OpenACC] Elaborate/simplify 'exit data'
'finalize' handling" (with "No functional changes") match your
understanding of what's going on?  If approving this patch, please
respond with "Reviewed-by: NAME " so that your effort will be
recorded in the commit log, see .

(It will be a separate discussion to change the 'GOMP_MAP_POINTER',
'GOMP_MAP_TO_PSET' stuff later on -- thinking about the changes from
Julian's big "OpenACC reference count overhaul" as well as
 "OpenACC/OpenMP 'target' 'exit
data'/'update' optimizations".  That patch here is just meant to document
what's going at present, and simplify things as a preparation for other
changes.)


Grüße
 Thomas


From 283577c63b374c3e368e3c0b68b90e19085f193c Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Fri, 13 Dec 2019 13:56:51 +0100
Subject: [PATCH] [OpenACC] Elaborate/simplify 'exit data' 'finalize' handling

No functional changes.
---
 gcc/gimplify.c| 23 +++
 gcc/testsuite/c-c++-common/goacc/finalize-1.c | 11 -
 gcc/testsuite/gfortran.dg/goacc/finalize-1.f  | 10 
 libgomp/oacc-mem.c| 14 +++
 4 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 9073680cb31..60a80cb8098 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ 

Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior - runtime

2019-12-11 Thread Thomas Schwinge
Hi!

On 2018-06-19T10:01:20-0700, Cesar Philippidis  wrote:
> This patch implements the OpenACC 2.5 data clause semantics in libgomp.

> --- a/libgomp/libgomp.h
> +++ b/libgomp/libgomp.h
> @@ -853,6 +853,8 @@ struct splay_tree_key_s {
>uintptr_t tgt_offset;
>/* Reference count.  */
>uintptr_t refcount;
> +  /* Dynamic reference count.  */
> +  uintptr_t dynamic_refcount;
>/* Pointer to the original mapping of "omp declare target link" object.  */
>splay_tree_key link_key;
>  };

See attached "[OpenACC] Initialize 'dynamic_refcount' whenever we
initialize 'refcount'" for 'Cases missed in r261813 "Update OpenACC data
clause semantics to the 2.5 behavior"'; committed to trunk in r279230,
and backported to gcc-9-branch in r279238.


Grüße
 Thomas


From 20d0998b970ba693b23ee24bd0c94ecb57adf281 Mon Sep 17 00:00:00 2001
From: tschwinge 
Date: Wed, 11 Dec 2019 16:48:44 +
Subject: [PATCH] [OpenACC] Initialize 'dynamic_refcount' whenever we
 initialize 'refcount'

Cases missed in r261813 "Update OpenACC data clause semantics to the 2.5
behavior".

	libgomp/
	* target.c (gomp_load_image_to_device, omp_target_associate_ptr):
	Initialize 'dynamic_refcount' whenever we initialize 'refcount'.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@279230 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libgomp/ChangeLog | 6 ++
 libgomp/target.c  | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog
index 6cefeba5f5f..6635ed7b44b 100644
--- a/libgomp/ChangeLog
+++ b/libgomp/ChangeLog
@@ -1,3 +1,9 @@
+2019-12-11  Thomas Schwinge  
+	Julian Brown  
+
+	* target.c (gomp_load_image_to_device, omp_target_associate_ptr):
+	Initialize 'dynamic_refcount' whenever we initialize 'refcount'.
+
 2019-12-11  Tobias Burnus  
 
 	* omp_lib.h.in: Fix spelling of function declaration
diff --git a/libgomp/target.c b/libgomp/target.c
index 39a24f56395..1151debf256 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -1334,6 +1334,7 @@ gomp_load_image_to_device (struct gomp_device_descr *devicep, unsigned version,
   k->tgt = tgt;
   k->tgt_offset = target_table[i].start;
   k->refcount = REFCOUNT_INFINITY;
+  k->dynamic_refcount = 0;
   k->link_key = NULL;
   array->left = NULL;
   array->right = NULL;
@@ -1366,6 +1367,7 @@ gomp_load_image_to_device (struct gomp_device_descr *devicep, unsigned version,
   k->tgt = tgt;
   k->tgt_offset = target_var->start;
   k->refcount = target_size & link_bit ? REFCOUNT_LINK : REFCOUNT_INFINITY;
+  k->dynamic_refcount = 0;
   k->link_key = NULL;
   array->left = NULL;
   array->right = NULL;
@@ -2627,6 +2629,7 @@ omp_target_associate_ptr (const void *host_ptr, const void *device_ptr,
   k->tgt = tgt;
   k->tgt_offset = (uintptr_t) device_ptr + device_offset;
   k->refcount = REFCOUNT_INFINITY;
+  k->dynamic_refcount = 0;
   array->left = NULL;
   array->right = NULL;
   splay_tree_insert (>mem_map, array);
-- 
2.17.1

From f301776d131dd584f1259a4e6bfa5662451407c4 Mon Sep 17 00:00:00 2001
From: tschwinge 
Date: Wed, 11 Dec 2019 16:51:31 +0000
Subject: [PATCH] [OpenACC, libgomp] Initialize 'dynamic_refcount' whenever we
 initialize 'refcount'

Cases missed in r261813 "Update OpenACC data clause semantics to the 2.5
behavior".

	libgomp/
	* target.c (gomp_load_image_to_device, omp_target_associate_ptr):
	Initialize 'dynamic_refcount' whenever we initialize 'refcount'.

Backport trunk r279230.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-9-branch@279238 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libgomp/ChangeLog | 6 ++
 libgomp/target.c  | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog
index 70a7f50c22b..c1959a44b8c 100644
--- a/libgomp/ChangeLog
+++ b/libgomp/ChangeLog
@@ -1,3 +1,9 @@
+2019-12-11  Thomas Schwinge  
+	Julian Brown  
+
+	* target.c (gomp_load_image_to_device, omp_target_associate_ptr):
+	Initialize 'dynamic_refcount' whenever we initialize 'refcount'.
+
 2019-12-11  Tobias Burnus  
 
 	Backported from mainline
diff --git a/libgomp/target.c b/libgomp/target.c
index 31148003d0a..97fc1ee2ddc 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -1214,6 +1214,7 @@ gomp_load_image_to_device (struct gomp_device_descr *devicep, unsigned version,
   k->tgt = tgt;
   k->tgt_offset = target_table[i].start;
   k->refcount = REFCOUNT_INFINITY;
+  k->dynamic_refcount = 0;
   k->link_key = NULL;
   array->left = NULL;
   array->right = NULL;
@@ -1246,6 +1247,7 @@ gomp_load_image_to_device (struct gomp_device_descr *devicep, unsigned version,
   k->tgt = tgt;
   k->tgt_offset = target_var->start;
   k->refcount = target_size & link_bit ? REFCOUNT_LINK : REFCOUNT_INFINI

In 'libgomp/target.c:gomp_exit_data', remove open-coded 'gomp_remove_var' (was: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior - runtime)

2019-12-09 Thread Thomas Schwinge
Hi!

On 2018-06-19T10:01:20-0700, Cesar Philippidis  wrote:
> --- a/libgomp/target.c
> +++ b/libgomp/target.c

> +attribute_hidden bool
> +gomp_remove_var (struct gomp_device_descr *devicep, splay_tree_key k)
> +{
> +  bool is_tgt_unmapped = false;
> +  splay_tree_remove (>mem_map, k);
> +  if (k->link_key)
> +splay_tree_insert (>mem_map, (splay_tree_node) k->link_key);
> +  if (k->tgt->refcount > 1)
> +k->tgt->refcount--;
> +  else
> +{
> +  is_tgt_unmapped = true;
> +  gomp_unmap_tgt (k->tgt);
> +}
> +  return is_tgt_unmapped;

This new function, can, like done here:

> @@ -1059,16 +1077,7 @@ gomp_unmap_vars (struct target_mem_desc *tgt, bool 
> do_copyfrom)
> + tgt->list[i].offset),
>   tgt->list[i].length);
>if (do_unmap)
> - {
> -   splay_tree_remove (>mem_map, k);
> -   if (k->link_key)
> - splay_tree_insert (>mem_map,
> -(splay_tree_node) k->link_key);
> -   if (k->tgt->refcount > 1)
> - k->tgt->refcount--;
> -   else
> - gomp_unmap_tgt (k->tgt);
> - }
> + gomp_remove_var (devicep, k);
>  }

..., and here:

> @@ -1298,17 +1307,7 @@ gomp_unload_image_from_device (struct 
> gomp_device_descr *devicep,
>else
>   {
> splay_tree_key n = splay_tree_lookup (>mem_map, );
> -   splay_tree_remove (>mem_map, n);
> -   if (n->link_key)
> - {
> -   if (n->tgt->refcount > 1)
> - n->tgt->refcount--;
> -   else
> - {
> -   is_tgt_unmapped = true;
> -   gomp_unmap_tgt (n->tgt);
> - }
> - }
> +   is_tgt_unmapped = gomp_remove_var (devicep, n);
>   }

..., also be used in 'gomp_exit_data', see attached "In
'libgomp/target.c:gomp_exit_data', remove open-coded 'gomp_remove_var'",
committed to trunk in r279118.


Grüße
 Thomas


From bbfdb255a0b5cb6e183e11026c2a482d4eeba981 Mon Sep 17 00:00:00 2001
From: tschwinge 
Date: Mon, 9 Dec 2019 11:39:57 +
Subject: [PATCH] In 'libgomp/target.c:gomp_exit_data', remove open-coded
 'gomp_remove_var'

	libgomp/
	* target.c (gomp_exit_data): Use 'gomp_remove_var'.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@279118 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libgomp/ChangeLog |  4 
 libgomp/target.c  | 11 +--
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog
index a0bd25177d1..c5541bcec81 100644
--- a/libgomp/ChangeLog
+++ b/libgomp/ChangeLog
@@ -1,3 +1,7 @@
+2019-12-09  Thomas Schwinge  
+
+	* target.c (gomp_exit_data): Use 'gomp_remove_var'.
+
 2019-12-09  Tobias Burnus  
 
 	* testsuite/libgomp.fortran/use_device_addr-3.f90: Make 'stop' codes
diff --git a/libgomp/target.c b/libgomp/target.c
index 84d6daa76ca..13f7921651f 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -2095,16 +2095,7 @@ gomp_exit_data (struct gomp_device_descr *devicep, size_t mapnum,
 	  - k->host_start),
 cur_node.host_end - cur_node.host_start);
 	  if (k->refcount == 0)
-	{
-	  splay_tree_remove (>mem_map, k);
-	  if (k->link_key)
-		splay_tree_insert (>mem_map,
-   (splay_tree_node) k->link_key);
-	  if (k->tgt->refcount > 1)
-		k->tgt->refcount--;
-	  else
-		gomp_unmap_tgt (k->tgt);
-	}
+	gomp_remove_var (devicep, k);
 
 	  break;
 	default:
-- 
2.17.1



signature.asc
Description: PGP signature


Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior - runtime

2019-05-29 Thread Thomas Schwinge
Hi Jakub!

Any comments on my questions, please?

On Thu, 02 May 2019 16:03:09 +0200, I wrote:
> I'm currently working on other pending OpenACC 'deviceptr' clause patches
> from our backlog, and I noticed the following, which I don't understand.
> You reviewed and approved this patch, could you please help?
> 
> On Tue, 19 Jun 2018 10:01:20 -0700, Cesar Philippidis 
>  wrote:
> > --- a/libgomp/oacc-parallel.c
> > +++ b/libgomp/oacc-parallel.c
> 
> > +/* Handle the mapping pair that are presented when a
> > +   deviceptr clause is used with Fortran.  */
> > +
> > +static void
> > +handle_ftn_pointers (size_t mapnum, void **hostaddrs, size_t *sizes,
> > +unsigned short *kinds)
> > +{
> > +  int i;
> > +
> > +  for (i = 0; i < mapnum; i++)
> > +{
> > +  unsigned short kind1 = kinds[i] & 0xff;
> > +
> > +  /* Handle Fortran deviceptr clause.  */
> > +  if (kind1 == GOMP_MAP_FORCE_DEVICEPTR)
> > +   {
> > + unsigned short kind2;
> > +
> > + if (i < (signed)mapnum - 1)
> > +   kind2 = kinds[i + 1] & 0xff;
> > + else
> > +   kind2 = 0x;
> > +
> > + if (sizes[i] == sizeof (void *))
> > +   continue;
> > +
> > + /* At this point, we're dealing with a Fortran deviceptr.
> > +If the next element is not what we're expecting, then
> > +this is an instance of where the deviceptr variable was
> > +not used within the region and the pointer was removed
> > +by the gimplifier.  */
> > + if (kind2 == GOMP_MAP_POINTER
> > + && sizes[i + 1] == 0
> > + && hostaddrs[i] == *(void **)hostaddrs[i + 1])
> > +   {
> > + kinds[i+1] = kinds[i];
> > + sizes[i+1] = sizeof (void *);
> > +   }
> > +
> > + /* Invalidate the entry.  */
> > + hostaddrs[i] = NULL;
> > +   }
> > +}
> >  }
> 
> This is used for rewriting the mappings for OpenACC 'parallel'
> etc. constructs:
> 
> > @@ -88,6 +141,8 @@ GOACC_parallel_keyed (int device, void (*fn) (void *),
> >thr = goacc_thread ();
> >acc_dev = thr->dev;
> >  
> > +  handle_ftn_pointers (mapnum, hostaddrs, sizes, kinds);
> > +
> >/* Host fallback if "if" clause is false or if the current device is set 
> > to
> >   the host.  */
> >if (host_fallback)
> 
> ..., and on our OpenACC development branch likewise for OpenACC 'data'
> constructs ('GOACC_data_start').
> 
> What this function seems to be doing, as I understand this, is that when
> there is an 'GOMP_MAP_FORCE_DEVICEPTR' with a size not eqal to pointer
> size (which should never happen, as per the information given
> 'include/gomp-constants.h'?), which is followed by a 'GOMP_MAP_POINTER',
> then preserve the 'GOMP_MAP_FORCE_DEVICEPTR' (by storing it into the slot
> of the 'GOMP_MAP_POINTER'), and unconditionally remove the
> 'GOMP_MAP_POINTER'.  This seems like a strange choice of a GCC/libgomp
> ABI to me -- or am I not understanding this correctly?
> 
> Instead of rewriting the mappings at run time, why isn't (presumably) the
> gimplifier changed to just emit the correct mappings?


Grüße
 Thomas


signature.asc
Description: PGP signature


Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior - runtime

2019-05-02 Thread Thomas Schwinge
Hi Jakub!

I'm currently working on other pending OpenACC 'deviceptr' clause patches
from our backlog, and I noticed the following, which I don't understand.
You reviewed and approved this patch, could you please help?

On Tue, 19 Jun 2018 10:01:20 -0700, Cesar Philippidis  
wrote:
> --- a/libgomp/oacc-parallel.c
> +++ b/libgomp/oacc-parallel.c

> +/* Handle the mapping pair that are presented when a
> +   deviceptr clause is used with Fortran.  */
> +
> +static void
> +handle_ftn_pointers (size_t mapnum, void **hostaddrs, size_t *sizes,
> +  unsigned short *kinds)
> +{
> +  int i;
> +
> +  for (i = 0; i < mapnum; i++)
> +{
> +  unsigned short kind1 = kinds[i] & 0xff;
> +
> +  /* Handle Fortran deviceptr clause.  */
> +  if (kind1 == GOMP_MAP_FORCE_DEVICEPTR)
> + {
> +   unsigned short kind2;
> +
> +   if (i < (signed)mapnum - 1)
> + kind2 = kinds[i + 1] & 0xff;
> +   else
> + kind2 = 0x;
> +
> +   if (sizes[i] == sizeof (void *))
> + continue;
> +
> +   /* At this point, we're dealing with a Fortran deviceptr.
> +  If the next element is not what we're expecting, then
> +  this is an instance of where the deviceptr variable was
> +  not used within the region and the pointer was removed
> +  by the gimplifier.  */
> +   if (kind2 == GOMP_MAP_POINTER
> +   && sizes[i + 1] == 0
> +   && hostaddrs[i] == *(void **)hostaddrs[i + 1])
> + {
> +   kinds[i+1] = kinds[i];
> +   sizes[i+1] = sizeof (void *);
> + }
> +
> +   /* Invalidate the entry.  */
> +   hostaddrs[i] = NULL;
> + }
> +}
>  }

This is used for rewriting the mappings for OpenACC 'parallel'
etc. constructs:

> @@ -88,6 +141,8 @@ GOACC_parallel_keyed (int device, void (*fn) (void *),
>thr = goacc_thread ();
>acc_dev = thr->dev;
>  
> +  handle_ftn_pointers (mapnum, hostaddrs, sizes, kinds);
> +
>/* Host fallback if "if" clause is false or if the current device is set to
>   the host.  */
>if (host_fallback)

..., and on our OpenACC development branch likewise for OpenACC 'data'
constructs ('GOACC_data_start').

What this function seems to be doing, as I understand this, is that when
there is an 'GOMP_MAP_FORCE_DEVICEPTR' with a size not eqal to pointer
size (which should never happen, as per the information given
'include/gomp-constants.h'?), which is followed by a 'GOMP_MAP_POINTER',
then preserve the 'GOMP_MAP_FORCE_DEVICEPTR' (by storing it into the slot
of the 'GOMP_MAP_POINTER'), and unconditionally remove the
'GOMP_MAP_POINTER'.  This seems like a strange choice of a GCC/libgomp
ABI to me -- or am I not understanding this correctly?

Instead of rewriting the mappings at run time, why isn't (presumably) the
gimplifier changed to just emit the correct mappings?


Grüße
 Thomas


signature.asc
Description: PGP signature


Re: [GCC 9 RM attention] Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior

2019-04-30 Thread Thomas Schwinge
Hi Jakub!

On Mon, 29 Apr 2019 12:59:03 +0200, Jakub Jelinek  wrote:
> On Mon, Apr 29, 2019 at 12:18:15PM +0200, Thomas Schwinge wrote:
> > I know it's very late in the GCC 9 release process, but I'm still
> > catching up with OpenACC patch review, and just at the end of last week
> > I'd noticed that this commit (trunk r261813):
> 
> I'd like to see full patch before considering.  The bar at this point for
> anything to gcc-9-branch is very high.

Sure, understood.


I've spent some time thinking about this ABI change, back and forth, and
even produced the obvious patch (to use 'GOACC_FLAG_IF_PRESENT',
'GOACC_FLAG_FINALIZE'; attached for posterity), but in the end I'd like
to withdraw, and keep the current ABI.  (..., and I'll instead follow up,
at a later point in time, with some documentation updates and code
restructuring, to make this better understandable/maintainable.)


Grüße
 Thomas


From 46913aca5aa2dc24b04bd9012b8506bf767b442e Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Mon, 29 Apr 2019 21:25:41 +0200
Subject: [PATCH] [WIP] 'GOACC_FLAG_IF_PRESENT', 'GOACC_FLAG_FINALIZE'

TODO Adjust tree-scanning test cases.
---
 gcc/gimplify.c   | 47 
 gcc/omp-expand.c | 22 +++
 include/gomp-constants.h |  4 
 libgomp/oacc-parallel.c  | 25 ++---
 4 files changed, 29 insertions(+), 69 deletions(-)

diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index e59f38261c36..44399b1af0d0 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -11811,53 +11811,6 @@ gimplify_omp_target_update (tree *expr_p, gimple_seq *pre_p)
 			 ort, TREE_CODE (expr));
   gimplify_adjust_omp_clauses (pre_p, NULL, _STANDALONE_CLAUSES (expr),
 			   TREE_CODE (expr));
-  if (TREE_CODE (expr) == OACC_UPDATE
-  && omp_find_clause (OMP_STANDALONE_CLAUSES (expr),
-			  OMP_CLAUSE_IF_PRESENT))
-{
-  /* The runtime uses GOMP_MAP_{TO,FROM} to denote the if_present
-	 clause.  */
-  for (tree c = OMP_STANDALONE_CLAUSES (expr); c; c = OMP_CLAUSE_CHAIN (c))
-	if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
-	  switch (OMP_CLAUSE_MAP_KIND (c))
-	{
-	case GOMP_MAP_FORCE_TO:
-	  OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
-	  break;
-	case GOMP_MAP_FORCE_FROM:
-	  OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_FROM);
-	  break;
-	default:
-	  break;
-	}
-}
-  else if (TREE_CODE (expr) == OACC_EXIT_DATA
-	   && omp_find_clause (OMP_STANDALONE_CLAUSES (expr),
-			   OMP_CLAUSE_FINALIZE))
-{
-  /* Use GOMP_MAP_DELETE/GOMP_MAP_FORCE_FROM to denote that "finalize"
-	 semantics apply to all mappings of this OpenACC directive.  */
-  bool finalize_marked = false;
-  for (tree c = OMP_STANDALONE_CLAUSES (expr); c; c = OMP_CLAUSE_CHAIN (c))
-	if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
-	  switch (OMP_CLAUSE_MAP_KIND (c))
-	{
-	case GOMP_MAP_FROM:
-	  OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_FORCE_FROM);
-	  finalize_marked = true;
-	  break;
-	case GOMP_MAP_RELEASE:
-	  OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_DELETE);
-	  finalize_marked = true;
-	  break;
-	default:
-	  /* Check consistency: libgomp relies on the very first data
-		 mapping clause being marked, so make sure we did that before
-		 any other mapping clauses.  */
-	  gcc_assert (finalize_marked);
-	  break;
-	}
-}
   stmt = gimple_build_omp_target (NULL, kind, OMP_STANDALONE_CLAUSES (expr));
 
   gimplify_seq_add_stmt (pre_p, stmt);
diff --git a/gcc/omp-expand.c b/gcc/omp-expand.c
index 89a3a3232671..53dbadea4c76 100644
--- a/gcc/omp-expand.c
+++ b/gcc/omp-expand.c
@@ -7542,14 +7542,28 @@ expand_omp_target (struct omp_region *region)
 
   clauses = gimple_omp_target_clauses (entry_stmt);
 
+  /* By default, no GOACC_FLAGs are set.  */
+  int goacc_flags_i = 0;
+
+  if (omp_find_clause (clauses, OMP_CLAUSE_IF_PRESENT))
+{
+  gcc_checking_assert (gimple_omp_target_kind (entry_stmt)
+			   == GF_OMP_TARGET_KIND_OACC_UPDATE);
+  goacc_flags_i |= GOACC_FLAG_IF_PRESENT;
+}
+
+  if (omp_find_clause (clauses, OMP_CLAUSE_FINALIZE))
+{
+  gcc_checking_assert (gimple_omp_target_kind (entry_stmt)
+			   == GF_OMP_TARGET_KIND_OACC_ENTER_EXIT_DATA);
+  goacc_flags_i |= GOACC_FLAG_FINALIZE;
+}
+
   tree device = NULL_TREE;
   location_t device_loc = UNKNOWN_LOCATION;
   tree goacc_flags = NULL_TREE;
   if (is_gimple_omp_oacc (entry_stmt))
-{
-  /* By default, no GOACC_FLAGs are set.  */
-  goacc_flags = integer_zero_node;
-}
+goacc_flags = build_int_cst (integer_type_node, goacc_flags_i);
   else
 {
   c = omp_find_clause (clauses, OMP_CLAUSE_DEVICE);
diff --git a/include/gomp-constants.h b/include/gomp-constants.h
index 8b93634f1b8b..8808c343034e 100644
--- a/include/gomp-constants.h
+++ b/include/gomp-constants.h
@@ -202,6 +202,10 @@ enum gomp_map_kind
 
 /* Force host fallback execution.  */
 #define GOACC_FLAG_HOST_FALLBACK	(1 << 0)

Re: [GCC 9 RM attention] Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior

2019-04-29 Thread Jakub Jelinek
On Mon, Apr 29, 2019 at 12:18:15PM +0200, Thomas Schwinge wrote:
> I know it's very late in the GCC 9 release process, but I'm still
> catching up with OpenACC patch review, and just at the end of last week
> I'd noticed that this commit (trunk r261813):

I'd like to see full patch before considering.  The bar at this point for
anything to gcc-9-branch is very high.

Jakub


[GCC 9 RM attention] Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior

2019-04-29 Thread Thomas Schwinge
Hi Jakub!

I know it's very late in the GCC 9 release process, but I'm still
catching up with OpenACC patch review, and just at the end of last week
I'd noticed that this commit (trunk r261813):

On Fri, 25 May 2018 13:01:58 -0700, Cesar Philippidis  
wrote:
> This patch updates GCC's to support OpenACC 2.5's data clause semantics
> [and other stuff...]

... should get rid off the following special-case handling for the new
OpenACC 'if_present' and 'finalize' clauses added here:

--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -10817,6 +10807,53 @@ gimplify_omp_target_update (tree *expr_p, 
gimple_seq *pre_p)
   ort, TREE_CODE (expr));
   gimplify_adjust_omp_clauses (pre_p, NULL, _STANDALONE_CLAUSES (expr),
 TREE_CODE (expr));
+  if (TREE_CODE (expr) == OACC_UPDATE
+  && omp_find_clause (OMP_STANDALONE_CLAUSES (expr),
+ OMP_CLAUSE_IF_PRESENT))
+{
+  /* The runtime uses GOMP_MAP_{TO,FROM} to denote the if_present
+clause.  */
+  for (tree c = OMP_STANDALONE_CLAUSES (expr); c; c = OMP_CLAUSE_CHAIN 
(c))
+   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
+ switch (OMP_CLAUSE_MAP_KIND (c))
+   {
+   case GOMP_MAP_FORCE_TO:
+ OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
+ break;
+   case GOMP_MAP_FORCE_FROM:
+ OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_FROM);
+ break;
+   default:
+ break;
+   }
+}
+  else if (TREE_CODE (expr) == OACC_EXIT_DATA
+  && omp_find_clause (OMP_STANDALONE_CLAUSES (expr),
+  OMP_CLAUSE_FINALIZE))
+{
+  /* Use GOMP_MAP_DELETE/GOMP_MAP_FORCE_FROM to denote that "finalize"
+semantics apply to all mappings of this OpenACC directive.  */
+  bool finalize_marked = false;
+  for (tree c = OMP_STANDALONE_CLAUSES (expr); c; c = OMP_CLAUSE_CHAIN 
(c))
+   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
+ switch (OMP_CLAUSE_MAP_KIND (c))
+   {
+   case GOMP_MAP_FROM:
+ OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_FORCE_FROM);
+ finalize_marked = true;
+ break;
+   case GOMP_MAP_RELEASE:
+ OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_DELETE);
+ finalize_marked = true;
+ break;
+   default:
+ /* Check consistency: libgomp relies on the very first data
+mapping clause being marked, so make sure we did that before
+any other mapping clauses.  */
+ gcc_assert (finalize_marked);
+ break;
+   }
+}
   stmt = gimple_build_omp_target (NULL, kind, OMP_STANDALONE_CLAUSES 
(expr));

   gimplify_seq_add_stmt (pre_p, stmt);

..., plus the corresponding decoding process on the libgomp side.

This should instead use the interface that I added in trunk r267448 'For
libgomp OpenACC entry points, redefine the "device" argument to "flags"'
to communicate such flags from the compiler to libgomp.

I'll cook up a patch, very localized to OpenACC code, which will remove
more lines of code that it'll be adding, but as it's an ABI change, it
needs to go into gcc-9-branch before the 9.1 release is made (planned for
end of week, as I've read).


Grüße
 Thomas


signature.asc
Description: PGP signature


Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior

2019-02-22 Thread Thomas Schwinge
Hi!

On Fri, 14 Dec 2018 22:24:47 +0100, I wrote:
> On Fri, 25 May 2018 13:01:58 -0700, Cesar Philippidis 
>  wrote:
> > This patch updates GCC's to support OpenACC 2.5's data clause semantics. 
> > In OpenACC 2.5, copy, copyin and copyout all behave like their 
> > present_or_* counterparts in OpenACC 2.0. The patch also adds support 
> > for the new finalize and if_present data clauses introduced in OpenACC 
> > 2.5. The finalize clause introduced some new reference counting behavior 
> > in the runtime; whereas 'acc exit data copyout' decrements the reference 
> > count of a variable, 'acc exit data finalize' actually removes it from 
> > the accelerator regardless of there are any pending references to it.
> > 
> > Due to the size of this patch, I had to compress it.
> 
> Well, or just handled separately the pieces that already were nicely
> separated, instead of combining them into one big patch?
> 
> > However, despite 
> > the size of the patch, which is mainly due to the augmented test cases, 
> > it fairly noninvasive. I was originally going to include support for 
> > declare allocate and deallocate, but those require more extensive 
> > modifications to the fortran FE.
> 
> (Why the idea of including even more independent changes?)
> 
> 
> Anyway.  Committed to trunk in r267153 the following to add in the
> missing changes from [...].

..., and now further committed to trunk in r269104 "Revert earlier
OpenACC 'routine' changes", as attached.


Grüße
 Thomas


From 9b42375414c5d9220b627bea41df7d5fc712fd0c Mon Sep 17 00:00:00 2001
From: tschwinge 
Date: Fri, 22 Feb 2019 10:50:18 +
Subject: [PATCH 3/9] Revert earlier OpenACC 'routine' changes

..., which were committed as part of, but logically don't belong into r261813
"Update OpenACC data clause semantics to the 2.5 behavior", and which confuse
later changes.

	gcc/fortran/
	* openmp.c (gfc_match_oacc_declare): Revert earlier changes.
	gcc/testsuite/
	* c-c++-common/goacc/routine-5.c: Revert earlier changes.
	* g++.dg/goacc/template.C: Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@269104 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/fortran/ChangeLog|   4 +
 gcc/fortran/openmp.c |   7 -
 gcc/testsuite/ChangeLog  |   3 +
 gcc/testsuite/c-c++-common/goacc/routine-5.c | 150 ---
 gcc/testsuite/g++.dg/goacc/template.C|   2 +-
 5 files changed, 104 insertions(+), 62 deletions(-)

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index c3bc30c42f6..74a6890ed70 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,7 @@
+2019-02-22  Thomas Schwinge  
+
+	* openmp.c (gfc_match_oacc_declare): Revert earlier changes.
+
 2019-02-21  Thomas Koenig  
 
 	* dump-parse-tree.c (debug): Implement for gfc_expr *,
diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
index 11dd3ae0ada..8aa4a2f18c4 100644
--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -2075,13 +2075,6 @@ gfc_match_oacc_declare (void)
 	  module_var = true;
 	}
 
-  if (ns->proc_name->attr.oacc_function)
-	{
-	  gfc_error ("Invalid declare in routine with $!ACC DECLARE at %L",
-		 );
-	  return MATCH_ERROR;
-	}
-
   if (s->attr.use_assoc)
 	{
 	  gfc_error ("Variable is USE-associated with !$ACC DECLARE at %L",
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b98cd355645..12901a9361a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,8 @@
 2019-02-22  Thomas Schwinge  
 
+	* c-c++-common/goacc/routine-5.c: Revert earlier changes.
+	* g++.dg/goacc/template.C: Likewise.
+
 	PR fortran/78027
 	* gfortran.dg/goacc/pr78027.f90: Add 'dg-additional-options "-Wno-hsa"'.
 
diff --git a/gcc/testsuite/c-c++-common/goacc/routine-5.c b/gcc/testsuite/c-c++-common/goacc/routine-5.c
index b759db3292d..b967a7447bd 100644
--- a/gcc/testsuite/c-c++-common/goacc/routine-5.c
+++ b/gcc/testsuite/c-c++-common/goacc/routine-5.c
@@ -4,11 +4,11 @@
 
 struct PC
 {
-#pragma acc routine seq /* { dg-error ".#pragma acc routine. must be at file scope" } */
+#pragma acc routine /* { dg-error ".#pragma acc routine. must be at file scope" } */
 };
 
 void PC1( /* { dg-bogus "variable or field .PC1. declared void" "TODO" { xfail c++ } } */
-#pragma acc routine seq
+#pragma acc routine
 	 /* { dg-error ".#pragma acc routine. must be at file scope" "" { target c } .-1 }
 	{ dg-error ".#pragma. is not allowed here" "" { target c++ } .-2 } */
 ) /* { dg-bogus "expected declaration specifiers or .\\.\\.\\.. before .\\). token" "TODO" { xfail c } } */
@@ -18,26 +18,26 @@ void PC1( /* { dg-bogus "variable or field .PC1. declared void" &q

Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior

2018-12-14 Thread Thomas Schwinge
Hi!

On Fri, 25 May 2018 13:01:58 -0700, Cesar Philippidis  
wrote:
> This patch updates GCC's to support OpenACC 2.5's data clause semantics. 
> In OpenACC 2.5, copy, copyin and copyout all behave like their 
> present_or_* counterparts in OpenACC 2.0. The patch also adds support 
> for the new finalize and if_present data clauses introduced in OpenACC 
> 2.5. The finalize clause introduced some new reference counting behavior 
> in the runtime; whereas 'acc exit data copyout' decrements the reference 
> count of a variable, 'acc exit data finalize' actually removes it from 
> the accelerator regardless of there are any pending references to it.
> 
> Due to the size of this patch, I had to compress it.

Well, or just handled separately the pieces that already were nicely
separated, instead of combining them into one big patch?

> However, despite 
> the size of the patch, which is mainly due to the augmented test cases, 
> it fairly noninvasive. I was originally going to include support for 
> declare allocate and deallocate, but those require more extensive 
> modifications to the fortran FE.

(Why the idea of including even more independent changes?)


Anyway.  Committed to trunk in r267153 the following to add in the
missing changes from Chung-Lin's "Adjust copy/copyin/copyout/create for
OpenACC 2.5" patch:

commit 8ccac5746ba73bde3a1db490359bbe2d5f62d4a0
Author: tschwinge 
Date:   Fri Dec 14 20:43:12 2018 +

Missing changes from "Adjust copy/copyin/copyout/create for OpenACC 2.5"

Most of that patch's changes were already committed as part of r261813 
"Update
OpenACC data clause semantics to the 2.5 behavior", but not all of them.

libgomp/
* oacc-mem.c (acc_present_or_create): Remove definition and change
to alias of acc_create.
(acc_present_or_copyin): Remove definition and change to alias of
acc_copyin.
* oacc-parallel.c (GOACC_enter_exit_data): Call acc_create instead
of acc_present_or_create.
* testsuite/libgomp.oacc-c-c++-common/data-already-1.c: Remove.
* 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/trunk@267153 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 libgomp/ChangeLog  | 26 ++
 libgomp/oacc-mem.c | 55 --
 libgomp/oacc-parallel.c|  4 --
 .../libgomp.oacc-c-c++-common/data-already-1.c | 20 
 .../libgomp.oacc-c-c++-common/data-already-2.c | 20 
 .../libgomp.oacc-c-c++-common/data-already-3.c | 20 
 .../libgomp.oacc-c-c++-common/data-already-4.c | 18 ---
 .../libgomp.oacc-c-c++-common/data-already-5.c | 18 ---
 .../libgomp.oacc-c-c++-common/data-already-6.c | 18 ---
 .../libgomp.oacc-c-c++-common/data-already-7.c | 18 ---
 .../libgomp.oacc-c-c++-common/data-already-8.c | 20 
 .../libgomp.oacc-fortran/data-already-1.f  | 16 ---
 .../libgomp.oacc-fortran/data-already-2.f  | 16 ---
 .../libgomp.oacc-fortran/data-already-3.f  | 15 --
 .../libgomp.oacc-fortran/data-already-4.f  | 14 --
 .../libgomp.oacc-fortran/data-already-5.f  | 14 --
 .../libgomp.oacc-fortran/data-already-6.f  | 14 --
 .../libgomp.oacc-fortran/data-already-7.f  | 14 --
 .../libgomp.oacc-fortran/data-already-8.f  | 16 ---
 19 files changed, 55 insertions(+), 301 deletions(-)

diff --git libgomp/ChangeLog libgomp/ChangeLog
index 349497d58ee6..084f174513b0 100644
--- libgomp/ChangeLog
+++ libgomp/ChangeLog
@@ -1,3 +1,29 @@
+2018-12-14  Thomas Schwinge  
+   Chung-Lin Tang  
+
+   * oacc-mem.c (acc_pres

Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior - runtime

2018-06-20 Thread Cesar Philippidis
On 06/20/2018 10:03 AM, Jakub Jelinek wrote:
> On Wed, Jun 20, 2018 at 09:59:29AM -0700, Cesar Philippidis wrote:

>> If it means anything, we have a significant async change that removes
>> the async_refcount field in that struct.
> 
> Wasn't async_refcount removed 2 years ago?

You're right. I was looking at the og8 history. I'm juggling a lot of
patches right now.

Cesar


Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior - runtime

2018-06-20 Thread Jakub Jelinek
On Wed, Jun 20, 2018 at 09:59:29AM -0700, Cesar Philippidis wrote:
> > I'm not entirely happy about this, it grows the structure for not just
> > OpenACC, but also OpenMP which will never use it.  Are there any fields
> > not used by OpenACC?  E.g. is link_key used?
> > Or could the dynamic refcounts be an array allocated (for OpenACC mappings
> > only) after the tgt->array array, accessed using
> > key->tgt->dynamic_refcounts[key - key->tgt->array] ?
> Sorry, I mistakenly committed this patch with the front end changes. Can
> I address this issue in a follow up patch?

Yes.  If it isn't possible to get rid of it, I can live with it, but would
appreciate if you tried to avoid it if possible.

> If it means anything, we have a significant async change that removes
> the async_refcount field in that struct.

Wasn't async_refcount removed 2 years ago?

Jakub


Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior - runtime

2018-06-20 Thread Cesar Philippidis
On 06/20/2018 09:45 AM, Jakub Jelinek wrote:
> On Tue, Jun 19, 2018 at 10:01:20AM -0700, Cesar Philippidis wrote:

>> >From 53ee03231c5e6e4747b4ef01335079a2d4a98480 Mon Sep 17 00:00:00 2001
>> From: Cesar Philippidis 
>> Date: Tue, 19 Jun 2018 09:33:04 -0700
>> Subject: [PATCH 7/7] runtime changes
>>
>> ---
>>  libgomp/libgomp.h   |   7 +-
>>  libgomp/libgomp.map |  12 +++
>>  libgomp/oacc-mem.c  | 196 ---
>>  libgomp/oacc-parallel.c | 198 ++--
>>  libgomp/openacc.f90 | 112 +++
>>  libgomp/openacc.h   |   6 ++
>>  libgomp/openacc_lib.h   |  40 
>>  libgomp/target.c|  41 -
>>  8 files changed, 528 insertions(+), 84 deletions(-)
>>
>> diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h
>> index 10ea8940c96..3a8cc2bd7d6 100644
>> --- a/libgomp/libgomp.h
>> +++ b/libgomp/libgomp.h
>> @@ -853,6 +853,8 @@ struct splay_tree_key_s {
>>uintptr_t tgt_offset;
>>/* Reference count.  */
>>uintptr_t refcount;
>> +  /* Dynamic reference count.  */
>> +  uintptr_t dynamic_refcount;
>>/* Pointer to the original mapping of "omp declare target link" object.  
>> */
>>splay_tree_key link_key;
>>  };
> 
> I'm not entirely happy about this, it grows the structure for not just
> OpenACC, but also OpenMP which will never use it.  Are there any fields
> not used by OpenACC?  E.g. is link_key used?
> Or could the dynamic refcounts be an array allocated (for OpenACC mappings
> only) after the tgt->array array, accessed using
> key->tgt->dynamic_refcounts[key - key->tgt->array] ?
Sorry, I mistakenly committed this patch with the front end changes. Can
I address this issue in a follow up patch?

If it means anything, we have a significant async change that removes
the async_refcount field in that struct.

Cesar


Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior - runtime

2018-06-20 Thread Jakub Jelinek
On Tue, Jun 19, 2018 at 10:01:20AM -0700, Cesar Philippidis wrote:
> This patch implements the OpenACC 2.5 data clause semantics in libgomp.
> 
> Is it OK for trunk?

> 2018-06-19  Chung-Lin Tang 
>   Thomas Schwinge 
>   Cesar Philippidis  
> 
>   libgomp/
>   * libgomp.h (struct splay_tree_key_s): Add dynamic_refcount member.
>   (gomp_acc_remove_pointer): Update declaration.
>   (gomp_acc_declare_allocate): Declare.
>   (gomp_remove_var): Declare.
>   * libgomp.map (OACC_2.5): Define.
>   * oacc-mem.c (acc_map_data): Update refcount.
>   (acc_unmap_data): Likewise.
>   (present_create_copy): Likewise.
>   (acc_create): Add FLAG_PRESENT when calling present_create_copy.
>   (acc_copyin): Likewise.
>   (FLAG_FINALIZE): Define.
>   (delete_copyout): Update dynamic refcounts, add support for FINALIZE.
>   (acc_delete_finalize): New function.
>   (acc_delete_finalize_async): New function.
>   (acc_copyout_finalize): New function.
>   (acc_copyout_finalize_async): New function.
>   (gomp_acc_insert_pointer): Update refcounts.
>   (gomp_acc_remove_pointer): Return if data is not present on the
>   accelerator.
>   * oacc-parallel.c (find_pset): Rename to find_pointer.
>   (find_pointer): Add support for GOMP_MAP_POINTER.
>   (handle_ftn_pointers): New function.
>   (GOACC_parallel_keyed): Update refcounts of variables.
>   (GOACC_enter_exit_data): Add support for finalized data mappings.
>   Add support for GOMP_MAP_{TO,ALLOC,RELESE,FROM}. Update handling
>   of fortran arrays.
>   (GOACC_update): Add support for GOMP_MAP_{ALWAYS_POINTER,TO,FROM}.
>   (GOACC_declare): Add support for GOMP_MAP_RELEASE, remove support
>   for GOMP_MAP_FORCE_FROM.
>   * openacc.f90 (module openacc_internal): Add
>   acc_copyout_finalize_{32_h,64_h,array_h,_l}, and
>   acc_delete_finalize_{32_h,64_h,array_h,_l}. Add interfaces for
>   acc_copyout_finalize and acc_delete_finalize.
>   (acc_copyout_finalize_32_h): New subroutine.
>   (acc_copyout_finalize_64_h): New subroutine.
>   (acc_copyout_finalize_array_h): New subroutine.
>   (acc_delete_finalize_32_h): New subroutine.
>   (acc_delete_finalize_64_h): New subroutine.
>   (acc_delete_finalize_array_h): New subroutine.
>   * openacc.h (acc_copyout_finalize): Declare.
>   (acc_copyout_finalize_async): Declare.
>   (acc_delete_finalize): Declare.
>   (acc_delete_finalize_async): Declare.
>   * openacc_lib.h (acc_copyout_finalize): New interface.
>   (acc_delete_finalize): New interface.
>   * target.c (gomp_map_vars): Update dynamic_refcount.
>   (gomp_remove_var): New function.
>   (gomp_unmap_vars): Use it.
>   (gomp_unload_image_from_device): Likewise.
> 
> 
> >From 53ee03231c5e6e4747b4ef01335079a2d4a98480 Mon Sep 17 00:00:00 2001
> From: Cesar Philippidis 
> Date: Tue, 19 Jun 2018 09:33:04 -0700
> Subject: [PATCH 7/7] runtime changes
> 
> ---
>  libgomp/libgomp.h   |   7 +-
>  libgomp/libgomp.map |  12 +++
>  libgomp/oacc-mem.c  | 196 ---
>  libgomp/oacc-parallel.c | 198 ++--
>  libgomp/openacc.f90 | 112 +++
>  libgomp/openacc.h   |   6 ++
>  libgomp/openacc_lib.h   |  40 
>  libgomp/target.c|  41 -
>  8 files changed, 528 insertions(+), 84 deletions(-)
> 
> diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h
> index 10ea8940c96..3a8cc2bd7d6 100644
> --- a/libgomp/libgomp.h
> +++ b/libgomp/libgomp.h
> @@ -853,6 +853,8 @@ struct splay_tree_key_s {
>uintptr_t tgt_offset;
>/* Reference count.  */
>uintptr_t refcount;
> +  /* Dynamic reference count.  */
> +  uintptr_t dynamic_refcount;
>/* Pointer to the original mapping of "omp declare target link" object.  */
>splay_tree_key link_key;
>  };

I'm not entirely happy about this, it grows the structure for not just
OpenACC, but also OpenMP which will never use it.  Are there any fields
not used by OpenACC?  E.g. is link_key used?
Or could the dynamic refcounts be an array allocated (for OpenACC mappings
only) after the tgt->array array, accessed using
key->tgt->dynamic_refcounts[key - key->tgt->array] ?

Jakub


Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior - middle end

2018-06-20 Thread Jakub Jelinek
On Tue, Jun 19, 2018 at 10:00:37AM -0700, Cesar Philippidis wrote:
> This patch implements the OpenACC 2.5 data clause semantics in the
> middle end.
> 
> Is it OK for trunk?
> 
> Cesar

> 2018-06-19  Chung-Lin Tang 
>   Thomas Schwinge 
>   Cesar Philippidis  
> 
>   gcc/c-family/
>   * c-pragma.h (enum pragma_omp_clause): Add
>   PRAGMA_OACC_CLAUSE_{FINALIZE,IF_PRESENT}. Remove
>   PRAGMA_OACC_CLAUSE_PRESENT_OR_{COPY,COPYIN,COPYOUT,CREATE}.
> 
>   gcc/
>   * gimplify.c (gimplify_scan_omp_clauses): Add support for
>   OMP_CLAUSE_{IF_PRESENT,FINALIZE}.
>   (gimplify_adjust_omp_clauses): Likewise.
>   (gimplify_oacc_declare_1): Add support for GOMP_MAP_RELEASE, remove
>   support for GOMP_MAP_FORCE_{ALLOC,TO,FROM,TOFROM}.
>   (gimplify_omp_target_update): Update handling of acc update and
>   enter/exit data.
>   * omp-low.c (install_var_field): Remove unused parameter
>   base_pointers_restrict.
>   (scan_sharing_clauses): Remove base_pointers_restrict parameter.
>   Update call to install_var_field. Handle OMP_CLAUSE_{IF_PRESENT,
>   FINALIZE}
>   (omp_target_base_pointers_restrict_p): Delete.
>   (scan_omp_target): Update call to scan_sharing_clauses.
>   * tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_{IF_PRESENT,
>   FINALIZE}.
>   * tree-nested.c (convert_nonlocal_omp_clauses): Handle
>   OMP_CLAUSE_{IF_PRESENT,FINALIZE}.
>   (convert_local_omp_clauses): Likewise.
>   * tree-pretty-print.c (dump_omp_clause): Likewise.
>   * tree.c (omp_clause_num_ops): Add entries for  OMP_CLAUSE_{IF_PRESENT,
>   FINALIZE}.
>   (omp_clause_code_name): Likewise.

Ok.

Jakub


Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior - Fortran

2018-06-20 Thread Jakub Jelinek
On Tue, Jun 19, 2018 at 09:59:57AM -0700, Cesar Philippidis wrote:
> This patch implements the OpenACC 2.5 data clause semantics in the
> Fortran FE.
> 
> Is it OK for trunk?
> 
> Cesar

> 2018-06-19  Chung-Lin Tang 
>   Thomas Schwinge 
>   Cesar Philippidis  
> 
>   gcc/fortran/
>   * gfortran.h (gfc_omp_clauses): Add unsigned if_present, finalize
>   bitfields.
>   * openmp.c (enum omp_mask2): Remove OMP_CLAUSE_PRESENT_OR_*. Add
>   OMP_CLAUSE_{IF_PRESENT,FINALIZE}.
>   (gfc_match_omp_clauses): Update handling of copy, copyin, copyout,
>   create, deviceptr, present_of_*. Add support for finalize and
>   if_present.
>   (OACC_PARALLEL_CLAUSES): Remove PRESENT_OR_* clauses.
>   (OACC_KERNELS_CLAUSES): Likewise.
>   (OACC_DATA_CLAUSES): Likewise.
>   (OACC_DECLARE_CLAUSES): Likewise.
>   (OACC_UPDATE_CLAUSES): Add IF_PRESENT clause.
>   (OACC_ENTER_DATA_CLAUSES): Remove PRESENT_OR_* clauses.
>   (OACC_EXIT_DATA_CLAUSES): Add FINALIZE clause.
>   (gfc_match_oacc_declare): Update to OpenACC 2.5 semantics.
>   * trans-openmp.c (gfc_trans_omp_clauses): Add support for IF_PRESENT
>   and FINALIZE.

Ok.

Jakub


Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior - C++

2018-06-20 Thread Jakub Jelinek
On Tue, Jun 19, 2018 at 09:58:26AM -0700, Cesar Philippidis wrote:
> This patch implements the OpenACC 2.5 data clause semantics in the C++ FE.
> 
> Is it OK for trunk?
> 
> Cesar

> 2018-06-19  Chung-Lin Tang 
>   Thomas Schwinge 
>   Cesar Philippidis  
> 
>   gcc/cp/
>   * parser.c (cp_parser_omp_clause_name): Add support for finalize
>   and if_present. Make present_or_{copy,copyin,copyout,create} aliases
>   to their non-present_or_* counterparts. Make 'self' an alias to
>   PRAGMA_OACC_CLAUSE_HOST.
>   (cp_parser_oacc_data_clause): Update GOMP mappings for
>   PRAGMA_OACC_CLAUSE_{COPY,COPYIN,COPYOUT,CREATE,DELETE}. Remove
>   PRAGMA_OACC_CLAUSE_{SELF,PRESENT_OR_*}.
>   (cp_parser_oacc_all_clauses): Handle finalize and if_present clauses.
>   Remove support for present_or_* clauses.
>   (OACC_KERNELS_CLAUSE_MASK): Remove PRESENT_OR_* clauses.
>   (OACC_PARALLEL_CLAUSE_MASK): Likewise.
>   (OACC_DECLARE_CLAUSE_MASK): Likewise.
>   (OACC_DATA_CLAUSE_MASK): Likewise.
>   (OACC_ENTER_DATA_CLAUSE_MASK): Remove PRESENT_OR_* clauses.
>   (OACC_EXIT_DATA_CLAUSE_MASK): Add FINALIZE clause.
>   (OACC_UPDATE_CLAUSE_MASK): Remove SELF, add IF_PRESENT.
>   (cp_parser_oacc_declare): Remove PRESENT_OR_* clauses.
>   * pt.c (tsubst_omp_clauses): Handle IF_PRESENT and FINALIZE.
>   * semantics.c (finish_omp_clauses): Handle IF_PRESENT and FINALIZE.

Ok, thanks.

Jakub


Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior - C

2018-06-20 Thread Jakub Jelinek
On Tue, Jun 19, 2018 at 09:59:09AM -0700, Cesar Philippidis wrote:
> This patch implements the OpenACC 2.5 data clause semantics in the C FE.
> 
> Is it OK for trunk?
> 
> Cesar

> 2018-06-19  Chung-Lin Tang 
>   Thomas Schwinge 
>   Cesar Philippidis  
> 
>   gcc/c/
>   * c-parser.c (c_parser_omp_clause_name): Add support for finalize
>   and if_present. Make present_or_{copy,copyin,copyout,create} aliases
>   to their non-present_or_* counterparts. Make 'self' an alias to
>   PRAGMA_OACC_CLAUSE_HOST.
>   (c_parser_oacc_data_clause): Update GOMP mappings for
>   PRAGMA_OACC_CLAUSE_{COPY,COPYIN,COPYOUT,CREATE,DELETE}. Remove
>   PRAGMA_OACC_CLAUSE_{SELF,PRESENT_OR_*}.
>   (c_parser_oacc_all_clauses): Handle finalize and if_present clauses.
>   Remove support for present_or_* clauses.
>   (OACC_KERNELS_CLAUSE_MASK): Remove PRESENT_OR_* clauses.
>   (OACC_PARALLEL_CLAUSE_MASK): Likewise.
>   (OACC_DECLARE_CLAUSE_MASK): Likewise.
>   (OACC_DATA_CLAUSE_MASK): Likewise.
>   (OACC_ENTER_DATA_CLAUSE_MASK): Remove PRESENT_OR_* clauses.
>   (OACC_EXIT_DATA_CLAUSE_MASK): Add FINALIZE clause.
>   (OACC_UPDATE_CLAUSE_MASK): Remove SELF, add IF_PRESENT.
>   (c_parser_oacc_declare): Remove PRESENT_OR_* clauses.
>   * c-typeck.c (c_finish_omp_clauses): Handle IF_PRESENT and FINALIZE.

Ok.

Jakub


Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior - runtime tests

2018-06-19 Thread Cesar Philippidis
This patch updates the existing OpenACC libgomp runtime tests with the
new OpenACC 2.5 data clause semantics.

Is it OK for trunk?

Cesar
2018-06-19  Chung-Lin Tang 
	Thomas Schwinge 
	Cesar Philippidis  

	libgomp/
	* testsuite/libgomp.oacc-c-c++-common/data-already-1.c: Update test
	case to utilize OpenACC 2.5 data clause semantics.
	* 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-c-c++-common/lib-16.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-25.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-32.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-83.c: Likewise.
	* testsuite/libgomp.oacc-fortran/data-5.f90: New test.
	* testsuite/libgomp.oacc-fortran/data-already-1.f: Update test case to
	utilize OpenACC 2.5 data clause semantics.
	* 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.
	* testsuite/libgomp.oacc-fortran/lib-32-1.f: Likewise.
	* testsuite/libgomp.oacc-fortran/lib-32-2.f: Likewise.


>From 43ba3412e27dda1fa619f39d2720bf109b83508c Mon Sep 17 00:00:00 2001
From: Cesar Philippidis 
Date: Tue, 19 Jun 2018 09:29:21 -0700
Subject: [PATCH 2/7] libgomp tests

---
 .../data-already-1.c  |  2 -
 .../data-already-2.c  |  2 -
 .../data-already-3.c  |  2 -
 .../data-already-4.c  |  2 -
 .../data-already-5.c  |  2 -
 .../data-already-6.c  |  2 -
 .../data-already-7.c  |  2 -
 .../data-already-8.c  |  2 -
 .../libgomp.oacc-c-c++-common/lib-16.c| 23 
 .../libgomp.oacc-c-c++-common/lib-25.c| 20 ---
 .../libgomp.oacc-c-c++-common/lib-32.c|  4 +-
 .../libgomp.oacc-c-c++-common/lib-83.c| 22 
 .../testsuite/libgomp.oacc-fortran/data-5.f90 | 56 +++
 .../libgomp.oacc-fortran/data-already-1.f |  2 -
 .../libgomp.oacc-fortran/data-already-2.f |  2 -
 .../libgomp.oacc-fortran/data-already-3.f |  2 -
 .../libgomp.oacc-fortran/data-already-4.f |  2 -
 .../libgomp.oacc-fortran/data-already-5.f |  2 -
 .../libgomp.oacc-fortran/data-already-6.f |  2 -
 .../libgomp.oacc-fortran/data-already-7.f |  2 -
 .../libgomp.oacc-fortran/data-already-8.f |  2 -
 .../testsuite/libgomp.oacc-fortran/lib-32-1.f |  4 +-
 .../testsuite/libgomp.oacc-fortran/lib-32-2.f |  4 +-
 23 files changed, 96 insertions(+), 69 deletions(-)
 create mode 100644 libgomp/testsuite/libgomp.oacc-fortran/data-5.f90

diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/data-already-1.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/data-already-1.c
index 0ed53a41a96..fd3b77dcff5 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/data-already-1.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/data-already-1.c
@@ -18,5 +18,3 @@ main (int argc, char *argv[])
 }
 
 /* { dg-output "CheCKpOInT(\n|\r\n|\r).*" } */
-/* { dg-output "Trying to map into device \\\[\[0-9a-fA-FxX\]+..\[0-9a-fA-FxX\]+\\\) object when \\\[\[0-9a-fA-FxX\]+..\[0-9a-fA-FxX\]+\\\) is already mapped" } */
-/* { dg-shouldfail "" } */
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/data-already-2.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/data-already-2.c
index 00adf2a2bf4..0118b2568e2 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/data-already-2.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/data-already-2.c
@@ -18,5 +18,3 @@ main (int argc, char *argv[])
 }
 
 /* { dg-output "CheCKpOInT(\n|\r\n|\r).*" } */
-/* { dg-output "Trying to map into device \\\[\[0-9a-fA-FxX\]+..\[0-9a-fA-FxX\]+\\\) object when \\\[\[0-9a-fA-FxX\]+..\[0-9a-fA-FxX\]+\\\) is already mapped" } */
-/* { dg-shouldfail "" } */
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/data-already-3.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/data-already-3.c
index 04073e323d9..b346c69826f 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/data-already-3.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/data-already-3.c
@@ -18,5 +18,3 @@ main (int argc, char *argv[])
 }
 
 /* { dg-output "CheCKpOInT(\n|\r\n|\r).*" } */
-/* { dg-output "already 

Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior - compiler tests

2018-06-19 Thread Cesar Philippidis
This patch updates the existing OpenACC compiler tests with the new
OpenACC 2.5 data clause semantics.

Is it OK for trunk?

Cesar
2018-06-19  Chung-Lin Tang 
	Thomas Schwinge 
	Cesar Philippidis  

	gcc/testsuite/
	* c-c++-common/goacc/declare-1.c: Update test case to utilize OpenACC
	2.5 data clause semantics.
	* c-c++-common/goacc/declare-2.c: Likewise.
	* c-c++-common/goacc/default-4.c: Likewise.
	* c-c++-common/goacc/finalize-1.c: New test.
	* c-c++-common/goacc/kernels-alias-2.c: Update test case to utilize
	OpenACC 2.5 data clause semantics.
	* c-c++-common/goacc/kernels-alias.c: Likewise.
	* c-c++-common/goacc/routine-5.c: Likewise.
	* c-c++-common/goacc/update-if_present-1.c: New test.
	* c-c++-common/goacc/update-if_present-2.c: New test.
	* g++.dg/goacc/template.C: Update test case to utilize OpenACC
	2.5 data clause semantics.
	* gfortran.dg/goacc/combined-directives.f90: Likewise.
	* gfortran.dg/goacc/data-tree.f95: Likewise.
	* gfortran.dg/goacc/declare-2.f95: Likewise.
	* gfortran.dg/goacc/default-4.f: Likewise.
	* gfortran.dg/goacc/enter-exit-data.f95: Likewise.
	* gfortran.dg/goacc/finalize-1.f: New test.
	* gfortran.dg/goacc/kernels-alias-2.f95: Update test case to utilize
	OpenACC 2.5 data clause semantics.
	* gfortran.dg/goacc/kernels-alias.f95: Likewise.
	* gfortran.dg/goacc/kernels-tree.f95: Likewise.
	* gfortran.dg/goacc/nested-function-1.f90: Likewise.
	* gfortran.dg/goacc/parallel-tree.f95: Likewise.
	* gfortran.dg/goacc/reduction-promotions.f90: Likewise.
	* gfortran.dg/goacc/update-if_present-1.f90: New test.
	* gfortran.dg/goacc/update-if_present-2.f90: New test.


>From 87819f5846a3d4aae3983740e09a0ac4e1eb866f Mon Sep 17 00:00:00 2001
From: Cesar Philippidis 
Date: Tue, 19 Jun 2018 09:28:54 -0700
Subject: [PATCH 1/7] compiler tests

---
 gcc/testsuite/c-c++-common/goacc/declare-1.c  |  12 ++
 gcc/testsuite/c-c++-common/goacc/declare-2.c  |  18 +--
 gcc/testsuite/c-c++-common/goacc/default-4.c  |   6 +-
 gcc/testsuite/c-c++-common/goacc/finalize-1.c |  28 
 .../c-c++-common/goacc/kernels-alias-2.c  |  10 +-
 .../c-c++-common/goacc/kernels-alias.c|  10 +-
 gcc/testsuite/c-c++-common/goacc/routine-5.c  | 150 +++---
 .../c-c++-common/goacc/update-if_present-1.c  |  28 
 .../c-c++-common/goacc/update-if_present-2.c  |  42 +
 gcc/testsuite/g++.dg/goacc/template.C |  13 +-
 .../gfortran.dg/goacc/combined-directives.f90 |   2 +-
 gcc/testsuite/gfortran.dg/goacc/data-tree.f95 |   8 +-
 gcc/testsuite/gfortran.dg/goacc/declare-2.f95 |   6 +-
 gcc/testsuite/gfortran.dg/goacc/default-4.f   |   6 +-
 .../gfortran.dg/goacc/enter-exit-data.f95 |   3 +
 gcc/testsuite/gfortran.dg/goacc/finalize-1.f  |  27 
 .../gfortran.dg/goacc/kernels-alias-2.f95 |  10 +-
 .../gfortran.dg/goacc/kernels-alias.f95   |  10 +-
 .../gfortran.dg/goacc/kernels-tree.f95|   8 +-
 .../gfortran.dg/goacc/nested-function-1.f90   |   8 +
 .../gfortran.dg/goacc/parallel-tree.f95   |  12 +-
 .../goacc/reduction-promotions.f90|   6 +-
 .../gfortran.dg/goacc/update-if_present-1.f90 |  27 
 .../gfortran.dg/goacc/update-if_present-2.f90 |  52 ++
 24 files changed, 345 insertions(+), 157 deletions(-)
 create mode 100644 gcc/testsuite/c-c++-common/goacc/finalize-1.c
 create mode 100644 gcc/testsuite/c-c++-common/goacc/update-if_present-1.c
 create mode 100644 gcc/testsuite/c-c++-common/goacc/update-if_present-2.c
 create mode 100644 gcc/testsuite/gfortran.dg/goacc/finalize-1.f
 create mode 100644 gcc/testsuite/gfortran.dg/goacc/update-if_present-1.f90
 create mode 100644 gcc/testsuite/gfortran.dg/goacc/update-if_present-2.f90

diff --git a/gcc/testsuite/c-c++-common/goacc/declare-1.c b/gcc/testsuite/c-c++-common/goacc/declare-1.c
index b036c636166..35b1ccd367b 100644
--- a/gcc/testsuite/c-c++-common/goacc/declare-1.c
+++ b/gcc/testsuite/c-c++-common/goacc/declare-1.c
@@ -19,6 +19,12 @@ int v4;
 int v5, v6, v7, v8;
 #pragma acc declare create(v5, v6) copyin(v7, v8)
 
+int v9;
+#pragma acc declare present_or_copyin(v9)
+
+int v10;
+#pragma acc declare present_or_create(v10)
+
 void
 f (void)
 {
@@ -49,6 +55,12 @@ f (void)
   extern int ve4;
 #pragma acc declare link(ve4)
 
+  extern int ve5;
+#pragma acc declare present_or_copyin(ve5)
+ 
+  extern int ve6;
+#pragma acc declare present_or_create(ve6)
+
   int va5;
 #pragma acc declare copy(va5)
 
diff --git a/gcc/testsuite/c-c++-common/goacc/declare-2.c b/gcc/testsuite/c-c++-common/goacc/declare-2.c
index e41a0f59537..33b82459bfc 100644
--- a/gcc/testsuite/c-c++-common/goacc/declare-2.c
+++ b/gcc/testsuite/c-c++-common/goacc/declare-2.c
@@ -29,13 +29,7 @@ int v6;
 #pragma acc declare present_or_copy(v6) /* { dg-error "at file scope" } */
 
 int v7;
-#pragma acc declare present_or_copyin(v7) /* { dg-error "at file scope" } */
-
-int v8;
-#pragma acc declare present_or_copyout(v8) /* { dg-error "at file scope" } */
-
-int v9;
-#pragma acc declare present_or_create(v9) /* { dg-error "at 

Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior - runtime

2018-06-19 Thread Cesar Philippidis
This patch implements the OpenACC 2.5 data clause semantics in libgomp.

Is it OK for trunk?

Cesar
2018-06-19  Chung-Lin Tang 
	Thomas Schwinge 
	Cesar Philippidis  

	libgomp/
	* libgomp.h (struct splay_tree_key_s): Add dynamic_refcount member.
	(gomp_acc_remove_pointer): Update declaration.
	(gomp_acc_declare_allocate): Declare.
	(gomp_remove_var): Declare.
	* libgomp.map (OACC_2.5): Define.
	* oacc-mem.c (acc_map_data): Update refcount.
	(acc_unmap_data): Likewise.
	(present_create_copy): Likewise.
	(acc_create): Add FLAG_PRESENT when calling present_create_copy.
	(acc_copyin): Likewise.
	(FLAG_FINALIZE): Define.
	(delete_copyout): Update dynamic refcounts, add support for FINALIZE.
	(acc_delete_finalize): New function.
	(acc_delete_finalize_async): New function.
	(acc_copyout_finalize): New function.
	(acc_copyout_finalize_async): New function.
	(gomp_acc_insert_pointer): Update refcounts.
	(gomp_acc_remove_pointer): Return if data is not present on the
	accelerator.
	* oacc-parallel.c (find_pset): Rename to find_pointer.
	(find_pointer): Add support for GOMP_MAP_POINTER.
	(handle_ftn_pointers): New function.
	(GOACC_parallel_keyed): Update refcounts of variables.
	(GOACC_enter_exit_data): Add support for finalized data mappings.
	Add support for GOMP_MAP_{TO,ALLOC,RELESE,FROM}. Update handling
	of fortran arrays.
	(GOACC_update): Add support for GOMP_MAP_{ALWAYS_POINTER,TO,FROM}.
	(GOACC_declare): Add support for GOMP_MAP_RELEASE, remove support
	for GOMP_MAP_FORCE_FROM.
	* openacc.f90 (module openacc_internal): Add
	acc_copyout_finalize_{32_h,64_h,array_h,_l}, and
	acc_delete_finalize_{32_h,64_h,array_h,_l}. Add interfaces for
	acc_copyout_finalize and acc_delete_finalize.
	(acc_copyout_finalize_32_h): New subroutine.
	(acc_copyout_finalize_64_h): New subroutine.
	(acc_copyout_finalize_array_h): New subroutine.
	(acc_delete_finalize_32_h): New subroutine.
	(acc_delete_finalize_64_h): New subroutine.
	(acc_delete_finalize_array_h): New subroutine.
	* openacc.h (acc_copyout_finalize): Declare.
	(acc_copyout_finalize_async): Declare.
	(acc_delete_finalize): Declare.
	(acc_delete_finalize_async): Declare.
	* openacc_lib.h (acc_copyout_finalize): New interface.
	(acc_delete_finalize): New interface.
	* target.c (gomp_map_vars): Update dynamic_refcount.
	(gomp_remove_var): New function.
	(gomp_unmap_vars): Use it.
	(gomp_unload_image_from_device): Likewise.


>From 53ee03231c5e6e4747b4ef01335079a2d4a98480 Mon Sep 17 00:00:00 2001
From: Cesar Philippidis 
Date: Tue, 19 Jun 2018 09:33:04 -0700
Subject: [PATCH 7/7] runtime changes

---
 libgomp/libgomp.h   |   7 +-
 libgomp/libgomp.map |  12 +++
 libgomp/oacc-mem.c  | 196 ---
 libgomp/oacc-parallel.c | 198 ++--
 libgomp/openacc.f90 | 112 +++
 libgomp/openacc.h   |   6 ++
 libgomp/openacc_lib.h   |  40 
 libgomp/target.c|  41 -
 8 files changed, 528 insertions(+), 84 deletions(-)

diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h
index 10ea8940c96..3a8cc2bd7d6 100644
--- a/libgomp/libgomp.h
+++ b/libgomp/libgomp.h
@@ -853,6 +853,8 @@ struct splay_tree_key_s {
   uintptr_t tgt_offset;
   /* Reference count.  */
   uintptr_t refcount;
+  /* Dynamic reference count.  */
+  uintptr_t dynamic_refcount;
   /* Pointer to the original mapping of "omp declare target link" object.  */
   splay_tree_key link_key;
 };
@@ -991,7 +993,9 @@ enum gomp_map_vars_kind
 };
 
 extern void gomp_acc_insert_pointer (size_t, void **, size_t *, void *);
-extern void gomp_acc_remove_pointer (void *, bool, int, int);
+extern void gomp_acc_remove_pointer (void *, size_t, bool, int, int, int);
+extern void gomp_acc_declare_allocate (bool, size_t, void **, size_t *,
+   unsigned short *);
 
 extern struct target_mem_desc *gomp_map_vars (struct gomp_device_descr *,
 	  size_t, void **, void **,
@@ -1001,6 +1005,7 @@ extern void gomp_unmap_vars (struct target_mem_desc *, bool);
 extern void gomp_init_device (struct gomp_device_descr *);
 extern void gomp_free_memmap (struct splay_tree_s *);
 extern void gomp_unload_device (struct gomp_device_descr *);
+extern bool gomp_remove_var (struct gomp_device_descr *, splay_tree_key);
 
 /* work.c */
 
diff --git a/libgomp/libgomp.map b/libgomp/libgomp.map
index 8752348fbf2..2cd3bf524bc 100644
--- a/libgomp/libgomp.map
+++ b/libgomp/libgomp.map
@@ -386,6 +386,18 @@ OACC_2.0.1 {
 	acc_pcreate;
 } OACC_2.0;
 
+OACC_2.5 {
+  global:
+	acc_copyout_finalize;
+	acc_copyout_finalize_32_h_;
+	acc_copyout_finalize_64_h_;
+	acc_copyout_finalize_array_h_;
+	acc_delete_finalize;
+	acc_delete_finalize_32_h_;
+	acc_delete_finalize_64_h_;
+	acc_delete_finalize_array_h_;
+} OACC_2.0.1;
+
 GOACC_2.0 {
   global:
 	GOACC_data_end;
diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index 158f0862018..3787ce49e38 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -347,6 +347,7 @@ acc_map_data (void 

Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior - middle end

2018-06-19 Thread Cesar Philippidis
This patch implements the OpenACC 2.5 data clause semantics in the
middle end.

Is it OK for trunk?

Cesar
2018-06-19  Chung-Lin Tang 
	Thomas Schwinge 
	Cesar Philippidis  

	gcc/c-family/
	* c-pragma.h (enum pragma_omp_clause): Add
	PRAGMA_OACC_CLAUSE_{FINALIZE,IF_PRESENT}. Remove
	PRAGMA_OACC_CLAUSE_PRESENT_OR_{COPY,COPYIN,COPYOUT,CREATE}.

	gcc/
	* gimplify.c (gimplify_scan_omp_clauses): Add support for
	OMP_CLAUSE_{IF_PRESENT,FINALIZE}.
	(gimplify_adjust_omp_clauses): Likewise.
	(gimplify_oacc_declare_1): Add support for GOMP_MAP_RELEASE, remove
	support for GOMP_MAP_FORCE_{ALLOC,TO,FROM,TOFROM}.
	(gimplify_omp_target_update): Update handling of acc update and
	enter/exit data.
	* omp-low.c (install_var_field): Remove unused parameter
	base_pointers_restrict.
	(scan_sharing_clauses): Remove base_pointers_restrict parameter.
	Update call to install_var_field. Handle OMP_CLAUSE_{IF_PRESENT,
	FINALIZE}
	(omp_target_base_pointers_restrict_p): Delete.
	(scan_omp_target): Update call to scan_sharing_clauses.
	* tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_{IF_PRESENT,
	FINALIZE}.
	* tree-nested.c (convert_nonlocal_omp_clauses): Handle
	OMP_CLAUSE_{IF_PRESENT,FINALIZE}.
	(convert_local_omp_clauses): Likewise.
	* tree-pretty-print.c (dump_omp_clause): Likewise.
	* tree.c (omp_clause_num_ops): Add entries for 	OMP_CLAUSE_{IF_PRESENT,
	FINALIZE}.
	(omp_clause_code_name): Likewise.


>From f79b0e6f0d796dc18ef1faf20b9fad0b7feeaa94 Mon Sep 17 00:00:00 2001
From: Cesar Philippidis 
Date: Tue, 19 Jun 2018 09:32:20 -0700
Subject: [PATCH 6/7] gcc middle end

---
 gcc/c-family/c-pragma.h |  6 +--
 gcc/gimplify.c  | 67 ++---
 gcc/omp-low.c   | 93 +
 gcc/tree-core.h |  8 +++-
 gcc/tree-nested.c   |  4 ++
 gcc/tree-pretty-print.c |  6 +++
 gcc/tree.c  |  8 +++-
 7 files changed, 88 insertions(+), 104 deletions(-)

diff --git a/gcc/c-family/c-pragma.h b/gcc/c-family/c-pragma.h
index c70380c211b..b322547b11a 100644
--- a/gcc/c-family/c-pragma.h
+++ b/gcc/c-family/c-pragma.h
@@ -138,16 +138,13 @@ enum pragma_omp_clause {
   PRAGMA_OACC_CLAUSE_DELETE,
   PRAGMA_OACC_CLAUSE_DEVICEPTR,
   PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT,
+  PRAGMA_OACC_CLAUSE_FINALIZE,
   PRAGMA_OACC_CLAUSE_GANG,
   PRAGMA_OACC_CLAUSE_HOST,
   PRAGMA_OACC_CLAUSE_INDEPENDENT,
   PRAGMA_OACC_CLAUSE_NUM_GANGS,
   PRAGMA_OACC_CLAUSE_NUM_WORKERS,
   PRAGMA_OACC_CLAUSE_PRESENT,
-  PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY,
-  PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN,
-  PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT,
-  PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE,
   PRAGMA_OACC_CLAUSE_SELF,
   PRAGMA_OACC_CLAUSE_SEQ,
   PRAGMA_OACC_CLAUSE_TILE,
@@ -156,6 +153,7 @@ enum pragma_omp_clause {
   PRAGMA_OACC_CLAUSE_VECTOR_LENGTH,
   PRAGMA_OACC_CLAUSE_WAIT,
   PRAGMA_OACC_CLAUSE_WORKER,
+  PRAGMA_OACC_CLAUSE_IF_PRESENT,
   PRAGMA_OACC_CLAUSE_COLLAPSE = PRAGMA_OMP_CLAUSE_COLLAPSE,
   PRAGMA_OACC_CLAUSE_COPYIN = PRAGMA_OMP_CLAUSE_COPYIN,
   PRAGMA_OACC_CLAUSE_DEVICE = PRAGMA_OMP_CLAUSE_DEVICE,
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 1523a27e828..97543ed5f70 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -8524,6 +8524,8 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
 	case OMP_CLAUSE_NOGROUP:
 	case OMP_CLAUSE_THREADS:
 	case OMP_CLAUSE_SIMD:
+	case OMP_CLAUSE_IF_PRESENT:
+	case OMP_CLAUSE_FINALIZE:
 	  break;
 
 	case OMP_CLAUSE_DEFAULTMAP:
@@ -9305,6 +9307,8 @@ gimplify_adjust_omp_clauses (gimple_seq *pre_p, gimple_seq body, tree *list_p,
 	case OMP_CLAUSE_AUTO:
 	case OMP_CLAUSE_SEQ:
 	case OMP_CLAUSE_TILE:
+	case OMP_CLAUSE_IF_PRESENT:
+	case OMP_CLAUSE_FINALIZE:
 	  break;
 
 	default:
@@ -9361,21 +9365,7 @@ gimplify_oacc_declare_1 (tree clause)
   switch (kind)
 {
   case GOMP_MAP_ALLOC:
-  case GOMP_MAP_FORCE_ALLOC:
-  case GOMP_MAP_FORCE_TO:
-	new_op = GOMP_MAP_DELETE;
-	ret = true;
-	break;
-
-  case GOMP_MAP_FORCE_FROM:
-	OMP_CLAUSE_SET_MAP_KIND (clause, GOMP_MAP_FORCE_ALLOC);
-	new_op = GOMP_MAP_FORCE_FROM;
-	ret = true;
-	break;
-
-  case GOMP_MAP_FORCE_TOFROM:
-	OMP_CLAUSE_SET_MAP_KIND (clause, GOMP_MAP_FORCE_TO);
-	new_op = GOMP_MAP_FORCE_FROM;
+	new_op = GOMP_MAP_RELEASE;
 	ret = true;
 	break;
 
@@ -10817,6 +10807,53 @@ gimplify_omp_target_update (tree *expr_p, gimple_seq *pre_p)
 			 ort, TREE_CODE (expr));
   gimplify_adjust_omp_clauses (pre_p, NULL, _STANDALONE_CLAUSES (expr),
 			   TREE_CODE (expr));
+  if (TREE_CODE (expr) == OACC_UPDATE
+  && omp_find_clause (OMP_STANDALONE_CLAUSES (expr),
+			  OMP_CLAUSE_IF_PRESENT))
+{
+  /* The runtime uses GOMP_MAP_{TO,FROM} to denote the if_present
+	 clause.  */
+  for (tree c = OMP_STANDALONE_CLAUSES (expr); c; c = OMP_CLAUSE_CHAIN (c))
+	if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
+	  switch (OMP_CLAUSE_MAP_KIND (c))
+	{
+	case GOMP_MAP_FORCE_TO:
+	  OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
+	  break;
+	case 

Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior - Fortran

2018-06-19 Thread Cesar Philippidis
This patch implements the OpenACC 2.5 data clause semantics in the
Fortran FE.

Is it OK for trunk?

Cesar
2018-06-19  Chung-Lin Tang 
	Thomas Schwinge 
	Cesar Philippidis  

	gcc/fortran/
	* gfortran.h (gfc_omp_clauses): Add unsigned if_present, finalize
	bitfields.
	* openmp.c (enum omp_mask2): Remove OMP_CLAUSE_PRESENT_OR_*. Add
	OMP_CLAUSE_{IF_PRESENT,FINALIZE}.
	(gfc_match_omp_clauses): Update handling of copy, copyin, copyout,
	create, deviceptr, present_of_*. Add support for finalize and
	if_present.
	(OACC_PARALLEL_CLAUSES): Remove PRESENT_OR_* clauses.
	(OACC_KERNELS_CLAUSES): Likewise.
	(OACC_DATA_CLAUSES): Likewise.
	(OACC_DECLARE_CLAUSES): Likewise.
	(OACC_UPDATE_CLAUSES): Add IF_PRESENT clause.
	(OACC_ENTER_DATA_CLAUSES): Remove PRESENT_OR_* clauses.
	(OACC_EXIT_DATA_CLAUSES): Add FINALIZE clause.
	(gfc_match_oacc_declare): Update to OpenACC 2.5 semantics.
	* trans-openmp.c (gfc_trans_omp_clauses): Add support for IF_PRESENT
	and FINALIZE.


>From 5a74cac327d44a6674a608c3fd3b80f2e04d0b47 Mon Sep 17 00:00:00 2001
From: Cesar Philippidis 
Date: Tue, 19 Jun 2018 09:31:57 -0700
Subject: [PATCH 5/7] fortran front end

---
 gcc/fortran/gfortran.h |   1 +
 gcc/fortran/openmp.c   | 105 -
 gcc/fortran/trans-openmp.c |  10 
 3 files changed, 67 insertions(+), 49 deletions(-)

diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 1d98d2554c7..0b89f8de950 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -1344,6 +1344,7 @@ typedef struct gfc_omp_clauses
   gfc_expr_list *tile_list;
   unsigned async:1, gang:1, worker:1, vector:1, seq:1, independent:1;
   unsigned wait:1, par_auto:1, gang_static:1;
+  unsigned if_present:1, finalize:1;
   locus loc;
 
 }
diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
index 97d6e782373..94a7f7eaa50 100644
--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -796,10 +796,6 @@ enum omp_mask2
   OMP_CLAUSE_COPYOUT,
   OMP_CLAUSE_CREATE,
   OMP_CLAUSE_PRESENT,
-  OMP_CLAUSE_PRESENT_OR_COPY,
-  OMP_CLAUSE_PRESENT_OR_COPYIN,
-  OMP_CLAUSE_PRESENT_OR_COPYOUT,
-  OMP_CLAUSE_PRESENT_OR_CREATE,
   OMP_CLAUSE_DEVICEPTR,
   OMP_CLAUSE_GANG,
   OMP_CLAUSE_WORKER,
@@ -813,6 +809,8 @@ enum omp_mask2
   OMP_CLAUSE_DELETE,
   OMP_CLAUSE_AUTO,
   OMP_CLAUSE_TILE,
+  OMP_CLAUSE_IF_PRESENT,
+  OMP_CLAUSE_FINALIZE,
   /* This must come last.  */
   OMP_MASK2_LAST
 };
@@ -1041,7 +1039,7 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask,
 	  if ((mask & OMP_CLAUSE_COPY)
 	  && gfc_match ("copy ( ") == MATCH_YES
 	  && gfc_match_omp_map_clause (>lists[OMP_LIST_MAP],
-	   OMP_MAP_FORCE_TOFROM))
+	   OMP_MAP_TOFROM))
 	continue;
 	  if (mask & OMP_CLAUSE_COPYIN)
 	{
@@ -1049,7 +1047,7 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask,
 		{
 		  if (gfc_match ("copyin ( ") == MATCH_YES
 		  && gfc_match_omp_map_clause (>lists[OMP_LIST_MAP],
-		   OMP_MAP_FORCE_TO))
+		   OMP_MAP_TO))
 		continue;
 		}
 	  else if (gfc_match_omp_variable_list ("copyin (",
@@ -1060,7 +1058,7 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask,
 	  if ((mask & OMP_CLAUSE_COPYOUT)
 	  && gfc_match ("copyout ( ") == MATCH_YES
 	  && gfc_match_omp_map_clause (>lists[OMP_LIST_MAP],
-	   OMP_MAP_FORCE_FROM))
+	   OMP_MAP_FROM))
 	continue;
 	  if ((mask & OMP_CLAUSE_COPYPRIVATE)
 	  && gfc_match_omp_variable_list ("copyprivate (",
@@ -1070,7 +1068,7 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask,
 	  if ((mask & OMP_CLAUSE_CREATE)
 	  && gfc_match ("create ( ") == MATCH_YES
 	  && gfc_match_omp_map_clause (>lists[OMP_LIST_MAP],
-	   OMP_MAP_FORCE_ALLOC))
+	   OMP_MAP_ALLOC))
 	continue;
 	  break;
 	case 'd':
@@ -1106,7 +1104,7 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask,
 	  if ((mask & OMP_CLAUSE_DELETE)
 	  && gfc_match ("delete ( ") == MATCH_YES
 	  && gfc_match_omp_map_clause (>lists[OMP_LIST_MAP],
-	   OMP_MAP_DELETE))
+	   OMP_MAP_RELEASE))
 	continue;
 	  if ((mask & OMP_CLAUSE_DEPEND)
 	  && gfc_match ("depend ( ") == MATCH_YES)
@@ -1161,19 +1159,10 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask,
 	   OMP_MAP_FORCE_TO))
 	continue;
 	  if ((mask & OMP_CLAUSE_DEVICEPTR)
-	  && gfc_match ("deviceptr ( ") == MATCH_YES)
-	{
-	  gfc_omp_namelist **list = >lists[OMP_LIST_MAP];
-	  gfc_omp_namelist **head = NULL;
-	  if (gfc_match_omp_variable_list ("", list, true, NULL,
-	   , false) == MATCH_YES)
-		{
-		  gfc_omp_namelist *n;
-		  for (n = *head; n; n = n->next)
-		n->u.map_op = OMP_MAP_FORCE_DEVICEPTR;
-		  continue;
-		}
-	}
+	  && gfc_match ("deviceptr ( ") == MATCH_YES
+	  && gfc_match_omp_map_clause (>lists[OMP_LIST_MAP],
+	   OMP_MAP_FORCE_DEVICEPTR))
+	continue;
 	  if ((mask & OMP_CLAUSE_DEVICE_RESIDENT)
 	  && 

Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior - C

2018-06-19 Thread Cesar Philippidis
This patch implements the OpenACC 2.5 data clause semantics in the C FE.

Is it OK for trunk?

Cesar
2018-06-19  Chung-Lin Tang 
	Thomas Schwinge 
	Cesar Philippidis  

	gcc/c/
	* c-parser.c (c_parser_omp_clause_name): Add support for finalize
	and if_present. Make present_or_{copy,copyin,copyout,create} aliases
	to their non-present_or_* counterparts. Make 'self' an alias to
	PRAGMA_OACC_CLAUSE_HOST.
	(c_parser_oacc_data_clause): Update GOMP mappings for
	PRAGMA_OACC_CLAUSE_{COPY,COPYIN,COPYOUT,CREATE,DELETE}. Remove
	PRAGMA_OACC_CLAUSE_{SELF,PRESENT_OR_*}.
	(c_parser_oacc_all_clauses): Handle finalize and if_present clauses.
	Remove support for present_or_* clauses.
	(OACC_KERNELS_CLAUSE_MASK): Remove PRESENT_OR_* clauses.
	(OACC_PARALLEL_CLAUSE_MASK): Likewise.
	(OACC_DECLARE_CLAUSE_MASK): Likewise.
	(OACC_DATA_CLAUSE_MASK): Likewise.
	(OACC_ENTER_DATA_CLAUSE_MASK): Remove PRESENT_OR_* clauses.
	(OACC_EXIT_DATA_CLAUSE_MASK): Add FINALIZE clause.
	(OACC_UPDATE_CLAUSE_MASK): Remove SELF, add IF_PRESENT.
	(c_parser_oacc_declare): Remove PRESENT_OR_* clauses.
	* c-typeck.c (c_finish_omp_clauses): Handle IF_PRESENT and FINALIZE.


>From 03ce56dc85f6b35e873688d482fd0b9570242c3f Mon Sep 17 00:00:00 2001
From: Cesar Philippidis 
Date: Tue, 19 Jun 2018 09:31:14 -0700
Subject: [PATCH 4/7] c front end

---
 gcc/c/c-parser.c | 115 +++
 gcc/c/c-typeck.c |   2 +
 2 files changed, 39 insertions(+), 78 deletions(-)

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 6b41a615dbd..7a926285f3a 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -11259,6 +11259,8 @@ c_parser_omp_clause_name (c_parser *parser)
 	case 'f':
 	  if (!strcmp ("final", p))
 	result = PRAGMA_OMP_CLAUSE_FINAL;
+	  else if (!strcmp ("finalize", p))
+	result = PRAGMA_OACC_CLAUSE_FINALIZE;
 	  else if (!strcmp ("firstprivate", p))
 	result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
 	  else if (!strcmp ("from", p))
@@ -11277,7 +11279,9 @@ c_parser_omp_clause_name (c_parser *parser)
 	result = PRAGMA_OACC_CLAUSE_HOST;
 	  break;
 	case 'i':
-	  if (!strcmp ("inbranch", p))
+	  if (!strcmp ("if_present", p))
+	result = PRAGMA_OACC_CLAUSE_IF_PRESENT;
+	  else if (!strcmp ("inbranch", p))
 	result = PRAGMA_OMP_CLAUSE_INBRANCH;
 	  else if (!strcmp ("independent", p))
 	result = PRAGMA_OACC_CLAUSE_INDEPENDENT;
@@ -11325,18 +11329,20 @@ c_parser_omp_clause_name (c_parser *parser)
 	result = PRAGMA_OMP_CLAUSE_PARALLEL;
 	  else if (!strcmp ("present", p))
 	result = PRAGMA_OACC_CLAUSE_PRESENT;
+	  /* As of OpenACC 2.5, these are now aliases of the non-present_or
+	 clauses.  */
 	  else if (!strcmp ("present_or_copy", p)
 		   || !strcmp ("pcopy", p))
-	result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY;
+	result = PRAGMA_OACC_CLAUSE_COPY;
 	  else if (!strcmp ("present_or_copyin", p)
 		   || !strcmp ("pcopyin", p))
-	result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN;
+	result = PRAGMA_OACC_CLAUSE_COPYIN;
 	  else if (!strcmp ("present_or_copyout", p)
 		   || !strcmp ("pcopyout", p))
-	result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT;
+	result = PRAGMA_OACC_CLAUSE_COPYOUT;
 	  else if (!strcmp ("present_or_create", p)
 		   || !strcmp ("pcreate", p))
-	result = PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE;
+	result = PRAGMA_OACC_CLAUSE_CREATE;
 	  else if (!strcmp ("priority", p))
 	result = PRAGMA_OMP_CLAUSE_PRIORITY;
 	  else if (!strcmp ("private", p))
@@ -11355,6 +11361,8 @@ c_parser_omp_clause_name (c_parser *parser)
 	result = PRAGMA_OMP_CLAUSE_SCHEDULE;
 	  else if (!strcmp ("sections", p))
 	result = PRAGMA_OMP_CLAUSE_SECTIONS;
+	  else if (!strcmp ("self", p)) /* "self" is a synonym for "host".  */
+	result = PRAGMA_OACC_CLAUSE_HOST;
 	  else if (!strcmp ("seq", p))
 	result = PRAGMA_OACC_CLAUSE_SEQ;
 	  else if (!strcmp ("shared", p))
@@ -11363,8 +11371,6 @@ c_parser_omp_clause_name (c_parser *parser)
 	result = PRAGMA_OMP_CLAUSE_SIMD;
 	  else if (!strcmp ("simdlen", p))
 	result = PRAGMA_OMP_CLAUSE_SIMDLEN;
-	  else if (!strcmp ("self", p))
-	result = PRAGMA_OACC_CLAUSE_SELF;
 	  break;
 	case 't':
 	  if (!strcmp ("taskgroup", p))
@@ -11646,15 +11652,7 @@ c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
copyout ( variable-list )
create ( variable-list )
delete ( variable-list )
-   present ( variable-list )
-   present_or_copy ( variable-list )
- pcopy ( variable-list )
-   present_or_copyin ( variable-list )
- pcopyin ( variable-list )
-   present_or_copyout ( variable-list )
- pcopyout ( variable-list )
-   present_or_create ( variable-list )
- pcreate ( variable-list ) */
+   present ( variable-list ) */
 
 static tree
 c_parser_oacc_data_clause (c_parser *parser, pragma_omp_clause c_kind,
@@ -11664,19 +11662,19 @@ c_parser_oacc_data_clause (c_parser *parser, pragma_omp_clause c_kind,
   switch (c_kind)
 {
 case PRAGMA_OACC_CLAUSE_COPY:
-  

Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior - C++

2018-06-19 Thread Cesar Philippidis
This patch implements the OpenACC 2.5 data clause semantics in the C++ FE.

Is it OK for trunk?

Cesar
2018-06-19  Chung-Lin Tang 
	Thomas Schwinge 
	Cesar Philippidis  

	gcc/cp/
	* parser.c (cp_parser_omp_clause_name): Add support for finalize
	and if_present. Make present_or_{copy,copyin,copyout,create} aliases
	to their non-present_or_* counterparts. Make 'self' an alias to
	PRAGMA_OACC_CLAUSE_HOST.
	(cp_parser_oacc_data_clause): Update GOMP mappings for
	PRAGMA_OACC_CLAUSE_{COPY,COPYIN,COPYOUT,CREATE,DELETE}. Remove
	PRAGMA_OACC_CLAUSE_{SELF,PRESENT_OR_*}.
	(cp_parser_oacc_all_clauses): Handle finalize and if_present clauses.
	Remove support for present_or_* clauses.
	(OACC_KERNELS_CLAUSE_MASK): Remove PRESENT_OR_* clauses.
	(OACC_PARALLEL_CLAUSE_MASK): Likewise.
	(OACC_DECLARE_CLAUSE_MASK): Likewise.
	(OACC_DATA_CLAUSE_MASK): Likewise.
	(OACC_ENTER_DATA_CLAUSE_MASK): Remove PRESENT_OR_* clauses.
	(OACC_EXIT_DATA_CLAUSE_MASK): Add FINALIZE clause.
	(OACC_UPDATE_CLAUSE_MASK): Remove SELF, add IF_PRESENT.
	(cp_parser_oacc_declare): Remove PRESENT_OR_* clauses.
	* pt.c (tsubst_omp_clauses): Handle IF_PRESENT and FINALIZE.
	* semantics.c (finish_omp_clauses): Handle IF_PRESENT and FINALIZE.


>From 8d4e76446e128d74d67c5eb367445e6e1f62b46c Mon Sep 17 00:00:00 2001
From: Cesar Philippidis 
Date: Tue, 19 Jun 2018 09:30:20 -0700
Subject: [PATCH 3/7] c++ front end

---
 gcc/cp/parser.c| 114 ++---
 gcc/cp/pt.c|   2 +
 gcc/cp/semantics.c |   2 +
 3 files changed, 40 insertions(+), 78 deletions(-)

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index c6206fc353c..902ec9c205c 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -31372,6 +31372,8 @@ cp_parser_omp_clause_name (cp_parser *parser)
 	case 'f':
 	  if (!strcmp ("final", p))
 	result = PRAGMA_OMP_CLAUSE_FINAL;
+	  else if (!strcmp ("finalize", p))
+	result = PRAGMA_OACC_CLAUSE_FINALIZE;
 	  else if (!strcmp ("firstprivate", p))
 	result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
 	  else if (!strcmp ("from", p))
@@ -31390,7 +31392,9 @@ cp_parser_omp_clause_name (cp_parser *parser)
 	result = PRAGMA_OACC_CLAUSE_HOST;
 	  break;
 	case 'i':
-	  if (!strcmp ("inbranch", p))
+	  if (!strcmp ("if_present", p))
+	result = PRAGMA_OACC_CLAUSE_IF_PRESENT;
+	  else if (!strcmp ("inbranch", p))
 	result = PRAGMA_OMP_CLAUSE_INBRANCH;
 	  else if (!strcmp ("independent", p))
 	result = PRAGMA_OACC_CLAUSE_INDEPENDENT;
@@ -31440,16 +31444,16 @@ cp_parser_omp_clause_name (cp_parser *parser)
 	result = PRAGMA_OACC_CLAUSE_PRESENT;
 	  else if (!strcmp ("present_or_copy", p)
 		   || !strcmp ("pcopy", p))
-	result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY;
+	result = PRAGMA_OACC_CLAUSE_COPY;
 	  else if (!strcmp ("present_or_copyin", p)
 		   || !strcmp ("pcopyin", p))
-	result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN;
+	result = PRAGMA_OACC_CLAUSE_COPYIN;
 	  else if (!strcmp ("present_or_copyout", p)
 		   || !strcmp ("pcopyout", p))
-	result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT;
+	result = PRAGMA_OACC_CLAUSE_COPYOUT;
 	  else if (!strcmp ("present_or_create", p)
 		   || !strcmp ("pcreate", p))
-	result = PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE;
+	result = PRAGMA_OACC_CLAUSE_CREATE;
 	  else if (!strcmp ("priority", p))
 	result = PRAGMA_OMP_CLAUSE_PRIORITY;
 	  else if (!strcmp ("proc_bind", p))
@@ -31466,8 +31470,8 @@ cp_parser_omp_clause_name (cp_parser *parser)
 	result = PRAGMA_OMP_CLAUSE_SCHEDULE;
 	  else if (!strcmp ("sections", p))
 	result = PRAGMA_OMP_CLAUSE_SECTIONS;
-	  else if (!strcmp ("self", p))
-	result = PRAGMA_OACC_CLAUSE_SELF;
+	  else if (!strcmp ("self", p)) /* "self" is a synonym for "host".  */
+	result = PRAGMA_OACC_CLAUSE_HOST;
 	  else if (!strcmp ("seq", p))
 	result = PRAGMA_OACC_CLAUSE_SEQ;
 	  else if (!strcmp ("shared", p))
@@ -31727,15 +31731,7 @@ cp_parser_omp_var_list (cp_parser *parser, enum omp_clause_code kind, tree list)
copyout ( variable-list )
create ( variable-list )
delete ( variable-list )
-   present ( variable-list )
-   present_or_copy ( variable-list )
- pcopy ( variable-list )
-   present_or_copyin ( variable-list )
- pcopyin ( variable-list )
-   present_or_copyout ( variable-list )
- pcopyout ( variable-list )
-   present_or_create ( variable-list )
- pcreate ( variable-list ) */
+   present ( variable-list ) */
 
 static tree
 cp_parser_oacc_data_clause (cp_parser *parser, pragma_omp_clause c_kind,
@@ -31745,19 +31741,19 @@ cp_parser_oacc_data_clause (cp_parser *parser, pragma_omp_clause c_kind,
   switch (c_kind)
 {
 case PRAGMA_OACC_CLAUSE_COPY:
-  kind = GOMP_MAP_FORCE_TOFROM;
+  kind = GOMP_MAP_TOFROM;
   break;
 case PRAGMA_OACC_CLAUSE_COPYIN:
-  kind = GOMP_MAP_FORCE_TO;
+  kind = GOMP_MAP_TO;
   break;
 case PRAGMA_OACC_CLAUSE_COPYOUT:
-  kind = GOMP_MAP_FORCE_FROM;
+  kind = GOMP_MAP_FROM;
   break;

Re: [OpenACC] Update OpenACC data clause semantics to the 2.5 behavior

2018-06-19 Thread Cesar Philippidis
Ping.

To make this patch easier to review, I'll split it into individual
patches for each major component in follow up emails.

Cesar

On 05/25/2018 01:01 PM, Cesar Philippidis wrote:
> This patch updates GCC's to support OpenACC 2.5's data clause semantics. 
> In OpenACC 2.5, copy, copyin and copyout all behave like their 
> present_or_* counterparts in OpenACC 2.0. The patch also adds support 
> for the new finalize and if_present data clauses introduced in OpenACC 
> 2.5. The finalize clause introduced some new reference counting behavior 
> in the runtime; whereas 'acc exit data copyout' decrements the reference 
> count of a variable, 'acc exit data finalize' actually removes it from 
> the accelerator regardless of there are any pending references to it.
> 
> Due to the size of this patch, I had to compress it. However, despite 
> the size of the patch, which is mainly due to the augmented test cases, 
> it fairly noninvasive. I was originally going to include support for 
> declare allocate and deallocate, but those require more extensive 
> modifications to the fortran FE.
> 
> Is this patch OK for trunk? I tested with x86_64-linux with nvptx 
> acceleration.
> 
> Thanks,
> Cesar
> 
> 2018-05-25  Chung-Lin Tang 
>   Thomas Schwinge 
>   Cesar Philippidis  
> 
>   gcc/c-family/
>   * c-pragma.h (enum pragma_omp_clause): Add
>   PRAGMA_OACC_CLAUSE_{FINALIZE,IF_PRESENT}. Remove
>   PRAGMA_OACC_CLAUSE_PRESENT_OR_{COPY,COPYIN,COPYOUT,CREATE}.
> 
>   gcc/c/
>   * c-parser.c (c_parser_omp_clause_name): Add support for finalize
>   and if_present. Make present_or_{copy,copyin,copyout,create} aliases
>   to their non-present_or_* counterparts. Make 'self' an alias to
>   PRAGMA_OACC_CLAUSE_HOST.
>   (c_parser_oacc_data_clause): Update GOMP mappings for
>   PRAGMA_OACC_CLAUSE_{COPY,COPYIN,COPYOUT,CREATE,DELETE}. Remove
>   PRAGMA_OACC_CLAUSE_{SELF,PRESENT_OR_*}.
>   (c_parser_oacc_all_clauses): Handle finalize and if_present clauses.
>   Remove support for present_or_* clauses.
>   (OACC_KERNELS_CLAUSE_MASK): Remove PRESENT_OR_* clauses.
>   (OACC_PARALLEL_CLAUSE_MASK): Likewise.
>   (OACC_DECLARE_CLAUSE_MASK): Likewise.
>   (OACC_DATA_CLAUSE_MASK): Likewise.
>   (OACC_ENTER_DATA_CLAUSE_MASK): Remove PRESENT_OR_* clauses.
>   (OACC_EXIT_DATA_CLAUSE_MASK): Add FINALIZE clause.
>   (OACC_UPDATE_CLAUSE_MASK): Remove SELF, add IF_PRESENT.
>   (c_parser_oacc_declare): Remove PRESENT_OR_* clauses.
>   * c-typeck.c (c_finish_omp_clauses): Handle IF_PRESENT and FINALIZE.
> 
>   gcc/cp/
>   * parser.c (cp_parser_omp_clause_name): Add support for finalize
>   and if_present. Make present_or_{copy,copyin,copyout,create} aliases
>   to their non-present_or_* counterparts. Make 'self' an alias to
>   PRAGMA_OACC_CLAUSE_HOST.
>   (cp_parser_oacc_data_clause): Update GOMP mappings for
>   PRAGMA_OACC_CLAUSE_{COPY,COPYIN,COPYOUT,CREATE,DELETE}. Remove
>   PRAGMA_OACC_CLAUSE_{SELF,PRESENT_OR_*}.
>   (cp_parser_oacc_all_clauses): Handle finalize and if_present clauses.
>   Remove support for present_or_* clauses.
>   (OACC_KERNELS_CLAUSE_MASK): Remove PRESENT_OR_* clauses.
>   (OACC_PARALLEL_CLAUSE_MASK): Likewise.
>   (OACC_DECLARE_CLAUSE_MASK): Likewise.
>   (OACC_DATA_CLAUSE_MASK): Likewise.
>   (OACC_ENTER_DATA_CLAUSE_MASK): Remove PRESENT_OR_* clauses.
>   (OACC_EXIT_DATA_CLAUSE_MASK): Add FINALIZE clause.
>   (OACC_UPDATE_CLAUSE_MASK): Remove SELF, add IF_PRESENT.
>   (cp_parser_oacc_declare): Remove PRESENT_OR_* clauses.
>   * pt.c (tsubst_omp_clauses): Handle IF_PRESENT and FINALIZE.
>   * semantics.c (finish_omp_clauses): Handle IF_PRESENT and FINALIZE.
> 
>   gcc/fortran/
>   * gfortran.h (gfc_omp_clauses): Add unsigned if_present, finalize
>   bitfields.
>   * openmp.c (enum omp_mask2): Remove OMP_CLAUSE_PRESENT_OR_*. Add
>   OMP_CLAUSE_{IF_PRESENT,FINALIZE}.
>   (gfc_match_omp_clauses): Update handling of copy, copyin, copyout,
>   create, deviceptr, present_of_*. Add support for finalize and
>   if_present.
>   (OACC_PARALLEL_CLAUSES): Remove PRESENT_OR_* clauses.
>   (OACC_KERNELS_CLAUSES): Likewise.
>   (OACC_DATA_CLAUSES): Likewise.
>   (OACC_DECLARE_CLAUSES): Likewise.
>   (OACC_UPDATE_CLAUSES): Add IF_PRESENT clause.
>   (OACC_ENTER_DATA_CLAUSES): Remove PRESENT_OR_* clauses.
>   (OACC_EXIT_DATA_CLAUSES): Add FINALIZE clause.
>   (gfc_match_oacc_declare): Update to OpenACC 2.5 semantics.
>   * trans-openmp.c (gfc_trans_omp_clauses): Add support for IF_PRESENT
>   and FINALIZE.
> 
>   gcc/
>   * gimplify.c (gimplify_scan_omp_clauses): Add support for
>   OMP_CLAUSE_{IF_PRESENT,FINALIZE}.
>   (gimplify_adjust_omp_clauses): Likewise.
>   (gimplify_oacc_declare_1): Add support for GOMP_MAP_RELEASE, remove
>   support for 

[OpenACC] Update OpenACC data clause semantics to the 2.5 behavior

2018-05-25 Thread Cesar Philippidis
This patch updates GCC's to support OpenACC 2.5's data clause semantics. 
In OpenACC 2.5, copy, copyin and copyout all behave like their 
present_or_* counterparts in OpenACC 2.0. The patch also adds support 
for the new finalize and if_present data clauses introduced in OpenACC 
2.5. The finalize clause introduced some new reference counting behavior 
in the runtime; whereas 'acc exit data copyout' decrements the reference 
count of a variable, 'acc exit data finalize' actually removes it from 
the accelerator regardless of there are any pending references to it.

Due to the size of this patch, I had to compress it. However, despite 
the size of the patch, which is mainly due to the augmented test cases, 
it fairly noninvasive. I was originally going to include support for 
declare allocate and deallocate, but those require more extensive 
modifications to the fortran FE.

Is this patch OK for trunk? I tested with x86_64-linux with nvptx 
acceleration.

Thanks,
Cesar

2018-05-25  Chung-Lin Tang 
Thomas Schwinge 
Cesar Philippidis  

gcc/c-family/
* c-pragma.h (enum pragma_omp_clause): Add
PRAGMA_OACC_CLAUSE_{FINALIZE,IF_PRESENT}. Remove
PRAGMA_OACC_CLAUSE_PRESENT_OR_{COPY,COPYIN,COPYOUT,CREATE}.

gcc/c/
* c-parser.c (c_parser_omp_clause_name): Add support for finalize
and if_present. Make present_or_{copy,copyin,copyout,create} aliases
to their non-present_or_* counterparts. Make 'self' an alias to
PRAGMA_OACC_CLAUSE_HOST.
(c_parser_oacc_data_clause): Update GOMP mappings for
PRAGMA_OACC_CLAUSE_{COPY,COPYIN,COPYOUT,CREATE,DELETE}. Remove
PRAGMA_OACC_CLAUSE_{SELF,PRESENT_OR_*}.
(c_parser_oacc_all_clauses): Handle finalize and if_present clauses.
Remove support for present_or_* clauses.
(OACC_KERNELS_CLAUSE_MASK): Remove PRESENT_OR_* clauses.
(OACC_PARALLEL_CLAUSE_MASK): Likewise.
(OACC_DECLARE_CLAUSE_MASK): Likewise.
(OACC_DATA_CLAUSE_MASK): Likewise.
(OACC_ENTER_DATA_CLAUSE_MASK): Remove PRESENT_OR_* clauses.
(OACC_EXIT_DATA_CLAUSE_MASK): Add FINALIZE clause.
(OACC_UPDATE_CLAUSE_MASK): Remove SELF, add IF_PRESENT.
(c_parser_oacc_declare): Remove PRESENT_OR_* clauses.
* c-typeck.c (c_finish_omp_clauses): Handle IF_PRESENT and FINALIZE.

gcc/cp/
* parser.c (cp_parser_omp_clause_name): Add support for finalize
and if_present. Make present_or_{copy,copyin,copyout,create} aliases
to their non-present_or_* counterparts. Make 'self' an alias to
PRAGMA_OACC_CLAUSE_HOST.
(cp_parser_oacc_data_clause): Update GOMP mappings for
PRAGMA_OACC_CLAUSE_{COPY,COPYIN,COPYOUT,CREATE,DELETE}. Remove
PRAGMA_OACC_CLAUSE_{SELF,PRESENT_OR_*}.
(cp_parser_oacc_all_clauses): Handle finalize and if_present clauses.
Remove support for present_or_* clauses.
(OACC_KERNELS_CLAUSE_MASK): Remove PRESENT_OR_* clauses.
(OACC_PARALLEL_CLAUSE_MASK): Likewise.
(OACC_DECLARE_CLAUSE_MASK): Likewise.
(OACC_DATA_CLAUSE_MASK): Likewise.
(OACC_ENTER_DATA_CLAUSE_MASK): Remove PRESENT_OR_* clauses.
(OACC_EXIT_DATA_CLAUSE_MASK): Add FINALIZE clause.
(OACC_UPDATE_CLAUSE_MASK): Remove SELF, add IF_PRESENT.
(cp_parser_oacc_declare): Remove PRESENT_OR_* clauses.
* pt.c (tsubst_omp_clauses): Handle IF_PRESENT and FINALIZE.
* semantics.c (finish_omp_clauses): Handle IF_PRESENT and FINALIZE.

gcc/fortran/
* gfortran.h (gfc_omp_clauses): Add unsigned if_present, finalize
bitfields.
* openmp.c (enum omp_mask2): Remove OMP_CLAUSE_PRESENT_OR_*. Add
OMP_CLAUSE_{IF_PRESENT,FINALIZE}.
(gfc_match_omp_clauses): Update handling of copy, copyin, copyout,
create, deviceptr, present_of_*. Add support for finalize and
if_present.
(OACC_PARALLEL_CLAUSES): Remove PRESENT_OR_* clauses.
(OACC_KERNELS_CLAUSES): Likewise.
(OACC_DATA_CLAUSES): Likewise.
(OACC_DECLARE_CLAUSES): Likewise.
(OACC_UPDATE_CLAUSES): Add IF_PRESENT clause.
(OACC_ENTER_DATA_CLAUSES): Remove PRESENT_OR_* clauses.
(OACC_EXIT_DATA_CLAUSES): Add FINALIZE clause.
(gfc_match_oacc_declare): Update to OpenACC 2.5 semantics.
* trans-openmp.c (gfc_trans_omp_clauses): Add support for IF_PRESENT
and FINALIZE.

gcc/
* gimplify.c (gimplify_scan_omp_clauses): Add support for
OMP_CLAUSE_{IF_PRESENT,FINALIZE}.
(gimplify_adjust_omp_clauses): Likewise.
(gimplify_oacc_declare_1): Add support for GOMP_MAP_RELEASE, remove
support for GOMP_MAP_FORCE_{ALLOC,TO,FROM,TOFROM}.
(gimplify_omp_target_update): Update handling of acc update and
enter/exit data.
* omp-low.c