[gcc r15-657] Fortran: invoke.texi - link to OpenCoarrays.org + mention libcaf_single

2024-05-19 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:544d5dcc9150c0ea278fba79ea515f5a87732ce7

commit r15-657-g544d5dcc9150c0ea278fba79ea515f5a87732ce7
Author: Tobias Burnus 
Date:   Mon May 20 08:33:31 2024 +0200

Fortran: invoke.texi - link to OpenCoarrays.org + mention libcaf_single

gcc/fortran/ChangeLog:

* invoke.texi (fcoarray): Link to OpenCoarrays.org;
mention libcaf_single.

Diff:
---
 gcc/fortran/invoke.texi | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi
index 40e8e4a7cdde..6bc42afe2c4f 100644
--- a/gcc/fortran/invoke.texi
+++ b/gcc/fortran/invoke.texi
@@ -1753,7 +1753,10 @@ Single-image mode, i.e. @code{num_images()} is always 
one.
 
 @item @samp{lib}
 Library-based coarray parallelization; a suitable GNU Fortran coarray
-library needs to be linked.
+library such as @url{http://opencoarrays.org} needs to be linked.
+Alternatively, GCC's @code{libcaf_single} library can be linked,
+albeit it only supports a single image.
+
 @end table


[gcc r15-658] Fortran: Fix SHAPE for zero-size arrays

2024-05-19 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:b701306a9b38bd74cdc26c7ece5add22f2203b56

commit r15-658-gb701306a9b38bd74cdc26c7ece5add22f2203b56
Author: Tobias Burnus 
Date:   Mon May 20 08:34:48 2024 +0200

Fortran: Fix SHAPE for zero-size arrays

PR fortran/115150

gcc/fortran/ChangeLog:

* trans-intrinsic.cc (gfc_conv_intrinsic_bound): Fix SHAPE
for zero-size arrays

gcc/testsuite/ChangeLog:

* gfortran.dg/shape_12.f90: New test.

Diff:
---
 gcc/fortran/trans-intrinsic.cc |  4 ++-
 gcc/testsuite/gfortran.dg/shape_12.f90 | 51 ++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index 80dc3426ab04..912c1000e186 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -3090,7 +3090,9 @@ gfc_conv_intrinsic_bound (gfc_se * se, gfc_expr * expr, 
enum gfc_isym_id op)
  lbound, gfc_index_one_node);
}
   else if (op == GFC_ISYM_SHAPE)
-   se->expr = size;
+   se->expr = fold_build2_loc (input_location, MAX_EXPR,
+   gfc_array_index_type, size,
+   gfc_index_zero_node);
   else
gcc_unreachable ();
 
diff --git a/gcc/testsuite/gfortran.dg/shape_12.f90 
b/gcc/testsuite/gfortran.dg/shape_12.f90
new file mode 100644
index ..e672e1ff9f95
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/shape_12.f90
@@ -0,0 +1,51 @@
+! { dg-do run }
+!
+! PR fortran/115150
+!
+! Check that SHAPE handles zero-sized arrays correctly
+!
+implicit none
+call one
+call two
+
+contains
+
+subroutine one
+  real,allocatable :: A(:),B(:,:)
+  allocate(a(3:0), b(5:1, 2:5))
+
+  if (any (shape(a) /= [0])) stop 1
+  if (any (shape(b) /= [0, 4])) stop 2
+  if (size(a) /= 0) stop 3
+  if (size(b) /= 0) stop 4
+  if (any (lbound(a) /= [1])) stop 5
+  if (any (lbound(b) /= [1, 2])) stop 6
+  if (any (ubound(a) /= [0])) stop 5
+  if (any (ubound(b) /= [0,5])) stop 6
+end
+
+subroutine two
+integer :: x1(10), x2(10,10)
+call f(x1, x2, -3)
+end
+
+subroutine f(y1, y2, n)
+  integer, value :: n
+  integer :: y1(1:n)
+  integer :: y2(1:n,4,2:*)
+  call g(y1, y2)
+end
+
+subroutine g(z1, z2)
+  integer :: z1(..), z2(..)
+
+  if (any (shape(z1) /= [0])) stop 1
+  if (any (shape(z2) /= [0, 4, -1])) stop 2
+  if (size(z1) /= 0) stop 3
+  if (size(z2) /= 0) stop 4
+  if (any (lbound(z1) /= [1])) stop 5
+  if (any (lbound(z2) /= [1, 1, 1])) stop 6
+  if (any (ubound(z1) /= [0])) stop 5
+  if (any (ubound(z2) /= [0, 4, -1])) stop 6
+end
+end


[gcc r15-3249] libgomp: Add interop types and routines to OpenMP's headers and module

2024-08-28 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:0beac1db38855eae0f71fa982ed05069d3873a9c

commit r15-3249-g0beac1db38855eae0f71fa982ed05069d3873a9c
Author: Tobias Burnus 
Date:   Wed Aug 28 11:50:43 2024 +0200

libgomp: Add interop types and routines to OpenMP's headers and module

This commit adds OpenMP 5.1+'s interop enumeration, type and routine
declarations to the C/C++ header file and, new in OpenMP TR13, also to
the Fortran module and omp_lib.h header file.

While a stub implementation is provided, only with foreign runtime
support by the libgomp GPU plugins and with the 'interop' directive,
this becomes really useful.

libgomp/ChangeLog:

* fortran.c (omp_get_interop_str_, omp_get_interop_name_,
omp_get_interop_type_desc_, omp_get_interop_rc_desc_): Add.
* libgomp.map (GOMP_5.1.3): New; add interop routines.
* omp.h.in: Add interop typedefs, enum and prototypes.
(__GOMP_DEFAULT_NULL): Define.
(omp_target_memcpy_async, omp_target_memcpy_rect_async):
Use it for the optional depend argument.
* omp_lib.f90.in: Add paramters and interfaces for interop.
* omp_lib.h.in: Likewise; move F90 '&' to column 81 for
-ffree-length-80.
* target.c (omp_get_num_interop_properties, omp_get_interop_int,
omp_get_interop_ptr, omp_get_interop_str, omp_get_interop_name,
omp_get_interop_type_desc, omp_get_interop_rc_desc): Add.
* config/gcn/target.c (omp_get_num_interop_properties,
omp_get_interop_int, omp_get_interop_ptr, omp_get_interop_str,
omp_get_interop_name, omp_get_interop_type_desc,
omp_get_interop_rc_desc): Add.
* config/nvptx/target.c (omp_get_num_interop_properties,
omp_get_interop_int, omp_get_interop_ptr, omp_get_interop_str,
omp_get_interop_name, omp_get_interop_type_desc,
omp_get_interop_rc_desc): Add.
* testsuite/libgomp.c-c++-common/interop-routines-1.c: New test.
* testsuite/libgomp.c-c++-common/interop-routines-2.c: New test.
* testsuite/libgomp.fortran/interop-routines-1.F90: New test.
* testsuite/libgomp.fortran/interop-routines-2.F90: New test.
* testsuite/libgomp.fortran/interop-routines-3.F: New test.
* testsuite/libgomp.fortran/interop-routines-4.F: New test.
* testsuite/libgomp.fortran/interop-routines-5.F: New test.
* testsuite/libgomp.fortran/interop-routines-6.F: New test.
* testsuite/libgomp.fortran/interop-routines-7.F90: New test.

Diff:
---
 libgomp/config/gcn/target.c| 105 ++
 libgomp/config/nvptx/target.c  | 105 ++
 libgomp/fortran.c  |  41 +++
 libgomp/libgomp.map|  15 +
 libgomp/omp.h.in   |  78 -
 libgomp/omp_lib.f90.in |  99 ++
 libgomp/omp_lib.h.in   | 170 --
 libgomp/target.c   | 110 +++
 .../libgomp.c-c++-common/interop-routines-1.c  | 287 +
 .../libgomp.c-c++-common/interop-routines-2.c  | 354 +
 .../libgomp.fortran/interop-routines-1.F90 | 236 ++
 .../libgomp.fortran/interop-routines-2.F90 |   3 +
 .../testsuite/libgomp.fortran/interop-routines-3.F |   2 +
 .../testsuite/libgomp.fortran/interop-routines-4.F |   4 +
 .../testsuite/libgomp.fortran/interop-routines-5.F |   4 +
 .../testsuite/libgomp.fortran/interop-routines-6.F |   4 +
 .../libgomp.fortran/interop-routines-7.F90 | 290 +
 17 files changed, 1883 insertions(+), 24 deletions(-)

diff --git a/libgomp/config/gcn/target.c b/libgomp/config/gcn/target.c
index 9cafea4e2cc7..f7fa6aa6396c 100644
--- a/libgomp/config/gcn/target.c
+++ b/libgomp/config/gcn/target.c
@@ -185,3 +185,108 @@ GOMP_target_enter_exit_data (int device, size_t mapnum, 
void **hostaddrs,
   (void) depend;
   __builtin_unreachable ();
 }
+
+int
+omp_get_num_interop_properties (const omp_interop_t interop
+   __attribute__ ((unused)))
+{
+  return 0;
+}
+
+omp_intptr_t
+omp_get_interop_int (const omp_interop_t interop,
+omp_interop_property_t property_id,
+omp_interop_rc_t *ret_code)
+{
+  if (ret_code == NULL)
+return 0;
+  if (property_id < omp_ipr_first || property_id >= 0)
+*ret_code = omp_irc_out_of_range;
+  else if (interop == omp_interop_none)
+*ret_code = omp_irc_empty;
+  else
+*ret_code = omp_irc_other;
+  return 0;
+}
+
+void *
+omp_get_interop_ptr (const omp_interop_t interop,
+omp_interop_property_t property_id,
+omp_interop_rc_t *ret_code)
+{
+  if (ret_code == NULL)
+return NULL;
+  if (property_id

[gcc r15-3374] lto-wrapper: Honor -save-temps for ltrans' makefile

2024-09-02 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:6640a59fed48ed4e485d4a970f3ca9ed9e908640

commit r15-3374-g6640a59fed48ed4e485d4a970f3ca9ed9e908640
Author: Tobias Burnus 
Date:   Mon Sep 2 10:28:29 2024 +0200

lto-wrapper: Honor -save-temps for ltrans' makefile

gcc/ChangeLog:

* lto-wrapper.cc (run_gcc): Honor -save-temps for
makefile name.

Diff:
---
 gcc/lto-wrapper.cc | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/lto-wrapper.cc b/gcc/lto-wrapper.cc
index 6bfc96590a5a..c07765b37a28 100644
--- a/gcc/lto-wrapper.cc
+++ b/gcc/lto-wrapper.cc
@@ -1994,7 +1994,10 @@ cont:
 
   if (parallel)
{
- makefile = make_temp_file (".mk");
+ if (save_temps)
+   makefile = concat (dumppfx, "ltrans.mk", NULL);
+ else
+   makefile = make_temp_file (".mk");
  mstream = fopen (makefile, "w");
  qsort (ltrans_priorities, nr, sizeof (int) * 2, cmp_priority);
}


[gcc r15-3375] lto/lto.cc: Fix build with not HAVE_WORKING_FORK

2024-09-02 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:5cbfb3a799bcded1a06897400a09f0efadc1f9e8

commit r15-3375-g5cbfb3a799bcded1a06897400a09f0efadc1f9e8
Author: Tobias Burnus 
Date:   Mon Sep 2 10:29:36 2024 +0200

lto/lto.cc: Fix build with not HAVE_WORKING_FORK

gcc/lto/ChangeLog:

* lto.cc: Add missing HAVE_WORKING_FORK.

Diff:
---
 gcc/lto/lto.cc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/lto/lto.cc b/gcc/lto/lto.cc
index 58ff0c45f577..52dd436fd9a1 100644
--- a/gcc/lto/lto.cc
+++ b/gcc/lto/lto.cc
@@ -62,8 +62,10 @@ along with GCC; see the file COPYING3.  If not see
 /* Number of parallel tasks to run.  */
 static int lto_parallelism;
 
+#ifdef HAVE_WORKING_FORK
 /* Number of active WPA streaming processes.  */
 static int nruns = 0;
+#endif
 
 /* GNU make's jobserver info.  */
 static jobserver_info *jinfo = NULL;


[gcc/devel/omp/gcc-14] (100 commits) Merge branch 'releases/gcc-14' into devel/omp/gcc-14

2024-09-03 Thread Tobias Burnus via Gcc-cvs
The branch 'devel/omp/gcc-14' was updated to point to:

 682fd948f835... Merge branch 'releases/gcc-14' into devel/omp/gcc-14

It previously pointed to:

 6d3c68ff05cf... amdgcn: Fix VGPR max count

Diff:

Summary of changes (added commits):
---

  682fd94... Merge branch 'releases/gcc-14' into devel/omp/gcc-14
  59157c0... i386: Fix vfpclassph non-optimizied intrin (*)
  2ac3806... Daily bump. (*)
  ba9a3f1... Check avx upper register for parallel. (*)
  db4d810... Daily bump. (*)
  a2e32a8... Daily bump. (*)
  657bf4a... Daily bump. (*)
  5999dd8... Fortran: fix ICE with use with rename of namelist member [P (*)
  552c7c1... Daily bump. (*)
  d3c14d4... Daily bump. (*)
  4d6c0c0... Add gcc ka.po (*)
  f5b3dae... i386: testsuite: Adapt fentryname3.c for r14-811 change [PR (*)
  377c3e9... i386: testsuite: Add -no-pie for pr113689-1.c [PR70150] (*)
  87aea23... Daily bump. (*)
  90b1232... Update gcc zh_CN.po (*)
  75892d9... MIPS: Include missing mips16.S in libgcc/lib1funcs.S (*)
  ef9c53b... Daily bump. (*)
  b414466... Daily bump. (*)
  5b75e1c... Daily bump. (*)
  8de3153... Daily bump. (*)
  27dc153... Align ix86_{move_max,store_max} with vectorizer. (*)
  ffd458d... Daily bump. (*)
  5146af5... Daily bump. (*)
  25812d8... [testsuite] [arm] [vect] adjust mve-vshr test [PR113281] (*)
  76ac167... Daily bump. (*)
  52da858... c++: fix ICE in convert_nontype_argument [PR116384] (*)
  af97b5e... testsuite: Prune warning about size of enums (*)
  1fad6ad... Daily bump. (*)
  c725748... AVR: ad target/116407 - Fix linker error "relocation trunca (*)
  919c42b... AVR: target/116407 - Fix linker error "relocation truncated (*)
  f4ce098... Daily bump. (*)
  f3d9c12... AVR: target/116390 - Fix an avrtiny asm out template. (*)
  0296001... Daily bump. (*)
  507b4e1... AVR: target/85624 - Use HImode for clrmemqi alignment. (*)
  edf95a4... testsuite: Verify -fshort-enums and -fno-short-enums in pr3 (*)
  5c1f687... testsuite: Add -fno-short-enums to pr97315-1.C (*)
  345d145... testsuite: Add -fwrapv to signbit-5.c (*)
  45a771d... i386: Fix some vex insns that prohibit egpr (*)
  86dacfb... aarch64: Add another use of force_subreg [PR115464] (*)
  32b2129... aarch64: Fix invalid nested subregs [PR115464] (*)
  4e7735a... Move ix86_align_loops into a separate pass and insert the p (*)
  ccca8df... Daily bump. (*)
  63c51e0... c++/coroutines: fix passing *this to promise type, again [P (*)
  d9bd361... [PATCH] RISC-V: Fix unresolved mcpu-[67].c tests (*)
  8c98f06... RISC-V: Make full-vec-move1.c test robust for optimization (*)
  7268985... Daily bump. (*)
  e903ada... s390: Fix high-level builtins vec_gfmsum{,_accum}_128 (*)
  5a63e19... Daily bump. (*)
  7d9bb37... Add -mcpu=power11 support. (*)
  f688431... Daily bump. (*)
  6bfd78c... Daily bump. (*)
  534ffe7... Daily bump. (*)
  6f1e687... Daily bump. (*)
  b0dd13e... i386: Fix up __builtin_ia32_b{extr{,i}_u{32,64},zhi_{s,d}i} (*)
  897cd79... Daily bump. (*)
  9ca1d7a... AVR: target/116295 - Fix unrecognizable insn with __flash r (*)
  a9255df... Daily bump. (*)
  49e8eee... Daily bump. (*)
  b1102f7... c++: alias and non-type template parm [PR116223] (*)
  987fc81... c++: parse error with -std=c++14 -fconcepts [PR116071] (*)
  ba26c47... hppa: Fix (plus (plus (mult (a) (mem_shadd_constant)) (b))  (*)
  f2b5ca6... wide-int: Fix up mul_internal overflow checking [PR116224] (*)
  3fe5720... libquadmath: Fix up libquadmath/math/sqrtq.c compilation in (*)
  cad2693... fortran: Fix up pasto in gfc_get_array_descr_info (*)
  ba45573... sh: Don't call make_insn_raw in sh_recog_treg_set_expr [PR1 (*)
  c5ef3b9... Daily bump. (*)
  de73898... compiler: panic arguments are empty interface type (*)
  2405d29... libgomp: Remove bogus warnings from privatized-ref-2.f90. (*)
  9906a98... Fortran: Suppress bogus used uninitialized warnings [PR1088 (*)
  daced76... Update gcc fr.po (*)
  eccf707... RISC-V: xtheadmemidx: Fix mode test for pre/post-modify add (*)
  5103ee7... Daily bump. (*)
  80a64e6... Daily bump. (*)
  c386665... libstdc++: Fix __cpp_lib_chrono for old std::string ABI (*)
  99eb84f... Daily bump. (*)
  21e2d27... Update gcc .po files (*)
  14fa2b2... forwprop: Don't add uses to dce list if debug statement [PR (*)
  a295076... Refine constraint "Bk" to define_special_memory_constraint. (*)
  30f4fa3... i386: Add non-optimize prefetchi intrins (*)
  79d32ba... LoongArch: Remove gawk extension from a generator script. (*)
  81db685... c++: generic lambda in default template argument [PR88313] (*)
  37e54ff... c++: alias of alias tmpl with dependent attrs [PR115897] (*)
  59e3934... libstdc++: fix uses of explicit object parameter [PR116038] (*)
  241f710... c++: normalizing ttp constraints [PR115656] (*)
  e548a88... c++: missing SFINAE during alias CTAD [PR115296] (*)
  1287b4a... c++: prev declared hidden tmpl friend inst [PR112288] (*)
  fb8da40... Daily bump. (*)
  c637241... libstdc++: Add [[nodiscard]] to some std::l

[gcc/devel/omp/gcc-14] Merge branch 'releases/gcc-14' into devel/omp/gcc-14

2024-09-03 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:682fd948f835fd5ada2de45988448c91e10f5016

commit 682fd948f835fd5ada2de45988448c91e10f5016
Merge: 6d3c68ff05cf 59157c038d68
Author: Tobias Burnus 
Date:   Tue Sep 3 10:54:46 2024 +0200

Merge branch 'releases/gcc-14' into devel/omp/gcc-14

Merge up to r14-10627-g59157c038d683e (3rd Sep 2024)

Diff:

 gcc/ChangeLog  |   252 +
 gcc/DATESTAMP  | 2 +-
 gcc/config.gcc | 4 +-
 gcc/config/aarch64/aarch64-sve-builtins-base.cc| 6 +-
 gcc/config/avr/avr-protos.h| 2 +-
 gcc/config/avr/avr.cc  |45 +-
 gcc/config/avr/avr.md  |12 +-
 gcc/config/i386/avx512fp16intrin.h | 4 +-
 gcc/config/i386/constraints.md | 2 +-
 gcc/config/i386/i386-features.cc   |   191 +
 gcc/config/i386/i386-options.cc| 6 +
 gcc/config/i386/i386-passes.def| 3 +
 gcc/config/i386/i386-protos.h  | 1 +
 gcc/config/i386/i386.cc|   194 +-
 gcc/config/i386/prfchiintrin.h | 9 +
 gcc/config/i386/sse.md |49 +-
 gcc/config/loongarch/genopts/gen-evolution.awk | 7 +-
 gcc/config/pa/pa.cc| 1 +
 gcc/config/riscv/thead.cc  | 6 +-
 gcc/config/rs6000/aix71.h  | 1 +
 gcc/config/rs6000/aix72.h  | 1 +
 gcc/config/rs6000/aix73.h  | 1 +
 gcc/config/rs6000/driver-rs6000.cc | 2 +
 gcc/config/rs6000/power10.md   |   144 +-
 gcc/config/rs6000/ppc-auxv.h   | 3 +-
 gcc/config/rs6000/rs6000-builtin.cc| 1 +
 gcc/config/rs6000/rs6000-c.cc  | 2 +
 gcc/config/rs6000/rs6000-cpus.def  | 5 +
 gcc/config/rs6000/rs6000-opts.h| 1 +
 gcc/config/rs6000/rs6000-string.cc | 1 +
 gcc/config/rs6000/rs6000-tables.opt|11 +-
 gcc/config/rs6000/rs6000.cc|32 +-
 gcc/config/rs6000/rs6000.h | 1 +
 gcc/config/rs6000/rs6000.md| 2 +-
 gcc/config/rs6000/rs6000.opt   | 6 +
 gcc/config/s390/s390-builtin-types.def | 2 +
 gcc/config/s390/s390-builtins.def  | 2 +
 gcc/config/s390/vecintrin.h| 4 +-
 gcc/config/sh/sh.cc|12 +-
 gcc/cp/ChangeLog   |   100 +
 gcc/cp/constraint.cc   | 9 +-
 gcc/cp/coroutines.cc   | 8 +-
 gcc/cp/cp-tree.h   | 2 +-
 gcc/cp/parser.cc   |44 +-
 gcc/cp/pt.cc   |25 +-
 gcc/cp/tree.cc |51 +-
 gcc/doc/invoke.texi| 2 +-
 gcc/explow.cc  |15 +
 gcc/explow.h   | 2 +
 gcc/fortran/ChangeLog  |32 +
 gcc/fortran/gfortran.h | 4 +
 gcc/fortran/trans-array.cc |43 +
 gcc/fortran/trans-io.cc| 3 +-
 gcc/fortran/trans-types.cc | 7 +-
 gcc/go/gofrontend/expressions.cc   | 6 +
 gcc/po/ChangeLog   |18 +
 gcc/po/be.po   |  7712 +-
 gcc/po/da.po   |  7730 +-
 gcc/po/de.po   |  7727 +-
 gcc/po/el.po   |  7709 +-
 gcc/po/es.po   |  7737 +-
 gcc/po/fi.po   |  7718 +-
 gcc/po/fr.po   |  7729 +-
 gcc/po/hr.po   |  7715 +-
 gcc/po/id.po   |  7727 +-
 gcc/po/ja.po   |  7713 +-
 gcc/po/ka.po   | 83090 +++
 gcc/po/nl.po   |  7719 +-
 gcc/po/ru.po   |  7732 +-
 gcc/po/sr.po   |  7725 +-
 gcc/po/sv.po   |  7717 +-
 gcc/po/tr.po   |  7741 +-
 gcc/po/uk.po   |  7734 +-
 gcc/po/vi.po   |  7725 +-
 gcc/po/zh_CN.

[gcc r15-3413] LTO/WPA: Ensure that output_offload_tables only writes table once [PR116535]

2024-09-03 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:2fcccf21a34f92ea060b492c9b2aecb56cd5d167

commit r15-3413-g2fcccf21a34f92ea060b492c9b2aecb56cd5d167
Author: Tobias Burnus 
Date:   Tue Sep 3 12:02:23 2024 +0200

LTO/WPA: Ensure that output_offload_tables only writes table once [PR116535]

When ltrans was written concurrently, e.g. via -flto=N (N > 1, assuming
sufficient partiations, e.g., via -flto-partition=max), 
output_offload_tables
wrote the output tables once per fork.

PR lto/116535

gcc/ChangeLog:

* lto-cgraph.cc (output_offload_tables): Remove offload_ frees.
* lto-streamer-out.cc (lto_output): Make call to it depend on
lto_get_out_decl_state ()->output_offload_tables_p.
* lto-streamer.h (struct lto_out_decl_state): Add
output_offload_tables_p field.
* tree-pass.h (ipa_write_optimization_summaries): Add bool argument.
* passes.cc (ipa_write_summaries_1): Add bool
output_offload_tables_p arg.
(ipa_write_summaries): Update call.
(ipa_write_optimization_summaries): Accept output_offload_tables_p.

gcc/lto/ChangeLog:

* lto.cc (stream_out): Update call to
ipa_write_optimization_summaries to pass true for first partition.

Diff:
---
 gcc/lto-cgraph.cc   | 10 --
 gcc/lto-streamer-out.cc |  3 ++-
 gcc/lto-streamer.h  |  3 +++
 gcc/lto/lto.cc  |  2 +-
 gcc/passes.cc   | 11 ---
 gcc/tree-pass.h |  3 ++-
 6 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/gcc/lto-cgraph.cc b/gcc/lto-cgraph.cc
index 6395033ab9df..1492409427c9 100644
--- a/gcc/lto-cgraph.cc
+++ b/gcc/lto-cgraph.cc
@@ -1139,16 +1139,6 @@ output_offload_tables (void)
 
   streamer_write_uhwi_stream (ob->main_stream, 0);
   lto_destroy_simple_output_block (ob);
-
-  /* In WHOPR mode during the WPA stage the joint offload tables need to be
- streamed to one partition only.  That's why we free offload_funcs and
- offload_vars after the first call of output_offload_tables.  */
-  if (flag_wpa)
-{
-  vec_free (offload_funcs);
-  vec_free (offload_vars);
-  vec_free (offload_ind_funcs);
-}
 }
 
 /* Verify the partitioning of NODE.  */
diff --git a/gcc/lto-streamer-out.cc b/gcc/lto-streamer-out.cc
index 523d6dad221e..a4b171358d41 100644
--- a/gcc/lto-streamer-out.cc
+++ b/gcc/lto-streamer-out.cc
@@ -2829,7 +2829,8 @@ lto_output (void)
  statements using the statement UIDs.  */
   output_symtab ();
 
-  output_offload_tables ();
+  if (lto_get_out_decl_state ()->output_offload_tables_p)
+output_offload_tables ();
 
   if (flag_checking)
 {
diff --git a/gcc/lto-streamer.h b/gcc/lto-streamer.h
index 79c44d2cae71..4da1a3efe033 100644
--- a/gcc/lto-streamer.h
+++ b/gcc/lto-streamer.h
@@ -531,6 +531,9 @@ struct lto_out_decl_state
 
   /* True if decl state is compressed.  */
   bool compressed;
+
+  /* True if offload tables should be output. */
+  bool output_offload_tables_p;
 };
 
 typedef struct lto_out_decl_state *lto_out_decl_state_ptr;
diff --git a/gcc/lto/lto.cc b/gcc/lto/lto.cc
index 52dd436fd9a1..1ee215d8f1d3 100644
--- a/gcc/lto/lto.cc
+++ b/gcc/lto/lto.cc
@@ -178,7 +178,7 @@ stream_out (char *temp_filename, lto_symtab_encoder_t 
encoder, int part)
 
   gcc_assert (!dump_file);
   streamer_dump_file = dump_begin (TDI_lto_stream_out, NULL, part);
-  ipa_write_optimization_summaries (encoder);
+  ipa_write_optimization_summaries (encoder, part == 0);
 
   free (CONST_CAST (char *, file->filename));
 
diff --git a/gcc/passes.cc b/gcc/passes.cc
index d73f8ba97b64..057850f4decb 100644
--- a/gcc/passes.cc
+++ b/gcc/passes.cc
@@ -2829,11 +2829,13 @@ ipa_write_summaries_2 (opt_pass *pass, struct 
lto_out_decl_state *state)
summaries.  SET is the set of nodes to be written.  */
 
 static void
-ipa_write_summaries_1 (lto_symtab_encoder_t encoder)
+ipa_write_summaries_1 (lto_symtab_encoder_t encoder,
+  bool output_offload_tables_p)
 {
   pass_manager *passes = g->get_passes ();
   struct lto_out_decl_state *state = lto_new_out_decl_state ();
   state->symtab_node_encoder = encoder;
+  state->output_offload_tables_p = output_offload_tables_p;
 
   lto_output_init_mode_table ();
   lto_push_out_decl_state (state);
@@ -2897,7 +2899,8 @@ ipa_write_summaries (void)
 if (vnode->need_lto_streaming)
   lto_set_symtab_encoder_in_partition (encoder, vnode);
 
-  ipa_write_summaries_1 (compute_ltrans_boundary (encoder));
+  ipa_write_summaries_1 (compute_ltrans_boundary (encoder),
+flag_generate_offload);
 
   free (order);
   if (streamer_dump_file)
@@ -2952,10 +2955,12 @@ ipa_write_optimization_summaries_1 (opt_pass *pass,
NULL, write out all summaries of all nodes. */
 
 void
-ipa_write_optimization_summaries (lto_symtab_encoder_t encoder)
+ipa_write_optimization_summaries (lto_symtab_encoder_t encoder,
+   

[gcc r15-3510] Fortran: Add OpenMP 'interop' directive parsing support

2024-09-06 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:4ce9e0a579fcd216c1a3439525201473402a895d

commit r15-3510-g4ce9e0a579fcd216c1a3439525201473402a895d
Author: Tobias Burnus 
Date:   Fri Sep 6 11:45:46 2024 +0200

Fortran: Add OpenMP 'interop' directive parsing support

Parse OpenMP's 'interop' directive but stop with a 'sorry, unimplemented'
after resolving.

Additionally, it moves some clause dumping away from the end directive as
that lead to 'nowait' not being printed when it should as some cases were
missed.

gcc/fortran/ChangeLog:

* dump-parse-tree.cc (show_omp_namelist): Handle OMP_LIST_INIT.
(show_omp_clauses): Handle OMP_LIST_{INIT,USE,DESTORY}; move 
'nowait'
from end-directive to the directive dump.
(show_omp_node, show_code_node): Handle EXEC_OMP_INTEROP.
* gfortran.h (enum gfc_statement): Add ST_OMP_INTEROP.
(OMP_LIST_INIT, OMP_LIST_USE, OMP_LIST_DESTROY): Add.
(enum gfc_exec_op): Add EXEC_OMP_INTEROP.
(struct gfc_omp_namelist): Add interop items to union.
(gfc_free_omp_namelist): Add boolean arg.
* match.cc (gfc_free_omp_namelist): Update to free
interop union members.
* match.h (gfc_match_omp_interop): New.
* openmp.cc (gfc_omp_directives): Uncomment 'interop' entry.
(gfc_free_omp_clauses, gfc_match_omp_allocate,
gfc_match_omp_flush, gfc_match_omp_clause_reduction): Update
call.
(enum omp_mask2): Add OMP_CLAUSE_{INIT,USE,DESTROY}.
(OMP_INTEROP_CLAUSES): Use it.
(gfc_match_omp_clauses): Match those clauses.
(gfc_match_omp_prefer_type, gfc_match_omp_init,
gfc_match_omp_interop): New.
(resolve_omp_clauses): Handle interop clauses.
(omp_code_to_statement): Add ST_OMP_INTEROP.
(gfc_resolve_omp_directive): Add EXEC_OMP_INTEROP.
* parse.cc (decode_omp_directive): Parse 'interop' directive.
(next_statement, gfc_ascii_statement): Handle ST_OMP_INTEROP.
* st.cc (gfc_free_statement): Likewise
* resolve.cc (gfc_resolve_code): Handle EXEC_OMP_INTEROP.
* trans.cc (trans_code): Likewise.
* trans-openmp.cc (gfc_trans_omp_directive): Print 'sorry'
for EXEC_OMP_INTEROP.

gcc/testsuite/ChangeLog:

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

Diff:
---
 gcc/fortran/dump-parse-tree.cc   |  61 +++-
 gcc/fortran/gfortran.h   |  17 +-
 gcc/fortran/match.cc |  13 +-
 gcc/fortran/match.h  |   1 +
 gcc/fortran/openmp.cc| 412 +--
 gcc/fortran/parse.cc |   7 +
 gcc/fortran/resolve.cc   |   1 +
 gcc/fortran/st.cc|   3 +-
 gcc/fortran/trans-openmp.cc  |   3 +
 gcc/fortran/trans.cc |   3 +-
 gcc/testsuite/gfortran.dg/gomp/interop-1.f90 |  62 
 gcc/testsuite/gfortran.dg/gomp/interop-2.f90 |  46 +++
 gcc/testsuite/gfortran.dg/gomp/interop-3.f90 |  59 
 13 files changed, 651 insertions(+), 37 deletions(-)

diff --git a/gcc/fortran/dump-parse-tree.cc b/gcc/fortran/dump-parse-tree.cc
index 80aa8ef84e7..0971e6cfee7 100644
--- a/gcc/fortran/dump-parse-tree.cc
+++ b/gcc/fortran/dump-parse-tree.cc
@@ -1374,6 +1374,8 @@ show_omp_namelist (int list_type, gfc_omp_namelist *n)
}
  ns_iter = n->u2.ns;
}
+  else if (list_type == OMP_LIST_INIT && n != n2)
+   fputs (") INIT(", dumpfile);
   if (list_type == OMP_LIST_ALLOCATE)
{
  if (n->u2.allocator)
@@ -1525,6 +1527,39 @@ show_omp_namelist (int list_type, gfc_omp_namelist *n)
fputs (", ", dumpfile);
  continue;
}
+  else if (list_type == OMP_LIST_INIT)
+   {
+ int i = 0;
+ if (n->u.init.target)
+   fputs ("target,", dumpfile);
+ if (n->u.init.targetsync)
+   fputs ("targetsync,", dumpfile);
+ char *prefer_type = n->u.init.str;
+ if (n->u.init.len)
+   fputs ("prefer_type(", dumpfile);
+ if (n->u.init.len)
+   while (*prefer_type)
+ {
+   fputc ('{', dumpfile);
+   if (n->u2.interop_int && n->u2.interop_int[i] != 0)
+ fprintf (dumpfile, "fr(%d),", n->u2.interop_int[i]);
+   else if (prefer_type[0] != ' ' || prefer_type[1] != '\0')
+ fprintf (dumpfile, "fr(\"%s\"),", prefer_type);
+   prefer_type += 1 + strlen (prefer_type);
+
+   while (*prefer_type)
+ {
+   fprintf (dumpfile, "attr(\"%s\"),", prefer_type);
+   pre

[gcc r15-3581] fortran/openmp.cc: Fix var init and locus use to avoid uninit values [PR fortran/116661]

2024-09-11 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:4e9265a474def98cb6cdb59c15fbcb7630ba330e

commit r15-3581-g4e9265a474def98cb6cdb59c15fbcb7630ba330e
Author: Tobias Burnus 
Date:   Wed Sep 11 09:25:47 2024 +0200

fortran/openmp.cc: Fix var init and locus use to avoid uninit values [PR 
fortran/116661]

gcc/fortran/ChangeLog:

PR fortran/116661
* openmp.cc (gfc_match_omp_prefer_type): NULL init a gfc_expr
variable and use right locus in gfc_error.

Diff:
---
 gcc/fortran/openmp.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index c04d8b0f5281..1145e2ff8900 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -1860,6 +1860,7 @@ gfc_match_omp_prefer_type (char **pref_str, int 
*pref_str_len, int **pref_int_ar
  }
fr_found = true;
gfc_symbol *sym = NULL;
+   e = NULL;
locus loc = gfc_current_locus;
if (gfc_match_symbol (&sym, 0) != MATCH_YES
|| gfc_match (" _") == MATCH_YES)
@@ -1881,7 +1882,7 @@ gfc_match_omp_prefer_type (char **pref_str, int 
*pref_str_len, int **pref_int_ar
  {
gfc_error ("Expected constant integer identifier or "
   "non-empty default-kind character literal at %L",
-  &e->where);
+  &loc);
gfc_free_expr (e);
return MATCH_ERROR;
  }


[gcc r15-3582] OpenMP: Add interop routines to omp_runtime_api_procname

2024-09-11 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:6291f25631500c2d1c2328f919aa4405c3837f02

commit r15-3582-g6291f25631500c2d1c2328f919aa4405c3837f02
Author: Tobias Burnus 
Date:   Wed Sep 11 12:02:24 2024 +0200

OpenMP: Add interop routines to omp_runtime_api_procname

gcc/
* omp-general.cc (omp_runtime_api_procname): Add
omp_get_interop_{int,name,ptr,rc_desc,str,type_desc}
and omp_get_num_interop_properties.

Diff:
---
 gcc/omp-general.cc | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc
index 0b61335dba40..aaa179afe13e 100644
--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -3260,7 +3260,10 @@ omp_runtime_api_procname (const char *name)
   "alloc",
   "calloc",
   "free",
+  "get_interop_int",
+  "get_interop_ptr",
   "get_mapped_ptr",
+  "get_num_interop_properties",
   "realloc",
   "target_alloc",
   "target_associate_ptr",
@@ -3289,6 +3292,10 @@ omp_runtime_api_procname (const char *name)
   "get_device_num",
   "get_dynamic",
   "get_initial_device",
+  "get_interop_name",
+  "get_interop_rc_desc",
+  "get_interop_str",
+  "get_interop_type_desc",
   "get_level",
   "get_max_active_levels",
   "get_max_task_priority",


[gcc r15-3629] gcn/mkoffload.cc: Use #embed for including the generated ELF file

2024-09-13 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:508ef585243d4674d06b0737bfe8769fc18f824f

commit r15-3629-g508ef585243d4674d06b0737bfe8769fc18f824f
Author: Tobias Burnus 
Date:   Fri Sep 13 16:18:46 2024 +0200

gcn/mkoffload.cc: Use #embed for including the generated ELF file

gcc/ChangeLog:

* config/gcn/mkoffload.cc (read_file): Remove.
(process_asm): Do not add '#include' to generated C file.
(process_obj): Generate C file that uses #embed and use
__SIZE_TYPE__ and __UINTPTR_TYPE__ instead the #include-defined
size_t and uintptr.
(main): Update call to it; remove no longer needed file I/O.

Diff:
---
 gcc/config/gcn/mkoffload.cc | 79 +++--
 1 file changed, 12 insertions(+), 67 deletions(-)

diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc
index 345bbf7709c4..1f6337719e9d 100644
--- a/gcc/config/gcn/mkoffload.cc
+++ b/gcc/config/gcn/mkoffload.cc
@@ -182,44 +182,6 @@ xputenv (const char *string)
   putenv (CONST_CAST (char *, string));
 }
 
-/* Read the whole input file.  It will be NUL terminated (but
-   remember, there could be a NUL in the file itself.  */
-
-static const char *
-read_file (FILE *stream, size_t *plen)
-{
-  size_t alloc = 16384;
-  size_t base = 0;
-  char *buffer;
-
-  if (!fseek (stream, 0, SEEK_END))
-{
-  /* Get the file size.  */
-  long s = ftell (stream);
-  if (s >= 0)
-   alloc = s + 100;
-  fseek (stream, 0, SEEK_SET);
-}
-  buffer = XNEWVEC (char, alloc);
-
-  for (;;)
-{
-  size_t n = fread (buffer + base, 1, alloc - base - 1, stream);
-
-  if (!n)
-   break;
-  base += n;
-  if (base + 1 == alloc)
-   {
- alloc *= 2;
- buffer = XRESIZEVEC (char, buffer, alloc);
-   }
-}
-  buffer[base] = 0;
-  *plen = base;
-  return buffer;
-}
-
 /* Parse STR, saving found tokens into PVALUES and return their number.
Tokens are assumed to be delimited by ':'.  */
 
@@ -651,10 +613,6 @@ process_asm (FILE *in, FILE *out, FILE *cfile)
   struct oaccdims *dims = XOBFINISH (&dims_os, struct oaccdims *);
   struct regcount *regcounts = XOBFINISH (®counts_os, struct regcount *);
 
-  fprintf (cfile, "#include \n");
-  fprintf (cfile, "#include \n");
-  fprintf (cfile, "#include \n\n");
-
   fprintf (cfile, "static const int gcn_num_vars = %d;\n\n", var_count);
   fprintf (cfile, "static const int gcn_num_ind_funcs = %d;\n\n", 
ind_fn_count);
 
@@ -719,35 +677,28 @@ process_asm (FILE *in, FILE *out, FILE *cfile)
 /* Embed an object file into a C source file.  */
 
 static void
-process_obj (FILE *in, FILE *cfile, uint32_t omp_requires)
+process_obj (const char *fname_in, FILE *cfile, uint32_t omp_requires)
 {
-  size_t len = 0;
-  const char *input = read_file (in, &len);
-
   /* Dump out an array containing the binary.
- FIXME: do this with objcopy.  */
-  fprintf (cfile, "static unsigned char gcn_code[] = {");
-  for (size_t i = 0; i < len; i += 17)
-{
-  fprintf (cfile, "\n\t");
-  for (size_t j = i; j < i + 17 && j < len; j++)
-   fprintf (cfile, "%3u,", (unsigned char) input[j]);
-}
-  fprintf (cfile, "\n};\n\n");
+ If the file is empty, a parse error is shown as the argument to is_empty
+ is an undeclared identifier.  */
+  fprintf (cfile,
+  "static unsigned char gcn_code[] = {\n"
+  "#embed \"%s\" if_empty (error_file_is_empty)\n"
+  "};\n\n", fname_in);
 
   fprintf (cfile,
   "static const struct gcn_image {\n"
-  "  size_t size;\n"
+  "  __SIZE_TYPE__ size;\n"
   "  void *image;\n"
   "} gcn_image = {\n"
-  "  %zu,\n"
+  "  sizeof(gcn_code),\n"
   "  gcn_code\n"
-  "};\n\n",
-  len);
+  "};\n\n");
 
   fprintf (cfile,
   "static const struct gcn_data {\n"
-  "  uintptr_t omp_requires_mask;\n"
+  "  __UINTPTR_TYPE__ omp_requires_mask;\n"
   "  const struct gcn_image *gcn_image;\n"
   "  unsigned kernel_count;\n"
   "  const struct hsa_kernel_description *kernel_infos;\n"
@@ -1305,13 +1256,7 @@ main (int argc, char **argv)
   fork_execute (ld_argv[0], CONST_CAST (char **, ld_argv), true, 
".ld_args");
   obstack_free (&ld_argv_obstack, NULL);
 
-  in = fopen (gcn_o_name, "r");
-  if (!in)
-   fatal_error (input_location, "cannot open intermediate gcn obj file");
-
-  process_obj (in, cfile, omp_requires);
-
-  fclose (in);
+  process_obj (gcn_o_name, cfile, omp_requires);
 
   xputenv (concat ("GCC_EXEC_PREFIX=", execpath, NULL));
   xputenv (concat ("COMPILER_PATH=", cpath, NULL));


[gcc r15-3630] Fortran: Fixes to OpenMP 'interop' directive parsing support

2024-09-13 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:99988464fc86354f0359c0fd91eee444fb5bd8a2

commit r15-3630-g99988464fc86354f0359c0fd91eee444fb5bd8a2
Author: Tobias Burnus 
Date:   Fri Sep 13 16:48:57 2024 +0200

Fortran: Fixes to OpenMP 'interop' directive parsing support

Handle lists as argument to 'fr' and 'attr'; fix parsing corner cases.
Additionally, 'fr' values are now internally stored as integer, permitting
the diagnoses (warning) for values not defined in the OpenMP additional
definitions document.

PR fortran/116661

gcc/fortran/ChangeLog:

* gfortran.h (gfc_omp_namelist): Rename 'init' members for clarity.
* match.cc (gfc_free_omp_namelist): Handle renaming.
* dump-parse-tree.cc (show_omp_namelist): Update for new format
and features.
* openmp.cc (gfc_match_omp_prefer_type): Parse list to 'fr' and 
'attr';
store 'fr' values as integer.
(gfc_match_omp_init): Rename variable names.

gcc/ChangeLog:

* omp-api.h (omp_get_fr_id_from_name, omp_get_name_from_fr_id): New
prototypes.
* omp-general.cc (omp_get_fr_id_from_name, omp_get_name_from_fr_id):
New.

include/ChangeLog:

* gomp-constants.h (GOMP_INTEROP_IFR_LAST,
GOMP_INTEROP_IFR_SEPARATOR, GOMP_INTEROP_IFR_NONE): New.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/interop-1.f90: Extend, update dg-*.
* gfortran.dg/gomp/interop-2.f90: Update dg-error.
* gfortran.dg/gomp/interop-3.f90: Add dg-warning.

Diff:
---
 gcc/fortran/dump-parse-tree.cc   |  84 +---
 gcc/fortran/gfortran.h   |   4 +-
 gcc/fortran/match.cc |  10 +-
 gcc/fortran/openmp.cc| 305 ---
 gcc/omp-api.h|   3 +
 gcc/omp-general.cc   |  29 +++
 gcc/testsuite/gfortran.dg/gomp/interop-1.f90 |  32 ++-
 gcc/testsuite/gfortran.dg/gomp/interop-2.f90 |   2 +-
 gcc/testsuite/gfortran.dg/gomp/interop-3.f90 |   2 +-
 include/gomp-constants.h |   5 +
 10 files changed, 314 insertions(+), 162 deletions(-)

diff --git a/gcc/fortran/dump-parse-tree.cc b/gcc/fortran/dump-parse-tree.cc
index 8fc6141611c4..3547d7f8aca3 100644
--- a/gcc/fortran/dump-parse-tree.cc
+++ b/gcc/fortran/dump-parse-tree.cc
@@ -37,6 +37,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "constructor.h"
 #include "version.h"
 #include "parse.h"  /* For gfc_ascii_statement.  */
+#include "omp-api.h"  /* For omp_get_name_from_fr_id.  */
+#include "gomp-constants.h"  /* For GOMP_INTEROP_IFR_SEPARATOR.  */
 
 /* Keep track of indentation for symbol tree dumps.  */
 static int show_level = 0;
@@ -1537,35 +1539,69 @@ show_omp_namelist (int list_type, gfc_omp_namelist *n)
}
   else if (list_type == OMP_LIST_INIT)
{
- int i = 0;
  if (n->u.init.target)
fputs ("target,", dumpfile);
  if (n->u.init.targetsync)
fputs ("targetsync,", dumpfile);
- char *prefer_type = n->u.init.str;
- if (n->u.init.len)
-   fputs ("prefer_type(", dumpfile);
- if (n->u.init.len)
-   while (*prefer_type)
- {
-   fputc ('{', dumpfile);
-   if (n->u2.interop_int && n->u2.interop_int[i] != 0)
- fprintf (dumpfile, "fr(%d),", n->u2.interop_int[i]);
-   else if (prefer_type[0] != ' ' || prefer_type[1] != '\0')
- fprintf (dumpfile, "fr(\"%s\"),", prefer_type);
-   prefer_type += 1 + strlen (prefer_type);
-
-   while (*prefer_type)
- {
-   fprintf (dumpfile, "attr(\"%s\"),", prefer_type);
-   prefer_type += 1 + strlen (prefer_type);
- }
-   fputc ('}', dumpfile);
-   ++prefer_type;
-   ++i;
+ if (n->u2.init_interop_fr)
+   {
+ char *attr_str = n->u.init.attr;
+ int idx = 0;
+ int fr_id;
+ fputs ("prefer_type(", dumpfile);
+ do
+   {
+ fr_id = n->u2.init_interop_fr[idx];
+ fputc ('{', dumpfile);
+ if (fr_id != GOMP_INTEROP_IFR_NONE)
+   {
+ fputs ("fr(", dumpfile);
+ do
+   {
+ const char *fr_str = omp_get_name_from_fr_id (fr_id);
+ if (fr_str)
+   fprintf (dumpfile, "\"%s\"", fr_str);
+ else
+   fprintf (dumpfile, "%d", fr_id);
+ fr_id = n->u2.init_interop_fr[++idx];
+ if (fr_id != GOMP_INTEROP_IFR_SEPARATOR)
+   fputc (',', d

[gcc/devel/omp/gcc-14] (312 commits) Merge remote-tracking branch 'origin/releases/gcc-14' into

2024-07-22 Thread Tobias Burnus via Gcc-cvs
The branch 'devel/omp/gcc-14' was updated to point to:

 b71fc8d1382b... Merge remote-tracking branch 'origin/releases/gcc-14' into 

It previously pointed to:

 8678fc697046... Revert "[og10] vect: Add target hook to prefer gather/scatt

Diff:

Summary of changes (added commits):
---

  b71fc8d... Merge remote-tracking branch 'origin/releases/gcc-14' into 
  323d010... [PR115565] cse: Don't use a valid regno for non-register in (*)
  91a6faf... Daily bump. (*)
  043f3ad... Daily bump. (*)
  bb34b7e... s390: Fix unresolved iterators bhfgq and xdee (*)
  2eca8a9... Avoid undefined behaviour in build_option_suggestions (*)
  94e4661... Revert "Fortran: Auto array allocation with function depend (*)
  6b6a056... Daily bump. (*)
  d15664f... Fortran: Fix wrong code in unlimited polymorphic assignment (*)
  5034af8... Fortran: Auto array allocation with function dependencies [ (*)
  1205104... rs6000: Fix .machine cpu selection w/ altivec [PR97367] (*)
  ca0fa18... Fortran: character array constructor with >= 4 constant ele (*)
  187eec8... Fix Xcode 16 build break with NULL != nullptr (*)
  0abce41... RISC-V: Split vwadd.wx and vwsub.wx and add helpers. (*)
  937713a... RISC-V: Do not allow v0 as dest when merging [PR115068]. (*)
  3a7e796... RISC-V: Add -X to link spec (*)
  92003fa... RISC-V: Fix parsing of Zic* extensions (*)
  68ef0c3... RISC-V: Bugfix ICE for RVV intrinisc vfw on _Float16 scalar (*)
  c38dbfc... RISC-V: Fix missing boolean_expression in zmmul extension (*)
  4db3875... RISC-V: Bugfix vec_extract v mode iterator restriction mism (*)
  87346ed... RISC-V: Bugfix vec_extract vls mode iterator restriction mi (*)
  c32995c... [PATCH] RISC-V: Fix unrecognizable pattern in riscv_expand_ (*)
  2d7dda8... RISC-V: Use tu policy for first-element vec_set [PR115725]. (*)
  b218c42... [RISC-V] add implied extension repeatly until stable (*)
  a2a2916... Daily bump. (*)
  493035c... eh: ICE with std::initializer_list and ASan [PR115865] (*)
  747c4b5... Do not use caller-saved registers for COMDAT functions (*)
  c314867... c++: ICE with __has_unique_object_representations [PR115476 (*)
  a4c9ade... i386: PR target/115351: RTX costs for *concatditi3 and *ins (*)
  b0452ed... analyzer: fix ICE seen with -fsanitize=undefined [PR114899] (*)
  0b7ec50... Fix points_to_local_or_readonly_memory_p wrt TARGET_MEM_REF (*)
  0f593e4... PR tree-optimization/113673: Avoid load merging when potent (*)
  0fbad21... testsuite: Fix up builtin-clear-padding-3.c for -funsigned- (*)
  f0c3a1c... c++/modules: Conditionally start timer during lazy load [PR (*)
  4871b0f... Daily bump. (*)
  1bbfe78... c++: constrained partial spec type context [PR111890] (*)
  2249c63... c++: alias template with dependent attributes [PR115897] (*)
  79c5a09... c++: bad 'this' conversion for nullary memfn [PR106760] (*)
  3a963d4... alpha: Fix duplicate !tlsgd!62 assemble error [PR115526] (*)
  01dfc5b... bitint: Use gsi_insert_on_edge rather than gsi_insert_on_ed (*)
  d668f87... gimple-fold: Fix up __builtin_clear_padding lowering [PR115 (*)
  297ea7e... c++: Fix ICE on constexpr placement new [PR115754] (*)
  bf64404... vect: Merge loop mask and cond_op mask in fold-left reducti (*)
  c58bede... tree-optimization/115868 - ICE with .MASK_CALL in simdclone (*)
  5fad0b5... c++/modules: Propagate BINDING_VECTOR_*_DUPS_P on realloc [ (*)
  4039c74... Daily bump. (*)
  59ed01d... tree-optimization/115841 - reduction epilogue placement iss (*)
  06829e5... tree-optimization/115843 - fix wrong-code with fully-masked (*)
  e01012c... tree-optimization/115701 - fix maybe_duplicate_ssa_info_at_ (*)
  6f74a5f... tree-optimization/115701 - factor out maybe_duplicate_ssa_i (*)
  ca275b6... tree-optimization/115867 - ICE with simdcall vectorization  (*)
  4a04110... Fixup unaligned load/store cost for znver5 (*)
  d702a95... Fixup unaligned load/store cost for znver4 (*)
  c8fdef7... [alpha] adjust MEM alignment for block move [PR115459] (*)
  b3cff83... RISC-V: Allow adding enabled extension via target arch attr (*)
  0e1f599... RISC-V: Rewrite target attribute handling (*)
  b604d59... RISC-V: Fix comment/naming in attribute parsing code (*)
  20fb450... RISC-V: Deduplicate arch subset list processing (*)
  ea5907d... RISC-V: testsuite: Properly gate LTO tests (*)
  7bc63f1... [i386] adjust flag_omit_frame_pointer in a single function  (*)
  102bcf1... [i386] restore recompute to override opts after change [PR1 (*)
  1fff665... x86: Update branch hint for Redwood Cove. (*)
  0fcadb3... Daily bump. (*)
  71ec9ed... Fortran: improve attribute conflict checking [PR93635] (*)
  13bfc38... Fix SSA_NAME leak due to def_stmt is removed before use_stm (*)
  53dd1ce... Daily bump. (*)
  c80a746... fortran: Assume there is no cyclic reference with submodule (*)
  55988c4... fortran: Correctly evaluate scalar MASK arguments of MINLOC (*)
  8197264... Daily bump. (*)
  89f9342... LoongArch: TFmode is not allowed to be stored in th

[gcc r15-2226] install.texi (gcn): Suggest newer commit for Newlib

2024-07-23 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:b95c82d60c8c88f6346c5602f2e22a4531afe47c

commit r15-2226-gb95c82d60c8c88f6346c5602f2e22a4531afe47c
Author: Tobias Burnus 
Date:   Tue Jul 23 12:41:40 2024 +0200

install.texi (gcn): Suggest newer commit for Newlib

Newlib 4.4.0 lacks two commits: 7dd4eb1db (2024-03-25) to fix device console
output for GFX10/GFX11 and ed50a50b9 (2024-04-04) to make the added lock.h
compilable with C++. This commit mentiones now also the second commit.

gcc/ChangeLog:

* doc/install.texi (amdgcn-x-amdhsa): Suggest newer git version
for newlib.

Diff:
---
 gcc/doc/install.texi | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index b54569925837..dda623f4410a 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -3952,9 +3952,9 @@ Instead of GNU Binutils, you will need to install LLVM 
15, or later, and copy
 by specifying a @code{--with-multilib-list=} that does not list @code{gfx1100}
 and @code{gfx1103}.
 
-Use Newlib (4.3.0 or newer; 4.4.0 contains some improvements and git commit
-7dd4eb1db (2024-03-25, post-4.4.0) fixes device console output for GFX10 and
-GFX11 devices).
+Use Newlib (4.3.0 or newer; 4.4.0 contains some improvements and git commits
+7dd4eb1db and ed50a50b9 (2024-04-04, post-4.4.0) fix device console output
+for GFX10 and GFX11 devices).
 
 To run the binaries, install the HSA Runtime from the
 @uref{https://rocm.docs.amd.com/,,ROCm Platform}, and use


[gcc r14-9441] libgomp/libgomp.texi: Fix @node order in @menu

2024-03-12 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:ef79c64cb5762c86ee04ddfcedb7fe31eaa3bac8

commit r14-9441-gef79c64cb5762c86ee04ddfcedb7fe31eaa3bac8
Author: Tobias Burnus 
Date:   Tue Mar 12 15:42:50 2024 +0100

libgomp/libgomp.texi: Fix @node order in @menu

While texinfo 7.0.3 does not warn, an older texinfo did complain about:
libgomp.texi:1964: warning: node next `omp_target_memcpy' in menu
`omp_target_memcpy_rect' and in sectioning `omp_target_memcpy_async' differ

libgomp/

* libgomp.texi (Device Memory Routines): Swap item order to match
the order of the '@node's of the '@subsection's.

Diff:
---
 libgomp/libgomp.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index bf5c7a76fc9..57165e0e981 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -1783,8 +1783,8 @@ pointers on devices. They have C linkage and do not throw 
exceptions.
 * omp_target_is_present:: Check whether storage is mapped
 * omp_target_is_accessible:: Check whether memory is device accessible
 * omp_target_memcpy:: Copy data between devices
-* omp_target_memcpy_rect:: Copy a subvolume of data between devices
 * omp_target_memcpy_async:: Copy data between devices asynchronously
+* omp_target_memcpy_rect:: Copy a subvolume of data between devices
 * omp_target_memcpy_rect_async:: Copy a subvolume of data between devices 
asynchronously
 @c * omp_target_memset:: /TR12
 @c * omp_target_memset_async:: /TR12


[gcc r14-9446] OpenMP/Fortran: Fix defaultmap(none) issue with dummy procedures [PR114283]

2024-03-13 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:c5037fcee2de438774466e78e46e6ab4df72a7fe

commit r14-9446-gc5037fcee2de438774466e78e46e6ab4df72a7fe
Author: Tobias Burnus 
Date:   Wed Mar 13 09:35:28 2024 +0100

OpenMP/Fortran: Fix defaultmap(none) issue with dummy procedures [PR114283]

Dummy procedures look similar to variables but aren't - neither in Fortran
nor in OpenMP. As the middle end sees PARM_DECLs, mark them as predetermined
firstprivate for mapping (as already done in gfc_omp_predetermined_sharing).

This does not address the isses related to procedure pointers, which are
still discussed on spec level [see PR].

PR fortran/114283

gcc/fortran/ChangeLog:

* trans-openmp.cc (gfc_omp_predetermined_mapping): Map dummy
procedures as firstprivate.

libgomp/ChangeLog:

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

Diff:
---
 gcc/fortran/trans-openmp.cc|  9 +
 .../libgomp.fortran/declare-target-indirect-4.f90  | 43 ++
 2 files changed, 52 insertions(+)

diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index a2bf15665b3..1dba47126ed 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -343,6 +343,15 @@ gfc_omp_predetermined_mapping (tree decl)
&& GFC_DECL_SAVED_DESCRIPTOR (decl)))
 return OMP_CLAUSE_DEFAULTMAP_TO;
 
+  /* Dummy procedures aren't considered variables by OpenMP, thus are
+ disallowed in OpenMP clauses.  They are represented as PARM_DECLs
+ in the middle-end, so return OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE here
+ to avoid complaining about their uses with defaultmap(none).  */
+  if (TREE_CODE (decl) == PARM_DECL
+  && TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
+  && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == FUNCTION_TYPE)
+return OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE;
+
   /* These are either array or derived parameters, or vtables.  */
   if (VAR_P (decl) && TREE_READONLY (decl)
   && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
diff --git a/libgomp/testsuite/libgomp.fortran/declare-target-indirect-4.f90 
b/libgomp/testsuite/libgomp.fortran/declare-target-indirect-4.f90
new file mode 100644
index 000..43f4295494c
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/declare-target-indirect-4.f90
@@ -0,0 +1,43 @@
+! { dg-additional-options "-fdump-tree-gimple" }
+
+! PR fortran/114283
+
+! { dg-final { scan-tree-dump "#pragma omp parallel shared\\(i\\) if\\(0\\) 
default\\(none\\) firstprivate\\(g\\)" "gimple" } }
+! { dg-final { scan-tree-dump "#pragma omp target num_teams\\(-2\\) 
thread_limit\\(0\\) firstprivate\\(h\\) map\\(from:j \\\[len: 4\\\]\\) 
defaultmap\\(none\\)" "gimple" } }
+
+
+module m
+  implicit none (type, external)
+  !$omp declare target indirect enter(f1, f2)
+contains
+  integer function f1 ()
+f1 = 99
+  end
+  integer function f2 ()
+f2 = 89
+  end
+end module m
+
+use m
+implicit none (type, external)
+call sub1(f1)
+call sub2(f2)
+contains
+  subroutine sub1(g)
+procedure(integer) :: g
+integer :: i
+!$omp parallel default(none) if(.false.) shared(i)
+  i = g ()
+!$omp end parallel
+if (i /= 99) stop 1
+  end
+
+  subroutine sub2(h)
+procedure(integer) :: h
+integer :: j
+!$omp target defaultmap(none) map(from:j)
+  j = h ()
+!$omp end target
+if (j /= 89) stop 1
+  end
+end


[gcc r14-9770] GCN: Fix --with-arch= handling in mkoffload [PR111966]

2024-04-03 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:b2460d621efe740bd95ad41afef6d806ec1bd9c7

commit r14-9770-gb2460d621efe740bd95ad41afef6d806ec1bd9c7
Author: Tobias Burnus 
Date:   Wed Apr 3 12:37:39 2024 +0200

GCN: Fix --with-arch= handling in mkoffload [PR111966]

The default -march= setting used in mkoffload did not reflect the modified
default set by GCC's configure-time --with-arch=, causing issues when
generating debug code.

gcc/ChangeLog:

PR other/111966
* config/gcn/mkoffload.cc (get_arch): New; moved -march= flag
handling from ...
(main): ... here; call it to handle --with-arch config option
and -march= commandline.

Diff:
---
 gcc/config/gcn/mkoffload.cc | 90 -
 1 file changed, 72 insertions(+), 18 deletions(-)

diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc
index 04356b86195..9a438de331a 100644
--- a/gcc/config/gcn/mkoffload.cc
+++ b/gcc/config/gcn/mkoffload.cc
@@ -35,6 +35,8 @@
 #include "gomp-constants.h"
 #include "simple-object.h"
 #include "elf.h"
+#include "configargs.h"  /* For configure_default_options.  */
+#include "multilib.h"  /* For multilib_options.  */
 
 /* These probably won't (all) be in elf.h for a while.  */
 #undef  EM_AMDGPU
@@ -846,6 +848,62 @@ compile_native (const char *infile, const char *outfile, 
const char *compiler,
   obstack_free (&argv_obstack, NULL);
 }
 
+static int
+get_arch (const char *str, const char *with_arch_str)
+{
+  if (strcmp (str, "fiji") == 0)
+return EF_AMDGPU_MACH_AMDGCN_GFX803;
+  else if (strcmp (str, "gfx900") == 0)
+return EF_AMDGPU_MACH_AMDGCN_GFX900;
+  else if (strcmp (str, "gfx906") == 0)
+return EF_AMDGPU_MACH_AMDGCN_GFX906;
+  else if (strcmp (str, "gfx908") == 0)
+return EF_AMDGPU_MACH_AMDGCN_GFX908;
+  else if (strcmp (str, "gfx90a") == 0)
+return EF_AMDGPU_MACH_AMDGCN_GFX90a;
+  else if (strcmp (str, "gfx1030") == 0)
+return EF_AMDGPU_MACH_AMDGCN_GFX1030;
+  else if (strcmp (str, "gfx1036") == 0)
+return EF_AMDGPU_MACH_AMDGCN_GFX1036;
+  else if (strcmp (str, "gfx1100") == 0)
+return EF_AMDGPU_MACH_AMDGCN_GFX1100;
+  else if (strcmp (str, "gfx1103") == 0)
+return EF_AMDGPU_MACH_AMDGCN_GFX1103;
+
+  error ("unrecognized argument in option %<-march=%s%>", str);
+
+  /* The suggestions are based on the configured multilib support; the compiler
+ itself might support more.  */
+  if (multilib_options[0] != '\0')
+{
+  /* Example: "march=gfx900/march=gfx906" */
+  char *args = (char *) alloca (strlen (multilib_options));
+  const char *p = multilib_options, *q = NULL;
+  args[0] = '\0';
+  while (true)
+   {
+ p = strchr (p, '=');
+ if (!p)
+   break;
+ if (q)
+   strcat (args, ", ");
+ ++p;
+ q = strchr (p, '/');
+ if (q)
+   strncat (args, p, q-p);
+ else
+   strcat (args, p);
+   }
+  inform (UNKNOWN_LOCATION, "valid arguments to %<-march=%> are: %s", 
args);
+}
+  else if (with_arch_str)
+inform (UNKNOWN_LOCATION, "valid argument to %<-march=%> is %qs", 
with_arch_str);
+
+  exit (FATAL_EXIT_CODE);
+
+  return 0;
+}
+
 int
 main (int argc, char **argv)
 {
@@ -853,9 +911,21 @@ main (int argc, char **argv)
   FILE *out = stdout;
   FILE *cfile = stdout;
   const char *outname = 0;
+  const char *with_arch_str = NULL;
 
   progname = tool_name;
+  gcc_init_libintl ();
   diagnostic_initialize (global_dc, 0);
+  diagnostic_color_init (global_dc);
+
+  for (size_t i = 0; i < ARRAY_SIZE (configure_default_options); i++)
+if (configure_default_options[i].name != NULL
+   && strcmp (configure_default_options[i].name, "arch") == 0)
+  {
+   with_arch_str = configure_default_options[0].value;
+   elf_arch = get_arch (configure_default_options[0].value, NULL);
+   break;
+  }
 
   obstack_init (&files_to_cleanup);
   if (atexit (mkoffload_cleanup) != 0)
@@ -961,24 +1031,8 @@ main (int argc, char **argv)
   else if (strcmp (argv[i], "-dumpbase") == 0
   && i + 1 < argc)
dumppfx = argv[++i];
-  else if (strcmp (argv[i], "-march=fiji") == 0)
-   elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX803;
-  else if (strcmp (argv[i], "-march=gfx900") == 0)
-   elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX900;
-  else if (strcmp (argv[i], "-march=gfx906") == 0)
-   elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX906;
-  else if (strcmp (argv[i], "-march=gfx908") == 0)
-   elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX908;
-  else if (strcmp (argv[i], "-march=gfx90a") == 0)
-   elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX90a;
-  else if (strcmp (argv[i], "-march=gfx1030") == 0)
-   elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX1030;
-  else if (strcmp (argv[i], "-march=gfx1036") == 0)
-   elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX1036;
-  else if (strcmp (argv[i], "-march=gfx1100") == 0)
-   elf_arch = EF_AMD

[gcc r14-9772] GCN: install.texi update for Newlib change and LLVM 18 release

2024-04-03 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:ce7cb109ff429bcdca03fccfc444b610c6cb528b

commit r14-9772-gce7cb109ff429bcdca03fccfc444b610c6cb528b
Author: Tobias Burnus 
Date:   Wed Apr 3 14:16:41 2024 +0200

GCN: install.texi update for Newlib change and LLVM 18 release

gcc/ChangeLog:

* doc/install.texi (amdgcn-*-amdhsa): Update Newlib recommendation
and update wording for LLVM 18 release.

Diff:
---
 gcc/doc/install.texi | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 269fe7ec870..970b1a67e74 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -3944,7 +3944,9 @@ Instead of GNU Binutils, you will need to install LLVM 
15, or later, and copy
 by specifying a @code{--with-multilib-list=} that does not list @code{gfx1100}
 and @code{gfx1103}.
 
-Use Newlib (4.3.0 or newer; 4.4.0 or later is recommended).
+Use Newlib (4.3.0 or newer; 4.4.0 contains some improvements and git commit
+7dd4eb1db (2025-03-25, post-4.4.0) fixes device console output for GFX10 and
+GFX11 devices).
 
 To run the binaries, install the HSA Runtime from the
 @uref{https://rocm.docs.amd.com/,,ROCm Platform}, and use
@@ -3954,8 +3956,8 @@ on the GPU.
 To enable support for GCN3 Fiji devices (gfx803), GCC has to be configured with
 @option{--with-arch=@code{fiji}} or
 @option{--with-multilib-list=@code{fiji},...}.  Note that support for Fiji
-devices has been removed in ROCm 4.0 and support in LLVM is deprecated and will
-be removed in LLVM 18.
+devices has been removed in ROCm 4.0 and support in LLVM was deprecated and has
+been removed in LLVM 18.
 
 @html
 


[gcc r14-9774] lto-wrapper.cc: Add offload target name to 'offload_args' suffix

2024-04-03 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:6f91cce9a314cd4bce16fe52a2ffbeb93d59320b

commit r14-9774-g6f91cce9a314cd4bce16fe52a2ffbeb93d59320b
Author: Tobias Burnus 
Date:   Wed Apr 3 15:47:12 2024 +0200

lto-wrapper.cc: Add offload target name to 'offload_args' suffix

lto-wrapper.cc's compile_offload_image calls mkoffload with
an @./a.offload_args argument ('a.' in case of, e.g., 'a.out'). However,
when generating code for both nvptx and gcn, they use the same name
with -save-temps. Hence, this commit adds a  + '.' before
'offload_args' in line with other offload-target-specific files.

gcc/ChangeLog:

* lto-wrapper.cc (compile_offload_image): Prefix 'offload_args'
suffix by the target name.

Diff:
---
 gcc/lto-wrapper.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/lto-wrapper.cc b/gcc/lto-wrapper.cc
index ca53e4b462e..610594cdc2b 100644
--- a/gcc/lto-wrapper.cc
+++ b/gcc/lto-wrapper.cc
@@ -993,7 +993,8 @@ compile_offload_image (const char *target, const char 
*compiler_path,
 
   obstack_ptr_grow (&argv_obstack, NULL);
   argv = XOBFINISH (&argv_obstack, char **);
-  fork_execute (argv[0], argv, true, "offload_args");
+  suffix = concat (target, ".offload_args", NULL);
+  fork_execute (argv[0], argv, true, suffix);
   obstack_free (&argv_obstack, NULL);
 
   free_array_of_ptrs ((void **) paths, n_paths);


[gcc r14-9785] libgomp.texi: Update entries in OpenMP TR12 implementation status

2024-04-04 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:1c89d1b9dc8c4957a4ec3674f691595641fd279b

commit r14-9785-g1c89d1b9dc8c4957a4ec3674f691595641fd279b
Author: Tobias Burnus 
Date:   Thu Apr 4 12:20:48 2024 +0200

libgomp.texi: Update entries in OpenMP TR12 implementation status

libgomp/ChangeLog:

* libgomp.texi (TR12): Honor post-TR12 directive name change; add
item about curly braces/BLOCK permitted in canonical loop nests.

Diff:
---
 libgomp/libgomp.texi | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 1ae0f01ccdc..71d62105a20 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -515,7 +515,8 @@ Technical Report (TR) 12 is the second preview for OpenMP 
6.0.
 @item @code{strict} modifier keyword to @code{num_threads} @tab N @tab
 @item @code{atomic} permitted in a construct with @code{order(concurrent)}
   @tab N @tab
-@item @code{coexecute} directive for Fortran @tab N @tab
+@item @code{workdistribute} directive for Fortran @tab N
+  @tab Renamed just after TR12; added in TR12 as @code{coexecute}
 @item Fortran DO CONCURRENT as associated loop in a @code{loop} construct
   @tab N @tab
 @item @code{threadset} clause in task-generating constructs @tab N @tab
@@ -539,6 +540,8 @@ Technical Report (TR) 12 is the second preview for OpenMP 
6.0.
 
 @unnumberedsubsec Other new TR 12 features
 @multitable @columnfractions .60 .10 .25
+@item Canonical loop nest enclosed in (multiple) curly braces (C/C++) or BLOCK 
constructs (Fortran)
+  @tab N @tab
 @item Relaxed Fortran restrictions to the @code{aligned} clause @tab N @tab
 @item Mapping lambda captures @tab N @tab
 @item New @code{omp_pause_stop_tool} constant for omp_pause_resource @tab N 
@tab


[gcc r14-9792] nvptx: In mkoffload.cc, call diagnostic_color_init + gcc_init_libintl

2024-04-04 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:7520a4992c94254016085a461c58c972497c4483

commit r14-9792-g7520a4992c94254016085a461c58c972497c4483
Author: Tobias Burnus 
Date:   Thu Apr 4 21:55:29 2024 +0200

nvptx: In mkoffload.cc, call diagnostic_color_init + gcc_init_libintl

gcc/ChangeLog:

* config/nvptx/mkoffload.cc (main): Call
gcc_init_libintl and diagnostic_color_init.

Diff:
---
 gcc/config/nvptx/mkoffload.cc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/config/nvptx/mkoffload.cc b/gcc/config/nvptx/mkoffload.cc
index a7fc28cbd3f..503b1abcefd 100644
--- a/gcc/config/nvptx/mkoffload.cc
+++ b/gcc/config/nvptx/mkoffload.cc
@@ -638,7 +638,9 @@ main (int argc, char **argv)
   const char *outname = 0;
 
   progname = tool_name;
+  gcc_init_libintl ();
   diagnostic_initialize (global_dc, 0);
+  diagnostic_color_init (global_dc);
 
   if (atexit (mkoffload_cleanup) != 0)
 fatal_error (input_location, "atexit failed");


[gcc r14-9843] Fortran: Accept again tab as alternative to space as separator [PR114304]

2024-04-08 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:477c8a82f38e353a8c6313b38197c70b12deea80

commit r14-9843-g477c8a82f38e353a8c6313b38197c70b12deea80
Author: Tobias Burnus 
Date:   Mon Apr 8 21:47:51 2024 +0200

Fortran: Accept again tab as alternative to space as separator [PR114304]

This fixes a side-effect of/regression caused by r14-9822-g93adf88cc6744a,
which was for the same PR.

PR libfortran/114304

libgfortran/ChangeLog:

* io/list_read.c (eat_separator): Accept tab as alternative to 
space.

gcc/testsuite/ChangeLog:

* gfortran.dg/pr114304-2.f90: New test.

Diff:
---
 gcc/testsuite/gfortran.dg/pr114304-2.f90 | 82 
 libgfortran/io/list_read.c   |  2 +-
 2 files changed, 83 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gfortran.dg/pr114304-2.f90 
b/gcc/testsuite/gfortran.dg/pr114304-2.f90
new file mode 100644
index 000..5ef5874f528
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr114304-2.f90
@@ -0,0 +1,82 @@
+! { dg-do run }
+!
+! PR fortran/114304
+!
+! Ensure that '\t' (tab) is supported as separator in list-directed input
+! While not really standard conform, this is widely used in user input and
+! widely supported.
+!
+
+use iso_c_binding
+implicit none
+character(len=*,kind=c_char), parameter :: tab = C_HORIZONTAL_TAB
+
+! Accept '' as variant to ' ' as separator
+! Check that  and  are handled
+
+character(len=*,kind=c_char), parameter :: nml_str &
+   = '&inparm'//C_CARRIAGE_RETURN // C_NEW_LINE // &
+ 'first'//tab//'='//tab//' .true.'// C_NEW_LINE // &
+ ' , other'//tab//' ='//tab//'3'//tab//', 2'//tab//'/'
+
+! Check that  is handled,
+
+! Note: For new line, Unix uses \n, Windows \r\n but old Apple systems used 
'\r'
+!
+! Gfortran does not seem to support all \r, but the following is supported
+! since ages, ! which seems to be a gfortran extension as ifort and flang 
don't like it.
+
+character(len=*,kind=c_char), parameter :: nml_str2 &
+   = '&inparm'//C_CARRIAGE_RETURN // C_NEW_LINE // &
+ 'first'//C_NEW_LINE//'='//tab//' .true.'// C_CARRIAGE_RETURN // &
+ ' , other'//tab//' ='//tab//'3'//tab//', 2'//tab//'/'
+
+character(len=*,kind=c_char), parameter :: str &
+   = tab//'1'//tab//'2,'//tab//'3'//tab//',4'//tab//','//tab//'5'//tab//'/'
+character(len=*,kind=c_char), parameter :: str2 &
+   = tab//'1'//tab//'2;'//tab//'3'//tab//';4'//tab//';'//tab//'5'//tab//'/'
+logical :: first
+integer :: other(4)
+integer :: ints(6)
+namelist /inparm/ first , other
+
+other = 1
+
+open(99, file="test.inp")
+write(99, '(a)') nml_str
+rewind(99)
+read(99,nml=inparm)
+close(99, status="delete")
+
+if (.not.first .or. any (other /= [3,2,1,1])) stop 1
+
+other = 9
+
+open(99, file="test.inp")
+write(99, '(a)') nml_str2
+rewind(99)
+read(99,nml=inparm)
+close(99, status="delete")
+
+if (.not.first .or. any (other /= [3,2,9,9])) stop 2
+
+ints = 66
+
+open(99, file="test.inp", decimal='point')
+write(99, '(a)') str
+rewind(99)
+read(99,*) ints
+close(99, status="delete")
+
+if (any (ints /= [1,2,3,4,5,66])) stop 3
+
+ints = 77 
+
+open(99, file="test.inp", decimal='comma')
+write(99, '(a)') str2
+rewind(99)
+read(99,*) ints
+close(99, status="delete")
+
+if (any (ints /= [1,2,3,4,5,77])) stop 4
+end
diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c
index b56f2a4e6d6..5bbbef26c26 100644
--- a/libgfortran/io/list_read.c
+++ b/libgfortran/io/list_read.c
@@ -463,7 +463,7 @@ eat_separator (st_parameter_dt *dtp)
 
   dtp->u.p.comma_flag = 0;
   c = next_char (dtp);
-  if (c == ' ')
+  if (c == ' ' || c == '\t')
 {
   eat_spaces (dtp);
   c = next_char (dtp);


[gcc r15-2377] libgomp: Fix declare target link with offset array-section mapping [PR116107]

2024-07-29 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:14c47e7eb06e8b95913794f6059560fc2fa6de91

commit r15-2377-g14c47e7eb06e8b95913794f6059560fc2fa6de91
Author: Tobias Burnus 
Date:   Mon Jul 29 11:40:38 2024 +0200

libgomp: Fix declare target link with offset array-section mapping 
[PR116107]

Assume that 'int var[100]' is 'omp declare target link(var)'. When now
mapping an array section with offset such as 'map(to:var[20:10])',
the device-side link pointer has to store &[0] minus
the offset such that var[20] will access [0]. But
the offset calculation was missed such that the device-side 'var' pointed
to the first element of the mapped data - and var[20] points beyond at
some invalid memory.

PR middle-end/116107

libgomp/ChangeLog:

* target.c (gomp_map_vars_internal): Honor array mapping offsets
with declare-target 'link' variables.
* testsuite/libgomp.c-c++-common/target-link-2.c: New test.

Diff:
---
 libgomp/target.c   |  7 ++-
 .../testsuite/libgomp.c-c++-common/target-link-2.c | 59 ++
 2 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/libgomp/target.c b/libgomp/target.c
index aa01c1367b98..efed6ad68ff4 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -1820,8 +1820,11 @@ gomp_map_vars_internal (struct gomp_device_descr 
*devicep,
if (k->aux && k->aux->link_key)
  {
/* Set link pointer on target to the device address of the
-  mapped object.  */
-   void *tgt_addr = (void *) (tgt->tgt_start + k->tgt_offset);
+  mapped object.  Also deal with offsets due to
+  array-section mapping.  */
+   void *tgt_addr = (void *) (tgt->tgt_start + k->tgt_offset
+  - (k->host_start
+ - 
k->aux->link_key->host_start));
/* We intentionally do not use coalescing here, as it's not
   data allocated by the current call to this function.  */
gomp_copy_host2dev (devicep, aq, (void *) n->tgt_offset,
diff --git a/libgomp/testsuite/libgomp.c-c++-common/target-link-2.c 
b/libgomp/testsuite/libgomp.c-c++-common/target-link-2.c
new file mode 100644
index ..15da1656ebf9
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c-c++-common/target-link-2.c
@@ -0,0 +1,59 @@
+/* { dg-do run }  */
+/* PR middle-end/116107  */
+
+#include 
+
+int arr[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
+#pragma omp declare target link(arr)
+
+#pragma omp begin declare target
+void f(int *res)
+{
+  __builtin_memcpy (res, &arr[5], sizeof(int)*10);
+}
+
+void g(int *res)
+{
+  __builtin_memcpy (res, &arr[3], sizeof(int)*10);
+}
+#pragma omp end declare target
+
+int main()
+{
+  int res[10], res2;
+  for (int dev = 0; dev < omp_get_num_devices(); dev++)
+{
+  __builtin_memset (res, 0, sizeof (res));
+  res2 = 99;
+
+  #pragma omp target enter data map(arr[5:10]) device(dev)
+
+  #pragma omp target map(from: res) device(dev)
+   f (res);
+
+  #pragma omp target map(from: res2) device(dev)
+   res2 = arr[5];
+
+  if (res2 != 6)
+   __builtin_abort ();
+  for (int i = 0; i < 10; i++)
+   if (res[i] != 6 + i)
+ __builtin_abort ();
+
+  #pragma omp target exit data map(release:arr[5:10]) device(dev)
+
+  for (int i = 0; i < 15; i++)
+   arr[i] *= 10;
+  __builtin_memset (res, 0, sizeof (res));
+
+  #pragma omp target enter data map(arr[3:10]) device(dev)
+
+  #pragma omp target map(from: res) device(dev)
+   g (res);
+
+  for (int i = 0; i < 10; i++)
+   if (res[i] != (4 + i)*10)
+ __builtin_abort ();
+}
+  return 0;
+}


[gcc r15-2378] OpenMP/Fortran: Fix handling of 'declare target' with 'link' clause [PR115559]

2024-07-29 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:29b1587e7d34667a1fd63071c1e4f5475cd71026

commit r15-2378-g29b1587e7d34667a1fd63071c1e4f5475cd71026
Author: Tobias Burnus 
Date:   Mon Jul 29 11:46:57 2024 +0200

OpenMP/Fortran: Fix handling of 'declare target' with 'link' clause 
[PR115559]

Contrary to a normal 'declare target', the 'declare target link' attribute
also needs to set node->offloadable and push the offload_vars in the front 
end.

Linked variables require that the data is mapped. For module variables, this
can happen anywhere. For variables in an external subprograms or the main
programm, this can only happen in the either that program itself or in an
internal subprogram. - Whether a variable is just normally mapped or linked 
then
becomes relevant if a device routine exists that can access that variable,
i.e. an internal procedure has then to be marked as declare target.

PR fortran/115559

gcc/fortran/ChangeLog:

* trans-common.cc (build_common_decl): Add 'omp declare target' and
'omp declare target link' variables to offload_vars.
* trans-decl.cc (add_attributes_to_decl): Likewise; update args and
call decl_attributes.
(get_proc_pointer_decl, gfc_get_extern_function_decl,
build_function_decl): Update calls.
(gfc_get_symbol_decl): Likewise; move after 'DECL_STATIC (t)=1'
to avoid errors with symtab_node::get_create.

libgomp/ChangeLog:

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

Diff:
---
 gcc/fortran/trans-common.cc|  21 
 gcc/fortran/trans-decl.cc  |  81 +-
 .../libgomp.fortran/declare-target-link.f90| 116 +
 3 files changed, 192 insertions(+), 26 deletions(-)

diff --git a/gcc/fortran/trans-common.cc b/gcc/fortran/trans-common.cc
index 5f44e7bd663d..e714342c3c0b 100644
--- a/gcc/fortran/trans-common.cc
+++ b/gcc/fortran/trans-common.cc
@@ -98,6 +98,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "coretypes.h"
 #include "tm.h"
 #include "tree.h"
+#include "cgraph.h"
+#include "context.h"
+#include "omp-offload.h"
 #include "gfortran.h"
 #include "trans.h"
 #include "stringpool.h"
@@ -497,6 +500,24 @@ build_common_decl (gfc_common_head *com, tree union_type, 
bool is_init)
  = tree_cons (get_identifier ("omp declare target"),
   omp_clauses, DECL_ATTRIBUTES (decl));
 
+  if (com->omp_declare_target_link || com->omp_declare_target)
+   {
+ /* Add to offload_vars; get_create does so for omp_declare_target,
+omp_declare_target_link requires manual work.  */
+ gcc_assert (symtab_node::get (decl) == 0);
+ symtab_node *node = symtab_node::get_create (decl);
+ if (node != NULL && com->omp_declare_target_link)
+   {
+ node->offloadable = 1;
+ if (ENABLE_OFFLOADING)
+   {
+ g->have_offload = true;
+ if (is_a  (node))
+   vec_safe_push (offload_vars, decl);
+   }
+   }
+   }
+
   /* Place the back end declaration for this common block in
  GLOBAL_BINDING_LEVEL.  */
   gfc_map_of_all_commons[identifier] = pushdecl_top_level (decl);
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 82fa2bb61349..0fdc41b1784b 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -46,7 +46,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "trans-stmt.h"
 #include "gomp-constants.h"
 #include "gimplify.h"
+#include "context.h"
 #include "omp-general.h"
+#include "omp-offload.h"
 #include "attr-fnspec.h"
 #include "tree-iterator.h"
 #include "dependency.h"
@@ -1472,19 +1474,18 @@ gfc_add_assign_aux_vars (gfc_symbol * sym)
 }
 
 
-static tree
-add_attributes_to_decl (symbol_attribute sym_attr, tree list)
+static void
+add_attributes_to_decl (tree *decl_p, const gfc_symbol *sym)
 {
   unsigned id;
-  tree attr;
+  tree list = NULL_TREE;
+  symbol_attribute sym_attr = sym->attr;
 
   for (id = 0; id < EXT_ATTR_NUM; id++)
 if (sym_attr.ext_attr & (1 << id) && ext_attr_list[id].middle_end_name)
   {
-   attr = build_tree_list (
-get_identifier (ext_attr_list[id].middle_end_name),
-NULL_TREE);
-   list = chainon (list, attr);
+   tree ident = get_identifier (ext_attr_list[id].middle_end_name);
+   list = tree_cons (ident, NULL_TREE, list);
   }
 
   tree clauses = NULL_TREE;
@@ -1547,6 +1548,7 @@ add_attributes_to_decl (symbol_attribute sym_attr, tree 
list)
   clauses = c;
 }
 
+  bool has_declare = true;
   if (sym_attr.omp_declare_target_link
   || sym_attr.oacc_declare_link)
 list = tree_cons (get_identifier ("omp declare target link"),
@@ -1558,12 +1560,45 @@ add_attributes_t

[gcc/devel/omp/gcc-14] (33 commits) Merge remote-tracking branch 'origin/releases/gcc-14' into

2024-07-29 Thread Tobias Burnus via Gcc-cvs
The branch 'devel/omp/gcc-14' was updated to point to:

 8ad1a509662a... Merge remote-tracking branch 'origin/releases/gcc-14' into 

It previously pointed to:

 b71fc8d1382b... Merge remote-tracking branch 'origin/releases/gcc-14' into 

Diff:

Summary of changes (added commits):
---

  8ad1a50... Merge remote-tracking branch 'origin/releases/gcc-14' into 
  9e05aff... OpenMP/Fortran: Fix handling of 'declare target' with 'link
  c9e52a1... libgomp: Fix declare target link with offset array-section 
  98baaa1... Fix ICE with -fdump-tree-moref (*)
  affb2e8... i386: Fix AVX512 intrin macro typo (*)
  b858a51... Daily bump. (*)
  c3eef3d... Daily bump. (*)
  8eae5b0... Daily bump. (*)
  92eb0ee... Daily bump. (*)
  a32aff1... Regenerate gcc.pot (*)
  a7f07e5... Daily bump. (*)
  181f40f... testsuite: Fix up pr116034.c test for big/pdp endian [PR116 (*)
  ab03866... RISC-V: Disable Zba optimization pattern if XTheadMemIdx is (*)
  ae2909a... Daily bump. (*)
  a544898... testsuite: Disable finite math only for test  [PR115826] (*)
  b41487a... libstdc++: Use [[maybe_unused]] attribute in src/c++23/prin (*)
  5fad887... libstdc++: Do not use isatty on avr [PR115482] (*)
  084768c... ssa: Fix up maybe_rewrite_mem_ref_base complex type handlin (*)
  81f356f... i386: Change prefetchi output template (*)
  109b389... [powerpc] [testsuite] reorder dg directives [PR106069] (*)
  066c789... c++/coroutines: correct passing *this to promise type [PR10 (*)
  50ff112... c++: xobj fn call without obj [PR115783] (*)
  dfae324... Daily bump. (*)
  9ddd5f8... Fix modref's iteraction with store merging (*)
  bd535b4... rs6000: Catch unsupported ABI errors when using -mrop-prote (*)
  35e5c2d... rs6000: Error on CPUs and ABIs that don't support the ROP p (*)
  e2d746e... rs6000: ROP - Emit hashst and hashchk insns on Power8 and l (*)
  33ebeb2... rs6000: Compute rop_hash_save_offset for non-Altivec compil (*)
  c33532c... rs6000: Update ELFv2 stack frame comment showing the correc (*)
  27ef3a0... Fix modref_eaf_analysis::analyze_ssa_name handling of value (*)
  f2e9808... Fix accounting of offsets in unadjusted_ptr_and_unit_offset (*)
  c5397d3... Compare loop bounds in ipa-icf (*)
  9a7d668... Reduce recursive inlining of always_inline functions (*)

(*) This commit already exists in another branch.
Because the reference `refs/heads/devel/omp/gcc-14' matches
your hooks.email-new-commits-only configuration,
no separate email is sent for this commit.


[gcc/devel/omp/gcc-14] libgomp: Fix declare target link with offset array-section mapping [PR116107]

2024-07-29 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:c9e52a1a3d2c2970065c254a414bab76f798ce7d

commit c9e52a1a3d2c2970065c254a414bab76f798ce7d
Author: Tobias Burnus 
Date:   Mon Jul 29 12:50:56 2024 +0200

libgomp: Fix declare target link with offset array-section mapping 
[PR116107]

Assume that 'int var[100]' is 'omp declare target link(var)'. When now
mapping an array section with offset such as 'map(to:var[20:10])',
the device-side link pointer has to store &[0] minus
the offset such that var[20] will access [0]. But
the offset calculation was missed such that the device-side 'var' pointed
to the first element of the mapped data - and var[20] points beyond at
some invalid memory.

PR middle-end/116107

libgomp/ChangeLog:

* target.c (gomp_map_vars_internal): Honor array mapping offsets
with declare-target 'link' variables.
* testsuite/libgomp.c-c++-common/target-link-2.c: New test.

(cherry picked from commit 14c47e7eb06e8b95913794f6059560fc2fa6de91)

Diff:
---
 libgomp/ChangeLog  | 11 
 libgomp/target.c   |  7 ++-
 .../testsuite/libgomp.c-c++-common/target-link-2.c | 59 ++
 3 files changed, 75 insertions(+), 2 deletions(-)

diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog
index 555f1f126f26..aaa2e8defe3e 100644
--- a/libgomp/ChangeLog
+++ b/libgomp/ChangeLog
@@ -1,3 +1,14 @@
+-- libgomp/ChangeLog -- 
+2024-07-29  Tobias Burnus  
+
+   Backported from master:
+   2024-07-29  Tobias Burnus  
+
+   PR middle-end/116107
+   * target.c (gomp_map_vars_internal): Honor array mapping offsets
+   with declare-target 'link' variables.
+   * testsuite/libgomp.c-c++-common/target-link-2.c: New test.
+
 2024-05-07  Jakub Jelinek  
 
Backported from master:
diff --git a/libgomp/target.c b/libgomp/target.c
index caa501c27acb..eb02d478e109 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -1892,8 +1892,11 @@ gomp_map_vars_internal (struct gomp_device_descr 
*devicep,
if (k->aux && k->aux->link_key)
  {
/* Set link pointer on target to the device address of the
-  mapped object.  */
-   void *tgt_addr = (void *) (tgt->tgt_start + k->tgt_offset);
+  mapped object.  Also deal with offsets due to
+  array-section mapping.  */
+   void *tgt_addr = (void *) (tgt->tgt_start + k->tgt_offset
+  - (k->host_start
+ - 
k->aux->link_key->host_start));
/* We intentionally do not use coalescing here, as it's not
   data allocated by the current call to this function.  */
gomp_copy_host2dev (devicep, aq, (void *) n->tgt_offset,
diff --git a/libgomp/testsuite/libgomp.c-c++-common/target-link-2.c 
b/libgomp/testsuite/libgomp.c-c++-common/target-link-2.c
new file mode 100644
index ..15da1656ebf9
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c-c++-common/target-link-2.c
@@ -0,0 +1,59 @@
+/* { dg-do run }  */
+/* PR middle-end/116107  */
+
+#include 
+
+int arr[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
+#pragma omp declare target link(arr)
+
+#pragma omp begin declare target
+void f(int *res)
+{
+  __builtin_memcpy (res, &arr[5], sizeof(int)*10);
+}
+
+void g(int *res)
+{
+  __builtin_memcpy (res, &arr[3], sizeof(int)*10);
+}
+#pragma omp end declare target
+
+int main()
+{
+  int res[10], res2;
+  for (int dev = 0; dev < omp_get_num_devices(); dev++)
+{
+  __builtin_memset (res, 0, sizeof (res));
+  res2 = 99;
+
+  #pragma omp target enter data map(arr[5:10]) device(dev)
+
+  #pragma omp target map(from: res) device(dev)
+   f (res);
+
+  #pragma omp target map(from: res2) device(dev)
+   res2 = arr[5];
+
+  if (res2 != 6)
+   __builtin_abort ();
+  for (int i = 0; i < 10; i++)
+   if (res[i] != 6 + i)
+ __builtin_abort ();
+
+  #pragma omp target exit data map(release:arr[5:10]) device(dev)
+
+  for (int i = 0; i < 15; i++)
+   arr[i] *= 10;
+  __builtin_memset (res, 0, sizeof (res));
+
+  #pragma omp target enter data map(arr[3:10]) device(dev)
+
+  #pragma omp target map(from: res) device(dev)
+   g (res);
+
+  for (int i = 0; i < 10; i++)
+   if (res[i] != (4 + i)*10)
+ __builtin_abort ();
+}
+  return 0;
+}


[gcc/devel/omp/gcc-14] OpenMP/Fortran: Fix handling of 'declare target' with 'link' clause [PR115559]

2024-07-29 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:9e05aff533d8c506aa6a99a1b9ac5c1743862af7

commit 9e05aff533d8c506aa6a99a1b9ac5c1743862af7
Author: Tobias Burnus 
Date:   Mon Jul 29 12:52:11 2024 +0200

OpenMP/Fortran: Fix handling of 'declare target' with 'link' clause 
[PR115559]

Contrary to a normal 'declare target', the 'declare target link' attribute
also needs to set node->offloadable and push the offload_vars in the front 
end.

Linked variables require that the data is mapped. For module variables, this
can happen anywhere. For variables in an external subprograms or the main
programm, this can only happen in the either that program itself or in an
internal subprogram. - Whether a variable is just normally mapped or linked 
then
becomes relevant if a device routine exists that can access that variable,
i.e. an internal procedure has then to be marked as declare target.

PR fortran/115559

gcc/fortran/ChangeLog:

* trans-common.cc (build_common_decl): Add 'omp declare target' and
'omp declare target link' variables to offload_vars.
* trans-decl.cc (add_attributes_to_decl): Likewise; update args and
call decl_attributes.
(get_proc_pointer_decl, gfc_get_extern_function_decl,
build_function_decl): Update calls.
(gfc_get_symbol_decl): Likewise; move after 'DECL_STATIC (t)=1'
to avoid errors with symtab_node::get_create.

libgomp/ChangeLog:

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

(cherry picked from commit 29b1587e7d34667a1fd63071c1e4f5475cd71026)

Diff:
---
 gcc/fortran/ChangeLog.omp  |  15 +++
 gcc/fortran/trans-common.cc|  21 
 gcc/fortran/trans-decl.cc  |  81 +-
 libgomp/ChangeLog.omp  |   8 ++
 .../libgomp.fortran/declare-target-link.f90| 116 +
 5 files changed, 215 insertions(+), 26 deletions(-)

diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp
index 917fad1de90a..31470f4852e4 100644
--- a/gcc/fortran/ChangeLog.omp
+++ b/gcc/fortran/ChangeLog.omp
@@ -1,3 +1,18 @@
+2024-07-29  Tobias Burnus  
+
+   Backported from master:
+   2024-07-29  Tobias Burnus  
+
+   PR fortran/115559
+   * trans-common.cc (build_common_decl): Add 'omp declare target' and
+   'omp declare target link' variables to offload_vars.
+   * trans-decl.cc (add_attributes_to_decl): Likewise; update args and
+   call decl_attributes.
+   (get_proc_pointer_decl, gfc_get_extern_function_decl,
+   build_function_decl): Update calls.
+   (gfc_get_symbol_decl): Likewise; move after 'DECL_STATIC (t)=1'
+   to avoid errors with symtab_node::get_create.
+
 2024-07-03  Thomas Schwinge  
 
* class.cc (generate_callback_wrapper) [GCC_NVPTX_H]: Disable.
diff --git a/gcc/fortran/trans-common.cc b/gcc/fortran/trans-common.cc
index 5f44e7bd663d..e714342c3c0b 100644
--- a/gcc/fortran/trans-common.cc
+++ b/gcc/fortran/trans-common.cc
@@ -98,6 +98,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "coretypes.h"
 #include "tm.h"
 #include "tree.h"
+#include "cgraph.h"
+#include "context.h"
+#include "omp-offload.h"
 #include "gfortran.h"
 #include "trans.h"
 #include "stringpool.h"
@@ -497,6 +500,24 @@ build_common_decl (gfc_common_head *com, tree union_type, 
bool is_init)
  = tree_cons (get_identifier ("omp declare target"),
   omp_clauses, DECL_ATTRIBUTES (decl));
 
+  if (com->omp_declare_target_link || com->omp_declare_target)
+   {
+ /* Add to offload_vars; get_create does so for omp_declare_target,
+omp_declare_target_link requires manual work.  */
+ gcc_assert (symtab_node::get (decl) == 0);
+ symtab_node *node = symtab_node::get_create (decl);
+ if (node != NULL && com->omp_declare_target_link)
+   {
+ node->offloadable = 1;
+ if (ENABLE_OFFLOADING)
+   {
+ g->have_offload = true;
+ if (is_a  (node))
+   vec_safe_push (offload_vars, decl);
+   }
+   }
+   }
+
   /* Place the back end declaration for this common block in
  GLOBAL_BINDING_LEVEL.  */
   gfc_map_of_all_commons[identifier] = pushdecl_top_level (decl);
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 643c93f36ee8..019e845bf9f0 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -46,7 +46,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "trans-stmt.h"
 #include "gomp-constants.h"
 #include "gimplify.h"
+#include "context.h"
 #include "omp-general.h"
+#include "omp-offload.h"
 #include "attr-fnspec.h"
 #include "tree-iterator.h"
 
@@ -1450,19 +1452,18 @@ gfc_add_assign_aux_vars (gfc_symbol * sym)

[gcc/devel/omp/gcc-14] Merge remote-tracking branch 'origin/releases/gcc-14' into devel/omp/gcc-14

2024-07-29 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:8ad1a509662a9af828600d053652d6d0f414027c

commit 8ad1a509662a9af828600d053652d6d0f414027c
Merge: 9e05aff533d8 98baaa17561c
Author: Tobias Burnus 
Date:   Mon Jul 29 12:52:36 2024 +0200

Merge remote-tracking branch 'origin/releases/gcc-14' into devel/omp/gcc-14

Merge up to commit r14-10515-g98baaa17561ca2 (29th July 2024)

Diff:

 gcc/ChangeLog  |  131 +
 gcc/DATESTAMP  |2 +-
 gcc/config/i386/avx512dqintrin.h   |   16 +-
 gcc/config/i386/avx512vlbwintrin.h |4 +-
 gcc/config/i386/avx512vlintrin.h   |2 +-
 gcc/config/i386/i386.md|2 +-
 gcc/config/riscv/bitmanip.md   |2 +-
 gcc/config/rs6000/rs6000-logue.cc  |   47 +-
 gcc/config/rs6000/rs6000.cc|   12 +
 gcc/config/rs6000/rs6000.md|6 +-
 gcc/cp/ChangeLog   |   21 +
 gcc/cp/call.cc |2 +-
 gcc/cp/coroutines.cc   |   18 +-
 gcc/ipa-icf-gimple.cc  |4 +
 gcc/ipa-inline.cc  |   79 +-
 gcc/ipa-modref.cc  |   16 +-
 gcc/ipa-prop.cc|4 +-
 gcc/po/ChangeLog   |4 +
 gcc/po/gcc.pot | 7713 ++--
 gcc/testsuite/ChangeLog|  132 +
 .../g++.dg/coroutines/pr104981-preview-this.C  |   34 +
 .../g++.dg/coroutines/pr115550-preview-this.C  |   47 +
 .../g++.dg/cpp23/explicit-obj-diagnostics11.C  |   48 +
 gcc/testsuite/g++.target/powerpc/pr106069.C|2 +-
 gcc/testsuite/gcc.c-torture/compile/pr115277.c |   28 +
 gcc/testsuite/gcc.c-torture/execute/pr114207.c |   23 +
 gcc/testsuite/gcc.c-torture/execute/pr115033.c |   35 +
 gcc/testsuite/gcc.c-torture/pr111613.c |   29 +
 gcc/testsuite/gcc.dg/pr116034.c|   23 +
 gcc/testsuite/gcc.dg/vect/tsvc/vect-tsvc-s1281.c   |3 +
 .../gcc.target/i386/avx512bw-vpalignr-1b.c |   18 +
 .../gcc.target/i386/avx512dq-vfpclasssd-1b.c   |   14 +
 .../gcc.target/i386/avx512dq-vfpcla-1b.c   |   14 +
 .../gcc.target/i386/avx512dq-vreducesd-1b.c|   16 +
 .../gcc.target/i386/avx512dq-vreducess-1b.c|   16 +
 .../gcc.target/i386/avx512vl-valignq-1b.c  |   15 +
 gcc/testsuite/gcc.target/i386/prefetchi-1.c|4 +-
 gcc/testsuite/gcc.target/powerpc/pr114759-2.c  |   17 +
 gcc/testsuite/gcc.target/powerpc/pr114759-3.c  |   21 +
 gcc/testsuite/gcc.target/powerpc/pr115389.c|   17 +
 gcc/testsuite/gcc.target/riscv/pr116035-1.c|   29 +
 gcc/testsuite/gcc.target/riscv/pr116035-2.c|   26 +
 gcc/testsuite/lib/target-supports.exp  |2 +-
 gcc/tree-ssa.cc|5 +-
 libstdc++-v3/ChangeLog |   17 +
 libstdc++-v3/src/c++23/print.cc|8 +-
 46 files changed, 4796 insertions(+), 3932 deletions(-)


[gcc r15-2381] libgomp.texi: Update 'Device Information Routines' section

2024-07-29 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:8d3325708c107d20d41f0bddb0ad161c18934561

commit r15-2381-g8d3325708c107d20d41f0bddb0ad161c18934561
Author: Tobias Burnus 
Date:   Mon Jul 29 17:43:42 2024 +0200

libgomp.texi: Update 'Device Information Routines' section

Update 'OpenMP Runtime Library Routines' by adding a note that invoking
inside a target region might invoke unspecified behavior. Additionally,
update omp_{get,set}_default_device for omp_{initial,invalid}_device
named constants.

libgomp/ChangeLog:

* libgomp.texi (OpenMP Runtime Library Routines): Add missing
title to some commented still undocumented items.
(Device Information Routines): Update.

Diff:
---
 libgomp/libgomp.texi | 48 +---
 1 file changed, 33 insertions(+), 15 deletions(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 50da248b74db..07cd75124b07 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -1208,11 +1208,11 @@ They have C linkage and do not throw exceptions.
 
 @menu
 * omp_get_proc_bind::   Whether threads may be moved between CPUs
-@c * omp_get_num_places:: 
-@c * omp_get_place_num_procs:: 
-@c * omp_get_place_proc_ids:: 
-@c * omp_get_place_num:: 
-@c * omp_get_partition_num_places:: 
+@c * omp_get_num_places::   Get the number of places available
+@c * omp_get_place_num_procs::  Get the number of processes associated with a 
place
+@c * omp_get_place_proc_ids::   Get number of processes associated with a place
+@c * omp_get_place_num::Get place number of the associated task
+@c * omp_get_partition_num_places:: Get number of places of innermost task
 @c * omp_get_partition_place_nums:: 
 @c * omp_set_affinity_format:: 
 @c * omp_get_affinity_format:: 
@@ -1627,8 +1627,12 @@ Returns the number of processors online on that device.
 @subsection @code{omp_set_default_device} -- Set the default device for target 
regions
 @table @asis
 @item @emph{Description}:
-Set the default device for target regions without device clause.  The argument
-shall be a nonnegative device number.
+Get the value of the @emph{default-device-var} ICV, which is used
+for target regions without a device clause.  The argument
+shall be a nonnegative device number, @code{omp_initial_device},
+or @code{omp_invalid_device}.
+
+The effect of running this routine in a @code{target} region is unspecified.
 
 @item @emph{C/C++}:
 @multitable @columnfractions .20 .80
@@ -1654,7 +1658,15 @@ shall be a nonnegative device number.
 @subsection @code{omp_get_default_device} -- Get the default device for target 
regions
 @table @asis
 @item @emph{Description}:
-Get the default device for target regions without device clause.
+Get the value of the @emph{default-device-var} ICV, which is used
+for target regions without a device clause. The value is either a
+nonnegative device number, @code{omp_initial_device} or
+@code{omp_invalid_device}. Note that for the host, the ICV can have two values
+and, hence, this routine might return either the value of the named constant
+@code{omp_initial_device} or the value returned by the
+@code{omp_get_initial_device} routine.
+
+The effect of running this routine in a @code{target} region is unspecified.
 
 @item @emph{C/C++}:
 @multitable @columnfractions .20 .80
@@ -1667,7 +1679,8 @@ Get the default device for target regions without device 
clause.
 @end multitable
 
 @item @emph{See also}:
-@ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device}
+@ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device},
+@ref{omp_get_initial_device}
 
 @item @emph{Reference}:
 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.30.
@@ -1681,6 +1694,8 @@ Get the default device for target regions without device 
clause.
 @item @emph{Description}:
 Returns the number of target devices.
 
+The effect of running this routine in a @code{target} region is unspecified.
+
 @item @emph{C/C++}:
 @multitable @columnfractions .20 .80
 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
@@ -1702,9 +1717,9 @@ Returns the number of target devices.
 @table @asis
 @item @emph{Description}:
 This function returns a device number that represents the device that the
-current thread is executing on. For OpenMP 5.0, this must be equal to the
-value returned by the @code{omp_get_initial_device} function when called
-from the host.
+current thread is executing on. When called on the host, it returns
+the same value as returned by the @code{omp_get_initial_device} function
+as required since OpenMP 5.0.
 
 @item @emph{C/C++}
 @multitable @columnfractions .20 .80
@@ -1754,9 +1769,11 @@ their language-specific counterparts.
 @table @asis
 @item @emph{Description}:
 This function returns a device number that represents the host device.
-For OpenMP 5.1, this must be equal to the value returned by the
+Since OpenMP 5.1, this is equal to the value returned by the
 @code{omp_get_num_devices} function.

[gcc r15-2401] gfortran.dg/compiler-directive_2.f: Update dg-error

2024-07-30 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:15158a8853a69f27a3c14644f35a93029dea6a84

commit r15-2401-g15158a8853a69f27a3c14644f35a93029dea6a84
Author: Tobias Burnus 
Date:   Tue Jul 30 10:18:06 2024 +0200

gfortran.dg/compiler-directive_2.f: Update dg-error

This is a fallout of commit r15-2378-g29b1587e7d3466
  OpenMP/Fortran: Fix handling of 'declare target' with 'link' clause 
[PR115559]
where the '!GCC$' attributes were added in reverse order.
Result: The error diagnostic for the stdcall/fastcall was reversed.
Solution: Swap the order in dg-error.

gcc/testsuite/ChangeLog:

* gfortran.dg/compiler-directive_2.f: Update dg-error.

Diff:
---
 gcc/testsuite/gfortran.dg/compiler-directive_2.f | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gfortran.dg/compiler-directive_2.f 
b/gcc/testsuite/gfortran.dg/compiler-directive_2.f
index 79169a896ae6..c31349f3348c 100644
--- a/gcc/testsuite/gfortran.dg/compiler-directive_2.f
+++ b/gcc/testsuite/gfortran.dg/compiler-directive_2.f
@@ -5,6 +5,6 @@
 ! Check for calling convention consitency
 ! in procedure-pointer assignments.
 !
-  subroutine test() ! { dg-error "fastcall and stdcall attributes are not 
compatible" }
+  subroutine test() ! { dg-error "stdcall and fastcall attributes are not 
compatible" }
 cGCC$ attributes stdcall, fastcall::test
   end subroutine test


[gcc/devel/omp/gcc-14] gfortran.dg/compiler-directive_2.f: Update dg-error

2024-07-30 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:4d76fe46875b14296ffc675b9580cb3c543d2310

commit 4d76fe46875b14296ffc675b9580cb3c543d2310
Author: Tobias Burnus 
Date:   Tue Jul 30 10:35:11 2024 +0200

gfortran.dg/compiler-directive_2.f: Update dg-error

This is a fallout of commit r15-2378-g29b1587e7d3466
  OpenMP/Fortran: Fix handling of 'declare target' with 'link' clause 
[PR115559]
where the '!GCC$' attributes were added in reverse order.
Result: The error diagnostic for the stdcall/fastcall was reversed.
Solution: Swap the order in dg-error.

gcc/testsuite/ChangeLog:

* gfortran.dg/compiler-directive_2.f: Update dg-error.

(cherry picked from commit 15158a8853a69f27a3c14644f35a93029dea6a84)

Diff:
---
 gcc/testsuite/ChangeLog.omp  | 7 +++
 gcc/testsuite/gfortran.dg/compiler-directive_2.f | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 055730cbdebb..3df8cf8b3b87 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,10 @@
+2024-07-30  Tobias Burnus  
+
+   Backported from master:
+   2024-07-30  Tobias Burnus  
+
+   * gfortran.dg/compiler-directive_2.f: Update dg-error.
+
 2024-05-28  Tobias Burnus  
 
* c-c++-common/gomp/lastprivate-conditional-1.c: Remove
diff --git a/gcc/testsuite/gfortran.dg/compiler-directive_2.f 
b/gcc/testsuite/gfortran.dg/compiler-directive_2.f
index 79169a896ae6..c31349f3348c 100644
--- a/gcc/testsuite/gfortran.dg/compiler-directive_2.f
+++ b/gcc/testsuite/gfortran.dg/compiler-directive_2.f
@@ -5,6 +5,6 @@
 ! Check for calling convention consitency
 ! in procedure-pointer assignments.
 !
-  subroutine test() ! { dg-error "fastcall and stdcall attributes are not 
compatible" }
+  subroutine test() ! { dg-error "stdcall and fastcall attributes are not 
compatible" }
 cGCC$ attributes stdcall, fastcall::test
   end subroutine test


[gcc r15-2472] omp-offload.cc: Fix value-expr handling of 'declare target link' vars [PR115637]

2024-08-01 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:c99cdcab4f1c497a872cf552138fd8ea27e9a5eb

commit r15-2472-gc99cdcab4f1c497a872cf552138fd8ea27e9a5eb
Author: Tobias Burnus 
Date:   Thu Aug 1 09:06:32 2024 +0200

omp-offload.cc: Fix value-expr handling of 'declare target link' vars 
[PR115637]

As the PR and included testcase shows, replacing 'arr2' by its value 
expression
'*arr2$13$linkptr' failed for
  MEM  [(c_char * {ref-all})&arr2]
which left 'arr2' in the code as unknown symbol. Now expand the value 
expression
already in pass_omp_target_link::execute's process_link_var_op 
walk_gimple_stmt
walk - and don't rely on gimple_regimplify_operands.

PR middle-end/115637

gcc/ChangeLog:

* gimplify.cc (gimplify_body): Fix macro name in the comment.
* omp-offload.cc (find_link_var_op): Rename to ...
(process_link_var_op): ... this. Replace value expr.
(pass_omp_target_link::execute): Update walk_gimple_stmt call.

libgomp/ChangeLog:

* testsuite/libgomp.fortran/declare-target-link.f90: Uncomment
now working code.

Co-authored-by: Richard Biener info = *tp = unshare_expr (DECL_VALUE_EXPR (t));
   *walk_subtrees = 0;
-  return t;
+  return NULL_TREE;
 }
 
   return NULL_TREE;
@@ -2924,7 +2926,10 @@ pass_omp_target_link::execute (function *fun)
  gimple_call_set_arg (gsi_stmt (gsi), 1, null_pointer_node);
  update_stmt (gsi_stmt (gsi));
}
- if (walk_gimple_stmt (&gsi, NULL, find_link_var_op, NULL))
+ struct walk_stmt_info wi;
+ memset (&wi, 0, sizeof (wi));
+ walk_gimple_stmt (&gsi, NULL, process_link_var_op, &wi);
+ if (wi.info)
gimple_regimplify_operands (gsi_stmt (gsi), &gsi);
}
 }
diff --git a/libgomp/testsuite/libgomp.fortran/declare-target-link.f90 
b/libgomp/testsuite/libgomp.fortran/declare-target-link.f90
index 2ce212d114fa..44c67f925bda 100644
--- a/libgomp/testsuite/libgomp.fortran/declare-target-link.f90
+++ b/libgomp/testsuite/libgomp.fortran/declare-target-link.f90
@@ -1,5 +1,7 @@
 ! { dg-additional-options "-Wall" }
+
 ! PR fortran/115559
+! PR middle-end/115637
 
 module m
integer :: A
@@ -73,24 +75,19 @@ contains
 !$omp target map(from:res)
   res = run_device1()
 !$omp end target
-print *, res
-! FIXME: arr2 not link mapped -> PR115637
-! if (res /= -11436) stop 5
-if (res /= -11546) stop 5 ! FIXME
+! print *, res
+if (res /= -11436) stop 5
   end
   integer function run_device1()
 !$omp declare target
 integer :: i
 run_device1 = -99
-! FIXME: arr2 not link mapped -> PR115637
-!   arr2 = [11,22,33,44]
+arr2 = [11,22,33,44]
 if (any (arr(10:50) /= [(i, i=10,50)])) then
   run_device1 = arr(11)
   return
 end if
-! FIXME: -> PR115637
-! run_device1 = sum(arr(10:13) + arr2)
-run_device1 = sum(arr(10:13) ) ! FIXME
+run_device1 = sum(arr(10:13) + arr2)
 do i = 10, 50
   arr(i) = 3 - 10 * arr(i)
 end do


[gcc/devel/omp/gcc-14] omp-offload.cc: Fix value-expr handling of 'declare target link' vars [PR115637]

2024-08-01 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:7543bfda00d7ea4b7f451da8d891d8ad0faade4c

commit 7543bfda00d7ea4b7f451da8d891d8ad0faade4c
Author: Tobias Burnus 
Date:   Thu Aug 1 10:36:43 2024 +0200

omp-offload.cc: Fix value-expr handling of 'declare target link' vars 
[PR115637]

As the PR and included testcase shows, replacing 'arr2' by its value 
expression
'*arr2$13$linkptr' failed for
  MEM  [(c_char * {ref-all})&arr2]
which left 'arr2' in the code as unknown symbol. Now expand the value 
expression
already in pass_omp_target_link::execute's process_link_var_op 
walk_gimple_stmt
walk - and don't rely on gimple_regimplify_operands.

PR middle-end/115637

gcc/ChangeLog:

* gimplify.cc (gimplify_body): Fix macro name in the comment.
* omp-offload.cc (find_link_var_op): Rename to ...
(process_link_var_op): ... this. Replace value expr.
(pass_omp_target_link::execute): Update walk_gimple_stmt call.

libgomp/ChangeLog:

* testsuite/libgomp.fortran/declare-target-link.f90: Uncomment
now working code.

Co-authored-by: Richard Biener 
+
+   Backported from master:
+   2024-08-01  Tobias Burnus  
+   Richard Biener  
 
* doc/tm.texi.in (TARGET_VECTORIZE_PREFER_GATHER_SCATTER): Remove
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index b91e098c280e..a4b1ae89cf51 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -20750,7 +20750,7 @@ gimplify_body (tree fndecl, bool do_parms)
   DECL_SAVED_TREE (fndecl) = NULL_TREE;
 
   /* If we had callee-copies statements, insert them at the beginning
- of the function and clear DECL_VALUE_EXPR_P on the parameters.  */
+ of the function and clear DECL_HAS_VALUE_EXPR_P on the parameters.  */
   if (!gimple_seq_empty_p (parm_stmts))
 {
   tree parm;
diff --git a/gcc/omp-offload.cc b/gcc/omp-offload.cc
index e3af1e21cdf4..b7003a9a95b6 100644
--- a/gcc/omp-offload.cc
+++ b/gcc/omp-offload.cc
@@ -3365,8 +3365,9 @@ public:
 /* Callback for walk_gimple_stmt used to scan for link var operands.  */
 
 static tree
-find_link_var_op (tree *tp, int *walk_subtrees, void *)
+process_link_var_op (tree *tp, int *walk_subtrees, void *data)
 {
+  struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
   tree t = *tp;
 
   if (VAR_P (t)
@@ -3374,8 +3375,9 @@ find_link_var_op (tree *tp, int *walk_subtrees, void *)
   && is_global_var (t)
   && lookup_attribute ("omp declare target link", DECL_ATTRIBUTES (t)))
 {
+  wi->info = *tp = unshare_expr (DECL_VALUE_EXPR (t));
   *walk_subtrees = 0;
-  return t;
+  return NULL_TREE;
 }
 
   return NULL_TREE;
@@ -3405,7 +3407,10 @@ pass_omp_target_link::execute (function *fun)
  gimple_call_set_arg (gsi_stmt (gsi), 1, null_pointer_node);
  update_stmt (gsi_stmt (gsi));
}
- if (walk_gimple_stmt (&gsi, NULL, find_link_var_op, NULL))
+ struct walk_stmt_info wi;
+ memset (&wi, 0, sizeof (wi));
+ walk_gimple_stmt (&gsi, NULL, process_link_var_op, &wi);
+ if (wi.info)
gimple_regimplify_operands (gsi_stmt (gsi), &gsi);
}
 }
diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 73cbc896ad16..d02bbb14e876 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,13 @@
+2024-08-01  Tobias Burnus  
+
+   Backported from master:
+   2024-08-01  Tobias Burnus  
+   Richard Biener  
 
Backported from master:
diff --git a/libgomp/testsuite/libgomp.fortran/declare-target-link.f90 
b/libgomp/testsuite/libgomp.fortran/declare-target-link.f90
index 2ce212d114fa..44c67f925bda 100644
--- a/libgomp/testsuite/libgomp.fortran/declare-target-link.f90
+++ b/libgomp/testsuite/libgomp.fortran/declare-target-link.f90
@@ -1,5 +1,7 @@
 ! { dg-additional-options "-Wall" }
+
 ! PR fortran/115559
+! PR middle-end/115637
 
 module m
integer :: A
@@ -73,24 +75,19 @@ contains
 !$omp target map(from:res)
   res = run_device1()
 !$omp end target
-print *, res
-! FIXME: arr2 not link mapped -> PR115637
-! if (res /= -11436) stop 5
-if (res /= -11546) stop 5 ! FIXME
+! print *, res
+if (res /= -11436) stop 5
   end
   integer function run_device1()
 !$omp declare target
 integer :: i
 run_device1 = -99
-! FIXME: arr2 not link mapped -> PR115637
-!   arr2 = [11,22,33,44]
+arr2 = [11,22,33,44]
 if (any (arr(10:50) /= [(i, i=10,50)])) then
   run_device1 = arr(11)
   return
 end if
-! FIXME: -> PR115637
-! run_device1 = sum(arr(10:13) + arr2)
-run_device1 = sum(arr(10:13) ) ! FIXME
+run_device1 = sum(arr(10:13) + arr2)
 do i = 10, 50
   arr(i) = 3 - 10 * arr(i)
 end do


[gcc/devel/omp/gcc-14] (12 commits) Merge branch 'releases/gcc-14' into devel/omp/gcc-14

2024-08-01 Thread Tobias Burnus via Gcc-cvs
The branch 'devel/omp/gcc-14' was updated to point to:

 84efccbc61d0... Merge branch 'releases/gcc-14' into devel/omp/gcc-14

It previously pointed to:

 7543bfda00d7... omp-offload.cc: Fix value-expr handling of 'declare target 

Diff:

Summary of changes (added commits):
---

  84efccb... Merge branch 'releases/gcc-14' into devel/omp/gcc-14
  04696df... Update ChangeLog and version files for release (*)
  0f4eb65... Daily bump. (*)
  10323e2... Daily bump. (*)
  ee6c5af... x86: Don't enable APX_F in 32-bit mode (*)
  7c688e0... Daily bump. (*)
  da7f0be... c++: wrong error initializing empty class [PR115900] (*)
  a7f1b00... tree-optimization/116057 - wrong code with CCP and vector C (*)
  61cb0c8... testsuite: Fix up consteval-prop21.C for 32-bit targets [PR (*)
  9662299... c++: if consteval and consteval propagation [PR115583] (*)
  56d5f8a... c++: consteval propagation and templates [PR115986] (*)
  f30caf1... c++: ICE with concept, local class, and lambda [PR115561] (*)

(*) This commit already exists in another branch.
Because the reference `refs/heads/devel/omp/gcc-14' matches
your hooks.email-new-commits-only configuration,
no separate email is sent for this commit.


[gcc/devel/omp/gcc-14] Merge branch 'releases/gcc-14' into devel/omp/gcc-14

2024-08-01 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:3d3c4425604c8917a8dc10f935453ebe82660016

commit 3d3c4425604c8917a8dc10f935453ebe82660016
Merge: 84efccbc61d0 973097d801a3
Author: Tobias Burnus 
Date:   Thu Aug 1 12:24:03 2024 +0200

Merge branch 'releases/gcc-14' into devel/omp/gcc-14

Merge up to r14-10528-g973097d801a303 (1st Aug 2024).
This includes one additional fix + the post-release bump to version 4.2.1.

Diff:

 gcc/BASE-VER   |  2 +-
 gcc/config/i386/sse.md | 42 +++---
 gcc/testsuite/gcc.target/i386/avx512dq-pr90991-1.c |  3 ++
 gcc/testsuite/gcc.target/i386/avx512dq-pr90991-2.c |  3 ++
 4 files changed, 28 insertions(+), 22 deletions(-)


[gcc/devel/omp/gcc-14] (3 commits) Merge branch 'releases/gcc-14' into devel/omp/gcc-14

2024-08-01 Thread Tobias Burnus via Gcc-cvs
The branch 'devel/omp/gcc-14' was updated to point to:

 3d3c4425604c... Merge branch 'releases/gcc-14' into devel/omp/gcc-14

It previously pointed to:

 84efccbc61d0... Merge branch 'releases/gcc-14' into devel/omp/gcc-14

Diff:

Summary of changes (added commits):
---

  3d3c442... Merge branch 'releases/gcc-14' into devel/omp/gcc-14
  973097d... i386: Fix up *_vinsert

[gcc r15-2713] libgomp.texi: Add OpenMP TR13 routines to @menu (commented out)

2024-08-05 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:1a5734135d265a7b363ead9f821676a2a358969b

commit r15-2713-g1a5734135d265a7b363ead9f821676a2a358969b
Author: Tobias Burnus 
Date:   Mon Aug 5 09:18:29 2024 +0200

libgomp.texi: Add OpenMP TR13 routines to @menu (commented out)

To keep track of missing routine documentation (both implemented and not),
the libgomp.texi file contains all non-OMPT routines as commented items
in @menu. This commit adds the routines added in TR13 as commented fixme
items.

libgomp/ChangeLog:

* libgomp.texi (OpenMP Runtime Library Routines): Add TR13 routines
to @menu (commented out).

Diff:
---
 libgomp/libgomp.texi | 27 +--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 07cd75124b07..c6759dd03bc3 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -1591,12 +1591,18 @@ They have C linkage and do not throw exceptions.
 @menu
 * omp_get_num_procs::   Number of processors online
 @c * omp_get_max_progress_width:: /TR11
+@c * omp_get_device_from_uid::  /TR13
+@c * omp_get_uid_from_device::  /TR13
 * omp_set_default_device::  Set the default device for target regions
 * omp_get_default_device::  Get the default device for target regions
 * omp_get_num_devices:: Number of target devices
 * omp_get_device_num::  Get device that current thread is running on
 * omp_is_initial_device::   Whether executing on the host device
 * omp_get_initial_device::  Device number of host device
+@c * omp_get_device_num_teams::  /TR13
+@c * omp_set_device_num_teams::  /TR13
+@c * omp_get_device_teams_thread_limit::  /TR13
+@c * omp_set_device_teams_thread_limit::  /TR13
 @end menu
 
 
@@ -2813,8 +2819,27 @@ Routines to manage and allocate memory on the current 
device.
 They have C linkage and do not throw exceptions.
 
 @menu
+@c * omp_get_devices_memspace:: /TR13
+@c * omp_get_device_memspace:: /TR13
+@c * omp_get_devices_and_host_memspace:: /TR13
+@c * omp_get_device_and_host_memspace:: /TR13
+@c * omp_get_devices_all_memspace:: /TR13
+@c * omp_get_memspace_num_resources:: /TR11
+@c * omp_get_memspace_pagesize:: /TR13
+@c * omp_get_submemspace:: /TR11
+@c * omp_init_mempartitioner:: /TR13
+@c * omp_destroy_mempartitioner:: /TR13
+@c * omp_init_mempartition:: /TR13
+@c * omp_destroy_mempartition:: /TR13
+@c * omp_mempartition_set_part:: /TR13
+@c * omp_mempartition_get_user_data:: /TR13
 * omp_init_allocator:: Create an allocator
 * omp_destroy_allocator:: Destroy an allocator
+@c * omp_get_devices_allocator:: /TR13
+@c * omp_get_device_allocator:: /TR13
+@c * omp_get_devices_and_host_allocator:: /TR13
+@c * omp_get_device_and_host_allocator:: /TR13
+@c * omp_get_devices_all_allocator:: /TR13
 * omp_set_default_allocator:: Set the default allocator
 * omp_get_default_allocator:: Get the default allocator
 * omp_alloc:: Memory allocation with an allocator
@@ -2823,8 +2848,6 @@ They have C linkage and do not throw exceptions.
 * omp_calloc:: Allocate nullified memory with an allocator
 * omp_aligned_calloc:: Allocate nullified aligned memory with an allocator
 * omp_realloc:: Reallocate memory allocated with OpenMP routines
-@c * omp_get_memspace_num_resources:: /TR11
-@c * omp_get_submemspace:: /TR11
 @end menu


[gcc r15-2742] libgomp: Device load_image - improve minor num-funcs/vars check

2024-08-06 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:0c56fd6a1fe086e038e61041b82df63e98958e9c

commit r15-2742-g0c56fd6a1fe086e038e61041b82df63e98958e9c
Author: Tobias Burnus 
Date:   Tue Aug 6 10:34:28 2024 +0200

libgomp: Device load_image - improve minor num-funcs/vars check

The run time library loads the offload functions and variable and optionally
the ICV variable and returns the number of loaded items, which has to match
the host side. The plugin returns "+1" (since GCC 12) for the ICV variable
entry, independently whether it was loaded or not, but the var's value
(start == end == 0) can be used to detect when this failed.

Thus, we can tighten the assert check - which this commit does together with
making the output less surprising - and simplify the condition further 
below.

libgomp/ChangeLog:

* target.c (gomp_load_image_to_device): Extend fatal-error message;
simplify a condition.

Diff:
---
 libgomp/target.c | 78 +---
 1 file changed, 35 insertions(+), 43 deletions(-)

diff --git a/libgomp/target.c b/libgomp/target.c
index efed6ad68ff4..fb9a6fb5c79e 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -2362,15 +2362,14 @@ gomp_load_image_to_device (struct gomp_device_descr 
*devicep, unsigned version,
num_ind_funcs
  ? (uint64_t *) host_ind_func_table : NULL);
 
-  if (num_target_entries != num_funcs + num_vars
-  /* "+1" due to the additional ICV struct.  */
-  && num_target_entries != num_funcs + num_vars + 1)
+  /* The "+1" is due to the additional ICV struct.  */
+  if (num_target_entries != num_funcs + num_vars + 1)
 {
   gomp_mutex_unlock (&devicep->lock);
   if (is_register_lock)
gomp_mutex_unlock (®ister_lock);
   gomp_fatal ("Cannot map target functions or variables"
- " (expected %u, have %u)", num_funcs + num_vars,
+ " (expected %u + %u + 1, have %u)", num_funcs, num_vars,
  num_target_entries);
 }
 
@@ -2454,48 +2453,41 @@ gomp_load_image_to_device (struct gomp_device_descr 
*devicep, unsigned version,
   array++;
 }
 
-  /* Last entry is for a ICVs variable.
- Tolerate case where plugin does not return those entries.  */
-  if (num_funcs + num_vars < num_target_entries)
+  /* Last entry is for the ICV struct variable; if absent, start = end = 0.  */
+  struct addr_pair *icv_var = &target_table[num_funcs + num_vars];
+  if (icv_var->start != 0)
 {
-  struct addr_pair *var = &target_table[num_funcs + num_vars];
-
-  /* Start address will be non-zero for the ICVs variable if
-the variable was found in this image.  */
-  if (var->start != 0)
+  /* The index of the devicep within devices[] is regarded as its
+'device number', which is different from the per-device type
+devicep->target_id.  */
+  int dev_num = (int) (devicep - &devices[0]);
+  struct gomp_offload_icvs *icvs = get_gomp_offload_icvs (dev_num);
+  size_t var_size = icv_var->end - icv_var->start;
+  if (var_size != sizeof (struct gomp_offload_icvs))
{
- /* The index of the devicep within devices[] is regarded as its
-'device number', which is different from the per-device type
-devicep->target_id.  */
- int dev_num = (int) (devicep - &devices[0]);
- struct gomp_offload_icvs *icvs = get_gomp_offload_icvs (dev_num);
- size_t var_size = var->end - var->start;
- if (var_size != sizeof (struct gomp_offload_icvs))
-   {
- gomp_mutex_unlock (&devicep->lock);
- if (is_register_lock)
-   gomp_mutex_unlock (®ister_lock);
- gomp_fatal ("offload plugin managed 'icv struct' not of expected "
- "format");
-   }
- /* Copy the ICVs variable to place on device memory, hereby
-actually designating its device number into effect.  */
- gomp_copy_host2dev (devicep, NULL, (void *) var->start, icvs,
- var_size, false, NULL);
- splay_tree_key k = &array->key;
- k->host_start = (uintptr_t) icvs;
- k->host_end =
-   k->host_start + (size_mask & sizeof (struct gomp_offload_icvs));
- k->tgt = tgt;
- k->tgt_offset = var->start;
- k->refcount = REFCOUNT_INFINITY;
- k->dynamic_refcount = 0;
- k->aux = NULL;
- array->left = NULL;
- array->right = NULL;
- splay_tree_insert (&devicep->mem_map, array);
- array++;
+ gomp_mutex_unlock (&devicep->lock);
+ if (is_register_lock)
+   gomp_mutex_unlock (®ister_lock);
+ gomp_fatal ("offload plugin managed 'icv struct' not of expected "
+ "format");
}
+  /* Copy the ICVs variable to place on device memory, hereby
+  

[gcc r15-2796] libgomp.c-c++-common/target-link-2.c: Fix test on multi-device systems

2024-08-07 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:aa689684d2bf58d1b7e7938a1392e7a260276d14

commit r15-2796-gaa689684d2bf58d1b7e7938a1392e7a260276d14
Author: Tobias Burnus 
Date:   Wed Aug 7 17:59:21 2024 +0200

libgomp.c-c++-common/target-link-2.c: Fix test on multi-device systems

libgomp/ChangeLog:

* testsuite/libgomp.c-c++-common/target-link-2.c: Reset variable
value to handle multi-device tests.

Diff:
---
 libgomp/testsuite/libgomp.c-c++-common/target-link-2.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libgomp/testsuite/libgomp.c-c++-common/target-link-2.c 
b/libgomp/testsuite/libgomp.c-c++-common/target-link-2.c
index 15da1656ebf9..b64fbde70e3d 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/target-link-2.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/target-link-2.c
@@ -54,6 +54,9 @@ int main()
   for (int i = 0; i < 10; i++)
if (res[i] != (4 + i)*10)
  __builtin_abort ();
+
+  for (int i = 0; i < 15; i++) /* Reset. */
+   arr[i] /= 10;
 }
   return 0;
 }


[gcc r15-2799] OpenMP: Constructors and destructors for "declare target" static aggregates

2024-08-07 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:f1bfba3a9b3f31e3e06bfd1911c9f223869ea03f

commit r15-2799-gf1bfba3a9b3f31e3e06bfd1911c9f223869ea03f
Author: Tobias Burnus 
Date:   Wed Aug 7 19:31:19 2024 +0200

OpenMP: Constructors and destructors for "declare target" static aggregates

This commit also compile-time expands (__builtin_)omp_is_initial_device for
both Fortran and C/C++ (unless, -fno-builtin-omp_is_initial_device is used).
But the main change is:

This commit adds support for running constructors and destructors for
static (file-scope) aggregates for C++ objects which are marked with
"declare target" directives on OpenMP offload targets.

Before this commit, space is allocated on the target for such aggregates,
but nothing ever constructs them properly, so they end up zero-initialised.

(See the new test static-aggr-constructor-destructor-3.C for a reason
why running constructors on the target is preferable to e.g. constructing
on the host and then copying the resulting object to the target.)

2024-08-07  Julian Brown  
Tobias Burnus  

gcc/ChangeLog:

* builtins.def (DEF_GOMP_BUILTIN_COMPILER): Define
DEF_GOMP_BUILTIN_COMPILER to handle the non-prefix version.
* gimple-fold.cc (gimple_fold_builtin_omp_is_initial_device): New.
(gimple_fold_builtin): Call it.
* omp-builtins.def (BUILT_IN_OMP_IS_INITIAL_DEVICE): Define.
* tree.cc (get_file_function_name): Support names for on-target
constructor/destructor functions.

gcc/cp/
* decl2.cc (tree-inline.h): Include.
(static_init_fini_fns): Bump to four entries. Update comment.
(start_objects, start_partial_init_fini_fn): Add 'omp_target'
parameter. Support "declare target" decls. Update forward 
declaration.
(emit_partial_init_fini_fn): Add 'host_fn' parameter. Return tree 
for
the created function. Support "declare target".
(OMP_SSDF_IDENTIFIER): New macro.
(partition_vars_for_init_fini): Support partitioning "declare 
target"
variables also.
(generate_ctor_or_dtor_function): Add 'omp_target' parameter. 
Support
"declare target" decls.
(c_parse_final_cleanups): Support constructors/destructors on OpenMP
offload targets.

gcc/fortran/ChangeLog:

* gfortran.h (gfc_option_t): Add disable_omp_is_initial_device.
* lang.opt (fbuiltin-): Add.
* options.cc (gfc_handle_option): Handle
-fno-builtin-omp_is_initial_device.
* f95-lang.cc (gfc_init_builtin_functions): Handle
DEF_GOMP_BUILTIN_COMPILER.
* trans-decl.cc (gfc_get_extern_function_decl): Add code to use
DEF_GOMP_BUILTIN_COMPILER for 'omp_is_initial_device'.

libgomp/ChangeLog:

* testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C: New 
test.
* testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C: New 
test.
* testsuite/libgomp.c++/static-aggr-constructor-destructor-3.C: New 
test.
* testsuite/libgomp.c-c++-common/target-is-initial-host.c: New test.
* testsuite/libgomp.c-c++-common/target-is-initial-host-2.c: New 
test.
* testsuite/libgomp.fortran/target-is-initial-host.f: New test.
* testsuite/libgomp.fortran/target-is-initial-host.f90: New test.
* testsuite/libgomp.fortran/target-is-initial-host-2.f90: New test.

Co-authored-by: Tobias Burnus 

Diff:
---
 gcc/builtins.def   |   4 +
 gcc/cp/decl2.cc| 229 +
 gcc/fortran/f95-lang.cc|   9 +
 gcc/fortran/gfortran.h |   1 +
 gcc/fortran/lang.opt   |   4 +
 gcc/fortran/options.cc |  12 ++
 gcc/fortran/trans-decl.cc  |   9 +
 gcc/gimple-fold.cc |  20 ++
 gcc/omp-builtins.def   |   4 +
 gcc/tree.cc|   6 +-
 .../static-aggr-constructor-destructor-1.C |  72 +++
 .../static-aggr-constructor-destructor-2.C |  50 +
 .../static-aggr-constructor-destructor-3.C |  36 
 .../target-is-initial-host-2.c |  43 
 .../libgomp.c-c++-common/target-is-initial-host.c  |  42 
 .../libgomp.fortran/target-is-initial-host-2.f90   |  37 
 .../libgomp.fortran/target-is-initial-host.f   |  35 
 .../libgomp.fortran/target-is-initial-host.f90 |  35 
 18 files changed, 608 insertions(+), 40 deletions(-)

diff --git a/gcc/builtins.def b/gcc/builtins.def
index f6f3e104f6a8..a3921aa6856a 100644
--- a/gcc/builtins.def
+++ b/gcc/builtins.de

[gcc r15-2814] libgomp.c++/static-aggr-constructor-destructor-{1, 2}.C: Fix scan-tree-dump

2024-08-08 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:e3a6dec326a127ad549246435b9d3835e9a32407

commit r15-2814-ge3a6dec326a127ad549246435b9d3835e9a32407
Author: Tobias Burnus 
Date:   Thu Aug 8 10:42:25 2024 +0200

libgomp.c++/static-aggr-constructor-destructor-{1,2}.C: Fix scan-tree-dump

In principle, the optimized dump should be the same on the host, but as
'nohost' is not handled, is is present. However when ENABLE_OFFLOADING is
false, it is handled early enough to remove the function.

libgomp/ChangeLog:

* testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C: 
Split
scan-tree-dump into with and without target offload_target_any.
* testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C:
Likewise.

Diff:
---
 .../libgomp.c++/static-aggr-constructor-destructor-1.C   | 15 ---
 .../libgomp.c++/static-aggr-constructor-destructor-2.C   | 16 +---
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git 
a/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C 
b/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C
index 403a071c0c01..b5aafc8cabc2 100644
--- a/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C
+++ b/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C
@@ -9,9 +9,18 @@
 
 // { dg-final { scan-tree-dump-not "omp_is_initial_device" "optimized" } }
 // { dg-final { scan-tree-dump-not "__omp_target_static_init_and_destruction" 
"optimized" } }
-// FIXME: should be '-not' not '-times' 1:
-// { dg-final { scan-tree-dump-times "void _GLOBAL__off_I_v1" 1 "optimized" } }
-// { dg-final { scan-tree-dump-times "__attribute__\\(\\(\[^\n\r]*omp declare 
target nohost" 1 "optimized" } }
+
+// (A) No offloading configured: The symbols aren't present
+// Caveat: They are present with -foffload=disable - or offloading
+// configured but none of the optional offload packages/binaries installed.
+// But the 'offload_target_any' check cannot distinguish those
+// { dg-final { scan-tree-dump-not "void _GLOBAL__off_I_v1" "optimized" { 
target { ! offload_target_any } } } }
+// { dg-final { scan-tree-dump-not "__attribute__\\(\\(\[^\n\r]*omp declare 
target nohost" "optimized" { target { ! offload_target_any } } } }
+
+// (B) With offload configured (and compiling for an offload target)
+// the symbols are present (missed optimization). Hence: FIXME.
+// { dg-final { scan-tree-dump-times "void _GLOBAL__off_I_v1" 1 "optimized" { 
target offload_target_any } } }
+// { dg-final { scan-tree-dump-times "__attribute__\\(\\(\[^\n\r]*omp declare 
target nohost" 1 "optimized" { target offload_target_any } } }
 
 // { dg-final { only_for_offload_target amdgcn-amdhsa 
scan-offload-tree-dump-not "omp_initial_device;" "optimized" { target 
offload_target_amdgcn } } }
 // { dg-final { only_for_offload_target amdgcn-amdhsa scan-offload-tree-dump 
"v1\\._x = 5;" "optimized" { target offload_target_amdgcn } } }
diff --git 
a/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C 
b/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C
index 6dd4260a522c..9652a721bbe2 100644
--- a/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C
+++ b/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C
@@ -9,9 +9,19 @@
 
 // { dg-final { scan-tree-dump-not "omp_is_initial_device" "optimized" } }
 // { dg-final { scan-tree-dump-not "__omp_target_static_init_and_destruction" 
"optimized" } }
-// FIXME: should be '-not' not '-times' 1:
-// { dg-final { scan-tree-dump-times "void _GLOBAL__off_I_" 1 "optimized" } }
-// { dg-final { scan-tree-dump-times "__attribute__\\(\\(\[^\n\r]*omp declare 
target nohost" 1 "optimized" } }
+
+// (A) No offloading configured: The symbols aren't present
+// Caveat: They are present with -foffload=disable - or offloading
+// configured but none of the optional offload packages/binaries installed.
+// But the 'offload_target_any' check cannot distinguish those
+// { dg-final { scan-tree-dump-not "void _GLOBAL__off_I_v1" "optimized" { 
target { ! offload_target_any } } } }
+// { dg-final { scan-tree-dump-not "__attribute__\\(\\(\[^\n\r]*omp declare 
target nohost" "optimized" { target { ! offload_target_any } } } }
+
+// (B) With offload configured (and compiling for an offload target)
+// the symbols are present (missed optimization). Hence: FIXME.
+// { dg-final { scan-tree-dump-times "void _GLOBAL__off_I_v1" 1 "optimized" { 
target offload_target_any } } }
+// { dg-final { scan-tree-dump-times "__attribute__\\(\\(\[^\n\r]*omp declare 
target nohost" 1 "optimized" { target offload_target_any } } }
+
 
 // { dg-final { only_for_offload_target amdgcn-amdhsa 
scan-offload-tree-dump-not "omp_initial_device;" "optimized" { target 
offload_target_amdgcn } } }
 // { dg-final { only_for_offload_target amdgcn-amdhsa scan-offload-tree-dump 
"v1\\._x = 5;" "optimized" { target offlo

[gcc r15-2817] libgomp/libgomp.texi: Mention -fno-builtin-omp_is_initial_device

2024-08-08 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:8b5a8b1f60e7d1a51429f118e0fb3d851abe6cd4

commit r15-2817-g8b5a8b1f60e7d1a51429f118e0fb3d851abe6cd4
Author: Tobias Burnus 
Date:   Thu Aug 8 14:24:59 2024 +0200

libgomp/libgomp.texi: Mention -fno-builtin-omp_is_initial_device

libgomp/ChangeLog:

* libgomp.texi (omp_is_initial_device): Mention
-fno-builtin-omp_is_initial_device and folding by default.

Diff:
---
 libgomp/libgomp.texi | 4 
 1 file changed, 4 insertions(+)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index c6759dd03bc3..081e22510a5d 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -1754,6 +1754,10 @@ This function returns @code{true} if currently running 
on the host device,
 @code{false} otherwise.  Here, @code{true} and @code{false} represent
 their language-specific counterparts.
 
+Note that in GCC this value is already folded to a constant in the compiler;
+compile with @option{-fno-builtin-omp_is_initial_device} if a run-time function
+is desired.
+
 @item @emph{C/C++}:
 @multitable @columnfractions .20 .80
 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}


[gcc r15-2834] libgomp.texi: Update implementation status table for OpenMP TR13

2024-08-08 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:89d2f3fefb0ae6dd4eb76f25009aa15735f09ed4

commit r15-2834-g89d2f3fefb0ae6dd4eb76f25009aa15735f09ed4
Author: Tobias Burnus 
Date:   Thu Aug 8 17:23:38 2024 +0200

libgomp.texi: Update implementation status table for OpenMP TR13

libgomp/ChangeLog:

* libgomp.texi (OpenMP Technical Report 13): Renamed from
'OpenMP Technical Report 12'; updated for TR13 changes.

Diff:
---
 libgomp/libgomp.texi | 120 +++
 1 file changed, 102 insertions(+), 18 deletions(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 081e22510a5d..fe25d879788b 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -169,7 +169,7 @@ See also @ref{OpenMP Implementation Status}.
 * OpenMP 5.0:: Feature completion status to 5.0 specification
 * OpenMP 5.1:: Feature completion status to 5.1 specification
 * OpenMP 5.2:: Feature completion status to 5.2 specification
-* OpenMP Technical Report 12:: Feature completion status to second 6.0 preview
+* OpenMP Technical Report 13:: Feature completion status to third 6.0 preview
 @end menu
 
 The @code{_OPENMP} preprocessor macro and Fortran's @code{openmp_version}
@@ -391,7 +391,7 @@ to address of matching mapped list item per 5.1, Sect. 
2.21.7.2 @tab N @tab
 @item @code{destroy} clause with destroy-var argument on @code{depobj}
   @tab Y @tab
 @item Deprecation of no-argument @code{destroy} clause on @code{depobj}
-  @tab N @tab
+  @tab N/A @tab undeprecated in OpenMP 6
 @item @code{linear} clause syntax changes and @code{step} modifier @tab Y @tab
 @item Deprecation of minus operator for reductions @tab N @tab
 @item Deprecation of separating @code{map} modifiers without comma @tab N @tab
@@ -448,20 +448,24 @@ to address of matching mapped list item per 5.1, Sect. 
2.21.7.2 @tab N @tab
 @end multitable
 
 
-@node OpenMP Technical Report 12
-@section OpenMP Technical Report 12
+@node OpenMP Technical Report 13
+@section OpenMP Technical Report 13
 
-Technical Report (TR) 12 is the second preview for OpenMP 6.0.
+Technical Report (TR) 13 is the third preview for OpenMP 6.0.
 
 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
 @multitable @columnfractions .60 .10 .25
-@item Features deprecated in versions 5.2, 5.1 and 5.0 were removed
+@item Features deprecated in versions 5.0, 5.1 and 5.2 were removed
   @tab N/A @tab Backward compatibility
 @item Full support for C23 was added @tab P @tab
 @item Full support for C++23 was added @tab P @tab
+@item Full support for Fortran 2023 was added @tab P @tab
 @item @code{_ALL} suffix to the device-scope environment variables
   @tab P @tab Host device number wrongly accepted
 @item @code{num_threads} now accepts a list @tab N @tab
+@item Abstract names added for @code{OMP_NUM_THREADS},
+  @code{OMP_THREAD_LIMIT} and @code{OMP_TEAMS_THREAD_LIMIT}
+  @tab N @tab
 @item Supporting increments with abstract names in @code{OMP_PLACES} @tab N 
@tab
 @item Extension of @code{OMP_DEFAULT_DEVICE} and new
   @code{OMP_AVAILABLE_DEVICES} environment vars @tab N @tab
@@ -470,28 +474,51 @@ Technical Report (TR) 12 is the second preview for OpenMP 
6.0.
   @tab Y @tab
 @item The OpenMP directive syntax was extended to include C 23 attribute
   specifiers @tab Y @tab
+@item Support for pure directives in Fortran's @code{do concurrent} @tab N @tab
 @item All inarguable clauses take now an optional Boolean argument @tab N @tab
 @item For Fortran, @emph{locator list} can be also function reference with
   data pointer result @tab N @tab
 @item Concept of @emph{assumed-size arrays} in C and C++
   @tab N @tab
 @item @emph{directive-name-modifier} accepted in all clauses @tab N @tab
+@item Argument-free version of @code{depobj} including added @code{init} clause
+  @tab N @tab
+@item Undeprecate omitting the argument to the @code{depend} clause of
+  the argument version of the @code{depend} construct @tab Y @tab
 @item For Fortran, atomic with BLOCK construct and, for C/C++, with
   unlimited curly braces supported @tab N @tab
+@item For Fortran, atomic with pointer comparison @tab N @tab
+@item For Fortran, atomic with enum and enumeration types @tab N @tab
 @item For Fortran, atomic compare with storing the comparison result
   @tab N @tab
 @item New @code{looprange} clause @tab N @tab
-@item Ref-count change for @code{use_device_ptr}/@code{use_device_addr}
+@item For Fortran, handling polymorphic types in data-sharing-attribute
+  clauses @tab P @tab @code{private} not supported
+@item For Fortran, rejecting polymorphic types in data-mapping clauses
+  @tab N @tab not diagnosed (and mostly unsupported)
+@item New @code{taskgraph} construct including @emph{saved} modifier and
+  @code{replayable} clause @tab N @tab
+@item @code{default} clause on the @code{target} directive @tab N @tab
+@item Ref-count change for @code{use_device_ptr} and @c

[gcc r15-749] contrib/gcc-changelog/git_update_version.py: Improve diagnostic

2024-05-21 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:9596f6567ce6fdf94227b97ac28d3549f421ef73

commit r15-749-g9596f6567ce6fdf94227b97ac28d3549f421ef73
Author: Tobias Burnus 
Date:   Tue May 21 10:13:13 2024 +0200

contrib/gcc-changelog/git_update_version.py: Improve diagnostic

contrib/ChangeLog:

* gcc-changelog/git_update_version.py: Add '-i'/'--ignore' argument
to add to-be-ignored commits via the command line.
(ignored_commits): Rename from IGNORED_COMMITS and change
type from tuple to set.
(prepend_to_changelog_files): Show git hash if errors occurred.
(update_current_branch): Mark argument as optional by defaulting
to None.

Diff:
---
 contrib/gcc-changelog/git_update_version.py | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/contrib/gcc-changelog/git_update_version.py 
b/contrib/gcc-changelog/git_update_version.py
index 24f6c43d0b2..c69a3a6897a 100755
--- a/contrib/gcc-changelog/git_update_version.py
+++ b/contrib/gcc-changelog/git_update_version.py
@@ -22,6 +22,7 @@ import argparse
 import datetime
 import logging
 import os
+import re
 
 from git import Repo
 
@@ -30,7 +31,7 @@ from git_repository import parse_git_revisions
 current_timestamp = datetime.datetime.now().strftime('%Y%m%d\n')
 
 # Skip the following commits, they cannot be correctly processed
-IGNORED_COMMITS = (
+ignored_commits = {
 'c2be82058fb40f3ae891c68d185ff53e07f14f45',
 '04a040d907a83af54e0a98bdba5bfabc0ef4f700',
 '2e96b5f14e4025691b57d2301d71aa6092ed44bc',
@@ -41,7 +42,7 @@ IGNORED_COMMITS = (
 '040e5b0edbca861196d9e2ea2af5e805769c8d5d',
 '8057f9aa1f7e70490064de796d7a8d42d446caf8',
 '109f1b28fc94c93096506e3df0c25e331cef19d0',
-'39f81924d88e3cc197fc3df74204c9b5e01e12f7')
+'39f81924d88e3cc197fc3df74204c9b5e01e12f7'}
 
 FORMAT = '%(asctime)s:%(levelname)s:%(name)s:%(message)s'
 logging.basicConfig(level=logging.INFO, format=FORMAT,
@@ -58,6 +59,7 @@ def read_timestamp(path):
 
 def prepend_to_changelog_files(repo, folder, git_commit, add_to_git):
 if not git_commit.success:
+logging.info(f"While processing {git_commit.info.hexsha}:")
 for error in git_commit.errors:
 logging.info(error)
 raise AssertionError()
@@ -93,13 +95,15 @@ parser.add_argument('-d', '--dry-mode',
  ' is expected')
 parser.add_argument('-c', '--current', action='store_true',
 help='Modify current branch (--push argument is ignored)')
+parser.add_argument('-i', '--ignore', action='append',
+help='list of commits to ignore')
 args = parser.parse_args()
 
 repo = Repo(args.git_path)
 origin = repo.remotes['origin']
 
 
-def update_current_branch(ref_name):
+def update_current_branch(ref_name=None):
 commit = repo.head.commit
 commit_count = 1
 while commit:
@@ -123,7 +127,7 @@ def update_current_branch(ref_name):
 head = head.parents[1]
 commits = parse_git_revisions(args.git_path, '%s..%s'
   % (commit.hexsha, head.hexsha), ref_name)
-commits = [c for c in commits if c.info.hexsha not in IGNORED_COMMITS]
+commits = [c for c in commits if c.info.hexsha not in ignored_commits]
 for git_commit in reversed(commits):
 prepend_to_changelog_files(repo, args.git_path, git_commit,
not args.dry_mode)
@@ -153,6 +157,9 @@ def update_current_branch(ref_name):
 else:
 logging.info('DATESTAMP unchanged')
 
+if args.ignore is not None:
+for item in args.ignore:
+ignored_commits.update(set(i for i in re.split(r'\s*,\s*|\s+', item)))
 
 if args.current:
 logging.info('=== Working on the current branch ===')


[gcc r14-10251] Fortran: Fix SHAPE for zero-size arrays

2024-05-28 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:dbeb3d127da07963ecaa26680da62a255199e9c2

commit r14-10251-gdbeb3d127da07963ecaa26680da62a255199e9c2
Author: Tobias Burnus 
Date:   Mon May 20 08:34:48 2024 +0200

Fortran: Fix SHAPE for zero-size arrays

PR fortran/115150

gcc/fortran/ChangeLog:

* trans-intrinsic.cc (gfc_conv_intrinsic_bound): Fix SHAPE
for zero-size arrays

gcc/testsuite/ChangeLog:

* gfortran.dg/shape_12.f90: New test.

(cherry picked from commit b701306a9b38bd74cdc26c7ece5add22f2203b56)

Diff:
---
 gcc/fortran/trans-intrinsic.cc |  4 ++-
 gcc/testsuite/gfortran.dg/shape_12.f90 | 51 ++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index 4e26af21b46..7cb7c2e6949 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -3090,7 +3090,9 @@ gfc_conv_intrinsic_bound (gfc_se * se, gfc_expr * expr, 
enum gfc_isym_id op)
  lbound, gfc_index_one_node);
}
   else if (op == GFC_ISYM_SHAPE)
-   se->expr = size;
+   se->expr = fold_build2_loc (input_location, MAX_EXPR,
+   gfc_array_index_type, size,
+   gfc_index_zero_node);
   else
gcc_unreachable ();
 
diff --git a/gcc/testsuite/gfortran.dg/shape_12.f90 
b/gcc/testsuite/gfortran.dg/shape_12.f90
new file mode 100644
index 000..e672e1ff9f9
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/shape_12.f90
@@ -0,0 +1,51 @@
+! { dg-do run }
+!
+! PR fortran/115150
+!
+! Check that SHAPE handles zero-sized arrays correctly
+!
+implicit none
+call one
+call two
+
+contains
+
+subroutine one
+  real,allocatable :: A(:),B(:,:)
+  allocate(a(3:0), b(5:1, 2:5))
+
+  if (any (shape(a) /= [0])) stop 1
+  if (any (shape(b) /= [0, 4])) stop 2
+  if (size(a) /= 0) stop 3
+  if (size(b) /= 0) stop 4
+  if (any (lbound(a) /= [1])) stop 5
+  if (any (lbound(b) /= [1, 2])) stop 6
+  if (any (ubound(a) /= [0])) stop 5
+  if (any (ubound(b) /= [0,5])) stop 6
+end
+
+subroutine two
+integer :: x1(10), x2(10,10)
+call f(x1, x2, -3)
+end
+
+subroutine f(y1, y2, n)
+  integer, value :: n
+  integer :: y1(1:n)
+  integer :: y2(1:n,4,2:*)
+  call g(y1, y2)
+end
+
+subroutine g(z1, z2)
+  integer :: z1(..), z2(..)
+
+  if (any (shape(z1) /= [0])) stop 1
+  if (any (shape(z2) /= [0, 4, -1])) stop 2
+  if (size(z1) /= 0) stop 3
+  if (size(z2) /= 0) stop 4
+  if (any (lbound(z1) /= [1])) stop 5
+  if (any (lbound(z2) /= [1, 1, 1])) stop 6
+  if (any (ubound(z1) /= [0])) stop 5
+  if (any (ubound(z2) /= [0, 4, -1])) stop 6
+end
+end


[gcc r13-8805] Fortran: Fix SHAPE for zero-size arrays

2024-05-28 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:3185cfe495944e6e5d000ccd820bed2e6f10cd6c

commit r13-8805-g3185cfe495944e6e5d000ccd820bed2e6f10cd6c
Author: Tobias Burnus 
Date:   Mon May 20 08:34:48 2024 +0200

Fortran: Fix SHAPE for zero-size arrays

PR fortran/115150

gcc/fortran/ChangeLog:

* trans-intrinsic.cc (gfc_conv_intrinsic_bound): Fix SHAPE
for zero-size arrays

gcc/testsuite/ChangeLog:

* gfortran.dg/shape_12.f90: New test.

(cherry picked from commit b701306a9b38bd74cdc26c7ece5add22f2203b56)

Diff:
---
 gcc/fortran/trans-intrinsic.cc |  4 ++-
 gcc/testsuite/gfortran.dg/shape_12.f90 | 51 ++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index aa0dea50089..455b61aa564 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -3090,7 +3090,9 @@ gfc_conv_intrinsic_bound (gfc_se * se, gfc_expr * expr, 
enum gfc_isym_id op)
  lbound, gfc_index_one_node);
}
   else if (op == GFC_ISYM_SHAPE)
-   se->expr = size;
+   se->expr = fold_build2_loc (input_location, MAX_EXPR,
+   gfc_array_index_type, size,
+   gfc_index_zero_node);
   else
gcc_unreachable ();
 
diff --git a/gcc/testsuite/gfortran.dg/shape_12.f90 
b/gcc/testsuite/gfortran.dg/shape_12.f90
new file mode 100644
index 000..e672e1ff9f9
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/shape_12.f90
@@ -0,0 +1,51 @@
+! { dg-do run }
+!
+! PR fortran/115150
+!
+! Check that SHAPE handles zero-sized arrays correctly
+!
+implicit none
+call one
+call two
+
+contains
+
+subroutine one
+  real,allocatable :: A(:),B(:,:)
+  allocate(a(3:0), b(5:1, 2:5))
+
+  if (any (shape(a) /= [0])) stop 1
+  if (any (shape(b) /= [0, 4])) stop 2
+  if (size(a) /= 0) stop 3
+  if (size(b) /= 0) stop 4
+  if (any (lbound(a) /= [1])) stop 5
+  if (any (lbound(b) /= [1, 2])) stop 6
+  if (any (ubound(a) /= [0])) stop 5
+  if (any (ubound(b) /= [0,5])) stop 6
+end
+
+subroutine two
+integer :: x1(10), x2(10,10)
+call f(x1, x2, -3)
+end
+
+subroutine f(y1, y2, n)
+  integer, value :: n
+  integer :: y1(1:n)
+  integer :: y2(1:n,4,2:*)
+  call g(y1, y2)
+end
+
+subroutine g(z1, z2)
+  integer :: z1(..), z2(..)
+
+  if (any (shape(z1) /= [0])) stop 1
+  if (any (shape(z2) /= [0, 4, -1])) stop 2
+  if (size(z1) /= 0) stop 3
+  if (size(z2) /= 0) stop 4
+  if (any (lbound(z1) /= [1])) stop 5
+  if (any (lbound(z2) /= [1, 1, 1])) stop 6
+  if (any (ubound(z1) /= [0])) stop 5
+  if (any (ubound(z2) /= [0, 4, -1])) stop 6
+end
+end


[gcc r12-10476] Fortran: Fix SHAPE for zero-size arrays

2024-05-28 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:e0b2c4f90f908a9bca4038c7ae0d8ca6ee157d8f

commit r12-10476-ge0b2c4f90f908a9bca4038c7ae0d8ca6ee157d8f
Author: Tobias Burnus 
Date:   Mon May 20 08:34:48 2024 +0200

Fortran: Fix SHAPE for zero-size arrays

PR fortran/115150

gcc/fortran/ChangeLog:

* trans-intrinsic.cc (gfc_conv_intrinsic_bound): Fix SHAPE
for zero-size arrays

gcc/testsuite/ChangeLog:

* gfortran.dg/shape_12.f90: New test.

(cherry picked from commit b701306a9b38bd74cdc26c7ece5add22f2203b56)

Diff:
---
 gcc/fortran/trans-intrinsic.cc |  4 ++-
 gcc/testsuite/gfortran.dg/shape_12.f90 | 51 ++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index c30cdfd37f9..9393ca10b06 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -3083,7 +3083,9 @@ gfc_conv_intrinsic_bound (gfc_se * se, gfc_expr * expr, 
enum gfc_isym_id op)
  lbound, gfc_index_one_node);
}
   else if (op == GFC_ISYM_SHAPE)
-   se->expr = size;
+   se->expr = fold_build2_loc (input_location, MAX_EXPR,
+   gfc_array_index_type, size,
+   gfc_index_zero_node);
   else
gcc_unreachable ();
 
diff --git a/gcc/testsuite/gfortran.dg/shape_12.f90 
b/gcc/testsuite/gfortran.dg/shape_12.f90
new file mode 100644
index 000..e672e1ff9f9
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/shape_12.f90
@@ -0,0 +1,51 @@
+! { dg-do run }
+!
+! PR fortran/115150
+!
+! Check that SHAPE handles zero-sized arrays correctly
+!
+implicit none
+call one
+call two
+
+contains
+
+subroutine one
+  real,allocatable :: A(:),B(:,:)
+  allocate(a(3:0), b(5:1, 2:5))
+
+  if (any (shape(a) /= [0])) stop 1
+  if (any (shape(b) /= [0, 4])) stop 2
+  if (size(a) /= 0) stop 3
+  if (size(b) /= 0) stop 4
+  if (any (lbound(a) /= [1])) stop 5
+  if (any (lbound(b) /= [1, 2])) stop 6
+  if (any (ubound(a) /= [0])) stop 5
+  if (any (ubound(b) /= [0,5])) stop 6
+end
+
+subroutine two
+integer :: x1(10), x2(10,10)
+call f(x1, x2, -3)
+end
+
+subroutine f(y1, y2, n)
+  integer, value :: n
+  integer :: y1(1:n)
+  integer :: y2(1:n,4,2:*)
+  call g(y1, y2)
+end
+
+subroutine g(z1, z2)
+  integer :: z1(..), z2(..)
+
+  if (any (shape(z1) /= [0])) stop 1
+  if (any (shape(z2) /= [0, 4, -1])) stop 2
+  if (size(z1) /= 0) stop 3
+  if (size(z2) /= 0) stop 4
+  if (any (lbound(z1) /= [1])) stop 5
+  if (any (lbound(z2) /= [1, 1, 1])) stop 6
+  if (any (ubound(z1) /= [0])) stop 5
+  if (any (ubound(z2) /= [0, 4, -1])) stop 6
+end
+end


[gcc r15-867] testsuite/*/gomp: Remove 'dg-prune-output "not supported yet"'

2024-05-28 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:c0d78289fcd9c04110907f8cad90d7e1e5c55a44

commit r15-867-gc0d78289fcd9c04110907f8cad90d7e1e5c55a44
Author: Tobias Burnus 
Date:   Tue May 28 19:52:44 2024 +0200

testsuite/*/gomp: Remove 'dg-prune-output "not supported yet"'

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/lastprivate-conditional-1.c: Remove
'{ dg-prune-output "not supported yet" }'.
* c-c++-common/gomp/requires-1.c: Likewise.
* c-c++-common/gomp/requires-2.c: Likewise.
* c-c++-common/gomp/reverse-offload-1.c: Likewise.
* g++.dg/gomp/requires-1.C: Likewise.
* gfortran.dg/gomp/requires-1.f90: Likewise.
* gfortran.dg/gomp/requires-2.f90: Likewise.
* gfortran.dg/gomp/requires-4.f90: Likewise.
* gfortran.dg/gomp/requires-5.f90: Likewise.
* gfortran.dg/gomp/requires-6.f90: Likewise.
* gfortran.dg/gomp/requires-7.f90: Likewise.

Diff:
---
 gcc/testsuite/c-c++-common/gomp/lastprivate-conditional-1.c | 2 --
 gcc/testsuite/c-c++-common/gomp/requires-1.c| 2 --
 gcc/testsuite/c-c++-common/gomp/requires-2.c| 2 --
 gcc/testsuite/c-c++-common/gomp/reverse-offload-1.c | 2 --
 gcc/testsuite/g++.dg/gomp/requires-1.C  | 2 --
 gcc/testsuite/gfortran.dg/gomp/requires-1.f90   | 2 --
 gcc/testsuite/gfortran.dg/gomp/requires-2.f90   | 2 --
 gcc/testsuite/gfortran.dg/gomp/requires-4.f90   | 1 -
 gcc/testsuite/gfortran.dg/gomp/requires-5.f90   | 2 --
 gcc/testsuite/gfortran.dg/gomp/requires-6.f90   | 2 --
 gcc/testsuite/gfortran.dg/gomp/requires-7.f90   | 1 -
 11 files changed, 20 deletions(-)

diff --git a/gcc/testsuite/c-c++-common/gomp/lastprivate-conditional-1.c 
b/gcc/testsuite/c-c++-common/gomp/lastprivate-conditional-1.c
index 722aba79a52..d4ef49690e8 100644
--- a/gcc/testsuite/c-c++-common/gomp/lastprivate-conditional-1.c
+++ b/gcc/testsuite/c-c++-common/gomp/lastprivate-conditional-1.c
@@ -60,5 +60,3 @@ bar (int *p)
s = u;
   }
 }
-
-/* { dg-prune-output "not supported yet" } */
diff --git a/gcc/testsuite/c-c++-common/gomp/requires-1.c 
b/gcc/testsuite/c-c++-common/gomp/requires-1.c
index e1f2e3a503f..a47ec659566 100644
--- a/gcc/testsuite/c-c++-common/gomp/requires-1.c
+++ b/gcc/testsuite/c-c++-common/gomp/requires-1.c
@@ -10,5 +10,3 @@ foo ()
 
 #pragma omp requires unified_shared_memory unified_address
 #pragma omp requires atomic_default_mem_order(seq_cst)
-
-/* { dg-prune-output "not supported yet" } */
diff --git a/gcc/testsuite/c-c++-common/gomp/requires-2.c 
b/gcc/testsuite/c-c++-common/gomp/requires-2.c
index 717b65caeea..d7430b1b1a4 100644
--- a/gcc/testsuite/c-c++-common/gomp/requires-2.c
+++ b/gcc/testsuite/c-c++-common/gomp/requires-2.c
@@ -6,5 +6,3 @@
 #pragma omp requires dynamic_allocators , dynamic_allocators   /* { dg-error 
"too many 'dynamic_allocators' clauses" } */
 #pragma omp requires atomic_default_mem_order(seq_cst) 
atomic_default_mem_order(seq_cst)   /* { dg-error "too many 
'atomic_default_mem_order' clauses" } */
 #pragma omp requires atomic_default_mem_order (seq_cst)/* { dg-error 
"more than one 'atomic_default_mem_order' clause in a single compilation unit" 
} */
-
-/* { dg-prune-output "not supported yet" } */
diff --git a/gcc/testsuite/c-c++-common/gomp/reverse-offload-1.c 
b/gcc/testsuite/c-c++-common/gomp/reverse-offload-1.c
index 9a3fa5230f8..ddc3c2c6be1 100644
--- a/gcc/testsuite/c-c++-common/gomp/reverse-offload-1.c
+++ b/gcc/testsuite/c-c++-common/gomp/reverse-offload-1.c
@@ -6,8 +6,6 @@
 /* { dg-final { scan-tree-dump-times "__attribute__\\(\\(omp declare 
target\\)\\)\[\n\r\]*int called_in_target2" 1 "omplower" } }  */
 /* { dg-final { scan-tree-dump-times "__attribute__\\(\\(omp declare target, 
omp declare target block\\)\\)\[\n\r\]*void tg_fn" 1 "omplower" } }  */
 
-/* { dg-prune-output "'reverse_offload' clause on 'requires' directive not 
supported yet" } */
-
 #pragma omp requires reverse_offload
 
 extern int add_3 (int);
diff --git a/gcc/testsuite/g++.dg/gomp/requires-1.C 
b/gcc/testsuite/g++.dg/gomp/requires-1.C
index aefeb288dad..5ca5e006da1 100644
--- a/gcc/testsuite/g++.dg/gomp/requires-1.C
+++ b/gcc/testsuite/g++.dg/gomp/requires-1.C
@@ -8,5 +8,3 @@ namespace M {
 #pragma omp requires atomic_default_mem_order(seq_cst)
 }
 }
-
-/* { dg-prune-output "not supported yet" } */
diff --git a/gcc/testsuite/gfortran.dg/gomp/requires-1.f90 
b/gcc/testsuite/gfortran.dg/gomp/requires-1.f90
index b115a654e71..19007834c45 100644
--- a/gcc/testsuite/gfortran.dg/gomp/requires-1.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/requires-1.f90
@@ -9,5 +9,3 @@ subroutine bar
 !$omp requires unified_shared_memory unified_address
 !$omp requires atomic_default_mem_order(seq_cst)
 end
-
-! { dg-prune-output "not yet supported" }
diff --git a/gcc/testsuite/gfortran.dg/gomp/requires-2.f90 
b/gcc/testsu

[gcc r15-898] libgomp: Enable USM for some nvptx devices

2024-05-29 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:4ccb3366ade6ec9493f8ca20ab73b0da4b9816db

commit r15-898-g4ccb3366ade6ec9493f8ca20ab73b0da4b9816db
Author: Tobias Burnus 
Date:   Wed May 29 15:14:38 2024 +0200

libgomp: Enable USM for some nvptx devices

A few high-end nvptx devices support the attribute
CU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS; for those, unified shared
memory is supported in hardware. This patch enables support for those -
if all installed nvptx devices have this feature (as the capabilities
are per device type).

This exposes a bug in gomp_copy_back_icvs as it did before use
omp_get_mapped_ptr to find mapped variables, but that returns
the unchanged pointer in cased of shared memory. But in this case,
we have a few actually mapped pointers - like the ICV variables.
Additionally, there was a mismatch with regards to '-1' for the
device number as gomp_copy_back_icvs and omp_get_mapped_ptr count
differently. Hence, do the lookup manually.

include/ChangeLog:

* cuda/cuda.h (CU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS): Add.

libgomp/ChangeLog:

* libgomp.texi (nvptx): Update USM description.
* plugin/plugin-nvptx.c (GOMP_OFFLOAD_get_num_devices):
Claim support when requesting USM and all devices support
CU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS.
* target.c (gomp_copy_back_icvs): Fix device ptr lookup.
(gomp_target_init): Set GOMP_OFFLOAD_CAP_SHARED_MEM is the
devices supports USM.

Diff:
---
 include/cuda/cuda.h   |  3 ++-
 libgomp/libgomp.texi  |  7 +--
 libgomp/plugin/plugin-nvptx.c | 15 +++
 libgomp/target.c  | 24 +++-
 4 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/include/cuda/cuda.h b/include/cuda/cuda.h
index 0dca4b3a5c0..804d08ca57e 100644
--- a/include/cuda/cuda.h
+++ b/include/cuda/cuda.h
@@ -83,7 +83,8 @@ typedef enum {
   CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_MULTIPROCESSOR = 39,
   CU_DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT = 40,
   CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING = 41,
-  CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_MULTIPROCESSOR = 82
+  CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_MULTIPROCESSOR = 82,
+  CU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS = 88
 } CUdevice_attribute;
 
 enum {
diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 71d62105a20..22868635230 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -6435,8 +6435,11 @@ The implementation remark:
   the next reverse offload region is only executed after the previous
   one returned.
 @item OpenMP code that has a @code{requires} directive with
-  @code{unified_shared_memory} will remove any nvptx device from the
-  list of available devices (``host fallback'').
+  @code{unified_shared_memory} runs on nvptx devices if and only if
+  all of those support the @code{pageableMemoryAccess} property;@footnote{
+  
@uref{https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#um-requirements}}
+  otherwise, all nvptx device are removed from the list of available
+  devices (``host fallback'').
 @item The default per-warp stack size is 128 kiB; see also @code{-msoft-stack}
   in the GCC manual.
 @item The OpenMP routines @code{omp_target_memcpy_rect} and
diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c
index 5aad3448a8d..4cedc5390a3 100644
--- a/libgomp/plugin/plugin-nvptx.c
+++ b/libgomp/plugin/plugin-nvptx.c
@@ -1201,8 +1201,23 @@ GOMP_OFFLOAD_get_num_devices (unsigned int 
omp_requires_mask)
   if (num_devices > 0
   && ((omp_requires_mask
   & ~(GOMP_REQUIRES_UNIFIED_ADDRESS
+  | GOMP_REQUIRES_UNIFIED_SHARED_MEMORY
   | GOMP_REQUIRES_REVERSE_OFFLOAD)) != 0))
 return -1;
+  /* Check whether host page access (direct or via migration) is supported;
+ if so, enable USM.  Currently, capabilities is per device type, hence,
+ check all devices.  */
+  if (num_devices > 0
+  && (omp_requires_mask & GOMP_REQUIRES_UNIFIED_SHARED_MEMORY))
+for (int dev = 0; dev < num_devices; dev++)
+  {
+   int pi;
+   CUresult r;
+   r = CUDA_CALL_NOCHECK (cuDeviceGetAttribute, &pi,
+  CU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS, dev);
+   if (r != CUDA_SUCCESS || pi == 0)
+ return -1;
+  }
   return num_devices;
 }
 
diff --git a/libgomp/target.c b/libgomp/target.c
index 5ec19ae489e..48689920d4a 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -2969,8 +2969,25 @@ gomp_copy_back_icvs (struct gomp_device_descr *devicep, 
int device)
   if (item == NULL)
 return;
 
+  gomp_mutex_lock (&devicep->lock);
+
+  struct splay_tree_s *mem_map = &devicep->mem_map;
+  struct splay_tree_key_s cur_node;
+  void *dev_ptr = NULL;
+
   void *host_ptr = &item->icvs;
-  void *dev_ptr = omp_get_mapped_ptr (host_ptr, device);
+

[gcc r15-899] libgomp: Enable USM for AMD APUs and MI200 devices

2024-05-29 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:18f477980c8597fe3dca2c2e8bd533c0c2b17aa6

commit r15-899-g18f477980c8597fe3dca2c2e8bd533c0c2b17aa6
Author: Tobias Burnus 
Date:   Wed May 29 15:29:06 2024 +0200

libgomp: Enable USM for AMD APUs and MI200 devices

If HSA_AMD_SYSTEM_INFO_SVM_ACCESSIBLE_BY_DEFAULT is true,
all GPUs on the system support unified shared memory. That's
the case for APUs and MI200 devices when XNACK is enabled.

XNACK can be enabled by setting HSA_XNACK=1 as env var for
supported devices; otherwise, if disable, USM code will
use host fallback.

gcc/ChangeLog:

* config/gcn/gcn-hsa.h (gcn_local_sym_hash): Fix typo.

include/ChangeLog:

* hsa.h (HSA_AMD_SYSTEM_INFO_SVM_ACCESSIBLE_BY_DEFAULT): Add
enum value.

libgomp/ChangeLog:

* libgomp.texi (gcn): Update USM handling
* plugin/plugin-gcn.c (GOMP_OFFLOAD_get_num_devices): Handle
USM if HSA_AMD_SYSTEM_INFO_SVM_ACCESSIBLE_BY_DEFAULT is true.

Diff:
---
 gcc/config/gcn/gcn-hsa.h|  2 +-
 include/hsa.h   |  4 +++-
 libgomp/libgomp.texi|  9 +++--
 libgomp/plugin/plugin-gcn.c | 17 +
 4 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/gcc/config/gcn/gcn-hsa.h b/gcc/config/gcn/gcn-hsa.h
index 4611bc55392..03220555075 100644
--- a/gcc/config/gcn/gcn-hsa.h
+++ b/gcc/config/gcn/gcn-hsa.h
@@ -80,7 +80,7 @@ extern unsigned int gcn_local_sym_hash (const char *name);
writes a new AMD GPU object file and the ABI version needs to be the
same. - LLVM <= 17 defaults to 4 while LLVM >= 18 defaults to 5.
GCC supports LLVM >= 13.0.1 and only LLVM >= 14 supports version 5.
-   Note that Fiji is only suppored with LLVM <= 17 as version 3 is no longer
+   Note that Fiji is only supported with LLVM <= 17 as version 3 is no longer
supported in LLVM >= 18.  */
 #define ABI_VERSION_SPEC "march=fiji:--amdhsa-code-object-version=3;" \
 "!march=*|march=*:--amdhsa-code-object-version=4"
diff --git a/include/hsa.h b/include/hsa.h
index f9b5d9daf85..3c7be95d7fd 100644
--- a/include/hsa.h
+++ b/include/hsa.h
@@ -466,7 +466,9 @@ typedef enum {
   /**
   * String containing the ROCr build identifier.
   */
-  HSA_AMD_SYSTEM_INFO_BUILD_VERSION = 0x200
+  HSA_AMD_SYSTEM_INFO_BUILD_VERSION = 0x200,
+
+  HSA_AMD_SYSTEM_INFO_SVM_ACCESSIBLE_BY_DEFAULT = 0x202
 } hsa_system_info_t;
 
 /**
diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 22868635230..e79bd7a3392 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -6360,8 +6360,13 @@ The implementation remark:
   such that the next reverse offload region is only executed after the 
previous
   one returned.
 @item OpenMP code that has a @code{requires} directive with
-  @code{unified_shared_memory} will remove any GCN device from the list of
-  available devices (``host fallback'').
+  @code{unified_shared_memory} is only supported if all AMD GPUs have the
+  @code{HSA_AMD_SYSTEM_INFO_SVM_ACCESSIBLE_BY_DEFAULT} property; for
+  discrete GPUs, this may require setting the @code{HSA_XNACK} environment
+  variable to @samp{1}; for systems with both an APU and a discrete GPU 
that
+  does not support XNACK, consider using @code{ROCR_VISIBLE_DEVICES} to
+  enable only the APU.  If not supported, all AMD GPU devices are removed
+  from the list of available devices (``host fallback'').
 @item The available stack size can be changed using the @code{GCN_STACK_SIZE}
   environment variable; the default is 32 kiB per thread.
 @item Low-latency memory (@code{omp_low_lat_mem_space}) is supported when the
diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c
index 3cdc7ba929f..3d882b5ab63 100644
--- a/libgomp/plugin/plugin-gcn.c
+++ b/libgomp/plugin/plugin-gcn.c
@@ -3355,8 +3355,25 @@ GOMP_OFFLOAD_get_num_devices (unsigned int 
omp_requires_mask)
   if (hsa_context.agent_count > 0
   && ((omp_requires_mask
   & ~(GOMP_REQUIRES_UNIFIED_ADDRESS
+  | GOMP_REQUIRES_UNIFIED_SHARED_MEMORY
   | GOMP_REQUIRES_REVERSE_OFFLOAD)) != 0))
 return -1;
+  /* Check whether host page access is supported; this is per system level
+ (all GPUs supported by HSA).  While intrinsically true for APUs, it
+ requires XNACK support for discrete GPUs.  */
+  if (hsa_context.agent_count > 0
+  && (omp_requires_mask & GOMP_REQUIRES_UNIFIED_SHARED_MEMORY))
+{
+  bool b;
+  hsa_system_info_t type = HSA_AMD_SYSTEM_INFO_SVM_ACCESSIBLE_BY_DEFAULT;
+  hsa_status_t status = hsa_fns.hsa_system_get_info_fn (type, &b);
+  if (status != HSA_STATUS_SUCCESS)
+   GOMP_PLUGIN_error ("HSA_AMD_SYSTEM_INFO_SVM_ACCESSIBLE_BY_DEFAULT "
+  "failed");
+  if (!b)
+   return -1;
+}
+
   return hsa_context.agent_count;
 }


[gcc r15-924] libgomp.texi: Impl. update for USM and missing 5.2 item

2024-05-30 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:370df6ef0fe6d99613050d33a18cc008be7ceca4

commit r15-924-g370df6ef0fe6d99613050d33a18cc008be7ceca4
Author: Tobias Burnus 
Date:   Thu May 30 13:21:43 2024 +0200

libgomp.texi: Impl. update for USM and missing 5.2 item

libgomp/ChangeLog:

* libgomp.texi (OpenMP 5.0 status): Mark 'requires' as done and
link to 'Offload-Target Specifics'.
(OpenMP 5.2 status): Add item about additional map-type modifiers
in 'declare mapper'.

Diff:
---
 libgomp/libgomp.texi | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index e79bd7a3392..d612488ad10 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -198,8 +198,8 @@ The OpenMP 4.5 specification is fully supported.
 @item @var{target-offload-var} ICV and @code{OMP_TARGET_OFFLOAD}
   env variable @tab Y @tab
 @item Nested-parallel changes to @var{max-active-levels-var} ICV @tab Y @tab
-@item @code{requires} directive @tab P
-  @tab complete but no non-host device provides 
@code{unified_shared_memory}
+@item @code{requires} directive @tab Y
+  @tab See also @ref{Offload-Target Specifics}
 @item @code{teams} construct outside an enclosing target region @tab Y @tab
 @item Non-rectangular loop nests @tab P
   @tab Full support for C/C++, partial for Fortran
@@ -443,6 +443,8 @@ to address of matching mapped list item per 5.1, Sect. 
2.21.7.2 @tab N @tab
   of the @code{interop} construct @tab N @tab
 @item Invoke virtual member functions of C++ objects created on the host device
   on other devices @tab N @tab
+@item @code{iterator} and @code{mapper} as map-type modifier in @code{declare 
mappter}
+  @tab N @tab
 @end multitable


[gcc r15-990] install.texi (gcn): Fix date of recommended newlib version

2024-06-03 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:16fb3abf0fb4b88ee0e27732db217909fa429a81

commit r15-990-g16fb3abf0fb4b88ee0e27732db217909fa429a81
Author: Tobias Burnus 
Date:   Mon Jun 3 12:56:39 2024 +0200

install.texi (gcn): Fix date of recommended newlib version

gcc/ChangeLog:

* doc/install.texi (gcn): Fix date of recommended newlib version.

Diff:
---
 gcc/doc/install.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 42b462a2ce2..c781646ac1f 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -3950,7 +3950,7 @@ by specifying a @code{--with-multilib-list=} that does 
not list @code{gfx1100}
 and @code{gfx1103}.
 
 Use Newlib (4.3.0 or newer; 4.4.0 contains some improvements and git commit
-7dd4eb1db (2025-03-25, post-4.4.0) fixes device console output for GFX10 and
+7dd4eb1db (2024-03-25, post-4.4.0) fixes device console output for GFX10 and
 GFX11 devices).
 
 To run the binaries, install the HSA Runtime from the


[gcc r15-1072] libgomp.texi (nvptx): Add missing preposition

2024-06-06 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:423522aacd9f30bb75aa77d38fccb630bfc4c98a

commit r15-1072-g423522aacd9f30bb75aa77d38fccb630bfc4c98a
Author: Tobias Burnus 
Date:   Thu Jun 6 16:37:55 2024 +0200

libgomp.texi (nvptx): Add missing preposition

libgomp/
* libgomp.texi (nvptx): Add missing preposition.

Diff:
---
 libgomp/libgomp.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index eb608915938..73e8e39ca42 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -6432,7 +6432,7 @@ The implementation remark:
 @item I/O within OpenMP target regions and OpenACC compute regions is supported
   using the C library @code{printf} functions.
   Additionally, the Fortran @code{print}/@code{write} statements are
-  supported within OpenMP target regions, but not yet OpenACC compute
+  supported within OpenMP target regions, but not yet within OpenACC 
compute
   regions.  @c The latter needs 'GOMP_NVPTX_NATIVE_GPU_THREAD_STACK_SIZE'.
 @item Compilation OpenMP code that contains @code{requires reverse_offload}
   requires at least @code{-march=sm_35}, compiling for @code{-march=sm_30}


[gcc r15-4298] Fortran: Use OpenACC's acc_on_device builtin, fix OpenMP' __builtin_is_initial_device

2024-10-13 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:3269a722b7a03613e9c4e2862bc5088c4a17cc11

commit r15-4298-g3269a722b7a03613e9c4e2862bc5088c4a17cc11
Author: Tobias Burnus 
Date:   Sun Oct 13 10:18:31 2024 +0200

Fortran: Use OpenACC's acc_on_device builtin, fix OpenMP' 
__builtin_is_initial_device

It turned out that 'if (omp_is_initial_device() .eqv. true)' gave an ICE
due to comparing 'int' with 'logical(4)'. When digging deeper, it also
turned out that when the procedure pointer is needed, the builtin cannot
be used, either.  (Follow up to r15-2799-gf1bfba3a9b3f31 )

Extend the code to also use the builtin acc_on_device with OpenACC,
which was previously only used in C/C++.  Additionally, fix folding
when offloading is not enabled.

Fixes additionally the BT_BOOL data type, which was 'char'/integer(1)
instead of bool, backing the booleaness; use bool_type_node as the rest
of GCC.

gcc/fortran/ChangeLog:

* gfortran.h (gfc_option_t): Add disable_acc_on_device.
* options.cc (gfc_handle_option): Handle -fno-builtin-acc_on_device.
* trans-decl.cc (gfc_get_extern_function_decl): Move
__builtin_omp_is_initial_device handling to ...
* trans-expr.cc (get_builtin_fn): ... this new function.
(conv_function_val): Call it.
(update_builtin_function): New.
(gfc_conv_procedure_call): Call it.
* types.def (BT_BOOL): Fix type by using bool_type_node.

gcc/ChangeLog:

* gimple-fold.cc (gimple_fold_builtin_acc_on_device): Also fold
when offloading is not configured.

libgomp/ChangeLog:

* libgomp.texi (TR13): Fix minor typos.
(omp_is_initial_device): Improve wording.
(acc_on_device): Note how to disable the builtin.
* testsuite/libgomp.oacc-fortran/acc_on_device-1-1.f90: Remove TODO.
* testsuite/libgomp.oacc-fortran/acc_on_device-1-2.f: Likewise.
Add -fno-builtin-acc_on_device.
* testsuite/libgomp.oacc-fortran/acc_on_device-1-3.f: Likewise.
* testsuite/libgomp.oacc-c-c++-common/routine-nohost-1.c: Update
dg- as !offloading_enabled now compile-time expands acc_on_device.
* testsuite/libgomp.fortran/target-is-initial-device-3.f90: New 
test.
* testsuite/libgomp.oacc-fortran/acc_on_device-2.f90: New test.

Diff:
---
 gcc/fortran/gfortran.h |  3 +-
 gcc/fortran/options.cc |  5 +-
 gcc/fortran/trans-decl.cc  |  9 
 gcc/fortran/trans-expr.cc  | 58 +++---
 gcc/fortran/types.def  |  3 +-
 gcc/gimple-fold.cc |  2 +-
 libgomp/libgomp.texi   | 18 ---
 .../libgomp.fortran/target-is-initial-device-3.f90 | 50 +++
 .../libgomp.oacc-c-c++-common/routine-nohost-1.c   |  3 +-
 .../libgomp.oacc-fortran/acc_on_device-1-1.f90 |  5 --
 .../libgomp.oacc-fortran/acc_on_device-1-2.f   |  7 +--
 .../libgomp.oacc-fortran/acc_on_device-1-3.f   |  7 +--
 .../libgomp.oacc-fortran/acc_on_device-2.f90   | 40 +++
 13 files changed, 164 insertions(+), 46 deletions(-)

diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 286c93baa74d..7aa9b1312fee 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -3204,7 +3204,8 @@ typedef struct
   int flag_init_logical;
   int flag_init_character;
   char flag_init_character_value;
-  int disable_omp_is_initial_device;
+  bool disable_omp_is_initial_device;
+  bool disable_acc_on_device;
 
   int fpe;
   int fpe_summary;
diff --git a/gcc/fortran/options.cc b/gcc/fortran/options.cc
index d998d0e61170..a55f1f36f3f9 100644
--- a/gcc/fortran/options.cc
+++ b/gcc/fortran/options.cc
@@ -868,11 +868,14 @@ gfc_handle_option (size_t scode, const char *arg, 
HOST_WIDE_INT value,
   break;
 
 case OPT_fbuiltin_:
-  /* We only handle -fno-builtin-omp_is_initial_device.  */
+  /* We only handle -fno-builtin-omp_is_initial_device
+and -fno-builtin-acc_on_device.  */
   if (value)
return false;  /* Not supported. */
   if (!strcmp ("omp_is_initial_device", arg))
gfc_option.disable_omp_is_initial_device = true;
+  else if (!strcmp ("acc_on_device", arg))
+   gfc_option.disable_acc_on_device = true;
   else
warning (0, "command-line option %<-fno-builtin-%s%> is not valid for "
 "Fortran", arg);
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 2586c6d7a79c..56b6202510e8 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -2231,15 +2231,6 @@ gfc_get_extern_function_decl (gfc_symbol * sym, 
gfc_actual_arglist *actual_args,
  to know that.  */
   gcc_assert (!(sym->attr.entry || sym->attr.entry_maste

[gcc r15-4291] Fortran/OpenMP: Warn when mapping polymorphic variables

2024-10-12 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:34b77d1b9ac53c89296a0d8bd7f4cf35eebd8001

commit r15-4291-g34b77d1b9ac53c89296a0d8bd7f4cf35eebd8001
Author: Tobias Burnus 
Date:   Sat Oct 12 14:55:22 2024 +0200

Fortran/OpenMP: Warn when mapping polymorphic variables

OpenMP (TR13) states for Fortran:
* For map: "If a list item has polymorphic type, the behavior is 
unspecified."
* "If the firstprivate clause is on a target construct and a variable is of
  polymorphic type, the behavior is unspecified."
which this commit now warns for.

gcc/fortran/ChangeLog:

* openmp.cc (resolve_omp_clauses): Diagnose polymorphic mapping.
* trans-openmp.cc (gfc_omp_finish_clause): Warn when
polymorphic variable is implicitly mapped.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/polymorphic-mapping.f90: New test.
* gfortran.dg/gomp/polymorphic-mapping-2.f90: New test.

Diff:
---
 gcc/fortran/openmp.cc  | 51 +-
 gcc/fortran/trans-openmp.cc|  5 +++
 .../gfortran.dg/gomp/polymorphic-mapping-2.f90 | 16 +++
 .../gfortran.dg/gomp/polymorphic-mapping.f90   | 51 ++
 4 files changed, 121 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index d9ccae8a11fd..2c12f5e362d6 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -9087,10 +9087,30 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses 
*omp_clauses,
  gfc_error ("List item %qs with allocatable components is not "
 "permitted in map clause at %L", n->sym->name,
 &n->where);
+   if (!openacc
+   && (list == OMP_LIST_MAP
+   || list == OMP_LIST_FROM
+   || list == OMP_LIST_TO)
+   && ((n->expr && n->expr->ts.type == BT_CLASS)
+   || (!n->expr && n->sym->ts.type == BT_CLASS)))
+ gfc_warning (OPT_Wopenmp,
+  "Mapping polymorphic list item at %L is "
+  "unspecified behavior", &n->where);
if (list == OMP_LIST_MAP && !openacc)
  switch (code->op)
{
case EXEC_OMP_TARGET:
+   case EXEC_OMP_TARGET_PARALLEL:
+   case EXEC_OMP_TARGET_PARALLEL_DO:
+   case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
+   case EXEC_OMP_TARGET_PARALLEL_LOOP:
+   case EXEC_OMP_TARGET_SIMD:
+   case EXEC_OMP_TARGET_TEAMS:
+   case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
+   case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
+   case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
+   case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
+   case EXEC_OMP_TARGET_TEAMS_LOOP:
case EXEC_OMP_TARGET_DATA:
  switch (n->u.map.op)
{
@@ -9113,8 +9133,8 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses 
*omp_clauses,
  gfc_error ("TARGET%s with map-type other than TO, "
 "FROM, TOFROM, or ALLOC on MAP clause "
 "at %L",
-code->op == EXEC_OMP_TARGET
-? "" : " DATA", &n->where);
+code->op == EXEC_OMP_TARGET_DATA
+? " DATA" : "", &n->where);
  break;
}
  break;
@@ -9381,6 +9401,33 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses 
*omp_clauses,
&& n->sym == omp_clauses->detach->symtree->n.sym)
  gfc_error ("DETACH event handle %qs in %s clause at %L",
 n->sym->name, name, &n->where);
+
+   if (!openacc
+   && list == OMP_LIST_FIRSTPRIVATE
+   && ((n->expr && n->expr->ts.type == BT_CLASS)
+   || (!n->expr && n->sym->ts.type == BT_CLASS)))
+ switch (code->op)
+   {
+   case EXEC_OMP_TARGET:
+   case EXEC_OMP_TARGET_PARALLEL:
+   case EXEC_OMP_TARGET_PARALLEL_DO:
+   case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
+   case EXEC_OMP_TARGET_PARALLEL_LOOP:
+   case EXEC_OMP_TARGET_SIMD:
+   case EXEC_OMP_TARGET_TEAMS:
+   case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
+   case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
+   case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
+   case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
+  

[gcc r15-4268] Fortran: Dead-function removal in error.cc (shrinking by 40%)

2024-10-11 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:459c6018d2308d0e6e6146cbcd2b73968fdb6404

commit r15-4268-g459c6018d2308d0e6e6146cbcd2b73968fdb6404
Author: Tobias Burnus 
Date:   Fri Oct 11 17:05:37 2024 +0200

Fortran: Dead-function removal in error.cc (shrinking by 40%)

This patch removes a large number of unused static functions from error.cc,
which previously were used for diagnostic but have been replaced by the 
common
diagnostic code.

gcc/fortran/ChangeLog:

* error.cc (error_char, error_string, error_uinteger, error_integer,
error_hwuint, error_hwint, gfc_widechar_display_length,
gfc_wide_display_length, error_printf, show_locus, show_loci):
Remove unused static functions.
(IBUF_LEN, MAX_ARGS): Remove now unused #define.

Diff:
---
 gcc/fortran/error.cc | 717 ---
 1 file changed, 717 deletions(-)

diff --git a/gcc/fortran/error.cc b/gcc/fortran/error.cc
index 2c29537a4ff0..e6c05aa149f4 100644
--- a/gcc/fortran/error.cc
+++ b/gcc/fortran/error.cc
@@ -128,136 +128,6 @@ gfc_buffer_error (bool flag)
 }
 
 
-/* Add a single character to the error buffer or output depending on
-   buffered_p.  */
-
-static void
-error_char (char)
-{
-  /* FIXME: Unused function to be removed in a subsequent patch.  */
-}
-
-
-/* Copy a string to wherever it needs to go.  */
-
-static void
-error_string (const char *p)
-{
-  while (*p)
-error_char (*p++);
-}
-
-
-/* Print a formatted integer to the error buffer or output.  */
-
-#define IBUF_LEN 60
-
-static void
-error_uinteger (unsigned long long int i)
-{
-  char *p, int_buf[IBUF_LEN];
-
-  p = int_buf + IBUF_LEN - 1;
-  *p-- = '\0';
-
-  if (i == 0)
-*p-- = '0';
-
-  while (i > 0)
-{
-  *p-- = i % 10 + '0';
-  i = i / 10;
-}
-
-  error_string (p + 1);
-}
-
-static void
-error_integer (long long int i)
-{
-  unsigned long long int u;
-
-  if (i < 0)
-{
-  u = (unsigned long long int) -i;
-  error_char ('-');
-}
-  else
-u = i;
-
-  error_uinteger (u);
-}
-
-
-static void
-error_hwuint (unsigned HOST_WIDE_INT i)
-{
-  char *p, int_buf[IBUF_LEN];
-
-  p = int_buf + IBUF_LEN - 1;
-  *p-- = '\0';
-
-  if (i == 0)
-*p-- = '0';
-
-  while (i > 0)
-{
-  *p-- = i % 10 + '0';
-  i = i / 10;
-}
-
-  error_string (p + 1);
-}
-
-static void
-error_hwint (HOST_WIDE_INT i)
-{
-  unsigned HOST_WIDE_INT u;
-
-  if (i < 0)
-{
-  u = (unsigned HOST_WIDE_INT) -i;
-  error_char ('-');
-}
-  else
-u = i;
-
-  error_uinteger (u);
-}
-
-
-static size_t
-gfc_widechar_display_length (gfc_char_t c)
-{
-  if (gfc_wide_is_printable (c) || c == '\t')
-/* Printable ASCII character, or tabulation (output as a space).  */
-return 1;
-  else if (c < ((gfc_char_t) 1 << 8))
-/* Displayed as \x??  */
-return 4;
-  else if (c < ((gfc_char_t) 1 << 16))
-/* Displayed as \u  */
-return 6;
-  else
-/* Displayed as \U  */
-return 10;
-}
-
-
-/* Length of the ASCII representation of the wide string, escaping wide
-   characters as print_wide_char_into_buffer() does.  */
-
-static size_t
-gfc_wide_display_length (const gfc_char_t *str)
-{
-  size_t i, len;
-
-  for (i = 0, len = 0; str[i]; i++)
-len += gfc_widechar_display_length (str[i]);
-
-  return len;
-}
-
 static int
 print_wide_char_into_buffer (gfc_char_t c, char *buf)
 {
@@ -332,593 +202,6 @@ gfc_print_wide_char (gfc_char_t c)
 }
 
 
-/* Show the file, where it was included, and the source line, give a
-   locus.  Calls error_printf() recursively, but the recursion is at
-   most one level deep.  */
-
-static void error_printf (const char *, ...) ATTRIBUTE_GCC_GFC(1,2);
-
-static void
-show_locus (locus *loc, int c1, int c2)
-{
-  gfc_linebuf *lb;
-  gfc_file *f;
-  gfc_char_t *p;
-  int i, offset, cmax;
-
-  /* TODO: Either limit the total length and number of included files
- displayed or add buffering of arbitrary number of characters in
- error messages.  */
-
-  /* Write out the error header line, giving the source file and error
- location (in GNU standard "[file]:[line].[column]:" format),
- followed by an "included by" stack and a blank line.  This header
- format is matched by a testsuite parser defined in
- lib/gfortran-dg.exp.  */
-
-  lb = loc->lb;
-  f = lb->file;
-
-  error_string (f->filename);
-  error_char (':');
-
-  error_integer (LOCATION_LINE (lb->location));
-
-  if ((c1 > 0) || (c2 > 0))
-error_char ('.');
-
-  if (c1 > 0)
-error_integer (c1);
-
-  if ((c1 > 0) && (c2 > 0))
-error_char ('-');
-
-  if (c2 > 0)
-error_integer (c2);
-
-  error_char (':');
-  error_char ('\n');
-
-  for (;;)
-{
-  i = f->inclusion_line;
-
-  f = f->up;
-  if (f == NULL) break;
-
-  error_printf ("Included at %s:%d:", f->filename, i);
-}
-
-  error_char ('\n');
-
-  /* Calculate an appropriate horizontal offset of the source line in
- ord

[gcc r15-4104] OpenMP: Allocate directive for static vars, clean up

2024-10-07 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:a8caeaacf499d58ba7ceabc311b7b71ca806f740

commit r15-4104-ga8caeaacf499d58ba7ceabc311b7b71ca806f740
Author: Tobias Burnus 
Date:   Mon Oct 7 10:45:14 2024 +0200

OpenMP: Allocate directive for static vars, clean up

For the 'allocate' directive, remove the sorry for static variables and
just keep using normal memory, but honor the requested alignment and set
a DECL_ATTRIBUTE in case a target may want to make use of this later on.
The documentation is updated accordingly.

The C diagnostic to check for predefined allocators (req. for static vars)
failed to accept GCC's ompx_gnu_... allocator, now fixed. (Fortran was
already okay; but both now use new common #defined value for checking.)
And while Fortran common block variables are still rejected, the check
has been improved as before the sorry diagnostic did not work for
common blocks in modules.

Finally, for 'allocate' clause on the target/task/taskloop directives,
there is now a warning for omp_thread_mem_alloc (i.e. predefined allocator
with access = thread), which is undefined behavior according to the
OpenMP specification.

And, last, testing showed that var decl + static_assert sets TREE_USED
but does not produce a statement list in C, which did run into an assert
in gimplify. This special case is now also handled.

gcc/c/ChangeLog:

* c-parser.cc (c_parser_omp_allocate): Set alignment for alignof;
accept static variables and fix predef allocator check.

gcc/fortran/ChangeLog:

* openmp.cc (is_predefined_allocator): Use gomp-constants.h consts.
* trans-common.cc (translate_common): Reject OpenMP allocate 
directives.
* trans-decl.cc (gfc_finish_var_decl): Handle allocate directive
for static variables.
(gfc_trans_deferred_vars): Update for the latter.

gcc/ChangeLog:

* gimplify.cc (gimplify_bind_expr): Fix corner case for OpenMP
allocate directive.
(gimplify_scan_omp_clauses): Warn if omp_thread_mem_alloc is used
as allocator with the target/task/taskloop directive.

include/ChangeLog:

* gomp-constants.h (GOMP_OMP_PREDEF_ALLOC_MAX,
GOMP_OMPX_PREDEF_ALLOC_MIN, GOMP_OMPX_PREDEF_ALLOC_MAX,
GOMP_OMP_PREDEF_ALLOC_THREADS): New defines.

libgomp/ChangeLog:

* allocator.c: Add static asserts for news
GOMP_OMP{,X}_PREDEF_ALLOC_{MIN,MAX} range values.
* libgomp.texi (OpenMP Impl. Status): Allocate directive for
static vars is now supported. Refer to PR for allocate clause.
(Memory allocation): Update for static vars; minor word tweaking.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/allocate-9.c: Update for removed sorry.
* gfortran.dg/gomp/allocate-15.f90: Likewise.
* gfortran.dg/gomp/allocate-pinned-1.f90: Likewise.
* gfortran.dg/gomp/allocate-4.f90: Likewise; add dg-error for
previously missing diagnostic.
* c-c++-common/gomp/allocate-18.c: New test.
* c-c++-common/gomp/allocate-19.c: New test.
* gfortran.dg/gomp/allocate-clause.f90: New test.
* gfortran.dg/gomp/allocate-static-2.f90: New test.
* gfortran.dg/gomp/allocate-static.f90: New test.

Diff:
---
 gcc/c/c-parser.cc  |  29 +++--
 gcc/fortran/openmp.cc  |   9 +-
 gcc/fortran/trans-common.cc|   4 +
 gcc/fortran/trans-decl.cc  | 131 +++--
 gcc/gimplify.cc|  22 +++-
 gcc/testsuite/c-c++-common/gomp/allocate-18.c  |  59 ++
 gcc/testsuite/c-c++-common/gomp/allocate-19.c  |  69 +++
 gcc/testsuite/c-c++-common/gomp/allocate-9.c   |  43 +++
 gcc/testsuite/gfortran.dg/gomp/allocate-15.f90 |   2 +-
 gcc/testsuite/gfortran.dg/gomp/allocate-4.f90  |   6 +-
 gcc/testsuite/gfortran.dg/gomp/allocate-clause.f90 |  61 ++
 .../gfortran.dg/gomp/allocate-pinned-1.f90 |   2 +-
 .../gfortran.dg/gomp/allocate-static-2.f90 |  52 
 gcc/testsuite/gfortran.dg/gomp/allocate-static.f90 |  62 ++
 include/gomp-constants.h   |   8 ++
 libgomp/allocator.c|   9 ++
 libgomp/libgomp.texi   |  15 +--
 17 files changed, 469 insertions(+), 114 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index a681438cbbef..fe01f955e215 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -20967,20 +20967,22 @@ c_parser_omp_allocate (c_parser *parser)
   if (TREE_STATIC (var))
{
  if (allocator == NULL_TREE && allocator_loc == UNKNOWN_LOCATION)
-   error_at (loc,

[gcc r15-4126] libgomp.texi: Update and cleanup of Impl. Status of OpenMP TR13

2024-10-07 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:e2039386b82901d2b7d78b2a27d2982aacbf46a4

commit r15-4126-ge2039386b82901d2b7d78b2a27d2982aacbf46a4
Author: Tobias Burnus 
Date:   Mon Oct 7 23:13:29 2024 +0200

libgomp.texi: Update and cleanup of Impl. Status of OpenMP TR13

libgomp/ChangeLog:

* libgomp.texi (OpenMP Technical Report 13): Wording cleanup;
sort as in Appendix B; add missing items; remove duplicates.

Diff:
---
 libgomp/libgomp.texi | 70 ++--
 1 file changed, 40 insertions(+), 30 deletions(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index bad06e143dc6..cc44efdd9371 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -462,28 +462,33 @@ Technical Report (TR) 13 is the third preview for OpenMP 
6.0.
 @item Full support for Fortran 2023 was added @tab P @tab
 @item @code{_ALL} suffix to the device-scope environment variables
   @tab P @tab Host device number wrongly accepted
-@item @code{num_threads} now accepts a list @tab N @tab
+@item @code{num_threads} clause now accepts a list @tab N @tab
 @item Abstract names added for @code{OMP_NUM_THREADS},
   @code{OMP_THREAD_LIMIT} and @code{OMP_TEAMS_THREAD_LIMIT}
   @tab N @tab
 @item Supporting increments with abstract names in @code{OMP_PLACES} @tab N 
@tab
 @item Extension of @code{OMP_DEFAULT_DEVICE} and new
   @code{OMP_AVAILABLE_DEVICES} environment vars @tab N @tab
+@item New @code{uid} trait for target devices and for
+  @code{OMP_AVAILABLE_DEVICES} and @code{OMP_DEFAULT_DEVICE} @tab N @tab
 @item New @code{OMP_THREADS_RESERVE} environment variable @tab N @tab
 @item The @code{decl} attribute was added to the C++ attribute syntax
   @tab Y @tab
-@item The OpenMP directive syntax was extended to include C 23 attribute
+@item The OpenMP directive syntax was extended to include C23 attribute
   specifiers @tab Y @tab
 @item Support for pure directives in Fortran's @code{do concurrent} @tab N @tab
 @item All inarguable clauses take now an optional Boolean argument @tab N @tab
 @item The @code{adjust_args} clause was extended to specify the argument by 
position
+  and supports variadic arguments @tab N @tab
 @item For Fortran, @emph{locator list} can be also function reference with
   data pointer result @tab N @tab
 @item Concept of @emph{assumed-size arrays} in C and C++
   @tab N @tab
 @item @emph{directive-name-modifier} accepted in all clauses @tab N @tab
-@item Argument-free version of @code{depobj} including added @code{init} clause
-  @tab N @tab
+@item Extension of @code{interop} operation of @code{append_args}, allowing
+  all modifiers of the @code{init} clause @tab N @tab
+@item New argument-free version of @code{depobj} with repeatable clauses and
+  the @code{init} clause @tab N @tab
 @item Undeprecate omitting the argument to the @code{depend} clause of
   the argument version of the @code{depend} construct @tab Y @tab
 @item For Fortran, atomic with BLOCK construct and, for C/C++, with
@@ -492,19 +497,20 @@ Technical Report (TR) 13 is the third preview for OpenMP 
6.0.
 @item For Fortran, atomic with enum and enumeration types @tab N @tab
 @item For Fortran, atomic compare with storing the comparison result
   @tab N @tab
-@item New @code{looprange} clause @tab N @tab
+@item Canonical loop sequences and new @code{looprange} clause @tab N @tab
 @item For Fortran, handling polymorphic types in data-sharing-attribute
   clauses @tab P @tab @code{private} not supported
 @item For Fortran, rejecting polymorphic types in data-mapping clauses
   @tab N @tab not diagnosed (and mostly unsupported)
 @item New @code{taskgraph} construct including @code{saved} modifier and
   @code{replayable} clause @tab N @tab
-@item @code{default} clause on the @code{target} directive @tab N @tab
-@item Ref-count change for @code{use_device_ptr} and @code{use_device_addr}
-  @tab N @tab
+@item @code{default} clause on the @code{target} directive and accepting
+  variable categories @tab N @tab
+@item Semantic change regarding the reference count update with
+  @code{use_device_ptr} and @code{use_device_addr} @tab N @tab
 @item Support for inductions @tab N @tab
-@item Deprecation of the combiner expression in the @code{declare_reduction}
-  argument @tab N @tab
+@item Reduction over private variables with @code{reduction} clause
+  @tab N @tab
 @item Implicit reduction identifiers of C++ classes
   @tab N @tab
 @item New @code{init_complete} clause to the @code{scan} directive
@@ -512,8 +518,6 @@ Technical Report (TR) 13 is the third preview for OpenMP 
6.0.
 @item @code{ref} modifier to the @code{map} clause @tab N @tab
 @item New @code{storage} map-type modifier; context-dependent @code{alloc} and
   @code{release} are aliases @tab N @tab
-@item Update of the map-type decay for mapping and @code{declare_mapper}
-  @tab N @tab
 @item Change of the @emph{map-type} p

[gcc r15-4127] Move gfortran.dg/gomp/allocate-static.f90 to libgomp.fortran/

2024-10-07 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:b95ad25f9c9376575dcde4bcb529d3ca31b27359

commit r15-4127-gb95ad25f9c9376575dcde4bcb529d3ca31b27359
Author: Tobias Burnus 
Date:   Mon Oct 7 23:57:42 2024 +0200

Move gfortran.dg/gomp/allocate-static.f90 to libgomp.fortran/

The testcase was turned into a 'dg-do run' check to check for the alignment,
but this only works in testsuite/gfortran.dg, causing link errors for
out-of-tree testing. The test was added in r15-4104-ga8caeaacf499d5.

gcc/testsuite/:

* gfortran.dg/gomp/allocate-static.f90: Move to libgomp/testsuite/.

libgomp/:

* testsuite/libgomp.fortran/allocate-static.f90: Moved from
gcc/testsuite/ as it is a dg-do run test; use real omp_lib_kinds
instead of local definition

Diff:
---
 .../testsuite/libgomp.fortran}/allocate-static.f90 | 28 --
 1 file changed, 28 deletions(-)

diff --git a/gcc/testsuite/gfortran.dg/gomp/allocate-static.f90 
b/libgomp/testsuite/libgomp.fortran/allocate-static.f90
similarity index 50%
rename from gcc/testsuite/gfortran.dg/gomp/allocate-static.f90
rename to libgomp/testsuite/libgomp.fortran/allocate-static.f90
index e43dae5793f0..2789e39e19bb 100644
--- a/gcc/testsuite/gfortran.dg/gomp/allocate-static.f90
+++ b/libgomp/testsuite/libgomp.fortran/allocate-static.f90
@@ -1,31 +1,3 @@
-! { dg-do run }
-
-module omp_lib_kinds
-  use iso_c_binding, only: c_int, c_intptr_t
-  implicit none
-  private :: c_int, c_intptr_t
-  integer, parameter :: omp_allocator_handle_kind = c_intptr_t
-
-  integer (kind=omp_allocator_handle_kind), &
- parameter :: omp_null_allocator = 0
-  integer (kind=omp_allocator_handle_kind), &
- parameter :: omp_default_mem_alloc = 1
-  integer (kind=omp_allocator_handle_kind), &
- parameter :: omp_large_cap_mem_alloc = 2
-  integer (kind=omp_allocator_handle_kind), &
- parameter :: omp_const_mem_alloc = 3
-  integer (kind=omp_allocator_handle_kind), &
- parameter :: omp_high_bw_mem_alloc = 4
-  integer (kind=omp_allocator_handle_kind), &
- parameter :: omp_low_lat_mem_alloc = 5
-  integer (kind=omp_allocator_handle_kind), &
- parameter :: omp_cgroup_mem_alloc = 6
-  integer (kind=omp_allocator_handle_kind), &
- parameter :: omp_pteam_mem_alloc = 7
-  integer (kind=omp_allocator_handle_kind), &
- parameter :: omp_thread_mem_alloc = 8
-end module
-
 module m
   use iso_c_binding, only: c_intptr_t
   use omp_lib_kinds, only: omp_default_mem_alloc


[gcc r15-4495] Fortran: Add range-based diagnostic

2024-10-19 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:ffdfc5b045d7364f76d1f41022b2286108898699

commit r15-4495-gffdfc5b045d7364f76d1f41022b2286108898699
Author: Tobias Burnus 
Date:   Sat Oct 19 10:18:30 2024 +0200

Fortran: Add range-based diagnostic

GCC's diagnostic engine gained a while ago support for ranges, i.e. instead
of pointing at a single character '^', it can also have a '^~' 
range.

This patch adds support for this and adds 9 users for it, which covers the
most common cases. A single '^' can be still useful. Some location data in
gfortran is rather bad - often the matching pattern includes whitespace such
that the before or after location points to the beginning/end of the
whitespace, which can be far of especially when comments and/or continuation
lines are involed. Otherwise, often a '^' still sufficient, albeit wrong
location data only becomes obvious once starting to use ranges.

The 'locus' is extended to support two ways to store the data; hereby
gfc_current_locus always contains the old format (at least during parsing)
and gfc_current_locus shall not be used in trans*.cc. The latter permits
a nice cleanup to just use input_location. Otherwise, the new format is
only used when switching to ranges.
The only reason to convert from location_t to locus occurs in trans*.cc
for the gfc_error (etc.) diagnostic and for gfc_trans_runtime_check; there
are 5 currently 5 such cases.  For gfc_* diagnostic, we could think of
another letter besides %L or a modifier like '%lL', if deemed useful.

In any case, the new format is just:
  locus->u.location = linemap_position_for_loc_and_offset (line_table,
 loc->u.lb->location, loc->nextc - loc->u.lb->line);
  locus->nextc = (gfc_char_t *) -1;  /* Marker for new format. */
i.e. using the existing location_t location in in the linebuffer (which
points to column 0) and add as offset the actually used column number.

As location_t handles ranges, we just use it also to store them via:
  location = make_location (caret, begin, end)
There are a few convenience macros/functions but that's all.

Alongside, a few minor fixes were done: linemap_location_before_p replaces
a line-number based comparison, which does not handle multiple statements
in the same line that ';' allows for.

gcc/fortran/ChangeLog:

* data.cc (gfc_assign_data_value): Use linemap_location_before_p
and GFC_LOCUS_IS_SET.
* decl.cc (gfc_verify_c_interop_param): Make better translatable.
(build_sym, variable_decl, gfc_match_formal_arglist,
gfc_match_subroutine): Add range-based locations, use it in
diagnostic and gobble whitespace for better locations.
* error.cc (gfc_get_location_with_offset): Handle new format.
(gfc_get_location_range): New.
* expr.cc (gfc_check_assign): Use GFC_LOCUS_IS_SET.
* frontend-passes.cc (check_locus_code, check_locus_expr):
Likewise.
(runtime_error_ne): Use GFC_LOCUS_IS_SET.
* gfortran.h (locus): Change lb to union with lb and location.
(GFC_LOCUS_IS_SET): Define.
(gfc_get_location_range): New prototype.
(gfc_new_symbol, gfc_get_symbol, gfc_get_sym_tree,
gfc_get_ha_symbol, gfc_get_ha_sym_tree): Take optional locus
argument.
* io.cc (io_constraint): Use GFC_LOCUS_IS_SET.
* match.cc (gfc_match_sym_tree): Use range locus.
* openmp.cc (gfc_match_omp_variable_list,
gfc_match_omp_doacross_sink): Likewise.
* parse.cc (next_free): Update for locus struct change.
* primary.cc (gfc_match_varspec): Likewise.
(match_variable): Use range locus.
* resolve.cc (find_array_spec): Use GFC_LOCUS_IS_SET.
* scanner.cc (gfc_at_eof, gfc_at_bol, gfc_start_source_files,
gfc_advance_line, gfc_define_undef_line, skip_fixed_comments,
gfc_gobble_whitespace, include_stmt, gfc_new_file): Update
for locus struct change.
* symbol.cc (gfc_new_symbol, gfc_get_sym_tree, gfc_get_symbol,
gfc_get_ha_sym_tree, gfc_get_ha_symbol): Take optional locus.
* trans-array.cc (gfc_trans_array_constructor_value): Use %L not %C.
(gfc_trans_g77_array, gfc_trans_dummy_array_bias,
gfc_trans_class_array, gfc_trans_deferred_array): Replace
gfc_{save,set,restore}_backend_locus by directly using
input_location.
* trans-common.cc (build_equiv_decl, get_init_field): Likewise.
* trans-decl.cc (gfc_get_extern_function_decl, build_function_decl,
build_entry_thunks, gfc_null_and_pass_deferred_len,
gfc_trans_deferred_vars, gfc_trans_use_stmts, finish_oacc_declare,
gfc_generate_bl

[gcc r15-4496] Fortran: Fix translatability of diagnostic strings

2024-10-19 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:efae253b9f863b066e899106d7f3ad9ef0cd3c58

commit r15-4496-gefae253b9f863b066e899106d7f3ad9ef0cd3c58
Author: Tobias Burnus 
Date:   Sat Oct 19 10:19:14 2024 +0200

Fortran: Fix translatability of diagnostic strings

gcc/fortran/ChangeLog:

* check.cc (is_c_interoperable): Use _(...) around to mark strings
as translatable.
* data.cc (gfc_assign_data_value): Move string literal to gfc_error
to make it translatable.
* resolve.cc (resolve_fl_variable, resolve_equivalence): Use G_(...)
around string literals.
* scanner.cc (skip_fixed_omp_sentinel): Replace '...' by %<...%>.
* trans-openmp.cc (gfc_split_omp_clauses,
gfc_trans_omp_declare_variant): Likewise.

Diff:
---
 gcc/fortran/check.cc| 20 ++--
 gcc/fortran/data.cc |  6 +++---
 gcc/fortran/resolve.cc  | 20 ++--
 gcc/fortran/scanner.cc  |  2 +-
 gcc/fortran/trans-openmp.cc |  4 ++--
 5 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/gcc/fortran/check.cc b/gcc/fortran/check.cc
index 79e6668d0afe..e90073ad4b04 100644
--- a/gcc/fortran/check.cc
+++ b/gcc/fortran/check.cc
@@ -5615,32 +5615,32 @@ is_c_interoperable (gfc_expr *expr, const char **msg, 
bool c_loc, bool c_f_ptr)
 
   if (expr->expr_type == EXPR_NULL && expr->ts.type == BT_UNKNOWN)
 {
-  *msg = "NULL() is not interoperable";
+  *msg = _("NULL() is not interoperable");
   return false;
 }
 
   if (expr->ts.type == BT_BOZ)
 {
-  *msg = "BOZ literal constant";
+  *msg = _("BOZ literal constant");
   return false;
 }
 
   if (expr->ts.type == BT_CLASS)
 {
-  *msg = "Expression is polymorphic";
+  *msg = _("Expression is polymorphic");
   return false;
 }
 
   if (expr->ts.type == BT_DERIVED && !expr->ts.u.derived->attr.is_bind_c
   && !expr->ts.u.derived->ts.is_iso_c)
 {
-  *msg = "Expression is a noninteroperable derived type";
+  *msg = _("Expression is a noninteroperable derived type");
   return false;
 }
 
   if (expr->ts.type == BT_PROCEDURE)
 {
-  *msg = "Procedure unexpected as argument";
+  *msg = _("Procedure unexpected as argument");
   return false;
 }
 
@@ -5650,14 +5650,14 @@ is_c_interoperable (gfc_expr *expr, const char **msg, 
bool c_loc, bool c_f_ptr)
   for (i = 0; gfc_logical_kinds[i].kind; i++)
 if (gfc_logical_kinds[i].kind == expr->ts.kind)
   return true;
-  *msg = "Extension to use a non-C_Bool-kind LOGICAL";
+  *msg = _("Extension to use a non-C_Bool-kind LOGICAL");
   return false;
 }
 
   if (gfc_notification_std (GFC_STD_GNU) && expr->ts.type == BT_CHARACTER
   && expr->ts.kind != 1)
 {
-  *msg = "Extension to use a non-C_CHAR-kind CHARACTER";
+  *msg = _("Extension to use a non-C_CHAR-kind CHARACTER");
   return false;
 }
 
@@ -5678,7 +5678,7 @@ is_c_interoperable (gfc_expr *expr, const char **msg, 
bool c_loc, bool c_f_ptr)
&& expr->ts.u.cl
&& !gfc_length_one_character_type_p (&expr->ts))
   {
-   *msg = "Type shall have a character length of 1";
+   *msg = _("Type shall have a character length of 1");
return false;
   }
 }
@@ -5689,7 +5689,7 @@ is_c_interoperable (gfc_expr *expr, const char **msg, 
bool c_loc, bool c_f_ptr)
 
   if (gfc_is_coarray (expr))
 {
-  *msg = "Coarrays are not interoperable";
+  *msg = _("Coarrays are not interoperable");
   return false;
 }
 
@@ -5700,7 +5700,7 @@ is_c_interoperable (gfc_expr *expr, const char **msg, 
bool c_loc, bool c_f_ptr)
   gfc_array_ref *ar = gfc_find_array_ref (expr);
   if (ar->type == AR_FULL && ar->as->type == AS_ASSUMED_SIZE)
{
- *msg = "Assumed-size arrays are not interoperable";
+ *msg = _("Assumed-size arrays are not interoperable");
  return false;
}
 }
diff --git a/gcc/fortran/data.cc b/gcc/fortran/data.cc
index c0974be88b22..e7202455b3ec 100644
--- a/gcc/fortran/data.cc
+++ b/gcc/fortran/data.cc
@@ -272,8 +272,6 @@ gfc_assign_data_value (gfc_expr *lvalue, gfc_expr *rvalue, 
mpz_t index,
   gfc_symbol *symbol;
   gfc_typespec *last_ts;
   mpz_t offset;
-  const char *msg = "F18(R841): data-implied-do object at %L is neither an "
-   "array-element nor a scalar-structure-component";
 
   symbol = lvalue->symtree->n.sym;
   init = symbol->value;
@@ -523,7 +521,9 @@ gfc_assign_data_value (gfc_expr *lvalue, gfc_expr *rvalue, 
mpz_t index,
 violates F18(R841). If the error is removed, the expected result
 is obtained. Leaving the code in place ensures a clean error
 recovery.  */
- gfc_error (msg, &lvalue->where);
+ gfc_error ("data-implied-do object at %L is neither an array-element "
+"nor a scalar-structure-component (F2018: R841)",
+ 

[gcc r15-4388] Add libgomp.oacc-fortran/acc_on_device-1-4.f

2024-10-16 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:ee4fdda70f1080bba5e49cadebc44333e19edeb4

commit r15-4388-gee4fdda70f1080bba5e49cadebc44333e19edeb4
Author: Tobias Burnus 
Date:   Wed Oct 16 16:15:40 2024 +0200

Add libgomp.oacc-fortran/acc_on_device-1-4.f

Kind of undoes r15-4315-g9f549d216c9716 by adding the original testcase 
back;
namely, adding acc_on_device-1-3.f as acc_on_device-1-4.f with
-fno-builtin-acc_on_device removed.

libgomp/ChangeLog:

* testsuite/libgomp.oacc-fortran/acc_on_device-1-4.f: New test;
same as acc_on_device-1-3.f but using the builtin function.

Diff:
---
 .../libgomp.oacc-fortran/acc_on_device-1-4.f   | 60 ++
 1 file changed, 60 insertions(+)

diff --git a/libgomp/testsuite/libgomp.oacc-fortran/acc_on_device-1-4.f 
b/libgomp/testsuite/libgomp.oacc-fortran/acc_on_device-1-4.f
new file mode 100644
index ..401d3a372b3b
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-fortran/acc_on_device-1-4.f
@@ -0,0 +1,60 @@
+! { dg-do run }
+! { dg-additional-options "-cpp" }
+
+! As acc_on_device-1-3.f, but using the acc_on_device builtin.
+
+! { dg-additional-options "-fopt-info-all-omp" }
+! { dg-additional-options "--param=openacc-privatization=noisy" }
+! { dg-additional-options "-foffload=-fopt-info-all-omp" }
+! { dg-additional-options "-foffload=--param=openacc-privatization=noisy" }
+! for testing/documenting aspects of that functionality.
+
+  IMPLICIT NONE
+  INCLUDE "openacc_lib.h"
+
+!Host.
+
+  IF (.NOT. ACC_ON_DEVICE (ACC_DEVICE_NONE)) STOP 1
+  IF (.NOT. ACC_ON_DEVICE (ACC_DEVICE_HOST)) STOP 2
+  IF (ACC_ON_DEVICE (ACC_DEVICE_NOT_HOST)) STOP 3
+  IF (ACC_ON_DEVICE (ACC_DEVICE_NVIDIA)) STOP 4
+  IF (ACC_ON_DEVICE (ACC_DEVICE_RADEON)) STOP 4
+
+
+!Host via offloading fallback mode.
+
+!$ACC PARALLEL IF(.FALSE.)
+! { dg-note {variable 'C\.[0-9]+' declared in block potentially has improper 
OpenACC privatization level: 'const_decl'} "TODO" { target *-*-* } .-1 }
+!TODO Unhandled 'CONST_DECL' instances for constant arguments in 
'acc_on_device' calls.
+  IF (.NOT. ACC_ON_DEVICE (ACC_DEVICE_NONE)) STOP 5
+  IF (.NOT. ACC_ON_DEVICE (ACC_DEVICE_HOST)) STOP 6
+  IF (ACC_ON_DEVICE (ACC_DEVICE_NOT_HOST)) STOP 7
+  IF (ACC_ON_DEVICE (ACC_DEVICE_NVIDIA)) STOP 8
+  IF (ACC_ON_DEVICE (ACC_DEVICE_RADEON)) STOP 8
+!$ACC END PARALLEL
+
+
+#if !ACC_DEVICE_TYPE_host
+
+! Offloaded.
+
+!$ACC PARALLEL
+! { dg-note {variable 'C\.[0-9]+' declared in block potentially has improper 
OpenACC privatization level: 'const_decl'} "TODO" { target { ! 
openacc_host_selected } } .-1 }
+  IF (ACC_ON_DEVICE (ACC_DEVICE_NONE)) STOP 9
+  IF (ACC_ON_DEVICE (ACC_DEVICE_HOST)) STOP 10
+  IF (.NOT. ACC_ON_DEVICE (ACC_DEVICE_NOT_HOST)) STOP 11
+#if ACC_DEVICE_TYPE_nvidia
+  IF (.NOT. ACC_ON_DEVICE (ACC_DEVICE_NVIDIA)) STOP 12
+#else
+  IF (ACC_ON_DEVICE (ACC_DEVICE_NVIDIA)) STOP 13
+#endif
+#if ACC_DEVICE_TYPE_radeon
+  IF (.NOT. ACC_ON_DEVICE (ACC_DEVICE_RADEON)) STOP 14
+#else
+  IF (ACC_ON_DEVICE (ACC_DEVICE_RADEON)) STOP 15
+#endif
+!$ACC END PARALLEL
+
+#endif
+
+  END


[gcc r15-4550] GCN: Initial generic-target handling, add more GCN macro defines

2024-10-22 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:1bdeebe69b71bf23c9bcd9965a736a5c1e0d5f83

commit r15-4550-g1bdeebe69b71bf23c9bcd9965a736a5c1e0d5f83
Author: Tobias Burnus 
Date:   Tue Oct 22 20:06:50 2024 +0200

GCN: Initial generic-target handling, add more GCN macro defines

Newer llvm-mc assemblers support the gfx*-generic targets, permitting to
generate code for all GPUs belonging to the same generation, even if not
optimal code. This requires LLVM 19.

This patch adds the compiler-side support for generic gfx and also
adds -march=gfx10-3-generic and -march=gfx-11. However, those -march= are
not documented nor used anywhere, yet.

Disclaimer: Not tested (as my ROCm does not support it); additionally,
libgomp/plugin/plugin-gcn.c has to be updated before it becomes useful.

For better compatibility with LLVM's Clang, this commit additionally adds
the macro definitions __GFX<9|10|11>__ for the architecture family,
__AMDGPU__ besides the existing __AMDGCN__ and the two strings-containing
macros __amdgcn_processor__ and __amdgcn_target_id__, where the former has
'-' replaced by '_' but otherwise both contain the lower case name. For the
new generic targets, the same happens, yielding, e.g., __gfx10_3_generic__.

gcc/ChangeLog:

* config/gcn/gcn-devices.def: Add generic version/flag as additional
value and architecture family entry; update; add gfx-10-3-generic
and gfx11-generic.
* config/gcn/gcn-hsa.h (ABI_VERSION_SPEC): Remove
(ASM_SPEC): Use generated ABI_VERSION_OPT instead.
* config/gcn/gcn-tables.opt: Regenerate
* config/gcn/gcn.h (gcn_device_def): Add generic_version and
arch_family members.
(TARGET_CPU_CPP_BUILTINS): Fix allocation bug, handle '-' in the
name and add additional macro defines.
* config/gcn/gcn.cc (gcn_devices): Handle it.
* config/gcn/gen-gcn-device-macros.awk: Likewise; use ELF name
for the macro name; generate ABI_VERSION_OPT.
* config/gcn/mkoffload.cc (ELFABIVERSION_AMDGPU_HSA_V6,
EF_AMDGPU_GENERIC_VERSION_V, EF_AMDGPU_GENERIC_VERSION_OFFSET,
GET_GENERIC_VERSION, SET_GENERIC_VERSION): Define.
(get_arch): Call SET_GENERIC_VERSION flag on elf_flags.
(copy_early_debug_info): If the arch sets the generic version,
use ELFABIVERSION_AMDGPU_HSA_V6.

Diff:
---
 gcc/config/gcn/gcn-devices.def   | 71 
 gcc/config/gcn/gcn-hsa.h |  9 +---
 gcc/config/gcn/gcn-tables.opt|  6 +++
 gcc/config/gcn/gcn.cc|  5 ++-
 gcc/config/gcn/gcn.h | 25 ++-
 gcc/config/gcn/gen-gcn-device-macros.awk | 39 +-
 gcc/config/gcn/mkoffload.cc  | 24 ++-
 7 files changed, 147 insertions(+), 32 deletions(-)

diff --git a/gcc/config/gcn/gcn-devices.def b/gcc/config/gcn/gcn-devices.def
index f2dbe18b6ae2..1305e0f8817f 100644
--- a/gcc/config/gcn/gcn-devices.def
+++ b/gcc/config/gcn/gcn-devices.def
@@ -62,18 +62,31 @@
purposes of calculating maximum occupancy.  Some devices have AVGPRs
in the same register file, some have more registers than are
addressable from a single kernel.  Used by libgomp's plugin-gcn.c.
+  9  "Generic Processor Version"  (unsigned, external)
+   Used as version field for generic processor support. For non-generic
+   code it is 0; otherwise, between 1 and 255. Initially, it is 1 for
+   each generic device, but incremented (for a given generic device) if
+   an new device of that series requires a code change;
+   cf. EF_AMDGPU_GENERIC_VERSION_V.  The version shall be the same as
+   generated by the used llvm-mc assembler.
+  10 "Architecture Family Name"  (string, external)
+   Used to #define '__GFX<...>__'.
 
 Fields marked "external", above, have values defined elsewhere (HSA, ROCM,
 LLVM, ELF, etc.) and must have matching definitions here.  Fields marked
 "internal" are defined and used only in GCC (although some may have
 user-visible effects) and may be refactored as needed.  */
 
+/* GCN GFX9 (Vega)  */
+
 GCN_DEVICE(gfx900, GFX900, 0x2c, ISA_GCN5,
   /* XNACK default */ HSACO_ATTR_OFF,
   /* SRAM_ECC default */ HSACO_ATTR_UNSUPPORTED,
   /* WAVE64 mode */ HSACO_ATTR_UNSUPPORTED,
   /* CU mode */ HSACO_ATTR_UNSUPPORTED,
-   /* Max ISA VGPRs */ 256
+  /* Max ISA VGPRs */ 256,
+  /* Generic code obj version */ 0,  /* non-generic */
+  /* Architecture Family */ GFX9
   )
 
 GCN_DEVICE(gfx906, GFX906, 0x2f, ISA_GCN5,
@@ -81,7 +94,9 @@ GCN_DEVICE(gfx906, GFX906, 0x2f, ISA_GCN5,
   /* SRAM_ECC default */ HSACO_ATTR_UNSUPPORTED,
   /* WAVE64 mode */ HSACO_ATTR_UNSUPPORTED,
   /* CU mode */ HSACO_ATT

[gcc r15-4565] Fortran: Minor follow-up cleanup to error.cc

2024-10-23 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:0ecc45a88d772268a3bd83af02759857da0826d4

commit r15-4565-g0ecc45a88d772268a3bd83af02759857da0826d4
Author: Tobias Burnus 
Date:   Wed Oct 23 12:25:00 2024 +0200

Fortran: Minor follow-up cleanup to error.cc

Follow up to r15-4268-g459c6018d2308d, which removed dead code,
but missing that terminal_width was only set but not used.

gcc/fortran/ChangeLog:

* error.cc (terminal_width, gfc_get_terminal_width): Remove.
(gfc_error_init_1): Do not call one to set the other.

Diff:
---
 gcc/fortran/error.cc | 12 
 1 file changed, 12 deletions(-)

diff --git a/gcc/fortran/error.cc b/gcc/fortran/error.cc
index 4e60b148a34c..b27cbede1645 100644
--- a/gcc/fortran/error.cc
+++ b/gcc/fortran/error.cc
@@ -39,8 +39,6 @@ static int suppress_errors = 0;
 
 static bool warnings_not_errors = false;
 
-static int terminal_width;
-
 /* True if the error/warnings should be buffered.  */
 static bool buffered_p;
 
@@ -141,21 +139,11 @@ gfc_query_suppress_errors (void)
 }
 
 
-/* Determine terminal width (for trimming source lines in output).  */
-
-static int
-gfc_get_terminal_width (void)
-{
-  return isatty (STDERR_FILENO) ? get_terminal_width () : INT_MAX;
-}
-
-
 /* Per-file error initialization.  */
 
 void
 gfc_error_init_1 (void)
 {
-  terminal_width = gfc_get_terminal_width ();
   gfc_buffer_error (false);
 }


[gcc r15-4285] Fortran: Unify gfc_get_location handling; fix expr->ts bug

2024-10-12 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:c20c9d8408f0ff4677acbd96f4803c191bd13ac6

commit r15-4285-gc20c9d8408f0ff4677acbd96f4803c191bd13ac6
Author: Tobias Burnus 
Date:   Sat Oct 12 10:48:41 2024 +0200

Fortran: Unify gfc_get_location handling; fix expr->ts bug

This commit reduces code duplication by moving gfc_get_location
from trans.cc to error.cc.  The gcc_assert is now used more often
and reveald a bug in gfc_match_array_constructor where the union
expr->ts.u.derived of a derived type is partially overwritten by
the assignment expr->ts.u.cl->... as a ts.type == BT_CHARACTER check
was missing.

gcc/fortran/ChangeLog:

* array.cc (gfc_match_array_constructor): Only update the
character length if the expression is of character type.
* error.cc (gfc_get_location_with_offset): New; split off
from ...
(gfc_format_decoder): ... here; call it.
* gfortran.h (gfc_get_location_with_offset): New prototype.
(gfc_get_location): New inline function.
* trans.cc (gfc_get_location): Remove function definition.
* trans.h (gfc_get_location): Remove declaration.

Diff:
---
 gcc/fortran/array.cc   |  2 +-
 gcc/fortran/error.cc   | 34 --
 gcc/fortran/gfortran.h |  7 +++
 gcc/fortran/trans.cc   | 12 
 gcc/fortran/trans.h|  4 
 5 files changed, 32 insertions(+), 27 deletions(-)

diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc
index ed8cb54803b8..773c5b72c851 100644
--- a/gcc/fortran/array.cc
+++ b/gcc/fortran/array.cc
@@ -1390,7 +1390,7 @@ done:
 expr = gfc_get_array_expr (BT_UNKNOWN, 0, &where);
 
   expr->value.constructor = head;
-  if (expr->ts.u.cl)
+  if (expr->ts.type == BT_CHARACTER && expr->ts.u.cl)
 expr->ts.u.cl->length_from_typespec = seen_ts;
 
   *result = expr;
diff --git a/gcc/fortran/error.cc b/gcc/fortran/error.cc
index e6c05aa149f4..d184ffd878ad 100644
--- a/gcc/fortran/error.cc
+++ b/gcc/fortran/error.cc
@@ -50,6 +50,21 @@ static gfc_error_buffer error_buffer;
 static output_buffer *pp_error_buffer, *pp_warning_buffer;
 static int warningcount_buffered, werrorcount_buffered;
 
+
+/* Return a location_t suitable for 'tree' for a gfortran locus.  During
+   parsing in gfortran, loc->lb->location contains only the line number
+   and LOCATION_COLUMN is 0; hence, the column has to be added when generating
+   locations for 'tree'.  */
+
+location_t
+gfc_get_location_with_offset (locus *loc, unsigned offset)
+{
+  gcc_checking_assert (loc->nextc >= loc->lb->line);
+  return linemap_position_for_loc_and_offset (line_table, loc->lb->location,
+ loc->nextc - loc->lb->line
+ + offset);
+}
+
 /* Return buffered_p.  */
 bool
 gfc_buffered_p (void)
@@ -411,6 +426,7 @@ gfc_format_decoder (pretty_printer *pp, text_info *text, 
const char *spec,
int precision, bool wide, bool set_locus, bool hash,
bool *quoted, pp_token_list &formatted_token_list)
 {
+  unsigned offset = 0;
   switch (*spec)
 {
 case 'C':
@@ -419,21 +435,19 @@ gfc_format_decoder (pretty_printer *pp, text_info *text, 
const char *spec,
static const char *result[2] = { "(1)", "(2)" };
locus *loc;
if (*spec == 'C')
- loc = &gfc_current_locus;
+ {
+   loc = &gfc_current_locus;
+   /* Point %C first offending character not the last good one. */
+   if (*loc->nextc != '\0')
+ offset++;
+ }
else
  loc = va_arg (*text->m_args_ptr, locus *);
-   gcc_assert (loc->nextc - loc->lb->line >= 0);
-   unsigned int offset = loc->nextc - loc->lb->line;
-   if (*spec == 'C' && *loc->nextc != '\0')
- /* Point %C first offending character not the last good one. */
- offset++;
+
/* If location[0] != UNKNOWN_LOCATION means that we already
   processed one of %C/%L.  */
int loc_num = text->get_location (0) == UNKNOWN_LOCATION ? 0 : 1;
-   location_t src_loc
- = linemap_position_for_loc_and_offset (line_table,
-loc->lb->location,
-offset);
+   location_t src_loc = gfc_get_location_with_offset (loc, offset);
text->set_location (loc_num, src_loc, SHOW_RANGE_WITH_CARET);
/* Colorize the markers to match the color choices of
   diagnostic_show_locus (the initial location has a color given
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 917866a7ef0c..e0ca7c114f77 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -3434,6 +3434,13 @@ const char * gfc_get_string (const char *, ...) 
ATTRIBUTE_PRINTF_1;
 bool gfc_find_sym_in_expr (gfc_symbol *, gfc_expr *);
 
 /* error.cc */
+location_t gfc_get_location_with_offset (locus *, unsigne

[gcc r15-4799] OpenMP/C++: Fix declare variant with reference-returning functions

2024-10-31 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:f011f8908182fd05ddd9a34881507b8584c44fb2

commit r15-4799-gf011f8908182fd05ddd9a34881507b8584c44fb2
Author: Tobias Burnus 
Date:   Thu Oct 31 11:28:57 2024 +0100

OpenMP/C++: Fix declare variant with reference-returning functions

gcc/cp/ChangeLog:

* decl.cc (omp_declare_variant_finalize_one): Strip indirect ref
around variant-function call when processing a variant.

gcc/testsuite/ChangeLog:

* g++.dg/gomp/declare-variant-9.C: New test.

Diff:
---
 gcc/cp/decl.cc|  3 +++
 gcc/testsuite/g++.dg/gomp/declare-variant-9.C | 29 +++
 2 files changed, 32 insertions(+)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 0bc320a2b396..b638f3af294d 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -8375,6 +8375,9 @@ omp_declare_variant_finalize_one (tree decl, tree attr)
   if (variant == error_mark_node && !processing_template_decl)
 return true;
 
+  if (TREE_CODE (variant) == INDIRECT_REF)
+variant = TREE_OPERAND (variant, 0);
+
   variant = cp_get_callee_fndecl_nofold (variant);
   input_location = save_loc;
 
diff --git a/gcc/testsuite/g++.dg/gomp/declare-variant-9.C 
b/gcc/testsuite/g++.dg/gomp/declare-variant-9.C
new file mode 100644
index ..7e26d8b11aee
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gomp/declare-variant-9.C
@@ -0,0 +1,29 @@
+/* { dg-additional-options "-fdump-tree-gimple" } */
+int &variant_fn();
+
+#pragma omp declare variant(variant_fn) match(user={condition(1)})
+int &bar();
+
+void sub(int &a)
+{
+  bar();
+  a = bar(); 
+}
+
+template
+T &templ_var_fn(T x);
+
+#pragma omp declare variant(templ_var_fn) match(user={condition(1)})
+template
+T &templ_base_fn(T x);
+
+void run(int &b)
+{
+  templ_base_fn(5);
+  b = templ_base_fn(7); 
+}
+
+/* { dg-final { scan-tree-dump "  variant_fn \\(\\);" "gimple" } } */
+/* { dg-final { scan-tree-dump "  _1 = variant_fn \\(\\);" "gimple" } } */
+/* { dg-final { scan-tree-dump "  templ_var_fn \\(5\\);" "gimple" } } */
+/* { dg-final { scan-tree-dump "  _1 = templ_var_fn \\(7\\);" "gimple" } 
} */


[gcc r15-4716] tree-core.h (omp_clause_code): Comments regarding range checks for OMP_CLAUSE_...

2024-10-28 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:6c45281a208652143c128541d80ce66da6d49868

commit r15-4716-g6c45281a208652143c128541d80ce66da6d49868
Author: Tobias Burnus 
Date:   Mon Oct 28 10:00:08 2024 +0100

tree-core.h (omp_clause_code): Comments regarding range checks for 
OMP_CLAUSE_...

gcc/ChangeLog:

* tree-core.h (enum omp_clause_code): Add comments to cross ref to
OMP_CLAUSE_DECL etc. and mark the ranges used in the range checks.

Diff:
---
 gcc/tree-core.h | 24 +++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-core.h b/gcc/tree-core.h
index e82f3a5f4f5b..2a91e7935ca1 100644
--- a/gcc/tree-core.h
+++ b/gcc/tree-core.h
@@ -241,12 +241,19 @@ enum tree_code_class {
 };
 
 /* OMP_CLAUSE codes.  Do not reorder, as this is used to index into
-   the tables omp_clause_num_ops and omp_clause_code_name.  */
+   the tables omp_clause_num_ops and omp_clause_code_name.
+
+   Note additionally that there are various range checks such as
+   for OMP_CLAUSE_SIZE or OMP_CLAUSE_DECL; clauses having those shall
+   be inside that range, those that have not shall be outside.  */
+
 enum omp_clause_code {
   /* Clause zero is special-cased inside the parser
  (c_parser_omp_variable_list).  */
   OMP_CLAUSE_ERROR = 0,
 
+  /* Range START below for: OMP_CLAUSE_DECL  */
+
   /* OpenACC/OpenMP clause: private (variable_list).  */
   OMP_CLAUSE_PRIVATE,
 
@@ -259,6 +266,9 @@ enum omp_clause_code {
   /* OpenMP clause: lastprivate (variable_list).  */
   OMP_CLAUSE_LASTPRIVATE,
 
+  /* Range START below for: OMP_CLAUSE_REDUCTION_CODE and
+ OMP_CLAUSE_REDUCTION_{INIT,MERGE,{DECL_,}PLACEHOLDER,OMP_ORIG_REF}  */
+
   /* OpenACC/OpenMP clause: reduction (operator:variable_list).
  OMP_CLAUSE_REDUCTION_CODE: The tree_code of the operator.
  Operand 1: OMP_CLAUSE_REDUCTION_INIT: Stmt-list to initialize the var.
@@ -277,6 +287,9 @@ enum omp_clause_code {
   /* OpenMP clause: in_reduction (operator:variable_list).  */
   OMP_CLAUSE_IN_REDUCTION,
 
+  /* Range END above for: OMP_CLAUSE_REDUCTION_CODE  and
+ OMP_CLAUSE_REDUCTION_{INIT,MERGE,{DECL_,}PLACEHOLDER,OMP_ORIG_REF}  */
+
   /* OpenMP clause: copyin (variable_list).  */
   OMP_CLAUSE_COPYIN,
 
@@ -330,12 +343,17 @@ enum omp_clause_code {
   /* OpenMP clause: exclusive (variable-list).  */
   OMP_CLAUSE_EXCLUSIVE,
 
+  /* Range START below for: OMP_CLAUSE_SIZE  */
+  /* Range START below for: OMP_CLAUSE_MOTION_PRESENT  */
+
   /* OpenMP clause: from (variable-list).  */
   OMP_CLAUSE_FROM,
 
   /* OpenMP clause: to (variable-list).  */
   OMP_CLAUSE_TO,
 
+  /* Range END above for: OMP_CLAUSE_MOTION_PRESENT  */
+
   /* OpenACC clauses: {copy, copyin, copyout, create, delete, deviceptr,
  device, host (self), present, present_or_copy (pcopy), present_or_copyin
  (pcopyin), present_or_copyout (pcopyout), present_or_create (pcreate)}
@@ -354,6 +372,8 @@ enum omp_clause_code {
  #pragma acc cache (variable-list).  */
   OMP_CLAUSE__CACHE_,
 
+  /* Range END above for: OMP_CLAUSE_SIZE */
+
   /* OpenACC clause: gang [(gang-argument-list)].
  Where
   gang-argument-list: [gang-argument-list, ] gang-argument
@@ -386,6 +406,8 @@ enum omp_clause_code {
   /* Internal clause: temporary for inscan reductions.  */
   OMP_CLAUSE__SCANTEMP_,
 
+  /* Range END above for: OMP_CLAUSE_DECL  */
+
   /* OpenACC/OpenMP clause: if (scalar-expression).  */
   OMP_CLAUSE_IF,


[gcc r15-5101] libgomp.c-c++-common/pr109062.c: Fix expected spin count for hybrid x86

2024-11-11 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:51147890383b89947c673ffd8d7c2cbd675261bd

commit r15-5101-g51147890383b89947c673ffd8d7c2cbd675261bd
Author: Tobias Burnus 
Date:   Mon Nov 11 17:22:20 2024 +0100

libgomp.c-c++-common/pr109062.c: Fix expected spin count for hybrid x86

On my system with E and P cores (hybrid) x86, the spincount is by default 1
and not 30, cf. PR109812 and r14-4571-ge1e127de18dbee.

Hence, this commit updates the expected value of the testcase to also
accept omp_display_env showing "GOMP_SPINCOUNT = '1'" - but only for
x86-64, which might be hybrid.

libgomp/ChangeLog:

* testsuite/libgomp.c-c++-common/pr109062.c: Update dg-output
to also accept GOMP_SPINCOUNT = 1 for x86-64.

Diff:
---
 libgomp/testsuite/libgomp.c-c++-common/pr109062.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libgomp/testsuite/libgomp.c-c++-common/pr109062.c 
b/libgomp/testsuite/libgomp.c-c++-common/pr109062.c
index 5c7c287dafd7..cb05c333e0e9 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/pr109062.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/pr109062.c
@@ -11,4 +11,8 @@ main ()
   return 0;
 }
 
-/* { dg-output ".*\\\[host] GOMP_SPINCOUNT = '30'.*" { target native } } */
+/* On hybrid x86-64, i.e. with P and E cores, the default is GOMP_SPINCOUNT=1;
+   hence, handle either value; see PR109812. */
+/* { dg-output ".*\\\[host] GOMP_SPINCOUNT = '(?:30|1)'.*" { target { 
native && { x86_64-*-* i?86-*-* } } } } */
+
+/* { dg-output ".*\\\[host] GOMP_SPINCOUNT = '30'.*" { target { native && 
{ ! { x86_64-*-* i?86-*-* } } } } } */


[gcc r15-5080] libgomp/plugin/plugin-gcn.c: Show device number in ISA error message

2024-11-11 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:8473010807a264af35fb7cecad6f9406feab929f

commit r15-5080-g8473010807a264af35fb7cecad6f9406feab929f
Author: Tobias Burnus 
Date:   Mon Nov 11 12:17:42 2024 +0100

libgomp/plugin/plugin-gcn.c: Show device number in ISA error message

libgomp/ChangeLog:

* plugin/plugin-gcn.c (isa_matches_agent): Mention the device number
and ROCR_VISIBLE_DEVICES when reporting an ISA mismatch error.

Diff:
---
 libgomp/plugin/plugin-gcn.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c
index 592a7b6daba4..f2f2940de9db 100644
--- a/libgomp/plugin/plugin-gcn.c
+++ b/libgomp/plugin/plugin-gcn.c
@@ -2414,14 +2414,17 @@ isa_matches_agent (struct agent_info *agent, Elf64_Ehdr 
*image)
 
   if (isa_field != agent->device_isa)
 {
-  char msg[120];
+  char msg[204];
   const char *agent_isa_s = isa_name (agent->device_isa);
   assert (agent_isa_s);
 
   snprintf (msg, sizeof msg,
-   "GCN code object ISA '%s' does not match GPU ISA '%s'.\n"
-   "Try to recompile with '-foffload-options=-march=%s'.\n",
-   isa_s, agent_isa_s, agent_isa_s);
+   "GCN code object ISA '%s' does not match GPU ISA '%s' "
+   "(device %d).\n"
+   "Try to recompile with '-foffload-options=-march=%s',\n"
+   "or use ROCR_VISIBLE_DEVICES to disable incompatible "
+   "devices.\n",
+   isa_s, agent_isa_s, agent->device_id, agent_isa_s);
 
   hsa_error (msg, HSA_STATUS_ERROR);
   return false;


[gcc r15-4801] OpenMP/C++: Use STRIP_REFERENCE_REF to fix declare variant with reference-returning functions

2024-10-31 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:f7ae087ef0132b01c3a2c04932058b996ebda18d

commit r15-4801-gf7ae087ef0132b01c3a2c04932058b996ebda18d
Author: Tobias Burnus 
Date:   Thu Oct 31 12:37:46 2024 +0100

OpenMP/C++: Use STRIP_REFERENCE_REF to fix declare variant with 
reference-returning functions

As Jakub suggested, use STRIP_REFERENCE_REF instead of doing it manually
as r15-4800-geb828a1e380e7b did.

gcc/cp/ChangeLog:

* decl.cc (omp_declare_variant_finalize_one): Use 
STRIP_REFERENCE_REF
instead of doing it manually.

Diff:
---
 gcc/cp/decl.cc | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index b638f3af294d..0e4533c6faba 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -8375,10 +8375,7 @@ omp_declare_variant_finalize_one (tree decl, tree attr)
   if (variant == error_mark_node && !processing_template_decl)
 return true;
 
-  if (TREE_CODE (variant) == INDIRECT_REF)
-variant = TREE_OPERAND (variant, 0);
-
-  variant = cp_get_callee_fndecl_nofold (variant);
+  variant = cp_get_callee_fndecl_nofold (STRIP_REFERENCE_REF (variant));
   input_location = save_loc;
 
   if (variant)


[gcc r15-3790] gcn/mkoffload.cc: Re-add fprintf for #include of stdlib.h/stdbool.h

2024-09-23 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:dfb750798b07e7f412d52c22145ca8bce1911ac8

commit r15-3790-gdfb750798b07e7f412d52c22145ca8bce1911ac8
Author: Tobias Burnus 
Date:   Mon Sep 23 10:24:05 2024 +0200

gcn/mkoffload.cc: Re-add fprintf for #include of stdlib.h/stdbool.h

In commit r15-3629-g508ef585243d4674d06b0737bfe8769fc18f824f, #embed
was added and no longer required fprintf '#include' removed, missing
somehow that with -mstack-size=, the generated configure_stack_size
will use 'setenv' and 'true'.

gcc/ChangeLog:

* config/gcn/mkoffload.cc (process_asm): (Re)add the fprintf
lines for stdlib.h/stdbool.h inclusion if gcn_stack_size is used.

Diff:
---
 gcc/config/gcn/mkoffload.cc | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc
index 1f6337719e9d..1a524ced6535 100644
--- a/gcc/config/gcn/mkoffload.cc
+++ b/gcc/config/gcn/mkoffload.cc
@@ -613,6 +613,12 @@ process_asm (FILE *in, FILE *out, FILE *cfile)
   struct oaccdims *dims = XOBFINISH (&dims_os, struct oaccdims *);
   struct regcount *regcounts = XOBFINISH (®counts_os, struct regcount *);
 
+  if (gcn_stack_size)
+{
+  fprintf (cfile, "#include \n");
+  fprintf (cfile, "#include \n\n");
+}
+
   fprintf (cfile, "static const int gcn_num_vars = %d;\n\n", var_count);
   fprintf (cfile, "static const int gcn_num_ind_funcs = %d;\n\n", 
ind_fn_count);


[gcc r15-3799] OpenMP: Fix omp_get_device_from_uid, minor cleanup

2024-09-23 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:cdb9aa0f623ec7899da445a47f4a502b2987dc7b

commit r15-3799-gcdb9aa0f623ec7899da445a47f4a502b2987dc7b
Author: Tobias Burnus 
Date:   Mon Sep 23 15:58:39 2024 +0200

OpenMP: Fix omp_get_device_from_uid, minor cleanup

In Fortran, omp_get_device_from_uid can also accept substrings, which are
then not NUL terminated.  Fixed by introducing a fortran.c wrapper function.
Additionally, in case of a fail the plugin functions now return NULL instead
of failing fatally such that a fall-back UID is generated.

gcc/ChangeLog:

* omp-general.cc (omp_runtime_api_procname): Strip "omp_" from
string; move get_device_from_uid as now a '_' suffix exists.

libgomp/ChangeLog:

* fortran.c (omp_get_device_from_uid_): New function.
* libgomp.map (GOMP_6.0): Add it.
* oacc-host.c (host_dispatch): Init '.uid' and '.get_uid_func'.
* omp_lib.f90.in: Make it used by removing bind(C).
* omp_lib.h.in: Likewise.
* target.c (omp_get_device_from_uid): Ensure the device is 
initialized.
* plugin/plugin-gcn.c (GOMP_OFFLOAD_get_uid): Add function comment;
return NULL in case of an error.
* plugin/plugin-nvptx.c (GOMP_OFFLOAD_get_uid): Likewise.
* testsuite/libgomp.fortran/device_uid.f90: Update to test 
substrings.

Diff:
---
 gcc/omp-general.cc   |  4 ++--
 libgomp/fortran.c| 18 ++
 libgomp/libgomp.map  |  1 +
 libgomp/oacc-host.c  |  2 ++
 libgomp/omp_lib.f90.in   |  5 ++---
 libgomp/omp_lib.h.in |  5 ++---
 libgomp/plugin/plugin-gcn.c  |  8 +++-
 libgomp/plugin/plugin-nvptx.c|  7 +--
 libgomp/target.c |  7 +--
 libgomp/testsuite/libgomp.fortran/device_uid.f90 | 18 --
 10 files changed, 60 insertions(+), 15 deletions(-)

diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc
index 12788ad02490..3dfbc315056f 100644
--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -3260,7 +3260,6 @@ omp_runtime_api_procname (const char *name)
   "alloc",
   "calloc",
   "free",
-  "get_device_from_uid",
   "get_interop_int",
   "get_interop_ptr",
   "get_mapped_ptr",
@@ -3290,6 +3289,7 @@ omp_runtime_api_procname (const char *name)
   "get_cancellation",
   "get_default_allocator",
   "get_default_device",
+  "get_device_from_uid",
   "get_device_num",
   "get_dynamic",
   "get_initial_device",
@@ -3339,7 +3339,7 @@ omp_runtime_api_procname (const char *name)
 as DECL_NAME only omp_* and omp_*_8 appear.  */
   "display_env",
   "get_ancestor_thread_num",
-  "omp_get_uid_from_device",
+  "get_uid_from_device",
   "get_partition_place_nums",
   "get_place_num_procs",
   "get_place_proc_ids",
diff --git a/libgomp/fortran.c b/libgomp/fortran.c
index 9b7f093555b0..7976e5b9638d 100644
--- a/libgomp/fortran.c
+++ b/libgomp/fortran.c
@@ -834,6 +834,24 @@ omp_get_interop_rc_desc_ (const char **res, size_t 
*res_len,
   *res_len = *res ? strlen (*res) : 0;
 }
 
+int
+omp_get_device_from_uid_ (const char *uid, size_t uid_len)
+{
+#ifndef LIBGOMP_OFFLOADED_ONLY
+  char *str = __builtin_alloca ((uid_len + 1) * sizeof (char));
+  memcpy (str, uid, uid_len * sizeof (char));
+  str[uid_len] = '\0';
+  return omp_get_device_from_uid (str);
+#else
+  /* Inside the target region, invoking this routine is undefined
+ behavior; thus, resolve it already here - instead of inside
+ libgomp/config/.../target.c.
+ Note that on nvptx __builtin_alloca is defined, but fails with a sorry
+ during compilation, as it is unsupported until isa 7.3 / sm_52.  */
+  return omp_invalid_device;
+#endif
+}
+
 void
 omp_get_uid_from_device_ (const char **res, size_t *res_len,
  int32_t device_num)
diff --git a/libgomp/libgomp.map b/libgomp/libgomp.map
index 0023d3e1b6de..4530b3adc94e 100644
--- a/libgomp/libgomp.map
+++ b/libgomp/libgomp.map
@@ -446,6 +446,7 @@ GOMP_5.1.3 {
 GOMP_6.0 {
   global:
omp_get_device_from_uid;
+   omp_get_device_from_uid_;
omp_get_uid_from_device;
omp_get_uid_from_device_;
omp_get_uid_from_device_8_;
diff --git a/libgomp/oacc-host.c b/libgomp/oacc-host.c
index 5efdf7fb7968..7d4362ebd6ce 100644
--- a/libgomp/oacc-host.c
+++ b/libgomp/oacc-host.c
@@ -263,6 +263,7 @@ host_openacc_destroy_thread_data (void *tls_data 
__attribute__ ((unused)))
 static struct gomp_device_descr host_dispatch =
   {
 .name = "host",
+.uid = NULL,
 .capabilities = (GOMP_OFFLOAD_CAP_SHARED_MEM
 | GOMP_OFFLOAD_CAP_NATIVE_EXEC
 | GOMP_OFFLOAD_CAP_OPENACC_200),
@@ -270,6 +271,7 @@ static struct 

[gcc r15-3822] OpenMP: Add support for 'self_maps' to the 'require' directive

2024-09-24 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:b752eed3e3f2f27570ea89b7c2339468698472a8

commit r15-3822-gb752eed3e3f2f27570ea89b7c2339468698472a8
Author: Tobias Burnus 
Date:   Tue Sep 24 10:53:59 2024 +0200

OpenMP: Add support for 'self_maps' to the 'require' directive

'self_maps' implies 'unified_shared_memory', except that the latter
also permits that explicit maps copy data to device memory while
self_maps does not. In GCC, currently, both are handled identical.

gcc/c/ChangeLog:

* c-parser.cc (c_parser_omp_requires): Handle self_maps clause.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_omp_requires): Handle self_maps clause.

gcc/fortran/ChangeLog:

* gfortran.h (enum gfc_omp_requires_kind): Add OMP_REQ_SELF_MAPS.
(gfc_namespace): Enlarge omp_requires bitfield.
* module.cc (enum ab_attribute, attr_bits): Add 
AB_OMP_REQ_SELF_MAPS.
(mio_symbol_attribute): Handle it.
* openmp.cc (gfc_check_omp_requires, gfc_match_omp_requires): Handle
self_maps clause.
* parse.cc (gfc_parse_file): Handle self_maps clause.

gcc/ChangeLog:

* lto-cgraph.cc (output_offload_tables, omp_requires_to_name): 
Handle
self_maps clause.
* omp-general.cc (struct omp_ts_info, omp_context_selector_matches):
Likewise for the associated trait.
* omp-general.h (enum omp_requires): Add OMP_REQUIRES_SELF_MAPS.
* omp-selectors.h (enum omp_ts_code): Add
OMP_TRAIT_IMPLEMENTATION_SELF_MAPS.

include/ChangeLog:

* gomp-constants.h (GOMP_REQUIRES_SELF_MAPS): #define.

libgomp/ChangeLog:

* plugin/plugin-gcn.c (GOMP_OFFLOAD_get_num_devices):
Accept self_maps clause.
* plugin/plugin-nvptx.c (GOMP_OFFLOAD_get_num_devices):
Likewise.
* libgomp.texi (TR13 Impl. Status): Set to 'Y'.
* target.c (gomp_requires_to_name, GOMP_offload_register_ver,
gomp_target_init): Handle self_maps clause.
* testsuite/libgomp.fortran/self_maps.f90: New test.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/declare-variant-1.c: Add self_maps test.
* c-c++-common/gomp/requires-4.c: Likewise.
* gfortran.dg/gomp/declare-variant-3.f90:  Likewise.
* c-c++-common/gomp/requires-2.c: Update dg-error msg.
* gfortran.dg/gomp/requires-2.f90: Likewise.
* gfortran.dg/gomp/requires-self-maps-aux.f90: New.
* gfortran.dg/gomp/requires-self-maps.f90: New.

Diff:
---
 gcc/c/c-parser.cc  |  3 ++
 gcc/cp/parser.cc   |  3 ++
 gcc/fortran/gfortran.h | 10 +++--
 gcc/fortran/module.cc  | 11 -
 gcc/fortran/openmp.cc  | 30 -
 gcc/fortran/parse.cc   |  3 ++
 gcc/lto-cgraph.cc  |  4 ++
 gcc/omp-general.cc | 21 ++
 gcc/omp-general.h  |  1 +
 gcc/omp-selectors.h|  1 +
 .../c-c++-common/gomp/declare-variant-1.c  |  6 +++
 gcc/testsuite/c-c++-common/gomp/requires-2.c   |  2 +-
 gcc/testsuite/c-c++-common/gomp/requires-4.c   |  1 +
 .../gfortran.dg/gomp/declare-variant-3.f90 |  3 ++
 gcc/testsuite/gfortran.dg/gomp/requires-2.f90  |  2 +-
 .../gfortran.dg/gomp/requires-self-maps-aux.f90| 18 
 .../gfortran.dg/gomp/requires-self-maps.f90| 17 
 include/gomp-constants.h   |  4 ++
 libgomp/libgomp.texi   |  2 +-
 libgomp/plugin/plugin-gcn.c|  4 +-
 libgomp/plugin/plugin-nvptx.c  |  4 +-
 libgomp/target.c   | 10 +++--
 libgomp/testsuite/libgomp.fortran/self_maps.f90| 49 ++
 23 files changed, 185 insertions(+), 24 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index aff5af174303..6a46577f5119 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -26208,6 +26208,8 @@ c_parser_omp_requires (c_parser *parser)
this_req = OMP_REQUIRES_UNIFIED_ADDRESS;
  else if (!strcmp (p, "unified_shared_memory"))
this_req = OMP_REQUIRES_UNIFIED_SHARED_MEMORY;
+ else if (!strcmp (p, "self_maps"))
+   this_req = OMP_REQUIRES_SELF_MAPS;
  else if (!strcmp (p, "dynamic_allocators"))
this_req = OMP_REQUIRES_DYNAMIC_ALLOCATORS;
  else if (!strcmp (p, "reverse_offload"))
@@ -26274,6 +26276,7 @@ c_parser_omp_requires (c_parser *parser)
{
  error_at (cloc, "expected %, "
  "%, "
+ "%,

[gcc r15-3836] libgomp: with USM, init 'link' variables with host address

2024-09-24 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:4cb20dc043cf70b8a1b4846c86599cc1ff9680d9

commit r15-3836-g4cb20dc043cf70b8a1b4846c86599cc1ff9680d9
Author: Tobias Burnus 
Date:   Tue Sep 24 17:41:39 2024 +0200

libgomp: with USM, init 'link' variables with host address

If requires unified_shared_memory or self_maps is set, make
'declare target link' variables to point initially to the host pointer.

libgomp/ChangeLog:

* target.c (gomp_load_image_to_device): For requires
unified_shared_memory, update 'link' vars to point to the host var.
* testsuite/libgomp.c-c++-common/target-link-3.c: New test.
* testsuite/libgomp.c-c++-common/target-link-4.c: New test.

Diff:
---
 libgomp/target.c   |  6 +++
 .../testsuite/libgomp.c-c++-common/target-link-3.c | 52 ++
 .../testsuite/libgomp.c-c++-common/target-link-4.c | 52 ++
 3 files changed, 110 insertions(+)

diff --git a/libgomp/target.c b/libgomp/target.c
index 6918694a843b..cf62af61f3b6 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -2454,6 +2454,12 @@ gomp_load_image_to_device (struct gomp_device_descr 
*devicep, unsigned version,
   array->right = NULL;
   splay_tree_insert (&devicep->mem_map, array);
   array++;
+
+  if (is_link_var
+ && (omp_requires_mask
+ & (GOMP_REQUIRES_UNIFIED_SHARED_MEMORY | 
GOMP_REQUIRES_SELF_MAPS)))
+   gomp_copy_host2dev (devicep, NULL, (void *) target_var->start,
+   &k->host_start, sizeof (void *), false, NULL);
 }
 
   /* Last entry is for the ICV struct variable; if absent, start = end = 0.  */
diff --git a/libgomp/testsuite/libgomp.c-c++-common/target-link-3.c 
b/libgomp/testsuite/libgomp.c-c++-common/target-link-3.c
new file mode 100644
index ..c707b38b7d46
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c-c++-common/target-link-3.c
@@ -0,0 +1,52 @@
+/* { dg-do run }  */
+
+#include 
+#include 
+
+#pragma omp requires unified_shared_memory
+
+int A[3] = {-3,-4,-5};
+static int q = -401;
+#pragma omp declare target link(A, q)
+
+#pragma omp begin declare target
+void
+f (uintptr_t *pA, uintptr_t *pq)
+{
+  if (A[0] != 1 || A[1] != 2 || A[2] != 3 || q != 42)
+__builtin_abort ();
+  A[0] = 13;
+  A[1] = 14;
+  A[2] = 15;
+  q = 23;
+  *pA = (uintptr_t) &A[0];
+  *pq = (uintptr_t) &q;
+}
+#pragma omp end declare target
+
+int
+main ()
+{
+  uintptr_t hpA = (uintptr_t) &A[0];
+  uintptr_t hpq = (uintptr_t) &q;
+  uintptr_t dpA, dpq;
+
+  A[0] = 1;
+  A[1] = 2;
+  A[2] = 3;
+  q = 42;
+
+  for (int i = 0; i <= omp_get_num_devices (); ++i)
+{
+  #pragma omp target device(device_num: i) map(dpA, dpq)
+   f (&dpA, &dpq);
+  if (hpA != dpA || hpq != dpq)
+   __builtin_abort ();
+  if (A[0] != 13 || A[1] != 14 || A[2] != 15 || q != 23)
+   __builtin_abort ();
+  A[0] = 1;
+  A[1] = 2;
+  A[2] = 3;
+  q = 42;
+}
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/target-link-4.c 
b/libgomp/testsuite/libgomp.c-c++-common/target-link-4.c
new file mode 100644
index ..785055e216d7
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c-c++-common/target-link-4.c
@@ -0,0 +1,52 @@
+/* { dg-do run }  */
+
+#include 
+#include 
+
+#pragma omp requires self_maps
+
+int A[3] = {-3,-4,-5};
+static int q = -401;
+#pragma omp declare target link(A, q)
+
+#pragma omp begin declare target
+void
+f (uintptr_t *pA, uintptr_t *pq)
+{
+  if (A[0] != 1 || A[1] != 2 || A[2] != 3 || q != 42)
+__builtin_abort ();
+  A[0] = 13;
+  A[1] = 14;
+  A[2] = 15;
+  q = 23;
+  *pA = (uintptr_t) &A[0];
+  *pq = (uintptr_t) &q;
+}
+#pragma omp end declare target
+
+int
+main ()
+{
+  uintptr_t hpA = (uintptr_t) &A[0];
+  uintptr_t hpq = (uintptr_t) &q;
+  uintptr_t dpA, dpq;
+
+  A[0] = 1;
+  A[1] = 2;
+  A[2] = 3;
+  q = 42;
+
+  for (int i = 0; i <= omp_get_num_devices (); ++i)
+{
+  #pragma omp target device(device_num: i) map(dpA, dpq)
+   f (&dpA, &dpq);
+  if (hpA != dpA || hpq != dpq)
+   __builtin_abort ();
+  if (A[0] != 13 || A[1] != 14 || A[2] != 15 || q != 23)
+   __builtin_abort ();
+  A[0] = 1;
+  A[1] = 2;
+  A[2] = 3;
+  q = 42;
+}
+}


[gcc r15-3895] Fortran/OpenMP: Middle-end support for mapping of DT with allocatable components

2024-09-26 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:e4a58b6f28383cb40e4fa287cc7dad43bafb85b2

commit r15-3895-ge4a58b6f28383cb40e4fa287cc7dad43bafb85b2
Author: Tobias Burnus 
Date:   Thu Sep 26 14:01:20 2024 +0200

Fortran/OpenMP: Middle-end support for mapping of DT with allocatable 
components

gcc/ChangeLog:

* langhooks-def.h (lhd_omp_deep_mapping_p,
lhd_omp_deep_mapping_cnt, lhd_omp_deep_mapping): New.
(LANG_HOOKS_OMP_DEEP_MAPPING_P, LANG_HOOKS_OMP_DEEP_MAPPING_CNT,
LANG_HOOKS_OMP_DEEP_MAPPING): Define.
(LANG_HOOKS_DECLS): Use it.
* langhooks.cc (lhd_omp_deep_mapping_p, lhd_omp_deep_mapping_cnt,
lhd_omp_deep_mapping): New stubs.
* langhooks.h (struct lang_hooks_for_decls): Add new hooks
* omp-expand.cc (expand_omp_target): Handle dynamic-size
addr/sizes/kinds arrays.
* omp-low.cc (build_sender_ref, fixup_child_record_type,
scan_sharing_clauses, lower_omp_target): Update to handle
new hooks and dynamic-size addr/sizes/kinds arrays.

Diff:
---
 gcc/langhooks-def.h |  10 +++
 gcc/langhooks.cc|  24 ++
 gcc/langhooks.h |  15 
 gcc/omp-expand.cc   |  18 -
 gcc/omp-low.cc  | 224 ++--
 5 files changed, 265 insertions(+), 26 deletions(-)

diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
index 179ed393fd29..f207ff96f0df 100644
--- a/gcc/langhooks-def.h
+++ b/gcc/langhooks-def.h
@@ -86,6 +86,10 @@ extern enum omp_clause_defaultmap_kind 
lhd_omp_predetermined_mapping (tree);
 extern tree lhd_omp_assignment (tree, tree, tree);
 extern void lhd_omp_finish_clause (tree, gimple_seq *, bool);
 extern tree lhd_omp_array_size (tree, gimple_seq *);
+extern bool lhd_omp_deep_mapping_p (const gimple *, tree);
+extern tree lhd_omp_deep_mapping_cnt (const gimple *, tree, gimple_seq *);
+extern void lhd_omp_deep_mapping (const gimple *, tree, unsigned HOST_WIDE_INT,
+ tree, tree, tree, tree, tree, gimple_seq *);
 struct gimplify_omp_ctx;
 extern void lhd_omp_firstprivatize_type_sizes (struct gimplify_omp_ctx *,
   tree);
@@ -272,6 +276,9 @@ extern tree lhd_unit_size_without_reusable_padding (tree);
 #define LANG_HOOKS_OMP_CLAUSE_LINEAR_CTOR NULL
 #define LANG_HOOKS_OMP_CLAUSE_DTOR hook_tree_tree_tree_null
 #define LANG_HOOKS_OMP_FINISH_CLAUSE lhd_omp_finish_clause
+#define LANG_HOOKS_OMP_DEEP_MAPPING_P lhd_omp_deep_mapping_p
+#define LANG_HOOKS_OMP_DEEP_MAPPING_CNT lhd_omp_deep_mapping_cnt
+#define LANG_HOOKS_OMP_DEEP_MAPPING lhd_omp_deep_mapping
 #define LANG_HOOKS_OMP_ALLOCATABLE_P hook_bool_tree_false
 #define LANG_HOOKS_OMP_SCALAR_P lhd_omp_scalar_p
 #define LANG_HOOKS_OMP_SCALAR_TARGET_P hook_bool_tree_false
@@ -306,6 +313,9 @@ extern tree lhd_unit_size_without_reusable_padding (tree);
   LANG_HOOKS_OMP_CLAUSE_LINEAR_CTOR, \
   LANG_HOOKS_OMP_CLAUSE_DTOR, \
   LANG_HOOKS_OMP_FINISH_CLAUSE, \
+  LANG_HOOKS_OMP_DEEP_MAPPING_P, \
+  LANG_HOOKS_OMP_DEEP_MAPPING_CNT, \
+  LANG_HOOKS_OMP_DEEP_MAPPING, \
   LANG_HOOKS_OMP_ALLOCATABLE_P, \
   LANG_HOOKS_OMP_SCALAR_P, \
   LANG_HOOKS_OMP_SCALAR_TARGET_P, \
diff --git a/gcc/langhooks.cc b/gcc/langhooks.cc
index b28c01deed21..54fc94e4364e 100644
--- a/gcc/langhooks.cc
+++ b/gcc/langhooks.cc
@@ -645,6 +645,30 @@ lhd_omp_array_size (tree, gimple_seq *)
   return NULL_TREE;
 }
 
+/* Returns true when additional mappings for a decl are needed.  */
+
+bool
+lhd_omp_deep_mapping_p (const gimple *, tree)
+{
+  return false;
+}
+
+/* Returns number of additional mappings for a decl.  */
+
+tree
+lhd_omp_deep_mapping_cnt (const gimple *, tree, gimple_seq *)
+{
+  return NULL_TREE;
+}
+
+/* Do the additional mappings.  */
+
+void
+lhd_omp_deep_mapping (const gimple *, tree, unsigned HOST_WIDE_INT, tree, tree,
+ tree, tree, tree, gimple_seq *)
+{
+}
+
 /* Return true if DECL is a scalar variable (for the purpose of
implicit firstprivatization & mapping). Only if alloc_ptr_ok
are allocatables and pointers accepted. */
diff --git a/gcc/langhooks.h b/gcc/langhooks.h
index cd944673cd62..87c3c58a6b34 100644
--- a/gcc/langhooks.h
+++ b/gcc/langhooks.h
@@ -313,6 +313,21 @@ struct lang_hooks_for_decls
   /* Do language specific checking on an implicitly determined clause.  */
   void (*omp_finish_clause) (tree clause, gimple_seq *pre_p, bool);
 
+  /* Additional language-specific mappings for a decl; returns true
+ if those may occur.  */
+  bool (*omp_deep_mapping_p) (const gimple *ctx_stmt, tree clause);
+
+  /* Additional language-specific mappings for a decl; returns the
+ number of additional mappings needed.  */
+  tree (*omp_deep_mapping_cnt) (const gimple *ctx_stmt, tree clause,
+   gimple_seq *seq);
+
+  /* Do the actual additional language-specific mappings for a decl. */
+  void (*omp_deep_mapping) (const gimple *stmt, tree clause,
+   

[gcc r15-3900] libgomp.texi: Fix deprecation note for omp_{get, set}_nested + OMP_NESTED

2024-09-26 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:9ec258bf65e6ae856491f607a987fe15b5385866

commit r15-3900-g9ec258bf65e6ae856491f607a987fe15b5385866
Author: Tobias Burnus 
Date:   Thu Sep 26 17:25:34 2024 +0200

libgomp.texi: Fix deprecation note for omp_{get,set}_nested + OMP_NESTED

libgomp/ChangeLog:

* libgomp.texi (omp_get_nested,omp_set_nested, OMP_NESTED): Fix
note about deprecation - correct is 5.0 not 5.2.

Diff:
---
 libgomp/libgomp.texi | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 29f5419cd0f1..22eff1d7b557 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -937,7 +937,7 @@ active nested regions to the maximum supported.  Disabling 
nested parallel
 regions sets the maximum number of active nested regions to one.
 
 Note that the @code{omp_set_nested} API routine was deprecated
-in the OpenMP specification 5.2 in favor of @code{omp_set_max_active_levels}.
+in the OpenMP specification 5.0 in favor of @code{omp_set_max_active_levels}.
 
 @item @emph{C/C++}:
 @multitable @columnfractions .20 .80
@@ -984,7 +984,7 @@ regions with @code{omp_set_max_active_levels} to one to 
disable, or
 above one to enable.
 
 Note that the @code{omp_get_nested} API routine was deprecated
-in the OpenMP specification 5.2 in favor of @code{omp_get_max_active_levels}.
+in the OpenMP specification 5.0 in favor of @code{omp_get_max_active_levels}.
 
 @item @emph{C/C++}:
 @multitable @columnfractions .20 .80
@@ -3934,7 +3934,7 @@ setting.  If both are undefined, nested parallel regions 
are enabled if
 more than one item, otherwise they are disabled by default.
 
 Note that the @code{OMP_NESTED} environment variable was deprecated in
-the OpenMP specification 5.2 in favor of @code{OMP_MAX_ACTIVE_LEVELS}.
+the OpenMP specification 5.0 in favor of @code{OMP_MAX_ACTIVE_LEVELS}.
 
 @item @emph{See also}:
 @ref{omp_set_max_active_levels}, @ref{omp_set_nested},


[gcc r15-3917] libgomp.texi: fix formatting; add post-TR13 OpenMP impl. status items

2024-09-27 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:6b7eaec20b046eebc771022e460c2206580aef04

commit r15-3917-g6b7eaec20b046eebc771022e460c2206580aef04
Author: Tobias Burnus 
Date:   Fri Sep 27 10:48:09 2024 +0200

libgomp.texi: fix formatting; add post-TR13 OpenMP impl. status items

libgomp/
* libgomp.texi (OpenMP Technical Report 13): Change @emph to @code;
add two post-TR13 OpenMP 6.0 items.

Diff:
---
 libgomp/libgomp.texi | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 22eff1d7b557..b561cb5f3f48 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -476,6 +476,7 @@ Technical Report (TR) 13 is the third preview for OpenMP 
6.0.
   specifiers @tab Y @tab
 @item Support for pure directives in Fortran's @code{do concurrent} @tab N @tab
 @item All inarguable clauses take now an optional Boolean argument @tab N @tab
+@item The @code{adjust_args} clause was extended to specify the argument by 
position
 @item For Fortran, @emph{locator list} can be also function reference with
   data pointer result @tab N @tab
 @item Concept of @emph{assumed-size arrays} in C and C++
@@ -496,7 +497,7 @@ Technical Report (TR) 13 is the third preview for OpenMP 
6.0.
   clauses @tab P @tab @code{private} not supported
 @item For Fortran, rejecting polymorphic types in data-mapping clauses
   @tab N @tab not diagnosed (and mostly unsupported)
-@item New @code{taskgraph} construct including @emph{saved} modifier and
+@item New @code{taskgraph} construct including @code{saved} modifier and
   @code{replayable} clause @tab N @tab
 @item @code{default} clause on the @code{target} directive @tab N @tab
 @item Ref-count change for @code{use_device_ptr} and @code{use_device_addr}
@@ -509,6 +510,10 @@ Technical Report (TR) 13 is the third preview for OpenMP 
6.0.
 @item New @code{init_complete} clause to the @code{scan} directive
   @tab N @tab
 @item @code{ref} modifier to the @code{map} clause @tab N @tab
+@item New @code{storage} map-type modifier; context-dependent @code{alloc} and
+  @code{release} are aliases. Update to map decay @tab N @tab
+@item Update of the map-type decay for mapping and @code{declare_mapper}
+  @tab N @tab
 @item Change of the @emph{map-type} property from @emph{ultimate} to
   @emph{default} @tab N @tab
 @item @code{self} modifier to @code{map} and @code{self} as
@@ -516,7 +521,6 @@ Technical Report (TR) 13 is the third preview for OpenMP 
6.0.
 @item Mapping of @emph{assumed-size arrays} in C, C++ and Fortran
   @tab N @tab
 @item @code{delete} as delete-modifier not as map type @tab N @tab
-@item @code{release} map-type modifier in @code{declare_mapper} @tab N @tab
 @item For Fortran, the @code{automap} modifier to the @code{enter} clause
   of @code{declare_target} @tab N @tab
 @item @code{groupprivate} directive @tab N @tab


[gcc r15-3919] libgomp.texi: Remove now duplicate TR13 item

2024-09-27 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:cfdc0a384aff5e06f80d3f55f4615abf350b193b

commit r15-3919-gcfdc0a384aff5e06f80d3f55f4615abf350b193b
Author: Tobias Burnus 
Date:   Fri Sep 27 12:06:17 2024 +0200

libgomp.texi: Remove now duplicate TR13 item

Remove an item under "Other new TR 13 features" that since the last commit
(r15-3917-g6b7eaec20b046e) to this file is is covered by the added
  "New @code{storage} map-type modifier; context-dependent @code{alloc} and
   @code{release} are aliases"
  "Update of the map-type decay for mapping and @code{declare_mapper}"

libgomp/
* libgomp.texi (TR13 status): Update semi-duplicated, semi-obsoleted
item; remove left-over half-sentence.

Diff:
---
 libgomp/libgomp.texi | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index b561cb5f3f48..c6464ece32e3 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -511,7 +511,7 @@ Technical Report (TR) 13 is the third preview for OpenMP 
6.0.
   @tab N @tab
 @item @code{ref} modifier to the @code{map} clause @tab N @tab
 @item New @code{storage} map-type modifier; context-dependent @code{alloc} and
-  @code{release} are aliases. Update to map decay @tab N @tab
+  @code{release} are aliases @tab N @tab
 @item Update of the map-type decay for mapping and @code{declare_mapper}
   @tab N @tab
 @item Change of the @emph{map-type} property from @emph{ultimate} to
@@ -633,8 +633,6 @@ Technical Report (TR) 13 is the third preview for OpenMP 
6.0.
 @item Multi-word directive names are now permitted with underscore @tab N @tab
 @item In Fortran (fixed + free), space between directive names is mandatory
   @tab N @tab
-@item @code{map(release: ...)} on @code{target} and @code{target_data} 
(map-type
-  decay changes) @tab N @tab post-TR13 item
 @end multitable


[gcc r15-3730] OpenMP: Add get_device_from_uid/omp_get_uid_from_device routines

2024-09-20 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:bf4a5efa80ef8438deb0a99c9a02b1f550aaf814

commit r15-3730-gbf4a5efa80ef8438deb0a99c9a02b1f550aaf814
Author: Tobias Burnus 
Date:   Fri Sep 20 09:25:33 2024 +0200

OpenMP: Add get_device_from_uid/omp_get_uid_from_device routines

Those TR13/OpenMP 6.0 routines permit a reproducible offloading to
a specific device by mapping an OpenMP device number to a
unique ID (UID). The GPU device UIDs should be universally unique,
the one for the host is not.

gcc/ChangeLog:

* omp-general.cc (omp_runtime_api_procname): Add
get_device_from_uid and omp_get_uid_from_device routines.

include/ChangeLog:

* cuda/cuda.h (cuDeviceGetUuid): Declare.
(cuDeviceGetUuid_v2): Add prototype.

libgomp/ChangeLog:

* config/gcn/target.c (omp_get_uid_from_device,
omp_get_device_from_uid): Add stub implementation.
* config/nvptx/target.c (omp_get_uid_from_device,
omp_get_device_from_uid): Likewise.
* fortran.c (omp_get_uid_from_device_,
omp_get_uid_from_device_8_): New functions.
* libgomp-plugin.h (GOMP_OFFLOAD_get_uid): Add prototype.
* libgomp.h (struct gomp_device_descr): Add 'uid' and 
'get_uid_func'.
* libgomp.map (GOMP_6.0): New, includind the new UID routines.
* libgomp.texi (OpenMP Technical Report 13): Mark UID routines as 
'Y'.
(Device Information Routines): Document new UID routines.
(Offload-Target Specifics): Document UID format.
* omp.h.in (omp_get_device_from_uid, omp_get_uid_from_device):
New prototype.
* omp_lib.f90.in (omp_get_device_from_uid, omp_get_uid_from_device):
New interface.
* omp_lib.h.in: Likewise.
* plugin/cuda-lib.def: Add cuDeviceGetUuid and cuDeviceGetUuid_v2 
via
CUDA_ONE_CALL_MAYBE_NULL.
* plugin/plugin-gcn.c (GOMP_OFFLOAD_get_uid): New.
* plugin/plugin-nvptx.c (GOMP_OFFLOAD_get_uid): New.
* target.c (str_omp_initial_device): New static var.
(STR_OMP_DEV_PREFIX): Define.
(gomp_get_uid_for_device, omp_get_uid_from_device,
omp_get_device_from_uid): New.
(gomp_load_plugin_for_device): DLSYM_OPT the function 'get_uid'.
(gomp_target_init): Set the device's 'uid' field to NULL.
* testsuite/libgomp.c/device_uid.c: New test.
* testsuite/libgomp.fortran/device_uid.f90: New test.

Diff:
---
 gcc/omp-general.cc   |  4 +-
 include/cuda/cuda.h  |  7 ++
 libgomp/config/gcn/target.c  | 14 
 libgomp/config/nvptx/target.c| 14 
 libgomp/fortran.c| 15 
 libgomp/libgomp-plugin.h |  1 +
 libgomp/libgomp.h|  2 +
 libgomp/libgomp.map  |  8 +++
 libgomp/libgomp.texi | 89 ++--
 libgomp/omp.h.in |  3 +
 libgomp/omp_lib.f90.in   | 23 ++
 libgomp/omp_lib.h.in | 23 ++
 libgomp/plugin/cuda-lib.def  |  2 +
 libgomp/plugin/plugin-gcn.c  | 16 +
 libgomp/plugin/plugin-nvptx.c| 34 +
 libgomp/target.c | 56 +++
 libgomp/testsuite/libgomp.c/device_uid.c | 38 ++
 libgomp/testsuite/libgomp.fortran/device_uid.f90 | 42 +++
 18 files changed, 384 insertions(+), 7 deletions(-)

diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc
index de91ba8a4a74..12788ad02490 100644
--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -3260,6 +3260,7 @@ omp_runtime_api_procname (const char *name)
   "alloc",
   "calloc",
   "free",
+  "get_device_from_uid",
   "get_interop_int",
   "get_interop_ptr",
   "get_mapped_ptr",
@@ -3338,12 +3339,13 @@ omp_runtime_api_procname (const char *name)
 as DECL_NAME only omp_* and omp_*_8 appear.  */
   "display_env",
   "get_ancestor_thread_num",
-  "init_allocator",
+  "omp_get_uid_from_device",
   "get_partition_place_nums",
   "get_place_num_procs",
   "get_place_proc_ids",
   "get_schedule",
   "get_team_size",
+  "init_allocator",
   "set_default_device",
   "set_dynamic",
   "set_max_active_levels",
diff --git a/include/cuda/cuda.h b/include/cuda/cuda.h
index 804d08ca57ea..3ade20f6bbf0 100644
--- a/include/cuda/cuda.h
+++ b/include/cuda/cuda.h
@@ -201,6 +201,10 @@ typedef struct {
   size_t WidthInBytes, Height, Depth;
 } CUDA_MEMCPY3D_PEER;
 
+typedef struct {
+  char bytes[16];
+} CUuuid;
+
 #define cuCtxCreate cuCtxCreate_v2
 CUresult cuCtxCreate (CUcontext *, unsi

[gcc r15-3856] OpenMP: Update OMP_REQUIRES_TARGET_USED for declare_target + interop

2024-09-25 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:fcff9c3dad4f356cbf56feaed7442893203a3003

commit r15-3856-gfcff9c3dad4f356cbf56feaed7442893203a3003
Author: Tobias Burnus 
Date:   Wed Sep 25 13:57:02 2024 +0200

OpenMP: Update OMP_REQUIRES_TARGET_USED for declare_target + interop

Older versions of the OpenMP specification were not clear about what counted
as device usage. Newer (like TR13) are rather clear. Hence, this commit adds
GCC's target-used flag also when a 'declare target' or an 'interop' are
encountered.  (The latter only to Fortran as C/C++ parsing support is still
missing.) TR13 also lists 'dispatch' as target-used construct (as it has the
device clause) and 'device_safesync' as clause with global requirement
property, but both are not yet supported in GCC.

gcc/c/ChangeLog:

* c-parser.cc (c_parser_omp_declare_target): Set target-used bit
in omp_requires_mask.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_omp_declare_target): Set target-used bit
in omp_requires_mask.

gcc/fortran/ChangeLog:

* parse.cc (decode_omp_directive): Set target-used bit of
omp_requires_mask when encountering the declare_target or interop
directive.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/interop-1.f90: Add dg-error for missing
omp requires requirement and declare_variant usage.
* gfortran.dg/gomp/requires-8.f90: Likewise.

Diff:
---
 gcc/c/c-parser.cc | 3 +++
 gcc/cp/parser.cc  | 3 +++
 gcc/fortran/parse.cc  | 8 ++--
 gcc/testsuite/gfortran.dg/gomp/interop-1.f90  | 2 +-
 gcc/testsuite/gfortran.dg/gomp/requires-8.f90 | 4 ++--
 5 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 6a46577f5119..a681438cbbef 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -25492,6 +25492,9 @@ c_parser_omp_declare_target (c_parser *parser)
   int device_type = 0;
   bool indirect = false;
   bool only_device_type_or_indirect = true;
+  if (flag_openmp)
+omp_requires_mask
+  = (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_TARGET_USED);
   if (c_parser_next_token_is (parser, CPP_NAME)
   || (c_parser_next_token_is (parser, CPP_COMMA)
  && c_parser_peek_2nd_token (parser)->type == CPP_NAME))
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 83ae38a33ab2..6d3be94bf448 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -49571,6 +49571,9 @@ cp_parser_omp_declare_target (cp_parser *parser, 
cp_token *pragma_tok)
   int device_type = 0;
   bool indirect = false;
   bool only_device_type_or_indirect = true;
+  if (flag_openmp)
+omp_requires_mask
+  = (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_TARGET_USED);
   if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)
   || (cp_lexer_next_token_is (parser->lexer, CPP_COMMA)
  && cp_lexer_nth_token_is (parser->lexer, 2, CPP_NAME)))
diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc
index e749bbdc6b59..9e06dbf0911d 100644
--- a/gcc/fortran/parse.cc
+++ b/gcc/fortran/parse.cc
@@ -1345,8 +1345,12 @@ decode_omp_directive (void)
 
   switch (ret)
 {
-/* Set omp_target_seen; exclude ST_OMP_DECLARE_TARGET.
-   FIXME: Get clarification, cf. OpenMP Spec Issue #3240.  */
+/* For the constraints on clauses with the global requirement property,
+   we set omp_target_seen. This included all clauses that take the
+   DEVICE clause, (BEGIN) DECLARE_TARGET and procedures run the device
+   (which effectively is implied by the former).  */
+case ST_OMP_DECLARE_TARGET:
+case ST_OMP_INTEROP:
 case ST_OMP_TARGET:
 case ST_OMP_TARGET_DATA:
 case ST_OMP_TARGET_ENTER_DATA:
diff --git a/gcc/testsuite/gfortran.dg/gomp/interop-1.f90 
b/gcc/testsuite/gfortran.dg/gomp/interop-1.f90
index 8c99fc97f888..b7d2164812cc 100644
--- a/gcc/testsuite/gfortran.dg/gomp/interop-1.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/interop-1.f90
@@ -17,7 +17,7 @@ module m
  integer (omp_interop_fr_kind), parameter :: omp_ifr_hsa = 7
 end module m
 
-subroutine sub1
+subroutine sub1  ! { dg-error "Program unit at .1. has OpenMP device 
constructs/routines but does not set !.OMP REQUIRES REVERSE_OFFLOAD but other 
program units do" }
   !$omp interop
   integer :: y ! { dg-error "Unexpected data declaration statement" }
 end subroutine sub1
diff --git a/gcc/testsuite/gfortran.dg/gomp/requires-8.f90 
b/gcc/testsuite/gfortran.dg/gomp/requires-8.f90
index 583c5a56b32e..3b0a7d81768c 100644
--- a/gcc/testsuite/gfortran.dg/gomp/requires-8.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/requires-8.f90
@@ -17,9 +17,9 @@ contains
  end subroutine foo
 end module m
 
-subroutine bar
+subroutine bar  ! { dg-error "has OpenMP device constructs/routines but does 
not set !.OMP REQUIRES REVERSE_OFFLOAD but other program units do" }
   !

[gcc r15-5017] libgomp.texi: Document OpenMP's Interoperability Routines

2024-11-07 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:e52cfd4bc23de14f1e1795bdf7ec161d94b8c087

commit r15-5017-ge52cfd4bc23de14f1e1795bdf7ec161d94b8c087
Author: Tobias Burnus 
Date:   Thu Nov 7 16:13:06 2024 +0100

libgomp.texi: Document OpenMP's Interoperability Routines

libgomp/ChangeLog:

* libgomp.texi (OpenMP Technical Report 13): Remove 'iterator'
in 'map' clause of 'declare mapper' as it is already the list above.
(Interoperability Routines): Add.
(omp_target_memcpy_async, omp_target_memcpy_rect_async):
Document that depobj_list may be omitted in C++ and Fortran.

Diff:
---
 libgomp/libgomp.texi | 333 +++
 1 file changed, 312 insertions(+), 21 deletions(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 6860963f3683..6679f6da4b9b 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -443,8 +443,7 @@ to address of matching mapped list item per 5.1, Sect. 
2.21.7.2 @tab N @tab
   of the @code{interop} construct @tab N @tab
 @item Invoke virtual member functions of C++ objects created on the host device
   on other devices @tab N @tab
-@item @code{iterator} and @code{mapper} as map-type modifier in @code{declare 
mapper}
-  @tab N @tab
+@item @code{mapper} as map-type modifier in @code{declare mapper} @tab N @tab
 @end multitable
 
 
@@ -668,7 +667,7 @@ specification in version 5.2.
 * Lock Routines::
 * Timing Routines::
 * Event Routine::
-@c * Interoperability Routines::
+* Interoperability Routines::
 * Memory Management Routines::
 @c * Tool Control Routine::
 * Environment Display Routine::
@@ -2211,8 +2210,9 @@ to the destination device's @var{dst} address shifted by 
@var{dst_offset}.
 Task dependence is expressed by passing an array of depend objects to
 @var{depobj_list}, where the number of array elements is passed as
 @var{depobj_count}; if the count is zero, the @var{depobj_list} argument is
-ignored.  The routine returns zero if the copying process has successfully
-been started and non-zero otherwise.
+ignored.  In C++ and Fortran, the @var{depobj_list} argument can also be
+omitted in that case.   The routine returns zero if the copying process has
+successfully been started and non-zero otherwise.
 
 Running this routine in a @code{target} region except on the initial device
 is not supported.
@@ -2332,7 +2332,8 @@ respectively.  The offset per dimension to the first 
element to be copied is
 given by the @var{dst_offset} and @var{src_offset} arguments.  Task dependence
 is expressed by passing an array of depend objects to @var{depobj_list}, where
 the number of array elements is passed as @var{depobj_count}; if the count is
-zero, the @var{depobj_list} argument is ignored.  The routine
+zero, the @var{depobj_list} argument is ignored.  In C++ and Fortran, the
+@var{depobj_list} argument can also be omitted in that case.  The routine
 returns zero on success and non-zero otherwise.
 
 The OpenMP specification only requires that @var{num_dims} up to three is
@@ -2961,21 +2962,311 @@ event handle that has already been fulfilled is also 
undefined.
 
 
 
-@c @node Interoperability Routines
-@c @section Interoperability Routines
-@c
-@c Routines to obtain properties from an @code{omp_interop_t} object.
-@c They have C linkage and do not throw exceptions.
-@c
-@c @menu
-@c * omp_get_num_interop_properties:: 
-@c * omp_get_interop_int:: 
-@c * omp_get_interop_ptr:: 
-@c * omp_get_interop_str:: 
-@c * omp_get_interop_name:: 
-@c * omp_get_interop_type_desc:: 
-@c * omp_get_interop_rc_desc:: 
-@c @end menu
+@node Interoperability Routines
+@section Interoperability Routines
+
+Routines to obtain properties from an object of OpenMP interop type.
+They have C linkage and do not throw exceptions.
+
+@menu
+* omp_get_num_interop_properties:: Get the number of implementation-specific 
properties
+* omp_get_interop_int:: Obtain integer-valued interoperability property
+* omp_get_interop_ptr:: Obtain pointer-valued interoperability property
+* omp_get_interop_str:: Obtain string-valued interoperability property
+* omp_get_interop_name:: Obtain the name of an interop_property value as string
+* omp_get_interop_type_desc:: Obtain type and description to an 
interop_property
+* omp_get_interop_rc_desc:: Obtain error string to an interop_rc error code
+@end menu
+
+
+
+@node omp_get_num_interop_properties
+@subsection @code{omp_get_num_interop_properties} -- Get the number of 
implementation-specific properties
+@table @asis
+@item @emph{Description}:
+The @code{omp_get_num_interop_properties} function returns the number of
+implementation-defined interoperability properties available for the passed
+@var{interop}, extending the OpenMP-defined properties.  The available OpenMP
+interop_property-type values range from @code{omp_ipr_first} to the value
+returned by @code{omp_get_num_interop_properties} minus one.
+
+No implementation-defined properties are currently defined i

[gcc r15-5392] libgomp/plugin/plugin-gcn.c: async-queue init - fix function-return type and fail fatally

2024-11-18 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:884637b6362391921100efa2c7db4f4452e2a13f

commit r15-5392-g884637b6362391921100efa2c7db4f4452e2a13f
Author: Tobias Burnus 
Date:   Mon Nov 18 14:58:21 2024 +0100

libgomp/plugin/plugin-gcn.c: async-queue init - fix function-return type 
and fail fatally

libgomp/ChangeLog:

* plugin/plugin-gcn.c (GOMP_OFFLOAD_openacc_async_construct): In
case of an error, call GOMP_PLUGIN_fatal not ..._error; use NULL
not false in return.

Diff:
---
 libgomp/plugin/plugin-gcn.c | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c
index f2f2940de9db..d26b93657bf6 100644
--- a/libgomp/plugin/plugin-gcn.c
+++ b/libgomp/plugin/plugin-gcn.c
@@ -4388,7 +4388,9 @@ GOMP_OFFLOAD_openacc_async_exec (void (*fn_ptr) (void *),
   gcn_exec (kernel, devaddrs, dims, targ_mem_desc, true, aq);
 }
 
-/* Create a new asynchronous thread and queue for running future kernels.  */
+/* Create a new asynchronous thread and queue for running future kernels;
+   issues a fatal error if the queue cannot be created as all callers expect
+   that the queue exists.  */
 
 struct goacc_asyncqueue *
 GOMP_OFFLOAD_openacc_async_construct (int device)
@@ -4416,18 +4418,18 @@ GOMP_OFFLOAD_openacc_async_construct (int device)
 
   if (pthread_mutex_init (&aq->mutex, NULL))
 {
-  GOMP_PLUGIN_error ("Failed to initialize a GCN agent queue mutex");
-  return false;
+  GOMP_PLUGIN_fatal ("Failed to initialize a GCN agent queue mutex");
+  return NULL;
 }
   if (pthread_cond_init (&aq->queue_cond_in, NULL))
 {
-  GOMP_PLUGIN_error ("Failed to initialize a GCN agent queue cond");
-  return false;
+  GOMP_PLUGIN_fatal ("Failed to initialize a GCN agent queue cond");
+  return NULL;
 }
   if (pthread_cond_init (&aq->queue_cond_out, NULL))
 {
-  GOMP_PLUGIN_error ("Failed to initialize a GCN agent queue cond");
-  return false;
+  GOMP_PLUGIN_fatal ("Failed to initialize a GCN agent queue cond");
+  return NULL;
 }
 
   hsa_status_t status = hsa_fns.hsa_queue_create_fn (agent->id,


[gcc r15-5381] libgomp/plugin/plugin-nvptx.c: Change false to NULL to fix C23 wrong-return-type error [PR117626]

2024-11-18 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:e7e3d1838f7cfb4a9fca711d735d8f5ea47d16dc

commit r15-5381-ge7e3d1838f7cfb4a9fca711d735d8f5ea47d16dc
Author: Tobias Burnus 
Date:   Mon Nov 18 11:06:58 2024 +0100

libgomp/plugin/plugin-nvptx.c: Change false to NULL to fix C23 
wrong-return-type error [PR117626]

libgomp/ChangeLog:

PR libgomp/117626
* plugin/plugin-nvptx.c (nvptx_open_device): Use 'CUDA_CALL_ERET'
with 'NULL' as error return instead of 'CUDA_CALL' that returns 
false.

Diff:
---
 libgomp/plugin/plugin-nvptx.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c
index e9a9d798fe6b..f6d7f0675714 100644
--- a/libgomp/plugin/plugin-nvptx.c
+++ b/libgomp/plugin/plugin-nvptx.c
@@ -595,8 +595,10 @@ nvptx_open_device (int n)
   GOMP_PLUGIN_debug (0, "Setting \"native\" GPU thread stack size"
 " ('CU_LIMIT_STACK_SIZE') to %u bytes\n",
 native_gpu_thread_stack_size);
-  CUDA_CALL (cuCtxSetLimit,
-CU_LIMIT_STACK_SIZE, (size_t) native_gpu_thread_stack_size);
+  CUDA_CALL_ERET (NULL,
+ cuCtxSetLimit,
+ CU_LIMIT_STACK_SIZE,
+ (size_t) native_gpu_thread_stack_size);
 }
 
   /* OpenMP "soft stacks".  */


[gcc r15-5251] libgomp.texi: Impl. Status - change TR13 to OpenMP 6.0 + fix routine typo

2024-11-14 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:28854cf68dc4ad1ce5a72440d1422cb2bb02dd62

commit r15-5251-g28854cf68dc4ad1ce5a72440d1422cb2bb02dd62
Author: Tobias Burnus 
Date:   Thu Nov 14 16:28:20 2024 +0100

libgomp.texi: Impl. Status - change TR13 to OpenMP 6.0 + fix routine typo

libgomp/
* libgomp.texi (OpenMP Implementation Status): Change TR13 to
OpenMP 6.0, now released. Fix a typo in the omp_target_memset_async
routine name.

Diff:
---
 libgomp/libgomp.texi | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 6679f6da4b9b..fe291208cfee 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -169,7 +169,7 @@ See also @ref{OpenMP Implementation Status}.
 * OpenMP 5.0:: Feature completion status to 5.0 specification
 * OpenMP 5.1:: Feature completion status to 5.1 specification
 * OpenMP 5.2:: Feature completion status to 5.2 specification
-* OpenMP Technical Report 13:: Feature completion status to third 6.0 preview
+* OpenMP 6.0:: Feature completion status to 6.0 specification
 @end menu
 
 The @code{_OPENMP} preprocessor macro and Fortran's @code{openmp_version}
@@ -447,10 +447,8 @@ to address of matching mapped list item per 5.1, Sect. 
2.21.7.2 @tab N @tab
 @end multitable
 
 
-@node OpenMP Technical Report 13
-@section OpenMP Technical Report 13
-
-Technical Report (TR) 13 is the third preview for OpenMP 6.0.
+@node OpenMP 6.0
+@section OpenMP 6.0
 
 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
 @multitable @columnfractions .60 .10 .25
@@ -596,7 +594,7 @@ Technical Report (TR) 13 is the third preview for OpenMP 
6.0.
 @item @code{omp_get_device_num_teams}, @code{omp_set_device_num_teams},
   @code{omp_get_device_teams_thread_limit}, and
   @code{omp_set_device_teams_thread_limit} routines @tab N @tab
-@item @code{omp_target_memset} and @code{omp_target_memset_rect_async} routines
+@item @code{omp_target_memset} and @code{omp_target_memset_async} routines
   @tab N @tab
 @item Fortran version of the interop runtime routines @tab N @tab
 @item Routines for obtaining memory spaces/allocators for shared/device memory
@@ -632,7 +630,7 @@ Technical Report (TR) 13 is the third preview for OpenMP 
6.0.
   @tab N @tab
 @end multitable
 
-@unnumberedsubsec Other new TR 13 features
+@unnumberedsubsec Other new OpenMP 6.0 features
 @multitable @columnfractions .60 .10 .25
 @item Multi-word directives now use underscore by default @tab N @tab
 @item Relaxed Fortran restrictions to the @code{aligned} clause @tab N @tab


[gcc r15-5886] OpenMP: 'allocate' directive - fixes for 'alignof' and [[omp::decl]]

2024-12-03 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:3d72e50caebf232fdd7f70613616ca4fd4fb472b

commit r15-5886-g3d72e50caebf232fdd7f70613616ca4fd4fb472b
Author: Tobias Burnus 
Date:   Tue Dec 3 11:02:03 2024 +0100

OpenMP: 'allocate' directive - fixes for 'alignof' and [[omp::decl]]

Fixed a check to permit [[omp::decl(allocate,...)]] parsing in C.

Additionaly, we discussed that 'allocate align' should not affect
'alignof' to avoid issues like with:

  int a;
  _Alignas(_Alignof(a)) int b;
  #pragma omp allocate(a) align(128)
  _Alignas(_Alignof(a)) int c;

Thus, the alignment is no longer set in the C and Fortran front ends,
but for static variables now in varpool_node::finalize_decl.
(For stack variables, the alignment is handled in gimplify_bind_expr.)

NOTE: 'omp allocate' is not yet supported in C++.

gcc/c/ChangeLog:

* c-parser.cc (c_parser_omp_allocate): Only check scope if
not in_omp_decl_attribute. Remove setting the alignment.

gcc/ChangeLog:

* cgraphunit.cc (varpool_node::finalize_decl): Set alignment
based on OpenMP's 'omp allocate' attribute/directive.

gcc/fortran/ChangeLog:

* trans-decl.cc (gfc_finish_var_decl): Remove setting the alignment.

libgomp/ChangeLog:

* libgomp.texi (Memory allocation): Mention (non-)effect of 'align'
on _Alignof.
* testsuite/libgomp.c/allocate-7.c: New test.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/allocate-18.c: Check that alignof is unaffected
by 'omp allocate'.
* c-c++-common/gomp/allocate-19.c: Likewise.

Diff:
---
 gcc/c/c-parser.cc |  5 +--
 gcc/cgraphunit.cc | 12 ++
 gcc/fortran/trans-decl.cc |  3 --
 gcc/testsuite/c-c++-common/gomp/allocate-18.c |  6 +--
 gcc/testsuite/c-c++-common/gomp/allocate-19.c | 10 ++---
 libgomp/libgomp.texi  |  6 +++
 libgomp/testsuite/libgomp.c/allocate-7.c  | 54 +++
 7 files changed, 81 insertions(+), 15 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 0acba0542df6..a7719acf0bf2 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -22158,7 +22158,7 @@ c_parser_omp_allocate (c_parser *parser)
"% directive", var);
  continue;
}
-  if (!c_check_in_current_scope (var))
+  if (!parser->in_omp_decl_attribute && !c_check_in_current_scope (var))
{
  error_at (OMP_CLAUSE_LOCATION (nl),
"% directive must be in the same scope as %qD",
@@ -22199,9 +22199,6 @@ c_parser_omp_allocate (c_parser *parser)
= {EXPR_LOC_OR_LOC (allocator, OMP_CLAUSE_LOCATION (nl)), var};
  walk_tree (&allocator, c_check_omp_allocate_allocator_r, &data, NULL);
}
-  if (alignment)
-   SET_DECL_ALIGN (var, BITS_PER_UNIT * MAX (tree_to_uhwi (alignment),
- DECL_ALIGN_UNIT (var)));
   DECL_ATTRIBUTES (var) = tree_cons (get_identifier ("omp allocate"),
 build_tree_list (allocator, alignment),
 DECL_ATTRIBUTES (var));
diff --git a/gcc/cgraphunit.cc b/gcc/cgraphunit.cc
index d60ebc1c9884..e954e889960b 100644
--- a/gcc/cgraphunit.cc
+++ b/gcc/cgraphunit.cc
@@ -983,6 +983,18 @@ varpool_node::finalize_decl (tree decl)
  && !DECL_ARTIFICIAL (node->decl)))
 node->force_output = true;
 
+  if (flag_openmp)
+{
+  tree attr = lookup_attribute ("omp allocate", DECL_ATTRIBUTES (decl));
+  if (attr)
+   {
+ tree align = TREE_VALUE (TREE_VALUE (attr));
+ if (align)
+   SET_DECL_ALIGN (decl, MAX (tree_to_uhwi (align) * BITS_PER_UNIT,
+  DECL_ALIGN (decl)));
+   }
+}
+
   if (symtab->state == CONSTRUCTION
   && (node->needed_p () || node->referred_to_p ()))
 enqueue_node (node);
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index a62fe3f0441c..d69c8430484a 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -830,9 +830,6 @@ gfc_finish_var_decl (tree decl, gfc_symbol * sym)
   tree alloc = gfc_conv_constant_to_tree (n->u2.allocator);
   tree align = (n->u.align ? gfc_conv_constant_to_tree (n->u.align)
   : NULL_TREE);
-  if (align != NULL_TREE)
-   SET_DECL_ALIGN (decl, MAX (tree_to_uhwi (align),
-   DECL_ALIGN_UNIT (decl)) * BITS_PER_UNIT);
   DECL_ATTRIBUTES (decl)
= tree_cons (get_identifier ("omp allocate"),
 build_tree_list (alloc, align), DECL_ATTRIBUTES (decl));
diff --git a/gcc/testsuite/c-c++-common/gomp/allocate-18.c 
b/gcc/testsuite/c-c++-common/gomp/allocate-18.c
index 4182f7ee37ec..93c5aca29a7c 100644
--

[gcc r15-6509] OpenMP: Enable has_device_addr clause for 'dispatch' in Fortran

2025-01-02 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:f642db74d936e5310e86ce0173c83673a309e440

commit r15-6509-gf642db74d936e5310e86ce0173c83673a309e440
Author: Tobias Burnus 
Date:   Thu Jan 2 22:41:03 2025 +0100

OpenMP: Enable has_device_addr clause for 'dispatch' in Fortran

Fortran version of commit r15-6178-g2cbb2408a830a6 for C/C++.
However, the has_device_addr clause on dispatch only becomes really
useful (for C++ and Fortran) once the 'need_device_addr' modifier
to declare variant's 'adjust_args' clause is supported (i.e. with
a future commit).

gcc/fortran/ChangeLog:

* openmp.cc (OMP_DISPATCH_CLAUSES): Add OMP_CLAUSE_HAS_DEVICE_ADDR.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/adjust-args-10.f90: New test.

Diff:
---
 gcc/fortran/openmp.cc |  3 +-
 gcc/testsuite/gfortran.dg/gomp/adjust-args-10.f90 | 99 +++
 2 files changed, 101 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 73d7803ff9c5..79c0f1b2e62a 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -5018,7 +5018,8 @@ cleanup:
| OMP_CLAUSE_INIT | OMP_CLAUSE_DESTROY | OMP_CLAUSE_USE)
 #define OMP_DISPATCH_CLAUSES   
\
   (omp_mask (OMP_CLAUSE_DEVICE) | OMP_CLAUSE_DEPEND | OMP_CLAUSE_NOVARIANTS
\
-   | OMP_CLAUSE_NOCONTEXT | OMP_CLAUSE_IS_DEVICE_PTR | OMP_CLAUSE_NOWAIT)
+   | OMP_CLAUSE_NOCONTEXT | OMP_CLAUSE_IS_DEVICE_PTR | OMP_CLAUSE_NOWAIT   
\
+   | OMP_CLAUSE_HAS_DEVICE_ADDR)
 
 
 static match
diff --git a/gcc/testsuite/gfortran.dg/gomp/adjust-args-10.f90 
b/gcc/testsuite/gfortran.dg/gomp/adjust-args-10.f90
new file mode 100644
index ..3b649b5d7d0e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/adjust-args-10.f90
@@ -0,0 +1,99 @@
+! { dg-additional-options "-fdump-tree-gimple" }
+
+! This mainly checks 'has_device_addr' without associated 'need_device_addr'
+!
+! Do diagnostic check / dump check only;
+! Note: this test should work as run-test as well.
+
+module m
+  use iso_c_binding
+  ! use omp_lib
+  implicit none (type, external)
+  interface
+integer function omp_get_default_device (); end
+integer function omp_get_num_devices (); end
+  end interface
+
+contains
+  subroutine g (x, y)
+!$omp declare variant(f) adjust_args(need_device_ptr: x, y) 
match(construct={dispatch})
+type(c_ptr), value :: x, y
+  end
+
+  subroutine f (cfrom, cto)
+type(c_ptr), value :: cfrom, cto
+integer, save :: cnt = 0
+cnt = cnt + 1
+if (cnt >= 3) then
+  if (omp_get_default_device () /= -1  &
+  .and. omp_get_default_device () < omp_get_num_devices ()) then
+! On offload device but not mapped
+if (.not. c_associated(cfrom)) & ! Not mapped
+  stop 1
+  else
+block
+  integer, pointer :: from(:)
+  call c_f_pointer(cfrom, from, shape=[1])
+  if (from(1) /= 5) &
+stop 2
+end block
+  end if
+  return
+end if
+
+!$omp target is_device_ptr(cfrom, cto)
+  block
+integer, pointer :: from(:), to(:)
+call c_f_pointer(cfrom, from, shape=[2])
+call c_f_pointer(cto, to, shape=[2])
+to(1) = from(1) * 10
+to(2) = from(2) * 10
+  end block
+  end
+
+  subroutine sub (a, b)
+integer, target :: a(:), b(:)
+type(c_ptr), target :: ca, cb
+
+ca = c_loc(a)
+cb = c_loc(b)
+
+! The has_device_addr is a bit questionable as the caller is not actually
+! passing a device address - but we cannot pass one because of the
+! following:
+!
+! As for 'b' need_device_ptr has been specified and 'b' is not
+! in the semantic requirement set 'is_device_ptr' (and only in 
'has_device_addr')
+! "the argument is converted in the same manner that a use_device_ptr 
clause
+!  on a target_data construct converts its pointer"
+
+!$omp dispatch is_device_ptr(ca), has_device_addr(cb)
+  call g (ca, cb)  ! { dg-warning "'has_device_addr' for 'cb' does not 
imply 'is_device_ptr' required for 'need_device_ptr' \\\[-Wopenmp\\\]" }
+  end
+end
+
+program main
+  use m
+  implicit none (type, external)
+
+  integer, target :: A(2), B(2) = [123, 456], C(1) = [5]
+  integer, pointer :: p(:)
+
+  p => A
+
+  !$omp target enter data map(A, B)
+
+  ! Note: We don't add  'use_device_addr(B)' here;
+  ! if we do, it will fail with an illegal memory access (why?).
+  !$omp target data use_device_ptr(p)
+call sub(p, B)
+call sub(C, B)  ! C is not mapped -> 'from' ptr == NULL
+  !$omp end target data
+
+  !$omp target exit data map(A, B)
+end
+
+! { dg-final { scan-tree-dump-times "#pragma omp dispatch 
is_device_ptr\\(ca\\) has_device_addr\\(cb\\)" 1 "gimple" } }
+! { dg-final { scan-tree-dump-times "__builtin_omp_get_mapped_ptr" 1 "gimple" 
} }
+! { dg-final { scan-tree-dump-times "D\\.\[0-9\]+ = 
__builtin_omp_get_mapped_ptr \\(cb" 1 "

[gcc/devel/omp/gcc-14] (497 commits) Merge branch 'releases/gcc-14' into devel/omp/gcc-14

2025-01-02 Thread Tobias Burnus via Gcc-cvs
The branch 'devel/omp/gcc-14' was updated to point to:

 fb877b22a6c0... Merge branch 'releases/gcc-14' into devel/omp/gcc-14

It previously pointed to:

 2f01bd9787dc... nvptx: PTX 'alloca' for '-mptx=7.3'+, '-march=sm_52'+ [PR65

Diff:

Summary of changes (added commits):
---

  fb877b2... Merge branch 'releases/gcc-14' into devel/omp/gcc-14
  979d5bf... Daily bump. (*)
  9a29512... Daily bump. (*)
  12dda7c... Daily bump. (*)
  ca80e35... Daily bump. (*)
  656425e... Daily bump. (*)
  ef7cda7... Daily bump. (*)
  cf65955... Daily bump. (*)
  49ec5f8... Daily bump. (*)
  02defdd... Daily bump. (*)
  1d6f91c... Daily bump. (*)
  83646dd... c++: integer overflow during constraint subsumption [PR1180 (*)
  ecd031a... Revert "arm: [MVE intrinsics] Fix support for predicate con (*)
  597daaa... Daily bump. (*)
  e79105a... testsuite: arm: Check for short circuit instructions [PR103 (*)
  d1710c4... Fortran: Fix testsuite regressions after r15-5083 [PR117797 (*)
  5c9fcac... Daily bump. (*)
  7cdf335... Daily bump. (*)
  e883a70... Daily bump. (*)
  0631c57... arm: [MVE intrinsics] Fix support for predicate constants [ (*)
  87f9c0e... Fix comment typos in tree-assume.cc (*)
  4bbb74c... testsuite: arm: Use effective-target for memset-inline* tes (*)
  44da17c... Daily bump. (*)
  9366c32... arm: Fix LDRD register overlap [PR117675] (*)
  f0caa19... Daily bump. (*)
  0361b4c... testsuite: arm: Mark pr81812.C as xfail for thumb1 (*)
  3b6ed0c... Fortran: Pointer fcn results must not be finalized [PR11789 (*)
  feeacb4... Daily bump. (*)
  e420277... Update cpplib sr.po (*)
  29d0724... libstdc++: Fix typo in Doxygen comment in  (*)
  3396834... doc: Fix typos for --enable-host-pie docs in install.texi (*)
  dfd4d76... ada: Fix internal error with Atomic Volatile_Full_Access ob (*)
  c1f2408... Daily bump. (*)
  1572e63... Fortran: Fix non_overridable typebound proc problems [PR846 (*)
  9fc9b64... Daily bump. (*)
  cfe2166... [PATCH] PR modula2/117120: case ch with a nul char constant (*)
  980e124... Daily bump. (*)
  3454cca... driver: fix crash with --diagnostics-plain-output [PR117942 (*)
  2fd2f40... c++: ICE with -Wduplicated-branches in template [PR117880] (*)
  da47084... [PATCH] PR modula2/115328: use enable forward bool and set  (*)
  c27a189... Daily bump. (*)
  d470d64... Fix precondition failure with Ada.Numerics.Generic_Real_Arr (*)
  cbedb33... testsuite: arm: Use -mtune=cortex-m4 for thumb-ifcvt.c test (*)
  add3560... testsuite: arm: Fix build error for thumb2-slow-flash-data- (*)
  7121921... Daily bump. (*)
  2d9dbaf... Fortran: Fix READ with padding in BLANK ZERO mode. (*)
  6ddd895... Daily bump. (*)
  21a09f0... Daily bump. (*)
  7b58a7e... s390: Fix UNSPEC_CC_TO_INT canonicalization (*)
  ac05446... tree-eh: Don't crash on GIMPLE_TRY_FINALLY with empty clean (*)
  7b8f236... Daily bump. (*)
  c08ae0c... i386: Fix unwanted fwprop to 3dNOW! insn [PR117926] (*)
  5e9cd91... Daily bump. (*)
  6385000... [PATCH] PR modula2/117948: Forward procedure declaration sh (*)
  5e55168... Daily bump. (*)
  1dbbfe2... Fortran: Fix B64.0 formatted write output. (*)
  be532c7... Fortran: Eliminate error prone translations. (*)
  7dff53c... [PATCH] PR modula2/117904: cc1gm2 ICE when compiling a cons (*)
  ad59007... fortran: Add default to switch in gfc_trans_transfer [PR117 (*)
  d3c18b9... Fortran: fix crash with bounds check writing array section  (*)
  de7dc9b... Daily bump. (*)
  4a73efc... c++: Don't reject pointer to virtual method during constant (*)
  0eb7f0a... AVR: target/64242 - Copy FP to a local reg in nonlocal_goto (*)
  524ba3a... Daily bump. (*)
  5902ea4... [PATCH] PR modula2/117660: Errors referring to variables of (*)
  f43c2ee... [PATCH] PR modula2/117371: Add check for zero step in for l (*)
  5ce16f9... Daily bump. (*)
  c1409e1... [PATCH] PR modula2/117371: type incompatibility between INT (*)
  de4f10f... [PATCH] modula2: Add dependencies for generated sources (*)
  3dff2f9... [PATCH] modula2: Reimplement parameter declaration and chec (*)
  92014ea... Update gcc zh_CN.po (*)
  f01f01f... middle-end:For multiplication try swapping operands when ma (*)
  d35eeec... [PATCH] modula2: M2MetaError.{def,mod} and P2SymBuild.mod f (*)
  b16824e... [PATCH] modula2: Tidyup gm2-compiler/M2MetaError.mod (*)
  e8acf68... [PATCH] PR modula2/115328 The FORWARD keyword is not implem (*)
  960fe2c... Daily bump. (*)
  986c71c... libstdc++: Use constexpr instead of _GLIBCXX20_CONSTEXPR in (*)
  3a1a3ba... libstdc++: avoid -Wsign-compare (*)
  61f4509... libstdc++: fix testcase regexp (*)
  3856917... libstdc++: avoid -Wzero-as-null-pointer-constant (*)
  f9e34b1... libstdc++: remove extra semicolons (*)
  d85ad17... libstdc++: Fix -Wunused-parameter warnings in Networking TS (*)
  31c7539... libstdc++: Silence -Woverloaded-virtual warning in cxx11-io (*)
  4b7a1db... libstdc++: Silence -Wattributes warning in exception_ptr (*)
  f2b027a... libstdc++: Remove unused typ

[gcc r15-6659] libgomp.texi: Minor update to omp_get_num_devices/omp_get_initial_device

2025-01-07 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:d3ccd89fa0d34d44226af47fe82c27ba7833fe65

commit r15-6659-gd3ccd89fa0d34d44226af47fe82c27ba7833fe65
Author: Tobias Burnus 
Date:   Tue Jan 7 16:43:30 2025 +0100

libgomp.texi: Minor update to omp_get_num_devices/omp_get_initial_device

libgomp/ChangeLog:

* libgomp.texi (OpenMP 6.0): Fix typo.
(omp_get_default_device): Update the wording as the value
returned by omp_get_initial_device is now ambiguous.
(omp_get_num_devices): Minor wording tweak.
(omp_get_initial_device): Note that the function may also
return omp_initial_device since OpenMP 6.

Diff:
---
 libgomp/libgomp.texi | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 9a42355ff5d4..7d8cd70287ee 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -550,7 +550,7 @@ to address of matching mapped list item per 5.1, Sect. 
2.21.7.2 @tab N @tab
 @item @code{interchange} loop-transformation construct @tab N @tab
 @item @code{reverse} loop-transformation construct @tab N @tab
 @item @code{split} loop-transformation construct @tab N @tab
-@item @code{stipe} loop-transformation construct @tab N @tab
+@item @code{stripe} loop-transformation construct @tab N @tab
 @item @code{tile} permitting association of grid and inter-tile loops @tab N 
@tab
 @item @code{strict} modifier keyword to @code{num_threads} @tab N @tab
 @item @code{safesync} clause to the @code{parallel} construct @tab N @tab
@@ -1760,10 +1760,9 @@ The effect of running this routine in a @code{target} 
region is unspecified.
 Get the value of the @emph{default-device-var} ICV, which is used
 for target regions without a device clause. The value is either a
 nonnegative device number, @code{omp_initial_device} or
-@code{omp_invalid_device}. Note that for the host, the ICV can have two values
-and, hence, this routine might return either the value of the named constant
-@code{omp_initial_device} or the value returned by the
-@code{omp_get_initial_device} routine.
+@code{omp_invalid_device}. Note that for the host, the ICV can have two values:
+either the value of the named constant @code{omp_initial_device} or the value
+returned by the @code{omp_get_num_devices} routine.
 
 The effect of running this routine in a @code{target} region is unspecified.
 
@@ -1791,7 +1790,7 @@ The effect of running this routine in a @code{target} 
region is unspecified.
 @subsection @code{omp_get_num_devices} -- Number of target devices
 @table @asis
 @item @emph{Description}:
-Returns the number of target devices.
+Returns the number of available non-host devices.
 
 The effect of running this routine in a @code{target} region is unspecified.
 
@@ -1938,7 +1937,8 @@ run-time function is desired.
 @item @emph{Description}:
 This function returns a device number that represents the host device.
 Since OpenMP 5.1, this is equal to the value returned by the
-@code{omp_get_num_devices} function.
+@code{omp_get_num_devices} function; since OpenMP 6.0 it may also return
+the value of @code{omp_initial_device}.
 
 The effect of running this routine in a @code{target} region is unspecified.


[gcc r15-7366] fortran/trans-openmp.cc: Use the correct member in gfc_omp_namelist [PR118745]

2025-02-04 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:3a5882707df50ed29905b3c47cbaa0868ea248c9

commit r15-7366-g3a5882707df50ed29905b3c47cbaa0868ea248c9
Author: Tobias Burnus 
Date:   Wed Feb 5 08:44:41 2025 +0100

fortran/trans-openmp.cc: Use the correct member in gfc_omp_namelist 
[PR118745]

gcc/fortran/ChangeLog:

PR fortran/118745
* trans-openmp.cc (gfc_trans_omp_declare_variant): Use
append_args_list in the condition for the append_arg location.

Diff:
---
 gcc/fortran/trans-openmp.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index a593f5a8e5e9..e29ef85ae398 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -8839,7 +8839,7 @@ gfc_trans_omp_declare_variant (gfc_namespace *ns)
last_arg->next = extra_arg;
  else if (extra_arg)
variant_proc_sym->formal = extra_arg;
- locus *loc = (odv->adjust_args_list
+ locus *loc = (odv->append_args_list
? &odv->append_args_list->where :  &odv->where);
  int nextra_arg = 0;
  for (; extra_arg; extra_arg = extra_arg->next)


[gcc r15-7457] [gcn] install.texi: Update for new ISA targets and their requirements

2025-02-10 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:7037fdf6bd0a4eea4a436b432265d6b7cc481737

commit r15-7457-g7037fdf6bd0a4eea4a436b432265d6b7cc481737
Author: Tobias Burnus 
Date:   Mon Feb 10 18:05:51 2025 +0100

[gcn] install.texi: Update for new ISA targets and their requirements

GCN now supports several additional ISA targets such that no longer
all targets have a multilib by default; add a note about this, the
generic targets and the required LLVM (and ROCm) versions.

gcc/ChangeLog:

* doc/install.texi (GCN): Update section about multilibs and
required LLVM version.

Diff:
---
 gcc/doc/install.texi | 30 ++
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 3b9f56b05292..d6cf318b3afe 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -3991,14 +3991,36 @@ This is a synonym for @samp{x86_64-*-solaris2*}.
 @heading amdgcn-*-amdhsa
 AMD GCN GPU target.
 
-Instead of GNU Binutils, you will need to install LLVM 15, or later, and copy
+Instead of GNU Binutils, you need to install LLVM and copy
 @file{bin/llvm-mc} to @file{amdgcn-amdhsa/bin/as},
 @file{bin/lld} to @file{amdgcn-amdhsa/bin/ld},
 @file{bin/llvm-nm} to @file{amdgcn-amdhsa/bin/nm}, and
 @file{bin/llvm-ar} to both @file{bin/amdgcn-amdhsa-ar} and
-@file{bin/amdgcn-amdhsa-ranlib}.  Note that LLVM 13.0.1 or LLVM 14 can be used
-by specifying a @code{--with-multilib-list=} that does not list @code{gfx1100}
-and @code{gfx1103}.
+@file{bin/amdgcn-amdhsa-ranlib}.
+
+The required version of LLVM depends on the devices that you want to support.
+As the list of ISAs is long, GCC by default only builds a subset of the
+supported ISAs as multilib; use @code{--with-multilib-list=} to tailor the 
built
+multilibs.  Note that mixing ISAs in the same binary is not supported and gives
+a linker error.
+
+By default, multilib support is built for @code{gfx900}, @code{gfx906},
+@code{gfx908}, @code{gfx90a}, @code{gfx90c}, @code{gfx1030}, @code{gfx1036},
+@code{gfx1100} and @code{gfx1103}.  The default multilib configuration
+requires LLVM 15 or newer.  LLVM 13.0.1 or LLVM 14 can be used by specifying
+a @code{--with-multilib-list=} that does not list any GFX 11 device nor
+@code{gfx1036}.  At least LLVM 16 is required for @code{gfx1150} and
+@code{gfx1151}, LLVM 19 for the generic @code{gfx9-generic},
+@code{gfx10-3-generic}, and @code{gfx11-generic} targets and for
+@code{gfx1152}, while LLVM 20 is required for @code{gfx1153}.
+
+The supported ISA architectures are listed in the GCC manual. The generic
+ISA targets @code{gfx9-generic}, @code{gfx10-3-generic}, and
+@code{gfx11-generic} reduce the number of required multilibs but note
+that @code{gfx9-generic} does not include @code{gfx908} or @code{gfx90a},
+that linking specific ISA code with generic code is currently not supported,
+and that only a future ROCm release (newer than 6.3.2) will be able to execute
+generic code.
 
 Use Newlib (4.3.0 or newer; 4.4.0 contains some improvements and 4.5.0 fixes
 the device console output for GFX10 and GFX11 devices).


[gcc r15-7458] [gcn] mkoffload.cc: Print fatal error if -march has no multilib but generic has

2025-02-10 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:4ce8ad684b90606a74f0cccfd9455184046c6c4e

commit r15-7458-g4ce8ad684b90606a74f0cccfd9455184046c6c4e
Author: Tobias Burnus 
Date:   Mon Feb 10 18:24:34 2025 +0100

[gcn] mkoffload.cc: Print fatal error if -march has no multilib but generic 
has

Assume that a distro has configured, e.g., a gfx9-generic multilib but not
for gfx902. In that case, mkoffload would fail to link with "error:
incompatible mach".  With this commit, an error is printed suggesting to try
the associated generic architecture instead.  The behavior is unchanged if
there is a multilib available for the specific ISA or when there is also no
multilib for the generic ICA.

Note: The build of generic multilibs are currently not enabled by default;
they also require the linker/assembler of LLVM 19 or newer and, in 
particular,
for the execution a future ROCm release. (The next one? In any case, 6.3.2
does not support generic ISAs, yet.)

gcc/ChangeLog:

* config/gcn/mkoffload.cc (enum elf_arch_code): Add
EF_AMDGPU_MACH_AMDGCN_NONE.
(elf_arch): Use enum elf_arch_code as type.
(tool_cleanup): Silence warning by removing tailing '.' from error.
(get_arch_name): Return enum elf_arch_code.
(check_for_missing_lib): New; print fatal error if the multilib
is not available but it is for the associate generic ISA.
(main): Call it.

Diff:
---
 gcc/config/gcn/mkoffload.cc | 101 +---
 1 file changed, 94 insertions(+), 7 deletions(-)

diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc
index 92e8fe70c12e..fbd68a6cd8c9 100644
--- a/gcc/config/gcn/mkoffload.cc
+++ b/gcc/config/gcn/mkoffload.cc
@@ -53,6 +53,7 @@
 
 /* Extract the EF_AMDGPU_MACH_AMDGCN_GFXnnn from the def file.  */
 enum elf_arch_code {
+  EF_AMDGPU_MACH_AMDGCN_NONE = -1,  /* For generic handling.  */
 #define GCN_DEVICE(name, NAME, ELF_ARCH, ...) \
   EF_AMDGPU_MACH_AMDGCN_ ## NAME = ELF_ARCH,
 #include "gcn-devices.def"
@@ -135,9 +136,8 @@ static struct obstack files_to_cleanup;
 enum offload_abi offload_abi = OFFLOAD_ABI_UNSET;
 const char *offload_abi_host_opts = NULL;
 
-uint32_t elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX900;  // Default GPU architecture.
+enum elf_arch_code elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX900;  // Default GPU 
architecture.
 uint32_t elf_flags = EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4;
-
 static int gcn_stack_size = 0;  /* Zero means use default.  */
 
 /* Delete tempfiles.  */
@@ -782,7 +782,7 @@ compile_native (const char *infile, const char *outfile, 
const char *compiler,
   obstack_ptr_grow (&argv_obstack, ".c");
   if (!offload_abi_host_opts)
 fatal_error (input_location,
-"%<-foffload-abi-host-opts%> not specified.");
+"%<-foffload-abi-host-opts%> not specified");
   obstack_ptr_grow (&argv_obstack, offload_abi_host_opts);
   obstack_ptr_grow (&argv_obstack, infile);
   obstack_ptr_grow (&argv_obstack, "-c");
@@ -796,16 +796,15 @@ compile_native (const char *infile, const char *outfile, 
const char *compiler,
   obstack_free (&argv_obstack, NULL);
 }
 
-static int
+static enum elf_arch_code
 get_arch (const char *str, const char *with_arch_str)
 {
   /* Use the def file to map the name to the elf_arch_code.  */
   if (!str) ;
 #define GCN_DEVICE(name, NAME, ELF, ...) \
   else if (strcmp (str, #name) == 0) \
-return ELF;
+return (enum elf_arch_code) ELF;
 #include "gcn-devices.def"
-#undef GCN_DEVICE
 
   /* else */
   error ("unrecognized argument in option %<-march=%s%>", str);
@@ -839,7 +838,91 @@ get_arch (const char *str, const char *with_arch_str)
 
   exit (FATAL_EXIT_CODE);
 
-  return 0;
+  return EF_AMDGPU_MACH_AMDGCN_NONE;
+}
+
+static const char*
+get_arch_name (enum elf_arch_code arch_code)
+{
+  switch (arch_code)
+{
+#define GCN_DEVICE(name, NAME, ELF, ...) \
+case EF_AMDGPU_MACH_AMDGCN_ ## NAME: \
+  return #name;
+#include "../../gcc/config/gcn/gcn-devices.def"
+default: return NULL;
+}
+}
+
+/* If an generic arch exists and for the chosen arch no (multi)lib is
+   available, print a fatal error - and suggest to compile for the generic
+   version instead.  */
+
+static void
+check_for_missing_lib (enum elf_arch_code elf_arch,
+  enum elf_arch_code default_arch)
+{
+  enum elf_arch_code generic_arch;
+  switch (elf_arch)
+{
+#define GCN_DEVICE(name, NAME, ELF, ISA, XNACK, SRAM, WAVE64, CU, \
+  MAX_ISA_VGPRS, GEN_VER, ARCH_FAM, GEN_MACH, ...) \
+case EF_AMDGPU_MACH_AMDGCN_ ## NAME: \
+  generic_arch = EF_AMDGPU_MACH_AMDGCN_ ## GEN_MACH; break;
+#include "../../gcc/config/gcn/gcn-devices.def"
+default: generic_arch = EF_AMDGPU_MACH_AMDGCN_NONE;
+}
+
+  /* If not generic or the default arch, the library version exists.  */
+  if (generic_arch == EF_AMDGPU_MACH_AMDGCN_NONE || elf_arch == default_a

[gcc r15-7376] Fortran/OpenMP: Add location data to 'sorry' [PR118740]

2025-02-05 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:6f95af4f22b641fbb3509f1436bce811d4e4acad

commit r15-7376-g6f95af4f22b641fbb3509f1436bce811d4e4acad
Author: Tobias Burnus 
Date:   Wed Feb 5 14:03:47 2025 +0100

Fortran/OpenMP: Add location data to 'sorry' [PR118740]

PR fortran/118740

gcc/fortran/ChangeLog:

* openmp.cc (gfc_match_omp_context_selector, 
match_omp_metadirective):
Change sorry to sorry_at and use gfc_current_locus as location.
* trans-openmp.cc (gfc_trans_omp_clauses): Likewise, but use 
n->where.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/append_args-2.f90: Update for line change.

Diff:
---
 gcc/fortran/openmp.cc| 6 --
 gcc/fortran/trans-openmp.cc  | 8 +---
 gcc/testsuite/gfortran.dg/gomp/append_args-2.f90 | 2 +-
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index b1684f841f5b..e8df9d63fec2 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -6536,7 +6536,8 @@ gfc_match_omp_context_selector (gfc_omp_set_selector *oss,
/* FIXME: The "requires" selector was added in OpenMP 5.1.
   Currently only the now-deprecated syntax
   from OpenMP 5.0 is supported.  */
-   sorry ("% selector is not supported yet");
+   sorry_at (gfc_get_location (&gfc_current_locus),
+ "% selector is not supported yet");
return MATCH_ERROR;
  }
else
@@ -6942,7 +6943,8 @@ match_omp_metadirective (bool begin_p)
   gfc_matching_omp_context_selector = false;
 
   if (is_omp_declarative_stmt (directive))
-   sorry ("declarative directive variants are not supported");
+   sorry_at (gfc_get_location (&gfc_current_locus),
+ "declarative directive variants are not supported");
 
   if (gfc_error_flag_test ())
{
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index e29ef85ae398..e9103cd3bac3 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -3345,7 +3345,8 @@ gfc_trans_omp_clauses (stmtblock_t *block, 
gfc_omp_clauses *clauses,
  if (openacc && n->sym->ts.type == BT_CLASS)
{
  if (n->sym->attr.optional)
-   sorry ("optional class parameter");
+   sorry_at (gfc_get_location (&n->where),
+ "optional class parameter");
  tree ptr = gfc_class_data_get (decl);
  ptr = build_fold_indirect_ref (ptr);
  OMP_CLAUSE_DECL (node) = ptr;
@@ -3761,7 +3762,8 @@ gfc_trans_omp_clauses (stmtblock_t *block, 
gfc_omp_clauses *clauses,
gcc_assert (!ref->next);
}
  else
-   sorry ("unhandled expression type");
+   sorry_at (gfc_get_location (&n->where),
+ "unhandled expression type");
}
 
  tree inner = se.expr;
@@ -4041,7 +4043,7 @@ gfc_trans_omp_clauses (stmtblock_t *block, 
gfc_omp_clauses *clauses,
gcc_unreachable ();
}
  else
-   sorry ("unhandled expression");
+   sorry_at (gfc_get_location (&n->where), "unhandled expression");
 
  finalize_map_clause:
 
diff --git a/gcc/testsuite/gfortran.dg/gomp/append_args-2.f90 
b/gcc/testsuite/gfortran.dg/gomp/append_args-2.f90
index a20f610a03dc..7a68977ed4d0 100644
--- a/gcc/testsuite/gfortran.dg/gomp/append_args-2.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/append_args-2.f90
@@ -40,7 +40,7 @@ contains
   subroutine f5 ()
 !$omp declare variant (f1ox) match(user={condition(flag)}) & ! { dg-error 
"the 'append_args' clause can only be specified if the 'dispatch' selector of 
the construct selector set appears in the 'match' clause at .1." }
 !$omp&  append_args ( interop ( target , targetsync) )
-! { dg-error "'q' at .1. must be a nonpointer, nonallocatable scalar 
integer dummy argument of 'omp_interop_kind' kind as it utilized with the 
'append_args' clause at .2." "" { target *-*-* } .-2 }
+! { dg-error "'q' at .1. must be a nonpointer, nonallocatable scalar 
integer dummy argument of 'omp_interop_kind' kind as it utilized with the 
'append_args' clause at .2." "" { target *-*-* } .-1 }
   end subroutine
 
   subroutine f6 (x, y)


[gcc r15-7405] [gcn] Fix gfx906's sramecc setting

2025-02-07 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:fa5544625d585a29463acce1f32a7f6fa13e3431

commit r15-7405-gfa5544625d585a29463acce1f32a7f6fa13e3431
Author: Tobias Burnus 
Date:   Fri Feb 7 10:44:18 2025 +0100

[gcn] Fix gfx906's sramecc setting

When compiling with -g, mkoffload.cc creates a device object file itself;
however, in order that the linker dos not complain, the ELF flags must
match what the compiler / linker does. For gfx906, the assembler defaults
to sramecc = any, but gcn-devices.def contained unsupported, which is not
the same - causing link errors. That's a regression caused by commit
r15-4540-ga6b26e5ea09779 - which can be best seen by looking at the
changes to mkoffload.cc.

Additionally, this commit adds '...' to the GCN_DEVICE #define in gcn.cc
to make it agnostic to the addition of fields.

gcc/ChangeLog:

* config/gcn/gcn-devices.def (GCN_DEVICE): Change sramecc for
gfx906 to 'any'.
* config/gcn/gcn.cc (GCN_DEVICE): Add tailing ... to #define.

Diff:
---
 gcc/config/gcn/gcn-devices.def | 2 +-
 gcc/config/gcn/gcn.cc  | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/config/gcn/gcn-devices.def b/gcc/config/gcn/gcn-devices.def
index 7d47a7b495d4..a8b21a358b48 100644
--- a/gcc/config/gcn/gcn-devices.def
+++ b/gcc/config/gcn/gcn-devices.def
@@ -91,7 +91,7 @@ GCN_DEVICE(gfx900, GFX900, 0x2c, ISA_GCN5,
 
 GCN_DEVICE(gfx906, GFX906, 0x2f, ISA_GCN5,
   /* XNACK default */ HSACO_ATTR_OFF,
-  /* SRAM_ECC default */ HSACO_ATTR_UNSUPPORTED,
+  /* SRAM_ECC default */ HSACO_ATTR_ANY,
   /* WAVE64 mode */ HSACO_ATTR_UNSUPPORTED,
   /* CU mode */ HSACO_ATTR_UNSUPPORTED,
   /* Max ISA VGPRs */ 256,
diff --git a/gcc/config/gcn/gcn.cc b/gcc/config/gcn/gcn.cc
index 4200cfaf0063..82fc6ff1e413 100644
--- a/gcc/config/gcn/gcn.cc
+++ b/gcc/config/gcn/gcn.cc
@@ -101,7 +101,8 @@ static hash_map lds_allocs;
 /* Import all the data from gcn-devices.def.
The PROCESSOR_GFXnnn should be indices for this table.  */
 const struct gcn_device_def gcn_devices[] = {
-#define GCN_DEVICE(name, NAME, ELF, ISA, XNACK, SRAMECC, WAVE64, CU, VGPRS, 
GEN_VER,ARCH_FAM) \
+#define GCN_DEVICE(name, NAME, ELF, ISA, XNACK, SRAMECC, WAVE64, CU, VGPRS, \
+  GEN_VER, ARCH_FAM, ...) \
 {PROCESSOR_ ## NAME, #name, #NAME, ISA, XNACK, SRAMECC, WAVE64, CU, VGPRS, 
\
  GEN_VER, #ARCH_FAM},
 #include "gcn-devices.def"


[gcc r15-7406] [gcn] Add gfx9-generic and generic-associated gfx*

2025-02-07 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:b5a29a93ee29a882c9ed28cb0e6835f97d6f8182

commit r15-7406-gb5a29a93ee29a882c9ed28cb0e6835f97d6f8182
Author: Tobias Burnus 
Date:   Fri Feb 7 11:55:08 2025 +0100

[gcn] Add gfx9-generic and generic-associated gfx*

This patch adds gfx9-generic, completing the gfx*-generic support.
It also adds all gfx* devices that are part of any of the gfx*-generic,
i.e. gfx902, gfx904, gfx909, gfx1031, gfx1032, gfx1033, gfx1034,
gfx1035, gfx1101, gfx1102, gfx1150, gfx1151, gfx1152, and gfx1153.

gcc/ChangeLog:

* config/gcn/gcn-devices.def (GCN_DEVICE): Add gfx9-generic,
gfx902, gfx904, gfx909, gfx1031, gfx1032, gfx1033, gfx1034,
gfx1035, gfx1101, gfx1102, gfx1150, gfx1151, gfx1152, and gfx1153.
Add a currently unused column linking, a specific ISA to a generic
one (if it exists).
* config/gcn/gcn-tables.opt: Regenerate
* doc/invoke.texi (AMD GCN): Add the the new gfc... and the older
gfx{10-3,11}-generic to -march= as 'experimental'.

Diff:
---
 gcc/config/gcn/gcn-devices.def | 202 ++---
 gcc/config/gcn/gcn-tables.opt  |  45 +
 gcc/doc/invoke.texi|  53 +++
 3 files changed, 289 insertions(+), 11 deletions(-)

diff --git a/gcc/config/gcn/gcn-devices.def b/gcc/config/gcn/gcn-devices.def
index a8b21a358b48..af1420382e2f 100644
--- a/gcc/config/gcn/gcn-devices.def
+++ b/gcc/config/gcn/gcn-devices.def
@@ -71,6 +71,10 @@
generated by the used llvm-mc assembler.
   10 "Architecture Family Name"  (string, external)
Used to #define '__GFX<...>__'.
+  11 "GENERIC NAME" (text, external)
+   The name of the generic ISA this device is compatible with or "NONE",
+   where the generic name is the NAME (field 2) of the associated
+   generic device.
 
 Fields marked "external", above, have values defined elsewhere (HSA, ROCM,
 LLVM, ELF, etc.) and must have matching definitions here.  Fields marked
@@ -86,7 +90,30 @@ GCN_DEVICE(gfx900, GFX900, 0x2c, ISA_GCN5,
   /* CU mode */ HSACO_ATTR_UNSUPPORTED,
   /* Max ISA VGPRs */ 256,
   /* Generic code obj version */ 0,  /* non-generic */
-  /* Architecture Family */ GFX9
+  /* Architecture Family */ GFX9,
+  /* Generic Name */ GFX9_GENERIC
+  )
+
+GCN_DEVICE(gfx902, GFX902, 0x2d, ISA_GCN5,
+  /* XNACK default */ HSACO_ATTR_OFF,
+  /* SRAM_ECC default */ HSACO_ATTR_UNSUPPORTED,
+  /* WAVE64 mode */ HSACO_ATTR_UNSUPPORTED,
+  /* CU mode */ HSACO_ATTR_UNSUPPORTED,
+  /* Max ISA VGPRs */ 256,
+  /* Generic code obj version */ 0,  /* non-generic */
+  /* Architecture Family */ GFX9,
+  /* Generic Name */ GFX9_GENERIC
+  )
+
+GCN_DEVICE(gfx904, GFX904, 0x2e, ISA_GCN5,
+  /* XNACK default */ HSACO_ATTR_OFF,
+  /* SRAM_ECC default */ HSACO_ATTR_UNSUPPORTED,
+  /* WAVE64 mode */ HSACO_ATTR_UNSUPPORTED,
+  /* CU mode */ HSACO_ATTR_UNSUPPORTED,
+  /* Max ISA VGPRs */ 256,
+  /* Generic code obj version */ 0,  /* non-generic */
+  /* Architecture Family */ GFX9,
+  /* Generic Name */ GFX9_GENERIC
   )
 
 GCN_DEVICE(gfx906, GFX906, 0x2f, ISA_GCN5,
@@ -96,7 +123,8 @@ GCN_DEVICE(gfx906, GFX906, 0x2f, ISA_GCN5,
   /* CU mode */ HSACO_ATTR_UNSUPPORTED,
   /* Max ISA VGPRs */ 256,
   /* Generic code obj version */ 0,  /* non-generic */
-  /* Architecture Family */ GFX9
+  /* Architecture Family */ GFX9,
+  /* Generic Name */ GFX9_GENERIC
   )
 
 GCN_DEVICE(gfx908, GFX908, 0x30, ISA_CDNA1,
@@ -106,7 +134,19 @@ GCN_DEVICE(gfx908, GFX908, 0x30, ISA_CDNA1,
   /* CU mode */ HSACO_ATTR_UNSUPPORTED,
   /* Max ISA VGPRs */ 256,
   /* Generic code obj version */ 0,  /* non-generic */
-  /* Architecture Family */ GFX9
+  /* Architecture Family */ GFX9,
+  /* Generic Name */ NONE
+  )
+
+GCN_DEVICE(gfx909, GFX909, 0x31, ISA_GCN5,
+  /* XNACK default */ HSACO_ATTR_ANY,
+  /* SRAM_ECC default */ HSACO_ATTR_UNSUPPORTED,
+  /* WAVE64 mode */ HSACO_ATTR_UNSUPPORTED,
+  /* CU mode */ HSACO_ATTR_UNSUPPORTED,
+  /* Max ISA VGPRs */ 256,
+  /* Generic code obj version */ 0,  /* non-generic */
+  /* Architecture Family */ GFX9,
+  /* Generic Name */ GFX9_GENERIC
   )
 
 GCN_DEVICE(gfx90a, GFX90A, 0x3f, ISA_CDNA2,
@@ -116,7 +156,8 @@ GCN_DEVICE(gfx90a, GFX90A, 0x3f, ISA_CDNA2,
   /* CU mode */ HSACO_ATTR_UNSUPPORTED,
   /* Max ISA VGPRs */ 512,
   /* Generic code obj version */ 0,  /* non-generic */
-  /* Architecture Family */ GFX9
+  /* Architecture Family */ GFX9,
+  /* Generic Name */ NONE
   )
 
 GCN_DEVICE(gfx90c, GFX90C, 0x32, ISA_GCN5

[gcc r15-7409] [GCN] Handle generic ISA names in libgomp's plugin-gcn.c

2025-02-07 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:8561e4e2903ae0b4aff1ed1dc9e9871c89df6b43

commit r15-7409-g8561e4e2903ae0b4aff1ed1dc9e9871c89df6b43
Author: Tobias Burnus 
Date:   Fri Feb 7 13:20:25 2025 +0100

[GCN] Handle generic ISA names in libgomp's plugin-gcn.c

libgomp/ChangeLog:

* plugin/plugin-gcn.c (ELFABIVERSION_AMDGPU_HSA_V6,
EF_AMDGPU_GENERIC_VERSION_V, EF_AMDGPU_GENERIC_VERSION_OFFSET,
GET_GENERIC_VERSION): New #define.
(elf_gcn_isa_is_generic): New.
(isa_matches_agent): Accept all generic code objects on the first
go; extend the diagnostic and handle runtime-failed case.
(create_and_finalize_hsa_program): Call it also after loading
the code failed, pass the status.

Diff:
---
 libgomp/plugin/plugin-gcn.c | 118 ++--
 1 file changed, 92 insertions(+), 26 deletions(-)

diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c
index 8015a6f80f3d..5c65778191a6 100644
--- a/libgomp/plugin/plugin-gcn.c
+++ b/libgomp/plugin/plugin-gcn.c
@@ -66,6 +66,14 @@
 #define R_AMDGPU_RELATIVE6413  /* B + A  */
 #endif
 
+#define ELFABIVERSION_AMDGPU_HSA_V64
+
+#define EF_AMDGPU_GENERIC_VERSION_V0xff00  /* Mask.  */
+#define EF_AMDGPU_GENERIC_VERSION_OFFSET   24
+
+#define GET_GENERIC_VERSION(VAR) ((VAR & EF_AMDGPU_GENERIC_VERSION_V) \
+ >> EF_AMDGPU_GENERIC_VERSION_OFFSET)
+
 /* GCN specific definitions for asynchronous queues.  */
 
 #define ASYNC_QUEUE_SIZE 64
@@ -242,7 +250,7 @@ struct kernel_dispatch
 };
 
 /* Structure of the kernargs segment, supporting console output.
- 
+
This needs to match the definitions in Newlib, and the expectations
in libgomp target code.  */
 
@@ -1668,6 +1676,13 @@ elf_gcn_isa_field (Elf64_Ehdr *image)
   return image->e_flags & EF_AMDGPU_MACH_MASK;
 }
 
+static int
+elf_gcn_isa_is_generic (Elf64_Ehdr *image)
+{
+  return (image->e_ident[8] == ELFABIVERSION_AMDGPU_HSA_V6
+ && GET_GENERIC_VERSION (image->e_flags));
+}
+
 /* Returns the name that the HSA runtime uses for the ISA or NULL if we do not
support the ISA. */
 
@@ -2399,38 +2414,88 @@ init_basic_kernel_info (struct kernel_info *kernel,
   return true;
 }
 
-/* Check that the GCN ISA of the given image matches the ISA of the agent. */
+/* If status is SUCCESS, assume that the code runs if either the ISA of agent
+   and code is the same - or it is generic code.
+   Otherwise, execution failed with the provided status code; try to give
+   some useful diagnostic.  */
 
 static bool
-isa_matches_agent (struct agent_info *agent, Elf64_Ehdr *image)
+isa_matches_agent (struct agent_info *agent, Elf64_Ehdr *image,
+  hsa_status_t status)
 {
+  /* Generic image - assume that it works and only return to here
+ when it fails, i.e. fatal == true.  */
+  if (status == HSA_STATUS_SUCCESS && elf_gcn_isa_is_generic (image))
+return true;
+
   int isa_field = elf_gcn_isa_field (image);
-  const char* isa_s = isa_name (isa_field);
-  if (!isa_s)
+  if (status == HSA_STATUS_SUCCESS && isa_field == agent->device_isa)
+return true;
+
+  /* If we get here, either the binary is non-generic and has a mismatch of
+ the ISA - or is generic but not handled by the ROCm (e.g. because ROCm
+ is too old).  */
+
+  char msg[340];
+  char agent_isa_xs[8];
+  char device_isa_xs[8];
+  const char *agent_isa_s = isa_name (agent->device_isa);
+  const char *device_isa_s = isa_name (isa_field);
+  if (agent_isa_s == NULL)
 {
-  hsa_error ("Unsupported ISA in GCN code object.", HSA_STATUS_ERROR);
-  return false;
+  snprintf (agent_isa_xs, sizeof agent_isa_xs,
+   "0x%X", agent->device_isa);
+  agent_isa_s = agent_isa_xs;
 }
-
-  if (isa_field != agent->device_isa)
+  if (device_isa_s == NULL)
 {
-  char msg[204];
-  const char *agent_isa_s = isa_name (agent->device_isa);
-  assert (agent_isa_s);
-
-  snprintf (msg, sizeof msg,
-   "GCN code object ISA '%s' does not match GPU ISA '%s' "
-   "(device %d).\n"
-   "Try to recompile with '-foffload-options=-march=%s',\n"
-   "or use ROCR_VISIBLE_DEVICES to disable incompatible "
-   "devices.\n",
-   isa_s, agent_isa_s, agent->device_id, agent_isa_s);
-
-  hsa_error (msg, HSA_STATUS_ERROR);
-  return false;
+  snprintf (device_isa_xs, sizeof device_isa_xs, "0x%X", isa_field);
+  device_isa_s = device_isa_xs;
 }
 
-  return true;
+  /* Some error which should be unrelated to the ISA.  */
+  if (status != HSA_STATUS_SUCCESS
+  && status != HSA_STATUS_ERROR_INVALID_CODE_OBJECT
+  && status != HSA_STATUS_ERROR_INVALID_ISA_NAME
+  && status != HSA_STATUS_ERROR_INCOMPATIBLE_ARGUMENTS)
+snprintf (msg, sizeof msg,
+ "Could not load GCN code object with ISA %s on GPU with "
+ 

[gcc r15-7410] [gcn] Fix the output amdhsa.version

2025-02-07 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:6aa3329b3430c6362ddf51e403d147e0b10d7401

commit r15-7410-g6aa3329b3430c6362ddf51e403d147e0b10d7401
Author: Tobias Burnus 
Date:   Fri Feb 7 13:22:08 2025 +0100

[gcn] Fix the output amdhsa.version

The amdhsa.version depends on the code object version; while V3 had 1.0,
V4 has 1.1 and V5 (and V6) have 1.2. GCC used 1.0 but generated since
a while either V4 or, with -march=gfx...-generic, V6. Now it uses the
proper version again.

gcc/ChangeLog:

* config/gcn/gcn.cc (gcn_hsa_declare_function_name): Update
'amdhsa.version' output to match used code version.
* config/gcn/gen-gcn-device-macros.awk: Add a comment to
crosslink.

Diff:
---
 gcc/config/gcn/gcn.cc| 17 +++--
 gcc/config/gcn/gen-gcn-device-macros.awk |  4 +++-
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/gcc/config/gcn/gcn.cc b/gcc/config/gcn/gcn.cc
index 82fc6ff1e413..b0c06d5e6320 100644
--- a/gcc/config/gcn/gcn.cc
+++ b/gcc/config/gcn/gcn.cc
@@ -6671,12 +6671,17 @@ gcn_hsa_declare_function_name (FILE *file, const char 
*name,
 
 #if 1
   /* The following is YAML embedded in assembler; tabs are not allowed.  */
-  fputs (".amdgpu_metadata\n"
-"amdhsa.version:\n"
-"  - 1\n"
-"  - 0\n"
-"amdhsa.kernels:\n"
-"  - .name: ", file);
+
+  /* 'amdhsa.version': code object V3 = 1.0, V4 = 1.1, V5/V6 = 1.2.  */
+  /* Keep in sync with 'amdhsa-code-object' in gen-gcn-device-macros.awk.  */
+  fprintf (file,
+  ".amdgpu_metadata\n"
+  "amdhsa.version:\n"
+  "  - 1\n"
+  "  - %d\n"
+  "amdhsa.kernels:\n"
+  "  - .name: ",
+  gcn_devices[gcn_arch].generic_version ? 2 /* V6 */ : 1 /* V4 */);
   assemble_name (file, name);
   fputs ("\n.symbol: ", file);
   assemble_name (file, name);
diff --git a/gcc/config/gcn/gen-gcn-device-macros.awk 
b/gcc/config/gcn/gen-gcn-device-macros.awk
index aa271004c27b..d227e6fcedfd 100644
--- a/gcc/config/gcn/gen-gcn-device-macros.awk
+++ b/gcc/config/gcn/gen-gcn-device-macros.awk
@@ -117,7 +117,9 @@ BEGIN {
 # same. - LLVM <= 17 defaults to 4 while LLVM >= 18 defaults to 5.
 # GCC supports LLVM >= 13.0.1 and only LLVM >= 14 supports version 5.
 # Code object V6 is supported since LLVM 19.
-
+#
+# Keep in sync with 'amdhsa.version' in gcn.cc
+#
 END {
   print ""
   print ""


[gcc r15-6082] plugin/plugin-gcn.c: Fix error handling of GOMP_OFFLOAD_openacc_async_construct

2024-12-10 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:7a12dc695b1ae70f9fc99baf95b7188af6515ed3

commit r15-6082-g7a12dc695b1ae70f9fc99baf95b7188af6515ed3
Author: Tobias Burnus 
Date:   Tue Dec 10 16:16:04 2024 +0100

plugin/plugin-gcn.c: Fix error handling of 
GOMP_OFFLOAD_openacc_async_construct

Follow up to r15-5392-g884637b6362391. As the name implies,
GOMP_OFFLOAD_openacc_async_construct is also externally called.
Hence, partially revert previous commit to permit unlocking handling
in oacc-async.c's lookup_goacc_asyncqueue by not failing fatally.

Hence, also the other (indirect) callers had to be updated:
GOMP_OFFLOAD_dev2dev fails now with 'false' and
GOMP_OFFLOAD_async_run fatally.

libgomp/ChangeLog:

* plugin/plugin-gcn.c (GOMP_OFFLOAD_dev2dev, 
GOMP_OFFLOAD_async_run):
Handle omp_async_queue == NULL after call to maybe_init_omp_async.
(GOMP_OFFLOAD_openacc_async_construct): Use error not fatal error,
partially reverting r15-5392.

Diff:
---
 libgomp/plugin/plugin-gcn.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c
index d26b93657bf6..239acf8cb750 100644
--- a/libgomp/plugin/plugin-gcn.c
+++ b/libgomp/plugin/plugin-gcn.c
@@ -3939,6 +3939,8 @@ GOMP_OFFLOAD_dev2dev (int device, void *dst, const void 
*src, size_t n)
 {
   struct agent_info *agent = get_agent_info (device);
   maybe_init_omp_async (agent);
+  if (!agent->omp_async_queue)
+   return false;
   queue_push_copy (agent->omp_async_queue, dst, src, n);
   return true;
 }
@@ -4350,6 +4352,8 @@ GOMP_OFFLOAD_async_run (int device, void *tgt_fn, void 
*tgt_vars,
 }
 
   maybe_init_omp_async (agent);
+  if (!agent->omp_async_queue)
+GOMP_PLUGIN_fatal ("Asynchronous queue initialization failed");
   queue_push_launch (agent->omp_async_queue, kernel, tgt_vars, kla);
   queue_push_callback (agent->omp_async_queue,
   GOMP_PLUGIN_target_task_completion, async_data);
@@ -4388,9 +4392,7 @@ GOMP_OFFLOAD_openacc_async_exec (void (*fn_ptr) (void *),
   gcn_exec (kernel, devaddrs, dims, targ_mem_desc, true, aq);
 }
 
-/* Create a new asynchronous thread and queue for running future kernels;
-   issues a fatal error if the queue cannot be created as all callers expect
-   that the queue exists.  */
+/* Create a new asynchronous thread and queue for running future kernels.  */
 
 struct goacc_asyncqueue *
 GOMP_OFFLOAD_openacc_async_construct (int device)
@@ -4418,17 +4420,17 @@ GOMP_OFFLOAD_openacc_async_construct (int device)
 
   if (pthread_mutex_init (&aq->mutex, NULL))
 {
-  GOMP_PLUGIN_fatal ("Failed to initialize a GCN agent queue mutex");
+  GOMP_PLUGIN_error ("Failed to initialize a GCN agent queue mutex");
   return NULL;
 }
   if (pthread_cond_init (&aq->queue_cond_in, NULL))
 {
-  GOMP_PLUGIN_fatal ("Failed to initialize a GCN agent queue cond");
+  GOMP_PLUGIN_error ("Failed to initialize a GCN agent queue cond");
   return NULL;
 }
   if (pthread_cond_init (&aq->queue_cond_out, NULL))
 {
-  GOMP_PLUGIN_fatal ("Failed to initialize a GCN agent queue cond");
+  GOMP_PLUGIN_error ("Failed to initialize a GCN agent queue cond");
   return NULL;
 }


[gcc r15-6336] OpenMP: Add declare variant's 'append_args' clause in C/C++

2024-12-18 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:12dd892b1a3ad719e76e6ca40f8cbc224610b849

commit r15-6336-g12dd892b1a3ad719e76e6ca40f8cbc224610b849
Author: Tobias Burnus 
Date:   Wed Dec 18 09:25:50 2024 +0100

OpenMP: Add declare variant's 'append_args' clause in C/C++

Add the append_args clause of 'declare variant' to C and C++,
fix/improve diagnostic for 'interop' clause and 'declare_variant'
clauses on the way.

Cleanup dispatch handling in gimplify_call_expr a bit and
partially handle 'append_args'. (Namely, those parts that
do not require libraries calls, i.e. a dispatch construct
where the 'device' and 'interop' clause has been specified.)

The sorry can be removed once an enum value like
  omp_ipr_(ompx_gnu_)omp_device_num (cf. OpenMP Spec Issue 4451)
has to be added to the runtime side such that omp_get_interop_int
returns the device number of an interop object (as passed to
dispatch via the interop clause); and a call to GOMP_interop
has to be added to create interop objects. Once available, only
a very localized change in gimplify_call_expr is required to
claim for full support. - And Fortran parsing support.

gcc/c-family/ChangeLog:

* c-omp.cc (c_omp_interop_t_p): Handle error_mark_node.

gcc/c/ChangeLog:

* c-parser.cc (c_parser_omp_clause_init_modifiers): New;
split of from ...
(c_parser_omp_clause_init): ... here; call it.
(c_finish_omp_declare_variant): Parse 'append_args' clause.
(c_parser_omp_clause_interop): Set tree used/read.

gcc/cp/ChangeLog:

* decl.cc (omp_declare_variant_finalize_one): Handle
append_args.
* parser.cc (cp_parser_omp_clause_init_modifiers): New;
split of from ...
(cp_parser_omp_clause_init):  ... here; call it.
(cp_parser_omp_all_clauses): Replace interop parsing by
a call to ...
(cp_parser_omp_clause_interop): ... this new function;
set tree used/read.
(cp_finish_omp_declare_variant): Parse 'append_args' clause.
(cp_parser_omp_declare): Update comment.
* pt.cc (tsubst_attribute, tsubst_omp_clauses): Handle template
substitution also for declare variant's append_args clause,
using for 'init' the same code as for interop's init clause.

gcc/ChangeLog:

* gimplify.cc (gimplify_call_expr): Update for OpenMP's
append_args; cleanup of OpenMP's dispatch clause handling.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/declare-variant-2.c: Update dg-error msg.
* c-c++-common/gomp/dispatch-12.c: Likewise.
* c-c++-common/gomp/dispatch-11.c: Likewise and extend a bit.
* c-c++-common/gomp/append-args-1.c: New test.
* c-c++-common/gomp/append-args-2.c: New test.
* c-c++-common/gomp/append-args-3.c: New test.
* g++.dg/gomp/append-args-1.C: New test.
* g++.dg/gomp/append-args-2.C: New test.
* g++.dg/gomp/append-args-3.C: New test.

Diff:
---
 gcc/c-family/c-omp.cc  |   2 +
 gcc/c/c-parser.cc  | 397 +++--
 gcc/cp/decl.cc |  86 -
 gcc/cp/parser.cc   | 287 ++-
 gcc/cp/pt.cc   |  11 +-
 gcc/gimplify.cc| 162 +++--
 gcc/testsuite/c-c++-common/gomp/append-args-1.c|  83 +
 gcc/testsuite/c-c++-common/gomp/append-args-2.c|   8 +
 gcc/testsuite/c-c++-common/gomp/append-args-3.c|  57 +++
 .../c-c++-common/gomp/declare-variant-2.c  |   4 +-
 gcc/testsuite/c-c++-common/gomp/dispatch-11.c  |  58 ++-
 gcc/testsuite/c-c++-common/gomp/dispatch-12.c  |  20 +-
 gcc/testsuite/g++.dg/gomp/append-args-1.C  | 134 +++
 gcc/testsuite/g++.dg/gomp/append-args-2.C  |  53 +++
 gcc/testsuite/g++.dg/gomp/append-args-3.C  | 100 ++
 15 files changed, 1197 insertions(+), 265 deletions(-)

diff --git a/gcc/c-family/c-omp.cc b/gcc/c-family/c-omp.cc
index 7e20e5a50829..5f2db146fed5 100644
--- a/gcc/c-family/c-omp.cc
+++ b/gcc/c-family/c-omp.cc
@@ -669,6 +669,8 @@ c_finish_omp_atomic (location_t loc, enum tree_code code,
 bool
 c_omp_interop_t_p (tree type)
 {
+  if (type == error_mark_node)
+return false;
   type = TYPE_MAIN_VARIANT (type);
   return (TREE_CODE (type) == ENUMERAL_TYPE
  && TYPE_NAME (type)
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index d0235809fb38..42fa383c57f5 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -20630,6 +20630,73 @@ c_parser_omp_modifier_prefer_type (c_parser *parser)
   return res;
 }
 
+/* OpenMP 5.1
+ modifiers of the 'init' clause, used by the 'init' and the
+ 'append_args' c

[gcc r15-6178] OpenMP: Enable has_device_addr clause for 'dispatch' in C/C++

2024-12-12 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:2cbb2408a830a63fbd901a4da3bfd341cec4b6ef

commit r15-6178-g2cbb2408a830a63fbd901a4da3bfd341cec4b6ef
Author: Tobias Burnus 
Date:   Thu Dec 12 18:58:59 2024 +0100

OpenMP: Enable has_device_addr clause for 'dispatch' in C/C++

The 'has_device_addr' of 'dispatch' has to be seen in conjunction with the
'need_device_addr' modifier to the 'adjust_args' clause of 'declare 
variant'.
As the latter has not yet been implemented, 'has_device_addr' has no real
effect. However, to prepare for 'need_device_addr' and as service to the 
user:

For C, where 'need_device_addr' is not permitted (contrary to C++ and 
Fortran),
a note is output when then the user tries to use it (alongside the existing
error that either 'nothing' or 'need_device_ptr' was expected).

And, on the ME side, is is lightly handled by diagnosing when - for the
same argument - there is a mismatch between the variant's adjust_args
'need_device_ptr' modifier and dispatch having an 'has_device_addr' clause
(or likewise for need_device_addr with is_device_ptr) as, according to the
spec, those are completely separate.
Thus, 'dispatch' will still do the host to device pointer conversion for
a 'need_device_ptr' argument, even if it appeared in a 'has_device_addr'
clause.

gcc/c/ChangeLog:

* c-parser.cc (OMP_DISPATCH_CLAUSE_MASK): Add has_device_addr 
clause.
(c_finish_omp_declare_variant): Add an 'inform' telling the user 
that
'need_device_addr' is invalid for C.

gcc/cp/ChangeLog:

* parser.cc (OMP_DISPATCH_CLAUSE_MASK): Add has_device_addr clause.

gcc/ChangeLog:

* gimplify.cc (gimplify_call_expr): When handling OpenMP's dispatch,
add diagnostic when there is a ptr vs. addr mismatch between
need_device_{addr,ptr} and {is,has}_device_{ptr,addr}, respectively.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/adjust-args-3.c: New test.
* gcc.dg/gomp/adjust-args-2.c: New test.

Diff:
---
 gcc/c/c-parser.cc   |  4 ++
 gcc/cp/parser.cc|  1 +
 gcc/gimplify.cc | 75 --
 gcc/testsuite/c-c++-common/gomp/adjust-args-3.c | 85 +
 gcc/testsuite/gcc.dg/gomp/adjust-args-2.c   |  5 ++
 5 files changed, 152 insertions(+), 18 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 4ec0ee85ac49..d0235809fb38 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -25271,6 +25271,7 @@ c_parser_omp_dispatch_body (c_parser *parser)
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)   
\
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOVARIANTS)   
\
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOCONTEXT)
\
+   | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HAS_DEVICE_ADDR)  
\
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INTEROP)  
\
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR)
\
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
@@ -26963,6 +26964,9 @@ c_finish_omp_declare_variant (c_parser *parser, tree 
fndecl, tree parms)
{
  error_at (c_parser_peek_token (parser)->location,
"expected % or %");
+ if (strcmp (p, "need_device_addr") == 0)
+   inform (c_parser_peek_token (parser)->location,
+   "% is not valid for C");
  goto fail;
}
}
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 8a3472a4b34e..15a5253b50d1 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -49924,6 +49924,7 @@ cp_parser_omp_dispatch_body (cp_parser *parser)
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)   
\
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOVARIANTS)   
\
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOCONTEXT)
\
+   | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HAS_DEVICE_ADDR)  
\
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INTEROP)  
\
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR)
\
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index 8495c45eddbb..dd0d992a9581 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -4124,27 +4124,39 @@ gimplify_call_expr (tree *expr_p, gimple_seq *pre_p, 
bool want_value)
arg_types = TREE_CHAIN (arg_types);
 
  bool need_device_ptr = false;
- for (tree arg
-  = TREE_PURPOSE (TREE_VALUE (adjust_args_list));
-  arg != NULL; arg = TREE

  1   2   3   4   >