[5/8] always define HAVE_simple_return and HAVE_return
diff mbox

Message ID 1430114140-15817-6-git-send-email-tbsaunde+gcc@tbsaunde.org
State New
Headers show

Commit Message

tbsaunde+gcc@tbsaunde.org April 27, 2015, 5:55 a.m. UTC
From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>

gcc/ChangeLog:

2015-04-27  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>

	* bb-reorder.c (HAVE_return): Don't check if its undefined.
	* defaults.h (gen_simple_return): New function.
	(gen_simple_return): Likewise.
	(HAVE_return): Add default definition to false.
	(HAVE_simple_return): Likewise.
	* cfgrtl.c (force_nonfallthru_and_redirect): Remove checks if
	HAVE_return and HAVE_simple_return are defined.
	* function.c (gen_return_pattern): Likewise.
	(convert_jumps_to_returns): Likewise.
	(thread_prologue_and_epilogue_insns): Likewise.
	* reorg.c (find_end_label): Likewise.
	(dbr_schedule): Likewise.
	* shrink-wrap.c: Likewise.
	* shrink-wrap.h: Likewise.
---
 gcc/bb-reorder.c  |  9 ---------
 gcc/cfgrtl.c      | 14 ++++++--------
 gcc/defaults.h    | 20 ++++++++++++++++++++
 gcc/function.c    | 52 ++++++++++++++--------------------------------------
 gcc/reorg.c       | 12 +-----------
 gcc/shrink-wrap.c |  3 ---
 gcc/shrink-wrap.h |  6 ------
 7 files changed, 41 insertions(+), 75 deletions(-)

Comments

Mike Stump May 6, 2015, 1:12 a.m. UTC | #1
On Apr 26, 2015, at 10:55 PM, tbsaunde+gcc@tbsaunde.org wrote:
> From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>
> 
> gcc/ChangeLog:
> 
> 2015-04-27  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>
> 
> 	* bb-reorder.c (HAVE_return): Don't check if its undefined.
> 	* defaults.h (gen_simple_return): New function.
> 	(gen_simple_return): Likewise.
> 	(HAVE_return): Add default definition to false.
> 	(HAVE_simple_return): Likewise.
> 	* cfgrtl.c (force_nonfallthru_and_redirect): Remove checks if
> 	HAVE_return and HAVE_simple_return are defined.
> 	* function.c (gen_return_pattern): Likewise.
> 	(convert_jumps_to_returns): Likewise.
> 	(thread_prologue_and_epilogue_insns): Likewise.
> 	* reorg.c (find_end_label): Likewise.
> 	(dbr_schedule): Likewise.
> 	* shrink-wrap.c: Likewise.
> 	* shrink-wrap.h: Likewise.

I’m seeing:

In file included from ./tm.h:30:0,
                 from ../../gcc/gcc/c-family/c-semantics.c:24:
../../gcc/gcc/defaults.h: In function ‘rtx_def* gen_simple_return()’:
../../gcc/gcc/defaults.h:1422:1: error: redefinition of ‘rtx_def* gen_simple_return()’
 gen_simple_return ()
 ^
In file included from ./tm.h:22:0,
                 from ../../gcc/gcc/c-family/c-semantics.c:24:
./insn-flags.h:1744:1: error: ‘rtx_def* gen_simple_return()’ previously defined here
 gen_simple_return(void)
 ^

in my port.

I have a simple_return and a return that is “0” enabled.

defaults.h has:

#ifndef HAVE_simple_return
#define HAVE_simple_return 0
static inline rtx
gen_simple_return ()
{
  gcc_unreachable ();
  return NULL;
}
#endif

and insn-flags.h has:

static inline rtx gen_simple_return                                      (void);
static inline rtx
gen_simple_return(void)
{
  return 0;
}

If I change the enable to “1” or “” then it compiles better.  Also, I can delete the pattern or change the name of the pattern and it works ok as well.

