]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
3 years agoopenmp: fix max_vf setting for amdgcn offloading
Andrew Stubbs [Fri, 8 Jul 2022 10:58:46 +0000 (11:58 +0100)] 
openmp: fix max_vf setting for amdgcn offloading

Ensure that the "max_vf" figure used for the "safelen" attribute is large
enough for the largest configured offload device.

This change gives ~10x speed improvement on the Bablestream "dot" benchmark for
AMD GCN.

gcc/ChangeLog:

* gimple-loop-versioning.cc (loop_versioning::loop_versioning): Add
comment.
* omp-general.cc (omp_max_simd_vf): New function.
* omp-general.h (omp_max_simd_vf): New prototype.
* omp-low.cc (lower_rec_simd_input_clauses): Select largest from
  omp_max_vf, omp_max_simt_vf, and omp_max_simd_vf.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp
(check_effective_target_amdgcn_offloading_enabled): New.
(check_effective_target_nvptx_offloading_enabled): New.
* gcc.dg/gomp/target-vf.c: New test.

3 years agoFix one issue in OpenMP 'requires' directive diagnostics
Thomas Schwinge [Fri, 8 Jul 2022 09:33:23 +0000 (11:33 +0200)] 
Fix one issue in OpenMP 'requires' directive diagnostics

Fix-up for recent commit 683f11843974f0bdf42f79cdcbb0c2b43c7b81b0
"OpenMP: Move omp requires checks to libgomp".

gcc/
* lto-cgraph.cc (input_offload_tables) <LTO_symtab_edge>: Correct
'fn2' computation.
libgomp/
* testsuite/libgomp.c-c++-common/requires-1.c: Add 'dg-note's.
* testsuite/libgomp.c-c++-common/requires-2.c: Likewise.
* testsuite/libgomp.c-c++-common/requires-3.c: Likewise.
* testsuite/libgomp.c-c++-common/requires-7.c: Likewise.
* testsuite/libgomp.fortran/requires-1.f90: Likewise.

(cherry picked from commit faa0c328ee65f0d6d65d6e20181d26e336071919)

3 years agoFix Intel MIC 'mkoffload' for OpenMP 'requires'
Thomas Schwinge [Thu, 7 Jul 2022 12:07:22 +0000 (14:07 +0200)] 
Fix Intel MIC 'mkoffload' for OpenMP 'requires'

Similar to how the other 'mkoffload's got changed in
recent commit 683f11843974f0bdf42f79cdcbb0c2b43c7b81b0
"OpenMP: Move omp requires checks to libgomp".

This also means finally switching Intel MIC 'mkoffload' to
'GOMP_offload_register_ver', 'GOMP_offload_unregister_ver',
making 'GOMP_offload_register', 'GOMP_offload_unregister'
legacy entry points.

gcc/
* config/i386/intelmic-mkoffload.cc (generate_host_descr_file)
(prepare_target_image, main): Handle OpenMP 'requires'.
(generate_host_descr_file): Switch to 'GOMP_offload_register_ver',
'GOMP_offload_unregister_ver'.
libgomp/
* target.c (GOMP_offload_register, GOMP_offload_unregister):
Denote as legacy entry points.
* testsuite/lib/libgomp.exp
(check_effective_target_offload_target_any): New proc.
* testsuite/libgomp.c-c++-common/requires-1.c: Enable for
'offload_target_any'.
* testsuite/libgomp.c-c++-common/requires-3.c: Likewise.
* testsuite/libgomp.c-c++-common/requires-7.c: Likewise.
* testsuite/libgomp.fortran/requires-1.f90: Likewise.

(cherry picked from commit 9ef714539cb7cc1cd746312fd5dcc987bf167471)

3 years agoEnhance 'libgomp.c-c++-common/requires-4.c', 'libgomp.c-c++-common/requires-5.c'...
Thomas Schwinge [Thu, 7 Jul 2022 12:05:53 +0000 (14:05 +0200)] 
Enhance 'libgomp.c-c++-common/requires-4.c', 'libgomp.c-c++-common/requires-5.c' testing

These should compile and link and execute in all configurations; host-fallback
execution, which we may actually verify.

Follow-up to recent commit 683f11843974f0bdf42f79cdcbb0c2b43c7b81b0
"OpenMP: Move omp requires checks to libgomp".

libgomp/
* testsuite/libgomp.c-c++-common/requires-4.c: Enhance testing.
* testsuite/libgomp.c-c++-common/requires-5.c: Likewise.

(cherry picked from commit 5647e2c3853cbd51a6536a84b8eb0eb3c210dfbf)

3 years agoAdjust 'libgomp.c-c++-common/requires-3.c'
Thomas Schwinge [Thu, 7 Jul 2022 12:05:17 +0000 (14:05 +0200)] 
Adjust 'libgomp.c-c++-common/requires-3.c'

As documented, this one does "Check diagnostic by device-compiler's lto1".
Indeed there are none when compiling with '-foffload=disable' with an
offloading-enabled compiler, so we should use 'offload_target_[...]', as
used in other similar test cases.

Follow-up to recent commit 683f11843974f0bdf42f79cdcbb0c2b43c7b81b0
"OpenMP: Move omp requires checks to libgomp".

libgomp/
* testsuite/libgomp.c-c++-common/requires-3.c: Adjust.

(cherry picked from commit 99831ceb872cd1a3f3207fd2dfe03ef65dd9089b)

3 years agoRestore 'GOMP_offload_unregister_ver' functionality
Thomas Schwinge [Thu, 7 Jul 2022 06:54:11 +0000 (08:54 +0200)] 
Restore 'GOMP_offload_unregister_ver' functionality

The recent commit 683f11843974f0bdf42f79cdcbb0c2b43c7b81b0
"OpenMP: Move omp requires checks to libgomp" changed the
'GOMP_offload_register_ver' interface but didn't change
'GOMP_offload_unregister_ver' accordingly, so we're no longer
actually unregistering.

gcc/
* config/gcn/mkoffload.cc (process_obj): Clarify 'target_data' ->
'[...]_data'.
* config/nvptx/mkoffload.cc (process): Likewise.
libgomp/
* target.c (GOMP_offload_register_ver): Clarify 'target_data' ->
'data'.
(GOMP_offload_unregister_ver): Likewise.  Fix up 'target_data'.

(cherry picked from commit 3f05e03d6cfdf723ca0556318b6a9aa37be438e7)

3 years agoDefine 'OMP_REQUIRES_[...]', 'GOMP_REQUIRES_[...]' in a single place
Thomas Schwinge [Thu, 7 Jul 2022 06:51:50 +0000 (08:51 +0200)] 
Define 'OMP_REQUIRES_[...]', 'GOMP_REQUIRES_[...]' in a single place

Clean up for recent commit 683f11843974f0bdf42f79cdcbb0c2b43c7b81b0
"OpenMP: Move omp requires checks to libgomp".

gcc/
* omp-general.h (enum omp_requires): Use 'GOMP_REQUIRES_[...]'.
include/
* gomp-constants.h (OMP_REQUIRES_[...]): Update comment.

(cherry picked from commit 2f0d819a81edee50a98a8a05eed585f0a72bb932)

3 years agolibgomp nvptx plugin: Remove '--with-cuda-driver=[...]' etc. configuration option
Thomas Schwinge [Tue, 5 Jul 2022 14:41:03 +0000 (16:41 +0200)] 
libgomp nvptx plugin: Remove '--with-cuda-driver=[...]' etc. configuration option

That means, exposing to the user only the '--without-cuda-driver' behavior:
including the GCC-shipped 'include/cuda/cuda.h' (not system <cuda.h>), and
'dlopen'ing the CUDA Driver library (not linking it).

For development purposes, the libgomp nvptx plugin developer may still manually
override that, to get the previous '--with-cuda-driver' behavior.

libgomp/
* plugin/Makefrag.am: Evaluate 'if PLUGIN_NVPTX_DYNAMIC' to true.
* plugin/configfrag.ac (--with-cuda-driver)
(--with-cuda-driver-include, --with-cuda-driver-lib)
(CUDA_DRIVER_INCLUDE, CUDA_DRIVER_LIB, PLUGIN_NVPTX_CPPFLAGS)
(PLUGIN_NVPTX_LDFLAGS, PLUGIN_NVPTX_LIBS, PLUGIN_NVPTX_DYNAMIC):
Remove.
* testsuite/libgomp-test-support.exp.in (cuda_driver_include)
(cuda_driver_lib): Remove.
* testsuite/lib/libgomp.exp (libgomp_init): Don't consider these.
* Makefile.in: Regenerate.
* configure: Likewise.
* testsuite/Makefile.in: Likewise.

(cherry picked from commit 1459b55d24ce6508330690bf4c932f7a5218c9f3)

3 years agoOpenMP: Move omp requires checks to libgomp
Tobias Burnus [Tue, 5 Jul 2022 13:31:01 +0000 (15:31 +0200)] 
OpenMP: Move omp requires checks to libgomp

This commit reverts OG12 commits
   commit 6ab6303f61c812d6e2f05d44af5cc79815c57bb8
   'OpenMP 5.0: requires directive'
and
   commit 47e5ba646c20fdb64fa233dd570f155880cafd04
   '[WIP] OpenMP 5.0: requires directive: workaround to fix libgomp IntelMIC plugin build'

And replaces those by the upstream version, commit r13-1458, i.e.
(cherry picked from commit 683f11843974f0bdf42f79cdcbb0c2b43c7b81b0)

It also updates
* libgomp/plugin/plugin-gcn.c (GOMP_OFFLOAD_get_num_devices)
to permit GOMP_REQUIRES_UNIFIED_ADDRESS | GOMP_REQUIRES_UNIFIED_SHARED_MEMORY,
moved from the now no-longer existing function GOMP_OFFLOAD_supported_features;
the flags were added in OG12 commit 12d14a9a255c1cc10e4506935327aabd9766967d,
'amdgcn: libgomp plugin USM implementation'.

And, likewise, it updates
* libgomp/plugin/plugin-nvptx.c (GOMP_OFFLOAD_get_num_devices)
from OG12 commit f3fd38e31fafdc7f6b6a721b53bdc595c4ec1e09,
'libgomp, nvptx: report USM'.

 * * *

Handle reverse_offload, unified_address, and unified_shared_memory
requirements in libgomp by saving them alongside the offload table.
When the device lto1 runs, it extracts the data for mkoffload. The
latter than passes the value on to GOMP_offload_register_ver.

lto1 (either the host one, with -flto [+ ENABLE_OFFLOADING], or in the
offload-device lto1) also does the the consistency check is done,
erroring out when the 'omp requires' clause use is inconsistent.

For all in-principle supported devices, if a requirement cannot be fulfilled,
the device is excluded from the (supported) devices list. Currently, none of
those requirements are marked as supported for any of the non-host devices.

gcc/c/ChangeLog:

* c-parser.cc (c_parser_omp_target_data, c_parser_omp_target_update,
c_parser_omp_target_enter_data, c_parser_omp_target_exit_data): Set
OMP_REQUIRES_TARGET_USED.
(c_parser_omp_requires): Remove sorry.

gcc/ChangeLog:

* config/gcn/mkoffload.cc (process_asm): Write '#include <stdint.h>'.
(process_obj): Pass omp_requires_mask to GOMP_offload_register_ver.
(main): Ask lto1 to obtain omp_requires_mask and pass it on.
* config/nvptx/mkoffload.cc (process, main): Likewise.
* lto-cgraph.cc (omp_requires_to_name): New.
(input_offload_tables): Save omp_requires_mask.
(output_offload_tables): Read it, check for consistency,
save value for mkoffload.
* omp-low.cc (lower_omp_target): Force output_offloadtables
call for OMP_REQUIRES_TARGET_USED.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_omp_target_data,
cp_parser_omp_target_enter_data, cp_parser_omp_target_exit_data,
cp_parser_omp_target_update): Set OMP_REQUIRES_TARGET_USED.
(cp_parser_omp_requires): Remove sorry.

gcc/fortran/ChangeLog:

* openmp.cc (gfc_match_omp_requires): Remove sorry.
* parse.cc (decode_omp_directive): Don't regard 'declare target'
as target usage for 'omp requires'; add more flags to
omp_requires_mask.

include/ChangeLog:

* gomp-constants.h (GOMP_VERSION): Bump to 2.
(GOMP_REQUIRES_UNIFIED_ADDRESS, GOMP_REQUIRES_UNIFIED_SHARED_MEMORY,
GOMP_REQUIRES_REVERSE_OFFLOAD, GOMP_REQUIRES_TARGET_USED):
New defines.

libgomp/ChangeLog:

* libgomp-plugin.h (GOMP_OFFLOAD_get_num_devices): Add
omp_requires_mask arg.
* plugin/plugin-gcn.c (GOMP_OFFLOAD_get_num_devices): Likewise;
return -1 when device available but omp_requires_mask != 0.
* plugin/plugin-nvptx.c (GOMP_OFFLOAD_get_num_devices): Likewise.
* oacc-host.c (host_get_num_devices, host_openacc_get_property):
Update call.
* oacc-init.c (resolve_device, acc_init_1, acc_shutdown_1,
goacc_attach_host_thread_to_device, acc_get_num_devices,
acc_set_device_num, get_property_any): Likewise.
* target.c (omp_requires_mask): New global var.
(gomp_requires_to_name): New.
(GOMP_offload_register_ver): Handle passed omp_requires_mask.
(gomp_target_init): Handle omp_requires_mask.
* libgomp.texi (OpenMP 5.0): Update requires impl. status.
(OpenMP 5.1): Add a missed item.
(OpenMP 5.2): Mark linear-clause change as supported in C/C++.
* testsuite/libgomp.c-c++-common/requires-1-aux.c: New test.
* testsuite/libgomp.c-c++-common/requires-1.c: New test.
* testsuite/libgomp.c-c++-common/requires-2-aux.c: New test.
* testsuite/libgomp.c-c++-common/requires-2.c: New test.
* testsuite/libgomp.c-c++-common/requires-3-aux.c: New test.
* testsuite/libgomp.c-c++-common/requires-3.c: New test.
* testsuite/libgomp.c-c++-common/requires-4-aux.c: New test.
* testsuite/libgomp.c-c++-common/requires-4.c: New test.
* testsuite/libgomp.c-c++-common/requires-5-aux.c: New test.
* testsuite/libgomp.c-c++-common/requires-5.c: New test.
* testsuite/libgomp.c-c++-common/requires-6.c: New test.
* testsuite/libgomp.c-c++-common/requires-7-aux.c: New test.
* testsuite/libgomp.c-c++-common/requires-7.c: New test.
* testsuite/libgomp.fortran/requires-1-aux.f90: New test.
* testsuite/libgomp.fortran/requires-1.f90: New test.

liboffloadmic/ChangeLog:

