1 /* Control flow graph analysis code for GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2003, 2004 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* This file contains various simple utilities to analyze the CFG. */
25 #include "coretypes.h"
28 #include "hard-reg-set.h"
29 #include "basic-block.h"
30 #include "insn-config.h"
35 /* Store the data structures necessary for depth-first search. */
36 struct depth_first_search_dsS {
37 /* stack for backtracking during the algorithm */
40 /* number of edges in the stack. That is, positions 0, ..., sp-1
44 /* record of basic blocks already seen by depth-first search */
45 sbitmap visited_blocks;
47 typedef struct depth_first_search_dsS *depth_first_search_ds;
49 static void flow_dfs_compute_reverse_init (depth_first_search_ds);
50 static void flow_dfs_compute_reverse_add_bb (depth_first_search_ds,
52 static basic_block flow_dfs_compute_reverse_execute (depth_first_search_ds);
53 static void flow_dfs_compute_reverse_finish (depth_first_search_ds);
54 static bool flow_active_insn_p (rtx);
56 /* Like active_insn_p, except keep the return value clobber around
60 flow_active_insn_p (rtx insn)
62 if (active_insn_p (insn))
65 /* A clobber of the function return value exists for buggy
66 programs that fail to return a value. Its effect is to
67 keep the return value from being live across the entire
68 function. If we allow it to be skipped, we introduce the
69 possibility for register livetime aborts. */
70 if (GET_CODE (PATTERN (insn)) == CLOBBER
71 && REG_P (XEXP (PATTERN (insn), 0))
72 && REG_FUNCTION_VALUE_P (XEXP (PATTERN (insn), 0)))
78 /* Return true if the block has no effect and only forwards control flow to
79 its single destination. */
82 forwarder_block_p (basic_block bb)
86 if (bb == EXIT_BLOCK_PTR || bb == ENTRY_BLOCK_PTR
87 || !bb->succ || bb->succ->succ_next)
90 for (insn = BB_HEAD (bb); insn != BB_END (bb); insn = NEXT_INSN (insn))
91 if (INSN_P (insn) && flow_active_insn_p (insn))
94 return (!INSN_P (insn)
95 || (JUMP_P (insn) && simplejump_p (insn))
96 || !flow_active_insn_p (insn));
99 /* Return nonzero if we can reach target from src by falling through. */
102 can_fallthru (basic_block src, basic_block target)
104 rtx insn = BB_END (src);
108 if (target == EXIT_BLOCK_PTR)
110 if (src->next_bb != target)
112 for (e = src->succ; e; e = e->succ_next)
113 if (e->dest == EXIT_BLOCK_PTR
114 && e->flags & EDGE_FALLTHRU)
117 insn2 = BB_HEAD (target);
118 if (insn2 && !active_insn_p (insn2))
119 insn2 = next_active_insn (insn2);
121 /* ??? Later we may add code to move jump tables offline. */
122 return next_active_insn (insn) == insn2;
125 /* Return nonzero if we could reach target from src by falling through,
126 if the target was made adjacent. If we already have a fall-through
127 edge to the exit block, we can't do that. */
129 could_fall_through (basic_block src, basic_block target)
133 if (target == EXIT_BLOCK_PTR)
135 for (e = src->succ; e; e = e->succ_next)
136 if (e->dest == EXIT_BLOCK_PTR
137 && e->flags & EDGE_FALLTHRU)
142 /* Mark the back edges in DFS traversal.
143 Return nonzero if a loop (natural or otherwise) is present.
144 Inspired by Depth_First_Search_PP described in:
146 Advanced Compiler Design and Implementation
148 Morgan Kaufmann, 1997
150 and heavily borrowed from flow_depth_first_order_compute. */
153 mark_dfs_back_edges (void)
164 /* Allocate the preorder and postorder number arrays. */
165 pre = xcalloc (last_basic_block, sizeof (int));
166 post = xcalloc (last_basic_block, sizeof (int));
168 /* Allocate stack for back-tracking up CFG. */
169 stack = xmalloc ((n_basic_blocks + 1) * sizeof (edge));
172 /* Allocate bitmap to track nodes that have been visited. */
173 visited = sbitmap_alloc (last_basic_block);
175 /* None of the nodes in the CFG have been visited yet. */
176 sbitmap_zero (visited);
178 /* Push the first edge on to the stack. */
179 stack[sp++] = ENTRY_BLOCK_PTR->succ;
187 /* Look at the edge on the top of the stack. */
191 e->flags &= ~EDGE_DFS_BACK;
193 /* Check if the edge destination has been visited yet. */
194 if (dest != EXIT_BLOCK_PTR && ! TEST_BIT (visited, dest->index))
196 /* Mark that we have visited the destination. */
197 SET_BIT (visited, dest->index);
199 pre[dest->index] = prenum++;
202 /* Since the DEST node has been visited for the first
203 time, check its successors. */
204 stack[sp++] = dest->succ;
207 post[dest->index] = postnum++;
211 if (dest != EXIT_BLOCK_PTR && src != ENTRY_BLOCK_PTR
212 && pre[src->index] >= pre[dest->index]
213 && post[dest->index] == 0)
214 e->flags |= EDGE_DFS_BACK, found = true;
216 if (! e->succ_next && src != ENTRY_BLOCK_PTR)
217 post[src->index] = postnum++;
220 stack[sp - 1] = e->succ_next;
229 sbitmap_free (visited);
234 /* Set the flag EDGE_CAN_FALLTHRU for edges that can be fallthru. */
237 set_edge_can_fallthru_flag (void)
245 for (e = bb->succ; e; e = e->succ_next)
247 e->flags &= ~EDGE_CAN_FALLTHRU;
249 /* The FALLTHRU edge is also CAN_FALLTHRU edge. */
250 if (e->flags & EDGE_FALLTHRU)
251 e->flags |= EDGE_CAN_FALLTHRU;
254 /* If the BB ends with an invertible condjump all (2) edges are
255 CAN_FALLTHRU edges. */
256 if (!bb->succ || !bb->succ->succ_next || bb->succ->succ_next->succ_next)
258 if (!any_condjump_p (BB_END (bb)))
260 if (!invert_jump (BB_END (bb), JUMP_LABEL (BB_END (bb)), 0))
262 invert_jump (BB_END (bb), JUMP_LABEL (BB_END (bb)), 0);
263 bb->succ->flags |= EDGE_CAN_FALLTHRU;
264 bb->succ->succ_next->flags |= EDGE_CAN_FALLTHRU;
268 /* Find unreachable blocks. An unreachable block will have 0 in
269 the reachable bit in block->flags. A nonzero value indicates the
270 block is reachable. */
273 find_unreachable_blocks (void)
276 basic_block *tos, *worklist, bb;
278 tos = worklist = xmalloc (sizeof (basic_block) * n_basic_blocks);
280 /* Clear all the reachability flags. */
283 bb->flags &= ~BB_REACHABLE;
285 /* Add our starting points to the worklist. Almost always there will
286 be only one. It isn't inconceivable that we might one day directly
287 support Fortran alternate entry points. */
289 for (e = ENTRY_BLOCK_PTR->succ; e; e = e->succ_next)
293 /* Mark the block reachable. */
294 e->dest->flags |= BB_REACHABLE;
297 /* Iterate: find everything reachable from what we've already seen. */
299 while (tos != worklist)
301 basic_block b = *--tos;
303 for (e = b->succ; e; e = e->succ_next)
304 if (!(e->dest->flags & BB_REACHABLE))
307 e->dest->flags |= BB_REACHABLE;
314 /* Functions to access an edge list with a vector representation.
315 Enough data is kept such that given an index number, the
316 pred and succ that edge represents can be determined, or
317 given a pred and a succ, its index number can be returned.
318 This allows algorithms which consume a lot of memory to
319 represent the normally full matrix of edge (pred,succ) with a
320 single indexed vector, edge (EDGE_INDEX (pred, succ)), with no
321 wasted space in the client code due to sparse flow graphs. */
323 /* This functions initializes the edge list. Basically the entire
324 flowgraph is processed, and all edges are assigned a number,
325 and the data structure is filled in. */
328 create_edge_list (void)
330 struct edge_list *elist;
336 block_count = n_basic_blocks + 2; /* Include the entry and exit blocks. */
340 /* Determine the number of edges in the flow graph by counting successor
341 edges on each basic block. */
342 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, EXIT_BLOCK_PTR, next_bb)
344 for (e = bb->succ; e; e = e->succ_next)
348 elist = xmalloc (sizeof (struct edge_list));
349 elist->num_blocks = block_count;
350 elist->num_edges = num_edges;
351 elist->index_to_edge = xmalloc (sizeof (edge) * num_edges);
355 /* Follow successors of blocks, and register these edges. */
356 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, EXIT_BLOCK_PTR, next_bb)
357 for (e = bb->succ; e; e = e->succ_next)
358 elist->index_to_edge[num_edges++] = e;
363 /* This function free's memory associated with an edge list. */
366 free_edge_list (struct edge_list *elist)
370 free (elist->index_to_edge);
375 /* This function provides debug output showing an edge list. */
378 print_edge_list (FILE *f, struct edge_list *elist)
382 fprintf (f, "Compressed edge list, %d BBs + entry & exit, and %d edges\n",
383 elist->num_blocks - 2, elist->num_edges);
385 for (x = 0; x < elist->num_edges; x++)
387 fprintf (f, " %-4d - edge(", x);
388 if (INDEX_EDGE_PRED_BB (elist, x) == ENTRY_BLOCK_PTR)
389 fprintf (f, "entry,");
391 fprintf (f, "%d,", INDEX_EDGE_PRED_BB (elist, x)->index);
393 if (INDEX_EDGE_SUCC_BB (elist, x) == EXIT_BLOCK_PTR)
394 fprintf (f, "exit)\n");
396 fprintf (f, "%d)\n", INDEX_EDGE_SUCC_BB (elist, x)->index);
400 /* This function provides an internal consistency check of an edge list,
401 verifying that all edges are present, and that there are no
405 verify_edge_list (FILE *f, struct edge_list *elist)
407 int pred, succ, index;
409 basic_block bb, p, s;
411 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, EXIT_BLOCK_PTR, next_bb)
413 for (e = bb->succ; e; e = e->succ_next)
415 pred = e->src->index;
416 succ = e->dest->index;
417 index = EDGE_INDEX (elist, e->src, e->dest);
418 if (index == EDGE_INDEX_NO_EDGE)
420 fprintf (f, "*p* No index for edge from %d to %d\n", pred, succ);
424 if (INDEX_EDGE_PRED_BB (elist, index)->index != pred)
425 fprintf (f, "*p* Pred for index %d should be %d not %d\n",
426 index, pred, INDEX_EDGE_PRED_BB (elist, index)->index);
427 if (INDEX_EDGE_SUCC_BB (elist, index)->index != succ)
428 fprintf (f, "*p* Succ for index %d should be %d not %d\n",
429 index, succ, INDEX_EDGE_SUCC_BB (elist, index)->index);
433 /* We've verified that all the edges are in the list, now lets make sure
434 there are no spurious edges in the list. */
436 FOR_BB_BETWEEN (p, ENTRY_BLOCK_PTR, EXIT_BLOCK_PTR, next_bb)
437 FOR_BB_BETWEEN (s, ENTRY_BLOCK_PTR->next_bb, NULL, next_bb)
441 for (e = p->succ; e; e = e->succ_next)
448 for (e = s->pred; e; e = e->pred_next)
455 if (EDGE_INDEX (elist, p, s)
456 == EDGE_INDEX_NO_EDGE && found_edge != 0)
457 fprintf (f, "*** Edge (%d, %d) appears to not have an index\n",
459 if (EDGE_INDEX (elist, p, s)
460 != EDGE_INDEX_NO_EDGE && found_edge == 0)
461 fprintf (f, "*** Edge (%d, %d) has index %d, but there is no edge\n",
462 p->index, s->index, EDGE_INDEX (elist, p, s));
466 /* Given PRED and SUCC blocks, return the edge which connects the blocks.
467 If no such edge exists, return NULL. */
470 find_edge (basic_block pred, basic_block succ)
474 for (e = pred->succ; e; e = e->succ_next)
481 /* This routine will determine what, if any, edge there is between
482 a specified predecessor and successor. */
485 find_edge_index (struct edge_list *edge_list, basic_block pred, basic_block succ)
489 for (x = 0; x < NUM_EDGES (edge_list); x++)
490 if (INDEX_EDGE_PRED_BB (edge_list, x) == pred
491 && INDEX_EDGE_SUCC_BB (edge_list, x) == succ)
494 return (EDGE_INDEX_NO_EDGE);
497 /* Dump the list of basic blocks in the bitmap NODES. */
500 flow_nodes_print (const char *str, const sbitmap nodes, FILE *file)
507 fprintf (file, "%s { ", str);
508 EXECUTE_IF_SET_IN_SBITMAP (nodes, 0, node, {fprintf (file, "%d ", node);});
512 /* Dump the list of edges in the array EDGE_LIST. */
515 flow_edge_list_print (const char *str, const edge *edge_list, int num_edges, FILE *file)
522 fprintf (file, "%s { ", str);
523 for (i = 0; i < num_edges; i++)
524 fprintf (file, "%d->%d ", edge_list[i]->src->index,
525 edge_list[i]->dest->index);
531 /* This routine will remove any fake predecessor edges for a basic block.
532 When the edge is removed, it is also removed from whatever successor
536 remove_fake_predecessors (basic_block bb)
540 for (e = bb->pred; e;)
545 if ((tmp->flags & EDGE_FAKE) == EDGE_FAKE)
550 /* This routine will remove all fake edges from the flow graph. If
551 we remove all fake successors, it will automatically remove all
552 fake predecessors. */
555 remove_fake_edges (void)
559 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR->next_bb, NULL, next_bb)
560 remove_fake_predecessors (bb);
563 /* This routine will remove all fake edges to the EXIT_BLOCK. */
566 remove_fake_exit_edges (void)
568 remove_fake_predecessors (EXIT_BLOCK_PTR);
572 /* This function will add a fake edge between any block which has no
573 successors, and the exit block. Some data flow equations require these
577 add_noreturn_fake_exit_edges (void)
582 if (bb->succ == NULL)
583 make_single_succ_edge (bb, EXIT_BLOCK_PTR, EDGE_FAKE);
586 /* This function adds a fake edge between any infinite loops to the
587 exit block. Some optimizations require a path from each node to
590 See also Morgan, Figure 3.10, pp. 82-83.
592 The current implementation is ugly, not attempting to minimize the
593 number of inserted fake edges. To reduce the number of fake edges
594 to insert, add fake edges from _innermost_ loops containing only
595 nodes not reachable from the exit block. */
598 connect_infinite_loops_to_exit (void)
600 basic_block unvisited_block;
601 struct depth_first_search_dsS dfs_ds;
603 /* Perform depth-first search in the reverse graph to find nodes
604 reachable from the exit block. */
605 flow_dfs_compute_reverse_init (&dfs_ds);
606 flow_dfs_compute_reverse_add_bb (&dfs_ds, EXIT_BLOCK_PTR);
608 /* Repeatedly add fake edges, updating the unreachable nodes. */
611 unvisited_block = flow_dfs_compute_reverse_execute (&dfs_ds);
612 if (!unvisited_block)
615 make_edge (unvisited_block, EXIT_BLOCK_PTR, EDGE_FAKE);
616 flow_dfs_compute_reverse_add_bb (&dfs_ds, unvisited_block);
619 flow_dfs_compute_reverse_finish (&dfs_ds);
623 /* Compute reverse top sort order. */
626 flow_reverse_top_sort_order_compute (int *rts_order)
633 /* Allocate stack for back-tracking up CFG. */
634 stack = xmalloc ((n_basic_blocks + 1) * sizeof (edge));
637 /* Allocate bitmap to track nodes that have been visited. */
638 visited = sbitmap_alloc (last_basic_block);
640 /* None of the nodes in the CFG have been visited yet. */
641 sbitmap_zero (visited);
643 /* Push the first edge on to the stack. */
644 stack[sp++] = ENTRY_BLOCK_PTR->succ;
652 /* Look at the edge on the top of the stack. */
657 /* Check if the edge destination has been visited yet. */
658 if (dest != EXIT_BLOCK_PTR && ! TEST_BIT (visited, dest->index))
660 /* Mark that we have visited the destination. */
661 SET_BIT (visited, dest->index);
664 /* Since the DEST node has been visited for the first
665 time, check its successors. */
666 stack[sp++] = dest->succ;
668 rts_order[postnum++] = dest->index;
672 if (! e->succ_next && src != ENTRY_BLOCK_PTR)
673 rts_order[postnum++] = src->index;
676 stack[sp - 1] = e->succ_next;
683 sbitmap_free (visited);
686 /* Compute the depth first search order and store in the array
687 DFS_ORDER if nonzero, marking the nodes visited in VISITED. If
688 RC_ORDER is nonzero, return the reverse completion number for each
689 node. Returns the number of nodes visited. A depth first search
690 tries to get as far away from the starting point as quickly as
694 flow_depth_first_order_compute (int *dfs_order, int *rc_order)
699 int rcnum = n_basic_blocks - 1;
702 /* Allocate stack for back-tracking up CFG. */
703 stack = xmalloc ((n_basic_blocks + 1) * sizeof (edge));
706 /* Allocate bitmap to track nodes that have been visited. */
707 visited = sbitmap_alloc (last_basic_block);
709 /* None of the nodes in the CFG have been visited yet. */
710 sbitmap_zero (visited);
712 /* Push the first edge on to the stack. */
713 stack[sp++] = ENTRY_BLOCK_PTR->succ;
721 /* Look at the edge on the top of the stack. */
726 /* Check if the edge destination has been visited yet. */
727 if (dest != EXIT_BLOCK_PTR && ! TEST_BIT (visited, dest->index))
729 /* Mark that we have visited the destination. */
730 SET_BIT (visited, dest->index);
733 dfs_order[dfsnum] = dest->index;
738 /* Since the DEST node has been visited for the first
739 time, check its successors. */
740 stack[sp++] = dest->succ;
742 /* There are no successors for the DEST node so assign
743 its reverse completion number. */
744 rc_order[rcnum--] = dest->index;
748 if (! e->succ_next && src != ENTRY_BLOCK_PTR
750 /* There are no more successors for the SRC node
751 so assign its reverse completion number. */
752 rc_order[rcnum--] = src->index;
755 stack[sp - 1] = e->succ_next;
762 sbitmap_free (visited);
764 /* The number of nodes visited should not be greater than
766 if (dfsnum > n_basic_blocks)
769 /* There are some nodes left in the CFG that are unreachable. */
770 if (dfsnum < n_basic_blocks)
779 struct dfst_node **node;
780 struct dfst_node *up;
783 /* Compute a preorder transversal ordering such that a sub-tree which
784 is the source of a cross edge appears before the sub-tree which is
785 the destination of the cross edge. This allows for easy detection
786 of all the entry blocks for a loop.
788 The ordering is compute by:
790 1) Generating a depth first spanning tree.
792 2) Walking the resulting tree from right to left. */
795 flow_preorder_transversal_compute (int *pot_order)
803 struct dfst_node *node;
804 struct dfst_node *dfst;
807 /* Allocate stack for back-tracking up CFG. */
808 stack = xmalloc ((n_basic_blocks + 1) * sizeof (edge));
811 /* Allocate the tree. */
812 dfst = xcalloc (last_basic_block, sizeof (struct dfst_node));
817 for (e = bb->succ; e; e = e->succ_next)
822 ? xcalloc (max_successors, sizeof (struct dfst_node *)) : NULL);
825 /* Allocate bitmap to track nodes that have been visited. */
826 visited = sbitmap_alloc (last_basic_block);
828 /* None of the nodes in the CFG have been visited yet. */
829 sbitmap_zero (visited);
831 /* Push the first edge on to the stack. */
832 stack[sp++] = ENTRY_BLOCK_PTR->succ;
839 /* Look at the edge on the top of the stack. */
844 /* Check if the edge destination has been visited yet. */
845 if (dest != EXIT_BLOCK_PTR && ! TEST_BIT (visited, dest->index))
847 /* Mark that we have visited the destination. */
848 SET_BIT (visited, dest->index);
850 /* Add the destination to the preorder tree. */
851 if (src != ENTRY_BLOCK_PTR)
853 dfst[src->index].node[dfst[src->index].nnodes++]
854 = &dfst[dest->index];
855 dfst[dest->index].up = &dfst[src->index];
859 /* Since the DEST node has been visited for the first
860 time, check its successors. */
861 stack[sp++] = dest->succ;
864 else if (e->succ_next)
865 stack[sp - 1] = e->succ_next;
871 sbitmap_free (visited);
873 /* Record the preorder transversal order by
874 walking the tree from right to left. */
877 node = &dfst[ENTRY_BLOCK_PTR->next_bb->index];
884 node = node->node[--node->nnodes];
885 pot_order[i++] = node - dfst;
893 for (i = 0; i < last_basic_block; i++)
900 /* Compute the depth first search order on the _reverse_ graph and
901 store in the array DFS_ORDER, marking the nodes visited in VISITED.
902 Returns the number of nodes visited.
904 The computation is split into three pieces:
906 flow_dfs_compute_reverse_init () creates the necessary data
909 flow_dfs_compute_reverse_add_bb () adds a basic block to the data
910 structures. The block will start the search.
912 flow_dfs_compute_reverse_execute () continues (or starts) the
913 search using the block on the top of the stack, stopping when the
916 flow_dfs_compute_reverse_finish () destroys the necessary data
919 Thus, the user will probably call ..._init(), call ..._add_bb() to
920 add a beginning basic block to the stack, call ..._execute(),
921 possibly add another bb to the stack and again call ..._execute(),
922 ..., and finally call _finish(). */
924 /* Initialize the data structures used for depth-first search on the
925 reverse graph. If INITIALIZE_STACK is nonzero, the exit block is
926 added to the basic block stack. DATA is the current depth-first
927 search context. If INITIALIZE_STACK is nonzero, there is an
928 element on the stack. */
931 flow_dfs_compute_reverse_init (depth_first_search_ds data)
933 /* Allocate stack for back-tracking up CFG. */
934 data->stack = xmalloc ((n_basic_blocks - (INVALID_BLOCK + 1))
935 * sizeof (basic_block));
938 /* Allocate bitmap to track nodes that have been visited. */
939 data->visited_blocks = sbitmap_alloc (last_basic_block - (INVALID_BLOCK + 1));
941 /* None of the nodes in the CFG have been visited yet. */
942 sbitmap_zero (data->visited_blocks);
947 /* Add the specified basic block to the top of the dfs data
948 structures. When the search continues, it will start at the
952 flow_dfs_compute_reverse_add_bb (depth_first_search_ds data, basic_block bb)
954 data->stack[data->sp++] = bb;
955 SET_BIT (data->visited_blocks, bb->index - (INVALID_BLOCK + 1));
958 /* Continue the depth-first search through the reverse graph starting with the
959 block at the stack's top and ending when the stack is empty. Visited nodes
960 are marked. Returns an unvisited basic block, or NULL if there is none
964 flow_dfs_compute_reverse_execute (depth_first_search_ds data)
971 bb = data->stack[--data->sp];
973 /* Perform depth-first search on adjacent vertices. */
974 for (e = bb->pred; e; e = e->pred_next)
975 if (!TEST_BIT (data->visited_blocks,
976 e->src->index - (INVALID_BLOCK + 1)))
977 flow_dfs_compute_reverse_add_bb (data, e->src);
980 /* Determine if there are unvisited basic blocks. */
981 FOR_BB_BETWEEN (bb, EXIT_BLOCK_PTR, NULL, prev_bb)
982 if (!TEST_BIT (data->visited_blocks, bb->index - (INVALID_BLOCK + 1)))
988 /* Destroy the data structures needed for depth-first search on the
992 flow_dfs_compute_reverse_finish (depth_first_search_ds data)
995 sbitmap_free (data->visited_blocks);
998 /* Performs dfs search from BB over vertices satisfying PREDICATE;
999 if REVERSE, go against direction of edges. Returns number of blocks
1000 found and their list in RSLT. RSLT can contain at most RSLT_MAX items. */
1002 dfs_enumerate_from (basic_block bb, int reverse,
1003 bool (*predicate) (basic_block, void *),
1004 basic_block *rslt, int rslt_max, void *data)
1006 basic_block *st, lbb;
1009 st = xcalloc (rslt_max, sizeof (basic_block));
1010 rslt[tv++] = st[sp++] = bb;
1011 bb->flags |= BB_VISITED;
1018 for (e = lbb->pred; e; e = e->pred_next)
1019 if (!(e->src->flags & BB_VISITED) && predicate (e->src, data))
1023 rslt[tv++] = st[sp++] = e->src;
1024 e->src->flags |= BB_VISITED;
1029 for (e = lbb->succ; e; e = e->succ_next)
1030 if (!(e->dest->flags & BB_VISITED) && predicate (e->dest, data))
1034 rslt[tv++] = st[sp++] = e->dest;
1035 e->dest->flags |= BB_VISITED;
1040 for (sp = 0; sp < tv; sp++)
1041 rslt[sp]->flags &= ~BB_VISITED;