gcc/libgomp/testsuite/libgomp.c++/target-12.C
Chung-Lin Tang 6c0399378e OpenMP 5.0: Remove array section base-pointer mapping semantics and other front-end adjustments
This patch implements three pieces of functionality:

(1) Adjust array section mapping to have standards conforming behavior,
mapping array sections should *NOT* also map the base-pointer:

struct S { int *ptr; ... };
struct S s;

Instead of generating this during gimplify:
                              map(to:*_1 [len: 400]) map(attach:s.ptr [bias: 0])

Now, adjust to:

(i.e. do not map the base-pointer together. The attach operation is still
generated, and if s.ptr is already mapped prior, attachment will happen)

The correct way of achieving the base-pointer-also-mapped behavior would be to
use:

(A small Fortran front-end patch to trans-openmp.c:gfc_trans_omp_array_section
 is also included, which removes generation of a GOMP_MAP_ALWAYS_POINTER for
 array types, which appears incorrect and causes a regression in
 libgomp.fortranlibgomp.fortran/struct-elem-map-1.f90)

(2) Related to the first item above, are fixes in libgomp/target.c to not
overwrite attached pointers when handling device<->host copies, mainly for the
"always" case.

(3) The third is a set of changes to the C/C++ front-ends to extend the allowed
component access syntax in map clauses. These changes are enabled for both
OpenACC and OpenMP.

gcc/c/ChangeLog:

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

gcc/cp/ChangeLog:

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

gcc/fortran/ChangeLog:

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

gcc/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

libgomp/ChangeLog:

	* target.c (gomp_map_vars_existing): Make sure attached pointer is
	not overwritten during cross-host/device copying.
	(gomp_update): Likewise.
	(gomp_exit_data): Likewise.
	* testsuite/libgomp.c++/target-11.C: Adjust testcase.
	* testsuite/libgomp.c++/target-12.C: Likewise.
	* testsuite/libgomp.c++/target-15.C: Likewise.
	* testsuite/libgomp.c++/target-16.C: Likewise.
	* testsuite/libgomp.c++/target-17.C: Likewise.
	* testsuite/libgomp.c++/target-21.C: Likewise.
	* testsuite/libgomp.c++/target-23.C: Likewise.
	* testsuite/libgomp.c/target-23.c: Likewise.
	* testsuite/libgomp.c/target-29.c: Likewise.
	* testsuite/libgomp.c-c++-common/target-implicit-map-2.c: New testcase.
2021-12-09 00:01:10 +08:00

94 lines
2.9 KiB
C

extern "C" void abort (void);
struct S { int s; int *u; int v[5]; };
volatile int z;
template <typename T>
void
foo ()
{
int u[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, err = 0;
T s = { 9, u + 3, { 10, 11, 12, 13, 14 } };
int *v = u + 4;
#pragma omp target enter data map (to: s.s, s.template u[0:5]) map (alloc: s.template v[1:3])
s.s++;
u[3]++;
s.v[1]++;
#pragma omp target update to (s.template s) to (s.u[0:2], s.v[1:3])
#pragma omp target map (alloc: s.s, s.v[1:3]) map (from: err)
{
err = 0;
if (s.s != 10 || s.v[1] != 12 || s.v[2] != 12 || s.v[3] != 13)
err = 1;
if (v[-1] != 4 || v[0] != 4 || v[1] != 5 || v[2] != 6 || v[3] != 7)
err = 1;
s.s++;
s.v[2] += 2;
v[-1] = 5;
v[3] = 9;
}
if (err)
abort ();
#pragma omp target map (alloc: s.u[0:5])
{
err = 0;
if (s.u[0] != 5 || s.u[1] != 4 || s.u[2] != 5 || s.u[3] != 6 || s.u[4] != 9)
err = 1;
s.u[1] = 12;
}
#pragma omp target update from (s.s, s.u[0:5]) from (s.v[1:3])
if (err || s.s != 11 || u[0] != 0 || u[1] != 1 || u[2] != 2 || u[3] != 5
|| u[4] != 12 || u[5] != 5 || u[6] != 6 || u[7] != 9 || u[8] != 8
|| u[9] != 9 || s.v[0] != 10 || s.v[1] != 12 || s.v[2] != 14
|| s.v[3] != 13 || s.v[4] != 14)
abort ();
#pragma omp target exit data map (release: s.s)
#pragma omp target exit data map (release: s.u[0:5])
#pragma omp target exit data map (delete: s.v[1:3])
#pragma omp target exit data map (release: s.s)
}
int
main ()
{
int u[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, err = 0;
S s = { 9, u + 3, { 10, 11, 12, 13, 14 } };
int *v = u + 4;
#pragma omp target enter data map (to: s.s, s.u, s.u[0:5]) map (alloc: s.v[1:3])
s.s++;
u[3]++;
s.v[1]++;
#pragma omp target update to (s.s) to (s.u[0:2], s.v[1:3])
#pragma omp target map (alloc: s.s, s.v[1:3]) map (from: err)
{
err = 0;
if (s.s != 10 || s.v[1] != 12 || s.v[2] != 12 || s.v[3] != 13)
err = 1;
if (v[-1] != 4 || v[0] != 4 || v[1] != 5 || v[2] != 6 || v[3] != 7)
err = 1;
s.s++;
s.v[2] += 2;
v[-1] = 5;
v[3] = 9;
}
if (err)
abort ();
#pragma omp target map (alloc: s.u[0:5])
{
err = 0;
if (s.u[0] != 5 || s.u[1] != 4 || s.u[2] != 5 || s.u[3] != 6 || s.u[4] != 9)
err = 1;
s.u[1] = 12;
}
#pragma omp target update from (s.s, s.u[0:5]) from (s.v[1:3])
if (err || s.s != 11 || u[0] != 0 || u[1] != 1 || u[2] != 2 || u[3] != 5
|| u[4] != 12 || u[5] != 5 || u[6] != 6 || u[7] != 9 || u[8] != 8
|| u[9] != 9 || s.v[0] != 10 || s.v[1] != 12 || s.v[2] != 14
|| s.v[3] != 13 || s.v[4] != 14)
abort ();
#pragma omp target exit data map (release: s.s)
#pragma omp target exit data map (release: s.u[0:5])
#pragma omp target exit data map (always, delete: s.v[1:3])
#pragma omp target exit data map (release: s.s)
#pragma omp target exit data map (always delete : s.v[1:3])
}