]> git.ipfire.org Git - thirdparty/gcc.git/commit
openmp: Handle C/C++ array reference base-pointers in array sections
authorChung-Lin Tang <cltang@codesourcery.com>
Thu, 24 Feb 2022 09:07:48 +0000 (01:07 -0800)
committerChung-Lin Tang <cltang@codesourcery.com>
Thu, 24 Feb 2022 09:07:48 +0000 (01:07 -0800)
commit2529510c9594e3ead522a4cf86ba2cd307dac78f
tree8108038a2b491222b0c0d5ebcb331458f2468dfc
parent249df772b70f7b9f50f68030d4ea9c25624cc578
openmp: Handle C/C++ array reference base-pointers in array sections

In cases where a program constructs its own deep-copying for arrays-of-pointers,
e.g:
   #pragma omp target enter data map(to:level->vectors[:N])
   for (i = 0; i < N; i++)
     #pragma omp target enter data map(to:level->vectors[i][:N])

We need to treat the part of the array reference before the array section
as a base-pointer (here 'level->vectors[i]'), providing pointer-attachment
behavior.

This patch adds this inside handle_omp_array_sections(), tracing the whole
sequence of array dimensions, creating a whole base-pointer reference
iteratively using build_array_ref(). The conditions are that each of the
"absorbed" dimensions must be length==1, and the final reference must be
of pointer-type (so that pointer attachment makes sense).

Merged from:
https://gcc.gnu.org/pipermail/gcc-patches/2022-February/590658.html

2022-02-24  Chung-Lin Tang  <cltang@codesourcery.com>

gcc/c/ChangeLog:

* c-typeck.cc (handle_omp_array_sections): Add handling for
creating array-reference base-pointer attachment clause.

gcc/cp/ChangeLog:

* semantics.cc (handle_omp_array_sections): Add handling for
creating array-reference base-pointer attachment clause.

gcc/ChangeLog:

* gimplify.cc (gimplify_scan_omp_clauses): Add case for
attach/detach map kind for ARRAY_REF of POINTER_TYPE.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/target-enter-data-1.c: Adjust testcase.

libgomp/testsuite/ChangeLog:

* libgomp.c-c++-common/ptr-attach-2.c: New test.
gcc/c/c-typeck.c
gcc/cp/semantics.c
gcc/gimplify.c
gcc/testsuite/c-c++-common/gomp/target-enter-data-1.c
libgomp/testsuite/libgomp.c-c++-common/ptr-attach-2.c [new file with mode: 0644]