[PATCH, OpenACC, og8] OpenACC kernels control flow analysis bug fix

2019-02-12 Thread Gergö Barany

Hi all,

The attached patch fixes a bug in recent work on OpenACC "kernels" 
regions. Jumps within nested binds or try statements were not analyzed 
correctly and could lead to ICEs.


Tested on x86_64 with offloading to NVPTX.

Thanks,
Gergö


Correctly handle nested bind and try statements in the OpenACC kernels
conversion control-flow region analysis.

gcc/
* omp-oacc-kernels.c (control_flow_regions::compute_regions): Factored
out...
(control_flow_regions::visit_gimple_seq): ... this new method, now also
handling bind and try statements.

gcc/testsuite/
* gcc/testsuite/c-c++-common/goacc/kernels-decompose-1.c: Add tests.
>From 6db1f381f344b4482dcca6b82fc6316d172840be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerg=C3=B6=20Barany?= 
Date: Mon, 11 Feb 2019 08:23:31 -0800
Subject: [PATCH] OpenACC kernels control flow analysis bug fix

Correctly handle nested bind and try statements in the OpenACC kernels
conversion control-flow region analysis.

gcc/
* omp-oacc-kernels.c (control_flow_regions::compute_regions): Factored
out...
(control_flow_regions::visit_gimple_seq): ... this new method, now also
handling bind and try statements.

gcc/testsuite/
* gcc/testsuite/c-c++-common/goacc/kernels-decompose-1.c: Add tests.
---
 gcc/omp-oacc-kernels.c | 94 +++---
 .../c-c++-common/goacc/kernels-decompose-1.c   | 44 ++
 2 files changed, 107 insertions(+), 31 deletions(-)

diff --git a/gcc/omp-oacc-kernels.c b/gcc/omp-oacc-kernels.c
index d1db492..1fa2647 100644
--- a/gcc/omp-oacc-kernels.c
+++ b/gcc/omp-oacc-kernels.c
@@ -935,12 +935,24 @@ class control_flow_regions
control-flow regions in the statement sequence SEQ.  */
 void compute_regions (gimple_seq seq);
 
+/* Helper for compute_regions, scanning a single statement sequence SEQ
+   starting at index IDX and returning the next index after the last
+   statement in the sequence.  */
+size_t visit_gimple_seq (gimple_seq seq, size_t idx);
+
 /* The mapping from statement indices to region representatives.  */
 vec  representatives;
 
 /* A cache mapping statement indices to a flag indicating whether the
statement is a top level OpenACC for loop.  */
 vec  omp_for_loops;
+
+/* A mapping of control flow statements (goto, switch, cond) to their
+   representatives.  */
+hash_map  control_flow_reps;
+
+/* A mapping of labels to their representatives.  */
+hash_map  label_reps;
 };
 
 control_flow_regions::control_flow_regions (gimple_seq seq)
