public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Joern Rennecke <joern.rennecke@superh.com>
To: gcc-patches@gcc.gnu.org
Subject: RFA: remove fixup_fallthru_exit_predecessor
Date: Fri, 04 Jun 2004 16:19:00 -0000	[thread overview]
Message-ID: <200406041556.i54FuCo20950@linsvr3.uk.superh.com> (raw)

> As far as I can see now, this basically requires that the epilogue is
> emitted at the end of the block with the fallthrough edge to the exit
> block, or in a new block after the former block, if there are other
> edges to the exit block.
> Any code that assumes that the physical end of the function is also
> the logical end after cfg optimizations have started would have to
> be fixed up.

This implements this approach.

2004-06-03  J"orn Rennecke <joern.rennecke@superh.com>

	* basic-block.h (could_fall_through): Declare.
	* cfganal.c (can_fallthru): Suceed if the target is EXIT_BLOCK_PTR.
	Fail if the source already has a fallthrough edge to the exit
	block pointer.
	(could_fall_through): New function.
	(make_edges): Check if we already have a fallthrough edge to the
	exit block pointer.
	cfglayout.c (fixup_fallthru_exit_predecessor): Delete.
	(cfg_layout_finalize): Don't call it.
	(fixup_reorder_chain): A fall through to the exit block does not
	require the block to come last.  Add sanity checks.
	* cfgrtl.c (rtl_split_edge): Add special handling of fall through
	edges to the exit block.

Index: basic-block.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/basic-block.h,v
retrieving revision 1.196
diff -p -r1.196 basic-block.h
*** basic-block.h	15 May 2004 09:39:28 -0000	1.196
--- basic-block.h	4 Jun 2004 13:30:05 -0000
*************** extern void find_sub_basic_blocks (basic
*** 628,633 ****
--- 628,634 ----
  extern void find_many_sub_basic_blocks (sbitmap);
  extern void rtl_make_eh_edge (sbitmap *, basic_block, rtx);
  extern bool can_fallthru (basic_block, basic_block);
+ extern bool could_fall_through (basic_block, basic_block);
  extern void flow_nodes_print (const char *, const sbitmap, FILE *);
  extern void flow_edge_list_print (const char *, const edge *, int, FILE *);
  extern void alloc_aux_for_block (basic_block, int);
Index: cfganal.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cfganal.c,v
retrieving revision 1.42
diff -p -r1.42 cfganal.c
*** cfganal.c	13 May 2004 06:39:32 -0000	1.42
--- cfganal.c	4 Jun 2004 13:30:05 -0000
*************** bool
*** 103,119 ****
  can_fallthru (basic_block src, basic_block target)
  {
    rtx insn = BB_END (src);
!   rtx insn2 = target == EXIT_BLOCK_PTR ? NULL : BB_HEAD (target);
  
    if (src->next_bb != target)
      return 0;
  
    if (insn2 && !active_insn_p (insn2))
      insn2 = next_active_insn (insn2);
  
    /* ??? Later we may add code to move jump tables offline.  */
    return next_active_insn (insn) == insn2;
  }
  \f
  /* Mark the back edges in DFS traversal.
     Return nonzero if a loop (natural or otherwise) is present.
--- 103,144 ----
  can_fallthru (basic_block src, basic_block target)
  {
    rtx insn = BB_END (src);
!   rtx insn2;
!   edge e;
  
+   if (target == EXIT_BLOCK_PTR)
+     return true;
    if (src->next_bb != target)
      return 0;
+   for (e = src->succ; e; e = e->succ_next)
+     if (e->dest == EXIT_BLOCK_PTR
+ 	&& e->flags & EDGE_FALLTHRU)
+     return 0;
  
+   insn2 = BB_HEAD (target);
    if (insn2 && !active_insn_p (insn2))
      insn2 = next_active_insn (insn2);
  
    /* ??? Later we may add code to move jump tables offline.  */
    return next_active_insn (insn) == insn2;
  }
+ 
+ /* Return nonzero if we could reach target from src by falling through,
+    if the target was made adjacent.  If we already have a fall-through
+    edge to the exit block, we can't do that.  */
+ bool
+ could_fall_through (basic_block src, basic_block target)
+ {
+   edge e;
+ 
+   if (target == EXIT_BLOCK_PTR)
+     return true;
+   for (e = src->succ; e; e = e->succ_next)
+     if (e->dest == EXIT_BLOCK_PTR
+ 	&& e->flags & EDGE_FALLTHRU)
+     return 0;
+   return true;
+ }
  \f
  /* Mark the back edges in DFS traversal.
     Return nonzero if a loop (natural or otherwise) is present.
Index: cfgbuild.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cfgbuild.c,v
retrieving revision 1.46
diff -p -r1.46 cfgbuild.c
*** cfgbuild.c	27 May 2004 12:56:30 -0000	1.46
--- cfgbuild.c	4 Jun 2004 13:30:05 -0000
*************** make_edges (rtx label_value_list, basic_
*** 313,318 ****
--- 313,319 ----
        rtx insn, x;
        enum rtx_code code;
        int force_fallthru = 0;
+       edge e;
  
        if (GET_CODE (BB_HEAD (bb)) == CODE_LABEL
  	  && LABEL_ALT_ENTRY_P (BB_HEAD (bb)))
*************** make_edges (rtx label_value_list, basic_
*** 435,440 ****
--- 436,447 ----
  
        /* Find out if we can drop through to the next block.  */
        insn = NEXT_INSN (insn);
+       for (e = bb->succ; e; e = e->succ_next)
+ 	if (e->dest == EXIT_BLOCK_PTR && e->flags & EDGE_FALLTHRU)
+ 	  {
+ 	    insn = 0;
+ 	    break;
+ 	  }
        while (insn
  	     && GET_CODE (insn) == NOTE
  	     && NOTE_LINE_NUMBER (insn) != NOTE_INSN_BASIC_BLOCK)
