X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=driver%2Ffirm_opt.c;h=5aff18b49084053b36a0970bdafc8a67d326d247;hb=866b5720ca01fb187c95c3b98b8516a22cc8eedf;hp=6981ddf86f9f2418c493b3c8b73570c4cdf50dee;hpb=ead9c60c8b20470ccbf14687bd1593a4c2da341f;p=cparser diff --git a/driver/firm_opt.c b/driver/firm_opt.c index 6981ddf..5aff18b 100644 --- a/driver/firm_opt.c +++ b/driver/firm_opt.c @@ -1,12 +1,9 @@ /** - * - * @file firm_opt.c -- Firm-generating back end optimizations. - * - * (C) 2005-2010 Michael Beck beck@ipd.info.uni-karlsruhe.de - * - * $Id$ + * (C) 2005-2010 + * @file + * @author Michael Beck, Matthias Braun + * @brief Firm-generating back end optimizations. */ - #include #include @@ -20,6 +17,7 @@ #include "firm_timing.h" #include "ast2firm.h" #include "adt/strutil.h" +#include "adt/util.h" /* optimization settings */ struct a_firm_opt { @@ -272,10 +270,10 @@ static void rts_map(void) { &rts_entities[rts_memset], i_mapper_memset }, { &rts_entities[rts_memcmp], i_mapper_memcmp } }; - i_record rec[sizeof(mapper)/sizeof(mapper[0])]; - unsigned i, n_map; + i_record rec[lengthof(mapper)]; + size_t n_map = 0; - for (i = n_map = 0; i < sizeof(mapper)/sizeof(mapper[0]); ++i) { + for (size_t i = 0; i != lengthof(mapper); ++i) { if (*mapper[i].ent != NULL) { rec[n_map].i_call.kind = INTRINSIC_CALL; rec[n_map].i_call.i_ent = *mapper[i].ent; @@ -328,11 +326,6 @@ static void do_gcse(ir_graph *irg) set_opt_global_cse(0); } -static void lower_blockcopy(ir_graph *irg) -{ - lower_CopyB(irg, 128, 4); -} - typedef enum opt_target { OPT_TARGET_IRG, /**< optimization function works on a single graph */ OPT_TARGET_IRP /**< optimization function works on the complete program */ @@ -361,6 +354,7 @@ typedef struct { } u; const char *description; opt_flags_t flags; + ir_timer_t *timer; } opt_config_t; static opt_config_t opts[] = { @@ -378,7 +372,7 @@ static opt_config_t opts[] = { IRG("if-conversion", opt_if_conv, "if-conversion", OPT_FLAG_NONE), IRG("invert-loops", do_loop_inversion, "loop inversion", OPT_FLAG_NONE), IRG("ivopts", do_stred, "induction variable strength reduction", OPT_FLAG_NONE), - IRG("local", optimize_graph_df, "local graph optimizations", OPT_FLAG_HIDE_OPTIONS), + IRG("local", local_opts, "local graph optimizations", OPT_FLAG_HIDE_OPTIONS), IRG("lower", lower_highlevel_graph, "lowering", OPT_FLAG_HIDE_OPTIONS | OPT_FLAG_ESSENTIAL), IRG("lower-mux", do_lower_mux, "mux lowering", OPT_FLAG_NONE), IRG("opt-load-store", optimize_load_store, "load store optimization", OPT_FLAG_NONE), @@ -396,7 +390,6 @@ static opt_config_t opts[] = { IRG("vrp", set_vrp_data, "value range propagation", OPT_FLAG_NONE), IRP("inline", do_inline, "inlining", OPT_FLAG_NONE), IRP("lower-const", lower_const_code, "lowering of constant code", OPT_FLAG_HIDE_OPTIONS | OPT_FLAG_NO_DUMP | OPT_FLAG_NO_VERIFY | OPT_FLAG_ESSENTIAL), - IRG("lower-blockcopy", lower_blockcopy, "replace small block copies with load/store sequences", OPT_FLAG_NO_DUMP), IRP("target-lowering", be_lower_for_target, "lowering necessary for target architecture", OPT_FLAG_HIDE_OPTIONS | OPT_FLAG_ESSENTIAL), IRP("opt-func-call", optimize_funccalls, "function call optimization", OPT_FLAG_NONE), IRP("opt-proc-clone", do_cloning, "procedure cloning", OPT_FLAG_NONE), @@ -406,15 +399,13 @@ static opt_config_t opts[] = { #undef IRP #undef IRG }; -static const int n_opts = sizeof(opts) / sizeof(opts[0]); -static ir_timer_t *timers[sizeof(opts)/sizeof(opts[0])]; + +#define FOR_EACH_OPT(i) for (opt_config_t *i = opts; i != endof(opts); ++i) static opt_config_t *get_opt(const char *name) { - int i; - for (i = 0; i < n_opts; ++i) { - opt_config_t *config = &opts[i]; - if (strcmp(config->name, name) == 0) + FOR_EACH_OPT(config) { + if (streq(config->name, name)) return config; } @@ -441,20 +432,18 @@ static bool get_opt_enabled(const char *name) */ static bool do_irg_opt(ir_graph *irg, const char *name) { - ir_graph *old_irg; - opt_config_t *config = get_opt(name); - size_t n = config - opts; + opt_config_t *const config = get_opt(name); assert(config != NULL); assert(config->target == OPT_TARGET_IRG); if (! (config->flags & OPT_FLAG_ENABLED)) return false; - old_irg = current_ir_graph; + ir_graph *const old_irg = current_ir_graph; current_ir_graph = irg; - timer_push(timers[n]); + timer_push(config->timer); config->u.transform_irg(irg); - timer_pop(timers[n]); + timer_pop(config->timer); if (firm_dump.all_phases && firm_dump.ir_graph) { dump_ir_graph(irg, name); @@ -472,15 +461,14 @@ static bool do_irg_opt(ir_graph *irg, const char *name) static void do_irp_opt(const char *name) { - opt_config_t *config = get_opt(name); - size_t n = config - opts; + opt_config_t *const config = get_opt(name); assert(config->target == OPT_TARGET_IRP); if (! (config->flags & OPT_FLAG_ENABLED)) return; - timer_push(timers[n]); + timer_push(config->timer); config->u.transform_irp(); - timer_pop(timers[n]); + timer_pop(config->timer); if (firm_dump.ir_graph && firm_dump.all_phases) { int i; @@ -518,7 +506,6 @@ static void enable_safe_defaults(void) set_opt_enabled("confirm", true); set_opt_enabled("opt-load-store", true); set_opt_enabled("lower", true); - set_opt_enabled("lower-blockcopy", true); set_opt_enabled("deconv", true); set_opt_enabled("remove-confirms", true); set_opt_enabled("ivopts", true); @@ -693,7 +680,6 @@ static void do_firm_lowering(const char *input_filename) for (i = get_irp_n_irgs() - 1; i >= 0; --i) { ir_graph *irg = get_irp_irg(i); - do_irg_opt(irg, "lower-blockcopy"); do_irg_opt(irg, "local"); do_irg_opt(irg, "deconv"); do_irg_opt(irg, "control-flow"); @@ -737,11 +723,10 @@ static void do_firm_lowering(const char *input_filename) void gen_firm_init(void) { unsigned pattern = 0; - int i; - for (i = 0; i < n_opts; ++i) { - timers[i] = ir_timer_new(); - timer_register(timers[i], opts[i].description); + FOR_EACH_OPT(i) { + i->timer = ir_timer_new(); + timer_register(i->timer, i->description); } t_verify = ir_timer_new(); timer_register(t_verify, "Firm: verify pass"); @@ -756,7 +741,7 @@ void gen_firm_init(void) if (firm_dump.stat_dag) pattern |= FIRMSTAT_COUNT_DAG; - ir_init(NULL); + ir_init(); firm_init_stat(firm_dump.statistic == STAT_NONE ? 0 : FIRMSTAT_ENABLED | FIRMSTAT_COUNT_STRONG_OP | FIRMSTAT_COUNT_CONSTS | pattern); @@ -783,7 +768,6 @@ void gen_firm_init(void) set_opt_algebraic_simplification(firm_opt.const_folding); set_opt_cse(firm_opt.cse); set_opt_global_cse(0); - set_opt_unreachable_code(1); } /** @@ -831,7 +815,6 @@ void gen_firm_finish(FILE *out, const char *input_filename) for (i = get_irp_n_irgs() - 1; i >= 0; --i) { ir_graph *irg = get_irp_irg(i); do_irg_opt(irg, "control-flow"); - do_irg_opt(irg, "lower-blockcopy"); } if (firm_dump.statistic & STAT_BEFORE_OPT) { @@ -870,8 +853,7 @@ static void disable_all_opts(void) firm_opt.strict_alias = false; firm_opt.no_alias = false; - for (int i = 0; i < n_opts; ++i) { - opt_config_t *config = &opts[i]; + FOR_EACH_OPT(config) { if (config->flags & OPT_FLAG_ESSENTIAL) { config->flags |= OPT_FLAG_ENABLED; } else { @@ -882,11 +864,8 @@ static void disable_all_opts(void) static bool firm_opt_option(const char *opt) { - bool enable = true; - if (strncmp(opt, "no-", 3) == 0) { - enable = false; - opt = opt + 3; - } + char const* const rest = strstart(opt, "no-"); + bool const enable = rest ? opt = rest, false : true; opt_config_t *config = get_opt(opt); if (config == NULL || (config->flags & OPT_FLAG_HIDE_OPTIONS)) @@ -901,11 +880,10 @@ void firm_option_help(print_option_help_func print_option_help) { print_option_help(firm_options[0].option, firm_options[0].description); - for (int i = 0; i < n_opts; ++i) { + FOR_EACH_OPT(config) { char buf[1024]; char buf2[1024]; - const opt_config_t *config = &opts[i]; if (config->flags & OPT_FLAG_HIDE_OPTIONS) continue; @@ -917,8 +895,7 @@ void firm_option_help(print_option_help_func print_option_help) print_option_help(buf, buf2); } - size_t const n_options = sizeof(firm_options)/sizeof(firm_options[0]); - for (size_t k = 0; k < n_options; ++k) { + for (size_t k = 0; k != lengthof(firm_options); ++k) { char buf[1024]; char buf2[1024]; snprintf(buf, sizeof(buf), "-f%s", firm_options[k].option); @@ -948,10 +925,9 @@ int firm_option(const char *const opt) } size_t const len = strlen(opt); - size_t const n_options = sizeof(firm_options)/sizeof(firm_options[0]); - for (size_t i = n_options; i != 0;) { + for (size_t i = lengthof(firm_options); i != 0;) { struct params const* const o = &firm_options[--i]; - if (len == o->opt_len && strncmp(opt, o->option, len) == 0) { + if (len == o->opt_len && memcmp(opt, o->option, len) == 0) { /* statistic options do accumulate */ if (o->flag == &firm_dump.statistic) *o->flag = (bool) (*o->flag | o->set);