From 1002a7ace111d746249fdea71af9b8e039cea0eb Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Wed, 23 Mar 2022 09:44:39 +0100 Subject: LTO: Fixes for renaming issues with offload/OpenMP [PR104285] gcc/lto/ChangeLog: PR middle-end/104285 * lto-partition.cc (maybe_rewrite_identifier): Use get_identifier for the returned string to be usable as hash key. (validize_symbol_for_target): Hence, use return value directly. (privatize_symbol_name_1): Track maybe_rewrite_identifier renames. * lto.cc (offload_handle_link_vars): Move function up before ... (do_whole_program_analysis): Call it after static renamings. (lto_main): Move call after static renamings. libgomp/ChangeLog: PR middle-end/104285 * testsuite/libgomp.c++/target-same-name-2-a.C: New test. * testsuite/libgomp.c++/target-same-name-2-b.C: New test. * testsuite/libgomp.c++/target-same-name-2.C: New test. * testsuite/libgomp.c-c++-common/target-same-name-1-a.c: New test. * testsuite/libgomp.c-c++-common/target-same-name-1-b.c: New test. * testsuite/libgomp.c-c++-common/target-same-name-1.c: New test. --- gcc/lto/lto-partition.cc | 17 ++++++++------ gcc/lto/lto.cc | 58 ++++++++++++++++++++++++++---------------------- 2 files changed, 41 insertions(+), 34 deletions(-) (limited to 'gcc/lto') diff --git a/gcc/lto/lto-partition.cc b/gcc/lto/lto-partition.cc index 062fd03..ebb9c3a 100644 --- a/gcc/lto/lto-partition.cc +++ b/gcc/lto/lto-partition.cc @@ -898,6 +898,11 @@ maybe_rewrite_identifier (const char *ptr) } copy[off] = valid; } + if (copy) + { + match = IDENTIFIER_POINTER (get_identifier (copy)); + free (copy); + } return match; #else return ptr; @@ -921,9 +926,7 @@ validize_symbol_for_target (symtab_node *node) { symtab->change_decl_assembler_name (decl, get_identifier (name2)); if (node->lto_file_data) - lto_record_renamed_decl (node->lto_file_data, name, - IDENTIFIER_POINTER - (DECL_ASSEMBLER_NAME (decl))); + lto_record_renamed_decl (node->lto_file_data, name, name2); } } @@ -936,12 +939,12 @@ static hash_map *lto_clone_numbers; static bool privatize_symbol_name_1 (symtab_node *node, tree decl) { - const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); + const char *name0 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); - if (must_not_rename (node, name)) + if (must_not_rename (node, name0)) return false; - name = maybe_rewrite_identifier (name); + const char *name = maybe_rewrite_identifier (name0); unsigned &clone_number = lto_clone_numbers->get_or_insert (name); symtab->change_decl_assembler_name (decl, clone_function_name ( @@ -949,7 +952,7 @@ privatize_symbol_name_1 (symtab_node *node, tree decl) clone_number++; if (node->lto_file_data) - lto_record_renamed_decl (node->lto_file_data, name, + lto_record_renamed_decl (node->lto_file_data, name0, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); diff --git a/gcc/lto/lto.cc b/gcc/lto/lto.cc index 98c336a..31b0c18 100644 --- a/gcc/lto/lto.cc +++ b/gcc/lto/lto.cc @@ -424,6 +424,32 @@ lto_wpa_write_files (void) timevar_pop (TV_WHOPR_WPA_IO); } +/* Create artificial pointers for "omp declare target link" vars. */ + +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))) + { + 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; + } +#endif +} + /* Perform whole program analysis (WPA) on the callgraph and write out the optimization plan. */ @@ -516,6 +542,7 @@ do_whole_program_analysis (void) to globals with hidden visibility because they are accessed from multiple partitions. */ lto_promote_cross_file_statics (); + offload_handle_link_vars (); if (dump_file) dump_end (partition_dump_id, dump_file); dump_file = NULL; @@ -549,32 +576,6 @@ do_whole_program_analysis (void) dump_memory_report ("Final"); } -/* Create artificial pointers for "omp declare target link" vars. */ - -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))) - { - 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; - } -#endif -} - unsigned int lto_option_lang_mask (void) { @@ -641,7 +642,10 @@ lto_main (void) materialize_cgraph (); if (!flag_ltrans) - lto_promote_statics_nonwpa (); + { + lto_promote_statics_nonwpa (); + offload_handle_link_vars (); + } /* Annotate the CU DIE and mark the early debug phase as finished. */ debuginfo_early_start (); -- cgit v1.1