+ir_node *get_Block_dominated_first(const ir_node *bl)
+{
+ assert(is_Block(bl));
+ return get_dom_info(bl)->first;
+}
+
+ir_node *get_Block_dominated_next(const ir_node *bl)
+{
+ assert(is_Block(bl));
+ return get_dom_info(bl)->next;
+}
+
+void dom_tree_walk(ir_node *bl, irg_walk_func *pre,
+ irg_walk_func *post, void *env)
+{
+ ir_node *p;
+
+ if(pre)
+ pre(bl, env);
+
+ dominates_for_each(bl, p) {
+ dom_tree_walk(p, pre, post, env);
+ }
+
+ if(post)
+ post(bl, env);
+}
+
+void dom_tree_walk_irg(ir_graph *irg, irg_walk_func *pre,
+ irg_walk_func *post, void *env)
+{
+ /* The root of the dominator tree should be the start node. */
+ ir_node *root = get_irg_start_block(irg);
+
+ assert(irg->dom_state == dom_consistent
+ && "The dominators of the irg must be consistent");
+ assert(root && "The start block of the graph is NULL?");
+ assert(get_dom_info(root)->idom == NULL
+ && "The start node in the graph must be the root of the dominator tree");
+ dom_tree_walk(root, pre, post, env);
+}
+
+static void assign_tree_pre_order(ir_node *bl, void *data)
+{
+ unsigned *num = data;
+ dom_info *bi = get_dom_info(bl);
+
+ bi->tree_pre_num = (*num)++;
+}
+
+static void assign_tree_pre_order_max(ir_node *bl, void *data)
+{
+ dom_info *bi = get_dom_info(bl);
+ ir_node *p;
+ unsigned max = 0;
+ unsigned children = 0;
+
+ for(p = bi->first; p; p = get_dom_info(p)->next) {
+ unsigned max_p = get_dom_info(p)->max_subtree_pre_num;
+ max = max > max_p ? max : max_p;
+ children++;
+ }
+
+ bi->max_subtree_pre_num = children > 0 ? max : bi->tree_pre_num;
+ assert(bi->max_subtree_pre_num >= bi->tree_pre_num);
+}
+
+/*--------------------------------------------------------------------*/
+/* Building and Removing the dominator datastructure */
+/*--------------------------------------------------------------------*/