Fix for flow_loops_level_compute

Michael Hayes m.hayes@elec.canterbury.ac.nz
Sat Jan 22 15:44:00 GMT 2000


We are not calculating the loop nesting depth and level for all the
outer loops apart from the first one.  This patch fixes this.  
It also changes the loop level to start from 1 to be consistent
with the loop optimizer.  I've also added a new field to the loops
structure that stores the maximum loop nesting depth (or levels
in the loop heirachy tree).

OK to commit?

Michael.

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

	* basic-block.h (struct loops): New field `levels'.
	* flow.c (flow_loops_level_compute): Traverse all outer loops.
	(flow_loop_level_compute): Initialise level to 1.
	(flow_loops_find): Set loops->levels.
	(flow_loops_dump): Print loops->levels.

Index: flow.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/flow.c,v
retrieving revision 1.207
diff -c -3 -p -r1.207 flow.c
*** flow.c	2000/01/20 03:59:57	1.207
--- flow.c	2000/01/22 23:35:03
*************** flow_loops_dump (loops, file, verbose)
*** 6387,6393 ****
    if (! num_loops || ! file)
      return;
  
!   fprintf (file, ";; %d loops found\n", num_loops);
  
    for (i = 0; i < num_loops; i++)
      {
--- 6387,6394 ----
    if (! num_loops || ! file)
      return;
  
!   fprintf (file, ";; %d loops found, %d levels\n", 
! 	   num_loops, loops->levels);
  
    for (i = 0; i < num_loops; i++)
      {
*************** flow_loop_level_compute (loop, depth)
*** 6783,6789 ****
       int depth;
  {
    struct loop *inner;
!   int level = 0;
  
    if (! loop)
      return 0;
--- 6784,6790 ----
       int depth;
  {
    struct loop *inner;
!   int level = 1;
  
    if (! loop)
      return 0;
*************** flow_loop_level_compute (loop, depth)
*** 6791,6797 ****
    /* Traverse loop tree assigning depth and computing level as the
       maximum level of all the inner loops of this loop.  The loop
       level is equivalent to the height of the loop in the loop tree
!      and corresponds to the number of enclosed loop levels.  */
    for (inner = loop->inner; inner; inner = inner->next)
      {
        int ilevel;
--- 6792,6799 ----
    /* Traverse loop tree assigning depth and computing level as the
       maximum level of all the inner loops of this loop.  The loop
       level is equivalent to the height of the loop in the loop tree
!      and corresponds to the number of enclosed loop levels (including
!      itself).  */
    for (inner = loop->inner; inner; inner = inner->next)
      {
        int ilevel;
*************** flow_loop_level_compute (loop, depth)
*** 6811,6821 ****
     hierarchy tree specfied by LOOPS.  Return the maximum enclosed loop
     level.  */
  
! static int 
  flow_loops_level_compute (loops)
       struct loops *loops;
  {
!   return flow_loop_level_compute (loops->tree, 1);
  }
  
  
--- 6813,6834 ----
     hierarchy tree specfied by LOOPS.  Return the maximum enclosed loop
     level.  */
  
! static int
  flow_loops_level_compute (loops)
       struct loops *loops;
  {
!   struct loop *loop;
!   int level;
!   int levels = 0;
! 
!   /* Traverse all the outer level loops.  */
!   for (loop = loops->tree; loop; loop = loop->next)
!     {
!       level = flow_loop_level_compute (loop, 1);
!       if (level > levels)
! 	levels = level;
!     }
!   return levels;
  }
  
  
*************** flow_loops_find (loops)
*** 6970,6976 ****
  
    /* Assign the loop nesting depth and enclosed loop level for each
       loop.  */
!   flow_loops_level_compute (loops);
  
    return num_loops;
  }
--- 6992,6998 ----
  
    /* Assign the loop nesting depth and enclosed loop level for each
       loop.  */
!   loops->levels = flow_loops_level_compute (loops);
  
    return num_loops;
  }
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/22 23:35:03
*************** struct loops
*** 325,330 ****
--- 333,341 ----
    /* Number of natural loops in the function.  */
    int num;
  
+   /* Maxium nested loop level in the function.  */
+   int levels;
+ 
    /* Array of natural loop descriptors (scanning this array in reverse order
       will find the inner loops before their enclosing outer loops).  */
    struct loop *array;



More information about the Gcc-patches mailing list