diff mbox

[PTX] some more cleanups

Message ID 566B117B.8060604@acm.org
State New
Headers show

Commit Message

Nathan Sidwell Dec. 11, 2015, 6:10 p.m. UTC
This patch:
1) removes unused hard register defines

2) removes unused ASM_OUTPUT_COMMON, ASM_OUTPUT_LOCAL defines (we define the 
aligned variants)

3) name the static chain registers.

4) formatting and simplification to bunch of function argument/return hooks.  In 
particular I found nvptx_function_arg_boundary quite confusing due to its mixing 
of BITS_PER_UNIT and BITS_PER_WORD.

nathan
diff mbox

Patch

2015-12-11  Nathan Sidwell  <nathan@acm.org>

	* config/nvptx/nvptx.h (RETURN_ADDR_REGNO): Delete.
	(OUTGOING_ARG_POINTER_REGNUM): Delete.
	(ASM_OUTPUT_COMMON, ASM_OUTPUT_LOCAL): Delete.
	(REGISTER_NAMES): Name static chain regs.
	* config/nvptx/nvptx.c (nvptx_function_arg): Add ARG_UNUSED, merge
	ifs.
	(nvptx_incoming_arg): Merge ifs.
	(nvptx_function_arg_boundary): Reimplement to avoid mixing units.
	(nvptx_function_value): Tail call nvptx_libcall_value.
	(nvptx_pass_by_reference): Add ARG_UNUSED.
	(nvptx_static_chain): Use conditional op.
	(nvptx_handle_kernel_attribute): Use VOID_TYPE_P.

Index: gcc/config/nvptx/nvptx.c
===================================================================
--- gcc/config/nvptx/nvptx.c	(revision 231564)
+++ gcc/config/nvptx/nvptx.c	(working copy)
@@ -392,15 +392,13 @@  arg_promotion (machine_mode mode)
 /* Implement TARGET_FUNCTION_ARG.  */
 
 static rtx
-nvptx_function_arg (cumulative_args_t, machine_mode mode,
+nvptx_function_arg (cumulative_args_t ARG_UNUSED (cum_v), machine_mode mode,
 		    const_tree, bool named)
 {
-  if (mode == VOIDmode)
+  if (mode == VOIDmode || !named)
     return NULL_RTX;
 
-  if (named)
-    return gen_reg_rtx (mode);
-  return NULL_RTX;
+  return gen_reg_rtx (mode);
 }
 
 /* Implement TARGET_FUNCTION_INCOMING_ARG.  */
@@ -410,10 +408,8 @@  nvptx_function_incoming_arg (cumulative_
 			     const_tree, bool named)
 {
   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
-  if (mode == VOIDmode)
-    return NULL_RTX;
 
-  if (!named)
+  if (mode == VOIDmode || !named)
     return NULL_RTX;
 
   /* No need to deal with split modes here, the only case that can
@@ -433,6 +429,7 @@  nvptx_function_arg_advance (cumulative_a
 			    bool ARG_UNUSED (named))
 {
   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
+
   cum->count++;
 }
 
@@ -449,6 +446,7 @@  static bool
 nvptx_strict_argument_naming (cumulative_args_t cum_v)
 {
   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
+
   return cum->fntype == NULL_TREE || stdarg_p (cum->fntype);
 }
 
@@ -460,21 +458,19 @@  nvptx_function_arg_boundary (machine_mod
   unsigned int boundary = type ? TYPE_ALIGN (type) : GET_MODE_BITSIZE (mode);
 
   if (boundary > BITS_PER_WORD)
-    return 2 * BITS_PER_WORD;
-
-  if (mode == BLKmode)
+    boundary = 2 * BITS_PER_WORD;
+  else if (mode == BLKmode)
     {
       HOST_WIDE_INT size = int_size_in_bytes (type);
+
       if (size > 4)
-        return 2 * BITS_PER_WORD;
-      if (boundary < BITS_PER_WORD)
-        {
-          if (size >= 3)
-            return BITS_PER_WORD;
-          if (size >= 2)
-            return 2 * BITS_PER_UNIT;
-        }
+        boundary = 8 * BITS_PER_UNIT;
+      else if (size > 2)
+	boundary = 4 * BITS_PER_UNIT;
+      else
+	boundary = size * BITS_PER_UNIT;
     }
+
   return boundary;
 }
 
@@ -487,6 +483,7 @@  nvptx_libcall_value (machine_mode mode,
     /* Pretend to return in a hard reg for early uses before pseudos can be
        generated.  */
     return gen_rtx_REG (mode, NVPTX_RETURN_REGNUM);
+
   return gen_reg_rtx (mode);
 }
 
@@ -503,11 +500,8 @@  nvptx_function_value (const_tree type, c
 					     &unsignedp, NULL_TREE, 1);
   if (outgoing)
     return gen_rtx_REG (mode, NVPTX_RETURN_REGNUM);
-  if (cfun->machine->start_call == NULL_RTX)
-    /* Pretend to return in a hard reg for early uses before pseudos can be
-       generated.  */
-    return gen_rtx_REG (mode, NVPTX_RETURN_REGNUM);
-  return gen_reg_rtx (mode);
+
+  return nvptx_libcall_value (mode, NULL_RTX);
 }
 
 /* Implement TARGET_FUNCTION_VALUE_REGNO_P.  */
