+2009-04-20 Richard Guenther <rguenther@suse.de>
+
+ * basic-block.h (get_all_dominated_blocks): Declare.
+ * dominance.c (get_all_dominated_blocks): New function.
+ * tree-cfg.c (get_all_dominated_blocks): Remove.
+ (remove_edge_and_dominated_blocks): Adjust.
+ * tree-ssa-phiprop.c (tree_ssa_phiprop_1): Fold in ...
+ (tree_ssa_phiprop): ... here. Use get_all_dominated_blocks
+ instead of recursing.
+
2009-04-20 Doug Kwan <dougkwan@google.com>
* cgraph.h (cgraph_node_ptr): New type for vector functions.
extern VEC (basic_block, heap) *get_dominated_by_region (enum cdi_direction,
basic_block *,
unsigned);
+extern VEC (basic_block, heap) *get_all_dominated_blocks (enum cdi_direction,
+ basic_block);
extern void add_to_dominance_info (enum cdi_direction, basic_block);
extern void delete_from_dominance_info (enum cdi_direction, basic_block);
basic_block recompute_dominator (enum cdi_direction, basic_block);
return doms;
}
+/* Returns the list of basic blocks including BB dominated by BB, in the
+ direction DIR. The vector will be sorted in preorder. */
+
+VEC (basic_block, heap) *
+get_all_dominated_blocks (enum cdi_direction dir, basic_block bb)
+{
+ VEC(basic_block, heap) *bbs = NULL;
+ unsigned i;
+
+ i = 0;
+ VEC_safe_push (basic_block, heap, bbs, bb);
+
+ do
+ {
+ basic_block son;
+
+ bb = VEC_index (basic_block, bbs, i++);
+ for (son = first_dom_son (dir, bb);
+ son;
+ son = next_dom_son (dir, son))
+ VEC_safe_push (basic_block, heap, bbs, son);
+ }
+ while (i < VEC_length (basic_block, bbs));
+
+ return bbs;
+}
+
/* Redirect all edges pointing to BB to TO. */
void
redirect_immediate_dominators (enum cdi_direction dir, basic_block bb,
return changed;
}
-/* Stores all basic blocks dominated by BB to DOM_BBS. */
-
-static void
-get_all_dominated_blocks (basic_block bb, VEC (basic_block, heap) **dom_bbs)
-{
- basic_block son;
-
- VEC_safe_push (basic_block, heap, *dom_bbs, bb);
- for (son = first_dom_son (CDI_DOMINATORS, bb);
- son;
- son = next_dom_son (CDI_DOMINATORS, son))
- get_all_dominated_blocks (son, dom_bbs);
-}
-
/* Removes edge E and all the blocks dominated by it, and updates dominance
information. The IL in E->src needs to be updated separately.
If dominance info is not available, only the edge E is removed.*/
get_immediate_dominator (CDI_DOMINATORS, e->dest)->index);
else
{
- get_all_dominated_blocks (e->dest, &bbs_to_remove);
+ bbs_to_remove = get_all_dominated_blocks (CDI_DOMINATORS, e->dest);
for (i = 0; VEC_iterate (basic_block, bbs_to_remove, i, bb); i++)
{
FOR_EACH_EDGE (f, ei, bb->succs)
return phi_inserted;
}
-/* Helper walking the dominator tree starting from BB and processing
- phi nodes with global data PHIVN and N. */
-
-static bool
-tree_ssa_phiprop_1 (basic_block bb, struct phiprop_d *phivn, size_t n)
-{
- bool did_something = false;
- basic_block son;
- gimple_stmt_iterator gsi;
-
- for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
- did_something |= propagate_with_phi (bb, gsi_stmt (gsi), phivn, n);
-
- for (son = first_dom_son (CDI_DOMINATORS, bb);
- son;
- son = next_dom_son (CDI_DOMINATORS, son))
- did_something |= tree_ssa_phiprop_1 (son, phivn, n);
-
- return did_something;
-}
-
/* Main entry for phiprop pass. */
static unsigned int
tree_ssa_phiprop (void)
{
+ VEC(basic_block, heap) *bbs;
struct phiprop_d *phivn;
+ bool did_something = false;
+ basic_block bb;
+ gimple_stmt_iterator gsi;
+ unsigned i;
calculate_dominance_info (CDI_DOMINATORS);
phivn = XCNEWVEC (struct phiprop_d, num_ssa_names);
- if (tree_ssa_phiprop_1 (ENTRY_BLOCK_PTR, phivn, num_ssa_names))
+ /* Walk the dominator tree in preorder. */
+ bbs = get_all_dominated_blocks (CDI_DOMINATORS,
+ single_succ (ENTRY_BLOCK_PTR));
+ for (i = 0; VEC_iterate (basic_block, bbs, i, bb); ++i)
+ for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
+ did_something |= propagate_with_phi (bb, gsi_stmt (gsi),
+ phivn, num_ssa_names);
+
+ if (did_something)
gsi_commit_edge_inserts ();
+ VEC_free (basic_block, heap, bbs);
free (phivn);
return 0;