]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
4 years agoStructure element mapping for OpenMP 5.0 v3 devel/omp/gcc-10
Chung-Lin Tang [Mon, 31 May 2021 13:45:50 +0000 (21:45 +0800)] 
Structure element mapping for OpenMP 5.0 v3

This is a merge of patch:
https://gcc.gnu.org/pipermail/gcc-patches/2021-May/571515.html

v2 patch already merged at 18dd4f283e15894a26c9a105c4f87d9a585f93c5,
this commit only consists of the v2-to-v3 diff part in above URL.

This v3 adds a small bug fix, where the initialization of the refcount didn't
handle all cases, fixed by using gomp_refcount_increment here (more consistent).

libgomp/ChangeLog:

* target.c (gomp_map_vars_internal): For new key entries, set
k->refcount to 0, remove initialization of k->structelem_refcount,
use gomp_increment_refcount to consistently handle all increment cases.

(manual cherry pick of e7073707bab79ceceaa0e2d25a632d03ac98d0fd)

4 years ago[og10] Rework indirect struct handling for OpenACC in gimplify.c
Julian Brown [Tue, 18 May 2021 17:22:56 +0000 (10:22 -0700)] 
[og10] Rework indirect struct handling for OpenACC in gimplify.c

This patch reworks indirect struct handling in gimplify.c (i.e. for
struct components mapped with "mystruct->a[0:n]", "mystruct->b", etc.),
for OpenACC.  The key observation leading to these changes was that
component mappings of references-to-structures is already implemented
and working, and indirect struct component handling via a pointer can
work quite similarly.  That lets us remove some earlier, special-case
handling for mapping indirect struct component accesses for OpenACC,
which required the pointed-to struct to be manually mapped before the
indirect component mapping.

With this patch, you can map struct components directly (e.g. an array
slice "mystruct->a[0:n]") just like you can map a non-indirect struct
component slice ("mystruct.a[0:n]"). Both references-to-pointers (with
the former syntax) and references to structs (with the latter syntax)
work now.

For Fortran class pointers, we no longer re-use GOMP_MAP_TO_PSET for the
class metadata (the structure that points to the class data and vptr)
-- it is instead treated as any other struct.

For C++, the struct handling also works for class members ("this->foo"),
without having to explicitly map "this[:1]" first.

For OpenACC, we permit chained indirect component references
("mystruct->a->b[0:n]"), though only the last part of such mappings will
trigger an attach/detach operation.  To properly use such a construct
on the target, you must still manually map "mystruct->a[:1]" first --
but there's no need to map "mystruct[:1]" explicitly before that.

This version of the patch avoids altering code paths for OpenMP,
where possible.

2021-05-19  Julian Brown  <julian@codesourcery.com>

gcc/fortran/
* trans-openmp.c (gfc_trans_omp_clauses): Don't create GOMP_MAP_TO_PSET
mappings for class metadata, nor GOMP_MAP_POINTER mappings for
POINTER_TYPE_P decls.

gcc/
* gimplify.c (extract_base_bit_offset): Add BASE_IND and OPENMP
parameters.  Handle pointer-typed indirect references for OpenACC
alongside reference-typed ones.
(strip_components_and_deref, aggregate_base_p): New functions.
(build_struct_group): Add pointer type indirect ref handling,
including chained references, for OpenACC.  Also handle references to
structs for OpenACC.  Conditionalise bits for OpenMP only where
appropriate.
(gimplify_scan_omp_clauses): Rework pointer-type indirect structure
access handling to work more like the reference-typed handling for
OpenACC only.
* omp-low.c (scan_sharing_clauses): Handle pointer-type indirect struct
references, and references to pointers to structs also.

gcc/testsuite/
* g++.dg/goacc/member-array-acc.C: New test.
* g++.dg/gomp/member-array-omp.C: New test.

libgomp/
* testsuite/libgomp.oacc-c-c++-common/deep-copy-15.c: New test.
* testsuite/libgomp.oacc-c-c++-common/deep-copy-16.c: New test.
* testsuite/libgomp.oacc-c++/deep-copy-17.C: New test.

4 years ago[og10] Refactor struct lowering for OpenACC/OpenMP in gimplify.c
Julian Brown [Tue, 18 May 2021 17:08:22 +0000 (10:08 -0700)] 
[og10] Refactor struct lowering for OpenACC/OpenMP in gimplify.c

This patch is a second attempt at refactoring struct component mapping
handling for OpenACC/OpenMP during gimplification, after the patch I
posted here:

  https://gcc.gnu.org/pipermail/gcc-patches/2018-November/510503.html

And improved here, post-review:

  https://gcc.gnu.org/pipermail/gcc-patches/2019-November/533394.html

This patch goes further, in that the struct-handling code is outlined
into its own function (to create the "GOMP_MAP_STRUCT" node and the
sorted list of nodes immediately following it, from a set of mappings
of components of a given struct or derived type). I've also gone through
the list-handling code and attempted to add comments documenting how it
works to the best of my understanding, and broken out a couple of helper
functions in order to (hopefully) have the code self-document better also.

2021-05-19  Julian Brown  <julian@codesourcery.com>

gcc/
* gimplify.c (insert_struct_comp_map): Refactor function into...
(build_struct_comp_nodes): This new function.  Remove list handling
and improve self-documentation.
(insert_node_after, move_node_after, move_nodes_after,
move_concat_nodes_after): New helper functions.
(build_struct_group): New function to build up GOMP_MAP_STRUCT node
groups to map struct components. Outlined from...
(gimplify_scan_omp_clauses): Here.  Call above function.

4 years ago[og10] Unify ARRAY_REF/INDIRECT_REF stripping code in extract_base_bit_offset
Julian Brown [Mon, 19 Apr 2021 13:24:41 +0000 (06:24 -0700)] 
[og10] Unify ARRAY_REF/INDIRECT_REF stripping code in extract_base_bit_offset

For historical reasons, it seems that extract_base_bit_offset
unnecessarily used two different ways to strip ARRAY_REF/INDIRECT_REF
nodes from component accesses. I verified that the two ways of performing
the operation gave the same results across the whole testsuite (and
several additional benchmarks).

The code was like this since an earlier "mechanical" refactoring by me,
first posted here:

  https://gcc.gnu.org/pipermail/gcc-patches/2018-November/510503.html

It was never clear to me if there was an important semantic
difference between the two ways of stripping the base before calling
get_inner_reference, but it appears that there is not, so one can go away.

2021-05-11  Julian Brown  <julian@codesourcery.com>

gcc/
* gimplify.c (extract_base_bit_offset): Unify ARRAY_REF/INDIRECT_REF
stripping code in first call/subsequent call cases.

4 years ago[og10] Rewrite GOMP_MAP_ATTACH_DETACH mappings unconditionally
Julian Brown [Tue, 18 May 2021 17:10:12 +0000 (10:10 -0700)] 
[og10] Rewrite GOMP_MAP_ATTACH_DETACH mappings unconditionally

It never makes sense for a GOMP_MAP_ATTACH_DETACH mapping to survive
beyond gimplify.c, so this patch rewrites such mappings to GOMP_MAP_ATTACH
or GOMP_MAP_DETACH unconditionally (rather than checking for a list
of types of OpenACC or OpenMP constructs), in cases where it hasn't
otherwise been done already in the preceding code.

2021-05-19  Julian Brown  <julian@codesourcery.com>

gcc/
* gimplify.c (gimplify_scan_omp_clauses): Simplify condition
for changing GOMP_MAP_ATTACH_DETACH to GOMP_MAP_ATTACH or
GOMP_MAP_DETACH.

4 years agoRemove array section base-pointer mapping semantics, and other front-end adjustments.
Chung-Lin Tang [Tue, 11 May 2021 11:24:32 +0000 (19:24 +0800)] 
Remove array section base-pointer mapping semantics, and other front-end adjustments.

This patch largely implements three pieces of functionality:
(1) Per discussion and clarification on the omp-lang mailing list, standards
    conforming behavior for mapping array sections should *NOT* also map the
    base-pointer. This patch adjusts OpenMP map clause behavior to do this.

(2) Fixes in libgomp/target.c to not overwrite attached pointers when handling
    device<->host copying.

(3) Changes to the C/C++ front-ends to extend the allowed component access syntax
    in map clauses.

2021-05-11  Chung-Lin Tang  <cltang@codesourcery.com>

gcc/c/ChangeLog:

* c-parser.c (struct omp_dim): New struct type for use inside
c_parser_omp_variable_list.
(c_parser_omp_variable_list): Allow multiple levels of array and
component accesses in array section base-pointer expression.
(c_parser_omp_clause_to): Set 'allow_deref' to true in call to
c_parser_omp_var_list_parens.
(c_parser_omp_clause_from): Likewise.
* c-typeck.c (handle_omp_array_sections_1): Extend allowed range
of base-pointer expressions involving INDIRECT/MEM/ARRAY_REF and
POINTER_PLUS_EXPR.
(c_finish_omp_clauses): Extend allowed ranged of expressions
involving INDIRECT/MEM/ARRAY_REF and POINTER_PLUS_EXPR.

gcc/cp/ChangeLog:

* parser.c (struct omp_dim): New struct type for use inside
cp_parser_omp_var_list_no_open.
(cp_parser_omp_var_list_no_open): Allow multiple levels of array and
component accesses in array section base-pointer expression.
(cp_parser_omp_all_clauses): Set 'allow_deref' to true in call to
cp_parser_omp_var_list for to/from clauses.
* semantics.c (handle_omp_array_sections_1): Extend allowed range
of base-pointer expressions involving INDIRECT/MEM/ARRAY_REF and
POINTER_PLUS_EXPR.
(handle_omp_array_sections): Adjust pointer map generation of
references.
(finish_omp_clauses): Extend allowed ranged of expressions
involving INDIRECT/MEM/ARRAY_REF and POINTER_PLUS_EXPR.

gcc/fortran/ChangeLog:

* trans-openmp.c (gfc_trans_omp_array_section): Do not generate
GOMP_MAP_ALWAYS_POINTER map for main array maps of ARRAY_TYPE type.

gcc/ChangeLog:

* gimplify.c (extract_base_bit_offset): Add 'tree *offsetp' parameter,
accomodate case where 'offset' return of get_inner_reference is
non-NULL.
(is_or_contains_p): Further robustify conditions.
(omp_target_reorder_clauses): In alloc/to/from sorting phase, also
move following GOMP_MAP_ALWAYS_POINTER maps along.  Add new sorting
phase where we make sure pointers with an attach/detach map are ordered
correctly.
(gimplify_scan_omp_clauses): Add modifications to avoid creating
GOMP_MAP_STRUCT and associated alloc map for attach/detach maps.

gcc/testsuite/ChangeLog:

* c-c++-common/goacc/deep-copy-arrayofstruct.c: Adjust testcase.
* c-c++-common/gomp/target-enter-data-1.c: New testcase.

libgomp/ChangeLog:

* target.c (gomp_map_vars_existing): Make sure attached pointer is
not overwritten during cross-host/device copying.
(gomp_update): Likewise.
(gomp_exit_data): Likewise.

* testsuite/libgomp.c++/target-11.C: Adjust testcase.
* testsuite/libgomp.c++/target-12.C: Likewise.
* testsuite/libgomp.c++/target-15.C: Likewise.
* testsuite/libgomp.c++/target-16.C: Likewise.
* testsuite/libgomp.c++/target-17.C: Likewise.
* testsuite/libgomp.c++/target-21.C: Likewise.
* testsuite/libgomp.c++/target-23.C: Likewise.
* testsuite/libgomp.c/target-23.c: Likewise.
* testsuite/libgomp.c/target-29.c: Likewise.

4 years agoFix up 'c-c++-common/goacc/firstprivate-mappings-1.c' for C, non-LP64
Thomas Schwinge [Fri, 7 May 2021 08:57:36 +0000 (10:57 +0200)] 
Fix up 'c-c++-common/goacc/firstprivate-mappings-1.c' for C, non-LP64

Follow-up to recent og10 commit a70b5b1aa8b3d32f6728dbfcfc00b0cff8c5219d
"OpenMP 5.0: Implement relaxation of implicit map vs. existing device
mappings".

gcc/testsuite/
* c-c++-common/goacc/firstprivate-mappings-1.c: Fix up for C,
non-LP64.

4 years agoOpenMP 5.0: Implement relaxation of implicit map vs. existing device mappings
Chung-Lin Tang [Wed, 5 May 2021 15:11:19 +0000 (08:11 -0700)] 
OpenMP 5.0: Implement relaxation of implicit map vs. existing device mappings

This patch implements relaxing the requirements when a map with the implicit
attribute encounters an overlapping existing map. As the OpenMP 5.0 spec
describes on page 320, lines 18-27 (and 5.1 spec, page 352, lines 13-22):

"If a single contiguous part of the original storage of a list item with an
 implicit data-mapping attribute has corresponding storage in the device data
 environment prior to a task encountering the construct that is associated with
 the map clause, only that part of the original storage will have corresponding
 storage in the device data environment as a result of the map clause."

Also tracked in the OpenMP spec context as issue #1463:
https://github.com/OpenMP/spec/issues/1463

2021-05-05  Chung-Lin Tang  <cltang@codesourcery.com>

include/ChangeLog:

* gomp-constants.h (GOMP_MAP_IMPLICIT): New special map kind bits value.
(GOMP_MAP_FLAG_SPECIAL_BITS): Define helper mask for whole set of
special map kind bits.
(GOMP_MAP_NONCONTIG_ARRAY_P): Adjust test for non-contiguous array map
kind bits to be more specific.
(GOMP_MAP_IMPLICIT_P): New predicate macro for implicit map kinds.

gcc/ChangeLog:

* tree.h (OMP_CLAUSE_MAP_IMPLICIT_P): New access macro for 'implicit'
bit, using 'base.deprecated_flag' field of tree_node.
* tree-pretty-print.c (dump_omp_clause): Add support for printing
implicit attribute in tree dumping.
* gimplify.c (gimplify_adjust_omp_clauses_1):
Set OMP_CLAUSE_MAP_IMPLICIT_P to 1 if map clause is implicitly created.
(gimplify_adjust_omp_clauses): Adjust place of adding implicitly created
clauses, from simple append, to starting of list, after non-map clauses.
* omp-low.c (lower_omp_target): Add GOMP_MAP_IMPLICIT bits into kind
values passed to libgomp for implicit maps.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/target-implicit-map-1.c: New test.
* c-c++-common/goacc/combined-reduction.c: Adjust scan test pattern.
* c-c++-common/goacc/firstprivate-mappings-1.c: Likewise.
* c-c++-common/goacc/mdc-1.c: Likewise.
        * c-c++-common/goacc/reduction-1.c: Likewise.
        * c-c++-common/goacc/reduction-2.c: Likewise.
        * c-c++-common/goacc/reduction-3.c: Likewise.
        * c-c++-common/goacc/reduction-4.c: Likewise.
        * c-c++-common/goacc/reduction-8.c: Likewise.
        * g++.dg/goacc/firstprivate-mappings-1.C: Likewise.
        * g++.dg/gomp/target-lambda-1.C: Likewise.
        * g++.dg/gomp/target-this-3.C: Likewise.
        * g++.dg/gomp/target-this-4.C: Likewise.
        * gfortran.dg/goacc/common-block-3.f90: Likewise.
        * gfortran.dg/goacc/loop-tree-1.f90: Likewise.
        * gfortran.dg/goacc/private-explicit-kernels-1.f95: Likewise.
* gfortran.dg/goacc/private-predetermined-kernels-1.f95: Likewise.

libgomp/ChangeLog:

* target.c (gomp_map_vars_existing): Add 'bool implicit' parameter, add
implicit map handling to allow a "superset" existing map as valid case.
(get_kind): Adjust to filter out GOMP_MAP_IMPLICIT bits in return value.
(get_implicit): New function to extract implicit status.
(gomp_map_fields_existing): Adjust arguments in calls to
gomp_map_vars_existing, and add uses of get_implicit.
(gomp_map_vars_internal): Likewise.

* testsuite/libgomp.c-c++-common/target-implicit-map-1.c: New test.

4 years ago[OpenACC] Fix an ICE where a loop with GT condition is collapsed.
Hafiz Abid Qadeer [Thu, 8 Apr 2021 16:31:30 +0000 (17:31 +0100)] 
[OpenACC] Fix an ICE where a loop with GT condition is collapsed.

We have seen an ICE both on trunk and devel/omp/gcc-10 branches which can
be reprodued with this simple testcase.  It occurs if an OpenACC loop has
a collapse clause and any of the loop being collapsed uses GT or GE
condition.  This issue is specific to OpenACC.

int main (void)
{
  int ix, iy;
  int dim_x = 16, dim_y = 16;
  {
       for (iy = dim_y - 1; iy > 0; --iy)
       for (ix = dim_x - 1; ix > 0; --ix)
        ;
  }
}

The problem is caused by a failing assertion in expand_oacc_collapse_init.
It checks that cond_code for fd->loop should be same as cond_code for all
the loops that are being collapsed.  As the cond_code for fd->loop is
LT_EXPR with collapse clause (set at the end of omp_extract_for_data),
this assertion forces that all the loop in collapse clause should use
< operator.