If they both did #ifndef HAVE_simple_return, and then insn-flags did #define HAVE_simple_return 0, I think it might work better.  I’ve not thought about it much.
Trevor Saunders May 6, 2015, 3:15 a.m. UTC | #2
On Tue, May 05, 2015 at 06:12:50PM -0700, Mike Stump wrote:
> On Apr 26, 2015, at 10:55 PM, tbsaunde+gcc@tbsaunde.org wrote:
> > From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>
> > 
> > gcc/ChangeLog:
> > 
> > 2015-04-27  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>
> > 
> > 	* bb-reorder.c (HAVE_return): Don't check if its undefined.
> > 	* defaults.h (gen_simple_return): New function.
> > 	(gen_simple_return): Likewise.
> > 	(HAVE_return): Add default definition to false.
> > 	(HAVE_simple_return): Likewise.
> > 	* cfgrtl.c (force_nonfallthru_and_redirect): Remove checks if
> > 	HAVE_return and HAVE_simple_return are defined.
> > 	* function.c (gen_return_pattern): Likewise.
> > 	(convert_jumps_to_returns): Likewise.
> > 	(thread_prologue_and_epilogue_insns): Likewise.
> > 	* reorg.c (find_end_label): Likewise.
> > 	(dbr_schedule): Likewise.
> > 	* shrink-wrap.c: Likewise.
> > 	* shrink-wrap.h: Likewise.
> 
> I’m seeing:
> 
> In file included from ./tm.h:30:0,
>                  from ../../gcc/gcc/c-family/c-semantics.c:24:
> ../../gcc/gcc/defaults.h: In function ‘rtx_def* gen_simple_return()’:
> ../../gcc/gcc/defaults.h:1422:1: error: redefinition of ‘rtx_def* gen_simple_return()’
>  gen_simple_return ()
>  ^
> In file included from ./tm.h:22:0,
>                  from ../../gcc/gcc/c-family/c-semantics.c:24:
> ./insn-flags.h:1744:1: error: ‘rtx_def* gen_simple_return()’ previously defined here
>  gen_simple_return(void)
>  ^
> 
> in my port.
> 
> I have a simple_return and a return that is “0” enabled.
> 
> defaults.h has:
> 
> #ifndef HAVE_simple_return
> #define HAVE_simple_return 0
> static inline rtx
> gen_simple_return ()
> {
>   gcc_unreachable ();
>   return NULL;
> }
> #endif
> 
> and insn-flags.h has:
> 
> static inline rtx gen_simple_return                                      (void);
> static inline rtx
> gen_simple_return(void)
> {
>   return 0;
> }
> 
> If I change the enable to “1” or “” then it compiles better.  Also, I can delete the pattern or change the name of the pattern and it works ok as well.
> 
> If they both did #ifndef HAVE_simple_return, and then insn-flags did #define HAVE_simple_return 0, I think it might work better.  I’ve not thought about it much.

