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]

[tree-ssa] insert changes


We are continueing to have problems inserting stmts into blocks that have
nothing but an empty_stmt_node in them. 

So, this changes the way the insert routines handle an empty block. This seems 
to work for me, it runs the testcases and bootstraps (well, we'll see shortly, 
but it looks good so far :-).

I wont check this in for a while, so those of you that make heavy use of 
the insert routines and might encounter an empty block should give this a 
whirl and make sure I haven't actually broken anything. I don't think I did :-)

This should also make bsi_insert_on_edge() work better.

Next I'll be tackling some of the remaining issues with the out-of-ssa pass.

Andrew


2003-04-29  Andrew MacLeod  <amacleod at redhat dot com>

	* tree-cfg.c (bsi_start): If there are no stmts in a block, use the
	context pointer to represent the basic block.
	(bsi_insert_after): Handle inserting into empty blocks better.
	(bsi_insert_before): Call bsi_insert_after to handle empty blocks.
	* tree-ssa.c (elim_create): Clear bitmap after its been processed 
	instead of during loop.


Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-cfg.c,v
retrieving revision 1.1.4.77
diff -c -p -r1.1.4.77 tree-cfg.c
*** tree-cfg.c	25 Apr 2003 23:42:38 -0000	1.1.4.77
--- tree-cfg.c	29 Apr 2003 13:00:02 -0000
*************** bsi_start (bb)
*** 3056,3061 ****
--- 3056,3067 ----
      else
        i.tp = NULL;
  
+   /* If there are no stmts in the block, set the context to point to the
+      basic block in case we try to insert a stmt with this iterator.  */
+ 
+   if (i.tp == NULL)
+     i.context = (tree) bb;
+ 
    return i;
  }
  
*************** bsi_insert_after (curr_bsi, t, mode)
*** 3331,3346 ****
    tree parent;
  
    curr_container = bsi_container (*curr_bsi);