There does not seem to be anything in the code which demands this
condition as loop with > condition works ok otherwise.  I digged old
mailing list a bit but could not find any discussion on this change.
Looking at the code, expand_oacc_for checks that fd->loop->cond_code is
either LT_EXPR or GT_EXPR.  I guess the original intention was to have
similar checks on the loop which are being collapsed. But the way check
was written does not acheive that.

I have fixed it by modifying the check in the assertion to be same as
check on fd->loop->cond_code.

I tested goacc and libgomp (with nvptx offloading) and did not see any
regression.  I have added new tests to check collapse with GT/GE condition.

PR middle-end/98088
gcc/
* omp-expand.c (expand_oacc_collapse_init): Update condition in
a gcc_assert.

gcc/testsuite/
* c-c++-common/goacc/collapse-2.c: New.

libgomp/
* testsuite/libgomp.oacc-c-c++-common/collapse-2.c: Add check
for loop with GT/GE condition.
* testsuite/libgomp.oacc-c-c++-common/collapse-3.c: Likewise.

4 years agoAdjust 'libgomp.oacc-fortran/derivedtypes-arrays-1.f90' for og10
Thomas Schwinge [Fri, 26 Mar 2021 14:19:49 +0000 (15:19 +0100)] 
Adjust 'libgomp.oacc-fortran/derivedtypes-arrays-1.f90' for og10

This is a fix-up for og10 commit c89b23b73edeeb7e3d8cbad278e505c2d6d770c4
"'libgomp.oacc-fortran/derivedtypes-arrays-1.f90' OpenACC 'serial' construct
diagnostic for nvptx offloading".

We're missing in og10 a few patches related to diagnostics location
tracking/checking, both compiler-side and testsuite-side.

libgomp/
* testsuite/libgomp.oacc-fortran/derivedtypes-arrays-1.f90: Adjust
for og10.

4 years agoamdgcn: Add gfx908 support
Andrew Stubbs [Thu, 22 Oct 2020 20:23:48 +0000 (21:23 +0100)] 
amdgcn: Add gfx908 support

gcc/

* config/gcn/gcn-opts.h (enum processor_type): Add PROCESSOR_GFX908.
* config/gcn/gcn.c (gcn_omp_device_kind_arch_isa): Add gfx908.
(output_file_start): Add gfx908.
* config/gcn/gcn.opt (gpu_type): Add gfx908.
* config/gcn/t-gcn-hsa (MULTILIB_OPTIONS): Add march=gfx908.
(MULTILIB_DIRNAMES): Add gfx908.
* config/gcn/mkoffload.c (EF_AMDGPU_MACH_AMDGCN_GFX908): New define.
(main): Recognize gfx908.
* config/gcn/t-omp-device: Add gfx908.

libgomp/

* plugin/plugin-gcn.c (EF_AMDGPU_MACH): Add
EF_AMDGPU_MACH_AMDGCN_GFX908.
(gcn_gfx908_s): New constant string.
(isa_hsa_name): Add gfx908.
(isa_code): Add gfx908.

(cherry picked from commit 3535402e20118655b2ad4085a6e1d4f1b9c46e92)

4 years agolibgomp HSA/GCN plugins: don't prepend the 'HSA_RUNTIME_LIB' path to 'libhsa-runtime6...
Thomas Schwinge [Thu, 25 Jun 2020 09:59:42 +0000 (11:59 +0200)] 
libgomp HSA/GCN plugins: don't prepend the 'HSA_RUNTIME_LIB' path to 'libhsa-runtime64.so'

For unknown reasons, this had gotten added for the libgomp HSA plugin in commit
b8d89b03db5f212919e4571671ebb4f5f8b1e19d (r242749) "Remove build dependence on
HSA run-time", and later propagated into the GCN plugin.

libgomp/
* plugin/plugin-hsa.c (init_enviroment_variables): Don't prepend
the 'HSA_RUNTIME_LIB' path to 'libhsa-runtime64.so'.
* plugin/plugin-gcn.c (init_environment_variables): Likewise.
* plugin/configfrag.ac (HSA_RUNTIME_LIB): Clean up.
* config.h.in: Regenerate.
* configure: Likewise.

(cherry picked from commit 7c1e856bedb4ae190c420ec2d2ca5e08730cf21d)

4 years ago'libgomp.oacc-fortran/derivedtypes-arrays-1.f90' OpenACC 'serial' construct diagnosti...
Thomas Schwinge [Thu, 11 Mar 2021 09:52:59 +0000 (10:52 +0100)] 
'libgomp.oacc-fortran/derivedtypes-arrays-1.f90' OpenACC 'serial' construct diagnostic for nvptx offloading

Fixup for recent commit d28f3da11d8c0aed9b746689d723022a9b5ec04c "openacc: Fix
lowering for derived-type mappings through array elements".  With nvptx
offloading we see the usual:

    [...]/libgomp.oacc-fortran/derivedtypes-arrays-1.f90: In function 'MAIN__._omp_fn.0':
    [...]/libgomp.oacc-fortran/derivedtypes-arrays-1.f90:90:40: warning: using vector_length (32), ignoring 1

libgomp/
* testsuite/libgomp.oacc-fortran/derivedtypes-arrays-1.f90:
OpenACC 'serial' construct diagnostic for nvptx offloading.

(cherry picked from commit 8bafce1be11a301c2421483736c634b8bf330e69)

4 years agoOpenMP 5.0: requires directive: adjust libgomp HSA plugin
Thomas Schwinge [Wed, 3 Mar 2021 21:51:01 +0000 (22:51 +0100)] 
OpenMP 5.0: requires directive: adjust libgomp HSA plugin

Fix-up for og10 commit c2e4a17adc0989f216c7fc3f93f150c66adba23a "OpenMP 5.0:
requires directive".

    libgomp: while loading libgomp-plugin-hsa.so.1: [...]/libgomp-plugin-hsa.so.1: undefined symbol: GOMP_OFFLOAD_supported_features

libgomp/
* plugin/plugin-hsa.c (GOMP_OFFLOAD_supported_features): New
function.

4 years ago[WIP] OpenMP 5.0: requires directive: workaround to fix libgomp IntelMIC plugin build
Thomas Schwinge [Wed, 3 Mar 2021 21:37:58 +0000 (22:37 +0100)] 
[WIP] OpenMP 5.0: requires directive: workaround to fix libgomp IntelMIC plugin build

Fix-up for og10 commit c2e4a17adc0989f216c7fc3f93f150c66adba23a "OpenMP 5.0:
requires directive".

The GCC offloading target configurations don't build/use
'crtoffloadbegin.o'/'crtoffloadtable.o'/'crtoffloadend.o'
('libgcc/offloadstuff.c'), but the libgomp IntelMIC plugin still does link
against libgomp, and the latter unconditionally refers to
'__requires_mask_table', '__requires_mask_table_end':

    make[3]: Entering directory '[...]/build-gcc-offload-x86_64-intelmicemul-linux-gnu/x86_64-intelmicemul-linux-gnu/liboffloadmic/plugin'
    [...]/build-gcc-offload-x86_64-intelmicemul-linux-gnu/./gcc/xg++ [...] -loffloadmic_target -lcoi_device -lgomp -rdynamic ../ofldbegin.o offload_target_main.o ../ofldend.o -o offload_target_main
    ./../../libgomp/.libs/libgomp.so: undefined reference to `__requires_mask_table_end'
    ./../../libgomp/.libs/libgomp.so: undefined reference to `__requires_mask_table'
    collect2: error: ld returned 1 exit status
    Makefile:806: recipe for target 'offload_target_main' failed
    make[3]: *** [offload_target_main] Error 1

I have not researched what a proper fix would look like.

libgomp/
* target.c (__requires_mask_table, __requires_mask_table_end): Add
'__attribute__((weak))'.

4 years agoAdjust 'gfortran.dg/gomp/order-4.f90' for og10
Thomas Schwinge [Fri, 16 Oct 2020 09:20:21 +0000 (11:20 +0200)] 
Adjust 'gfortran.dg/gomp/order-4.f90' for og10

Testcase added in og10 commit 835160b024ce34bc6f258e7df366bb5c15e12a4b "OpenMP:
Handle order(concurrent) clause in gfortran" (cherry picked from commit
d8140b9ed3c0fed041aedaff3fa4a603984ca10f), but og10 doesn't have commit
4f2ab6b89e170f1343f935761481c3745fe603b1 "[OpenMP, gimplifier] 'inform' after
'error' diagnostic".

gcc/testsuite/
* gfortran.dg/gomp/order-4.f90: Adjust.

4 years agoLambda capturing of pointers and references in target directives
Chung-Lin Tang [Thu, 18 Mar 2021 18:29:20 +0000 (02:29 +0800)] 
Lambda capturing of pointers and references in target directives

This patch implements proper lambda capturing of pointer and reference variables
as specified in OpenMP 5.0. We map the entire closure object as a to-map,
attach pointers to zero-length array sections, and perform mapping of
references.

2021-03-18  Chung-Lin Tang  <cltang@codesourcery.com>

gcc/cp/ChangeLog:

* cp-tree.h (set_omp_target_this_expr): Delete.
(finish_omp_target_clauses): New prototype.
* lambda.c (lambda_expr_this_capture): Remove call to
set_omp_target_this_expr.
* parser.c (cp_parser_omp_target): Likewise.
* pt.c (tsubst_expr): Add call to finish_omp_target_clauses for target
directives.
* semantics.c (omp_target_this_expr): Delete.
(omp_target_ptr_members_accessed): Delete.
(finish_non_static_data_member): Remove call to
set_omp_target_this_expr. Remove use of omp_target_ptr_members_accessed.
(finish_this_expr): Remove call to set_omp_target_this_expr.
(struct omp_target_walk_data): New struct for walking over
target-directive tree body.
(finish_omp_target_clauses_r): New function for tree walk.
(finish_omp_target_clauses): New function, with code factored out from
finish_omp_target. Add lambda object handling case.
(finish_omp_target): Factor code out and adjust to use
finish_omp_target_clauses.
(finish_omp_clauses): Revert prior "Adjustments to allow '*ptr' and
'ptr->member' cases in map clausess.", since not needed with new
organization of target-directive clause processing.

gcc/testsuite/ChangeLog:

* g++.dg/gomp/target-lambda-1.C: New test.

libgomp/testsuite/ChangeLog:

* libgomp.c++/target-lambda-1.C: New test.

4 years agoFix template case of non-static member access inside member functions
Chung-Lin Tang [Thu, 11 Mar 2021 08:31:08 +0000 (00:31 -0800)] 
Fix template case of non-static member access inside member functions

Prior patches for C++ non-static member access had problems under template
classes, due to re-calling of finish_omp_clauses after finish_omp_target
created the implicit maps required, but not of allowed form in finish_omp_clauses.

This patch solves this by slightly relaxing the allowed expressions in
finish_omp_clauses.

2021-03-11  Chung-Lin Tang  <cltang@codesourcery.com>

gcc/cp/ChangeLog:

* semantics.c (finish_omp_clauses): Adjustments to allow '*ptr' and
'ptr->member' cases in map clausess.
(finish_omp_target): Use INDIRECT_REF instead of MEM_REF in created
clauses, add processing_template_decl handling.

gcc/ChangeLog:

* gimplify.c (gimplify_scan_omp_clauses): Under !DECL_P case of
GOMP_CLAUSE_MAP handling, add STRIP_NOPS for indir_p case, add to
struct_deref_set for map(*ptr_to_struct) cases.

gcc/testsuite/ChangeLog:

* g++.dg/gomp/target-this-3.C: Adjust scan test.
* g++.dg/gomp/target-this-4.C: Likewise.
* g++.dg/gomp/target-this-5.C: New test.

libgomp/ChangeLog:

* testsuite/libgomp.c++/target-this-5.C: New test.

4 years agoArrow operator handling for C front-end in OpenMP map clauses
Chung-Lin Tang [Mon, 8 Mar 2021 07:56:52 +0000 (15:56 +0800)] 
Arrow operator handling for C front-end in OpenMP map clauses

This patch merges some of the equivalent changes already done for the C++
front-end to the C parts.

2021-03-08  Chung-Lin Tang  <cltang@codesourcery.com>

gcc/c/ChangeLog:

* c-parser.c (c_parser_omp_clause_map): Set 'allow_deref' argument in
call to c_parser_omp_variable_list to 'true'.
* c-typeck.c (handle_omp_array_sections_1): Add strip of MEM_REF in
array base handling.
(c_finish_omp_clauses): Handle 'A->member' case in map clauses.

gcc/ChangeLog:

* gimplify.c (gimplify_scan_omp_clauses): Add MEM_REF case when
handling component_ref_p case. Add unshare_expr and gimplification
when created GOMP_MAP_STRUCT is not a DECL. Add code to add
firstprivate pointer for *pointer-to-struct case.

gcc/testsuite/ChangeLog:

* gcc.dg/gomp/target-3.c: New test.

4 years agoamdgcn: Fix early-debug relocations
Andrew Stubbs [Thu, 22 Oct 2020 12:27:47 +0000 (13:27 +0100)] 
amdgcn: Fix early-debug relocations

The relocation symbols were inadvertantly wiped when the type was set in
mkoffload.

gcc/ChangeLog

* config/gcn/mkoffload.c (copy_early_debug_info): Don't wipe
relocation symbols.

(cherry picked from commit d24a4c8c4256cc287ebf4ad80368b4f1edb1733e)

4 years agoDWARF: late code range fixup
Andrew Stubbs [Thu, 4 Mar 2021 23:12:17 +0000 (23:12 +0000)] 
DWARF: late code range fixup

Ensure that the parent DWARF subprograms of offload kernel functions have a
code range, and are therefore not discarded by GDB.  This is only necessary
when the parent function does not actually exist in the final binary, which is
commonly the case within the offload device's binary.

This patch replaces 808bdf1bb29 and fdcb23540a2.  It should be squashed with
those before being posted upstream.

gcc/

* gcc/dwarf2out.c (notional_parents_list): New file variable.
(gen_subprogram_die): Record offload kernel functions in
notional_parents_list.
(fixup_notional_parents): New function.
(dwarf2out_finish): Call fixup_notional_parents.
(dwarf2out_c_finalize): Reset notional_parents_list.

4 years agoopenmp: Scale type precision of collapsed iterator variable
Kwok Cheung Yeung [Mon, 1 Mar 2021 22:15:30 +0000 (14:15 -0800)] 
openmp: Scale type precision of collapsed iterator variable

This sets the type precision of the collapsed iterator variable to the
sum of the precision of the collapsed loop variables, up to a maximum of
sizeof(long long) (i.e. 64-bits).

2021-03-01  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/
* omp-expand.c (expand_oacc_for): Convert .tile variable to
diff_type before multiplying.
* omp-general.c (omp_extract_for_data): Use accumulated precision
of all collapsed for-loops as precision of iteration variable, up
to the precision of a long long.

libgomp/
* testsuite/libgomp.c-c++-common/collapse-4.c: New.
* testsuite/libgomp.fortran/collapse5.f90: New.

4 years agoAllow static constexpr fields in mappable types for C++
Chung-Lin Tang [Wed, 3 Mar 2021 14:39:10 +0000 (22:39 +0800)] 
Allow static constexpr fields in mappable types for C++

This patch is a merge of:
https://gcc.gnu.org/legacy-ml/gcc-patches/2020-01/msg01246.html

Static members in general disqualify a C++ class from being target mappable,
but static constexprs are inline optimized away, so should not interfere.

OpenMP 5.0 in general lifts the static member limitation, so this
patch will probably further adjusted later.

2021-03-03  Chung-Lin Tang  <cltang@codesourcery.com>

gcc/cp/ChangeLog:

* decl2.c (cp_omp_mappable_type_1): Allow fields with
DECL_DECLARED_CONSTEXPR_P to be mapped.

gcc/testsuite/ChangeLog:

* g++.dg/goacc/static-constexpr-1.C: New test.
* g++.dg/gomp/static-constexpr-1.C: New test.

4 years agonvptx: remove erroneous stack deletion
Andrew Stubbs [Tue, 23 Feb 2021 21:35:08 +0000 (21:35 +0000)] 
nvptx: remove erroneous stack deletion

The stacks are not supposed to be deleted every time memory is allocated, only
when there is insufficient memory.  The unconditional call here seems to be in
error, and is causing a costly reallocation of the stacks before every launch.

libgomp/

* plugin/plugin-nvptx.c (GOMP_OFFLOAD_alloc): Remove early call to
nvptx_stacks_free.

4 years agoFortran: add contiguous check for ptr assignment, fix non-contig check (PR97242)
Tobias Burnus [Wed, 30 Sep 2020 13:01:13 +0000 (15:01 +0200)] 
Fortran: add contiguous check for ptr assignment, fix non-contig check (PR97242)

gcc/fortran/ChangeLog:

PR fortran/97242
* expr.c (gfc_is_not_contiguous): Fix check.
(gfc_check_pointer_assign): Use it.

gcc/testsuite/ChangeLog:

PR fortran/97242
* gfortran.dg/contiguous_11.f90: New test.
* gfortran.dg/contiguous_4.f90: Update.
* gfortran.dg/contiguous_7.f90: Update.

(cherry picked from commit 65167982efa4dbb96698d026e6d7e17acb513f0a)

4 years agoDWARF: fix ICE caused by offload debug fix
Andrew Stubbs [Fri, 26 Feb 2021 11:40:06 +0000 (11:40 +0000)] 
DWARF: fix ICE caused by offload debug fix

