[gcc/aoliva/heads/testme] (5 commits) make_type_from_size avoid TYPE_DEBUG_TYPE / TREE_TYPE loops

2024-06-28 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 8f9705aadea... make_type_from_size avoid TYPE_DEBUG_TYPE / TREE_TYPE loops

It previously pointed to:

 dec24e79d4e... Avoid dropping bits from num/den in fixed-point types

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  dec24e7... Avoid dropping bits from num/den in fixed-point types
  9235979... Map unpacked type to packed deduped type for debug info
  c0c2a61... make_type_from_size: fix compare for type reuse
  d16dbd4... Follow only proper TYPE_DEBUG_TYPE


Summary of changes (added commits):
---

  8f9705a... make_type_from_size avoid TYPE_DEBUG_TYPE / TREE_TYPE loops
  2e886d9... Map unpacked type to packed deduped type for debug info
  cdfb1ef... make_type_from_size: fix compare for type reuse
  0803a2d... Follow only proper TYPE_DEBUG_TYPE
  d47c7fe... Avoid dropping bits from num/den in fixed-point types


[gcc(refs/users/aoliva/heads/testme)] Avoid dropping bits from num/den in fixed-point types

2024-06-28 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:d47c7fee5148a9ec1226bba9bc85ab9a3366e7e2

commit d47c7fee5148a9ec1226bba9bc85ab9a3366e7e2
Author: Alexandre Oliva 
Date:   Thu Jun 27 09:11:54 2024 -0300

Avoid dropping bits from num/den in fixed-point types

We used to use an unsigned 128-bit type to hold the numerator and
denominator used to represent the delta of a fixed-point type in debug
information, but there are cases in which that was not enough, and
more significant bits silently overflowed and got omitted from debug
information.

Introduce a mode in which UI_to_gnu selects a wide-enough unsigned
type, and use that to convert numerator and denominator.


for  gcc/ada/ChangeLog

* gcc-interface/cuintp.cc (UI_To_gnu): Add mode that selects a
wide enough unsigned type.
* gcc-interface/decl.cc (gnat_to_gnu_entity): Use it for
numerator and denominator of fixed-point types.

Diff:
---
 gcc/ada/gcc-interface/cuintp.cc | 47 ++---
 gcc/ada/gcc-interface/decl.cc   | 15 +
 2 files changed, 41 insertions(+), 21 deletions(-)

diff --git a/gcc/ada/gcc-interface/cuintp.cc b/gcc/ada/gcc-interface/cuintp.cc
index cdf6c019750..ad345096282 100644
--- a/gcc/ada/gcc-interface/cuintp.cc
+++ b/gcc/ada/gcc-interface/cuintp.cc
@@ -35,6 +35,7 @@
 #include "tree.h"
 #include "inchash.h"
 #include "fold-const.h"
+#include "stor-layout.h"
 
 #include "ada.h"
 #include "types.h"
@@ -67,7 +68,8 @@ build_cst_from_int (tree type, HOST_WIDE_INT low)
 /* Similar to UI_To_Int, but return a GCC INTEGER_CST or REAL_CST node,
depending on whether TYPE is an integral or real type.  Overflow is tested
by the constant-folding used to build the node.  TYPE is the GCC type of
-   the resulting node.  */
+   the resulting node.  If TYPE is NULL, an unsigned integer type wide enough
+   to hold the entire constant is selected.  */
 
 tree
 UI_To_gnu (Uint Input, tree type)
@@ -77,8 +79,10 @@ UI_To_gnu (Uint Input, tree type)
  any such possible value for intermediate computations and then rely on a
  conversion back to TYPE to perform the bias adjustment when need be.  */
   tree comp_type
-= TREE_CODE (type) == INTEGER_TYPE && TYPE_BIASED_REPRESENTATION_P (type)
-  ? get_base_type (type) : type;
+= (!type ? gnat_type_for_size (32, 0)
+   : (TREE_CODE (type) == INTEGER_TYPE
+ && TYPE_BIASED_REPRESENTATION_P (type))
+   ? get_base_type (type) : type);
   tree gnu_ret;
 
   if (Input <= Uint_Direct_Last)
@@ -88,6 +92,7 @@ UI_To_gnu (Uint Input, tree type)
   Int Idx = (*Uints_Ptr)[Input - Uint_Table_Start].Loc;
   Pos Length = (*Uints_Ptr)[Input - Uint_Table_Start].Length;
   Int First = (*Udigits_Ptr)[Idx];
+  tree_code code = First < 0 ? MINUS_EXPR : PLUS_EXPR;
   tree gnu_base;
 
   gcc_assert (Length > 0);
@@ -99,26 +104,34 @@ UI_To_gnu (Uint Input, tree type)
 convert the final result back to the incoming type later on.  */
   if (!SCALAR_FLOAT_TYPE_P (comp_type) && TYPE_PRECISION (comp_type) < 32)
comp_type = gnat_type_for_size (32, 0);
+  else if (!type && TYPE_UNSIGNED (comp_type))
+   /* Choose a signed type, so that we can detect overflow.  */
+   comp_type = make_signed_type (TYPE_PRECISION (comp_type));
 
   gnu_base = build_cst_from_int (comp_type, Base);
 
   gnu_ret = build_cst_from_int (comp_type, First);
-  if (First < 0)
-   for (Idx++, Length--; Length; Idx++, Length--)
- gnu_ret = fold_build2 (MINUS_EXPR, comp_type,
-fold_build2 (MULT_EXPR, comp_type,
- gnu_ret, gnu_base),
-build_cst_from_int (comp_type,
-(*Udigits_Ptr)[Idx]));
-  else
-   for (Idx++, Length--; Length; Idx++, Length--)
- gnu_ret = fold_build2 (PLUS_EXPR, comp_type,
-fold_build2 (MULT_EXPR, comp_type,
- gnu_ret, gnu_base),
-build_cst_from_int (comp_type,
-(*Udigits_Ptr)[Idx]));
+  for (Idx++, Length--; Length; Idx++, Length--)
+   for (;;)
+ {
+   tree next_ret = fold_build2 (code, comp_type,
+fold_build2 (MULT_EXPR, comp_type,
+ gnu_ret, gnu_base),
+build_cst_from_int
+(comp_type, (*Udigits_Ptr)[Idx]));
+   if (!TREE_OVERFLOW (next_ret) || type)
+ {
+   gnu_ret = next_ret;
+   break;
+ }
+   comp_type = make_signed_type (TYPE_PRECISION (comp_type) * 2);
+   gnu_base = convert (comp_type, gnu_base);
+   gnu_ret = 

[gcc(refs/users/aoliva/heads/testme)] Follow only proper TYPE_DEBUG_TYPE

2024-06-28 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:0803a2d3d173cf0153d9c6777b42f54d2a193d96

commit 0803a2d3d173cf0153d9c6777b42f54d2a193d96
Author: Alexandre Oliva 
Date:   Thu Jun 27 09:10:29 2024 -0300

Follow only proper TYPE_DEBUG_TYPE

TYPE_DEBUG_TYPE's storage is shared with other sorts of references to
types, so it shouldn't be accessed unless TYPE_CAN_HAVE_DEBUG_TYPE_P
holds.


for  gcc/ada/ChangeLog

* gcc-interface/misc.cc (gnat_get_array_descr_info): Only follow
TYPE_DEBUG_TYPE if TYPE_CAN_HAVE_DEBUG_TYPE_P.

Diff:
---
 gcc/ada/gcc-interface/misc.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/gcc-interface/misc.cc b/gcc/ada/gcc-interface/misc.cc
index 4f6f6774fe7..f77629ce70b 100644
--- a/gcc/ada/gcc-interface/misc.cc
+++ b/gcc/ada/gcc-interface/misc.cc
@@ -967,7 +967,8 @@ gnat_get_array_descr_info (const_tree const_type,
 
   while (true)
{
- if (TYPE_DEBUG_TYPE (source_element_type))
+ if (TYPE_CAN_HAVE_DEBUG_TYPE_P (source_element_type)
+ && TYPE_DEBUG_TYPE (source_element_type))
source_element_type = TYPE_DEBUG_TYPE (source_element_type);
  else if (TYPE_IS_PADDING_P (source_element_type))
source_element_type


[gcc(refs/users/aoliva/heads/testme)] make_type_from_size: fix compare for type reuse

2024-06-28 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:cdfb1ef5b6c21a89bc518a170d359169f1e28fde

commit cdfb1ef5b6c21a89bc518a170d359169f1e28fde
Author: Alexandre Oliva 
Date:   Thu Jun 27 09:11:01 2024 -0300

make_type_from_size: fix compare for type reuse

When make_type_from_size is called with a biased type, for an entity
that isn't explicitly biased, we may refrain from reusing the given
type because it doesn't seem to match, and then proceed to create an
exact copy of that type.

Compute earlier the biased status of the expected type, early enough
for the suitability check of the given type.  Modify for_biased
instead of biased_p, so that biased_p remains with the given type's
status for the comparison.


for  gcc/ada/ChangeLog

* gcc-interface/utils.cc (make_type_from_size): Fix type reuse
by combining biased_p and for_biased earlier.  Hold the
combination in for_biased, adjusting later uses.

Diff:
---
 gcc/ada/gcc-interface/utils.cc | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/gcc-interface/utils.cc b/gcc/ada/gcc-interface/utils.cc
index 0eb9af8d4a2..d8d42f57b89 100644
--- a/gcc/ada/gcc-interface/utils.cc
+++ b/gcc/ada/gcc-interface/utils.cc
@@ -1383,6 +1383,11 @@ make_type_from_size (tree type, tree size_tree, bool 
for_biased)
   biased_p = (TREE_CODE (type) == INTEGER_TYPE
  && TYPE_BIASED_REPRESENTATION_P (type));
 
+  /* FOR_BIASED initially refers to the entity's representation,
+not to its type's.  The type we're to return must take both
+into account.  */
+  for_biased |= biased_p;
+
   /* Integer types with precision 0 are forbidden.  */
   if (size == 0)
size = 1;
@@ -1394,12 +1399,10 @@ make_type_from_size (tree type, tree size_tree, bool 
for_biased)
  || size > (Enable_128bit_Types ? 128 : LONG_LONG_TYPE_SIZE))
break;
 
-  biased_p |= for_biased;
-
   /* The type should be an unsigned type if the original type is unsigned
 or if the lower bound is constant and non-negative or if the type is
 biased, see E_Signed_Integer_Subtype case of gnat_to_gnu_entity.  */
-  if (type_unsigned_for_rm (type) || biased_p)
+  if (type_unsigned_for_rm (type) || for_biased)
new_type = make_unsigned_type (size);
   else
new_type = make_signed_type (size);
@@ -1409,7 +1412,7 @@ make_type_from_size (tree type, tree size_tree, bool 
for_biased)
   /* Copy the name to show that it's essentially the same type and
 not a subrange type.  */
   TYPE_NAME (new_type) = TYPE_NAME (type);
-  TYPE_BIASED_REPRESENTATION_P (new_type) = biased_p;
+  TYPE_BIASED_REPRESENTATION_P (new_type) = for_biased;
   SET_TYPE_RM_SIZE (new_type, bitsize_int (size));
   return new_type;


[gcc(refs/users/aoliva/heads/testme)] Map unpacked type to packed deduped type for debug info

2024-06-28 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:2e886d9baca052fdb7957b05697d0bdbf847c251

commit 2e886d9baca052fdb7957b05697d0bdbf847c251
Author: Alexandre Oliva 
Date:   Thu Jun 27 09:11:27 2024 -0300

Map unpacked type to packed deduped type for debug info

Avoid creating unnecessary copies of types in make_type_from_size.
Cache the packed version of a biased type in TYPE_DEBUG_TYPE, so as to
map the unpacked type to it.


for  gcc/ada/ChangeLog

* gcc-interface/utils.cc (make_type_from_size): Cache packed
variant, and map unpacked type to it in debug info.

for  gcc/testsuite/ChangeLog

* gnat.dg/bias1.adb: Count occurrences of -7.*DW_AT_GNU_bias.

Diff:
---
 gcc/ada/gcc-interface/utils.cc  | 19 +++
 gcc/testsuite/gnat.dg/bias1.adb |  3 ++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/gcc-interface/utils.cc b/gcc/ada/gcc-interface/utils.cc
index d8d42f57b89..daf8d7ccdc5 100644
--- a/gcc/ada/gcc-interface/utils.cc
+++ b/gcc/ada/gcc-interface/utils.cc
@@ -1399,6 +1399,15 @@ make_type_from_size (tree type, tree size_tree, bool 
for_biased)
  || size > (Enable_128bit_Types ? 128 : LONG_LONG_TYPE_SIZE))
break;
 
+  /* If we've already created this type, the base type is supposed
+to map to it.  Check that it is what we expect.  */
+  if (TYPE_CAN_HAVE_DEBUG_TYPE_P (type)
+ && (new_type = TYPE_DEBUG_TYPE (type))
+ && TYPE_PRECISION (new_type) == size
+ && ((TREE_CODE (new_type) == INTEGER_TYPE
+  && TYPE_BIASED_REPRESENTATION_P (new_type)) == for_biased))
+   return new_type;
+
   /* The type should be an unsigned type if the original type is unsigned
 or if the lower bound is constant and non-negative or if the type is
 biased, see E_Signed_Integer_Subtype case of gnat_to_gnu_entity.  */
@@ -1414,6 +1423,16 @@ make_type_from_size (tree type, tree size_tree, bool 
for_biased)
   TYPE_NAME (new_type) = TYPE_NAME (type);
   TYPE_BIASED_REPRESENTATION_P (new_type) = for_biased;
   SET_TYPE_RM_SIZE (new_type, bitsize_int (size));
+
+  /* Enable us to avoid creating the same narrower type multiple
+times, and avoid duplication in debug information, by mapping
+the wider type to the narrower version.  If biasing is
+different, we use the narrower type for debug information.  */
+  if (TYPE_CAN_HAVE_DEBUG_TYPE_P (type)
+ && !TYPE_DEBUG_TYPE (type)
+ && biased_p == for_biased)
+   SET_TYPE_DEBUG_TYPE (type, new_type);
+
   return new_type;
 
 case RECORD_TYPE:
diff --git a/gcc/testsuite/gnat.dg/bias1.adb b/gcc/testsuite/gnat.dg/bias1.adb
index 016a159b692..d9a00a1aa45 100644
--- a/gcc/testsuite/gnat.dg/bias1.adb
+++ b/gcc/testsuite/gnat.dg/bias1.adb
@@ -1,6 +1,7 @@
 --  { dg-do compile }
 --  { dg-options "-cargs -g -dA -gnatws -fgnat-encodings=gdb -margs" }
 --  { dg-final { scan-assembler "DW_AT_GNU_bias" } }
+--  { dg-final { scan-assembler-times "-7.*DW_AT_GNU_bias" 1 } }
 
 procedure Bias1 is
type Small is range -7 .. -4;
@@ -31,4 +32,4 @@ procedure Bias1 is
 
 begin
null;
-end Bias1;
\ No newline at end of file
+end Bias1;


[gcc(refs/users/aoliva/heads/testme)] make_type_from_size avoid TYPE_DEBUG_TYPE / TREE_TYPE loops

2024-06-28 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:8f9705aadea6b840c9a1403a7497dde7bb586ce6

commit 8f9705aadea6b840c9a1403a7497dde7bb586ce6
Author: Alexandre Oliva 
Date:   Fri Jun 28 05:35:58 2024 -0300

make_type_from_size avoid TYPE_DEBUG_TYPE / TREE_TYPE loops

Diff:
---
 gcc/ada/gcc-interface/utils.cc | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/gcc-interface/utils.cc b/gcc/ada/gcc-interface/utils.cc
index daf8d7ccdc5..b46e035e1d4 100644
--- a/gcc/ada/gcc-interface/utils.cc
+++ b/gcc/ada/gcc-interface/utils.cc
@@ -1427,10 +1427,12 @@ make_type_from_size (tree type, tree size_tree, bool 
for_biased)
   /* Enable us to avoid creating the same narrower type multiple
 times, and avoid duplication in debug information, by mapping
 the wider type to the narrower version.  If biasing is
-different, we use the narrower type for debug information.  */
+different, we use the narrower type for debug information.
+Be careful to avoid forming loops.  */
   if (TYPE_CAN_HAVE_DEBUG_TYPE_P (type)
  && !TYPE_DEBUG_TYPE (type)
- && biased_p == for_biased)
+ && biased_p == for_biased
+ && TREE_TYPE (new_type) != type)
SET_TYPE_DEBUG_TYPE (type, new_type);
 
   return new_type;


[gcc r15-1703] Use gfc_reset_vptr more consistently.

2024-06-28 Thread Andre Vehreschild via Gcc-cvs
https://gcc.gnu.org/g:3f8ce76f53d0fd6bb871f0d85d29be96c5d10c81

commit r15-1703-g3f8ce76f53d0fd6bb871f0d85d29be96c5d10c81
Author: Andre Vehreschild 
Date:   Fri Jun 7 08:57:36 2024 +0200

Use gfc_reset_vptr more consistently.

The vptr for a class type is set in various ways in different
locations.  Refactor the use and simplify code.

gcc/fortran/ChangeLog:

* trans-array.cc (structure_alloc_comps): Use reset_vptr.
* trans-decl.cc (gfc_trans_deferred_vars): Same.
(gfc_generate_function_code): Same.
* trans-expr.cc (gfc_reset_vptr): Allow supplying the class
type.
(gfc_conv_procedure_call): Use reset_vptr.
* trans-intrinsic.cc (gfc_conv_intrinsic_transfer): Same.

Diff:
---
 gcc/fortran/trans-array.cc | 34 +
 gcc/fortran/trans-decl.cc  | 19 ++
 gcc/fortran/trans-expr.cc  | 57 +-
 gcc/fortran/trans-intrinsic.cc | 10 +---
 4 files changed, 38 insertions(+), 82 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 26237f43bec..510f429ef8e 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -9885,15 +9885,7 @@ structure_alloc_comps (gfc_symbol * der_type, tree decl, 
tree dest,
  else
{
  /* Build the vtable address and set the vptr with it.  */
- tree vtab;
- gfc_symbol *vtable;
- vtable = gfc_find_derived_vtab (c->ts.u.derived);
- vtab = vtable->backend_decl;
- if (vtab == NULL_TREE)
-   vtab = gfc_get_symbol_decl (vtable);
- vtab = gfc_build_addr_expr (NULL, vtab);
- vtab = fold_convert (TREE_TYPE (tmp), vtab);
- gfc_add_modify (&tmpblock, tmp, vtab);
+ gfc_reset_vptr (&tmpblock, nullptr, tmp, c->ts.u.derived);
}
}
 
@@ -9924,15 +9916,13 @@ structure_alloc_comps (gfc_symbol * der_type, tree 
decl, tree dest,
  && (CLASS_DATA (c)->attr.allocatable
  || CLASS_DATA (c)->attr.class_pointer))
{
- tree vptr_decl;
+ tree class_ref;
 
  /* Allocatable CLASS components.  */
- comp = fold_build3_loc (input_location, COMPONENT_REF, ctype,
- decl, cdecl, NULL_TREE);
-
- vptr_decl = gfc_class_vptr_get (comp);
+ class_ref = fold_build3_loc (input_location, COMPONENT_REF, ctype,
+  decl, cdecl, NULL_TREE);
 
- comp = gfc_class_data_get (comp);
+ comp = gfc_class_data_get (class_ref);
  if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (comp)))
gfc_conv_descriptor_data_set (&fnblock, comp,
  null_pointer_node);
@@ -9947,19 +9937,7 @@ structure_alloc_comps (gfc_symbol * der_type, tree decl, 
tree dest,
  /* The dynamic type of a disassociated pointer or unallocated
 allocatable variable is its declared type. An unlimited
 polymorphic entity has no declared type.  */
- if (!UNLIMITED_POLY (c))
-   {
- vtab = gfc_find_derived_vtab (c->ts.u.derived);
- if (!vtab->backend_decl)
-gfc_get_symbol_decl (vtab);
- tmp = gfc_build_addr_expr (NULL_TREE, vtab->backend_decl);
-   }
- else
-   tmp = build_int_cst (TREE_TYPE (vptr_decl), 0);
-
- tmp = fold_build2_loc (input_location, MODIFY_EXPR,
-void_type_node, vptr_decl, tmp);
- gfc_add_expr_to_block (&fnblock, tmp);
+ gfc_reset_vptr (&fnblock, nullptr, class_ref, c->ts.u.derived);
 
  cmp_has_alloc_comps = false;
}
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 8d4f06a4e1d..11247ddc07a 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -5107,26 +5107,11 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, 
gfc_wrapped_block * block)
  if (sym->ts.type == BT_CLASS)
{
  /* Initialize _vptr to declared type.  */
- gfc_symbol *vtab;
- tree rhs;
-
  gfc_save_backend_locus (&loc);
  gfc_set_backend_locus (&sym->declared_at);
  e = gfc_lval_expr_from_sym (sym);
- gfc_add_vptr_component (e);
- gfc_init_se (&se, NULL);
- se.want_pointer = 1;
- gfc_conv_expr (&se, e);
+ gfc_reset_vptr (&init, e);
  gfc_free_expr (e);
- if (UNLIMITED_POLY (sym))
-   rhs = build_int_cst (TREE_TYPE (se.e

[gcc r15-1704] Add gfc_class_set_vptr.

2024-06-28 Thread Andre Vehreschild via Gcc-cvs
https://gcc.gnu.org/g:aa3599a10cab34104c0b9bd6951c5f0c420795d8

commit r15-1704-gaa3599a10cab34104c0b9bd6951c5f0c420795d8
Author: Andre Vehreschild 
Date:   Tue Jun 11 12:52:26 2024 +0200

Add gfc_class_set_vptr.

First step to adding a general assign all class type's data members
routine.  Having a general routine prevents forgetting to tackle the
edge cases, e.g. setting _len.

gcc/fortran/ChangeLog:

* trans-expr.cc (gfc_class_set_vptr): Add setting of _vptr
member.
* trans-intrinsic.cc (conv_intrinsic_move_alloc): First use
of gfc_class_set_vptr and refactor very similar code.
* trans.h (gfc_class_set_vptr): Declare the new function.

gcc/testsuite/ChangeLog:

* gfortran.dg/unlimited_polymorphic_11.f90: Remove unnecessary
casts in gd-final expression.

Diff:
---
 gcc/fortran/trans-expr.cc  |  48 +
 gcc/fortran/trans-intrinsic.cc | 203 ++---
 gcc/fortran/trans.h|   6 +-
 .../gfortran.dg/unlimited_polymorphic_11.f90   |   2 +-
 4 files changed, 111 insertions(+), 148 deletions(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 454b87581f5..477c2720187 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -599,6 +599,54 @@ gfc_reset_vptr (stmtblock_t *block, gfc_expr *e, tree 
class_container,
 }
 
 
+/* Set the vptr of a class in to from the type given in from.  If from is NULL,
+   then reset the vptr to the default or to.  */
+
+void
+gfc_class_set_vptr (stmtblock_t *block, tree to, tree from)
+{
+  tree tmp, vptr_ref;
+
+  vptr_ref = gfc_get_vptr_from_expr (to);
+  if (POINTER_TYPE_P (TREE_TYPE (from))
+  && GFC_CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (from
+{
+  gfc_add_modify (block, vptr_ref,
+ fold_convert (TREE_TYPE (vptr_ref),
+   gfc_get_vptr_from_expr (from)));
+}
+  else if (VAR_P (from)
+  && strncmp (IDENTIFIER_POINTER (DECL_NAME (from)), "__vtab", 6) == 0)
+{
+  gfc_add_modify (block, vptr_ref,
+ gfc_build_addr_expr (TREE_TYPE (vptr_ref), from));
+}
+  else if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (from)))
+  && GFC_CLASS_TYPE_P (
+TREE_TYPE (TREE_OPERAND (TREE_OPERAND (from, 0), 0
+{
+  gfc_add_modify (block, vptr_ref,
+ fold_convert (TREE_TYPE (vptr_ref),
+   gfc_get_vptr_from_expr (TREE_OPERAND (
+ TREE_OPERAND (from, 0), 0;
+}
+  else
+{
+  tree vtab;
+  gfc_symbol *type;
+  tmp = TREE_TYPE (from);
+  if (POINTER_TYPE_P (tmp))
+   tmp = TREE_TYPE (tmp);
+  gfc_find_symbol (IDENTIFIER_POINTER (TYPE_NAME (tmp)), gfc_current_ns, 1,
+  &type);
+  vtab = gfc_find_derived_vtab (type)->backend_decl;
+  gcc_assert (vtab);
+  gfc_add_modify (block, vptr_ref,
+ gfc_build_addr_expr (TREE_TYPE (vptr_ref), vtab));
+}
+}
+
+
 /* Reset the len for unlimited polymorphic objects.  */
 
 void
diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index ac7fcd250d3..5ea10e84060 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -12667,10 +12667,9 @@ conv_intrinsic_move_alloc (gfc_code *code)
 {
   stmtblock_t block;
   gfc_expr *from_expr, *to_expr;
-  gfc_expr *to_expr2, *from_expr2 = NULL;
   gfc_se from_se, to_se;
-  tree tmp;
-  bool coarray;
+  tree tmp, to_tree, from_tree;
+  bool coarray, from_is_class, from_is_scalar;
 
   gfc_start_block (&block);
 
@@ -12680,178 +12679,94 @@ conv_intrinsic_move_alloc (gfc_code *code)
   gfc_init_se (&from_se, NULL);
   gfc_init_se (&to_se, NULL);
 
-  gcc_assert (from_expr->ts.type != BT_CLASS
- || to_expr->ts.type == BT_CLASS);
+  gcc_assert (from_expr->ts.type != BT_CLASS || to_expr->ts.type == BT_CLASS);
   coarray = gfc_get_corank (from_expr) != 0;
 
-  if (from_expr->rank == 0 && !coarray)
+  from_is_class = from_expr->ts.type == BT_CLASS;
+  from_is_scalar = from_expr->rank == 0 && !coarray;
+  if (to_expr->ts.type == BT_CLASS || from_is_scalar)
 {
-  if (from_expr->ts.type != BT_CLASS)
-   from_expr2 = from_expr;
+  from_se.want_pointer = 1;
+  if (from_is_scalar)
+   gfc_conv_expr (&from_se, from_expr);
   else
-   {
- from_expr2 = gfc_copy_expr (from_expr);
- gfc_add_data_component (from_expr2);
-   }
-
-  if (to_expr->ts.type != BT_CLASS)
-   to_expr2 = to_expr;
+   gfc_conv_expr_descriptor (&from_se, from_expr);
+  if (from_is_class)
+   from_tree = gfc_class_data_get (from_se.expr);
   else
{
- to_expr2 = gfc_copy_expr (to_expr);
- gfc_add_data_component (to_expr2);
+ gfc_symbol *vtab;
+  

[gcc/devel/omp/gcc-14] Identify OMP development branch in output of 'gcc --version'

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:26ae7c67702a081fadbb93b41596fa4ead4f1e96

commit 26ae7c67702a081fadbb93b41596fa4ead4f1e96
Author: Kwok Cheung Yeung 
Date:   Mon Jun 20 15:41:57 2022 +0100

Identify OMP development branch in output of 'gcc --version'

2022-06-20  Kwok Cheung Yeung  

gcc/
* Makefile.in (REVISION_s): Change default message.

Diff:
---
 gcc/ChangeLog.omp | 4 
 gcc/Makefile.in   | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
new file mode 100644
index 000..236d7953743
--- /dev/null
+++ b/gcc/ChangeLog.omp
@@ -0,0 +1,4 @@
+2022-06-20  Kwok Cheung Yeung  
+
+   * Makefile.in (REVISION_s): Change default message.
+
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index a74761b7ab3..7718f2da577 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -954,7 +954,7 @@ ifdef REVISION_c
 REVISION_s  := \
   "\"$(if $(DEVPHASE_c)$(filter-out 0,$(PATCHLEVEL_c)), $(REVISION_c))\""
 else
-REVISION_s  := "\"\""
+REVISION_s  := "\" [OG14]\""
 endif
 
 # Shorthand variables for dependency lists.


[gcc/devel/omp/gcc-14] Various OpenACC reduction enhancements - ME and nvptx changes

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:0626769c2203460e61fe3c5e4083549723453f3c

commit 0626769c2203460e61fe3c5e4083549723453f3c
Author: Julian Brown 
Date:   Tue Feb 12 15:06:55 2019 -0800

Various OpenACC reduction enhancements - ME and nvptx changes

Parts of the first posting got lost in the second posting, above.
This version hopefully contains everything.

2018-10-30  Cesar Philippidis  

gcc/
* config/nvptx/nvptx.cc (nvptx_propagate_unified): New.
(nvptx_split_blocks): Call it for cond_uni insn.
(nvptx_expand_cond_uni): New.
(enum nvptx_builtins): Add NVPTX_BUILTIN_COND_UNI.
(nvptx_init_builtins): Initialize it.
(nvptx_expand_builtin):
(nvptx_generate_vector_shuffle): Change integral SHIFT operand to
tree BITS operand.
(nvptx_vector_reduction): New.
(nvptx_adjust_reduction_type): New.
(nvptx_goacc_reduction_setup): Use it to adjust the type of 
ref_to_res.
(nvptx_goacc_reduction_init): Don't update LHS if it doesn't exist.
(nvptx_goacc_reduction_fini): Call nvptx_vector_reduction for 
vector.
Use it to adjust the type of ref_to_res.
(nvptx_goacc_reduction_teardown):
* config/nvptx/nvptx.md (cond_uni): New pattern.

Diff:
---
 gcc/ChangeLog.omp |  19 
 gcc/config/nvptx/nvptx.cc | 233 +-
 gcc/config/nvptx/nvptx.md |   7 ++
 gcc/gimplify.cc   |   8 +-
 gcc/omp-general.h |   2 +-
 gcc/omp-low.cc|  29 +-
 gcc/omp-offload.cc|  11 +++
 7 files changed, 278 insertions(+), 31 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 4f4d1dbfad4..4ba97e30d5c 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,22 @@
+2018-10-30  Cesar Philippidis  
+
+   * config/nvptx/nvptx.cc (nvptx_propagate_unified): New.
+   (nvptx_split_blocks): Call it for cond_uni insn.
+   (nvptx_expand_cond_uni): New.
+   (enum nvptx_builtins): Add NVPTX_BUILTIN_COND_UNI.
+   (nvptx_init_builtins): Initialize it.
+   (nvptx_expand_builtin):
+   (nvptx_generate_vector_shuffle): Change integral SHIFT operand to
+   tree BITS operand.
+   (nvptx_vector_reduction): New.
+   (nvptx_adjust_reduction_type): New.
+   (nvptx_goacc_reduction_setup): Use it to adjust the type of ref_to_res.
+   (nvptx_goacc_reduction_init): Don't update LHS if it doesn't exist.
+   (nvptx_goacc_reduction_fini): Call nvptx_vector_reduction for vector.
+   Use it to adjust the type of ref_to_res.
+   (nvptx_goacc_reduction_teardown):
+   * config/nvptx/nvptx.md (cond_uni): New pattern.
+
 2018-06-29  Cesar Philippidis  
James Norris  
 
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index 2a8f713c680..3e52354bd12 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -1,5 +1,5 @@
 /* Target code for NVPTX.
-   Copyright (C) 2014-2024 Free Software Foundation, Inc.
+   Copyright (C) 2014-2023 Free Software Foundation, Inc.
Contributed by Bernd Schmidt 
 
This file is part of GCC.
@@ -3487,6 +3487,52 @@ nvptx_mach_vector_length ()
   return cfun->machine->axis_dim[MACH_VECTOR_LENGTH];
 }
 
+/* UNIFIED is a cond_uni insn.  Find the branch insn it affects, and
+   mark that as unified.  We expect to be in a single block.  */
+
+static void
+nvptx_propagate_unified (rtx_insn *unified)
+{
+  rtx_insn *probe = unified;
+  rtx cond_reg = SET_DEST (PATTERN (unified));
+  rtx pat = NULL_RTX;
+
+  /* Find the comparison.  (We could skip this and simply scan to he
+ blocks' terminating branch, if we didn't care for self
+ checking.)  */
+  for (;;)
+{
+  probe = next_real_insn (probe);
+  if (!probe)
+   break;
+  pat = PATTERN (probe);
+
+  if (GET_CODE (pat) == SET
+ && GET_RTX_CLASS (GET_CODE (SET_SRC (pat))) == RTX_COMPARE
+ && XEXP (SET_SRC (pat), 0) == cond_reg)
+   break;
+  gcc_assert (NONJUMP_INSN_P (probe));
+}
+  gcc_assert (pat);
+  rtx pred_reg = SET_DEST (pat);
+
+  /* Find the branch.  */
+  do
+probe = NEXT_INSN (probe);
+  while (!JUMP_P (probe));
+
+  pat = PATTERN (probe);
+  rtx itec = XEXP (SET_SRC (pat), 0);
+  gcc_assert (XEXP (itec, 0) == pred_reg);
+
+  /* Mark the branch's condition as unified.  */
+  rtx unspec = gen_rtx_UNSPEC (BImode, gen_rtvec (1, pred_reg),
+  UNSPEC_BR_UNIFIED);
+  bool ok = validate_change (probe, &XEXP (itec, 0), unspec, false);
+
+  gcc_assert (ok);
+}
+
 /* Loop structure of the function.  The entire function is described as
a NULL loop.  */
 /* See also 'gcc/omp-oacc-neuter-broadcast.cc:struct parallel_g'.  */
@@ -3590,6 +3636,9 @@ nvptx_split_blocks (bb_insn_map_t *map)
continue;
  switch (recog_memoized (insn))
{
+   case CODE_FOR_con

[gcc/devel/omp/gcc-14] Various OpenACC reduction enhancements - test cases

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:62c01939d1176334be2ee119a2a045fa7b050f57

commit 62c01939d1176334be2ee119a2a045fa7b050f57
Author: Julian Brown 
Date:   Tue Feb 12 15:14:22 2019 -0800

Various OpenACC reduction enhancements - test cases

2018-12-13  Cesar Philippidis  
Nathan Sidwell  
Julian Brown  

gcc/testsuite/
* c-c++-common/goacc/orphan-reductions-1.c: New test.
* c-c++-common/goacc/reduction-9.c: New test.
* c-c++-common/goacc/routine-4.c: Update.
* g++.dg/goacc/reductions-1.C: New test.
* gcc.dg/goacc/loop-processing-1.c: Update.
* gfortran.dg/goacc/orphan-reductions-1.f90: New test.

libgomp/
* testsuite/libgomp.oacc-c-c++-common/par-reduction-3.c: New test.
* testsuite/libgomp.oacc-c-c++-common/reduction-cplx-flt-2.c: New 
test.
* testsuite/libgomp.oacc-fortran/reduction-9.f90: New test.

Diff:
---
 gcc/testsuite/ChangeLog.omp|  11 +
 gcc/testsuite/c-c++-common/goacc/reduction-9.c | 111 +
 gcc/testsuite/g++.dg/goacc/reductions-1.C  | 548 +
 gcc/testsuite/gcc.dg/goacc/loop-processing-1.c |   2 +-
 libgomp/ChangeLog.omp  |   8 +
 .../libgomp.oacc-c-c++-common/par-reduction-3.c|  29 ++
 .../reduction-cplx-flt-2.c |  32 ++
 .../testsuite/libgomp.oacc-fortran/reduction-9.f90 |  54 ++
 8 files changed, 794 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 75d810faac5..b3892abb522 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,14 @@
+2018-12-13  Cesar Philippidis  
+   Nathan Sidwell  
+   Julian Brown  
+
+   * c-c++-common/goacc/orphan-reductions-1.c: New test.
+   * c-c++-common/goacc/reduction-9.c: New test.
+   * c-c++-common/goacc/routine-4.c: Update.
+   * g++.dg/goacc/reductions-1.C: New test.
+   * gcc.dg/goacc/loop-processing-1.c: Update.
+   * gfortran.dg/goacc/orphan-reductions-1.f90: New test.
+
 2018-06-29  Cesar Philippidis  
James Norris  
 
diff --git a/gcc/testsuite/c-c++-common/goacc/reduction-9.c 
b/gcc/testsuite/c-c++-common/goacc/reduction-9.c
new file mode 100644
index 000..eba1d028d98
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/goacc/reduction-9.c
@@ -0,0 +1,111 @@
+/* Exercise invalid reductions on array and struct members.  */
+
+void
+test_parallel ()
+{
+  struct {
+int a;
+float b[5];
+  } s1, s2[10];
+
+  int i;
+  double z[100];
+
+#pragma acc parallel reduction(+:s1.a) /* { dg-error "expected '\\\)' before 
'\\\.' token" } */
+  for (i = 0; i < 10; i++)
+s1.a += 1;
+
+#pragma acc parallel reduction(+:s1.b[3]) /* { dg-error "expected '\\\)' 
before '\\\.' token" } */
+  for (i = 0; i < 10; i++)
+s1.b[3] += 1;
+
+#pragma acc parallel reduction(+:s2[2].a) /* { dg-error "expected '\\\)' 
before '\\\[' token" } */
+  for (i = 0; i < 10; i++)
+s2[2].a += 1;
+
+#pragma acc parallel reduction(+:s2[3].b[4]) /* { dg-error "expected '\\\)' 
before '\\\[' token" } */
+  for (i = 0; i < 10; i++)
+s2[3].b[4] += 1;
+
+#pragma acc parallel reduction(+:z[5]) /* { dg-error "expected '\\\)' before 
'\\\[' token" } */
+  for (i = 0; i < 10; i++)
+z[5] += 1;
+}
+
+void
+test_combined ()
+{
+  struct {
+int a;
+float b[5];
+  } s1, s2[10];
+
+  int i;
+  double z[100];
+
+#pragma acc parallel loop reduction(+:s1.a) /* { dg-error "expected '\\\)' 
before '\\\.' token" } */
+  for (i = 0; i < 10; i++)
+s1.a += 1;
+
+#pragma acc parallel loop reduction(+:s1.b[3]) /* { dg-error "expected '\\\)' 
before '\\\.' token" } */
+  for (i = 0; i < 10; i++)
+s1.b[3] += 1;
+
+#pragma acc parallel loop reduction(+:s2[2].a) /* { dg-error "expected '\\\)' 
before '\\\[' token" } */
+  for (i = 0; i < 10; i++)
+s2[2].a += 1;
+
+#pragma acc parallel loop reduction(+:s2[3].b[4]) /* { dg-error "expected 
'\\\)' before '\\\[' token" } */
+  for (i = 0; i < 10; i++)
+s2[3].b[4] += 1;
+
+#pragma acc parallel loop reduction(+:z[5]) /* { dg-error "expected '\\\)' 
before '\\\[' token" } */
+  for (i = 0; i < 10; i++)
+z[5] += 1;
+
+}
+
+void
+test_loops ()
+{
+  struct {
+int a;
+float b[5];
+  } s1, s2[10];
+
+  int i;
+  double z[100];
+
+#pragma acc parallel
+  {
+#pragma acc loop reduction(+:s1.a) /* { dg-error "expected '\\\)' before 
'\\\.' token" } */
+  for (i = 0; i < 10; i++)
+s1.a += 1;
+
+#pragma acc loop reduction(+:s1.b[3]) /* { dg-error "expected '\\\)' before 
'\\\.' token" } */
+  for (i = 0; i < 10; i++)
+s1.b[3] += 1;
+
+#pragma acc loop reduction(+:s2[2].a) /* { dg-error "expected '\\\)' before 
'\\\[' token" } */
+  for (i = 0; i < 10; i++)
+s2[2].a += 1;
+
+#pragma acc loop reduction(+:s2[3].b[4]) /* { dg-error "expected '\\\)' before 
'\\\[' token" } */
+  for (i = 0; i < 10; i

[gcc/devel/omp/gcc-14] Adjustments and additions to testcases

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:26dacc8be16704ddfdd0e22c3611b410a445edcc

commit 26dacc8be16704ddfdd0e22c3611b410a445edcc
Author: Julian Brown 
Date:   Tue Feb 26 13:18:36 2019 -0800

Adjustments and additions to testcases

Some additions of redundant "present" clauses dropped.

2018-10-22  Cesar Philippidis  

gcc/testsuite/
* g++.dg/goacc/loop-1.c: New test.
* g++.dg/goacc/loop-2.c: New test.
* g++.dg/goacc/loop-3.c: New test.

2018-10-22  James Norris  
Cesar Philippidis  
Tom de Vries  

libgomp/
* testsuite/libgomp.oacc-fortran/data-3.f90: Update parallel
regions to denote variables copyied in via acc enter data as
present.
* testsuite/libgomp.oacc-c-c++-common/subr.h: Reimplement.
* testsuite/libgomp.oacc-c-c++-common/subr.ptx: Regenerated PTX.
* testsuite/libgomp.oacc-c-c++-common/timer.h: Removed.
* testsuite/libgomp.oacc-c-c++-common/lib-69.c: Change async checks.
* testsuite/libgomp.oacc-c-c++-common/lib-70.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-72.c: Rework kernel i/f 
and
change async checks.
* testsuite/libgomp.oacc-c-c++-common/lib-73.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-74.c: Rework kernel i/f 
and
timing checks.
* testsuite/libgomp.oacc-c-c++-common/lib-75.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-76.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-78.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-79.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-81.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-82.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-93.c: New test.

Diff:
---
 gcc/testsuite/ChangeLog.omp|   6 +
 gcc/testsuite/g++.dg/goacc/loop-1.c|  23 +++
 gcc/testsuite/g++.dg/goacc/loop-2.c|  70 +++
 gcc/testsuite/g++.dg/goacc/loop-3.c|  43 
 libgomp/ChangeLog.omp  |  25 +++
 .../testsuite/libgomp.oacc-c-c++-common/lib-69.c   |  55 +
 .../testsuite/libgomp.oacc-c-c++-common/lib-70.c   |  79 +++-
 .../testsuite/libgomp.oacc-c-c++-common/lib-72.c   |  60 +-
 .../testsuite/libgomp.oacc-c-c++-common/lib-73.c   |  64 +-
 .../testsuite/libgomp.oacc-c-c++-common/lib-74.c   |  87 +++-
 .../testsuite/libgomp.oacc-c-c++-common/lib-75.c   |  81 ++--
 .../testsuite/libgomp.oacc-c-c++-common/lib-76.c   |  80 ++--
 .../testsuite/libgomp.oacc-c-c++-common/lib-78.c   |  83 +++-
 .../testsuite/libgomp.oacc-c-c++-common/lib-79.c   |  83 ++--
 .../testsuite/libgomp.oacc-c-c++-common/lib-81.c   | 102 --
 .../testsuite/libgomp.oacc-c-c++-common/lib-82.c   |  43 +---
 .../testsuite/libgomp.oacc-c-c++-common/lib-93.c   |  19 ++
 libgomp/testsuite/libgomp.oacc-c-c++-common/subr.h |  45 +
 .../testsuite/libgomp.oacc-c-c++-common/subr.ptx   | 222 -
 .../testsuite/libgomp.oacc-c-c++-common/timer.h| 103 --
 libgomp/testsuite/libgomp.oacc-fortran/data-3.f90  |  12 +-
 21 files changed, 492 insertions(+), 893 deletions(-)

diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index b3892abb522..21eab80c776 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,9 @@
+2018-10-22  Cesar Philippidis  
+
+   * g++.dg/goacc/loop-1.c: New test.
+   * g++.dg/goacc/loop-2.c: New test.
+   * g++.dg/goacc/loop-3.c: New test.
+
 2018-12-13  Cesar Philippidis  
Nathan Sidwell  
Julian Brown  
diff --git a/gcc/testsuite/g++.dg/goacc/loop-1.c 
b/gcc/testsuite/g++.dg/goacc/loop-1.c
new file mode 100644
index 000..51b20b0e2da
--- /dev/null
+++ b/gcc/testsuite/g++.dg/goacc/loop-1.c
@@ -0,0 +1,23 @@
+void
+f (int i, float j, int k)
+{
+#pragma acc parallel num_gangs (i) num_workers (i) vector_length (i)
+#pragma acc loop gang
+  for (i = 0; i < 20; ++i)
+;
+
+#pragma acc parallel num_gangs (j) /* { dg-error "'num_gangs' expression must 
be integral" } */
+#pragma acc loop gang
+  for (i = 0; i < 20; ++i)
+;
+
+#pragma acc parallel num_workers (j) /* { dg-error "'num_workers' expression 
must be integral" } */
+#pragma acc loop gang
+  for (i = 0; i < 20; ++i)
+;
+
+#pragma acc parallel vector_length (j) /* { dg-error "'vector_length' 
expression must be integral" } */
+#pragma acc loop gang
+  for (i = 0; i < 20; ++i)
+;
+}
diff --git a/gcc/testsuite/g++.dg/goacc/loop-2.c 
b/gcc/testsuite/g++.dg/goacc/loop-2.c
new file mode 100644
index 000..ddfb4804353
--- /dev/null
+++ b/gcc/testsuite/g++.dg/goacc/loop-2.c
@@ -0,0 +1,70 @@
+void
+f (int i, int j, int k)
+{
+#pragma acc kernels
+#pragma acc loop gang
+  for 

[gcc] Created branch 'devel/omp/gcc-14'

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
The branch 'devel/omp/gcc-14' was created pointing to:

 735bbbfc6ea... Fix scan dumps in readonly-1.c


[gcc/devel/omp/gcc-14] Default compute dimensions (compile time)

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:48aca3e3007df5918dc8edd29c42adf3701497da

commit 48aca3e3007df5918dc8edd29c42adf3701497da
Author: Julian Brown 
Date:   Tue Feb 26 14:12:06 2019 -0800

Default compute dimensions (compile time)

Typo fix relative to last posted version.

2018-10-05  Nathan Sidwell  
Tom de Vries  
Thomas Schwinge  
Julian Brown  

gcc/
* doc/invoke.texi (fopenacc-dim): Update.
* omp-offload.cc (oacc_parse_default_dims): Update.

gcc/testsuite/
* c-c++-common/goacc/acc-icf.c: Update.
* c-c++-common/goacc/parallel-dims-1.c: Likewise.
* gfortran.dg/goacc/routine-4.f90: Likewise.
* gfortran.dg/goacc/routine-multiple-directives-1.f90: Likewise.

libgomp/
* testsuite/libgomp.oacc-c-c++-common/loop-default-compile.c: New.
* testsuite/libgomp.oacc-c-c++-common/loop-warn-1.c: New.
* testsuite/libgomp.oacc-c-c++-common/parallel-dims.c: Update.

Diff:
---
 gcc/ChangeLog.omp  |  8 +
 gcc/doc/invoke.texi|  8 +++--
 gcc/omp-offload.cc | 25 +--
 gcc/testsuite/ChangeLog.omp| 10 ++
 gcc/testsuite/c-c++-common/goacc/acc-icf.c |  4 +--
 gcc/testsuite/c-c++-common/goacc/parallel-dims-1.c |  3 +-
 gcc/testsuite/gfortran.dg/goacc/routine-4.f90  |  4 +++
 .../goacc/routine-multiple-directives-1.f90|  4 +--
 libgomp/ChangeLog.omp  |  9 ++
 .../loop-default-compile.c | 13 
 .../libgomp.oacc-c-c++-common/loop-warn-1.c| 37 ++
 11 files changed, 109 insertions(+), 16 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 4ba97e30d5c..952a79c8c24 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,11 @@
+2018-10-05  Nathan Sidwell  
+   Tom de Vries  
+   Thomas Schwinge  
+   Julian Brown  
+
+   * doc/invoke.texi (fopenacc-dim): Update.
+   * omp-offload.cc (oacc_parse_default_dims): Update.
+
 2018-10-30  Cesar Philippidis  
 
* config/nvptx/nvptx.cc (nvptx_propagate_unified): New.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 9456ced468a..3e2f9bd5b4b 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -2795,8 +2795,12 @@ have support for @option{-pthread}.
 @item -fopenacc-dim=@var{geom}
 Specify default compute dimensions for parallel offload regions that do
 not explicitly specify.  The @var{geom} value is a triple of
-':'-separated sizes, in order 'gang', 'worker' and, 'vector'.  A size
-can be omitted, to use a target-specific default value.
+':'-separated sizes, in order 'gang', 'worker' and, 'vector'.  If a size
+is to be deferred until execution '-' can be used, alternatively a size
+can be omitted to use a target-specific default value.  When deferring
+to runtime, the environment variable @var{GOMP_OPENACC_DIM} can be set.
+It has the same format as the option value, except that '-' is not
+permitted.
 
 @opindex fopenmp
 @cindex OpenMP parallel
diff --git a/gcc/omp-offload.cc b/gcc/omp-offload.cc
index 738b64f8c16..b2ba9042758 100644
--- a/gcc/omp-offload.cc
+++ b/gcc/omp-offload.cc
@@ -875,8 +875,9 @@ oacc_get_min_dim (int dim)
 }
 
 /* Parse the default dimension parameter.  This is a set of
-   :-separated optional compute dimensions.  Each specified dimension
-   is a positive integer.  When device type support is added, it is
+   :-separated optional compute dimensions.  Each dimension is either
+   a positive integer, or '-' for a dynamic value computed at
+   runtime.  When device type support is added, it is
planned to be a comma separated list of such compute dimensions,
with all but the first prefixed by the colon-terminated device
type.  */
@@ -911,14 +912,20 @@ oacc_parse_default_dims (const char *dims)
 
  if (*pos != ':')
{
- long val;
- const char *eptr;
+ long val = 0;
 
- errno = 0;
- val = strtol (pos, CONST_CAST (char **, &eptr), 10);
- if (errno || val <= 0 || (int) val != val)
-   goto malformed;
- pos = eptr;
+ if (*pos == '-')
+   pos++;
+ else
+   {
+ const char *eptr;
+
+ errno = 0;
+ val = strtol (pos, CONST_CAST (char **, &eptr), 10);
+ if (errno || val <= 0 || (int) val != val)
+   goto malformed;
+ pos = eptr;
+   }
  oacc_default_dims[ix] = (int) val;
}
}
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 21eab80c776..bb18fa23628 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/C

[gcc/devel/omp/gcc-14] Enable GOMP_MAP_FIRSTPRIVATE_INT for OpenACC

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:a743b0947593f38fd93fa1bc5f8dd3c50ba5c498

commit a743b0947593f38fd93fa1bc5f8dd3c50ba5c498
Author: Julian Brown 
Date:   Tue Feb 26 15:10:21 2019 -0800

Enable GOMP_MAP_FIRSTPRIVATE_INT for OpenACC

2018-12-22  Cesar Philippidis  
Julian Brown  
Tobias Burnus  

gcc/
* omp-low.cc (maybe_lookup_field_in_outer_ctx): New function.
(convert_to_firstprivate_int): New function.
(convert_from_firstprivate_int): New function.
(lower_omp_target): Enable GOMP_MAP_FIRSTPRIVATE_INT in OpenACC.
Remove unused variable.

libgomp/
* oacc-parallel.c (GOACC_parallel_keyed): Handle
GOMP_MAP_FIRSTPRIVATE_INT host addresses.
* plugin/plugin-nvptx.c (nvptx_exec): Handle
GOMP_MAP_FIRSTPRIVATE_INT host addresses.
* testsuite/libgomp.oacc-c++/firstprivate-int.C: New test.
* testsuite/libgomp.oacc-c-c++-common/firstprivate-int.c: New
test.
* testsuite/libgomp.oacc-fortran/firstprivate-int.f90: New test.

Diff:
---
 gcc/ChangeLog.omp  |  10 +
 gcc/omp-low.cc | 147 +--
 libgomp/ChangeLog.omp  |  12 ++
 .../testsuite/libgomp.oacc-c++/firstprivate-int.C  |  83 +
 .../libgomp.oacc-c-c++-common/firstprivate-int.c   |  67 +++
 .../libgomp.oacc-fortran/firstprivate-int.f90  | 205 +
 6 files changed, 512 insertions(+), 12 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 952a79c8c24..b305525df30 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,13 @@
+2018-12-22  Cesar Philippidis  
+Julian Brown  
+Tobias Burnus  
+
+   * omp-low.cc (maybe_lookup_field_in_outer_ctx): New function.
+   (convert_to_firstprivate_int): New function.
+   (convert_from_firstprivate_int): New function.
+   (lower_omp_target): Enable GOMP_MAP_FIRSTPRIVATE_INT in OpenACC.
+   Remove unused variable.
+
 2018-10-05  Nathan Sidwell  
Tom de Vries  
Thomas Schwinge  
diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index e64e784940f..e53e4e3a7db 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -4614,6 +4614,19 @@ maybe_lookup_decl_in_outer_ctx (tree decl, omp_context 
*ctx)
   return t ? t : decl;
 }
 
+/* Returns true if DECL is present inside a field that encloses CTX.  */
+
+static bool
+maybe_lookup_field_in_outer_ctx (tree decl, omp_context *ctx)
+{
+  omp_context *up;
+
+  for (up = ctx->outer; up; up = up->outer)
+if (maybe_lookup_field (decl, up))
+  return true;
+
+  return false;
+}
 
 /* Construct the initialization value for reduction operation OP.  */
 
@@ -12806,6 +12819,74 @@ lower_omp_taskreg (gimple_stmt_iterator *gsi_p, 
omp_context *ctx)
 }
 }
 
+/* Helper function for lower_omp_target.  Converts VAR to something that can
+   be represented by a POINTER_SIZED_INT_NODE.  Any new instructions are
+   appended to GS.  This is used to optimize firstprivate variables, so that
+   small types (less precision than POINTER_SIZE) do not require additional
+   data mappings.  */
+
+static tree
+convert_to_firstprivate_int (tree var, gimple_seq *gs)
+{
+  tree type = TREE_TYPE (var), new_type = NULL_TREE;
+
+  if (omp_privatize_by_reference (var))
+{
+  type = TREE_TYPE (type);
+  tree tmp = create_tmp_var (type);
+  gimplify_assign (tmp, build_simple_mem_ref (var), gs);
+  var = tmp;
+}
+
+  if (INTEGRAL_TYPE_P (type) || POINTER_TYPE_P (type))
+return fold_convert (pointer_sized_int_node, var);
+
+  gcc_assert (tree_to_uhwi (TYPE_SIZE (type)) <= POINTER_SIZE);
+
+  new_type = lang_hooks.types.type_for_size (tree_to_uhwi (TYPE_SIZE (type)),
+true);
+  tree tmp = create_tmp_var (new_type);
+  var = fold_build1 (VIEW_CONVERT_EXPR, new_type, var);
+  gimplify_assign (tmp, var, gs);
+
+  return fold_convert (pointer_sized_int_node, tmp);
+}
+
+/* Like convert_to_firstprivate_int, but restore the original type.  */
+
+static tree
+convert_from_firstprivate_int (tree var, bool is_ref, gimple_seq *gs)
+{
+  tree type = TREE_TYPE (var);
+  tree new_type = NULL_TREE;
+  tree tmp = NULL_TREE;
+
+  gcc_assert (TREE_CODE (var) == MEM_REF);
+  var = TREE_OPERAND (var, 0);
+
+  if (INTEGRAL_TYPE_P (var) || POINTER_TYPE_P (type))
+return fold_convert (type, var);
+
+  gcc_assert (tree_to_uhwi (TYPE_SIZE (type)) <= POINTER_SIZE);
+
+  new_type = lang_hooks.types.type_for_size (tree_to_uhwi (TYPE_SIZE (type)),
+true);
+
+  tmp = create_tmp_var (new_type);
+  var = fold_convert (new_type, var);
+  gimplify_assign (tmp, var, gs);
+  var = fold_build1 (VIEW_CONVERT_EXPR, type, tmp);
+
+  if (is_ref)
+{
+  tmp = create_tmp_var (build_pointer_type (type)

[gcc/devel/omp/gcc-14] Merge non-contiguous array support patches.

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:b143c1c447945ce05903ff1360ead97774dfce4b

commit b143c1c447945ce05903ff1360ead97774dfce4b
Author: Chung-Lin Tang 
Date:   Sun Apr 19 05:10:43 2020 -0700

Merge non-contiguous array support patches.

This version is based from v4, posted upstream here:
https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543437.html

2020-04-19  Chung-Lin Tang  

PR other/76739

gcc/c/
* c-typeck.cc (handle_omp_array_sections_1): Add 'bool 
&non_contiguous'
parameter, adjust recursive call site, add cases for allowing
pointer based multi-dimensional arrays for OpenACC.
(handle_omp_array_sections): Adjust handle_omp_array_sections_1 
call,
handle non-contiguous case to create dynamic array map.

gcc/cp/
* semantics.cc (handle_omp_array_sections_1): Add 'bool 
&non_contiguous'
parameter, adjust recursive call site, add cases for allowing
pointer based multi-dimensional arrays for OpenACC.
(handle_omp_array_sections): Adjust handle_omp_array_sections_1 
call,
handle non-contiguous case to create dynamic array map.

gcc/fortran/
* f95-lang.cc (DEF_FUNCTION_TYPE_VAR_5): New symbol.
* types.def (BT_FN_VOID_INT_SIZE_PTR_PTR_PTR_VAR): New type.

gcc/
* builtin-types.def (BT_FN_VOID_INT_SIZE_PTR_PTR_PTR_VAR): New type.
* omp-builtins.def (BUILT_IN_GOACC_DATA_START): Adjust function type
to new BT_FN_VOID_INT_SIZE_PTR_PTR_PTR_VAR.
* gimplify.cc (gimplify_scan_omp_clauses): Skip gimplification of
OMP_CLAUSE_SIZE of non-contiguous array maps (which is a TREE_LIST).
* omp-expand.cc (expand_omp_target): Add non-contiguous array 
descriptor
pointers to variadic arguments.
* omp-low.cc (append_field_to_record_type): New function.
(create_noncontig_array_descr_type): Likewise.
(create_noncontig_array_descr_init_code): Likewise.
(scan_sharing_clauses): For non-contiguous array map kinds, check 
for
supported dimension structure, and install non-contiguous array
variable into current omp_context.
(reorder_noncontig_array_clauses): New function.
(scan_omp_target): Call reorder_noncontig_array_clauses to place
non-contiguous array map clauses at beginning of clause sequence.
(lower_omp_target): Add handling for non-contiguous array map kinds,
add all created non-contiguous array descriptors to
gimple_omp_target_data_arg.

gcc/testsuite/
* c-c++-common/goacc/noncontig_array-1.c: New test.

libgomp/
* libgomp_g.h (GOACC_data_start): Add variadic '...' to declaration.
* libgomp.h (gomp_map_vars_openacc): New function declaration.
* oacc-int.h (struct goacc_ncarray_dim): New struct declaration.
(struct goacc_ncarray_descr_type): Likewise.
(struct goacc_ncarray): Likewise.
(struct goacc_ncarray_info): Likewise.
(goacc_noncontig_array_create_ptrblock): New function declaration.
* oacc-parallel.c (goacc_noncontig_array_count_rows): New function.
(goacc_noncontig_array_compute_sizes): Likewise.
(goacc_noncontig_array_fill_rows_1): Likewise.
(goacc_noncontig_array_fill_rows): Likewise.
(goacc_process_noncontiguous_arrays): Likewise.
(goacc_noncontig_array_create_ptrblock): Likewise.
(GOACC_parallel_keyed): Use goacc_process_noncontiguous_arrays to
handle non-contiguous array descriptors at end of varargs, adjust
to use gomp_map_vars_openacc.
(GOACC_data_start): Likewise. Adjust function type to accept 
varargs.
* target.c (gomp_map_vars_internal): Add struct goacc_ncarray_info *
nca_info parameter, add handling code for non-contiguous arrays.
(gomp_map_vars_openacc): Add new function for specialization of
gomp_map_vars_internal for OpenACC structured region usage.
* testsuite/libgomp.oacc-c-c++-common/noncontig_array-1.c: New test.
* testsuite/libgomp.oacc-c-c++-common/noncontig_array-2.c: New test.
* testsuite/libgomp.oacc-c-c++-common/noncontig_array-3.c: New test.
* testsuite/libgomp.oacc-c-c++-common/noncontig_array-4.c: New test.
* testsuite/libgomp.oacc-c-c++-common/noncontig_array-utils.h: 
Support
header for new tests.

include/
* gomp-constants.h (GOMP_MAP_FLAG_SPECIAL_3): Define.
(enum gomp_map_kind): Add GOMP_MAP_NONCONTIG_ARRAY,
GOMP_MAP_NONCONTIG_ARRAY_TO, GOMP_MAP_NONCONTIG_ARRAY_FROM,
GOMP_MAP_NONCONTIG_ARRAY_TOFROM, GOMP_MAP_

[gcc/devel/omp/gcc-14] Enable firstprivate OpenACC reductions

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:38dfac029a0fddcf70bcff08adf1d68fd437662b

commit 38dfac029a0fddcf70bcff08adf1d68fd437662b
Author: Julian Brown 
Date:   Tue Feb 26 15:59:03 2019 -0800

Enable firstprivate OpenACC reductions

2018-09-05  Cesar Philippidis  
Chung-Lin Tang  

gcc/
* gimplify.cc (omp_add_variable): Enable firstprivate reduction
variables.

gcc/testsuite/
* c-c++-common/goacc/reduction-10.c: New test.

libgomp/
* testsuite/libgomp.oacc-c-c++-common/privatize-reduction-1.c: New
test.
* testsuite/libgomp.oacc-c-c++-common/privatize-reduction-2.c: New
test.

Diff:
---
 gcc/ChangeLog.omp  |  6 ++
 gcc/gimplify.cc| 19 +++--
 gcc/testsuite/ChangeLog.omp|  5 ++
 gcc/testsuite/c-c++-common/goacc/reduction-10.c| 93 ++
 libgomp/ChangeLog.omp  |  8 ++
 .../privatize-reduction-1.c| 41 ++
 .../privatize-reduction-2.c| 23 ++
 7 files changed, 188 insertions(+), 7 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index e2c65c4e789..1a936376617 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,9 @@
+2018-09-05  Cesar Philippidis  
+   Chung-Lin Tang  
+
+   * gimplify.cc (omp_add_variable): Enable firstprivate reduction
+   variables.
+
 2018-09-20  Cesar Philippidis  
 
* omp-low.cc (lower_oacc_head_mark): Don't mark OpenACC auto
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index 07f835c17d9..086bcc259f5 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -7793,20 +7793,27 @@ omp_add_variable (struct gimplify_omp_ctx *ctx, tree 
decl, unsigned int flags)
   else
 splay_tree_insert (ctx->variables, (splay_tree_key)decl, flags);
 
-  /* For reductions clauses in OpenACC loop directives, by default create a
- copy clause on the enclosing parallel construct for carrying back the
- results.  */
+  /* For OpenACC loop directives, when a reduction clause is placed on
+ the outermost acc loop within an acc parallel or kernels
+ construct, it must have an implied copy data mapping. E.g.
+
+   #pragma acc parallel
+{
+  #pragma acc loop reduction (+:sum)
+
+ a copy clause for sum should be added on the enclosing parallel
+ construct for carrying back the results.  */
   if (ctx->region_type == ORT_ACC && (flags & GOVD_REDUCTION))
 {
   struct gimplify_omp_ctx *outer_ctx = ctx->outer_context;
-  while (outer_ctx)
+  if (outer_ctx)
{
  n = splay_tree_lookup (outer_ctx->variables, (splay_tree_key)decl);
  if (n != NULL)
{
  /* Ignore local variables and explicitly declared clauses.  */
  if (n->value & (GOVD_LOCAL | GOVD_EXPLICIT))
-   break;
+   ;
  else if (outer_ctx->region_type == ORT_ACC_KERNELS)
{
  /* According to the OpenACC spec, such a reduction variable
@@ -7826,9 +7833,7 @@ omp_add_variable (struct gimplify_omp_ctx *ctx, tree 
decl, unsigned int flags)
{
  splay_tree_insert (outer_ctx->variables, (splay_tree_key)decl,
 GOVD_MAP | GOVD_SEEN);
- break;
}
- outer_ctx = outer_ctx->outer_context;
}
 }
 }
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 5f40504a53e..96699d4a74f 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,8 @@
+2018-09-05  Cesar Philippidis  
+   Chung-Lin Tang  
+
+   * c-c++-common/goacc/reduction-10.c: New test.
+
 2018-09-20  Cesar Philippidis  
 
* c-c++-common/goacc/loop-auto-1.c: Adjust test case to conform to
diff --git a/gcc/testsuite/c-c++-common/goacc/reduction-10.c 
b/gcc/testsuite/c-c++-common/goacc/reduction-10.c
new file mode 100644
index 000..579aa561479
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/goacc/reduction-10.c
@@ -0,0 +1,93 @@
+/* { dg-additional-options "-fdump-tree-gimple" } */
+
+#define n 1000
+
+int
+main(void)
+{
+  int i, j;
+  int result, array[n];
+
+#pragma acc parallel loop reduction (+:result)
+  for (i = 0; i < n; i++)
+result ++;
+
+#pragma acc parallel
+#pragma acc loop reduction (+:result)
+  for (i = 0; i < n; i++)
+result ++;
+
+#pragma acc parallel
+#pragma acc loop
+  for (i = 0; i < n; i++)
+{
+  result = i;
+
+#pragma acc loop reduction(+:result)
+  for (j = 0; j < n; j++)
+   result ++;
+
+  array[i] = result;
+}
+
+#pragma acc parallel
+#pragma acc loop
+  for (i = 0; i < n; i++)
+{
+  result = i;
+
+#pragma acc loop worker vector reduction(+:result)
+  for (j = 0; j < n; j++)
+   result ++;
+
+  array[i] = resu

[gcc/devel/omp/gcc-14] Don't mark OpenACC auto loops as independent inside acc parallel regions

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:3c0d30600e09e0cdd62b8eaa1ee046f93756f8be

commit 3c0d30600e09e0cdd62b8eaa1ee046f93756f8be
Author: Julian Brown 
Date:   Tue Feb 26 15:55:23 2019 -0800

Don't mark OpenACC auto loops as independent inside acc parallel regions

2018-09-20  Cesar Philippidis  

gcc/
* omp-low.cc (lower_oacc_head_mark): Don't mark OpenACC auto
loops as independent inside acc parallel regions.

gcc/testsuite/
* c-c++-common/goacc/loop-auto-1.c: Adjust test case to conform to
the new behavior of the auto clause in OpenACC 2.5.
* c-c++-common/goacc/loop-auto-2.c: Likewise.
* gcc.dg/goacc/loop-processing-1.c: Likewise.
* c-c++-common/goacc/loop-auto-3.c: New test.
* gfortran.dg/goacc/loop-auto-1.f90: New test.

libgomp/
* testsuite/libgomp.oacc-c-c++-common/loop-auto-1.c: Adjust test 
case
to conform to the new behavior of the auto clause in OpenACC 2.5.

Diff:
---
 gcc/ChangeLog.omp  |  5 ++
 gcc/omp-low.cc |  6 +-
 gcc/testsuite/ChangeLog.omp|  9 +++
 gcc/testsuite/c-c++-common/goacc/loop-auto-1.c | 50 ++--
 gcc/testsuite/c-c++-common/goacc/loop-auto-2.c |  4 +-
 gcc/testsuite/c-c++-common/goacc/loop-auto-3.c | 78 +++
 gcc/testsuite/gcc.dg/goacc/loop-processing-1.c |  2 +-
 gcc/testsuite/gfortran.dg/goacc/loop-auto-1.f90| 88 ++
 libgomp/ChangeLog.omp  |  5 ++
 .../libgomp.oacc-c-c++-common/loop-auto-1.c| 20 ++---
 10 files changed, 227 insertions(+), 40 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index b305525df30..e2c65c4e789 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,8 @@
+2018-09-20  Cesar Philippidis  
+
+   * omp-low.cc (lower_oacc_head_mark): Don't mark OpenACC auto
+   loops as independent inside acc parallel regions.
+
 2018-12-22  Cesar Philippidis  
 Julian Brown  
 Tobias Burnus  
diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index e53e4e3a7db..a6da27934de 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -8545,8 +8545,10 @@ lower_oacc_head_mark (location_t loc, tree ddvar, tree 
clauses,
   else
 gcc_unreachable ();
 
-  /* In a parallel region, loops are implicitly INDEPENDENT.  */
-  if (!tgt || is_oacc_parallel_or_serial (tgt))
+  /* In a parallel region, loops without auto and seq clauses are
+ implicitly INDEPENDENT.  */
+  if ((!tgt || is_oacc_parallel_or_serial (tgt))
+  && !(tag & (OLF_SEQ | OLF_AUTO)))
 tag |= OLF_INDEPENDENT;
 
   /* Loops inside OpenACC 'kernels' decomposed parts' regions are expected to
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index bb18fa23628..5f40504a53e 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,12 @@
+2018-09-20  Cesar Philippidis  
+
+   * c-c++-common/goacc/loop-auto-1.c: Adjust test case to conform to
+   the new behavior of the auto clause in OpenACC 2.5.
+   * c-c++-common/goacc/loop-auto-2.c: Likewise.
+   * gcc.dg/goacc/loop-processing-1.c: Likewise.
+   * c-c++-common/goacc/loop-auto-3.c: New test.
+   * gfortran.dg/goacc/loop-auto-1.f90: New test.
+
 2018-10-05  Nathan Sidwell  
Tom de Vries  
Thomas Schwinge  
diff --git a/gcc/testsuite/c-c++-common/goacc/loop-auto-1.c 
b/gcc/testsuite/c-c++-common/goacc/loop-auto-1.c
index 124befc4002..dcad07f11c8 100644
--- a/gcc/testsuite/c-c++-common/goacc/loop-auto-1.c
+++ b/gcc/testsuite/c-c++-common/goacc/loop-auto-1.c
@@ -10,7 +10,7 @@ void Foo ()
 #pragma acc loop seq
for (int jx = 0; jx < 10; jx++) {}
 
-#pragma acc loop auto /* { dg-warning "insufficient partitioning" } */
+#pragma acc loop auto independent /* { dg-warning "insufficient partitioning" 
} */
for (int jx = 0; jx < 10; jx++) {}
   }
 
@@ -20,7 +20,7 @@ void Foo ()
 #pragma acc loop auto
for (int jx = 0; jx < 10; jx++) {}
 
-#pragma acc loop auto /* { dg-warning "insufficient partitioning" } */
+#pragma acc loop auto independent /* { dg-warning "insufficient partitioning" 
} */
for (int jx = 0; jx < 10; jx++)
  {
 #pragma acc loop vector
@@ -51,7 +51,7 @@ void Foo ()
 #pragma acc loop vector
for (int jx = 0; jx < 10; jx++)
  {
-#pragma acc loop auto /* { dg-warning "insufficient partitioning" } */
+#pragma acc loop auto independent /* { dg-warning "insufficient partitioning" 
} */
for (int kx = 0; kx < 10; kx++) {}
  }
 
@@ -64,27 +64,27 @@ void Foo ()
 
   }
 
-#pragma acc loop auto
+#pragma acc loop auto independent
 for (int ix = 0; ix < 10; ix++)
   {
-#pragma acc loop auto
+#pragma acc loop auto independent
for (int jx = 0; jx < 10; jx++)
  {
-#pragma acc l

[gcc/devel/omp/gcc-14] Tweak target selector for libgomp.oacc-c-c++-common/lib-93.c.

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:492bac7bbe908f9330095f4212a2227f752aa0f3

commit 492bac7bbe908f9330095f4212a2227f752aa0f3
Author: Julian Brown 
Date:   Tue Mar 19 06:53:56 2019 -0700

Tweak target selector for libgomp.oacc-c-c++-common/lib-93.c.

libgomp/
* testsuite/libgomp.oacc-c-c++-common/lib-93.c: Adjust target 
selector.

Diff:
---
 libgomp/ChangeLog.omp| 4 
 libgomp/testsuite/libgomp.oacc-c-c++-common/lib-93.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 6c0f9951eb9..3c0e493531d 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,7 @@
+2019-03-19  Julian Brown  
+
+   * testsuite/libgomp.oacc-c-c++-common/lib-93.c: Adjust target selector.
+
 2018-09-05  Cesar Philippidis  
Chung-Lin Tang  
 
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-93.c 
b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-93.c
index bc60a16c64f..07d2541599a 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-93.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-93.c
@@ -1,4 +1,4 @@
-/* { dg-do run { target { ! openacc_nvidia_accel_configured } } } */
+/* { dg-do run { target { ! openacc_nvidia_accel_selected } } } */
 
 #include 
 #include 


[gcc/devel/omp/gcc-14] Tweak error return value for acc_set_cuda_stream.

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:9707e3cd58f569a555800f673c41f69bb95af073

commit 9707e3cd58f569a555800f673c41f69bb95af073
Author: Julian Brown 
Date:   Tue Feb 12 06:36:03 2019 -0800

Tweak error return value for acc_set_cuda_stream.

The return value of acc_set_cuda_stream is unspecified in OpenACC 2.6.
The testsuite changes might be unnecessary with the current async code.

libgomp/
* oacc-cuda.c (acc_set_cuda_stream): Return 0 on error/invalid
arguments.
* testsuite/libgomp.oacc-c-c++-common/lib-84.c: Handle unnumbered
async stream being an alias for a numbered async stream.
* testsuite/libgomp.oacc-c-c++-common/lib-85.c: Likewise.

Diff:
---
 libgomp/ChangeLog.omp| 8 
 libgomp/oacc-cuda.c  | 5 -
 libgomp/testsuite/libgomp.oacc-c-c++-common/lib-84.c | 6 ++
 libgomp/testsuite/libgomp.oacc-c-c++-common/lib-85.c | 6 ++
 4 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 1bfebcb3217..2769eb88dad 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,11 @@
+2019-02-12  Julian Brown 
+
+   * oacc-cuda.c (acc_set_cuda_stream): Return 0 on error/invalid
+   arguments.
+   * testsuite/libgomp.oacc-c-c++-common/lib-84.c: Handle unnumbered
+   async stream being an alias for a numbered async stream.
+   * testsuite/libgomp.oacc-c-c++-common/lib-85.c: Likewise.
+
 2020-04-19  Chung-Lin Tang  
 
PR other/76739
diff --git a/libgomp/oacc-cuda.c b/libgomp/oacc-cuda.c
index 83bbb37c0e9..74cb95b4c1c 100644
--- a/libgomp/oacc-cuda.c
+++ b/libgomp/oacc-cuda.c
@@ -115,6 +115,9 @@ acc_get_cuda_stream (int async)
   return ret;
 }
 
+/* As of OpenACC 2.6, the return code of this function appears to be
+   unspecified.  We choose to return 1 for success, or 0 for failure.  */
+
 int
 acc_set_cuda_stream (int async, void *stream)
 {
@@ -127,7 +130,7 @@ acc_set_cuda_stream (int async, void *stream)
 
   thr = goacc_thread ();
 
-  int ret = -1;
+  int ret = 0;
   if (thr && thr->dev && thr->dev->openacc.cuda.set_stream_func)
 {
   acc_prof_info prof_info;
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-84.c 
b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-84.c
index c1ff76372fc..674e09a251d 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-84.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-84.c
@@ -39,6 +39,12 @@ main (int argc, char **argv)
   if (streams[i] != NULL)
abort ();
 
+  /* The no-value async may be an alias for a numbered async stream.
+Skip over setting it below else the above NULL check will fail for
+the aliased stream.  */
+  if (i == acc_async_noval)
+   continue;
+
   r = cuStreamCreate (&streams[i], CU_STREAM_DEFAULT);
   if (r != CUDA_SUCCESS)
{
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-85.c 
b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-85.c
index db250657ac5..4e5c7b1b905 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-85.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-85.c
@@ -39,6 +39,12 @@ main (int argc, char **argv)
   if (streams[i] != NULL)
abort ();
 
+  /* The no-value async may be an alias for a numbered async stream.
+ Skip over setting it below else the above NULL check will fail for
+ the aliased stream.  */
+  if (i == acc_async_noval)
+   continue;
+
   r = cuStreamCreate (&streams[i], CU_STREAM_DEFAULT);
   if (r != CUDA_SUCCESS)
{


[gcc/devel/omp/gcc-14] Add changes to profiling interface from OG8 branch

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:5b50c1a9025c19112ea37d613147f814632a707e

commit 5b50c1a9025c19112ea37d613147f814632a707e
Author: Kwok Cheung Yeung 
Date:   Fri Jun 21 10:40:38 2019 -0700

Add changes to profiling interface from OG8 branch

This bundles up the parts of the profiling code from the OG8 branch that 
were
not included in the upstream patch.

libgomp/
* testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c: Update.

libgomp/
* oacc-init.c (get_property_any): Add profiling code.

libgomp/
* Makefile.am (libgomp_la_SOURCES): Add
oacc-profiling-acc_register_library.c.
* Makefile.in: Regenerate.
* libgomp.texi: Remove paragraph about acc_register_library.
* oacc-parallel.c (GOACC_parallel_keyed_internal): Set device_api 
for
profiling.
* oacc-profiling-acc_register_library.c: New file.
* oacc-profiling.c (goacc_profiling_initialize): Call
acc_register_library.  Avoid duplicate registration.
(acc_register_library): Remove.
* config/nvptx/oacc-profiling-acc_register_library.c:
New empty file.
* config/nvptx/oacc-profiling.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/acc_prof-dispatch-1.c: Remove
call to acc_register_library.
* testsuite/libgomp.oacc-c-c++-common/acc_prof-init-1.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c: 
Likewise.
* testsuite/libgomp.oacc-c-c++-common/acc_prof-parallel-1.c: 
Likewise.
* testsuite/libgomp.oacc-c-c++-common/acc_prof-valid_bytes-1.c:
Likewise.
* testsuite/libgomp.oacc-c-c++-common/acc_prof-version-1.c: 
Likewise.

Diff:
---
 libgomp/ChangeLog.omp  | 32 ++
 libgomp/Makefile.am|  2 +-
 libgomp/Makefile.in|  9 +++--
 .../nvptx/oacc-profiling-acc_register_library.c|  0
 libgomp/config/nvptx/oacc-profiling.c  |  0
 libgomp/libgomp.texi   |  8 -
 libgomp/oacc-init.c| 21 +++-
 libgomp/oacc-parallel.c|  2 ++
 libgomp/oacc-profiling-acc_register_library.c  | 39 ++
 libgomp/oacc-profiling.c   | 32 +++---
 .../acc_prof-dispatch-1.c  |  2 --
 .../libgomp.oacc-c-c++-common/acc_prof-init-1.c|  2 --
 .../libgomp.oacc-c-c++-common/acc_prof-kernels-1.c | 19 +++
 .../acc_prof-parallel-1.c  |  2 --
 .../acc_prof-valid_bytes-1.c   |  2 --
 .../libgomp.oacc-c-c++-common/acc_prof-version-1.c |  2 --
 16 files changed, 133 insertions(+), 41 deletions(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 6d67a9e9bc6..6262293cb35 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,35 @@
+2019-01-23  Thomas Schwinge 
+
+   * testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c: Update.
+
+2018-12-20  Maciej W. Rozycki  
+
+   * oacc-init.c (get_property_any): Add profiling code.
+
+2017-02-28  Thomas Schwinge  
+
+   * Makefile.am (libgomp_la_SOURCES): Add
+   oacc-profiling-acc_register_library.c.
+   * Makefile.in: Regenerate.
+   * libgomp.texi: Remove paragraph about acc_register_library.
+   * oacc-parallel.c (GOACC_parallel_keyed_internal): Set device_api for
+   profiling.
+   * oacc-profiling-acc_register_library.c: New file.
+   * oacc-profiling.c (goacc_profiling_initialize): Call
+   acc_register_library.  Avoid duplicate registration.
+   (acc_register_library): Remove.
+   * config/nvptx/oacc-profiling-acc_register_library.c:
+   New empty file.
+   * config/nvptx/oacc-profiling.c: Likewise.
+   * testsuite/libgomp.oacc-c-c++-common/acc_prof-dispatch-1.c: Remove
+   call to acc_register_library.
+   * testsuite/libgomp.oacc-c-c++-common/acc_prof-init-1.c: Likewise.
+   * testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c: Likewise.
+   * testsuite/libgomp.oacc-c-c++-common/acc_prof-parallel-1.c: Likewise.
+   * testsuite/libgomp.oacc-c-c++-common/acc_prof-valid_bytes-1.c:
+   Likewise.
+   * testsuite/libgomp.oacc-c-c++-common/acc_prof-version-1.c: Likewise.
+
 2019-01-09  Julian Brown  
 
* libgomp.texi: Update mentions of OpenACC version to 2.6.  Update
diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index 1871590596d..4ca22ba2d95 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -72,7 +72,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
target.c splay-tree.c libgomp-plugin.c oacc-parallel.c oacc-host.c \
oacc-init.c oacc-mem.c oacc-async.c oacc-plugin

[gcc/devel/omp/gcc-14] Add OpenACC Fortran support for deviceptr and variable in common blocks

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:987bb4c25b4076eb54f043644bdf9988378be90d

commit 987bb4c25b4076eb54f043644bdf9988378be90d
Author: Julian Brown 
Date:   Tue Feb 12 14:32:34 2019 -0800

Add OpenACC Fortran support for deviceptr and variable in common blocks

2018-06-29  Cesar Philippidis  
James Norris  

gcc/fortran/
* openmp.cc (gfc_match_omp_map_clause): Re-write handling of the
deviceptr clause.  Add new common_blocks argument.  Propagate it to
gfc_match_omp_variable_list.
(gfc_match_omp_clauses): Update calls to gfc_match_omp_map_clauses.
(resolve_positive_int_expr): Promote the warning to an error.
(check_array_not_assumed): Remove pointer check.
(resolve_oacc_nested_loops): Error on do concurrent loops.
* trans-openmp.cc (gfc_omp_finish_clause): Don't create pointer data
mappings for deviceptr clauses.
(gfc_trans_omp_clauses): Likewise.

gcc/
* gimplify.cc (enum gimplify_omp_var_data): Add GOVD_DEVICETPR.
(oacc_default_clause): Privatize fortran common blocks.
(omp_notice_variable): Add GOVD_DEVICEPTR attribute when 
appropriate.
Defer the expansion of DECL_VALUE_EXPR for common block decls.
(gimplify_scan_omp_clauses): Add GOVD_DEVICEPTR attribute when
appropriate.
(gimplify_adjust_omp_clauses_1): Set GOMP_MAP_FORCE_DEVICEPTR for
implicit deviceptr mappings.

gcc/testsuite/
* c-c++-common/goacc/deviceptr-4.c: Update.
* gfortran.dg/goacc/loop-2-kernels-tile.f95: Update.
* gfortran.dg/goacc/loop-2-parallel-tile.f95: Update.
* gfortran.dg/goacc/sie.f95: Update.
* gfortran.dg/goacc/tile-1.f90: Update.
* gfortran.dg/gomp/pr77516.f90: Update.

libgomp/
* oacc-parallel.c (GOACC_parallel_keyed): Handle Fortran deviceptr
clause.
(GOACC_data_start): Likewise.
* testsuite/libgomp.oacc-fortran/deviceptr-1.f90: New test.

Diff:
---
 gcc/ChangeLog.omp  |  10 ++
 gcc/fortran/ChangeLog.omp  |   6 +
 gcc/fortran/openmp.cc  |   5 +-
 gcc/fortran/trans-openmp.cc|   9 +
 gcc/gimplify.cc|  12 +-
 gcc/testsuite/ChangeLog.omp|  10 ++
 gcc/testsuite/c-c++-common/goacc/deviceptr-4.c |   2 +-
 .../gfortran.dg/goacc/loop-2-kernels-tile.f95  |   4 +-
 .../gfortran.dg/goacc/loop-2-parallel-tile.f95 |   4 +-
 gcc/testsuite/gfortran.dg/goacc/sie.f95|  36 ++--
 gcc/testsuite/gfortran.dg/goacc/tile-1.f90 |  16 +-
 gcc/testsuite/gfortran.dg/gomp/pr77516.f90 |   2 +-
 libgomp/ChangeLog.omp  |   8 +
 libgomp/oacc-parallel.c|   2 +
 .../testsuite/libgomp.oacc-fortran/deviceptr-1.f90 | 197 +
 15 files changed, 287 insertions(+), 36 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 4b389ee8046..4f4d1dbfad4 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,13 @@
+2018-06-29  Cesar Philippidis  
+   James Norris  
+
+   * gimplify.cc (enum gimplify_omp_var_data): Add GOVD_DEVICETPR.
+   (omp_notice_variable): Add GOVD_DEVICEPTR attribute when appropriate.
+   (gimplify_scan_omp_clauses): Add GOVD_DEVICEPTR attribute when
+   appropriate.
+   (gimplify_adjust_omp_clauses_1): Set GOMP_MAP_FORCE_DEVICEPTR for
+   implicit deviceptr mappings.
+
 2023-04-18  Kwok Cheung Yeung  
 
* gimplify.cc (omp_group_base): Handle GOMP_MAP_NONCONTIG_ARRAY_*
diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp
index b742e1bfe35..379b2aee149 100644
--- a/gcc/fortran/ChangeLog.omp
+++ b/gcc/fortran/ChangeLog.omp
@@ -1,3 +1,9 @@
+2018-06-29  Cesar Philippidis  
+   James Norris  
+
+   * openmp.cc (resolve_positive_int_expr): Promote the warning to an
+   error.
+
 2020-04-19  Chung-Lin Tang  
 
PR other/76739
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 315ec68f259..2dbe89057b1 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -7158,9 +7158,8 @@ resolve_positive_int_expr (gfc_expr *expr, const char 
*clause)
   if (expr->expr_type == EXPR_CONSTANT
   && expr->ts.type == BT_INTEGER
   && mpz_sgn (expr->value.integer) <= 0)
-gfc_warning ((flag_openmp || flag_openmp_simd) ? OPT_Wopenmp : 0,
-"INTEGER expression of %s clause at %L must be positive",
-clause, &expr->where);
+gfc_error ("INTEGER expression of %s clause at %L must be positive",
+  clause, &expr->where);
 }
 
 static void
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index f867e2240

[gcc/devel/omp/gcc-14] NVPTX GOMP_OFFLOAD_openacc_async_construct arg fix and gomp_print_* support

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:0225c5c9aa9adfc3cfd269b40288a5ba671d0d93

commit 0225c5c9aa9adfc3cfd269b40288a5ba671d0d93
Author: Julian Brown 
Date:   Mon Jul 29 15:05:35 2019 -0700

NVPTX GOMP_OFFLOAD_openacc_async_construct arg fix and gomp_print_* support

libgomp/
* config/nvptx/gomp_print.c (gomp_print_string, gomp_print_integer,
gomp_print_double): New.

Diff:
---
 libgomp/ChangeLog.omp |  5 +
 libgomp/config/nvptx/gomp_print.c | 20 
 2 files changed, 25 insertions(+)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 6262293cb35..9cdcb3d18ab 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,8 @@
+2019-07-31  Julian Brown  
+
+   * config/nvptx/gomp_print.c (gomp_print_string, gomp_print_integer,
+   gomp_print_double): New.
+
 2019-01-23  Thomas Schwinge 
 
* testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c: Update.
diff --git a/libgomp/config/nvptx/gomp_print.c 
b/libgomp/config/nvptx/gomp_print.c
new file mode 100644
index 000..811bdd6e9a9
--- /dev/null
+++ b/libgomp/config/nvptx/gomp_print.c
@@ -0,0 +1,20 @@
+#include 
+#include 
+
+void
+gomp_print_string (const char *msg, const char *value)
+{
+  printf ("%s%s\n", msg, value);
+}
+
+void
+gomp_print_integer (const char *msg, int64_t value)
+{
+  printf ("%s%ld\n", msg, value);
+}
+
+void
+gomp_print_double (const char *msg, double value)
+{
+  printf ("%s%f\n", msg, value);
+}


[gcc/devel/omp/gcc-14] Various OpenACC reduction enhancements - FE changes

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:bae1b81b71b158901d0342b471450a3938ef2828

commit bae1b81b71b158901d0342b471450a3938ef2828
Author: Julian Brown 
Date:   Tue Feb 12 14:56:12 2019 -0800

Various OpenACC reduction enhancements - FE changes

This version differs somewhat from the last version posted upstream
(and addresses some of Jakub's review comments).

2018-12-13  Cesar Philippidis  
Nathan Sidwell  
Julian Brown  

gcc/c/
* c-parser.cc (c_parser_omp_variable_list): New c_omp_region_type
argument.  Use it to specialize handling of OMP_CLAUSE_REDUCTION for
OpenACC.
(c_parser_oacc_data_clause): Add region-type argument.
(c_parser_oacc_data_clause_deviceptr): Likewise.
(c_parser_omp_clause_reduction): Change is_omp boolean parameter to
c_omp_region_type.  Update call to c_parser_omp_variable_list.
(c_parser_oacc_all_clauses): Update calls to
c_parser_omp_clause_reduction.
(c_parser_omp_all_clauses): Likewise.
(c_parser_oacc_cache): Update call to c_parser_omp_var_list_parens.
* c-typeck.cc (c_finish_omp_clauses): Emit an error on orphan 
OpenACC
gang reductions.  Suppress user-defined reduction error for OpenACC.

gcc/cp/
* parser.cc (cp_parser_omp_var_list_no_open):  New c_omp_region_type
argument.  Use it to specialize handling of OMP_CLAUSE_REDUCTION for
OpenACC.
(cp_parser_omp_var_list): Add c_omp_region_type argument. Update 
call
to cp_parser_omp_var_list_parens.
(cp_parser_oacc_data_clause): Update call to cp_parser_omp_var_list.
(cp_parser_omp_clause_reduction): Change is_omp boolean parameter to
c_omp_region_type.  Update call to cp_parser_omp_var_list_no_open.
(cp_parser_oacc_all_clauses): Update call to
cp_parser_omp_clause_reduction.
(cp_parser_omp_all_clauses): Likewise.
* semantics.cc (finish_omp_reduction_clause): Add c_omp_region_type
argument.  Suppress user-defined reduction error for OpenACC.
(finish_omp_clauses): Emit an error on orphan OpenACC gang 
reductions.

gcc/fortran/
* openmp.cc (oacc_is_parallel): New.
(resolve_oacc_loop_blocks): Emit an error on orphan OpenACC
gang reductions.
* trans-openmp.cc (gfc_omp_clause_copy_ctor): Permit reductions.

2022-02-03  Kwok Cheung Yeung  

gcc/c/
* c-parser.cc (c_parser_omp_clause_map): Update call to
c_parser_omp_variable_list.
(c_parser_omp_clause_to): Update call to 
c_parser_omp_var_list_parens.
(c_parser_omp_clause_from): Likewise.

gcc/cp/
* parser.cc (cp_parser_omp_clause_map): Update call to
cp_parser_omp_var_list_no_open.
(cp_parser_omp_all_clauses): Update calls to cp_parser_omp_var_list.

Diff:
---
 gcc/c/ChangeLog.omp | 25 +
 gcc/c/c-parser.cc   | 41 -
 gcc/c/c-typeck.cc   |  7 +--
 gcc/cp/ChangeLog.omp| 25 +
 gcc/cp/parser.cc| 29 -
 gcc/cp/semantics.cc | 15 +--
 gcc/fortran/ChangeLog.omp   |  9 +
 gcc/fortran/trans-openmp.cc |  3 ++-
 8 files changed, 115 insertions(+), 39 deletions(-)

diff --git a/gcc/c/ChangeLog.omp b/gcc/c/ChangeLog.omp
index 76ed3228d5d..a95b2adc8f8 100644
--- a/gcc/c/ChangeLog.omp
+++ b/gcc/c/ChangeLog.omp
@@ -1,3 +1,28 @@
+2022-02-03  Kwok Cheung Yeung  
+
+   * c-parser.ccc (c_parser_omp_clause_map): Update call to
+   c_parser_omp_variable_list.
+   (c_parser_omp_clause_to): Update call to c_parser_omp_var_list_parens.
+   (c_parser_omp_clause_from): Likewise.
+
+2018-12-13  Cesar Philippidis  
+   Nathan Sidwell  
+   Julian Brown  
+
+   * c-parser.c (c_parser_omp_variable_list): New c_omp_region_type
+   argument.  Use it to specialize handling of OMP_CLAUSE_REDUCTION for
+   OpenACC.
+   (c_parser_oacc_data_clause): Add region-type argument.
+   (c_parser_oacc_data_clause_deviceptr): Likewise.
+   (c_parser_omp_clause_reduction): Change is_omp boolean parameter to
+   c_omp_region_type.  Update call to c_parser_omp_variable_list.
+   (c_parser_oacc_all_clauses): Update calls to
+   c_parser_omp_clause_reduction.
+   (c_parser_omp_all_clauses): Likewise.
+   (c_parser_oacc_cache): Update call to c_parser_omp_var_list_parens.
+   * c-typeck.c (c_finish_omp_clauses): Emit an error on orphan OpenACC
+   gang reductions.  Suppress user-defined reduction error for OpenACC.
+
 2020-04-19  Chung-Lin Tang  
 
PR other/76739
diff --git a/gcc/c/c-parser.cc

[gcc/devel/omp/gcc-14] Fix libgomp.oacc-fortran/lib-13.f90 async bug

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:8998cc60c1cbbdef603090eab63e5835bf071d41

commit 8998cc60c1cbbdef603090eab63e5835bf071d41
Author: Julian Brown 
Date:   Tue Sep 3 07:57:05 2019 -0700

Fix libgomp.oacc-fortran/lib-13.f90 async bug

libgomp/
* testsuite/libgomp.oacc-fortran/lib-13.f90: End data region after
wait API calls.

Diff:
---
 libgomp/ChangeLog.omp | 5 +
 libgomp/testsuite/libgomp.oacc-fortran/lib-13.f90 | 3 +--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 0b91f66735d..0aa2e823b36 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,8 @@
+2019-09-05  Julian Brown  
+
+   * testsuite/libgomp.oacc-fortran/lib-13.f90: End data region after
+   wait API calls.
+
 2019-08-08  Julian Brown  
 
* plugin/plugin-gcn.c (GOMP_OFFLOAD_openacc_exec_params,
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/lib-13.f90 
b/libgomp/testsuite/libgomp.oacc-fortran/lib-13.f90
index deb2c288604..f6bd27a4701 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/lib-13.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/lib-13.f90
@@ -19,11 +19,10 @@ program main
 end do
   !$acc end parallel
 end do
-  !$acc end data
 
   call acc_wait_all_async (nprocs + 1)
-
   call acc_wait (nprocs + 1)
+  !$acc end data
 
   if (acc_async_test (1) .neqv. .TRUE.) stop 1
   if (acc_async_test (2) .neqv. .TRUE.) stop 2


[gcc/devel/omp/gcc-14] Add missing exec_params libgomp plugin entry points

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:41fe653017bfa52e6a479a2760a480b49b75f862

commit 41fe653017bfa52e6a479a2760a480b49b75f862
Author: Julian Brown 
Date:   Mon Aug 5 15:05:35 2019 -0700

Add missing exec_params libgomp plugin entry points

libgomp/
* plugin/plugin-gcn.c (GOMP_OFFLOAD_openacc_exec_params,
GOMP_OFFLOAD_openacc_async_exec_params): New functions.

Diff:
---
 libgomp/ChangeLog.omp   |  5 +
 libgomp/plugin/plugin-gcn.c | 17 +
 2 files changed, 22 insertions(+)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 9cdcb3d18ab..0b91f66735d 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,8 @@
+2019-08-08  Julian Brown  
+
+   * plugin/plugin-gcn.c (GOMP_OFFLOAD_openacc_exec_params,
+   GOMP_OFFLOAD_openacc_async_exec_params): New functions.
+
 2019-07-31  Julian Brown  
 
* config/nvptx/gomp_print.c (gomp_print_string, gomp_print_integer,
diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c
index 3cdc7ba929f..4988dfb0c8e 100644
--- a/libgomp/plugin/plugin-gcn.c
+++ b/libgomp/plugin/plugin-gcn.c
@@ -4415,6 +4415,14 @@ GOMP_OFFLOAD_openacc_exec (void (*fn_ptr) (void *),
 
 /* Run an asynchronous OpenACC kernel on the specified queue.  */
 
+void
+GOMP_OFFLOAD_openacc_exec_params (void (*fn_ptr) (void *), size_t mapnum,
+ void **hostaddrs, void **devaddrs,
+ unsigned *dims, void *targ_mem_desc)
+{
+  GOMP_PLUGIN_fatal ("OpenACC exec params unimplemented.");
+}
+
 void
 GOMP_OFFLOAD_openacc_async_exec (void (*fn_ptr) (void *),
 size_t mapnum __attribute__((unused)),
@@ -4430,6 +4438,15 @@ GOMP_OFFLOAD_openacc_async_exec (void (*fn_ptr) (void *),
 
 /* Create a new asynchronous thread and queue for running future kernels.  */
 
+void
+GOMP_OFFLOAD_openacc_async_exec_params (void (*fn) (void *), size_t mapnum,
+   void **hostaddrs, void **devaddrs,
+   unsigned *dims, void *targ_mem_desc,
+   struct goacc_asyncqueue *aq)
+{
+  GOMP_PLUGIN_fatal ("OpenACC async exec params unimplemented.");
+}
+
 struct goacc_asyncqueue *
 GOMP_OFFLOAD_openacc_async_construct (int device)
 {


[gcc/devel/omp/gcc-14] Update OpenACC version to 2.6

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:aa9da9b039b10c5ad3b48f010ad0d037b7927ef4

commit aa9da9b039b10c5ad3b48f010ad0d037b7927ef4
Author: Julian Brown 
Date:   Wed Jan 9 03:41:04 2019 -0800

Update OpenACC version to 2.6

libgomp/
* libgomp.texi: Update mentions of OpenACC version to 2.6.  Update
section numbers to match version 2.6 of the spec.

Diff:
---
 libgomp/ChangeLog.omp | 5 +
 libgomp/libgomp.texi  | 5 -
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 3c0e493531d..6d67a9e9bc6 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,8 @@
+2019-01-09  Julian Brown  
+
+   * libgomp.texi: Update mentions of OpenACC version to 2.6.  Update
+   section numbers to match version 2.6 of the spec.
+
 2019-03-19  Julian Brown  
 
* testsuite/libgomp.oacc-c-c++-common/lib-93.c: Adjust target selector.
diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 71d62105a20..e6b54a63e9b 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -4199,6 +4199,9 @@ Generally, they are available only for the host, with the 
exception of
 @code{acc_on_device}, which is available for both the host and the
 acceleration device.
 
+This list has not yet been updated for the OpenACC specification in
+version 2.6.
+
 @menu
 * acc_get_num_devices:: Get number of devices for the given device
 type.
@@ -5556,7 +5559,7 @@ Function for library registration.
 @chapter OpenACC Environment Variables
 
 The variables @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}
-are defined by section 4 of the OpenACC specification in version 2.0.
+are defined by section 4 of the OpenACC specification in version 2.6.
 The variable @env{ACC_PROFLIB}
 is defined by section 4 of the OpenACC specification in version 2.6.


[gcc/devel/omp/gcc-14] Reference reduction localization

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:cfcdfd136fb23355d24d59605cbe3b3979abcd2c

commit cfcdfd136fb23355d24d59605cbe3b3979abcd2c
Author: Julian Brown 
Date:   Tue Sep 3 08:54:28 2019 -0700

Reference reduction localization

gcc/
* gimplify.cc (privatize_reduction): New struct.
(localize_reductions_r, localize_reductions): New functions.
(gimplify_omp_for): Call localize_reductions.
(gimplify_omp_workshare): Likewise.
* omp-low.cc (lower_oacc_reductions): Handle localized reductions.
Create fewer temp vars.
* tree-core.h (omp_clause_code): Add 
OMP_CLAUSE_REDUCTION_PRIVATE_DECL
documentation.
* tree.cc (omp_clause_num_ops): Bump number of ops for
OMP_CLAUSE_REDUCTION to 6.
(walk_tree_1): Adjust accordingly.
* tree.h (OMP_CLAUSE_REDUCTION_PRIVATE_DECL): Add macro.

Diff:
---
 gcc/ChangeLog.omp |  26 ++
 gcc/gimplify.cc   | 102 ++
 gcc/omp-low.cc|  45 +++-
 gcc/tree-core.h   |   4 ++-
 gcc/tree.cc   |   2 +-
 gcc/tree.h|   2 ++
 6 files changed, 146 insertions(+), 35 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 1a936376617..93231368ff4 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,29 @@
+2019-09-06  Julian Brown  
+
+   * gimplify.cc (gimplify_omp_for): Use for_stmt in call to
+   localize_reductions.
+
+2019-09-06  Julian Brown  
+
+   * gimplify.cc (gimplify_omp_workshare): Use OMP_CLAUSES, OMP_BODY
+   instead of OMP_TARGET_CLAUSES, OMP_TARGET_BODY.
+
+2019-09-05  Cesar Philippidis  
+   Julian Brown  
+
+   * gimplify.cc (privatize_reduction): New struct.
+   (localize_reductions_r, localize_reductions): New functions.
+   (gimplify_omp_for): Call localize_reductions.
+   (gimplify_omp_workshare): Likewise.
+   * omp-low.cc (lower_oacc_reductions): Handle localized reductions.
+   Create fewer temp vars.
+   * tree-core.h (omp_clause_code): Add OMP_CLAUSE_REDUCTION_PRIVATE_DECL
+   documentation.
+   * tree.cc (omp_clause_num_ops): Bump number of ops for
+   OMP_CLAUSE_REDUCTION to 6.
+   (walk_tree_1): Adjust accordingly.
+   * tree.h (OMP_CLAUSE_REDUCTION_PRIVATE_DECL): Add macro.
+
 2018-09-05  Cesar Philippidis  
Chung-Lin Tang  
 
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index 086bcc259f5..a96698ab007 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -263,6 +263,11 @@ struct gimplify_omp_ctx
   int defaultmap[5];
 };
 
+struct privatize_reduction
+{
+  tree ref_var, local_var;
+};
+
 static struct gimplify_ctx *gimplify_ctxp;
 static struct gimplify_omp_ctx *gimplify_omp_ctxp;
 static bool in_omp_construct;
@@ -15092,6 +15097,80 @@ find_standalone_omp_ordered (tree *tp, int 
*walk_subtrees, void *)
   return NULL_TREE;
 }
 
+/* Helper function for localize_reductions.  Replace all uses of REF_VAR with
+   LOCAL_VAR.  */
+
+static tree
+localize_reductions_r (tree *tp, int *walk_subtrees, void *data)
+{
+  enum tree_code tc = TREE_CODE (*tp);
+  struct privatize_reduction *pr = (struct privatize_reduction *) data;
+
+  if (TYPE_P (*tp))
+*walk_subtrees = 0;
+
+  switch (tc)
+{
+case INDIRECT_REF:
+case MEM_REF:
+  if (TREE_OPERAND (*tp, 0) == pr->ref_var)
+   *tp = pr->local_var;
+
+  *walk_subtrees = 0;
+  break;
+
+case VAR_DECL:
+case PARM_DECL:
+case RESULT_DECL:
+  if (*tp == pr->ref_var)
+   *tp = pr->local_var;
+
+  *walk_subtrees = 0;
+  break;
+
+default:
+  break;
+}
+
+  return NULL_TREE;
+}
+
+/* OpenACC worker and vector loop state propagation requires reductions
+   to be inside local variables.  This function replaces all reference-type
+   reductions variables associated with the loop with a local copy.  It is
+   also used to create private copies of reduction variables for those
+   which are not associated with acc loops.  */
+
+static void
+localize_reductions (tree clauses, tree body)
+{
+  tree c, var, type, new_var;
+  struct privatize_reduction pr;
+
+  for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
+if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
+  {
+   var = OMP_CLAUSE_DECL (c);
+
+   if (!lang_hooks.decls.omp_privatize_by_reference (var))
+ {
+   OMP_CLAUSE_REDUCTION_PRIVATE_DECL (c) = NULL;
+   continue;
+ }
+
+   type = TREE_TYPE (TREE_TYPE (var));
+   new_var = create_tmp_var (type, IDENTIFIER_POINTER (DECL_NAME (var)));
+
+   pr.ref_var = var;
+   pr.local_var = new_var;
+
+   walk_tree (&body, localize_reductions_r, &pr, NULL);
+
+   OMP_CLAUSE_REDUCTION_PRIVATE_DECL (c) = new_var;
+  }
+}
+
+
 /* Gimplify the gross structure of an OMP_FOR statement.  */
 
 static enum gimplify_status
@@ -15331,6 +15410,24 @@ gimplify_omp_for (tree *expr_p, g

[gcc/devel/omp/gcc-14] Handle references in OpenACC "private" clauses

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:141a592bf147c91c28de7864fa12259687e827e3

commit 141a592bf147c91c28de7864fa12259687e827e3
Author: Julian Brown 
Date:   Fri Sep 20 13:53:10 2019 -0700

Handle references in OpenACC "private" clauses

gcc/
* gimplify.cc (localize_reductions): Rewrite references for
OMP_CLAUSE_PRIVATE also.

Diff:
---
 gcc/ChangeLog.omp |  7 ++-
 gcc/gimplify.cc   | 15 +++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 93231368ff4..53b4189892b 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,8 @@
+2019-09-20  Julian Brown  
+
+   * gimplify.cc (localize_reductions): Rewrite references for
+   OMP_CLAUSE_PRIVATE also.
+
 2019-09-06  Julian Brown  
 
* gimplify.cc (gimplify_omp_for): Use for_stmt in call to
@@ -24,7 +29,7 @@
(walk_tree_1): Adjust accordingly.
* tree.h (OMP_CLAUSE_REDUCTION_PRIVATE_DECL): Add macro.
 
-2018-09-05  Cesar Philippidis  
+2019-07-10  Cesar Philippidis  
Chung-Lin Tang  
 
* gimplify.cc (omp_add_variable): Enable firstprivate reduction
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index a96698ab007..69ffa9698b9 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -15168,6 +15168,21 @@ localize_reductions (tree clauses, tree body)
 
OMP_CLAUSE_REDUCTION_PRIVATE_DECL (c) = new_var;
   }
+else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE)
+  {
+   var = OMP_CLAUSE_DECL (c);
+
+   if (!lang_hooks.decls.omp_privatize_by_reference (var))
+ continue;
+
+   type = TREE_TYPE (TREE_TYPE (var));
+   new_var = create_tmp_var (type, IDENTIFIER_POINTER (DECL_NAME (var)));
+
+   pr.ref_var = var;
+   pr.local_var = new_var;
+
+   walk_tree (&body, localize_reductions_r, &pr, NULL);
+  }
 }


[gcc/devel/omp/gcc-14] Fortran "declare create"/allocate support for OpenACC

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:65be1389eeda9b3b97f6587721215c3f31bd7f98

commit 65be1389eeda9b3b97f6587721215c3f31bd7f98
Author: Julian Brown 
Date:   Tue Feb 26 15:48:00 2019 -0800

Fortran "declare create"/allocate support for OpenACC

2018-10-04  Cesar Philippidis  
Julian Brown  

gcc/
* omp-low.cc (scan_sharing_clauses): Update handling of OpenACC 
declare
create, declare copyin and declare deviceptr to have local 
lifetimes.
(convert_to_firstprivate_int): Handle pointer types.
(convert_from_firstprivate_int): Likewise.  Create local storage for
the values being pointed to.  Add new orig_type argument.
(lower_omp_target): Handle GOMP_MAP_DECLARE_{ALLOCATE,DEALLOCATE}.
Add orig_type argument to convert_from_firstprivate_int call.
Allow pointer types with GOMP_MAP_FIRSTPRIVATE_INT.  Don't privatize
firstprivate VLAs.
* tree-pretty-print.cc (dump_omp_clause): Handle
GOMP_MAP_DECLARE_{ALLOCATE,DEALLOCATE}.

gcc/fortran/
* gfortran.h (enum gfc_omp_map_op): Add OMP_MAP_DECLARE_ALLOCATE,
OMP_MAP_DECLARE_DEALLOCATE.
(gfc_omp_clauses): Add update_allocatable.
* trans-array.cc (gfc_array_allocate): Call
gfc_trans_oacc_declare_allocate for decls that have 
oacc_declare_create
attribute set.
* trans-decl.cc (find_module_oacc_declare_clauses): Relax
oacc_declare_create to OMP_MAP_ALLOC, and oacc_declare_copyin to
OMP_MAP_TO, in order to match OpenACC 2.5 semantics.
* trans-openmp.cc (gfc_trans_omp_clauses): Use 
GOMP_MAP_ALWAYS_POINTER
(for update directive) or GOMP_MAP_FIRSTPRIVATE_POINTER (otherwise) 
for
allocatable scalar decls.  Handle 
OMP_MAP_DECLARE_{ALLOCATE,DEALLOCATE}
clauses.
(gfc_trans_oacc_executable_directive): Use GOMP_MAP_ALWAYS_POINTER
for allocatable scalar data clauses inside acc update directives.
(gfc_trans_oacc_declare_allocate): New function.
* trans-stmt.cc (gfc_trans_allocate): Call
gfc_trans_oacc_declare_allocate for decls with oacc_declare_create
attribute set.
(gfc_trans_deallocate): Likewise.
* trans.h (gfc_trans_oacc_declare_allocate): Declare.

gcc/testsuite/
* gfortran.dg/goacc/declare-allocatable-1.f90: New test.

include/
* gomp-constants.h (enum gomp_map_kind): Define
GOMP_MAP_DECLARE_{ALLOCATE,DEALLOCATE} and GOMP_MAP_FLAG_SPECIAL_4.

libgomp/
* oacc-mem.c (gomp_acc_declare_allocate): New function.
* oacc-parallel.c (GOACC_enter_exit_data): Handle
GOMP_MAP_DECLARE_{ALLOCATE,DEALLOCATE}.
* testsuite/libgomp.oacc-fortran/allocatable-scalar.f90: New test.
* testsuite/libgomp.oacc-fortran/declare-allocatable-2.f90: New 
test.
* testsuite/libgomp.oacc-fortran/declare-allocatable-3.f90: New 
test.
* testsuite/libgomp.oacc-fortran/declare-allocatable-4.f90: New 
test.

2020-02-19  Julian Brown  

gcc/fortran/
* trans-openmp.cc (gfc_omp_check_optional_argument): Handle non-decl
case.

gcc/
* gimplify.cc (gimplify_scan_omp_clauses): Handle
GOMP_MAP_DECLARE_ALLOCATE and GOMP_MAP_DECLARE_DEALLOCATE.

libgomp/
* libgomp.h (gomp_acc_declare_allocate): Remove prototype.
* oacc-mem.c (gomp_acc_declare_allocate): Make static.  Add POINTER
argument. Use acc_delete instead of acc_free.  Handle scalar
mappings.
(find_group_last): Handle GOMP_MAP_DECLARE_ALLOCATE and
GOMP_MAP_DECLARE_DEALLOCATE groupings.
(goacc_enter_data_internal): Fix kind check for
GOMP_MAP_DECLARE_ALLOCATE. Pass new pointer argument to
gomp_acc_declare_allocate.
(goacc_exit_data_internal): Unlock device mutex around
gomp_acc_declare_allocate call. Pass new pointer argument. Handle
group pointer mapping for deallocate.

2021-04-07  Kwok Cheung Yeung  

libgomp/
* oacc-mem.c (goacc_enter_data_internal): Unlock mutex before 
calling
gomp_acc_declare_allocate and relock it afterwards.

2023-04-17  Kwok Cheung Yeung  

* gimplify.cc (omp_group_base): Handle GOMP_MAP_DECLARE_ALLOCATE
and GOMP_MAP_DECLARE_DEALLOCATE.

Diff:
---
 gcc/ChangeLog.omp  |  25 +++
 gcc/fortran/ChangeLog.omp  |  30 +++
 gcc/fortran/gfortran.h |   6 +-
 gcc/fortran/trans-array.cc |   4 +
 gcc/fortran/trans-decl.cc  

[gcc/devel/omp/gcc-14] Fix OpenACC "ephemeral" asynchronous host-to-device copies

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:a9145a813c2716ec613cff163a3bbc9ea108e84d

commit a9145a813c2716ec613cff163a3bbc9ea108e84d
Author: Julian Brown 
Date:   Wed Sep 11 13:22:03 2019 -0700

Fix OpenACC "ephemeral" asynchronous host-to-device copies

libgomp/
* testsuite/libgomp.oacc-c-c++-common/deep-copy-10.c (main): Fix
async-safety issue. Increase number of iterations.

Diff:
---
 libgomp/ChangeLog.omp  |  6 ++
 libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-10.c | 14 --
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 52d5cfe3b25..9389a0eefe3 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,9 @@
+2019-09-17  Julian Brown  
+   Kwok Cheung Yeung  
+
+   * testsuite/libgomp.oacc-c-c++-common/deep-copy-10.c (main): Fix
+   async-safety issue. Increase number of iterations.
+
 2018-10-04  Cesar Philippidis  
Julian Brown  
 
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-10.c 
b/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-10.c
index 573a8214bf0..dadb6d37942 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-10.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-10.c
@@ -1,6 +1,8 @@
 #include 
 
-/* Test asyncronous attach and detach operation.  */
+#define ITERATIONS 1023
+
+/* Test asynchronous attach and detach operation.  */
 
 typedef struct {
   int *a;
@@ -25,13 +27,13 @@ main (int argc, char* argv[])
 
 #pragma acc enter data copyin(m)
 
-  for (int i = 0; i < 99; i++)
+  for (int i = 0; i < ITERATIONS; i++)
 {
   int j;
-#pragma acc parallel loop copy(m.a[0:N]) async(i % 2)
+#pragma acc parallel loop copy(m.a[0:N]) async(0)
   for (j = 0; j < N; j++)
m.a[j]++;
-#pragma acc parallel loop copy(m.b[0:N]) async((i + 1) % 2)
+#pragma acc parallel loop copy(m.b[0:N]) async(1)
   for (j = 0; j < N; j++)
m.b[j]++;
 }
@@ -40,9 +42,9 @@ main (int argc, char* argv[])
 
   for (i = 0; i < N; i++)
 {
-  if (m.a[i] != 99)
+  if (m.a[i] != ITERATIONS)
abort ();
-  if (m.b[i] != 99)
+  if (m.b[i] != ITERATIONS)
abort ();
 }


[gcc/devel/omp/gcc-14] Fix vector handling for firstprivate of <= pointer size

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:9d43e819d88f97c7ade7f8c95c35ea3464ea7771

commit 9d43e819d88f97c7ade7f8c95c35ea3464ea7771
Author: Tobias Burnus 
Date:   Fri Mar 6 16:24:52 2020 +0100

Fix vector handling for firstprivate of <= pointer size

Test case is the existing libgomp.oacc-c++/firstprivate-mappings-1.C.

* omp-low.c (convert_from_firstprivate_int):
Use VIEW_CONVERT also for vectors.

Diff:
---
 gcc/ChangeLog.omp | 5 +
 gcc/omp-low.cc| 3 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 68653888065..331a88af92d 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,8 @@
+2020-02-06  Tobias Burnus  
+
+   * omp-low.c (convert_from_firstprivate_int):
+   Use VIEW_CONVERT also for vectors.
+
 2023-04-17  Kwok Cheung Yeung  
 
* gimplify.cc (omp_group_base): Handle GOMP_MAP_DECLARE_ALLOCATE
diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index 0b35f2469a6..2db80e2498b 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -12851,7 +12851,8 @@ convert_from_firstprivate_int (tree var, tree 
orig_type, bool is_ref,
 {
   tree_code code = NOP_EXPR;
 
-  if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == COMPLEX_TYPE)
+  if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == COMPLEX_TYPE
+ || VECTOR_TYPE_P (type))
code = VIEW_CONVERT_EXPR;
 
   if (code == VIEW_CONVERT_EXPR


[gcc/devel/omp/gcc-14] Add XFAIL for libgomp.oacc-c-c++-common/data-firstprivate-1.c

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:6f759e76f00d70bf1d44a25767c73ec2de855452

commit 6f759e76f00d70bf1d44a25767c73ec2de855452
Author: Kwok Cheung Yeung 
Date:   Tue Mar 24 09:36:42 2020 -0700

Add XFAIL for libgomp.oacc-c-c++-common/data-firstprivate-1.c

The firstprivate_int optimization changes the semantics of firstprivate
in this test, so XFAIL it until the correct semantics for firstprivate
have been decided (PR92036).

2020-03-24  Kwok Cheung Yeung  

libgomp/
* testsuite/libgomp.oacc-c-c++-common/data-firstprivate-1.c: XFAIL
execution test.

Diff:
---
 libgomp/ChangeLog.omp | 5 +
 libgomp/testsuite/libgomp.oacc-c-c++-common/data-firstprivate-1.c | 6 ++
 2 files changed, 11 insertions(+)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 9389a0eefe3..cfc780519bb 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,8 @@
+2020-03-24  Kwok Cheung Yeung  
+
+   * testsuite/libgomp.oacc-c-c++-common/data-firstprivate-1.c: XFAIL
+   execution test.
+
 2019-09-17  Julian Brown  
Kwok Cheung Yeung  
 
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/data-firstprivate-1.c 
b/libgomp/testsuite/libgomp.oacc-c-c++-common/data-firstprivate-1.c
index 8900a4e070d..4b88c53fac7 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/data-firstprivate-1.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/data-firstprivate-1.c
@@ -1,6 +1,12 @@
 /* Test behavior of 'firstprivate' lexically vs. dynamically nested inside a
'data' region.  */
 
+/* The firstprivate_int optimization changes the semantics of firstprivate
+   in dynamically_nested_compute_2 to copy-by-value when not using shared
+   memory, leading to the behaviour suggested in PR92036 for this case.  */
+
+/* { dg-xfail-run-if "firstprivate_int" { *-*-* } { "-DACC_MEM_SHARED=0" } } */
+
 #include 


[gcc/devel/omp/gcc-14] OpenACC: fix privatization of by-reference arrays

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:8d7562192cc814c6d0d48b424d7751762871a37b

commit 8d7562192cc814c6d0d48b424d7751762871a37b
Author: Tobias Burnus 
Date:   Wed Jun 3 15:35:12 2020 +0200

OpenACC: fix privatization of by-reference arrays

Replacing of a by-reference variable in a private clause by a local variable
makes sense; however, for arrays, the size is not directly known by the 
type.
This causes an ICE via create_tmp_var which indirectly invokes
force_constant_size in this case - but the latter only handled Ada.

gcc/ChangeLog:

* gimplify.cc (localize_reductions): Do not create local
variable for privatized arrays.

Diff:
---
 gcc/ChangeLog.omp | 5 +
 gcc/gimplify.cc   | 3 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 331a88af92d..d4abd1c117c 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,8 @@
+2020-06-03  Tobias Burnus  
+
+   * gimplify.cc (localize_reductions): Do not create local
+   variable for privatized arrays.
+
 2020-02-06  Tobias Burnus  
 
* omp-low.c (convert_from_firstprivate_int):
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index 1741f740f51..3a69d7b99b0 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -15195,8 +15195,9 @@ localize_reductions (tree clauses, tree body)
 
if (!lang_hooks.decls.omp_privatize_by_reference (var))
  continue;
-
type = TREE_TYPE (TREE_TYPE (var));
+   if (TREE_CODE (type) == ARRAY_TYPE)
+ continue;
new_var = create_tmp_var (type, IDENTIFIER_POINTER (DECL_NAME (var)));
 
pr.ref_var = var;


[gcc/devel/omp/gcc-14] Fix goacc/noncontig_array-1.c testcase

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:e11726d3467543de45448097dde27ba34bf04bfe

commit e11726d3467543de45448097dde27ba34bf04bfe
Author: Kwok Cheung Yeung 
Date:   Tue Jun 2 06:36:45 2020 -0700

Fix goacc/noncontig_array-1.c testcase

2020-06-02  Kwok Cheung Yeung  

gcc/testsuite/
* c-c++-common/goacc/noncontig_array-1.c: Dump Gimple pass.

Diff:
---
 gcc/testsuite/ChangeLog.omp  | 4 
 gcc/testsuite/c-c++-common/goacc/noncontig_array-1.c | 1 +
 2 files changed, 5 insertions(+)

diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index a3ea10f60e3..09f26c50472 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,7 @@
+2020-06-02  Kwok Cheung Yeung  
+
+   * c-c++-common/goacc/noncontig_array-1.c: Dump Gimple pass.
+
 2018-10-04  Cesar Philippidis  
 Julian Brown  
 
diff --git a/gcc/testsuite/c-c++-common/goacc/noncontig_array-1.c 
b/gcc/testsuite/c-c++-common/goacc/noncontig_array-1.c
index ea738f5b65b..fe7480ab2e7 100644
--- a/gcc/testsuite/c-c++-common/goacc/noncontig_array-1.c
+++ b/gcc/testsuite/c-c++-common/goacc/noncontig_array-1.c
@@ -1,4 +1,5 @@
 /* { dg-do compile } */
+/* { dg-additional-options "-fdump-tree-gimple" } */
 
 void foo (void)
 {


[gcc/devel/omp/gcc-14] libgomp.oacc-fortran/firstprivate-int.f90 fix for nonexisting kind-16 int

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:61d66e2e494655a34cca7289ae584d2644f1a65f

commit 61d66e2e494655a34cca7289ae584d2644f1a65f
Author: Tobias Burnus 
Date:   Thu Jul 16 14:37:23 2020 +0200

libgomp.oacc-fortran/firstprivate-int.f90 fix for nonexisting kind-16 int

libgomp/
* testsuite/libgomp.oacc-fortran/firstprivate-int.f90: Use
highest available integer kind instead of assuming that kind=16 
exists.

Diff:
---
 libgomp/ChangeLog.omp   |  5 +
 libgomp/testsuite/libgomp.oacc-fortran/firstprivate-int.f90 | 12 
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index cfc780519bb..0afab7fd332 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,8 @@
+2020-07-16  Tobias Burnus  
+
+   * testsuite/libgomp.oacc-fortran/firstprivate-int.f90: Use
+   highest available integer kind instead of assuming that kind=16 exists.
+
 2020-03-24  Kwok Cheung Yeung  
 
* testsuite/libgomp.oacc-c-c++-common/data-firstprivate-1.c: XFAIL
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/firstprivate-int.f90 
b/libgomp/testsuite/libgomp.oacc-fortran/firstprivate-int.f90
index 3b148ce7517..abc175f37e3 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/firstprivate-int.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/firstprivate-int.f90
@@ -3,19 +3,22 @@
 ! { dg-do run }
 
 program test
+  use iso_fortran_env, only: integer_kinds
   implicit none
 
   integer (kind=1)  :: i1i, i1o
   integer (kind=2)  :: i2i, i2o
   integer (kind=4)  :: i4i, i4o
   integer (kind=8)  :: i8i, i8o
-  integer (kind=16) :: i16i, i16o
+! Use highest-precision integer, which might be less than '16'
+! assume integer_kinds == logical_kinds
+  integer (kind=maxval(integer_kinds)) :: i16i, i16o
 
   logical (kind=1)  :: l1i, l1o
   logical (kind=2)  :: l2i, l2o
   logical (kind=4)  :: l4i, l4o
   logical (kind=8)  :: l8i, l8o
-  logical (kind=16) :: l16i, l16o
+  logical (kind=maxval(integer_kinds)) :: l16i, l16o
 
   real (kind=4)  :: r4i, r4o
   real (kind=8)  :: r8i, r8o
@@ -108,19 +111,20 @@ subroutine subtest(i1i, i2i, i4i, i8i, i16i, i1o, i2o, 
i4o, i8o, i16o, &
l1i, l2i, l4i, l8i, l16i, l1o, l2o, l4o, l8o, l16o, &
r4i, r8i, r4o, r8o, c4i, c8i, c4o, c8o, &
ch1i, ch4i, ch1o, ch4o)
+  use iso_fortran_env, only: integer_kinds
   implicit none
 
   integer (kind=1)  :: i1i, i1o
   integer (kind=2)  :: i2i, i2o
   integer (kind=4)  :: i4i, i4o
   integer (kind=8)  :: i8i, i8o
-  integer (kind=16) :: i16i, i16o
+  integer (kind=maxval(integer_kinds)) :: i16i, i16o
 
   logical (kind=1)  :: l1i, l1o
   logical (kind=2)  :: l2i, l2o
   logical (kind=4)  :: l4i, l4o
   logical (kind=8)  :: l8i, l8o
-  logical (kind=16) :: l16i, l16o
+  logical (kind=maxval(integer_kinds)) :: l16i, l16o
 
   real (kind=4)  :: r4i, r4o
   real (kind=8)  :: r8i, r8o


[gcc/devel/omp/gcc-14] Update dg-* in gfortran.dg/gomp/pr67500.f90

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:9e8395708c0027ad1de871bae870c4b0185a74fd

commit 9e8395708c0027ad1de871bae870c4b0185a74fd
Author: Tobias Burnus 
Date:   Fri Aug 21 13:28:06 2020 +0200

Update dg-* in gfortran.dg/gomp/pr67500.f90

Contrary to GCC 11, OG10 uses an error instead of a warning,
cf. commit 271c7fef548a86676d304b1eb2be5c0d47280bd6.

gcc/testsuite/
* gfortran.dg/gomp/pr67500.f90: Change dg-warning to
dg-error.

Diff:
---
 gcc/testsuite/ChangeLog.omp| 5 +
 gcc/testsuite/gfortran.dg/gomp/pr67500.f90 | 8 
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 09f26c50472..1ac91cf1b01 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,8 @@
+2020-08-21  Tobias Burnus  
+
+   * gfortran.dg/gomp/pr67500.f90: Change dg-warning to
+   dg-error.
+
 2020-06-02  Kwok Cheung Yeung  
 
* c-c++-common/goacc/noncontig_array-1.c: Dump Gimple pass.
diff --git a/gcc/testsuite/gfortran.dg/gomp/pr67500.f90 
b/gcc/testsuite/gfortran.dg/gomp/pr67500.f90
index 1cecdc48578..11ed69f10a7 100644
--- a/gcc/testsuite/gfortran.dg/gomp/pr67500.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/pr67500.f90
@@ -10,11 +10,11 @@ subroutine f2
 end
 
 subroutine f3 (i)
-  !$omp declare simd simdlen(-2)   ! { dg-warning "INTEGER expression of 
SIMDLEN clause at .1. must be positive" }
+  !$omp declare simd simdlen(-2)   ! { dg-error "INTEGER expression of SIMDLEN 
clause at .1. must be positive" }
 end subroutine
 
 subroutine f4
-  !$omp declare simd simdlen(0)   ! { dg-warning "INTEGER expression 
of SIMDLEN clause at .1. must be positive" }
+  !$omp declare simd simdlen(0)   ! { dg-error "INTEGER expression of 
SIMDLEN clause at .1. must be positive" }
 end
 
 subroutine foo(p, d, n)
@@ -31,11 +31,11 @@ subroutine foo(p, d, n)
   do i = 1, 16
   end do
 
-  !$omp simd safelen(-2)! { dg-warning "INTEGER expression of SAFELEN 
clause at .1. must be positive" }
+  !$omp simd safelen(-2)! { dg-error "INTEGER expression of SAFELEN clause 
at .1. must be positive" }
   do i = 1, 16
   end do
 
-  !$omp simd safelen(0) ! { dg-warning "INTEGER expression of SAFELEN 
clause at .1. must be positive" }
+  !$omp simd safelen(0) ! { dg-error "INTEGER expression of SAFELEN clause 
at .1. must be positive" }
   do i = 1, 16
   end do


[gcc/devel/omp/gcc-14] [og10] openacc: Adjust loop lowering for AMD GCN

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:98b00803288d24913de1314f86692ef4740dbd82

commit 98b00803288d24913de1314f86692ef4740dbd82
Author: Julian Brown 
Date:   Fri Nov 6 15:17:29 2020 -0800

[og10] openacc: Adjust loop lowering for AMD GCN

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

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

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

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

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

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

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

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

2021-01-13  Julian Brown  

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

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

Diff:
---
 gcc/ChangeLog.omp  |   7 +
 gcc/omp-offload.cc | 159 -
 libgomp/ChangeLog.omp  |  10 ++
 .../libgomp.oacc-c-c++-common/loop-gwv-1.c |  15 +-
 .../libgomp.oacc-c-c++-common/loop-red-gwv-1.c |  17 ++-
 .../libgomp.oacc-c-c++-common/loop-red-wv-1.c  |  16 +++
 .../libgomp.oacc-c-c++-common/loop-wv-1.c  |  16 +++
 .../libgomp.oacc-c-c++-common/routine-gwv-1.c  |  17 ++-
 .../libgomp.oacc-c-c++-common/routine-wv-1.c   |  16 +++
 9 files changed, 230 insertions(+), 43 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index d4abd1c117c..06ee9d83b27 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,10 @@
+2021-01-13  Julian Brown  
+
+   * omp-offload.cc (oacc_thread_numbers): Add VF_BY_VECTORIZER parameter.
+   Add overloaded wrapper for previous arguments & behaviour.
+   (oacc_xform_loop): Lower vector loops to iterate a multiple of
+   omp_max_vf times over contiguous steps on non-SIMT targets.
+
 2020-06-03  Tobias Burnus  
 
* gimplify.cc (localize_reductions): Do not create local
diff --git a/gcc/omp-offload.cc b/gcc/omp-offload.cc
index b2ba9042758..6c652387a07 100644
--- a/gcc/omp-offload.cc
+++ b/gcc/omp-offload.cc
@@ -521,11 +521,13 @@ oacc_dim_call (bool pos, in

[gcc/devel/omp/gcc-14] [og10] vect: Add target hook to prefer gather/scatter instructions

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:4abc54b6d6c3129cf4233e49231b1255b236c2be

commit 4abc54b6d6c3129cf4233e49231b1255b236c2be
Author: Julian Brown 
Date:   Wed Nov 25 09:08:01 2020 -0800

[og10] vect: Add target hook to prefer gather/scatter instructions

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

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

2021-01-13  Julian Brown  

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

Diff:
---
 gcc/ChangeLog.omp  | 11 +++
 gcc/config/gcn/gcn.cc  |  2 ++
 gcc/doc/tm.texi|  5 +
 gcc/doc/tm.texi.in |  2 ++
 gcc/target.def |  8 
 gcc/tree-vect-stmts.cc |  9 +++--
 6 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 06ee9d83b27..e8ff6483444 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,14 @@
+2021-01-13  Julian Brown  
+
+   * doc/tm.texi.in (TARGET_VECTORIZE_PREFER_GATHER_SCATTER): Add
+   documentation hook.
+   * doc/tm.texi: Regenerate.
+   * target.def (prefer_gather_scatter): Add target hook under vectorizer.
+   * tree-vect-stmts.cc (get_group_load_store_type): Optionally prefer
+   gather/scatter instructions to scalar/elementwise fallback.
+   * config/gcn/gcn.cc (TARGET_VECTORIZE_PREFER_GATHER_SCATTER): Define
+   hook.
+
 2021-01-13  Julian Brown  
 
* omp-offload.cc (oacc_thread_numbers): Add VF_BY_VECTORIZER parameter.
diff --git a/gcc/config/gcn/gcn.cc b/gcc/config/gcn/gcn.cc
index d6531f55190..a247eecd8e8 100644
--- a/gcc/config/gcn/gcn.cc
+++ b/gcc/config/gcn/gcn.cc
@@ -8059,6 +8059,8 @@ gcn_dwarf_register_span (rtx rtl)
   gcn_vector_alignment_reachable
 #undef  TARGET_VECTOR_MODE_SUPPORTED_P
 #define TARGET_VECTOR_MODE_SUPPORTED_P gcn_vector_mode_supported_p
+#undef  TARGET_VECTORIZE_PREFER_GATHER_SCATTER
+#define TARGET_VECTORIZE_PREFER_GATHER_SCATTER true
 
 struct gcc_target targetm = TARGET_INITIALIZER;
 
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index c8b8b126b24..e64c7541f60 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -6482,6 +6482,11 @@ The default is @code{NULL_TREE} which means to not 
vectorize scatter
 stores.
 @end deftypefn
 
+@deftypevr {Target Hook} bool TARGET_VECTORIZE_PREFER_GATHER_SCATTER
+This hook is set to TRUE if gather loads or scatter stores are cheaper on
+this target than a sequence of elementwise loads or stores.
+@end deftypevr
+
 @deftypefn {Target Hook} int TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN 
(struct cgraph_node *@var{}, struct cgraph_simd_clone *@var{}, @var{tree}, 
@var{int}, @var{bool})
 This hook should set @var{vecsize_mangle}, @var{vecsize_int}, 
@var{vecsize_float}
 fields in @var{simd_clone} structure pointed by @var{clone_info} argument and 
also
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index 658e1e63371..645950b12d7 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -4309,6 +4309,8 @@ address;  but often a machine-dependent strategy can 
generate better code.
 
 @hook TARGET_VECTORIZE_BUILTIN_SCATTER
 
+@hook TARGET_VECTORIZE_PREFER_GATHER_SCATTER
+
 @hook TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN
 
 @hook TARGET_SIMD_CLONE_ADJUST
diff --git a/gcc/target.def b/gcc/target.def
index fdad7bbc93e..e4b26a7df3e 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -2044,6 +2044,14 @@ all zeros.  GCC can then try to branch around the 
instruction instead.",
  (unsigned ifn),
  default_empty_mask_is_expensive)
 
+/* Prefer gather/scatter loads/stores to e.g. elementwise accesses if\n\
+we cannot use a contiguous access.  */
+DEFHOOKPOD
+(prefer_gather_scatter,
+ "This hook is set to TRUE if gather loads or scatter stores are cheaper on\n\
+this target than a sequence of elementwise loads or stores.",
+ bool, false)
+
 /* Target builtin that implements vector gather operation.  */
 DEFHO

[gcc/devel/omp/gcc-14] DWARF: late code range fixup

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:ebd204090cd4c7938668b4e8ec69b63bf43bf6ad

commit ebd204090cd4c7938668b4e8ec69b63bf43bf6ad
Author: Andrew Stubbs 
Date:   Sun Dec 6 19:23:55 2020 +

DWARF: late code range fixup

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

gcc/

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

Diff:
---
 gcc/ChangeLog.omp | 23 +
 gcc/dwarf2out.cc  | 61 +--
 2 files changed, 82 insertions(+), 2 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index e8ff6483444..dd70a08ff7d 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,26 @@
+2021-03-04  Andrew Stubbs 
+
+   * dwarf2out.cc (notional_parents_list): New file variable.
+   (gen_subprogram_die): Record offload kernel functions in
+   notional_parents_list.
+   (fixup_notional_parents): New function.
+   (dwarf2out_finish): Call fixup_notional_parents.
+   (dwarf2out_c_finalize): Reset notional_parents_list.
+
+2021-02-26  Andrew Stubbs  
+
+   * dwarf2out.cc (gen_subprogram_die): Replace existing low/high PC
+   attributes, rather than ICE.
+
+2021-01-16  Andrew Stubbs  
+
+   * dwarf2out.cc (gen_subprogram_die): Check offload attributes only.
+
+2021-01-15  Andrew Stubbs  
+
+   * dwarf2out.cc (gen_subprogram_die): Add high/low_pc attributes for
+   parents of offload kernels.
+
 2021-01-13  Julian Brown  
 
* doc/tm.texi.in (TARGET_VECTORIZE_PREFER_GATHER_SCATTER): Add
diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index 1b0e8b5a5b2..9f747e8fcee 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -3487,6 +3487,12 @@ static GTY(()) limbo_die_node *limbo_die_list;
DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set.  */
 static GTY(()) limbo_die_node *deferred_asm_name;
 
+/* A list of DIEs for which we may have to add a notional code range to the
+   parent DIE.  This happens for parents of nested offload kernels, and is
+   necessary because the parents don't exist on the offload target, yet GDB
+   expects parents of real functions to also appear to exist.  */
+static GTY(()) limbo_die_node *notional_parents_list;
+
 struct dwarf_file_hasher : ggc_ptr_hash
 {
   typedef const char *compare_type;
@@ -23883,8 +23889,24 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
  if (fde->dw_fde_begin)
{
  /* We have already generated the labels.  */
- add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
- fde->dw_fde_end, false);
+ add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
+ fde->dw_fde_end, false);
+
+/* Offload kernel functions are nested within a parent function
+   that doesn't actually exist within the offload object.  GDB
+   will ignore the function and everything nested within unless
+   we give the parent a code range.  We can't do it here because
+   that breaks the case where the parent actually does exist (as
+   it does on the host-side), so we defer the fixup for later.  */
+if (lookup_attribute ("omp target entrypoint",
+  DECL_ATTRIBUTES (decl)))
+  {
+limbo_die_node *node = ggc_cleared_alloc ();
+node->die = subr_die;
+node->created_for = decl;
+node->next = notional_parents_list;
+notional_parents_list = node;
+  }
}
  else
{
@@ -32219,6 +32241,37 @@ flush_limbo_die_list (void)
 }
 }
 
+/* Add a code range to the notional parent function (which does not actually
+   exist) so that GDB does not ignore all the child functions.  The actual
+   values do not matter, but need to be valid labels, so we simply copy those
+   from the child function.
+
+   Typically this occurs when we have an offload kernel, where the parent
+   function only exists in the host-side portion of the code.  */
+
+static void
+fixup_notional_parents (void)
+{
+  limbo_die_node *node;
+
+  while ((node = notional_parents_list))
+{
+  dw_die_ref die = node->die;
+  dw_die_ref parent = die->die_parent;
+  notional_parents_list = node->next;
+
+  if (parent
+ && parent->die_tag == DW_TAG_subprogram
+ && !ge

[gcc/devel/omp/gcc-14] nvptx: remove erroneous stack deletion

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:9923231220713968375f689a9c81f77b93296c98

commit 9923231220713968375f689a9c81f77b93296c98
Author: Andrew Stubbs 
Date:   Tue Feb 23 21:35:08 2021 +

nvptx: remove erroneous stack deletion

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

libgomp/

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

Diff:
---
 libgomp/ChangeLog.omp | 5 +
 libgomp/plugin/plugin-nvptx.c | 2 --
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index c6c0a47e580..2ca82622336 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,8 @@
+2021-02-23  Andrew Stubbs  
+
+   * plugin/plugin-nvptx.c (GOMP_OFFLOAD_alloc): Remove early call to
+   nvptx_stacks_free.
+
 2021-01-13  Julian Brown  
 
* testsuite/libgomp.oacc-c-c++-common/loop-gwv-1.c: Adjust for loop
diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c
index 5aad3448a8d..36527bcbed9 100644
--- a/libgomp/plugin/plugin-nvptx.c
+++ b/libgomp/plugin/plugin-nvptx.c
@@ -1581,8 +1581,6 @@ GOMP_OFFLOAD_alloc (int ord, size_t size)
   ptx_dev->free_blocks = NULL;
   pthread_mutex_unlock (&ptx_dev->free_blocks_lock);
 
-  nvptx_stacks_free (ptx_dev, false);
-
   while (blocks)
 {
   tmp = blocks->next;


[gcc/devel/omp/gcc-14] Update expected messages in data-clause-1 tests

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:87ea4de1c4a360d5d62357491a41811213f4528c

commit 87ea4de1c4a360d5d62357491a41811213f4528c
Author: Kwok Cheung Yeung 
Date:   Thu Apr 29 15:06:38 2021 -0700

Update expected messages in data-clause-1 tests

The patch 'Merge non-contiguous array support patches' handles one of the
non-contiguous cases such that it is no longer an error.

2021-04-29  Kwok Cheung Yeung  

gcc/testsuite/
* c-c++-common/goacc/data-clause-1.c (foo): Remove expected message.
* g++.dg/goacc/data-clause-1.C (foo): Remove expected message.

Diff:
---
 gcc/testsuite/ChangeLog.omp  | 5 +
 gcc/testsuite/c-c++-common/goacc/data-clause-1.c | 2 +-
 gcc/testsuite/g++.dg/goacc/data-clause-1.C   | 2 +-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 6ff9a06aab7..2bdd10f928e 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,8 @@
+2021-04-29  Kwok Cheung Yeung  
+
+   * c-c++-common/goacc/data-clause-1.c (foo): Remove expected message.
+   * g++.dg/goacc/data-clause-1.C (foo): Remove expected message.
+
 2021-02-01  Chung-Lin Tang  
 
* c-c++-common/gomp/clauses-2.c: Adjust testcase.
diff --git a/gcc/testsuite/c-c++-common/goacc/data-clause-1.c 
b/gcc/testsuite/c-c++-common/goacc/data-clause-1.c
index 9952ac4fb4f..b78f691dc9f 100644
--- a/gcc/testsuite/c-c++-common/goacc/data-clause-1.c
+++ b/gcc/testsuite/c-c++-common/goacc/data-clause-1.c
@@ -98,7 +98,7 @@ foo (int g[3][10], int h[4][8], int i[2][10], int j[][9],
 bar (&j2[0][0]);
   #pragma acc parallel copy(q[1:2])
 ;
-  #pragma acc parallel copy(q[3:5][:10]) /* { dg-error "array section is not 
contiguous" } */
+  #pragma acc parallel copy(q[3:5][:10])
 ;
   #pragma acc parallel copy(r[3:][2:1][1:2])
 ;
diff --git a/gcc/testsuite/g++.dg/goacc/data-clause-1.C 
b/gcc/testsuite/g++.dg/goacc/data-clause-1.C
index 07ef6aed788..daea3f4706b 100644
--- a/gcc/testsuite/g++.dg/goacc/data-clause-1.C
+++ b/gcc/testsuite/g++.dg/goacc/data-clause-1.C
@@ -99,7 +99,7 @@ foo (int g[3][10], int h[4][8], int i[2][10], int j[][9],
 bar (&j2[0][0]);
   #pragma acc parallel copy(q[1:2])
 ;
-  #pragma acc parallel copy(q[3:5][:10]) /* { dg-error "array section is not 
contiguous" } */
+  #pragma acc parallel copy(q[3:5][:10])
 ;
   #pragma acc parallel copy(r[3:][2:1][1:2])
 ;


[gcc/devel/omp/gcc-14] DWARF address space for variables

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:b14f86ba525e24c6a5af8867ff152e53258b58e1

commit b14f86ba525e24c6a5af8867ff152e53258b58e1
Author: Andrew Stubbs 
Date:   Fri Jan 15 11:26:46 2021 +

DWARF address space for variables

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

gcc/ChangeLog:

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

Diff:
---
 gcc/ChangeLog.omp | 7 ++-
 gcc/dwarf2out.cc  | 9 +
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index dd70a08ff7d..e35ced18751 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,8 @@
+2021-01-15  Andrew Stubbs  
+
+   * dwarf2out.cc (add_location_or_const_value_attribute): Set
+   DW_AT_address_class, if appropriate.
+
 2021-03-04  Andrew Stubbs 
 
* dwarf2out.cc (notional_parents_list): New file variable.
@@ -16,7 +21,7 @@
 
* dwarf2out.cc (gen_subprogram_die): Check offload attributes only.
 
-2021-01-15  Andrew Stubbs  
+2020-12-06  Andrew Stubbs  
 
* dwarf2out.cc (gen_subprogram_die): Add high/low_pc attributes for
parents of offload kernels.
diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index 9f747e8fcee..7ee945d066e 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -20998,6 +20998,15 @@ add_location_or_const_value_attribute (dw_die_ref die, 
tree decl, bool cache_p)
   if (list)
 {
   add_AT_location_description (die, DW_AT_location, list);
+
+  addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
+  if (!ADDR_SPACE_GENERIC_P (as))
+   {
+ int action = targetm.addr_space.debug (as);
+ /* Positive values indicate an address_class.  */
+ if (action >= 0)
+   add_AT_unsigned (die, DW_AT_address_class, action);
+   }
   return true;
 }
   /* None of that worked, so it must not really have a location;


[gcc/devel/omp/gcc-14] libgomp amdgcn: Fix issues with dynamic OpenMP thread scaling

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:2ca4602a941c1dfba2de376e3e523c7dd0491055

commit 2ca4602a941c1dfba2de376e3e523c7dd0491055
Author: Andrew Stubbs 
Date:   Tue Aug 3 13:45:35 2021 +0100

libgomp amdgcn: Fix issues with dynamic OpenMP thread scaling

libgomp/ChangeLog:

* config/gcn/bar.h (gomp_barrier_init): Limit thread count to the
actual physical number.
* config/gcn/team.c (gomp_team_start): Don't attempt to set up
threads that do not exist.

Diff:
---
 libgomp/ChangeLog.omp | 7 +++
 libgomp/config/gcn/bar.h  | 3 +++
 libgomp/config/gcn/team.c | 4 
 3 files changed, 14 insertions(+)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 2ca82622336..5bf3a8a6890 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,10 @@
+2021-08-03  Andrew Stubbs  
+
+   * config/gcn/bar.h (gomp_barrier_init): Limit thread count to the
+   actual physical number.
+   * config/gcn/team.c (gomp_team_start): Don't attempt to set up
+   threads that do not exist.
+
 2021-02-23  Andrew Stubbs  
 
* plugin/plugin-nvptx.c (GOMP_OFFLOAD_alloc): Remove early call to
diff --git a/libgomp/config/gcn/bar.h b/libgomp/config/gcn/bar.h
index a130c749d00..645791575e9 100644
--- a/libgomp/config/gcn/bar.h
+++ b/libgomp/config/gcn/bar.h
@@ -55,6 +55,9 @@ typedef unsigned int gomp_barrier_state_t;
 
 static inline void gomp_barrier_init (gomp_barrier_t *bar, unsigned count)
 {
+  unsigned actual_thread_count = __builtin_gcn_dim_size (1);
+  if (count > actual_thread_count)
+count = actual_thread_count;
   bar->total = count;
   bar->awaited = count;
   bar->awaited_final = count;
diff --git a/libgomp/config/gcn/team.c b/libgomp/config/gcn/team.c
index bd3df448b52..47bf2df55ac 100644
--- a/libgomp/config/gcn/team.c
+++ b/libgomp/config/gcn/team.c
@@ -206,6 +206,10 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned 
nthreads,
   if (nthreads == 1)
 return;
 
+  unsigned actual_thread_count = __builtin_gcn_dim_size (1);
+  if (nthreads > actual_thread_count)
+nthreads = actual_thread_count;
+
   /* Release existing idle threads.  */
   for (unsigned i = 1; i < nthreads; ++i)
 {


[gcc/devel/omp/gcc-14] OpenMP 5.0: Allow multiple clauses mapping same variable

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:6bb82ce8294046ec11d9f9a3bd84ad5cb0a7e01c

commit 6bb82ce8294046ec11d9f9a3bd84ad5cb0a7e01c
Author: Chung-Lin Tang 
Date:   Mon Feb 1 03:16:47 2021 -0800

OpenMP 5.0: Allow multiple clauses mapping same variable

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

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

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

2021-02-01  Chung-Lin Tang  

gcc/cp/ChangeLog:

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

gcc/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

Diff:
---
 gcc/ChangeLog.omp   | 15 +
 gcc/cp/ChangeLog.omp|  5 ++
 gcc/omp-low.cc  | 89 +++--
 gcc/testsuite/ChangeLog.omp |  4 ++
 gcc/testsuite/c-c++-common/gomp/clauses-2.c |  2 +-
 gcc/testsuite/c-c++-common/gomp/map-6.c |  4 +-
 6 files changed, 87 insertions(+), 32 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index e35ced18751..d000c3614a8 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,18 @@
+2021-02-01  Chung-Lin Tang  
+
+   * omp-low.cc (install_var_field): Add new 'tree key_expr = NULL_TREE'
+   default parameter. Set splay-tree lookup key to key_expr instead of
+   var if key_expr is non-NULL. Adjust call to install_parm_decl.
+   Update comments.
+   (scan_sharing_clauses): Use clause tree expression as splay-tree key
+   for map/to/from and OpenACC firstprivate cases when installing the
+   variable field into the send/receive record type.
+   (maybe_lookup_field_in_outer_ctx): Add code to search through
+   construct clauses instead of entirely based on splay-tree lookup.
+   (lower_oacc_reductions): Adjust to find map-clause of reduction
+   variable, then create receiver-ref.
+   (lower_omp_target): Adjust to lookup var field using clause expression.
+
 2021-01-15  Andrew Stubbs  
 
* dwarf2out.cc (add_location_or_const_value_attribute): Set
diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp
index a87d118e4bb..bfdc3be2c4e 100644
--- a/gcc/cp/ChangeLog.omp
+++ b/gcc/cp/ChangeLog.omp
@@ -1,3 +1,8 @@
+2021-02-01  Chung-Lin Tang  
+
+   * semantics.cc (finish_omp_clauses):  Adjust to allow duplicate
+   mapped variables for OpenMP.
+
 2022-02-03  Kwok Cheung Yeung  
 
* parser.ccc (cp_parser_omp_clause_map): Update call to
diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index 2db80e2498b..fe6e20f444a 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -776,24 +776,28 @@ build_sender_ref (tree var, omp_context *ctx)
   return build_sender_ref ((splay_tree_key) var, ctx);
 }
 
-/* Add a new field for VAR inside the structure CTX->SENDER_DECL.  If
-   BASE_POINTERS_RESTRICT, declare the field with restrict.  */
-
 static void
-install_var_field (tree var, bool by_ref, int mask, omp_context *ctx)
+install_var_field (tree var, bool by_ref, int mask, omp_context *ctx,
+  tree key_expr = NULL_TREE)
 {
   tree field, type, sfield = NULL_TREE;
   splay_tree_key key = (splay_tree_key) var;
 
-  if ((mask & 16) != 0)
-{
-  key = (splay_tree_key) &DECL_NAME (var);
-  gcc_checking_assert (key != (splay_tree_key) var);
-}
-  if ((mask & 8) != 0)
+  if (key_expr)
+/* Allow user to explicitly set the expression used as the key.  */
+key = (splay_tree_key) key_expr;
+  else
 {
-  key = (splay_tree_key) &DECL_UID (var);
-  gcc_checking_assert (key != (splay_tree_key) var);
+  if ((mask & 16) != 0)
+   {
+ key = (splay_tree_key) &DECL_NAME (var);
+ gcc_checking_assert (key != (splay_tree_key) var);
+   }
+  if ((mask & 8) != 0)
+   {
+ key = (splay_tree_key)

[gcc/devel/omp/gcc-14] openmp: Scale type precision of collapsed iterator variable

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:22da577a9f974b499e4364719086e4835dfbd529

commit 22da577a9f974b499e4364719086e4835dfbd529
Author: Kwok Cheung Yeung 
Date:   Mon Mar 1 14:15:30 2021 -0800

openmp: Scale type precision of collapsed iterator variable

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

2021-03-01  Kwok Cheung Yeung  

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

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

Diff:
---
 gcc/ChangeLog.omp  |  8 +
 gcc/omp-expand.cc  |  5 ++-
 gcc/omp-general.cc | 39 +++---
 libgomp/ChangeLog.omp  |  5 +++
 .../testsuite/libgomp.c-c++-common/collapse-4.c| 23 +
 libgomp/testsuite/libgomp.fortran/collapse5.f90| 23 +
 6 files changed, 90 insertions(+), 13 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index d000c3614a8..8199cacbdd7 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,11 @@
+2021-03-01  Kwok Cheung Yeung  
+
+   * omp-expand.cc (expand_oacc_for): Convert .tile variable to
+   diff_type before multiplying.
+   * omp-general.cc (omp_extract_for_data): Use accumulated precision
+   of all collapsed for-loops as precision of iteration variable, up
+   to the precision of a long long.
+
 2021-02-01  Chung-Lin Tang  
 
* omp-low.cc (install_var_field): Add new 'tree key_expr = NULL_TREE'
diff --git a/gcc/omp-expand.cc b/gcc/omp-expand.cc
index a8782a09df8..98b9b44e9d0 100644
--- a/gcc/omp-expand.cc
+++ b/gcc/omp-expand.cc
@@ -7778,7 +7778,10 @@ expand_oacc_for (struct omp_region *region, struct 
omp_for_data *fd)
   tile_size = create_tmp_var (diff_type, ".tile_size");
   expr = build_int_cst (diff_type, 1);
   for (int ix = 0; ix < fd->collapse; ix++)
-   expr = fold_build2 (MULT_EXPR, diff_type, counts[ix].tile, expr);
+   {
+ tree tile = fold_convert (diff_type, counts[ix].tile);
+ expr = fold_build2 (MULT_EXPR, diff_type, tile, expr);
+   }
   expr = force_gimple_operand_gsi (&gsi, expr, true,
   NULL_TREE, true, GSI_SAME_STMT);
   ass = gimple_build_assign (tile_size, expr);
diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc
index 2c095200d5b..9a125a28afa 100644
--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -395,6 +395,7 @@ omp_extract_for_data (gomp_for *for_stmt, struct 
omp_for_data *fd,
  fd->non_rect = true;
}
 }
+  int accum_iter_precision = 0;
   for (i = 0; i < cnt; i++)
 {
   if (i == 0
@@ -478,19 +479,33 @@ omp_extract_for_data (gomp_for *for_stmt, struct 
omp_for_data *fd,
{
  if (fd->collapse == 1 && !fd->tiling)
iter_type = TREE_TYPE (loop->v);
- else if (i == 0
-  || TYPE_PRECISION (iter_type)
- < TYPE_PRECISION (TREE_TYPE (loop->v)))
+ else
{
- if (TREE_CODE (iter_type) == BITINT_TYPE
- || TREE_CODE (TREE_TYPE (loop->v)) == BITINT_TYPE)
-   iter_type
- = build_bitint_type (TYPE_PRECISION (TREE_TYPE (loop->v)),
-  1);
- else
-   iter_type
- = build_nonstandard_integer_type
-   (TYPE_PRECISION (TREE_TYPE (loop->v)), 1);
+ int loop_precision = TYPE_PRECISION (TREE_TYPE (loop->v));
+ int iter_type_precision = 0;
+ const int max_accum_precision
+   = TYPE_PRECISION (long_long_unsigned_type_node);
+
+ accum_iter_precision += loop_precision;
+
+ if (i == 0
+ || (loop_precision >= max_accum_precision
+ && loop_precision >= TYPE_PRECISION (iter_type)))
+   iter_type_precision = loop_precision;
+ else if (TYPE_PRECISION (iter_type) < max_accum_precision)
+   iter_type_precision
+ = MIN (1 << ceil_log2 (accum_iter_precision),
+max_accum_precision);
+
+ if (iter_type_precision)
+   {
+ if (TREE_CODE (iter_type) == BITINT_TYPE
+ || TREE_CODE (TREE_TYPE (loop->v)) == BITINT_TYPE)
+   iter_type = build_bitint_type (iter_type_precision, 1);
+ else
+

[gcc/devel/omp/gcc-14] openacc: fix ICE for non-decl expression in non-contiguous array base-pointer

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:151fc161d0ed640048444ca18f9325e3d2e03e99

commit 151fc161d0ed640048444ca18f9325e3d2e03e99
Author: Chung-Lin Tang 
Date:   Thu Aug 19 16:17:02 2021 +0800

openacc: fix ICE for non-decl expression in non-contiguous array 
base-pointer

Currently, we do not support cases like struct-members as the base-pointer
for an OpenACC non-contiguous array. Mark such cases as unsupported in the
C/C++ front-ends, instead of ICEing on them.

gcc/c/ChangeLog:

* c-typeck.cc (handle_omp_array_sections_1): Robustify 
non-contiguous
array check and reject non-DECL base-pointer cases as unsupported.

gcc/cp/ChangeLog:

* semantics.cc (handle_omp_array_sections_1): Robustify 
non-contiguous
array check and reject non-DECL base-pointer cases as unsupported.

Diff:
---
 gcc/c/ChangeLog.omp  |  5 +
 gcc/c/c-typeck.cc| 19 ---
 gcc/cp/ChangeLog.omp |  5 +
 gcc/cp/semantics.cc  | 23 +--
 4 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/gcc/c/ChangeLog.omp b/gcc/c/ChangeLog.omp
index a95b2adc8f8..4b8331c3744 100644
--- a/gcc/c/ChangeLog.omp
+++ b/gcc/c/ChangeLog.omp
@@ -1,3 +1,8 @@
+2021-08-19  Chung-Lin Tang  
+
+   * c-typeck.cc (handle_omp_array_sections_1): Robustify non-contiguous
+   array check and reject non-DECL base-pointer cases as unsupported.
+
 2022-02-03  Kwok Cheung Yeung  
 
* c-parser.ccc (c_parser_omp_clause_map): Update call to
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 7f466b858d9..3fea8185c0a 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -14186,14 +14186,27 @@ handle_omp_array_sections_1 (tree c, tree t, 
vec &types,
  if (d_length == NULL_TREE || !integer_onep (d_length))
{
  if (ort == C_ORT_ACC)
-   non_contiguous = true;
- else
{
+ while (TREE_CODE (d) == TREE_LIST)
+   d = TREE_CHAIN (d);
+ if (DECL_P (d))
+   {
+ /* Note that OpenACC does accept these kinds of
+non-contiguous pointer based arrays.  */
+ non_contiguous = true;
+ break;
+   }
  error_at (OMP_CLAUSE_LOCATION (c),
-   "array section is not contiguous in %qs clause",
+   "base-pointer expression in %qs clause not "
+   "supported for non-contiguous arrays",
omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
  return error_mark_node;
}
+
+ error_at (OMP_CLAUSE_LOCATION (c),
+   "array section is not contiguous in %qs clause",
+   omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+ return error_mark_node;
}
}
}
diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp
index bfdc3be2c4e..71b0f57918f 100644
--- a/gcc/cp/ChangeLog.omp
+++ b/gcc/cp/ChangeLog.omp
@@ -1,3 +1,8 @@
+2021-08-19  Chung-Lin Tang  
+
+   * semantics.cc (handle_omp_array_sections_1): Robustify non-contiguous
+   array check and reject non-DECL base-pointer cases as unsupported.
+
 2021-02-01  Chung-Lin Tang  
 
* semantics.cc (finish_omp_clauses):  Adjust to allow duplicate
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 9c7258989f4..9b8d5ac2ce8 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -5824,9 +5824,7 @@ handle_omp_array_sections_1 (tree c, tree t, vec 
&types,
  return error_mark_node;
}
   /* If there is a pointer type anywhere but in the very first
-array-section-subscript, the array section could be non-contiguous.
-Note that OpenACC does accept these kinds of non-contiguous pointer
-based arrays.  */
+array-section-subscript, the array section could be non-contiguous.  */
   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
  && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
  && TREE_CODE (TREE_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
@@ -5840,14 +5838,27 @@ handle_omp_array_sections_1 (tree c, tree t, vec 
&types,
  if (d_length == NULL_TREE || !integer_onep (d_length))
{
  if (ort == C_ORT_ACC)
-   non_contiguous = true;
- else
{
+ while (TREE_CODE (d) == TREE_LIST)
+   d = TREE_CHAIN (d);
+ if (DECL_P (d))
+   {
+ /* Note that OpenACC does accept these kinds of
+non-contiguous pointer based arrays.  */
+ non_contiguous = true;
+   

[gcc/devel/omp/gcc-14] Fix gimple_debug_cfg declaration

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:2adadd825fca68ee64104d251c2ac4898fbc59b4

commit 2adadd825fca68ee64104d251c2ac4898fbc59b4
Author: Frederik Harwath 
Date:   Tue Nov 16 16:08:40 2021 +0100

Fix gimple_debug_cfg declaration

Silence a warning. The argument type did not match the definition.

gcc/ChangeLog:

* tree-cfg.h (gimple_debug_cfg): Change argument type from int
to dump_flags_t.

Diff:
---
 gcc/ChangeLog.omp | 5 +
 gcc/tree-cfg.h| 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 8199cacbdd7..8fdd8731424 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,8 @@
+2021-11-16  Frederik Harwath  
+
+   * tree-cfg.h (gimple_debug_cfg): Change argument type from int
+   to dump_flags_t.
+
 2021-03-01  Kwok Cheung Yeung  
 
* omp-expand.cc (expand_oacc_for): Convert .tile variable to
diff --git a/gcc/tree-cfg.h b/gcc/tree-cfg.h
index 0564b79b4ab..e55991740e8 100644
--- a/gcc/tree-cfg.h
+++ b/gcc/tree-cfg.h
@@ -45,7 +45,7 @@ extern void clear_special_calls (void);
 extern edge find_taken_edge (basic_block, tree);
 extern void gimple_debug_bb (basic_block);
 extern basic_block gimple_debug_bb_n (int);
-extern void gimple_debug_cfg (int);
+extern void gimple_debug_cfg (dump_flags_t);
 extern void gimple_dump_cfg (FILE *, dump_flags_t);
 extern void dump_cfg_stats (FILE *);
 extern void debug_cfg_stats (void);


[gcc/devel/omp/gcc-14] testsuite/libgomp.oacc-fortran/: Add -Wopenacc-parallelism

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:f2cf2b994c4d8c871fad5502ffb9aaee9ea4f4e0

commit f2cf2b994c4d8c871fad5502ffb9aaee9ea4f4e0
Author: Tobias Burnus 
Date:   Thu Oct 21 09:28:57 2021 +0200

testsuite/libgomp.oacc-fortran/: Add -Wopenacc-parallelism

The following testcases expect the -Wopenacc-parallelism warning output
but did fail as not compiled with that warning; solution: add it.

libgomp/ChangeLog:

* testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90: Compile
with -Wopenacc-parallelism.
* testsuite/libgomp.oacc-fortran/declare-allocatable-3.f90: 
Likewise.

Diff:
---
 libgomp/ChangeLog.omp| 6 ++
 libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90 | 1 +
 libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-3.f90 | 1 +
 3 files changed, 8 insertions(+)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 6931529c366..928dee0287a 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,9 @@
+2021-10-21  Tobias Burnus  
+
+   * testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90: Compile
+   with -Wopenacc-parallelism.
+   * testsuite/libgomp.oacc-fortran/declare-allocatable-3.f90: Likewise.
+
 2021-03-01  Kwok Cheung Yeung  
 
* testsuite/libgomp.c-c++-common/collapse-4.c: New.
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90 
b/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90
index 1c8ccd9f61f..40cfde34aae 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90
@@ -1,6 +1,7 @@
 ! Test OpenACC 'declare create' with allocatable arrays.
 
 ! { dg-do run }
+! { dg-additional-options "-Wopenacc-parallelism" }
 
 !TODO-OpenACC-declare-allocate
 ! Not currently implementing correct '-DACC_MEM_SHARED=0' behavior:
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-3.f90 
b/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-3.f90
index 9381b00343d..c64d4bbe211 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-3.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-3.f90
@@ -1,6 +1,7 @@
 ! Test declare create with allocatable arrays.
 
 ! { dg-do run }
+! { dg-additional-options "-Wopenacc-parallelism" }
 
 module vars
   implicit none


[gcc/devel/omp/gcc-14] libgomp, nvptx: Update bundled CUDA header file

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:209d374b10250f889fca6c9def989e27484ffdf7

commit 209d374b10250f889fca6c9def989e27484ffdf7
Author: Kwok Cheung Yeung 
Date:   Wed Jun 22 07:43:05 2022 -0700

libgomp, nvptx: Update bundled CUDA header file

This updates the bundled cuda.h header file to include some new API calls 
and
constants that are now used in the code.

This patch should be included when the "libgomp, nvptx: low-latency memory
allocator" or "openmp: Add support for 'target_device' context selector set"
patches are upstreamed.

2022-06-21  Kwok Cheung Yeung  

include/
* cuda/cuda.h (CUdevice_attribute): Add definitions for
CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR and
CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR.
(CUmemAttach_flags): New.
(CUpointer_attribute): New.
(cuMemAllocManaged): New prototype.
(cuPointerGetAttribute): New prototype.

libgomp/
* plugin/cuda-lib.def (cuMemAllocManaged): Add new call.
(cuPointerGetAttribute): Likewise.

Diff:
---
 include/ChangeLog.omp   | 10 ++
 include/cuda/cuda.h | 12 
 libgomp/ChangeLog.omp   |  5 +
 libgomp/plugin/cuda-lib.def |  2 ++
 4 files changed, 29 insertions(+)

diff --git a/include/ChangeLog.omp b/include/ChangeLog.omp
index a460e639d22..261be6b587a 100644
--- a/include/ChangeLog.omp
+++ b/include/ChangeLog.omp
@@ -1,3 +1,13 @@
+2022-06-21  Kwok Cheung Yeung  
+
+   * cuda/cuda.h (CUdevice_attribute): Add definitions for
+   CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR and
+   CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR.
+   (CUmemAttach_flags): New.
+   (CUpointer_attribute): New.
+   (cuMemAllocManaged): New prototype.
+   (cuPointerGetAttribute): New prototype.
+
 2018-10-04  Cesar Philippidis  
 Julian Brown  
 
diff --git a/include/cuda/cuda.h b/include/cuda/cuda.h
index 0dca4b3a5c0..826db47ea52 100644
--- a/include/cuda/cuda.h
+++ b/include/cuda/cuda.h
@@ -83,9 +83,19 @@ 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_COMPUTE_CAPABILITY_MAJOR = 75,
+  CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR = 76,
   CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_MULTIPROCESSOR = 82
 } CUdevice_attribute;
 
+typedef enum {
+  CU_MEM_ATTACH_GLOBAL = 0x1
+} CUmemAttach_flags;
+
+typedef enum {
+  CU_POINTER_ATTRIBUTE_IS_MANAGED = 8
+} CUpointer_attribute;
+
 enum {
   CU_EVENT_DEFAULT = 0,
   CU_EVENT_DISABLE_TIMING = 2
@@ -245,6 +255,7 @@ CUresult cuMemGetInfo (size_t *, size_t *);
 CUresult cuMemAlloc (CUdeviceptr *, size_t);
 #define cuMemAllocHost cuMemAllocHost_v2
 CUresult cuMemAllocHost (void **, size_t);
+CUresult cuMemAllocManaged(CUdeviceptr *, size_t, unsigned int);
 CUresult cuMemHostAlloc (void **, size_t, unsigned int);
 CUresult cuMemcpy (CUdeviceptr, CUdeviceptr, size_t);
 CUresult cuMemcpyPeer (CUdeviceptr, CUcontext, CUdeviceptr, CUcontext, size_t);
@@ -286,6 +297,7 @@ CUresult cuModuleLoadData (CUmodule *, const void *);
 CUresult cuModuleUnload (CUmodule);
 CUresult cuOccupancyMaxPotentialBlockSize(int *, int *, CUfunction,
  CUoccupancyB2DSize, size_t, int);
+CUresult cuPointerGetAttribute(void *, CUpointer_attribute, CUdeviceptr);
 typedef void (*CUstreamCallback)(CUstream, CUresult, void *);
 CUresult cuStreamAddCallback(CUstream, CUstreamCallback, void *, unsigned int);
 CUresult cuStreamCreate (CUstream *, unsigned);
diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 928dee0287a..35b25404133 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,8 @@
+2022-06-21  Kwok Cheung Yeung  
+
+   * plugin/cuda-lib.def (cuMemAllocManaged): Add new call.
+   (cuPointerGetAttribute): Likewise.
+
 2021-10-21  Tobias Burnus  
 
* testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90: Compile
diff --git a/libgomp/plugin/cuda-lib.def b/libgomp/plugin/cuda-lib.def
index 007c6e0f4df..bd25375c26a 100644
--- a/libgomp/plugin/cuda-lib.def
+++ b/libgomp/plugin/cuda-lib.def
@@ -29,6 +29,7 @@ CUDA_ONE_CALL_MAYBE_NULL (cuLinkCreate_v2)
 CUDA_ONE_CALL (cuLinkDestroy)
 CUDA_ONE_CALL (cuMemAlloc)
 CUDA_ONE_CALL (cuMemAllocHost)
+CUDA_ONE_CALL (cuMemAllocManaged)
 CUDA_ONE_CALL (cuMemHostAlloc)
 CUDA_ONE_CALL (cuMemcpy)
 CUDA_ONE_CALL (cuMemcpyDtoDAsync)
@@ -50,6 +51,7 @@ CUDA_ONE_CALL (cuModuleLoad)
 CUDA_ONE_CALL (cuModuleLoadData)
 CUDA_ONE_CALL (cuModuleUnload)
 CUDA_ONE_CALL_MAYBE_NULL (cuOccupancyMaxPotentialBlockSize)
+CUDA_ONE_CALL (cuPointerGetAttribute)
 CUDA_ONE_CALL (cuStreamAddCallback)
 CUDA_ONE_CALL (cuStreamCreate)
 CUDA_ONE_CALL (cuStreamDestroy)


[gcc/devel/omp/gcc-14] Fortran: Fix proc pointer as elemental arg handling

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:2fa5c4bc10dfd4e9235c2e12c23c39aa3a1e364f

commit 2fa5c4bc10dfd4e9235c2e12c23c39aa3a1e364f
Author: Tobias Burnus 
Date:   Thu May 12 10:39:58 2022 +0200

Fortran: Fix proc pointer as elemental arg handling

The vtab's _callback function calls the elemental 'cb'
  cb (var(:)%comp, comp_types_vtable._callback);
which gets called in a scalarization loop as 'var' might be a
nonscalar. Without the patch, that got translated as:
  D.1234 = &comp_types_vtable._callback
  ...
   cb (&(*D.4060)[S.3 + D.4071], &D.1234);
where 'D.1234' is function_type. With the patch, it remains a pointer;
i.e. D.1234 = comp... and 'cb (..., D.1234)', avoiding ME ICE.

Note: Fortran (F2018, C15100) requires that dummy arguments are
dummy data objects, which rules out dummy procs/proc-pointer dummies,
which is enforced in resolve_fl_procedure.
Thus, this change only affects the internally generated code.

gcc/fortran/ChangeLog:

* trans-array.cc (gfc_scalar_elemental_arg_saved_as_reference):
Return true for attr.proc_pointer expressions.

gcc/testsuite/ChangeLog:

* gfortran.dg/finalize_38b.f90: Compile with -Ofast.

Diff:
---
 gcc/fortran/ChangeLog.omp  | 5 +
 gcc/fortran/trans-array.cc | 6 ++
 gcc/testsuite/ChangeLog.omp| 4 
 gcc/testsuite/gfortran.dg/finalize_38b.f90 | 1 +
 4 files changed, 16 insertions(+)

diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp
index 9a702e5ecb1..c5e1dfd959e 100644
--- a/gcc/fortran/ChangeLog.omp
+++ b/gcc/fortran/ChangeLog.omp
@@ -1,3 +1,8 @@
+2022-05-12  Tobias Burnus  
+
+   * trans-array.cc (gfc_scalar_elemental_arg_saved_as_reference):
+   Return true for attr.proc_pointer expressions.
+
 2022-04-27  Tobias Burnus 
 
* resolve.cc (gfc_resolve_finalizers): Remove
diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 1a9495448f3..0dcef85c563 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -3113,6 +3113,12 @@ gfc_scalar_elemental_arg_saved_as_reference (gfc_ss_info 
* ss_info)
   && gfc_expr_is_variable (ss_info->expr))
 return true;
 
+  /* Proc pointers: avoid creating a non-pointer function temporary;
+ should only get used internally due to constraints. */
+  if (!ss_info->data.scalar.needs_temporary &&
+  gfc_expr_attr (ss_info->expr).proc_pointer)
+return true;
+
   /* Otherwise the expression is evaluated to a temporary variable before the
  scalarization loop.  */
   return false;
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 89603da68c0..39d3b8401ae 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,7 @@
+2022-05-12  Tobias Burnus  
+
+   * gfortran.dg/finalize_38b.f90: Compile with -Ofast.
+
 2022-04-27  Tobias Burnus 
 
* gfortran.dg/abstract_type_6.f03: Remove dg-error as
diff --git a/gcc/testsuite/gfortran.dg/finalize_38b.f90 
b/gcc/testsuite/gfortran.dg/finalize_38b.f90
index 442e1753311..99c288784d6 100644
--- a/gcc/testsuite/gfortran.dg/finalize_38b.f90
+++ b/gcc/testsuite/gfortran.dg/finalize_38b.f90
@@ -1,4 +1,5 @@
 ! { dg-do compile }
+! { dg-additional-options "-Ofast" }
 !
 ! Check finalization
 !


[gcc/devel/omp/gcc-14] libgomp, openmp: Add ompx_pinned_mem_alloc

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:cc86be741309901e36b92ec4aa3bf4bfadab5a03

commit cc86be741309901e36b92ec4aa3bf4bfadab5a03
Author: Andrew Stubbs 
Date:   Mon Apr 22 17:51:22 2024 +0200

libgomp, openmp: Add ompx_pinned_mem_alloc

This creates a new predefined allocator as a shortcut for using pinned
memory with OpenMP.  The name uses the OpenMP extension space and is
intended to be consistent with other OpenMP implementations currently in
development.

The allocator is equivalent to using a custom allocator with the pinned
trait and the null fallback trait.

libgomp/ChangeLog:

* allocator.c (omp_max_predefined_alloc): Update.
(predefined_alloc_mapping): Add ompx_pinned_mem_alloc entry.
(omp_aligned_alloc): Support ompx_pinned_mem_alloc.
(omp_free): Likewise.
(omp_aligned_calloc): Likewise.
(omp_realloc): Likewise.
* omp.h.in (omp_allocator_handle_t): Add ompx_pinned_mem_alloc.
* omp_lib.f90.in: Add ompx_pinned_mem_alloc.
* testsuite/libgomp.c/alloc-pinned-5.c: New test.
* testsuite/libgomp.c/alloc-pinned-6.c: New test.
* testsuite/libgomp.fortran/alloc-pinned-1.f90: New test.

Co-Authored-By: Thomas Schwinge 

Diff:
---
 libgomp/ChangeLog.omp  |  14 +++
 libgomp/allocator.c|  58 
 libgomp/omp.h.in   |   1 +
 libgomp/omp_lib.f90.in |   2 +
 libgomp/testsuite/libgomp.c/alloc-pinned-5.c   | 103 +
 libgomp/testsuite/libgomp.c/alloc-pinned-6.c   | 101 
 .../testsuite/libgomp.fortran/alloc-pinned-1.f90   |  16 
 7 files changed, 276 insertions(+), 19 deletions(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 1f881fa77fc..d8413bba3e3 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,17 @@
+2023-08-23  Andrew Stubbs  
+
+   * allocator.c (omp_max_predefined_alloc): Update.
+   (predefined_alloc_mapping): Add ompx_pinned_mem_alloc entry.
+   (omp_aligned_alloc): Support ompx_pinned_mem_alloc.
+   (omp_free): Likewise.
+   (omp_aligned_calloc): Likewise.
+   (omp_realloc): Likewise.
+   * omp.h.in (omp_allocator_handle_t): Add ompx_pinned_mem_alloc.
+   * omp_lib.f90.in: Add ompx_pinned_mem_alloc.
+   * testsuite/libgomp.c/alloc-pinned-5.c: New test.
+   * testsuite/libgomp.c/alloc-pinned-6.c: New test.
+   * testsuite/libgomp.fortran/alloc-pinned-1.f90: New test.
+
 2022-03-01  Tobias Burnus  
 
* testsuite/libgomp.fortran/allocatable-comp.f90: New test.
diff --git a/libgomp/allocator.c b/libgomp/allocator.c
index cdedc7d80e9..dfff7dd08d4 100644
--- a/libgomp/allocator.c
+++ b/libgomp/allocator.c
@@ -98,7 +98,7 @@ GOMP_is_alloc (void *ptr)
 }
 
 
-#define omp_max_predefined_alloc omp_thread_mem_alloc
+#define omp_max_predefined_alloc ompx_pinned_mem_alloc
 
 /* These macros may be overridden in config//allocator.c.
The defaults (no override) are to return NULL for pinned memory requests
@@ -141,6 +141,7 @@ static const omp_memspace_handle_t 
predefined_alloc_mapping[] = {
   omp_low_lat_mem_space,   /* omp_cgroup_mem_alloc (implementation defined). */
   omp_low_lat_mem_space,   /* omp_pteam_mem_alloc (implementation defined). */
   omp_low_lat_mem_space,   /* omp_thread_mem_alloc (implementation defined). */
+  omp_default_mem_space,   /* ompx_pinned_mem_alloc. */
 };
 
 #define ARRAY_SIZE(A) (sizeof (A) / sizeof ((A)[0]))
@@ -686,8 +687,10 @@ retry:
  memspace = (allocator_data
  ? allocator_data->memspace
  : predefined_alloc_mapping[allocator]);
- ptr = MEMSPACE_ALLOC (memspace, new_size,
-   allocator_data && allocator_data->pinned);
+ int pinned = (allocator_data
+   ? allocator_data->pinned
+   : allocator == ompx_pinned_mem_alloc);
+ ptr = MEMSPACE_ALLOC (memspace, new_size, pinned);
}
   if (ptr == NULL)
goto fail;
@@ -708,7 +711,8 @@ retry:
 fail:;
   int fallback = (allocator_data
  ? allocator_data->fallback
- : allocator == omp_default_mem_alloc
+ : (allocator == omp_default_mem_alloc
+|| allocator == ompx_pinned_mem_alloc)
  ? omp_atv_null_fb
  : omp_atv_default_mem_fb);
   switch (fallback)
@@ -823,6 +827,7 @@ omp_free (void *ptr, omp_allocator_handle_t allocator)
 #endif
 
   memspace = predefined_alloc_mapping[data->allocator];
+  pinned = (data->allocator == ompx_pinned_mem_alloc);
 }
 
   MEMSPACE_FREE (memspace, data->ptr, data->size, pinned);
@@ -996,8 +1001,10 @@ retry:
  memspace = (allocator_data
  ? allocator_data->memspace
   

[gcc/devel/omp/gcc-14] openmp: Add -foffload-memory

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:33f539fa1466fa2ac21091c35b81d00741adc85f

commit 33f539fa1466fa2ac21091c35b81d00741adc85f
Author: Andrew Stubbs 
Date:   Mon Apr 22 18:07:00 2024 +0200

openmp: Add -foffload-memory

Add a new option.  It's inactive until I add some follow-up patches.

gcc/ChangeLog:

* common.opt: Add -foffload-memory and its enum values.
* coretypes.h (enum offload_memory): New.

Diff:
---
 gcc/ChangeLog.omp   |  6 ++
 gcc/common.opt  | 16 
 gcc/coretypes.h |  7 +++
 gcc/doc/invoke.texi | 16 +++-
 4 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 52306a5d516..f2bf2eb5b50 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,9 @@
+2023-08-23  Andrew Stubbs  
+
+   * common.opt: Add -foffload-memory and its enum values.
+   * coretypes.h (enum offload_memory): New.
+   * doc/invoke.texi: Document -foffload-memory.
+
 2022-10-19  Tobias Burnus  
 
* omp-expand.cc (expand_omp_target): Fix OpenACC in case there
diff --git a/gcc/common.opt b/gcc/common.opt
index ad348844775..e19c4ef1166 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2339,6 +2339,22 @@ Enum(offload_abi) String(ilp32) Value(OFFLOAD_ABI_ILP32)
 EnumValue
 Enum(offload_abi) String(lp64) Value(OFFLOAD_ABI_LP64)
 
+foffload-memory=
+Common Joined RejectNegative Enum(offload_memory) Var(flag_offload_memory) 
Init(OFFLOAD_MEMORY_NONE)
+-foffload-memory=[none|unified|pinned] Use an offload memory optimization.
+
+Enum
+Name(offload_memory) Type(enum offload_memory) UnknownError(Unknown offload 
memory option %qs)
+
+EnumValue
+Enum(offload_memory) String(none) Value(OFFLOAD_MEMORY_NONE)
+
+EnumValue
+Enum(offload_memory) String(unified) Value(OFFLOAD_MEMORY_UNIFIED)
+
+EnumValue
+Enum(offload_memory) String(pinned) Value(OFFLOAD_MEMORY_PINNED)
+
 fomit-frame-pointer
 Common Var(flag_omit_frame_pointer) Optimization
 When possible do not generate stack frames.
diff --git a/gcc/coretypes.h b/gcc/coretypes.h
index 1ac6f0abea3..938cfa93753 100644
--- a/gcc/coretypes.h
+++ b/gcc/coretypes.h
@@ -218,6 +218,13 @@ enum offload_abi {
   OFFLOAD_ABI_ILP32
 };
 
+/* Types of memory optimization for an offload device.  */
+enum offload_memory {
+  OFFLOAD_MEMORY_NONE,
+  OFFLOAD_MEMORY_UNIFIED,
+  OFFLOAD_MEMORY_PINNED
+};
+
 /* Types of profile update methods.  */
 enum profile_update {
   PROFILE_UPDATE_SINGLE,
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 3e2f9bd5b4b..a368d80a123 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -202,7 +202,7 @@ in the following sections.
 -fno-builtin  -fno-builtin-@var{function}  -fcond-mismatch
 -ffreestanding  -fgimple  -fgnu-tm  -fgnu89-inline  -fhosted
 -flax-vector-conversions  -fms-extensions
--foffload=@var{arg}  -foffload-options=@var{arg}
+-foffload=@var{arg}  -foffload-options=@var{arg} -foffload-memory=@var{arg}
 -fopenacc  -fopenacc-dim=@var{geom}
 -fopenmp  -fopenmp-simd  -fopenmp-target-simd-clone@r{[}=@var{device-type}@r{]}
 -fpermitted-flt-eval-methods=@var{standard}
@@ -2779,6 +2779,20 @@ Typical command lines are
 -foffload-options=amdgcn-amdhsa=-march=gfx906
 @end smallexample
 
+@opindex foffload-memory
+@cindex OpenMP offloading memory modes
+@item -foffload-memory=none
+@itemx -foffload-memory=unified
+@itemx -foffload-memory=pinned
+Enable a memory optimization mode to use with OpenMP.  The default behavior,
+@option{-foffload-memory=none}, is to do nothing special (unless enabled via
+a requires directive in the code).  @option{-foffload-memory=unified} is
+equivalent to @code{#pragma omp requires unified_shared_memory}.
+@option{-foffload-memory=pinned} forces all host memory to be pinned (this
+mode may require the user to increase the ulimit setting for locked memory).
+All translation units must select the same setting to avoid undefined
+behavior.
+
 @opindex fopenacc
 @cindex OpenACC accelerator programming
 @item -fopenacc


[gcc/devel/omp/gcc-14] openmp: -foffload-memory=pinned

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:f5d71ce1361d48cd79b679e2223004215d583436

commit f5d71ce1361d48cd79b679e2223004215d583436
Author: Andrew Stubbs 
Date:   Mon Apr 22 18:09:14 2024 +0200

openmp: -foffload-memory=pinned

Implement the -foffload-memory=pinned option such that libgomp is
instructed to enable fully-pinned memory at start-up.  The option is
intended to provide a performance boost to certain offload programs without
modifying the code.

This feature only works on Linux, at present, and simply calls mlockall to
enable always-on memory pinning.  It requires that the ulimit feature is
set high enough to accommodate all the program's memory usage.

In this mode the ompx_pinned_memory_alloc feature is disabled as it is not
needed and may conflict.

gcc/ChangeLog:

* omp-builtins.def (BUILT_IN_GOMP_ENABLE_PINNED_MODE): New.
* omp-low.cc (omp_enable_pinned_mode): New function.
(execute_lower_omp): Call omp_enable_pinned_mode.

libgomp/ChangeLog:

* config/linux/allocator.c (always_pinned_mode): New variable.
(GOMP_enable_pinned_mode): New function.
(linux_memspace_alloc): Disable pinning when always_pinned_mode set.
(linux_memspace_calloc): Likewise.
(linux_memspace_free): Likewise.
(linux_memspace_realloc): Likewise.
* libgomp.map: Add GOMP_enable_pinned_mode.
* testsuite/libgomp.c/alloc-pinned-7.c: New test.
* testsuite/libgomp.c-c++-common/alloc-pinned-1.c: New test.

Diff:
---
 gcc/ChangeLog.omp  |  6 ++
 gcc/omp-builtins.def   |  3 +
 gcc/omp-low.cc | 66 ++
 libgomp/ChangeLog.omp  | 12 
 libgomp/config/linux/allocator.c   | 26 +
 libgomp/libgomp.map|  1 +
 .../libgomp.c-c++-common/alloc-pinned-1.c  | 28 +
 libgomp/testsuite/libgomp.c/alloc-pinned-7.c   | 63 +
 8 files changed, 205 insertions(+)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index f2bf2eb5b50..f4b52d9e3ec 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,9 @@
+2023-08-23  Andrew Stubbs  
+
+   * omp-builtins.def (BUILT_IN_GOMP_ENABLE_PINNED_MODE): New.
+   * omp-low.cc (omp_enable_pinned_mode): New function.
+   (execute_lower_omp): Call omp_enable_pinned_mode.
+
 2023-08-23  Andrew Stubbs  
 
* common.opt: Add -foffload-memory and its enum values.
diff --git a/gcc/omp-builtins.def b/gcc/omp-builtins.def
index d3e9c924fe1..9c47fef08a4 100644
--- a/gcc/omp-builtins.def
+++ b/gcc/omp-builtins.def
@@ -476,3 +476,6 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_WARNING, "GOMP_warning",
  BT_FN_VOID_CONST_PTR_SIZE, ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_ERROR, "GOMP_error",
  BT_FN_VOID_CONST_PTR_SIZE, 
ATTR_COLD_NORETURN_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_ENABLE_PINNED_MODE,
+ "GOMP_enable_pinned_mode",
+ BT_FN_VOID, ATTR_NOTHROW_LIST)
diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index dcdd7a6b967..94de26b6013 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -15214,6 +15214,68 @@ lower_omp (gimple_seq *body, omp_context *ctx)
   input_location = saved_location;
 }
 
+/* Emit a constructor function to enable -foffload-memory=pinned
+   at runtime.  Libgomp handles the OS mode setting, but we need to trigger
+   it by calling GOMP_enable_pinned mode before the program proper runs.  */
+
+static void
+omp_enable_pinned_mode ()
+{
+  static bool visited = false;
+  if (visited)
+return;
+  visited = true;
+
+  /* Create a new function like this:
+ 
+   static void __attribute__((constructor))
+   __set_pinned_mode ()
+   {
+ GOMP_enable_pinned_mode ();
+   }
+  */
+
+  tree name = get_identifier ("__set_pinned_mode");
+  tree voidfntype = build_function_type_list (void_type_node, NULL_TREE);
+  tree decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, name, voidfntype);
+
+  TREE_STATIC (decl) = 1;
+  TREE_USED (decl) = 1;
+  DECL_ARTIFICIAL (decl) = 1;
+  DECL_IGNORED_P (decl) = 0;
+  TREE_PUBLIC (decl) = 0;
+  DECL_UNINLINABLE (decl) = 1;
+  DECL_EXTERNAL (decl) = 0;
+  DECL_CONTEXT (decl) = NULL_TREE;
+  DECL_INITIAL (decl) = make_node (BLOCK);
+  BLOCK_SUPERCONTEXT (DECL_INITIAL (decl)) = decl;
+  DECL_STATIC_CONSTRUCTOR (decl) = 1;
+  DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("constructor"),
+ NULL_TREE, NULL_TREE);
+
+  tree t = build_decl (UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE,
+  void_type_node);
+  DECL_ARTIFICIAL (t) = 1;
+  DECL_IGNORED_P (t) = 1;
+  DECL_CONTEXT (t) = decl;
+  DECL_RESULT (decl) = t;
+
+  push_struct_function (decl);
+  init_tree_ssa (cfun);

[gcc/devel/omp/gcc-14] libgomp, nvptx: Cuda pinned memory

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:cd021784a82ace28b251096274a790bce0ec26c4

commit cd021784a82ace28b251096274a790bce0ec26c4
Author: Andrew Stubbs 
Date:   Mon Apr 22 18:42:50 2024 +0200

libgomp, nvptx: Cuda pinned memory

Use Cuda to pin memory, instead of Linux mlock, when available.

There are two advantages: firstly, this gives a significant speed boost for
NVPTX offloading, and secondly, it side-steps the usual OS ulimit/rlimit
setting.

The design adds a device independent plugin API for allocating pinned 
memory,
and then implements it for NVPTX.  At present, the other supported devices 
do
not have equivalent capabilities (or requirements).

libgomp/ChangeLog:

* config/linux/allocator.c: Include assert.h.
(using_device_for_page_locked): New variable.
(linux_memspace_alloc): Add init0 parameter. Support device pinning.
(linux_memspace_calloc): Set init0 to true.
(linux_memspace_free): Support device pinning.
(linux_memspace_realloc): Support device pinning.
(MEMSPACE_ALLOC): Set init0 to false.
* libgomp-plugin.h
(GOMP_OFFLOAD_page_locked_host_alloc): New prototype.
(GOMP_OFFLOAD_page_locked_host_free): Likewise.
* libgomp.h (gomp_page_locked_host_alloc): Likewise.
(gomp_page_locked_host_free): Likewise.
(struct gomp_device_descr): Add page_locked_host_alloc_func and
page_locked_host_free_func.
* libgomp_g.h (GOMP_enable_pinned_mode): New prototype.
* plugin/plugin-nvptx.c
(GOMP_OFFLOAD_page_locked_host_alloc): New function.
(GOMP_OFFLOAD_page_locked_host_free): Likewise.
* target.c (device_for_page_locked): New variable.
(get_device_for_page_locked): New function.
(gomp_page_locked_host_alloc): Likewise.
(gomp_page_locked_host_free): Likewise.
(gomp_load_plugin_for_device): Add page_locked_host_alloc and
page_locked_host_free.
* testsuite/libgomp.c/alloc-pinned-1.c: Change expectations for 
NVPTX
devices.
* testsuite/libgomp.c/alloc-pinned-2.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-3.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-4.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-5.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-6.c: Likewise.

Co-Authored-By: Thomas Schwinge 

Diff:
---
 libgomp/ChangeLog.omp|  34 +++
 libgomp/config/linux/allocator.c | 142 ---
 libgomp/libgomp-plugin.h |   2 +
 libgomp/libgomp.h|   4 +
 libgomp/libgomp_g.h  |   1 +
 libgomp/plugin/plugin-nvptx.c|  34 +++
 libgomp/target.c | 136 +
 libgomp/testsuite/libgomp.c/alloc-pinned-1.c |  25 +
 libgomp/testsuite/libgomp.c/alloc-pinned-2.c |  25 +
 libgomp/testsuite/libgomp.c/alloc-pinned-3.c |  43 +++-
 libgomp/testsuite/libgomp.c/alloc-pinned-4.c |  43 +++-
 libgomp/testsuite/libgomp.c/alloc-pinned-5.c |  25 +
 libgomp/testsuite/libgomp.c/alloc-pinned-6.c |  34 ++-
 13 files changed, 498 insertions(+), 50 deletions(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index c5fcab7ea83..10fbb51ebe5 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,37 @@
+2023-08-23  Andrew Stubbs  
+
+   * config/linux/allocator.c: Include assert.h.
+   (using_device_for_page_locked): New variable.
+   (linux_memspace_alloc): Add init0 parameter. Support device pinning.
+   (linux_memspace_calloc): Set init0 to true.
+   (linux_memspace_free): Support device pinning.
+   (linux_memspace_realloc): Support device pinning.
+   (MEMSPACE_ALLOC): Set init0 to false.
+   * libgomp-plugin.h
+   (GOMP_OFFLOAD_page_locked_host_alloc): New prototype.
+   (GOMP_OFFLOAD_page_locked_host_free): Likewise.
+   * libgomp.h (gomp_page_locked_host_alloc): Likewise.
+   (gomp_page_locked_host_free): Likewise.
+   (struct gomp_device_descr): Add page_locked_host_alloc_func and
+   page_locked_host_free_func.
+   * libgomp_g.h (GOMP_enable_pinned_mode): New prototype.
+   * plugin/plugin-nvptx.c
+   (GOMP_OFFLOAD_page_locked_host_alloc): New function.
+   (GOMP_OFFLOAD_page_locked_host_free): Likewise.
+   * target.c (device_for_page_locked): New variable.
+   (get_device_for_page_locked): New function.
+   (gomp_page_locked_host_alloc): Likewise.
+   (gomp_page_locked_host_free): Likewise.
+   (gomp_load_plugin_for_device): Add page_locked_host_alloc and
+   page_locked_host_free.
+   * testsuite/libgomp.c/alloc-pinned-1.c: Change expectations for NVPTX
+   devices.
+  

[gcc/devel/omp/gcc-14] libgomp: fine-grained pinned memory allocator

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:1a95130b797ad364163e5343969ab4b2102baab4

commit 1a95130b797ad364163e5343969ab4b2102baab4
Author: Andrew Stubbs 
Date:   Mon Apr 22 19:37:18 2024 +0200

libgomp: fine-grained pinned memory allocator

This patch introduces a new custom memory allocator for use with pinned
memory (in the case where the Cuda allocator isn't available).  In future,
this allocator will also be used for Unified Shared Memory.  Both memories
are incompatible with the system malloc because allocated memory cannot
share a page with memory allocated for other purposes.

This means that small allocations will no longer consume an entire page of
pinned memory.  Unfortunately, it also means that pinned memory pages will
never be unmapped (although they may be reused).

The implementation is not perfect; there are various corner cases 
(especially
related to extending onto new pages) where allocations and reallocations may
be sub-optimal, but it should still be a step forward in support for small
allocations.

I have considered using libmemkind's "fixed" memory but rejected it for 
three
reasons: 1) libmemkind may not always be present at runtime, 2) there's no
currently documented means to extend a "fixed" kind one page at a time
(although the code appears to have an undocumented function that may do the
job, and/or extending libmemkind to support the MAP_LOCKED mmap flag with 
its
regular kinds would be straight-forward), 3) USM benefits from having the
metadata located in different memory and using an external implementation 
makes
it hard to guarantee this.

libgomp/ChangeLog:

* Makefile.am (libgomp_la_SOURCES): Add usmpin-allocator.c.
* Makefile.in: Regenerate.
* config/linux/allocator.c: Include unistd.h.
(pin_ctx): New variable.
(ctxlock): New variable.
(linux_init_pin_ctx): New function.
(linux_memspace_alloc): Use usmpin-allocator for pinned memory.
(linux_memspace_free): Likewise.
(linux_memspace_realloc): Likewise.
* libgomp.h (usmpin_init_context): New prototype.
(usmpin_register_memory): New prototype.
(usmpin_alloc): New prototype.
(usmpin_free): New prototype.
(usmpin_realloc): New prototype.
* testsuite/libgomp.c/alloc-pinned-1.c: Adjust for new behaviour.
* testsuite/libgomp.c/alloc-pinned-2.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-5.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-8.c: New test.
* usmpin-allocator.c: New file.

Diff:
---
 libgomp/ChangeLog.omp|  22 ++
 libgomp/Makefile.am  |   3 +-
 libgomp/Makefile.in  |  13 +-
 libgomp/config/linux/allocator.c |  91 +---
 libgomp/libgomp.h|  10 +
 libgomp/testsuite/libgomp.c/alloc-pinned-8.c | 127 +++
 libgomp/usmpin-allocator.c   | 319 +++
 7 files changed, 549 insertions(+), 36 deletions(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 10fbb51ebe5..4eb08fdef0d 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,25 @@
+2023-08-23  Andrew Stubbs  
+
+   * Makefile.am (libgomp_la_SOURCES): Add usmpin-allocator.c.
+   * Makefile.in: Regenerate.
+   * config/linux/allocator.c: Include unistd.h.
+   (pin_ctx): New variable.
+   (ctxlock): New variable.
+   (linux_init_pin_ctx): New function.
+   (linux_memspace_alloc): Use usmpin-allocator for pinned memory.
+   (linux_memspace_free): Likewise.
+   (linux_memspace_realloc): Likewise.
+   * libgomp.h (usmpin_init_context): New prototype.
+   (usmpin_register_memory): New prototype.
+   (usmpin_alloc): New prototype.
+   (usmpin_free): New prototype.
+   (usmpin_realloc): New prototype.
+   * testsuite/libgomp.c/alloc-pinned-1.c: Adjust for new behaviour.
+   * testsuite/libgomp.c/alloc-pinned-2.c: Likewise.
+   * testsuite/libgomp.c/alloc-pinned-5.c: Likewise.
+   * testsuite/libgomp.c/alloc-pinned-8.c: New test.
+   * usmpin-allocator.c: New file.
+
 2023-08-23  Andrew Stubbs  
 
* config/linux/allocator.c: Include assert.h.
diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index 4ca22ba2d95..5d355f20cc4 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -72,7 +72,8 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
target.c splay-tree.c libgomp-plugin.c oacc-parallel.c oacc-host.c \
oacc-init.c oacc-mem.c oacc-async.c oacc-plugin.c oacc-cuda.c \
priority_queue.c affinity-fmt.c teams.c allocator.c oacc-profiling.c \
-   oacc-target.c target-indirect.c oacc-profiling-acc_register_library.c
+   oacc-ta

[gcc/devel/omp/gcc-14] Fix ICE when cache-3-1.c testcase is run

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:628a000bdbf63252c2ede13ccab8e99a19769866

commit 628a000bdbf63252c2ede13ccab8e99a19769866
Author: Kwok Cheung Yeung 
Date:   Thu Mar 17 16:00:52 2022 +

Fix ICE when cache-3-1.c testcase is run

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

2022-03-17  Kwok Cheung Yeung  

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

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

Diff:
---
 gcc/c/ChangeLog.omp  | 5 +
 gcc/c/c-typeck.cc| 3 ++-
 gcc/cp/ChangeLog.omp | 5 +
 gcc/cp/semantics.cc  | 3 ++-
 4 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/gcc/c/ChangeLog.omp b/gcc/c/ChangeLog.omp
index 4b8331c3744..db1ddfb1720 100644
--- a/gcc/c/ChangeLog.omp
+++ b/gcc/c/ChangeLog.omp
@@ -1,3 +1,8 @@
+2022-03-17  Kwok Cheung Yeung  
+
+   * c-typeck.cc (handle_omp_array_sections_1): Add check to ensure
+   that clause is a map.
+
 2021-08-19  Chung-Lin Tang  
 
* c-typeck.cc (handle_omp_array_sections_1): Robustify non-contiguous
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 3fea8185c0a..b5a023a1299 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -14185,7 +14185,8 @@ handle_omp_array_sections_1 (tree c, tree t, vec 
&types,
  tree d_length = TREE_OPERAND (d, 2);
  if (d_length == NULL_TREE || !integer_onep (d_length))
{
- if (ort == C_ORT_ACC)
+ if (ort == C_ORT_ACC
+ && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
{
  while (TREE_CODE (d) == TREE_LIST)
d = TREE_CHAIN (d);
diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp
index 71b0f57918f..c78a2d37e18 100644
--- a/gcc/cp/ChangeLog.omp
+++ b/gcc/cp/ChangeLog.omp
@@ -1,3 +1,8 @@
+2022-03-17  Kwok Cheung Yeung  
+
+   * semantics.cc (handle_omp_array_sections_1):  Add check to ensure
+   that clause is a map.
+
 2021-08-19  Chung-Lin Tang  
 
* semantics.cc (handle_omp_array_sections_1): Robustify non-contiguous
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 9b8d5ac2ce8..0e88b380696 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -5837,7 +5837,8 @@ handle_omp_array_sections_1 (tree c, tree t, vec 
&types,
  tree d_length = TREE_OPERAND (d, 2);
  if (d_length == NULL_TREE || !integer_onep (d_length))
{
- if (ort == C_ORT_ACC)
+ if (ort == C_ORT_ACC
+ && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
{
  while (TREE_CODE (d) == TREE_LIST)
d = TREE_CHAIN (d);


[gcc/devel/omp/gcc-14] Fix gfortran.dg/gomp/num-teams-2.f90

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:2adb0ec35cd47b34d47c961f6ae46089e3e02cbc

commit 2adb0ec35cd47b34d47c961f6ae46089e3e02cbc
Author: Tobias Burnus 
Date:   Mon Jun 27 13:26:43 2022 +0200

Fix gfortran.dg/gomp/num-teams-2.f90

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

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

Diff:
---
 gcc/testsuite/ChangeLog.omp|  4 
 gcc/testsuite/gfortran.dg/gomp/num-teams-2.f90 | 12 ++--
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 39d3b8401ae..7756bc0bb92 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,7 @@
+2022-06-27  Tobias Burnus  
+
+   * gfortran.dg/gomp/num-teams-2.f90: Use dg-error not dg-warning.
+
 2022-05-12  Tobias Burnus  
 
* gfortran.dg/finalize_38b.f90: Compile with -Ofast.
diff --git a/gcc/testsuite/gfortran.dg/gomp/num-teams-2.f90 
b/gcc/testsuite/gfortran.dg/gomp/num-teams-2.f90
index e7814a11a5a..f3031481d4a 100644
--- a/gcc/testsuite/gfortran.dg/gomp/num-teams-2.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/num-teams-2.f90
@@ -9,13 +9,13 @@ subroutine foo (i)
   !$omp teams num_teams (6 : 4)! { dg-warning "NUM_TEAMS lower 
bound at .1. larger than upper bound at .2." }
   !$omp end teams
 
-  !$omp teams num_teams (-7)   ! { dg-warning "INTEGER expression of 
NUM_TEAMS clause at .1. must be positive" }
+  !$omp teams num_teams (-7)   ! { dg-error "INTEGER expression of 
NUM_TEAMS clause at .1. must be positive" }
   !$omp end teams
 
-  !$omp teams num_teams (i : -7)   ! { dg-warning "INTEGER 
expression of NUM_TEAMS clause at .1. must be positive" }
+  !$omp teams num_teams (i : -7)   ! { dg-error "INTEGER 
expression of NUM_TEAMS clause at .1. must be positive" }
   !$omp end teams
 
-  !$omp teams num_teams (-7 : 8)   ! { dg-warning "INTEGER 
expression of NUM_TEAMS clause at .1. must be positive" }
+  !$omp teams num_teams (-7 : 8)   ! { dg-error "INTEGER 
expression of NUM_TEAMS clause at .1. must be positive" }
   !$omp end teams
 end
 
@@ -25,13 +25,13 @@ subroutine bar (i)
   !$omp target teams num_teams (6 : 4) ! { dg-warning "NUM_TEAMS lower bound 
at .1. larger than upper bound at .2." }
   !$omp end target teams
 
-  !$omp target teams num_teams (-7)! { dg-warning "INTEGER expression of 
NUM_TEAMS clause at .1. must be positive" }
+  !$omp target teams num_teams (-7)! { dg-error "INTEGER expression of 
NUM_TEAMS clause at .1. must be positive" }
   !$omp end target teams
 
-  !$omp target teams num_teams (i : -7)! { dg-warning "INTEGER 
expression of NUM_TEAMS clause at .1. must be positive" }
+  !$omp target teams num_teams (i : -7)! { dg-error "INTEGER 
expression of NUM_TEAMS clause at .1. must be positive" }
   !$omp end target teams
 
-  !$omp target teams num_teams (-7 : 8)! { dg-warning "INTEGER 
expression of NUM_TEAMS clause at .1. must be positive" }
+  !$omp target teams num_teams (-7 : 8)! { dg-error "INTEGER 
expression of NUM_TEAMS clause at .1. must be positive" }
   !$omp end target teams
 end
 end module


[gcc/devel/omp/gcc-14] gfortran.dg/gomp/scope-6.f90: Update scan-tree-dump

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:7056269f8fcad4580ce9faaa5016a15d4b7ca367

commit 7056269f8fcad4580ce9faaa5016a15d4b7ca367
Author: Tobias Burnus 
Date:   Thu Oct 6 10:58:23 2022 +0200

gfortran.dg/gomp/scope-6.f90: Update scan-tree-dump

gcc/testsuite/
* gfortran.dg/gomp/scope-6.f90: Likewise.

Diff:
---
 gcc/testsuite/ChangeLog.omp| 4 
 gcc/testsuite/gfortran.dg/gomp/scope-6.f90 | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 5bf09420432..51c468dc364 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,7 @@
+2022-10-06  Tobias Burnus  
+
+   * gfortran.dg/gomp/scope-6.f90: Likewise.
+
 2022-07-12  Andrew Stubbs  
 
* lib/target-supports.exp
diff --git a/gcc/testsuite/gfortran.dg/gomp/scope-6.f90 
b/gcc/testsuite/gfortran.dg/gomp/scope-6.f90
index 4c4f5e034f7..39a65904c33 100644
--- a/gcc/testsuite/gfortran.dg/gomp/scope-6.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/scope-6.f90
@@ -20,4 +20,4 @@ contains
   end
 end
 
-! { dg-final { scan-tree-dump "omp scope private\\(a\\) firstprivate\\(b\\) 
reduction\\(\\+:c\\) allocate\\(allocator\\(D\\.\[0-9\]+\\):a\\) 
allocate\\(allocator\\(D\\.\[0-9\]+\\):b\\) 
allocate\\(allocator\\(D\\.\[0-9\]+\\):c\\)" "original" } }
+! { dg-final { scan-tree-dump "omp scope private\\(a\\) firstprivate\\(b\\) 
reduction\\(\\+:c\\) allocate\\(allocator\\(h\\):a\\) 
allocate\\(allocator\\(h\\):b\\) allocate\\(allocator\\(h\\):c\\)" "original" } 
}


[gcc/devel/omp/gcc-14] openmp: fix max_vf setting for amdgcn offloading

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:2481350075a8a562a43d9a7c13a622489c2fd435

commit 2481350075a8a562a43d9a7c13a622489c2fd435
Author: Andrew Stubbs 
Date:   Fri Jul 8 11:58:46 2022 +0100

openmp: fix max_vf setting for amdgcn offloading

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

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

gcc/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

Diff:
---
 gcc/ChangeLog.omp |  9 +
 gcc/gimple-loop-versioning.cc |  5 -
 gcc/omp-general.cc| 18 ++
 gcc/omp-general.h |  1 +
 gcc/omp-low.cc|  9 -
 gcc/testsuite/ChangeLog.omp   |  7 +++
 gcc/testsuite/gcc.dg/gomp/target-vf.c | 21 +
 gcc/testsuite/lib/target-supports.exp | 10 ++
 8 files changed, 78 insertions(+), 2 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index f4b52d9e3ec..d7256902331 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,12 @@
+2022-07-12  Andrew Stubbs  
+
+   * gimple-loop-versioning.cc (loop_versioning::loop_versioning): Add
+   comment.
+   * omp-general.cc (omp_max_simd_vf): New function.
+   * omp-general.h (omp_max_simd_vf): New prototype.
+   * omp-low.cc (lower_rec_simd_input_clauses): Select largest from
+ omp_max_vf, omp_max_simt_vf, and omp_max_simd_vf.
+
 2023-08-23  Andrew Stubbs  
 
* omp-builtins.def (BUILT_IN_GOMP_ENABLE_PINNED_MODE): New.
diff --git a/gcc/gimple-loop-versioning.cc b/gcc/gimple-loop-versioning.cc
index 17877f06921..c22c24bd958 100644
--- a/gcc/gimple-loop-versioning.cc
+++ b/gcc/gimple-loop-versioning.cc
@@ -555,7 +555,10 @@ loop_versioning::loop_versioning (function *fn)
  unvectorizable code, since it is the largest size that can be
  handled efficiently by scalar code.  omp_max_vf calculates the
  maximum number of bytes in a vector, when such a value is relevant
- to loop optimization.  */
+ to loop optimization.
+ FIXME: this probably needs to use omp_max_simd_vf when in a target
+ region, but how to tell? (And MAX_FIXED_MODE_SIZE is large enough that
+ it doesn't actually matter.)  */
   m_maximum_scale = estimated_poly_value (omp_max_vf ());
   m_maximum_scale = MAX (m_maximum_scale, MAX_FIXED_MODE_SIZE);
 }
diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc
index 9a125a28afa..faa248ebd17 100644
--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -1039,6 +1039,24 @@ omp_max_simt_vf (void)
   return 0;
 }
 
+/* Return maximum SIMD width if offloading may target SIMD hardware.  */
+
+int
+omp_max_simd_vf (void)
+{
+  if (!optimize)
+return 0;
+  if (ENABLE_OFFLOADING)
+for (const char *c = getenv ("OFFLOAD_TARGET_NAMES"); c;)
+  {
+   if (startswith (c, "amdgcn"))
+ return 64;
+   else if ((c = strchr (c, ':')))
+ c++;
+  }
+  return 0;
+}
+
 /* Store the construct selectors as tree codes from last to first.
CTX is a list of trait selectors, nconstructs must be equal to its
length, and the array CONSTRUCTS holds the output.  */
diff --git a/gcc/omp-general.h b/gcc/omp-general.h
index 15e092f1286..e478d9bdeab 100644
--- a/gcc/omp-general.h
+++ b/gcc/omp-general.h
@@ -164,6 +164,7 @@ extern gimple *omp_build_barrier (tree lhs);
 extern tree find_combined_omp_for (tree *, int *, void *);
 extern poly_uint64 omp_max_vf (void);
 extern int omp_max_simt_vf (void);
+extern int omp_max_simd_vf (void);
 extern const char *omp_context_name_list_prop (tree);
 extern void omp_construct_traits_to_codes (tree, int, enum tree_code *);
 extern tree omp_check_context_selector (location_t loc, tree ctx);
diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index 94de26b6013..dc0a6906c67 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -4822,7 +4822,14 @@ lower_rec_simd_input_clauses (tree new_var, omp_context 
*ctx,
 {
   if (known_eq (sctx->max_vf, 0U))
 {
-  sctx->max_vf = sctx->is_simt ? omp_max_simt_vf () : omp_max_vf ();
+  /* If we are compiling for multiple devices choose the largest VF.  */
+  sctx->max_vf = omp_max_vf ();
+  if (omp_maybe_offloaded_ctx (ctx))
+   {
+ if (sctx->is_simt)
+   sctx->max_v

[gcc/devel/omp/gcc-14] omp-oacc-kernels-decompose.cc: fix -fcompare-debug with GIMPLE_DEBUG

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:1bee3d91a026b0124320a55ce679181db3411dcd

commit 1bee3d91a026b0124320a55ce679181db3411dcd
Author: Tobias Burnus 
Date:   Fri Oct 21 15:31:25 2022 +0200

omp-oacc-kernels-decompose.cc: fix -fcompare-debug with GIMPLE_DEBUG

GIMPLE_DEBUG were put in a parallel region of its own, which is not
only pointless but also breaks -fcompare-debug. With this commit,
they are handled like simple assignments: those placed are places
into the same body as the loop such that only one parallel region
remains as without debugging. This fixes the existing testcase
libgomp.oacc-c-c++-common/kernels-loop-g.c.

Note: GIMPLE_DEBUG are only accepted with -fcompare-debug; if they
appear otherwise, decompose_kernels_region_body rejects them with
a sorry (unchanged).

gcc/
* omp-oacc-kernels-decompose.cc (top_level_omp_for_in_stmt,
decompose_kernels_region_body): Handle GIMPLE_DEBUG like
simple assignment.

Diff:
---
 gcc/ChangeLog.omp | 6 ++
 gcc/omp-oacc-kernels-decompose.cc | 5 +++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index d7256902331..4eef9f49974 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,9 @@
+2022-10-21  Tobias Burnus  
+
+   * omp-oacc-kernels-decompose.cc (top_level_omp_for_in_stmt,
+   decompose_kernels_region_body): Handle GIMPLE_DEBUG like
+   simple assignment.
+
 2022-07-12  Andrew Stubbs  
 
* gimple-loop-versioning.cc (loop_versioning::loop_versioning): Add
diff --git a/gcc/omp-oacc-kernels-decompose.cc 
b/gcc/omp-oacc-kernels-decompose.cc
index 4ed4b68f53f..ac76fc483ec 100644
--- a/gcc/omp-oacc-kernels-decompose.cc
+++ b/gcc/omp-oacc-kernels-decompose.cc
@@ -120,7 +120,8 @@ top_level_omp_for_in_stmt (gimple *stmt)
  for (gsi = gsi_start (body); !gsi_end_p (gsi); gsi_next (&gsi))
{
  gimple *body_stmt = gsi_stmt (gsi);
- if (gimple_code (body_stmt) == GIMPLE_ASSIGN)
+ if (gimple_code (body_stmt) == GIMPLE_ASSIGN
+ || gimple_code (body_stmt) == GIMPLE_DEBUG)
continue;
  else if (gimple_code (body_stmt) == GIMPLE_OMP_FOR
   && gsi_one_before_end_p (gsi))
@@ -1363,7 +1364,7 @@ decompose_kernels_region_body (gimple *kernels_region, 
tree kernels_clauses)
= (gimple_code (stmt) == GIMPLE_ASSIGN
   && TREE_CODE (gimple_assign_lhs (stmt)) == VAR_DECL
   && DECL_ARTIFICIAL (gimple_assign_lhs (stmt)));
- if (!is_simple_assignment)
+ if (!is_simple_assignment && gimple_code (stmt) != GIMPLE_DEBUG)
only_simple_assignments = false;
}
 }


[gcc/devel/omp/gcc-14] OpenMP: Add uses_allocators support

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:77163463ddb2b2fa7139f112092eb61d9204573d

commit 77163463ddb2b2fa7139f112092eb61d9204573d
Author: Tobias Burnus 
Date:   Wed Apr 24 15:46:22 2024 +0200

OpenMP: Add uses_allocators support

This adds middle end support for uses_allocators, wires Fortran to use it 
and
add C/C++ parsing support.

gcc/ChangeLog:

* builtin-types.def (BT_FN_VOID_PTRMODE):
(BT_FN_PTRMODE_PTRMODE_INT_PTR): Add.
* gimplify.cc (gimplify_bind_expr): Diagnose missing
uses_allocators clause.
(gimplify_scan_omp_clauses, gimplify_adjust_omp_clauses,
gimplify_omp_workshare): Handle uses_allocators.
* omp-builtins.def (BUILT_IN_OMP_INIT_ALLOCATOR,
BUILT_IN_OMP_DESTROY_ALLOCATOR): Add.
* omp-low.cc (scan_sharing_clauses):
* tree-core.h (enum omp_clause_code): Add 
OMP_CLAUSE_USES_ALLOCATORS.
* tree.cc (omp_clause_num_ops, omp_clause_code_name): Likewise.
* tree-pretty-print.cc (dump_omp_clause): Handle it.
* tree.h (OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR,
OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE,
OMP_CLAUSE_USES_ALLOCATORS_TRAITS): New.

gcc/c-family/ChangeLog:

* c-omp.cc (c_omp_split_clauses): Hande uses_allocators.
* c-pragma.h (enum pragma_omp_clause): Add
PRAGMA_OMP_CLAUSE_USES_ALLOCATORS.

gcc/c/ChangeLog:

* c-parser.cc (c_parser_omp_clause_uses_allocators): New.
(c_parser_omp_clause_name, c_parser_omp_all_clauses,
OMP_TARGET_CLAUSE_MASK): Handle uses_allocators.
* c-typeck.cc (c_finish_omp_clauses): Likewise.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_omp_clause_uses_allocators): New.
(cp_parser_omp_clause_name, cp_parser_omp_all_clauses,
OMP_TARGET_CLAUSE_MASK): Handle uses_allocators.
* semantics.cc (finish_omp_clauses): Likewise.

gcc/fortran/ChangeLog:

* trans-array.cc (gfc_conv_array_initializer): Set PURPOSE
when building constructor for get_initialized_tmp_var.
* trans-openmp.cc (gfc_trans_omp_clauses): Handle uses_allocators.
* types.def (BT_FN_VOID_PTRMODE, BT_FN_PTRMODE_PTRMODE_INT_PTR): 
Add.

libgomp/ChangeLog:

* testsuite/libgomp.c++/c++.exp (check_effective_target_c,
check_effective_target_c++): Add.
* testsuite/libgomp.c/c.exp (check_effective_target_c,
check_effective_target_c++): Add.
* testsuite/libgomp.fortran/uses_allocators_2.f90: Remove 'sorry'.
* testsuite/libgomp.c-c++-common/uses_allocators-1.c: New test.
* testsuite/libgomp.c-c++-common/uses_allocators-2.c: New test.
* testsuite/libgomp.c-c++-common/uses_allocators-3.c: New test.
* testsuite/libgomp.c-c++-common/uses_allocators-4.c: New test.
* testsuite/libgomp.fortran/uses_allocators_3.f90: New test.
* testsuite/libgomp.fortran/uses_allocators_4.f90: New test.
* testsuite/libgomp.fortran/uses_allocators_5.f90: New test.
* testsuite/libgomp.fortran/uses_allocators_6.f90: New test.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/allocate-1.f90: Add uses_allocators.
* gfortran.dg/gomp/scope-6.f90: Update dg-scan-tree-dump.
* c-c++-common/gomp/uses_allocators-1.c: New test.
* c-c++-common/gomp/uses_allocators-2.c: New test.
* gfortran.dg/gomp/uses_allocators-1.f90: New test.

Co-authored-by: Chung-Lin Tang 

Diff:
---
 gcc/ChangeLog.omp  |  19 ++
 gcc/builtin-types.def  |   3 +
 gcc/c-family/ChangeLog.omp |  20 ++
 gcc/c-family/c-omp.cc  |   1 +
 gcc/c-family/c-pragma.h|   1 +
 gcc/c/ChangeLog.omp|   8 +
 gcc/c/c-parser.cc  | 216 ++-
 gcc/c/c-typeck.cc  | 105 +
 gcc/cp/ChangeLog.omp   |   8 +
 gcc/cp/parser.cc   | 237 -
 gcc/cp/semantics.cc|  95 +
 gcc/fortran/ChangeLog.omp  |   8 +
 gcc/fortran/trans-array.cc |   9 +-
 gcc/fortran/trans-openmp.cc|  42 +++-
 gcc/fortran/types.def  |   3 +
 gcc/gimplify.cc| 183 +++-
 gcc/omp-builtins.def   |   4 +
 gcc/omp-low.cc |  32 +++
 gcc/testsuite/ChangeLog.omp|   9 +
 .../c-c++-common/gomp/uses_allocators-1.c  |  46 ++

[gcc/devel/omp/gcc-14] vect: WORKAROUND vectorizer bug

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:3eabba8cc53d92d60ae8d3dc008d0c732c43f84f

commit 3eabba8cc53d92d60ae8d3dc008d0c732c43f84f
Author: Andrew Stubbs 
Date:   Fri Oct 21 14:19:31 2022 +0100

vect: WORKAROUND vectorizer bug

This patch disables vectorization of memory accesses to non-default address
spaces where the pointer size is different to the usual pointer size.  This
condition typically occurs in OpenACC programs on amdgcn, where LDS memory 
is
used for broadcasting gang-private variables between threads. In particular,
see libgomp.oacc-c-c++-common/private-variables.c

The problem is that the address space information is dropped from the 
various
types in the middle-end and eventually it triggers an ICE trying to do an
address conversion.  That ICE can be avoided by defining
POINTERS_EXTEND_UNSIGNED, but that just produces wrong RTL code later on.

A correct solution would ensure that all the vectypes have the correct 
address
spaces, but I don't have time for that right now.

gcc/ChangeLog:

* tree-vect-data-refs.cc (vect_analyze_data_refs): Workaround an
address-space bug.

Diff:
---
 gcc/ChangeLog.omp  |  5 +
 gcc/tree-vect-data-refs.cc | 16 +++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index c4b70ba1849..7d04b110b3a 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,8 @@
+2022-10-24  Andrew Stubbs  
+
+   * tree-vect-data-refs.cc (vect_analyze_data_refs): Workaround an
+   address-space bug.
+
 2023-11-19  Tobias Burnus  
Chung-Lin Tang 
 
diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc
index c531079d3bb..7f2b8f0b928 100644
--- a/gcc/tree-vect-data-refs.cc
+++ b/gcc/tree-vect-data-refs.cc
@@ -4929,7 +4929,21 @@ vect_analyze_data_refs (vec_info *vinfo, poly_uint64 
*min_vf, bool *fatal)
   /* Set vectype for STMT.  */
   scalar_type = TREE_TYPE (DR_REF (dr));
   tree vectype = get_vectype_for_scalar_type (vinfo, scalar_type);
-  if (!vectype)
+
+  /* FIXME: If the object is in an address-space in which the pointer size
+is different to the default address space then vectorizing here will
+lead to an ICE down the road because the address space information
+gets lost.  This work-around fixes the problem until we have a proper
+solution.  */
+  tree base_object = DR_REF (dr);
+  tree op = (TREE_CODE (base_object) == COMPONENT_REF
+|| TREE_CODE (base_object) == ARRAY_REF
+? TREE_OPERAND (base_object, 0) : base_object);
+  addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (op));
+  bool addr_space_bug = (!ADDR_SPACE_GENERIC_P (as)
+&& targetm.addr_space.pointer_mode (as) != Pmode);
+
+  if (!vectype || addr_space_bug)
 {
   if (dump_enabled_p ())
 {


[gcc/devel/omp/gcc-14] OpenMP/Fortran: 'target update' with strides + DT components

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:4990ac3c83c0dd6d7c82bc04792bc2ce0c1d811b

commit 4990ac3c83c0dd6d7c82bc04792bc2ce0c1d811b
Author: Tobias Burnus 
Date:   Wed Nov 2 09:06:28 2022 +0100

OpenMP/Fortran: 'target update' with strides + DT components

OpenMP 5.0 permits to use arrays with strides and derived
type components for the list items to the 'from'/'to' clauses
of the 'target update' directive.

Partially committed to mainline as:

6629444170f85  OpenMP/Fortran: 'target update' with DT components

This patch contains the differences to the mainline version.

gcc/fortran/ChangeLog:

* openmp.cc (resolve_omp_clauses): Apply to OpenMP target update.

libgomp/ChangeLog:

* testsuite/libgomp.fortran/target-13.f90: Update test.

Diff:
---
 gcc/fortran/ChangeLog.omp   |  4 
 gcc/fortran/openmp.cc   |  9 +++--
 libgomp/ChangeLog.omp   |  4 
 libgomp/testsuite/libgomp.fortran/target-13.f90 | 13 -
 4 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp
index 0069235d138..542416db912 100644
--- a/gcc/fortran/ChangeLog.omp
+++ b/gcc/fortran/ChangeLog.omp
@@ -1,3 +1,7 @@
+2022-11-02  Tobias Burnus  
+
+   * openmp.cc (resolve_omp_clauses): Apply to OpenMP target update.
+
 2023-11-19  Tobias Burnus  
Chung-Lin Tang 
 
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index f81d158c3f7..ac6c3934a4d 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -8450,8 +8450,11 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses 
*omp_clauses,
   Only raise an error here if we're really sure the
   array isn't contiguous.  An expression such as
   arr(-n:n,-n:n) could be contiguous even if it looks
-  like it may not be.  */
+  like it may not be.
+  And OpenMP's 'target update' permits strides for
+  the to/from clause. */
if (code->op != EXEC_OACC_UPDATE
+   && code->op != EXEC_OMP_TARGET_UPDATE
&& list != OMP_LIST_CACHE
&& list != OMP_LIST_DEPEND
&& !gfc_is_simply_contiguous (n->expr, false, true)
@@ -8511,7 +8514,9 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses 
*omp_clauses,
int i;
gfc_array_ref *ar = &lastslice->u.ar;
for (i = 0; i < ar->dimen; i++)
- if (ar->stride[i] && code->op != EXEC_OACC_UPDATE)
+ if (ar->stride[i]
+ && code->op != EXEC_OACC_UPDATE
+ && code->op != EXEC_OMP_TARGET_UPDATE)
{
  gfc_error ("Stride should not be specified for "
 "array section in %s clause at %L",
diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 6db91098a6f..75c6085eef6 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,7 @@
+2022-11-02  Tobias Burnus  
+
+   * testsuite/libgomp.fortran/target-13.f90: Update test.
+
 2023-11-19  Tobias Burnus  
Chung-Lin Tang 
 
diff --git a/libgomp/testsuite/libgomp.fortran/target-13.f90 
b/libgomp/testsuite/libgomp.fortran/target-13.f90
index 6aacc778449..e6334a5275f 100644
--- a/libgomp/testsuite/libgomp.fortran/target-13.f90
+++ b/libgomp/testsuite/libgomp.fortran/target-13.f90
@@ -76,7 +76,7 @@ var3a = var3
 
 ! ---
 
-!$omp target update from(var1%at(2:3))
+!$omp target update from(var1%at(::2))
 
 if (var1a /= var1) error stop
 if (any (var2a /= var2)) error stop
@@ -134,17 +134,20 @@ var1a%at(2)%a = var1a%at(2)%a * 7
 var1a%at(3)%s = var1a%at(3)%s * (-3)
 
 block
-  integer, volatile :: i1,i2,i3,i4
+  integer, volatile :: i1,i2,i3,i4,i5,i6
   i1 = 1
   i2 = 2
   i3 = 1
-  i4 = 2
-  !$omp target update from(var3(i1:i2)) from(var1%at(i3:i4))
+  i4 = 1
+  i5 = 2
+  i6 = 1
+  !$omp target update from(var3(i1:i2:i3)) from(var1%at(i4:i5:i6))
   i1 = 3
   i2 = 3
   i3 = 1
   i4 = 5
-  !$omp target update from(var1%at(i1)%s) from(var1%at(i2)%a(i3:i4))
+  i5 = 1
+  !$omp target update from(var1%at(i1)%s) from(var1%at(i1)%a(i3:i4:i5))
 end block
 
 if (var1 /= var1) error stop


[gcc/devel/omp/gcc-14] Fortran "declare create"/allocate support for OpenACC: adjust 'libgomp.oacc-fortran/declare-allocata

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:2770ce41615557e595065ce0c5db71e9f3d82b0a

commit 2770ce41615557e595065ce0c5db71e9f3d82b0a
Author: Thomas Schwinge 
Date:   Wed Nov 2 16:49:13 2022 +0100

Fortran "declare create"/allocate support for OpenACC: adjust 
'libgomp.oacc-fortran/declare-allocatable-1*.f90'

libgomp/
* 
testsuite/libgomp.oacc-fortran/declare-allocatable-1-directive.f90:
Adjust.
* testsuite/libgomp.oacc-fortran/declare-allocatable-1-runtime.f90:
Likewise.
* testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90:
Likewise.

Diff:
---
 libgomp/ChangeLog.omp| 9 +
 .../libgomp.oacc-fortran/declare-allocatable-1-directive.f90 | 7 +++
 .../libgomp.oacc-fortran/declare-allocatable-1-runtime.f90   | 7 +++
 libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90 | 5 +
 4 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index d3c2c178353..5cc6e37bbc0 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,12 @@
+2022-11-02  Tobias Burnus  
+
+   * testsuite/libgomp.oacc-fortran/declare-allocatable-1-directive.f90:
+   Adjust.
+   * testsuite/libgomp.oacc-fortran/declare-allocatable-1-runtime.f90:
+   Likewise.
+   * testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90:
+   Likewise.
+
 2022-11-02  Tobias Burnus  
 
* testsuite/libgomp.fortran/target-enter-data-3a.f90: New test.
diff --git 
a/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1-directive.f90 
b/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1-directive.f90
index 759873bad67..bdeabca3eb5 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1-directive.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1-directive.f90
@@ -2,11 +2,10 @@
 
 ! { dg-do run }
 
-!TODO-OpenACC-declare-allocate
-! Missing support for OpenACC "Changes from Version 2.0 to 2.5":
+! We've got support for OpenACC "Changes from Version 2.0 to 2.5":
 ! "The 'declare create' directive with a Fortran 'allocatable' has new 
behavior".
-! Thus, after 'allocate'/before 'deallocate', do
-! '!$acc enter data create'/'!$acc exit data delete' manually.
+! Yet, after 'allocate'/before 'deallocate', do
+! '!$acc enter data create'/'!$acc exit data delete' manually, too.
 
 !TODO { dg-additional-options -fno-inline } for stable results regarding 
OpenACC 'routine'.
 
diff --git 
a/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1-runtime.f90 
b/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1-runtime.f90
index e4cb9c378a3..a3e17c82828 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1-runtime.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1-runtime.f90
@@ -2,11 +2,10 @@
 
 ! { dg-do run }
 
-!TODO-OpenACC-declare-allocate
-! Missing support for OpenACC "Changes from Version 2.0 to 2.5":
+! We've got support for OpenACC "Changes from Version 2.0 to 2.5":
 ! "The 'declare create' directive with a Fortran 'allocatable' has new 
behavior".
-! Thus, after 'allocate'/before 'deallocate', call 'acc_create'/'acc_delete'
-! manually.
+! Yet, after 'allocate'/before 'deallocate', call 'acc_create'/'acc_delete'
+! manually, too.
 
 !TODO { dg-additional-options -fno-inline } for stable results regarding 
OpenACC 'routine'.
 
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90 
b/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90
index 40cfde34aae..7220661b54a 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90
@@ -3,11 +3,8 @@
 ! { dg-do run }
 ! { dg-additional-options "-Wopenacc-parallelism" }
 
-!TODO-OpenACC-declare-allocate
-! Not currently implementing correct '-DACC_MEM_SHARED=0' behavior:
-! Missing support for OpenACC "Changes from Version 2.0 to 2.5":
+! We've got support for OpenACC "Changes from Version 2.0 to 2.5":
 ! "The 'declare create' directive with a Fortran 'allocatable' has new 
behavior".
-! { dg-xfail-run-if TODO { *-*-* } { -DACC_MEM_SHARED=0 } }
 
 !TODO { dg-additional-options -fno-inline } for stable results regarding 
OpenACC 'routine'.


[gcc/devel/omp/gcc-14] Fortran/OpenMP: Fix DT struct-component with 'alloc' and array descr

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:06a430ade09674aebfbf865328a528411d901573

commit 06a430ade09674aebfbf865328a528411d901573
Author: Tobias Burnus 
Date:   Wed Nov 2 17:04:53 2022 +0100

Fortran/OpenMP: Fix DT struct-component with 'alloc' and array descr

When using 'map(alloc: var, dt%comp)' needs to have a 'to' mapping of
the array descriptor as otherwise the bounds are not available in the
target region. - Likewise for character strings.

This patch implements this; however, some additional issues are exposed
by the testcase; those are '#if 0'ed and will be handled later.

Submitted to mainline (but pending review):
https://gcc.gnu.org/pipermail/gcc-patches/2022-November/604887.html

gcc/fortran/ChangeLog:

* trans-openmp.cc (gfc_trans_omp_clauses): Ensure DT struct-comp 
with
array descriptor and 'alloc:' have the descriptor mapped with 'to:'.

libgomp/ChangeLog:

* testsuite/libgomp.fortran/target-enter-data-3a.f90: New test.

Diff:
---
 gcc/fortran/ChangeLog.omp  |   5 +
 libgomp/ChangeLog.omp  |   4 +
 .../libgomp.fortran/target-enter-data-3a.f90   | 567 +
 3 files changed, 576 insertions(+)

diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp
index 542416db912..4f1e80a42b2 100644
--- a/gcc/fortran/ChangeLog.omp
+++ b/gcc/fortran/ChangeLog.omp
@@ -1,3 +1,8 @@
+2022-11-02  Tobias Burnus  
+
+   * trans-openmp.cc (gfc_trans_omp_clauses): Ensure DT struct-comp with
+   array descriptor and 'alloc:' have the descriptor mapped with 'to:'.
+
 2022-11-02  Tobias Burnus  
 
* openmp.cc (resolve_omp_clauses): Apply to OpenMP target update.
diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 75c6085eef6..d3c2c178353 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,7 @@
+2022-11-02  Tobias Burnus  
+
+   * testsuite/libgomp.fortran/target-enter-data-3a.f90: New test.
+
 2022-11-02  Tobias Burnus  
 
* testsuite/libgomp.fortran/target-13.f90: Update test.
diff --git a/libgomp/testsuite/libgomp.fortran/target-enter-data-3a.f90 
b/libgomp/testsuite/libgomp.fortran/target-enter-data-3a.f90
new file mode 100644
index 000..1fe3f03c7b8
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/target-enter-data-3a.f90
@@ -0,0 +1,567 @@
+! { dg-additional-options "-cpp" }
+
+! FIXME: Some tests do not work yet. Those are for now in '#if 0'
+
+! Check that 'map(alloc:' properly works with
+! - deferred-length character strings
+! - arrays with array descriptors
+! For those, the array descriptor / string length must be mapped with 'to:'
+
+program main
+implicit none
+
+type t
+  integer :: ic(2:5), ic2
+  character(len=11) :: ccstr(3:4), ccstr2
+  character(len=11,kind=4) :: cc4str(3:7), cc4str2
+  integer, pointer :: pc(:), pc2
+  character(len=:), pointer :: pcstr(:), pcstr2
+  character(len=:,kind=4), pointer :: pc4str(:), pc4str2
+end type t
+
+type(t) :: dt
+
+integer :: ii(5), ii2
+character(len=11) :: clstr(-1:1), clstr2
+character(len=11,kind=4) :: cl4str(0:3), cl4str2
+integer, pointer :: ip(:), ip2
+integer, allocatable :: ia(:), ia2
+character(len=:), pointer :: pstr(:), pstr2
+character(len=:), allocatable :: astr(:), astr2
+character(len=:,kind=4), pointer :: p4str(:), p4str2
+character(len=:,kind=4), allocatable :: a4str(:), a4str2
+
+
+allocate(dt%pc(5), dt%pc2)
+allocate(character(len=2) :: dt%pcstr(2))
+allocate(character(len=4) :: dt%pcstr2)
+
+allocate(character(len=3,kind=4) :: dt%pc4str(2:3))
+allocate(character(len=5,kind=4) :: dt%pc4str2)
+
+allocate(ip(5), ip2, ia(8), ia2)
+allocate(character(len=2) :: pstr(-2:0))
+allocate(character(len=4) :: pstr2)
+allocate(character(len=6) :: astr(3:5))
+allocate(character(len=8) :: astr2)
+
+allocate(character(len=3,kind=4) :: p4str(2:4))
+allocate(character(len=5,kind=4) :: p4str2)
+allocate(character(len=7,kind=4) :: a4str(-2:3))
+allocate(character(len=9,kind=4) :: a4str2)
+
+
+! integer :: ic(2:5), ic2
+
+!$omp target enter data map(alloc: dt%ic)
+!$omp target map(alloc: dt%ic)
+  if (size(dt%ic) /= 4) error stop
+  if (lbound(dt%ic, 1) /= 2) error stop
+  if (ubound(dt%ic, 1) /= 5) error stop
+  dt%ic = [22, 33, 44, 55]
+!$omp end target
+!$omp target exit data map(from: dt%ic)
+if (size(dt%ic) /= 4) error stop
+if (lbound(dt%ic, 1) /= 2) error stop
+if (ubound(dt%ic, 1) /= 5) error stop
+if (any (dt%ic /= [22, 33, 44, 55])) error stop
+
+!$omp target enter data map(alloc: dt%ic2)
+!$omp target map(alloc: dt%ic2)
+  dt%ic2 = 42
+!$omp end target
+!$omp target exit data map(from: dt%ic2)
+if (dt%ic2 /= 42) error stop
+
+
+! character(len=11) :: ccstr(3:4), ccstr2
+
+!$omp target enter data map(alloc: dt%ccstr)
+!$omp target map(alloc: dt%ccstr)
+  if (len(dt%ccstr) /= 11) error stop
+  if (size(dt%ccstr) /= 2) error stop
+  if (lbound(dt%ccstr, 1) /= 3) error stop
+  if (ubound(dt%ccstr, 1) /= 4) error st

[gcc/devel/omp/gcc-14] Fortran "declare create"/allocate support for OpenACC: adjust 'libgomp.oacc-fortran/declare-allocata

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:a29e58f4b314862a72730119f85e9125879abf0b

commit a29e58f4b314862a72730119f85e9125879abf0b
Author: Thomas Schwinge 
Date:   Wed Nov 2 16:50:33 2022 +0100

Fortran "declare create"/allocate support for OpenACC: adjust 
'libgomp.oacc-fortran/declare-allocatable-array_descriptor-1*.f90'

libgomp/
* 
testsuite/libgomp.oacc-fortran/declare-allocatable-array_descriptor-1-directive.f90:
Adjust.
* 
testsuite/libgomp.oacc-fortran/declare-allocatable-array_descriptor-1-runtime.f90:
Likewise.
* 
testsuite/libgomp.oacc-fortran/declare-allocatable-array_descriptor-1.f90:
New.

Diff:
---
 libgomp/ChangeLog.omp  |   7 +
 ...re-allocatable-array_descriptor-1-directive.f90 |  41 +--
 ...lare-allocatable-array_descriptor-1-runtime.f90 | 107 --
 .../declare-allocatable-array_descriptor-1.f90 | 405 +
 4 files changed, 499 insertions(+), 61 deletions(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 5cc6e37bbc0..663f004ed7f 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,5 +1,12 @@
 2022-11-02  Tobias Burnus  
 
+   * 
testsuite/libgomp.oacc-fortran/declare-allocatable-array_descriptor-1-directive.f90:
+   Adjust.
+   * 
testsuite/libgomp.oacc-fortran/declare-allocatable-array_descriptor-1-runtime.f90:
+   Likewise.
+   * 
testsuite/libgomp.oacc-fortran/declare-allocatable-array_descriptor-1.f90:
+   New.
+
* testsuite/libgomp.oacc-fortran/declare-allocatable-1-directive.f90:
Adjust.
* testsuite/libgomp.oacc-fortran/declare-allocatable-1-runtime.f90:
diff --git 
a/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-array_descriptor-1-directive.f90
 
b/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-array_descriptor-1-directive.f90
index 6604f72c5c1..0f4d21a138b 100644
--- 
a/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-array_descriptor-1-directive.f90
+++ 
b/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-array_descriptor-1-directive.f90
@@ -7,11 +7,10 @@
 ! host/device array descriptors.
 ! { dg-skip-if n/a { *-*-* } { -DACC_MEM_SHARED=1 } }
 
-!TODO-OpenACC-declare-allocate
-! Missing support for OpenACC "Changes from Version 2.0 to 2.5":
+! We've got support for OpenACC "Changes from Version 2.0 to 2.5":
 ! "The 'declare create' directive with a Fortran 'allocatable' has new 
behavior".
-! Thus, after 'allocate'/before 'deallocate', do
-! '!$acc enter data create'/'!$acc exit data delete' manually.
+! Yet, after 'allocate'/before 'deallocate', do
+! '!$acc enter data create'/'!$acc exit data delete' manually, too.
 
 
 !TODO { dg-additional-options -fno-inline } for stable results regarding 
OpenACC 'routine'.
@@ -101,8 +100,6 @@ program test
 
   allocate (b(n1_lb:n1_ub))
   call verify_n1_allocated
-  if (acc_is_present (b)) error stop
-  !$acc enter data create (b)
   ! This is now OpenACC "present":
   if (.not.acc_is_present (b)) error stop
   ! ..., and got the actual array descriptor installed:
@@ -110,15 +107,16 @@ program test
   call verify_n1_allocated
   !$acc end serial
 
+  !$acc enter data create (b)
+  if (.not.acc_is_present (b)) error stop
+  !$acc serial
+  call verify_n1_allocated
+  !$acc end serial
+
   do i = n1_lb, n1_ub
  b(i) = i - 1
   end do
 
-  ! In 'declare-allocatable-array_descriptor-1-runtime.f90', this does "verify
-  ! that host-to-device copy doesn't touch the device-side (still initial)
-  ! array descriptor (but it does copy the array data").  This is here not
-  ! applicable anymore, as we've already gotten the actual array descriptor
-  ! installed.  Thus now verify that it does copy the array data.
   call acc_update_device (b)
   !$acc serial
   call verify_n1_allocated
@@ -143,12 +141,6 @@ program test
   !TODO 'GOMP_MAP_TO_PSET':
   ! { dg-final { scan-tree-dump-times {(?n)^ *#pragma omp target oacc_parallel 
map\(tofrom:MEM  \[\(integer\(kind=[0-9]+\)\[0:\] 
\*\)[^\]]+\] \[len: [^\]]+\]\) map\(alloc:b\.data \[pointer assign, bias: 0\]\) 
map\(from:id1_2 \[len: [0-9]+\]\)$} 1 gimple } }
 
-  ! In 'declare-allocatable-array_descriptor-1-runtime.f90', this does "verify
-  ! that device-to-host copy doesn't touch the host-side array descriptor,
-  ! doesn't copy out the device-side (still initial) array descriptor (but it
-  ! does copy the array data)".  This is here not applicable anymore, as we've
-  ! already gotten the actual array descriptor installed.  Thus now verify that
-  ! it does copy the array data.
   call acc_update_self (b)
   call verify_n1_allocated
 
@@ -223,14 +215,13 @@ program test
 
   !$acc exit data delete (b)
   if (.not.allocated (b)) error stop
-  if (acc_is_present (b)) error stop
-  ! The device-side array descriptor doesn't get updated, so 'b' still appears
-  ! as "allocated":
+  if (.not.acc_is_present (b)) error stop
   !$acc serial
   call verify_n1

[gcc/devel/omp/gcc-14] amdgcn: Support AMD-specific 'isa' and 'arch' traits in OpenMP context selectors

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:5e56c3791448a93320388dc18d464ca283f92c65

commit 5e56c3791448a93320388dc18d464ca283f92c65
Author: Paul-Antoine Arras 
Date:   Wed Nov 30 14:52:55 2022 +0100

amdgcn: Support AMD-specific 'isa' and 'arch' traits in OpenMP context 
selectors

Add libgomp support for 'amdgcn' as arch, and for each processor type (as 
passed
to '-march') as isa traits.
Add test case for all supported 'isa' values used as context selectors in a
metadirective construct.

libgomp/ChangeLog:

* config/gcn/selector.c (GOMP_evaluate_current_device): Recognise 
'amdgcn'
as arch, and '-march' values (as well as 'gfx803') as isa traits.
* testsuite/libgomp.c-c++-common/metadirective-6.c: New test.

Diff:
---
 libgomp/ChangeLog.omp  |  6 +++
 .../libgomp.c-c++-common/metadirective-6.c | 48 ++
 2 files changed, 54 insertions(+)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 663f004ed7f..4947ef676bb 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,9 @@
+2022-12-06  Paul-Antoine Arras 
+
+   * config/gcn/selector.c (GOMP_evaluate_current_device): Recognise 
'amdgcn'
+   as arch, and '-march' values (as well as 'gfx803') as isa traits.
+   * testsuite/libgomp.c-c++-common/metadirective-6.c: New test.
+
 2022-11-02  Tobias Burnus  
 
* 
testsuite/libgomp.oacc-fortran/declare-allocatable-array_descriptor-1-directive.f90:
diff --git a/libgomp/testsuite/libgomp.c-c++-common/metadirective-6.c 
b/libgomp/testsuite/libgomp.c-c++-common/metadirective-6.c
new file mode 100644
index 000..b3aa57be313
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c-c++-common/metadirective-6.c
@@ -0,0 +1,48 @@
+/* { dg-do link { target { offload_target_amdgcn } } } */
+/* { dg-additional-options "-foffload=-fdump-tree-ompdevlow" } */
+
+#define N 100
+
+void f (int x[], int y[], int z[])
+{
+  int i;
+
+  #pragma omp target map(to: x, y) map(from: z)
+#pragma omp metadirective \
+  when (device={isa("gfx803")}: teams num_teams(512)) \
+  when (device={isa("gfx900")}: teams num_teams(256)) \
+  when (device={isa("gfx906")}: teams num_teams(128)) \
+  when (device={isa("gfx908")}: teams num_teams(64)) \
+  when (device={isa("gfx90a")}: teams num_teams(32)) \
+  default (teams num_teams(4))
+   for (i = 0; i < N; i++)
+ z[i] = x[i] * y[i];
+}
+
+int main (void)
+{
+  int x[N], y[N], z[N];
+  int i;
+
+  for (i = 0; i < N; i++)
+{
+  x[i] = i;
+  y[i] = -i;
+}
+
+  f (x, y, z);
+
+  for (i = 0; i < N; i++)
+if (z[i] != x[i] * y[i])
+  return 1;
+
+  return 0;
+}
+
+/* The metadirective should be resolved after Gimplification.  */
+
+/* { dg-final { scan-offload-tree-dump "__builtin_GOMP_teams4 \\(512, 512" 
"ompdevlow" { target { any-opts "-foffload=-march=fiji" } } } } */
+/* { dg-final { scan-offload-tree-dump "__builtin_GOMP_teams4 \\(256, 256" 
"ompdevlow" { target { any-opts "-foffload=-march=gfx900" } } } } */
+/* { dg-final { scan-offload-tree-dump "__builtin_GOMP_teams4 \\(128, 128" 
"ompdevlow" { target { any-opts "-foffload=-march=gfx906" } } } } */
+/* { dg-final { scan-offload-tree-dump "__builtin_GOMP_teams4 \\(64, 64" 
"ompdevlow" { target { any-opts "-foffload=-march=gfx908" } } } } */
+/* { dg-final { scan-offload-tree-dump "__builtin_GOMP_teams4 \\(32, 32" 
"ompdevlow" { target { any-opts "-foffload=-march=gfx90a" } } } } */


[gcc/devel/omp/gcc-14] nvptx target: Global constructor, destructor support, via nvptx-tools 'ld'

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:3b95ca26fe581997662b83009a8980cd43b13f41

commit 3b95ca26fe581997662b83009a8980cd43b13f41
Author: Thomas Schwinge 
Date:   Tue May 28 23:20:29 2024 +0200

nvptx target: Global constructor, destructor support, via nvptx-tools 'ld'

The function attributes 'constructor', 'destructor', and 'init_priority' now
work, as do the C++ features making use of this.  Test cases with effective
target 'global_constructor' and 'init_priority' now generally work, and
'check-gcc-c++' test results greatly improve; no more
"sorry, unimplemented: global constructors not supported on this target".

For proper execution test results, this depends on


"ld: Global constructor/destructor support".

gcc/
* config/nvptx/nvptx.h: Configure global constructor, destructor
support.
gcc/testsuite/
* gcc.dg/no_profile_instrument_function-attr-1.c: GCC/nvptx is
'NO_DOT_IN_LABEL' but not 'NO_DOLLAR_IN_LABEL', so '$' may apper
in identifiers.
* lib/target-supports.exp
(check_effective_target_global_constructor): Enable for nvptx.
libgcc/
* config/nvptx/crt0.c (__gbl_ctors): New weak function.
(__main): Invoke it.
* config/nvptx/gbl-ctors.c: New.
* config/nvptx/t-nvptx: Configure global constructor, destructor
support.

(cherry picked from commit d9c90c82d900fdae95df4499bf5f0a4ecb903b53)

Diff:
---
 gcc/ChangeLog.omp  | 17 +
 gcc/config/nvptx/nvptx.h   | 14 +++-
 .../gcc.dg/no_profile_instrument_function-attr-1.c |  2 +-
 gcc/testsuite/lib/target-supports.exp  |  3 +-
 libgcc/config/nvptx/crt0.c | 12 
 libgcc/config/nvptx/gbl-ctors.c| 74 ++
 libgcc/config/nvptx/t-nvptx|  9 ++-
 7 files changed, 126 insertions(+), 5 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 7d04b110b3a..b80e90cb32a 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,20 @@
+2024-05-28  Thomas Schwinge  
+
+   * config/nvptx/nvptx.h: Configure global constructor, destructor
+   support.
+   gcc/testsuite/
+   * gcc.dg/no_profile_instrument_function-attr-1.c: GCC/nvptx is
+   'NO_DOT_IN_LABEL' but not 'NO_DOLLAR_IN_LABEL', so '$' may apper
+   in identifiers.
+   * lib/target-supports.exp
+   (check_effective_target_global_constructor): Enable for nvptx.
+   libgcc/
+   * config/nvptx/crt0.c (__gbl_ctors): New weak function.
+   (__main): Invoke it.
+   * config/nvptx/gbl-ctors.c: New.
+   * config/nvptx/t-nvptx: Configure global constructor, destructor
+   support.
+
 2022-10-24  Andrew Stubbs  
 
* tree-vect-data-refs.cc (vect_analyze_data_refs): Workaround an
diff --git a/gcc/config/nvptx/nvptx.h b/gcc/config/nvptx/nvptx.h
index e282aad1b73..74f4a68924c 100644
--- a/gcc/config/nvptx/nvptx.h
+++ b/gcc/config/nvptx/nvptx.h
@@ -356,7 +356,19 @@ struct GTY(()) machine_function
 #define MOVE_MAX 8
 #define MOVE_RATIO(SPEED) 4
 #define FUNCTION_MODE QImode
-#define HAS_INIT_SECTION 1
+
+/* Implement global constructor, destructor support in a conceptually simpler
+   way than using 'collect2' (the program): implement the respective
+   functionality in the nvptx-tools 'ld'.  This however still requires the
+   compiler-side effects corresponding to 'USE_COLLECT2': the global
+   constructor, destructor support functions need to have external linkage, and
+   therefore names that are "unique across the whole link".  Use
+   '!targetm.have_ctors_dtors' to achieve this (..., and thus don't need to
+   provide 'targetm.asm_out.constructor', 'targetm.asm_out.destructor').  */
+#define TARGET_HAVE_CTORS_DTORS false
+
+/* See 'libgcc/config/nvptx/crt0.c' for wrapping of 'main'.  */
+#define HAS_INIT_SECTION
 
 /* The C++ front end insists to link against libstdc++ -- which we don't build.
Tell it to instead link against the innocuous libgcc.  */
diff --git a/gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c 
b/gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c
index 909f8a68479..5b4101cf596 100644
--- a/gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c
+++ b/gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c
@@ -18,7 +18,7 @@ int main ()
   return foo ();
 }
 
-/* { dg-final { scan-tree-dump-times "__gcov0\[._\]main.* = PROF_edge_counter" 
1 "optimized"} } */
+/* { dg-final { scan-tree-dump-times "__gcov0\[$._\]main.* = 
PROF_edge_counter" 1 "optimized"} } */
 /* { dg-final { scan-tree-dump-times "__gcov_indirect_call_profiler_v" 1 
"optimized" } } */
 /* { dg-final { scan-tree-dump-times "__gcov_time_profiler_counter = " 1 
"optimi

[gcc/devel/omp/gcc-14] Clean up after newlib "nvptx: In offloading execution, map '_exit' to 'abort' [GCC PR85463]"

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:2ebccb5c0ad3347c15aa6cfca2d85cd09b6b5d9b

commit 2ebccb5c0ad3347c15aa6cfca2d85cd09b6b5d9b
Author: Thomas Schwinge 
Date:   Wed Jun 5 14:34:06 2024 +0200

Clean up after newlib "nvptx: In offloading execution, map '_exit' to 
'abort' [GCC PR85463]"

PR target/85463
libgfortran/
* runtime/minimal.c [__nvptx__] (exit): Don't override.
libgomp/
* config/nvptx/error.c (exit): Don't override.
* testsuite/libgomp.oacc-fortran/error_stop-1.f: Update.
* testsuite/libgomp.oacc-fortran/error_stop-2.f: Likewise.
* testsuite/libgomp.oacc-fortran/error_stop-3.f: Likewise.
* testsuite/libgomp.oacc-fortran/stop-1.f: Likewise.
* testsuite/libgomp.oacc-fortran/stop-2.f: Likewise.
* testsuite/libgomp.oacc-fortran/stop-3.f: Likewise.

(cherry picked from commit 395ac0417a17ba6405873f891f895417d696b603)

Diff:
---
 libgfortran/ChangeLog.omp |  3 +++
 libgfortran/runtime/minimal.c |  8 
 libgomp/ChangeLog.omp | 10 ++
 libgomp/config/nvptx/error.c  |  7 ---
 libgomp/testsuite/libgomp.oacc-fortran/error_stop-1.f |  8 +---
 libgomp/testsuite/libgomp.oacc-fortran/error_stop-2.f |  8 +---
 libgomp/testsuite/libgomp.oacc-fortran/error_stop-3.f |  8 +---
 libgomp/testsuite/libgomp.oacc-fortran/stop-1.f   | 13 +
 libgomp/testsuite/libgomp.oacc-fortran/stop-2.f   |  6 +-
 libgomp/testsuite/libgomp.oacc-fortran/stop-3.f   | 12 
 10 files changed, 50 insertions(+), 33 deletions(-)

diff --git a/libgfortran/ChangeLog.omp b/libgfortran/ChangeLog.omp
new file mode 100644
index 000..e4955f75d44
--- /dev/null
+++ b/libgfortran/ChangeLog.omp
@@ -0,0 +1,3 @@
+2024-06-05  Thomas Schwinge  
+
+   * runtime/minimal.c [__nvptx__] (exit): Don't override.
diff --git a/libgfortran/runtime/minimal.c b/libgfortran/runtime/minimal.c
index f13b3a4bf90..619f818c844 100644
--- a/libgfortran/runtime/minimal.c
+++ b/libgfortran/runtime/minimal.c
@@ -31,14 +31,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
 #endif
 
 
-#if __nvptx__
-/* Map "exit" to "abort"; see PR85463 '[nvptx] "exit" in offloaded region
-   doesn't terminate process'.  */
-# undef exit
-# define exit(status) do { (void) (status); abort (); } while (0)
-#endif
-
-
 #if __nvptx__
 /* 'printf' is all we have.  */
 # undef estr_vprintf
diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 4947ef676bb..2bffd33f0e3 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,13 @@
+2024-06-05  Thomas Schwinge  
+
+   * config/nvptx/error.c (exit): Don't override.
+   * testsuite/libgomp.oacc-fortran/error_stop-1.f: Update.
+   * testsuite/libgomp.oacc-fortran/error_stop-2.f: Likewise.
+   * testsuite/libgomp.oacc-fortran/error_stop-3.f: Likewise.
+   * testsuite/libgomp.oacc-fortran/stop-1.f: Likewise.
+   * testsuite/libgomp.oacc-fortran/stop-2.f: Likewise.
+   * testsuite/libgomp.oacc-fortran/stop-3.f: Likewise.
+
 2022-12-06  Paul-Antoine Arras 
 
* config/gcn/selector.c (GOMP_evaluate_current_device): Recognise 
'amdgcn'
diff --git a/libgomp/config/nvptx/error.c b/libgomp/config/nvptx/error.c
index 7e668276004..f7a2536c29b 100644
--- a/libgomp/config/nvptx/error.c
+++ b/libgomp/config/nvptx/error.c
@@ -58,11 +58,4 @@
 #endif
 
 
-/* The 'exit (EXIT_FAILURE);' of an Fortran (only, huh?) OpenMP 'error'
-   directive with 'severity (fatal)' causes a hang, so 'abort' instead of
-   'exit'.  */
-#undef exit
-#define exit(status) abort ()
-
-
 #include "../../error.c"
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/error_stop-1.f 
b/libgomp/testsuite/libgomp.oacc-fortran/error_stop-1.f
index de727749a53..3918d6853f6 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/error_stop-1.f
+++ b/libgomp/testsuite/libgomp.oacc-fortran/error_stop-1.f
@@ -16,14 +16,16 @@
   END PROGRAM MAIN
 
 ! { dg-output "CheCKpOInT(\n|\r\n|\r)+" }
+
 ! { dg-output "ERROR STOP (\n|\r\n|\r)+" }
 !
 ! In gfortran's main program, libfortran's set_options is called - which sets
 ! compiler_options.backtrace = 1 by default.  For an offload libgfortran, this
 ! is never called and, hence, "Error termination." is never printed.  Thus:
 ! { dg-output "Error termination.*" { target { ! { 
openacc_nvidia_accel_selected || openacc_radeon_accel_selected } } } }
-!
-! PR85463:
+
+! PR85463.  The 'exit' implementation used with nvptx
+! offloading is a little bit different.
 ! { dg-output "libgomp: cuStreamSynchronize error.*" { target 
openacc_nvidia_accel_selected } }
-!
+
 ! { dg-shouldfail "" }
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/error_stop-2.f 
b/libgomp/testsuite/libgomp.oacc-fortran/error_stop-2.f
index 475c9cb5850..5951e8cbe64 100644
--- a/libgomp/testsuite/libgom

[gcc/devel/omp/gcc-14] nvptx: Make 'nvptx_uniform_warp_check' fit for non-full-warp execution, via 'vote.all.pred'

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:a4fd191a5bc44904409e05ad6dc702fb478c1484

commit a4fd191a5bc44904409e05ad6dc702fb478c1484
Author: Thomas Schwinge 
Date:   Fri May 10 12:50:23 2024 +0200

nvptx: Make 'nvptx_uniform_warp_check' fit for non-full-warp execution, via 
'vote.all.pred'

For example, this allows for '-muniform-simt' code to be executed
single-threaded, which currently fails (device-side 'trap'): the 
'0x'
bitmask isn't correct if not all 32 threads of a warp are active.  The same
issue/fix, I suppose but have not verified, would apply if we were to allow 
for
OpenACC 'vector_length' smaller than 32, for example for OpenACC 'serial'.

We use 'nvptx_uniform_warp_check' only for PTX ISA version less than 6.0.
Otherwise we're using 'nvptx_warpsync', which emits 'bar.warp.sync 
0x',
which evidently appears to do the right thing.  (I've tested 
'-muniform-simt'
code executing single-threaded.)

The change that I proposed on 2022-12-15 was to emit PTX code to calculate
'(1 << %ntid.x) - 1' as the actual bitmask to use instead of '0x'.
This works, but the PTX JIT generates SASS code to do this computation.

In turn, this change now uses PTX 'vote.all.pred' -- which even simplifies 
upon
the original code a little bit, see the following examplary SASS 'diff' 
before
vs. after this change:

[...]
  /*[...]*/   SYNC  
  (*"BRANCH_TARGETS .L_x_332"*)}
  .L_x_332:
- /*[...]*/   VOTE.ANY R9, PT, PT ;
+ /*[...]*/   VOTE.ALL P1, PT ;
- /*[...]*/   ISETP.NE.U32.AND P1, PT, R9, 
-0x1, PT ;
- /*[...]*/  @!P1 BRA `(.L_x_333) ;
+ /*[...]*/   @P1 BRA `(.L_x_333) ;
  /*[...]*/   BPT.TRAP 0x1 ;
  .L_x_333:
- /*[...]*/   @P1 EXIT ;
+ /*[...]*/  @!P1 EXIT ;
[...]

gcc/
* config/nvptx/nvptx.md (nvptx_uniform_warp_check): Make fit for
non-full-warp execution, via 'vote.all.pred'.
gcc/testsuite/
* gcc.target/nvptx/nvptx.exp
(check_effective_target_default_ptx_isa_version_at_least_6_0):
New.
* gcc.target/nvptx/uniform-simt-2.c: Adjust.
* gcc.target/nvptx/uniform-simt-5.c: New.

(cherry picked from commit b4e68dd9084e48ee3e83c11d7f27548d8cca7066)

Diff:
---
 gcc/ChangeLog.omp   | 11 ++
 gcc/config/nvptx/nvptx.md   | 13 +---
 gcc/testsuite/gcc.target/nvptx/nvptx.exp|  5 +
 gcc/testsuite/gcc.target/nvptx/uniform-simt-2.c |  2 +-
 gcc/testsuite/gcc.target/nvptx/uniform-simt-5.c | 28 +
 5 files changed, 50 insertions(+), 9 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index b80e90cb32a..66d27e6ab7c 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,14 @@
+2024-05-10  Thomas Schwinge  
+
+   * config/nvptx/nvptx.md (nvptx_uniform_warp_check): Make fit for
+   non-full-warp execution, via 'vote.all.pred'.
+   gcc/testsuite/
+   * gcc.target/nvptx/nvptx.exp
+   (check_effective_target_default_ptx_isa_version_at_least_6_0):
+   New.
+   * gcc.target/nvptx/uniform-simt-2.c: Adjust.
+   * gcc.target/nvptx/uniform-simt-5.c: New.
+
 2024-05-28  Thomas Schwinge  
 
* config/nvptx/nvptx.h: Configure global constructor, destructor
diff --git a/gcc/config/nvptx/nvptx.md b/gcc/config/nvptx/nvptx.md
index 4118de52a9a..4c32a20176a 100644
--- a/gcc/config/nvptx/nvptx.md
+++ b/gcc/config/nvptx/nvptx.md
@@ -2316,14 +2316,11 @@
   {
 const char *insns[] = {
   "{",
-  "\\t"  ".reg.b32""\\t" "%%r_act;",
-  "%.\\t""vote.ballot.b32" "\\t" "%%r_act,1;",
-  "\\t"  ".reg.pred"   "\\t" "%%r_do_abort;",
-  "\\t"  "mov.pred""\\t" "%%r_do_abort,0;",
-  "%.\\t""setp.ne.b32" "\\t" "%%r_do_abort,%%r_act,"
- "0x;",
-  "@ %%r_do_abort\\t" "trap;",
-  "@ %%r_do_abort\\t" "exit;",
+  "\\t"".reg.pred" "\\t" "%%r_sync;",
+  "\\t""mov.pred"  "\\t" "%%r_sync, 1;",
+  "%.\\t"  "vote.all.pred" "\\t" "%%r_sync, 1;",
+  "@!%%r_sync\\t"  "trap;",
+  "@!%%r_sync\\t"  "exit;",
   "}",
   NULL
 };
diff --git a/gcc/testsuite/gcc.target/nvptx/nvptx.exp 
b/gcc/testsuite/gcc.target/nvptx/nvptx.exp
index 97aa7ae0852..3151381f51a 100644
--- a/gcc/testsuite/gcc.target/nvptx/nvptx.exp
+++ b/gcc/testsuite/gcc.target/nvptx/nvptx.exp
@@ -49,6 +49,11 @@ proc check_effective_target_default_ptx_isa_version_a

[gcc/devel/omp/gcc-14] nvptx offloading: Global constructor, destructor support, via nvptx-tools 'ld'

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:c3967d1faf17d3eba7e78530c13ec5dc63e0beca

commit c3967d1faf17d3eba7e78530c13ec5dc63e0beca
Author: Thomas Schwinge 
Date:   Wed Jun 5 12:40:50 2024 +0200

nvptx offloading: Global constructor, destructor support, via nvptx-tools 
'ld'

This extends commit d9c90c82d900fdae95df4499bf5f0a4ecb903b53
"nvptx target: Global constructor, destructor support, via nvptx-tools 'ld'"
for offloading.

libgcc/
* config/nvptx/gbl-ctors.c ["mgomp"]
(__do_global_ctors__entry__mgomp)
(__do_global_dtors__entry__mgomp): New.
[!"mgomp"] (__do_global_ctors__entry, __do_global_dtors__entry):
New.
libgomp/
* plugin/plugin-nvptx.c (nvptx_do_global_cdtors): New.
(nvptx_close_device, GOMP_OFFLOAD_load_image)
(GOMP_OFFLOAD_unload_image): Call it.

(cherry picked from commit 5bbe5350a0932c78d4ffce292ba4104a6fe6ef96)

Diff:
---
 libgcc/ChangeLog.omp|   7 +++
 libgcc/config/nvptx/gbl-ctors.c |  55 +++
 libgomp/ChangeLog.omp   |   6 +++
 libgomp/plugin/plugin-nvptx.c   | 117 +++-
 4 files changed, 184 insertions(+), 1 deletion(-)

diff --git a/libgcc/ChangeLog.omp b/libgcc/ChangeLog.omp
new file mode 100644
index 000..7294ca9aace
--- /dev/null
+++ b/libgcc/ChangeLog.omp
@@ -0,0 +1,7 @@
+2024-06-05  Thomas Schwinge  
+
+   * config/nvptx/gbl-ctors.c ["mgomp"]
+   (__do_global_ctors__entry__mgomp)
+   (__do_global_dtors__entry__mgomp): New.
+   [!"mgomp"] (__do_global_ctors__entry, __do_global_dtors__entry):
+   New.
diff --git a/libgcc/config/nvptx/gbl-ctors.c b/libgcc/config/nvptx/gbl-ctors.c
index a2ca053e5e3..a56d64f8ef8 100644
--- a/libgcc/config/nvptx/gbl-ctors.c
+++ b/libgcc/config/nvptx/gbl-ctors.c
@@ -68,6 +68,61 @@ __gbl_ctors (void)
 }
 
 
+/* For nvptx offloading configurations, need '.entry' wrappers.  */
+
+# if defined(__nvptx_softstack__) && defined(__nvptx_unisimt__)
+
+/* OpenMP */
+
+/* See 'crt0.c', 'mgomp.c'.  */
+extern void *__nvptx_stacks[32] __attribute__((shared,nocommon));
+extern unsigned __nvptx_uni[32] __attribute__((shared,nocommon));
+
+__attribute__((kernel)) void __do_global_ctors__entry__mgomp (void *);
+
+void
+__do_global_ctors__entry__mgomp (void *nvptx_stacks_0)
+{
+  __nvptx_stacks[0] = nvptx_stacks_0;
+  __nvptx_uni[0] = 0;
+
+  __static_do_global_ctors ();
+}
+
+__attribute__((kernel)) void __do_global_dtors__entry__mgomp (void *);
+
+void
+__do_global_dtors__entry__mgomp (void *nvptx_stacks_0)
+{
+  __nvptx_stacks[0] = nvptx_stacks_0;
+  __nvptx_uni[0] = 0;
+
+  __static_do_global_dtors ();
+}
+
+# else
+
+/* OpenACC */
+
+__attribute__((kernel)) void __do_global_ctors__entry (void);
+
+void
+__do_global_ctors__entry (void)
+{
+  __static_do_global_ctors ();
+}
+
+__attribute__((kernel)) void __do_global_dtors__entry (void);
+
+void
+__do_global_dtors__entry (void)
+{
+  __static_do_global_dtors ();
+}
+
+# endif
+
+
 /* The following symbol just provides a means for the nvptx-tools 'ld' to
trigger linking in this file.  */
 
diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 2bffd33f0e3..b1c3ec684fd 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,9 @@
+2024-06-05  Thomas Schwinge  
+
+   * plugin/plugin-nvptx.c (nvptx_do_global_cdtors): New.
+   (nvptx_close_device, GOMP_OFFLOAD_load_image)
+   (GOMP_OFFLOAD_unload_image): Call it.
+
 2024-06-05  Thomas Schwinge  
 
* config/nvptx/error.c (exit): Don't override.
diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c
index 5e1b6876324..16c69bb4511 100644
--- a/libgomp/plugin/plugin-nvptx.c
+++ b/libgomp/plugin/plugin-nvptx.c
@@ -346,6 +346,11 @@ static struct ptx_device **ptx_devices;
default is set here.  */
 static unsigned lowlat_pool_size = 8 * 1024;
 
+static bool nvptx_do_global_cdtors (CUmodule, struct ptx_device *,
+   const char *);
+static size_t nvptx_stacks_size ();
+static void *nvptx_stacks_acquire (struct ptx_device *, size_t, int);
+
 static inline struct nvptx_thread *
 nvptx_thread (void)
 {
@@ -565,6 +570,18 @@ nvptx_close_device (struct ptx_device *ptx_dev)
   if (!ptx_dev)
 return true;
 
+  bool ret = true;
+
+  for (struct ptx_image_data *image = ptx_dev->images;
+   image != NULL;
+   image = image->next)
+{
+  if (!nvptx_do_global_cdtors (image->module, ptx_dev,
+  "__do_global_dtors__entry"
+  /* or "__do_global_dtors__entry__mgomp" */))
+   ret = false;
+}
+
   for (struct ptx_free_block *b = ptx_dev->free_blocks; b;)
 {
   struct ptx_free_block *b_next = b->next;
@@ -585,7 +602,8 @@ nvptx_close_device (struct ptx_device *ptx_dev)
 CUDA_CALL (cuCtxDestroy, ptx_dev->ctx);
 
   free (ptx_dev);
-  return true;
+
+  return ret;
 }
 
 stat

[gcc/devel/omp/gcc-14] nvptx, libgcc: Stub unwinding implementation

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:91b932c193e0c83b5daa9295ea1c52914258457e

commit 91b932c193e0c83b5daa9295ea1c52914258457e
Author: Thomas Schwinge 
Date:   Wed Jun 5 13:11:04 2024 +0200

nvptx, libgcc: Stub unwinding implementation

Adding stub '_Unwind_Backtrace', '_Unwind_GetIPInfo' functions is necessary
for linking libbacktrace, as a normal (non-'LIBGFOR_MINIMAL') configuration
of libgfortran wants to do, for example.

The file 'libgcc/config/nvptx/unwind-nvptx.c' is copied from
'libgcc/config/gcn/unwind-gcn.c'.

libgcc/ChangeLog:

* config/nvptx/t-nvptx: Add unwind-nvptx.c.
* config/nvptx/unwind-nvptx.c: New file.

Co-authored-by: Andrew Stubbs 
(cherry picked from commit a29c5852a606588175d11844db84da0881227100)

Diff:
---
 libgcc/ChangeLog.omp   |  6 ++
 libgcc/config/nvptx/t-nvptx|  3 ++-
 libgcc/config/nvptx/unwind-nvptx.c | 37 +
 3 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/libgcc/ChangeLog.omp b/libgcc/ChangeLog.omp
index 7294ca9aace..62461642e5f 100644
--- a/libgcc/ChangeLog.omp
+++ b/libgcc/ChangeLog.omp
@@ -1,3 +1,9 @@
+2024-06-05  Thomas Schwinge  
+   Andrew Stubbs 
+
+   * config/nvptx/t-nvptx: Add unwind-nvptx.c.
+   * config/nvptx/unwind-nvptx.c: New file.
+
 2024-06-05  Thomas Schwinge  
 
* config/nvptx/gbl-ctors.c ["mgomp"]
diff --git a/libgcc/config/nvptx/t-nvptx b/libgcc/config/nvptx/t-nvptx
index 260ed6334db..1ff574c2982 100644
--- a/libgcc/config/nvptx/t-nvptx
+++ b/libgcc/config/nvptx/t-nvptx
@@ -1,6 +1,7 @@
 LIB2ADD=$(srcdir)/config/nvptx/reduction.c \
$(srcdir)/config/nvptx/mgomp.c \
-   $(srcdir)/config/nvptx/atomic.c
+   $(srcdir)/config/nvptx/atomic.c \
+   $(srcdir)/config/nvptx/unwind-nvptx.c
 
 # Until we have libstdc++-v3/libsupc++ proper.
 LIB2ADD += $(srcdir)/c++-minimal/guard.c
diff --git a/libgcc/config/nvptx/unwind-nvptx.c 
b/libgcc/config/nvptx/unwind-nvptx.c
new file mode 100644
index 000..d08ba266be1
--- /dev/null
+++ b/libgcc/config/nvptx/unwind-nvptx.c
@@ -0,0 +1,37 @@
+/* Stub unwinding implementation.
+
+   Copyright (C) 2019-2024 Free Software Foundation, Inc.
+   Contributed by Mentor Graphics
+
+   This file is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by the
+   Free Software Foundation; either version 3, or (at your option) any
+   later version.
+
+   This file is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   .  */
+
+#include "unwind.h"
+
+_Unwind_Reason_Code
+_Unwind_Backtrace(_Unwind_Trace_Fn trace, void * trace_argument)
+{
+  return 0;
+}
+
+_Unwind_Ptr
+_Unwind_GetIPInfo (struct _Unwind_Context *c, int *ip_before_insn)
+{
+  return 0;
+}


[gcc/devel/omp/gcc-14] nvptx offloading: 'GOMP_NVPTX_NATIVE_GPU_THREAD_STACK_SIZE' environment variable [PR97384, PR105274]

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:0c917e4821cf4b3dc46e703e7f1fcbf9dd7f0f13

commit 0c917e4821cf4b3dc46e703e7f1fcbf9dd7f0f13
Author: Thomas Schwinge 
Date:   Fri May 31 17:04:39 2024 +0200

nvptx offloading: 'GOMP_NVPTX_NATIVE_GPU_THREAD_STACK_SIZE' environment 
variable [PR97384, PR105274]

... as a means to manually set the "native" GPU thread stack size.

PR libgomp/97384
PR libgomp/105274
libgomp/
* plugin/cuda-lib.def (cuCtxSetLimit): Add.
* plugin/plugin-nvptx.c (nvptx_open_device): Handle
'GOMP_NVPTX_NATIVE_GPU_THREAD_STACK_SIZE' environment variable.

(cherry picked from commit 0d25989d60d15866ef4737d66e02432f50717255)

Diff:
---
 libgomp/ChangeLog.omp |  6 ++
 libgomp/plugin/cuda-lib.def   |  1 +
 libgomp/plugin/plugin-nvptx.c | 45 +++
 3 files changed, 52 insertions(+)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index b1c3ec684fd..4021dc46fab 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,9 @@
+2024-05-31  Thomas Schwinge  
+
+   * plugin/cuda-lib.def (cuCtxSetLimit): Add.
+   * plugin/plugin-nvptx.c (nvptx_open_device): Handle
+   'GOMP_NVPTX_NATIVE_GPU_THREAD_STACK_SIZE' environment variable.
+
 2024-06-05  Thomas Schwinge  
 
* plugin/plugin-nvptx.c (nvptx_do_global_cdtors): New.
diff --git a/libgomp/plugin/cuda-lib.def b/libgomp/plugin/cuda-lib.def
index bd25375c26a..f3aa3fb3639 100644
--- a/libgomp/plugin/cuda-lib.def
+++ b/libgomp/plugin/cuda-lib.def
@@ -4,6 +4,7 @@ CUDA_ONE_CALL (cuCtxGetCurrent)
 CUDA_ONE_CALL (cuCtxGetDevice)
 CUDA_ONE_CALL (cuCtxPopCurrent)
 CUDA_ONE_CALL (cuCtxPushCurrent)
+CUDA_ONE_CALL (cuCtxSetLimit)
 CUDA_ONE_CALL (cuCtxSynchronize)
 CUDA_ONE_CALL (cuDeviceGet)
 CUDA_ONE_CALL (cuDeviceGetAttribute)
diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c
index 16c69bb4511..84bac0beafd 100644
--- a/libgomp/plugin/plugin-nvptx.c
+++ b/libgomp/plugin/plugin-nvptx.c
@@ -150,6 +150,8 @@ init_cuda_lib (void)
 
 #include "secure_getenv.h"
 
+static void notify_var (const char *, const char *);
+
 #undef MIN
 #undef MAX
 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
@@ -341,6 +343,9 @@ struct ptx_device
 
 static struct ptx_device **ptx_devices;
 
+/* "Native" GPU thread stack size.  */
+static unsigned native_gpu_thread_stack_size = 0;
+
 /* OpenMP kernels reserve a small amount of ".shared" space for use by
omp_alloc.  The size is configured using GOMP_NVPTX_LOWLAT_POOL, but the
default is set here.  */
@@ -555,6 +560,46 @@ nvptx_open_device (int n)
   ptx_dev->free_blocks = NULL;
   pthread_mutex_init (&ptx_dev->free_blocks_lock, NULL);
 
+  /* "Native" GPU thread stack size.  */
+  {
+/* This is intentionally undocumented, until we work out a proper, common
+   scheme (as much as makes sense) between all offload plugins as well
+   as between nvptx offloading use of "native" stacks for OpenACC vs.
+   OpenMP "soft stacks" vs. OpenMP '-msoft-stack-reserve-local=[...]'.
+
+   GCN offloading has a 'GCN_STACK_SIZE' environment variable (without
+   'GOMP_' prefix): documented; presumably used for all things OpenACC and
+   OpenMP?  Based on GCN command-line option '-mstack-size=[...]' (marked
+   "obsolete"), that one may be set via a GCN 'mkoffload'-synthesized
+   'constructor' function.  */
+const char *var_name = "GOMP_NVPTX_NATIVE_GPU_THREAD_STACK_SIZE";
+const char *env_var = secure_getenv (var_name);
+notify_var (var_name, env_var);
+
+if (env_var != NULL)
+  {
+   char *endptr;
+   unsigned long val = strtoul (env_var, &endptr, 10);
+   if (endptr == NULL || *endptr != '\0'
+   || errno == ERANGE || errno == EINVAL
+   || val > UINT_MAX)
+ GOMP_PLUGIN_error ("Error parsing %s", var_name);
+   else
+ native_gpu_thread_stack_size = val;
+  }
+  }
+  if (native_gpu_thread_stack_size == 0)
+; /* Zero means use default.  */
+  else
+{
+  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);
+}
+
+  /* OpenMP "soft stacks".  */
   ptx_dev->omp_stacks.ptr = 0;
   ptx_dev->omp_stacks.size = 0;
   pthread_mutex_init (&ptx_dev->omp_stacks.lock, NULL);


[gcc/devel/omp/gcc-14] nvptx, libgfortran: Switch out of "minimal" mode

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:ad7af5eced07642132fb9f7784f9b4007d48ccc4

commit ad7af5eced07642132fb9f7784f9b4007d48ccc4
Author: Thomas Schwinge 
Date:   Wed Jun 5 13:13:24 2024 +0200

nvptx, libgfortran: Switch out of "minimal" mode

..., in order to enable (portions of) Fortran I/O, for example.

libgfortran/
* configure.ac: No longer set 'LIBGFOR_MINIMAL' for nvptx.
* configure: Regenerate.
libgomp/
* libgomp.texi (nvptx): Update.
* testsuite/libgomp.fortran/target-print-1-nvptx.f90: Remove.
* testsuite/libgomp.fortran/target-print-1.f90: Adjust.
* testsuite/libgomp.oacc-fortran/error_stop-2-nvptx.f: New.
* testsuite/libgomp.oacc-fortran/error_stop-2.f: Adjust.
* testsuite/libgomp.oacc-fortran/print-1-nvptx.f90: Adjust.
* testsuite/libgomp.oacc-fortran/print-1.f90: Adjust.
* testsuite/libgomp.oacc-fortran/stop-2-nvptx.f: New.
* testsuite/libgomp.oacc-fortran/stop-2.f: Adjust.

Co-authored-by: Andrew Stubbs 
(cherry picked from commit 3a4775d4403f2e88b589e88a9937cc1fd45a0e87)

Diff:
---
 libgfortran/ChangeLog.omp  |  5 +++
 libgfortran/configure  | 21 +---
 libgfortran/configure.ac   | 17 -
 libgomp/ChangeLog.omp  | 12 +++
 libgomp/libgomp.texi   | 10 +++---
 .../libgomp.fortran/target-print-1-nvptx.f90   | 11 --
 .../testsuite/libgomp.fortran/target-print-1.f90   |  3 --
 .../libgomp.oacc-fortran/error_stop-2-nvptx.f  | 39 +
 .../testsuite/libgomp.oacc-fortran/error_stop-2.f  |  3 +-
 .../libgomp.oacc-fortran/print-1-nvptx.f90 | 40 ++
 libgomp/testsuite/libgomp.oacc-fortran/print-1.f90 |  4 +--
 .../testsuite/libgomp.oacc-fortran/stop-2-nvptx.f  | 36 +++
 libgomp/testsuite/libgomp.oacc-fortran/stop-2.f|  3 +-
 13 files changed, 151 insertions(+), 53 deletions(-)

diff --git a/libgfortran/ChangeLog.omp b/libgfortran/ChangeLog.omp
index e4955f75d44..61e17b0bc54 100644
--- a/libgfortran/ChangeLog.omp
+++ b/libgfortran/ChangeLog.omp
@@ -1,3 +1,8 @@
+2024-06-05  Thomas Schwinge  
+
+   * configure.ac: No longer set 'LIBGFOR_MINIMAL' for nvptx.
+   * configure: Regenerate.
+
 2024-06-05  Thomas Schwinge  
 
* runtime/minimal.c [__nvptx__] (exit): Don't override.
diff --git a/libgfortran/configure b/libgfortran/configure
index 774dd52fc95..11a1bc5f070 100755
--- a/libgfortran/configure
+++ b/libgfortran/configure
@@ -6207,17 +6207,12 @@ else
 fi
 
 
-# For GPU offloading, not everything in libfortran can be supported.
-# Currently, the only target that has this problem is nvptx.  The
-# following is a (partial) list of features that are unsupportable on
-# this particular target:
-# * Constructors
-# * alloca
-# * C library support for I/O, with printf as the one notable exception
-# * C library support for other features such as signal, environment
-#   variables, time functions
-
- if test "x${target_cpu}" = xnvptx; then
+# "Minimal" mode is for targets that cannot (yet) support all features of
+# libgfortran.  It avoids the need for working constructors, alloca, and C
+# library support for I/O, signals, environment variables, time functions, etc.
+# At present there are no targets that require this mode.
+
+ if false; then
   LIBGFOR_MINIMAL_TRUE=
   LIBGFOR_MINIMAL_FALSE='#'
 else
@@ -12852,7 +12847,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12855 "configure"
+#line 12850 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12958,7 +12953,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12961 "configure"
+#line 12956 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac
index 46585a3ee14..cca1ea0ea97 100644
--- a/libgfortran/configure.ac
+++ b/libgfortran/configure.ac
@@ -209,17 +209,12 @@ AM_CONDITIONAL(LIBGFOR_USE_SYMVER, [test 
"x$gfortran_use_symver" != xno])
 AM_CONDITIONAL(LIBGFOR_USE_SYMVER_GNU, [test "x$gfortran_use_symver" = xgnu])
 AM_CONDITIONAL(LIBGFOR_USE_SYMVER_SUN, [test "x$gfortran_use_symver" = xsun])
 
-# For GPU offloading, not everything in libfortran can be supported.
-# Currently, the only target that has this problem is nvptx.  The
-# following is a (partial) list of features that are unsupportable on
-# this particular target:
-# * Constructors
-# * alloca
-# * C library support for I/O, with printf as the one notable exception
-# * C library support for other features such as signal, environment
-#   variables, time functions
-
-AM_CONDITIONAL(LIBGFOR_MINIMAL, [test "x${target_cpu}" = xnvptx])
+# "Minimal" mode is for 

[gcc/devel/omp/gcc-14] libgomp: Merge 'gomp_map_vars_openacc' into 'goacc_map_vars' [PR76739]

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:d4d800ff78697e45ca3c9e24dba0d1166265d381

commit d4d800ff78697e45ca3c9e24dba0d1166265d381
Author: Thomas Schwinge 
Date:   Thu Mar 2 18:36:47 2023 +0100

libgomp: Merge 'gomp_map_vars_openacc' into 'goacc_map_vars' [PR76739]

Upstream has 'goacc_map_vars'; merge the new 'gomp_map_vars_openacc' into 
it.
(Maybe the latter didn't exist yet when the former was originally added?)
No functional change.

Clean-up for og12 commit 15d0f61a7fecdc8fd12857c40879ea3730f6d99f
"Merge non-contiguous array support patches".

PR other/76739
libgomp/
* libgomp.h (goacc_map_vars): Add 'struct goacc_ncarray_info *'
formal parameter.
(gomp_map_vars_openacc): Remove.
* target.c (goacc_map_vars): Adjust.
(gomp_map_vars_openacc): Remove.
* oacc-mem.c (acc_map_data, goacc_enter_datum)
(goacc_enter_data_internal): Adjust.
* oacc-parallel.c (GOACC_parallel_keyed, GOACC_data_start):
Adjust.

Diff:
---
 libgomp/ChangeLog.omp   | 13 +
 libgomp/libgomp.h   |  9 -
 libgomp/oacc-mem.c  |  8 
 libgomp/oacc-parallel.c | 10 +-
 libgomp/target.c| 17 +++--
 5 files changed, 29 insertions(+), 28 deletions(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 967db4b8f61..191c3e61ad3 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,16 @@
+2023-03-10  Thomas Schwinge  
+
+   PR other/76739
+   * libgomp.h (goacc_map_vars): Add 'struct goacc_ncarray_info *'
+   formal parameter.
+   (gomp_map_vars_openacc): Remove.
+   * target.c (goacc_map_vars): Adjust.
+   (gomp_map_vars_openacc): Remove.
+   * oacc-mem.c (acc_map_data, goacc_enter_datum)
+   (goacc_enter_data_internal): Adjust.
+   * oacc-parallel.c (GOACC_parallel_keyed, GOACC_data_start):
+   Adjust.
+
 2024-05-31  Thomas Schwinge  
 
* libgomp.texi (nvptx): Update.
diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h
index 3009a0c9977..6966e1e5200 100644
--- a/libgomp/libgomp.h
+++ b/libgomp/libgomp.h
@@ -1463,15 +1463,14 @@ extern void gomp_attach_pointer (struct 
gomp_device_descr *,
 extern void gomp_detach_pointer (struct gomp_device_descr *,
 struct goacc_asyncqueue *, splay_tree_key,
 uintptr_t, bool, struct gomp_coalesce_buf *);
+struct goacc_ncarray_info;
 extern struct target_mem_desc *goacc_map_vars (struct gomp_device_descr *,
   struct goacc_asyncqueue *,
   size_t, void **, void **,
-  size_t *, void *, bool,
+  size_t *, void *,
+  struct goacc_ncarray_info *,
+  bool,
   enum gomp_map_vars_kind);
-extern struct target_mem_desc *gomp_map_vars_openacc (struct gomp_device_descr 
*,
- struct goacc_asyncqueue *,
- size_t, void **, size_t *,
- unsigned short *, void *);
 extern void goacc_unmap_vars (struct target_mem_desc *, bool,
  struct goacc_asyncqueue *);
 extern void gomp_init_device (struct gomp_device_descr *);
diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index 45eb837e6ad..feca3b28318 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -403,7 +403,7 @@ acc_map_data (void *h, void *d, size_t s)
 
   struct target_mem_desc *tgt
= goacc_map_vars (acc_dev, NULL, mapnum, &hostaddrs, &devaddrs, &sizes,
- &kinds, true, GOMP_MAP_VARS_ENTER_DATA);
+ &kinds, NULL, true, GOMP_MAP_VARS_ENTER_DATA);
   assert (tgt);
   assert (tgt->list_count == 1);
   splay_tree_key n = tgt->list[0].key;
@@ -568,7 +568,7 @@ goacc_enter_datum (void **hostaddrs, size_t *sizes, void 
*kinds, int async)
 
   struct target_mem_desc *tgt
= goacc_map_vars (acc_dev, aq, mapnum, hostaddrs, NULL, sizes,
- kinds, true, GOMP_MAP_VARS_ENTER_DATA);
+ kinds, NULL, true, GOMP_MAP_VARS_ENTER_DATA);
   assert (tgt);
   assert (tgt->list_count == 1);
   n = tgt->list[0].key;
@@ -1263,7 +1263,7 @@ goacc_enter_data_internal (struct gomp_device_descr 
*acc_dev, size_t mapnum,
  gomp_mutex_unlock (&acc_dev->lock);
  struct target_mem_desc *tgt_
= goacc_map_vars (acc_dev, aq, groupnum, &hostaddrs[i], NULL,
- &sizes[i], &kinds[i], true,
+ &sizes[i], &kinds[i], NULL, true,
   

[gcc/devel/omp/gcc-14] Fortran: Add attr.class_ok check for generate_callback_wrapper

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:1bd79a2f001df20272284d0bd1037d7d5627efe6

commit 1bd79a2f001df20272284d0bd1037d7d5627efe6
Author: Tobias Burnus 
Date:   Thu Mar 23 14:29:00 2023 +0100

Fortran: Add attr.class_ok check for generate_callback_wrapper

Proper variables/components of type BT_CLASS have 'class_ok' set; check
for that to avoid an ICE on invalid code for gfortran.dg/pr108434.f90.

gcc/fortran/
* class.cc (generate_callback_wrapper): Add attr.class_ok check.
* resolve.cc (resolve_fl_derived): Likewise.

Diff:
---
 gcc/fortran/ChangeLog.omp | 5 +
 gcc/fortran/class.cc  | 5 -
 gcc/fortran/resolve.cc| 3 ++-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp
index 4f1e80a42b2..26d69b8081f 100644
--- a/gcc/fortran/ChangeLog.omp
+++ b/gcc/fortran/ChangeLog.omp
@@ -1,3 +1,8 @@
+2023-03-23  Tobias Burnus  
+
+   * class.cc (generate_callback_wrapper): Add attr.class_ok check.
+   * resolve.cc (resolve_fl_derived): Likewise.
+
 2022-11-02  Tobias Burnus  
 
* trans-openmp.cc (gfc_trans_omp_clauses): Ensure DT struct-comp with
diff --git a/gcc/fortran/class.cc b/gcc/fortran/class.cc
index 987722f601f..15aacd98fd8 100644
--- a/gcc/fortran/class.cc
+++ b/gcc/fortran/class.cc
@@ -2680,6 +2680,9 @@ generate_callback_wrapper (gfc_symbol *vtab, gfc_symbol 
*derived,
 cb (token, comp->var(.data), size, 0, var's cb fn);  */
   for (gfc_component *comp = derived->components; comp; comp = comp->next)
 {
+  if (__builtin_expect (comp->ts.type == BT_CLASS
+   && !comp->attr.class_ok, 0))
+   continue;
   bool pointer = (comp->ts.type == BT_CLASS
  ? CLASS_DATA (comp)->attr.pointer : comp->attr.pointer);
   bool proc_ptr = comp->attr.proc_pointer;
@@ -2720,7 +2723,7 @@ generate_callback_wrapper (gfc_symbol *vtab, gfc_symbol 
*derived,
  size->where = gfc_current_locus;
}
 
-  if (!proc_ptr && comp->ts.type == BT_CLASS)
+  if (!proc_ptr && comp->ts.type == BT_CLASS && comp->attr.class_ok)
{
  gfc_add_data_component (expr);
  if (comp->attr.dimension)
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 3aaeeed1c4f..1f861d9f908 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -15945,7 +15945,8 @@ resolve_fl_derived (gfc_symbol *sym)
   gfc_component *c = (sym->attr.is_class
  ? CLASS_DATA (sym->components) : sym->components);
   for ( ; c; c = c->next)
-if ((c->ts.type == BT_DERIVED || c->ts.type == BT_CLASS)
+if ((c->ts.type == BT_DERIVED
+   || (c->ts.type == BT_CLASS && c->attr.class_ok))
&& !c->ts.u.derived->resolve_symbol_called)
   {
if (c->ts.u.derived->components == NULL


[gcc/devel/omp/gcc-14] amdgcn: gather/scatter with DImode offsets

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:3760f09cafa8db5c42a8dc3193839c25a4994a46

commit 3760f09cafa8db5c42a8dc3193839c25a4994a46
Author: Andrew Stubbs 
Date:   Mon Mar 6 12:42:44 2023 +

amdgcn: gather/scatter with DImode offsets

The GPU architecture requires SImode offsets on gather/scatter instructions,
but they can also take a vector of absolute addresses, so this allows
gather/scatter in more situations.

gcc/ChangeLog:

* config/gcn/gcn-valu.md (gather_load): New.
(scatter_store): New.
(mask_gather_load): New.
(mask_scatter_store): New.

Diff:
---
 gcc/ChangeLog.omp  |   7 +++
 gcc/config/gcn/gcn-valu.md | 123 +
 2 files changed, 130 insertions(+)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 66d27e6ab7c..3f6b3e44e02 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,10 @@
+2023-03-17  Andrew Stubbs  
+
+   * config/gcn/gcn-valu.md (gather_load): New.
+   (scatter_store): New.
+   (mask_gather_load): New.
+   (mask_scatter_store): New.
+
 2024-05-10  Thomas Schwinge  
 
* config/nvptx/nvptx.md (nvptx_uniform_warp_check): Make fit for
diff --git a/gcc/config/gcn/gcn-valu.md b/gcc/config/gcn/gcn-valu.md
index e8381d28c1b..15fdeb7d1ea 100644
--- a/gcc/config/gcn/gcn-valu.md
+++ b/gcc/config/gcn/gcn-valu.md
@@ -,6 +,34 @@
 ;;
 ;; TODO: implement combined gather and zero_extend, but only for -msram-ecc=on
 
+(define_expand "gather_load"
+  [(match_operand:V_ALL 0 "register_operand")
+   (match_operand:DI 1 "register_operand")
+   (match_operand: 2 "register_operand")
+   (match_operand 3 "immediate_operand")
+   (match_operand:SI 4 "gcn_alu_operand")]
+  ""
+  {
+rtx vec_base = gen_reg_rtx (mode);
+rtx addr = gen_reg_rtx (mode);
+rtx multiplier = gen_reg_rtx (mode);
+rtx offsets = gen_reg_rtx (mode);
+
+if (CONST_INT_P (operands[4]) && INTVAL (operands[4]) != 1)
+  {
+   emit_insn (gen_vec_duplicate (multiplier, operands[4]));
+   emit_insn (gen_mul3 (offsets, operands[2], multiplier));
+  }
+else
+  offsets = operands[2];
+emit_insn (gen_vec_duplicate (vec_base, operands[1]));
+emit_insn (gen_add3 (addr, vec_base, offsets));
+
+emit_insn (gen_gather_insn_1offset (operands[0], addr, const0_rtx,
+ const0_rtx, const0_rtx));
+DONE;
+  })
+
 (define_expand "gather_load"
   [(match_operand:V_MOV 0 "register_operand")
(match_operand:DI 1 "register_operand")
@@ -1244,6 +1272,34 @@
(set_attr "gcn_version" "*,cdna2,*,cdna2")
(set_attr "xnack" "off,off,on,on")])
 
+(define_expand "scatter_store"
+  [(match_operand:DI 0 "register_operand")
+   (match_operand: 1 "register_operand")
+   (match_operand 2 "immediate_operand")
+   (match_operand:SI 3 "gcn_alu_operand")
+   (match_operand:V_ALL 4 "register_operand")]
+  ""
+  {
+rtx vec_base = gen_reg_rtx (mode);
+rtx addr = gen_reg_rtx (mode);
+rtx multiplier = gen_reg_rtx (mode);
+rtx offsets = gen_reg_rtx (mode);
+
+if (CONST_INT_P (operands[3]) && INTVAL (operands[3]) != 1)
+  {
+   emit_insn (gen_vec_duplicate (multiplier, operands[3]));
+   emit_insn (gen_mul3 (offsets, operands[1], multiplier));
+  }
+else
+  offsets = operands[1];
+emit_insn (gen_vec_duplicate (vec_base, operands[0]));
+emit_insn (gen_add3 (addr, vec_base, offsets));
+
+emit_insn (gen_scatter_insn_1offset (addr, const0_rtx, operands[4],
+  const0_rtx, const0_rtx));
+DONE;
+  })
+
 (define_expand "scatter_store"
   [(match_operand:DI 0 "register_operand")
(match_operand: 1 "register_operand")
@@ -4034,6 +4090,41 @@
 DONE;
   })
 
+(define_expand "mask_gather_load"
+  [(match_operand:V_ALL 0 "register_operand")
+   (match_operand:DI 1 "register_operand")
+   (match_operand: 2 "register_operand")
+   (match_operand 3 "immediate_operand")
+   (match_operand:SI 4 "gcn_alu_operand")
+   (match_operand:DI 5 "")]
+  ""
+  {
+rtx vec_base = gen_reg_rtx (mode);
+rtx addr = gen_reg_rtx (mode);
+rtx multiplier = gen_reg_rtx (mode);
+rtx offsets = gen_reg_rtx (mode);
+rtx exec = force_reg (DImode, operands[5]);
+
+if (CONST_INT_P (operands[4]) && INTVAL (operands[4]) != 1)
+  {
+   emit_insn (gen_vec_duplicate (multiplier, operands[4]));
+   emit_insn (gen_mul3 (offsets, operands[2], multiplier));
+  }
+else
+  offsets = operands[2];
+emit_insn (gen_vec_duplicate (vec_base, operands[1]));
+emit_insn (gen_add3 (addr, vec_base, offsets));
+
+/* Masked lanes are required to hold zero.  */
+emit_move_insn (operands[0], gcn_vec_constant (mode, 0));
+
+emit_insn (gen_gather_insn_1offset_exec (operands[0], addr,
+  const0_rtx, const0_rtx,
+  const0_rtx, oper

[gcc/devel/omp/gcc-14] Fortran/OpenMP: Fix 'alloc' and 'from' mapping for allocatable components

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:cc72c031b0be60f5c24f52ad0dd2c932f3737766

commit cc72c031b0be60f5c24f52ad0dd2c932f3737766
Author: Tobias Burnus 
Date:   Thu Mar 23 18:04:17 2023 +0100

Fortran/OpenMP: Fix 'alloc' and 'from' mapping for allocatable components

Even with 'alloc' and map-entering 'from' mapping, the following should 
hold.
For explicit mapping, that's already the case, this handles the automatical
deep mapping of allocatable components. Namely:
* On the device, the array bounds (of allocated allocatables) must match the
  host, implying 'to' (or 'tofrom') mapping.
* On map exiting, the copying out shall not destroy the unallocated 
allocation
  status (nor the pointer address of allocated allocatables).

The latter was not a problem for allocated allocatables as for those a 
pointer
was GOMP_MAP_ATTACHed; however, for unallocated allocatables, before it 
copied
back device-allocated memory which might not be nullified.

While 'alloc' was not deep-mapped at all, for map-entering 'from', the array
bounds were not set, making allocated derived-type components inaccessible 
on
the device (and wrong on the host on copy back).

The solution is, first, to deep-map 'alloc' as well and to copy to the 
device
even with 'alloc' and (map-entering) 'from'. This copying is only done if 
there
is a scalar (for the unallocated case) or array allocatable directly in the
derived type and then it is shallowly copied; the data pointed to is then 
again
only alloc'ed, unless it contains in turn allocatables.

gcc/fortran/

* trans-openmp.cc (gfc_has_alloc_comps): Add 'bool
shallow_alloc_only=false' arg.
(gfc_omp_replace_alloc_by_to_mapping): New, call it.
(gfc_omp_deep_map_kind_p): Return 'true' also for '(present,)alloc'.
(gfc_omp_deep_mapping_item, gfc_omp_deep_mapping_do): On map 
entering,
replace shallowly 'alloc'/'from' by '(from)to' mapping if there are
allocatable components.

libgomp/

* testsuite/libgomp.fortran/map-alloc-comp-8.f90: New test.

Diff:
---
 gcc/fortran/ChangeLog.omp  |  10 +
 gcc/fortran/trans-openmp.cc|  96 +++-
 libgomp/ChangeLog.omp  |   4 +
 .../testsuite/libgomp.fortran/map-alloc-comp-8.f90 | 268 +
 4 files changed, 371 insertions(+), 7 deletions(-)

diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp
index 26d69b8081f..d64851275b1 100644
--- a/gcc/fortran/ChangeLog.omp
+++ b/gcc/fortran/ChangeLog.omp
@@ -1,3 +1,13 @@
+2023-03-23  Tobias Burnus  
+
+   * trans-openmp.cc (gfc_has_alloc_comps): Add 'bool
+   shallow_alloc_only=false' arg.
+   (gfc_omp_replace_alloc_by_to_mapping): New, call it.
+   (gfc_omp_deep_map_kind_p): Return 'true' also for '(present,)alloc'.
+   (gfc_omp_deep_mapping_item, gfc_omp_deep_mapping_do): On map entering,
+   replace shallowly 'alloc'/'from' by '(from)to' mapping if there are
+   allocatable components.
+
 2023-03-23  Tobias Burnus  
 
* class.cc (generate_callback_wrapper): Add attr.class_ok check.
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index 6dab261c381..a4abc689895 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -389,10 +389,13 @@ gfc_omp_report_decl (tree decl)
 }
 
 /* Return true if TYPE has any allocatable components;
-   if ptr_ok, the decl itself is permitted to have the POINTER attribute.  */
+   if ptr_ok, the decl itself is permitted to have the POINTER attribute.
+   if shallow_alloc_only, returns only true if any of the fields is an
+   allocatable; called with true by gfc_omp_replace_alloc_by_to_mapping.  */
 
 static bool
-gfc_has_alloc_comps (tree type, tree decl, bool ptr_ok)
+gfc_has_alloc_comps (tree type, tree decl, bool ptr_ok,
+bool shallow_alloc_only=false)
 {
   tree field, ftype;
 
@@ -425,12 +428,50 @@ gfc_has_alloc_comps (tree type, tree decl, bool ptr_ok)
   if (GFC_DESCRIPTOR_TYPE_P (ftype)
  && GFC_TYPE_ARRAY_AKIND (ftype) == GFC_ARRAY_ALLOCATABLE)
return true;
-  if (gfc_has_alloc_comps (ftype, field, false))
+  if (!shallow_alloc_only
+ && gfc_has_alloc_comps (ftype, field, false))
return true;
 }
   return false;
 }
 
+/* gfc_omp_replace_alloc_by_to_mapping is used with gfc_omp_deep_mapping... to
+   handle the following:
+
+   For map(alloc: dt), the array descriptors of allocatable components should
+   be mapped as 'to'; this could be done by (A) adding 'map(to: dt%alloc_comp)'
+   for each component (and avoiding to increment the reference count).
+   Or (B) by just mapping all of 'dt' as 'to'.
+
+   If 'dt' contains several allocatable components and not much other data,
+   (A) is more efficient. If 'dt' contains a large const-size array,

[gcc/devel/omp/gcc-14] Given OpenACC 'async', defer 'free' of non-contiguous array support data structures [PR76739]

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:876d5805ad7aedef891471f2071ac0c56d2702fb

commit 876d5805ad7aedef891471f2071ac0c56d2702fb
Author: Thomas Schwinge 
Date:   Wed Mar 15 13:34:02 2023 +0100

Given OpenACC 'async', defer 'free' of non-contiguous array support data 
structures [PR76739]

Fix-up for og12 commit 15d0f61a7fecdc8fd12857c40879ea3730f6d99f
"Merge non-contiguous array support patches".

PR other/76739
libgomp/
* oacc-parallel.c (GOACC_parallel_keyed): Given OpenACC 'async',
defer 'free' of non-contiguous array support data structures.
* target.c (gomp_map_vars_internal): Likewise.

Diff:
---
 libgomp/ChangeLog.omp   | 7 +++
 libgomp/oacc-parallel.c | 5 -
 libgomp/target.c| 6 +-
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index b3e29fdd39f..4110df8790d 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,10 @@
+2023-03-24  Thomas Schwinge  
+
+   PR other/76739
+   * oacc-parallel.c (GOACC_parallel_keyed): Given OpenACC 'async',
+   defer 'free' of non-contiguous array support data structures.
+   * target.c (gomp_map_vars_internal): Likewise.
+
 2023-03-23  Tobias Burnus  
 
* testsuite/libgomp.fortran/map-alloc-comp-8.f90: New test.
diff --git a/libgomp/oacc-parallel.c b/libgomp/oacc-parallel.c
index b2a2ec9b120..4194a9cd1ac 100644
--- a/libgomp/oacc-parallel.c
+++ b/libgomp/oacc-parallel.c
@@ -472,7 +472,10 @@ GOACC_parallel_keyed (int flags_m, void (*fn) (void *),
   struct target_mem_desc *tgt
   = goacc_map_vars (acc_dev, aq, mapnum, hostaddrs, NULL, sizes, kinds,
nca_info, true, GOMP_MAP_VARS_TARGET);
-  free (nca_info);
+  if (aq == NULL)
+free (nca_info);
+  else
+acc_dev->openacc.async.queue_callback_func (aq, free, nca_info);
 
   if (profiling_p)
 {
diff --git a/libgomp/target.c b/libgomp/target.c
index fba76ec51ea..635c1d006a2 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -1992,7 +1992,11 @@ gomp_map_vars_internal (struct gomp_device_descr 
*devicep,
(nca, target_ptrblock);
  gomp_copy_host2dev (devicep, aq, target_ptrblock, ptrblock,
  nca->ptrblock_size, false, cbufp);
- free (ptrblock);
+ if (aq)
+   /* Free once the transfer has completed.  */
+   devicep->openacc.async.queue_callback_func (aq, free, 
ptrblock);
+ else
+   free (ptrblock);
}
}
}


[gcc/devel/omp/gcc-14] libgomp: Simplify OpenMP reverse offload host <-> device memory copy implementation

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:bb69f066430029ef6864286becefa4ee63b2a138

commit bb69f066430029ef6864286becefa4ee63b2a138
Author: Thomas Schwinge 
Date:   Tue Mar 21 16:14:16 2023 +0100

libgomp: Simplify OpenMP reverse offload host <-> device memory copy 
implementation

... by using the existing 'goacc_asyncqueue' instead of re-coding parts of 
it.

Follow-up to commit 131d18e928a3ea1ab2d3bf61aa92d68a8a254609
"libgomp/nvptx: Prepare for reverse-offload callback handling",
and commit ea4b23d9c82d9be3b982c3519fe5e8e9d833a6a8
"libgomp: Handle OpenMP's reverse offloads".

libgomp/
* target.c (gomp_target_rev): Instead of 'dev_to_host_cpy',
'host_to_dev_cpy', 'token', take a single 'goacc_asyncqueue'.
* libgomp.h (gomp_target_rev): Adjust.
* libgomp-plugin.c (GOMP_PLUGIN_target_rev): Adjust.
* libgomp-plugin.h (GOMP_PLUGIN_target_rev): Adjust.
* plugin/plugin-gcn.c (process_reverse_offload): Adjust.
* plugin/plugin-nvptx.c (rev_off_dev_to_host_cpy)
(rev_off_host_to_dev_cpy): Remove.
(GOMP_OFFLOAD_run): Adjust.

Diff:
---
 libgomp/ChangeLog.omp | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index fc51f6b35a1..e586c90fb07 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,5 +1,15 @@
 2023-03-24  Thomas Schwinge  
 
+   * target.c (gomp_target_rev): Instead of 'dev_to_host_cpy',
+   'host_to_dev_cpy', 'token', take a single 'goacc_asyncqueue'.
+   * libgomp.h (gomp_target_rev): Adjust.
+   * libgomp-plugin.c (GOMP_PLUGIN_target_rev): Adjust.
+   * libgomp-plugin.h (GOMP_PLUGIN_target_rev): Adjust.
+   * plugin/plugin-gcn.c (process_reverse_offload): Adjust.
+   * plugin/plugin-nvptx.c (rev_off_dev_to_host_cpy)
+   (rev_off_host_to_dev_cpy): Remove.
+   (GOMP_OFFLOAD_run): Adjust.
+
* target.c (gomp_unmap_vars_internal): Queue splay-tree keys for
removal after main loop.


[gcc/devel/omp/gcc-14] In 'libgomp/target.c:gomp_unmap_vars_internal', defer 'gomp_remove_var'

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:13e48a31611421154614f159795a35b5a6531624

commit 13e48a31611421154614f159795a35b5a6531624
Author: Thomas Schwinge 
Date:   Tue Mar 14 19:42:12 2023 +0100

In 'libgomp/target.c:gomp_unmap_vars_internal', defer 'gomp_remove_var'

An upcoming change requires that 'gomp_remove_var' be deferred until after 
all
'gomp_copy_dev2host' calls have been handled.

Do this likewise to how commit 275c736e732d29934e4d22e8f030d5aae8c12a52
"libgomp: Structure element mapping for OpenMP 5.0" changed 
'gomp_exit_data'.

libgomp/
* target.c (gomp_unmap_vars_internal): Queue splay-tree keys for
removal after main loop.

Diff:
---
 libgomp/ChangeLog.omp |  3 +++
 libgomp/target.c  | 34 +++---
 2 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 4110df8790d..fc51f6b35a1 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,5 +1,8 @@
 2023-03-24  Thomas Schwinge  
 
+   * target.c (gomp_unmap_vars_internal): Queue splay-tree keys for
+   removal after main loop.
+
PR other/76739
* oacc-parallel.c (GOACC_parallel_keyed): Given OpenACC 'async',
defer 'free' of non-contiguous array support data structures.
diff --git a/libgomp/target.c b/libgomp/target.c
index 635c1d006a2..f1450ce7dcd 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -2234,6 +2234,9 @@ gomp_unmap_vars_internal (struct target_mem_desc *tgt, 
bool do_copyfrom,
 false, NULL);
 }
 
+  size_t nrmvars = 0;
+  splay_tree_key remove_vars[tgt->list_count];
+
   for (i = 0; i < tgt->list_count; i++)
 {
   splay_tree_key k = tgt->list[i].key;
@@ -2255,16 +2258,21 @@ gomp_unmap_vars_internal (struct target_mem_desc *tgt, 
bool do_copyfrom,
(void *) (k->tgt->tgt_start + k->tgt_offset
  + tgt->list[i].offset),
tgt->list[i].length);
+  /* Queue all removals together for processing below.
+See also 'gomp_exit_data'.  */
   if (do_remove)
-   {
- struct target_mem_desc *k_tgt = k->tgt;
- bool is_tgt_unmapped = gomp_remove_var (devicep, k);
- /* It would be bad if TGT got unmapped while we're still iterating
-over its LIST_COUNT, and also expect to use it in the following
-code.  */
- assert (!is_tgt_unmapped
- || k_tgt != tgt);
-   }
+   remove_vars[nrmvars++] = k;
+}
+
+  for (i = 0; i < nrmvars; i++)
+{
+  splay_tree_key k = remove_vars[i];
+  struct target_mem_desc *k_tgt = k->tgt;
+  bool is_tgt_unmapped = gomp_remove_var (devicep, k);
+  /* It would be bad if TGT got unmapped while we're still iterating over
+its LIST_COUNT, and also expect to use it in the following code.  */
+  assert (!is_tgt_unmapped
+ || k_tgt != tgt);
 }
 
   if (aq)
@@ -4217,7 +4225,7 @@ gomp_exit_data (struct gomp_device_descr *devicep, size_t 
mapnum,
   false, NULL);
   }
 
-  int nrmvars = 0;
+  size_t nrmvars = 0;
   splay_tree_key remove_vars[mapnum];
 
   for (i = 0; i < mapnum; i++)
@@ -4280,10 +4288,6 @@ gomp_exit_data (struct gomp_device_descr *devicep, 
size_t mapnum,
 errors if we still have following element siblings to copy back.
 While we're at it, it also seems more disciplined to simply
 queue all removals together for processing below.
-
-Structured block unmapping (i.e. gomp_unmap_vars_internal) should
-not have this problem, since they maintain an additional
-tgt->refcount = 1 reference to the target_mem_desc to start with.
  */
  if (do_remove)
remove_vars[nrmvars++] = k;
@@ -4298,7 +4302,7 @@ gomp_exit_data (struct gomp_device_descr *devicep, size_t 
mapnum,
}
 }
 
-  for (int i = 0; i < nrmvars; i++)
+  for (i = 0; i < nrmvars; i++)
 gomp_remove_var (devicep, remove_vars[i]);
 
   gomp_mutex_unlock (&devicep->lock);


[gcc/devel/omp/gcc-14] libgomp: Mark Loop transformation constructs as implemented in the implementation status

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:e316a82383e3280dcc0cf25107866de84cd0eb38

commit e316a82383e3280dcc0cf25107866de84cd0eb38
Author: Jakub Jelinek 
Date:   Thu Jun 6 08:30:42 2024 +0200

libgomp: Mark Loop transformation constructs as implemented in the 
implementation status

The implementation has been committed in r15-1037.

2024-06-06  Jakub Jelinek  

* libgomp.texi (OpenMP 5.1 status): Mark Loop transformation 
constructs
as implemented.

(cherry picked from commit 6a6bab4ba36c5d190b3151055e683e7067be92c1)

Diff:
---
 libgomp/ChangeLog.omp | 5 +
 libgomp/libgomp.texi  | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 11579d68f4d..1b8f3dbaaf2 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,8 @@
+2024-06-06  Jakub Jelinek  
+
+   * libgomp.texi (OpenMP 5.1 status): Mark Loop transformation constructs
+   as implemented.
+
 2024-06-05  Jakub Jelinek  
Frederik Harwath  
Sandra Loosemore  
diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 34e61a34a58..526e936ef52 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -302,7 +302,7 @@ The OpenMP 4.5 specification is fully supported.
 @item @code{error} directive @tab Y @tab
 @item @code{masked} construct @tab Y @tab
 @item @code{scope} directive @tab Y @tab
-@item Loop transformation constructs @tab N @tab
+@item Loop transformation constructs @tab Y @tab
 @item @code{strict} modifier in the @code{grainsize} and @code{num_tasks}
   clauses of the @code{taskloop} construct @tab Y @tab
 @item @code{align} clause in @code{allocate} directive @tab P


[gcc/devel/omp/gcc-14] libgomp: Document OpenMP 'pinned' memory

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:ec03b6cec89e125eb5c955ca7180f06910f3527d

commit ec03b6cec89e125eb5c955ca7180f06910f3527d
Author: Thomas Schwinge 
Date:   Fri Mar 24 15:14:57 2023 +0100

libgomp: Document OpenMP 'pinned' memory

libgomp/
* libgomp.texi (AMD Radeon, nvptx): Document OpenMP 'pinned'
memory.

Diff:
---
 libgomp/ChangeLog.omp | 5 +
 libgomp/libgomp.texi  | 8 
 2 files changed, 13 insertions(+)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 1b8f3dbaaf2..afb7dd62bc1 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,8 @@
+2023-04-03  Thomas Schwinge  
+
+   * libgomp.texi (AMD Radeon, nvptx): Document OpenMP 'pinned'
+   memory.
+
 2024-06-06  Jakub Jelinek  
 
* libgomp.texi (OpenMP 5.1 status): Mark Loop transformation constructs
diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 526e936ef52..bc105464208 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -6357,6 +6357,9 @@ The implementation remark:
 @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'').
+@item OpenMP @emph{pinned} memory (@code{omp_atk_pinned},
+  @code{ompx_pinned_mem_alloc}, for example)
+  is allocated via @code{mmap}, @code{mlock}.
 @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
@@ -6434,6 +6437,11 @@ The implementation remark:
 @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'').
+@item OpenMP @emph{pinned} memory (@code{omp_atk_pinned},
+  @code{ompx_pinned_mem_alloc}, for example)
+  is allocated via @code{cuMemHostAlloc} (CUDA Driver API).
+  This potentially helps optimization of host <-> device data
+  transfers.
 @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


[gcc/devel/omp/gcc-14] OpenMP: Constructors and destructors for "declare target" static aggregates

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:9127b4db9c58f48e0b47816d64e22c21404136b3

commit 9127b4db9c58f48e0b47816d64e22c21404136b3
Author: Julian Brown 
Date:   Tue May 16 20:11:37 2023 +0100

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

This patch 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.

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

The approach taken is to generate a set of constructors to run on the
target: this currently works for AMD GCN, but fails on NVPTX due
to lack of constructor/destructor support there so far on mainline.
(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.)

2023-05-12  Julian Brown  

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/
* omp-builtins.def (BUILT_IN_OMP_IS_INITIAL_DEVICE): New builtin.
* tree.cc (get_file_function_name): Support names for on-target
constructor/destructor functions.

libgomp/
* 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.

Diff:
---
 gcc/ChangeLog.omp  |   6 +
 gcc/cp/ChangeLog.omp   |  16 ++
 gcc/cp/decl2.cc| 241 +
 gcc/omp-builtins.def   |   2 +
 gcc/tree.cc|   6 +-
 libgomp/ChangeLog.omp  |   9 +
 .../static-aggr-constructor-destructor-1.C |  28 +++
 .../static-aggr-constructor-destructor-2.C |  31 +++
 .../static-aggr-constructor-destructor-3.C |  36 +++
 9 files changed, 335 insertions(+), 40 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index fc4f8013d0c..381645ddf39 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,9 @@
+2023-05-12  Julian Brown  
+
+   * omp-builtins.def (BUILT_IN_OMP_IS_INITIAL_DEVICE): New builtin.
+   * tree.cc (get_file_function_name): Support names for on-target
+   constructor/destructor functions.
+
 2024-06-05  Jakub Jelinek  
Frederik Harwath  
Sandra Loosemore  
diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp
index e85a1077c42..ab3be42ba67 100644
--- a/gcc/cp/ChangeLog.omp
+++ b/gcc/cp/ChangeLog.omp
@@ -1,3 +1,19 @@
+2023-05-12  Julian Brown  
+
+   * 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.
+
 2024-06-05  Jakub Jelinek  
Frederik Harwath  
Sandra Loosemore  
diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 806a2a4bc69..d255483eba1 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -50,20 +50,22 @@ along with GCC; see the file COPYING3.  If not see
 #include "asan.h"
 #include "optabs-query.h"
 #include "omp-general.h"
+#include "tree-inline.h"
 
 /* Id for dumping the raw trees.  */
 int raw_dump_id;
  
 extern cpp_reader *parse_in;
 
-static tree start

[gcc/devel/omp/gcc-14] OpenACC: Pass pre-allocated 'ptrblock' to 'goacc_noncontig_array_create_ptrblock' [PR76739]

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:b27632c02e2d3f8084fc739d7728e95bc3ff7260

commit b27632c02e2d3f8084fc739d7728e95bc3ff7260
Author: Thomas Schwinge 
Date:   Wed Mar 15 14:32:12 2023 +0100

OpenACC: Pass pre-allocated 'ptrblock' to 
'goacc_noncontig_array_create_ptrblock' [PR76739]

... to simplify later changes.  No functional change.

Follow-up for og12 commit 15d0f61a7fecdc8fd12857c40879ea3730f6d99f
"Merge non-contiguous array support patches".

PR other/76739
libgomp/
* target.c (gomp_map_vars_internal): Pass pre-allocated 'ptrblock'
to 'goacc_noncontig_array_create_ptrblock'.
* oacc-parallel.c (goacc_noncontig_array_create_ptrblock): Adjust.
* oacc-int.h (goacc_noncontig_array_create_ptrblock): Adjust.

Diff:
---
 libgomp/ChangeLog.omp   | 6 ++
 libgomp/oacc-int.h  | 3 ++-
 libgomp/oacc-parallel.c | 5 ++---
 libgomp/target.c| 5 +++--
 4 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index afb7dd62bc1..00292901389 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,5 +1,11 @@
 2023-04-03  Thomas Schwinge  
 
+   PR other/76739
+   * target.c (gomp_map_vars_internal): Pass pre-allocated 'ptrblock'
+   to 'goacc_noncontig_array_create_ptrblock'.
+   * oacc-parallel.c (goacc_noncontig_array_create_ptrblock): Adjust.
+   * oacc-int.h (goacc_noncontig_array_create_ptrblock): Adjust.
+
* libgomp.texi (AMD Radeon, nvptx): Document OpenMP 'pinned'
memory.
 
diff --git a/libgomp/oacc-int.h b/libgomp/oacc-int.h
index 90e27277d3a..1732f8be48e 100644
--- a/libgomp/oacc-int.h
+++ b/libgomp/oacc-int.h
@@ -213,7 +213,8 @@ struct goacc_ncarray_info
   struct goacc_ncarray ncarray[];
 };
 
-extern void *goacc_noncontig_array_create_ptrblock (struct goacc_ncarray *, 
void *);
+extern void goacc_noncontig_array_create_ptrblock (struct goacc_ncarray *,
+  void *, void *);
 
 
 #ifdef HAVE_ATTRIBUTE_VISIBILITY
diff --git a/libgomp/oacc-parallel.c b/libgomp/oacc-parallel.c
index 4194a9cd1ac..58bed420ee1 100644
--- a/libgomp/oacc-parallel.c
+++ b/libgomp/oacc-parallel.c
@@ -165,13 +165,13 @@ goacc_process_noncontiguous_arrays (size_t mapnum, void 
**hostaddrs,
   return nca_info;
 }
 
-void *
+void
 goacc_noncontig_array_create_ptrblock (struct goacc_ncarray *nca,
+  void *ptrblock,
   void *tgt_ptrblock_addr)
 {
   struct goacc_ncarray_descr_type *descr = nca->descr;
   void **tgt_data_rows = nca->tgt_data_rows;
-  void *ptrblock = gomp_malloc (nca->ptrblock_size);
   void **curr_dim_ptrblock = (void **) ptrblock;
   size_t n = 1;
 
@@ -210,7 +210,6 @@ goacc_noncontig_array_create_ptrblock (struct goacc_ncarray 
*nca,
   curr_dim_ptrblock = next_dim_ptrblock;
 }
   assert (n == nca->data_row_num);
-  return ptrblock;
 }
 
 /* Handle the mapping pair that are presented when a
diff --git a/libgomp/target.c b/libgomp/target.c
index f1450ce7dcd..0c71b5f84ca 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -1988,8 +1988,9 @@ gomp_map_vars_internal (struct gomp_device_descr *devicep,
 accelerator side ptrblock and copy it in.  */
  if (nca->ptrblock_size)
{
- void *ptrblock = goacc_noncontig_array_create_ptrblock
-   (nca, target_ptrblock);
+ void *ptrblock = gomp_malloc (nca->ptrblock_size);
+ goacc_noncontig_array_create_ptrblock
+   (nca, ptrblock, target_ptrblock);
  gomp_copy_host2dev (devicep, aq, target_ptrblock, ptrblock,
  nca->ptrblock_size, false, cbufp);
  if (aq)


[gcc/devel/omp/gcc-14] Use OpenACC code to process OpenMP target regions

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:027cbe929314ee40bcca49fce3265f3ecbf72ed5

commit 027cbe929314ee40bcca49fce3265f3ecbf72ed5
Author: Chung-Lin Tang 
Date:   Fri May 19 12:14:04 2023 -0700

Use OpenACC code to process OpenMP target regions

(forward ported from devel/omp/gcc-12)

This is a backport of:
https://gcc.gnu.org/pipermail/gcc-patches/2023-May/619003.html

This patch implements '-fopenmp-target=acc', which enables internally 
handling
a subset of OpenMP target regions as OpenACC parallel regions. This 
basically
includes target, teams, parallel, distribute, for/do constructs, and 
atomics.

Essentially, we adjust the internal kinds to OpenACC type, and let OpenACC 
code
paths handle them, with various needed adjustments throughout middle-end and
nvptx backend. When using this "OMPACC" mode, if there are cases the patch
doesn't handle, it issues a warning, and reverts to normal processing for 
that
target region.

gcc/ChangeLog:

* builtins.cc (expand_builtin_omp_builtins): New function.
(expand_builtin): Add expand cases for BUILT_IN_GOMP_BARRIER,
BUILT_IN_OMP_GET_THREAD_NUM, BUILT_IN_OMP_GET_NUM_THREADS,
BUILT_IN_OMP_GET_TEAM_NUM, and BUILT_IN_OMP_GET_NUM_TEAMS using
expand_builtin_omp_builtins, enabled under -fopenmp-target=acc.
* cgraphunit.cc (analyze_functions): Add call to
omp_ompacc_attribute_tagging, enabled under -fopenmp-target=acc.
* common.opt (fopenmp-target=): Add new option and enums.
* config/nvptx/mkoffload.cc (main): Handle -fopenmp-target=.
* config/nvptx/nvptx-protos.h (nvptx_expand_omp_get_num_threads): 
New
prototype.
(nvptx_mem_shared_p): Likewise.
* config/nvptx/nvptx.cc (omp_num_threads_sym): New global static RTX
symbol for number of threads in team.
(omp_num_threads_align): New var for alignment of 
omp_num_threads_sym.
(need_omp_num_threads): New bool for if any function references
omp_num_threads_sym.
(nvptx_option_override): Initialize omp_num_threads_sym/align.
(write_as_kernel): Disable normal OpenMP kernel entry under OMPACC 
mode.
(nvptx_declare_function_name): Disable shim function under OMPACC 
mode.
Disable soft-stack under OMPACC mode. Add generation of neutering 
init
code under OMPACC mode.
(nvptx_output_set_softstack): Return "" under OMPACC mode.
(nvptx_expand_call): Set parallelism to vector for function calls 
with
"ompacc for" attached.
(nvptx_expand_oacc_fork): Set mode to GOMP_DIM_VECTOR under OMPACC 
mode.
(nvptx_expand_oacc_join): Likewise.
(nvptx_expand_omp_get_num_threads): New function.
(nvptx_mem_shared_p): New function.
(nvptx_mach_max_workers): Return 1 under OMPACC mode.
(nvptx_mach_vector_length): Return 32 under OMPACC mode.
(nvptx_single): Add adjustments for OMPACC mode, which have
parallel-construct fork/joins, and regions of code where neutering 
is
dynamically determined.
(nvptx_reorg): Enable neutering under OMPACC mode when "ompacc for"
attribute is attached to function. Disable uniform-simt when under
OMPACC mode.
(nvptx_file_end): Write __nvptx_omp_num_threads out when needed.
(nvptx_goacc_fork_join): Return true under OMPACC mode.
* config/nvptx/nvptx.h (struct GTY(()) machine_function): Add
omp_parallel_predicate and omp_fn_entry_num_threads_reg fields.
* config/nvptx/nvptx.md (unspecv): Add UNSPECV_GET_TID,
UNSPECV_GET_NTID, UNSPECV_GET_CTAID, UNSPECV_GET_NCTAID,
UNSPECV_OMP_PARALLEL_FORK, UNSPECV_OMP_PARALLEL_JOIN entries.
(nvptx_shared_mem_operand): New predicate.
(gomp_barrier): New expand pattern.
(omp_get_num_threads): New expand pattern.
(omp_get_num_teams): New insn pattern.
(omp_get_thread_num): Likewise.
(omp_get_team_num): Likewise.
(get_ntid): Likewise.
(nvptx_omp_parallel_fork): Likewise.
(nvptx_omp_parallel_join): Likewise.

* flag-types.h (omp_target_mode_kind): New flag value enum.
* gimplify.cc (struct gimplify_omp_ctx): Add 'bool ompacc' field.
(gimplify_scan_omp_clauses): Handle OMP_CLAUSE__OMPACC_.
(gimplify_adjust_omp_clauses): Likewise.
(gimplify_omp_ctx_ompacc_p): New function.
(gimplify_omp_for): Handle combined loops under OMPACC.

* lto-wrapper.cc (append_compiler_options): Add OPT_fopenmp_target_.
* omp-builtins.def (BUILT_IN_OMP_GET_THREAD_NUM): Remove CONST.
(BUILT_IN_OMP_GET_NUM_THREADS): Likewise.
   

[gcc/devel/omp/gcc-14] OpenACC: Reimplement "inheritance" for lexically-nested offload regions

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:be1f186f0f3a45937be7e96bf6d65f372b045be7

commit be1f186f0f3a45937be7e96bf6d65f372b045be7
Author: Julian Brown 
Date:   Thu Jun 15 19:23:10 2023 +

OpenACC: Reimplement "inheritance" for lexically-nested offload regions

This patch reimplements "lexical inheritance" for OpenACC offload regions
inside "data" regions, allowing e.g. this to work:

  int *ptr;
  [...]
  #pragma acc data copyin(ptr[10:2])
  {
#pragma acc parallel
{ ... }
  }

here, the "copyin" is mirrored on the inner "acc parallel" as
"present(ptr[10:2])" -- allowing code within the parallel to use that
section of the array even though the mapping is implicit.

In terms of implementation, this works by expanding mapping nodes for
"acc data" to include pointer mappings that might be needed by inner
offload regions. The resulting mapping group is then copied to the inner
offload region as needed, rewriting the first node to "force_present".
The pointer mapping nodes are then removed from the "acc data" later
during gimplification.

For OpenMP, pointer mapping nodes on equivalent "omp data" regions are
not needed, so remain suppressed during expansion.

2023-06-16  Julian Brown  

gcc/c-family/
* c-omp.cc (c_omp_address_inspector::expand_array_base): Don't omit
pointer nodes for OpenACC.

gcc/
* gimplify.cc (omp_tsort_mark, omp_mapping_group): Move before
gimplify_omp_ctx. Add constructor to omp_mapping_group.
(gimplify_omp_ctx): Add DECL_DATA_CLAUSE field.
(new_omp_context, delete_omp_context): Initialise and free above 
field.
(omp_gather_mapping_groups_1): Use constructor for 
omp_mapping_group.
(gimplify_scan_omp_clauses): Record mappings that might be lexically
inherited.  Don't remove
GOMP_MAP_FIRSTPRIVATE_POINTER/GOMP_MAP_FIRSTPRIVATE_REFERENCE yet.
(gomp_oacc_needs_data_present): New function.
(gimplify_adjust_omp_clauses_1): Implement lexical inheritance
behaviour for OpenACC.
(gimplify_adjust_omp_clauses): Remove
GOMP_MAP_FIRSTPRIVATE_POINTER/GOMP_MAP_FIRSTPRIVATE_REFERENCE here
instead, after lexical inheritance is done.

gcc/testsuite/
* c-c++-common/goacc/acc-data-chain.c: New test.
* gfortran.dg/goacc/pr70828.f90: Likewise.
* gfortran.dg/goacc/assumed-size.f90: Likewise.

libgomp/
* testsuite/libgomp.oacc-c-c++-common/pr70828.c: New test.
* testsuite/libgomp.oacc-c-c++-common/pr70828-2.c: Likewise.
* testsuite/libgomp.oacc-fortran/pr70828.f90: Likewise.
* testsuite/libgomp.oacc-fortran/pr70828-2.f90: Likewise.
* testsuite/libgomp.oacc-fortran/pr70828-3.f90: Likewise.
* testsuite/libgomp.oacc-fortran/pr70828-4.f90: Likewise.
* testsuite/libgomp.oacc-fortran/pr70828-5.f90: Likewise.
* testsuite/libgomp.oacc-fortran/pr70828-6.f90: Likewise.

Diff:
---
 gcc/ChangeLog.omp  |  17 ++
 gcc/c-family/ChangeLog.omp |   7 +-
 gcc/c-family/c-omp.cc  |  13 +-
 gcc/gimplify.cc| 207 -
 gcc/testsuite/ChangeLog.omp|   6 +
 gcc/testsuite/c-c++-common/goacc/acc-data-chain.c  |  24 +++
 gcc/testsuite/gfortran.dg/goacc/assumed-size.f90   |  35 
 gcc/testsuite/gfortran.dg/goacc/pr70828.f90|  22 +++
 libgomp/ChangeLog.omp  |  11 ++
 .../libgomp.oacc-c-c++-common/pr70828-2.c  |  34 
 .../testsuite/libgomp.oacc-c-c++-common/pr70828.c  |  27 +++
 .../testsuite/libgomp.oacc-fortran/pr70828-2.f90   |  31 +++
 .../testsuite/libgomp.oacc-fortran/pr70828-3.f90   |  34 
 .../testsuite/libgomp.oacc-fortran/pr70828-4.f90   |  31 +++
 .../testsuite/libgomp.oacc-fortran/pr70828-5.f90   |  29 +++
 .../testsuite/libgomp.oacc-fortran/pr70828-6.f90   |  28 +++
 libgomp/testsuite/libgomp.oacc-fortran/pr70828.f90 |  24 +++
 17 files changed, 524 insertions(+), 56 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 381645ddf39..ac55142fa48 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,20 @@
+2023-06-19  Julian Brown  
+
+   * gimplify.cc (omp_tsort_mark, omp_mapping_group): Move before
+   gimplify_omp_ctx. Add constructor to omp_mapping_group.
+   (gimplify_omp_ctx): Add DECL_DATA_CLAUSE field.
+   (new_omp_context, delete_omp_context): Initialise and free above field.
+   (omp_gather_mapping_groups_1): Use constructor for omp_mapping_group.
+   (gimplify_scan_omp_clauses): Record mappings that might be lexically
+   inherited.  Don't remove
+   GOMP_MAP_FIRSTPRIVATE_POINTER/GOMP_MAP_FIRSTPRIVATE

[gcc/devel/omp/gcc-14] OpenACC: Allow implicit uses of assumed-size arrays in offload regions

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:5813266ee2fc9f9f9e90e44f72bde348411318e4

commit 5813266ee2fc9f9f9e90e44f72bde348411318e4
Author: Julian Brown 
Date:   Mon Jun 19 09:10:14 2023 +

OpenACC: Allow implicit uses of assumed-size arrays in offload regions

This patch reimplements the functionality of the previously-reverted
patch "Assumed-size arrays with non-lexical data mappings". The purpose
is to support implicit uses of assumed-size arrays for Fortran when those
arrays have already been mapped on the target some other way (e.g. by
"acc enter data").

This relates to upstream OpenACC issue 489 (not yet resolved).

2023-06-16  Julian Brown  

gcc/fortran/
* trans-openmp.cc (gfc_omp_finish_clause): Treat implicitly-mapped
assumed-size arrays as zero-sized for OpenACC, rather than an error.

gcc/testsuite/
* gfortran.dg/goacc/assumed-size.f90: Don't expect error.

libgomp/
* testsuite/libgomp.oacc-fortran/nonlexical-assumed-size-1.f90: New
test.
* testsuite/libgomp.oacc-fortran/nonlexical-assumed-size-2.f90: New
test.

Diff:
---
 gcc/fortran/ChangeLog.omp  |  5 +++
 gcc/fortran/trans-openmp.cc| 16 ++---
 gcc/testsuite/ChangeLog.omp|  4 +++
 gcc/testsuite/gfortran.dg/goacc/assumed-size.f90   |  4 +--
 libgomp/ChangeLog.omp  |  7 
 .../nonlexical-assumed-size-1.f90  | 28 +++
 .../nonlexical-assumed-size-2.f90  | 40 ++
 7 files changed, 98 insertions(+), 6 deletions(-)

diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp
index e28e1133d69..cbf99275a44 100644
--- a/gcc/fortran/ChangeLog.omp
+++ b/gcc/fortran/ChangeLog.omp
@@ -1,3 +1,8 @@
+2023-06-19  Julian Brown  
+
+   * trans-openmp.cc (gfc_omp_finish_clause): Treat implicitly-mapped
+   assumed-size arrays as zero-sized for OpenACC, rather than an error.
+
 2023-06-19  Julian Brown  
 
* trans-openmp.cc (gfc_omp_finish_clause): Handle "declare create" for
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index 33436bd9c5f..73441836fbc 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -1596,6 +1596,7 @@ gfc_omp_finish_clause (tree c, gimple_seq *pre_p, bool 
openacc)
 return;
 
   tree decl = OMP_CLAUSE_DECL (c);
+  bool assumed_size = false;
 
   /* Assumed-size arrays can't be mapped implicitly, they have to be
  mapped explicitly using array sections.  */
@@ -1606,9 +1607,14 @@ gfc_omp_finish_clause (tree c, gimple_seq *pre_p, bool 
openacc)
GFC_TYPE_ARRAY_RANK (TREE_TYPE (decl)) - 1)
 == NULL)
 {
-  error_at (OMP_CLAUSE_LOCATION (c),
-   "implicit mapping of assumed size array %qD", decl);
-  return;
+  if (openacc)
+   assumed_size = true;
+  else
+   {
+ error_at (OMP_CLAUSE_LOCATION (c),
+   "implicit mapping of assumed size array %qD", decl);
+ return;
+   }
 }
 
   if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR)
@@ -1663,7 +1669,9 @@ gfc_omp_finish_clause (tree c, gimple_seq *pre_p, bool 
openacc)
   else
{
  OMP_CLAUSE_DECL (c) = decl;
- OMP_CLAUSE_SIZE (c) = NULL_TREE;
+ OMP_CLAUSE_SIZE (c) = assumed_size ? size_zero_node : NULL_TREE;
+ if (assumed_size)
+   OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
}
   if (TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE
  && (GFC_DECL_GET_SCALAR_POINTER (orig_decl)
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 5bafd09b66f..55c2248f2ce 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,7 @@
+2023-06-19  Julian Brown  
+
+   * gfortran.dg/goacc/assumed-size.f90: Don't expect error.
+
 2023-06-19  Julian Brown  
 
* c-c++-common/goacc/acc-data-chain.c: New test.
diff --git a/gcc/testsuite/gfortran.dg/goacc/assumed-size.f90 
b/gcc/testsuite/gfortran.dg/goacc/assumed-size.f90
index 4fced2e70c9..12f44c4743a 100644
--- a/gcc/testsuite/gfortran.dg/goacc/assumed-size.f90
+++ b/gcc/testsuite/gfortran.dg/goacc/assumed-size.f90
@@ -4,7 +4,8 @@
 ! exit data, respectively.
 
 ! This does not appear to be supported by the OpenACC standard as of version
-! 3.0.  Check for an appropriate error message.
+! 3.0.  There is however real-world code that relies on this working, so we
+! make an attempt to support it.
 
 program test
   implicit none
@@ -26,7 +27,6 @@ subroutine dtest (a, n)
   !$acc enter data copyin(a(1:n))
 
   !$acc parallel loop
-! { dg-error {implicit mapping of assumed size array 'a'} "" { target *-*-* } 
.-1 }
   do i = 1, n
  a(i) = i
   end do
diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index ff49b4769de

[gcc/devel/omp/gcc-14] OpenACC: Improve implicit mapping for non-lexically nested offload regions

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:b918a7e4b4bdf070bfa9ede48ef9d22f89ff7795

commit b918a7e4b4bdf070bfa9ede48ef9d22f89ff7795
Author: Julian Brown 
Date:   Sat Jun 10 15:17:19 2023 +

OpenACC: Improve implicit mapping for non-lexically nested offload regions

This patch enables use of the OMP_CLAUSE_RUNTIME_IMPLICIT_P flag for
OpenACC.

This allows code like this to work correctly:

  int arr[100];
  [...]
  #pragma acc enter data copyin(arr[20:10])

  /* No explicit mapping of 'arr' here.  */
  #pragma acc parallel
  { /* use of arr[20:10]... */ }

  #pragma acc exit data copyout(arr[20:10])

Otherwise, the implicit "copy" ("present_or_copy") on the parallel
corresponds to the whole array, and that fails at runtime when the
subarray is mapped.

The numbering of the GOMP_MAP_IMPLICIT bit clashes with the OpenACC
"non-contiguous" dynamic array support, so the GOMP_MAP_NONCONTIG_ARRAY_P
macro has been adjusted to account for that.

This behaviour relates to upstream OpenACC issue 490 (not yet resolved).

2023-06-16  Julian Brown  

gcc/
* gimplify.cc (gimplify_adjust_omp_clauses_1): Set
OMP_CLAUSE_MAP_RUNTIME_IMPLICIT_P for OpenACC also.

gcc/testsuite/
* c-c++-common/goacc/combined-reduction.c: Adjust scan output.
* c-c++-common/goacc/reduction-1.c: Likewise.
* c-c++-common/goacc/reduction-2.c: Likewise.
* c-c++-common/goacc/reduction-3.c: Likewise.
* c-c++-common/goacc/reduction-4.c: Likewise.
* c-c++-common/goacc/reduction-10.c: Likewise.
* gfortran.dg/goacc/loop-tree-1.f90: Likewise.

include/
* gomp-constants.h (GOMP_MAP_NONCONTIG_ARRAY_P): Tweak condition.

libgomp/
* testsuite/libgomp.oacc-c-c++-common/implicit-mapping-1.c: New 
test.

Diff:
---
 gcc/ChangeLog.omp  |  5 +
 gcc/gimplify.cc|  5 +
 gcc/testsuite/ChangeLog.omp| 10 +
 .../c-c++-common/goacc/combined-reduction.c|  2 +-
 gcc/testsuite/c-c++-common/goacc/reduction-1.c |  4 ++--
 gcc/testsuite/c-c++-common/goacc/reduction-10.c|  9 
 gcc/testsuite/c-c++-common/goacc/reduction-2.c |  4 ++--
 gcc/testsuite/c-c++-common/goacc/reduction-3.c |  4 ++--
 gcc/testsuite/c-c++-common/goacc/reduction-4.c |  4 ++--
 gcc/testsuite/gfortran.dg/goacc/loop-tree-1.f90|  2 +-
 include/ChangeLog.omp  |  4 
 include/gomp-constants.h   |  3 ++-
 libgomp/ChangeLog.omp  |  4 
 .../libgomp.oacc-c-c++-common/implicit-mapping-1.c | 24 ++
 14 files changed, 65 insertions(+), 19 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 05120c5266d..4f8af8bfaa4 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,8 @@
+2023-06-19  Julian Brown  
+
+   * gimplify.cc (gimplify_adjust_omp_clauses_1): Set
+   OMP_CLAUSE_MAP_RUNTIME_IMPLICIT_P for OpenACC also.
+
 2023-06-19  Julian Brown  
 
* gimplify.cc (gimplify_adjust_omp_clauses_1): Handle "oacc declare
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index efa28440a80..f46b5884619 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -13903,10 +13903,7 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, void 
*data)
  gcc_unreachable ();
}
   OMP_CLAUSE_SET_MAP_KIND (clause, kind);
-  /* Setting of the implicit flag for the runtime is currently disabled for
-OpenACC.  */
-  if ((gimplify_omp_ctxp->region_type & ORT_ACC) == 0)
-   OMP_CLAUSE_MAP_RUNTIME_IMPLICIT_P (clause) = 1;
+  OMP_CLAUSE_MAP_RUNTIME_IMPLICIT_P (clause) = 1;
   if (DECL_SIZE (decl)
  && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
{
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 55c2248f2ce..d264a017242 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,13 @@
+2023-06-19  Julian Brown  
+
+   * c-c++-common/goacc/combined-reduction.c: Adjust scan output.
+   * c-c++-common/goacc/reduction-1.c: Likewise.
+   * c-c++-common/goacc/reduction-2.c: Likewise.
+   * c-c++-common/goacc/reduction-3.c: Likewise.
+   * c-c++-common/goacc/reduction-4.c: Likewise.
+   * c-c++-common/goacc/reduction-10.c: Likewise.
+   * gfortran.dg/goacc/loop-tree-1.f90: Likewise.
+
 2023-06-19  Julian Brown  
 
* gfortran.dg/goacc/assumed-size.f90: Don't expect error.
diff --git a/gcc/testsuite/c-c++-common/goacc/combined-reduction.c 
b/gcc/testsuite/c-c++-common/goacc/combined-reduction.c
index ecf23f59d66..40b93acc9ea 100644
--- a/gcc/testsuite/c-c++-common/goacc/combined-reduction.c
+++ b/gcc/testsuite/c-c++-common/goacc/combined-reduction.c
@@ -25,5 +25,5 @@ main 

[gcc/devel/omp/gcc-14] OpenACC: "declare create" fixes wrt. "allocatable" variables

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:4e14dd9c20db032fb77cc59fa3e5dc9a18ca533f

commit 4e14dd9c20db032fb77cc59fa3e5dc9a18ca533f
Author: Julian Brown 
Date:   Sat Jun 10 07:53:57 2023 +

OpenACC: "declare create" fixes wrt. "allocatable" variables

This patch fixes a case revealed by the previous patch where a synthetic
"acc data" region created for a "declare create" variable could interact
strangely with lexical inheritance behaviour.  In fact, it doesn't seem
right to create the "acc data" region for allocatable variables at all
-- doing so means that a data region is likely to be created for an
unallocated variable.

The fix is not to add such variables to the synthetic "acc data" region
at all, and defer to the code that performs "enter data"/"exit data"
for them when allocated/deallocated on the host instead. Then, "declare
create" variables are implicitly turned into "present" clauses on in-scope
offload regions.

2023-06-16  Julian Brown  

gcc/fortran/
* trans-openmp.cc (gfc_omp_finish_clause): Handle "declare create" 
for
scalar allocatable variables.
(gfc_trans_omp_clauses): Don't include allocatable vars in synthetic
"acc data" region created for "declare create" variables.  Mark such
variables with the "oacc declare create" attribute instead.  Don't
create ALWAYS_POINTER mapping for target-to-host updates of declare
create variables.
(gfc_trans_oacc_declare): Handle empty clause list.

gcc/
* gimplify.cc (gimplify_adjust_omp_clauses_1): Handle "oacc declare
create" attribute.

libgomp/
* testsuite/libgomp.oacc-fortran/declare-create-1.f90: New test.
* testsuite/libgomp.oacc-fortran/declare-create-2.f90: New test.
* testsuite/libgomp.oacc-fortran/declare-create-3.f90: New test.

Diff:
---
 gcc/ChangeLog.omp  |  5 +++
 gcc/fortran/ChangeLog.omp  | 11 ++
 gcc/fortran/trans-openmp.cc| 45 +++---
 gcc/gimplify.cc|  8 
 libgomp/ChangeLog.omp  |  6 +++
 .../libgomp.oacc-fortran/declare-create-1.f90  | 21 ++
 .../libgomp.oacc-fortran/declare-create-2.f90  | 25 
 .../libgomp.oacc-fortran/declare-create-3.f90  | 25 
 8 files changed, 141 insertions(+), 5 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index ac55142fa48..05120c5266d 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,8 @@
+2023-06-19  Julian Brown  
+
+   * gimplify.cc (gimplify_adjust_omp_clauses_1): Handle "oacc declare
+   create" attribute.
+
 2023-06-19  Julian Brown  
 
* gimplify.cc (omp_tsort_mark, omp_mapping_group): Move before
diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp
index 04c900a3ee3..e28e1133d69 100644
--- a/gcc/fortran/ChangeLog.omp
+++ b/gcc/fortran/ChangeLog.omp
@@ -1,3 +1,14 @@
+2023-06-19  Julian Brown  
+
+   * trans-openmp.cc (gfc_omp_finish_clause): Handle "declare create" for
+   scalar allocatable variables.
+   (gfc_trans_omp_clauses): Don't include allocatable vars in synthetic
+   "acc data" region created for "declare create" variables.  Mark such
+   variables with the "oacc declare create" attribute instead.  Don't
+   create ALWAYS_POINTER mapping for target-to-host updates of declare
+   create variables.
+   (gfc_trans_oacc_declare): Handle empty clause list.
+
 2024-06-05  Jakub Jelinek  
Frederik Harwath  
Sandra Loosemore  
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index 71a8fff7496..33436bd9c5f 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -1628,7 +1628,16 @@ gfc_omp_finish_clause (tree c, gimple_seq *pre_p, bool 
openacc)
   orig_decl = decl;
 
   c4 = build_omp_clause (OMP_CLAUSE_LOCATION (c), OMP_CLAUSE_MAP);
-  OMP_CLAUSE_SET_MAP_KIND (c4, GOMP_MAP_POINTER);
+  if (openacc
+ && GFC_DECL_GET_SCALAR_ALLOCATABLE (decl)
+ && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_PRESENT)
+   /* This allows "declare create" to work for scalar allocatables.  The
+  resulting mapping nodes are:
+force_present(*var) firstprivate_pointer(var)
+  which is the same as an explicit "present" clause gives.  */
+   OMP_CLAUSE_SET_MAP_KIND (c4, GOMP_MAP_FIRSTPRIVATE_POINTER);
+  else
+   OMP_CLAUSE_SET_MAP_KIND (c4, GOMP_MAP_POINTER);
   OMP_CLAUSE_DECL (c4) = decl;
   OMP_CLAUSE_SIZE (c4) = size_int (0);
   decl = build_fold_indirect_ref (decl);
@@ -4579,6 +4588,29 @@ gfc_trans_omp_clauses (stmtblock_t *block, 
gfc_omp_clauses *clauses,
  if (!n->sym->attr.referenced)
continue;
 
+   

[gcc/devel/omp/gcc-14] OpenMP: C++ "declare mapper" support

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:b1536b2e60373c02e49b94e9c567be0ad0a6d792

commit b1536b2e60373c02e49b94e9c567be0ad0a6d792
Author: Julian Brown 
Date:   Thu Feb 3 12:38:12 2022 -0800

OpenMP: C++ "declare mapper" support

This patch adds support for OpenMP 5.0 "declare mapper" functionality
for C++.  I've merged it to og13 based on the last version
posted upstream, with some minor changes due to the newly-added
'present' map modifier support.  There's also a fix to splay-tree
traversal in gimplify.cc:omp_instantiate_implicit_mappers, and this patch
omits the rearrangement of gimplify.cc:gimplify_{scan,adjust}_omp_clauses
that I separated out into its own patch and applied (to og13) already.

2023-06-30  Julian Brown  

gcc/c-family/
* c-common.h (omp_mapper_list): Add forward declaration.
(c_omp_find_nested_mappers, c_omp_instantiate_mappers): Add 
prototypes.
* c-omp.cc (c_omp_find_nested_mappers): New function.
(remap_mapper_decl_info): New struct.
(remap_mapper_decl_1, omp_instantiate_mapper,
c_omp_instantiate_mappers): New functions.

gcc/cp/
* constexpr.cc (reduced_constant_expression_p): Add 
OMP_DECLARE_MAPPER
case.
(cxx_eval_constant_expression, potential_constant_expression_1):
Likewise.
* cp-gimplify.cc (cxx_omp_finish_mapper_clauses): New function.
* cp-objcp-common.h (LANG_HOOKS_OMP_FINISH_MAPPER_CLAUSES,
LANG_HOOKS_OMP_MAPPER_LOOKUP, 
LANG_HOOKS_OMP_EXTRACT_MAPPER_DIRECTIVE,
LANG_HOOKS_OMP_MAP_ARRAY_SECTION): Define langhooks.
* cp-tree.h (lang_decl_base): Add omp_declare_mapper_p field.  
Recount
spare bits comment.
(DECL_OMP_DECLARE_MAPPER_P): New macro.
(omp_mapper_id, cp_check_omp_declare_mapper, 
omp_instantiate_mappers,
cxx_omp_finish_mapper_clauses, cxx_omp_mapper_lookup,
cxx_omp_extract_mapper_directive, cxx_omp_map_array_section: Add
prototypes.
* decl.cc (check_initializer): Add OpenMP declare mapper support.
(cp_finish_decl): Set DECL_INITIAL for OpenMP declare mapper var 
decls
as appropriate.
* decl2.cc (mark_used): Instantiate OpenMP "declare mapper" magic 
var
decls.
* error.cc (dump_omp_declare_mapper): New function.
(dump_simple_decl): Use above.
* parser.cc (cp_parser_omp_clause_map): Add KIND parameter.  Support
"mapper" modifier.
(cp_parser_omp_all_clauses): Add KIND argument to
cp_parser_omp_clause_map call.
(cp_parser_omp_target): Call omp_instantiate_mappers before
finish_omp_clauses.
(cp_parser_omp_declare_mapper): New function.
(cp_parser_omp_declare): Add "declare mapper" support.
* pt.cc (tsubst_decl): Adjust name of "declare mapper" magic var 
decls
once we know their type.
(tsubst_omp_clauses): Call omp_instantiate_mappers before
finish_omp_clauses, for target regions.
(tsubst_expr): Support OMP_DECLARE_MAPPER nodes.
(instantiate_decl): Instantiate initialiser (i.e definition) for 
OpenMP
declare mappers.
* semantics.cc (gimplify.h): Include.
(omp_mapper_id, omp_mapper_lookup, omp_extract_mapper_directive,
cxx_omp_map_array_section, cp_check_omp_declare_mapper): New 
functions.
(finish_omp_clauses): Delete GOMP_MAP_PUSH_MAPPER_NAME and
GOMP_MAP_POP_MAPPER_NAME artificial clauses.
(omp_target_walk_data): Add MAPPERS field.
(finish_omp_target_clauses_r): Scan for uses of struct/union/class 
type
variables.
(finish_omp_target_clauses): Create artificial mapper binding 
clauses
for used structs/unions/classes in offload region.

gcc/fortran/
* parse.cc (tree.h, fold-const.h, tree-hash-traits.h): Add includes
(for additions to omp-general.h).

gcc/
* gimplify.cc (gimplify_omp_ctx): Add IMPLICIT_MAPPERS field.
(new_omp_context): Initialise IMPLICIT_MAPPERS hash map.
(delete_omp_context): Delete IMPLICIT_MAPPERS hash map.
(instantiate_mapper_info): New structs.
(remap_mapper_decl_1, omp_mapper_copy_decl, omp_instantiate_mapper,
omp_instantiate_implicit_mappers): New functions.
(gimplify_scan_omp_clauses): Handle MAPPER_BINDING clauses.
(gimplify_adjust_omp_clauses): Instantiate implicit declared 
mappers.
(gimplify_omp_declare_mapper): New function.
(gimplify_expr): Call above function.
* langhooks-def.h (lhd_omp_finish_mapper_clauses,
lhd_omp_mapper_lookup, lhd_omp_extract_mapper_directive,
lhd_omp_map_arra

[gcc/devel/omp/gcc-14] OpenMP: Support OpenMP 5.0 "declare mapper" directives for C

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:a32ca2311855534cab7e072f6497b93c8f9b22e0

commit a32ca2311855534cab7e072f6497b93c8f9b22e0
Author: Julian Brown 
Date:   Thu Feb 17 15:58:27 2022 -0800

OpenMP: Support OpenMP 5.0 "declare mapper" directives for C

This patch adds support for "declare mapper" directives (and the "mapper"
modifier on "map" clauses) for C.

2023-06-30  Julian Brown  

gcc/c/
* c-decl.cc (c_omp_mapper_id, c_omp_mapper_decl, 
c_omp_mapper_lookup,
c_omp_extract_mapper_directive, c_omp_map_array_section,
c_omp_scan_mapper_bindings_r, c_omp_scan_mapper_bindings): New
functions.
* c-objc-common.h (LANG_HOOKS_OMP_FINISH_MAPPER_CLAUSES,
LANG_HOOKS_OMP_MAPPER_LOOKUP, 
LANG_HOOKS_OMP_EXTRACT_MAPPER_DIRECTIVE,
LANG_HOOKS_OMP_MAP_ARRAY_SECTION): Define langhooks for C.
* c-parser.cc (c_parser_omp_clause_map): Add KIND parameter.  Handle
mapper modifier.
(c_parser_omp_all_clauses): Update call to c_parser_omp_clause_map 
with
new kind argument.
(c_parser_omp_target): Instantiate explicit mappers and record 
bindings
for implicit mappers.
(c_parser_omp_declare_mapper): Parse "declare mapper" directives.
(c_parser_omp_declare): Support "declare mapper".
* c-tree.h (c_omp_finish_mapper_clauses, c_omp_mapper_lookup,
c_omp_extract_mapper_directive, c_omp_map_array_section,
c_omp_mapper_id, c_omp_mapper_decl, c_omp_scan_mapper_bindings,
c_omp_instantiate_mappers): Add prototypes.
* c-typeck.cc (c_finish_omp_clauses): Handle 
GOMP_MAP_PUSH_MAPPER_NAME
and GOMP_MAP_POP_MAPPER_NAME.
(c_omp_finish_mapper_clauses): New function (langhook).

gcc/testsuite/
* c-c++-common/gomp/declare-mapper-4.c: Enable for C.
* c-c++-common/gomp/declare-mapper-5.c: Likewise.
* c-c++-common/gomp/declare-mapper-6.c: Likewise.
* c-c++-common/gomp/declare-mapper-7.c: Likewise.
* c-c++-common/gomp/declare-mapper-8.c: Likewise.
* c-c++-common/gomp/declare-mapper-9.c: Likewise.
* c-c++-common/gomp/declare-mapper-12.c: Enable for C.
* gcc.dg/gomp/declare-mapper-10.c: New test.
* gcc.dg/gomp/declare-mapper-11.c: New test.

libgomp/
* testsuite/libgomp.c-c++-common/declare-mapper-9.c: Enable for C.
* testsuite/libgomp.c-c++-common/declare-mapper-10.c: Likewise.
* testsuite/libgomp.c-c++-common/declare-mapper-11.c: Likewise.
* testsuite/libgomp.c-c++-common/declare-mapper-12.c: Likewise.
* testsuite/libgomp.c-c++-common/declare-mapper-13.c: Likewise.
* testsuite/libgomp.c-c++-common/declare-mapper-14.c: Likewise.

Diff:
---
 gcc/c/ChangeLog.omp|  25 ++
 gcc/c/c-decl.cc| 169 +
 gcc/c/c-objc-common.h  |  12 +
 gcc/c/c-parser.cc  | 279 +++--
 gcc/c/c-tree.h |   8 +
 gcc/c/c-typeck.cc  |  15 ++
 gcc/testsuite/ChangeLog.omp|  12 +
 .../c-c++-common/gomp/declare-mapper-12.c  |   2 +-
 gcc/testsuite/c-c++-common/gomp/declare-mapper-4.c |   2 +-
 gcc/testsuite/c-c++-common/gomp/declare-mapper-5.c |   2 +-
 gcc/testsuite/c-c++-common/gomp/declare-mapper-6.c |   2 +-
 gcc/testsuite/c-c++-common/gomp/declare-mapper-7.c |   2 +-
 gcc/testsuite/c-c++-common/gomp/declare-mapper-8.c |   2 +-
 gcc/testsuite/c-c++-common/gomp/declare-mapper-9.c |   2 +-
 gcc/testsuite/gcc.dg/gomp/declare-mapper-10.c  |  61 +
 gcc/testsuite/gcc.dg/gomp/declare-mapper-11.c  |  33 +++
 libgomp/ChangeLog.omp  |   9 +
 .../libgomp.c-c++-common/declare-mapper-10.c   |   2 +-
 .../libgomp.c-c++-common/declare-mapper-11.c   |   2 +-
 .../libgomp.c-c++-common/declare-mapper-12.c   |   2 +-
 .../libgomp.c-c++-common/declare-mapper-13.c   |   2 +-
 .../libgomp.c-c++-common/declare-mapper-14.c   |   2 +-
 .../libgomp.c-c++-common/declare-mapper-9.c|   2 +-
 23 files changed, 619 insertions(+), 30 deletions(-)

diff --git a/gcc/c/ChangeLog.omp b/gcc/c/ChangeLog.omp
index 74bde236cd1..b1301ae43c9 100644
--- a/gcc/c/ChangeLog.omp
+++ b/gcc/c/ChangeLog.omp
@@ -1,3 +1,28 @@
+2023-06-30  Julian Brown  
+
+   * c-decl.cc (c_omp_mapper_id, c_omp_mapper_decl, c_omp_mapper_lookup,
+   c_omp_extract_mapper_directive, c_omp_map_array_section,
+   c_omp_scan_mapper_bindings_r, c_omp_scan_mapper_bindings): New
+   functions.
+   * c-objc-common.h (LANG_HOOKS_OMP_FINISH_MAPPER_CLAUSES,
+   LANG_HOOKS_OMP_MAPPER_LOOKUP, LANG_HOOKS_OMP_EXTRACT_MAPPER_DIRECTIVE,
+   LANG_HOOKS_OMP_MAP_ARRAY_

[gcc/devel/omp/gcc-14] OpenMP: Expand "declare mapper" mappers for target {enter, exit, } data directives

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:1188d7e329d329d0e92534fcc8c739450d3d6eae

commit 1188d7e329d329d0e92534fcc8c739450d3d6eae
Author: Julian Brown 
Date:   Mon Jul 3 19:07:11 2023 +

OpenMP: Expand "declare mapper" mappers for target {enter,exit,} data 
directives

This patch allows 'declare mapper' mappers to be used on 'omp target
data', 'omp target enter data' and 'omp target exit data' directives.
For each of these, only explicit mappings are supported, unlike for
'omp target' directives where implicit uses of variables inside an
offload region might trigger mappers also.

Each of C, C++ and Fortran are supported.

The patch also adjusts 'map kind decay' to match OpenMP 5.2 semantics,
which is particularly important with regard to 'exit data' operations.

2023-07-06  Julian Brown  

gcc/c-family/
* c-common.h (c_omp_region_type): Add C_ORT_EXIT_DATA,
C_ORT_OMP_EXIT_DATA.
(c_omp_instantiate_mappers): Add region type parameter.
* c-omp.cc (omp_split_map_kind, omp_join_map_kind,
omp_map_decayed_kind): New functions.
(omp_instantiate_mapper): Add ORT parameter.  Implement map kind 
decay
for instantiated mapper clauses.
(c_omp_instantiate_mappers): Add ORT parameter, pass to
omp_instantiate_mapper.

gcc/c/
* c-parser.cc (c_parser_omp_target_data): Instantiate mappers for
'omp target data'.
(c_parser_omp_target_enter_data): Instantiate mappers for 'omp 
target
enter data'.
(c_parser_omp_target_exit_data): Instantiate mappers for 'omp target
exit data'.
(c_parser_omp_target): Add c_omp_region_type argument to
c_omp_instantiate_mappers call.
* c-tree.h (c_omp_instantiate_mappers): Remove spurious prototype.

gcc/cp/
* parser.cc (cp_parser_omp_target_data): Instantiate mappers for 
'omp
target data'.
(cp_parser_omp_target_enter_data): Instantiate mappers for 'omp 
target
enter data'.
(cp_parser_omp_target_exit_data): Instantiate mappers for 'omp 
target
exit data'.
(cp_parser_omp_target): Add c_omp_region_type argument to
c_omp_instantiate_mappers call.
* pt.cc (tsubst_omp_clauses): Instantiate mappers for OMP regions 
other
than just C_ORT_OMP_TARGET.
(tsubst_expr): Update call to tsubst_omp_clauses for 
OMP_TARGET_UPDATE,
OMP_TARGET_ENTER_DATA, OMP_TARGET_EXIT_DATA stanza.
* semantics.cc (cxx_omp_map_array_section): Avoid calling
build_array_ref for non-array/non-pointer bases (error reported
already).

gcc/fortran/
* trans-openmp.cc (omp_split_map_op, omp_join_map_op,
omp_map_decayed_kind): New functions.
(gfc_trans_omp_instantiate_mapper): Add CD parameter.  Implement map
kind decay.
(gfc_trans_omp_instantiate_mappers): Add CD parameter.  Pass to 
above
function.
(gfc_trans_omp_target_data): Instantiate mappers for 'omp target 
data'.
(gfc_trans_omp_target_enter_data): Instantiate mappers for 'omp 
target
enter data'.
(gfc_trans_omp_target_exit_data): Instantiate mappers for 'omp 
target
exit data'.

gcc/testsuite/
* c-c++-common/gomp/declare-mapper-15.c: New test.
* c-c++-common/gomp/declare-mapper-16.c: New test.
* g++.dg/gomp/declare-mapper-1.C: Adjust expected scan output.
* gfortran.dg/gomp/declare-mapper-22.f90: New test.
* gfortran.dg/gomp/declare-mapper-23.f90: New test.

Diff:
---
 gcc/c-family/ChangeLog.omp |  12 ++
 gcc/c-family/c-common.h|   2 +-
 gcc/c-family/c-omp.cc  | 193 ++-
 gcc/c/ChangeLog.omp|  12 ++
 gcc/c/c-parser.cc  |  11 +-
 gcc/c/c-tree.h |   1 -
 gcc/cp/ChangeLog.omp   |  18 ++
 gcc/cp/parser.cc   |  15 +-
 gcc/cp/pt.cc   |   8 +-
 gcc/cp/semantics.cc|   5 +-
 gcc/fortran/ChangeLog.omp  |  14 ++
 gcc/fortran/trans-openmp.cc| 209 +++--
 gcc/testsuite/ChangeLog.omp|   8 +
 .../c-c++-common/gomp/declare-mapper-15.c  |  59 ++
 .../c-c++-common/gomp/declare-mapper-16.c  |  39 
 gcc/testsuite/g++.dg/gomp/declare-mapper-1.C   |   2 +-
 .../gfortran.dg/gomp/declare-mapper-22.f90 |  60 ++
 .../gfortran.dg/gomp/declare-mapper-23.f90 |  25 +++
 18 files changed, 657 insertions(+

[gcc/devel/omp/gcc-14] OpenMP: Fortran "!$omp declare mapper" support

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:015cb4002d6c022b33234e6098303edf159fb19e

commit 015cb4002d6c022b33234e6098303edf159fb19e
Author: Julian Brown 
Date:   Tue Nov 29 22:01:49 2022 +

OpenMP: Fortran "!$omp declare mapper" support

This patch implements "omp declare mapper" functionality for Fortran,
following the equivalent support for C and C++.  This version of the
patch has been merged to og13 and contains various fixes for e.g.:

  * Mappers with deferred-length strings

  * Array descriptors not being appropriately transferred
to the offload target (see "OMP_MAP_POINTER_ONLY" and
gimplify.cc:omp_maybe_get_descriptor_from_ptr).

2023-06-30  Julian Brown  

gcc/fortran/
* dump-parse-tree.cc (show_attr): Show omp_udm_artificial_var flag.
(show_omp_namelist): Support OMP_MAP_POINTER_ONLY and OMP_MAP_UNSET.
* f95-lang.cc (LANG_HOOKS_OMP_FINISH_MAPPER_CLAUSES,
LANG_HOOKS_OMP_EXTRACT_MAPPER_DIRECTIVE,
LANG_HOOKS_OMP_MAP_ARRAY_SECTION): Define language hooks.
* gfortran.h (gfc_statement): Add ST_OMP_DECLARE_MAPPER.
(symbol_attribute): Add omp_udm_artificial_var attribute.
(gfc_omp_map_op): Add OMP_MAP_POINTER_ONLY and OMP_MAP_UNSET.
(gfc_omp_namelist): Add udm pointer to u2 union.
(gfc_omp_udm): New struct.
(gfc_omp_namelist_udm): New struct.
(gfc_symtree): Add omp_udm pointer.
(gfc_namespace): Add omp_udm_root symtree. Add omp_udm_ns flag.
(gfc_free_omp_namelist): Update prototype.
(gfc_free_omp_udm, gfc_omp_udm_find, gfc_find_omp_udm,
gfc_resolve_omp_udms): Add prototypes.
* match.cc (gfc_free_omp_namelist): Change FREE_NS and FREE_ALIGN
parameters to LIST number, to handle freeing user-defined mapper
namelists safely.
* match.h (gfc_match_omp_declare_mapper): Add prototype.
* module.cc (ab_attribute): Add AB_OMP_DECLARE_MAPPER_VAR.
(attr_bits): Add OMP_DECLARE_MAPPER_VAR.
(mio_symbol_attribute): Read/write AB_OMP_DECLARE_MAPPER_VAR 
attribute.
Set referenced attr on read.
(omp_map_clause_ops, omp_map_cardinality): New arrays.
(load_omp_udms, check_omp_declare_mappers): New functions.
(read_module): Load and check OMP declare mappers.
(write_omp_udm, write_omp_udms): New functions.
(write_module): Write OMP declare mappers.
* openmp.cc (gfc_free_omp_clauses, gfc_match_omp_variable_list,
gfc_match_omp_to_link, gfc_match_omp_depend_sink,
gfc_match_omp_clause_reduction): Update calls to 
gfc_free_omp_namelist.
(gfc_free_omp_udm, gfc_find_omp_udm, gfc_omp_udm_find,
gfc_match_omp_declare_mapper): New functions.
(gfc_match_omp_clauses): Add DEFAULT_MAP_OP parameter. Update calls 
to
gfc_free_omp_namelist.  Add declare mapper support.
(resolve_omp_clauses): Add declare mapper support.  Update calls to
gfc_free_omp_namelist.
(gfc_resolve_omp_udm, gfc_resolve_omp_udms): New functions.
* parse.cc (decode_omp_directive): Add declare mapper support.
(case_omp_decl): Add ST_OMP_DECLARE_MAPPER case.
(gfc_ascii_statement): Add ST_OMP_DECLARE_MAPPER case.
* resolve.cc (resolve_types): Call gfc_resolve_omp_udms.
* st.cc (gfc_free_statement): Update call to gfc_free_omp_namelist.
* symbol.cc (free_omp_udm_tree): New function.
(gfc_free_namespace): Call above.
* trans-decl.cc (omp_declare_mapper_ns): New global.
(gfc_finish_var_decl, gfc_generate_function_code): Support declare
mappers.
(gfc_trans_deferred_vars): Ignore artificial declare-mapper vars.
* trans-openmp.cc (tree-iterator.h): Include.
(toc_directive): New enum.
(gfc_trans_omp_array_section): Change OP and OPENMP parameters to
toc_directive CD ('clause directive').
(gfc_omp_finish_mapper_clauses, gfc_omp_extract_mapper_directive,
gfc_omp_map_array_section): New functions.
(omp_clause_directive): New enum.
(gfc_trans_omp_clauses): Remove DECLARE_SIMD and OPENACC parameters.
Replace with toc_directive CD, defaulting to TOC_OPENMP.  Add 
declare
mapper support and OMP_MAP_POINTER_ONLY support.
(gfc_trans_omp_construct, gfc_trans_oacc_executable_directive,
gfc_trans_oacc_combined_directive): Update calls to
gfc_trans_omp_clauses.
(gfc_subst_replace, gfc_subst_prepend_ref): New variables.
(gfc_subst_in_expr_1, gfc_subst_in_expr, gfc_subst_mapper_var,
gfc_trans_omp_instantiate_mapper, gfc_trans_omp_instantiate_mappers,
gfc_r

[gcc/devel/omp/gcc-14] OpenACC: Vector length warning fixes for implicit mapping/declare create tests

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:c6d93a417a8c5c9037f5e80e0099e9570eb2c919

commit c6d93a417a8c5c9037f5e80e0099e9570eb2c919
Author: Julian Brown 
Date:   Tue Jul 11 13:25:29 2023 +

OpenACC: Vector length warning fixes for implicit mapping/declare create 
tests

This patch adds expected "vector length" warnings to several tests
for NVPTX.

2023-07-11  Julian Brown  

libgomp/
* testsuite/libgomp.oacc-c-c++-common/implicit-mapping-1.c: Add
expected warning.
* testsuite/libgomp.oacc-fortran/declare-create-1.f90: Likewise.
* testsuite/libgomp.oacc-fortran/declare-create-2.f90: Likewise.
* testsuite/libgomp.oacc-fortran/declare-create-3.f90: Likewise.
* testsuite/libgomp.oacc-fortran/nonlexical-assumed-size-1.f90:
Likewise.
* testsuite/libgomp.oacc-fortran/nonlexical-assumed-size-2.f90:
Likewise.

Diff:
---
 libgomp/ChangeLog.omp| 12 
 .../testsuite/libgomp.oacc-c-c++-common/implicit-mapping-1.c |  1 +
 libgomp/testsuite/libgomp.oacc-fortran/declare-create-1.f90  |  1 +
 libgomp/testsuite/libgomp.oacc-fortran/declare-create-2.f90  |  1 +
 libgomp/testsuite/libgomp.oacc-fortran/declare-create-3.f90  |  1 +
 .../libgomp.oacc-fortran/nonlexical-assumed-size-1.f90   |  1 +
 .../libgomp.oacc-fortran/nonlexical-assumed-size-2.f90   |  1 +
 7 files changed, 18 insertions(+)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index b89cb1c846f..1294fe39c4c 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,15 @@
+2023-07-12  Julian Brown  
+
+   * testsuite/libgomp.oacc-c-c++-common/implicit-mapping-1.c: Add
+   expected warning.
+   * testsuite/libgomp.oacc-fortran/declare-create-1.f90: Likewise.
+   * testsuite/libgomp.oacc-fortran/declare-create-2.f90: Likewise.
+   * testsuite/libgomp.oacc-fortran/declare-create-3.f90: Likewise.
+   * testsuite/libgomp.oacc-fortran/nonlexical-assumed-size-1.f90:
+   Likewise.
+   * testsuite/libgomp.oacc-fortran/nonlexical-assumed-size-2.f90:
+   Likewise.
+
 2023-06-30  Julian Brown  
 
* testsuite/libgomp.fortran/declare-mapper-2.f90: New test.
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/implicit-mapping-1.c 
b/libgomp/testsuite/libgomp.oacc-c-c++-common/implicit-mapping-1.c
index 4825e875998..ed0ab94cd8f 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/implicit-mapping-1.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/implicit-mapping-1.c
@@ -12,6 +12,7 @@ int main(void)
 #pragma acc enter data copyin(arr[30:10])
 
 #pragma acc serial
+/* { dg-warning {using .vector_length \(32\)., ignoring 1} "" { target 
openacc_nvidia_accel_selected } .-1 } */
   {
 arr[33] = 66;
   }
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/declare-create-1.f90 
b/libgomp/testsuite/libgomp.oacc-fortran/declare-create-1.f90
index 9e7e60f1440..057b5eb958a 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/declare-create-1.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/declare-create-1.f90
@@ -11,6 +11,7 @@ use m
 mint = 0
 
 !$acc serial
+! { dg-warning {using .vector_length \(32\)., ignoring 1} "" { target 
openacc_nvidia_accel_selected } .-1 }
 mint = 5
 !$acc end serial
 
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/declare-create-2.f90 
b/libgomp/testsuite/libgomp.oacc-fortran/declare-create-2.f90
index 675f6902775..dd7c9798fba 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/declare-create-2.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/declare-create-2.f90
@@ -13,6 +13,7 @@ allocate(mint)
 mint = 0
 
 !$acc serial
+! { dg-warning {using .vector_length \(32\)., ignoring 1} "" { target 
openacc_nvidia_accel_selected } .-1 }
 mint = 5
 !$acc end serial
 
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/declare-create-3.f90 
b/libgomp/testsuite/libgomp.oacc-fortran/declare-create-3.f90
index 16651cb1f5e..7cceaa5f8a3 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/declare-create-3.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/declare-create-3.f90
@@ -13,6 +13,7 @@ allocate(mint(1:20))
 mint = 0
 
 !$acc serial
+! { dg-warning {using .vector_length \(32\)., ignoring 1} "" { target 
openacc_nvidia_accel_selected } .-1 }
 mint = 5
 !$acc end serial
 
diff --git 
a/libgomp/testsuite/libgomp.oacc-fortran/nonlexical-assumed-size-1.f90 
b/libgomp/testsuite/libgomp.oacc-fortran/nonlexical-assumed-size-1.f90
index 4b61e1cee9b..8b173c72d88 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/nonlexical-assumed-size-1.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/nonlexical-assumed-size-1.f90
@@ -19,6 +19,7 @@ integer :: arr(*)
 !$acc enter data copyin(arr(1:10))
 
 !$acc serial
+! { dg-warning {using .vector_length \(32\)., ignoring 1} "" { target 
openacc_nvidia_accel_selected } .-1 }
 arr(5) = 5
 !$acc end serial
 
diff --git 
a/libgomp/testsuite/libgomp.oacc-fortran/nonlexical-assumed-s

[gcc/devel/omp/gcc-14] OpenMP: Enable c-c++-common/gomp/declare-mapper-3.c for C

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:96b232bd730b98f7ab4e172a8ea9a1d46f38bbb3

commit 96b232bd730b98f7ab4e172a8ea9a1d46f38bbb3
Author: Julian Brown 
Date:   Thu Jul 13 17:12:05 2023 +

OpenMP: Enable c-c++-common/gomp/declare-mapper-3.c for C

This patch enables the c-c++-common/gomp/declare-mapper-3.c test for C.
This was seemingly overlooked in commit 393fd99c90e.

2023-07-14  Julian Brown  

gcc/testsuite/
* c-c++-common/gomp/declare-mapper-3.c: Enable for C.

Diff:
---
 gcc/testsuite/ChangeLog.omp| 4 
 gcc/testsuite/c-c++-common/gomp/declare-mapper-3.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 2c1e85747c0..e4c8afd0293 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,7 @@
+2023-07-14  Julian Brown  
+
+   * c-c++-common/gomp/declare-mapper-3.c: Enable for C.
+
 2023-07-06  Julian Brown  
 
* c-c++-common/gomp/declare-mapper-15.c: New test.
diff --git a/gcc/testsuite/c-c++-common/gomp/declare-mapper-3.c 
b/gcc/testsuite/c-c++-common/gomp/declare-mapper-3.c
index 983d979d68c..e491bcd0ce6 100644
--- a/gcc/testsuite/c-c++-common/gomp/declare-mapper-3.c
+++ b/gcc/testsuite/c-c++-common/gomp/declare-mapper-3.c
@@ -1,4 +1,4 @@
-// { dg-do compile { target c++ } }
+// { dg-do compile }
 // { dg-additional-options "-fdump-tree-gimple" }
 
 #include 


[gcc/devel/omp/gcc-14] OpenMP: Move Fortran 'declare mapper' instantiation code

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:d2ffdc33f61e889d29b53c82d8514835c6e626aa

commit d2ffdc33f61e889d29b53c82d8514835c6e626aa
Author: Julian Brown 
Date:   Fri Jul 14 00:23:10 2023 +

OpenMP: Move Fortran 'declare mapper' instantiation code

This patch moves the code for explicit 'declare mapper' directive
instantiation in the Fortran front-end to openmp.cc from trans-openmp.cc.
The transformation takes place entirely in the front end's own
representation and doesn't involve middle-end trees at all. Also, having
the code in openmp.cc is more convenient for the following patch that
introduces the 'resolve_omp_mapper_clauses' function.

2023-08-10  Julian Brown  

gcc/fortran/
* gfortran.h (toc_directive): Move here.
(gfc_omp_instantiate_mappers, gfc_get_location): Add prototypes.
* openmp.cc (omp_split_map_op, omp_join_map_op, 
omp_map_decayed_kind,
omp_basic_map_kind_name, gfc_subst_replace, gfc_subst_prepend_ref,
gfc_subst_in_expr_1, gfc_subst_in_expr, gfc_subst_mapper_var): Move
here.
(gfc_omp_instantiate_mapper, gfc_omp_instantiate_mappers): Move here
and rename.
* trans-openmp.cc (toc_directive, omp_split_map_op, omp_join_map_op,
omp_map_decayed_kind, gfc_subst_replace, gfc_subst_prepend_ref,
gfc_subst_in_expr_1, gfc_subst_in_expr, gfc_subst_mapper_var,
gfc_trans_omp_instantiate_mapper, 
gfc_trans_omp_instantiate_mappers):
Remove from here.
(gfc_trans_omp_target, gfc_trans_omp_target_data,
gfc_trans_omp_target_enter_data, gfc_trans_omp_target_exit_data):
Rename calls to gfc_omp_instantiate_mappers.

Diff:
---
 gcc/fortran/ChangeLog.omp   |  19 ++
 gcc/fortran/gfortran.h  |  17 ++
 gcc/fortran/openmp.cc   | 436 
 gcc/fortran/trans-openmp.cc | 389 +--
 4 files changed, 477 insertions(+), 384 deletions(-)

diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp
index ce5eaa1e263..95b3bb90e8f 100644
--- a/gcc/fortran/ChangeLog.omp
+++ b/gcc/fortran/ChangeLog.omp
@@ -1,3 +1,22 @@
+2023-08-10  Julian Brown  
+
+   * gfortran.h (toc_directive): Move here.
+   (gfc_omp_instantiate_mappers, gfc_get_location): Add prototypes.
+   * openmp.cc (omp_split_map_op, omp_join_map_op, omp_map_decayed_kind,
+   omp_basic_map_kind_name, gfc_subst_replace, gfc_subst_prepend_ref,
+   gfc_subst_in_expr_1, gfc_subst_in_expr, gfc_subst_mapper_var): Move
+   here.
+   (gfc_omp_instantiate_mapper, gfc_omp_instantiate_mappers): Move here
+   and rename.
+   * trans-openmp.cc (toc_directive, omp_split_map_op, omp_join_map_op,
+   omp_map_decayed_kind, gfc_subst_replace, gfc_subst_prepend_ref,
+   gfc_subst_in_expr_1, gfc_subst_in_expr, gfc_subst_mapper_var,
+   gfc_trans_omp_instantiate_mapper, gfc_trans_omp_instantiate_mappers):
+   Remove from here.
+   (gfc_trans_omp_target, gfc_trans_omp_target_data,
+   gfc_trans_omp_target_enter_data, gfc_trans_omp_target_exit_data):
+   Rename calls to gfc_omp_instantiate_mappers.
+
 2023-07-06  Julian Brown  
 
* trans-openmp.cc (omp_split_map_op, omp_join_map_op,
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index f98aa871917..3d4abfc6cfd 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -3271,6 +3271,19 @@ typedef struct gfc_finalizer
 gfc_finalizer;
 #define gfc_get_finalizer() XCNEW (gfc_finalizer)
 
+/* Control clause translation per-directive for gfc_trans_omp_clauses.  Also
+   used for gfc_omp_instantiate_mappers.  */
+
+enum toc_directive
+{
+  TOC_OPENMP,
+  TOC_OPENMP_DECLARE_SIMD,
+  TOC_OPENMP_DECLARE_MAPPER,
+  TOC_OPENMP_EXIT_DATA,
+  TOC_OPENACC,
+  TOC_OPENACC_DECLARE,
+  TOC_OPENACC_EXIT_DATA
+};
 
 / Function prototypes */
 
@@ -3752,6 +3765,9 @@ void gfc_resolve_omp_do_blocks (gfc_code *, gfc_namespace 
*);
 void gfc_resolve_omp_declare_simd (gfc_namespace *);
 void gfc_resolve_omp_udrs (gfc_symtree *);
 void gfc_resolve_omp_udms (gfc_symtree *);
+void gfc_omp_instantiate_mappers (gfc_code *, gfc_omp_clauses *,
+ toc_directive = TOC_OPENMP,
+ int = OMP_LIST_MAP);
 void gfc_omp_save_and_clear_state (struct gfc_omp_saved_state *);
 void gfc_omp_restore_state (struct gfc_omp_saved_state *);
 void gfc_free_expr_list (gfc_expr_list *);
@@ -4006,6 +4022,7 @@ bool gfc_convert_to_structure_constructor (gfc_expr *, 
gfc_symbol *,
 /* trans.cc */
 void gfc_generate_code (gfc_namespace *);
 void gfc_generate_module_code (gfc_namespace *);
+location_t gfc_get_location (locus *);
 
 /* trans-intrinsic.cc */
 bool gfc_inline_intrinsic_function_p (gfc_expr *);
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 1deaddf0098..e7bb4dc80b7 

[gcc/devel/omp/gcc-14] OpenMP: Reprocess expanded clauses after 'declare mapper' instantiation

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:628859fb41e9f21b9ee048efa5723b1ab4a39a63

commit 628859fb41e9f21b9ee048efa5723b1ab4a39a63
Author: Julian Brown 
Date:   Sat Jul 15 09:16:44 2023 +

OpenMP: Reprocess expanded clauses after 'declare mapper' instantiation

This patch reprocesses expanded clauses after 'declare mapper'
instantiation -- checking things such as duplicated clauses, illegal
use of strided accesses, and so forth.  Two functions are broken out
of the 'resolve_omp_clauses' function and reused in a new function
'resolve_omp_mapper_clauses', called after mapper instantiation.

This improves diagnostic output.

2023-08-10  Julian Brown  

gcc/fortran/
* gfortran.h (gfc_omp_clauses): Add NS field.
* openmp.cc (verify_omp_clauses_symbol_dups,
omp_verify_map_motion_clauses): New functions, broken out of...
(resolve_omp_clauses): Here.  Record namespace containing clauses.
Call above functions.
(resolve_omp_mapper_clauses): New function, using helper functions
broken out above.
(gfc_resolve_omp_directive): Add NS parameter to resolve_omp_clauses
calls.
(gfc_omp_instantiate_mappers): Call resolve_omp_mapper_clauses if we
instantiate any mappers.

gcc/testsuite/
* gfortran.dg/gomp/declare-mapper-26.f90: New test.
* gfortran.dg/gomp/declare-mapper-29.f90: New test.

Diff:
---
 gcc/fortran/ChangeLog.omp  |   14 +
 gcc/fortran/gfortran.h |1 +
 gcc/fortran/openmp.cc  | 1123 +++-
 gcc/testsuite/ChangeLog.omp|5 +
 .../gfortran.dg/gomp/declare-mapper-26.f90 |   28 +
 .../gfortran.dg/gomp/declare-mapper-29.f90 |   22 +
 6 files changed, 672 insertions(+), 521 deletions(-)

diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp
index 95b3bb90e8f..515a30cd557 100644
--- a/gcc/fortran/ChangeLog.omp
+++ b/gcc/fortran/ChangeLog.omp
@@ -1,3 +1,17 @@
+2023-08-10  Julian Brown  
+
+   * gfortran.h (gfc_omp_clauses): Add NS field.
+   * openmp.cc (verify_omp_clauses_symbol_dups,
+   omp_verify_map_motion_clauses): New functions, broken out of...
+   (resolve_omp_clauses): Here.  Record namespace containing clauses.
+   Call above functions.
+   (resolve_omp_mapper_clauses): New function, using helper functions
+   broken out above.
+   (gfc_resolve_omp_directive): Add NS parameter to resolve_omp_clauses
+   calls.
+   (gfc_omp_instantiate_mappers): Call resolve_omp_mapper_clauses if we
+   instantiate any mappers.
+
 2023-08-10  Julian Brown  
 
* gfortran.h (toc_directive): Move here.
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 3d4abfc6cfd..491a1498279 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -1590,6 +1590,7 @@ typedef struct gfc_omp_clauses
   struct gfc_omp_assumptions *assume;
   struct gfc_expr_list *sizes_list;
   const char *critical_name;
+  gfc_namespace *ns;
   enum gfc_omp_default_sharing default_sharing;
   enum gfc_omp_atomic_op atomic_op;
   enum gfc_omp_defaultmap defaultmap[OMP_DEFAULTMAP_CAT_NUM];
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index e7bb4dc80b7..574c1b2ba0c 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -7822,246 +7822,18 @@ gfc_resolve_omp_assumptions (gfc_omp_assumptions 
*assume)
 &el->expr->where);
 }
 
-
-/* OpenMP directive resolving routines.  */
+/* Check OMP_CLAUSES for duplicate symbols and various other constraints.
+   Helper function for resolve_omp_clauses and resolve_omp_mapper_clauses.  */
 
 static void
-resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
-gfc_namespace *ns, bool openacc = false)
+verify_omp_clauses_symbol_dups (gfc_code *code, gfc_omp_clauses *omp_clauses,
+   gfc_namespace *ns, bool openacc)
 {
-  gfc_omp_namelist *n, *last;
-  gfc_expr_list *el;
+  gfc_omp_namelist *n;
   int list;
-  int ifc;
-  bool if_without_mod = false;
-  gfc_omp_linear_op linear_op = OMP_LINEAR_DEFAULT;
-  static const char *clause_names[]
-= { "PRIVATE", "FIRSTPRIVATE", "LASTPRIVATE", "COPYPRIVATE", "SHARED",
-   "COPYIN", "UNIFORM", "AFFINITY", "ALIGNED", "LINEAR", "DEPEND", "MAP",
-   "TO", "FROM", "INCLUSIVE", "EXCLUSIVE",
-   "REDUCTION", "REDUCTION" /*inscan*/, "REDUCTION" /*task*/,
-   "IN_REDUCTION", "TASK_REDUCTION",
-   "DEVICE_RESIDENT", "LINK", "USE_DEVICE",
-   "CACHE", "IS_DEVICE_PTR", "USE_DEVICE_PTR", "USE_DEVICE_ADDR",
-   "NONTEMPORAL", "ALLOCATE", "HAS_DEVICE_ADDR", "ENTER",
-   "USES_ALLOCATORS" };
-  STATIC_ASSERT (ARRAY_SIZE (clause_names) == OMP_LIST_NUM);
-
-  if (omp_clauses == NULL)
-return;
-
-  if (ns == NULL)
-ns = gfc_current_ns;
-
-  if (omp_c

[gcc/devel/omp/gcc-14] OpenMP: Look up 'declare mapper' definitions at resolution time not parse time

2024-06-28 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:4c94d35536cb3a7cb2a30dae3b8d01370f7a4bea

commit 4c94d35536cb3a7cb2a30dae3b8d01370f7a4bea
Author: Julian Brown 
Date:   Wed Aug 9 10:49:15 2023 +

OpenMP: Look up 'declare mapper' definitions at resolution time not parse 
time

This patch moves 'declare mapper' lookup for OpenMP clauses from parse
time to resolution time for Fortran, and adds diagnostics for missing
named mappers.  This changes clause lookup in a particular case -- where
several 'declare mapper's are defined in a context, mappers declared
earlier may now instantiate mappers declared later, whereas previously
they would not.  I think the new behaviour makes more sense -- at an
invocation site, all mappers are visible no matter the declaration order
in some particular block.  I've adjusted tests to account for this.

I think the new arrangement better matches the Fortran FE's usual way of
doing things -- mapper lookup is a semantic concept, not a syntactical
one, so shouldn't be handled in the syntax-handling code.

The patch also fixes a case where the user explicitly writes 'default'
as the name on the mapper modifier for a clause.

2023-08-10  Julian Brown  

gcc/fortran/
* gfortran.h (gfc_omp_namelist_udm): Add MAPPER_ID field to store 
the
mapper name to use for lookup during resolution.
* match.cc (gfc_free_omp_namelist): Handle OMP_LIST_TO and
OMP_LIST_FROM when freeing mapper references.
* module.cc (load_omp_udms, write_omp_udm): Handle MAPPER_ID field.
* openmp.cc (gfc_match_omp_clauses): Handle explicitly-specified
'default' name.  Don't do mapper lookup here, but record mapper 
name if
the user specifies one.
(resolve_omp_clauses): Do mapper lookup here instead.  Report error 
for
missing named mapper.

gcc/testsuite/
* gfortran.dg/gomp/declare-mapper-31.f90: New test.

libgomp/
* testsuite/libgomp.fortran/declare-mapper-30.f90: New test.
* testsuite/libgomp.fortran/declare-mapper-4.f90: Adjust test for 
new
lookup behaviour.

Diff:
---
 gcc/fortran/ChangeLog.omp  | 13 ++
 gcc/fortran/gfortran.h |  3 ++
 gcc/fortran/match.cc   |  4 +-
 gcc/fortran/module.cc  |  6 +++
 gcc/fortran/openmp.cc  | 46 --
 gcc/testsuite/ChangeLog.omp|  4 ++
 .../gfortran.dg/gomp/declare-mapper-31.f90 | 34 
 libgomp/ChangeLog.omp  |  6 +++
 .../libgomp.fortran/declare-mapper-30.f90  | 24 +++
 .../testsuite/libgomp.fortran/declare-mapper-4.f90 | 18 +
 10 files changed, 139 insertions(+), 19 deletions(-)

diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp
index 515a30cd557..30610d7e699 100644
--- a/gcc/fortran/ChangeLog.omp
+++ b/gcc/fortran/ChangeLog.omp
@@ -1,3 +1,16 @@
+2023-08-10  Julian Brown  
+
+   * gfortran.h (gfc_omp_namelist_udm): Add MAPPER_ID field to store the
+   mapper name to use for lookup during resolution.
+   * match.cc (gfc_free_omp_namelist): Handle OMP_LIST_TO and
+   OMP_LIST_FROM when freeing mapper references.
+   * module.cc (load_omp_udms, write_omp_udm): Handle MAPPER_ID field.
+   * openmp.cc (gfc_match_omp_clauses): Handle explicitly-specified
+   'default' name.  Don't do mapper lookup here, but record mapper name if
+   the user specifies one.
+   (resolve_omp_clauses): Do mapper lookup here instead.  Report error for
+   missing named mapper.
+
 2023-08-10  Julian Brown  
 
* gfortran.h (gfc_omp_clauses): Add NS field.
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 491a1498279..8289b98ca73 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -1777,6 +1777,9 @@ gfc_omp_udm;
 
 typedef struct gfc_omp_namelist_udm
 {
+  /* Used to store mapper_id before resolution.  */
+  const char *mapper_id;
+
   bool multiple_elems_p;
   struct gfc_omp_udm *udm;
 }
diff --git a/gcc/fortran/match.cc b/gcc/fortran/match.cc
index 331a9c05f03..4e023856bf4 100644
--- a/gcc/fortran/match.cc
+++ b/gcc/fortran/match.cc
@@ -5540,7 +5540,9 @@ void
 gfc_free_omp_namelist (gfc_omp_namelist *name, int list)
 {
   bool free_ns = (list == OMP_LIST_AFFINITY || list == OMP_LIST_DEPEND);
-  bool free_mapper = (list == OMP_LIST_MAP);
+  bool free_mapper = (list == OMP_LIST_MAP
+ || list == OMP_LIST_TO
+ || list == OMP_LIST_FROM);
   bool free_align_allocator = (list == OMP_LIST_ALLOCATE);
   bool free_mem_traits_space = (list == OMP_LIST_USES_ALLOCATORS);
   gfc_omp_namelist *n;
diff --git a/gcc/fortran/module.cc b/gcc/fortran/module.cc
index de2077f288f..96867f889b4 100644
--

  1   2   >