X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Fcfopt.c;h=7ca15daa4f252f72d955a3238e06d6449de4a5e1;hb=6be797281b157f8f71b9c47d28b3d09f2a7918cc;hp=278fbe3b6bea06eaa6a5c3273bfec4f2d5d8c31f;hpb=183c08a8d00578cfc700cdd0d8387b920a5996da;p=libfirm diff --git a/ir/opt/cfopt.c b/ir/opt/cfopt.c index 278fbe3b6..7ca15daa4 100644 --- a/ir/opt/cfopt.c +++ b/ir/opt/cfopt.c @@ -46,7 +46,6 @@ #include "irdump.h" #include "irverify.h" #include "iredges.h" -#include "opt_manage.h" #include "array_t.h" @@ -239,8 +238,10 @@ non_dispensable: * has only one predecessor with an unconditional jump to this block; * and if this block does not contain any phis. */ -static void merge_blocks(ir_node *b) +static void merge_blocks(ir_node *b, void *env) { + (void) env; + if (get_Block_n_cfgpreds(b) == 1) { ir_node* pred = get_Block_cfgpred(b, 0); if (is_Jmp(pred)) { @@ -571,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)); } @@ -807,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; } } @@ -821,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; @@ -832,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); @@ -847,27 +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_VALID_EXTENDED_BLOCKS - | 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 @@ -875,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); @@ -927,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. */