This should be squashed with 808bdf1bb29 and fdcb23540a2 to go to mainline.

gcc/

* dwarf2out.c (gen_subprogram_die): Replace existing low/high PC
attributes, rather than ICE.

4 years agoRecommit "Enable gimplify GOMP_MAP_STRUCT handling of (COMPONENT_REF (INDIRECT_REF...
Chung-Lin Tang [Fri, 26 Feb 2021 12:14:49 +0000 (20:14 +0800)] 
Recommit "Enable gimplify GOMP_MAP_STRUCT handling of (COMPONENT_REF (INDIRECT_REF ...)) map clauses".

This patch was reverted in commit ea43db9372133e84f95bdb2c6934a5cc3db3d530
due to a regression. Now re-applying to devel/omp/gcc-10 after regression fixed.

This patch tries to allow map(A->ptr) to be properly handled the same way as
map(B.ptr) expressions. map(struct:*A) clauses are now produced during
gimplify.

This patch, as of time of commit, is only pushed to devel/omp/gcc-10, not yet
submitted as mainline patch to upstream.

2021-02-26  Chung-Lin Tang  <cltang@codesourcery.com>

gcc/ChangeLog:

* gimplify.c ("tree-hash-traits.h"): Add include.
(gimplify_scan_omp_clauses): Change struct_map_to_clause to type
hash_map<tree_operand, tree> *. Adjust struct map handling to handle
cases of *A and A->B expressions.
(gimplify_adjust_omp_clauses): Move GOMP_MAP_STRUCT removal code for
exit data directives code to earlier position.

gcc/testsuite/ChangeLog:

* g++.dg/gomp/target-3.C: Adjust testcase gimple scanning.
* g++.dg/gomp/target-this-2.C: Likewise.
* g++.dg/gomp/target-this-3.C: Likewise.
* g++.dg/gomp/target-this-4.C: Likewise.

libgomp/ChangeLog:

* testsuite/libgomp.c++/target-23.C: New testcase.

4 years agoFix regression of array members in OpenMP map clauses.
Chung-Lin Tang [Fri, 26 Feb 2021 12:13:29 +0000 (20:13 +0800)] 
Fix regression of array members in OpenMP map clauses.

Fixed a regression of array members not working in OpenMP map clauses after
commit bf8605f14ec33ea31233a3567f3184fee667b695.

This patch itself probably should be considered a fix for commit aadfc9843.

2021-02-26  Chung-Lin Tang  <cltang@codesourcery.com>

gcc/cp/ChangeLog:

* semantics.c (handle_omp_array_sections): Adjust position of making
COMPONENT_REF from FIELD_DECL to earlier position.

4 years ago[og10] openacc: Strided array sections and components of derived-type arrays
Julian Brown [Wed, 10 Feb 2021 19:18:13 +0000 (11:18 -0800)] 
[og10] openacc: Strided array sections and components of derived-type arrays

This patch disallows selecting components of array sections in update
directives for OpenACC, as specified in OpenACC 3.0, "2.14.4. Update
Directive":

  In Fortran, members of variables of derived type may appear, including
  a subarray of a member. Members of subarrays of derived type may
  not appear.

The diagnostic for attempting to use the same construct on other
directives has also been improved.

gcc/fortran/
* openmp.c (resolve_omp_clauses): Disallow selecting components
of arrays of derived type.

gcc/testsuite/
* gfortran.dg/goacc/array-with-dt-2.f90: Remove expected errors.
* gfortran.dg/goacc/array-with-dt-6.f90: New test.
* gfortran.dg/goacc/mapping-tests-2.f90: Update expected error.
* gfortran.dg/goacc/ref_inquiry.f90: Update expected errors.
* gfortran.dg/gomp/ref_inquiry.f90: Likewise.

libgomp/
* testsuite/libgomp.oacc-fortran/array-stride-dt-1.f90: Remove
expected errors.

(cherry picked from commit 366cf1127a547ff77024a551abb01bb1a6e963cd)

4 years ago[og10] openacc: Fix lowering for derived-type mappings through array elements
Julian Brown [Thu, 21 Jan 2021 14:54:54 +0000 (06:54 -0800)] 
[og10] openacc: Fix lowering for derived-type mappings through array elements

This patch fixes lowering of derived-type mappings which select elements
of arrays of derived types, and similar. These would previously lead
to ICEs.

With this change, OpenACC directives can pass through constructs that
are no longer recognized by the gimplifier, hence alterations are needed
there also.

gcc/fortran/
* trans-openmp.c (gfc_trans_omp_clauses): Handle element selection
for arrays of derived types.

gcc/
* gimplify.c (gimplify_scan_omp_clauses): Handle ATTACH_DETACH
for non-decls.

gcc/testsuite/
* gfortran.dg/goacc/array-with-dt-1.f90: New test.
* gfortran.dg/goacc/array-with-dt-3.f90: Likewise.
* gfortran.dg/goacc/array-with-dt-4.f90: Likewise.
* gfortran.dg/goacc/array-with-dt-5.f90: Likewise.
* gfortran.dg/goacc/derived-chartypes-1.f90: Re-enable test.
* gfortran.dg/goacc/derived-chartypes-2.f90: Likewise.
* gfortran.dg/goacc/derived-classtypes-1.f95: Uncomment
previously-broken directives.

libgomp/
* testsuite/libgomp.oacc-fortran/derivedtypes-arrays-1.f90: New test.
* testsuite/libgomp.oacc-fortran/update-dt-array.f90: Likewise.

(cherry picked from commit d28f3da11d8c0aed9b746689d723022a9b5ec04c)

4 years ago[og10] Fortran: %re/%im fixes for OpenMP/OpenACC + gfc_is_simplify_contiguous
Tobias Burnus [Tue, 16 Feb 2021 16:39:49 +0000 (17:39 +0100)] 
[og10] Fortran: %re/%im fixes for OpenMP/OpenACC + gfc_is_simplify_contiguous

gcc/fortran/ChangeLog:

* expr.c (gfc_is_simplify_contiguous): Handle REF_INQUIRY, i.e.
%im and %re which are EXPR_VARIABLE.
* openmp.c (resolve_omp_clauses): Diagnose %re/%im explicitly.

gcc/testsuite/ChangeLog:

* gfortran.dg/goacc/ref_inquiry.f90: New test.
* gfortran.dg/gomp/ref_inquiry.f90: New test.

(cherry picked from commit 799478b8914c438f7a33eb319efbae69c81f2111)

4 years ago[og10] Fortran: OpenMP/OpenACC diagnose substring rejections better
Tobias Burnus [Thu, 4 Feb 2021 11:32:59 +0000 (12:32 +0100)] 
[og10] Fortran: OpenMP/OpenACC diagnose substring rejections better

gcc/fortran/ChangeLog:

* openmp.c (resolve_omp_clauses): Explicitly diagnose
substrings as not permitted.

gcc/testsuite/ChangeLog:

* gfortran.dg/goacc/substring.f90: New test.
* gfortran.dg/gomp/substring.f90: New test.

(cherry picked from commit f0e618faeb619ec02dabbef203a5575fca44a7f7)

4 years ago[og10] openacc: Character types and mixed arrays/derived type tests
Julian Brown [Thu, 4 Feb 2021 18:13:22 +0000 (10:13 -0800)] 
[og10] openacc: Character types and mixed arrays/derived type tests

This patch adds some tests for character types that are components
of derived types used in OpenACC data-movement clauses (some of which
currently fail and are thus XFAILed), and tests (also XFAILed) mixing
arrays and derived types.  The XFAILs are addressed by follow-on patches.
Originally a combination of several mainline patches.

(cherry picked from commit b2d84e9f9cccbe4ee662f7002b83105629d09939)
(cherry picked from commit 9a4d32f85ccebc0ee4b24e6d9d7a4f11c04d7146)
(cherry picked from commit b0fb2720d88d680af18981a2097397196b505a1f)
(cherry picked from commit f7fb2f662fe12f327ece8b034ab76b36fdca4696)

gcc/testsuite/
* gfortran.dg/goacc/array-with-dt-2.f90: New test.
* gfortran.dg/goacc/derived-chartypes-1.f90: Likewise.
* gfortran.dg/goacc/derived-chartypes-2.f90: Likewise.
* gfortran.dg/goacc/derived-chartypes-3.f90: Likewise.
* gfortran.dg/goacc/derived-chartypes-4.f90: Likewise.

libgomp/
* testsuite/libgomp.oacc-fortran/array-stride-dt-1.f90: New test.

4 years ago[og10] openacc: Use class_pointer instead of pointer attribute for class types
Julian Brown [Sat, 30 Jan 2021 01:18:07 +0000 (17:18 -0800)] 
[og10] openacc: Use class_pointer instead of pointer attribute for class types

Elsewhere in the Fortran front-end, the class_pointer attribute is
used for BT_CLASS entities instead of the pointer attribute. This patch
follows suit for OpenACC. I couldn't actually come up with a test case
where this makes a difference (i.e., where "class_pointer" and "pointer"
have different values at this point in the code), but this may nonetheless
fix a latent bug.

gcc/fortran/
* trans-openmp.c (gfc_trans_omp_clauses): Use class_pointer attribute
for BT_CLASS.

(cherry picked from commit f743fe231663e32d52db987650d0ec3381a777af)

4 years ago[og10] openacc: Dereference BT_CLASS data pointers but not BT_DERIVED pointers
Julian Brown [Fri, 29 Jan 2021 23:37:27 +0000 (15:37 -0800)] 
[og10] openacc: Dereference BT_CLASS data pointers but not BT_DERIVED pointers

The stanza in gfc_trans_omp_clauses that handles derived type members
that are themselves derived type pointers or class pointers now adds
an explicit dereference only for the latter. The former is already
dereferenced transparently in gfc_conv_component_ref.

gcc/fortran/
* trans-openmp.c (gfc_trans_omp_clauses): Fix dereferencing for
BT_DERIVED members.

gcc/testsuite/
* gfortran.dg/goacc/derived-classtypes-1.f95: New test.

(cherry picked from commit cff6e8db880b6e262730b1ce9a9cb00c1f5571e2)

4 years agonvptx - invoke.texi: Update default of -misa
Tobias Burnus [Mon, 12 Oct 2020 11:13:20 +0000 (13:13 +0200)] 
nvptx - invoke.texi: Update default of -misa

Followup to commit 383400a6078d75bbfa1216c9af2c37f7e88740c9

