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]

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


New ABI functionality requested by Matsushita (plus a minor bugfix).
The idea is to deal with "missing prototype" cases more sanely, when
the actual function returns a pointer (in a0) but the implicit
prototype says it returns an int (in d0).  No regressions.

	* config/mn10300/mn10300.c (TARGET_DEFAULT_TARGET_FLAGS): Add
	MASK_PTR_A0D0.
	(expand_epilogue): When appropriate, copy a0 to d0.
	(mn10300_return_in_memory): Support variable size types also.
	(mn10300_pass_by_reference): Likewise.
	* config/mn10300/mn10300.md: Add UNSPEC_A0D0.
	(epilogue_copy_a0d0): New.
	* config/mn10300/mn10300.opt: Add -mreturn-pointer-on-d0.
	* doc/invoke.texi: Document it.

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  config/mn10300/mn10300.c
--- config/mn10300/mn10300.c	25 Jun 2005 01:21:50 -0000	1.81
+++ config/mn10300/mn10300.c	9 Sep 2005 20:59:41 -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
 
@@ -973,6 +973,14 @@ expand_epilogue (void)
   size = get_frame_size () + current_function_outgoing_args_size;
   size += (current_function_outgoing_args_size ? 4 : 0);
 
+  if (TARGET_PTR_A0D0
+      && current_function_return_rtx
+      && GET_CODE (current_function_return_rtx) == REG
+      && REGNO (current_function_return_rtx) == FIRST_ADDRESS_REGNUM)
+    {
+      emit_insn (gen_epilogue_copy_a0d0 ());
+    }
+
   if (TARGET_AM33_2 && fp_regs_to_save ())
     {
       int num_regs_to_save = fp_regs_to_save (), i;
@@ -1449,7 +1457,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 +1515,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
Index: config/mn10300/mn10300.md
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mn10300/mn10300.md,v
retrieving revision 1.61
diff -p -U3 -r1.61  config/mn10300/mn10300.md
--- config/mn10300/mn10300.md	25 Jun 2005 01:21:50 -0000	1.61
+++ config/mn10300/mn10300.md	9 Sep 2005 20:59:41 -0000
@@ -46,6 +46,7 @@
   (UNSPEC_GOT		2)
   (UNSPEC_GOTOFF	3)
   (UNSPEC_PLT		4)
+  (UNSPEC_A0D0		5)
 ])
 
 (include "predicates.md")
@@ -2479,6 +2480,12 @@
 }"
   [(set_attr "cc" "clobber")])
 
+(define_insn "epilogue_copy_a0d0"
+  [(unspec_volatile [(const_int 0)] UNSPEC_A0D0)]
+  ""
+  "mov a0,d0 # -mreturn-pointer-on-d0"
+  )
+
 ;; Try to combine consecutive updates of the stack pointer (or any
 ;; other register for that matter).
 (define_peephole
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  config/mn10300/mn10300.opt
--- config/mn10300/mn10300.opt	25 Jun 2005 01:21:50 -0000	1.2
+++ config/mn10300/mn10300.opt	9 Sep 2005 20:59:41 -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.676
diff -p -U3 -r1.676  doc/invoke.texi
--- doc/invoke.texi	6 Sep 2005 10:59:50 -0000	1.676
+++ doc/invoke.texi	9 Sep 2005 20:59:47 -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}
@@ -10570,6 +10571,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]