Commit 9074deee by Tobias Burnus

openmp: ensure variables in offload table are streamed out (PRs 94848 + 95551)

gcc/ChangeLog:

	PR lto/94848
	PR middle-end/95551
	* omp-offload.c (add_decls_addresses_to_decl_constructor,
	omp_finish_file): Skip removed items.
	* lto-cgraph.c (output_offload_tables): Likewise; set force_output
	to this node for variables and functions.

libgomp/ChangeLog:

	PR lto/94848
	PR middle-end/95551
	* testsuite/libgomp.fortran/target-var.f90: New test.

(cherry picked from commit 1c0fdaf79e3618fd7512608a2e5c62b6b306e9e8)
parent 0a274fa1
...@@ -1067,6 +1067,10 @@ output_offload_tables (void) ...@@ -1067,6 +1067,10 @@ output_offload_tables (void)
for (unsigned i = 0; i < vec_safe_length (offload_funcs); i++) for (unsigned i = 0; i < vec_safe_length (offload_funcs); i++)
{ {
symtab_node *node = symtab_node::get ((*offload_funcs)[i]);
if (!node)
continue;
node->force_output = true;
streamer_write_enum (ob->main_stream, LTO_symtab_tags, streamer_write_enum (ob->main_stream, LTO_symtab_tags,
LTO_symtab_last_tag, LTO_symtab_unavail_node); LTO_symtab_last_tag, LTO_symtab_unavail_node);
lto_output_fn_decl_index (ob->decl_state, ob->main_stream, lto_output_fn_decl_index (ob->decl_state, ob->main_stream,
...@@ -1075,6 +1079,10 @@ output_offload_tables (void) ...@@ -1075,6 +1079,10 @@ output_offload_tables (void)
for (unsigned i = 0; i < vec_safe_length (offload_vars); i++) for (unsigned i = 0; i < vec_safe_length (offload_vars); i++)
{ {
symtab_node *node = symtab_node::get ((*offload_vars)[i]);
if (!node)
continue;
node->force_output = true;
streamer_write_enum (ob->main_stream, LTO_symtab_tags, streamer_write_enum (ob->main_stream, LTO_symtab_tags,
LTO_symtab_last_tag, LTO_symtab_variable); LTO_symtab_last_tag, LTO_symtab_variable);
lto_output_var_decl_index (ob->decl_state, ob->main_stream, lto_output_var_decl_index (ob->decl_state, ob->main_stream,
......
...@@ -124,6 +124,10 @@ add_decls_addresses_to_decl_constructor (vec<tree, va_gc> *v_decls, ...@@ -124,6 +124,10 @@ add_decls_addresses_to_decl_constructor (vec<tree, va_gc> *v_decls,
#endif #endif
&& lookup_attribute ("omp declare target link", DECL_ATTRIBUTES (it)); && lookup_attribute ("omp declare target link", DECL_ATTRIBUTES (it));
/* See also omp_finish_file and output_offload_tables in lto-cgraph.c. */
if (!symtab_node::get (it))
continue;
tree size = NULL_TREE; tree size = NULL_TREE;
if (is_var) if (is_var)
size = fold_convert (const_ptr_type_node, DECL_SIZE_UNIT (it)); size = fold_convert (const_ptr_type_node, DECL_SIZE_UNIT (it));
...@@ -180,7 +184,7 @@ omp_finish_file (void) ...@@ -180,7 +184,7 @@ omp_finish_file (void)
add_decls_addresses_to_decl_constructor (offload_vars, v_v); add_decls_addresses_to_decl_constructor (offload_vars, v_v);
tree vars_decl_type = build_array_type_nelts (pointer_sized_int_node, tree vars_decl_type = build_array_type_nelts (pointer_sized_int_node,
num_vars * 2); vec_safe_length (v_v));
tree funcs_decl_type = build_array_type_nelts (pointer_sized_int_node, tree funcs_decl_type = build_array_type_nelts (pointer_sized_int_node,
num_funcs); num_funcs);
SET_TYPE_ALIGN (vars_decl_type, TYPE_ALIGN (pointer_sized_int_node)); SET_TYPE_ALIGN (vars_decl_type, TYPE_ALIGN (pointer_sized_int_node));
...@@ -215,11 +219,17 @@ omp_finish_file (void) ...@@ -215,11 +219,17 @@ omp_finish_file (void)
for (unsigned i = 0; i < num_funcs; i++) for (unsigned i = 0; i < num_funcs; i++)
{ {
tree it = (*offload_funcs)[i]; tree it = (*offload_funcs)[i];
/* See also add_decls_addresses_to_decl_constructor
and output_offload_tables in lto-cgraph.c. */
if (!symtab_node::get (it))
continue;
targetm.record_offload_symbol (it); targetm.record_offload_symbol (it);
} }
for (unsigned i = 0; i < num_vars; i++) for (unsigned i = 0; i < num_vars; i++)
{ {
tree it = (*offload_vars)[i]; tree it = (*offload_vars)[i];
if (!symtab_node::get (it))
continue;
#ifdef ACCEL_COMPILER #ifdef ACCEL_COMPILER
if (DECL_HAS_VALUE_EXPR_P (it) if (DECL_HAS_VALUE_EXPR_P (it)
&& lookup_attribute ("omp declare target link", && lookup_attribute ("omp declare target link",
......
! { dg-additional-options "-O3" }
!
! With -O3 the static local variable A.10 generated for
! the array constructor [-2, -4, ..., -20] is optimized
! away - which has to be handled in the offload_vars table.
!
program main
implicit none (type, external)
integer :: j
integer, allocatable :: A(:)
A = [(3*j, j=1, 10)]
call bar (A)
deallocate (A)
contains
subroutine bar (array)
integer :: i
integer :: array(:)
!$omp target map(from:array)
!$acc parallel copyout(array)
array = [(-2*i, i = 1, size(array))]
!$omp do private(array)
!$acc loop gang private(array)
do i = 1, 10
array(i) = 9*i
end do
if (any (array /= [(-2*i, i = 1, 10)])) error stop 2
!$omp end target
!$acc end parallel
end subroutine bar
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment