[committed] [PR85221] Set 'omp declare target', 'omp declare target link' attributes for Fortran OpenACC 'declare'd variables (was: [gomp4] Re: OpenACC declare directive updates)

2019-06-18 Thread Thomas Schwinge
Hi!

On Fri, 27 Nov 2015 12:37:23 +0100, I wrote:
> On Thu, 19 Nov 2015 10:22:16 -0600, James Norris  
> wrote:
> > [...]

> Merging your trunk r230722 and r230725 with the existing Fortran OpenACC
> declare implementation present on gomp-4_0-branch, I effectively applied
> the following to gomp-4_0-branch in 231002.  Please verify this.
> 
> Regarding my Fortran XFAIL comments in
> ,
> with some of my earlier changes "#if 0"ed in
> gcc/fortran/trans-decl.c:add_attributes_to_decl,
> libgomp.oacc-fortran/declare-3.f90 again PASSes.  But I don't understand
> (why something like) this code (isn't needed/done differently in C/C++).

There remains a lot of mystery to be resolved regarding the OpenACC
'declare' implementation...  :-(

> --- gcc/fortran/trans-decl.c
> +++ gcc/fortran/trans-decl.c
> @@ -1302,15 +1302,20 @@ add_attributes_to_decl (symbol_attribute sym_attr, 
> tree list)
>}
>  
>if (sym_attr.omp_declare_target
> +#if 0 /* TODO */
>|| sym_attr.oacc_declare_create
>|| sym_attr.oacc_declare_copyin
>|| sym_attr.oacc_declare_deviceptr
> -  || sym_attr.oacc_declare_device_resident)
> +  || sym_attr.oacc_declare_device_resident
> +#endif
> +  )
>  list = tree_cons (get_identifier ("omp declare target"),
> NULL_TREE, list);
> +#if 0 /* TODO */
>if (sym_attr.oacc_declare_link)
>  list = tree_cons (get_identifier ("omp declare target link"),
> NULL_TREE, list);
> +#endif

As PR85221 "[openacc] ICE in install_var_field, at omp-low.c:657" tells
us, yes, these are actually necessary.

I'm confused why not all OpenACC 'declare' clauses are handled here, but
looking into that is for another day, or week.

Committed to trunk in r272453 "[PR85221] Set 'omp declare target', 'omp
declare target link' attributes for Fortran OpenACC 'declare'd
variables", see attached.


Grüße
 Thomas


From b7194d24d942998da2ab8f6f5dc080e3fff81972 Mon Sep 17 00:00:00 2001
From: tschwinge 
Date: Tue, 18 Jun 2019 22:15:43 +
Subject: [PATCH] [PR85221] Set 'omp declare target', 'omp declare target link'
 attributes for Fortran OpenACC 'declare'd variables

	gcc/fortran/
	PR fortran/85221
	* trans-decl.c (add_attributes_to_decl): Handle OpenACC 'declare'
	directive.
	gcc/testsuite/
	PR fortran/85221
	* gfortran.dg/goacc/declare-3.f95: New file.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@272453 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/fortran/ChangeLog |  6 +++
 gcc/fortran/trans-decl.c  |  9 +++-
 gcc/testsuite/ChangeLog   |  3 ++
 gcc/testsuite/gfortran.dg/goacc/declare-3.f95 | 47 +++
 4 files changed, 63 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/goacc/declare-3.f95

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index d30fa2e50a88..6fd97b61ce05 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,9 @@
+2019-06-18  Thomas Schwinge  
+
+	PR fortran/85221
+	* trans-decl.c (add_attributes_to_decl): Handle OpenACC 'declare'
+	directive.
+
 2019-06-16  Thomas Koenig  
 
 	* dump_parse_tree (debug): Add verison for formal arglist.
diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index b8e07274febd..f504c279c31b 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -1432,10 +1432,15 @@ add_attributes_to_decl (symbol_attribute sym_attr, tree list)
   list = oacc_replace_fn_attrib_attr (list, dims);
 }
 
-  if (sym_attr.omp_declare_target_link)
+  if (sym_attr.omp_declare_target_link
+  || sym_attr.oacc_declare_link)
 list = tree_cons (get_identifier ("omp declare target link"),
 		  NULL_TREE, list);
-  else if (sym_attr.omp_declare_target)
+  else if (sym_attr.omp_declare_target
+	   || sym_attr.oacc_declare_create
+	   || sym_attr.oacc_declare_copyin
+	   || sym_attr.oacc_declare_deviceptr
+	   || sym_attr.oacc_declare_device_resident)
 list = tree_cons (get_identifier ("omp declare target"),
 		  clauses, list);
 
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 59d39e8c179a..552ccc6fbd68 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,8 @@
 2019-06-18  Thomas Schwinge  
 
+	PR fortran/85221
+	* gfortran.dg/goacc/declare-3.f95: New file.
+
 	PR middle-end/90859
 	* c-c++-common/goacc/firstprivate-mappings-1.c: Update.
 
diff --git a/gcc/testsuite/gfortran.dg/goacc/declare-3.f95 b/gcc/testsuite/gfortran.dg/goacc/declare-3.f95
new file mode 100644
index ..ec5d4c5a062a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/goacc/declare-3.f95
@@ -0,0 +1,47 @@
+! Test valid usage of the OpenACC 'declare' directive.
+
+module mod_a
+  implicit none
+  integer :: a
+  !$acc declare create (a)
+end module
+
+module mod_b
+  implicit none
+  integer :: b
+  !$acc declare copyin (b)
+end module
+
+module mod_c
+  

[gomp4] Re: OpenACC declare directive updates

2015-11-27 Thread Thomas Schwinge
Hi!

On Thu, 19 Nov 2015 10:22:16 -0600, James Norris  
wrote:
> --- a/gcc/fortran/dump-parse-tree.c
> +++ b/gcc/fortran/dump-parse-tree.c