* plugin/libgomp-plugin-intelmic.cpp (GOMP_OFFLOAD_get_num_devices):
Return -1 when device available but omp_requires_mask != 0.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/requires-4.c: Update dg-*.
* c-c++-common/gomp/reverse-offload-1.c: Likewise.
* c-c++-common/gomp/target-device-ancestor-2.c: Likewise.
* c-c++-common/gomp/target-device-ancestor-3.c: Likewise.
* c-c++-common/gomp/target-device-ancestor-4.c: Likewise.
* c-c++-common/gomp/target-device-ancestor-5.c: Likewise.
* gfortran.dg/gomp/target-device-ancestor-3.f90: Likewise.
* gfortran.dg/gomp/target-device-ancestor-4.f90: Likewise.
* gfortran.dg/gomp/target-device-ancestor-5.f90: Likewise.
* gfortran.dg/gomp/target-device-ancestor-2.f90: Likewise. Move
post-FE checks to ...
* gfortran.dg/gomp/target-device-ancestor-2a.f90: ... this new file.
* gfortran.dg/gomp/requires-8.f90: Update as we don't regard
'declare target' for the 'requires' usage requirement.

Co-authored-by: Chung-Lin Tang <cltang@codesourcery.com>
Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
3 years agoMerge branch 'releases/gcc-12' into devel/omp/gcc-12
Tobias Burnus [Tue, 5 Jul 2022 09:45:39 +0000 (11:45 +0200)] 
Merge branch 'releases/gcc-12' into devel/omp/gcc-12

Merge up to r12-8550-g92d1e271a92dff333314f18379e61d8b3d84d2bd (5th July 2022)

3 years agoOpenMP/Fortran: Add support for OpenMP 5.2 linear clause syntax
Tobias Burnus [Tue, 5 Jul 2022 09:38:01 +0000 (11:38 +0200)] 
OpenMP/Fortran: Add support for OpenMP 5.2 linear clause syntax

Fortran part to C/C++
commit r13-1002-g03b71406323ddc065b1d7837d8b43b17e4b048b5

gcc/fortran/ChangeLog:

* gfortran.h (gfc_omp_namelist): Update by creating 'linear' struct,
move 'linear_op' as 'op' to id and add 'old_modifier' to it.
* dump-parse-tree.cc (show_omp_namelist): Update accordingly.
* module.cc (mio_omp_declare_simd): Likewise.
* trans-openmp.cc (gfc_trans_omp_clauses): Likewise.
* openmp.cc (resolve_omp_clauses): Likewise; accept new-style
'val' modifier with do/simd.
(gfc_match_omp_clauses): Handle OpenMP 5.2 linear clause syntax.

libgomp/ChangeLog:

* libgomp.texi (OpenMP 5.2): Mark linear-clause change as 'Y'.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/linear-4.c: New test.
* gfortran.dg/gomp/linear-2.f90: New test.
* gfortran.dg/gomp/linear-3.f90: New test.
* gfortran.dg/gomp/linear-4.f90: New test.
* gfortran.dg/gomp/linear-5.f90: New test.
* gfortran.dg/gomp/linear-6.f90: New test.
* gfortran.dg/gomp/linear-7.f90: New test.
* gfortran.dg/gomp/linear-8.f90: New test.

Co-authored-by: Jakub Jelinek <jakub@redhat.com>
(cherry picked from commit c3297044f0055880dd23ffbf641aa3a5860197e1)

3 years agoOpenMP: Handle tofrom with target enter/exit data
Tobias Burnus [Tue, 5 Jul 2022 09:34:50 +0000 (11:34 +0200)] 
OpenMP: Handle tofrom with target enter/exit data

In 5.2, a map clause can be map-entering or map-exiting,
either containing 'tofrom'. The main reason for this is
permit 'map(x)' with 'omp target enter/exit data',
avoiding to specify 'to:/from:' explicitly. (OpenMP
defaults to 'tofrom'.)

gcc/c/ChangeLog:

* c-parser.cc (c_parser_omp_target_enter_data,
c_parser_omp_target_exit_data): Accept tofrom
map-type modifier but use 'to' / 'from' internally.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_omp_target_enter_data,
cp_parser_omp_target_exit_data): Accept tofrom
map-type modifier but use 'to' / 'from' internally.

gcc/fortran/ChangeLog:

* dump-parse-tree.cc (show_omp_namelist): For the map-type,
also handle the always modifer and release/delete.
* openmp.cc (resolve_omp_clauses): Accept tofrom
map-type modifier for target enter/exit data,
but use 'to' / 'from' internally.

libgomp/ChangeLog:

* libgomp.texi (OpenMP 5.2): Mark target enter/exit data
with fromto as implemented.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/target-data-2.c: New test.
* c-c++-common/gomp/target-data-3.c: New test.
* gfortran.dg/gomp/target-data-1.f90: New test.
* gfortran.dg/gomp/target-data-2.f90: New test.

(cherry picked from commit 9a668532fb19e7c57aa595a26ce3f0d95f9cbb1b)

3 years agogcn: Remove useless register keyword
Tobias Burnus [Tue, 5 Jul 2022 09:31:46 +0000 (11:31 +0200)] 
gcn: Remove useless register keyword

gcc/ChangeLog:

* config/gcn/gcn-protos.h (print_operand_address): Remove register
keyword on 'rtx addr' argument.

(cherry picked from commit 7780dc5b2d02785186583fc8eced3c9e3aec4552)

3 years agoamdgcn: test global constructors
Andrew Stubbs [Tue, 5 Jul 2022 09:30:26 +0000 (11:30 +0200)] 
amdgcn: test global constructors

The tests are disabled for historical reasons only.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp (check_effective_target_global_constructor):
Remove amdgcn.

(cherry picked from commit a1f8a3860fe5c83a023688c29636b5abe03db949)

3 years agoamdgcn: remove obsolete assembler workarounds
Andrew Stubbs [Tue, 5 Jul 2022 09:28:54 +0000 (11:28 +0200)] 
amdgcn: remove obsolete assembler workarounds

This nonsense is no longer required, now that the minimum supported
assembler version is LLVM 13.0.1.

gcc/ChangeLog:

* config/gcn/gcn.md (*movbi): Remove assembler bug workarounds.
(jump): Likewise.
(movdi_symbol_save_scc): Likewise.

(cherry picked from commit b06a282921c71bbc5cab69bc515804bd80f55e92)

3 years agoopenmp: Fix up get-mapped-ptr-1.{c,f90} tests
Jakub Jelinek [Tue, 5 Jul 2022 09:27:03 +0000 (11:27 +0200)] 
openmp: Fix up get-mapped-ptr-1.{c,f90} tests

On Tue, Jun 14, 2022 at 06:41:37PM +0200, Thomas Schwinge wrote:
> In an offloading configuration, I'm seeing:
>
>     PASS: libgomp.fortran/get-mapped-ptr-1.f90   -O  (test for excess errors)
>     [-PASS:-]{+FAIL:+} libgomp.fortran/get-mapped-ptr-1.f90   -O  execution test
>
> Does that one need similar treatment?

I assume not just that but libgomp.c-c++-common/get-mapped-ptr-1.c too?

It both needs the same treatment, and in the get-mapped-ptr-1.c
case there is even UB, while the Fortran version was using c_loc (q)
as the host pointer, in C/C++ it was using q which was value of
uninitialized pointer.

2022-06-15  Jakub Jelinek  <jakub@redhat.com>

* testsuite/libgomp.c-c++-common/get-mapped-ptr-1.c (main): Initialize
q to ddress of an automatic variable.  Use -5 instead of -1 in
omp_get_mapped_ptr call.  Add test with omp_initial_device.
* testsuite/libgomp.fortran/get-mapped-ptr-1.f90 (main): Use -5 instead
of -1 in omp_get_mapped_ptr call.  Add test with omp_initial_device.
Renumber stop arguments afterwards.

(cherry picked from commit 7bfb3f488a7ec58109a859c66bf4eddc6354065b)

3 years agoopenmp: Conforming device numbers and omp_{initial,invalid}_device
Jakub Jelinek [Tue, 5 Jul 2022 09:22:20 +0000 (11:22 +0200)] 
openmp: Conforming device numbers and omp_{initial,invalid}_device

OpenMP 5.2 changed once more what device numbers are allowed.
In 5.1, valid device numbers were [0, omp_get_num_devices()].
5.2 makes also -1 valid (calls it omp_initial_device), which is equivalent
in behavior to omp_get_num_devices() number but has the advantage that it
is a constant.  And it also introduces omp_invalid_device which is
also a constant with implementation defined value < -1.  That value should
act like sNaN, any time any device construct (GOMP_target*) or OpenMP runtime
API routine is asked for such a device, the program is terminated.
And if OMP_TARGET_OFFLOAD=mandatory, all non-conforming device numbers (which
is all but [-1, omp_get_num_devices()] other than omp_invalid_device)
must be treated like omp_invalid_device.

For device constructs, we have a compatibility problem, we've historically
used 2 magic negative values to mean something special.
GOMP_DEVICE_ICV (-1) means device clause wasn't present, pick the
     omp_get_default_device () number
