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]

cfglayout improvement


Hi,
We handle fallthru exit edges in the cfglayout by unconditionally moving the
basic block to be last in the sequence.  This may not be what optimization pass
intend and it breaks when basic block gets duplicatied.
The attached patch makes it to handle in proper way by redirecting the edge to
the label just before end of function.

I've bootstrapped it on cfg-branch, but I would like to get this into mainline
if the patch http://gcc.gnu.org/ml/gcc-patches/2002-02/msg02045.html
will get approved.  I will install it to the branch tomorrow.

Sun May  5 23:03:18 CEST 2002  Jan Hubicka  <jh@suse.cz>

	* cfglayout.c (fixup_fallthru_exit_predecessor): Kill.
	(fixup_reorder_chain): properly handle edges to exit block.

*** cfglayout.c.old	Sun May  5 23:33:41 2002
--- cfglayout.c	Mon May  6 00:13:41 2002
*************** static void set_block_levels		PARAMS ((t
*** 46,52 ****
  static void change_scope		PARAMS ((rtx, tree, tree));
  
  void verify_insn_chain			PARAMS ((void));
- static void fixup_fallthru_exit_predecessor PARAMS ((void));
  static void cleanup_unconditional_jumps	PARAMS ((struct loops *));
  static rtx unlink_insn_chain PARAMS ((rtx, rtx));
  static rtx duplicate_insn_chain PARAMS ((rtx, rtx));
--- 46,51 ----
*************** scope_to_insns_finalize ()
*** 357,363 ****
  static void
  fixup_reorder_chain ()
  {
!   basic_block bb;
    int index;
    rtx insn = NULL;
  
--- 356,362 ----
  static void
  fixup_reorder_chain ()
  {
!   basic_block bb, last_bb;
    int index;
    rtx insn = NULL;
  
*************** fixup_reorder_chain ()
*** 368,373 ****
--- 367,373 ----
         bb != 0;
         bb = RBI (bb)->next, index++)
      {
+       last_bb = bb;
        if (RBI (bb)->header)
  	{
  	  if (insn)
*************** fixup_reorder_chain ()
*** 430,435 ****
--- 430,459 ----
  	else if (! (e->flags & EDGE_EH))
  	  e_taken = e;
  
+       /* In case we need to create edge into exit block,
+ 	 we must ensure empty basic block to be last in the
+ 	 instruction chain and redirect the edge there.  */
+       if (e_fall && e_fall->dest == EXIT_BLOCK_PTR
+ 	  && bb != last_bb)
+ 	{
+ 	  if (!forwarder_block_p (last_bb)
+ 	      || last_bb->succ->dest != EXIT_BLOCK_PTR)
+ 	    {
+ 	      edge ne;
+ 	      nb = create_basic_block (n_basic_blocks, NULL_RTX, NULL_RTX);
+ 	      ne = make_edge (nb, EXIT_BLOCK_PTR, EDGE_FALLTHRU);
+ 	      ne->probability = REG_BR_PROB_BASE;
+ 	      alloc_aux_for_block (nb, sizeof (struct reorder_block_def));
+ 	      RBI (nb)->visited = 1;
+ 	      RBI (last_bb)->next = nb;
+ 	      last_bb = nb;
+ 	    }
+ 	  redirect_edge_succ_nodup (e_fall, last_bb);
+ 	  last_bb->frequency += EDGE_FREQUENCY (e_fall);
+ 	  last_bb->count += e_fall->count;
+ 	  last_bb->succ->count += e_fall->count;
+ 	}
+ 
        bb_end_insn = bb->end;
        if (GET_CODE (bb_end_insn) == JUMP_INSN)
  	{
*************** cleanup_unconditional_jumps (loops)
*** 668,700 ****
      }
  }
  
- /* 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 ()
- {
-   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 && RBI (bb)->next)
-     {
-       basic_block c = BASIC_BLOCK (0);
- 
-       while (RBI (c)->next != bb)
- 	c = RBI (c)->next;
- 
-       RBI (c)->next = RBI (bb)->next;
-       while (RBI (c)->next)
- 	c = RBI (c)->next;
- 
-       RBI (c)->next = bb;
-       RBI (bb)->next = NULL;
-     }
- }
  
  /* Return true in case it is possible to duplicate the basic block BB.  */
  
--- 692,697 ----
*************** cfg_layout_initialize (loops)
*** 969,975 ****
  void
  cfg_layout_finalize ()
  {
-   fixup_fallthru_exit_predecessor ();
    fixup_reorder_chain ();
  
  #ifdef ENABLE_CHECKING
--- 966,971 ----


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