@@ -1008,41 +1020,12 @@ control_flow_regions::union_reps (size_t a, size_t b)
 void
 control_flow_regions::compute_regions (gimple_seq seq)
 {
-  hash_map  control_flow_reps;
-  hash_map  label_reps;
-  size_t current_region = 0, idx = 0;
+  size_t idx = 0;
 
   /* In a first pass, assign an initial region to each statement.  Except in
  the case of OpenACC loops, each statement simply gets the same region
  representative as its predecessor.  */
-  for (gimple_stmt_iterator gsi = gsi_start (seq);
-   !gsi_end_p (gsi);
-   gsi_next (&gsi))
-{
-  gimple *stmt = gsi_stmt (gsi);
-  gimple *omp_for = top_level_omp_for_in_stmt (stmt);
-  omp_for_loops.safe_push (omp_for != NULL);
-  if (omp_for != NULL)
-{
-  /* Assign a new region to this loop and to its successor.  */
-  current_region = idx;
-  representatives.safe_push (current_region);
-  current_region++;
-}
-  else
-{
-  representatives.safe_push (current_region);
-  /* Remember any jumps and labels for the second pass below.  */
-  if (gimple_code (stmt) == GIMPLE_COND
-  || gimple_code (stmt) == GIMPLE_SWITCH
-  || gimple_code (stmt) == GIMPLE_GOTO)
-control_flow_reps.put (stmt, current_region);
-  else if (gimple_code (stmt) == GIMPLE_LABEL)
-label_reps.put (gimple_label_label (as_a  (stmt)),
-current_region);
-}
-  idx++;
-}
+  visit_gimple_seq (seq, idx);
   gcc_assert (representatives.length () == omp_for_loops.length ());
 
   /* Revisit all the control flow statements and union the region of each
@@ -1087,6 +1070,55 @@ control_flow_regions::compute_regions (gimple_seq seq)
 }
 }
 
+size_t
+control_flow_regions::visit_gimple_seq (gimple_seq seq, size_t idx)
+{
+  size_t current_region = idx;
+
+  for (gimple_stmt_iterator gsi = gsi_start (seq);
+   !gsi_end_p (gsi);
+   gsi_next (&gsi))
+{
+  gimple *stmt = gsi_stmt (gsi);
+  gimple *omp_for = top_level_omp_for_in_stmt (stmt);
+  omp_for_loops.safe_push (omp_for != NULL);
+  if (omp_for != NULL)
+{
+  /* Assign a new region to this loop and to its successor.  */
+  current_region = idx;
+  representatives.safe_push (current_region);
+  current_region++;
+ 

[PATCH, OpenACC, og8] Fix incorrect test case

2019-02-19 Thread Gergö Barany

Hi,

This patch fixes a broken test case I added in a recent patch: 
https://gcc.gnu.org/ml/gcc-patches/2019-01/msg01504.html


The broken test can segfault due to writing to read-only memory, which 
this new version avoids. Will apply to the openacc-gcc-8-branch shortly.



Thanks,
Gergö


libgomp/
* testsuite/libgomp.oacc-fortran/initialize_kernels_loops.f90: Update.
>From 65bf7b1656d4cffa2bd057c2e3a2129d449d04a3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerg=C3=B6=20Barany?= 
Date: Tue, 19 Feb 2019 04:17:26 -0800
Subject: [PATCH] [og8] Fix incorrect test case

OpenACC kernels regions implicitly copy variables to and from the device,
but in this test case a loop bound lives in read-only memory and the test
can segfault.

libgomp/
* testsuite/libgomp.oacc-fortran/initialize_kernels_loops.f90: Update.
---
 libgomp/ChangeLog.openacc   | 4 
 libgomp/testsuite/libgomp.oacc-fortran/initialize_kernels_loops.f90 | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/libgomp/ChangeLog.openacc b/libgomp/ChangeLog.openacc
index 96908d1..3485c9d 100644
--- a/libgomp/ChangeLog.openacc
+++ b/libgomp/ChangeLog.openacc
@@ -1,3 +1,7 @@
+2019-02-19  Gergö Barany  
+
+	* testsuite/libgomp.oacc-fortran/initialize_kernels_loops.f90: Update.
+
 2019-01-31  Thomas Schwinge  
 
 	* testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c:
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/initialize_kernels_loops.f90 b/libgomp/testsuite/libgomp.oacc-fortran/initialize_kernels_loops.f90
index e8b4f3a..990a8ef 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/initialize_kernels_loops.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/initialize_kernels_loops.f90
@@ -6,7 +6,7 @@ subroutine kernel(lo, hi, a, b, c)
 integer :: lo, hi, i
 real, dimension(lo:hi) :: a, b, c
 
-!$acc kernels
+!$acc kernels copyin(lo, hi)
 !$acc loop independent ! { dg-warning "note: parallelized loop nest in OpenACC .kernels. construct" }
 do i = lo, hi
   b(i) = a(i)
-- 
2.8.1



Re: [PATCH, OpenACC, og8] OpenACC kernels control flow analysis bug fix

2019-02-20 Thread Gergö Barany
Ping. Thomas, is this OK for openacc-gcc-8-branch? It would be great if 
I could commit this before Friday.


Thanks,
Gergö


On 12/02/2019 20:02, Gergö Barany wrote:

Hi all,

The attached patch fixes a bug in recent work on OpenACC "kernels" 
regions. Jumps within nested binds or try statements were not analyzed 
correctly and could lead to ICEs.


Tested on x86_64 with offloading to NVPTX.

Thanks,
Gergö


Correctly handle nested bind and try statements in the OpenACC kernels
conversion control-flow region analysis.

     gcc/
     * omp-oacc-kernels.c (control_flow_regions::compute_regions): Factored
     out...
     (control_flow_regions::visit_gimple_seq): ... this new method, now 
also

     handling bind and try statements.

     gcc/testsuite/
     * gcc/testsuite/c-c++-common/goacc/kernels-decompose-1.c: Add tests.




[PATCH][og8] Update code and reduction tests for `serial' construct

2018-12-21 Thread Gergö Barany
This fixes a conflict between two recently committed patches to 
openacc-gcc-8-branch, Maciej's "Add OpenACC 2.6 `serial' construct 
support" and my "Report errors on missing OpenACC reduction clauses in 
nested reductions". The former renamed a function which caused the 
latter to no longer compile.


Additionally, new tests for OpenACC reductions in serial regions are 
added, and the existing ones separated out by region kind 
(parallel/kernels/serial).


OK for openacc-gcc-8-branch?


2018-12-21  Gergö Barany  

gcc/
* omp-low.c (scan_sharing_clauses): Fix call to renamed function
is_oacc_parallel.
gcc/testsuite/c-c++-common/goacc/
* nested-reductions-fail.c: Renamed to...
* nested-reductions-parallel-fail.c: ...this file, with kernels tests...
* nested-reductions-kernels-fail.c: ... moved to this new file.
* nested-reductions-serial-fail.c: New test.
* nested-reductions.c: Renamed to...
* nested-reductions-parallel.c: ... this file, with kernels tests...
* nested-reductions-kernels.c: ... moved to this new file.
* nested-reductions-serial.c: New test.
>From 72098b852c0cee656f61395c04f9271a0a598761 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerg=C3=B6=20Barany?= 
Date: Fri, 21 Dec 2018 00:08:09 -0800
Subject: [PATCH] [og8] Update code and reduction tests for `serial' construct

gcc/
* omp-low.c (scan_sharing_clauses): Fix call to renamed function
is_oacc_parallel.
gcc/testsuite/c-c++-common/goacc/
* nested-reductions-fail.c: Renamed to...
* nested-reductions-parallel-fail.c: ...this file, with kernels tests...
* nested-reductions-kernels-fail.c: ... moved to this new file.
* nested-reductions-serial-fail.c: New test.
* nested-reductions.c: Renamed to...
* nested-reductions-parallel.c: ... this file, with kernels tests...
* nested-reductions-kernels.c: ... moved to this new file.
* nested-reductions-serial.c: New test.
---
 gcc/ChangeLog.openacc  |   5 +
 gcc/omp-low.c  |   2 +-
 gcc/testsuite/ChangeLog.openacc|  15 +
 .../c-c++-common/goacc/nested-reductions-fail.c| 492 -
 .../goacc/nested-reductions-kernels-fail.c | 273 
 .../c-c++-common/goacc/nested-reductions-kernels.c | 227 ++
 .../goacc/nested-reductions-parallel-fail.c| 447 +++
 .../goacc/nested-reductions-parallel.c | 384 
 .../goacc/nested-reductions-serial-fail.c  | 446 +++
 .../c-c++-common/goacc/nested-reductions-serial.c  | 391 
 .../c-c++-common/goacc/nested-reductions.c | 420 --
 11 files changed, 2189 insertions(+), 913 deletions(-)
 delete mode 100644 gcc/testsuite/c-c++-common/goacc/nested-reductions-fail.c
 create mode 100644 gcc/testsuite/c-c++-common/goacc/nested-reductions-kernels-fail.c
 create mode 100644 gcc/testsuite/c-c++-common/goacc/nested-reductions-kernels.c
 create mode 100644 gcc/testsuite/c-c++-common/goacc/nested-reductions-parallel-fail.c
 create mode 100644 gcc/testsuite/c-c++-common/goacc/nested-reductions-parallel.c
 create mode 100644 gcc/testsuite/c-c++-common/goacc/nested-reductions-serial-fail.c
 create mode 100644 gcc/testsuite/c-c++-common/goacc/nested-reductions-serial.c
 delete mode 100644 gcc/testsuite/c-c++-common/goacc/nested-reductions.c

diff --git a/gcc/ChangeLog.openacc b/gcc/ChangeLog.openacc
index 5973625..718044c 100644
--- a/gcc/ChangeLog.openacc
+++ b/gcc/ChangeLog.openacc
@@ -1,3 +1,8 @@
+2018-12-21  Gergö Barany  
+
+	* omp-low.c (scan_sharing_clauses): Fix call to renamed function
+	is_oacc_parallel.
+
 2018-12-20  Gergö Barany  
 
 	* omp-low.c (struct omp_context): New fields
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 6b7b23e..72b6548 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -1286,7 +1286,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx,
 	  goto do_private;
 
 	case OMP_CLAUSE_REDUCTION:
-  if (is_oacc_parallel (ctx) || is_oacc_kernels (ctx))
+  if (is_gimple_omp_oacc (ctx->stmt))
 ctx->local_reduction_clauses
 	  = tree_cons (NULL, c, ctx->local_reduction_clauses);
 	  decl = OMP_CLAUSE_DECL (c);
diff --git a/gcc/testsuite/ChangeLog.openacc b/gcc/testsuite/ChangeLog.openacc
index 4af31e5..473eb9d 100644
--- a/gcc/testsuite/ChangeLog.openacc
+++ b/gcc/testsuite/ChangeLog.openacc
@@ -1,3 +1,18 @@
+2018-12-21  Gergö Barany  
+
+	* c-c++-common/goacc/nested-reductions-fail.c: Renamed to...
+	* c-c++-common/goacc/nested-reductions-parallel-fail.c: ...this file,
+	with kernels tests...
+	* c-c++-common/goacc/nested-reductions-kernels-fail.c: ... moved to this
+	new file.
+	* c-c++-common/goacc/nested-reductions-serial-fail.c: New test.
+	* c-c++-common/goacc/nested-reductions.c: Renamed to...
+	* 

[PATCH] [og8] Add OpenACC 2.6 if and if_present clauses on host_data construct

2018-12-21 Thread Gergö Barany
OpenACC 2.6 specifies `if' and `if_present' clauses on the `host_data' 
construct. These patches add support for these clauses. The first patch, 
by Thomas, reorganizes libgomp internals to turn a "device" argument 
into "flags" that can provide more information to the runtime. The 
second patch adds support for the `if' and `if_present' clauses, using 
the new flag mechanism.


OK for openacc-gcc-8-branch?

gcc/
* omp-expand.c (expand_omp_target): Restructure OpenACC vs. OpenMP
code paths.  Update for libgomp OpenACC entry points change.
include/
* gomp-constants.h (GOACC_FLAG_HOST_FALLBACK)
(GOACC_FLAGS_MARSHAL_OP, GOACC_FLAGS_UNMARSHAL): Define.
libgomp/
* oacc-parallel.c (GOACC_parallel_keyed, GOACC_parallel)
(GOACC_data_start, GOACC_enter_exit_data, GOACC_update)
(GOACC_declare): Redefine the "device" argument to "flags".


gcc/c/
* c-parser.c (OACC_HOST_DATA_CLAUSE_MASK): Add PRAGMA_OACC_CLAUSE_IF
and PRAGMA_OACC_CLAUSE_IF_PRESENT.
gcc/cp/
* parser.c (OACC_HOST_DATA_CLAUSE_MASK): Likewise.

gcc/fortran/
* openmp.c (OACC_HOST_DATA_CLAUSES): Add OMP_CLAUSE_IF and
OMP_CLAUSE_IF_PRESENT.

gcc/
* omp-expand.c (expand_omp_target): Handle if_present flag on
OpenACC host_data construct.

gcc/testsuite/c-c++-common/goacc/
* host_data-1.c: Add tests of if and if_present clauses on host_data.
gcc/testsuite/gfortran.dg/goacc/
* host_data-tree.f95: Likewise.

include/
* gomp-constants.h (GOACC_FLAG_HOST_DATA_IF_PRESENT): New constant.

libgomp/
* libgomp.h (enum gomp_map_vars_kind): Add
GOMP_MAP_VARS_OPENACC_IF_PRESENT.

libgomp/
* oacc-parallel.c (GOACC_data_start): Handle
GOACC_FLAG_HOST_DATA_IF_PRESENT flag.
* target.c (gomp_map_vars_async): Handle
GOMP_MAP_VARS_OPENACC_IF_PRESENT mapping kind.

libgomp/testsuite/libgomp.oacc-c-c++-common/
* host_data-6.c: New test.
>From 6d719cc2bcfa8f7ed8cb59e753e44aab6bf634fb Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Wed, 19 Dec 2018 20:04:18 +0100
Subject: [PATCH 1/2] For libgomp OpenACC entry points, redefine the "device"
 argument to "flags"

... so that we're then able to use this for other flags in addition to
"GOACC_FLAG_HOST_FALLBACK".

	gcc/
	* omp-expand.c (expand_omp_target): Restructure OpenACC vs. OpenMP
	code paths.  Update for libgomp OpenACC entry points change.
	include/
	* gomp-constants.h (GOACC_FLAG_HOST_FALLBACK)
	(GOACC_FLAGS_MARSHAL_OP, GOACC_FLAGS_UNMARSHAL): Define.
	libgomp/
	* oacc-parallel.c (GOACC_parallel_keyed, GOACC_parallel)
	(GOACC_data_start, GOACC_enter_exit_data, GOACC_update)
	(GOACC_declare): Redefine the "device" argument to "flags".
---
 gcc/ChangeLog.openacc  |   5 ++
 gcc/omp-expand.c   | 111 +
 gcc/tree-ssa-structalias.c |   4 +-
 include/ChangeLog.openacc  |   5 ++
 include/gomp-constants.h   |  12 +
 libgomp/ChangeLog.openacc  |   6 +++
 libgomp/oacc-parallel.c|  60 ++--
 7 files changed, 139 insertions(+), 64 deletions(-)

diff --git a/gcc/ChangeLog.openacc b/gcc/ChangeLog.openacc
index 718044c..6a51b1e 100644
--- a/gcc/ChangeLog.openacc
+++ b/gcc/ChangeLog.openacc
@@ -1,3 +1,8 @@
+2018-12-21  Thomas Schwinge  
+
+	* omp-expand.c (expand_omp_target): Restructure OpenACC vs. OpenMP
+	code paths.  Update for libgomp OpenACC entry points change.
+
 2018-12-21  Gergö Barany  
 
 	* omp-low.c (scan_sharing_clauses): Fix call to renamed function
diff --git a/gcc/omp-expand.c b/gcc/omp-expand.c
index 988b1bb..ea264da 100644
--- a/gcc/omp-expand.c
+++ b/gcc/omp-expand.c
@@ -7204,7 +7204,7 @@ expand_omp_target (struct omp_region *region)
  transfers.  */
   tree t1, t2, t3, t4, device, cond, depend, c, clauses;
   enum built_in_function start_ix;
-  location_t clause_loc;
+  location_t clause_loc = UNKNOWN_LOCATION;
   unsigned int flags_i = 0;
 
   switch (gimple_omp_target_kind (entry_stmt))
@@ -7249,49 +7249,62 @@ expand_omp_target (struct omp_region *region)
 
   clauses = gimple_omp_target_clauses (entry_stmt);
 
-  /* By default, the value of DEVICE is GOMP_DEVICE_ICV (let runtime
- library choose) and there is no conditional.  */
-  cond = NULL_TREE;
-  device = build_int_cst (integer_type_node, GOMP_DEVICE_ICV);
-
-  c = omp_find_clause (clauses, OMP_CLAUSE_IF);
-  if (c)
-cond = OMP_CLAUSE_IF_EXPR (c);
-
-  c = omp_find_clause (clauses, OMP_CLAUSE_DEVICE);
-  if (c)
+  device = NULL_TREE;
+  tree goacc_flags = NULL_TREE;
+  if (is_gimple_omp_oacc (entry_stmt))
 {
-  /* Even if we pass it to all library function calls, it is currently only
-	 defined/used for the OpenMP target ones.  */
-  gcc_checking_assert (start_ix == BUILT_IN_GOMP_TARGET
-			   || start_ix == BUILT_IN_GOMP_TARGET_DATA
-			   || start_ix == BUILT_IN_GOMP_TARGET_UPDATE
-			   || start_ix == BUILT_IN_GOMP_TARGET_ENTER_EXIT_DATA);
-
-  device = OMP_CLAUSE_DEVICE_ID (c);
-  clause_loc = OMP_

[PATCH] Add myself to MAINTAINERS

2018-12-21 Thread Gergö Barany

Hi all,

this patch adds me to MAINTAINERS in the Write After Approval section.

Will commit to trunk.


Thanks,
Gergö
>From 2b5e62781aadfb5d89f6b11f4c4cb8e5cfe373be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerg=C3=B6=20Barany?= 
Date: Fri, 21 Dec 2018 09:05:35 -0800
Subject: [PATCH] Add myself to MAINTAINERS.

* MAINTAINERS (Write After Approval): Add myself.
---
 ChangeLog   | 4 
 MAINTAINERS | 1 +
 2 files changed, 5 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index e36fc6f..11cfa2a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2018-12-21  Gergö Barany  
+
+	* MAINTAINERS (Write After Approval): Add myself.
+
 2018-12-10  Segher Boessenkool  
 
 	* contrib/config-list.mk: Remove powerpc-eabispe and powerpc-linux_spe.
diff --git a/MAINTAINERS b/MAINTAINERS
index 5d88479..dcf744d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -311,6 +311,7 @@ Giovanni Bajo	
 Simon Baldwin	
 Scott Bambrough	
 Wolfgang Bangerth
+Gergö Barany	
 Charles Baylis	
 Tejas Belagod	
 Jon Beniston	
-- 
2.8.1



[PATCH, OpenACC] Rework computation of default OpenACC mapping clauses

2019-01-25 Thread Gergö Barany
This patch unifies and simplifies the handling of OpenACC default 
mapping clauses for parallel, serial, and kernels regions.


OK for openacc-gcc-8-branch?

Thanks,
Gergö


gcc/
* gimplify.c (oacc_default_clause): Refactor and unify computation of
default mapping clauses.
>From 32a38daf2084bb266aa3a0c61c9176098d2d4bdb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerg=C3=B6=20Barany?= 
Date: Mon, 21 Jan 2019 03:01:02 -0800
Subject: [PATCH] Rework computation of default OpenACC mapping clauses

gcc/
* gimplify.c (oacc_default_clause): Refactor and unify computation of
default mapping clauses.
---
 gcc/ChangeLog.openacc |  5 
 gcc/gimplify.c| 75 +--
 2 files changed, 41 insertions(+), 39 deletions(-)

diff --git a/gcc/ChangeLog.openacc b/gcc/ChangeLog.openacc
index 22cdb5b..932fb37 100644
--- a/gcc/ChangeLog.openacc
+++ b/gcc/ChangeLog.openacc
@@ -1,3 +1,8 @@
+2019-01-24  Gergö Barany  
+
+	* gimplify.c (oacc_default_clause): Refactor and unify computation of
+	default mapping clauses.
+
 2019-01-09  Julian Brown  
 
 	* doc/invoke.texi: Update mention of OpenACC version to 2.6.
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index a60e395..a6a4d2a 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -7191,58 +7191,55 @@ oacc_default_clause (struct gimplify_omp_ctx *ctx, tree decl, unsigned flags)
   flags |= GOVD_MAP_TO_ONLY;
 }
 
+  unsigned private_mapping_flag = 0;
+  unsigned default_scalar_flags = 0;
+  /* Aggregates default to 'present_or_copy', or 'present'.  */
+  unsigned aggregate_flags
+= (ctx->default_kind != OMP_CLAUSE_DEFAULT_PRESENT
+? GOVD_MAP
+: GOVD_MAP | GOVD_MAP_FORCE_PRESENT);
+
   switch (ctx->region_type)
 {
 case ORT_ACC_KERNELS:
   rkind = "kernels";
-
-  if (is_private)
-	flags |= GOVD_MAP;
-  else if (AGGREGATE_TYPE_P (type))
-	{
-	  /* Aggregates default to 'present_or_copy', or 'present'.  */
-	  if (ctx->default_kind != OMP_CLAUSE_DEFAULT_PRESENT)
-	flags |= GOVD_MAP;
-	  else
-	flags |= GOVD_MAP | GOVD_MAP_FORCE_PRESENT;
-	}
-  else
-	/* Scalars default to 'copy'.  */
-	flags |= GOVD_MAP | GOVD_MAP_FORCE;
-
+  /* Scalars default to 'copy'.  */
+  default_scalar_flags = GOVD_MAP | GOVD_MAP_FORCE;
+  /* There are no private mappings on kernels regions.  */
+  gcc_assert (!is_private);
   break;
-
 case ORT_ACC_PARALLEL:
+  rkind = "parallel";
+  /* Scalars default to 'firstprivate'.  */
+  default_scalar_flags = GOVD_FIRSTPRIVATE;
+  private_mapping_flag = GOVD_FIRSTPRIVATE;
+  break;
 case ORT_ACC_SERIAL:
-  rkind = ctx->region_type == ORT_ACC_PARALLEL ? "parallel" : "serial";
-
-  if (TREE_CODE (type) == REFERENCE_TYPE
-	  && TREE_CODE (TREE_TYPE (type)) == POINTER_TYPE)
-	flags |= GOVD_MAP | GOVD_MAP_0LEN_ARRAY;
-  else if (!lang_GNU_Fortran () && TREE_CODE (type) == POINTER_TYPE)
-	flags |= GOVD_MAP | GOVD_MAP_0LEN_ARRAY;
-  else if (is_private)
-	flags |= GOVD_FIRSTPRIVATE;
-  else if (on_device || declared)
-	flags |= GOVD_MAP;
-  else if (AGGREGATE_TYPE_P (type))
-	{
-	  /* Aggregates default to 'present_or_copy', or 'present'.  */
-	  if (ctx->default_kind != OMP_CLAUSE_DEFAULT_PRESENT)
-	flags |= GOVD_MAP;
-	  else
-	flags |= GOVD_MAP | GOVD_MAP_FORCE_PRESENT;
-	}
-  else
-	/* Scalars default to 'firstprivate'.  */
-	flags |= GOVD_FIRSTPRIVATE;
-
+  rkind = "serial";
+  /* Scalars default to 'firstprivate'.  */
+  default_scalar_flags = GOVD_FIRSTPRIVATE;
+  private_mapping_flag = GOVD_FIRSTPRIVATE;
   break;
 
 default:
   gcc_unreachable ();
 }
 
+  if (TREE_CODE (type) == REFERENCE_TYPE
+  && TREE_CODE (TREE_TYPE (type)) == POINTER_TYPE)
+flags |= GOVD_MAP | GOVD_MAP_0LEN_ARRAY;
+  else if (!lang_GNU_Fortran () && TREE_CODE (type) == POINTER_TYPE)
+flags |= GOVD_MAP | GOVD_MAP_0LEN_ARRAY;
+  else if (is_private)
+flags |= private_mapping_flag;
+  else if (on_device || declared)
+flags |= GOVD_MAP;
+  else if (AGGREGATE_TYPE_P (type))
+flags |= aggregate_flags;
+  else
+/* This is a scalar getting the default mapping.  */
+flags |= default_scalar_flags;
+
   if (DECL_ARTIFICIAL (decl))
 ; /* We can get compiler-generated decls, and should not complain
 	 about them.  */
-- 
2.8.1



[PATCH, OpenACC] Rework OpenACC Fortran DO loop initialization

2019-01-25 Thread Gergö Barany
This patch moves OpenACC Fortan DO loop setup code from the head of a 
region to just before each loop. This is in preparation for upcoming 
patches reworking the handling of OpenACC kernels regions.


OK for openacc-gcc-8-branch?

Thanks,
Gergö


gcc/fortran/
* trans-openmp.c (gfc_privatize_nodesc_array_clauses): Renamed from
gfc_privatize_nodesc_arrays, initialization part factored out to...
(gfc_reinitialize_privatized_arrays): ... this new function, called...
(gfc_trans_omp_do): ... from here for OpenACC loops.

libgomp/
* testsuite/libgomp.oacc-fortran/initialize_kernels_loops.f90: New 
test.
>From f4768a88a4e2ab5dc80feb7bfb06cd273c849f72 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerg=C3=B6=20Barany?= 
Date: Mon, 21 Jan 2019 03:08:57 -0800
Subject: [PATCH] Rework OpenACC Fortran DO loop initialization

Fortran DO loops on arrays with non-constant bounds (like a(lo:hi)) need
special setup code to compute the bounds and offsets for the iteration. In
an OpenACC region containing multiple loops, this used to be done in a block
of code at the start of the region for all of the loops. But the upcoming
kernels conversion expects this kind of setup code to immediately precede
the corresponding loop, and variables are not mapped correctly otherwise.
This patch separates out the initialization part for each loop and places it
immediately before the loop.

gcc/fortran/
* trans-openmp.c (gfc_privatize_nodesc_array_clauses): Renamed from
gfc_privatize_nodesc_arrays, initialization part factored out to...
(gfc_reinitialize_privatized_arrays): ... this new function, called...
(gfc_trans_omp_do): ... from here for OpenACC loops.

libgomp/
* testsuite/libgomp.oacc-fortran/initialize_kernels_loops.f90: New test.
---
 gcc/fortran/ChangeLog.openacc  |  7 ++
 gcc/fortran/trans-openmp.c | 86 +-
 libgomp/ChangeLog.openacc  |  4 +
 .../initialize_kernels_loops.f90   | 31 
 4 files changed, 92 insertions(+), 36 deletions(-)
 create mode 100644 libgomp/testsuite/libgomp.oacc-fortran/initialize_kernels_loops.f90

diff --git a/gcc/fortran/ChangeLog.openacc b/gcc/fortran/ChangeLog.openacc
index 0f31f3e..450056d 100644
--- a/gcc/fortran/ChangeLog.openacc
+++ b/gcc/fortran/ChangeLog.openacc
@@ -1,3 +1,10 @@
+2019-01-24  Gergö Barany  
+
+	* trans-openmp.c (gfc_privatize_nodesc_array_clauses): Renamed from
+	gfc_privatize_nodesc_arrays, initialization part factored out to...
+	(gfc_reinitialize_privatized_arrays): ... this new function, called...
+	(gfc_trans_omp_do): ... from here for OpenACC loops.
+
 2019-01-09  Julian Brown  
 
 	* cpp.c (cpp_define_builtins): Update _OPENACC define to 201711.
diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c
index d5dbf18..5a444c3 100644
--- a/gcc/fortran/trans-openmp.c
+++ b/gcc/fortran/trans-openmp.c
@@ -3198,6 +3198,44 @@ gfc_scan_nodesc_arrays (gfc_expr **e, int *walk_subtrees ATTRIBUTE_UNUSED,
   return 0;
 }
 
+/* Reinitialize any arrays used inside CODE.  Place the initialization
+   sequences in CODE.  */
+
+static void
+gfc_reinitialize_privatized_arrays (gfc_code *code, stmtblock_t *block)
+{
+  hash_set  *array_set = new hash_set  ();
+  gfc_code_walker (&code, gfc_dummy_code_callback, gfc_scan_nodesc_arrays,
+		   array_set);
+
+  hash_set::iterator its = array_set->begin ();
+
+  for (; its != array_set->end (); ++its)
+{
+  gfc_symbol *sym = *its;
+  tree parm = gfc_get_symbol_decl (sym);
+  tree type = TREE_TYPE (parm);
+  tree offset, tmp;
+
+  /* Evaluate the bounds of the array.  */
+  gfc_trans_array_bounds (type, sym, &offset, block, false);
+
+  /* Set the offset.  */
+  if (TREE_CODE (GFC_TYPE_ARRAY_OFFSET (type)) == VAR_DECL)
+gfc_add_modify (block, GFC_TYPE_ARRAY_OFFSET (type), offset);
+
+  /* Set the pointer itself if we aren't using the parameter
+ directly.  */
+  if (TREE_CODE (parm) != PARM_DECL && DECL_LANG_SPECIFIC (parm)
+  && GFC_DECL_SAVED_DESCRIPTOR (parm))
+{
+  tmp = convert (TREE_TYPE (parm),
+ GFC_DECL_SAVED_DESCRIPTOR (parm));
+  gfc_add_modify (block, parm, tmp);
+}
+}
+}
+
 /* Build a set of internal array variables (lbound, ubound, stride, etc.)
that need privatization.  */
 
@@ -3219,41 +3257,12 @@ gfc_privatize_nodesc_arrays_1 (tree *tp, int *walk_subtrees, void *data)
   return NULL;
 }
 
