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