Don't you need to handle OMP_LIST_LINK in
gcc/fortran/dump-parse-tree.c:show_omp_clauses; OMP_LIST_DEVICE_RESIDENT
is being handled there (but maps to the wrong string?).  (See
gomp-4_0-branch.)  When touching that, please sort the "case OMP_LIST_*"s
corresponding to the order the OMP_LIST_* are defined in
gcc/fortran/gfortran.h.

> --- a/gcc/fortran/openmp.c
> +++ b/gcc/fortran/openmp.c

I see OMP_LIST_DEVICE_RESIDENT being handled in
gcc/fortran/openmp.c:resolve_omp_clauses and
gcc/fortran/openmp.c:gfc_resolve_oacc_declare, but not OMP_LIST_LINK --
is that correct?  Likewise, in
gcc/fortran/trans-openmp.c:gfc_trans_omp_clauses.

Also, oacc_declare_device_resident is handled in a lot more places
compared to oacc_declare_link -- is that correct?  In fact, there doesn't
seem to be any "consumer" for the latter, but I see the OpenACC link
clause being used in the test cases you added, so I wonder how that
works.


Merging your trunk r230722 and r230725 with the existing Fortran OpenACC
declare implementation present on gomp-4_0-branch, I effectively applied
the following to gomp-4_0-branch in 231002.  Please verify this.

