6c0399378e
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.
124 lines
2.8 KiB
C
124 lines
2.8 KiB
C
extern "C" void abort ();
|
|
struct T { int a; int *b; int c; char (&d)[10]; };
|
|
struct S { int *s; char *u; T v; short *w; short *&x; };
|
|
volatile int z;
|
|
|
|
template <typename A, typename B, typename C, typename D>
|
|
void
|
|
foo ()
|
|
{
|
|
A d[10];
|
|
B *e;
|
|
C a[32], i;
|
|
A b[32];
|
|
B c[32];
|
|
for (i = 0; i < 32; i++)
|
|
{
|
|
a[i] = i;
|
|
b[i] = 32 + i;
|
|
c[i] = 64 + i;
|
|
}
|
|
for (i = 0; i < 10; i++)
|
|
d[i] = 17 + i;
|
|
e = c + 18;
|
|
D s = { a, b + 2, { 0, a + 16, 0, d }, c + 3, e };
|
|
int err = 0;
|
|
#pragma omp target map (to: s.v.b, s.v.b[0:z + 7]) \
|
|
map (s.template u, s.template u[z + 1:z + 4]) \
|
|
map (tofrom: s.s, s.s[3:3]) \
|
|
map (tofrom: s. template v. template d[z + 1:z + 3])\
|
|
map (from: s.w, s.w[z:4], s.x, s.x[1:3], err) private (i)
|
|
{
|
|
err = 0;
|
|
for (i = 0; i < 7; i++)
|
|
if (s.v.b[i] != 16 + i)
|
|
err = 1;
|
|
for (i = 1; i < 5; i++)
|
|
if (s.u[i] != 34 + i)
|
|
err = 1;
|
|
for (i = 3; i < 6; i++)
|
|
if (s.s[i] != i)
|
|
err = 1;
|
|
else
|
|
s.s[i] = 128 + i;
|
|
for (i = 1; i < 4; i++)
|
|
if (s.v.d[i] != 17 + i)
|
|
err = 1;
|
|
else
|
|
s.v.d[i] = 23 + i;
|
|
for (i = 0; i < 4; i++)
|
|
s.w[i] = 96 + i;
|
|
for (i = 1; i < 4; i++)
|
|
s.x[i] = 173 + i;
|
|
}
|
|
if (err)
|
|
abort ();
|
|
for (i = 0; i < 32; i++)
|
|
if (a[i] != ((i >= 3 && i < 6) ? 128 + i : i)
|
|
|| b[i] != 32 + i
|
|
|| c[i] != ((i >= 3 && i < 7) ? 93 + i : ((i >= 19 && i < 22) ? 155 + i : 64 + i)))
|
|
abort ();
|
|
for (i = 0; i < 10; i++)
|
|
if (d[i] != ((i >= 1 && i < 4) ? 23 + i : 17 + i))
|
|
abort ();
|
|
}
|
|
|
|
int
|
|
main ()
|
|
{
|
|
char d[10];
|
|
short *e;
|
|
int a[32], i;
|
|
char b[32];
|
|
short c[32];
|
|
for (i = 0; i < 32; i++)
|
|
{
|
|
a[i] = i;
|
|
b[i] = 32 + i;
|
|
c[i] = 64 + i;
|
|
}
|
|
for (i = 0; i < 10; i++)
|
|
d[i] = 17 + i;
|
|
e = c + 18;
|
|
S s = { a, b + 2, { 0, a + 16, 0, d }, c + 3, e };
|
|
int err = 0;
|
|
#pragma omp target map (to: s.v.b, s.v.b[0:z + 7], s.u, s.u[z + 1:z + 4]) \
|
|
map (tofrom: s.s, s.s[3:3], s.v.d[z + 1:z + 3]) \
|
|
map (from: s.w, s.w[z:4], s.x, s.x[1:3], err) private (i)
|
|
{
|
|
err = 0;
|
|
for (i = 0; i < 7; i++)
|
|
if (s.v.b[i] != 16 + i)
|
|
err = 1;
|
|
for (i = 1; i < 5; i++)
|
|
if (s.u[i] != 34 + i)
|
|
err = 1;
|
|
for (i = 3; i < 6; i++)
|
|
if (s.s[i] != i)
|
|
err = 1;
|
|
else
|
|
s.s[i] = 128 + i;
|
|
for (i = 1; i < 4; i++)
|
|
if (s.v.d[i] != 17 + i)
|
|
err = 1;
|
|
else
|
|
s.v.d[i] = 23 + i;
|
|
for (i = 0; i < 4; i++)
|
|
s.w[i] = 96 + i;
|
|
for (i = 1; i < 4; i++)
|
|
s.x[i] = 173 + i;
|
|
}
|
|
if (err)
|
|
abort ();
|
|
for (i = 0; i < 32; i++)
|
|
if (a[i] != ((i >= 3 && i < 6) ? 128 + i : i)
|
|
|| b[i] != 32 + i
|
|
|| c[i] != ((i >= 3 && i < 7) ? 93 + i : ((i >= 19 && i < 22) ? 155 + i : 64 + i)))
|
|
abort ();
|
|
for (i = 0; i < 10; i++)
|
|
if (d[i] != ((i >= 1 && i < 4) ? 23 + i : 17 + i))
|
|
abort ();
|
|
foo <char, short, int, S> ();
|
|
return 0;
|
|
}
|