On 12/20/2017 12:25 AM, Cesar Philippidis wrote:
In CUDA 9, Nvidia removed support for treating the labels of functions
as generic address spaces as part of their PTX 6.0 changes. More
specifically,
<http://docs.nvidia.com/cuda/parallel-thread-execution/index.html#changes-in-ptx-isa-version-6-0>:

   Support for taking address of labels, using labels in initializers
   which was unimplemented has been removed from the spec.

Despite targeting PTX 3.0, the ptxas assembler shipped with CUDA 9 no
longer support that legacy functionality. Consequently, this prevented
newlib from building. This patch fixes that problem by not using a
generic address space when initializing variables using a label address.


What is the effect for pre-9.0 cudas?

Is this OK for trunk?


How did you test this?

Thanks,
Cesar


og7-ptx-cuda9.diff


2017-12-19  Cesar Philippidis  <ce...@codesourcery.com>

        gcc/
        * config/nvptx/nvptx.c (output_init_frag): Don't use generic address
        spaces for function labels.

        gcc/testsuite/
        * gcc.target/nvptx/indirect_call.c: New test.


diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c
index dfb27ef..a7b4c09 100644
--- a/gcc/config/nvptx/nvptx.c
+++ b/gcc/config/nvptx/nvptx.c
@@ -1894,9 +1894,15 @@ output_init_frag (rtx sym)
if (sym)
      {
-      fprintf (asm_out_file, "generic(");
+      bool function = SYMBOL_REF_DECL (sym)
+       && (TREE_CODE (SYMBOL_REF_DECL (sym)) == FUNCTION_DECL);

Please indent using parentheses like this:

bool function = (SYMBOL_REF_DECL (sym)
                 && (TREE_CODE (SYMBOL_REF_DECL (sym)) == ...));


+      if (!function)
+       fprintf (asm_out_file, "generic(");
        output_address (VOIDmode, sym);
-      fprintf (asm_out_file, val ? ") + " : ")");
+      if (!function)
+       fprintf (asm_out_file, val ? ") + " : ")");
+      else if (val)
+       fprintf (asm_out_file, " + ");


Please use:

      if (!function)
        fprintf (asm_out_file, ")");
      if (val)
        fprintf (asm_out_file, " + ");

      }
if (!sym || val)
diff --git a/gcc/testsuite/gcc.target/nvptx/indirect_call.c 
b/gcc/testsuite/gcc.target/nvptx/indirect_call.c
new file mode 100644
index 0000000..39992a7
--- /dev/null
+++ b/gcc/testsuite/gcc.target/nvptx/indirect_call.c
@@ -0,0 +1,19 @@
+/* { dg-options "-O2 -msoft-stack" } */
+/* { dg-do run } */
+
+int
+f1 (int a)
+{
+  return a + 1;
+}
+
+int (*f2)(int) = f1;
+
+int
+main ()
+{
+  if (f2 (100) != 101)
+    __builtin_abort();
+
+  return 0;
+}


Reply via email to