Regarding my Fortran XFAIL comments in
,
with some of my earlier changes "#if 0"ed in
gcc/fortran/trans-decl.c:add_attributes_to_decl,
libgomp.oacc-fortran/declare-3.f90 again PASSes.  But I don't understand
(why something like) this code (isn't needed/done differently in C/C++).
The XFAIL in libgomp.oacc-fortran/declare-1.f90 means to be resolved
(gomp-4_0-branch only; not seen on trunk): "libgomp: cuStreamSynchronize
error: an illegal memory access was encountered".

commit 95e909a492b001df6d6faffdfa6047a5e9919561
Merge: 8373bdf e18d05e
Author: tschwinge 
Date:   Fri Nov 27 09:41:03 2015 +

svn merge -r 230720:230725 svn+ssh://gcc.gnu.org/svn/gcc/trunk


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

 gcc/fortran/ChangeLog  |  51 +
 gcc/fortran/gfortran.h |  17 +-
 gcc/fortran/openmp.c   | 235 +
 gcc/fortran/parse.c|   2 +-
 gcc/fortran/parse.h|   2 +-
 gcc/fortran/resolve.c  |   1 -
 gcc/fortran/st.c   |   2 +-
 gcc/fortran/symbol.c   |  12 +-
 gcc/fortran/trans-decl.c   | 198 +
 gcc/fortran/trans-openmp.c |  29 +--
 gcc/fortran/trans-stmt.c   |   3 +-
 gcc/testsuite/ChangeLog|   6 +
 gcc/testsuite/gfortran.dg/goacc/declare-1.f95  |   4 +-
 gcc/testsuite/gfortran.dg/goacc/declare-2.f95  |  43 +++-
 libgomp/ChangeLog  |   9 +
 .../testsuite/libgomp.oacc-fortran/declare-1.f90   |  13 ++
 .../testsuite/libgomp.oacc-fortran/declare-2.f90   |   2 +
 .../testsuite/libgomp.oacc-fortran/declare-3.f90   |   4 +-
 .../testsuite/libgomp.oacc-fortran/declare-4.f90   |   2 +
 .../testsuite/libgomp.oacc-fortran/declare-5.f90   |   1 +
 20 files changed, 347 insertions(+), 289 deletions(-)

[diff --git gcc/fortran/ChangeLog gcc/fortran/ChangeLog]
diff --git gcc/fortran/gfortran.h gcc/fortran/gfortran.h
index c8401cf..dd186b5 100644
--- gcc/fortran/gfortran.h
+++ gcc/fortran/gfortran.h
@@ -1250,17 +1250,18 @@ gfc_omp_clauses;
 
 #define gfc_get_omp_clauses() XCNEW (gfc_omp_clauses)
 
-/* Node in the linked list used for storing OpenACC declare constructs.  */
+
+/* Node in the linked list used for storing !$oacc declare constructs.  */
 
 typedef struct gfc_oacc_declare
 {
   struct gfc_oacc_declare *next;
-  locus where;
   bool module_var;
   gfc_omp_clauses *clauses;
-  gfc_omp_clauses *return_clauses;
+  locus loc;
 }
 gfc_oacc_declare;
+
 #define gfc_get_oacc_declare() XCNEW (gfc_oacc_declare)
 
 
@@ -1685,8 +1686,8 @@ typedef struct gfc_namespace
  this namespace.  */
   struct gfc_data *data, *old_data;
 
-  /* !$ACC DECLARE clauses.  */
-  struct gfc_oacc_declare *oacc_declare;
+  /* !$ACC DECLARE.  */
+  gfc_oacc_declare *oacc_declare;
 
   /* !$ACC ROUTINE clauses.  */
   gfc_omp_clauses *oacc_routine_clauses;
@@ -2455,8 +2456,8 @@ typedef struct gfc_code
 struct gfc_code *which_construct;
 int stop_code;
 gfc_entry_list *entry;
-gfc_omp_clauses *omp_clauses;
 gfc_oacc_declare *oacc_declare;
+gfc_omp_clauses *omp_clauses;
 const char *omp_name;
 gfc_omp_namelist *omp_namelist;
 bool omp_bool;
@@ -2958,7 +2959,7 @@ gfc_expr *gfc_get_parentheses (gfc_expr *);
 /* openmp.c */
 struct gfc_omp_saved_state { void *ptrs[2]; int ints[1];

Re: OpenACC declare directive updates

2015-11-20 Thread Jakub Jelinek
On Thu, Nov 19, 2015 at 10:22:16AM -0600, James Norris wrote:
> 2015-XX-XX  James Norris  
>   Cesar Philippidis  
> 
>   gcc/fortran/
>   * dump-parse-tree.c (show_namespace): Handle declares.
>   * gfortran.h (struct symbol_attribute): New fields.
>   (enum gfc_omp_map_map): Add OMP_MAP_DEVICE_RESIDENT and OMP_MAP_LINK.
>   (OMP_LIST_LINK): New enum.
>   (struct gfc_oacc_declare): New structure.
>   (gfc_get_oacc_declare): New definition.
>   (struct gfc_namespace): Change type.
>   (enum gfc_exec_op): Add EXEC_OACC_DECLARE.
>   (struct gfc_code): New field.
>   * module.c (enum ab_attribute): Add AB_OACC_DECLARE_CREATE,
>   AB_OACC_DECLARE_COPYIN, AB_OACC_DECLARE_DEVICEPTR,
>   AB_OACC_DECLARE_DEVICE_RESIDENT, AB_OACC_DECLARE_LINK
>   (attr_bits): Add new initializers.
>   (mio_symbol_attribute): Handle new atributes.
>   * openmp.c (gfc_free_oacc_declare_clauses): New function.
>   (gfc_match_oacc_clause_link: Likewise.
>   (OMP_CLAUSE_LINK): New definition.
>   (gfc_match_omp_clauses): Handle OMP_CLAUSE_LINK.
>   (OACC_DECLARE_CLAUSES): Add OMP_CLAUSE_LINK
>   (gfc_match_oacc_declare): Add checking and module handling.
>   (gfc_resolve_oacc_declare): Reimplement.
>   * parse.c (case_decl): Add ST_OACC_DECLARE.
>   (parse_spec): Remove handling.
>   (parse_progunit): Remove handling.
>   * parse.h (struct gfc_state_data): Change type.
>   * resolve.c (gfc_resolve_blocks): Handle EXEC_OACC_DECLARE.
>   * st.c (gfc_free_statement): Handle EXEC_OACC_DECLARE.
>   * symbol.c (check_conflict): Add conflict checks.
>   (gfc_add_oacc_declare_create, gfc_add_oacc_declare_copyin, 
>   gfc_add_oacc_declare_deviceptr, gfc_add_oacc_declare_device_resident):
>   New functions.
>   (gfc_copy_attr): Handle new symbols.
>   * trans-decl.c (add_clause, find_module_oacc_declare_clauses,
>   finish_oacc_declare): New functions.
>   (gfc_generate_function_code): Replace with call.
>   * trans-openmp.c (gfc_trans_oacc_declare): Reimplement.
>   (gfc_trans_oacc_directive): Handle EXEC_OACC_DECLARE.
>   * trans-stmt.c (gfc_trans_block_construct): Replace with call.
>   * trans-stmt.h (gfc_trans_oacc_declare): Remove argument.
>   * trans.c (trans_code): Handle EXEC_OACC_DECLARE.
> 
>   gcc/testsuite
>   * gfortran.dg/goacc/declare-1.f95: Update test.
>   * gfortran.dg/goacc/declare-2.f95: New test.
> 
>   libgomp/
>   * testsuite/libgomp.oacc-fortran/declare-1.f90: New test.
>   * testsuite/libgomp.oacc-fortran/declare-2.f90: Likewise.
>   * testsuite/libgomp.oacc-fortran/declare-3.f90: Likewise.
>   * testsuite/libgomp.oacc-fortran/declare-4.f90: Likewise.
>   * testsuite/libgomp.oacc-fortran/declare-5.f90: Likewise.
>   * testsuite/libgomp.oacc-fortran/declare-5.f90: Likewise.

Ok.

Jakub


Re: OpenACC declare directive updates

2015-11-19 Thread James Norris

Jakub,

Here's the updated version of the Fortran changes. More test
cases have been added as well as the issues that Cesar
pointed on in error checking have been addressed (Thanks).
I've also addressed the issue, described below, in dealing
with declare directives when found within a BLOCK construct.

On 11/06/2015 01:49 PM, Jakub Jelinek wrote:

On Fri, Nov 06, 2015 at 01:45:09PM -0600, James Norris wrote:

Okay, I'll fix this.

After fixing, OK to commit?

Thank you for taking the time for the review.


Well, isn't this patch really dependent on the other one?

Also, wonder about BLOCK stmt in Fortran, that can give you variables that
don't live through the whole function, but only a portion of it even in
Fortran.




On 11/18/2015 02:09 PM, Cesar Philippidis wrote:
> On 11/08/2015 08:53 PM, James Norris wrote:
>
>
> What block stmt? The most recent version of Fortran OpenACC 2.0a
> supports is 2003. The block construct is a 2008 feature. I don't think
> that's applicable to this version. Jim, maybe you should add an error
> message for variables defined in blocks.
>
> Thinking about this some more, I wonder if we should emit an error if
> any acc constructs are used inside blocks? That's probably overly
> pessimistic though.

Thanks!
Jim

2015-XX-XX  James Norris  
Cesar Philippidis  

gcc/fortran/
* dump-parse-tree.c (show_namespace): Handle declares.
* gfortran.h (struct symbol_attribute): New fields.
(enum gfc_omp_map_map): Add OMP_MAP_DEVICE_RESIDENT and OMP_MAP_LINK.
(OMP_LIST_LINK): New enum.
(struct gfc_oacc_declare): New structure.
(gfc_get_oacc_declare): New definition.
(struct gfc_namespace): Change type.
(enum gfc_exec_op): Add EXEC_OACC_DECLARE.
(struct gfc_code): New field.
* module.c (enum ab_attribute): Add AB_OACC_DECLARE_CREATE,
AB_OACC_DECLARE_COPYIN, AB_OACC_DECLARE_DEVICEPTR,
AB_OACC_DECLARE_DEVICE_RESIDENT, AB_OACC_DECLARE_LINK
(attr_bits): Add new initializers.
(mio_symbol_attribute): Handle new atributes.
* openmp.c (gfc_free_oacc_declare_clauses): New function.
(gfc_match_oacc_clause_link: Likewise.
(OMP_CLAUSE_LINK): New definition.
(gfc_match_omp_clauses): Handle OMP_CLAUSE_LINK.
(OACC_DECLARE_CLAUSES): Add OMP_CLAUSE_LINK
(gfc_match_oacc_declare): Add checking and module handling.
(gfc_resolve_oacc_declare): Reimplement.
* parse.c (case_decl): Add ST_OACC_DECLARE.
(parse_spec): Remove handling.
(parse_progunit): Remove handling.
* parse.h (struct gfc_state_data): Change type.
* resolve.c (gfc_resolve_blocks): Handle EXEC_OACC_DECLARE.
* st.c (gfc_free_statement): Handle EXEC_OACC_DECLARE.
* symbol.c (check_conflict): Add conflict checks.
(gfc_add_oacc_declare_create, gfc_add_oacc_declare_copyin, 
gfc_add_oacc_declare_deviceptr, gfc_add_oacc_declare_device_resident):
New functions.
(gfc_copy_attr): Handle new symbols.
* trans-decl.c (add_clause, find_module_oacc_declare_clauses,
finish_oacc_declare): New functions.
(gfc_generate_function_code): Replace with call.
* trans-openmp.c (gfc_trans_oacc_declare): Reimplement.
(gfc_trans_oacc_directive): Handle EXEC_OACC_DECLARE.
* trans-stmt.c (gfc_trans_block_construct): Replace with call.
* trans-stmt.h (gfc_trans_oacc_declare): Remove argument.
* trans.c (trans_code): Handle EXEC_OACC_DECLARE.

gcc/testsuite
* gfortran.dg/goacc/declare-1.f95: Update test.
* gfortran.dg/goacc/declare-2.f95: New test.

libgomp/
* testsuite/libgomp.oacc-fortran/declare-1.f90: New test.
* testsuite/libgomp.oacc-fortran/declare-2.f90: Likewise.
* testsuite/libgomp.oacc-fortran/declare-3.f90: Likewise.
* testsuite/libgomp.oacc-fortran/declare-4.f90: Likewise.
* testsuite/libgomp.oacc-fortran/declare-5.f90: Likewise.
* testsuite/libgomp.oacc-fortran/declare-5.f90: Likewise.
diff --git a/gcc/fortran/dump-parse-tree.c b/gcc/fortran/dump-parse-tree.c
index 83ecbaa..48476af 100644
--- a/gcc/fortran/dump-parse-tree.c
+++ b/gcc/fortran/dump-parse-tree.c
@@ -2570,12 +2570,16 @@ show_namespace (gfc_namespace *ns)
   for (eq = ns->equiv; eq; eq = eq->next)
 show_equiv (eq);
 
-  if (ns->oacc_declare_clauses)
+  if (ns->oacc_declare)
 {
+  struct gfc_oacc_declare *decl;
   /* Dump !$ACC DECLARE clauses.  */
-  show_indent ();
-  fprintf (dumpfile, "!$ACC DECLARE");
-  show_omp_clauses (ns->oacc_declare_clauses);
+  for (decl = ns->oacc_declare; decl; decl = decl->next)
+	{
+	  show_indent ();
+	  fprintf (dumpfile, "!$ACC DECLARE");
+	  show_omp_clauses (decl->clauses);
+	}
 }
 
   fputc ('\n', dumpfile);
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index e13b4d4..5487c93 100644
--- a/gcc/fortran/gfor

Re: Re: OpenACC declare directive updates

2015-11-18 Thread Cesar Philippidis
On 11/08/2015 08:53 PM, James Norris wrote:

> The attached patch and ChangeLog reflect the updates from your
> review: https://gcc.gnu.org/ml/gcc-patches/2015-11/msg00714.html
> and Cesar's review:
> https://gcc.gnu.org/ml/gcc-patches/2015-11/msg00885.html.
> 
> With the changes made in this patch I think I'm handling the
> situation that you pointed out here correctly:
> 
> "Also, wonder about BLOCK stmt in Fortran, that can give you variables that
> don't live through the whole function, but only a portion of it even in
> Fortran."

What block stmt? The most recent version of Fortran OpenACC 2.0a
supports is 2003. The block construct is a 2008 feature. I don't think
that's applicable to this version. Jim, maybe you should add an error
message for variables defined in blocks.

Thinking about this some more, I wonder if we should emit an error if
any acc constructs are used inside blocks? That's probably overly
pessimistic though.

Cesar


Re: OpenACC declare directive updates

2015-11-08 Thread James Norris

Cesar,


I only noticed these because I thought I fixed them in the patch you
asked me to revert from gomp-4_0-branch. At the very least, please try
to be consistent on iterating OMP_LIST_*.

Thank you for noticing!

Jakub,

The attached patch and ChangeLog reflect the updates from your
review: https://gcc.gnu.org/ml/gcc-patches/2015-11/msg00714.html
and Cesar's review: https://gcc.gnu.org/ml/gcc-patches/2015-11/msg00885.html.

With the changes made in this patch I think I'm handling the
situation that you pointed out here correctly:

"Also, wonder about BLOCK stmt in Fortran, that can give you variables that
don't live through the whole function, but only a portion of it even in
Fortran."

OK to commit to trunk?

Thanks!
Jim

2015-XX-XX  James Norris  
Joseph Myers  

gcc/c-family/
* c-pragma.c (oacc_pragmas): Add entry for declare directive. 
* c-pragma.h (enum pragma_kind): Add PRAGMA_OACC_DECLARE.
(enum pragma_omp_clause): Add PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT and
PRAGMA_OACC_CLAUSE_LINK.

gcc/c/
* c-parser.c (c_parser_pragma): Handle PRAGMA_OACC_DECLARE.
(c_parser_omp_clause_name): Handle 'device_resident' clause.
(c_parser_oacc_data_clause): Handle PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
and PRAGMA_OMP_CLAUSE_LINK.
(c_parser_oacc_all_clauses): Handle PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
and PRAGMA_OACC_CLAUSE_LINK.
(OACC_DECLARE_CLAUSE_MASK): New definition.
(c_parser_oacc_declare): New function.

gcc/cp/
* parser.c (cp_parser_omp_clause_name): Handle 'device_resident'
clause.
(cp_parser_oacc_data_clause): Handle PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
and PRAGMA_OMP_CLAUSE_LINK.
(cp_paser_oacc_all_clauses): Handle PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
and PRAGMA_OMP_CLAUSE_LINK.
(OACC_DECLARE_CLAUSE_MASK): New definition.
(cp_parser_oacc_declare): New function.
(cp_parser_pragma): Handle PRAGMA_OACC_DECLARE.
* pt.c (tsubst_expr): Handle OACC_DECLARE.

gcc/
* gimple-pretty-print.c (dump_gimple_omp_target): Handle
GF_OMP_TARGET_KIND_OACC_DECLARE. 
* gimple.h (enum gf_mask): Add GF_OMP_TARGET_KIND_OACC_DECLARE.
(is_gomple_omp_oacc): Handle GF_OMP_TARGET_KIND_OACC_DECLARE.
* gimplify.c (gimplify_bind_expr): Prepend 'exit' stmt to cleanup.
* omp-builtins.def (BUILT_IN_GOACC_DECLARE): New builtin.
* omp-low.c (expand_omp_target): Handle
GF_OMP_TARGET_KIND_OACC_DECLARE and BUILTIN_GOACC_DECLARE.
(build_omp_regions_1): Handlde GF_OMP_TARGET_KIND_OACC_DECLARE.
(lower_omp_target): Handle GF_OMP_TARGET_KIND_OACC_DECLARE,
GOMP_MAP_DEVICE_RESIDENT and GOMP_MAP_LINK.
(make_gimple_omp_edges): Handle GF_OMP_TARGET_KIND_OACC_DECLARE.

gcc/testsuite
* c-c++-common/goacc/declare-1.c: New test.
* c-c++-common/goacc/declare-2.c: Likewise.

include/
* gomp-constants.h (enum gomp_map_kind): Add GOMP_MAP_DEVICE_RESIDENT
and GOMP_MAP_LINK.

libgomp/

* libgomp.map (GOACC_2.0.1): Export GOACC_declare.
* oacc-parallel.c (GOACC_declare): New function.
* testsuite/libgomp.oacc-c-c++-common/declare-1.c: New test.
* testsuite/libgomp.oacc-c-c++-common/declare-5.c: Likewise.
diff --git a/gcc/c-family/c-pragma.c b/gcc/c-family/c-pragma.c
index ac11838..cd0cc27 100644
--- a/gcc/c-family/c-pragma.c
+++ b/gcc/c-family/c-pragma.c
@@ -1207,6 +1207,7 @@ static const struct omp_pragma_def oacc_pragmas[] = {
   { "atomic", PRAGMA_OACC_ATOMIC },
   { "cache", PRAGMA_OACC_CACHE },
   { "data", PRAGMA_OACC_DATA },
+  { "declare", PRAGMA_OACC_DECLARE },
   { "enter", PRAGMA_OACC_ENTER_DATA },
   { "exit", PRAGMA_OACC_EXIT_DATA },
   { "kernels", PRAGMA_OACC_KERNELS },
diff --git a/gcc/c-family/c-pragma.h b/gcc/c-family/c-pragma.h
index 953c4e3..c6a2981 100644
--- a/gcc/c-family/c-pragma.h
+++ b/gcc/c-family/c-pragma.h
@@ -30,6 +30,7 @@ enum pragma_kind {
   PRAGMA_OACC_ATOMIC,
   PRAGMA_OACC_CACHE,
   PRAGMA_OACC_DATA,
+  PRAGMA_OACC_DECLARE,
   PRAGMA_OACC_ENTER_DATA,
   PRAGMA_OACC_EXIT_DATA,
   PRAGMA_OACC_KERNELS,
@@ -151,6 +152,7 @@ enum pragma_omp_clause {
   PRAGMA_OACC_CLAUSE_CREATE,
   PRAGMA_OACC_CLAUSE_DELETE,
   PRAGMA_OACC_CLAUSE_DEVICEPTR,
+  PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT,
   PRAGMA_OACC_CLAUSE_GANG,
   PRAGMA_OACC_CLAUSE_HOST,
   PRAGMA_OACC_CLAUSE_INDEPENDENT,
@@ -175,7 +177,8 @@ enum pragma_omp_clause {
   PRAGMA_OACC_CLAUSE_FIRSTPRIVATE = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE,
   PRAGMA_OACC_CLAUSE_IF = PRAGMA_OMP_CLAUSE_IF,
   PRAGMA_OACC_CLAUSE_PRIVATE = PRAGMA_OMP_CLAUSE_PRIVATE,
-  PRAGMA_OACC_CLAUSE_REDUCTION = PRAGMA_OMP_CLAUSE_REDUCTION
+  PRAGMA_OACC_CLAUSE_REDUCTION = PRAGMA_OMP_CLAUSE_REDUCTION,
+  PRAGMA_OACC_CLAUSE_LINK = PRAGMA_OMP_CLAUSE_LINK
 };
 
 extern struct cpp_reader* parse_in;
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser

Re: Re: OpenACC declare directive updates

2015-11-08 Thread Cesar Philippidis
On 11/08/2015 07:29 AM, James Norris wrote:

> The attached patch and ChangeLog reflect the updates from your
> review: https://gcc.gnu.org/ml/gcc-patches/2015-11/msg00714.html.
> All of the issues pointed out, have been address.
> 
> With the changes made in this patch I think I'm handling the
> situation that you pointed out here correctly:
> 
> On Fri, Nov 06, 2015 at 01:45:09PM -0600, James Norris wrote:
> 
> Also, wonder about BLOCK stmt in Fortran, that can give you variables that
> don't live through the whole function, but only a portion of it even in
> Fortran.
> 
> OK to commit to trunk?

I'll defer to Jakub, but here are a couple of comments.

>  void
>  gfc_resolve_oacc_declare (gfc_namespace *ns)
>  {
>int list;
>gfc_omp_namelist *n;
>locus loc;
> +  gfc_oacc_declare *oc;
>  
> -  if (ns->oacc_declare_clauses == NULL)
> +  if (ns->oacc_declare == NULL)
>  return;
>  
> -  loc = ns->oacc_declare_clauses->loc;
> +  loc = gfc_current_locus;
>  
> -  for (list = OMP_LIST_DEVICE_RESIDENT;
> -   list <= OMP_LIST_DEVICE_RESIDENT; list++)
> -for (n = ns->oacc_declare_clauses->lists[list]; n; n = n->next)
> -  {
> - n->sym->mark = 0;
> - if (n->sym->attr.flavor == FL_PARAMETER)
> -   gfc_error ("PARAMETER object %qs is not allowed at %L", n->sym->name, 
> &loc);
> -  }
> +  for (oc = ns->oacc_declare; oc; oc = oc->next)
> +{
> +  for (list = OMP_LIST_DEVICE_RESIDENT;
> +list <= OMP_LIST_DEVICE_RESIDENT; list++)

Why is this loop necessary?

> + for (n = oc->clauses->lists[list]; n; n = n->next)
> +   {
> + n->sym->mark = 0;
> + if (n->sym->attr.flavor == FL_PARAMETER)
> +   gfc_error ("PARAMETER object %qs is not allowed at %L",
> +  n->sym->name, &loc);
> +   }
>  
> -  for (list = OMP_LIST_DEVICE_RESIDENT;
> -   list <= OMP_LIST_DEVICE_RESIDENT; list++)
> -for (n = ns->oacc_declare_clauses->lists[list]; n; n = n->next)
> -  {
> - if (n->sym->mark)
> -   gfc_error ("Symbol %qs present on multiple clauses at %L",
> -  n->sym->name, &loc);
> - else
> -   n->sym->mark = 1;
> -  }
> +  for (list = OMP_LIST_DEVICE_RESIDENT;
> + list <= OMP_LIST_DEVICE_RESIDENT; list++)

And here.

> + for (n = oc->clauses->lists[list]; n; n = n->next)
> +   {
> + if (n->sym->mark)
> +   gfc_error ("Symbol %qs present on multiple clauses at %L",
> +  n->sym->name, &loc);
> + else
> +   n->sym->mark = 1;
> +   }
>  
> -  for (n = ns->oacc_declare_clauses->lists[OMP_LIST_DEVICE_RESIDENT]; n;
> -   n = n->next)
> -check_array_not_assumed (n->sym, loc, "DEVICE_RESIDENT");
> -}
> +  for (n = oc->clauses->lists[OMP_LIST_DEVICE_RESIDENT]; n; n = n->next)

This is better.

> + check_array_not_assumed (n->sym, loc, "DEVICE_RESIDENT");
> +
> +  for (n = oc->clauses->lists[OMP_LIST_MAP]; n; n = n->next)
> + {
> +   if (n->expr && n->expr->ref->type == REF_ARRAY)
> +   gfc_error ("Array sections: %qs not allowed in"
> +  " $!ACC DECLARE at %L", n->sym->name, &loc);
> + }
> +}
> +
> +  for (oc = ns->oacc_declare; oc; oc = oc->next)
> +{
> +  for (list = OMP_LIST_LINK; list <= OMP_LIST_LINK; list++)

?

> + for (n = oc->clauses->lists[list]; n; n = n->next)
> +   n->sym->mark = 0;
> +}
>  
> +  for (oc = ns->oacc_declare; oc; oc = oc->next)
> +{
> +  for (list = OMP_LIST_LINK; list <= OMP_LIST_LINK; list++)

?

> + for (n = oc->clauses->lists[list]; n; n = n->next)
> +   {
> + if (n->sym->mark)
> +   gfc_error ("Symbol %qs present on multiple clauses at %L",
> +  n->sym->name, &loc);
> + else
> +   n->sym->mark = 1;
> +   }
> +}
> +
> +  for (oc = ns->oacc_declare; oc; oc = oc->next)
> +{
> +  for (list = OMP_LIST_LINK; list <= OMP_LIST_LINK; list++)

?

> + for (n = oc->clauses->lists[list]; n; n = n->next)
> +   n->sym->mark = 0;
> +}
> +}

I only noticed these because I thought I fixed them in the patch you
asked me to revert from gomp-4_0-branch. At the very least, please try
to be consistent on iterating OMP_LIST_*.

Cesar



Re: OpenACC declare directive updates

2015-11-08 Thread James Norris

Jakub,

The attached patch and ChangeLog reflect the updates from your
review: https://gcc.gnu.org/ml/gcc-patches/2015-11/msg00714.html.
All of the issues pointed out, have been address.

With the changes made in this patch I think I'm handling the
situation that you pointed out here correctly:

On Fri, Nov 06, 2015 at 01:45:09PM -0600, James Norris wrote:

Also, wonder about BLOCK stmt in Fortran, that can give you variables that
don't live through the whole function, but only a portion of it even in
Fortran.

OK to commit to trunk?

Thanks!
Jim

2015-XX-XX  James Norris  
Cesar Philippidis  

gcc/fortran/
* dump-parse-tree.c (show_namespace): Handle declares.
* f95-lang.c (gfc_attribute_table): New entry.
* gfortran.h (struct symbol_attribute): New fields.
(enum gfc_omp_map_map): Add OMP_MAP_DEVICE_RESIDENT and OMP_MAP_LINK.
(OMP_LIST_LINK): New enum.
(struct gfc_oacc_declare): New structure.
(gfc_get_oacc_declare): New definition.
(struct gfc_namespace): Change type.
(enum gfc_exec_op): Add EXEC_OACC_DECLARE.
(struct gfc_code): New field.
* module.c (enum ab_attribute): Add AB_OACC_DECLARE_CREATE,
AB_OACC_DECLARE_COPYIN, AB_OACC_DECLARE_DEVICEPTR,
AB_OACC_DECLARE_DEVICE_RESIDENT, AB_OACC_DECLARE_LINK
(attr_bits): Add new initializers.
(mio_symbol_attribute): Handle new atributes.
* openmp.c (gfc_free_oacc_declare_clauses): New function.
(OMP_CLAUSE_LINK): New definition.
(gfc_match_omp_clauses): Handle OMP_CLAUSE_LINK.
(OACC_DECLARE_CLAUSES): Add OMP_CLAUSE_LINK
(gfc_match_oacc_declare): Add checking and module handling.
(gfc_resolve_oacc_declare): Use duplicate detection.
* parse.c (case_decl): Add ST_OACC_DECLARE.
(parse_spec): Remove handling.
(parse_progunit): Remove handling.
* parse.h (struct gfc_state_data): Change type.
* resolve.c (gfc_resolve_blocks): Handle EXEC_OACC_DECLARE.
* st.c (gfc_free_statement): Handle EXEC_OACC_DECLARE.
* symbol.c (check_conflict): Add conflict checks.
(gfc_add_oacc_declare_create, gfc_add_oacc_declare_copyin, 
gfc_add_oacc_declare_deviceptr, gfc_add_oacc_declare_device_resident):
New functions.
(gfc_copy_attr): Handle new symbols.
* trans-decl.c (add_attributes_to_decl): Create identifier.
(struct oacc_return): New structure.
(find_oacc_return, add_clause, find_module_oacc_declare_clauses,
finish_oacc_declare): New functions.
(gfc_generate_function_code): Replace with call.
* trans-openmp.c (gfc_trans_omp_clauses): Add conditional.
(gfc_trans_oacc_declare): Reimplement.
(gfc_trans_oacc_directive): Handle EXEC_OACC_DECLARE.
* trans-stmt.c (gfc_trans_block_construct): Replace with call.
* trans-stmt.h (gfc_trans_oacc_declare): Remove argument.
* trans.c (trans_code): Handle EXEC_OACC_DECLARE.

gcc/testsuite
* gfortran.dg/goacc/declare-1.f95: Update test.
* gfortran.dg/goacc/declare-2.f95: New test.

libgomp/
* testsuite/libgomp.oacc-fortran/declare-1.f90: New test.
* testsuite/libgomp.oacc-fortran/declare-2.f90: Likewise.
* testsuite/libgomp.oacc-fortran/declare-3.f90: Likewise.
* testsuite/libgomp.oacc-fortran/declare-4.f90: Likewise.
* testsuite/libgomp.oacc-fortran/declare-5.f90: Likewise.
diff --git a/gcc/fortran/dump-parse-tree.c b/gcc/fortran/dump-parse-tree.c
index 83ecbaa..48476af 100644
--- a/gcc/fortran/dump-parse-tree.c
+++ b/gcc/fortran/dump-parse-tree.c
@@ -2570,12 +2570,16 @@ show_namespace (gfc_namespace *ns)
   for (eq = ns->equiv; eq; eq = eq->next)
 show_equiv (eq);
 
-  if (ns->oacc_declare_clauses)
+  if (ns->oacc_declare)
 {
+  struct gfc_oacc_declare *decl;
   /* Dump !$ACC DECLARE clauses.  */
-  show_indent ();
-  fprintf (dumpfile, "!$ACC DECLARE");
-  show_omp_clauses (ns->oacc_declare_clauses);
+  for (decl = ns->oacc_declare; decl; decl = decl->next)
+	{
+	  show_indent ();
+	  fprintf (dumpfile, "!$ACC DECLARE");
+	  show_omp_clauses (decl->clauses);
+	}
 }
 
   fputc ('\n', dumpfile);
diff --git a/gcc/fortran/f95-lang.c b/gcc/fortran/f95-lang.c
index 2e91470..a8458b0 100644
--- a/gcc/fortran/f95-lang.c
+++ b/gcc/fortran/f95-lang.c
@@ -99,6 +99,8 @@ static const struct attribute_spec gfc_attribute_table[] =
affects_type_identity } */
   { "omp declare target", 0, 0, true,  false, false,
 gfc_handle_omp_declare_target_attribute, false },
+  { "oacc declare", 0, 0, true,  false, false,
+gfc_handle_omp_declare_target_attribute, false },
   { NULL,		  0, 0, false, false, false, NULL, false }
 };
 
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index e13b4d4..3965b08 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -841,6 +841,13 @

Re: OpenACC declare directive updates

2015-11-06 Thread James Norris

Jakub,

On 11/06/2015 01:49 PM, Jakub Jelinek wrote:

On Fri, Nov 06, 2015 at 01:45:09PM -0600, James Norris wrote:

Okay, I'll fix this.

After fixing, OK to commit?

Thank you for taking the time for the review.

Well, isn't this patch really dependent on the other one?


Yes. Should I combine the patches into a single patch?



Also, wonder about BLOCK stmt in Fortran, that can give you variables that
don't live through the whole function, but only a portion of it even in
Fortran.


Let me scratch my head on that one.


Jakub


Thanks again,
Jim



Re: OpenACC declare directive updates

2015-11-06 Thread Jakub Jelinek
On Fri, Nov 06, 2015 at 01:45:09PM -0600, James Norris wrote:
> Okay, I'll fix this.
> 
> After fixing, OK to commit?
> 
> Thank you for taking the time for the review.

Well, isn't this patch really dependent on the other one?

Also, wonder about BLOCK stmt in Fortran, that can give you variables that
don't live through the whole function, but only a portion of it even in
Fortran.

Jakub


Re: OpenACC declare directive updates

2015-11-06 Thread James Norris

Jakub,


On 11/06/2015 01:31 PM, Jakub Jelinek wrote:

On Wed, Nov 04, 2015 at 06:32:00AM -0600, James Norris wrote:

+/* Node in the linked list used for storing !$oacc declare constructs.  */
+
+typedef struct gfc_oacc_declare
+{
+  struct gfc_oacc_declare *next;
+  bool module_var;
+  gfc_omp_clauses *clauses;
+  gfc_omp_clauses *return_clauses;
+}
+gfc_oacc_declare;
+
+#define gfc_get_oacc_declare() XCNEW (gfc_oacc_declare)
+
+
  /* Node in the linked list used for storing !$omp declare simd constructs.  */
  
  typedef struct gfc_omp_declare_simd

@@ -1644,7 +1668,7 @@ typedef struct gfc_namespace
struct gfc_data *data, *old_data;
  
/* !$ACC DECLARE clauses.  */

-  gfc_omp_clauses *oacc_declare_clauses;
+  struct gfc_oacc_declare *oacc_declare_clauses;

This should be renamed now that it doesn't hold just clauses,
perhaps just oacc_declare?  Also, no need to use struct keyword.


That's fine, I'll fix that.




@@ -2857,6 +2957,42 @@ oacc_compatible_clauses (gfc_omp_clauses *clauses, int 
list,
return false;
  }
  
+/* Check if a variable appears in multiple clauses.  */

+
+static void
+resolve_omp_duplicate_list (gfc_omp_namelist *clause_list, bool openacc,
+   int list)
+{
+  gfc_omp_namelist *n;
+  const char *error_msg = "Symbol %qs present on multiple clauses at %L";
+
+  /* OpenACC reduction clauses are compatible with everything.  We only
+ need to check if a reduction variable is used more than once.  */
+  if (openacc && list == OMP_LIST_REDUCTION)
+{
+  hash_set reductions;
+
+  for (n = clause_list; n; n = n->next)
+   {
+ if (reductions.contains (n->sym))
+   gfc_error (error_msg, n->sym->name, &n->expr->where);
+ else
+   reductions.add (n->sym);
+   }
+
+  return;
+}
+
+  /* Ensure that variables are only used in one clause.  */
+  for (n = clause_list; n; n = n->next)
+{
+  if (n->sym->mark)
+   gfc_error (error_msg, n->sym->name, &n->expr->where);
+  else
+   n->sym->mark = 1;
+}
+}

You are readding a function that has been rejected, OMP_LIST_REDUCTION
is handled differently now.

Jakub


Okay, I'll fix this.

After fixing, OK to commit?

Thank you for taking the time for the review.

Jim





Re: OpenACC declare directive updates

2015-11-06 Thread Jakub Jelinek
On Wed, Nov 04, 2015 at 06:32:00AM -0600, James Norris wrote:
> +/* Node in the linked list used for storing !$oacc declare constructs.  */
> +
> +typedef struct gfc_oacc_declare
> +{
> +  struct gfc_oacc_declare *next;
> +  bool module_var;
> +  gfc_omp_clauses *clauses;
> +  gfc_omp_clauses *return_clauses;
> +}
> +gfc_oacc_declare;
> +
> +#define gfc_get_oacc_declare() XCNEW (gfc_oacc_declare)
> +
> +
>  /* Node in the linked list used for storing !$omp declare simd constructs.  
> */
>  
>  typedef struct gfc_omp_declare_simd
> @@ -1644,7 +1668,7 @@ typedef struct gfc_namespace
>struct gfc_data *data, *old_data;
>  
>/* !$ACC DECLARE clauses.  */
> -  gfc_omp_clauses *oacc_declare_clauses;
> +  struct gfc_oacc_declare *oacc_declare_clauses;

This should be renamed now that it doesn't hold just clauses,
perhaps just oacc_declare?  Also, no need to use struct keyword.

> @@ -2857,6 +2957,42 @@ oacc_compatible_clauses (gfc_omp_clauses *clauses, int 
> list,
>return false;
>  }
>  
> +/* Check if a variable appears in multiple clauses.  */
> +
> +static void
> +resolve_omp_duplicate_list (gfc_omp_namelist *clause_list, bool openacc,
> + int list)
> +{
> +  gfc_omp_namelist *n;
> +  const char *error_msg = "Symbol %qs present on multiple clauses at %L";
> +
> +  /* OpenACC reduction clauses are compatible with everything.  We only
> + need to check if a reduction variable is used more than once.  */
> +  if (openacc && list == OMP_LIST_REDUCTION)
> +{
> +  hash_set reductions;
> +
> +  for (n = clause_list; n; n = n->next)
> + {
> +   if (reductions.contains (n->sym))
> + gfc_error (error_msg, n->sym->name, &n->expr->where);
> +   else
> + reductions.add (n->sym);
> + }
> +
> +  return;
> +}
> +
> +  /* Ensure that variables are only used in one clause.  */
> +  for (n = clause_list; n; n = n->next)
> +{
> +  if (n->sym->mark)
> + gfc_error (error_msg, n->sym->name, &n->expr->where);
> +  else
> + n->sym->mark = 1;
> +}
> +}

You are readding a function that has been rejected, OMP_LIST_REDUCTION
is handled differently now.

Jakub


Re: OpenACC declare directive updates

2015-11-06 Thread James Norris

Jakub,

Ping

Do you need more information before you can review this patch?

Thanks!
Jim


On 11/04/2015 06:32 AM, James Norris wrote:


 This patch updates the processing of OpenACC declare directive for
 Fortran in the following areas:

 1) module support
 2) device_resident and link clauses
 3) clause checking
 4) directive generation

 Commentary on the changes is included as an attachment (NOTES).

 All of the code is in the gomp-4_0-branch.

 Regtested on x86_64-linux.

 Thanks!
 Jim