gcc/ChangeLog
* doc/invoke.texi (nvptx's -misa): Update default to sm_35.

(cherry picked from commit 91e4e16b550540723cca824b9674c7d8c43f4849)

4 years ago[nvptx] Set -misa=sm_35 by default
Tom de Vries [Fri, 9 Oct 2020 09:36:10 +0000 (11:36 +0200)] 
[nvptx] Set -misa=sm_35 by default

The nvptx-as assembler verifies the ptx code using ptxas, if there's any
in the PATH.

The default in the nvptx port for -misa=sm_xx is sm_30, but the ptxas of the
latest cuda release (11.1) no longer supports sm_30.

Consequently we cannot build gcc against that release (although we should
still be able to build without any cuda release).

Fix this by setting -misa=sm_35 by default.

Tested check-gcc on nvptx.

Tested libgomp on x86_64-linux with nvpx accelerator.

Both build again cuda 9.1.

gcc/ChangeLog:

2020-10-09  Tom de Vries  <tdevries@suse.de>

PR target/97348
* config/nvptx/nvptx.h (ASM_SPEC): Also pass -m to nvptx-as if
default is used.
* config/nvptx/nvptx.opt (misa): Init with PTX_ISA_SM35.

(cherry picked from commit 383400a6078d75bbfa1216c9af2c37f7e88740c9)

4 years agoRevert "Enable gimplify GOMP_MAP_STRUCT handling of (COMPONENT_REF (INDIRECT_REF...
Catherine Moore [Sat, 13 Feb 2021 17:04:44 +0000 (09:04 -0800)] 
Revert "Enable gimplify GOMP_MAP_STRUCT handling of (COMPONENT_REF (INDIRECT_REF ...)) map clauses."

This reverts commit bf8605f14ec33ea31233a3567f3184fee667b695.

Regressions were reported for BZ 9574 - C++ class member mapping.

4 years agoFortran: Fix rank of assumed-rank array [PR99043]
Tobias Burnus [Fri, 12 Feb 2021 15:43:54 +0000 (16:43 +0100)] 
Fortran: Fix rank of assumed-rank array [PR99043]

gcc/fortran/ChangeLog:

PR fortran/99043
* trans-expr.c (gfc_conv_procedure_call): Don't reset
rank of assumed-rank array.

gcc/testsuite/ChangeLog:

PR fortran/99043
* gfortran.dg/assumed_rank_20.f90: New test.

(cherry picked from commit f699e0b16578cdc1be8b90691ef8b0964af32d2f)

4 years agoFortran: Fix some select rank issues [PR97694 and 97723].
Tobias Burnus [Fri, 12 Feb 2021 10:21:08 +0000 (11:21 +0100)] 
Fortran: Fix some select rank issues [PR97694 and 97723].

Backport from mainline; also fixes PR fortran/99045

2020-12-27  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/97694
PR fortran/97723
* check.c (allocatable_check): Select rank temporaries are
permitted even though they are treated as associate variables.
* resolve.c (gfc_resolve_code): Break on select rank as well as
select type so that the block os resolved.
* trans-stmt.c (trans_associate_var): Class associate variables
that are optional dummies must use the backend_decl.

gcc/testsuite/
PR fortran/97694
PR fortran/97723
* gfortran.dg/select_rank_5.f90: New test.

(cherry picked from commit c4a678981572c12d158709ace0d3f23dd04cf217)

4 years agoopenmp: Fix ICE on non-rectangular loop with known 0 iterations
Jakub Jelinek [Wed, 18 Nov 2020 08:40:45 +0000 (09:40 +0100)] 
openmp: Fix ICE on non-rectangular loop with known 0 iterations

The loops in the testcase are non-rectangular and have 0 iterations
(the outer loop iterates, but the inner one never).  In this case we
just have the overall number of iterations computed (0), and don't have
factor and other values computed.  We never need to map logical iterations
to the individual iterations in that case, and we were crashing during
expansion of that code.

2020-11-18  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/97862
* omp-expand.c (expand_omp_for_init_vars): Don't use the sqrt path
if number of iterations is constant 0.

* c-c++-common/gomp/pr97862.c: New test.

(cherry picked from commit ba009860aec4619f2424f5bdee812f14572dc3cc)

4 years agoopenmp: Improve composite triangular loop lowering and expansion
Jakub Jelinek [Tue, 13 Oct 2020 07:30:47 +0000 (09:30 +0200)] 
openmp: Improve composite triangular loop lowering and expansion

This propagates needed values from the point where number of iterations
is calculated on composite loops to the places where that information
is needed to use the more efficient square root discovery to compute
the starting iterator values from the logical iteration number.

2020-10-13  Jakub Jelinek  <jakub@redhat.com>

* omp-low.c (add_taskreg_looptemp_clauses): For triangular loops
with non-constant number of iterations add another 4 _looptemp_
clauses before the (optional) one for lastprivate.
(lower_omp_for_lastprivate): Skip those clauses when looking for
the lastprivate clause.
(lower_omp_for): For triangular loops with non-constant number of
iterations add another 4 _looptemp_ clauses.
* omp-expand.c (expand_omp_for_init_counts): For triangular loops
with non-constant number of iterations set counts[0],
fd->first_inner_iterations, fd->factor and fd->adjn1 from the newly
added _looptemp_ clauses.
(expand_omp_for_init_vars): Initialize the newly added _looptemp_
clauses.
(find_lastprivate_looptemp): New function.
(expand_omp_for_static_nochunk, expand_omp_for_static_chunk,
expand_omp_taskloop_for_outer): Use it instead of manually skipping
_looptemp_ clauses.

(cherry picked from commit 14707c896a207606f13886d3b3251e8db1f3c9c0)

4 years agoopenmp: Add support for non-rectangular loops in taskloop construct
Jakub Jelinek [Thu, 13 Aug 2020 07:06:05 +0000 (09:06 +0200)] 
openmp: Add support for non-rectangular loops in taskloop construct

2020-08-13  Jakub Jelinek  <jakub@redhat.com>

* gimplify.c (gimplify_omp_taskloop_expr): New function.
(gimplify_omp_for): Use it.  For OMP_FOR_NON_RECTANGULAR
loops adjust in outer taskloop the var-outer decls.
* omp-expand.c (expand_omp_taskloop_for_inner): Handle non-rectangular
loops.
(expand_omp_for): Don't reject non-rectangular taskloop.
* omp-general.c (omp_extract_for_data): Don't assert that
non-rectangular loops have static schedule, instead treat loop->m1
or loop->m2 as if loop->n1 or loop->n2 is non-constant.

* testsuite/libgomp.c/loop-22.c (main): Add some further tests.
* testsuite/libgomp.c/loop-23.c (main): Likewise.
* testsuite/libgomp.c/loop-24.c: New test.

(cherry picked from commit 2e47c8c6eac405ceb599bf5e31ac3717c22a008c)

4 years agoopenmp: Handle even some combined non-rectangular loops
Jakub Jelinek [Wed, 5 Aug 2020 08:45:16 +0000 (10:45 +0200)] 
openmp: Handle even some combined non-rectangular loops

The number of loops computation and logical iteration -> actual iterator values
computations can now be done separately even on composite constructs (though
for triangular loops it would still be more efficient to propagate a few values
through, will handle that incrementally).
simd and taskloop are still unhandled.

2020-08-05  Jakub Jelinek  <jakub@redhat.com>

* omp-expand.c (expand_omp_for): Don't disallow combined non-rectangular
loops.

* testsuite/libgomp.c/loop-22.c: New test.
* testsuite/libgomp.c/loop-23.c: New test.

(cherry picked from commit 9f3abfb84e2a7ca115b0550c32308b5ada3e6a46)

4 years agoopenmp: Use more efficient logical -> actual computation even if # iterations is...
Jakub Jelinek [Wed, 5 Aug 2020 08:37:25 +0000 (10:37 +0200)] 
openmp: Use more efficient logical -> actual computation even if # iterations is computed at runtime

For triangular loops use more efficient logical iteration number
to actual iterator values computation even for non-rectangular loops
where number of loop iterations could not be computed at compile time.

2020-08-05  Jakub Jelinek  <jakub@redhat.com>

* omp-expand.c (expand_omp_for_init_counts): Remember
first_inner_iterations, factor and n1o from the number of iterations
computation in *fd.
(expand_omp_for_init_vars): Use more efficient logical iteration number
to actual iterator values computation even for non-rectangular loops
where number of loop iterations could not be computed at compile time.

(cherry picked from commit 325714b4968050c927fe72f4a4ba860da2bf4ee2)

4 years agoopenmp: Compute number of collapsed loop iterations more efficiently for some non...
Jakub Jelinek [Tue, 4 Aug 2020 08:53:07 +0000 (10:53 +0200)] 
openmp: Compute number of collapsed loop iterations more efficiently for some non-rectangular loops

2020-08-04  Jakub Jelinek  <jakub@redhat.com>

* omp-expand.c (expand_omp_for_init_counts): For triangular loops
compute number of iterations at runtime more efficiently.
(expand_omp_for_init_vars): Adjust immediate dominators.
(extract_omp_for_update_vars): Likewise.

(cherry picked from commit 29e0ad452cdf001bccd12c1cb5f4797df1114a3a)

4 years agoopenmp: Fix up loop-21.c
Jakub Jelinek [Wed, 15 Jul 2020 14:34:54 +0000 (16:34 +0200)] 
openmp: Fix up loop-21.c

I've missed
+FAIL: libgomp.c/loop-21.c execution test
during testing of the recent patch.  The problem is that while
for the number of iterations computation it doesn't matter if we compute
min_inner_iterations as (m2 * first + n2 + (adjusted step) + m1 * first + n1) / step
or (m2 * last + n2 + (adjusted step) + m1 * last + n1) / step provided that
in the second case we use as factor (m1 - m2) * ostep / step rather than
(m2 - m1) * ostep / step, for the logical to actual iterator values computation
it does matter and in my hand written C implementations of all the cases (outer
vs. inner loop with increasing vs. decreasing iterator) I'm using the same computation
and it worked well for all the pseudo-random iterators testing it was doing.

It also means min_inner_iterations is misnamed, because it is not really
minimum number of inner iterations, whether the first or last outer iteration
results in the smaller or larger value of this can be (sometimes) only
determined at runtime.
So this patch also renames it to first_inner_iterations.

2020-07-15  Jakub Jelinek  <jakub@redhat.com>

PR libgomp/96198
* omp-general.h (struct omp_for_data): Rename min_inner_iterations
member to first_inner_iterations, adjust comment.
* omp-general.c (omp_extract_for_data): Adjust for the above change.
Always use n1first and n2first to compute it, rather than depending
on single_nonrect_cond_code.  Similarly, always compute factor
as (m2 - m1) * outer_step / inner_step rather than sometimes m1 - m2
depending on single_nonrect_cond_code.
* omp-expand.c (expand_omp_for_init_vars): Rename min_inner_iterations
to first_inner_iterations and min_inner_iterationsd to
first_inner_iterationsd.

(cherry picked from commit 79c12969ec3e9185fdbb90d3b1699d64b1cd0901)

4 years agoopenmp: Adjust outer bounds of non-rect loops
Jakub Jelinek [Tue, 14 Jul 2020 08:31:59 +0000 (10:31 +0200)] 
openmp: Adjust outer bounds of non-rect loops

In loops like:
  #pragma omp parallel for collapse(2)
  for (i = -4; i < 8; i++)
    for (j = 3 * i; j > 2 * i; j--)
for some outer loop iterations there are no inner loop iterations at all,
the condition is false.  In order to use Summæ Potestate to count number
of iterations or to transform the logical iteration number to actual
iterator values using quadratic non-equation root discovery the outer
iterator range needs to be adjusted, such that the inner loop has at least
one iteration for each of the outer loop iterator value in the reduced
range.  Sometimes this adjustment is done at the start of the range,
at other times at the end.

This patch implements it during the compile time number of loop computation
(if all expressions are compile time constants).

2020-07-14  Jakub Jelinek  <jakub@redhat.com>

* omp-general.h (struct omp_for_data): Add adjn1 member.
* omp-general.c (omp_extract_for_data): For non-rect loop, punt on
count computing if n1, n2 or step are not INTEGER_CST earlier.
Narrow the outer iterator range if needed so that non-rect loop
has at least one iteration for each outer range iteration.  Compute
adjn1.
* omp-expand.c (expand_omp_for_init_vars): Use adjn1 if non-NULL
instead of the outer loop's n1.

* testsuite/libgomp.c/loop-21.c: New test.

(cherry picked from commit f418bd4b92a03ee0ec0fe4cfcd896e86e11ac2cf)

4 years agoopenmp: Optimize triangular loop logical iterator to actual iterators computation...
Jakub Jelinek [Thu, 9 Jul 2020 10:07:17 +0000 (12:07 +0200)] 
openmp: Optimize triangular loop logical iterator to actual iterators computation using search for quadratic equation root(s)

This patch implements the optimized logical to actual iterators
computation for triangular loops.

I have a rough implementation using integers, but this one uses floating
point.  There is a small problem that -fopenmp programs aren't linked with
-lm, so it does it only if the hw has sqrt optab (and uses ifn rather than
__builtin_sqrt because it obviously doesn't need errno handling etc.).

Do you think it is ok this way, or should I use the integral computation
using inlined isqrt (we have inequation of the form
start >= x * t10 + t11 * (((x - 1) * x) / 2)
where t10 and t11 are signed long long values and start unsigned long long,
and the division by 2 actually is a problem for accuracy in some cases, so
if we do it in integral, we need to do actually
      long long t12 = 2 * t10 - t11;
      unsigned long long t13 = t12 * t12 + start * 8 * t11;
      unsigned long long isqrt_ = isqrtull (t13);
      long long x = (((long long) isqrt_ - t12) / t11) >> 1;
with careful overflow checking on all the computations before isqrtull
(and on overflows use the fallback implementation).

2020-07-09  Jakub Jelinek  <jakub@redhat.com>

* omp-general.h (struct omp_for_data): Add min_inner_iterations
and factor members.
* omp-general.c (omp_extract_for_data): Initialize them and remember
them in OMP_CLAUSE_COLLAPSE_COUNT if needed and restore from there.
* omp-expand.c (expand_omp_for_init_counts): Fix up computation of
counts[fd->last_nonrect] if fd->loop.n2 is INTEGER_CST.
(expand_omp_for_init_vars): For
fd->first_nonrect + 1 == fd->last_nonrect loops with for now
INTEGER_CST fd->loop.n2 find quadratic equation roots instead of
using fallback method when possible.

* testsuite/libgomp.c/loop-19.c: New test.
* testsuite/libgomp.c/loop-20.c: New test.

(cherry picked from commit 5acef69f9d3d9f3c537b5e5157519edf02f86c4d)

4 years agoopenmp: Diagnose non-rectangular loops with invalid steps
Jakub Jelinek [Thu, 2 Jul 2020 09:03:33 +0000 (11:03 +0200)] 
openmp: Diagnose non-rectangular loops with invalid steps

THe OpenMP 5 standard requires that if some loop in OpenMP loop nest refers
to some outer loop's iterator variable, then the subtraction of the multiplication
factors for the outer iterator multiplied by the outer increment modulo the
inner increment is 0.  For loops with non-constants in any of these we can't
diagnose it, it would be a task for something like -fsanitize=openmp,
but if all these are constant, we can diagnose it.

2020-07-02  Jakub Jelinek  <jakub@redhat.com>

* omp-expand.c (expand_omp_for): Diagnose non-rectangular loops with
invalid steps - ((m2 - m1) * incr_outer) % incr must be 0 in valid
OpenMP non-rectangular loops.  Use XALLOCAVEC.

* c-c++-common/gomp/loop-7.c: New test.

(cherry picked from commit 9d50112acfc01f85fe0fb6d88b329e6122e817b3)

4 years agoopenmp: Non-rectangular loop support for non-composite worksharing loops and distribute
Jakub Jelinek [Sat, 27 Jun 2020 10:43:36 +0000 (12:43 +0200)] 
openmp: Non-rectangular loop support for non-composite worksharing loops and distribute

This implements the fallback mentioned in
https://gcc.gnu.org/pipermail/gcc/2020-June/232874.html
Special cases for triangular loops etc. to follow later, also composite
constructs not supported yet (need to check the passing of temporaries around)
and lastprivate might not give the same answers as serial loop if the last
innermost body iteration isn't the last one for some of the outer loops
(that will need to be solved separately together with rectangular loops that have no
innermost body iterations, but some of the outer loops actually iterate).
Also, simd needs work.

2020-06-27  Jakub Jelinek  <jakub@redhat.com>

* omp-general.h (struct omp_for_data_loop): Add non_rect_referenced
member, move outer member.
(struct omp_for_data): Add first_nonrect and last_nonrect members.
* omp-general.c (omp_extract_for_data): Initialize first_nonrect,
last_nonrect and non_rect_referenced members.
* omp-expand.c (expand_omp_for_init_counts): Handle non-rectangular
loops.
(expand_omp_for_init_vars): Add nonrect_bounds parameter.  Handle
non-rectangular loops.
(extract_omp_for_update_vars): Likewise.
(expand_omp_for_generic, expand_omp_for_static_nochunk,
expand_omp_for_static_chunk, expand_omp_simd,
expand_omp_taskloop_for_outer, expand_omp_taskloop_for_inner): Adjust
expand_omp_for_init_vars and extract_omp_for_update_vars callers.
(expand_omp_for): Don't sorry on non-composite worksharing-loop or
distribute.

* testsuite/libgomp.c/loop-17.c: New test.
* testsuite/libgomp.c/loop-18.c: New test.

(cherry picked from commit aed3ab253dada2b7d2ed63cc6a8e15e263d5dd35)

4 years agoopenmp: Fix two pastos in non-rect loop OpenMP lowering.
Jakub Jelinek [Wed, 24 Jun 2020 08:25:37 +0000 (10:25 +0200)] 
openmp: Fix two pastos in non-rect loop OpenMP lowering.

2020-06-24  Jakub Jelinek  <jakub@redhat.com>

* omp-low.c (lower_omp_for): Fix two pastos.

(cherry picked from commit f0008858dec9b16da153b948834abb20b9f1ab32)

4 years agoopenmp: Compute triangular loop number of iterations at compile time
Jakub Jelinek [Mon, 22 Jun 2020 09:06:08 +0000 (11:06 +0200)] 
openmp: Compute triangular loop number of iterations at compile time

2020-06-22  Jakub Jelinek  <jakub@redhat.com>

* omp-general.c (omp_extract_for_data): For triangular loops with
all loop invariant expressions constant where the innermost loop is
executed at least once compute number of iterations at compile time.

(cherry picked from commit c154b8bc56831e4d9d421c52c8fcf95c570255ad)

4 years agoopenmp: Initial part of OpenMP 5.0 non-rectangular loop support
Jakub Jelinek [Tue, 16 Jun 2020 14:31:13 +0000 (16:31 +0200)] 
openmp: Initial part of OpenMP 5.0 non-rectangular loop support

OpenMP 5.0 adds support for non-rectangular loop collapses, e.g.
triangular and more complex.

This patch deals just with the diagnostics so that they aren't rejected
immediately as before.  As the spec generally requires as before that the
iteration variable initializer and bound in the comparison as invariant
vs. the outermost loop, and just add some exceptional forms that can violate
that, we need to avoid folding the expressions until we can detect them and
in order to avoid folding it later on, I chose to use a TREE_VEC in those
expressions to hold the var_outer * expr1 + expr2 triplet, the patch adds
pretty-printing of that, gimplification etc. and just sorry_at during
omp expansion for now.

The next step will be to implement the different cases of that one by one.

2020-06-16  Jakub Jelinek  <jakub@redhat.com>

gcc/
* tree.h (OMP_FOR_NON_RECTANGULAR): Define.
* gimplify.c (gimplify_omp_for): Diagnose schedule, ordered
or dist_schedule clause on non-rectangular loops.  Handle
gimplification of non-rectangular lb/b expressions.  When changing
iteration variable, adjust also non-rectangular lb/b expressions
referencing that.
* omp-general.h (struct omp_for_data_loop): Add m1, m2 and outer
members.
(struct omp_for_data): Add non_rect member.
* omp-general.c (omp_extract_for_data): Handle non-rectangular
loops.  Fill in non_rect, m1, m2 and outer.
* omp-low.c (lower_omp_for): Handle non-rectangular lb/b expressions.
* omp-expand.c (expand_omp_for): Emit sorry_at for unsupported
non-rectangular loop cases and assert for cases that can't be
non-rectangular.
* tree-pretty-print.c (dump_mem_ref): Formatting fix.
(dump_omp_loop_non_rect_expr): New function.
(dump_generic_node): Handle non-rectangular OpenMP loops.
* tree-pretty-print.h (dump_omp_loop_non_rect_expr): Declare.
* gimple-pretty-print.c (dump_gimple_omp_for): Handle non-rectangular
OpenMP loops.
gcc/c-family/
* c-common.h (c_omp_check_loop_iv_exprs): Add an int argument.
* c-omp.c (struct c_omp_check_loop_iv_data): Add maybe_nonrect and
idx members.
(c_omp_is_loop_iterator): New function.
(c_omp_check_loop_iv_r): Use it.  Add support for silent scanning
if outer loop iterator is present.  Perform duplicate checking through
hash_set in the function rather than expecting caller to do that.
Pass NULL instead of d->ppset to walk_tree_1.
(c_omp_check_nonrect_loop_iv): New function.
(c_omp_check_loop_iv): Use it.  Fill in new members, allow
non-rectangular loop forms, diagnose multiple associated loops with
the same iterator.  Pass NULL instead of &pset to walk_tree_1.
(c_omp_check_loop_iv_exprs): Likewise.
gcc/c/
* c-parser.c (c_parser_expr_no_commas): Save, clear and restore
c_in_omp_for.
(c_parser_omp_for_loop): Set c_in_omp_for around some calls to avoid
premature c_fully_fold.  Defer explicit c_fully_fold calls to after
c_finish_omp_for.
* c-tree.h (c_in_omp_for): Declare.
* c-typeck.c (c_in_omp_for): Define.
(build_modify_expr): Avoid c_fully_fold if c_in_omp_for.
(digest_init): Likewise.
(build_binary_op): Likewise.
gcc/cp/
* semantics.c (handle_omp_for_class_iterator): Adjust
c_omp_check_loop_iv_exprs caller.
(finish_omp_for): Likewise.  Don't call fold_build_cleanup_point_expr
before calling c_finish_omp_for and c_omp_check_loop_iv, move it
after those calls.
* pt.c (tsubst_omp_for_iterator): Handle non-rectangular loops.
gcc/testsuite/
* c-c++-common/gomp/loop-6.c: New test.
* gcc.dg/gomp/loop-1.c: Don't expect diagnostics on valid
non-rectangular loops.
* gcc.dg/gomp/loop-2.c: New test.
* g++.dg/gomp/loop-1.C: Don't expect diagnostics on valid
non-rectangular loops.
* g++.dg/gomp/loop-2.C: Likewise.
* g++.dg/gomp/loop-5.C: New test.
* g++.dg/gomp/loop-6.C: New test.

(cherry picked from commit 1160ec9a141faf1c4c0496c7412c8febeb623962)

4 years agoEnable gimplify GOMP_MAP_STRUCT handling of (COMPONENT_REF (INDIRECT_REF ...)) map...
Chung-Lin Tang [Mon, 8 Feb 2021 15:53:55 +0000 (07:53 -0800)] 
Enable gimplify GOMP_MAP_STRUCT handling of (COMPONENT_REF (INDIRECT_REF ...)) map clauses.

This patch tries to allow map(A->ptr) to be properly handled the same way as
map(B.ptr) expressions. map(struct:*A) clauses are now produced during
gimplify.

This patch, as of time of commit, is only pushed to devel/omp/gcc-10, not yet
submitted as mainline patch to upstream.

2021-02-08  Chung-Lin Tang  <cltang@codesourcery.com>

gcc/ChangeLog:

* gimplify.c ("tree-hash-traits.h"): Add include.
(gimplify_scan_omp_clauses): Change struct_map_to_clause to type
hash_map<tree_operand, tree> *. Adjust struct map handling to handle
cases of *A and A->B expressions.
(gimplify_adjust_omp_clauses): Move GOMP_MAP_STRUCT removal code for
exit data directives code to earlier position.

gcc/testsuite/ChangeLog:

* g++.dg/gomp/target-3.C: Adjust testcase gimple scanning.
* g++.dg/gomp/target-this-2.C: Likewise.
* g++.dg/gomp/target-this-3.C: Likewise.
* g++.dg/gomp/target-this-4.C: Likewise.

libgomp/ChangeLog:

* testsuite/libgomp.c++/target-23.C: New testcase.

4 years agoOpenMP 5.0: requires directive
Chung-Lin Tang [Tue, 2 Feb 2021 12:34:01 +0000 (20:34 +0800)] 
OpenMP 5.0: requires directive

This is a merge of:
https://gcc.gnu.org/pipermail/gcc-patches/2021-January/563393.html

This patch completes more of the reverse_offload, unified_address, and
unified_shared_memory clauses for the OpenMP 5.0 requires directive,
including runtime verification of the offload target.
(currently no offload devices actually support above features, only
warning messages are emitted)

This may possibly reverted/updated when a final patch is approved
for mainline.

2021-02-02  Chung-Lin Tang  <cltang@codesourcery.com>

gcc/c/ChangeLog:

* c-parser.c (c_parser_declaration_or_fndef): Set
OMP_REQUIRES_TARGET_USED in omp_requires_mask if function has
"omp declare target" attribute.
(c_parser_omp_target_data): Set    OMP_REQUIRES_TARGET_USED in
omp_requires_mask.
(c_parser_omp_target_enter_data): Likewise.
(c_parser_omp_target_exit_data): Likewise.
(c_parser_omp_requires): Adjust to only mention "not implemented yet"
for OMP_REQUIRES_DYNAMIC_ALLOCATORS.

gcc/cp/ChangeLog:

* parser.c (cp_parser_simple_declaration): Set
OMP_REQUIRES_TARGET_USED in omp_requires_mask if function has
"omp declare target" attribute.
(cp_parser_omp_target_data): Set OMP_REQUIRES_TARGET_USED in
omp_requires_mask.
(cp_parser_omp_target_enter_data): Likewise.
(cp_parser_omp_target_exit_data): Likewise.
(cp_parser_omp_requires): Adjust to only mention "not implemented yet"
for OMP_REQUIRES_DYNAMIC_ALLOCATORS.

gcc/fortran/ChangeLog:

* openmp.c (gfc_check_omp_requires): Fix REVERSE_OFFLOAD typo.
(gfc_match_omp_requires): Adjust to only mention "not implemented yet"
for OMP_REQUIRES_DYNAMIC_ALLOCATORS.
* parse.c ("tree.h"): Add include.
("omp-general.h"): Likewise.
(gfc_parse_file): Add code to merge omp_requires to omp_requires_mask.

gcc/ChangeLog:

* omp-offload.c (omp_finish_file): Add code to reate OpenMP requires
mask variable in .gnu.gomp_requires section if needed.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/requires-4.c: Remove prune of "not supported yet".
* gcc/testsuite/gfortran.dg/gomp/requires-4.f90: Fix REVERSE_OFFLOAD typo.
* gcc/testsuite/gfortran.dg/gomp/requires-8.f90: Likewise.

include/ChangeLog:

* gomp-constants.h (GOMP_REQUIRES_UNIFIED_ADDRESS): New symbol.
(GOMP_REQUIRES_UNIFIED_SHARED_MEMORY): Likewise.
(GOMP_REQUIRES_REVERSE_OFFLOAD): Likewise.

libgcc/ChangeLog:

* offloadstuff.c (__requires_mask_table): New symbol to mark start of
.gnu.gomp_requires section.
(__requires_mask_table_end): New symbol to mark end of
.gnu.gomp_requires section.

libgomp/ChangeLog:

* libgomp-plugin.h (GOMP_OFFLOAD_supported_features): New declaration.
* libgomp.h (struct gomp_device_descr): New 'supported_features_func'
plugin hook field.
* oacc-host.c (host_supported_features): New host hook function.
(host_dispatch): Initialize 'supported_features_func' host hook.
* plugin/plugin-gcn.c (GOMP_OFFLOAD_supported_features): New function.
* plugin/plugin-nvptx.c (GOMP_OFFLOAD_supported_features): Likewise.
* target.c (<stdio.h>): Add include of standard header.
(gomp_requires_mask): New static variable.
(__requires_mask_table): New declaration.
(__requires_mask_table_end): Likewise.
(gomp_load_plugin_for_device): Add loading of 'supported_features' hook.
(gomp_target_init): Add code to summarize .gnu._gomp_requires section
mask values, emit error if inconsistency found.

* testsuite/libgomp.c-c++-common/requires-1.c: New test.
* testsuite/libgomp.c-c++-common/requires-1-aux.c: New file linked with
above test.
* testsuite/libgomp.c-c++-common/requires-2.c: New test.
* testsuite/libgomp.c-c++-common/requires-2-aux.c: New file linked with
above test.

liboffloadmic/ChangeLog:

* plugin/libgomp-plugin-intelmic.cpp (GOMP_OFFLOAD_supported_features):
New function.

4 years agoOpenMP 5.0: map this[:1] in C++ non-static member functions (PR 92120)
Chung-Lin Tang [Tue, 2 Feb 2021 12:31:37 +0000 (20:31 +0800)] 
OpenMP 5.0: map this[:1] in C++ non-static member functions (PR 92120)

This is a merge of:
https://gcc.gnu.org/pipermail/gcc-patches/2020-November/558975.html

This patch creates automatic mapping of map(this[:1]) and pointer members
as zero-length array sections, as specified by the OpenMP 5.0 specification.

This may possibly reverted/updated when a final patch is approved
for mainline.

2021-02-02  Chung-Lin Tang  <cltang@codesourcery.com>

PR middle-end/92120

gcc/cp/ChangeLog:

* cp-tree.h (finish_omp_target): New declaration.
(set_omp_target_this_expr): Likewise.
* lambda.c (lambda_expr_this_capture): Add call to
set_omp_target_this_expr.
* parser.c (cp_parser_omp_target): Factor out code, change to call
finish_omp_target, add re-initing call to set_omp_target_this_expr.
* semantics.c (omp_target_this_expr): New static variable.
(omp_target_ptr_members_accessed): New static hash_map for tracking
accessed non-static pointer-type members.
(finish_non_static_data_member): Add call to set_omp_target_this_expr.
Add recording of non-static pointer-type members access.
(finish_this_expr): Add call to set_omp_target_this_expr.
(set_omp_target_this_expr): New function to set omp_target_this_expr.
(finish_omp_target): New function with code merged from
cp_parser_omp_target, plus code to implement this[:1] and __closure map
clauses for OpenMP.

(handle_omp_array_sections_1): Move code to peel of '*' for
reference-based COMPONENT_REFs before FIELD_DECL transforming.
(finish_omp_clauses): Handle 'A->member' case in map clauses.

gcc/ChangeLog:

* omp-low.c (lower_omp_target):
Handle GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION, and
GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION map kinds.
* tree-pretty-print.c (dump_omp_clause): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/gomp/target-this-1.C: New testcase.
* g++.dg/gomp/target-this-2.C: New testcase.
* g++.dg/gomp/target-this-3.C: New testcase.
* g++.dg/gomp/target-this-4.C: New testcase.

include/ChangeLog:

* gomp-constants.h (enum gomp_map_kind):
Add GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION, and
GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION map kinds.
(GOMP_MAP_POINTER_P):
Include GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION.

libgomp/ChangeLog:

* libgomp.h (gomp_attach_pointer): Add bool parameter.
* oacc-mem.c (acc_attach_async): Update call to gomp_attach_pointer.
(goacc_enter_data_internal): Likewise.
* target.c (gomp_map_vars_existing): Update assert condition to
include GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION.
(gomp_map_pointer): Add 'bool allow_zero_length_array_sections'
parameter, add support for mapping a pointer with NULL target.
(gomp_attach_pointer): Add 'bool allow_zero_length_array_sections'
parameter, add support for attaching a pointer with NULL target.
(gomp_map_vars_internal): Update calls to gomp_map_pointer and
gomp_attach_pointer, add handling for
GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION, and
GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION cases.
* testsuite/libgomp.c++/target-this-1.C: New testcase.
* testsuite/libgomp.c++/target-this-2.C: New testcase.
* testsuite/libgomp.c++/target-this-3.C: New testcase.
* testsuite/libgomp.c++/target-this-4.C: New testcase.

4 years agoOpenMP 5.0: Allow multiple clauses mapping same variable
Chung-Lin Tang [Mon, 1 Feb 2021 11:16:47 +0000 (03:16 -0800)] 
OpenMP 5.0: Allow multiple clauses mapping same variable

This is a merge of:
https://gcc.gnu.org/pipermail/gcc-patches/2020-December/562081.html

This patch now allows multiple clauses on the same construct to map
the same variable, which was not valid in OpenMP 4.5, but now allowed
in 5.0.

This may possibly reverted/updated when a final patch is approved
for mainline.

2021-02-01  Chung-Lin Tang  <cltang@codesourcery.com>

gcc/c/ChangeLog:

* c-typeck.c (c_finish_omp_clauses): Adjust to allow duplicate
mapped variables for OpenMP.

gcc/cp/ChangeLog:

* semantics.c (finish_omp_clauses):  Adjust to allow duplicate
mapped variables for OpenMP.

gcc/ChangeLog:

* omp-low.c (install_parm_decl): Add new 'tree key_expr' parameter.
Use key_expr as splay-tree key instead of var itself.
(install_var_field): Add new 'tree key_expr = NULL_TREE'
default parameter. Set splay-tree lookup key to key_expr instead of
var if key_expr is non-NULL. Adjust call to install_parm_decl.
Update comments.
(scan_sharing_clauses): Use clause tree expression as splay-tree key
for map/to/from and OpenACC firstprivate cases when installing the
variable field into the send/receive record type.
(maybe_lookup_field_in_outer_ctx): Add code to search through
construct clauses instead of entirely based on splay-tree lookup.
(lower_oacc_reductions): Adjust to find map-clause of reduction
variable, then create receiver-ref.
(lower_omp_target): Adjust to lookup var field using clause expression.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/clauses-2.c: Adjust testcase.

4 years agoOpenMP 5.0 Structure element mapping
Chung-Lin Tang [Wed, 27 Jan 2021 13:35:43 +0000 (21:35 +0800)] 
OpenMP 5.0 Structure element mapping

This is a merge of:
https://gcc.gnu.org/pipermail/gcc-patches/2020-December/561139.html

This patch implements the changes to the behavior of target mapping structure
elements, as specified in OpenMP 5.0.

This may possibly reverted/updated when a final patch is approved
for mainline.

libgomp/ChangeLog:

* hashtab.h (htab_clear): New function with initialization code
factored out from...
(htab_create): ...here, adjust to use htab_clear function.

* libgomp.h (REFCOUNT_SPECIAL): New symbol to denote range of
special refcount values, add comments.
(REFCOUNT_INFINITY): Adjust definition to use REFCOUNT_SPECIAL.
(REFCOUNT_LINK): Likewise.
(REFCOUNT_STRUCTELEM): New special refcount range for structure
element siblings.
(REFCOUNT_STRUCTELEM_P): Macro for testing for structure element
sibling maps.
(REFCOUNT_STRUCTELEM_FLAG_FIRST): Flag to indicate first sibling.
(REFCOUNT_STRUCTELEM_FLAG_LAST):  Flag to indicate last sibling.
(REFCOUNT_STRUCTELEM_FIRST_P): Macro to test _FIRST flag.
(REFCOUNT_STRUCTELEM_LAST_P): Macro to test _LAST flag.
(struct splay_tree_key_s): Add structelem_refcount and
structelem_refcount_ptr fields into a union with dynamic_refcount.
Add comments.
(gomp_map_vars): Delete declaration.
(gomp_map_vars_async): Likewise.
(gomp_unmap_vars): Likewise.
(gomp_unmap_vars_async): Likewise.
(goacc_map_vars): New declaration.
(goacc_unmap_vars): Likewise.

* oacc-mem.c (acc_map_data): Adjust to use goacc_map_vars.
(goacc_enter_datum): Likewise.
(goacc_enter_data_internal): Likewise.
* oacc-parallel.c (GOACC_parallel_keyed): Adjust to use goacc_map_vars
and goacc_unmap_vars.
(GOACC_data_start): Adjust to use goacc_map_vars.
(GOACC_data_end): Adjust to use goacc_unmap_vars.

* target.c (hash_entry_type): New typedef.
(htab_alloc): New function hook for hashtab.h.
(htab_free): Likewise.
(htab_hash): Likewise.
(htab_eq): Likewise.
(hashtab.h): Add file include.
(gomp_increment_refcount): New function.
(gomp_decrement_refcount): Likewise.
(gomp_map_vars_existing): Add refcount_set parameter, adjust to use
gomp_increment_refcount.
(gomp_map_fields_existing): Add refcount_set parameter, adjust calls
to gomp_map_vars_existing.

(gomp_map_vars_internal): Add refcount_set parameter, add local openmp_p
variable to guard OpenMP specific paths, adjust calls to
gomp_map_vars_existing, add structure element sibling splay_tree_key
sequence creation code, adjust Fortran map case to avoid increment
under OpenMP.
(gomp_map_vars): Adjust to static, add refcount_set parameter, manage
local refcount_set if caller passed in NULL, adjust call to
gomp_map_vars_internal.
(gomp_map_vars_async): Adjust and rename into...
(goacc_map_vars): ...this new function, adjust call to
gomp_map_vars_internal.

(gomp_remove_splay_tree_key): New function with code factored out from
gomp_remove_var_internal.
(gomp_remove_var_internal): Add code to handle removing multiple
splay_tree_key sequence for structure elements, adjust code to use
gomp_remove_splay_tree_key for splay-tree key removal.
(gomp_unmap_vars_internal): Add refcount_set parameter, adjust to use
gomp_decrement_refcount.
(gomp_unmap_vars): Adjust to static, add refcount_set parameter, manage
local refcount_set if caller passed in NULL, adjust call to
gomp_unmap_vars_internal.
(gomp_unmap_vars_async): Adjust and rename into...
(goacc_unmap_vars): ...this new function, adjust call to
gomp_unmap_vars_internal.
(GOMP_target): Manage refcount_set and adjust calls to gomp_map_vars and
gomp_unmap_vars.
(GOMP_target_ext): Likewise.
(gomp_target_data_fallback): Adjust call to gomp_map_vars.
(GOMP_target_data): Likewise.
(GOMP_target_data_ext): Likewise.
(GOMP_target_end_data): Adjust call to gomp_unmap_vars.
(gomp_exit_data): Add refcount_set parameter, adjust to use
gomp_decrement_refcount, adjust to queue splay-tree keys for removal
after main loop.
(GOMP_target_enter_exit_data): Manage refcount_set and adjust calls to
gomp_map_vars and gomp_exit_data.
(gomp_target_task_fn): Likewise.

* testsuite/libgomp.c-c++-common/refcount-1.c: New testcase.
* testsuite/libgomp.c-c++-common/struct-elem-1.c: New testcase.
* testsuite/libgomp.c-c++-common/struct-elem-2.c: New testcase.
* testsuite/libgomp.c-c++-common/struct-elem-3.c: New testcase.
* testsuite/libgomp.c-c++-common/struct-elem-4.c: New testcase.
* testsuite/libgomp.c-c++-common/struct-elem-5.c: New testcase.

4 years agoamdgcn: Allow V64DFmode min/max reductions
Andrew Stubbs [Mon, 9 Nov 2020 17:42:34 +0000 (17:42 +0000)] 
amdgcn: Allow V64DFmode min/max reductions

I don't know why these were disabled. There're no direct min/max DPP
instructions for this mode, but the "use moves" strategy works fine.

gcc/ChangeLog:

* config/gcn/gcn.c (gcn_expand_reduc_scalar): Use move instructions
for V64DFmode min/max reductions.

Backport from d9f50366102a8ca3521e4854f7716bd013c8ea0a.

4 years agoopenmp: Fix intermittent hanging of task-detach-6 libgomp tests [PR98738]
Kwok Cheung Yeung [Thu, 21 Jan 2021 13:38:47 +0000 (05:38 -0800)] 
openmp: Fix intermittent hanging of task-detach-6 libgomp tests [PR98738]

This adds support for the task detach clause to taskwait, and fixes a
number of problems related to semaphores that may lead to a hang in
some circumstances.

2021-01-21  Kwok Cheung Yeung  <kcy@codesourcery.com>

libgomp/

PR libgomp/98738
* libgomp.h (enum gomp_task_kind): Add GOMP_TASK_DETACHED.
* task.c (task_fulfilled_p): Check detach field as well.
(GOMP_task): Add thread to debug messages.  Use address of task as
the event handle.
(gomp_barrier_handle_tasks): Fix indentation.  Use address of task
as event handle. Set kind of suspended detach task to
GOMP_TASK_DETACHED and decrement task_running_count.  Move
finish_cancelled block out of else branch.  Skip decrement of
task_running_count if task kind is GOMP_TASK_DETACHED.
(GOMP_taskwait): Finish fulfilled detach tasks.  Update comment.
Queue detach tasks that have not been fulfilled.
(omp_fulfill_event): Use address of task as event handle.  Post
to taskwait_sem and taskgroup_sem if necessary.  Check
task_running_count before calling gomp_team_barrier_wake.
* testsuite/libgomp.c-c++-common/task-detach-5.c (main): Change
data-sharing of detach events on enclosing parallel to private.
* testsuite/libgomp.c-c++-common/task-detach-6.c (main): Likewise.
* testsuite/libgomp.fortran/task-detach-5.f90 (task_detach_5):
Likewise.
* testsuite/libgomp.fortran/task-detach-6.f90 (task_detach_6):
Likewise.

4 years agolibgomp: Fix up GOMP_task on s390x
Jakub Jelinek [Wed, 20 Jan 2021 21:09:22 +0000 (22:09 +0100)] 
libgomp: Fix up GOMP_task on s390x

On Wed, Jan 20, 2021 at 05:04:39PM +0100, Florian Weimer wrote:
> Sorry, this appears to cause OpenMP task state corruption in RPM.  We
> have only seen this on s390x.

Haven't actually verified it, but my suspection is that this is a caller
stack corruption.

We play with fire with the GOMP_task API/ABI extensions, the GOMP_task
function used to be:
void
GOMP_task (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *),
           long arg_size, long arg_align, bool if_clause, unsigned flags);
and later:
void
GOMP_task (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *),
           long arg_size, long arg_align, bool if_clause, unsigned flags,
           void **depend);
and later:
void
GOMP_task (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *),
           long arg_size, long arg_align, bool if_clause, unsigned flags,
           void **depend, int priority);
