ia32: Do not ignore the floating point control word anymore and make it callee-save.
[libfirm] / ir / opt / cfopt.c
index 07a3703..7ca15da 100644 (file)
@@ -46,7 +46,6 @@
 #include "irdump.h"
 #include "irverify.h"
 #include "iredges.h"
-#include "opt_manage.h"
 
 #include "array_t.h"
 
@@ -573,13 +572,13 @@ typedef enum block_flags_t {
 static bool get_block_flag(const ir_nodehashmap_t *infos, const ir_node *block,
                            int flag)
 {
-       return PTR_TO_INT(ir_nodehashmap_get(infos, block)) & flag;
+       return PTR_TO_INT(ir_nodehashmap_get(void, infos, block)) & flag;
 }
 
 static void set_block_flag(ir_nodehashmap_t *infos, ir_node *block,
                            block_flags_t flag)
 {
-       int data = PTR_TO_INT(ir_nodehashmap_get(infos, block));
+       int data = PTR_TO_INT(ir_nodehashmap_get(void, infos, block));
        data |= flag;
        ir_nodehashmap_insert(infos, block, INT_TO_PTR(data));
 }
@@ -809,12 +808,13 @@ static void cfgopt_ignoring_phis(ir_graph *irg)
                irg_block_walk_graph(irg, NULL, optimize_ifs, &env);
 
                if (env.changed) {
-                       clear_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_DOMINANCE);
+                       confirm_irg_properties(irg, IR_GRAPH_PROPERTIES_NONE);
                        /* clear block info, because it must be recomputed */
                        irg_block_walk_graph(irg, clear_block_info, NULL, &env.block_infos);
                        /* Removing blocks and Conds might enable more optimizations */
                        continue;
                } else {
+                       confirm_irg_properties(irg, IR_GRAPH_PROPERTIES_ALL);
                        break;
                }
        }
@@ -823,7 +823,7 @@ static void cfgopt_ignoring_phis(ir_graph *irg)
 }
 
 /* Optimizations of the control flow that also require changes of Phi nodes.  */
-static ir_graph_state_t do_cfopt(ir_graph *irg)
+void optimize_cf(ir_graph *irg)
 {
        int i, j, n;
        ir_node **in = NULL;
@@ -834,13 +834,11 @@ static ir_graph_state_t do_cfopt(ir_graph *irg)
        env.changed    = false;
        env.phis_moved = false;
 
-       assert(get_irg_phase_state(irg) != phase_building);
-
        /* if the graph is not pinned, we cannot determine empty blocks */
        assert(get_irg_pinned(irg) != op_pin_state_floats &&
               "Control flow optimization need a pinned graph");
 
-       edges_deactivate(irg);
+       assure_irg_properties(irg, IR_GRAPH_PROPERTY_NO_UNREACHABLE_CODE);
 
        /* First the "simple" optimizations, which do not touch Phis */
        cfgopt_ignoring_phis(irg);
@@ -849,26 +847,13 @@ static ir_graph_state_t do_cfopt(ir_graph *irg)
        ir_reserve_resources(irg, IR_RESOURCE_BLOCK_MARK | IR_RESOURCE_IRN_LINK
                             | IR_RESOURCE_PHI_LIST);
 
-       /* The switch Cond optimization might expose unreachable code, so we loop */
-       for (;;) {
-               bool changed = false;
-
-               assure_doms(irg);
-
-               /*
-                * This pass collects all Phi nodes in a link list in the block
-                * nodes.  Further it performs simple control flow optimizations.
-                * Finally it marks all blocks that do not contain useful
-                * computations, i.e., these blocks might be removed.
-                */
-               irg_walk(end, clear_link_and_mark_blocks_removable, collect_nodes, NULL);
-
-               if (!changed)
-                       break;
-
-               clear_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_DOMINANCE
-                                  | IR_GRAPH_STATE_CONSISTENT_ENTITY_USAGE);
-       }
+       /*
+        * This pass collects all Phi nodes in a link list in the block
+        * nodes.  Further it performs simple control flow optimizations.
+        * Finally it marks all blocks that do not contain useful
+        * computations, i.e., these blocks might be removed.
+        */
+       irg_walk(end, clear_link_and_mark_blocks_removable, collect_nodes, NULL);
 
        /* assert due to collect_nodes:
         * 1. removable blocks are now marked as such
@@ -876,10 +861,10 @@ static ir_graph_state_t do_cfopt(ir_graph *irg)
         */
 
        /* Optimize the standard code.
-        * It walks only over block nodes and adapts these and the Phi nodes in these
-        * blocks, which it finds in a linked list computed before.
-        * */
-       assure_doms(irg);
+        * It walks only over block nodes and adapts these and the Phi nodes in
+        * these blocks, which it finds in a linked list computed before.
+        */
+       assure_irg_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE);
        irg_block_walk_graph(irg, optimize_blocks, merge_blocks, &env);
 
        new_end = optimize_in_place(end);
@@ -928,18 +913,8 @@ static ir_graph_state_t do_cfopt(ir_graph *irg)
                }
        }
 
-       return 0;
-}
-
-static optdesc_t opt_cf = {
-       "control-flow",
-       IR_GRAPH_STATE_NO_UNREACHABLE_CODE,
-       do_cfopt,
-};
-
-void optimize_cf(ir_graph *irg)
-{
-       perform_irg_optimization(irg, &opt_cf);
+       confirm_irg_properties(irg,
+               env.changed ? IR_GRAPH_PROPERTIES_NONE : IR_GRAPH_PROPERTIES_ALL);
 }
 
 /* Creates an ir_graph pass for optimize_cf. */