hrm, I didn't realize you could sometimes get a dummy function in
insn-flags.h (especially without it defining the macro that seems kind
of broken on genflags' part).  What I think we could actually do is
change genflags to #define HAVE_x 0 if it is going to emit the static
function and some how have a list of insns that always get emited so you
don't need the define_insn with enabled = 0 in every target's md file.
The one big trick with this is that all the #ifdef HAVE_foo need to be
updated so it'll take a little time.

Trev

Patch
diff mbox

diff --git a/gcc/bb-reorder.c b/gcc/bb-reorder.c
index c2a3be3..c134712 100644
--- a/gcc/bb-reorder.c
+++ b/gcc/bb-reorder.c
@@ -142,15 +142,6 @@ 
    the object file there will be an extra round.  */
 #define N_ROUNDS 5
 
-/* Stubs in case we don't have a return insn.
-   We have to check at run time too, not only compile time.  */
-
-#ifndef HAVE_return
-#define HAVE_return 0
-#define gen_return() NULL_RTX
-#endif
-
-
 struct target_bb_reorder default_target_bb_reorder;
 #if SWITCHABLE_TARGET
 struct target_bb_reorder *this_target_bb_reorder = &default_target_bb_reorder;
diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
index 322d1a9..7027502 100644
--- a/gcc/cfgrtl.c
+++ b/gcc/cfgrtl.c
@@ -1705,21 +1705,19 @@  force_nonfallthru_and_redirect (edge e, basic_block target, rtx jump_label)
     {
       if (jump_label == ret_rtx)
 	{
-#ifdef HAVE_return
+	  if (!HAVE_return)
+	    gcc_unreachable ();
+
 	  emit_jump_insn_after_setloc (gen_return (), BB_END (jump_block), loc);
-#else
-	  gcc_unreachable ();
-#endif
 	}
       else
 	{
 	  gcc_assert (jump_label == simple_return_rtx);
-#ifdef HAVE_simple_return
+	  if (!HAVE_simple_return)
+	    gcc_unreachable ();
+
 	  emit_jump_insn_after_setloc (gen_simple_return (),
 				       BB_END (jump_block), loc);
-#else
-	  gcc_unreachable ();
-#endif
 	}
       set_return_jump_label (BB_END (jump_block));
     }
diff --git a/gcc/defaults.h b/gcc/defaults.h
index 6f915bd..d3da328 100644
--- a/gcc/defaults.h
+++ b/gcc/defaults.h
@@ -1398,6 +1398,26 @@  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define TARGET_SUPPORTS_WIDE_INT 0
 #endif
 
+#ifndef HAVE_simple_return
+#define HAVE_simple_return 0
+static inline rtx
+gen_simple_return ()
+{
+  gcc_unreachable ();
+  return NULL;
+}
+#endif
+
+#ifndef HAVE_return
+#define HAVE_return 0
+static inline rtx
+gen_return ()
+{
+  gcc_unreachable ();
+  return NULL;
+}
+#endif
+
 #endif /* GCC_INSN_FLAGS_H  */
 
 #endif  /* ! GCC_DEFAULTS_H */
diff --git a/gcc/function.c b/gcc/function.c
index 9077c91..561a1c5 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -5649,7 +5649,6 @@  prologue_epilogue_contains (const_rtx insn)
   return 0;
 }
 
-#ifdef HAVE_return
 /* Insert use of return register before the end of BB.  */
 
 static void
@@ -5674,12 +5673,10 @@  emit_use_return_register_into_block (basic_block bb)
 static rtx
 gen_return_pattern (bool simple_p)
 {
-#ifdef HAVE_simple_return
+  if (!HAVE_simple_return)
+    gcc_assert (!simple_p);
+
   return simple_p ? gen_simple_return () : gen_return ();
-#else
-  gcc_assert (!simple_p);
-  return gen_return ();
-#endif
 }
 
 /* Insert an appropriate return pattern at the end of block BB.  This
@@ -5697,7 +5694,6 @@  emit_return_into_block (bool simple_p, basic_block bb)
   gcc_assert (ANY_RETURN_P (pat));
   JUMP_LABEL (jump) = pat;
 }
-#endif
 
 /* Set JUMP_LABEL for a return insn.  */
 
@@ -5713,7 +5709,6 @@  set_return_jump_label (rtx returnjump)
     JUMP_LABEL (returnjump) = ret_rtx;
 }
 
-#if defined (HAVE_return) || defined (HAVE_simple_return)
 /* Return true if there are any active insns between HEAD and TAIL.  */
 bool
 active_insn_between (rtx_insn *head, rtx_insn *tail)
@@ -5788,15 +5783,13 @@  convert_jumps_to_returns (basic_block last_bb, bool simple_p,
 	    dest = ret_rtx;
 	  if (!redirect_jump (jump, dest, 0))
 	    {
-#ifdef HAVE_simple_return
-	      if (simple_p)
+	      if (HAVE_simple_return && simple_p)
 		{
 		  if (dump_file)
 		    fprintf (dump_file,
 			     "Failed to redirect bb %d branch.\n", bb->index);
 		  unconverted.safe_push (e);
 		}
-#endif
 	      continue;
 	    }
 
@@ -5811,15 +5804,13 @@  convert_jumps_to_returns (basic_block last_bb, bool simple_p,
 	}
       else
 	{
-#ifdef HAVE_simple_return
-	  if (simple_p)
+	  if (HAVE_simple_return && simple_p)
 	    {
 	      if (dump_file)
 		fprintf (dump_file,
 			 "Failed to redirect bb %d branch.\n", bb->index);
 	      unconverted.safe_push (e);
 	    }
-#endif
 	  continue;
 	}
 
@@ -5847,7 +5838,6 @@  emit_return_for_exit (edge exit_fallthru_edge, bool simple_p)
   exit_fallthru_edge->flags &= ~EDGE_FALLTHRU;
   return last_bb;
 }