!   curr_bb = bb_for_stmt (*curr_container);
!   curr_stmt = bsi_stmt (*curr_bsi);
!   parent = parent_stmt (curr_stmt);
!   inserted_tsi = tsi_from_bsi (*curr_bsi);
  
    /* Some blocks are empty. The block iterator points to an empty_stmt_node
       in those cases only.  */
  
    if (curr_stmt == NULL_TREE)
      {
        tsi_link_after (&inserted_tsi, t, TSI_NEW_STMT);
        append_stmt_to_bb (tsi_container (inserted_tsi), curr_bb, parent);
  
--- 3337,3380 ----
    tree parent;
  
    curr_container = bsi_container (*curr_bsi);
!   if (curr_container)
!     {
!       curr_stmt = bsi_stmt (*curr_bsi);
!       curr_bb = bb_for_stmt (*curr_container);
!       parent = parent_stmt (curr_stmt);
!     }
!   else
!     {
!       curr_stmt = NULL_TREE;
!       parent = NULL_TREE;
!       /* bsi_start () will initialize the context pointer to the basic block
!          if the the block is completely devoid of instructions, except
! 	 for possibnly an empty_stmt_node.  */
!       if (curr_bsi->tp == NULL && curr_bsi->context != NULL)
!         curr_bb = (basic_block)(curr_bsi->context);
!       else
!         abort ();
!     }
  
    /* Some blocks are empty. The block iterator points to an empty_stmt_node
       in those cases only.  */
  
    if (curr_stmt == NULL_TREE)
      {
+       /* An empty block should have only one successor, so try to find the 
+          parent block from it.  */
+       edge succ;
+ 
+       succ = curr_bb->succ;
+       if (succ->succ_next != NULL)
+         abort ();
+       
+       if (curr_bb->head_tree_p == NULL)
+         abort ();
+       if (succ->dest != EXIT_BLOCK_PTR)
+ 	parent = parent_stmt (*(succ->dest->head_tree_p));
+       
+       inserted_tsi = tsi_start (curr_bb->head_tree_p);
        tsi_link_after (&inserted_tsi, t, TSI_NEW_STMT);
        append_stmt_to_bb (tsi_container (inserted_tsi), curr_bb, parent);
  
*************** bsi_insert_after (curr_bsi, t, mode)
*** 3350,3355 ****
--- 3384,3391 ----
      }
    else
      {
+       inserted_tsi = tsi_from_bsi (*curr_bsi);
+ 
        same_tsi = bsi_link_after (&inserted_tsi, t, curr_bb, parent);
        bsi_update_from_tsi (curr_bsi, same_tsi);
        if (mode == BSI_NEW_STMT)
*************** bsi_insert_before (curr_bsi, t, mode)
*** 3382,3422 ****
    tree parent;
  
    curr_container = bsi_container (*curr_bsi);
    curr_bb = bb_for_stmt (*curr_container);
    curr_stmt = bsi_stmt (*curr_bsi);
    parent = parent_stmt (curr_stmt);
    inserted_tsi = tsi_from_bsi (*curr_bsi);
  
!   /* Some blocks are empty. The block iterator points to an empty_stmt_node
!      in those cases only.  */
! 
!   if (curr_stmt == NULL_TREE)
!     {
!       tsi_link_after (&inserted_tsi, t, TSI_NEW_STMT);
!       append_stmt_to_bb (tsi_container (inserted_tsi), curr_bb, parent);
! 
!       /* In this case, we will *always* return the new stmt since BSI_SAME_STMT
!          doesn't really exist.  */
!       *curr_bsi = bsi_from_tsi (inserted_tsi);
!     }
    else
!     {
!       /* The only case that needs attention is when the insert is before
! 	 the last stmt in a block. In this case, we have to update the
! 	 container of the end pointer.  */
!       tsi_link_before (&inserted_tsi, t, TSI_NEW_STMT);
!       add_stmt_to_bb (tsi_container (inserted_tsi), curr_bb, parent);
! 
!       same_tsi = inserted_tsi;
!       tsi_next (&same_tsi);
!       if (curr_container == curr_bb->end_tree_p)
!         curr_bb->end_tree_p = tsi_container (same_tsi);
!         
!       if (mode == BSI_SAME_STMT)
!         bsi_update_from_tsi (curr_bsi, same_tsi);
!       else
!         bsi_update_from_tsi (curr_bsi, inserted_tsi);
!     }
  
    inserted_stmt = tsi_stmt (inserted_tsi);
  
--- 3418,3448 ----
    tree parent;
  
    curr_container = bsi_container (*curr_bsi);
+ 
+   /* If this block is empty, let bsi_insert_after() handle it.  */
+   if (curr_container == NULL || bsi_stmt (*curr_bsi) == NULL_TREE)
+     bsi_insert_after (curr_bsi, t, mode);
+     
    curr_bb = bb_for_stmt (*curr_container);
    curr_stmt = bsi_stmt (*curr_bsi);
    parent = parent_stmt (curr_stmt);
    inserted_tsi = tsi_from_bsi (*curr_bsi);
  
!   /* The only case that needs attention is when the insert is before
!      the last stmt in a block. In this case, we have to update the
!      container of the end pointer.  */
!   tsi_link_before (&inserted_tsi, t, TSI_NEW_STMT);
!   add_stmt_to_bb (tsi_container (inserted_tsi), curr_bb, parent);
! 
!   same_tsi = inserted_tsi;
!   tsi_next (&same_tsi);
!   if (curr_container == curr_bb->end_tree_p)
!     curr_bb->end_tree_p = tsi_container (same_tsi);
!     
!   if (mode == BSI_SAME_STMT)
!     bsi_update_from_tsi (curr_bsi, same_tsi);
    else
!     bsi_update_from_tsi (curr_bsi, inserted_tsi);
  
    inserted_stmt = tsi_stmt (inserted_tsi);
  
Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa.c,v
retrieving revision 1.1.4.69
diff -c -p -r1.1.4.69 tree-ssa.c
*** tree-ssa.c	26 Apr 2003 03:04:04 -0000	1.1.4.69
--- tree-ssa.c	29 Apr 2003 13:00:03 -0000
*************** elim_create (g, T)
*** 1132,1142 ****
        EXECUTE_IF_SET_IN_BITMAP (g->succ[T], 0, S,
  	{
  	  SET_BIT (g->visited, T);
- 	  bitmap_clear_bit(g->succ[T], S);
  	  insert_copy_on_edge (g->e, 
  			       partition_to_var (g->map, T), 
  			       partition_to_var (g->map, S));
  	});
      }
    
  }
--- 1132,1142 ----
        EXECUTE_IF_SET_IN_BITMAP (g->succ[T], 0, S,
  	{
  	  SET_BIT (g->visited, T);
  	  insert_copy_on_edge (g->e, 
  			       partition_to_var (g->map, T), 
  			       partition_to_var (g->map, S));
  	});
+       bitmap_clear (g->succ[T]);
      }
    
  }



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