]> git.ipfire.org Git - thirdparty/gcc.git/commit
OpenMP: Constructors and destructors for "declare target" static aggregates
authorTobias Burnus <tburnus@baylibre.com>
Wed, 7 Aug 2024 17:31:19 +0000 (19:31 +0200)
committerThomas Schwinge <tschwinge@baylibre.com>
Fri, 25 Apr 2025 16:09:19 +0000 (18:09 +0200)
commit0367df9d4fc07c95f08a6a499f36c96851cbe832
treee8d3fb9e9e28513648628b9fa1bbf64aa56649ab
parent14568217c74206c9c5d033050fba6fe2ab57bb05
OpenMP: Constructors and destructors for "declare target" static aggregates

This commit also compile-time expands (__builtin_)omp_is_initial_device for
both Fortran and C/C++ (unless, -fno-builtin-omp_is_initial_device is used).
But the main change is:

This commit adds support for running constructors and destructors for
static (file-scope) aggregates for C++ objects which are marked with
"declare target" directives on OpenMP offload targets.

Before this commit, space is allocated on the target for such aggregates,
but nothing ever constructs them properly, so they end up zero-initialised.

(See the new test static-aggr-constructor-destructor-3.C for a reason
why running constructors on the target is preferable to e.g. constructing
on the host and then copying the resulting object to the target.)

2024-08-07  Julian Brown  <julian@codesourcery.com>
    Tobias Burnus  <tobias@baylibre.com>

gcc/ChangeLog:

* builtins.def (DEF_GOMP_BUILTIN_COMPILER): Define
DEF_GOMP_BUILTIN_COMPILER to handle the non-prefix version.
* gimple-fold.cc (gimple_fold_builtin_omp_is_initial_device): New.
(gimple_fold_builtin): Call it.
* omp-builtins.def (BUILT_IN_OMP_IS_INITIAL_DEVICE): Define.
* tree.cc (get_file_function_name): Support names for on-target
constructor/destructor functions.

gcc/cp/
* decl2.cc (tree-inline.h): Include.
(static_init_fini_fns): Bump to four entries. Update comment.
(start_objects, start_partial_init_fini_fn): Add 'omp_target'
parameter. Support "declare target" decls. Update forward declaration.
(emit_partial_init_fini_fn): Add 'host_fn' parameter. Return tree for
the created function. Support "declare target".
(OMP_SSDF_IDENTIFIER): New macro.
(partition_vars_for_init_fini): Support partitioning "declare target"
variables also.
(generate_ctor_or_dtor_function): Add 'omp_target' parameter. Support
"declare target" decls.
(c_parse_final_cleanups): Support constructors/destructors on OpenMP
offload targets.

gcc/fortran/ChangeLog:

* gfortran.h (gfc_option_t): Add disable_omp_is_initial_device.
* lang.opt (fbuiltin-): Add.
* options.cc (gfc_handle_option): Handle
-fno-builtin-omp_is_initial_device.
* f95-lang.cc (gfc_init_builtin_functions): Handle
DEF_GOMP_BUILTIN_COMPILER.
* trans-decl.cc (gfc_get_extern_function_decl): Add code to use
DEF_GOMP_BUILTIN_COMPILER for 'omp_is_initial_device'.

libgomp/ChangeLog:

* testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C: New test.
* testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C: New test.
* testsuite/libgomp.c++/static-aggr-constructor-destructor-3.C: New test.
* testsuite/libgomp.c-c++-common/target-is-initial-host.c: New test.
* testsuite/libgomp.c-c++-common/target-is-initial-host-2.c: New test.
* testsuite/libgomp.fortran/target-is-initial-host.f: New test.
* testsuite/libgomp.fortran/target-is-initial-host.f90: New test.
* testsuite/libgomp.fortran/target-is-initial-host-2.f90: New test.

Co-authored-by: Tobias Burnus <tobias@baylibre.com>
(cherry picked from commit f1bfba3a9b3f31e3e06bfd1911c9f223869ea03f)
22 files changed:
gcc/ChangeLog.omp
gcc/builtins.def
gcc/cp/ChangeLog.omp
gcc/cp/decl2.cc
gcc/fortran/ChangeLog.omp
gcc/fortran/f95-lang.cc
gcc/fortran/gfortran.h
gcc/fortran/lang.opt
gcc/fortran/options.cc
gcc/fortran/trans-decl.cc
gcc/gimple-fold.cc
gcc/omp-builtins.def
gcc/tree.cc
libgomp/ChangeLog.omp
libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-3.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/target-is-initial-host-2.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/target-is-initial-host.c [new file with mode: 0644]
libgomp/testsuite/libgomp.fortran/target-is-initial-host-2.f90 [new file with mode: 0644]
libgomp/testsuite/libgomp.fortran/target-is-initial-host.f [new file with mode: 0644]
libgomp/testsuite/libgomp.fortran/target-is-initial-host.f90 [new file with mode: 0644]