re PR other/53316 (Introduce -Og)

2012-09-19  Richard Guenther  <rguenther@suse.de>

	PR other/53316
	* common.opt (optimize_debug): New variable.
	(Og): New optimization level.
	* doc/invoke.texi (Og): Document.
	* opts.c (maybe_default_option): Add debug parameter.
	(maybe_default_options): Likewise.
	(default_options_optimization): Handle -Og.
	(common_handle_option): Likewise.
	* passes.c (gate_all_optimizations): Do not run with -Og.
	(gate_all_optimizations_g): New gate, run with -Og.
	(pass_all_optimizations_g): New container pass, run with -Og.
	(init_optimization_passes): Schedule pass_all_optimizations_g
	alongside pass_all_optimizations.

From-SVN: r191464
This commit is contained in:
Richard Guenther 2012-09-19 09:29:57 +00:00 committed by Richard Biener
parent f20132e7ae
commit bf7a718571
5 changed files with 117 additions and 17 deletions

View file

@ -1,3 +1,19 @@
2012-09-19 Richard Guenther <rguenther@suse.de>
PR other/53316
* common.opt (optimize_debug): New variable.
(Og): New optimization level.
* doc/invoke.texi (Og): Document.
* opts.c (maybe_default_option): Add debug parameter.
(maybe_default_options): Likewise.
(default_options_optimization): Handle -Og.
(common_handle_option): Likewise.
* passes.c (gate_all_optimizations): Do not run with -Og.
(gate_all_optimizations_g): New gate, run with -Og.
(pass_all_optimizations_g): New container pass, run with -Og.
(init_optimization_passes): Schedule pass_all_optimizations_g
alongside pass_all_optimizations.
2012-09-19 Richard Guenther <rguenther@suse.de>
PR tree-optimization/54132

View file

@ -32,6 +32,9 @@ int optimize
Variable
int optimize_size
Variable
int optimize_debug
; Not used directly to control optimizations, only to save -Ofast
; setting for "optimize" attributes.
Variable
@ -449,6 +452,10 @@ Ofast
Common Optimization
Optimize for speed disregarding exact standards compliance
Og
Common Optimization
Optimize for debugging experience rather than speed or size
Q
Driver

View file

@ -422,7 +422,7 @@ Objective-C and Objective-C++ Dialects}.
-fvariable-expansion-in-unroller -fvect-cost-model -fvpt -fweb @gol
-fwhole-program -fwpa -fuse-linker-plugin @gol
--param @var{name}=@var{value}
-O -O0 -O1 -O2 -O3 -Os -Ofast}
-O -O0 -O1 -O2 -O3 -Os -Ofast -Og}
@item Preprocessor Options
@xref{Preprocessor Options,,Options Controlling the Preprocessor}.
@ -6364,6 +6364,14 @@ valid for all standard-compliant programs.
It turns on @option{-ffast-math} and the Fortran-specific
@option{-fno-protect-parens} and @option{-fstack-arrays}.
@item -Og
@opindex Og
Optimize debugging experience. @option{-Og} enables optimizations
that do not interfere with debugging. It should be the optimization
level of choice for the standard edit-compile-debug cycle, offering
a reasonable level of optimization while maintaining fast compilation
and a good debugging experience.
If you use multiple @option{-O} options, with or without level numbers,
the last such option is the one that is effective.
@end table

View file

