On 10/26/15 07:36, Richard Biener wrote:

Looks better now.

+         {
  #ifdef HAVE_oacc_fork

(etc.)  can you use target-insn.def and targetm.have_oacc_fork () instead?


I've committed this to gomp4.  Will port and update the patches for trunk.

nathan
2015-10-26  Nathan Sidwell  <nat...@codesourcery.com>

	* internal-fn.c (expand_UNIQUE, expand_GOACC_DIM_SIZE,
	expand_GOACC_DIM_POS): Use targetm to discover and generate insns.
	* target-insns.def (oacc_dim_pos, oacc_dim_size, oacc_fork,
	oacc_join, unique): Define insns.

Index: gcc/internal-fn.c
===================================================================
--- gcc/internal-fn.c	(revision 229365)
+++ gcc/internal-fn.c	(working copy)
@@ -1970,32 +1970,30 @@ expand_UNIQUE (gcall *stmt)
       gcc_unreachable ();
 
     case IFN_UNIQUE_UNSPEC:
-#ifdef HAVE_unique
-      pattern = gen_unique ();
-#endif
+      if (targetm.have_unique ())
+	pattern = targetm.gen_unique ();
       break;
 
     case IFN_UNIQUE_OACC_FORK:
     case IFN_UNIQUE_OACC_JOIN:
-      {
-#if defined (HAVE_oacc_fork) && defined (HAVE_oacc_join)
-	tree lhs = gimple_call_lhs (stmt);
-	rtx target = const0_rtx;
-
-	if (lhs)
-	  target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
-
-	rtx data_dep = expand_normal (gimple_call_arg (stmt, 1));
-	rtx axis = expand_normal (gimple_call_arg (stmt, 2));
-
-	if (code == IFN_UNIQUE_OACC_FORK)
-	  pattern = gen_oacc_fork (target, data_dep, axis);
-	else
-	  pattern = gen_oacc_join (target, data_dep, axis);
-#else
+      if (targetm.have_oacc_fork () && targetm.have_oacc_join ())
+	{
+	  tree lhs = gimple_call_lhs (stmt);
+	  rtx target = const0_rtx;
+
+	  if (lhs)
+	    target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
+
+	  rtx data_dep = expand_normal (gimple_call_arg (stmt, 1));
+	  rtx axis = expand_normal (gimple_call_arg (stmt, 2));
+
+	  if (code == IFN_UNIQUE_OACC_FORK)
+	    pattern = targetm.gen_oacc_fork (target, data_dep, axis);
+	  else
+	    pattern = targetm.gen_oacc_join (target, data_dep, axis);
+	}
+      else
 	gcc_unreachable ();
-#endif
-      }
       break;
     }
 
@@ -2012,40 +2010,47 @@ expand_GOACC_DATA_END_WITH_ARG (gcall *s
   gcc_unreachable ();
 }
 
+/* GOACC_DIM_SIZE returns the size of the specified compute axis.  */
+
 static void
-expand_GOACC_DIM_SIZE (gcall *ARG_UNUSED (stmt))
+expand_GOACC_DIM_SIZE (gcall *stmt)
 {
-#ifdef HAVE_oacc_dim_size
-  tree lhs = gimple_call_lhs (stmt);
-
-  if (!lhs)
-    return;
-  
-  rtx target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
-  rtx dim = expand_expr (gimple_call_arg (stmt, 0), NULL_RTX,
-			 VOIDmode, EXPAND_NORMAL);
-  emit_insn (gen_oacc_dim_size (target, dim));
-#else
-  gcc_unreachable ();
-#endif
+  if (targetm.have_oacc_dim_size ())
+    {
+      tree lhs = gimple_call_lhs (stmt);
+
+      if (!lhs)
+	return;
+
+      rtx target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
+      rtx dim = expand_expr (gimple_call_arg (stmt, 0), NULL_RTX,
+			     VOIDmode, EXPAND_NORMAL);
+      emit_insn (targetm.gen_oacc_dim_size (target, dim));
+    }
+  else
+    gcc_unreachable ();
 }
 
+/* GOACC_DIM_POS returns the index of the executing thread along the
+   specified axis.  */
+
 static void
-expand_GOACC_DIM_POS (gcall *ARG_UNUSED (stmt))
+expand_GOACC_DIM_POS (gcall *stmt)
 {
-#ifdef HAVE_oacc_dim_pos
-  tree lhs = gimple_call_lhs (stmt);
-
-  if (!lhs)
-    return;
-  
-  rtx target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
-  rtx dim = expand_expr (gimple_call_arg (stmt, 0), NULL_RTX,
-			 VOIDmode, EXPAND_NORMAL);
-  emit_insn (gen_oacc_dim_pos (target, dim));
-#else
-  gcc_unreachable ();
-#endif
+  if (targetm.have_oacc_dim_pos ())
+    {
+      tree lhs = gimple_call_lhs (stmt);
+
+      if (!lhs)
+	return;
+
+      rtx target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
+      rtx dim = expand_expr (gimple_call_arg (stmt, 0), NULL_RTX,
+			     VOIDmode, EXPAND_NORMAL);
+      emit_insn (targetm.gen_oacc_dim_pos (target, dim));
+    }
+  else
+    gcc_unreachable ();
 }
 
 /* All the GOACC_REDUCTION variants  get expanded in oacc_device_lower.  */
Index: gcc/target-insns.def
===================================================================
--- gcc/target-insns.def	(revision 229364)
+++ gcc/target-insns.def	(working copy)
@@ -64,6 +64,10 @@ DEF_TARGET_INSN (memory_barrier, (void))
 DEF_TARGET_INSN (movstr, (rtx x0, rtx x1, rtx x2))
 DEF_TARGET_INSN (nonlocal_goto, (rtx x0, rtx x1, rtx x2, rtx x3))
 DEF_TARGET_INSN (nonlocal_goto_receiver, (void))
+DEF_TARGET_INSN (oacc_dim_pos, (rtx x0, rtx x1))
+DEF_TARGET_INSN (oacc_dim_size, (rtx x0, rtx x1))
+DEF_TARGET_INSN (oacc_fork, (rtx x0, rtx x1, rtx x2))
+DEF_TARGET_INSN (oacc_join, (rtx x0, rtx x1, rtx x2))
 DEF_TARGET_INSN (prefetch, (rtx x0, rtx x1, rtx x2))
 DEF_TARGET_INSN (probe_stack, (rtx x0))
 DEF_TARGET_INSN (probe_stack_address, (rtx x0))
@@ -89,5 +93,6 @@ DEF_TARGET_INSN (stack_protect_test, (rt
 DEF_TARGET_INSN (store_multiple, (rtx x0, rtx x1, rtx x2))
 DEF_TARGET_INSN (tablejump, (rtx x0, rtx x1))
 DEF_TARGET_INSN (trap, (void))
+DEF_TARGET_INSN (unique, (void))
 DEF_TARGET_INSN (untyped_call, (rtx x0, rtx x1, rtx x2))
 DEF_TARGET_INSN (untyped_return, (rtx x0, rtx x1))

Reply via email to