bool
mark_dfs_back_edges (void)
{
- edge_iterator *stack;
int *pre;
int *post;
- int sp;
int prenum = 1;
int postnum = 1;
bool found = false;
post = XCNEWVEC (int, last_basic_block_for_fn (cfun));
/* Allocate stack for back-tracking up CFG. */
- stack = XNEWVEC (edge_iterator, n_basic_blocks_for_fn (cfun) + 1);
- sp = 0;
+ auto_vec<edge_iterator, 20> stack (n_basic_blocks_for_fn (cfun) + 1);
/* Allocate bitmap to track nodes that have been visited. */
auto_sbitmap visited (last_basic_block_for_fn (cfun));
bitmap_clear (visited);
/* Push the first edge on to the stack. */
- stack[sp++] = ei_start (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs);
+ stack.quick_push (ei_start (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs));
- while (sp)
+ while (!stack.is_empty ())
{
- edge_iterator ei;
basic_block src;
basic_block dest;
/* Look at the edge on the top of the stack. */
- ei = stack[sp - 1];
+ edge_iterator ei = stack.last ();
src = ei_edge (ei)->src;
dest = ei_edge (ei)->dest;
ei_edge (ei)->flags &= ~EDGE_DFS_BACK;
{
/* Since the DEST node has been visited for the first
time, check its successors. */
- stack[sp++] = ei_start (dest->succs);
+ stack.quick_push (ei_start (dest->succs));
}
else
post[dest->index] = postnum++;
post[src->index] = postnum++;
if (!ei_one_before_end_p (ei))
- ei_next (&stack[sp - 1]);
+ ei_next (&stack.last ());
else
- sp--;
+ stack.pop ();
}
}
free (pre);
free (post);
- free (stack);
return found;
}
post_order_compute (int *post_order, bool include_entry_exit,
bool delete_unreachable)
{
- edge_iterator *stack;
- int sp;
int post_order_num = 0;
int count;
post_order[post_order_num++] = EXIT_BLOCK;
/* Allocate stack for back-tracking up CFG. */
- stack = XNEWVEC (edge_iterator, n_basic_blocks_for_fn (cfun) + 1);
- sp = 0;
+ auto_vec<edge_iterator, 20> stack (n_basic_blocks_for_fn (cfun) + 1);
/* Allocate bitmap to track nodes that have been visited. */
auto_sbitmap visited (last_basic_block_for_fn (cfun));
bitmap_clear (visited);
/* Push the first edge on to the stack. */
- stack[sp++] = ei_start (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs);
+ stack.quick_push (ei_start (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs));
- while (sp)
+ while (!stack.is_empty ())
{
- edge_iterator ei;
basic_block src;
basic_block dest;
/* Look at the edge on the top of the stack. */
- ei = stack[sp - 1];
+ edge_iterator ei = stack.last ();
src = ei_edge (ei)->src;
dest = ei_edge (ei)->dest;
if (EDGE_COUNT (dest->succs) > 0)
/* Since the DEST node has been visited for the first
time, check its successors. */
- stack[sp++] = ei_start (dest->succs);
+ stack.quick_push (ei_start (dest->succs));
else
post_order[post_order_num++] = dest->index;
}
post_order[post_order_num++] = src->index;
if (!ei_one_before_end_p (ei))
- ei_next (&stack[sp - 1]);
+ ei_next (&stack.last ());
else
- sp--;
+ stack.pop ();
}
}
tidy_fallthru_edges ();
}
- free (stack);
return post_order_num;
}
sbitmap *start_points)
{
basic_block bb;
- edge_iterator *stack;
- int sp;
int post_order_num = 0;
if (flag_checking)
verify_no_unreachable_blocks ();
/* Allocate stack for back-tracking up CFG. */
- stack = XNEWVEC (edge_iterator, n_basic_blocks_for_fn (cfun) + 1);
- sp = 0;
+ auto_vec<edge_iterator, 20> stack (n_basic_blocks_for_fn (cfun) + 1);
/* Allocate bitmap to track nodes that have been visited. */
auto_sbitmap visited (last_basic_block_for_fn (cfun));
if (bitmap_bit_p (*start_points, bb->index)
&& EDGE_COUNT (bb->preds) > 0)
{
- stack[sp++] = ei_start (bb->preds);
+ stack.quick_push (ei_start (bb->preds));
bitmap_set_bit (visited, bb->index);
}
if (EDGE_COUNT (EXIT_BLOCK_PTR_FOR_FN (cfun)->preds))
{
- stack[sp++] = ei_start (EXIT_BLOCK_PTR_FOR_FN (cfun)->preds);
+ stack.quick_push (ei_start (EXIT_BLOCK_PTR_FOR_FN (cfun)->preds));
bitmap_set_bit (visited, EXIT_BLOCK_PTR_FOR_FN (cfun)->index);
}
}
/* Push the initial edge on to the stack. */
if (EDGE_COUNT (bb->preds) > 0)
{
- stack[sp++] = ei_start (bb->preds);
+ stack.quick_push (ei_start (bb->preds));
bitmap_set_bit (visited, bb->index);
}
}
bool has_unvisited_bb = false;
/* The inverted traversal loop. */
- while (sp)
+ while (!stack.is_empty ())
{
edge_iterator ei;
basic_block pred;
/* Look at the edge on the top of the stack. */
- ei = stack[sp - 1];
+ ei = stack.last ();
bb = ei_edge (ei)->dest;
pred = ei_edge (ei)->src;
if (EDGE_COUNT (pred->preds) > 0)
/* Since the predecessor node has been visited for the first
time, check its predecessors. */
- stack[sp++] = ei_start (pred->preds);
+ stack.quick_push (ei_start (pred->preds));
else
post_order[post_order_num++] = pred->index;
}
post_order[post_order_num++] = bb->index;
if (!ei_one_before_end_p (ei))
- ei_next (&stack[sp - 1]);
+ ei_next (&stack.last ());
else
- sp--;
+ stack.pop ();
}
}
/* Detect any infinite loop and activate the kludge.
Note that this doesn't check EXIT_BLOCK itself
- since EXIT_BLOCK is always added after the outer do-while loop. */
+ since EXIT_BLOCK is always added after the outer do-while loop. */
FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun),
EXIT_BLOCK_PTR_FOR_FN (cfun), next_bb)
if (!bitmap_bit_p (visited, bb->index))
basic_block be = dfs_find_deadend (bb);
gcc_assert (be != NULL);
bitmap_set_bit (visited, be->index);
- stack[sp++] = ei_start (be->preds);
+ stack.quick_push (ei_start (be->preds));
break;
}
}
}
- if (has_unvisited_bb && sp == 0)
+ if (has_unvisited_bb && stack.is_empty ())
{
- /* No blocks are reachable from EXIT at all.
+ /* No blocks are reachable from EXIT at all.
Find a dead-end from the ENTRY, and restart the iteration. */
basic_block be = dfs_find_deadend (ENTRY_BLOCK_PTR_FOR_FN (cfun));
gcc_assert (be != NULL);
bitmap_set_bit (visited, be->index);
- stack[sp++] = ei_start (be->preds);
+ stack.quick_push (ei_start (be->preds));
}
/* The only case the below while fires is
when there's an infinite loop. */
}
- while (sp);
+ while (!stack.is_empty ());
/* EXIT_BLOCK is always included. */
post_order[post_order_num++] = EXIT_BLOCK;
- free (stack);
return post_order_num;
}
int *pre_order, int *rev_post_order,
bool include_entry_exit)
{
- edge_iterator *stack;
- int sp;
int pre_order_num = 0;
int rev_post_order_num = n_basic_blocks_for_fn (cfun) - 1;
/* Allocate stack for back-tracking up CFG. */
- stack = XNEWVEC (edge_iterator, n_basic_blocks_for_fn (cfun) + 1);
- sp = 0;
+ auto_vec<edge_iterator, 20> stack (n_basic_blocks_for_fn (cfun) + 1);
if (include_entry_exit)
{
bitmap_clear (visited);
/* Push the first edge on to the stack. */
- stack[sp++] = ei_start (ENTRY_BLOCK_PTR_FOR_FN (fn)->succs);
+ stack.quick_push (ei_start (ENTRY_BLOCK_PTR_FOR_FN (fn)->succs));
- while (sp)
+ while (!stack.is_empty ())
{
- edge_iterator ei;
basic_block src;
basic_block dest;
/* Look at the edge on the top of the stack. */
- ei = stack[sp - 1];
+ edge_iterator ei = stack.last ();
src = ei_edge (ei)->src;
dest = ei_edge (ei)->dest;
if (EDGE_COUNT (dest->succs) > 0)
/* Since the DEST node has been visited for the first
time, check its successors. */
- stack[sp++] = ei_start (dest->succs);
+ stack.quick_push (ei_start (dest->succs));
else if (rev_post_order)
/* There are no successors for the DEST node so assign
its reverse completion number. */
rev_post_order[rev_post_order_num--] = src->index;
if (!ei_one_before_end_p (ei))
- ei_next (&stack[sp - 1]);
+ ei_next (&stack.last ());
else
- sp--;
+ stack.pop ();
}
}
- free (stack);
-
if (include_entry_exit)
{
if (pre_order)