Add first_block and last_block to loops structure

Michael Hayes m.hayes@elec.canterbury.ac.nz
Thu Jan 20 14:13:00 GMT 2000


Jason Eckhardt writes:
 > 
 > Has anyone approved this patch?
 >   http://gcc.gnu.org/ml/gcc-patches/1999-12/msg01013.html
 > This is needed, for example, for the static branch prediction work.

Noone with authority has.  I think that it is OK in principle, but
would recommend the following instead since it appears that the first
and last blocks of a loop are useful for many of the passes using the
natural loop information.

Michael.


2000-01-21  Michael Hayes  <m.hayes@elec.canterbury.ac.nz>

	* basic-block.h (struct loop): New fields 'first' and 'last'.
	* flow.c (flow_loops_find): Compute loop->first and loop->last.
	(flow_loops_dump): Use loop->first to check for NOTE_INSN_LOOP_BEG
	and loop->last to check for NOTE_INSN_LOOP_END.

Index: flow.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/flow.c,v
retrieving revision 1.205
diff -c -3 -p -r1.205 flow.c
*** flow.c	2000/01/14 17:14:43	1.205
--- flow.c	2000/01/20 22:11:48
*************** flow_loops_dump (loops, file, verbose)
*** 6444,6459 ****
  	{
  	  /* 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)));
  	}
      }
  
--- 6444,6459 ----
  	{
  	  /* Print diagnostics to compare our concept of a loop with
  	     what the loop notes say.  */
! 	  if (GET_CODE (PREV_INSN (loop->first->head)) != NOTE
! 	      || NOTE_LINE_NUMBER (PREV_INSN (loop->first->head))
  	      != NOTE_INSN_LOOP_BEG)
  	    fprintf (file, ";; No NOTE_INSN_LOOP_BEG at %d\n", 
! 		     INSN_UID (PREV_INSN (loop->first->head)));
! 	  if (GET_CODE (NEXT_INSN (loop->last->end)) != NOTE
! 	      || NOTE_LINE_NUMBER (NEXT_INSN (loop->last->end))
  	      != NOTE_INSN_LOOP_END)
  	    fprintf (file, ";; No NOTE_INSN_LOOP_END at %d\n",
! 		     INSN_UID (NEXT_INSN (loop->last->end)));
  	}
      }
  
*************** flow_loops_find (loops)
*** 6942,6948 ****
  		  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.  */
  		  loop->num_exits
--- 6942,6957 ----
  		  loop->nodes = sbitmap_alloc (n_basic_blocks);
  		  loop->num_nodes
  		    = flow_loop_nodes_find (header, latch, loop->nodes);
! 
! 		  /* Compute first and last blocks within the loop.
! 		     These are often the same as the loop header and
! 		     loop latch respectively, but this is not always
! 		     the case.  */
! 		  loop->first
! 		    = BASIC_BLOCK (sbitmap_first_set_bit (loop->nodes));
! 		  loop->last
! 		    = BASIC_BLOCK (sbitmap_last_set_bit (loop->nodes));	
! 	  
  		  /* Find edges which exit the loop.  Note that a node
  		     may have several exit edges.  */
  		  loop->num_exits
Index: basic-block.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/basic-block.h,v
retrieving revision 1.46
diff -c -3 -p -r1.46 basic-block.h
*** basic-block.h	2000/01/15 03:01:49	1.46
--- basic-block.h	2000/01/20 22:11:49
*************** struct loop
*** 239,244 ****
--- 239,252 ----
    /* Basic block of loop pre-header or NULL if it does not exist.  */
    basic_block pre_header;
  
+   /* The first block in the loop.  This is not necessarily the same as
+      the loop header.  */
+   basic_block first;
+ 
+   /* The last block in the loop.  This is not necessarily the same as
+      the loop latch.  */
+   basic_block last;
+ 
    /* Bitmap of blocks contained within the loop.  */
    sbitmap nodes;
  



More information about the Gcc-patches mailing list