@ -314,15 +314,15 @@ init_options_struct (struct gcc_options *opts, struct gcc_options *opts_set)
}
/* If indicated by the optimization level LEVEL (-Os if SIZE is set,
-Ofast if FAST is set), apply the option DEFAULT_OPT to OPTS and
OPTS_SET, diagnostic context DC, location LOC, with language mask
LANG_MASK and option handlers HANDLERS. */
-Ofast if FAST is set, -Og if DEBUG is set), apply the option DEFAULT_OPT
to OPTS and OPTS_SET, diagnostic context DC, location LOC, with language
mask LANG_MASK and option handlers HANDLERS. */
static void
maybe_default_option (struct gcc_options *opts,
struct gcc_options *opts_set,
const struct default_options *default_opt,
int level, bool size, bool fast,
int level, bool size, bool fast, bool debug,
unsigned int lang_mask,
const struct cl_option_handlers *handlers,
location_t loc,
@ -335,6 +335,8 @@ maybe_default_option (struct gcc_options *opts,
gcc_assert (level == 2);
if (fast)
gcc_assert (level == 3);
if (debug)
gcc_assert (level == 1);
switch (default_opt->levels)
{
@ -351,7 +353,11 @@ maybe_default_option (struct gcc_options *opts,
break;
case OPT_LEVELS_1_PLUS_SPEED_ONLY:
enabled = (level >= 1 && !size);
enabled = (level >= 1 && !size && !debug);
break;
case OPT_LEVELS_1_PLUS_NOT_DEBUG:
enabled = (level >= 1 && !debug);
break;
case OPT_LEVELS_2_PLUS:
@ -359,7 +365,7 @@ maybe_default_option (struct gcc_options *opts,
break;
case OPT_LEVELS_2_PLUS_SPEED_ONLY:
enabled = (level >= 2 && !size);
enabled = (level >= 2 && !size && !debug);
break;
case OPT_LEVELS_3_PLUS:
@ -405,7 +411,7 @@ static void
maybe_default_options (struct gcc_options *opts,
struct gcc_options *opts_set,
const struct default_options *default_opts,
int level, bool size, bool fast,
int level, bool size, bool fast, bool debug,
unsigned int lang_mask,
const struct cl_option_handlers *handlers,
location_t loc,
@ -415,7 +421,8 @@ maybe_default_options (struct gcc_options *opts,
for (i = 0; default_opts[i].levels != OPT_LEVELS_NONE; i++)
maybe_default_option (opts, opts_set, &default_opts[i],
level, size, fast, lang_mask, handlers, loc, dc);
level, size, fast, debug,
lang_mask, handlers, loc, dc);
}
/* Table of options enabled by default at different levels. */
@ -444,7 +451,7 @@ static const struct default_options default_options_table[] =
{ OPT_LEVELS_1_PLUS, OPT_ftree_dominator_opts, NULL, 1 },
{ OPT_LEVELS_1_PLUS, OPT_ftree_dse, NULL, 1 },
{ OPT_LEVELS_1_PLUS, OPT_ftree_ter, NULL, 1 },
{ OPT_LEVELS_1_PLUS, OPT_ftree_sra, NULL, 1 },
{ OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_sra, NULL, 1 },
{ OPT_LEVELS_1_PLUS, OPT_ftree_copyrename, NULL, 1 },
{ OPT_LEVELS_1_PLUS, OPT_ftree_fre, NULL, 1 },
{ OPT_LEVELS_1_PLUS, OPT_ftree_copy_prop, NULL, 1 },
@ -498,7 +505,7 @@ static const struct default_options default_options_table[] =
/* Inlining of functions reducing size is a good idea with -Os
regardless of them being declared inline. */
{ OPT_LEVELS_3_PLUS_AND_SIZE, OPT_finline_functions, NULL, 1 },
{ OPT_LEVELS_1_PLUS, OPT_finline_functions_called_once, NULL, 1 },
{ OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_finline_functions_called_once, NULL, 1 },
{ OPT_LEVELS_3_PLUS, OPT_funswitch_loops, NULL, 1 },
{ OPT_LEVELS_3_PLUS, OPT_fgcse_after_reload, NULL, 1 },
{ OPT_LEVELS_3_PLUS, OPT_ftree_vectorize, NULL, 1 },
@ -540,6 +547,7 @@ default_options_optimization (struct gcc_options *opts,
opts->x_optimize = 1;
opts->x_optimize_size = 0;
opts->x_optimize_fast = 0;
opts->x_optimize_debug = 0;
}
else
{
@ -555,6 +563,7 @@ default_options_optimization (struct gcc_options *opts,
opts->x_optimize = 255;
opts->x_optimize_size = 0;
opts->x_optimize_fast = 0;
opts->x_optimize_debug = 0;
}
}
break;
@ -565,6 +574,7 @@ default_options_optimization (struct gcc_options *opts,
/* Optimizing for size forces optimize to be 2. */
opts->x_optimize = 2;
opts->x_optimize_fast = 0;
opts->x_optimize_debug = 0;
break;
case OPT_Ofast:
@ -572,6 +582,15 @@ default_options_optimization (struct gcc_options *opts,
opts->x_optimize_size = 0;
opts->x_optimize = 3;
opts->x_optimize_fast = 1;
opts->x_optimize_debug = 0;
break;
case OPT_Og:
/* -Og selects optimization level 1. */
opts->x_optimize_size = 0;
opts->x_optimize = 1;
opts->x_optimize_fast = 0;
opts->x_optimize_debug = 1;
break;
default:
@ -582,7 +601,8 @@ default_options_optimization (struct gcc_options *opts,
maybe_default_options (opts, opts_set, default_options_table,
opts->x_optimize, opts->x_optimize_size,
opts->x_optimize_fast, lang_mask, handlers, loc, dc);
opts->x_optimize_fast, opts->x_optimize_debug,
lang_mask, handlers, loc, dc);
/* -O2 param settings. */
opt2 = (opts->x_optimize >= 2);
@ -612,7 +632,8 @@ default_options_optimization (struct gcc_options *opts,
maybe_default_options (opts, opts_set,
targetm_common.option_optimization_table,
opts->x_optimize, opts->x_optimize_size,
opts->x_optimize_fast, lang_mask, handlers, loc, dc);
opts->x_optimize_fast, opts->x_optimize_debug,
lang_mask, handlers, loc, dc);
}
/* After all options at LOC have been read into OPTS and OPTS_SET,
@ -1408,6 +1429,7 @@ common_handle_option (struct gcc_options *opts,
case OPT_O:
case OPT_Os:
case OPT_Ofast:
case OPT_Og:
/* Currently handled in a prescan. */
break;

View file

@ -337,10 +337,7 @@ static struct gimple_opt_pass pass_all_early_optimizations =
static bool
gate_all_optimizations (void)
{
return (optimize >= 1
/* Don't bother doing anything if the program has errors.
We have to pass down the queue if we already went into SSA */
&& (!seen_error () || gimple_in_ssa_p (cfun)));
return optimize >= 1 && !optimize_debug;
}
static struct gimple_opt_pass pass_all_optimizations =
@ -362,6 +359,33 @@ static struct gimple_opt_pass pass_all_optimizations =
}
};
/* Gate: execute, or not, all of the non-trivial optimizations. */
static bool
gate_all_optimizations_g (void)
{
return optimize >= 1 && optimize_debug;
}
static struct gimple_opt_pass pass_all_optimizations_g =
{
{
GIMPLE_PASS,
"*all_optimizations_g", /* name */
gate_all_optimizations_g, /* gate */
NULL, /* execute */
NULL, /* sub */
NULL, /* next */
0, /* static_pass_number */
TV_OPTIMIZE, /* tv_id */
0, /* properties_required */
0, /* properties_provided */
0, /* properties_destroyed */
0, /* todo_flags_start */
0 /* todo_flags_finish */
}
};
static bool
gate_rest_of_compilation (void)
{
@ -1494,6 +1518,29 @@ init_optimization_passes (void)
NEXT_PASS (pass_uncprop);
NEXT_PASS (pass_local_pure_const);
}
NEXT_PASS (pass_all_optimizations_g);
{
struct opt_pass **p = &pass_all_optimizations_g.pass.sub;
NEXT_PASS (pass_remove_cgraph_callee_edges);
NEXT_PASS (pass_strip_predict_hints);
/* Lower remaining pieces of GIMPLE. */
NEXT_PASS (pass_lower_complex);
NEXT_PASS (pass_lower_vector_ssa);
/* Perform simple scalar cleanup which is constant/copy propagation. */
NEXT_PASS (pass_ccp);
NEXT_PASS (pass_copy_prop);
NEXT_PASS (pass_rename_ssa_copies);
NEXT_PASS (pass_dce);
/* Fold remaining builtins. */
NEXT_PASS (pass_object_sizes);
NEXT_PASS (pass_fold_builtins);
/* ??? We do want some kind of loop invariant motion, but we possibly
need to adjust LIM to be more friendly towards preserving accurate
debug information here. */
NEXT_PASS (pass_late_warn_uninitialized);
NEXT_PASS (pass_uncprop);
NEXT_PASS (pass_local_pure_const);
}
NEXT_PASS (pass_tm_init);
{
struct opt_pass **p = &pass_tm_init.pass.sub;