GOMP_DEVICE_FALLBACK (-2) means the host device (this is used e.g. for
  #pragma omp target if (cond)
  where if cond is false, we pass -2
But 5.2 requires that omp_initial_device is -1 (there were discussions
about it, advantage of -1 is that one can say iterate over the
[-1, omp_get_num_devices()-1] range to get all devices starting with
the host/initial one.
And also, if user passes -2, unless it is omp_invalid_device, we need to
treat it like non-conforming with OMP_TARGET_OFFLOAD=mandatory.

So, the patch does on the compiler side some number remapping,
user_device_num >= -2U ? user_device_num - 1 : user_device_num.
This remapping is done at compile time if device clause has constant
argument, otherwise at runtime, and means that for user -1 (omp_initial_device)
we pass -2 to GOMP_* in the runtime library where it treats it like host
fallback, while -2 is remapped to -3 (one of the non-conforming device numbers,
for those it doesn't matter which one is which).
omp_invalid_device is then -4.
For the OpenMP device runtime APIs, no remapping is done.

This patch doesn't deal with the initial default-device-var for
OMP_TARGET_OFFLOAD=mandatory , the spec says that the inital ICV value
for that should in that case depend on whether there are any offloading
devices or not (if not, should be omp_invalid_device), but that means
we can't determine the number of devices lazily (and let libraries have the
possibility to register their offloading data etc.).

2022-06-13  Jakub Jelinek  <jakub@redhat.com>

gcc/
* omp-expand.cc (expand_omp_target): Remap user provided
device clause arguments, -1 to -2 and -2 to -3, either
at compile time if constant, or at runtime.
include/
* gomp-constants.h (GOMP_DEVICE_INVALID): Define.
libgomp/
* omp.h.in (omp_initial_device, omp_invalid_device): New enumerators.
* omp_lib.f90.in (omp_initial_device, omp_invalid_device): New
parameters.
* omp_lib.h.in (omp_initial_device, omp_invalid_device): Likewise.
* target.c (resolve_device): Add remapped argument, handle
GOMP_DEVICE_ICV only if remapped is true (and clear remapped),
for negative values, treat GOMP_DEVICE_FALLBACK as fallback only
if remapped, otherwise treat omp_initial_device that way.  For
omp_invalid_device, always emit gomp_fatal, even when
OMP_TARGET_OFFLOAD isn't mandatory.
(GOMP_target, GOMP_target_ext, GOMP_target_data, GOMP_target_data_ext,
GOMP_target_update, GOMP_target_update_ext,
GOMP_target_enter_exit_data): Pass true as remapped argument to
resolve_device.
(omp_target_alloc, omp_target_free, omp_target_is_present,
omp_target_memcpy_check, omp_target_associate_ptr,
omp_target_disassociate_ptr, omp_get_mapped_ptr,
omp_target_is_accessible): Pass false as remapped argument to
resolve_device.  Treat omp_initial_device the same as
gomp_get_num_devices ().  Don't bypass resolve_device calls if
device_num is negative.
(omp_pause_resource): Treat omp_initial_device the same as
gomp_get_num_devices ().  Call resolve_device.
* icv-device.c (omp_set_default_device): Always set to device_num
even when it is negative.
* libgomp.texi: Document that Conforming device numbers,
omp_initial_device and omp_invalid_device is implemented.
* testsuite/libgomp.c/target-41.c (main): Add test with
omp_initial_device.
* testsuite/libgomp.c/target-45.c: New test.
* testsuite/libgomp.c/target-46.c: New test.
* testsuite/libgomp.c/target-47.c: New test.
* testsuite/libgomp.c-c++-common/target-is-accessible-1.c (main): Add
test with omp_initial_device.  Use -5 instead of -1 for negative value
test.
* testsuite/libgomp.fortran/target-is-accessible-1.f90 (main):
Likewise.  Reorder stop numbers.

(cherry picked from commit 1158fe43407568f20415b16575ddbfff216bf8b6)

3 years agoOpenMP: Handle ancestor:1 with discover_declare_target
Tobias Burnus [Tue, 5 Jul 2022 09:18:23 +0000 (11:18 +0200)] 
OpenMP: Handle ancestor:1 with discover_declare_target

gcc/
* omp-offload.cc (omp_discover_declare_target_tgt_fn_r,
omp_discover_declare_target_fn_r): Don't walk reverse-offload
target regions.

gcc/testsuite/
* c-c++-common/gomp/reverse-offload-1.c: New.

(cherry picked from commit 209de00fdb9da90a727337d6e752ea583a11d982)

3 years agoOpenMP: Fortran - fix ancestor's requires reverse_offload check
Tobias Burnus [Tue, 5 Jul 2022 09:16:43 +0000 (11:16 +0200)] 
OpenMP: Fortran - fix ancestor's requires reverse_offload check

gcc/fortran/

* openmp.cc (gfc_match_omp_clauses): Check also parent namespace
for 'requires reverse_offload'.

gcc/testsuite/

* gfortran.dg/gomp/target-device-ancestor-5.f90: New test.

(cherry picked from commit 5e5deac508e3025e2d2c36212aa52d52001b893d)

3 years agoopenmp: Add support for OpenMP 5.2 linear clause syntax for C/C++
Jakub Jelinek [Tue, 5 Jul 2022 09:15:15 +0000 (11:15 +0200)] 
openmp: Add support for OpenMP 5.2 linear clause syntax for C/C++

The syntax for linear clause changed in 5.2, the original syntax
which is still valid is:
linear (var1, var2)
linear (var3, var4 : step1)
The 4.5 syntax with modifiers like:
linear (val (var5, var6))
linear (val (var7, var8) : step2)
is still supported in 5.2, but is deprecated there.
Instead, one can use a new syntax:
linear (var9, var10 : val)
linear (var11, var12 : step (step3), val)
As val, ref, uval or step (someexpr) can be valid expressions (and especially
in C++ can be const / constexpr / consteval), the spec says that
when the whole step expression is val (or ref or uval) or step ( ... )
then it is the new modifier syntax, one can use + 0 or 0 + or 1 * or * 1
or ()s to say it is the old step expression.
Also, 5.2 now allows val modifier to be specified even outside of declare simd
(but not the other modifiers).  I've implemented this for the new modifier
syntax only, the old one keeps the old restriction (which is why
OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER flag has been introduced).

2022-06-07  Jakub Jelinek  <jakub@redhat.com>

gcc/
* tree.h (OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER): Define.
* tree-pretty-print.cc (dump_omp_clause) <case OMP_CLAUSE_LINEAR>:
Adjust clause printing style depending on
OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER.
gcc/c/
* c-parser.cc (c_parser_omp_clause_linear): Parse OpenMP 5.2
style linear clause modifiers.  Set
OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER flag on the clauses when
old style modifiers are used.
* c-typeck.cc (c_finish_omp_clauses): Only reject linear clause
with val modifier on simd or for if the old style modifiers are
used.
gcc/cp/
* parser.cc (cp_parser_omp_clause_linear): Parse OpenMP 5.2
style linear clause modifiers.  Set
OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER flag on the clauses when
old style modifiers are used.
* semantics.cc (finish_omp_clauses): Only reject linear clause
with val modifier on simd or for if the old style modifiers are
used.
gcc/fortran/
* trans-openmp.cc (gfc_trans_omp_clauses): Set
OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER on OMP_CLAUSE_LINEAR
clauses unconditionally for now.
gcc/testsuite/
* c-c++-common/gomp/linear-2.c: New test.
* c-c++-common/gomp/linear-3.c: New test.
* g++.dg/gomp/linear-3.C: New test.
* g++.dg/gomp/linear-4.C: New test.
* g++.dg/gomp/linear-5.C: New test.

(cherry picked from commit 03b71406323ddc065b1d7837d8b43b17e4b048b5)

3 years agoarm: reinstate HAVE_GAS_ARM_EXTENDED_ARCH
Andrew Stubbs [Tue, 5 Jul 2022 09:11:54 +0000 (11:11 +0200)] 
arm: reinstate HAVE_GAS_ARM_EXTENDED_ARCH

The check was removed by accident.

gcc/ChangeLog:

* config.in: Regenerate.
* configure: Regenerate.
* configure.ac: Reinstate HAVE_GAS_ARM_EXTENDED_ARCH test.

(cherry picked from commit 36bd6eafb6062f1fb92a994538c6ed017ced670b)

3 years agogfortran.dg/gomp/scope-6.f90: Add \\ to scan-tree-dump
Tobias Burnus [Tue, 5 Jul 2022 08:09:23 +0000 (10:09 +0200)] 
gfortran.dg/gomp/scope-6.f90: Add \\ to scan-tree-dump

Missed git add for the hot fix before committing
r13-982-gff35a75473d28205e52ecbcf9e6b5107b8b5ab90

gcc/testsuite/
* gfortran.dg/gomp/scope-6.f90: Fix dg-final scan-tree-dump.

(cherry picked from commit 6a098f4e16351617ebbb9ad66fb802e8c4a57c77)

3 years agoOpenMP/Fortran: Add support for firstprivate and allocate clauses on scope construct
Tobias Burnus [Tue, 5 Jul 2022 08:03:25 +0000 (10:03 +0200)] 
OpenMP/Fortran: Add support for firstprivate and allocate clauses on scope construct

Fortran commit to C/C++/backend commit
r13-862-gf38b20d68fade5a922b9f68c4c3841e653d1b83c

gcc/fortran/ChangeLog:

* openmp.cc (OMP_SCOPE_CLAUSES): Add firstprivate and allocate.

libgomp/ChangeLog:

* libgomp.texi (OpenMP 5.2): Mark scope w/ firstprivate/allocate as Y.
* testsuite/libgomp.fortran/scope-2.f90: New test.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/scope-5.f90: New test.
* gfortran.dg/gomp/scope-6.f90: New test.

(cherry picked from commit ff35a75473d28205e52ecbcf9e6b5107b8b5ab90)

3 years agoopenmp: Add support for firstprivate and allocate clauses on scope construct
Jakub Jelinek [Tue, 5 Jul 2022 08:01:09 +0000 (10:01 +0200)] 
openmp: Add support for firstprivate and allocate clauses on scope construct

OpenMP 5.2 adds support for firstprivate and allocate clauses on the scope
construct and this patch adds that support to GCC.
5.2 unfortunately (IMNSHO mistakenly) marked scope construct as worksharing,
which implies that it isn't possible to nest inside of it other scope,
worksharing loop, sections, explicit barriers, single etc. which would
make scope far less useful.  I'm not implementing that part, keeping the
5.1 behavior here, and will file an issue to revert that for OpenMP 6.0.
But, for firstprivate it keeps the restriction that is now implied from
worksharing construct that listed var can't be private in outer context,
where for reduction 5.1 had similar restriction explicit even for scope
and 5.2 has it implicitly through worksharing construct.

2022-05-31  Jakub Jelinek  <jakub@redhat.com>

gcc/
* omp-low.cc (build_outer_var_ref): For code == OMP_CLAUSE_ALLOCATE
allow var to be private in the outer context.
(lower_private_allocate): Pass OMP_CLAUSE_ALLOCATE as last argument
to build_outer_var_ref.
gcc/c/
* c-parser.cc (OMP_SCOPE_CLAUSE_MASK): Add firstprivate and allocate
clauses.
gcc/cp/
* parser.cc (OMP_SCOPE_CLAUSE_MASK): Add firstprivate and allocate
clauses.
gcc/testsuite/
* c-c++-common/gomp/scope-5.c: New test.
* c-c++-common/gomp/scope-6.c: New test.
* g++.dg/gomp/attrs-1.C (bar): Add firstprivate and allocate clauses
to scope construct.
* g++.dg/gomp/attrs-2.C (bar): Likewise.
libgomp/
* testsuite/libgomp.c-c++-common/allocate-1.c (foo): Add testcase for
scope construct with allocate clause.
* testsuite/libgomp.c-c++-common/allocate-3.c (foo): Likewise.
* testsuite/libgomp.c-c++-common/scope-2.c: New test.

(cherry picked from commit f38b20d68fade5a922b9f68c4c3841e653d1b83c)

3 years agoOpenMP/Fortran: Add support for enter clause on declare target
Tobias Burnus [Tue, 5 Jul 2022 07:54:48 +0000 (09:54 +0200)] 
OpenMP/Fortran: Add support for enter clause on declare target

Fortran version to C/C++ commit r13-797-g0ccba4ed8571c18c7015413441e971

gcc/fortran/ChangeLog:

* dump-parse-tree.cc (show_omp_clauses): Handle OMP_LIST_ENTER.
* gfortran.h: Add OMP_LIST_ENTER.
* openmp.cc (enum omp_mask2, OMP_DECLARE_TARGET_CLAUSES): Add
OMP_CLAUSE_ENTER.
(gfc_match_omp_clauses, gfc_match_omp_declare_target,
resolve_omp_clauses): Handle 'enter' clause.

libgomp/ChangeLog:

* libgomp.texi (OpenMP 5.2): Mark 'enter' clause as supported.
* testsuite/libgomp.fortran/declare-target-1.f90: Extend to test
explicit 'to' and 'enter' clause.
* testsuite/libgomp.fortran/declare-target-2.f90: Update accordingly.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/declare-target-2.f90: Add 'enter' clause test.
* gfortran.dg/gomp/declare-target-4.f90: Likewise.

(cherry picked from commit e3803f9cbb67efef7462589fe50d00b404356bc9)

3 years agoopenmp: Adjust diagnostics about same variable in link and to/enter clauses
Jakub Jelinek [Tue, 5 Jul 2022 07:29:23 +0000 (09:29 +0200)] 
openmp: Adjust diagnostics about same variable in link and to/enter clauses

On Fri, May 27, 2022 at 04:52:17PM +0200, Tobias Burnus wrote:
> The 'TO'/'ENTER' usage is first stored in a linked list – and
> then as attribute to the symbol. I am not sure how to handle it best.

This reminds me I've left the C/C++ FE diagnostics about mixing link and
to/enter on the same variable in separate directives as is, so it always
talked about mixing link and to clauses.

This patch adjusts it, so that if link is first, it talks about the
clause actually used and if link is later, uses to or enter together
in the wording.

2022-05-28  Jakub Jelinek  <jakub@redhat.com>

gcc/c/
* c-parser.cc (c_parser_omp_declare_target): If OMP_CLAUSE_LINK was
seen first, use "%<to%>" or "%<enter%>" depending on
OMP_CLAUSE_ENTER_TO of the current clause, otherwise use
"%<to%> or %<enter%>" wording.
gcc/cp/
* parser.cc (handle_omp_declare_target_clause): If OMP_CLAUSE_LINK was
seen first, use "%<to%>" or "%<enter%>" depending on
OMP_CLAUSE_ENTER_TO of the current clause, otherwise use
"%<to%> or %<enter%>" wording.
gcc/testsuite/
* c-c++-common/gomp/declare-target-2.c: Add further tests for mixing of
link and to/enter clauses on separate directives.

(cherry picked from commit 931249276acb4bdab778fe2bf4e81a1a31a78e6c)

3 years agoopenmp: Add support for enter clause on declare target
Jakub Jelinek [Tue, 5 Jul 2022 07:27:36 +0000 (09:27 +0200)] 
openmp: Add support for enter clause on declare target

OpenMP 5.1 and earlier had 2 different uses of to clause, one for target
update construct with one semantics, and one for declare target directive
with a different semantics.
Under the hood we were using OMP_CLAUSE_TO_DECLARE to represent the latter.
OpenMP 5.2 renamed the declare target clause to to enter, the old one is
kept as a deprecated alias.

As we are far from having full OpenMP 5.2 support, this patch adds support
for the enter clause (and renames OMP_CLAUSE_TO_DECLARE to OMP_CLAUSE_ENTER
with a flag to tell the spelling of the clause for better diagnostics),
but doesn't deprecate the to clause on declare target just yet (that
should be done as one of the last steps in 5.2 support).

2022-05-27  Jakub Jelinek  <jakub@redhat.com>

gcc/
* tree-core.h (enum omp_clause_code): Rename OMP_CLAUSE_TO_DECLARE
to OMP_CLAUSE_ENTER.
* tree.h (OMP_CLAUSE_ENTER_TO): Define.
* tree.cc (omp_clause_num_ops, omp_clause_code_name): Rename
OMP_CLAUSE_TO_DECLARE to OMP_CLAUSE_ENTER.
* tree-pretty-print.cc (dump_omp_clause): Handle OMP_CLAUSE_ENTER
instead of OMP_CLAUSE_TO_DECLARE, if OMP_CLAUSE_ENTER_TO, print
"to" instead of "enter".
* tree-nested.cc (convert_nonlocal_omp_clauses,
convert_local_omp_clauses): Handle OMP_CLAUSE_ENTER instead of
OMP_CLAUSE_TO_DECLARE.
gcc/c-family/
* c-pragma.h (enum pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_ENTER.
gcc/c/
* c-parser.cc (c_parser_omp_clause_name): Parse enter clause.
(c_parser_omp_all_clauses): For to clause on declare target, use
OMP_CLAUSE_ENTER clause with OMP_CLAUSE_ENTER_TO instead of
OMP_CLAUSE_TO_DECLARE clause.  Handle PRAGMA_OMP_CLAUSE_ENTER.
(OMP_DECLARE_TARGET_CLAUSE_MASK): Add enter clause.
(c_parser_omp_declare_target): Use OMP_CLAUSE_ENTER instead of
OMP_CLAUSE_TO_DECLARE.
* c-typeck.cc (c_finish_omp_clauses): Handle OMP_CLAUSE_ENTER instead
of OMP_CLAUSE_TO_DECLARE, to OMP_CLAUSE_ENTER_TO use "to" as clause
name in diagnostics instead of
omp_clause_code_name[OMP_CLAUSE_CODE (c)].
gcc/cp/
* parser.cc (cp_parser_omp_clause_name): Parse enter clause.
(cp_parser_omp_all_clauses): For to clause on declare target, use
OMP_CLAUSE_ENTER clause with OMP_CLAUSE_ENTER_TO instead of
OMP_CLAUSE_TO_DECLARE clause.  Handle PRAGMA_OMP_CLAUSE_ENTER.
(OMP_DECLARE_TARGET_CLAUSE_MASK): Add enter clause.
(cp_parser_omp_declare_target): Use OMP_CLAUSE_ENTER instead of
OMP_CLAUSE_TO_DECLARE.
* semantics.cc (finish_omp_clauses): Handle OMP_CLAUSE_ENTER instead
of OMP_CLAUSE_TO_DECLARE, to OMP_CLAUSE_ENTER_TO use "to" as clause
name in diagnostics instead of
omp_clause_code_name[OMP_CLAUSE_CODE (c)].
gcc/testsuite/
* c-c++-common/gomp/clauses-3.c: Add tests with enter clause instead
of to or modify some existing to clauses to enter.
* c-c++-common/gomp/declare-target-1.c: Likewise.
* c-c++-common/gomp/declare-target-2.c: Likewise.
* c-c++-common/gomp/declare-target-3.c: Likewise.
* g++.dg/gomp/attrs-9.C: Likewise.
* g++.dg/gomp/declare-target-1.C: Likewise.
libgomp/
* testsuite/libgomp.c-c++-common/target-40.c: Modify some existing to
clauses to enter.
* testsuite/libgomp.c/target-41.c: Likewise.

(cherry picked from commit 0ccba4ed8571c18c7015413441e971d4863c3644)

3 years agolibgomp.texi: Add more to-be-implemented OpenMP 5.2 features
Tobias Burnus [Tue, 5 Jul 2022 07:23:13 +0000 (09:23 +0200)] 
libgomp.texi: Add more to-be-implemented OpenMP 5.2 features

libgomp/
* libgomp.texi (Other new OpenMP 5.1 features): Add
'begin declare target'.
(Other new OpenMP 5.2 features): New.

(cherry picked from commit 8255b49ed8ab37fd61d85bb48f97c618f05a8392)

3 years agoGCN: Add gfx908/gfx90a to -march/-mtune in invoke.texi
Tobias Burnus [Tue, 5 Jul 2022 07:22:06 +0000 (09:22 +0200)] 
GCN: Add gfx908/gfx90a to -march/-mtune in invoke.texi

gcc/
* doc/invoke.texi (AMD GCN Options): Add gfx908/gfx90a.

(cherry picked from commit 2a790686fd11bc90032ff67c996c5a2752305625)

3 years agolibgomp: Fix occassional hangs with taskwait nowait depend
Jakub Jelinek [Tue, 5 Jul 2022 07:19:47 +0000 (09:19 +0200)] 
libgomp: Fix occassional hangs with taskwait nowait depend

Richi reported occassional hangs with taskwait-depend-nowait-1.*
tests and I've finally manged to reproduce.  The problem is if
taskwait depend without nowait is encountered soon after
taskwait depend nowait and the former depends on the latter and there
is no other work to do, the taskwait depend without nowait is put
to sleep, but the empty_task optimization in
gomp_task_run_post_handle_dependers wouldn't wake it up in that
case.  gomp_task_run_post_handle_dependers normally does some wakeups
because it schedules more work (another task), which is not the
case of empty_task, but we need to do the wakeups that would be done
upon task completion so that we awake sleeping threads when the
last child is done.
So, the taskwait-depend-nowait-1.* testcase is fixed with the
else if (__builtin_expect (task->parent_depends_on, 0) part of
the patch.
The new testcase can hang on another problem, if the empty task
is the last task of a taskgroup, we need to use atomic store
like elsewhere to decrease the counter to 0, and wake up taskgroup
end if needed.
Yet another spot which can sleep is normal taskwait (without depend),
but I believe nothing needs to be done for that - in that case we
await solely until the children's queue has no tasks, tasks still
waiting for dependencies aren't accounted in that, but the reason
is that if taskwait should wait for something, there needs to be at least
one active child doing something (in the children queue), which then
possibly awakes some of its siblings when the dependencies are met,
or in the empty task case awakes further dependencies, but in any
case the child that finished is still handled as active child and
will awake taskwait at the end if there is nothing further to
do.
Last sleeping case are barriers, but that is handled by ++ret and
awaking the barrier.

2022-05-25  Jakub Jelinek  <jakub@redhat.com>

* task.c (gomp_task_run_post_handle_dependers): If empty_task
is the last task taskwait depend depends on, wake it up.
Similarly if it is the last child of a taskgroup, use atomic
store instead of decrement and awak taskgroup wait if any.
* testsuite/libgomp.c-c++-common/taskwait-depend-nowait-2.c: New test.

(cherry picked from commit c125f504c43a1d863b040375872b6696a6c2b681)

3 years agoOpenMP: Support nowait with Fortran [PR105378]
Tobias Burnus [Tue, 5 Jul 2022 07:18:13 +0000 (09:18 +0200)] 
OpenMP: Support nowait with Fortran [PR105378]

Fortran part to C/C++/libgomp
commit r13-724-gb43836914bdc2a37563cf31359b2c4803bfe4374

gcc/fortran/

PR c/105378
* openmp.cc (gfc_match_omp_taskwait): Accept nowait.

gcc/testsuite/

PR c/105378
* gfortran.dg/gomp/taskwait-depend-nowait-1.f90: New.

libgomp/

PR c/105378
* libgomp.texi (OpenMP 5.1): Set 'taskwait nowait' to 'Y'.
* testsuite/libgomp.fortran/taskwait-depend-nowait-1.f90: New.

(cherry picked from commit 4fb2b4f7ea6b80ae75d3efb6f86e7c6179080535)

3 years agoopenmp: Add taskwait nowait depend support [PR105378]
Jakub Jelinek [Tue, 5 Jul 2022 07:11:46 +0000 (09:11 +0200)] 
openmp: Add taskwait nowait depend support [PR105378]

This patch adds support for (so far C/C++)
  #pragma omp taskwait nowait depend(...)
directive, which is like
  #pragma omp task depend(...)
  ;
but slightly optimized on the library side, so that it creates
the task only for the purpose of dependency tracking and doesn't actually
schedule it and wait for it when the dependencies are satisfied, instead
makes its dependencies satisfied right away.

2022-05-24  Jakub Jelinek  <jakub@redhat.com>

PR c/105378
gcc/
* omp-builtins.def (BUILT_IN_GOMP_TASKWAIT_DEPEND_NOWAIT): New
builtin.
* gimplify.cc (gimplify_omp_task): Diagnose taskwait with nowait
clause but no depend clauses.
* omp-expand.cc (expand_taskwait_call): Use
BUILT_IN_GOMP_TASKWAIT_DEPEND_NOWAIT rather than
BUILT_IN_GOMP_TASKWAIT_DEPEND if nowait clause is present.
gcc/c/
* c-parser.cc (OMP_TASKWAIT_CLAUSE_MASK): Add nowait clause.
gcc/cp/
* parser.cc (OMP_TASKWAIT_CLAUSE_MASK): Add nowait clause.
gcc/testsuite/
* c-c++-common/gomp/taskwait-depend-nowait-1.c: New test.
libgomp/
* libgomp_g.h (GOMP_taskwait_depend_nowait): Declare.
* libgomp.map (GOMP_taskwait_depend_nowait): Export at GOMP_5.1.1.
* task.c (empty_task): New function.
(gomp_task_run_post_handle_depend_hash): Declare earlier.
(gomp_task_run_post_handle_depend): Declare.
(GOMP_task): Optimize fn == empty_task if there is nothing to wait
for.
(gomp_task_run_post_handle_dependers): Optimize task->fn == empty_task.
(GOMP_taskwait_depend_nowait): New function.
* testsuite/libgomp.c-c++-common/taskwait-depend-nowait-1.c: New test.

(cherry picked from commit b43836914bdc2a37563cf31359b2c4803bfe4374)

3 years agolibgomp: Add new runtime routines omp_target_memcpy_async and omp_target_memcpy_rect_...
Marcel Vollweiler [Tue, 5 Jul 2022 06:50:02 +0000 (08:50 +0200)] 
libgomp: Add new runtime routines omp_target_memcpy_async and omp_target_memcpy_rect_async

This patch adds two new OpenMP runtime routines: omp_target_memcpy_async and
omp_target_memcpy_rect_async. Both functions are introduced in OpenMP 5.1 as
asynchronous variants of omp_target_memcpy and omp_target_memcpy_rect.

In contrast to the synchronous variants, the asynchronous functions have two
additional function parameters to allow the specification of task dependences:

int depobj_count
omp_depend_t *depobj_list

integer(c_int), value :: depobj_count
integer(omp_depend_kind), optional :: depobj_list(*)

The implementation splits the synchronous functions into two parts: (a) check
and (b) copy. Then (a) is used in the asynchronous functions for the sequential
part, and the actual copy process (b) is executed in a new created task. The
sequential part (a) takes into account the requirements for the return values:

"The routine returns zero if successful. Otherwise, it returns a non-zero
value." (omp_target_memcpy_async, OpenMP 5.1 spec, section 3.8.7)

"An application can determine the number of inclusive dimensions supported by an
implementation by passing NULL pointers (or C_NULL_PTR, for Fortran) for both
dst and src. The routine returns the number of dimensions supported by the
implementation for the specified device numbers. No copy operation is
performed." (omp_target_memcpy_rect_async, OpenMP 5.1 spec, section 3.8.8)

Due to asynchronicity an error is thrown if the asynchronous memcpy is not
successful (in contrast to the synchronous functions which use a return
value unequal to zero).

gcc/ChangeLog:

* omp-low.cc (omp_runtime_api_call): Added target_memcpy_async and
target_memcpy_rect_async to omp_runtime_apis array.

libgomp/ChangeLog:

* libgomp.map: Added omp_target_memcpy_async and
omp_target_memcpy_rect_async.
* libgomp.texi: Both functions are now supported.
* omp.h.in: Added omp_target_memcpy_async and
omp_target_memcpy_rect_async.
* omp_lib.f90.in: Added interfaces for both new functions.
* omp_lib.h.in: Likewise.
* target.c (ialias_redirect): Added for GOMP_task.
(omp_target_memcpy): Restructured into check and copy part.
(omp_target_memcpy_check): New helper function for omp_target_memcpy and
omp_target_memcpy_async that checks requirements.
(omp_target_memcpy_copy): New helper function for omp_target_memcpy and
omp_target_memcpy_async that performs the memcpy.
(omp_target_memcpy_async_helper): New helper function that is used in
omp_target_memcpy_async for the asynchronous task.
(omp_target_memcpy_async): Added.
(omp_target_memcpy_rect): Restructured into check and copy part.
(omp_target_memcpy_rect_check): New helper function for
omp_target_memcpy_rect and omp_target_memcpy_rect_async that checks
requirements.
(omp_target_memcpy_rect_copy): New helper function for
omp_target_memcpy_rect and omp_target_memcpy_rect_async that performs
the memcpy.
(omp_target_memcpy_rect_async_helper): New helper function that is used
in omp_target_memcpy_rect_async for the asynchronous task.
(omp_target_memcpy_rect_async): Added.
* task.c (ialias): Added for GOMP_task.
* testsuite/libgomp.c-c++-common/target-memcpy-async-1.c: New test.
* testsuite/libgomp.c-c++-common/target-memcpy-async-2.c: New test.
* testsuite/libgomp.c-c++-common/target-memcpy-rect-async-1.c: New test.
* testsuite/libgomp.c-c++-common/target-memcpy-rect-async-2.c: New test.
* testsuite/libgomp.fortran/target-memcpy-async-1.f90: New test.
* testsuite/libgomp.fortran/target-memcpy-async-2.f90: New test.
* testsuite/libgomp.fortran/target-memcpy-rect-async-1.f90: New test.
* testsuite/libgomp.fortran/target-memcpy-rect-async-2.f90: New test.

(cherry picked from commit 6c420193e86b39a09304b2845335571eefe24d5d)

3 years ago'include/cuda/cuda.h': Add parts necessary for nvptx-tools 'nvptx-run'
Thomas Schwinge [Tue, 5 Jul 2022 06:46:17 +0000 (08:46 +0200)] 
'include/cuda/cuda.h': Add parts necessary for nvptx-tools 'nvptx-run'

include/
* cuda/cuda.h (enum CUjit_option): Add
'CU_JIT_GENERATE_DEBUG_INFO', 'CU_JIT_GENERATE_LINE_INFO'.
(enum CUlimit): Add 'CU_LIMIT_STACK_SIZE',
'CU_LIMIT_MALLOC_HEAP_SIZE'.
(cuCtxSetLimit, cuGetErrorName): Add.

(cherry picked from commit 86f64400a5692499856d41462461327b93f82b8d)

3 years ago'include/cuda/cuda.h': For C++, wrap in 'extern "C"'
Thomas Schwinge [Tue, 5 Jul 2022 06:41:50 +0000 (08:41 +0200)] 
'include/cuda/cuda.h': For C++, wrap in 'extern "C"'

include/
* cuda/cuda.h: For C++, wrap in 'extern "C"'.

(cherry picked from commit bdd1dc1bfbe1492edf3ce5e4288cfbc55be329ab)

3 years agoOpenMP: Add Fortran support for inoutset depend-kind
Tobias Burnus [Tue, 5 Jul 2022 06:39:29 +0000 (08:39 +0200)] 
OpenMP: Add Fortran support for inoutset depend-kind

Fortran additions to the C/C++ + ME/libgomp commit
r13-556-g2c16eb3157f86ae561468c540caf8eb326106b5f

gcc/fortran/ChangeLog:

* gfortran.h (enum gfc_omp_depend_op): Add OMP_DEPEND_INOUTSET.
(gfc_omp_clauses): Enlarge ENUM_BITFIELD.
* dump-parse-tree.cc (show_omp_namelist, show_omp_clauses): Handle
'inoutset' depend modifier.
* openmp.cc (gfc_match_omp_clauses, gfc_match_omp_depobj): Likewise.
* trans-openmp.cc (gfc_trans_omp_clauses, gfc_trans_omp_depobj):
Likewise.

libgomp/ChangeLog:

* libgomp.texi (OpenMP 5.1): Set 'inoutset' to Y.
(OpenMP Context Selectors): Add missing comma.
* testsuite/libgomp.fortran/depend-5.f90: Add inoutset test.
* testsuite/libgomp.fortran/depend-6.f90: Likewise.
* testsuite/libgomp.fortran/depend-7.f90: Likewise.
* testsuite/libgomp.fortran/depend-inoutset-1.f90: New test.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/all-memory-1.f90: Add inoutset test.
* gfortran.dg/gomp/all-memory-2.f90: Likewise.
* gfortran.dg/gomp/depobj-1.f90: Likewise.
* gfortran.dg/gomp/depobj-2.f90: Likewise.

(cherry picked from commit ba8563693fb4eb1317fcbd54883516c3873782f4)

3 years agoOpenMP: Skip target-nesting warning for reverse offload
Tobias Burnus [Tue, 5 Jul 2022 06:36:42 +0000 (08:36 +0200)] 
OpenMP: Skip target-nesting warning for reverse offload

gcc/ChangeLog:

* omp-low.cc (check_omp_nesting_restrictions): Skip warning for
target inside target if inner is reverse offload.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/target-device-ancestor-5.c: New test.

(cherry picked from commit 47554478a13f64bff1ee4b9bb0319ae63d42ca52)

3 years agoDaily bump.
GCC Administrator [Tue, 5 Jul 2022 00:19:34 +0000 (00:19 +0000)] 
Daily bump.

3 years agolibgomp.texi: Document OpenMP context selectors
Tobias Burnus [Mon, 4 Jul 2022 19:45:43 +0000 (21:45 +0200)] 
libgomp.texi: Document OpenMP context selectors

libgomp/
* libgomp.texi (Offload-Target Specifics): New chapter; add section
to document OpenMP context selectors.

(cherry picked from commit 61fe7b7d463f2f6bbeb175c345a68b844b396d56)

3 years agogcn/t-omp-device: Add 'amdgcn' as 'arch' [PR105602]
Tobias Burnus [Mon, 4 Jul 2022 19:42:42 +0000 (21:42 +0200)] 
gcn/t-omp-device: Add 'amdgcn' as 'arch' [PR105602]

Improve cross-compiler handling.

gcc/ChangeLog:

PR target/105602
* config/gcn/t-omp-device (arch): Add 'amdgcn' besides existing 'gcn'.
* config/gcn/gcn.cc (gcn_omp_device_kind_arch_isa): Likewise.

(cherry picked from commit ebe5dace8c318b38f42cfe1d148e90dcdfadb31e)

3 years agoopenmp: Add support for inoutset depend-kind
Jakub Jelinek [Mon, 4 Jul 2022 19:32:48 +0000 (21:32 +0200)] 
openmp: Add support for inoutset depend-kind

This patch adds support for inoutset depend-kind in depend
clauses.  It is very similar to the in depend-kind in that
a task with a dependency with that depend-kind is dependent
on all previously created sibling tasks with matching address
unless they have the same depend-kind.
In the in depend-kind case everything is dependent except
for in -> in dependency, for inoutset everything is
dependent except for inoutset -> inoutset dependency.
mutexinoutset is also similar (everything is dependent except
for mutexinoutset -> mutexinoutset dependency), but there is
also the additional restriction that only one task with
mutexinoutset for each address can be scheduled at once (i.e.
mutual exclusitivty).  For now we support mutexinoutset
the same as inout/out, but the inoutset support is full.

In order not to bump the ABI for dependencies each time
(we've bumped it already once, the old ABI supports only
inout/out and in depend-kind, the new ABI supports
inout/out, mutexinoutset, in and depobj), this patch arranges
for inoutset to be at least for the time being always handled
as if it was specified through depobj even when it is not.
So it uses the new ABI for that and inoutset are represented
like depobj - pointer to a pair of pointers where the first one
will be the actual address of the object mentioned in depend
clause and second pointer will be (void *) GOMP_DEPEND_INOUTSET.

2022-05-17  Jakub Jelinek  <jakub@redhat.com>

gcc/
* tree-core.h (enum omp_clause_depend_kind): Add
OMP_CLAUSE_DEPEND_INOUTSET.
* tree-pretty-print.cc (dump_omp_clause): Handle
OMP_CLAUSE_DEPEND_INOUTSET.
* gimplify.cc (gimplify_omp_depend): Likewise.
* omp-low.cc (lower_depend_clauses): Likewise.
gcc/c-family/
* c-omp.cc (c_finish_omp_depobj): Handle
OMP_CLAUSE_DEPEND_INOUTSET.
gcc/c/
* c-parser.cc (c_parser_omp_clause_depend): Parse
inoutset depend-kind.
(c_parser_omp_depobj): Likewise.
gcc/cp/
* parser.cc (cp_parser_omp_clause_depend): Parse
inoutset depend-kind.
(cp_parser_omp_depobj): Likewise.
* cxx-pretty-print.cc (cxx_pretty_printer::statement): Handle
OMP_CLAUSE_DEPEND_INOUTSET.
gcc/testsuite/
* c-c++-common/gomp/all-memory-1.c (boo): Add test with
inoutset depend-kind.
* c-c++-common/gomp/all-memory-2.c (boo): Likewise.
* c-c++-common/gomp/depobj-1.c (f1): Likewise.
(f2): Adjusted expected diagnostics.
* g++.dg/gomp/depobj-1.C (f4): Adjust expected diagnostics.
include/
* gomp-constants.h (GOMP_DEPEND_INOUTSET): Define.
libgomp/
* libgomp.h (struct gomp_task_depend_entry): Change is_in type
from bool to unsigned char.
* task.c (gomp_task_handle_depend): Handle GOMP_DEPEND_INOUTSET.
Ignore dependencies where
task->depend[i].is_in && task->depend[i].is_in == ent->is_in
rather than just task->depend[i].is_in && ent->is_in.  Remember
whether GOMP_DEPEND_IN loop is needed and guard the loop with that
conditional.
(gomp_task_maybe_wait_for_dependencies): Handle GOMP_DEPEND_INOUTSET.
Ignore dependencies where elem.is_in && elem.is_in == ent->is_in
rather than just elem.is_in && ent->is_in.
* testsuite/libgomp.c-c++-common/depend-1.c (test): Add task with
inoutset depend-kind.
* testsuite/libgomp.c-c++-common/depend-2.c (test): Likewise.
* testsuite/libgomp.c-c++-common/depend-3.c (test): Likewise.
* testsuite/libgomp.c-c++-common/depend-inoutset-1.c: New test.

(cherry picked from commit 2c16eb3157f86ae561468c540caf8eb326106b5f)

3 years agolibgomp.texi: Add OpenMP 5.2 implementation status
Tobias Burnus [Mon, 4 Jul 2022 19:24:21 +0000 (21:24 +0200)] 
libgomp.texi: Add OpenMP 5.2 implementation status

libgomp/
* libgomp.texi (OpenMP Implementation Status): Add 5.2 table.

(cherry picked from commit 472aecb78908d47491d3e6c0beb4eb44f7109751)

3 years agoOpenMP: Add omp_all_memory support to Fortran
Tobias Burnus [Mon, 4 Jul 2022 19:17:44 +0000 (21:17 +0200)] 
OpenMP: Add omp_all_memory support to Fortran

Fortran part to the C/C++/backend implementation
r13-337-g7f78783dbedca0183d193e475262ca3c489fd365

gcc/fortran/ChangeLog:

* dump-parse-tree.cc (show_omp_namelist): Handle omp_all_memory.
* openmp.cc (gfc_match_omp_variable_list, gfc_match_omp_depend_sink,
gfc_match_omp_clauses, resolve_omp_clauses): Likewise.
* trans-openmp.cc (gfc_trans_omp_clauses, gfc_trans_omp_depobj):
Likewise.
* resolve.cc (resolve_symbol): Reject it as symbol.

libgomp/ChangeLog:

* libgomp.texi (OpenMP 5.1): Set omp_all_memory to 'Y'.
* testsuite/libgomp.fortran/depend-5.f90: New test.
* testsuite/libgomp.fortran/depend-6.f90: New test.
* testsuite/libgomp.fortran/depend-7.f90: New test.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/all-memory-1.f90: New test.
* gfortran.dg/gomp/all-memory-2.f90: New test.
* gfortran.dg/gomp/all-memory-3.f90: New test.

(cherry picked from commit 4f94c38a9237b728b3a3f76c169b5b47f6c45187)

3 years agoOpenMP, C++: Add template support for the has_device_addr clause.
Marcel Vollweiler [Mon, 4 Jul 2022 19:13:39 +0000 (21:13 +0200)] 
OpenMP, C++: Add template support for the has_device_addr clause.

This patch adds support for list items in the has_device_addr clause which type
is given by C++ template parameters.

gcc/cp/ChangeLog:

* pt.cc (tsubst_omp_clauses): Added OMP_CLAUSE_HAS_DEVICE_ADDR.
* semantics.cc (finish_omp_clauses): Added template decl processing.

libgomp/ChangeLog:

* testsuite/libgomp.c++/target-has-device-addr-7.C: New test.
* testsuite/libgomp.c++/target-has-device-addr-8.C: New test.
* testsuite/libgomp.c++/target-has-device-addr-9.C: New test.

(cherry picked from commit b4fb9f4f9a10d825302cfb5a0ecefa796570d8bc)

3 years agolibgomp.fortran/target-nowait-array-section.f90: Fix typo
Tobias Burnus [Mon, 4 Jul 2022 19:09:25 +0000 (21:09 +0200)] 
libgomp.fortran/target-nowait-array-section.f90: Fix typo

Fix typo as requested in the review approval.

libgomp/ChangeLog:

* testsuite/libgomp.fortran/target-nowait-array-section.f90: New test.

(cherry picked from commit 70d624ff067920d6d57ce5064ddc2a2411377488)

3 years agoOpenMP/Fortran: Use firstprivat not alloc for ptr attach for arrays
Tobias Burnus [Fri, 13 May 2022 18:00:34 +0000 (20:00 +0200)] 
OpenMP/Fortran: Use firstprivat not alloc for ptr attach for arrays

For a non-descriptor array,  map(A(n:m)) was mapped as
  map(tofrom:A[n-1] [len: ...]) map(alloc:A [pointer assign, bias: ...])
with this patch, it is changed to
  map(tofrom:A[n-1] [len: ...]) map(firstprivate:A [pointer assign, bias: ...])

The latter avoids an alloc - and also avoids the race condition with
nowait in the enclosed testcase. (Note: predantically, the testcase is
invalid since OpenMP 5.1, violating the map clause restriction at [354:10-13].

gcc/fortran/ChangeLog:

* trans-openmp.cc (gfc_trans_omp_clauses): When mapping nondescriptor
array sections, use GOMP_MAP_FIRSTPRIVATE_POINTER instead of
GOMP_MAP_POINTER for the pointer attachment.

libgomp/ChangeLog:

* testsuite/libgomp.fortran/target-nowait-array-section.f90: New test.

(cherry picked from commit a46d6268371c446566f656858aada8775a0c988e)

3 years agoDon't use gori depedencies to optimize.
Andrew MacLeod [Mon, 4 Jul 2022 15:21:34 +0000 (11:21 -0400)] 
Don't use gori depedencies to optimize.

  The routine fold_using_range::relation_fold_and_or needs to verify that both
operands of 2 stmts are the same, and uses GORIs dependency cache for this.
This cache cannot be counted on to reflect the current contents of a
stmt, expecially in the presence of an IL changing pass.  Instead, look at the
statement operands.

PR tree-optimization/106114
gcc/
* gimple-range-fold.cc (fold_using_range::relation_fold_and_or): Check
statement operands instead of GORI cache.
gcc/testsuite/
* gcc.dg/pr106114.c: New.

3 years agod: Fix error: aggregate value used where floating point was expected
Iain Buclaw [Wed, 29 Jun 2022 19:52:39 +0000 (21:52 +0200)] 
d: Fix error: aggregate value used where floating point was expected

Casting from vector to static array is permitted, and the frontend
generates a reinterpret cast, but casting back the other way resulted in
an error.  This has been fixed to be properly handled in the code
generation pass of VectorExp, and the conversion for lvalue and rvalue
handling done in convert_expr and convert_for_rvalue respectively.

PR d/106139

gcc/d/ChangeLog:

* d-convert.cc (convert_expr): Handle casting from array to vector.
(convert_for_rvalue): Rewrite vector to array casts of the same
element type into a constructor.
(convert_for_assignment): Return calling convert_for_rvalue.
* expr.cc (ExprVisitor::visit (VectorExp *)): Handle generating a
vector expression from a static array.
* toir.cc (IRVisitor::visit (ReturnStatement *)): Call
convert_for_rvalue on return value.

gcc/testsuite/ChangeLog:

* gdc.dg/pr106139a.d: New test.
* gdc.dg/pr106139b.d: New test.
* gdc.dg/pr106139c.d: New test.
* gdc.dg/pr106139d.d: New test.

(cherry picked from commit 329bef49da30158d30fed1106002bb71674776bd)

3 years agoPR target/105991: Recognize PLUS and XOR forms of rldimi in rs6000.md.
Roger Sayle [Mon, 4 Jul 2022 12:58:37 +0000 (13:58 +0100)] 
PR target/105991: Recognize PLUS and XOR forms of rldimi in rs6000.md.

This patch addresses PR target/105991 where a change to prefer representing
shifts and adds at the tree-level as multiplications, causes problems for
the rldimi patterns in the powerpc backend.  The issue is that rs6000.md
models this pattern using IOR, and some variants that have the equivalent
PLUS or XOR in the RTL fail to match some *rotl<mode>4_insert patterns.
This is fixed in this patch by adding a define_insn_and_split to locally
canonicalize the PLUS and XOR forms to the backend's preferred IOR form.

Backported from master.

2022-07-04  Roger Sayle  <roger@nextmovesoftware.com>
    Marek Polacek  <polacek@redhat.com>
    Segher Boessenkool  <segher@kernel.crashing.org>
    Kewen Lin  <linkw@linux.ibm.com>

gcc/ChangeLog
PR target/105991
* config/rs6000/rs6000.md (rotl<mode>3_insert_3): Check that
exact_log2 doesn't return -1 (or zero).
(plus_xor): New code iterator.
(*rotl<mode>3_insert_3_<code>): New define_insn_and_split.

gcc/testsuite/ChangeLog
PR target/105991
* gcc.target/powerpc/pr105991.c: New test case.

3 years agoloongarch: use -mno-check-zero-division as the default for optimized code
Xi Ruoyao [Sat, 2 Jul 2022 08:16:44 +0000 (16:16 +0800)] 
loongarch: use -mno-check-zero-division as the default for optimized code

Integer division by zero is undefined behavior anyway, and there are
already many platforms where neither the GCC port and the hardware do
anything to trap on division by zero.  So any portable program shall not
rely on SIGFPE on division by zero, in both theory and practice.  As the
result, there is no real reason to cost two additional instructions just
for the trap on division by zero with a new ISA.

One remaining reason to trap on division by zero may be debugging,
especially while -fsanitize=integer-divide-by-zero is not implemented
for LoongArch yet.  To make debugging easier, keep -mcheck-zero-division
as the default for -O0 and -Og, but use -mno-check-zero-division as the
default for all other optimization levels.

Backport this behavior change for 12.2, so 12.1 will be the only release
with a different default.

Co-authored-by: Lulu Cheng <chenglulu@loongson.cn>
gcc/ChangeLog:

* config/loongarch/loongarch.cc (loongarch_check_zero_div_p):
New static function.
(loongarch_idiv_insns): Use loongarch_check_zero_div_p instead
of TARGET_CHECK_ZERO_DIV.
(loongarch_output_division): Likewise.
* common/config/loongarch/loongarch-common.cc
(TARGET_DEFAULT_TARGET_FLAGS): Remove unneeded hook.
* doc/invoke.texi: Update to match the new behavior.

gcc/testsuite/ChangeLog:

* gcc.c-torture/execute/20101011-1.c (dg-additional-options):
add -mcheck-zero-division for LoongArch targets.

(cherry picked from commit f150dc1bd11802b70277f0fa209f2d23695a1095)

3 years agoDaily bump.
GCC Administrator [Mon, 4 Jul 2022 00:19:07 +0000 (00:19 +0000)] 
Daily bump.

3 years agoFortran: error recovery on invalid CLASS(), PARAMETER declarations [PR105243]
Harald Anlauf [Wed, 29 Jun 2022 19:36:17 +0000 (21:36 +0200)] 
Fortran: error recovery on invalid CLASS(), PARAMETER declarations [PR105243]

gcc/fortran/ChangeLog:

PR fortran/103137
PR fortran/103138
PR fortran/103693
PR fortran/105243
* decl.cc (gfc_match_data_decl): Reject CLASS entity declaration
when it is given the PARAMETER attribute.

gcc/testsuite/ChangeLog:

PR fortran/103137
PR fortran/103138
PR fortran/103693
PR fortran/105243
* gfortran.dg/class_58.f90: Fix test.
* gfortran.dg/class_73.f90: New test.

Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
(cherry picked from commit 4c233cabbe388a6b8957c1507e129090e9267ceb)

3 years agoFortran: improve error recovery for EXTENDS_TYPE_OF() [PR106121]
Harald Anlauf [Tue, 28 Jun 2022 20:29:28 +0000 (22:29 +0200)] 
Fortran: improve error recovery for EXTENDS_TYPE_OF() [PR106121]

gcc/fortran/ChangeLog:

PR fortran/106121
* simplify.cc (gfc_simplify_extends_type_of): Do not attempt to
simplify when one of the arguments is a CLASS variable that was
not properly declared.

gcc/testsuite/ChangeLog:

PR fortran/106121
* gfortran.dg/extends_type_of_4.f90: New test.

Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
(cherry picked from commit b8f284d3673004dffae714b56ed663467c2a52a7)

3 years agoPR target/106122: Don't update %esp via the stack with -Oz on x86.
Roger Sayle [Sun, 3 Jul 2022 13:01:17 +0000 (14:01 +0100)] 
PR target/106122: Don't update %esp via the stack with -Oz on x86.

When optimizing for size with -Oz, setting a register can be minimized by
pushing an immediate value to the stack and popping it to the destination.
Alas the one general register that shouldn't be updated via the stack is
the stack pointer itself, where "pop %esp" can't be represented in GCC's
RTL ("use of a register mentioned in pre_inc, pre_dec, post_inc or
post_dec is not permitted within the same instruction").  This patch
fixes PR target/106122 by explicitly checking for SP_REG in the
problematic peephole2.

2022-07-O3  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
PR target/106122
* config/i386/i386.md (peephole2): Avoid generating pop %esp
when optimizing for size.

gcc/testsuite/ChangeLog
PR target/106122
* gcc.target/i386/pr106122.c: New test case.

3 years agoDaily bump.
GCC Administrator [Sun, 3 Jul 2022 00:19:11 +0000 (00:19 +0000)] 
Daily bump.

3 years agojit: avoid calloc() poisoning on musl [PR106102]
Sergei Trofimovich [Mon, 27 Jun 2022 22:42:44 +0000 (23:42 +0100)] 
jit: avoid calloc() poisoning on musl [PR106102]

On musl <pthread.h> uses calloc() (via <sched.h>). jit/ includes
it directly and exposes use of poisoned calloc():

    /build/build/./prev-gcc/xg++ ... ../../gcc-13-20220626/gcc/jit/jit-playback.cc
    make[3]: *** [Makefile:1143: jit/libgccjit.o] Error 1
    make[3]: *** Waiting for unfinished jobs....
    In file included from /<<NIX>>/musl-1.2.3-dev/include/pthread.h:30,
                     from ../../gcc-13-20220626/gcc/jit/jit-playback.cc:44:
    /<<NIX>>/musl-1.2.3-dev/include/sched.h:84:7: error: attempt to use poisoned "calloc"
       84 | void *calloc(size_t, size_t);
          |       ^
    /<<NIX>>/musl-1.2.3-dev/include/sched.h:124:36: error: attempt to use poisoned "calloc"
      124 | #define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n)))
          |                                    ^

The change moves <pthread.h> inclusion to "system.h" under new
INCLUDE_PTHREAD_H guard and uses this mechanism in libgccjit.

gcc/

PR c++/106102
* system.h: Introduce INCLUDE_PTHREAD_H macros to include <pthread.h>.

gcc/jit/

PR c++/106102
* jit-playback.cc: Include <pthread.h> via "system.h" to avoid calloc()
poisoning.
* jit-recording.cc: Ditto.
* libgccjit.cc: Ditto.

(cherry picked from commit 49d508065bdd36fb1a9b6aad9666b1edb5e06474)

3 years agoc++: avoid <memory> poisoning on musl [PR106102]
Sergei Trofimovich [Mon, 27 Jun 2022 12:27:24 +0000 (13:27 +0100)] 
c++: avoid <memory> poisoning on musl [PR106102]

On musl <pthread.h> uses calloc() (via <sched.h>). <memory> includes
it indirectly and exposes use of poisoned calloc() when module code
is built:

    /build/build/./prev-gcc/xg++ ... ../../gcc-13-20220626/gcc/cp/mapper-resolver.cc
        In file included from /<<NIX>>/musl-1.2.3-dev/include/pthread.h:30,
                 from /build/build/prev-x86_64-unknown-linux-musl/libstdc++-v3/include/x86_64-unknown-linux-musl/bits/gthr-default.h:35,
                 ....
                 from /build/build/prev-x86_64-unknown-linux-musl/libstdc++-v3/include/memory:77,
                 from ../../gcc-13-20220626/gcc/../libcody/cody.hh:24,
                 from ../../gcc-13-20220626/gcc/cp/../../c++tools/resolver.h:25,
                 from ../../gcc-13-20220626/gcc/cp/../../c++tools/resolver.cc:23,
                 from ../../gcc-13-20220626/gcc/cp/mapper-resolver.cc:32:
    /<<NIX>>/musl-1.2.3-dev/include/sched.h:84:7: error: attempt to use poisoned "calloc"
       84 | void *calloc(size_t, size_t);
          |       ^
    /<<NIX>>/musl-1.2.3-dev/include/sched.h:124:36: error: attempt to use poisoned "calloc"
      124 | #define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n)))
          |                                    ^

gcc/cp/

PR c++/106102
* mapper-client.cc: Include <memory> via "system.h".
* mapper-resolver.cc: Ditto.
* module.cc: Ditto.

libcc1/

PR c++/106102
* libcc1plugin.cc: Include <memory> via "system.h".
* libcp1plugin.cc: Ditto.

(cherry picked from commit 3b21c21f3f5726823e19728fdd1571a14aae0fb3)

3 years agoDaily bump.
GCC Administrator [Sat, 2 Jul 2022 00:19:15 +0000 (00:19 +0000)] 
Daily bump.

3 years agoMerge branch 'releases/gcc-12' into devel/omp/gcc-12
Kwok Cheung Yeung [Fri, 1 Jul 2022 17:38:07 +0000 (18:38 +0100)] 
Merge branch 'releases/gcc-12' into devel/omp/gcc-12

Merged up to commit e748398b3ef6412ef35b85ef6b0893809aeb49cd (1st July 2022).

3 years agoamdgcn: libgomp plugin USM implementation
Andrew Stubbs [Mon, 20 Jun 2022 14:51:15 +0000 (15:51 +0100)] 
amdgcn: libgomp plugin USM implementation

Implement the Unified Shared Memory API calls in the GCN plugin.

The allocate and free are pretty straight-forward because all "target" memory
allocations are compatible with USM, on the right hardware.  However, there's
no known way to check what memory region was used, after the fact, so we use a
splay tree to record allocations so we can answer "is_usm_ptr" later.

libgomp/ChangeLog:

* plugin/plugin-gcn.c (struct usm_splay_tree_key_s): New.
(usm_splay_compare): New.
(splay_tree_prefix): New.
(GOMP_OFFLOAD_usm_alloc): New.
(GOMP_OFFLOAD_usm_free): New.
(GOMP_OFFLOAD_is_usm_ptr): New.
(GOMP_OFFLOAD_supported_features): Move into the OpenMP API fold.
Add GOMP_REQUIRES_UNIFIED_ADDRESS and
GOMP_REQUIRES_UNIFIED_SHARED_MEMORY.
(gomp_fatal): New.
(splay_tree_c): New.
* testsuite/lib/libgomp.exp (check_effective_target_omp_usm): New.
* testsuite/libgomp.c++/usm-1.C: Use dg-require-effective-target.
* testsuite/libgomp.c-c++-common/requires-1.c: Likewise.
* testsuite/libgomp.c/usm-1.c: Likewise.
* testsuite/libgomp.c/usm-2.c: Likewise.
* testsuite/libgomp.c/usm-3.c: Likewise.
* testsuite/libgomp.c/usm-4.c: Likewise.
* testsuite/libgomp.c/usm-5.c: Likewise.
* testsuite/libgomp.c/usm-6.c: Likewise.

3 years agoamdgcn, openmp: Auto-detect USM mode and set HSA_XNACK
Andrew Stubbs [Fri, 17 Jun 2022 12:07:11 +0000 (13:07 +0100)] 
amdgcn, openmp: Auto-detect USM mode and set HSA_XNACK

The AMD GCN runtime must be set to the correct mode for Unified Shared Memory
to work, but this is not always clear at compile and link time due to the split
nature of the offload compilation pipeline.

This patch sets a new attribute on OpenMP offload functions to ensure that the
information is passed all the way to the backend.  The backend then places a
marker in the assembler code for mkoffload to find. Finally mkoffload places a
constructor function into the final program to ensure that the HSA_XNACK
environment variable passes the correct mode to the GPU.

The HSA_XNACK variable must be set before the HSA runtime is even loaded, so
it makes more sense to have this set within the constructor than at some point
later within libgomp or the GCN plugin.

gcc/ChangeLog:

* config/gcn/gcn.c (unified_shared_memory_enabled): New variable.
(gcn_init_cumulative_args): Handle attribute "omp unified memory".
(gcn_hsa_declare_function_name): Emit "MKOFFLOAD OPTIONS: USM+".
* config/gcn/mkoffload.c (TEST_XNACK_OFF): New macro.
(process_asm): Detect "MKOFFLOAD OPTIONS: USM+".
Emit configure_xnack constructor, as required.
* omp-low.c (create_omp_child_function): Add attribute "omp unified
memory".

3 years agoamdgcn: Support XNACK mode
Andrew Stubbs [Fri, 10 Jun 2022 14:15:49 +0000 (15:15 +0100)] 
amdgcn: Support XNACK mode

The XNACK feature allows memory load instructions to restart safely following
a page-miss interrupt.  This is useful for shared-memory devices, like APUs,
and to implement OpenMP Unified Shared Memory.

To support the feature we must be able to set the appropriate meta-data and
set the load instructions to early-clobber.  When the port supports scheduling
of s_waitcnt instructions there will be further requirements.

gcc/ChangeLog:

* config/gcn/gcn-hsa.h (XNACKOPT): New macro.
(ASM_SPEC): Use XNACKOPT.
* config/gcn/gcn-opts.h (enum sram_ecc_type): Rename to ...
(enum hsaco_attr_type): ... this, and generalize the names.
(TARGET_XNACK): New macro.
* config/gcn/gcn-valu.md (gather<mode>_insn_1offset<exec>):
Add xnack compatible alternatives.
(gather<mode>_insn_2offsets<exec>): Likewise.
* config/gcn/gcn.c (gcn_option_override): Permit -mxnack for devices
other than Fiji.
(gcn_expand_epilogue): Remove early-clobber problems.
(output_file_start): Emit xnack attributes.
(gcn_hsa_declare_function_name): Obey -mxnack setting.
* config/gcn/gcn.md (xnack): New attribute.
(enabled): Rework to include "xnack" attribute.
(*movbi): Add xnack compatible alternatives.
(*mov<mode>_insn): Likewise.
(*mov<mode>_insn): Likewise.
(*mov<mode>_insn): Likewise.
(*movti_insn): Likewise.
* config/gcn/gcn.opt (-mxnack): Add the "on/off/any" syntax.
(sram_ecc_type): Rename to ...
(hsaco_attr_type: ... this.)
* config/gcn/mkoffload.c (SET_XNACK_ANY): New macro.
(TEST_XNACK): Delete.
(TEST_XNACK_ANY): New macro.
(TEST_XNACK_ON): New macro.
(main): Support the new -mxnack=on/off/any syntax.

3 years agoc++: simpler fix for PR106024
Jason Merrill [Fri, 1 Jul 2022 15:02:54 +0000 (11:02 -0400)] 
c++: simpler fix for PR106024

Actually, for release branches let's just avoid the lookup for the lambdas
that are the problematic case and only make the bigger change on trunk.

PR c++/106024

gcc/cp/ChangeLog:

* parser.cc (cp_parser_lookup_name): Limit previous change to
lambdas.

3 years agoFix ICE on sh
Vladimir Makarov [Sat, 28 May 2022 18:08:38 +0000 (12:08 -0600)] 
Fix ICE on sh

gcc/
PR target/103722
* config/sh/sh.cc (sh_register_move_cost): Avoid cost "2" (which
is special) for various scenarios.

(cherry picked from commit ce1580252ea57de23a595e9804ea87ed4353aa6a)

3 years agoc++: lambda template in requires [PR105541]
Jason Merrill [Wed, 11 May 2022 18:53:26 +0000 (14:53 -0400)] 
c++: lambda template in requires [PR105541]

Since the patch for PR103408, the template parameters for the lambda in this
test have level 1 instead of 2, and we were treating null template args as 1
level of arguments, so tsubst_template_parms decided it had nothing to do.
Fixed by distinguishing between <> and no args at all, which is what we have
in our "substitution" in a requires-expression.

PR c++/105541

gcc/cp/ChangeLog:

* cp-tree.h (TMPL_ARGS_DEPTH): 0 for null args.
* parser.cc (cp_parser_enclosed_template_argument_list):
Use 0-length TREE_VEC for <>.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/lambda-requires1.C: New test.

3 years agoc++: tweak resolve_args change
Jason Merrill [Fri, 1 Jul 2022 04:37:10 +0000 (00:37 -0400)] 
c++: tweak resolve_args change

I don't know why I used tf_error instead of complain here.

PR c++/105779

gcc/cp/ChangeLog:

* call.cc (resolve_args): Use complain.

3 years agoc++: dependent generic lambda template-id [PR106024]
Jason Merrill [Fri, 24 Jun 2022 03:14:35 +0000 (23:14 -0400)] 
c++: dependent generic lambda template-id [PR106024]

We were wrongly looking up the generic lambda op() in a dependent scope, and
then trying to look up its instantiation at substitution time, but lambdas
aren't instantiated, so we crashed.  The fix is to not look into dependent
class scopes.

But this created trouble with wrongly trying to use a template from the
enclosing scope when we aren't actually looking at a template-argument-list,
in template/lookup18.C, so let's avoid that.

PR c++/106024

gcc/cp/ChangeLog:

* parser.cc (missing_template_diag): Factor out...
(cp_parser_id_expression): ...from here.
(cp_parser_lookup_name): Don't look in dependent object_type.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/lambda-generic10.C: New test.

3 years agoFix gfortran.dg/gomp/num-teams-2.f90
Tobias Burnus [Mon, 27 Jun 2022 11:26:43 +0000 (13:26 +0200)] 
Fix gfortran.dg/gomp/num-teams-2.f90

OG11 contrary to mainline issues an error for resolve_positive_int_expr
(-> OG11 commit a14b3f29681da1d2465e15f98b8cf8d5c64a2c3c). Update
testcase accordingly.

gcc/testsuite/
* gfortran.dg/gomp/num-teams-2.f90: Use dg-error not dg-warning.

3 years agoDaily bump.
GCC Administrator [Fri, 1 Jul 2022 00:19:20 +0000 (00:19 +0000)] 
Daily bump.

3 years agoFortran: handle explicit-shape specs with constant bounds [PR105954]
Harald Anlauf [Mon, 20 Jun 2022 18:59:55 +0000 (20:59 +0200)] 
Fortran: handle explicit-shape specs with constant bounds [PR105954]

gcc/fortran/ChangeLog:

PR fortran/105954
* decl.cc (variable_decl): Adjust upper bounds for explicit-shape
specs with constant bound expressions to ensure non-negative
extents.

gcc/testsuite/ChangeLog:

PR fortran/105954
* gfortran.dg/pr105954.f90: New test.

(cherry picked from commit a312407bd715647f7c11b67e0a52effc94d0f15d)

3 years agoFortran: fix simplification of INDEX(str1,str2) [PR105691]
Harald Anlauf [Tue, 21 Jun 2022 21:20:18 +0000 (23:20 +0200)] 
Fortran: fix simplification of INDEX(str1,str2) [PR105691]

gcc/fortran/ChangeLog:

PR fortran/105691
* simplify.cc (gfc_simplify_index): Replace old simplification
code by the equivalent of the runtime library implementation.  Use
HOST_WIDE_INT instead of int for string index, length variables.

gcc/testsuite/ChangeLog:

PR fortran/105691
* gfortran.dg/index_6.f90: New test.

(cherry picked from commit ff35dbc02092fbcd3d814fcd9fe8e871c3f741fd)

3 years agoFortran: fix checking of arguments to UNPACK when MASK is a variable [PR105813]
Harald Anlauf [Fri, 24 Jun 2022 20:21:39 +0000 (22:21 +0200)] 
Fortran: fix checking of arguments to UNPACK when MASK is a variable [PR105813]

gcc/fortran/ChangeLog:

PR fortran/105813
* check.cc (gfc_check_unpack): Try to simplify MASK argument to
UNPACK so that checking of the VECTOR argument can work when MASK
is a variable.

gcc/testsuite/ChangeLog:

PR fortran/105813
* gfortran.dg/unpack_vector_1.f90: New test.

(cherry picked from commit f21f17f95c0237f4f987a5fa9f1fa9c7e0db3c40)

3 years agoFix mis-merge of 'dwarf: Multi-register CFI address support'
Kwok Cheung Yeung [Thu, 30 Jun 2022 15:49:15 +0000 (16:49 +0100)] 
Fix mis-merge of 'dwarf: Multi-register CFI address support'

This should be a fixup to 13b6c7639cfdca892a3f02b63596b097e1839f38:
'dwarf: Multi-register CFI address support'.

2022-06-30  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/
* dwarf2cfi.cc (get_cfa_from_loc_descr): Check op against DW_OP_bregx.

3 years agoBuild fixes for OG12 on more recent GCC versions
Kwok Cheung Yeung [Thu, 30 Jun 2022 15:22:10 +0000 (16:22 +0100)] 
Build fixes for OG12 on more recent GCC versions

This fixes a number of minor issues that can cause the build to fail on
recent versions of GCC.

2022-06-30  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/fortran/
* openmp.cc (gfc_resolve_omp_allocate): Initialize tail to NULL.

(This should be a fixup to 491478d12b83e102f72858e8a871a25c951df293: 'Add
parsing support for allocate directive (OpenMP 5.0)')

2022-06-30  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/
* omp-offload.cc (oacc_loop_get_cfg_loop): Cast tail_mark to
gimple* for dump_printf.
* tree-scalar-evolution.cc (oacc_ifn_call_extract): Remove
unused variable 'call'.

(This should be a fixup to 491478d12b83e102f72858e8a871a25c951df293: 'Build
fix for 'openacc: Use Graphite for dependence analysis in "kernels" region')

2022-06-30  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/
* omp-low.cc (usm_transform): Remove unused function argument.

(This should be a fixup to 54c2d861ac62e30ebf34a4e62ee0d55478a742b9: 'Build
fix for 'openmp: Use libgomp memory allocation functions with unified shared
memory')

2022-06-30  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/
* omp-offload.cc (oacc_loop_warn_if_false_independent): Remove extra
'.' at end of message.

(This should be a fixup to 01e6774b725ffa667efd818a46795189a281addf: 'Build
fix for 'openacc: Warn about "independent" "kernels" loops with
data-dependences')

2022-06-30  Tobias Burnus  <tobias@codesourcery.com>

gcc/
* graphite-isl-ast-to-gimple.cc (graphite_oacc_analyze_scop): Update
arguments of dump_printf.

(This should be a fixup to a7e863fc4d54fb645fef05f01a024250184964bb:
'openacc: Add runtime alias checking for OpenACC kernels')

3 years agoFix string formatting issues
Kwok Cheung Yeung [Thu, 30 Jun 2022 14:31:41 +0000 (15:31 +0100)] 
Fix string formatting issues

Stricter format-string checking in more recent versions of GCC can cause
build failures.

2022-06-30  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/
* omp-data-optimize.cc (omp_data_optimize_add_candidate): Suppress
format checking.
(omp_data_optimize_can_be_private): Likewise.
(omp_data_optimize_can_be_private): Likewise.

(This should be a fixup to ab53d5a6a27dce2a92f28a62ceb6e184c8356f25: 'openacc:
Add data optimization pass')

2022-06-30  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/
* gimplify.cc (gimplify_scan_omp_clauses): Remove extra
'%<..%>' pair in format string.

(This should be a fixup to dbc770c4351c8824e8083f8aff6117a6b4ba3c0d: 'openmp:
Implement uses_allocators clause')

3 years agoAdd ChangeLog.omp entries for "Build fix for 'openmp: allow requires unified_shared_m...
Kwok Cheung Yeung [Thu, 30 Jun 2022 18:46:57 +0000 (19:46 +0100)] 
Add ChangeLog.omp entries for "Build fix for 'openmp: allow requires unified_shared_memory'"

3 years agoBuild fix for 'openmp: allow requires unified_shared_memory'
Tobias Burnus [Thu, 30 Jun 2022 06:30:48 +0000 (08:30 +0200)] 
Build fix for 'openmp: allow requires unified_shared_memory'

OG12 commit fa65fc45972d27f2fd79a44eaba1978348177ee9 added an
error diagnostic (moved around in later commits); this diagnostic
caused bootstrap fails as %<...%> were missing. This commit adds
them.

gcc/c/
* c-parser.cc (c_parser_omp_requires): Add missing %<...%> in error.

gcc/cp/
* parser.cc (cp_parser_omp_requires): Add missing %<...%> in error.

3 years agoDaily bump.
GCC Administrator [Thu, 30 Jun 2022 00:19:11 +0000 (00:19 +0000)] 
Daily bump.

3 years agolibsanitizer: cherry-pick 791e0d1bc85d
Martin Liska [Wed, 29 Jun 2022 13:28:07 +0000 (15:28 +0200)] 
libsanitizer: cherry-pick 791e0d1bc85d

791e0d1bc85d: [compiler-rt] Add NO_EXEC_STACK_DIRECTIVE on s390x
(cherry picked from commit aa87b7541b4c11f59c521154513f844ea6b5c977)

3 years agobootstrap/105551 - restore nvptx build
Richard Biener [Wed, 11 May 2022 08:47:34 +0000 (10:47 +0200)] 
bootstrap/105551 - restore nvptx build

The following makes sure to disable var-tracking if only
dwarf2-line debuginfo is present.

2022-05-11  Richard Biener  <rguenther@suse.de>

PR bootstrap/105551
* opts.cc (finish_options): Also disable var-tracking if
!DWARF2_DEBUGGING_INFO.

(cherry picked from commit e7d9fdf5e0ee4c34a880139254340b4165016289)

3 years agoLoongArch: Remove undefined behavior from code [PR 106097]
Lulu Cheng [Mon, 27 Jun 2022 08:26:25 +0000 (16:26 +0800)] 
LoongArch: Remove undefined behavior from code [PR 106097]

C++2017 and previous standard description:

The value of E1 << E2 is E1 left-shifted E2 bit positions;
vacated bits are zero-filled. If E1 has an unsigned type,
the value of the result is E1×2E2, reduced modulo one more
than the maximum value representable inthe result type.
Otherwise, if E1 has a signed type and non-negative value,
and E1×2E2 is representablein the corresponding unsigned
type of the result type, then that value, converted to the
result type, is the resulting value; otherwise, the behavior
is undefined.

The value of E1 >> E2 is E1 right-shifted E2 bit positions.
If E1 has an unsigned type or if E1 has a signed type and
a non-negative value, the value of the result is the integral
part of the quotient of E1/2E2. If E1 has a signed type and
a negative value, the resulting value is implementation-defined.

gcc/ChangeLog:

PR target/106097
* config/loongarch/loongarch.cc (loongarch_build_integer):
Remove undefined behavior from code.

(cherry picked from commit 43653547e7c8da2cd861bceb4a3e4bd338787ced)

3 years agoDaily bump.
GCC Administrator [Wed, 29 Jun 2022 00:19:26 +0000 (00:19 +0000)] 
Daily bump.

3 years agoRevert changes to acc_prof-init-1.c and acc_prof-parallel-1.c
Kwok Cheung Yeung [Fri, 24 Jun 2022 20:29:28 +0000 (21:29 +0100)] 
Revert changes to acc_prof-init-1.c and acc_prof-parallel-1.c

There is an interaction between the commits "OpenACC profiling-interface
fixes for asynchronous operations" and "[OpenACC] Clarify sequencing of
'async' data copying vs. profiling events in
'libgomp.oacc-c-c++-common/acc_prof-{init,parallel}-1.c'", leading to an
execution test failure and hang in these two tests.

This reverts changes to the tests made by the second patch, allowing the
tests to pass.

2022-05-30  Kwok Cheung Yeung  <kcy@codesourcery.com>

libgomp/
* testsuite/libgomp.oacc-c-c++-common/acc_prof-init-1.c
(cb_compute_construct_end): Remove COPYIN block.
(main): Remove assignments to acc_async.
* testsuite/libgomp.oacc-c-c++-common/acc_prof-parallel-1.c
(cb_enter_data_end): Remove COPYIN block.
(main): Remove assignment to acc_async.

3 years agoFix excess errors in pr85381-3.c testcase
Kwok Cheung Yeung [Tue, 31 May 2022 11:23:11 +0000 (12:23 +0100)] 
Fix excess errors in pr85381-3.c testcase

Should probably be a fixup to 'openacc: Adjust test expectations to new
"kernels" handling'.

2022-05-31  Kwok Cheung Yeung  <kcy@codesourcery.com>

* testsuite/libgomp.oacc-c-c++-common/pr85381-3.c (foo_v, foo_w):
Re-add dg-warning entries.

3 years agoFix Fortran array-access regressions
Kwok Cheung Yeung [Wed, 25 May 2022 11:10:03 +0000 (12:10 +0100)] 
Fix Fortran array-access regressions

The arguments to gfc_build_array_ref were recently updated in the commit
'fortran: Use pointer arithmetic to index arrays [PR102043]', but a call
from gfc_conv_array_ref used the old function signature.  This went
unnoticed due to the use of default arguments.

This patch should be merged into 'Fortran: delinearize multi-dimensional
array accesses'.

2022-05-22  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/fortran/
* trans-array.cc (gfc_conv_array_ref): Update arguments to
gfc_build_array_ref.

3 years agoFix ICE in nested-function-1.c testcase
Kwok Cheung Yeung [Fri, 13 May 2022 15:46:36 +0000 (16:46 +0100)] 
Fix ICE in nested-function-1.c testcase

The ICE occurs during Gimple verification after the ompexp stage because
one of the arguments to the generated builtin call is of a Gimple reg type,
but isn't a Gimple value (because it is marked addressable).

This appears to be fallout from the commit "OpenACC 'kernels' decomposition:
Mark variables used in synthesized data clauses as addressable [PR100280]".
The launch dimensions have been added to the arguments of a builtin call
by oacc_set_fn_attrib, but one of the dimensions has been marked addressable.

Fixed by forcing the added arguments to be re-gimplified.

2022-05-13  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/
* omp-expand.cc (expand_omp_target): Gimplify launch dimensions used
in function call.

3 years agoFix ICE in kernels-decompose-pr100280-1.c testcase
Kwok Cheung Yeung [Tue, 10 May 2022 14:46:37 +0000 (15:46 +0100)] 
Fix ICE in kernels-decompose-pr100280-1.c testcase

Check that there is a DECL_INITIAL associated with prev_stmt before using it.

2022-04-15  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/c-family/
* c-omp.cc (check_and_annotate_for_loop): Check that the DECL_INITIAL
is non-NULL before using.

3 years agoFix ICE in OpenACC kernel testcases
Kwok Cheung Yeung [Thu, 14 Apr 2022 20:21:11 +0000 (21:21 +0100)] 
Fix ICE in OpenACC kernel testcases

This is due to sequences like this occurring:

<bb 11> :
  .data_dep.8_27 = .UNIQUE (OACC_TAIL_MARK, .data_dep.8_16, 2);

<bb 12> :
  .data_dep.8_29 = .UNIQUE (OACC_JOIN, .data_dep.8_27, -1);
...
<bb 15> :
  .UNIQUE (OACC_TAIL_MARK, .data_dep.8_33);

The final tail mark has no LHS, causing code that assumes its presence to
segfault.  The LHS and the assignment appear to have been removed as dead
code by the cddce1 stage.

Fixed by checking for the presence of the LHS before using it.

2022-04-14  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/
* graphite-oacc.cc (find_oacc_tail_marks): Check that data_dep is
non-NULL before testing it.
(reduction_use_in_outer_loop_p): Likewise.

3 years agoFix ICE when cache-3-1.c testcase is run
Kwok Cheung Yeung [Thu, 17 Mar 2022 16:00:52 +0000 (16:00 +0000)] 
Fix ICE when cache-3-1.c testcase is run

A change that was present in the OG11 version of
'openmp: in_reduction clause support on target construct' but
not in the mainline version resulted in non-contiguous
arrays being accepted in cache clauses, only to ICE later.

2022-03-17  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/c/
* c-typeck.cc (handle_omp_array_sections_1): Add check to ensure
that clause is a map.

gcc/cp/
* semantics.cc (handle_omp_array_sections_1):  Add check to ensure
that clause is a map.

3 years agolibgomp nvptx plugin: Only consider '--with-cuda-driver=[...]' when applicable
Thomas Schwinge [Thu, 12 May 2022 15:51:43 +0000 (17:51 +0200)] 
libgomp nvptx plugin: Only consider '--with-cuda-driver=[...]' when applicable

They're not applicable in 'PLUGIN_NVPTX_DYNAMIC' configurations.

libgomp/
* plugin/Makefrag.am (libgomp_plugin_nvptx_la_CPPFLAGS)
[PLUGIN_NVPTX_DYNAMIC]: Don't append '$(PLUGIN_NVPTX_CPPFLAGS)'.
(libgomp_plugin_nvptx_la_LDFLAGS) [PLUGIN_NVPTX_DYNAMIC]: Don't
append '$(PLUGIN_NVPTX_LDFLAGS)'.
* Makefile.in: Regenerate.

(cherry picked from commit 1f89e48789d230c78ec60ff3dc9e7e2478cc3df9)

3 years agoRefactor '-ldl' handling for libgomp proper and plugins
Thomas Schwinge [Thu, 5 May 2022 21:01:36 +0000 (23:01 +0200)] 
Refactor '-ldl' handling for libgomp proper and plugins

Instead of implicit global 'LIBS="-ldl $LIBS"' via 'AC_CHECK_LIB', make
'-ldl' explicit for libgomp proper, and clean up 'PLUGIN_GCN_LIBS',
'PLUGIN_NVPTX_LIBS' accordingly.

libgomp/
* Makefile.am (libgomp_la_LIBADD): Initialize.
* plugin/configfrag.ac (DL_LIBS): New.
(PLUGIN_GCN_LIBS): Remove.
(PLUGIN_NVPTX_LIBS): Don't set in the 'PLUGIN_NVPTX_DYNAMIC' case.
* plugin/Makefrag.am (libgomp_la_LIBADD)
(libgomp_plugin_gcn_la_LIBADD): Consider '$(DL_LIBS)'.
(libgomp_plugin_nvptx_la_LIBADD) <PLUGIN_NVPTX_DYNAMIC>: Likewise.
* Makefile.in: Regenerate.
* config.h.in: Likewise.
* configure: Likewise.
* testsuite/Makefile.in: Likewise.

(cherry picked from commit dcc266796a6afa18eeba1edde81f9eb78e6c83ce)

3 years agolibgomp nvptx plugin: Split 'PLUGIN_NVPTX_DYNAMIC' into 'PLUGIN_NVPTX_INCLUDE_SYSTEM_...
Thomas Schwinge [Thu, 7 Apr 2022 21:10:16 +0000 (23:10 +0200)] 
libgomp nvptx plugin: Split 'PLUGIN_NVPTX_DYNAMIC' into 'PLUGIN_NVPTX_INCLUDE_SYSTEM_CUDA_H' and 'PLUGIN_NVPTX_LINK_LIBCUDA'

Including the GCC-shipped 'include/cuda/cuda.h' vs. system <cuda.h> and
'dlopen'ing the CUDA Driver library vs. linking it are separate concerns.

libgomp/
* plugin/Makefrag.am: Handle 'PLUGIN_NVPTX_DYNAMIC'.
* plugin/configfrag.ac (PLUGIN_NVPTX_DYNAMIC): Change
'AC_DEFINE_UNQUOTED' into 'AM_CONDITIONAL'.
* plugin/plugin-nvptx.c: Split 'PLUGIN_NVPTX_DYNAMIC' into
'PLUGIN_NVPTX_INCLUDE_SYSTEM_CUDA_H' and
'PLUGIN_NVPTX_LINK_LIBCUDA'.
* Makefile.in: Regenerate.
* config.h.in: Likewise.
* configure: Likewise.

(cherry picked from commit cd644ce8be2d1ba8d759ce4c00a2ded5a040b70d)

3 years agolibgomp plugins: Don't 'AC_SUBST' and 'AC_DEFINE_UNQUOTED' for 'PLUGIN_GCN', 'PLUGIN_...
Thomas Schwinge [Thu, 5 May 2022 21:10:23 +0000 (23:10 +0200)] 
libgomp plugins: Don't 'AC_SUBST' and 'AC_DEFINE_UNQUOTED' for 'PLUGIN_GCN', 'PLUGIN_NVPTX'

Nothing ever used these.

libgomp/
* plugin/configfrag.ac: Don't 'AC_SUBST' and 'AC_DEFINE_UNQUOTED'
for 'PLUGIN_GCN', 'PLUGIN_NVPTX'.
* Makefile.in: Regenerate.
* config.h.in: Likewise.
* configure: Likewise.
* testsuite/Makefile.in: Likewise.

(cherry picked from commit edbd2b1caaa79d68467418a4571c3b09f9602805)

3 years agoopenmp: Add omp_all_memory support (C/C++ only so far)
Jakub Jelinek [Thu, 12 May 2022 06:31:20 +0000 (08:31 +0200)] 
openmp: Add omp_all_memory support (C/C++ only so far)

The ugly part is that OpenMP 5.1 made omp_all_memory a reserved identifier
which isn't allowed to be used anywhere but in the depend clause, this is
against how everything else has been handled in OpenMP so far (where
some identifiers could have special meaning in some OpenMP clauses or
pragmas but not elsewhere).
The patch handles it by making it a conditional keyword (for -fopenmp
only) and emitting a better diagnostics when it is used in a primary
expression.  Having a nicer diagnostics when e.g. trying to do
int omp_all_memory;
or
int *omp_all_memory[10];
etc. would mean changing too many spots and hooking into name lookups
to reject declaring any such symbols would be too ugly and I'm afraid
there are way too many spots where one can introduce a name
(variables, functions, namespaces, struct, enum, enumerators, template
arguments, ...).

Otherwise, the handling is quite simple, normal depend clauses lower
into addresses of variables being handed over to the library, for
omp_all_memory I'm using NULL pointers.  omp_all_memory can only be
used with inout or out depend kinds and means that a task is dependent
on all previously created sibling tasks that have any dependency (of
any depend kind) and that any later created sibling tasks will be
dependent on it if they have any dependency.

2022-05-12  Jakub Jelinek  <jakub@redhat.com>

gcc/
* gimplify.cc (gimplify_omp_depend): Don't build_fold_addr_expr
if null_pointer_node.
(gimplify_scan_omp_clauses): Likewise.
* tree-pretty-print.cc (dump_omp_clause): Print null_pointer_node
as omp_all_memory.
gcc/c-family/
* c-common.h (enum rid): Add RID_OMP_ALL_MEMORY.
* c-omp.cc (c_finish_omp_depobj): Don't build_fold_addr_expr
if null_pointer_node.
gcc/c/
* c-parser.cc (c_parse_init): Register omp_all_memory as keyword
if flag_openmp.
(c_parser_postfix_expression): Diagnose uses of omp_all_memory
in postfix expressions.
(c_parser_omp_variable_list): Handle omp_all_memory in depend
clause.
* c-typeck.cc (c_finish_omp_clauses): Handle omp_all_memory
keyword in depend clause as null_pointer_node, diagnose invalid
uses.
gcc/cp/
* lex.cc (init_reswords): Register omp_all_memory as keyword
if flag_openmp.
* parser.cc (cp_parser_primary_expression): Diagnose uses of
omp_all_memory in postfix expressions.
(cp_parser_omp_var_list_no_open): Handle omp_all_memory in depend
clause.
* semantics.cc (finish_omp_clauses): Handle omp_all_memory
keyword in depend clause as null_pointer_node, diagnose invalid
uses.
* pt.cc (tsubst_omp_clause_decl): Pass through omp_all_memory.
gcc/testsuite/
* c-c++-common/gomp/all-memory-1.c: New test.
* c-c++-common/gomp/all-memory-2.c: New test.
* c-c++-common/gomp/all-memory-3.c: New test.
* g++.dg/gomp/all-memory-1.C: New test.
* g++.dg/gomp/all-memory-2.C: New test.
libgomp/
* libgomp.h (struct gomp_task): Add depend_all_memory member.
* task.c (gomp_init_task): Initialize depend_all_memory.
(gomp_task_handle_depend): Handle omp_all_memory.
(gomp_task_run_post_handle_depend_hash): Clear
parent->depend_all_memory if equal to current task.
(gomp_task_maybe_wait_for_dependencies): Handle omp_all_memory.
* testsuite/libgomp.c-c++-common/depend-1.c: New test.
* testsuite/libgomp.c-c++-common/depend-2.c: New test.
* testsuite/libgomp.c-c++-common/depend-3.c: New test.

(cherry picked from commit 7f78783dbedca0183d193e475262ca3c489fd365)

3 years agolibgomp: Remove unused '--with-hsa-runtime', '--with-hsa-runtime-include', '--with...
Thomas Schwinge [Wed, 6 Apr 2022 10:26:13 +0000 (12:26 +0200)] 
libgomp: Remove unused '--with-hsa-runtime', '--with-hsa-runtime-include', '--with-hsa-runtime-lib'

With recent commit 2e309a4eff80e55b53d32d26926a2a94eabfea21 "libgomp testsuite:
Don't amend 'LD_LIBRARY_PATH' for system-provided HSA Runtime library",
and commit d6adba307508c75f1ccb2121eb1a43c9ab1d4056 "libgomp GCN plugin:
Clean up unused references to system-provided HSA Runtime library", the last
uses of '--with-hsa-runtime' etc. are gone.

gcc/
* doc/install.texi: Don't document '--with-hsa-runtime',
'--with-hsa-runtime-include', '--with-hsa-runtime-lib'.

libgomp/
* plugin/configfrag.ac: Remove '--with-hsa-runtime',
'--with-hsa-runtime-include', '--with-hsa-runtime-lib' processing.
* Makefile.in: Regenerate.
* configure: Likewise.
* testsuite/Makefile.in: Likewise.

(cherry picked from commit 876ac21b7e796f9efb859dfb46ae2a4126b0b782)

3 years agolibgomp GCN plugin: Clean up always-empty 'PLUGIN_GCN_CPPFLAGS', 'PLUGIN_GCN_LDFLAGS'
Thomas Schwinge [Wed, 6 Apr 2022 10:15:28 +0000 (12:15 +0200)] 
libgomp GCN plugin: Clean up always-empty 'PLUGIN_GCN_CPPFLAGS', 'PLUGIN_GCN_LDFLAGS'

After recent commit d6adba307508c75f1ccb2121eb1a43c9ab1d4056
"libgomp GCN plugin: Clean up unused references to system-provided HSA Runtime
library", these aren't set anymore.

libgomp/
* plugin/Makefrag.am (libgomp_plugin_gcn_la_CPPFLAGS): Don't
consider 'PLUGIN_GCN_CPPFLAGS'.
(libgomp_plugin_gcn_la_LDFLAGS): Don't consider
'PLUGIN_GCN_LDFLAGS'.
* plugin/configfrag.ac (PLUGIN_GCN_CPPFLAGS, PLUGIN_GCN_LDFLAGS):
Remove.
* Makefile.in: Regenerate.
* configure: Likewise.
* testsuite/Makefile.in: Likewise.

(cherry picked from commit 91a6dcd14915181b4bce51cd44b56a3e9f9d35d8)

3 years agolibgomp GCN plugin: Clean up unused references to system-provided HSA Runtime library
Thomas Schwinge [Wed, 6 Apr 2022 09:31:45 +0000 (11:31 +0200)] 
libgomp GCN plugin: Clean up unused references to system-provided HSA Runtime library

This is only active if GCC is 'configure'd with '--with-hsa-runtime=[...]' or
'--with-hsa-runtime-include=[...]', '--with-hsa-runtime-lib=[...]' -- which
nobody really is doing, as far as I can tell.

Originally changed for the libgomp HSA plugin in
commit b8d89b03db5f212919e4571671ebb4f5f8b1e19d (r242749)
"Remove build dependence on HSA run-time", and later propagated into the GCN
plugin, these are no longer built against system-provided HSA Runtime library.
Instead, unconditionally built against the GCC-shipped 'include/hsa*.h' header
files, and at run time does 'dlopen("libhsa-runtime64.so.1")'.  It thus doesn't
make sense to consider references to system-provided HSA Runtime library during
libgomp GCN plugin build.

libgomp/
* plugin/configfrag.ac (HSA_RUNTIME_CPPFLAGS)
(HSA_RUNTIME_LDFLAGS): Remove.
* configure: Regenerate.

(cherry picked from commit d6adba307508c75f1ccb2121eb1a43c9ab1d4056)

3 years agolibgomp testsuite: Don't amend 'LD_LIBRARY_PATH' for system-provided HSA Runtime...
Thomas Schwinge [Wed, 6 Apr 2022 08:39:56 +0000 (10:39 +0200)] 
libgomp testsuite: Don't amend 'LD_LIBRARY_PATH' for system-provided HSA Runtime library

This is only active if GCC is 'configure'd with '--with-hsa-runtime=[...]' or
'--with-hsa-runtime-lib=[...]' -- which nobody really is doing, as far as I can
tell.

'libgomp/testsuite/lib/libgomp.exp:libgomp_init' states:

    # For build-tree testing, also consider the library paths used for builing.
    # For installed testing, we assume all that to be provided in the sysroot.
    if { $blddir != "" } {
        [...]
        global hsa_runtime_lib
        if { $hsa_runtime_lib != "" } {
            append always_ld_library_path ":$hsa_runtime_lib"
        }
    }

However, the libgomp GCN plugin is unconditionally built against the
GCC-shipped 'include/hsa*.h' header files, and at run time does
'dlopen("libhsa-runtime64.so.1")', so there is no system-provided HSA Runtime
library "used for builing".  It thus doesn't make sense to amend
'LD_LIBRARY_PATH' for system-provided HSA Runtime library.

libgomp/
* testsuite/lib/libgomp.exp (libgomp_init): Don't
'append always_ld_library_path ":$hsa_runtime_lib"'.
* testsuite/libgomp-test-support.exp.in (hsa_runtime_lib): Don't set.

(cherry picked from commit 2e309a4eff80e55b53d32d26926a2a94eabfea21)

3 years agoFix up 'libgomp.fortran/use_device_addr-5.f90' multi-device testing
Thomas Schwinge [Tue, 10 May 2022 12:43:56 +0000 (14:43 +0200)] 
Fix up 'libgomp.fortran/use_device_addr-5.f90' multi-device testing

Fix-up for recent commit r13-116-g3f8c389fe90bf565a6221a46bb7fb745dd4c1510
"OpenMP: Fix use_device_{addr,ptr} with in-data-sharing arg", where we
currently get:

    libgomp: use_device_ptr pointer wasn't mapped
    FAIL: libgomp.fortran/use_device_addr-5.f90   -O  execution test

libgomp/
* testsuite/libgomp.fortran/use_device_addr-5.f90: Fix up
multi-device testing.

(cherry picked from commit 798152475559a6be8049692932cc747c6499e7f5)

3 years agoOpenMP, libgomp: Add new runtime routine omp_target_is_accessible.
Marcel Vollweiler [Fri, 6 May 2022 14:28:26 +0000 (07:28 -0700)] 
OpenMP, libgomp: Add new runtime routine omp_target_is_accessible.

gcc/ChangeLog:

* omp-low.cc (omp_runtime_api_call): Added target_is_accessible to
omp_runtime_apis array.

libgomp/ChangeLog:

* libgomp.map: Added omp_target_is_accessible.
* libgomp.texi: Tagged omp_target_is_accessible as supported.
* omp.h.in: Added omp_target_is_accessible.
* omp_lib.f90.in: Added interface for omp_target_is_accessible.
* omp_lib.h.in: Likewise.
* target.c (omp_target_is_accessible): Added implementation of
omp_target_is_accessible.
* testsuite/libgomp.c-c++-common/target-is-accessible-1.c: New test.
* testsuite/libgomp.fortran/target-is-accessible-1.f90: New test.

(cherry picked from commit 4043f53cb4a3541f7a6e4f4132419f78ab7ec4f7)