gcc/libgomp/libgomp_g.h
Kwok Cheung Yeung a49c7d3193 openmp: Add support for the 'indirect' clause in C/C++
This adds support for the 'indirect' clause in the 'declare target'
directive.  Functions declared as indirect may be called via function
pointers passed from the host in offloaded code.

Virtual calls to member functions via the object pointer in C++ are
currently not supported in target regions.

2023-11-07  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/c-family/
	* c-attribs.cc (c_common_attribute_table): Add attribute for
	indirect functions.
	* c-pragma.h (enum parma_omp_clause): Add entry for indirect clause.

gcc/c/
	* c-decl.cc (c_decl_attributes): Add attribute for indirect
	functions.
	* c-lang.h (c_omp_declare_target_attr): Add indirect field.
	* c-parser.cc (c_parser_omp_clause_name): Handle indirect clause.
	(c_parser_omp_clause_indirect): New.
	(c_parser_omp_all_clauses): Handle indirect clause.
	(OMP_DECLARE_TARGET_CLAUSE_MASK): Add indirect clause to mask.
	(c_parser_omp_declare_target): Handle indirect clause.  Emit error
	message if device_type or indirect clauses used alone.  Emit error
	if indirect clause used with device_type that is not 'any'.
	(OMP_BEGIN_DECLARE_TARGET_CLAUSE_MASK): Add indirect clause to mask.
	(c_parser_omp_begin): Handle indirect clause.
	* c-typeck.cc (c_finish_omp_clauses): Handle indirect clause.

gcc/cp/
	* cp-tree.h (cp_omp_declare_target_attr): Add indirect field.
	* decl2.cc (cplus_decl_attributes): Add attribute for indirect
	functions.
	* parser.cc (cp_parser_omp_clause_name): Handle indirect clause.
	(cp_parser_omp_clause_indirect): New.
	(cp_parser_omp_all_clauses): Handle indirect clause.
	(handle_omp_declare_target_clause): Add extra parameter.  Add
	indirect attribute for indirect functions.
	(OMP_DECLARE_TARGET_CLAUSE_MASK): Add indirect clause to mask.
	(cp_parser_omp_declare_target): Handle indirect clause.  Emit error
	message if device_type or indirect clauses used alone.  Emit error
	if indirect clause used with device_type that is not 'any'.
	(OMP_BEGIN_DECLARE_TARGET_CLAUSE_MASK): Add indirect clause to mask.
	(cp_parser_omp_begin): Handle indirect clause.
	* semantics.cc (finish_omp_clauses): Handle indirect clause.

gcc/
	* lto-cgraph.cc (enum LTO_symtab_tags): Add tag for indirect
	functions.
	(output_offload_tables): Write indirect functions.
	(input_offload_tables): read indirect functions.
	* lto-section-names.h (OFFLOAD_IND_FUNC_TABLE_SECTION_NAME): New.
	* omp-builtins.def (BUILT_IN_GOMP_TARGET_MAP_INDIRECT_PTR): New.
	* omp-offload.cc (offload_ind_funcs): New.
	(omp_discover_implicit_declare_target): Add functions marked with
	'omp declare target indirect' to indirect functions list.
	(omp_finish_file): Add indirect functions to section for offload
	indirect functions.
	(execute_omp_device_lower): Redirect indirect calls on target by
	passing function pointer to BUILT_IN_GOMP_TARGET_MAP_INDIRECT_PTR.
	(pass_omp_device_lower::gate): Run pass_omp_device_lower if
	indirect functions are present on an accelerator device.
	* omp-offload.h (offload_ind_funcs): New.
	* tree-core.h (omp_clause_code): Add OMP_CLAUSE_INDIRECT.
	* tree.cc (omp_clause_num_ops): Add entry for OMP_CLAUSE_INDIRECT.
	(omp_clause_code_name): Likewise.
	* tree.h (OMP_CLAUSE_INDIRECT_EXPR): New.
	* config/gcn/mkoffload.cc (process_asm): Process offload_ind_funcs
	section.  Count number of indirect functions.
	(process_obj): Emit number of indirect functions.
	* config/nvptx/mkoffload.cc (ind_func_ids, ind_funcs_tail): New.
	(process): Emit offload_ind_func_table in PTX code.  Emit indirect
	function names and count in image.
	* config/nvptx/nvptx.cc (nvptx_record_offload_symbol): Mark
	indirect functions in PTX code with IND_FUNC_MAP.

