+/**
+ * Block-Walker: uses dominance depth to mark dead blocks.
+ */
+static void find_unreachable_blocks(ir_node *block, void *env)
+{
+ pdeq *waitq = (pdeq*) env;
+
+ if (get_Block_dom_depth(block) < 0) {
+ ir_graph *irg = get_irn_irg(block);
+ ir_node *end = get_irg_end(irg);
+
+ const ir_edge_t *edge;
+ foreach_block_succ(block, edge) {
+ const ir_edge_t *edge2;
+ ir_node *succ_block = get_edge_src_irn(edge);
+ enqueue_node(succ_block, waitq);
+ foreach_out_edge(succ_block, edge2) {
+ ir_node *succ = get_edge_src_irn(edge2);
+ if (is_Phi(succ))
+ enqueue_node(succ, waitq);
+ }
+ }
+ enqueue_node(end, waitq);
+ }
+}
+
+/* Applies local optimizations (see iropt.h) to all nodes reachable from node n. */
+void local_optimize_graph(ir_graph *irg)
+{
+ ir_graph *rem = current_ir_graph;
+ current_ir_graph = irg;
+
+ do_local_optimize(get_irg_end(irg));
+
+ current_ir_graph = rem;
+}
+