Switch irg index to type size_t, making the API more consistent.
[libfirm] / ir / opt / cfopt.c
index 90780f4..d01d1a7 100644 (file)
@@ -137,7 +137,7 @@ static void merge_blocks(ir_node *node, void *ctx)
 {
        int i;
        ir_node *new_block;
-       merge_env *env = ctx;
+       merge_env *env = (merge_env*)ctx;
 
        /* clear the link field for ALL nodes first */
        set_irn_link(node, NULL);
@@ -179,7 +179,7 @@ static void merge_blocks(ir_node *node, void *ctx)
                        }
 
                        /* normally, we would create a Bad block here, but this must be
-                        * prevented, so just set it's cf to Bad.
+                        * prevented, so just set its cf to Bad.
                         */
                        if (is_Block_dead(new_block)) {
                                ir_graph *irg = get_irn_irg(node);
@@ -203,7 +203,7 @@ static void merge_blocks(ir_node *node, void *ctx)
 static void remove_unreachable_blocks_and_conds(ir_node *block, void *env)
 {
        int i;
-       int *changed = env;
+       int *changed = (int*)env;
 
        /* Check block predecessors and turn control flow into bad.
           Beware of Tuple, kill them. */
@@ -244,8 +244,8 @@ static void remove_unreachable_blocks_and_conds(ir_node *block, void *env)
  */
 static void collect_nodes(ir_node *n, void *ctx)
 {
-       ir_opcode code = get_irn_opcode(n);
-       merge_env *env ctx;
+       unsigned   code = get_irn_opcode(n);
+       merge_env *env  = (merge_env*)ctx;
 
        if (code == iro_Block) {
                /* mark the block as non-removable if it is labeled */
@@ -416,7 +416,7 @@ static void optimize_blocks(ir_node *b, void *ctx)
        int i, j, k, n, max_preds, n_preds, p_preds = -1;
        ir_node *pred, *phi, *next;
        ir_node **in;
-       merge_env *env = ctx;
+       merge_env *env = (merge_env*)ctx;
 
        /* Count the number of predecessor if this block is merged with pred blocks
           that are empty. */
@@ -427,9 +427,9 @@ static void optimize_blocks(ir_node *b, void *ctx)
        in = XMALLOCN(ir_node*, max_preds);
 
        /*- Fix the Phi nodes of the current block -*/
-       for (phi = get_irn_link(b); phi != NULL; phi = next) {
+       for (phi = (ir_node*)get_irn_link(b); phi != NULL; phi = (ir_node*)next) {
                assert(is_Phi(phi));
-               next = get_irn_link(phi);
+               next = (ir_node*)get_irn_link(phi);
 
                /* Find the new predecessors for the Phi */
                p_preds = 0;
@@ -483,9 +483,9 @@ static void optimize_blocks(ir_node *b, void *ctx)
                        ir_node *next_phi;
 
                        /* we found a predecessor block at position k that will be removed */
-                       for (phi = get_irn_link(predb); phi; phi = next_phi) {
+                       for (phi = (ir_node*)get_irn_link(predb); phi; phi = next_phi) {
                                int q_preds = 0;
-                               next_phi = get_irn_link(phi);
+                               next_phi = (ir_node*)get_irn_link(phi);
 
                                assert(is_Phi(phi));
 
@@ -597,8 +597,8 @@ static void optimize_blocks(ir_node *b, void *ctx)
  */
 static void remove_simple_blocks(ir_node *block, void *ctx)
 {
-       ir_node *new_blk = equivalent_node(block);
-       merge_env *env = ctx;
+       merge_env *env = (merge_env*)ctx;
+       ir_node   *new_blk = equivalent_node(block);
 
        if (new_blk != block) {
                exchange(block, new_blk);
@@ -622,8 +622,8 @@ static int handle_switch_cond(ir_node *cond)
 {
        ir_node *sel = get_Cond_selector(cond);
 
-       ir_node *proj1 = get_irn_link(cond);
-       ir_node *proj2 = get_irn_link(proj1);
+       ir_node *proj1 = (ir_node*)get_irn_link(cond);
+       ir_node *proj2 = (ir_node*)get_irn_link(proj1);
        ir_node *jmp, *blk;
 
        blk = get_nodes_block(cond);
@@ -638,7 +638,7 @@ static int handle_switch_cond(ir_node *cond)
        } else if (get_irn_link(proj2) == NULL) {
                /* We have two Proj's here. Check if the Cond has
                   a constant argument */
-               tarval *tv = value_of(sel);
+               ir_tarval *tv = value_of(sel);
 
                if (tv != tarval_bad) {
                        /* we have a constant switch */
@@ -702,7 +702,6 @@ void optimize_cf(ir_graph *irg)
        int i, j, n, changed;
        ir_node **in = NULL;
        ir_node *cond, *end = get_irg_end(irg);
-       ir_graph *rem = current_ir_graph;
        plist_element_t *el;
        merge_env env;
 
@@ -712,8 +711,6 @@ void optimize_cf(ir_graph *irg)
        assert(get_irg_pinned(irg) != op_pin_state_floats &&
               "Control flow optimization need a pinned graph");
 
-       current_ir_graph = irg;
-
        /* FIXME: control flow opt destroys block edges. So edges are deactivated here. Fix the edges! */
        edges_deactivate(irg);
 
@@ -770,7 +767,7 @@ restart:
 
        /* handle all collected switch-Conds */
        foreach_plist(env.list, el) {
-               cond = plist_element_get_value(el);
+               cond = (ir_node*)plist_element_get_value(el);
                env.changed |= handle_switch_cond(cond);
        }
        plist_free(env.list);
@@ -876,8 +873,6 @@ restart:
                        fprintf(stderr, "VERIFY_BAD in optimize_cf()\n");
                }
        }
-
-       current_ir_graph = rem;
 }
 
 /* Creates an ir_graph pass for optimize_cf. */