gcc/testsuite/
	* c-c++-common/gomp/declare-target-7.c: Update expected error message.
	* c-c++-common/gomp/declare-target-indirect-1.c: New.
	* c-c++-common/gomp/declare-target-indirect-2.c: New.
	* g++.dg/gomp/attrs-21.C (v12): Update expected error message.
	* g++.dg/gomp/declare-target-indirect-1.C: New.
	* gcc.dg/gomp/attrs-21.c (v12): Update expected error message.

include/
	* gomp-constants.h (GOMP_VERSION): Increment to 3.
	(GOMP_VERSION_SUPPORTS_INDIRECT_FUNCS): New.

libgcc/
	* offloadstuff.c (OFFLOAD_IND_FUNC_TABLE_SECTION_NAME): New.
	(__offload_ind_func_table): New.
	(__offload_ind_funcs_end): New.
	(__OFFLOAD_TABLE__): Add entries for indirect functions.

libgomp/
	* Makefile.am (libgomp_la_SOURCES): Add target-indirect.c.
	* Makefile.in: Regenerate.
	* libgomp-plugin.h (GOMP_INDIRECT_ADDR_MAP): New define.
	(GOMP_OFFLOAD_load_image): Add extra argument.
	* libgomp.h (struct indirect_splay_tree_key_s): New.
	(indirect_splay_tree_node, indirect_splay_tree,
	indirect_splay_tree_key): New.
	(indirect_splay_compare): New.
	* libgomp.map (GOMP_5.1.1): Add GOMP_target_map_indirect_ptr.
	* libgomp.texi (OpenMP 5.1): Update documentation on indirect
	calls in target region and on indirect clause.
	(Other new OpenMP 5.2 features): Add entry for virtual function calls.
	* libgomp_g.h (GOMP_target_map_indirect_ptr): Add prototype.
	* oacc-host.c (host_load_image): Add extra argument.
	* target.c (gomp_load_image_to_device): If the GOMP_VERSION is high
	enough, read host indirect functions table and pass to
	load_image_func.
	* config/accel/target-indirect.c: New.
	* config/linux/target-indirect.c: New.
	* config/gcn/team.c (build_indirect_map): Add prototype.
	(gomp_gcn_enter_kernel): Initialize support for indirect
	function calls on GCN target.
	* config/nvptx/team.c (build_indirect_map): Add prototype.
	(gomp_nvptx_main): Initialize support for indirect function
	calls on NVPTX target.
	* plugin/plugin-gcn.c (struct gcn_image_desc): Add field for
	indirect functions count.
	(GOMP_OFFLOAD_load_image): Add extra argument.  If the GOMP_VERSION
	is high enough, build address translation table and copy it to target
	memory.
	* plugin/plugin-nvptx.c (nvptx_tdata): Add field for indirect
	functions count.
	(GOMP_OFFLOAD_load_image): Add extra argument.  If the GOMP_VERSION
	is high enough, Build address translation table and copy it to target
	memory.
	* testsuite/libgomp.c-c++-common/declare-target-indirect-1.c: New.
	* testsuite/libgomp.c-c++-common/declare-target-indirect-2.c: New.
	* testsuite/libgomp.c++/declare-target-indirect-1.C: New.
2023-11-07 15:44:50 +00:00

405 lines
15 KiB
C

