diff mbox

[gomp4] fix spinlock

Message ID 55C31DAB.9040307@acm.org
State New
Headers show

Commit Message

Nathan Sidwell Aug. 6, 2015, 8:41 a.m. UTC
I've committed this to fix the spinlock problem Cesar fell over.  While there I 
added more checking on the worker dimension.

nathan
diff mbox

Patch

2015-08-06  Nathan Sidwell  <nathan@codesourcery.com>

	* config/nvptx/nvptx.c (nvptx_expand_lock_unlock): Create label.
	(nvptx_validate_dims): Check worker dimension is not too big.
	* config/nvptx/nvptx.mc (nvptx_spinlock): Take label.

Index: gcc/config/nvptx/nvptx.c
===================================================================
--- gcc/config/nvptx/nvptx.c	(revision 226605)
+++ gcc/config/nvptx/nvptx.c	(working copy)
@@ -3318,8 +3318,14 @@  nvptx_expand_lock_unlock (tree exp, bool
   if (!lock)
     emit_insn (barrier);
   if (lock)
-    pat = gen_nvptx_spinlock (mem, space,
-			      gen_reg_rtx (SImode), gen_reg_rtx (BImode));
+    {
+      rtx_code_label *label = gen_label_rtx ();
+
+      LABEL_NUSES (label)++;
+      pat = gen_nvptx_spinlock (mem, space,
+				gen_reg_rtx (SImode), gen_reg_rtx (BImode),
+				label);
+    }
   else
     pat = gen_nvptx_spinunlock (mem, space);
   emit_insn (pat);
@@ -3531,7 +3537,6 @@  nvptx_validate_dims (tree decl, tree dim
 {
   tree adims[GOMP_DIM_MAX];
   unsigned ix;
-  bool changed = false;
   tree pos = dims;
 
   for (ix = 0; ix != GOMP_DIM_MAX; ix++)
@@ -3541,6 +3546,7 @@  nvptx_validate_dims (tree decl, tree dim
     }
   /* Define vector size for known hardware.  */
 #define PTX_VECTOR_LENGTH 32
+#define PTX_WORKER_LENGTH 32
   /* If the worker size is not 1, the vector size must be 32.  If
      the vector size is not 1, it must be 32.  */
   if ((adims[GOMP_DIM_WORKER]
@@ -3562,6 +3568,17 @@  nvptx_validate_dims (tree decl, tree dim
 	}
     }
 
+  /* Check the num workers is not too large.  */
+  if (adims[GOMP_DIM_WORKER]
+      && TREE_INT_CST_LOW (adims[GOMP_DIM_WORKER]) > PTX_WORKER_LENGTH)
+    {
+      tree use = build_int_cst (integer_type_node, PTX_WORKER_LENGTH);
+      warning_at (DECL_SOURCE_LOCATION (decl), 0,
+		  "using num_workers (%E), ignoring %E",
+		  use, adims[GOMP_DIM_WORKER]);
+      adims[GOMP_DIM_WORKER] = use;
+    }
+
   /* Set defaults.  */
   for (ix = 0; ix != GOMP_DIM_MAX; ix++)
     if (!adims[ix])
Index: gcc/config/nvptx/nvptx.md
===================================================================
--- gcc/config/nvptx/nvptx.md	(revision 226605)
+++ gcc/config/nvptx/nvptx.md	(working copy)
@@ -1578,9 +1578,10 @@ 
 			(match_operand:SI 1 "const_int_operand" "i")]
 		       UNSPECV_UNLOCK)
       (match_operand:SI 2 "register_operand" "=R")
-      (match_operand:BI 3 "register_operand" "=R")])]
+      (match_operand:BI 3 "register_operand" "=R")
+      (label_ref (match_operand 4 "" ""))])]
    ""
-   "1:\\t.atom%R1.cas.b32 %2,%0,0,1;setp.ne.u32 %3,%2,0;@%3 bra.uni 1b;")
+   "%4:\\t.atom%R1.cas.b32 %2,%0,0,1;setp.ne.u32 %3,%2,0;@%3 bra.uni %4;")
 
 (define_insn "nvptx_spinunlock"
    [(unspec_volatile [(match_operand:SI 0 "memory_operand" "m")