X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Fcfopt.c;h=d01d1a76a3f1e1a14afd0f1cd2f5bf1c8f0b0e8f;hb=b7b24e372a1338ecd5eb26bdd285a8cbe7b1fec9;hp=e2a658a43d7b4b8538aea4b4524421a6fe80b72a;hpb=32ea6ea0320f551448bb66e534e3351977464d42;p=libfirm diff --git a/ir/opt/cfopt.c b/ir/opt/cfopt.c index e2a658a43..d01d1a76a 100644 --- a/ir/opt/cfopt.c +++ b/ir/opt/cfopt.c @@ -40,7 +40,7 @@ #include "irgwalk.h" #include "irgmod.h" #include "irdump.h" -#include "irvrfy.h" +#include "irverify.h" #include "iredges.h" #include "array_t.h" @@ -104,9 +104,10 @@ static int remove_senseless_conds(ir_node *bl) ir_node *cond_j = skip_Proj(pred_j); if (cond_j == cond_i) { - ir_node *jmp = new_r_Jmp(get_nodes_block(cond_i)); + ir_graph *irg = get_irn_irg(bl); + ir_node *jmp = new_r_Jmp(get_nodes_block(cond_i)); set_irn_n(bl, i, jmp); - set_irn_n(bl, j, new_Bad()); + set_irn_n(bl, j, new_r_Bad(irg)); DBG_OPT_IFSIM2(cond_i, jmp); changed = 1; @@ -119,7 +120,7 @@ static int remove_senseless_conds(ir_node *bl) } /** An environment for merge_blocks and collect nodes. */ -typedef struct _merge_env { +typedef struct merge_env { int changed; /**< Set if the graph was changed. */ int phis_moved; /**< Set if Phi nodes were moved. */ plist_t *list; /**< Helper list for all found Switch Conds. */ @@ -136,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); @@ -171,9 +172,6 @@ static void merge_blocks(ir_node *node, void *ctx) promote it directly below. Nevertheless, we sometimes reach a block the first time through a dataflow node. In this case we optimized the block as such and have to promote the Bad here. */ - assert((get_opt_control_flow_straightening() || - get_opt_control_flow_weak_simplification()) && - ("strange flag setting")); exchange(b, new_block); env->changed = 1; b = new_block; @@ -181,10 +179,11 @@ 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)) { - exchange(node, new_Bad()); + ir_graph *irg = get_irn_irg(node); + exchange(node, new_r_Bad(irg)); env->changed = 1; } } @@ -204,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. */ @@ -216,8 +215,9 @@ static void remove_unreachable_blocks_and_conds(ir_node *block, void *env) ir_node *pred_bl = get_nodes_block(skip_Proj(skipped)); if (is_Block_dead(pred_bl) || (get_Block_dom_depth(pred_bl) < 0)) { + ir_graph *irg = get_irn_irg(block); set_Block_dead(pred_bl); - exchange(pred_X, new_Bad()); + exchange(pred_X, new_r_Bad(irg)); *changed = 1; } else if (skipped != pred_X) { set_Block_cfgpred(block, i, skipped); @@ -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 */ @@ -327,12 +327,6 @@ static int test_whether_dispensable(ir_node *b, int pos) return 0; if (is_Block_removable(pred)) { - if (!get_opt_optimize() || !get_opt_control_flow_strong_simplification()) { - /* Mark block so that is will not be removed: optimization is turned off. */ - set_Block_non_removable(pred); - return 1; - } - /* Seems to be empty. At least we detected this in collect_nodes. */ if (get_irn_link(b) == NULL) { /* There are no Phi nodes ==> all predecessors are dispensable. */ @@ -422,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. */ @@ -433,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; @@ -489,15 +483,16 @@ 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)); if (get_Block_idom(b) != predb) { /* predb is not the dominator. There can't be uses of pred's Phi nodes, kill them .*/ - exchange(phi, new_Bad()); + ir_graph *irg = get_irn_irg(b); + exchange(phi, new_r_Bad(irg)); } else { /* predb is the direct dominator of b. There might be uses of the Phi nodes from predb in further block, so move this phi from the predecessor into the block b */ @@ -581,7 +576,7 @@ static void optimize_blocks(ir_node *b, void *ctx) in[n_preds++] = pred_X; } /* Remove block as it might be kept alive. */ - exchange(pred, b/*new_Bad()*/); + exchange(pred, b/*new_r_Bad(irg)*/); } else { /* case 3: */ in[n_preds++] = get_Block_cfgpred(b, i); @@ -602,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); @@ -627,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); @@ -643,19 +638,20 @@ 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 */ - long num = get_tarval_long(tv); - long def_num = get_Cond_default_proj(cond); + long num = get_tarval_long(tv); + long def_num = get_Cond_default_proj(cond); + ir_graph *irg = get_irn_irg(cond); if (def_num == get_Proj_proj(proj1)) { /* first one is the defProj */ if (num == get_Proj_proj(proj2)) { jmp = new_r_Jmp(blk); exchange(proj2, jmp); - exchange(proj1, new_Bad()); + exchange(proj1, new_r_Bad(irg)); return 1; } } else if (def_num == get_Proj_proj(proj2)) { @@ -663,7 +659,7 @@ static int handle_switch_cond(ir_node *cond) if (num == get_Proj_proj(proj1)) { jmp = new_r_Jmp(blk); exchange(proj1, jmp); - exchange(proj2, new_Bad()); + exchange(proj2, new_r_Bad(irg)); return 1; } } else { @@ -671,12 +667,12 @@ static int handle_switch_cond(ir_node *cond) if (num == get_Proj_proj(proj1)) { jmp = new_r_Jmp(blk); exchange(proj1, jmp); - exchange(proj2, new_Bad()); + exchange(proj2, new_r_Bad(irg)); return 1; } else if (num == get_Proj_proj(proj2)) { jmp = new_r_Jmp(blk); exchange(proj2, jmp); - exchange(proj1, new_Bad()); + exchange(proj1, new_r_Bad(irg)); return 1; } } @@ -706,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; @@ -716,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); @@ -740,7 +733,7 @@ restart: if (is_Block(ka)) { /* do NOT keep dead blocks */ if (is_Block_dead(ka) || get_Block_dom_depth(ka) < 0) { - set_End_keepalive(end, i, new_Bad()); + set_End_keepalive(end, i, new_r_Bad(irg)); changed = 1; } } else { @@ -748,7 +741,7 @@ restart: if (is_Bad(block) || is_Block_dead(block) || get_Block_dom_depth(block) < 0) { /* do NOT keep nodes in dead blocks */ - set_End_keepalive(end, i, new_Bad()); + set_End_keepalive(end, i, new_r_Bad(irg)); changed = 1; } } @@ -774,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); @@ -802,7 +795,7 @@ restart: if (is_Block(ka)) { /* do NOT keep dead blocks */ if (is_Block_dead(ka) || get_Block_dom_depth(ka) < 0) { - set_End_keepalive(end, i, new_Bad()); + set_End_keepalive(end, i, new_r_Bad(irg)); changed = 1; } } else { @@ -810,7 +803,7 @@ restart: if (is_Bad(block) || is_Block_dead(block) || get_Block_dom_depth(block) < 0) { /* do NOT keep nodes in dead blocks */ - set_End_keepalive(end, i, new_Bad()); + set_End_keepalive(end, i, new_r_Bad(irg)); changed = 1; } } @@ -875,14 +868,11 @@ restart: /* the verifier doesn't work yet with floating nodes */ if (get_irg_pinned(irg) == op_pin_state_pinned) { /* after optimize_cf(), only Bad data flow may remain. */ - if (irg_vrfy_bads(irg, BAD_DF | BAD_BLOCK | TUPLE)) { - dump_ir_block_graph(irg, "-vrfy-cf"); - dump_ir_graph(irg, "-vrfy-cf"); - fprintf(stderr, "VRFY_BAD in optimize_cf()\n"); + if (irg_verify_bads(irg, BAD_DF | BAD_BLOCK | TUPLE)) { + dump_ir_graph(irg, "-verify-cf"); + fprintf(stderr, "VERIFY_BAD in optimize_cf()\n"); } } - - current_ir_graph = rem; } /* Creates an ir_graph pass for optimize_cf. */