9 #include "iroptimize.h"
16 #include "opt_manage.h"
18 static void deactivate_entity_usage(ir_graph *irg)
20 set_irg_entity_usage_state(irg, ir_entity_usage_not_computed);
23 static void nop(ir_graph *irg) {
27 void perform_irg_optimization(ir_graph *irg, optdesc_t *opt)
29 ir_graph_state_t new_irg_state;
30 ir_graph_state_t required = opt->requirements;
31 const bool dump = get_irp_optimization_dumps();
33 /* no bad block requires no unreachable code */
34 if (required & IR_GRAPH_STATE_NO_BAD_BLOCKS)
35 required |= IR_GRAPH_STATE_NO_UNREACHABLE_BLOCKS;
37 /** Some workarounds because information is currently duplicated */
38 // FIXME should not be necessary!
39 if (loopinfo_inconsistent == get_irg_loopinfo_state(irg))
40 clear_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_LOOPINFO);
41 if (ir_entity_usage_not_computed == get_irg_entity_usage_state(irg))
42 clear_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_ENTITY_USAGE);
44 /* assure that all requirements for the optimization are fulfilled */
45 #define PREPARE(st,func) if (st & (required ^ irg->state)) {func(irg); set_irg_state(irg,st);}
46 PREPARE(IR_GRAPH_STATE_ONE_RETURN, normalize_one_return)
47 PREPARE(IR_GRAPH_STATE_NO_CRITICAL_EDGES, remove_critical_cf_edges)
48 PREPARE(IR_GRAPH_STATE_NO_UNREACHABLE_BLOCKS, remove_unreachable_blocks)
49 PREPARE(IR_GRAPH_STATE_NO_BAD_BLOCKS, remove_bads)
50 PREPARE(IR_GRAPH_STATE_CONSISTENT_DOMINANCE, assure_doms)
51 PREPARE(IR_GRAPH_STATE_CONSISTENT_POSTDOMINANCE, assure_postdoms)
52 PREPARE(IR_GRAPH_STATE_CONSISTENT_OUT_EDGES, edges_assure)
53 PREPARE(IR_GRAPH_STATE_CONSISTENT_OUTS, assure_irg_outs)
54 PREPARE(IR_GRAPH_STATE_CONSISTENT_LOOPINFO, assure_cf_loop)
55 PREPARE(IR_GRAPH_STATE_CONSISTENT_ENTITY_USAGE, assure_irg_entity_usage_computed)
56 PREPARE(IR_GRAPH_STATE_VALID_EXTENDED_BLOCKS, compute_extbb)
58 /* now all the requirements for the optimization are fulfilled */
60 dump_ir_graph(irg, opt->name);
62 new_irg_state = opt->optimization(irg);
65 dump_ir_graph(irg, opt->name);
67 /* unless the optimization returned that some state is retained,
68 * we disable the corresponding irg state.
69 * Since we currently duplicate information, sometimes another func must be called too.
71 #define INVALIDATE(state,func) if (!(state & new_irg_state)) {clear_irg_state(irg,state); func(irg);}
72 INVALIDATE(IR_GRAPH_STATE_NO_CRITICAL_EDGES, nop)
73 INVALIDATE(IR_GRAPH_STATE_NO_UNREACHABLE_BLOCKS, nop)
74 INVALIDATE(IR_GRAPH_STATE_NO_BAD_BLOCKS, nop)
75 INVALIDATE(IR_GRAPH_STATE_ONE_RETURN, nop)
76 INVALIDATE(IR_GRAPH_STATE_CONSISTENT_DOMINANCE, nop)
77 INVALIDATE(IR_GRAPH_STATE_CONSISTENT_POSTDOMINANCE, nop)
78 INVALIDATE(IR_GRAPH_STATE_CONSISTENT_OUTS, nop)
79 INVALIDATE(IR_GRAPH_STATE_CONSISTENT_OUT_EDGES, edges_deactivate)
80 INVALIDATE(IR_GRAPH_STATE_CONSISTENT_LOOPINFO, set_irg_loopinfo_inconsistent)
81 INVALIDATE(IR_GRAPH_STATE_CONSISTENT_ENTITY_USAGE, deactivate_entity_usage)
82 INVALIDATE(IR_GRAPH_STATE_VALID_EXTENDED_BLOCKS, set_irg_extblk_inconsistent)
84 if (!(new_irg_state & IR_GRAPH_STATE_BROKEN_FOR_VERIFIER)) {
85 irg_verify(irg, VERIFY_ENFORCE_SSA);