Natural loop detection

Michael Hayes m.hayes@elec.canterbury.ac.nz
Thu Nov 18 01:04:00 GMT 1999


Could someone please appraise the following patches I have written for
natural loop detection.  The code uses GCC's CFG to detect natural
loops and to build a loop heirachy tree.  I have tried to write the
code so that it can be used generically by the optimisers.


For example, here's an example of using the routines to dump debugging
information about natural loops to a file.

void debug_loops (insns, file)
     rtx insns;
     FILE *file;
{
  struct loops loops_info;
  int num_loops;

  /* Set up CFG.  */
  find_basic_blocks (insns, max_reg_num (), file, 1);

  /* Find natural loops using the CFG.  */
  num_loops = flow_loops_find (&loops_info);

  /* Dump loop information.  */
  flow_loops_dump (&loops_info, file, 0);

  /* Free loop information.  */
  flow_loops_free (&loops_info);
}

Michael.

1999-11-18  Michael Hayes  <m.hayes@elec.canterbury.ac.nz>

	* flow.c (flow_nodes_print, flow_loops_cfg_dump, flow_loop_nested_p,
		flow_loops_dump, flow_loops_free, flow_loop_exits_find, 
		flow_loop_nodes_find, flow_depth_first_order_compute, 
		flow_loop_pre_header_find, flow_loop_tree_node_add,
		flow_loops_tree_build, flow_loop_level_compute, 
		flow_loops_level_compute, flow_loops_find,
		flow_loop_outside_edge_p): New functions to find natural
		loops in the CFG and to build loop heirachy tree.
	* basic-block.h (flow_loops_find, flow_loops_free, flow_loop_dump):
	Added protoypes.
	(struct loops, struct loop): Define.
	* sbitmap.c (sbitmap_a_subset_b_p): New function.
	* sbitmap.h (sbitmap_a_subset_b_p): Added prototype.

Index: flow.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/flow.c,v
retrieving revision 1.189
diff -c -3 -p -r1.189 flow.c
*** flow.c	1999/11/18 06:45:55	1.189
--- flow.c	1999/11/18 08:24:45
*************** add_noreturn_fake_exit_edges ()
*** 6332,6334 ****
--- 6332,6956 ----
      if (BASIC_BLOCK (x)->succ == NULL)
        make_edge (NULL, BASIC_BLOCK (x), EXIT_BLOCK_PTR, EDGE_FAKE);
  }
