+/* Returns the list of basic blocks including BB dominated by BB, in the
+ direction DIR up to DEPTH in the dominator tree. The DEPTH of zero will
+ produce a vector containing all dominated blocks. The vector will be sorted
+ in preorder. */
+
+VEC (basic_block, heap) *
+get_dominated_to_depth (enum cdi_direction dir, basic_block bb, int depth)
+{
+ VEC(basic_block, heap) *bbs = NULL;
+ unsigned i;
+ unsigned next_level_start;
+
+ i = 0;
+ VEC_safe_push (basic_block, heap, bbs, bb);
+ next_level_start = 1; /* = VEC_length (basic_block, bbs); */
+
+ 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);
+
+ if (i == next_level_start && --depth)
+ next_level_start = VEC_length (basic_block, bbs);
+ }
+ while (i < next_level_start);
+
+ return bbs;
+}
+
+/* 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)
+{
+ return get_dominated_to_depth (dir, bb, 0);
+}
+