/* Copyright (C) 2005-2023 Free Software Foundation, Inc.
Contributed by Richard Henderson <rth@redhat.com>.
This file is part of the GNU Offloading and Multi Processing Library
(libgomp).
Libgomp is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
/* This file contains prototypes of functions in the external ABI.
This file is included by files in the testsuite. */
#ifndef LIBGOMP_G_H
#define LIBGOMP_G_H 1
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
/* barrier.c */
extern void GOMP_barrier (void);
extern bool GOMP_barrier_cancel (void);
/* critical.c */
extern void GOMP_critical_start (void);
extern void GOMP_critical_end (void);
extern void GOMP_critical_name_start (void **);
extern void GOMP_critical_name_end (void **);
extern void GOMP_atomic_start (void);
extern void GOMP_atomic_end (void);
/* loop.c */
extern bool GOMP_loop_static_start (long, long, long, long, long *, long *);
extern bool GOMP_loop_dynamic_start (long, long, long, long, long *, long *);
extern bool GOMP_loop_guided_start (long, long, long, long, long *, long *);
extern bool GOMP_loop_runtime_start (long, long, long, long *, long *);
extern bool GOMP_loop_nonmonotonic_dynamic_start (long, long, long, long,
long *, long *);
extern bool GOMP_loop_nonmonotonic_guided_start (long, long, long, long,
long *, long *);
extern bool GOMP_loop_nonmonotonic_runtime_start (long, long, long,
long *, long *);
extern bool GOMP_loop_maybe_nonmonotonic_runtime_start (long, long, long,
long *, long *);
extern bool GOMP_loop_start (long, long, long, long, long, long *, long *,
uintptr_t *, void **);
extern bool GOMP_loop_ordered_static_start (long, long, long, long,
long *, long *);
extern bool GOMP_loop_ordered_dynamic_start (long, long, long, long,
long *, long *);
extern bool GOMP_loop_ordered_guided_start (long, long, long, long,
long *, long *);
extern bool GOMP_loop_ordered_runtime_start (long, long, long, long *, long *);
extern bool GOMP_loop_ordered_start (long, long, long, long, long, long *,
long *, uintptr_t *, void **);
extern bool GOMP_loop_static_next (long *, long *);
extern bool GOMP_loop_dynamic_next (long *, long *);
extern bool GOMP_loop_guided_next (long *, long *);
extern bool GOMP_loop_runtime_next (long *, long *);
extern bool GOMP_loop_nonmonotonic_dynamic_next (long *, long *);
extern bool GOMP_loop_nonmonotonic_guided_next (long *, long *);
extern bool GOMP_loop_nonmonotonic_runtime_next (long *, long *);
extern bool GOMP_loop_maybe_nonmonotonic_runtime_next (long *, long *);
extern bool GOMP_loop_ordered_static_next (long *, long *);
extern bool GOMP_loop_ordered_dynamic_next (long *, long *);
extern bool GOMP_loop_ordered_guided_next (long *, long *);
extern bool GOMP_loop_ordered_runtime_next (long *, long *);
extern bool GOMP_loop_doacross_static_start (unsigned, long *, long, long *,
long *);
extern bool GOMP_loop_doacross_dynamic_start (unsigned, long *, long, long *,
long *);
extern bool GOMP_loop_doacross_guided_start (unsigned, long *, long, long *,
long *);
extern bool GOMP_loop_doacross_runtime_start (unsigned, long *, long *,
long *);
extern bool GOMP_loop_doacross_start (unsigned, long *, long, long, long *,
long *, uintptr_t *, void **);
extern void GOMP_parallel_loop_static_start (void (*)(void *), void *,
unsigned, long, long, long, long);
extern void GOMP_parallel_loop_dynamic_start (void (*)(void *), void *,
unsigned, long, long, long, long);
extern void GOMP_parallel_loop_guided_start (void (*)(void *), void *,
unsigned, long, long, long, long);
extern void GOMP_parallel_loop_runtime_start (void (*)(void *), void *,
unsigned, long, long, long);
extern void GOMP_parallel_loop_static (void (*)(void *), void *,
unsigned, long, long, long, long,
unsigned);
extern void GOMP_parallel_loop_dynamic (void (*)(void *), void *,
unsigned, long, long, long, long,
unsigned);
extern void GOMP_parallel_loop_guided (void (*)(void *), void *,
unsigned, long, long, long, long,
unsigned);
extern void GOMP_parallel_loop_runtime (void (*)(void *), void *,
unsigned, long, long, long,
unsigned);
extern void GOMP_parallel_loop_nonmonotonic_dynamic (void (*)(void *), void *,
unsigned, long, long,
long, long, unsigned);
extern void GOMP_parallel_loop_nonmonotonic_guided (void (*)(void *), void *,
unsigned, long, long,
long, long, unsigned);
extern void GOMP_parallel_loop_nonmonotonic_runtime (void (*)(void *), void *,
unsigned, long, long,
long, unsigned);
extern void GOMP_parallel_loop_maybe_nonmonotonic_runtime (void (*)(void *),
void *, unsigned,
long, long,
long, unsigned);
extern void GOMP_loop_end (void);
extern void GOMP_loop_end_nowait (void);
extern bool GOMP_loop_end_cancel (void);
/* loop_ull.c */
extern bool GOMP_loop_ull_static_start (bool, unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_dynamic_start (bool, unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_guided_start (bool, unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_runtime_start (bool, unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_nonmonotonic_dynamic_start (bool, unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_nonmonotonic_guided_start (bool, unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_nonmonotonic_runtime_start (bool, unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_maybe_nonmonotonic_runtime_start (bool,
unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_start (bool, unsigned long long, unsigned long long,
unsigned long long, long, unsigned long long,
unsigned long long *, unsigned long long *,
uintptr_t *, void **);
extern bool GOMP_loop_ull_ordered_static_start (bool, unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_ordered_dynamic_start (bool, unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_ordered_guided_start (bool, unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_ordered_runtime_start (bool, unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_ordered_start (bool, unsigned long long,
unsigned long long,
unsigned long long, long,
unsigned long long,
unsigned long long *,
unsigned long long *,
uintptr_t *, void **);
extern bool GOMP_loop_ull_static_next (unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_dynamic_next (unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_guided_next (unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_runtime_next (unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_nonmonotonic_dynamic_next (unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_nonmonotonic_guided_next (unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_nonmonotonic_runtime_next (unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_maybe_nonmonotonic_runtime_next (unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_ordered_static_next (unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_ordered_dynamic_next (unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_ordered_guided_next (unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_ordered_runtime_next (unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_doacross_static_start (unsigned,
unsigned long long *,
unsigned long long,
unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_doacross_dynamic_start (unsigned,
unsigned long long *,
unsigned long long,
unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_doacross_guided_start (unsigned,
unsigned long long *,
unsigned long long,
unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_doacross_runtime_start (unsigned,
unsigned long long *,
unsigned long long *,
unsigned long long *);
extern bool GOMP_loop_ull_doacross_start (unsigned, unsigned long long *,
long, unsigned long long,
unsigned long long *,
unsigned long long *,
uintptr_t *, void **);
/* ordered.c */
extern void GOMP_ordered_start (void);
extern void GOMP_ordered_end (void);
extern void GOMP_doacross_post (long *);
extern void GOMP_doacross_wait (long, ...);
extern void GOMP_doacross_ull_post (unsigned long long *);
extern void GOMP_doacross_ull_wait (unsigned long long, ...);
/* parallel.c */
extern void GOMP_parallel_start (void (*) (void *), void *, unsigned);
extern void GOMP_parallel_end (void);
extern void GOMP_parallel (void (*) (void *), void *, unsigned, unsigned);
extern unsigned GOMP_parallel_reductions (void (*) (void *), void *, unsigned,
unsigned);
extern bool GOMP_cancel (int, bool);
extern bool GOMP_cancellation_point (int);
/* task.c */
extern void GOMP_task (void (*) (void *), void *, void (*) (void *, void *),
long, long, bool, unsigned, void **, int, void *);
extern void GOMP_taskloop (void (*) (void *), void *,
void (*) (void *, void *), long, long, unsigned,
unsigned long, int, long, long, long);
extern void GOMP_taskloop_ull (void (*) (void *), void *,
void (*) (void *, void *), long, long,
unsigned, unsigned long, int,
unsigned long long, unsigned long long,
unsigned long long);
extern void GOMP_taskwait (void);
extern void GOMP_taskwait_depend (void **);
extern void GOMP_taskwait_depend_nowait (void **);
extern void GOMP_taskyield (void);
extern void GOMP_taskgroup_start (void);
extern void GOMP_taskgroup_end (void);
extern void GOMP_taskgroup_reduction_register (uintptr_t *);
extern void GOMP_taskgroup_reduction_unregister (uintptr_t *);
extern void GOMP_task_reduction_remap (size_t, size_t, void **);
extern void GOMP_workshare_task_reduction_unregister (bool);
/* sections.c */
extern unsigned GOMP_sections_start (unsigned);
extern unsigned GOMP_sections2_start (unsigned, uintptr_t *, void **);
extern unsigned GOMP_sections_next (void);
extern void GOMP_parallel_sections_start (void (*) (void *), void *,
unsigned, unsigned);
extern void GOMP_parallel_sections (void (*) (void *), void *,
unsigned, unsigned, unsigned);
extern void GOMP_sections_end (void);
extern void GOMP_sections_end_nowait (void);
extern bool GOMP_sections_end_cancel (void);
/* single.c */
extern bool GOMP_single_start (void);
extern void *GOMP_single_copy_start (void);
extern void GOMP_single_copy_end (void *);
/* scope.c */
extern void GOMP_scope_start (uintptr_t *);
/* target.c */
extern void GOMP_target (int, void (*) (void *), const void *,
size_t, void **, size_t *, unsigned char *);
extern void GOMP_target_ext (int, void (*) (void *), size_t, void **, size_t *,
unsigned short *, unsigned int, void **, void **);
extern void GOMP_target_data (int, const void *,
size_t, void **, size_t *, unsigned char *);
extern void GOMP_target_data_ext (int, size_t, void **, size_t *,
unsigned short *);
extern void GOMP_target_end_data (void);
extern void GOMP_target_update (int, const void *,
size_t, void **, size_t *, unsigned char *);
extern void GOMP_target_update_ext (int, size_t, void **, size_t *,
unsigned short *, unsigned int, void **);
extern void GOMP_target_enter_exit_data (int, size_t, void **, size_t *,
unsigned short *, unsigned int,
void **);
extern void GOMP_teams (unsigned int, unsigned int);
extern bool GOMP_teams4 (unsigned int, unsigned int, unsigned int, bool);
extern void *GOMP_target_map_indirect_ptr (void *);
/* teams.c */
extern void GOMP_teams_reg (void (*) (void *), void *, unsigned, unsigned,
unsigned);
/* allocator.c */
extern void *GOMP_alloc (size_t, size_t, uintptr_t);
extern void GOMP_free (void *, uintptr_t);
/* error.c */
extern void GOMP_warning (const char *, size_t);
extern void GOMP_error (const char *, size_t);
/* oacc-async.c */
extern void GOACC_wait (int, int, ...);
/* oacc-mem.c */
extern void GOACC_enter_exit_data (int, size_t, void **, size_t *,
unsigned short *, int, int, ...);
extern void GOACC_enter_data (int, size_t, void **, size_t *,
unsigned short *, int, int, ...);
extern void GOACC_exit_data (int, size_t, void **, size_t *,
unsigned short *, int, int, ...);
extern void GOACC_declare (int, size_t, void **, size_t *, unsigned short *);
/* oacc-parallel.c */
extern void GOACC_parallel_keyed (int, void (*) (void *), size_t,
void **, size_t *, unsigned short *, ...);
extern void GOACC_parallel (int, void (*) (void *), size_t, void **, size_t *,
unsigned short *, int, int, int, int, int, ...);
extern void GOACC_data_start (int, size_t, void **, size_t *,
unsigned short *);
extern void GOACC_data_end (void);
extern void GOACC_update (int, size_t, void **, size_t *,
unsigned short *, int, int, ...);
extern int GOACC_get_num_threads (void);
extern int GOACC_get_thread_num (void);
#endif /* LIBGOMP_G_H */