aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/nvptx
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2022-03-11 13:41:01 +0100
committerTom de Vries <tdevries@suse.de>2022-03-22 14:35:34 +0100
commitf8b15e177155960017ac0c5daef8780d1127f91c (patch)
tree675c4471f8a297f0e66d0b0baeca3a48d946ca6c /gcc/config/nvptx
parenta624388b9546b066250be8baa118b7d50c403c25 (diff)
downloadgcc-f8b15e177155960017ac0c5daef8780d1127f91c.zip
gcc-f8b15e177155960017ac0c5daef8780d1127f91c.tar.gz
gcc-f8b15e177155960017ac0c5daef8780d1127f91c.tar.bz2
[nvptx] Use .alias directive for mptx >= 6.3
Starting with ptx isa version 6.3, a ptx directive .alias is available. Use this directive to support symbol aliases, as far as possible. The alias support is off by default. It can be turned on using a switch -malias. Furthermore, for pre-sm_75, it's not effective unless the ptx version is bumped to 6.3 or higher using -mptx (given that the default for pre-sm_75 is 6.0). The alias support has the following limitations. Only function aliases are supported. Weak aliases are not supported. That is, if I disable the check in nvptx_asm_output_def_from_decls that disallows this, a weak alias is emitted and parsed by the driver. But the test gcc.dg/globalalias.c starts failing, with the behaviour matching the comment about "weird behavior of AIX's .set pseudo-op": a weak alias may resolve to different functions in different files. Aliases to weak symbols are not supported (see gcc.dg/localalias.c). This is currently not prohibited by the compiler, but with the driver link we run into: "error: Function test with .weak scope cannot be aliased". Aliases to aliases are not supported (see libgomp.c-c++-common/pr96390.c). This is currently not prohibited by the compiler, but with the driver link we run into: "Internal error: alias to unknown symbol" . Unreferenced aliases are not emitted (these can occur f.i. when inlining a call to an alias). This avoids driver link error "Internal error: reference to deleted section". When enabling malias by default, libgomp detects alias support and consequently libgomp.a will contains a few uses of .alias. This however results in aforementioned "Internal error: reference to deleted section" in many test-cases. Either there's some error with how .alias is used, or there's a driver bug. While this issue is not resolved, we keep malias off-by-default. At some point we may add support in the nvptx-tools linker for symbol aliases, and define f.i. malias=ptx and malias=ld to choose between the two in the compiler. An example of where this support is useful, is the OvO (OpenMP vs Offload) testsuite. The testsuite passes already at -O2. But at -O0, there are errors in some c++ test-cases due to missing symbol alias support. By compiling with -malias, the whole testsuite passes also at -O0. This patch causes a regression: ... -PASS: gcc.dg/pr60797.c (test for errors, line 4) +FAIL: gcc.dg/pr60797.c (test for errors, line 4) ... The test-case is skipped for effective target alias, and both without and with this patch the nvptx target is considered to not support it, so the test-case is executed. The test-case expects an error message along the lines of "alias definitions not supported in this configuration", but instead we run into: ... gcc.dg/pr60797.c:4:12: error: foo aliased to undefined symbol ... This is probably due to the fact that the nvptx backend now defines macros ASM_OUTPUT_DEF and ASM_OUTPUT_DEF_FROM_DECLS, so from the point of view of the common part of the compiler, aliases are supported. gcc/ChangeLog: 2022-03-18 Tom de Vries <tdevries@suse.de> PR target/104957 * config/nvptx/nvptx-protos.h (nvptx_asm_output_def_from_decls): Declare. * config/nvptx/nvptx.cc (write_fn_proto_1): Don't add function marker for alias. (SET_ASM_OP, NVPTX_ASM_OUTPUT_DEF): New macro def. (nvptx_asm_output_def_from_decls): New function. * config/nvptx/nvptx.h (ASM_OUTPUT_DEF): New macro def, define to gcc_unreachable (). (ASM_OUTPUT_DEF_FROM_DECLS): New macro def, define to nvptx_asm_output_def_from_decls. * config/nvptx/nvptx.opt (malias): New opt. gcc/testsuite/ChangeLog: 2022-03-18 Tom de Vries <tdevries@suse.de> PR target/104957 * gcc.target/nvptx/alias-1.c: New test. * gcc.target/nvptx/alias-2.c: New test. * gcc.target/nvptx/alias-3.c: New test. * gcc.target/nvptx/alias-4.c: New test. * gcc.target/nvptx/nvptx.exp (check_effective_target_runtime_ptx_isa_version_6_3): New proc.
Diffstat (limited to 'gcc/config/nvptx')
-rw-r--r--gcc/config/nvptx/nvptx-protos.h1
-rw-r--r--gcc/config/nvptx/nvptx.cc74
-rw-r--r--gcc/config/nvptx/nvptx.h17
-rw-r--r--gcc/config/nvptx/nvptx.opt3
4 files changed, 94 insertions, 1 deletions
diff --git a/gcc/config/nvptx/nvptx-protos.h b/gcc/config/nvptx/nvptx-protos.h
index 0bf9af4..ca0a87e 100644
--- a/gcc/config/nvptx/nvptx-protos.h
+++ b/gcc/config/nvptx/nvptx-protos.h
@@ -43,6 +43,7 @@ extern void nvptx_output_ascii (FILE *, const char *, unsigned HOST_WIDE_INT);
extern void nvptx_cpu_cpp_builtins (void);
extern void nvptx_register_pragmas (void);
extern unsigned int nvptx_data_alignment (const_tree, unsigned int);
+extern void nvptx_asm_output_def_from_decls (FILE *, tree, tree);
#ifdef RTX_CODE
extern void nvptx_expand_oacc_fork (unsigned);
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index f83f98c..b2f7b4a 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -77,6 +77,7 @@
#include "opts.h"
#include "tree-pretty-print.h"
#include "rtl-iter.h"
+#include "cgraph.h"
/* This file should be included last. */
#include "target-def.h"
@@ -968,7 +969,8 @@ static void
write_fn_proto_1 (std::stringstream &s, bool is_defn,
const char *name, const_tree decl)
{
- write_fn_marker (s, is_defn, TREE_PUBLIC (decl), name);
+ if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) == NULL)
+ write_fn_marker (s, is_defn, TREE_PUBLIC (decl), name);
/* PTX declaration. */
if (DECL_EXTERNAL (decl))
@@ -7393,6 +7395,76 @@ nvptx_mem_local_p (rtx mem)
return false;
}
+/* Define locally, for use in NVPTX_ASM_OUTPUT_DEF. */
+#define SET_ASM_OP ".alias "
+
+/* Define locally, for use in nvptx_asm_output_def_from_decls. Add NVPTX_
+ prefix to avoid clash with ASM_OUTPUT_DEF from nvptx.h.
+ Copy of ASM_OUTPUT_DEF from defaults.h, with added terminating
+ semicolon. */
+#define NVPTX_ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \
+ do \
+ { \
+ fprintf ((FILE), "%s", SET_ASM_OP); \
+ assemble_name (FILE, LABEL1); \
+ fprintf (FILE, ","); \
+ assemble_name (FILE, LABEL2); \
+ fprintf (FILE, ";\n"); \
+ } \
+ while (0)
+
+void
+nvptx_asm_output_def_from_decls (FILE *stream, tree name, tree value)
+{
+ if (nvptx_alias == 0 || !TARGET_PTX_6_3)
+ {
+ /* Copied from assemble_alias. */
+ error_at (DECL_SOURCE_LOCATION (name),
+ "alias definitions not supported in this configuration");
+ TREE_ASM_WRITTEN (name) = 1;
+ return;
+ }
+
+ if (lookup_attribute ("weak", DECL_ATTRIBUTES (name)))
+ {
+ /* Prevent execution FAILs for gcc.dg/globalalias.c and
+ gcc.dg/pr77587.c. */
+ error_at (DECL_SOURCE_LOCATION (name),
+ "weak alias definitions not supported in this configuration");
+ TREE_ASM_WRITTEN (name) = 1;
+ return;
+ }
+
+ /* Ptx also doesn't support value having weak linkage, but we can't detect
+ that here, so we'll end up with:
+ "error: Function test with .weak scope cannot be aliased".
+ See gcc.dg/localalias.c. */
+
+ if (TREE_CODE (name) != FUNCTION_DECL)
+ {
+ error_at (DECL_SOURCE_LOCATION (name),
+ "non-function alias definitions not supported"
+ " in this configuration");
+ TREE_ASM_WRITTEN (name) = 1;
+ return;
+ }
+
+ if (!cgraph_node::get (name)->referred_to_p ())
+ /* Prevent "Internal error: reference to deleted section". */
+ return;
+
+ std::stringstream s;
+ write_fn_proto (s, false, get_fnname_from_decl (name), name);
+ fputs (s.str ().c_str (), stream);
+
+ tree id = DECL_ASSEMBLER_NAME (name);
+ NVPTX_ASM_OUTPUT_DEF (stream, IDENTIFIER_POINTER (id),
+ IDENTIFIER_POINTER (value));
+}
+
+#undef NVPTX_ASM_OUTPUT_DEF
+#undef SET_ASM_OP
+
#undef TARGET_OPTION_OVERRIDE
#define TARGET_OPTION_OVERRIDE nvptx_option_override
diff --git a/gcc/config/nvptx/nvptx.h b/gcc/config/nvptx/nvptx.h
index b55ade6..75ac7a6 100644
--- a/gcc/config/nvptx/nvptx.h
+++ b/gcc/config/nvptx/nvptx.h
@@ -315,6 +315,23 @@ struct GTY(()) machine_function
((VALUE) = GET_MODE_BITSIZE ((MODE)), 2)
#define SUPPORTS_WEAK 1
+
+/* The documentation states that ASM_OUTPUT_DEF_FROM_DECLS is used in
+ preference to ASM_OUTPUT_DEF if the tree nodes are available. However, we
+ need the tree nodes to emit the prototype, so at this point it's not clear
+ how we can support ASM_OUTPUT_DEF. Still, we need to define it, or
+ ASM_OUTPUT_DEF_FROM_DECLS is ignored. For now, assert, and once we run
+ into it possibly improve by somehow emitting the prototype elsewhere, or
+ emitting a reasonable error message. */
+#define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \
+ do \
+ { \
+ gcc_unreachable (); \
+ } \
+ while (0)
+#define ASM_OUTPUT_DEF_FROM_DECLS(STREAM, NAME, VALUE) \
+ nvptx_asm_output_def_from_decls (STREAM, NAME, VALUE)
+
#define NO_DOT_IN_LABEL
#define ASM_COMMENT_START "//"
diff --git a/gcc/config/nvptx/nvptx.opt b/gcc/config/nvptx/nvptx.opt
index fea99c5..980428b 100644
--- a/gcc/config/nvptx/nvptx.opt
+++ b/gcc/config/nvptx/nvptx.opt
@@ -85,3 +85,6 @@ Initialize ptx registers.
mptx-comment
Target Var(nvptx_comment) Init(1) Undocumented
+
+malias
+Target Var(nvptx_alias) Init(0) Undocumented