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]

Re: [mn10300] return-in-a0-d0 ABI helper


> You'll have to walk through expand_value_return and its children
> (particularly emit_group_load).  You might also have to peek at
> expand_function_end.

It turns out that mn10300 uses $a0 to return pointers to temp areas
for returning structures, and the struct-return code doesn't support
parallels.  Fortunately, you can't use those types of functions
without prototypes anyway.  Revised patch attached.

	* config/mn10300/mn10300.c (TARGET_DEFAULT_TARGET_FLAGS): Add
	MASK_PTR_A0D0.
	(mn10300_return_in_memory): Support variable size types also.
	(mn10300_pass_by_reference): Likewise.
	(mn10300_function_value): New.
	* config/mn10300/mn10300.h (FUNCTION_VALUE): Call the above.
	(FUNCTION_OUTGOING_VALUE): Likewise.
	* config/mn10300/mn10300.opt: Add -mreturn-pointer-on-d0.
	* doc/invoke.texi: Document it.

Index: config/mn10300/mn10300-protos.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mn10300/mn10300-protos.h,v
retrieving revision 1.19
diff -p -U3 -r1.19 mn10300-protos.h
--- config/mn10300/mn10300-protos.h	25 Jun 2005 01:21:50 -0000	1.19
+++ config/mn10300/mn10300-protos.h	21 Sep 2005 23:11:15 -0000
@@ -49,6 +49,7 @@ extern bool mn10300_wide_const_load_uses
 #ifdef TREE_CODE
 extern struct rtx_def *function_arg (CUMULATIVE_ARGS *,
 				     enum machine_mode, tree, int);
+extern rtx mn10300_function_value (tree, tree, int);
 #endif /* TREE_CODE */
 
 extern void expand_prologue (void);
