On 5/18/20 1:49 PM, Richard Biener wrote:
On Mon, May 18, 2020 at 1:10 PM Jakub Jelinek via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
On Mon, May 18, 2020 at 01:03:40PM +0200, Jakub Jelinek wrote:
The optimize attribute is used to specify that a function is to be compiled
with different optimization options than specified on the command line.
```
It's pretty clear about the command line arguments (that are ignored).
That is not clear at all. The difference is primarily in what the option
string says in there.
And if we decide we want to keep existing behavior (haven't checked if we
actually behave that way yet), we should add some syntax that will allow
ammending command line options rather than replacing it.
Hello.
Back to this, I must say that option handling is a complex thing in the GCC.
We do behave this way - while we're running against the current
gcc_options we call decode_options which first does
default_options_optimization. So it behaves inconsistently with
respect to options not explicitly listed in default_options_table.
Yes, we basically build on top of the currently selection flags.
We use default_options_table because any optimization level selection
in an optimization attribute should efficiently enforce call of
default_options_table.
What about using them only in case one changes optimization level (patch)?
Martin
But I also think doing the whole processing as in decode_options
is the only thing that's really tested. And a fix would be to not
start from the current set of options but from a clean slate...
The code clearly thinks we're doing incremental changes:
/* Save current options. */
cl_optimization_save (&cur_opts, &global_options);
/* If we previously had some optimization options, use them as the
default. */
if (old_opts)
cl_optimization_restore (&global_options,
TREE_OPTIMIZATION (old_opts));
/* Parse options, and update the vector. */
parse_optimize_options (args, true);
DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node)
= build_optimization_node (&global_options);
/* Restore current options. */
cl_optimization_restore (&global_options, &cur_opts);
so for example you should see -fipa-pta preserved from the
command-line while -fno-tree-pta would be overridden even
if not mentioned explicitely in the optimize attribute.
IMHO the current situation is far from useful...
Richard.
Could be say start the optimize attribute string with + or something
similar.
Does target attribute behave that way too?
Jakub
diff --git a/gcc/opts.c b/gcc/opts.c
index ec3ca0720f9..8c39562c697 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -571,6 +571,7 @@ default_options_optimization (struct gcc_options *opts,
unsigned int i;
int opt2;
bool openacc_mode = false;
+ bool opt_level_changed = false;
/* Scan to see what optimization level has been specified. That will
determine the default value of many flags. */
@@ -603,6 +604,7 @@ default_options_optimization (struct gcc_options *opts,
opts->x_optimize_debug = 0;
}
}
+ opt_level_changed = true;
break;
case OPT_Os:
@@ -612,6 +614,7 @@ default_options_optimization (struct gcc_options *opts,
opts->x_optimize = 2;
opts->x_optimize_fast = 0;
opts->x_optimize_debug = 0;
+ opt_level_changed = true;
break;
case OPT_Ofast:
@@ -620,6 +623,7 @@ default_options_optimization (struct gcc_options *opts,
opts->x_optimize = 3;
opts->x_optimize_fast = 1;
opts->x_optimize_debug = 0;
+ opt_level_changed = true;
break;
case OPT_Og:
@@ -628,6 +632,7 @@ default_options_optimization (struct gcc_options *opts,
opts->x_optimize = 1;
opts->x_optimize_fast = 0;
opts->x_optimize_debug = 1;
+ opt_level_changed = true;
break;
case OPT_fopenacc:
@@ -641,10 +646,11 @@ 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, opts->x_optimize_debug,
- lang_mask, handlers, loc, dc);
+ if (opt_level_changed)
+ maybe_default_options (opts, opts_set, default_options_table,
+ opts->x_optimize, opts->x_optimize_size,
+ opts->x_optimize_fast, opts->x_optimize_debug,
+ lang_mask, handlers, loc, dc);
/* -O2 param settings. */
opt2 = (opts->x_optimize >= 2);