public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/marxin/heads/slp-function-v2)] openmp: ensure variables in offload table are streamed out (PRs 94848 + 95551)
@ 2020-06-11 10:04 Martin Liska
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Liska @ 2020-06-11 10:04 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:1c0fdaf79e3618fd7512608a2e5c62b6b306e9e8

commit 1c0fdaf79e3618fd7512608a2e5c62b6b306e9e8
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Mon Jun 8 23:24:57 2020 +0200

    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.

Diff:
---
 gcc/lto-cgraph.c                                 |  8 ++++++
 gcc/omp-offload.c                                | 12 ++++++++-
 libgomp/testsuite/libgomp.fortran/target-var.f90 | 32 ++++++++++++++++++++++++
 3 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c
index a671c671fa7..93a99f3465b 100644
--- a/gcc/lto-cgraph.c
+++ b/gcc/lto-cgraph.c
@@ -1069,6 +1069,10 @@ output_offload_tables (void)
 
   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,
 			   LTO_symtab_last_tag, LTO_symtab_unavail_node);
       lto_output_fn_decl_ref (ob->decl_state, ob->main_stream,
@@ -1077,6 +1081,10 @@ output_offload_tables (void)
 
   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,
 			   LTO_symtab_last_tag, LTO_symtab_variable);
       lto_output_var_decl_ref (ob->decl_state, ob->main_stream,
diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c
index b2df91a5724..4e44cfc9d0a 100644
--- a/gcc/omp-offload.c
+++ b/gcc/omp-offload.c
@@ -125,6 +125,10 @@ add_decls_addresses_to_decl_constructor (vec<tree, va_gc> *v_decls,
 #endif
 	  && 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;
       if (is_var)
 	size = fold_convert (const_ptr_type_node, DECL_SIZE_UNIT (it));
@@ -341,7 +345,7 @@ omp_finish_file (void)
       add_decls_addresses_to_decl_constructor (offload_vars, v_v);
 
       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,
 						     num_funcs);
       SET_TYPE_ALIGN (vars_decl_type, TYPE_ALIGN (pointer_sized_int_node));
@@ -376,11 +380,17 @@ omp_finish_file (void)
       for (unsigned i = 0; i < num_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);
 	}
       for (unsigned i = 0; i < num_vars; i++)
 	{
 	  tree it = (*offload_vars)[i];
+	  if (!symtab_node::get (it))
+	    continue;
 #ifdef ACCEL_COMPILER
 	  if (DECL_HAS_VALUE_EXPR_P (it)
 	      && lookup_attribute ("omp declare target link",
diff --git a/libgomp/testsuite/libgomp.fortran/target-var.f90 b/libgomp/testsuite/libgomp.fortran/target-var.f90
new file mode 100644
index 00000000000..5e5ccd47c96
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/target-var.f90
@@ -0,0 +1,32 @@
+! { 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


^ permalink raw reply	[flat|nested] 2+ messages in thread
* [gcc(refs/users/marxin/heads/slp-function-v2)] openmp: ensure variables in offload table are streamed out (PRs 94848 + 95551)
@ 2020-06-11 10:07 Martin Liska
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Liska @ 2020-06-11 10:07 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:bf4ab2689bb586971d5b2ab6b13d078cd7ac45af

commit bf4ab2689bb586971d5b2ab6b13d078cd7ac45af
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Tue Jun 9 16:31:22 2020 +0200

    openmp: ensure variables in offload table are streamed out (PRs 94848 + 95551)
    
    gcc/ChangeLog:
    
            * omp-offload.c (add_decls_addresses_to_decl_constructor,
            omp_finish_file): With in_lto_p, stream out all offload-table
            items even if the symtab_node does not exist.

Diff:
---
 gcc/omp-offload.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c
index 4e44cfc9d0a..32c2485abd4 100644
--- a/gcc/omp-offload.c
+++ b/gcc/omp-offload.c
@@ -126,7 +126,7 @@ add_decls_addresses_to_decl_constructor (vec<tree, va_gc> *v_decls,
 	  && 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))
+      if (!in_lto_p && !symtab_node::get (it))
 	continue;
 
       tree size = NULL_TREE;
@@ -382,14 +382,14 @@ omp_finish_file (void)
 	  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))
+	  if (!in_lto_p && !symtab_node::get (it))
 	    continue;
 	  targetm.record_offload_symbol (it);
 	}
       for (unsigned i = 0; i < num_vars; i++)
 	{
 	  tree it = (*offload_vars)[i];
-	  if (!symtab_node::get (it))
+	  if (!in_lto_p && !symtab_node::get (it))
 	    continue;
 #ifdef ACCEL_COMPILER
 	  if (DECL_HAS_VALUE_EXPR_P (it)


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-11 10:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-11 10:04 [gcc(refs/users/marxin/heads/slp-function-v2)] openmp: ensure variables in offload table are streamed out (PRs 94848 + 95551) Martin Liska
2020-06-11 10:07 Martin Liska

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).