-#endif
 
 
 /* Generate the prologue and epilogue RTL if the machine supports it.  Thread
@@ -5902,10 +5892,8 @@  void
 thread_prologue_and_epilogue_insns (void)
 {
   bool inserted;
-#ifdef HAVE_simple_return
   vec<edge> unconverted_simple_returns = vNULL;
   bitmap_head bb_flags;
-#endif
   rtx_insn *returnjump;
   rtx_insn *epilogue_end ATTRIBUTE_UNUSED;
   rtx_insn *prologue_seq ATTRIBUTE_UNUSED, *split_prologue_seq ATTRIBUTE_UNUSED;
@@ -5976,7 +5964,6 @@  thread_prologue_and_epilogue_insns (void)
     }
 #endif
 
-#ifdef HAVE_simple_return
   bitmap_initialize (&bb_flags, &bitmap_default_obstack);
 
   /* Try to perform a kind of shrink-wrapping, making sure the
@@ -5984,7 +5971,6 @@  thread_prologue_and_epilogue_insns (void)
      function that require it.  */
 
   try_shrink_wrapping (&entry_edge, orig_entry_edge, &bb_flags, prologue_seq);
-#endif
 
   if (split_prologue_seq != NULL_RTX)
     {
@@ -6009,14 +5995,11 @@  thread_prologue_and_epilogue_insns (void)
 
   exit_fallthru_edge = find_fallthru_edge (EXIT_BLOCK_PTR_FOR_FN (cfun)->preds);
 
-#ifdef HAVE_simple_return
-  if (entry_edge != orig_entry_edge)
+  if (HAVE_simple_return && entry_edge != orig_entry_edge)
     exit_fallthru_edge
 	= get_unconverted_simple_return (exit_fallthru_edge, bb_flags,
 					 &unconverted_simple_returns,
 					 &returnjump);
-#endif
-#ifdef HAVE_return
   if (HAVE_return)
     {
       if (exit_fallthru_edge == NULL)
@@ -6035,17 +6018,16 @@  thread_prologue_and_epilogue_insns (void)
 	    {
 	      last_bb = emit_return_for_exit (exit_fallthru_edge, false);
 	      epilogue_end = returnjump = BB_END (last_bb);
-#ifdef HAVE_simple_return
+
 	      /* Emitting the return may add a basic block.
 		 Fix bb_flags for the added block.  */
-	      if (last_bb != exit_fallthru_edge->src)
+	      if (HAVE_simple_return && last_bb != exit_fallthru_edge->src)
 		bitmap_set_bit (&bb_flags, last_bb->index);
-#endif
+
 	      goto epilogue_done;
 	    }
 	}
     }
-#endif
 
   /* A small fib -- epilogue is not yet completed, but we wish to re-use
      this marker for the splits of EH_RETURN patterns, and nothing else
@@ -6157,10 +6139,9 @@  epilogue_done:
 	}
     }
 
-#ifdef HAVE_simple_return
-  convert_to_simple_return (entry_edge, orig_entry_edge, bb_flags, returnjump,
-			    unconverted_simple_returns);
-#endif
+  if (HAVE_simple_return)
+    convert_to_simple_return (entry_edge, orig_entry_edge, bb_flags,
+			      returnjump, unconverted_simple_returns);
 
 #ifdef HAVE_sibcall_epilogue
   /* Emit sibling epilogues before any sibling call sites.  */
