From 88cc26afec80dae40d8e08de0e6db6c308e64f79 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 9 Jun 2016 18:37:58 -0400 Subject: Re-work optimization levels. -O3 is the new default, for the future cost-based optimizer. -O4 enables the surprising/aggressive optimizations that used to be under -O3. -Ofast is a synonym for -O4. --- parse.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'parse.c') diff --git a/parse.c b/parse.c index e9e1b52..c24592c 100644 --- a/parse.c +++ b/parse.c @@ -609,10 +609,20 @@ static struct expr *parse_debug(struct parser_state *state) { * Parse -On. */ static struct expr *parse_optlevel(struct parser_state *state) { - if (!parse_int(state, state->argv[0] + 2, &state->cmdline->optlevel, IF_INT)) { + int *optlevel = &state->cmdline->optlevel; + + if (strcmp(state->argv[0], "-Ofast") == 0) { + *optlevel = 4; + } else if (!parse_int(state, state->argv[0] + 2, optlevel, IF_INT)) { return NULL; } + if (*optlevel > 4) { + pretty_warning(state->cmdline->stderr_colors, + "warning: %s is the same as -O4.\n\n", + state->argv[0]); + } + return parse_nullary_flag(state); } @@ -1777,8 +1787,8 @@ static struct expr *optimize_whole_expr(const struct parser_state *state, struct } } - if (optlevel >= 3 && expr->pure && expr != &expr_false) { - debug_opt(state, "-O3: top-level purity: %e <==> %e\n", expr, &expr_false); + if (optlevel >= 4 && expr->pure && expr != &expr_false) { + debug_opt(state, "-O4: top-level purity: %e <==> %e\n", expr, &expr_false); free_expr(expr); expr = &expr_false; } @@ -1798,7 +1808,7 @@ static void dump_cmdline(const struct cmdline *cmdline) { fputs("-P ", stderr); } - if (cmdline->optlevel != 2) { + if (cmdline->optlevel != 3) { fprintf(stderr, "-O%d ", cmdline->optlevel); } @@ -1853,7 +1863,7 @@ struct cmdline *parse_cmdline(int argc, char *argv[]) { cmdline->mindepth = 0; cmdline->maxdepth = INT_MAX; cmdline->flags = BFTW_RECOVER; - cmdline->optlevel = 2; + cmdline->optlevel = 3; cmdline->debug = 0; cmdline->expr = &expr_true; cmdline->nopen_files = 0; -- cgit v1.2.3