and now:
void
GOMP_task (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *),
           long arg_size, long arg_align, bool if_clause, unsigned flags,
           void **depend, int priority, void *detach)
and which of those depend, priority and detach argument is present depends
on the bits in flags.
I'm afraid the compiler just decided to spill the detach = NULL store in
  if ((flags & GOMP_TASK_FLAG_DETACH) == 0)
    detach = NULL;
on s390x into the argument stack slot.  Not a problem if the caller passes
all those 10 arguments, but if not, can clobber random stack location.

This hack should fix it up.  Priority doesn't need changing, but I've
changed it anyway just to be safe.  With the patch none of the 3 arguments
are ever modified, so I'd hope gcc doesn't decide to spill something
unrelated there.

2021-01-20  Jakub Jelinek  <jakub@redhat.com>

* task.c (GOMP_task): Rename priority argument to priority_arg,
add priority automatic variable and modify that variable.  Instead of
clearing detach argument when GOMP_TASK_FLAG_DETACH bit is not set,
check flags for that bit.

(cherry picked from commit 0bb27b81a762d3c607bd25409337c749f836c0cd)

4 years agoFix gfortran.dg/gomp/task-detach-1.f90 for non 64bit pointers
Tobias Burnus [Wed, 20 Jan 2021 10:27:26 +0000 (11:27 +0100)] 
Fix gfortran.dg/gomp/task-detach-1.f90 for non 64bit pointers

