This patch implements the simple_return pattern to enable -fshrink-wrap
on SH. It also clean up some redundancies for expand_epilogue (called
twice from the "return" and "epilogue" patterns and the
sh_expand_prologue parameter type.

No regressions with sh-superh-elf and sh4-linux gcc testsuites.

Thanks

Christian

2012-08-29  Christian Bruel  <christian.br...@st.com>

	* config/sh/sh-protos.h (sh_need_epilogue): Delete.
	* config/sh/sh.c (sh_need_epilogue): Delete.
	(sh_need_epilogue_known): Delete.
	(sh_output_function_epilogue): Remove sh_need_epilogue_known.
	* config/sh/sh.md (any_return): New iterator and optab.
	(simple_return): Define.
	(return): Check epilogue_completed.
	(epilogue): Use inline return rtl.
	(sh_expand_epilogue): Cleanup parameters boolean type.

Index: gcc/config/sh/sh-protos.h
===================================================================
--- gcc/config/sh/sh-protos.h	(revision 191129)
+++ gcc/config/sh/sh-protos.h	(working copy)
@@ -117,7 +117,6 @@
 extern int sh_media_register_for_return (void);
 extern void sh_expand_prologue (void);
 extern void sh_expand_epilogue (bool);
-extern bool sh_need_epilogue (void);
 extern void sh_set_return_address (rtx, rtx);
 extern int initial_elimination_offset (int, int);
 extern bool fldi_ok (void);
Index: gcc/config/sh/sh.c
===================================================================
--- gcc/config/sh/sh.c	(revision 191129)
+++ gcc/config/sh/sh.c	(working copy)
@@ -7901,22 +7901,6 @@
 
 static int sh_need_epilogue_known = 0;
 
-bool
-sh_need_epilogue (void)
-{
-  if (! sh_need_epilogue_known)
-    {
-      rtx epilogue;
-
-      start_sequence ();
-      sh_expand_epilogue (0);
-      epilogue = get_insns ();
-      end_sequence ();
-      sh_need_epilogue_known = (epilogue == NULL ? -1 : 1);
-    }
-  return sh_need_epilogue_known > 0;
-}
-
 /* Emit code to change the current function's return address to RA.
    TEMP is available as a scratch register, if needed.  */
 
@@ -7996,7 +7980,6 @@
 sh_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED,
 			     HOST_WIDE_INT size ATTRIBUTE_UNUSED)
 {
-  sh_need_epilogue_known = 0;
 }
 
 static rtx
Index: gcc/config/sh/sh.md
===================================================================
--- gcc/config/sh/sh.md	(revision 191129)
+++ gcc/config/sh/sh.md	(working copy)
@@ -177,6 +177,10 @@
   (UNSPECV_EH_RETURN	12)
 ])
 
+(define_code_iterator any_return [return simple_return])
+(define_code_attr optab [(return "return")
+			 (simple_return "simple_return")])
+
 ;; -------------------------------------------------------------------------
 ;; Attributes
 ;; -------------------------------------------------------------------------
@@ -9280,7 +9284,7 @@
   [(return)]
   ""
 {
-  sh_expand_epilogue (1);
+  sh_expand_epilogue (true);
   if (TARGET_SHCOMPACT)
     {
       rtx insn, set;
@@ -10099,9 +10103,13 @@
 }
   [(set_attr "type" "load_media")])
 
+(define_expand "simple_return"
+  [(simple_return)]
+ "")
+
 (define_expand "return"
-  [(return)]
-  "reload_completed && ! sh_need_epilogue ()"
+  [(simple_return)]
+ "reload_completed && epilogue_completed"
 {
   if (TARGET_SHMEDIA)
     {
@@ -10117,8 +10125,8 @@
     }
 })
 
-(define_insn "*return_i"
-  [(return)]
+(define_insn "*<optab>_i"
+  [(any_return)]
   "TARGET_SH1 && ! (TARGET_SHCOMPACT
 		    && (crtl->args.info.call_cookie
 			& CALL_COOKIE_RET_TRAMP (1)))
@@ -10244,19 +10252,12 @@
 (define_expand "prologue"
   [(const_int 0)]
   ""
-{
-  sh_expand_prologue ();
-  DONE;
-})
+  "sh_expand_prologue (); DONE;")
 
 (define_expand "epilogue"
   [(return)]
   ""
-{
-  sh_expand_epilogue (0);
-  emit_jump_insn (gen_return ());
-  DONE;
-})
+  "sh_expand_epilogue (false);")
 
 (define_expand "eh_return"
   [(use (match_operand 0 "register_operand" ""))]

Reply via email to