-/* Reinitialize all of the arrays inside ARRAY_SET in BLOCK.  Append private
-   clauses for those arrays in CLAUSES.  */
+/* Append private clauses for the arrays in BLOCK to CLAUSES.  */
 
 static tree
-gfc_privatize_nodesc_arrays (hash_set *array_set,
-			 stmtblock_t *block, tree clauses)
+gfc_privatize_nodesc_array_clauses (stmtblock_t *block, tree clauses)
 {
-  hash_set::iterator its = array_set->begin ();
   hash_set *private_decls = new 

[PATCH, OpenACC] Remove spurious OpenACC error on combining "auto" with gang/worker/vector

2019-01-25 Thread Gergö Barany
On OpenACC loop constructs, it is OK according to the OpenACC spec to 
have both the "auto" clause and one or more of the "gang", "worker", or 
"vector" clauses. GCC emits errors for this combination; this patch 
eliminates that error.


OK for openacc-gcc-8-branch?

Thanks,
Gergö


gcc/
* omp-low.c (check_oacc_kernel_gwv): Remove spurious error message.
* omp-offload.c (oacc_loop_fixed_partitions): Likewise.

gcc/testsuite/
* c-c++-common/goacc/combined-directives-3.c: Adjust test.
* c-c++-common/goacc/loop-2-kernels.c: Likewise.
* c-c++-common/goacc/loop-2-parallel.c: Likewise.
>From d8e7f1826d423de05e11afcb6e422ccaced0f6ea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerg=C3=B6=20Barany?= 
Date: Wed, 23 Jan 2019 03:10:07 -0800
Subject: [PATCH] Remove spurious OpenACC error on combining "auto" with
 gang/worker/vector

gcc/
* omp-low.c (check_oacc_kernel_gwv): Remove spurious error message.
* omp-offload.c (oacc_loop_fixed_partitions): Likewise.

gcc/testsuite/
* c-c++-common/goacc/combined-directives-3.c: Adjust test.
* c-c++-common/goacc/loop-2-kernels.c: Likewise.
* c-c++-common/goacc/loop-2-parallel.c: Likewise.
---
 gcc/ChangeLog.openacc|  5 +
 gcc/omp-low.c|  3 ---
 gcc/omp-offload.c|  7 ++-
 gcc/testsuite/ChangeLog.openacc  |  6 ++
 gcc/testsuite/c-c++-common/goacc/combined-directives-3.c |  4 ++--
 gcc/testsuite/c-c++-common/goacc/loop-2-kernels.c| 12 ++--
 gcc/testsuite/c-c++-common/goacc/loop-2-parallel.c   | 12 ++--
 7 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/gcc/ChangeLog.openacc b/gcc/ChangeLog.openacc
index 932fb37..f3c741c 100644
--- a/gcc/ChangeLog.openacc
+++ b/gcc/ChangeLog.openacc
@@ -1,5 +1,10 @@
 2019-01-24  Gergö Barany  
 
+	* omp-low.c (check_oacc_kernel_gwv): Remove spurious error message.
+	* omp-offload.c (oacc_loop_fixed_partitions): Likewise.
+
+2019-01-24  Gergö Barany  
+
 	* gimplify.c (oacc_default_clause): Refactor and unify computation of
 	default mapping clauses.
 
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 72b6548..f48002e 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -2397,9 +2397,6 @@ check_oacc_kernel_gwv (gomp_for *stmt, omp_context *ctx)
   if (has_seq && (this_mask || has_auto))
 	error_at (gimple_location (stmt), "% overrides other"
 		  " OpenACC loop specifiers");
-  else if (has_auto && this_mask)
-	error_at (gimple_location (stmt), "% conflicts with other"
-		  " OpenACC loop specifiers");
 
   if (this_mask & outer_mask)
 	error_at (gimple_location (stmt), "inner loop uses same"
diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c
index d428c6f..57a7a06 100644
--- a/gcc/omp-offload.c
+++ b/gcc/omp-offload.c
@@ -1211,14 +1211,11 @@ oacc_loop_fixed_partitions (oacc_loop *loop, unsigned outer_mask)
   bool maybe_auto
 	= !seq_par && this_mask == (tiling ? this_mask & -this_mask : 0);
 
-  if ((this_mask != 0) + auto_par + seq_par > 1)
+  if (seq_par && (this_mask != 0 || auto_par))
 	{
 	  if (noisy)
 	error_at (loop->loc,
-		  seq_par
-		  ? G_("% overrides other OpenACC loop specifiers")
-		  : G_("% conflicts with other OpenACC loop "
-			   "specifiers"));
+		  G_("% overrides other OpenACC loop specifiers"));
 	  maybe_auto = false;
 	  loop->flags &= ~OLF_AUTO;
 	  if (seq_par)
diff --git a/gcc/testsuite/ChangeLog.openacc b/gcc/testsuite/ChangeLog.openacc
index 3bdce2e..3850d97 100644
--- a/gcc/testsuite/ChangeLog.openacc
+++ b/gcc/testsuite/ChangeLog.openacc
@@ -1,3 +1,9 @@
+2019-01-24  Gergö Barany  
+
+	* c-c++-common/goacc/combined-directives-3.c: Adjust test.
+	* c-c++-common/goacc/loop-2-kernels.c: Likewise.
+	* c-c++-common/goacc/loop-2-parallel.c: Likewise.
+
 2019-01-09  Julian Brown  
 
 	* c-c++-common/cpp/openacc-define-3.c: Update expected value for
diff --git a/gcc/testsuite/c-c++-common/goacc/combined-directives-3.c b/gcc/testsuite/c-c++-common/goacc/combined-directives-3.c
index 77d4182..5aa84dc 100644
--- a/gcc/testsuite/c-c++-common/goacc/combined-directives-3.c
+++ b/gcc/testsuite/c-c++-common/goacc/combined-directives-3.c
@@ -12,9 +12,9 @@ main ()
 for (y = 0; y < 10; y++)
   ;
 
-#pragma acc parallel loop gang auto /* { dg-error "'auto' conflicts with other OpenACC loop specifiers" } */
+#pragma acc parallel loop gang seq /* { dg-error "'seq' overrides other OpenACC loop specifiers" } */
   for (x = 0; x < 10; x++)
-#pragma acc loop worker auto /* { dg-error "'auto' conflicts with other OpenACC loop specifiers" } */
+#pragma acc loop worker seq /* { dg-error "'seq' overrides other OpenACC loop specifiers" } */
 for (y = 0; y < 10; y++)
 #pragma acc loop vector
   for (z = 0; z < 10; z++)
diff --git a/gcc/testsuite/c-c++-common/goacc/loop-2-kernels.c b/gcc/testsuite/c-c++-common/goacc/loop-2-kernels.c
index 3a

Re: [PATCH, OpenACC] Rework computation of default OpenACC mapping clauses

2019-01-29 Thread Gergö Barany

On 28/01/2019 18:00, Thomas Schwinge wrote:

On Fri, 25 Jan 2019 15:09:49 +0100, Gergö Barany  
wrote:

OK for openacc-gcc-8-branch?


Yes.


Thanks, committed along with the other patches I posted at the same time 
(Rework OpenACC Fortran DO loop initialization, Remove spurious OpenACC 
error on combining "auto" with gang/worker/vector), and with 
Reviewed-by: notes added to the commit messages.



Thanks,
Gergö