Index: config/mn10300/mn10300.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mn10300/mn10300.c,v
retrieving revision 1.81
diff -p -U3 -r1.81 mn10300.c
--- config/mn10300/mn10300.c	25 Jun 2005 01:21:50 -0000	1.81
+++ config/mn10300/mn10300.c	21 Sep 2005 23:11:15 -0000
@@ -95,7 +95,7 @@ static int mn10300_arg_partial_bytes (CU
 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
 
 #undef TARGET_DEFAULT_TARGET_FLAGS
-#define TARGET_DEFAULT_TARGET_FLAGS MASK_MULT_BUG
+#define TARGET_DEFAULT_TARGET_FLAGS MASK_MULT_BUG | MASK_PTR_A0D0
 #undef TARGET_HANDLE_OPTION
 #define TARGET_HANDLE_OPTION mn10300_handle_option
 
@@ -1449,7 +1449,9 @@ static bool
 mn10300_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
 {
   /* Return values > 8 bytes in length in memory.  */
-  return int_size_in_bytes (type) > 8 || TYPE_MODE (type) == BLKmode;
+  return (int_size_in_bytes (type) > 8
+	  || int_size_in_bytes (type) == 0
+	  || TYPE_MODE (type) == BLKmode);
 }
 
 /* Flush the argument registers to the stack for a stdarg function;
@@ -1505,7 +1507,7 @@ mn10300_pass_by_reference (CUMULATIVE_AR
   else
     size = GET_MODE_SIZE (mode);
 
-  return size > 8;
+  return (size > 8 || size == 0);
 }
 
 /* Return an RTX to represent where a value with mode MODE will be returned
@@ -1598,6 +1600,37 @@ mn10300_arg_partial_bytes (CUMULATIVE_AR
   return nregs * UNITS_PER_WORD - cum->nbytes;
 }
 
+/* Return the location of the function's value.  This will be either
+   $d0 for integer functions, $a0 for pointers, or a PARALLEL of both
+   $d0 and $a0 if the -mreturn-pointer-on-do flag is set.  Note that
+   we only return the PARALLEL for outgoing values; we do not want
+   callers relying on this extra copy.  */
+
+rtx
+mn10300_function_value (tree valtype, tree func, int outgoing)
+{
+  rtx rv;
+  enum machine_mode mode = TYPE_MODE (valtype);
+
+  if (! POINTER_TYPE_P (valtype))
+    return gen_rtx_REG (mode, FIRST_DATA_REGNUM);
+  else if (! TARGET_PTR_A0D0 || ! outgoing
+	   || current_function_returns_struct)
+    return gen_rtx_REG (mode, FIRST_ADDRESS_REGNUM);
+
+  rv = gen_rtx_PARALLEL (mode, rtvec_alloc (2));
+  XVECEXP (rv, 0, 0)
+    = gen_rtx_EXPR_LIST (VOIDmode,
+			 gen_rtx_REG (mode, FIRST_ADDRESS_REGNUM),
+			 GEN_INT (0));
+  
+  XVECEXP (rv, 0, 1)
+    = gen_rtx_EXPR_LIST (VOIDmode,
+			 gen_rtx_REG (mode, FIRST_DATA_REGNUM),
+			 GEN_INT (0));
+  return rv;
+}
+
 /* Output a tst insn.  */
 const char *
 output_tst (rtx operand, rtx insn)
Index: config/mn10300/mn10300.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mn10300/mn10300.h,v
retrieving revision 1.91
diff -p -U3 -r1.91 mn10300.h
--- config/mn10300/mn10300.h	6 Aug 2005 13:26:13 -0000	1.91
+++ config/mn10300/mn10300.h	21 Sep 2005 23:11:15 -0000
@@ -594,8 +594,9 @@ struct cum_arg {int nbytes; };
    otherwise, FUNC is 0.  */
 
 #define FUNCTION_VALUE(VALTYPE, FUNC) \
-  gen_rtx_REG (TYPE_MODE (VALTYPE), POINTER_TYPE_P (VALTYPE) \
-	       ? FIRST_ADDRESS_REGNUM : FIRST_DATA_REGNUM)
+  mn10300_function_value (VALTYPE, FUNC, 0)
+#define FUNCTION_OUTGOING_VALUE(VALTYPE, FUNC) \
+  mn10300_function_value (VALTYPE, FUNC, 1)
 
 /* Define how to find the value returned by a library function
    assuming the value has mode MODE.  */
Index: config/mn10300/mn10300.opt
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mn10300/mn10300.opt,v
retrieving revision 1.2
diff -p -U3 -r1.2 mn10300.opt
--- config/mn10300/mn10300.opt	25 Jun 2005 01:21:50 -0000	1.2
+++ config/mn10300/mn10300.opt	21 Sep 2005 23:11:15 -0000
@@ -35,3 +35,7 @@ Work around hardware multiply bug
 mrelax
 Target RejectNegative
 Enable linker relaxations
+
+mreturn-pointer-on-d0
+Target Report Mask(PTR_A0D0)
+Return pointers in both a0 and d0
Index: doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.677
diff -p -U3 -r1.677 invoke.texi
--- doc/invoke.texi	12 Sep 2005 19:54:05 -0000	1.677
+++ doc/invoke.texi	21 Sep 2005 23:11:16 -0000
@@ -609,6 +609,7 @@ Objective-C and Objective-C++ Dialects}.
 @gccoptlist{-mmult-bug  -mno-mult-bug @gol
 -mam33  -mno-am33 @gol
 -mam33-2  -mno-am33-2 @gol
+-mreturn-pointer-on-d0 @gol
 -mno-crt0  -mrelax}
 
 @emph{MS1 Options}
@@ -10584,6 +10585,14 @@ Generate code which uses features specif
 Do not generate code which uses features specific to the AM33 processor.  This
 is the default.
 
+@item -mreturn-pointer-on-d0
+@opindex mreturn-pointer-on-d0
+When generating a function which returns a pointer, return the pointer
+in both @code{a0} and @code{d0}.  Otherwise, the pointer is returned
+only in a0, and attempts to call such functions without a prototype
+would result in errors.  Note that this option is on by default; use
+@option{-mno-return-pointer-on-d0} to disable it.
+
 @item -mno-crt0
 @opindex mno-crt0
 Do not link in the C run-time initialization object file.


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