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]

some -freoder-blocks fixes



Hi
This patch fixes three bugs in block reordering code found by verify_flow_info.
Sometimes it added second label at the start of block already having the label
and also code for creating new basic block was quite weird keeping some fields
uninitialized.

I've changed it to use create_basic_block and simplified it a bit.  Also code
was setting the basic block boundaries incorrectly, pointing to the barrier,
not jump insn.  These bugs was causing strange problems in sched.

Note that I am still getting aborts in reg_stack due to missing barrier
after the return insn. I didn't tracked down this bug yet. (I need to prepare
for ramsey theory exam first)

Wed Feb 23 13:00:06 CET 2000  Jan Hubicka  <jh@suse.cz>
	* flow.c (fixup_reorder_chain): Avoid double labels in the basic block;
	end of basic block is jump_insn, not barrier; use create_basic_block
	instead of creating basic block by hand.

*** flow.c.old	Tue Feb 22 22:15:57 2000
--- flow.c	Tue Feb 22 23:46:19 2000
*************** fixup_reorder_chain ()
*** 7575,7585 ****
      {
        if (REORDER_BLOCK_ADD_JUMP (BASIC_BLOCK (i)))
  	{
- 	  rtx new_label = gen_label_rtx ();
  	  rtx label_insn, jump_insn, barrier_insn;
  
! 	  label_insn = emit_label_before (new_label,
! 			  REORDER_BLOCK_ADD_JUMP (BASIC_BLOCK (i))->head);
  	  REORDER_BLOCK_ADD_JUMP (BASIC_BLOCK (i))->head = label_insn;	 
  
  	  jump_insn = emit_jump_insn_after (gen_jump (label_insn),
--- 7575,7591 ----
      {
        if (REORDER_BLOCK_ADD_JUMP (BASIC_BLOCK (i)))
  	{
  	  rtx label_insn, jump_insn, barrier_insn;
  
! 	  if (GET_CODE (REORDER_BLOCK_ADD_JUMP (BASIC_BLOCK (i))->head)
! 	      == CODE_LABEL)
! 	    label_insn  = REORDER_BLOCK_ADD_JUMP (BASIC_BLOCK (i))->head;
! 	  else
! 	    {
! 	      rtx new_label = gen_label_rtx ();
! 	      label_insn = emit_label_before (new_label,
! 			      REORDER_BLOCK_ADD_JUMP (BASIC_BLOCK (i))->head);
! 	    }
  	  REORDER_BLOCK_ADD_JUMP (BASIC_BLOCK (i))->head = label_insn;	 
  
  	  jump_insn = emit_jump_insn_after (gen_jump (label_insn),
*************** fixup_reorder_chain ()
*** 7588,7647 ****
  	  ++LABEL_NUSES (label_insn);
  	  barrier_insn = emit_barrier_after (jump_insn);
  	  if (GET_CODE (BASIC_BLOCK (i)->end) != JUMP_INSN)
! 	    BASIC_BLOCK (i)->end = barrier_insn;
  	  /* Add block for jump.  Typically this is when a then is not
  	     predicted and we are jumping to the moved then block.  */
  	  else	
  	    {
! 	      basic_block b;
  
- 	      b = (basic_block) obstack_alloc (function_obstack, sizeof (*b));
  	      VARRAY_GROW (basic_block_info, ++n_basic_blocks);
! 	      BASIC_BLOCK (n_basic_blocks - 1) = b;
! 	      b->index = n_basic_blocks - 1;
! 	      b->head = emit_note_before (NOTE_INSN_BASIC_BLOCK, jump_insn);
! 	      NOTE_BASIC_BLOCK (b->head) = b;
! 	      b->end = barrier_insn;
! 	      
! 	      {
! 		basic_block nb = BASIC_BLOCK (n_basic_blocks - 1);
! 		nb->global_live_at_start
! 		  = OBSTACK_ALLOC_REG_SET (function_obstack);
! 		nb->global_live_at_end
! 		  = OBSTACK_ALLOC_REG_SET (function_obstack);
! 
! 		COPY_REG_SET (nb->global_live_at_start,
! 			      BASIC_BLOCK (i)->global_live_at_start);
! 		COPY_REG_SET (nb->global_live_at_end,
! 			      BASIC_BLOCK (i)->global_live_at_start);
! 		if (BASIC_BLOCK (i)->local_set)
! 		  {
! 		    OBSTACK_ALLOC_REG_SET (function_obstack);
! 		    COPY_REG_SET (nb->local_set, BASIC_BLOCK (i)->local_set);
! 		  }
! 		else
! 		  BASIC_BLOCK (nb->index)->local_set = 0;
! 
! 		nb->aux = xcalloc (1, sizeof (struct reorder_block_def));
! 		REORDER_BLOCK_INDEX (BASIC_BLOCK (n_basic_blocks - 1))
! 		  = REORDER_BLOCK_INDEX (BASIC_BLOCK (i)) + 1;
! 		/* Relink to new block.  */
! 		nb->succ = BASIC_BLOCK (i)->succ;
! 
! 		make_edge (0, BASIC_BLOCK (i), nb, 0);
! 		BASIC_BLOCK (i)->succ->succ_next
! 		  = BASIC_BLOCK (i)->succ->succ_next->succ_next;
! 		nb->succ->succ_next = 0;
! 		/* Fix reorder block index to reflect new block.  */
! 		for (j = 0; j < n_basic_blocks - 1; j++)
! 		  {
! 		    basic_block bbj = BASIC_BLOCK (j);
! 		    basic_block bbi = BASIC_BLOCK (i);
! 		    if (REORDER_BLOCK_INDEX (bbj)
! 			>= REORDER_BLOCK_INDEX (bbi) + 1)
! 		      REORDER_BLOCK_INDEX (bbj)++;
! 		  }
! 	      }
  	    }
  	}
      }
--- 7594,7647 ----
  	  ++LABEL_NUSES (label_insn);
  	  barrier_insn = emit_barrier_after (jump_insn);
  	  if (GET_CODE (BASIC_BLOCK (i)->end) != JUMP_INSN)
! 	    BASIC_BLOCK (i)->end = jump_insn;
  	  /* Add block for jump.  Typically this is when a then is not
  	     predicted and we are jumping to the moved then block.  */
  	  else	
  	    {
! 	      basic_block nb;
  
  	      VARRAY_GROW (basic_block_info, ++n_basic_blocks);
! 	      create_basic_block (n_basic_blocks - 1, jump_insn,
! 				  jump_insn, NULL);
! 	      nb = BASIC_BLOCK (n_basic_blocks - 1);
! 	      nb->global_live_at_start
! 		= OBSTACK_ALLOC_REG_SET (function_obstack);
! 	      nb->global_live_at_end
! 		= OBSTACK_ALLOC_REG_SET (function_obstack);
! 
! 	      COPY_REG_SET (nb->global_live_at_start,
! 			    BASIC_BLOCK (i)->global_live_at_start);
! 	      COPY_REG_SET (nb->global_live_at_end,
! 			    BASIC_BLOCK (i)->global_live_at_start);
! 	      if (BASIC_BLOCK (i)->local_set)
! 		{
! 		  OBSTACK_ALLOC_REG_SET (function_obstack);
! 		  COPY_REG_SET (nb->local_set, BASIC_BLOCK (i)->local_set);
! 		}
! 	      else
! 		BASIC_BLOCK (nb->index)->local_set = 0;
! 
! 	      nb->aux = xcalloc (1, sizeof (struct reorder_block_def));
! 	      REORDER_BLOCK_INDEX (BASIC_BLOCK (n_basic_blocks - 1))
! 		= REORDER_BLOCK_INDEX (BASIC_BLOCK (i)) + 1;
! 	      /* Relink to new block.  */
! 	      nb->succ = BASIC_BLOCK (i)->succ;
! 	      nb->succ->src = nb;
! 
! 	      make_edge (0, BASIC_BLOCK (i), nb, 0);
! 	      BASIC_BLOCK (i)->succ->succ_next
! 		= BASIC_BLOCK (i)->succ->succ_next->succ_next;
! 	      nb->succ->succ_next = 0;
! 	      /* Fix reorder block index to reflect new block.  */
! 	      for (j = 0; j < n_basic_blocks - 1; j++)
! 		{
! 		  basic_block bbj = BASIC_BLOCK (j);
! 		  basic_block bbi = BASIC_BLOCK (i);
! 		  if (REORDER_BLOCK_INDEX (bbj)
! 		      >= REORDER_BLOCK_INDEX (bbi) + 1)
! 		    REORDER_BLOCK_INDEX (bbj)++;
! 		}
  	    }
  	}
      }

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