This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PTX] atomic_compare_exchange_$n


The atomic_compare_exchange_$n builtins have an exciting calling convention where the 4th ('weak') parm is dropped in a real call. This caused gcc.dg/atomic-noinline.c to fail on PTX as the prototype didn't match the use.

Fixed thusly when emitting the ptx prototyp. Also fixed is the subsequently uncovered type mismatch in the testcase -- atomic_is_lock_free's first parm is size_t not int. Usually this mismatch is harmless even when one is 64 bits and the other 32. But again, PTX requires a match.

Applied to trunk.

nathan
2016-05-13  Nathan Sidwell  <nathan@acm.org>

	gcc/
	* config/nvptx/nvptx.c (write_fn_proto): Handle
	BUILT_IN_ATOMIC_COMPARE_EXCHANGE_n oddity.

	gcc/testsuite/
	* gcc.dg/atomic-noinline-aux.c: Include stddef.h. Fix
	__atomic_is_lock_free declaration.

Index: config/nvptx/nvptx.c
===================================================================
--- config/nvptx/nvptx.c	(revision 236208)
+++ config/nvptx/nvptx.c	(working copy)
@@ -751,6 +751,26 @@ write_fn_proto (std::stringstream &s, bo
   tree fntype = TREE_TYPE (decl);
   tree result_type = TREE_TYPE (fntype);
 
+  /* atomic_compare_exchange_$n builtins have an exceptional calling
+     convention.  */
+  int not_atomic_weak_arg = -1;
+  if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
+    switch (DECL_FUNCTION_CODE (decl))
+      {
+      case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_1:
+      case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_2:
+      case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_4:
+      case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_8:
+      case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_16:
+	/* These atomics skip the 'weak' parm in an actual library
+	   call.  We must skip it in the prototype too.  */
+	not_atomic_weak_arg = 3;
+	break;
+
+      default:
+	break;
+      }
+
   /* Declare the result.  */
   bool return_in_mem = write_return_type (s, true, result_type);
 
@@ -775,11 +795,14 @@ write_fn_proto (std::stringstream &s, bo
       prototyped = false;
     }
 
-  for (; args; args = TREE_CHAIN (args))
+  for (; args; args = TREE_CHAIN (args), not_atomic_weak_arg--)
     {
       tree type = prototyped ? TREE_VALUE (args) : TREE_TYPE (args);
-
-      argno = write_arg_type (s, -1, argno, type, prototyped);
+      
+      if (not_atomic_weak_arg)
+	argno = write_arg_type (s, -1, argno, type, prototyped);
+      else
+	gcc_assert (type == boolean_type_node);
     }
 
   if (stdarg_p (fntype))
Index: testsuite/gcc.dg/alias-15.c
===================================================================
--- testsuite/gcc.dg/alias-15.c	(revision 236208)
+++ testsuite/gcc.dg/alias-15.c	(nonexistent)
@@ -1,15 +0,0 @@
-/* { dg-do compile } */
-/* { dg-additional-options  "-O2 -fdump-ipa-cgraph" } */
-
-/* RTL-level CSE shouldn't introduce LCO (for the string) into varpool */
-char *p;
-
-void foo ()
-{
-  p = "abc\n";
-
-  while (*p != '\n')
-    p++;
-}
-
-/* { dg-final { scan-ipa-dump-not "LC0" "cgraph" } } */
Index: testsuite/gcc.dg/atomic-noinline-aux.c
===================================================================
--- testsuite/gcc.dg/atomic-noinline-aux.c	(revision 236208)
+++ testsuite/gcc.dg/atomic-noinline-aux.c	(working copy)
@@ -7,6 +7,7 @@
    the exact entry points the test file will require.  All these routines
    simply set the first parameter to 1, and the caller will test for that.  */
 
+#include <stddef.h>
 #include <stdlib.h>
 #include <stdbool.h>
 #include <string.h>
@@ -64,7 +65,7 @@ __atomic_fetch_nand_1 (unsigned char *p,
   return ret;
 }
 
-bool __atomic_is_lock_free (int i, void *p)
+bool __atomic_is_lock_free (size_t i, void *p)
 {
   *(short *)p = 1;
   return true;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]