Index: cfglayout.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cfglayout.c,v
retrieving revision 1.59
diff -p -r1.59 cfglayout.c
*** cfglayout.c	25 May 2004 12:54:53 -0000	1.59
--- cfglayout.c	4 Jun 2004 13:30:05 -0000
*************** static void set_block_levels (tree, int)
*** 53,59 ****
  static void change_scope (rtx, tree, tree);
  
  void verify_insn_chain (void);
- static void fixup_fallthru_exit_predecessor (void);
  static tree insn_scope (rtx);
  static void update_unlikely_executed_notes (basic_block);
  \f
--- 53,58 ----
*************** fixup_reorder_chain (void)
*** 714,719 ****
--- 713,722 ----
  		      && invert_jump (bb_end_insn,
  				      label_for_bb (e_fall->dest), 0))
  		    {
+ #ifdef ENABLE_CHECKING
+ 		      if (!could_fall_through (e_taken->src, e_taken->dest))
+ 			abort ();
+ #endif
  		      e_fall->flags &= ~EDGE_FALLTHRU;
  		      e_taken->flags |= EDGE_FALLTHRU;
  		      update_br_prob_note (bb);
*************** fixup_reorder_chain (void)
*** 731,736 ****
--- 734,743 ----
  	      else if (invert_jump (bb_end_insn,
  				    label_for_bb (e_fall->dest), 0))
  		{
+ #ifdef ENABLE_CHECKING
+ 		  if (!could_fall_through (e_taken->src, e_taken->dest))
+ 		    abort ();
+ #endif
  		  e_fall->flags &= ~EDGE_FALLTHRU;
  		  e_taken->flags |= EDGE_FALLTHRU;
  		  update_br_prob_note (bb);
*************** fixup_reorder_chain (void)
*** 770,776 ****
  	    continue;
  
  	  /* A fallthru to exit block.  */
! 	  if (!bb->rbi->next && e_fall->dest == EXIT_BLOCK_PTR)
  	    continue;
  	}
  
--- 777,783 ----
  	    continue;
  
  	  /* A fallthru to exit block.  */
! 	  if (e_fall->dest == EXIT_BLOCK_PTR)
  	    continue;
  	}
  
*************** verify_insn_chain (void)
*** 910,943 ****
      abort ();
  }
  \f
- /* The block falling through to exit must be the last one in the
-    reordered chain.  Ensure that this condition is met.  */
- static void
- fixup_fallthru_exit_predecessor (void)
- {
-   edge e;
-   basic_block bb = NULL;
- 
-   for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
-     if (e->flags & EDGE_FALLTHRU)
-       bb = e->src;
- 
-   if (bb && bb->rbi->next)
-     {
-       basic_block c = ENTRY_BLOCK_PTR->next_bb;
- 
-       while (c->rbi->next != bb)
- 	c = c->rbi->next;
- 
-       c->rbi->next = bb->rbi->next;
-       while (c->rbi->next)
- 	c = c->rbi->next;
- 
-       c->rbi->next = bb;
-       bb->rbi->next = NULL;
-     }
- }
- \f
  /* Return true in case it is possible to duplicate the basic block BB.  */
  
  /* We do not want to declare the function in a header file, since it should
--- 917,922 ----
*************** cfg_layout_finalize (void)
*** 1176,1182 ****
    verify_flow_info ();
  #endif
    rtl_register_cfg_hooks ();
-   fixup_fallthru_exit_predecessor ();
    fixup_reorder_chain ();
  
  #ifdef ENABLE_CHECKING
--- 1155,1160 ----
Index: cfgrtl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cfgrtl.c,v
retrieving revision 1.118
diff -p -r1.118 cfgrtl.c
*** cfgrtl.c	13 May 2004 06:39:32 -0000	1.118
--- cfgrtl.c	4 Jun 2004 13:30:05 -0000
*************** rtl_split_edge (edge edge_in)
*** 1337,1343 ****
    else
      before = NULL_RTX;
  
!   bb = create_basic_block (before, NULL, edge_in->dest->prev_bb);
  
    /* ??? This info is likely going to be out of date very soon.  */
    if (edge_in->dest->global_live_at_start)
--- 1337,1355 ----
    else
      before = NULL_RTX;
  
!   /* If this is a fall through edge to the exit block, the blocks might be
!      not adjacent, and the right place is the after the source.  */
!   if (edge_in->flags & EDGE_FALLTHRU && edge_in->dest == EXIT_BLOCK_PTR)
!     {
!       before = NEXT_INSN (BB_END (edge_in->src));
!       if (before
! 	  && GET_CODE (before) == NOTE
! 	  && NOTE_LINE_NUMBER (before) == NOTE_INSN_LOOP_END)
! 	before = NEXT_INSN (before);
!       bb = create_basic_block (before, NULL, edge_in->src);
!     }
!   else
!     bb = create_basic_block (before, NULL, edge_in->dest->prev_bb);
  
    /* ??? This info is likely going to be out of date very soon.  */
    if (edge_in->dest->global_live_at_start)

             reply	other threads:[~2004-06-04 15:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-04 16:19 Joern Rennecke [this message]
2004-06-08 19:40 ` Richard Henderson
2004-06-09 15:53   ` Joern Rennecke
2004-06-10 19:22     ` RFA: Use fixup_fallthru_exit_predecessor only for !HAVE_prologue targets, and only after reload (Was: Re: RFA: remove fixup_fallthru_exit_predecessor) Joern Rennecke
2004-06-11 23:33       ` Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200406041556.i54FuCo20950@linsvr3.uk.superh.com \
    --to=joern.rennecke@superh.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).