* [PTX] assembler name mangling
@ 2016-05-13 15:56 Nathan Sidwell
2016-05-13 16:39 ` Alexander Monakov
0 siblings, 1 reply; 3+ messages in thread
From: Nathan Sidwell @ 2016-05-13 15:56 UTC (permalink / raw)
To: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 591 bytes --]
I've committed this cleanup to use TARGET_MANGLE_DECL_ASSEMBLER_NAME rather than
the ad-hoc solution the ptx backend currently has. I didn't address it during
the earlier set of cleanups as I felt there were more important things to
address then.
I did discover an issue in langhooks, where the target name mangling hook wasn't
being called, and led to __builtin_realloc and friends not being mangled as
needed. I've applied this change to langhooks as obvious. The only other use
of this target hook appears to be i386-mingw, where the additional call appears
harmless.
nathan
[-- Attachment #2: ptx-mangle.patch --]
[-- Type: text/x-patch, Size: 4012 bytes --]
2016-05-13 Nathan Sidwell <nathan@acm.org>
* config/nvptx/nvptx.c (nvptx_mangle_decl_assembler_name): New.
(nvptx_name_replacement): Delete.
(write_fn_proto, write_fn_proto_from_insn,
nvptx_output_call_insn): Remove nvptx_name_replacement call.
(TARGET_MANGLE_DECL_ASSEMBLER_NAME): Override.
* langhooks.c (add_builtin_funcction_common): Call
targetm.mangle_decl_assembler_name.
Index: config/nvptx/nvptx.c
===================================================================
--- config/nvptx/nvptx.c (revision 236211)
+++ config/nvptx/nvptx.c (working copy)
@@ -211,6 +211,31 @@ nvptx_ptx_type_from_mode (machine_mode m
}
}
+/* 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. */
@@ -256,24 +281,6 @@ 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. */
-
-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. */
@@ -731,13 +738,8 @@ write_fn_proto (std::stringstream &s, bo
if (is_defn)
/* Emit a declaration. The PTX assembler gets upset without it. */
name = write_fn_proto (s, false, name, decl);
- else
- {
- /* Avoid repeating the name replacement. */
- name = nvptx_name_replacement (name);
- if (name[0] == '*')
- name++;
- }
+ else if (name[0] == '*')
+ name++;
write_fn_marker (s, is_defn, TREE_PUBLIC (decl), name);
@@ -841,7 +843,6 @@ write_fn_proto_from_insn (std::stringstr
}
else
{
- name = nvptx_name_replacement (name);
write_fn_marker (s, false, true, name);
s << "\t.extern .func ";
}
@@ -1859,7 +1860,6 @@ nvptx_output_call_insn (rtx_insn *insn,
if (decl)
{
const char *name = get_fnname_from_decl (decl);
- name = nvptx_name_replacement (name);
assemble_name (asm_out_file, name);
}
else
@@ -4887,6 +4887,9 @@ 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
Index: langhooks.c
===================================================================
--- langhooks.c (revision 236208)
+++ langhooks.c (working copy)
@@ -561,6 +561,8 @@ add_builtin_function_common (const char
if (library_name)
{
tree libname = get_identifier (library_name);
+
+ libname = targetm.mangle_decl_assembler_name (decl, libname);
SET_DECL_ASSEMBLER_NAME (decl, libname);
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PTX] assembler name mangling
2016-05-13 15:56 [PTX] assembler name mangling Nathan Sidwell
@ 2016-05-13 16:39 ` Alexander Monakov
2016-05-16 12:53 ` Nathan Sidwell
0 siblings, 1 reply; 3+ messages in thread
From: Alexander Monakov @ 2016-05-13 16:39 UTC (permalink / raw)
To: Nathan Sidwell; +Cc: GCC Patches
Hello,
On Fri, 13 May 2016, Nathan Sidwell wrote:
> I've committed this cleanup to use TARGET_MANGLE_DECL_ASSEMBLER_NAME rather
> than the ad-hoc solution the ptx backend currently has. I didn't address it
> during the earlier set of cleanups as I felt there were more important things
> to address then.
This regresses offloading compilation: the new hook isn't applied during LTO
stream-in, so target functions named 'call' won't be remapped.
I'd solve it by avoiding the hook and performing remapping in a simple IPA
pass registered from the backend.
Alexander
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PTX] assembler name mangling
2016-05-13 16:39 ` Alexander Monakov
@ 2016-05-16 12:53 ` Nathan Sidwell
0 siblings, 0 replies; 3+ messages in thread
From: Nathan Sidwell @ 2016-05-16 12:53 UTC (permalink / raw)
To: Alexander Monakov; +Cc: GCC Patches
On 05/13/16 12:39, Alexander Monakov wrote:
> This regresses offloading compilation: the new hook isn't applied during LTO
> stream-in, so target functions named 'call' won't be remapped.
foop :( I've restored the old behaviour.
nathan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-05-16 12:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-13 15:56 [PTX] assembler name mangling Nathan Sidwell
2016-05-13 16:39 ` Alexander Monakov
2016-05-16 12:53 ` Nathan Sidwell
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).