gcc/testsuite/ChangeLog:

PR fortran/98763
* gfortran.dg/gomp/task-detach-1.f90: Use integer(1) to avoid
missing diagnostic issues with c_intptr_t == default integer kind.

(cherry picked from commit a95538b6c5a9ea480e341da9ca8fbf201417dba5)

4 years agoopenmp: Don't ICE on detach clause with erroneous decl [PR98742]
Jakub Jelinek [Wed, 20 Jan 2021 07:35:20 +0000 (08:35 +0100)] 
openmp: Don't ICE on detach clause with erroneous decl [PR98742]

Similarly to how we handle erroneous operands to e.g. allocate clause,
this change just removes those clauses instead of accessing TYPE_MAIN_VARIANT
of its type, which doesn't work on error_mark_node.  Also, just for good
measure, bails out if TYPE_NAME is NULL.

2021-01-20  Jakub Jelinek  <jakub@redhat.com>

PR c++/98742
* semantics.c (finish_omp_clauses) <case OMP_CLAUSE_DETACH>: If
error_operand_p, remove clause without further checking.  Check
for non-NULL TYPE_NAME.

* c-c++-common/gomp/task-detach-2.c: New test.

(cherry picked from commit 7ab1abf3b82a3bcfff9b7bc596166fef6a0d83ab)

4 years agoopenmp: Don't optimize shared to firstprivate on task with depend clause
Jakub Jelinek [Fri, 18 Dec 2020 20:43:20 +0000 (21:43 +0100)] 
openmp: Don't optimize shared to firstprivate on task with depend clause

The attached testcase is miscompiled, because we optimize shared clauses
to firstprivate when task body can't modify the variable even when the
task has depend clause.  That is wrong, because firstprivate means the
variable will be copied immediately when the task is created, while with
depend clause some other task might change it later before the dependencies
are satisfied and the task should observe the value only after the change.

2020-12-18  Jakub Jelinek  <jakub@redhat.com>

* gimplify.c (struct gimplify_omp_ctx): Add has_depend member.
(gimplify_scan_omp_clauses): Set it to true if OMP_CLAUSE_DEPEND
appears on OMP_TASK.
(gimplify_adjust_omp_clauses_1, gimplify_adjust_omp_clauses): Force
GOVD_WRITTEN on shared variables if task construct has depend clause.

* testsuite/libgomp.c/task-6.c: New test.

(cherry picked from commit 8b60459465252c7d47b58abf83fae2aa84915b03)

4 years agoRTEMS: Fix libgomp build
Sebastian Huber [Mon, 18 Jan 2021 06:23:46 +0000 (07:23 +0100)] 
RTEMS: Fix libgomp build

libgomp/

* config/rtems/sem.h (gomp_sem_getcount): New function.

(cherry picked from commit 0f951b3dd34b355579b4c9a9e287d32ac771bc67)

4 years agolibgomp: Don't access gomp_sem_t as int using atomics unconditionally
Jakub Jelinek [Mon, 18 Jan 2021 06:18:46 +0000 (07:18 +0100)] 
libgomp: Don't access gomp_sem_t as int using atomics unconditionally

This patch introduces gomp_sem_getcount wrapper, which uses sem_getvalue
for POSIX and atomic loads for linux futex and accel.  rtems for now
remains broken.

2021-01-18  Jakub Jelinek  <jakub@redhat.com>

* config/linux/sem.h (gomp_sem_getcount): New function.
* config/posix/sem.h (gomp_sem_getcount): New function.
* config/posix/sem.c (gomp_sem_getcount): New function.
* config/accel/sem.h (gomp_sem_getcount): New function.
* task.c (task_fulfilled_p): Use gomp_sem_getcount.
(omp_fulfill_event): Likewise.

(cherry picked from commit d3b41bde961713ff4af7e18011126434c497edba)

4 years agoopenmp: Add support for the OpenMP 5.0 task detach clause
Kwok Cheung Yeung [Sat, 16 Jan 2021 20:58:13 +0000 (12:58 -0800)] 
openmp: Add support for the OpenMP 5.0 task detach clause

2021-01-16  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/
* builtin-types.def
(BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT): Rename
to...
(BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT_PTR):
...this.  Add extra argument.
* gimplify.c (omp_default_clause): Ensure that event handle is
firstprivate in a task region.
(gimplify_scan_omp_clauses): Handle OMP_CLAUSE_DETACH.
(gimplify_adjust_omp_clauses): Likewise.
* omp-builtins.def (BUILT_IN_GOMP_TASK): Change function type to
BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT_PTR.
* omp-expand.c (expand_task_call): Add GOMP_TASK_FLAG_DETACH to flags
if detach clause specified.  Add detach argument when generating
call to GOMP_task.
* omp-low.c (scan_sharing_clauses): Setup data environment for detach
clause.
(finish_taskreg_scan): Move field for variable containing the event
handle to the front of the struct.
* tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_DETACH.  Fix
ordering.
* tree-nested.c (convert_nonlocal_omp_clauses): Handle
OMP_CLAUSE_DETACH clause.
(convert_local_omp_clauses): Handle OMP_CLAUSE_DETACH clause.
* tree-pretty-print.c (dump_omp_clause): Handle OMP_CLAUSE_DETACH.
* tree.c (omp_clause_num_ops): Add entry for OMP_CLAUSE_DETACH.
Fix ordering.
(omp_clause_code_name): Add entry for OMP_CLAUSE_DETACH.  Fix
ordering.
(walk_tree_1): Handle OMP_CLAUSE_DETACH.

