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]

[patch] Clean up FUNCTION_ARG_PADDING.


Hi,

Attached is a patch to clean up FUNCTION_ARG_PADDING.

Several ports define FUNCTION_ARG_PADDING to take care of special
cases and then fall back to the default definition for other cases.
When they do so, they copy the original definition of
FUNCTION_ARG_PADDING sitting in expr.c.

The patch cleans up the repeated definitions by defining a new
function default_function_arg_padding() and have back ends call it if
they want to fall back to the original definition.

If we decide to use target-def.h in future, this patch can certainly
be a step towards that.

Tested on i686-pc-linux-gnu.  Built cc1 for each affected target.  OK
to apply?

Kazu Hirata

2003-07-01  Kazu Hirata  <kazu@cs.umass.edu>

	* expr.c (default_function_arg_padding): New.
	* expr.h: Add a prototype for default_function_arg_padding.
	(FUNCTION_ARG_PADDING): Call default_function_arg_padding.
	* config/ia64/ia64.c (ia64_hpux_function_arg_padding):
	Likewise.
	* config/m68hc11/m68hc11.c (m68hc11_function_arg_padding):
	Likewise.
	* config/rs6000/rs6000.c (function_arg_padding): Likewise.
	* config/sparc/sparc.c (function_arg_padding): Likewise.

Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/expr.c,v
retrieving revision 1.559
diff -u -r1.559 expr.c
--- expr.c	29 Jun 2003 17:47:37 -0000	1.559
+++ expr.c	1 Jul 2003 01:41:34 -0000
@@ -3781,6 +3781,21 @@
 }
 #endif
 
+/* Determine the direction of padding for a function argument.  */
+
+enum direction
+default_function_arg_padding (enum machine_mode mode, tree type)
+{
+  return
+    (! BYTES_BIG_ENDIAN							
+     ? upward								
+     : ((mode == BLKmode						
+	 ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST		
+	    && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT)) 
+	 : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)			
+	? downward : upward));
+}
+
 /* Generate code to push X onto the stack, assuming it has mode MODE and
    type TYPE.
    MODE is redundant except when X is a CONST_INT (since they don't
Index: expr.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/expr.h,v
retrieving revision 1.143
diff -u -r1.143 expr.h
--- expr.h	29 Jun 2003 16:21:58 -0000	1.143
+++ expr.h	1 Jul 2003 01:41:34 -0000
@@ -138,19 +138,17 @@
 ((SIZE).var == 0 ? GEN_INT ((SIZE).constant)			\
  : expand_expr (ARGS_SIZE_TREE (SIZE), NULL_RTX, VOIDmode, 0))
 
+/* Determine the direction of padding for a function argument.  */
+extern enum direction default_function_arg_padding (enum machine_mode mode,
+						    tree type);
+
 /* Supply a default definition for FUNCTION_ARG_PADDING:
    usually pad upward, but pad short args downward on
    big-endian machines.  */
 
 #ifndef FUNCTION_ARG_PADDING
-#define FUNCTION_ARG_PADDING(MODE, TYPE)				\
-  (! BYTES_BIG_ENDIAN							\
-   ? upward								\
-   : (((MODE) == BLKmode						\
-       ? ((TYPE) && TREE_CODE (TYPE_SIZE (TYPE)) == INTEGER_CST		\
-	  && int_size_in_bytes (TYPE) < (PARM_BOUNDARY / BITS_PER_UNIT)) \
-       : GET_MODE_BITSIZE (MODE) < PARM_BOUNDARY)			\
-      ? downward : upward))
+#define FUNCTION_ARG_PADDING(MODE, TYPE)		\
+  (default_function_arg_padding ((MODE), (TYPE)))
 #endif
 
 /* Supply a default definition for FUNCTION_ARG_BOUNDARY.  Normally, we let
Index: config/ia64/ia64.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/ia64/ia64.c,v
retrieving revision 1.234
diff -u -r1.234 ia64.c
--- config/ia64/ia64.c	27 Jun 2003 09:49:40 -0000	1.234
+++ config/ia64/ia64.c	1 Jul 2003 01:41:37 -0000
@@ -8337,14 +8337,8 @@
        && int_size_in_bytes (type) < UNITS_PER_WORD)
      return upward;
 
-   /* This is the standard FUNCTION_ARG_PADDING with !BYTES_BIG_ENDIAN
-      hardwired to be true.  */
-
-   return((mode == BLKmode
-       ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
-          && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT))
-       : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
-      ? downward : upward);
+   /* Fall back to the default.  */
+   return default_function_arg_padding (mode, type);
 }
 
 /* Linked list of all external functions that are to be emitted by GCC.
Index: config/m68hc11/m68hc11.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/m68hc11/m68hc11.c,v
retrieving revision 1.83
diff -u -r1.83 m68hc11.c
--- config/m68hc11/m68hc11.c	1 Jul 2003 01:15:05 -0000	1.83
+++ config/m68hc11/m68hc11.c	1 Jul 2003 01:41:38 -0000
@@ -1582,14 +1582,8 @@
   if (type != 0 && AGGREGATE_TYPE_P (type))
     return upward;
 
-  /* This is the default definition.  */
-  return (!BYTES_BIG_ENDIAN
-	  ? upward
-	  : ((mode == BLKmode
-	      ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
-		 && int_size_in_bytes (type) <
-		 (PARM_BOUNDARY / BITS_PER_UNIT)) : GET_MODE_BITSIZE (mode) <
-	      PARM_BOUNDARY) ? downward : upward));
+  /* Fall back to the default.  */
+  return default_function_arg_padding (mode, type);
 }
 
 
Index: config/rs6000/rs6000.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000.c,v
retrieving revision 1.500
diff -u -r1.500 rs6000.c
--- config/rs6000/rs6000.c	30 Jun 2003 13:30:45 -0000	1.500
+++ config/rs6000/rs6000.c	1 Jul 2003 01:41:45 -0000
@@ -3745,14 +3745,8 @@
   if (type != 0 && AGGREGATE_TYPE_P (type))
     return upward;
 
-  /* This is the default definition.  */
-  return (! BYTES_BIG_ENDIAN
-	  ? upward
-	  : ((mode == BLKmode
-	      ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
-		 && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT))
-	      : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
-	     ? downward : upward));
+  /* Fall back to the default.  */
+  return default_function_arg_padding (mode, type);
 }
 
 /* If defined, a C expression that gives the alignment boundary, in bits,
Index: config/sparc/sparc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/sparc/sparc.c,v
retrieving revision 1.251
diff -u -r1.251 sparc.c
--- config/sparc/sparc.c	27 Jun 2003 09:49:44 -0000	1.251
+++ config/sparc/sparc.c	1 Jul 2003 01:41:47 -0000
@@ -5198,14 +5198,8 @@
   if (TARGET_ARCH64 && type != 0 && AGGREGATE_TYPE_P (type))
     return upward;
 
-  /* This is the default definition.  */
-  return (! BYTES_BIG_ENDIAN
-	  ? upward
-	  : ((mode == BLKmode
-	      ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
-		 && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT))
-	      : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
-	     ? downward : upward));
+  /* Fall back to the default.  */
+  return default_function_arg_padding (mode, type);
 }
 
 /* Handle FUNCTION_VALUE, FUNCTION_OUTGOING_VALUE, and LIBCALL_VALUE macros.


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