X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=driver%2Ffirm_opt.c;h=8d3d3fa2ec30f4f859043252632aa39a44fcd1fa;hb=ed07e4be99cb6911f67a3de7d9034b375c7e9886;hp=5844b1d1890ddef1a5274a953eb4fbd443a0bc52;hpb=d9f918c846087ee7fc1b97e83671181c1ecf2fff;p=cparser diff --git a/driver/firm_opt.c b/driver/firm_opt.c index 5844b1d..8d3d3fa 100644 --- a/driver/firm_opt.c +++ b/driver/firm_opt.c @@ -20,6 +20,10 @@ #include "firm_cmdline.h" #include "firm_timing.h" +#ifdef _WIN32 +#define snprintf _snprintf +#endif + #if defined(_DEBUG) || defined(FIRM_DEBUG) #define DBG(x) dbg_printf x #else @@ -56,10 +60,10 @@ #define CHECK_ALL(cond) \ do { \ if (cond) { \ - int i; \ + int ii; \ timer_push(TV_VERIFY); \ - for (i = get_irp_n_irgs() - 1; i >= 0; --i) \ - irg_verify(get_irp_irg(i), VRFY_ENFORCE_SSA); \ + for (ii = get_irp_n_irgs() - 1; ii >= 0; --ii) \ + irg_verify(get_irp_irg(ii), VRFY_ENFORCE_SSA); \ timer_pop(); \ } \ } while (0) @@ -107,7 +111,6 @@ static const ir_settings_arch_dep_t *ad_param = NULL; static create_intrinsic_fkt *arch_create_intrinsic = NULL; static void *create_intrinsic_ctx = NULL; static const ir_settings_if_conv_t *if_conv_info = NULL; -static unsigned char be_support_inline_asm = FALSE; /* entities of runtime functions */ ir_entity_ptr rts_entities[rts_max]; @@ -285,11 +288,11 @@ static void dump_all_count(const char *const suffix) */ static void do_firm_optimizations(const char *input_filename, int firm_const_exists) { - ir_entity **keep_methods; - int i, arr_len; + 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); @@ -308,6 +311,9 @@ static void do_firm_optimizations(const char *input_filename, int firm_const_exi 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 :-). */ @@ -325,35 +331,32 @@ static void do_firm_optimizations(const char *input_filename, int firm_const_exi CHECK_ALL(firm_opt.check_all); } - if (firm_opt.tail_rec) { - timer_push(TV_TAIL_REC); - opt_tail_recursion(); + /* 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(); - - DUMP_ALL_C(firm_dump.ir_graph && firm_dump.all_phases, "tail_rec"); - CHECK_ALL(firm_opt.check_all); } if (firm_opt.func_calls) { timer_push(TV_REAL_FUNC_CALL); - optimize_funccalls(firm_const_exists); + 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); } - if (firm_opt.do_inline) { - timer_push(TV_INLINE); - inline_leave_functions(500, 80, 30, FALSE); - timer_pop(); - DUMP_ALL_C(firm_dump.ir_graph && firm_dump.all_phases, "inl"); - 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) @@ -424,6 +427,7 @@ static void do_firm_optimizations(const char *input_filename, int firm_const_exi 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); @@ -447,14 +451,6 @@ static void do_firm_optimizations(const char *input_filename, int firm_const_exi irg_verify(irg, VRFY_ENFORCE_SSA); } - if (firm_opt.loop_unrolling) { - timer_push(TV_LOOP_UNROLL); - optimize_loop_unrolling(irg); - timer_pop(); - DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "loop"); - CHECK_ONE(firm_opt.check_all, irg); - } - if (firm_opt.load_store) { timer_push(TV_LOAD_STORE); optimize_load_store(irg); @@ -463,7 +459,7 @@ static void do_firm_optimizations(const char *input_filename, int firm_const_exi CHECK_ONE(firm_opt.check_all, irg); } - lower_highlevel_graph(irg); + lower_highlevel_graph(irg, firm_opt.lower_bitfields); if (firm_opt.deconv) { timer_push(TV_DECONV); @@ -518,7 +514,7 @@ static void do_firm_optimizations(const char *input_filename, int firm_const_exi } timer_push(TV_OSR); - opt_osr(current_ir_graph, osr_flag_default /*| osr_flag_ignore_x86_shift*/); + 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); @@ -537,9 +533,23 @@ static void do_firm_optimizations(const char *input_filename, int firm_const_exi 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_dump.ir_graph) { @@ -567,8 +577,10 @@ static void do_firm_optimizations(const char *input_filename, int firm_const_exi DUMP_ALL(firm_dump.ir_graph, "-opt"); /* verify optimized graphs */ - for (i = get_irp_n_irgs() - 1; i >= 0; --i) - irg_verify(get_irp_irg(i), VRFY_ENFORCE_SSA); + 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"); @@ -664,6 +676,7 @@ static int compute_type_size(ir_type *ty) ir_node *upper = get_array_upper_bound(ty, i); ir_graph *rem = current_ir_graph; tarval *tv_lower, *tv_upper; + long val_lower, val_upper; current_ir_graph = get_const_code_irg(); local_optimize_node(lower); @@ -682,7 +695,9 @@ static int compute_type_size(ir_type *ty) return 0; } - size *= get_tarval_long(tv_upper) - get_tarval_long(tv_lower); + val_upper = get_tarval_long(tv_upper); + val_lower = get_tarval_long(tv_lower); + size *= val_upper - val_lower; } restore_optimization_state(&state); @@ -708,24 +723,14 @@ static int compute_type_size(ir_type *ty) } /* compute_type_size */ /** - * layout all types of the Firm graph + * layout all non-frame types of the Firm graph */ static void compute_type_sizes(void) { int i; ir_type *tp; - ir_graph *irg; - /* all frame types */ - for (i = get_irp_n_irgs() - 1; i >= 0; --i) { - irg = get_irp_irg(i); - /* do not optimize away variables in debug mode */ - if (firm_opt.debug_mode == DBG_MODE_NONE) - opt_frame_irg(irg); - compute_type_size(get_irg_frame_type(irg)); - } - - /* all other types */ + /* all non-frame other types */ for (i = get_irp_n_types() - 1; i >= 0; --i) { tp = get_irp_type(i); compute_type_size(tp); @@ -741,6 +746,24 @@ static void compute_type_sizes(void) } } /* compute_type_sizes */ +/** + * layout all frame-types of the Firm graph + */ +static void compute_frame_type_sizes(void) +{ + int i; + ir_graph *irg; + + /* all frame types */ + for (i = get_irp_n_irgs() - 1; i >= 0; --i) { + irg = get_irp_irg(i); + /* do not optimize away variables in debug mode */ + if (firm_opt.debug_mode == DBG_MODE_NONE) + opt_frame_irg(irg); + compute_type_size(get_irg_frame_type(irg)); + } +} /* compute_frame_type_sizes */ + /** * do Firm lowering * @@ -776,7 +799,6 @@ static void do_firm_lowering(const char *input_filename) } timer_push(TV_DW_LOWER); lower_dw_ops(&init); - DUMP_ALL(firm_dump.ir_graph, "-dw"); timer_pop(); } @@ -828,7 +850,6 @@ static void do_firm_lowering(const char *input_filename) CHECK_ONE(firm_opt.check_all, current_ir_graph); } -// set_opt_global_cse(0); timer_push(TV_LOAD_STORE); optimize_load_store(current_ir_graph); timer_pop(); @@ -914,9 +935,7 @@ void gen_firm_init(void) if (firm_be_opt.selection == BE_FIRM_BE) { const backend_params *be_params = be_init(); - be_support_inline_asm = be_params->support_inline_asm; - - firm_opt.lower_ll = be_params->do_dw_lowering; + firm_opt.lower_ll = (a_byte) be_params->do_dw_lowering; params.arch_op_settings = be_params->arch_op_settings; arch_create_intrinsic = be_params->arch_create_intrinsic_fkt; @@ -942,6 +961,9 @@ void gen_firm_init(void) set_opt_precise_exc_context(firm_opt.precise_exc); set_opt_fragile_ops(firm_opt.fragile_ops); + /* Sel node cannot produce NULL pointers */ + set_opt_sel_based_null_check_elim(1); + /* dynamic dispatch works currently only if whole world scenarios */ set_opt_dyn_meth_dispatch(0); @@ -950,7 +972,7 @@ void gen_firm_init(void) /* do not run architecture dependent optimizations in building phase */ arch_dep_set_opts(arch_dep_none); - do_node_verification(firm_opt.vrfy); + do_node_verification((firm_verification_t) firm_opt.vrfy); if (firm_dump.filter) only_dump_method_with_name(new_id_from_str(firm_dump.filter)); @@ -995,7 +1017,8 @@ void gen_firm_finish(FILE *out, const char *input_filename, int c_mode, int firm int i; /* the general for dumping option must be set, or the others will not work */ - firm_dump.ir_graph |= firm_dump.all_phases | firm_dump.extbb; + firm_dump.ir_graph + = (a_byte) (firm_dump.ir_graph | firm_dump.all_phases | firm_dump.extbb); dump_keepalive_edges(1); dump_consts_local(1); @@ -1039,6 +1062,12 @@ void gen_firm_finish(FILE *out, const char *input_filename, int c_mode, int firm /* computes the sizes of all types that are still not computed */ compute_type_sizes(); + /* lower copyb nodes */ + for (i = get_irp_n_irgs() - 1; i >= 0; --i) { + ir_graph *irg = get_irp_irg(i); + lower_CopyB(irg, 128, 4); + } + if (firm_dump.statistic & STAT_BEFORE_OPT) { stat_dump_snapshot(input_filename, "noopt"); } @@ -1056,6 +1085,9 @@ void gen_firm_finish(FILE *out, const char *input_filename, int c_mode, int firm if (firm_opt.lower) do_firm_lowering(input_filename); + /* computes the sizes of all frame types */ + compute_frame_type_sizes(); + /* set the phase to low */ for (i = get_irp_n_irgs() - 1; i >= 0; --i) set_irg_phase_low(get_irp_irg(i)); @@ -1078,9 +1110,10 @@ void gen_firm_finish(FILE *out, const char *input_filename, int c_mode, int firm #endif /* enable architecture dependent optimizations */ - arch_dep_set_opts((firm_opt.muls ? arch_dep_mul_to_shift : arch_dep_none) | + arch_dep_set_opts((arch_dep_opts_t) + ((firm_opt.muls ? arch_dep_mul_to_shift : arch_dep_none) | (firm_opt.divs ? arch_dep_div_by_const : arch_dep_none) | - (firm_opt.mods ? arch_dep_mod_by_const : arch_dep_none) ); + (firm_opt.mods ? arch_dep_mod_by_const : arch_dep_none) )); if (firm_dump.statistic & STAT_FINAL_IR)