From b434610704af7d25c66e2c6f5dd8c8ab46aa6df2 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 16 May 2016 13:16:28 +0000 Subject: [PATCH] nvptx.c (nvptx_mangle_decl_assembler_name): Revert. * config/nvptx/nvptx.c (nvptx_mangle_decl_assembler_name): Revert. (nvptx_name_replacement): Restore. Add comment. (write_fn_proto, write_fn_proto_from_insn, nvptx_output_call_insn): Restore (TARGET_MANGLE_DECL_ASSEMBLER_NAME): Delete. From-SVN: r236286 --- gcc/ChangeLog | 12 ++++++-- gcc/config/nvptx/nvptx.c | 60 ++++++++++++++++++++-------------------- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ec7cf67a522..4ecd3e7919e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2016-05-16 Nathan Sidwell + + * config/nvptx/nvptx.c (nvptx_mangle_decl_assembler_name): Revert. + (nvptx_name_replacement): Restore. Add comment. + (write_fn_proto, write_fn_proto_from_insn, + nvptx_output_call_insn): Restore + (TARGET_MANGLE_DECL_ASSEMBLER_NAME): Delete. + 2016-05-16 Wilco Dijkstra * config/aarch64/aarch64.md @@ -59,8 +67,8 @@ 2016-05-16 Jan Hubicka * ipa-inline.c (report_inline_failed_reason): Look into thunks, too - (inline_small_functions): Do not look for function symbol when resetting - caches. + (inline_small_functions): Do not look for function symbol when + resetting caches. 2016-05-16 Jan Hubicka diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c index 85f85bb6404..e81a450a20c 100644 --- a/gcc/config/nvptx/nvptx.c +++ b/gcc/config/nvptx/nvptx.c @@ -211,31 +211,6 @@ nvptx_ptx_type_from_mode (machine_mode mode, bool promote) } } -/* Return an identifier node for DECL. Usually thee default mangled - name ID is useable. Some names cannot be used directly, so prefix - them with __nvptx_. */ - -static tree -nvptx_mangle_decl_assembler_name (tree ARG_UNUSED (decl), tree id) -{ - static const char *const bad_names[] = - {"call", "malloc", "free", "realloc", 0}; - int ix; - const char *name = IDENTIFIER_POINTER (id); - - for (ix = 0; bad_names[ix]; ix++) - if (!strcmp (bad_names[ix], name)) - { - char *new_name = XALLOCAVEC (char, - strlen (name) + sizeof ("__nvptx_")); - sprintf (new_name, "__nvptx_%s", name); - id = get_identifier (new_name); - break; - } - - return id; -} - /* Encode the PTX data area that DECL (which might not actually be a _DECL) should reside in. */ @@ -281,6 +256,27 @@ section_for_decl (const_tree decl) return section_for_sym (XEXP (DECL_RTL (CONST_CAST (tree, decl)), 0)); } +/* Check NAME for special function names and redirect them by returning a + replacement. This applies to malloc, free and realloc, for which we + want to use libgcc wrappers, and call, which triggers a bug in + ptxas. We can't use TARGET_MANGLE_DECL_ASSEMBLER_NAME, as that's + not active in an offload compiler -- the names are all set by the + host-side compiler. */ + +static const char * +nvptx_name_replacement (const char *name) +{ + if (strcmp (name, "call") == 0) + return "__nvptx_call"; + if (strcmp (name, "malloc") == 0) + return "__nvptx_malloc"; + if (strcmp (name, "free") == 0) + return "__nvptx_free"; + if (strcmp (name, "realloc") == 0) + return "__nvptx_realloc"; + return name; +} + /* If MODE should be treated as two registers of an inner mode, return that inner mode. Otherwise return VOIDmode. */ @@ -738,8 +734,13 @@ write_fn_proto (std::stringstream &s, bool is_defn, if (is_defn) /* Emit a declaration. The PTX assembler gets upset without it. */ name = write_fn_proto (s, false, name, decl); - else if (name[0] == '*') - name++; + else + { + /* Avoid repeating the name replacement. */ + name = nvptx_name_replacement (name); + if (name[0] == '*') + name++; + } write_fn_marker (s, is_defn, TREE_PUBLIC (decl), name); @@ -843,6 +844,7 @@ write_fn_proto_from_insn (std::stringstream &s, const char *name, } else { + name = nvptx_name_replacement (name); write_fn_marker (s, false, true, name); s << "\t.extern .func "; } @@ -1860,6 +1862,7 @@ nvptx_output_call_insn (rtx_insn *insn, rtx result, rtx callee) if (decl) { const char *name = get_fnname_from_decl (decl); + name = nvptx_name_replacement (name); assemble_name (asm_out_file, name); } else @@ -4887,9 +4890,6 @@ nvptx_goacc_reduction (gcall *call) #undef TARGET_NO_REGISTER_ALLOCATION #define TARGET_NO_REGISTER_ALLOCATION true -#undef TARGET_MANGLE_DECL_ASSEMBLER_NAME -#define TARGET_MANGLE_DECL_ASSEMBLER_NAME nvptx_mangle_decl_assembler_name - #undef TARGET_ENCODE_SECTION_INFO #define TARGET_ENCODE_SECTION_INFO nvptx_encode_section_info #undef TARGET_RECORD_OFFLOAD_SYMBOL -- 2.30.2