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]

[patch, commited] Fix small inconsistency in loop analysis


Hello,

flow_loops_find is not creating the loop tree in case the function has
no basic blocks; this is somewhat inconsistent, as in other cases when
there are no loops in the function, we create the root of the tree.
Dealing with this special case when preserving the loops through
optimizations is somewhat annoying, so this patch fixes the
inconsistency by creating the root of the tree even in this special
case.

Bootstrapped & regtested on ia64, commited.

Zdenek

	* cfgloop.c (init_loops_structure): New function.
	(flow_loops_find): Create root of the loop tree unconditionally.

Index: cfgloop.c
===================================================================
*** cfgloop.c	(revision 126869)
--- cfgloop.c	(working copy)
*************** alloc_loop (void)
*** 343,348 ****
--- 343,371 ----
    return loop;
  }
  
+ /* Initializes loops structure LOOPS, reserving place for NUM_LOOPS loops
+    (including the root of the loop tree).  */
+ 
+ static void
+ init_loops_structure (struct loops *loops, unsigned num_loops)
+ {
+   struct loop *root;
+ 
+   memset (loops, 0, sizeof *loops);
+   loops->larray = VEC_alloc (loop_p, gc, num_loops);
+ 
+   /* Dummy loop containing whole function.  */
+   root = alloc_loop ();
+   root->num_nodes = n_basic_blocks;
+   root->latch = EXIT_BLOCK_PTR;
+   root->header = ENTRY_BLOCK_PTR;
+   ENTRY_BLOCK_PTR->loop_father = root;
+   EXIT_BLOCK_PTR->loop_father = root;
+ 
+   VEC_quick_push (loop_p, loops->larray, root);
+   loops->tree_root = root;
+ }
+ 
  /* Find all the natural loops in the function and save in LOOPS structure and
     recalculate loop_depth information in basic block structures.
     Return the number of natural loops found.  */
*************** flow_loops_find (struct loops *loops)
*** 358,378 ****
    int *rc_order;
    basic_block header;
    basic_block bb;
-   struct loop *root;
  
!   memset (loops, 0, sizeof *loops);
  
    /* Taking care of this degenerate case makes the rest of
       this code simpler.  */
    if (n_basic_blocks == NUM_FIXED_BLOCKS)
!     return 0;
  
    dfs_order = NULL;
    rc_order = NULL;
  
-   /* Ensure that the dominators are computed.  */
-   calculate_dominance_info (CDI_DOMINATORS);
- 
    /* Count the number of loop headers.  This should be the
       same as the number of natural loops.  */
    headers = sbitmap_alloc (last_basic_block);
--- 381,401 ----
    int *rc_order;
    basic_block header;
    basic_block bb;
  
!   /* Ensure that the dominators are computed.  */
!   calculate_dominance_info (CDI_DOMINATORS);
  
    /* Taking care of this degenerate case makes the rest of
       this code simpler.  */
    if (n_basic_blocks == NUM_FIXED_BLOCKS)
!     {
!       init_loops_structure (loops, 1);
!       return 1;
!     }
  
    dfs_order = NULL;
    rc_order = NULL;
  
    /* Count the number of loop headers.  This should be the
       same as the number of natural loops.  */
    headers = sbitmap_alloc (last_basic_block);
*************** flow_loops_find (struct loops *loops)
*** 415,432 ****
      }
  
    /* Allocate loop structures.  */
!   loops->larray = VEC_alloc (loop_p, gc, num_loops + 1);
! 
!   /* Dummy loop containing whole function.  */
!   root = alloc_loop ();
!   root->num_nodes = n_basic_blocks;
!   root->latch = EXIT_BLOCK_PTR;
!   root->header = ENTRY_BLOCK_PTR;
!   ENTRY_BLOCK_PTR->loop_father = root;
!   EXIT_BLOCK_PTR->loop_father = root;
! 
!   VEC_quick_push (loop_p, loops->larray, root);
!   loops->tree_root = root;
  
    /* Find and record information about all the natural loops
       in the CFG.  */
--- 438,444 ----
      }
  
    /* Allocate loop structures.  */
!   init_loops_structure (loops, num_loops + 1);
  
    /* Find and record information about all the natural loops
       in the CFG.  */


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