OpenMP/OpenACC: Unordered/non-constant component offset runtime diagnostic
commitf5745dc1426bdb1a53ebaf7af758b2250ccbff02
authorJulian Brown <julian@codesourcery.com>
Sun, 9 Oct 2022 20:26:09 +0000 (9 20:26 +0000)
committerJulian Brown <julian@codesourcery.com>
Fri, 15 Dec 2023 10:33:52 +0000 (15 10:33 +0000)
treedd1d55ced447489b6c07b17be14616cba68d54ce
parentef9754dfdf18a89de3da23c4f23365f4c2611367
OpenMP/OpenACC: Unordered/non-constant component offset runtime diagnostic

This patch adds support for non-constant component offsets in "map"
clauses for OpenMP (and the equivalants for OpenACC), which are not able
to be sorted into order at compile time.  Normally struct accesses in
such clauses are gathered together and sorted into increasing address
order after a "GOMP_MAP_STRUCT" node: if we have variable indices,
that is no longer possible.

This version of the patch scales back the previously-posted version to
merely add a diagnostic for incorrect usage of component accesses with
variably-indexed arrays of structs: the only permitted variant is where
we have multiple indices that are the same, but we could not prove so
at compile time.  Rather than silently producing the wrong result for
cases where the indices are in fact different, we error out (e.g.,
"map(dtarr(i)%arrptr, dtarr(j)%arrptr(4:8))", for different i/j).

For now, multiple *constant* array indices are still supported (see
map-arrayofstruct-1.c).  That could perhaps be addressed with a follow-up
patch, if necessary.

This version of the patch renumbers the GOMP_MAP_STRUCT_UNORD kind to
avoid clashing with the OpenACC "non-contiguous" dynamic array support
(though that is not yet applied to mainline).

2023-08-18  Julian Brown  <julian@codesourcery.com>

gcc/
* gimplify.cc (extract_base_bit_offset): Add VARIABLE_OFFSET parameter.
(omp_get_attachment, omp_group_last, omp_group_base,
omp_directive_maps_explicitly): Add GOMP_MAP_STRUCT_UNORD support.
(omp_accumulate_sibling_list): Update calls to extract_base_bit_offset.
Support GOMP_MAP_STRUCT_UNORD.
(omp_build_struct_sibling_lists, gimplify_scan_omp_clauses,
gimplify_adjust_omp_clauses, gimplify_omp_target_update): Add
GOMP_MAP_STRUCT_UNORD support.
* omp-low.cc (lower_omp_target): Add GOMP_MAP_STRUCT_UNORD support.
* tree-pretty-print.cc (dump_omp_clause): Likewise.

include/
* gomp-constants.h (gomp_map_kind): Add GOMP_MAP_STRUCT_UNORD.

libgomp/
* oacc-mem.c (find_group_last, goacc_enter_data_internal,
goacc_exit_data_internal, GOACC_enter_exit_data): Add
GOMP_MAP_STRUCT_UNORD support.
* target.c (gomp_map_vars_internal): Add GOMP_MAP_STRUCT_UNORD support.
Detect incorrect use of variable indexing of arrays of structs.
(GOMP_target_enter_exit_data, gomp_target_task_fn): Add
GOMP_MAP_STRUCT_UNORD support.
* testsuite/libgomp.c-c++-common/map-arrayofstruct-1.c: New test.
* testsuite/libgomp.c-c++-common/map-arrayofstruct-2.c: New test.
* testsuite/libgomp.c-c++-common/map-arrayofstruct-3.c: New test.
* testsuite/libgomp.fortran/map-subarray-5.f90: New test.
gcc/gimplify.cc
gcc/omp-low.cc
gcc/tree-pretty-print.cc
include/gomp-constants.h
libgomp/oacc-mem.c
libgomp/target.c
libgomp/testsuite/libgomp.c-c++-common/map-arrayofstruct-1.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/map-arrayofstruct-2.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/map-arrayofstruct-3.c [new file with mode: 0644]
libgomp/testsuite/libgomp.fortran/map-subarray-5.f90 [new file with mode: 0644]