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]

Add first_block and last_block to loops structure



Hi
This patch adds two new fields (first_block and last_block) to the loop
structure.  They can be used by passes that tread loop as interval in
the insn chain such as alignment code in shorten_branches.
Also is usefull for searching of LOOP notes, because they ought to appear
near the first_block and last_block.

I am calculating the info in flow_loop_nodes_find, because it is readily
available there. If you know about better solution, please let me know.

Note that the these values are not equivalent to loop_header and loop_latch,
when entry to loop is not the first basic block. This happends even in "normal"
loops (not only those constructed by gotos), when the condition is not copied
by jump.

Fri Dec 30 06:51:45 CET 1999  Jan Hubicka  <hubicka@freesoft.cz>
	* basic_block.h (struct loops): Add first_block and last_block fields.
	* flow.c (flow_loop_nodes_find): New parameters first_block and last_block,
	calculate them.
	(flow_loops_dump): Print the first_block and last_block fields, use them for
	searching the LOOP notes.
	(flow_loops_find): Update call of flow_loop_nodes_find.

*** flow.c.noi	Thu Dec 30 04:57:05 1999
--- flow.c	Thu Dec 30 05:19:49 1999
*************** static void flow_exits_print PROTO ((con
*** 353,359 ****
  static void flow_loops_cfg_dump		PROTO ((const struct loops *, FILE *));
  static int flow_loop_nested_p		PROTO ((struct loop *, struct loop *));
  static int flow_loop_exits_find		PROTO ((const sbitmap, edge **));
! static int flow_loop_nodes_find	PROTO ((basic_block, basic_block, sbitmap));
  static int flow_depth_first_order_compute PROTO ((int *));
  static basic_block flow_loop_pre_header_find PROTO ((basic_block, const sbitmap *));
  static void flow_loop_tree_node_add	PROTO ((struct loop *, struct loop *));
--- 353,361 ----
  static void flow_loops_cfg_dump		PROTO ((const struct loops *, FILE *));
  static int flow_loop_nested_p		PROTO ((struct loop *, struct loop *));
  static int flow_loop_exits_find		PROTO ((const sbitmap, edge **));
! static int flow_loop_nodes_find		PROTO ((basic_block, basic_block,
! 						basic_block *, basic_block *,
! 						sbitmap));
  static int flow_depth_first_order_compute PROTO ((int *));
  static basic_block flow_loop_pre_header_find PROTO ((basic_block, const sbitmap *));
  static void flow_loop_tree_node_add	PROTO ((struct loop *, struct loop *));
*************** flow_loops_dump (loops, file, verbose)
*** 6397,6408 ****
      {
        struct loop *loop = &loops->array[i];
  
!       fprintf (file, ";; loop %d (%d to %d):\n;;   header %d, latch %d, pre-header %d, depth %d, level %d, outer %ld\n",
  	       i, INSN_UID (loop->header->head), INSN_UID (loop->latch->end),
  	       loop->header->index, loop->latch->index,
  	       loop->pre_header ? loop->pre_header->index : -1, 
  	       loop->depth, loop->level,
! 	       (long) (loop->outer ? (loop->outer - loops->array) : -1));
        fprintf (file, ";;   %d", loop->num_nodes);
        flow_nodes_print (" nodes", loop->nodes, file);
        fprintf (file, ";;   %d", loop->num_exits);
--- 6399,6411 ----
      {
        struct loop *loop = &loops->array[i];
  
!       fprintf (file, ";; loop %d (%d to %d):\n;;   header %d, latch %d, pre-header %d, depth %d, level %d, outer %ld, first %d, last %d\n",
  	       i, INSN_UID (loop->header->head), INSN_UID (loop->latch->end),
  	       loop->header->index, loop->latch->index,
  	       loop->pre_header ? loop->pre_header->index : -1, 
  	       loop->depth, loop->level,
! 	       (long) (loop->outer ? (loop->outer - loops->array) : -1),
! 	       loop->first_block->index, loop->last_block->index);
        fprintf (file, ";;   %d", loop->num_nodes);
        flow_nodes_print (" nodes", loop->nodes, file);
        fprintf (file, ";;   %d", loop->num_exits);
*************** flow_loops_dump (loops, file, verbose)
*** 6439,6454 ****
  	{
  	  /* Print diagnostics to compare our concept of a loop with
  	     what the loop notes say.  */
! 	  if (GET_CODE (PREV_INSN (loop->header->head)) != NOTE
! 	      || NOTE_LINE_NUMBER (PREV_INSN (loop->header->head))
  	      != NOTE_INSN_LOOP_BEG)
  	    fprintf (file, ";; No NOTE_INSN_LOOP_BEG at %d\n", 
! 		     INSN_UID (PREV_INSN (loop->header->head)));
! 	  if (GET_CODE (NEXT_INSN (loop->latch->end)) != NOTE
! 	      || NOTE_LINE_NUMBER (NEXT_INSN (loop->latch->end))
  	      != NOTE_INSN_LOOP_END)
  	    fprintf (file, ";; No NOTE_INSN_LOOP_END at %d\n",
! 		     INSN_UID (NEXT_INSN (loop->latch->end)));
  	}
      }
  
--- 6442,6457 ----
  	{
  	  /* Print diagnostics to compare our concept of a loop with
  	     what the loop notes say.  */
! 	  if (GET_CODE (PREV_INSN (loop->first_block->head)) != NOTE
! 	      || NOTE_LINE_NUMBER (PREV_INSN (loop->first_block->head))
  	      != NOTE_INSN_LOOP_BEG)
  	    fprintf (file, ";; No NOTE_INSN_LOOP_BEG at %d\n", 
! 		     INSN_UID (PREV_INSN (loop->first_block->head)));
! 	  if (GET_CODE (NEXT_INSN (loop->last_block->end)) != NOTE
! 	      || NOTE_LINE_NUMBER (NEXT_INSN (loop->last_block->end))
  	      != NOTE_INSN_LOOP_END)
  	    fprintf (file, ";; No NOTE_INSN_LOOP_END at %d\n",
! 		     INSN_UID (NEXT_INSN (loop->last_block->end)));
  	}
      }
  
*************** flow_loop_exits_find (nodes, exits)
*** 6545,6553 ****
     latch LATCH and store in NODES.  Return the number of nodes within
     the loop.  */
  static int 
! flow_loop_nodes_find (header, latch, nodes)
       basic_block header;
       basic_block latch;
       sbitmap nodes;
  {
    basic_block *stack;
--- 6548,6558 ----
     latch LATCH and store in NODES.  Return the number of nodes within
     the loop.  */
  static int 
! flow_loop_nodes_find (header, latch, first_block, last_block, nodes)
       basic_block header;
       basic_block latch;
+      basic_block *first_block;
+      basic_block *last_block;
       sbitmap nodes;
  {
    basic_block *stack;
*************** flow_loop_nodes_find (header, latch, nod
*** 6562,6572 ****
--- 6567,6583 ----
    SET_BIT (nodes, header->index);
    num_nodes++;
    header->loop_depth++;
+   *first_block = header;
+   *last_block = header;
  
    /* Push the loop latch on to the stack.  */
    if (! TEST_BIT (nodes, latch->index))
      {
        SET_BIT (nodes, latch->index);
+       if (latch->index < (*first_block)->index)
+ 	*first_block = latch;
+       if (latch->index > (*last_block)->index)
+ 	*last_block = latch;
        latch->loop_depth++;
        num_nodes++;
        stack[sp++] = latch;
*************** flow_loop_nodes_find (header, latch, nod
*** 6588,6593 ****
--- 6599,6608 ----
  	      && ! TEST_BIT (nodes, ancestor->index))
  	    {
  	      SET_BIT (nodes, ancestor->index);
+ 	      if (ancestor->index < (*first_block)->index)
+ 		*first_block = ancestor;
+ 	      if (ancestor->index > (*last_block)->index)
+ 		*last_block = ancestor;
  	      ancestor->loop_depth++;
  	      num_nodes++;
  	      stack[sp++] = ancestor;
*************** flow_loops_find (loops)
*** 6932,6938 ****
  		  /* Find nodes contained within the loop.  */
  		  loop->nodes = sbitmap_alloc (n_basic_blocks);
  		  loop->num_nodes
! 		    = flow_loop_nodes_find (header, latch, loop->nodes);
  		  
  		  /* Find edges which exit the loop.  Note that a node
  		     may have several exit edges.  */
--- 6947,6954 ----
  		  /* Find nodes contained within the loop.  */
  		  loop->nodes = sbitmap_alloc (n_basic_blocks);
  		  loop->num_nodes
! 		    = flow_loop_nodes_find (header, latch, &loop->first_block,
! 					    &loop->last_block, loop->nodes);
  		  
  		  /* Find edges which exit the loop.  Note that a node
  		     may have several exit edges.  */
*** basic-block.h.noi	Thu Dec 30 04:57:00 1999
--- basic-block.h	Thu Dec 30 04:58:18 1999
*************** struct loop
*** 236,241 ****
--- 236,245 ----
    /* Basic block of loop latch.  */
    basic_block latch;
  
+   /* Basic block with smallest/largest ID inside loop.  */
+   basic_block first_block, last_block;
+ 
+ 
    /* Basic block of loop pre-header or NULL if it does not exist.  */
    basic_block pre_header;
  


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