@@ -522,8 +516,8 @@  nvptx_function_value_regno_p (const unsi
    reference in memory.  */
 
 static bool
-nvptx_pass_by_reference (cumulative_args_t, machine_mode mode,
-			 const_tree type, bool)
+nvptx_pass_by_reference (cumulative_args_t ARG_UNUSED (cum), machine_mode mode,
+			 const_tree type, bool ARG_UNUSED (named))
 {
   return !PASS_IN_REG_P (mode, type);
 }
@@ -572,10 +566,9 @@  nvptx_static_chain (const_tree fndecl, b
   if (!DECL_STATIC_CHAIN (fndecl))
     return NULL;
 
-  if (incoming_p)
-    return gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM);
-  else
-    return gen_rtx_REG (Pmode, OUTGOING_STATIC_CHAIN_REGNUM);
+
+  return gen_rtx_REG (Pmode, (incoming_p ? STATIC_CHAIN_REGNUM
+			      : OUTGOING_STATIC_CHAIN_REGNUM));
 }
 
 /* Helper for write_arg.  Emit a single PTX argument of MODE, either
@@ -3829,8 +3822,7 @@  nvptx_handle_kernel_attribute (tree *nod
       error ("%qE attribute only applies to functions", name);
       *no_add_attrs = true;
     }
-
-  else if (TREE_TYPE (TREE_TYPE (decl)) != void_type_node)
+  else if (!VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
     {
       error ("%qE attribute requires a void return type", name);
       *no_add_attrs = true;
Index: gcc/config/nvptx/nvptx.h
===================================================================
--- gcc/config/nvptx/nvptx.h	(revision 231564)
+++ gcc/config/nvptx/nvptx.h	(working copy)
@@ -153,10 +153,8 @@  enum reg_class
 #define NVPTX_RETURN_REGNUM 4
 #define FRAME_POINTER_REGNUM 15
 #define ARG_POINTER_REGNUM 14
-#define RETURN_ADDR_REGNO 13
 
 #define STATIC_CHAIN_REGNUM 12
-#define OUTGOING_ARG_POINTER_REGNUM 11
 #define OUTGOING_STATIC_CHAIN_REGNUM 10
 
 #define FIRST_PARM_OFFSET(FNDECL) ((void)(FNDECL), 0)
@@ -251,13 +249,10 @@  struct GTY(()) machine_function
 #undef ASM_APP_OFF
 #define ASM_APP_OFF "\t// #NO_APP \n"
 
-#define ASM_OUTPUT_COMMON(stream, name, size, rounded)
-#define ASM_OUTPUT_LOCAL(stream, name, size, rounded)
-
 #define REGISTER_NAMES							\
   {									\
-    "%hr0", "%outargs", "%hfp", "%hr3", "%retval", "%retval_in", "%hr6", "%hr7",	\
-    "%hr8", "%hr9", "%hr10", "%hr11", "%hr12", "%hr13", "%argp", "%frame" \
+    "%hr0", "%outargs", "%hfp", "%hr3", "%retval", "%hr5", "%hr6", "%hr7",	\
+    "%hr8", "%hr9", "%chain_out", "%hr11", "%chain_in", "%hr13", "%argp", "%frame" \
   }
 
 #define DBX_REGISTER_NUMBER(N) N