- int i;
- ir_graph *irg;
- unsigned aa_opt;
-
- /* FIXME: cloning might ADD new graphs. */
- irg_dump_no = calloc(get_irp_last_idx(), sizeof(*irg_dump_no));
-
- set_opt_strength_red(firm_opt.strength_red);
- set_opt_scalar_replacement(firm_opt.scalar_replace);
- set_opt_auto_create_sync(firm_opt.auto_sync);
- set_opt_alias_analysis(firm_opt.alias_analysis);
-
- aa_opt = aa_opt_no_opt;
- if (firm_opt.strict_alias)
- aa_opt |= aa_opt_type_based | aa_opt_byte_type_may_alias;
- if (firm_opt.no_alias)
- aa_opt = aa_opt_no_alias;
-
- set_irp_memory_disambiguator_options(aa_opt);
-
- timer_start(TV_ALL_OPT);
-
- if (firm_opt.remove_unused) {
- ir_entity **keep_methods;
- int arr_len;
-
- /* Analysis that finds the free methods,
- i.e. methods that are dereferenced.
- Optimizes polymorphic calls :-). */
- cgana(&arr_len, &keep_methods);
-
- /* Remove methods that are never called. */
- gc_irgs(arr_len, keep_methods);
-
- free(keep_methods);
- }
-
- if (! firm_opt.freestanding) {
- rts_map();
- DUMP_ALL_C(firm_dump.ir_graph && firm_dump.all_phases, "rts");
- CHECK_ALL(firm_opt.check_all);
- }
-
- /* first step: kill dead code */
- for (i = 0; i < get_irp_n_irgs(); i++) {
- irg = current_ir_graph = get_irp_irg(i);
- /* Confirm construction currently can only handle blocks with only one control
- flow predecessor. Calling optimize_cf here removes Bad predecessors and help
- the optimization of switch constructs. */
- timer_push(TV_CF_OPT);
- optimize_graph_df(irg);
- optimize_cf(irg);
- timer_pop();
- }
-
- if (firm_opt.func_calls) {
- timer_push(TV_REAL_FUNC_CALL);
- optimize_funccalls(firm_const_exists, NULL);
- timer_pop();
- DUMP_ALL_C(firm_dump.ir_graph && firm_dump.all_phases, "func_call");
- CHECK_ALL(firm_opt.check_all);
- }
-
- /* do lowering on the const code irg */
- lower_const_code();
-
- for (i = 0; i < get_irp_n_irgs(); i++) {
- irg = current_ir_graph = get_irp_irg(i);
-
-#ifdef FIRM_EXT_GRS
- /* If SIMD optimization is on, make sure we have only 1 return */
- if (firm_ext_grs.create_pattern || firm_ext_grs.simd_opt)
- normalize_one_return(irg);
-#endif
-
-
-#if 0
- if (firm_opt.modes) {
- /* convert all modes into integer if possible */
- arch_mode_conversion(irg, predefs.mode_uint);
- }
-#endif
- timer_push(TV_SCALAR_REPLACE);
- scalar_replacement_opt(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "scalar");
- CHECK_ONE(firm_opt.check_all, irg);
-
- timer_push(TV_LOCAL_OPT);
- optimize_graph_df(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "lopt");
- CHECK_ONE(firm_opt.check_all, irg);
-
- timer_push(TV_REASSOCIATION);
- optimize_reassociation(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "reassoc");
- CHECK_ONE(firm_opt.check_all, irg);
-
- compute_doms(irg);
- CHECK_ONE(firm_opt.check_all, irg);
-
- if (firm_opt.gcse) {
- timer_push(TV_CODE_PLACE);
- set_opt_global_cse(1);
- optimize_graph_df(irg);
- place_code(irg);
- set_opt_global_cse(0);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "place");
- CHECK_ONE(firm_opt.check_all, irg);
- }
-
- if (firm_opt.confirm) {
- /* Confirm construction currently can only handle blocks with only one control
- flow predecessor. Calling optimize_cf here removes Bad predecessors and help
- the optimization of switch constructs. */
- timer_push(TV_CF_OPT);
- optimize_cf(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "cfopt");
- CHECK_ONE(firm_opt.check_all, irg);
- timer_push(TV_CONFIRM_CREATE);
- construct_confirms(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "confirms");
- CHECK_ONE(firm_opt.check_all, irg);
-
- timer_push(TV_LOCAL_OPT);
- optimize_graph_df(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "lopt");
- CHECK_ONE(firm_opt.check_all, irg);
- }
-
- if (firm_opt.luffig) {
- opt_ldst2(irg);
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "ldst2");
- CHECK_ONE(firm_opt.check_all, irg);
- }
-
- timer_push(TV_CF_OPT);
- optimize_cf(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "cfopt");
- CHECK_ONE(firm_opt.check_all, irg);
-
- if (firm_opt.load_store) {
- timer_push(TV_LOAD_STORE);
- optimize_load_store(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "ldst");
- CHECK_ONE(firm_opt.check_all, irg);
- }
-
- lower_highlevel_graph(irg, firm_opt.lower_bitfields);
-
- if (firm_opt.deconv) {
- timer_push(TV_DECONV);
- conv_opt(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "deconv");
- CHECK_ONE(firm_opt.check_all, irg);
- }
-
- if (firm_opt.cond_eval) {
- timer_push(TV_COND_EVAL);
- opt_cond_eval(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "cond_eval");
- CHECK_ONE(firm_opt.check_all, irg);
- }
-
- /* should we really remove the Confirm here? */
- if (firm_opt.confirm) {
- timer_push(TV_CONFIRM_CREATE);
- remove_confirms(irg);
- timer_pop();
- }
-
- if (firm_opt.gvn_pre) {
- do_gvn_pre(irg);
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "pre");
- CHECK_ONE(firm_opt.check_all, irg);
- irg_verify(irg, VRFY_ENFORCE_SSA);
- }
-
- if (! firm_opt.gcse) {
- timer_push(TV_CODE_PLACE);
- optimize_graph_df(irg);
- place_code(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "place");
- CHECK_ONE(firm_opt.check_all, irg);
- }
-
- compute_doms(irg);
- compute_postdoms(irg);
- DUMP_ONE_CFG_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "dom");
- CHECK_ONE(firm_opt.check_all, irg);
-
- construct_backedges(irg);
-
- timer_push(TV_CF_OPT);
- optimize_cf(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "cfopt");
- CHECK_ONE(firm_opt.check_all, irg);
-
- if (firm_opt.if_conversion) {
- timer_push(TV_IF_CONV);
- opt_if_conv(current_ir_graph, if_conv_info);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "if");
- CHECK_ONE(firm_opt.check_all, current_ir_graph);
-
- timer_push(TV_LOCAL_OPT);
- optimize_graph_df(current_ir_graph);
- timer_pop();
- timer_push(TV_CF_OPT);
- optimize_cf(current_ir_graph);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "after_if");
- CHECK_ONE(firm_opt.check_all, current_ir_graph);
- }
-
- if (firm_opt.bool_opt) {
- opt_bool(irg);
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "bool");
- CHECK_ONE(firm_opt.check_all, irg);
- }
-
- timer_push(TV_OSR);
- opt_osr(current_ir_graph, osr_flag_default | osr_flag_keep_reg_pressure | osr_flag_ignore_x86_shift);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "stred");
- CHECK_ONE(firm_opt.check_all, irg);
-
- timer_push(TV_LOCAL_OPT);
- optimize_graph_df(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "lopt");
- CHECK_ONE(firm_opt.check_all, irg);
-
- edges_deactivate(irg);
- timer_push(TV_DEAD_NODE);
- dead_node_elimination(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "dead");
- CHECK_ONE(firm_opt.check_all, irg);
- }
-
- if (firm_opt.do_inline) {
- inline_functions(500, 50);
- DUMP_ALL_C(firm_dump.ir_graph && firm_dump.all_phases, "inl");
- CHECK_ALL(firm_opt.check_all);
- }
- if (firm_opt.cloning) {
- proc_cloning((float)firm_opt.clone_threshold);
- DUMP_ALL_C(firm_dump.ir_graph && firm_dump.all_phases, "clone");
- CHECK_ALL(firm_opt.check_all);
- }
- if (firm_opt.tail_rec) {
- timer_push(TV_TAIL_REC);
- opt_tail_recursion();
- timer_pop();
-
- DUMP_ALL_C(firm_dump.ir_graph && firm_dump.all_phases, "tail_rec");
- CHECK_ALL(firm_opt.check_all);
- }
-
- if (firm_opt.cond_eval) {
- for (i = 0; i < get_irp_n_irgs(); i++) {
- irg = get_irp_irg(i);
- timer_push(TV_COND_EVAL);
- opt_cond_eval(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "cond_eval");
- CHECK_ONE(firm_opt.check_all, irg);
- }
- }
-
- /* final run of local optimizations */
- for (i = 0; i < get_irp_n_irgs(); i++) {
- irg = get_irp_irg(i);
- timer_push(TV_LOCAL_OPT);
- optimize_graph_df(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "local_opt");
- CHECK_ONE(firm_opt.check_all, irg);
-
- timer_push(TV_CF_OPT);
- optimize_cf(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "cfopt");
- CHECK_ONE(firm_opt.check_all, irg);
- }
-
- if (firm_dump.ir_graph) {
- /* recompute backedges for nicer dumps */
- for (i = 0; i < get_irp_n_irgs(); i++)
- construct_cf_backedges(get_irp_irg(i));
- }
-
- if (firm_opt.remove_unused) {
- ir_entity **keep_methods;
- int arr_len;
-
- /* Analysis that finds the free methods,
- i.e. methods that are dereferenced.
- Optimizes polymorphic calls :-). */
- cgana(&arr_len, &keep_methods);
-
- /* Remove methods that are never called. */
- gc_irgs(arr_len, keep_methods);
-
- free(keep_methods);
- }
-
-
- DUMP_ALL(firm_dump.ir_graph, "-opt");
-
- /* verify optimized graphs */
- for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
- ir_graph *irg = get_irp_irg(i);
- irg_verify(irg, VRFY_ENFORCE_SSA);
- }
-
- if (firm_dump.statistic & STAT_AFTER_OPT)
- stat_dump_snapshot(input_filename, "opt");
-
- timer_stop(TV_ALL_OPT);
-} /* do_firm_optimizations */