Richard Biener wrote:
I'm not sure, you pushed some of the changes under discussion, so

[Slightly prematurely/accidentally early. As it wasn't really
wrong, I didn't want to revert it, though.]

I thought this one was off the table. [...]

OK, I finally found the patch that I wanted to attach – but didn't
because I put it into the wrong directory and picked the latest
patch from the right directory. - And did not notice when I pinged!

Sorry for the confusion! Attached is the patch I was actually
trying to talk about in my last two emails ...


Note the removed 'offload_handle_link_vars' call; as written in the
previous email (which quotes the calls in the source code), this
call comes to early for handling renaming of same-named global
static variables stemming from multiple TU. Hence, calls were added
to later parts in the code (same function, indirectly in the 'if'
and directly in the 'else' branch).
However, the old call stayed - such that the function was always
called twice. This was redundant but only started failing
when creating the symtab node and not only invoked build_decl twice.

Since it is now only called once, the 'DECL_HAS_VALUE_EXPR_P' check
could now be removed again!

Sorry again!

Tobias
lto.cc: OpenMP's offload_handle_link_vars - fix for global variables [PR127273]

This is about variables that appear in OpenMP's 'link' clause of
the 'declare target' directive. On the host, they are normal
static variables - while on the device, they are pointer variables
that point to the actual data, i.e. the access 'var' on the host
becomes '* var$linkptr' on the device side, using a VALUE_EXPR
to achieve this.  The offload_handle_link_vars handles this 
('#if ACCEL_COMPILER').

For global variables, additional issues occurred:
* The function would be called multiple times for the same variable
  each time calling 'build_decl' again.
  Solution: If there is already a VALUE_EXPR, skip.
* Some code, in particular ipa_reference_var_uid assumes that also
  decl->decl_with_vis.symtab_node is not NULL.
  Solution: Call varpool_node::finalize_decl to create it.
* For some reasons some IPA analysis assumes that it is not needed
  and, hence, the node can be removed, which fails (see previous item).
  Solution: Use force_output.

As global static variables have to be output via the offload_vars,
the host and device side need to exist to make sure the n-th variable
in the host table is the same as the n-th variable on the device side,
i.e. forcing the output makes sense.

PR middle-end/127273

gcc/lto/ChangeLog:

	* lto.cc (offload_handle_link_vars): Create node and force_output;
	avoid creating the same '...$linkptr' var multiple times.

libgomp/ChangeLog:

	* testsuite/libgomp.c/usm_env_handling-1-self.c: Remove 'dg-ice'.

 gcc/lto/lto.cc                                        | 4 ++++
 libgomp/testsuite/libgomp.c/usm_env_handling-1-self.c | 8 ++------
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/gcc/lto/lto.cc b/gcc/lto/lto.cc
index 76837c27be8..d22827bbcc0 100644
--- a/gcc/lto/lto.cc
+++ b/gcc/lto/lto.cc
@@ -481,29 +481,33 @@ lto_wpa_write_files (void)
 static void
 offload_handle_link_vars (void)
 {
 #ifdef ACCEL_COMPILER
   varpool_node *var;
   FOR_EACH_VARIABLE (var)
     if (lookup_attribute ("omp declare target link",
 			  DECL_ATTRIBUTES (var->decl)))
       {
+	if (DECL_HAS_VALUE_EXPR_P (var->decl))
+	  continue;
 	tree type = build_pointer_type (TREE_TYPE (var->decl));
 	tree link_ptr_var = build_decl (UNKNOWN_LOCATION, VAR_DECL,
 					clone_function_name (var->decl,
 							     "linkptr"), type);
 	TREE_USED (link_ptr_var) = 1;
 	TREE_STATIC (link_ptr_var) = 1;
 	TREE_PUBLIC (link_ptr_var) = TREE_PUBLIC (var->decl);
 	DECL_ARTIFICIAL (link_ptr_var) = 1;
 	SET_DECL_ASSEMBLER_NAME (link_ptr_var, DECL_NAME (link_ptr_var));
 	SET_DECL_VALUE_EXPR (var->decl, build_simple_mem_ref (link_ptr_var));
 	DECL_HAS_VALUE_EXPR_P (var->decl) = 1;
+	varpool_node::finalize_decl (link_ptr_var);
+	varpool_node::get (link_ptr_var)->force_output = var->force_output;
       }
 #endif
 }
 
 /* Perform whole program analysis (WPA) on the callgraph and write out the
    optimization plan.  */
 
 static void
 do_whole_program_analysis (void)
diff --git a/libgomp/testsuite/libgomp.c/usm_env_handling-1-self.c b/libgomp/testsuite/libgomp.c/usm_env_handling-1-self.c
index 37a7b915b18..79cbd9ff031 100644
--- a/libgomp/testsuite/libgomp.c/usm_env_handling-1-self.c
+++ b/libgomp/testsuite/libgomp.c/usm_env_handling-1-self.c
@@ -1,13 +1,9 @@
 /* { dg-do run }  */
 
 /* Check that a global static variable is consistently updated on the device. */
 
-// ICE for A$linkptr in nvptx lto1 with ipa_reference_var_uid
-// when compiling with -fopenmp -O1 or higher
-// {Segmentation [Ff]ault}{ offload_target_nvptx } }
-// { dg-ice "PR target/127273" { offload_target_nvptx } }
-// { dg-excess-errors "'mkoffload' failure etc." { xfail { offload_target_nvptx } } } */
-
+// PR middle-end/127273 for an ICE fix
+// PR middle-end/122205 for converting enter to link for self_maps
 
 #define USE_SELF_MAPS 1
 #include "usm_env_handling-1.c"

Reply via email to