+ 
+ /* Dump the list of basic blocks in the bitmap NODES.  */
+ static void flow_nodes_print (str, nodes, file)
+      const char *str;
+      const sbitmap nodes;
+      FILE *file;
+ {
+   int node;
+ 
+   fprintf (file, "%s { ", str);
+   EXECUTE_IF_SET_IN_SBITMAP (nodes, 0, node, {fprintf (file, "%d ", node);});
+   fputs ("}\n", file);
+ }
+ 
+ 
+ /* Dump loop related CFG information.  */
+ static void flow_loops_cfg_dump (loops, file)
+      const struct loops *loops;
+      FILE *file;
+ {
+   int i;
+ 
+   if (! loops->num || ! file || !loops->cfg.dom)
+     return;
+ 
+   for (i = 0; i < n_basic_blocks; i++)
+     {
+       edge succ;
+ 
+       fprintf (file, ";; %d succs { ", i);
+       for (succ = BASIC_BLOCK (i)->succ; succ; succ = succ->succ_next)
+ 	fprintf (file, "%d ", succ->dest->index);
+       flow_nodes_print ("} dom", loops->cfg.dom[i], file);	
+     }
+ 
+   if (loops->cfg.dfs_order)
+     {
+       fputs (";; DFS order: ", file);
+       for (i = 0; i < n_basic_blocks; i++)
+ 	fprintf (file, "%d ", loops->cfg.dfs_order[i]);
+       fputs ("\n", file);
+     }
+ }
+ 
+ 
+ /* Return non-zero if the nodes of LOOP are a subset of OUTER.  */
+ int flow_loop_nested_p (outer, loop)
+      struct loop *outer;
+      struct loop *loop;
+ {
+   return sbitmap_a_subset_b_p (loop->nodes, outer->nodes);
+ }
+ 
+ 
+ /* Dump the loop information specified by LOOPS to the stream FILE.  */
+ void flow_loops_dump (loops, file, verbose)
+      const struct loops *loops;
+      FILE *file;
+      int verbose;
+ {
+   int i;
+   int num_loops;
+ 
+   num_loops = loops->num;
+   if (! num_loops || ! file)
+     return;
+ 
+   fprintf (file, ";; %d loops found\n", num_loops);
+ 
+   for (i = 0; i < num_loops; i++)
+     {
+       struct loop *loop = &loops->array[i];
+       basic_block bb_header = BASIC_BLOCK (loop->header);
+       basic_block bb_latch = BASIC_BLOCK (loop->latch);
+ 
+       fprintf (file, ";; loop %d (%d to %d):\n"
+ 	       ";;   header %d, latch %d, pre-header %d,"
+ 	       " depth %d, level %d, parent %d\n",
+ 	       i, INSN_UID (bb_header->head), INSN_UID (bb_latch->end),
+ 	       loop->header, loop->latch, loop->pre_header, 
+ 	       loop->depth, loop->level,
+ 	       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);
+       flow_nodes_print (" exits", loop->exits, file);
+ 
+       if (loop->shared)
+ 	{
+ 	  int j;
+ 
+ 	  for (j = 0; j < i; j++)
+ 	    {
+ 	      struct loop *oloop = &loops->array[j];
+ 
+ 	      if (loop->header == oloop->header)
+ 		{
+ 		  int disjoint;
+ 		  int smaller;
+ 
+ 		  smaller = loop->num_nodes < oloop->num_nodes;
+ 
+ 		  /* If the union of LOOP and OLOOP is different than
+ 		     the larger of LOOP and OLOOP then LOOP and OLOOP
+ 		     must be disjoint.  */
+ 		  disjoint = ! flow_loop_nested_p (smaller ? loop : oloop);
+ 		  fprintf (file, ";; loop header %d shared by loops %d, %d"
+ 			   " %s\n",
+ 			   loop->header, i, j,
+ 			   disjoint ? "disjoint" : "nested");
+ 		}
+ 	    }
+ 	}
+ 
+       if (verbose)
+ 	{
+ 	  /* Print diagnostics to compare our concept of a loop with
+ 	     what the loop notes say.  */
+ 	  if (GET_CODE (PREV_INSN (bb_header->head)) != NOTE
+ 	      || NOTE_LINE_NUMBER (PREV_INSN (bb_header->head))
+ 	      != NOTE_INSN_LOOP_BEG)
+ 	    fprintf (file, ";; No NOTE_INSN_LOOP_BEG at %d\n", 
+ 		     INSN_UID (PREV_INSN (bb_header->head)));
+ 	  if (GET_CODE (NEXT_INSN (bb_latch->end)) != NOTE
+ 	      || NOTE_LINE_NUMBER ( NEXT_INSN (bb_latch->end))
+ 	      != NOTE_INSN_LOOP_END)
+ 	    fprintf (file, ";; No NOTE_INSN_LOOP_END at %d\n",
+ 		     INSN_UID (NEXT_INSN (bb_latch->end)));
+ 	}
+     }
+ 
+   if (verbose)
+     flow_loops_cfg_dump (loops, file);
+ }
+ 
+ 
+ /* Free all the mmeory allocated for LOOPS.  */
+ void flow_loops_free (loops)
+        struct loops *loops;
+ {
+   if (loops->array)
+     {
+       int i;
+ 
+       if (! loops->num)
+ 	abort ();
+ 
+       for (i = 0; i < loops->num; i++)
+ 	{
+ 	  struct loop *loop = &loops->array[i];
+ 	  
+ 	  if (loop->nodes)
+ 	    free (loop->nodes);
+ 	  if (loop->exits)
+ 	    free (loop->exits);
+ 	}
+       
+       if (loops->cfg.dom)
+ 	free (loops->cfg.dom);
+       if (loops->cfg.dfs_order)
+ 	free (loops->cfg.dfs_order);
+ 
+       free (loops->shared_headers);
+       free (loops->array);
+       loops->array = NULL;
+     }
+ }
+ 
+ 
+ /* Find the exits from the loop using the bitmap of loop nodes NODES
+    and store in EXITS.  Return the number of exits from the loop.  */
+ int flow_loop_exits_find (exits, nodes)
+      sbitmap exits;
+      const sbitmap nodes;
+ {
+   edge e;
+   int node;
+   int num_exits;
+ 
+   sbitmap_zero (exits);
+   num_exits = 0;
+ 
+   /* Check all nodes within the loop to see if there are any
+      successors not in the loop.  If so, mark them as exit nodes.
+      Note that a node may have multiple exiting edges.  */
+   EXECUTE_IF_SET_IN_SBITMAP (nodes, 0, node, {
+     for (e = BASIC_BLOCK (node)->succ; e; e = e->succ_next)
+       {
+ 	int snode = e->dest->index;	  
+ 	if (snode == EXIT_BLOCK || ! TEST_BIT (nodes, snode))
+ 	  {
+ 	    SET_BIT (exits, node);
+ 	    num_exits++;
+ 	  }
+       }
+   });
+   return num_exits;
+ }
+ 
+ 
+ /* Find the nodes contained within the loop with header HEADER and
+    latch LATCH and store in NODES.  Return the number of nodes within
+    the loop.  */
+ static int flow_loop_nodes_find (nodes, header, latch)
+      sbitmap nodes;
+      int header;
+      int latch;
+ {
+   int *stack;
+   int sp;
+   int num_nodes = 0;
+ 
+   stack = (int *) xmalloc (n_basic_blocks * sizeof (int));
+   sp = 0;
+ 
+   /* Start with only the loop header in the set of loop nodes.  */
+   sbitmap_zero (nodes);
+   SET_BIT (nodes, header);
+   num_nodes++;
+ 
+   /* Push the loop latch on to the stack.  */
+   if (! TEST_BIT (nodes, latch))
+     {
+       SET_BIT (nodes, latch);
+       num_nodes++;
+       stack[sp++] = latch;
+     }
+ 
+   while (sp)
+     {
+       int node;
+       edge e;
+ 
+       node = stack[--sp];
+       for (e = BASIC_BLOCK (node)->pred; e; e = e->pred_next)
+ 	{
+ 	  int ancestor = e->src->index;
+ 	  
+ 	  /* If each ancestor not marked as part of loop, add to set of
+ 	     loop nodes and push on to stack.  */
+ 	  if (ancestor != ENTRY_BLOCK && ! TEST_BIT (nodes, ancestor))
+ 	    {
+ 	      SET_BIT (nodes, ancestor);
+ 	      num_nodes++;
+ 	      stack[sp++] = ancestor;
+ 	    }
+ 	}
+     }
+   free (stack);
+   return num_nodes;
+ }
+ 
+ 
+ /* Compute the depth first search order and store in the array
+    DFS_ORDER, marking the nodes visited in VISITED.  Returns the
+    number of nodes visited.  */
+ int flow_depth_first_order_compute (dfs_order, visited)
+      int *dfs_order;
+      sbitmap visited;
+ {
+   edge e;
+   edge *stack;
+   int sp;
+   int dfsnum = 0;
+ 
+   stack = (edge *) xmalloc (n_basic_blocks * sizeof (edge));
+   sp = 0;
+ 
+   /* None of the nodes in the CFG have been visited yet.  */
+   sbitmap_zero (visited);
+   
+   /* Start with the first successor edge from the entry block.  */
+   e = ENTRY_BLOCK_PTR->succ;
+   while (e)
+     {
+       int snode = e->src->index;
+       int dnode = e->dest->index;
+       
+       /* Mark that we have visited this node.  */
+       if (snode != ENTRY_BLOCK)
+ 	SET_BIT (visited, snode);
+ 
+       /* If this node has not been visited before, push the current
+ 	 edge on to the stack and proceed with the first successor
+ 	 edge of this node.  */
+       if (dnode != EXIT_BLOCK && ! TEST_BIT (visited, dnode)
+ 	  && BASIC_BLOCK (dnode)->succ)
+ 	{
+ 	  stack[sp++] = e;
+ 	  e = BASIC_BLOCK (dnode)->succ;
+ 	}
+       else
+ 	{
+ 	  if (dnode != EXIT_BLOCK && ! TEST_BIT (visited, dnode)
+ 	      && ! BASIC_BLOCK (dnode)->succ)
+ 	    {
+ 	      /* DNODE has no successors (for example, a non-returning
+                  function is called) so do not push the current edge
+                  but carry on with its next successor.  */
+ 	      dfs_order[dnode] = n_basic_blocks - ++dfsnum;
+ 	      SET_BIT (visited, dnode);
+ 	    }
+ 
+ 	  while (! e->succ_next && snode != ENTRY_BLOCK)
+ 	    {
+ 	      dfs_order[snode] = n_basic_blocks - ++dfsnum;
+ 	      /* Pop edge off stack.  */
+ 	      e = stack[--sp];
+ 	      snode = e->src->index;
+ 	    }
+ 	  e = e->succ_next;
+ 	}
+     }
+   free (stack);
+ 
+   /* The number of nodes visited should not be greater than
+      n_basic_blocks.  */
+   if (dfsnum > n_basic_blocks)
+     abort ();
+ 
+   /* There are some nodes left in the CFG that are unreachable.  */
+   if (dfsnum < n_basic_blocks)
+     abort ();
+   return dfsnum;
+ }
+ 
+ 
+ /* Return the block number for the pre-header of the loop with header
+    HEADER where DOM specifies the dominator information.  Return -1 if
+    there is no pre-header.  */
+ int flow_loop_pre_header_find (header, dom)
+      int header;
+      const sbitmap *dom;     
+ {
+   int pre_header;
+   edge e;
+ 
+   /* If block p is a predecessor of the header and is the only block
+      that the header does not dominate, then it is the pre-header.  */
+   pre_header = -1;
+   for (e = BASIC_BLOCK (header)->pred; e; e = e->pred_next)
+     {
+       int node = e->src->index;
+       
+       if (node != ENTRY_BLOCK && ! TEST_BIT (dom[node], header))
+ 	{
+ 	  if (pre_header == -1)
+ 	    pre_header = node;
+ 	  else
+ 	    {
+ 	      /* There are multiple forward edges into the header.  */
+ 	      pre_header = -1;
+ 	      break;
+ 	    }
+ 	}
+     }
+   return pre_header;
+ }
+ 
+ 
+ /* Add LOOP to the loop heirachy tree.  */
+ static void flow_loop_tree_node_add (parent, loop)
+      struct loop *parent;
+      struct loop *loop;
+ {
+   struct loop *outer;
+ 
+   if (!loop)
+     return;
+ 
+   for (outer = parent; outer; outer = outer->next)
+     {
+       if (flow_loop_nested_p (outer, loop))
+ 	{
+ 	  if (outer->inner)
+ 	    {
+ 	      flow_loop_tree_node_add (outer->inner, loop);
+ 	    }
+ 	  else
+ 	    {
+ 	      outer->inner = loop;
+ 	      loop->outer = outer;
+ 	      loop->next = NULL;
+ 	    }
+ 	  return;
+ 	}
+     }
+   loop->next = parent->next;
+   parent->next = loop;
+   loop->outer = parent->outer;
+ }
+ 
+ 
+ /* Build the loop heirachy tree for LOOPS.  */
+ void flow_loops_tree_build (loops)
+        struct loops *loops;
+ {
+   int i;
+   int num_loops;
+ 
+   num_loops = loops->num;
+   if (! num_loops)
+     return;
+ 
+   /* Root the loop heirachy tree with the first loop found.
+      Since we used a depth first search this should be the 
+      outermost loop.  */
+   loops->tree = &loops->array[0];
+   loops->tree->outer = loops->tree->inner = loops->tree->next = NULL;
+   
+   for (i = 1; i < num_loops; i++)
+     flow_loop_tree_node_add (loops->tree, &loops->array[i]);
+ }
+ 
+ 
+ /* Helper function to compute loop nesting depth and enclosed loop level
+    for the natural loop specified by LOOP at the loop depth DEPTH.  */
+ int flow_loop_level_compute (loop, depth)
+      struct loop *loop;
+      int depth;
+ {
+   struct loop *inner;
+   int level = 0;
+ 
+   if (! loop)
+     return 0;
+ 
+   /* 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;
+ 
+       ilevel = flow_loop_level_compute (inner, depth + 1) + 1;
+ 
+       if (ilevel > level)
+ 	level = ilevel;
+     }
+   loop->level = level;
+   loop->depth = depth;
+   return level;
+ }
+ 
+ 
+ /* Compute the loop nesting depth and enclosed loop level for the loop
+    heirachy 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, 0);
+ }
+ 
+ 
+ /* Find all the natural loops in the function and save in LOOPS structure.
+    Return the number of natural loops found.  */
+ int flow_loops_find (loops)
+        struct loops *loops;
+ {
+   int i;
+   int b;
+   int num_loops;
+   edge e;
+   sbitmap headers;
+   sbitmap *dom;
+   int *dfs_order;
+   
+   loops->num = 0;
+   loops->array = NULL;
+   loops->tree = NULL;
+   dfs_order = NULL;
+ 
+   /* Taking care of this degenerate case makes the rest of
+      this code simpler.  */
+   if (n_basic_blocks == 0)
+     return 0;
+ 
+   /* Compute the dominators and post dominators.  We don't
+      currently use post dominators.  */
+   dom = sbitmap_vector_alloc (n_basic_blocks, n_basic_blocks);
+ 
+   compute_flow_dominators (dom, NULL);
+ 
+   /* Count the number of back edges.  This should be the same as the number
+      of natural loops.  */
+   num_loops = 0;
+   for (b = 0; b < n_basic_blocks; b++)
+     {
+       for (e = BASIC_BLOCK (b)->pred; e; e = e->pred_next)
+ 	{
+ 	  int latch = e->src->index;
+ 	  
+ 	  /* Look for back edges where a predecessor is dominated
+ 	     by this block.  A natural loop has a single entry
+ 	     node (header) that dominates all the nodes in the
+ 	     loop.  It also has single back edge to the header
+ 	     from a latch node.  Note that multiple natural loops
+ 	     may share the same header.  */
+ 	  if (latch != ENTRY_BLOCK && TEST_BIT (dom[latch], b))
+ 	    num_loops++;
+ 	}
+     }
+   
+   if (num_loops)
+     {
+       int *loop_stack;
+       int sp;
+       sbitmap visited;
+ 
+       /* Determine best order to scan nodes so that outer natural
+ 	 loops will be found before inner natural loops.  */
+       dfs_order = (int *) xmalloc (n_basic_blocks * sizeof (int));
+       visited = sbitmap_alloc (n_basic_blocks);
+       flow_depth_first_order_compute (dfs_order, visited);
+       free (visited);
+       
+       loop_stack = (int *) xmalloc (num_loops * sizeof (int));
+       sp = 0;
+       
+       loops->array = (struct loop *)
+ 	xmalloc (num_loops * sizeof (struct loop));
+       bzero ((char *)loops->array, num_loops * sizeof (struct loop));
+       
+       headers = sbitmap_alloc (n_basic_blocks);
+       sbitmap_zero (headers);
+       loops->shared_headers = sbitmap_alloc (n_basic_blocks);
+       sbitmap_zero (loops->shared_headers);
+ 
+       num_loops = 0;
+       for (b = 0; b < n_basic_blocks; b++)
+ 	{
+ 	  int header;
+ 
+ 	  /* Search the nodes of the CFG in DFS order that we can find
+ 	     outer loops first.  */
+ 	  header = dfs_order[b];
+ 	  
+ 	  /* Look for all the possible latch blocks for this header.  */
+ 	  for (e = BASIC_BLOCK (header)->pred; e; e = e->pred_next)
+ 	    {
+ 	      int latch = e->src->index;
+ 	      
+ 	      /* Look for back edges where a predecessor is dominated
+ 		 by this block.  A natural loop has a single entry
+ 		 node (header) that dominates all the nodes in the
+ 		 loop.  It also has single back edge to the header
+ 		 from a latch node.  Note that multiple natural loops
+ 		 may share the same header.  */
+ 	      if (latch != ENTRY_BLOCK && TEST_BIT (dom[latch], header))
+ 		{
+ 		  struct loop *loop;
+ 		  
+ 		  loop = loops->array + num_loops;
+ 		  
+ 		  loop->header = header;
+ 		  loop->latch = latch;
+ 		  
+ 		  /* Keep track of blocks that are loop headers so that we can
+ 		     tell which loops should be merged.  */
+ 		  if (TEST_BIT (headers, header))
+ 		    SET_BIT (loops->shared_headers, header);
+ 		  SET_BIT (headers, header);
+ 		  
+ 		  /* Find nodes contained within the loop.  */
+ 		  loop->nodes = sbitmap_alloc (n_basic_blocks);
+ 		  loop->num_nodes =
+ 		    flow_loop_nodes_find (loop->nodes, header, latch);
+ 		  
+ 		  /* Find nodes which exit the loop.  Note that a node
+ 		     may have several exit edges.  */
+ 		  loop->exits = sbitmap_alloc (n_basic_blocks);
+ 		  loop->num_exits
+ 		    = flow_loop_exits_find (loop->exits, loop->nodes);
+ 
+ 		  /* Look to see if the loop has a pre-header node. */
+ 		  loop->pre_header 
+ 		    = flow_loop_pre_header_find (header, dom);
+ 		  num_loops++;
+ 		}
+ 	    }
+ 	}
+       
+       /* Natural loops with shared headers may either be disjoint or
+ 	 nested.  Disjoint loops with shared headers cannot be inner
+ 	 loops and should be merged.  For now just mark loops that share
+ 	 headers.  */
+       for (i = 0; i < num_loops; i++)
+ 	if (TEST_BIT (loops->shared_headers, loops->array[i].header))
+ 	  loops->array[i].shared = 1;
+ 
+       free (loop_stack);
+       free (headers);
+     }
+ 
+   loops->num = num_loops;
+ 
+   /* Save CFG derived information to avoid recomputing it.  */
+   loops->cfg.dom = dom;
+   loops->cfg.dfs_order = dfs_order;
+ 
+   /* Build the loop heirachy tree.  */
+   flow_loops_tree_build (loops);
+ 
+   /* Assign the loop nesting depth and enclosed loop level.  */
+   flow_loops_level_compute (loops);
+ 
+   return num_loops;
+ }
+ 
+ 
+ /* Return non-zero if EDGE enters header of LOOP from outside of LOOP.  */
+ int flow_loop_outside_edge_p (loop, e)
+      const struct loop *loop;
+      edge e;
+ {
+   if (e->dest->index != loop->header)
+     abort ();
+   return (e->src->index == ENTRY_BLOCK)
+     || ! TEST_BIT (loop->nodes, e->src->index);
+ }
Index: basic-block.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/basic-block.h,v
retrieving revision 1.41
diff -c -3 -p -r1.41 basic-block.h
*** basic-block.h	1999/11/18 08:00:50	1.41
--- basic-block.h	1999/11/18 08:24:46
*************** extern void update_life_info	PROTO ((sbi
*** 274,279 ****
--- 274,359 ----
  					int));
  extern int count_or_remove_death_notes	PROTO ((sbitmap, int));
  
+ 
+ /* Structure to hold information for each natural loop.  */
+ struct loop
+ {
+   /* Basic block number of loop header.  */
+   int header;
+ 
+   /* Basic block number of loop pre-header or -1 if it does not exist.  */
+   int pre_header;
+ 
+   /* Basic block number of loop latch.  */
+   int latch;
+ 
+   /* Bitmap of blocks contained within the loop.  */
+   sbitmap nodes;
+ 
+   /* Number of blocks contained within the loop.  */
+   int num_nodes;
+ 
+   /* Bitmap of blocks that exit the loop.  */
+   sbitmap exits;
+ 
+   /* Number of blocks that exit the loop.  */
+   int num_exits;
+ 
+   /* Non-zero if the loop shares a header with another loop.  */
+   int shared;
+ 
+   /* The loop nesting depth.  */
+   int depth;
+ 
+   /* The height of the loop (enclosed loop levels) within the loop
+      heirachy tree.  */
+   int level;
+ 
+   /* The outer (parent) loop or NULL if outermost loop.  */
+   struct loop *outer;
+ 
+   /* The first inner (child) loop or NULL if inner loop.  */
+   struct loop *inner;
+ 
+   /* Link to the next loop (sibling).  */
+   struct loop *next;
+ 
+   /* Auxiliary info specific to a pass.  */
+   void *info;
+ };
+ 
+ 
+ /* Structure to hold CFG information about natural loops within a function.  */
+ struct loops
+ {
+   /* Number of natural loops in the function.  */
+   int num;
+ 
+   /* Array of natural loop descriptors.  */
+   struct loop *array;
+ 
+   /* Pointer to root of loop heirachy tree.  */
+   struct loop *tree;
+ 
+   /* Information derived from the CFG.  */
+   struct cfg
+   {
+     /* The bitmap vector of dominators or NULL if not computed.  */
+     sbitmap *dom;
+ 
+     /* The ordering of the basic blocks in a depth first search.  */
+     int *dfs_order;
+   } cfg;
+ 
+   /* Headers shared by multiple loops that should be merged.  */
+   sbitmap shared_headers;
+ };
+ 
+ extern int flow_loops_find PROTO ((struct loops *));
+ extern void flow_loops_free PROTO ((struct loops *));
+ extern void flow_loops_dump PROTO ((const struct loops *, FILE *, int));
+ 
+ 
  /* In lcm.c */
  extern struct edge_list *pre_edge_lcm 	PROTO ((FILE *, int, sbitmap *,
  						sbitmap *, sbitmap *, 
Index: sbitmap.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/sbitmap.c,v
retrieving revision 1.6
diff -c -3 -p -r1.6 sbitmap.c
*** sbitmap.c	1999/11/15 07:01:22	1.6
--- sbitmap.c	1999/11/18 08:04:23
*************** sbitmap_a_or_b (dst, a, b)
*** 265,270 ****
--- 265,289 ----
      }
    return changed;
  }
+ /* Return non-zero if A is a subset of B.  */
+ 
+ int
+ sbitmap_a_subset_b_p (a, b)
+      sbitmap a, b;
+ {
+   int i;
+   sbitmap_ptr ap, bp;
+ 
+   ap = a->elms;
+   bp = b->elms;
+   for (i = 0; i < a->size; i++)
+     {
+       if ((*ap | *bp) != *bp)
+ 	return 0;
+       ap++; bp++;
+     }
+   return 1;
+ }
  
  /* Set DST to be (A or (B and C)).
     Return non-zero if any change is made.  */
Index: sbitmap.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/sbitmap.h,v
retrieving revision 1.3
diff -c -3 -p -r1.3 sbitmap.h
*** sbitmap.h	1999/08/25 18:01:48	1.3
--- sbitmap.h	1999/11/18 08:04:23
*************** extern int sbitmap_a_or_b_and_c PROTO ((
*** 109,114 ****
--- 109,115 ----
  extern int sbitmap_a_and_b_or_c PROTO ((sbitmap, sbitmap, sbitmap, sbitmap));
  extern int sbitmap_a_and_b PROTO ((sbitmap, sbitmap, sbitmap));
  extern int sbitmap_a_or_b PROTO ((sbitmap, sbitmap, sbitmap));
+ extern int sbitmap_a_subset_b_p PROTO ((sbitmap, sbitmap));
  
  struct int_list;
  extern void sbitmap_intersect_of_predsucc PROTO ((sbitmap, sbitmap *,



More information about the Gcc-patches mailing list