Remove pointless local variables.
[libfirm] / ir / ir / irgopt.c
index 9c3eb8e..256296c 100644 (file)
@@ -71,18 +71,19 @@ static void optimize_in_place_wrapper(ir_node *n, void *env)
  */
 static inline void do_local_optimize(ir_node *n)
 {
+       ir_graph *irg = get_irn_irg(n);
+
        /* Handle graph state */
-       assert(get_irg_phase_state(current_ir_graph) != phase_building);
+       assert(get_irg_phase_state(irg) != phase_building);
 
        if (get_opt_global_cse())
-               set_irg_pinned(current_ir_graph, op_pin_state_floats);
-       set_irg_outs_inconsistent(current_ir_graph);
-       set_irg_doms_inconsistent(current_ir_graph);
-       set_irg_loopinfo_inconsistent(current_ir_graph);
+               set_irg_pinned(irg, op_pin_state_floats);
+       set_irg_outs_inconsistent(irg);
+       set_irg_doms_inconsistent(irg);
+       set_irg_loopinfo_inconsistent(irg);
 
        /* Clean the value_table in irg for the CSE. */
-       del_identities(current_ir_graph->value_table);
-       current_ir_graph->value_table = new_identities();
+       new_identities(irg);
 
        /* walk over the graph */
        irg_walk(n, firm_clear_link, optimize_in_place_wrapper, NULL);
@@ -111,7 +112,8 @@ static void kill_dead_blocks(ir_node *block, void *env)
                 * Note that the new dominance code correctly handles
                 * the End block, i.e. it is always reachable from Start
                 */
-               set_Block_dead(block);
+               ir_graph *irg = get_irn_irg(block);
+               exchange(block, get_irg_bad(irg));
        }
 }
 
@@ -121,9 +123,6 @@ void local_optimize_graph(ir_graph *irg)
        ir_graph *rem = current_ir_graph;
        current_ir_graph = irg;
 
-       if (get_irg_dom_state(irg) == dom_consistent)
-               irg_block_walk_graph(irg, NULL, kill_dead_blocks, NULL);
-
        do_local_optimize(get_irg_end(irg));
 
        current_ir_graph = rem;
@@ -154,12 +153,12 @@ static void enqueue_users(ir_node *n, pdeq *waitq)
 
 /**
  * Data flow optimization walker.
- * Optimizes all nodes and enqueue it's users
+ * Optimizes all nodes and enqueue its users
  * if done.
  */
 static void opt_walker(ir_node *n, void *env)
 {
-       pdeq *waitq = env;
+       pdeq *waitq = (pdeq*)env;
        ir_node *optimized;
 
        optimized = optimize_in_place_2(n);
@@ -182,16 +181,21 @@ int optimize_graph_df(ir_graph *irg)
        current_ir_graph = irg;
 
        state = edges_assure(irg);
-
-       if (get_opt_global_cse())
-               set_irg_pinned(current_ir_graph, op_pin_state_floats);
+       assure_doms(irg);
 
        /* Clean the value_table in irg for the CSE. */
-       del_identities(irg->value_table);
-       irg->value_table = new_identities();
+       new_identities(irg);
 
-       if (get_irg_dom_state(irg) == dom_consistent)
-               irg_block_walk_graph(irg, NULL, kill_dead_blocks, NULL);
+       if (get_opt_global_cse()) {
+               set_irg_pinned(irg, op_pin_state_floats);
+       }
+
+       /* The following enables unreachable code elimination (=Blocks may be
+        * Bad). We cannot enable it in global_cse nodes since we can't
+        * determine a nodes block there and therefore can't remove all code
+        * in unreachable blocks */
+       set_irg_state(irg, IR_GRAPH_STATE_BAD_BLOCK);
+       irg_block_walk_graph(irg, NULL, kill_dead_blocks, NULL);
 
        /* invalidate info */
        set_irg_outs_inconsistent(irg);
@@ -209,9 +213,8 @@ int optimize_graph_df(ir_graph *irg)
 
        /* finish the wait queue */
        while (! pdeq_empty(waitq)) {
-               ir_node *n = pdeq_getl(waitq);
-               if (! is_Bad(n))
-                       opt_walker(n, waitq);
+               ir_node *n = (ir_node*)pdeq_getl(waitq);
+               opt_walker(n, waitq);
        }
 
        del_pdeq(waitq);
@@ -226,6 +229,8 @@ int optimize_graph_df(ir_graph *irg)
        end  = get_irg_end(irg);
        remove_End_Bads_and_doublets(end);
 
+       clear_irg_state(irg, IR_GRAPH_STATE_BAD_BLOCK);
+
        current_ir_graph = rem;
        return changed;
 }