gcc/c-family/
* c-pragma.h (pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_DETACH.
Redefine PRAGMA_OACC_CLAUSE_DETACH.

gcc/c/
* c-parser.c (c_parser_omp_clause_detach): New.
(c_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_DETACH clause.
(OMP_TASK_CLAUSE_MASK): Add mask for PRAGMA_OMP_CLAUSE_DETACH.
* c-typeck.c (c_finish_omp_clauses): Handle PRAGMA_OMP_CLAUSE_DETACH
clause.  Prevent use of detach with mergeable and overriding the
data sharing mode of the event handle.

gcc/cp/
* parser.c (cp_parser_omp_clause_detach): New.
(cp_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_DETACH.
(OMP_TASK_CLAUSE_MASK): Add mask for PRAGMA_OMP_CLAUSE_DETACH.
* pt.c (tsubst_omp_clauses): Handle OMP_CLAUSE_DETACH clause.
* semantics.c (finish_omp_clauses): Handle OMP_CLAUSE_DETACH clause.
Prevent use of detach with mergeable and overriding the data sharing
mode of the event handle.

gcc/fortran/
* dump-parse-tree.c (show_omp_clauses): Handle detach clause.
* frontend-passes.c (gfc_code_walker): Walk detach expression.
* gfortran.h (struct gfc_omp_clauses): Add detach field.
(gfc_c_intptr_kind): New.
* openmp.c (gfc_free_omp_clauses): Free detach clause.
(gfc_match_omp_detach): New.
(enum omp_mask1): Add OMP_CLAUSE_DETACH.
(enum omp_mask2): Remove OMP_CLAUSE_DETACH.
(gfc_match_omp_clauses): Handle OMP_CLAUSE_DETACH for OpenMP.
(OMP_TASK_CLAUSES): Add OMP_CLAUSE_DETACH.
(resolve_omp_clauses): Prevent use of detach with mergeable and
overriding the data sharing mode of the event handle.
* trans-openmp.c (gfc_trans_omp_clauses): Handle detach clause.
* trans-types.c (gfc_c_intptr_kind): New.
(gfc_init_kinds): Initialize gfc_c_intptr_kind.
* types.def
(BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT): Rename
to...
(BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT_PTR):
...this.  Add extra argument.

gcc/testsuite/
* c-c++-common/gomp/task-detach-1.c: New.
* g++.dg/gomp/task-detach-1.C: New.
* gcc.dg/gomp/task-detach-1.c: New.
* gfortran.dg/gomp/task-detach-1.f90: New.

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

libgomp/
* fortran.c (omp_fulfill_event_): New.
* libgomp.h (struct gomp_task): Add detach and completion_sem fields.
(struct gomp_team): Add task_detach_queue and task_detach_count
fields.
* libgomp.map (OMP_5.0.1): Add omp_fulfill_event and omp_fulfill_event_.
* libgomp_g.h (GOMP_task): Add extra argument.
* omp.h.in (enum omp_event_handle_t): New.
(omp_fulfill_event): New.
* omp_lib.f90.in (omp_event_handle_kind): New.
(omp_fulfill_event): New.
* omp_lib.h.in (omp_event_handle_kind): New.
(omp_fulfill_event): Declare.
* priority_queue.c (priority_tree_find): New.
(priority_list_find): New.
(priority_queue_find): New.
* priority_queue.h (priority_queue_predicate): New.
(priority_queue_find): New.
* task.c (gomp_init_task): Initialize detach field.
(task_fulfilled_p): New.
(GOMP_task): Add detach argument.  Ignore detach argument if
GOMP_TASK_FLAG_DETACH not set in flags.  Initialize completion_sem
field. Copy address of completion_sem into detach argument and
into the start of the data record.  Wait for detach event if task
not deferred.
(gomp_barrier_handle_tasks): Queue tasks with unfulfilled events.
Remove completed tasks and requeue dependent tasks.
(omp_fulfill_event): New.
* team.c (gomp_new_team): Initialize task_detach_queue and
task_detach_count fields.
(free_team): Free task_detach_queue field.
* testsuite/libgomp.c-c++-common/task-detach-1.c: New testcase.
* testsuite/libgomp.c-c++-common/task-detach-2.c: New testcase.
* testsuite/libgomp.c-c++-common/task-detach-3.c: New testcase.
* testsuite/libgomp.c-c++-common/task-detach-4.c: New testcase.
* testsuite/libgomp.c-c++-common/task-detach-5.c: New testcase.
* testsuite/libgomp.c-c++-common/task-detach-6.c: New testcase.
* testsuite/libgomp.fortran/task-detach-1.f90: New testcase.
* testsuite/libgomp.fortran/task-detach-2.f90: New testcase.
* testsuite/libgomp.fortran/task-detach-3.f90: New testcase.
* testsuite/libgomp.fortran/task-detach-4.f90: New testcase.
* testsuite/libgomp.fortran/task-detach-5.f90: New testcase.
* testsuite/libgomp.fortran/task-detach-6.f90: New testcase.

(cherry picked from commit a6d22fb21c6f1ad7e8b6b722bfc0e7e11f50cb92)

4 years agoTarget mapping C++ members inside member functions
Chung-Lin Tang [Thu, 21 Jan 2021 15:04:26 +0000 (23:04 +0800)] 
Target mapping C++ members inside member functions

This is a merge of:
https://gcc.gnu.org/pipermail/gcc-patches/2020-December/562467.html

This patch fixes some problems with target mapping when inside
C++ member functions:

1. Allow deref '->' in map clauses.
2. Allow this[X] in map clauses.
3. Create map(this->member) from map(member), when encountering
   member's FIELD_DECL.

This may possibly reverted/updated when a final patch is approved
for mainline.

gcc/cp/ChangeLog:
* parser.c (cp_parser_omp_clause_map): Adjust call to
cp_parser_omp_var_list_no_open to set 'allow_deref' argument to true.
* semantics.c (handle_omp_array_sections_1): Add handling to create
'this->member' from 'member' FIELD_DECL.
(finish_omp_clauses): Likewise. Adjust to allow 'this[]' in OpenMP
map clauses.

gcc/testsuite/ChangeLog:
* g++.dg/gomp/target-3.C: New test.
* g++.dg/gomp/this-2.C: Adjust testcase.

4 years agoCorrect fix offload dwarf info
Andrew Stubbs [Sat, 16 Jan 2021 15:18:07 +0000 (15:18 +0000)] 
Correct fix offload dwarf info

The previous patch wasn't quite right, apparently.  Somehow the behaviour
changed after another clean build?  This tweak fixes it.

This patch should be squashed with fdcb23540a2 to go to mainline.

gcc/ChangeLog:

* dwarf2out.c (gen_subprogram_die): Check offload attributes only.

4 years agoDWARF address space for variables
Andrew Stubbs [Fri, 15 Jan 2021 11:26:46 +0000 (11:26 +0000)] 
DWARF address space for variables

Add DWARF address class attributes for variables that exist outside the
generic address space.  In particular, this is the case for gang-private
variables in OpenACC offload kernels.

gcc/ChangeLog:

* dwarf2out.c (add_location_or_const_value_attribute): Set
DW_AT_address_class, if appropriate.

4 years agoamdgcn: DWARF address spaces
Andrew Stubbs [Wed, 7 Oct 2020 13:15:22 +0000 (14:15 +0100)] 
amdgcn: DWARF address spaces

Map GCN address spaces to the proposed DWARF address spaces defined by AMD.

gcc/ChangeLog:

* config/gcn/gcn.c: Include dwarf2.h.
(gcn_addr_space_debug): New function.
(TARGET_ADDR_SPACE_DEBUG): New hook.

4 years agoamdgcn: Fix DWARF variables with alloca
Andrew Stubbs [Fri, 8 Jan 2021 13:56:52 +0000 (13:56 +0000)] 
amdgcn: Fix DWARF variables with alloca

Require a frame pointer for entry functions that use alloca because it isn't
possible to encode the DWARF frame otherwise.  Adjust the CFA definition
expressions accordingly.

gcc/ChangeLog:

* config/gcn/gcn.c (gcn_expand_prologue): Use the frame pointer for
the DWARF CFA, if it exists.
(gcn_frame_pointer_rqd): Require a frame pointer for entry functions
that use alloca.

4 years agoFix offload dwarf info
Andrew Stubbs [Sun, 6 Dec 2020 19:23:55 +0000 (19:23 +0000)] 
Fix offload dwarf info

Add a notional code range to the notional parent function of offload kernel
functions.  This is enough to prevent GDB discarding them.

gcc/ChangeLog:

* dwarf2out.c (gen_subprogram_die): Add high/low_pc attributes for
parents of offload kernels.

4 years ago[og10] vect: Add target hook to prefer gather/scatter instructions
Julian Brown [Wed, 25 Nov 2020 17:08:01 +0000 (09:08 -0800)] 
[og10] vect: Add target hook to prefer gather/scatter instructions

For AMD GCN, the instructions available for loading/storing vectors are
always scatter/gather operations (i.e. there are separate addresses for
each vector lane), so the current heuristic to avoid gather/scatter
operations with too many elements in get_group_load_store_type is
counterproductive. Avoiding such operations in that function can
subsequently lead to a missed vectorization opportunity whereby later
analyses in the vectorizer try to use a very wide array type which is
not available on this target, and thus it bails out.

The attached patch adds a target hook to override the "single_element_p"
heuristic in the function as a target hook, and activates it for GCN. This
allows much better code to be generated for affected loops.

2021-01-13  Julian Brown  <julian@codesourcery.com>

gcc/
* doc/tm.texi.in (TARGET_VECTORIZE_PREFER_GATHER_SCATTER): Add
documentation hook.
* doc/tm.texi: Regenerate.
* target.def (prefer_gather_scatter): Add target hook under vectorizer.
* tree-vect-stmts.c (get_group_load_store_type): Optionally prefer
gather/scatter instructions to scalar/elementwise fallback.
* config/gcn/gcn.c (TARGET_VECTORIZE_PREFER_GATHER_SCATTER): Define
hook.

4 years ago[og10] openacc: Adjust loop lowering for AMD GCN
Julian Brown [Fri, 6 Nov 2020 23:17:29 +0000 (15:17 -0800)] 
[og10] openacc: Adjust loop lowering for AMD GCN

This patch adjusts OpenACC loop lowering in the AMD GCN target compiler
in such a way that the autovectorizer can vectorize the "vector" dimension
of those loops in more cases.

Rather than generating "SIMT" code that executes a scalar instruction
stream for each lane of a vector in lockstep, for GCN we model the GPU
like a typical CPU, with separate instructions to operate on scalar and
vector data. That means that unlike other offload targets, we rely on
the autovectorizer to handle the innermost OpenACC parallelism level,
which is "vector".

Because of this, the OpenACC builtin functions to return the current
vector lane and the vector width return 0 and 1 respectively, despite
the native vector width being 64 elements wide.

This allows generated code to work with our chosen compilation model,
but the way loops are lowered in omp-offload.c:oacc_xform_loop does not
understand the discrepancy between logical (OpenACC) and physical vector
sizes correctly. That means that if a loop is partitioned over e.g. the
worker AND vector dimensions, we actually lower with unit vector size --
meaning that if we then autovectorize, we end up trying to vectorize
over the "worker" dimension rather than the vector one! Then, because
the number of workers is not fixed at compile time, that means the
autovectorizer has a hard time analysing the loop and thus vectorization
often fails entirely.

We can fix this by deducing the true vector width in oacc_xform_loop,
and using that when we are on a "non-SIMT" offload target. We can then
rearrange how loops are lowered in that function so that the loop form
fed to the autovectorizer is more amenable to vectorization -- namely,
the innermost step is set to process each loop iteration sequentially.

For some benchmarks, allowing vectorization to succeed leads to quite
impressive performance improvements -- I've observed between 2.5x and
40x on one machine/GPU combination.

The low-level builtins available to user code (__builtin_goacc_parlevel_id
and __builtin_goacc_parlevel_size) continue to return 0/1 respectively
for the vector dimension for AMD GCN, even if their containing loop is
vectorized -- that's a quirk that we might possibly want to address at
some later date.

Only non-"chunking" loops are handled at present. "Chunking" loops are
still lowered as before.

2021-01-13  Julian Brown  <julian@codesourcery.com>

gcc/
* omp-offload.c (oacc_thread_numbers): Add VF_BY_VECTORIZER parameter.
Add overloaded wrapper for previous arguments & behaviour.
(oacc_xform_loop): Lower vector loops to iterate a multiple of
omp_max_vf times over contiguous steps on non-SIMT targets.

libgomp/testsuite/
* libgomp.oacc-c-c++-common/loop-gwv-1.c: Adjust for loop lowering
changes.
* libgomp.oacc-c-c++-common/loop-wv-1.c: Likewise.
* libgomp.oacc-c-c++-common/loop-red-gwv-1.c: Likewise.
* libgomp.oacc-c-c++-common/loop-red-wv-1.c: Likewise.
* libgomp.oacc-c-c++-common/routine-gwv-1.c: Likewise.
* libgomp.oacc-c-c++-common/routine-wv-1.c: Likewise.

4 years agoamdgcn: Remove dead code for fixed v0 register
Julian Brown [Wed, 25 Nov 2020 00:42:55 +0000 (16:42 -0800)] 
amdgcn: Remove dead code for fixed v0 register

This patch removes code to fix the v0 register in
gcn_conditional_register_usage that was missed out of the previous patch
removing the need for that:

  https://gcc.gnu.org/pipermail/gcc-patches/2019-November/534284.html

Backport from mainline:

2021-01-13  Julian Brown  <julian@codesourcery.com>

gcc/
* config/gcn/gcn.c (gcn_conditional_register_usage): Remove dead code
to fix v0 register.

(cherry picked from commit 7993fe1877a689463d8c71a0873e5cc8db080273)

4 years agoamdgcn: Fix exec register live-on-entry to BB in md-reorg
Julian Brown [Fri, 6 Nov 2020 22:53:29 +0000 (14:53 -0800)] 
amdgcn: Fix exec register live-on-entry to BB in md-reorg

This patch fixes a corner case in the AMD GCN md-reorg pass when the
EXEC register is live on entry to a BB, and could be clobbered by code
inserted by the pass before a use in (e.g.) a different BB.

Backport from mainline:

2021-01-13  Julian Brown  <julian@codesourcery.com>

gcc/
* config/gcn/gcn.c (gcn_md_reorg): Fix case where EXEC reg is live
on entry to a BB.

(cherry picked from commit 3df6fac0080468d1521775e82a5e060f0b1c78ca)

4 years agoamdgcn: Improve FP division accuracy
Julian Brown [Mon, 30 Nov 2020 19:10:04 +0000 (11:10 -0800)] 
amdgcn: Improve FP division accuracy

GCN has a reciprocal-approximation instruction but no
hardware divide. This patch adjusts the open-coded reciprocal
approximation/Newton-Raphson refinement steps to use fused multiply-add
instructions as is necessary to obtain a properly-rounded result, and
adds further refinement steps to correctly round the full division result.

The patterns in question are still guarded by a flag_reciprocal_math
condition, and do not yet support denormals.

Backport from mainline:

2021-01-13  Julian Brown  <julian@codesourcery.com>

gcc/
* config/gcn/gcn-valu.md (recip<mode>2<exec>, recip<mode>2): Use unspec
for reciprocal-approximation instructions.
(div<mode>3): Use fused multiply-accumulate operations for reciprocal
refinement and division result.
* config/gcn/gcn.md (UNSPEC_RCP): New unspec constant.

gcc/testsuite/
* gcc.target/gcn/fpdiv.c: New test.

(cherry picked from commit c8812bac8ee39f73ea881e4f6260acf5590b4190)

4 years agoamdgcn: Fix subdf3 pattern
Julian Brown [Mon, 30 Nov 2020 20:01:37 +0000 (12:01 -0800)] 
amdgcn: Fix subdf3 pattern

This patch fixes a typo in the subdf3 pattern that meant it had a
non-standard name and thus the compiler would emit a libcall rather than
the proper hardware instruction for DFmode subtraction.

Backport from mainline:

2021-01-13  Julian Brown  <julian@codesourcery.com>

gcc/
* config/gcn/gcn-valu.md (subdf): Rename to...
(subdf3): This.

(cherry picked from commit abb3993e49c04bd40e42f196f55785cc3fd81682)

4 years agonvptx: Cache stacks block for OpenMP kernel launch
Julian Brown [Wed, 21 Oct 2020 17:00:19 +0000 (10:00 -0700)] 
nvptx: Cache stacks block for OpenMP kernel launch

2021-01-05  Julian Brown  <julian@codesourcery.com>

libgomp/
* plugin/plugin-nvptx.c (SOFTSTACK_CACHE_LIMIT): New define.
(struct ptx_device): Add omp_stacks struct.
(nvptx_open_device): Initialise cached-stacks housekeeping info.
(nvptx_close_device): Free cached stacks block and mutex.
(nvptx_stacks_free): New function.
(nvptx_alloc): Add SUPPRESS_ERRORS parameter.
(GOMP_OFFLOAD_alloc): Add strategies for freeing soft-stacks block.
(nvptx_stacks_alloc): Rename to...
(nvptx_stacks_acquire): This.  Cache stacks block between runs if same
size or smaller is required.
(nvptx_stacks_free): Remove.
(GOMP_OFFLOAD_run): Call nvptx_stacks_acquire and lock stacks block
during kernel execution.

(cherry picked from commit 6b577a17b26347e78c8b9167f24fc5c9d9724270)

4 years agoFortran: Delay vtab generation until after parsing [PR92587]
Tobias Burnus [Tue, 5 Jan 2021 11:29:09 +0000 (12:29 +0100)] 
Fortran: Delay vtab generation until after parsing [PR92587]

Forward port of GCC 10 commit 6f3f06e431c181d3e51d31f49a2bf0be2944ae93
which is a backport of mainline commit ba9fa684053917a07bfa8f4742da0e196e72b9a2

gcc/fortran/ChangeLog:

PR fortran/92587
* match.c (gfc_match_assignment): Move gfc_find_vtab call from here ...
* resolve.c (gfc_resolve_code): ... to here.

gcc/testsuite/ChangeLog:

PR fortran/92587
* gfortran.dg/finalize_37.f90: New test.

(cherry picked from commit ba9fa684053917a07bfa8f4742da0e196e72b9a2)

4 years agoopenmp: Fix g++.dg/gomp/declare-target-3.C testcase when offloading is disabled
Kwok Cheung Yeung [Fri, 18 Dec 2020 20:05:20 +0000 (12:05 -0800)] 
openmp: Fix g++.dg/gomp/declare-target-3.C testcase when offloading is disabled

This is a backport from mainline of commit
bfb37fa4dd49ee775ae90355464265a2f60c1067.

2020-12-18  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/testsuite/
* g++.dg/gomp/declare-target-3.C: Only check .offload_var_table
entries if offloading is enabled.

4 years agoOpenMP: Add implicit declare target for nested procedures
Tobias Burnus [Wed, 30 Sep 2020 12:59:27 +0000 (14:59 +0200)] 
OpenMP: Add implicit declare target for nested procedures

This is a backport from mainline of commit
8b0a63e47cd83f4e8534d0d201739bdd10f321a2.

gcc/ChangeLog:

* omp-offload.c (omp_discover_implicit_declare_target): Also
handled nested functions.

libgomp/ChangeLog:

* testsuite/libgomp.fortran/declare-target-3.f90: New test.

4 years agoopenmp: Implicitly add 'declare target' directives for dynamic initializers in C++
Kwok Cheung Yeung [Fri, 18 Dec 2020 16:26:34 +0000 (08:26 -0800)] 
openmp: Implicitly add 'declare target' directives for dynamic initializers in C++

This is a backport from mainline (commit
3af02d32cce2ff1ff11d078cf8094305f57ca179).

2020-12-18  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/
* langhooks-def.h (lhd_get_decl_init): New.
(lhd_finish_decl_inits): New.
(LANG_HOOKS_GET_DECL_INIT): New.
(LANG_HOOKS_OMP_FINISH_DECL_INITS): New.
(LANG_HOOKS_DECLS): Add LANG_HOOKS_GET_DECL_INIT and
LANG_HOOKS_OMP_FINISH_DECL_INITS.
* langhooks.c (lhd_omp_get_decl_init): New.
(lhd_omp_finish_decl_inits): New.
* langhooks.h (struct lang_hooks_for_decls): Add omp_get_decl_init
and omp_finish_decl_inits.
* omp-offload.c (omp_discover_declare_target_var_r): Use
get_decl_init langhook in place of DECL_INITIAL.  Call
omp_finish_decl_inits langhook at end of function.

gcc/cp/
* cp-lang.c (cxx_get_decl_init): New.
(cxx_omp_finish_decl_inits): New.
(LANG_HOOKS_GET_DECL_INIT): New.
(LANG_HOOKS_OMP_FINISH_DECL_INITS): New.
* cp-tree.h (dynamic_initializers): New.
* decl.c (dynamic_initializers): New.
* decl2.c (c_parse_final_cleanups): Add initializer entries
from vars to dynamic_initializers.

gcc/testsuite/
* g++.dg/gomp/declare-target-3.C: New.

4 years agoopenmp: Implement OpenMP 5.0 base-pointer attachement and clause ordering
Chung-Lin Tang [Tue, 10 Nov 2020 11:36:58 +0000 (03:36 -0800)] 
openmp: Implement OpenMP 5.0 base-pointer attachement and clause ordering

This patch implements some parts of the target variable mapping changes
specified in OpenMP 5.0, including base-pointer attachment/detachment
behavior for array section list-items in map clauses, and ordering of
map clauses according to map kind.

2020-11-10  Chung-Lin Tang  <cltang@codesourcery.com>

gcc/c-family/ChangeLog:

* c-common.h (c_omp_adjust_map_clauses): New declaration.
* c-omp.c (struct map_clause): Helper type for c_omp_adjust_map_clauses.
(c_omp_adjust_map_clauses): New function.

gcc/c/ChangeLog:

* c-parser.c (c_parser_omp_target_data): Add use of
new c_omp_adjust_map_clauses function. Add GOMP_MAP_ATTACH_DETACH as
handled map clause kind.
(c_parser_omp_target_enter_data): Likewise.
(c_parser_omp_target_exit_data): Likewise.
(c_parser_omp_target): Likewise.
* c-typeck.c (handle_omp_array_sections): Adjust COMPONENT_REF case to
use GOMP_MAP_ATTACH_DETACH map kind for C_ORT_OMP region type.
(c_finish_omp_clauses): Adjust bitmap checks to allow struct decl and
same struct field access to co-exist on OpenMP construct.

gcc/cp/ChangeLog:

* parser.c (cp_parser_omp_target_data): Add use of
new c_omp_adjust_map_clauses function. Add GOMP_MAP_ATTACH_DETACH as
handled map clause kind.
(cp_parser_omp_target_enter_data): Likewise.
(cp_parser_omp_target_exit_data): Likewise.
(cp_parser_omp_target): Likewise.
* semantics.c (handle_omp_array_sections): Adjust COMPONENT_REF case to
use GOMP_MAP_ATTACH_DETACH map kind for C_ORT_OMP region type. Fix
interaction between reference case and attach/detach.
(finish_omp_clauses): Adjust bitmap checks to allow struct decl and
same struct field access to co-exist on OpenMP construct.

gcc/ChangeLog:

* gimplify.c (is_or_contains_p): New static helper function.
(omp_target_reorder_clauses): New function.
(gimplify_scan_omp_clauses): Add use of omp_target_reorder_clauses to
reorder clause list according to OpenMP 5.0 rules. Add handling of
GOMP_MAP_ATTACH_DETACH for OpenMP cases.
* omp-low.c (is_omp_target): New static helper function.
(scan_sharing_clauses): Add scan phase handling of GOMP_MAP_ATTACH/DETACH
for OpenMP cases.
(lower_omp_target): Add lowering handling of GOMP_MAP_ATTACH/DETACH for
OpenMP cases.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/clauses-2.c: Remove dg-error cases now valid.
* gfortran.dg/gomp/map-2.f90: Likewise.
* c-c++-common/gomp/map-5.c: New testcase.

libgomp/ChangeLog:

* libgomp.h (enum gomp_map_vars_kind): Adjust enum values to be bit-flag
usable.
* oacc-mem.c (acc_map_data): Adjust gomp_map_vars argument flags to
'GOMP_MAP_VARS_OPENACC | GOMP_MAP_VARS_ENTER_DATA'.
(goacc_enter_datum): Likewise for call to gomp_map_vars_async.
(goacc_enter_data_internal): Likewise.
* target.c (gomp_map_vars_internal):
Change checks of GOMP_MAP_VARS_ENTER_DATA to use bit-and (&). Adjust use
of gomp_attach_pointer for OpenMP cases.
(gomp_exit_data): Add handling of GOMP_MAP_DETACH.
(GOMP_target_enter_exit_data): Add handling of GOMP_MAP_ATTACH.
* testsuite/libgomp.c-c++-common/ptr-attach-1.c: New testcase.

4 years agoopenmp: Retire nest-var ICV for OpenMP 5.1
Kwok Cheung Yeung [Wed, 18 Nov 2020 19:24:36 +0000 (11:24 -0800)] 
openmp: Retire nest-var ICV for OpenMP 5.1

This removes the nest-var ICV, expressing nesting in terms of the
max-active-levels-var ICV instead.  The max-active-levels-var ICV
is now per data environment rather than per device.

This is a backport from mainline (commit
6fae7eda968db658c280ad6f94fe6906a15af0c9).

2020-11-18  Kwok Cheung Yeung  <kcy@codesourcery.com>

libgomp/
* env.c (gomp_global_icv): Remove nest_var field.  Add
max_active_levels_var field.
(gomp_max_active_levels_var): Remove.
(parse_boolean): Return true on success.
(handle_omp_display_env): Express OMP_NESTED in terms of
max_active_levels_var.  Change format specifier for
max_active_levels_var.
(initialize_env): Set max_active_levels_var from
OMP_MAX_ACTIVE_LEVELS, OMP_NESTED, OMP_NUM_THREADS and
OMP_PROC_BIND.
* icv.c (omp_set_nested): Express in terms of
max_active_levels_var.
(omp_get_nested): Likewise.
(omp_set_max_active_levels): Use max_active_levels_var field instead
of gomp_max_active_levels_var.
(omp_get_max_active_levels): Likewise.
* libgomp.h (struct gomp_task_icv): Remove nest_var field.  Add
max_active_levels_var field.
(gomp_supported_active_levels): Set to UCHAR_MAX.
(gomp_max_active_levels_var): Delete.
* libgomp.texi (omp_get_nested): Update documentation.
(omp_set_nested): Likewise.
(OMP_MAX_ACTIVE_LEVELS): Likewise.
(OMP_NESTED): Likewise.
(OMP_NUM_THREADS): Likewise.
(OMP_PROC_BIND): Likewise.
* parallel.c (gomp_resolve_num_threads): Replace reference
to nest_var with max_active_levels_var.  Use max_active_levels_var
field instead of gomp_max_active_levels_var.

4 years agoopenmp: Mark deprecated symbols in OpenMP 5.0
Kwok Cheung Yeung [Thu, 5 Nov 2020 18:11:23 +0000 (10:11 -0800)] 
openmp: Mark deprecated symbols in OpenMP 5.0

This is a backport from mainline (commit
10508db867934264bbc2578f1f454c19fa558fd3).

2020-11-05  Ulrich Drepper  <drepper@redhat.com>
    Kwok Cheung Yeung  <kcy@codesourcery.com>

libgomp/
* Makefile.am (%.mod): Add -cpp and -fopenmp to compile flags.
* Makefile.in: Regenerate.
* fortran.c: Wrap uses of omp_set_nested and omp_get_nested with
pragmas to ignore -Wdeprecated-declarations warnings.
* icv.c: Likewise.
* omp.h.in (__GOMP_DEPRECATED_5_0): Define.
Mark omp_lock_hint_* enum values, omp_lock_hint_t, omp_set_nested,
and omp_get_nested with __GOMP_DEPRECATED_5_0.
* omp_lib.f90.in: Mark omp_get_nested and omp_set_nested as
deprecated.
* testsuite/libgomp.c++/affinity-1.C: Add -Wno-deprecated-declarations
to test options.
* testsuite/libgomp.c/affinity-1.c: Likewise.
* testsuite/libgomp.c/affinity-2.c: Likewise.
* testsuite/libgomp.c/appendix-a/a.15.1.c: Likewise.
* testsuite/libgomp.c/lib-1.c: Likewise.
* testsuite/libgomp.c/nested-1.c: Likewise.
* testsuite/libgomp.c/nested-2.c: Likewise.
* testsuite/libgomp.c/nested-3.c: Likewise.
* testsuite/libgomp.c/pr32362-1.c: Likewise.
* testsuite/libgomp.c/pr32362-2.c: Likewise.
* testsuite/libgomp.c/pr32362-3.c: Likewise.
* testsuite/libgomp.c/pr35549.c: Likewise.
* testsuite/libgomp.c/pr42942.c: Likewise.
* testsuite/libgomp.c/pr61200.c: Likewise.
* testsuite/libgomp.c/sort-1.c: Likewise.
* testsuite/libgomp.c/target-5.c: Likewise.
* testsuite/libgomp.c/target-6.c: Likewise.
* testsuite/libgomp.c/teams-1.c: Likewise.
* testsuite/libgomp.c/thread-limit-1.c: Likewise.
* testsuite/libgomp.c/thread-limit-2.c: Likewise.
* testsuite/libgomp.c/thread-limit-4.c: Likewise.
* testsuite/libgomp.fortran/affinity1.f90: Likewise.
* testsuite/libgomp.fortran/lib1.f90: Likewise.
* testsuite/libgomp.fortran/lib2.f: Likewise.
* testsuite/libgomp.fortran/nested1.f90: Likewise.
* testsuite/libgomp.fortran/teams1.f90: Likewise.

4 years agoopenmp: Add test for OMP_TARGET_OFFLOAD=mandatory for cases where it must not fail
Jakub Jelinek [Thu, 22 Oct 2020 07:33:17 +0000 (09:33 +0200)] 
openmp: Add test for OMP_TARGET_OFFLOAD=mandatory for cases where it must not fail

This is a backport from mainline (commit
17c5b7e1dc47bab6e6cedbf4b2d88cef3283533e).

2020-10-22  Jakub Jelinek  <jakub@redhat.com>

* testsuite/libgomp.c/target-41.c: New test.

4 years agoopenmp: Change omp_get_initial_device () to match OpenMP 5.1 requirements
Jakub Jelinek [Thu, 22 Oct 2020 07:31:01 +0000 (09:31 +0200)] 
openmp: Change omp_get_initial_device () to match OpenMP 5.1 requirements

> Therefore, I think until omp_get_initial_device () value is changed, we

The following so far untested patch implements that change.

OpenMP 4.5 said for omp_get_initial_device:
The value of the device number is implementation defined. If it is between 0 and one less than
omp_get_num_devices() then it is valid for use with all device constructs and routines; if it is
outside that range, then it is only valid for use with the device memory routines and not in the
device clause.
and OpenMP 5.0 similarly, but OpenMP 5.1 says:
The value of the device number is the value returned by the omp_get_num_devices routine.

As the new value is compatible with what has been required earlier, I think
we can change it already now.

This is a backport from mainline (commit
74c9882b80bda50b37c9555498de7123c6bdb9e4).

2020-10-22  Jakub Jelinek  <jakub@redhat.com>

* icv.c (omp_get_initial_device): Remove including corresponding
ialias.
* icv-device.c (omp_get_initial_device): New function.  Return
gomp_get_num_devices ().  Add ialias.
* target.c (resolve_device): Don't fail with
OMP_TARGET_OFFLOAD=mandatory if device_id is equal to
gomp_get_num_devices ().
(omp_target_alloc, omp_target_free, omp_target_is_present,
omp_target_memcpy, omp_target_memcpy_rect, omp_target_associate_ptr,
omp_target_disassociate_ptr, omp_pause_resource): Use
gomp_get_num_devices () instead of GOMP_DEVICE_HOST_FALLBACK on the
first use in the functions, in uses dominated by the
gomp_get_num_devices call use num_devices_openmp instead.
* libgomp.texi (omp_get_initial_device): Document.
* config/gcn/icv-device.c (omp_get_initial_device): New function.
Add ialias.
* config/nvptx/icv-device.c (omp_get_initial_device): Likewise.
* testsuite/libgomp.c/target-40.c: New test.

4 years agoopenmp: Implement support for OMP_TARGET_OFFLOAD environment variable
Kwok Cheung Yeung [Tue, 20 Oct 2020 11:15:59 +0000 (04:15 -0700)] 
openmp: Implement support for OMP_TARGET_OFFLOAD environment variable

This implements support for the OMP_TARGET_OFFLOAD environment variable
introduced in the OpenMP 5.0 standard, which controls how offloading
is handled.  It may be set to MANDATORY (abort if offloading cannot be
performed), DISABLED (no offloading to devices) or DEFAULT (offload to
device if possible, fall back to host if not).

This is a backport from mainline (commits
1bfc07d150790fae93184a79a7cce897655cb37b,
35f258f4bbba7fa044f90b4f14d1bc942db58089 and
121a8812c45b3155ccbd268b000ad00a778e81e8).

2020-10-20  Kwok Cheung Yeung  <kcy@codesourcery.com>
    Jakub Jelinek  <jakub@redhat.com>

libgomp/
* env.c (gomp_target_offload_var): New.
(parse_target_offload): New.
(handle_omp_display_env): Print value of OMP_TARGET_OFFLOAD.
(initialize_env): Parse OMP_TARGET_OFFLOAD.
* libgomp.h (gomp_target_offload_t): New.
(gomp_target_offload_var): New.
* libgomp.texi (OMP_TARGET_OFFLOAD): New section.
* target.c (resolve_device): Generate error if device not found and
offloading is mandatory.
(gomp_target_fallback): Generate error if offloading is mandatory.
(GOMP_target): Add argument in call to gomp_target_fallback.
(GOMP_target_ext): Likewise.
(gomp_target_data_fallback): Generate error if offloading is mandatory.
(GOMP_target_data): Add argument in call to gomp_target_data_fallback.
(GOMP_target_data_ext): Likewise.
(gomp_target_task_fn): Add argument in call to gomp_target_fallback.
(gomp_target_init): Return early if offloading is disabled.
Inside of the function, use automatic
variables corresponding to num_devices, num_devices_openmp and devices
global variables and update the globals only at the end of the
function.

4 years agoopenmp: Add support for the omp_get_supported_active_levels runtime library routine
Kwok Cheung Yeung [Wed, 7 Oct 2020 16:34:32 +0000 (09:34 -0700)] 
openmp: Add support for the omp_get_supported_active_levels runtime library routine

This patch implements the omp_get_supported_active_levels runtime routine
from the OpenMP 5.0 specification, which returns the maximum number of
active nested parallel regions supported by this implementation.  The
current maximum (set using the omp_set_max_active_levels routine or the
OMP_MAX_ACTIVE_LEVELS environment variable) cannot exceed this number.

This is a backport from mainline (commits
8949b985dbaf07d433bd57d2883e1e5414f20e75 and
445567b22a3c535be0b1861b393e9a0b050f2b1e).

2020-10-13  Kwok Cheung Yeung  <kcy@codesourcery.com>

libgomp/
* env.c (gomp_max_active_levels_var): Initialize to
gomp_supported_active_levels.
(initialize_env): Limit gomp_max_active_levels_var to be at most
equal to gomp_supported_active_levels.
* fortran.c (omp_get_supported_active_levels): Add ialias_redirect.
(omp_get_supported_active_levels_): New.
* icv.c (omp_set_max_active_levels): Limit gomp_max_active_levels_var
to at most equal to gomp_supported_active_levels.
(omp_get_supported_active_levels): New.
* libgomp.h (gomp_supported_active_levels): New.
* libgomp.map (OMP_5.0.1): Add omp_get_supported_active_levels and
omp_get_supported_active_levels_.
* libgomp.texi (omp_get_max_active_levels): Modify description.
(omp_get_supported_active_levels): New.
(omp_set_max_active_levels): Update.  Add reference to
omp_get_supported_active_levels.
* omp.h.in (omp_get_supported_active_levels): New.
* omp_lib.f90.in (omp_get_supported_active_levels): New.
* omp_lib.h.in (omp_get_supported_active_levels): New.
* testsuite/libgomp.c/lib-2.c (main): Check omp_get_max_active_levels
against omp_get_supported_active_levels.
* testsuite/libgomp.fortran/lib4.f90 (lib4): Likewise.

4 years agoMerge remote-tracking branch 'origin/releases/gcc-10' into devel/omp/gcc-10
Tobias Burnus [Mon, 28 Sep 2020 17:58:57 +0000 (19:58 +0200)] 
Merge remote-tracking branch 'origin/releases/gcc-10' into devel/omp/gcc-10

Merged up to a6c47f4ce26639bfbc72821ae629b9af7744a9d7 (2020-09-28)

4 years agoOpenMP: Handle cpp_implicit_alias in declare-target discovery (PR96390)
Tobias Burnus [Mon, 28 Sep 2020 17:57:50 +0000 (19:57 +0200)] 
OpenMP: Handle cpp_implicit_alias in declare-target discovery (PR96390)

Backport mainline version; updates commit
ef509d1985aa53a8c0875c25ad4050ea807be10e for later review-comment
changes.

gcc/ChangeLog:

PR middle-end/96390
* omp-offload.c (omp_discover_declare_target_tgt_fn_r): Handle
alias nodes.

libgomp/ChangeLog:

PR middle-end/96390
* testsuite/libgomp.c++/pr96390.C: New test.
* testsuite/libgomp.c-c++-common/pr96390.c: New test.

(cherry picked from commit 2a10a2c0689db280ee3a94164504b7196b8370f4)

4 years agogomp/pr94874.c: Update scan-tree-dump
Tobias Burnus [Mon, 28 Sep 2020 17:57:20 +0000 (19:57 +0200)] 
gomp/pr94874.c: Update scan-tree-dump

g++ on OG10 adds an additional temporary compared to mainline.

* c-c++-common/gomp/pr94874.c: Update scan-tree-dump.

4 years agotestsuite: [aarch64] Fix aarch64/advsimd-intrinsics/v{trn,uzp,zip}_half.c
Christophe Lyon [Fri, 25 Sep 2020 10:40:18 +0000 (10:40 +0000)] 
testsuite: [aarch64] Fix aarch64/advsimd-intrinsics/v{trn,uzp,zip}_half.c

Since r11-3402 (g:65c9878641cbe0ed898aa7047b7b994e9d4a5bb1), the
vtrn_half, vuzp_half and vzip_half started failing with

vtrn_half.c:76:17: error: redeclaration of 'vector_float64x2' with no linkage
vtrn_half.c:77:17: error: redeclaration of 'vector2_float64x2' with no linkage
vtrn_half.c:80:17: error: redeclaration of 'vector_res_float64x2' with no linkage

This is because r11-3402 now always declares float64x2 variables for
aarch64, leading to a duplicate declaration in these testcases.

The fix is simply to remove these now useless declarations.

These tests are skipped on arm*, so there is no impact on that target.

2020-09-25  Christophe Lyon  <christophe.lyon@linaro.org>

gcc/testsuite/
PR target/71233
* gcc.target/aarch64/advsimd-intrinsics/vtrn_half.c: Remove
declarations of vector, vector2, vector_res for float64x2 type.
* gcc.target/aarch64/advsimd-intrinsics/vuzp_half.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vzip_half.c: Likewise.

(cherry picked from commit 8c775bf447e190024fa08c55e38db94dd013a393)

4 years agoAArch64: Implement missing p128<->f64 reinterpret intrinsics
Kyrylo Tkachov [Wed, 23 Sep 2020 16:37:58 +0000 (17:37 +0100)] 
AArch64: Implement missing p128<->f64 reinterpret intrinsics

This patch implements the missing reinterprets to and from poly128_t and
float64x2_t.
I've plugged in the appropriate testing in the advsimd-intrinsics.exp
too.

Bootstrapped and tested on aarch64-none-linux-gnu.
Tested advsimd-intrinsics.exp on arm-none-eabi too to make sure arm
testing isn't affected.

gcc/
PR target/71233
* config/aarch64/arm_neon.h (vreinterpretq_f64_p128,
vreinterpretq_p128_f64): Define.

gcc/testsuite/
PR target/71233
* gcc.target/aarch64/advsimd-intrinsics/arm-neon-ref.h
(clean_results): Add float64x2_t cleanup.
(DECL_VARIABLE_128BITS_VARIANTS): Add float64x2_t variable.
* gcc.target/aarch64/advsimd-intrinsics/vreinterpret_p128.c: Add
testing of vreinterpretq_f64_p128, vreinterpretq_p128_f64.

(cherry picked from commit 65c9878641cbe0ed898aa7047b7b994e9d4a5bb1)

4 years agoAArch64: Implement missing vrndns_f32 intrinsic
Kyrylo Tkachov [Wed, 23 Sep 2020 11:02:29 +0000 (12:02 +0100)] 
AArch64: Implement missing vrndns_f32 intrinsic

This patch implements the missing vrndns_f32 intrinsic. This operates on a scalar float32_t value.
It can be mapped down to a __builtin_aarch64_frintnsf builtin.

This patch does that.

Bootstrapped and tested on aarch64-none-linux-gnu.

gcc/
PR target/71233
* config/aarch64/aarch64-simd-builtins.def (frintn): Use BUILTIN_VHSDF_HSDF
for modes.  Remove explicit hf instantiation.
* config/aarch64/arm_neon.h (vrndns_f32): Define.

gcc/testsuite/
PR target/71233
* gcc.target/aarch64/simd/vrndns_f32_1.c: New test.

(cherry picked from commit 02b5377b3766804059b7824330d33d0e1cef2e5b)

4 years agoAArch64: Implement missing _p64 intrinsics for vector permutes
Kyrylo Tkachov [Wed, 23 Sep 2020 10:07:50 +0000 (11:07 +0100)] 
AArch64: Implement missing _p64 intrinsics for vector permutes

This patch implements some missing vector permute intrinsics operating on poly64x2_t types.
They are implemented identically to their uint64x2_t brethren.

Bootstrapped and tested on aarch64-none-linux-gnu.

gcc/
PR target/71233
* config/aarch64/arm_neon.h (vtrn1q_p64, vtrn2q_p64, vuzp1q_p64,
vuzp2q_p64, vzip1q_p64, vzip2q_p64): Define.

gcc/testsuite/
PR target/71233
* gcc.target/aarch64/simd/trn_zip_p64_1.c: New test.

(cherry picked from commit e8e818399d70c5a5a3d30a54d305c6e2b92e2c66)

4 years agoAArch64: Implement vldrq_p128 intrinsic
Kyrylo Tkachov [Wed, 23 Sep 2020 09:32:42 +0000 (10:32 +0100)] 
AArch64: Implement vldrq_p128 intrinsic

This patch implements the missing vldrq_p128 intrinsic that just loads from the appropriate pointer.

Bootstrapped and tested on aarch64-none-linux-gnu.

gcc/
PR target/71233
* config/aarch64/arm_neon.h (vldrq_p128): Define.

gcc/testsuite/
PR target/71233
* gcc.target/aarch64/simd/vldrq_p128_1.c: New test.

(cherry picked from commit f2868e4bcff2c7b882d01231f039459c00e59d7b)