@@ -6174,11 +6155,8 @@  epilogue_done:
 
       if (!CALL_P (insn)
 	  || ! SIBLING_CALL_P (insn)
-#ifdef HAVE_simple_return
-	  || (entry_edge != orig_entry_edge
-	      && !bitmap_bit_p (&bb_flags, bb->index))
-#endif
-	  )
+	  || (HAVE_simple_return && (entry_edge != orig_entry_edge
+				     && !bitmap_bit_p (&bb_flags, bb->index))))
 	{
 	  ei_next (&ei);
 	  continue;
@@ -6225,9 +6203,7 @@  epilogue_done:
     }
 #endif
 
-#ifdef HAVE_simple_return
   bitmap_clear (&bb_flags);
-#endif
 
   /* Threading the prologue and epilogue changes the artificial refs
      in the entry and exit blocks.  */
diff --git a/gcc/reorg.c b/gcc/reorg.c
index 4922a77..a44d4a3 100644
--- a/gcc/reorg.c
+++ b/gcc/reorg.c
@@ -485,11 +485,7 @@  find_end_label (rtx kind)
       else
 	{
 #ifdef HAVE_epilogue
-	  if (HAVE_epilogue
-#ifdef HAVE_return
-	      && ! HAVE_return
-#endif
-	      )
+	  if (HAVE_epilogue && ! HAVE_return)
 	    /* The RETURN insn has its delay slot filled so we cannot
 	       emit the label just before it.  Since we already have
 	       an epilogue and cannot emit a new RETURN, we cannot
@@ -500,7 +496,6 @@  find_end_label (rtx kind)
 	  /* Otherwise, make a new label and emit a RETURN and BARRIER,
 	     if needed.  */
 	  emit_label (label);
-#ifdef HAVE_return
 	  if (HAVE_return)
 	    {
 	      /* The return we make may have delay slots too.  */
@@ -511,7 +506,6 @@  find_end_label (rtx kind)
 	      if (num_delay_slots (insn) > 0)
 		obstack_ptr_grow (&unfilled_slots_obstack, insn);
 	    }
-#endif
 	}
       *plabel = label;
     }
@@ -3825,12 +3819,8 @@  dbr_schedule (rtx_insn *first)
     delete_related_insns (function_simple_return_label);
 
   need_return_insns = false;
-#ifdef HAVE_return
   need_return_insns |= HAVE_return && function_return_label != 0;
-#endif
-#ifdef HAVE_simple_return
   need_return_insns |= HAVE_simple_return && function_simple_return_label != 0;
-#endif
   if (need_return_insns)
     make_return_insns (first);
 
diff --git a/gcc/shrink-wrap.c b/gcc/shrink-wrap.c
index 3928f3d..6c59da9 100644
--- a/gcc/shrink-wrap.c
+++ b/gcc/shrink-wrap.c
@@ -80,7 +80,6 @@  along with GCC; see the file COPYING3.  If not see
 #include "regcprop.h"
 #include "rtl-iter.h"
 
-#ifdef HAVE_simple_return
 
 /* Return true if INSN requires the stack frame to be set up.
    PROLOGUE_USED contains the hard registers used in the function
@@ -1043,5 +1042,3 @@  convert_to_simple_return (edge entry_edge, edge orig_entry_edge,
 	  }
     }
 }
-
-#endif
diff --git a/gcc/shrink-wrap.h b/gcc/shrink-wrap.h
index 2a91e32..8c9582d 100644
--- a/gcc/shrink-wrap.h
+++ b/gcc/shrink-wrap.h
@@ -23,9 +23,6 @@  along with GCC; see the file COPYING3.  If not see
 #include "hashtab.h"
 #include "vec.h"
 #include "machmode.h"
-
-#ifdef HAVE_simple_return
-
 #include "function.h"
 
 /* In shrink-wrap.c.  */
@@ -43,9 +40,6 @@  extern void convert_to_simple_return (edge entry_edge, edge orig_entry_edge,
 				      rtx_insn *returnjump,
 				      vec<edge> unconverted_simple_returns);
 #define SHRINK_WRAPPING_ENABLED (flag_shrink_wrap && HAVE_simple_return)
-#else
-#define SHRINK_WRAPPING_ENABLED false
-#endif
 
 #endif  /* GCC_SHRINK_WRAP_H  */