openmp: Implicitly add 'declare target' directives for dynamic initializers in C++
authorKwok Cheung Yeung <kcy@codesourcery.com>
Fri, 18 Dec 2020 16:26:34 +0000 (08:26 -0800)
committerKwok Cheung Yeung <kcy@codesourcery.com>
Fri, 18 Dec 2020 16:38:30 +0000 (08:38 -0800)
commit3af02d32cce2ff1ff11d078cf8094305f57ca179
treea9affc2bf477cd04d393cc9b5aa6392b54074a42
parent7ff5706fcd732b671afb2d308e8dab7e23050823
openmp: Implicitly add 'declare target' directives for dynamic initializers in C++

2020-12-18  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/
* langhooks-def.h (lhd_get_decl_init): New.
(lhd_finish_decl_inits): New.
(LANG_HOOKS_GET_DECL_INIT): New.
(LANG_HOOKS_OMP_FINISH_DECL_INITS): New.
(LANG_HOOKS_DECLS): Add LANG_HOOKS_GET_DECL_INIT and
LANG_HOOKS_OMP_FINISH_DECL_INITS.
* langhooks.c (lhd_omp_get_decl_init): New.
(lhd_omp_finish_decl_inits): New.
* langhooks.h (struct lang_hooks_for_decls): Add omp_get_decl_init
and omp_finish_decl_inits.
* omp-offload.c (omp_discover_declare_target_var_r): Use
get_decl_init langhook in place of DECL_INITIAL.  Call
omp_finish_decl_inits langhook at end of function.

gcc/cp/
* cp-lang.c (cxx_get_decl_init): New.
(cxx_omp_finish_decl_inits): New.
(LANG_HOOKS_GET_DECL_INIT): New.
(LANG_HOOKS_OMP_FINISH_DECL_INITS): New.
* cp-tree.h (dynamic_initializers): New.
* decl.c (dynamic_initializers): New.
* decl2.c (c_parse_final_cleanups): Add initializer entries
from vars to dynamic_initializers.

gcc/testsuite/
* g++.dg/gomp/declare-target-3.C: New.
gcc/cp/cp-lang.c
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/decl2.c
gcc/langhooks-def.h
gcc/langhooks.c
gcc/langhooks.h
gcc/omp-offload.c
gcc/testsuite/g++.dg/gomp/declare-target-3.C [new file with mode: 0644]