[gcc(refs/users/marxin/heads/parse-opt-and-target-opts)] WIP path.
Martin Liska
marxin@gcc.gnu.org
Fri Mar 5 14:26:09 GMT 2021
https://gcc.gnu.org/g:ad894de38e021da579f322cb16e8557ce5e367fa
commit ad894de38e021da579f322cb16e8557ce5e367fa
Author: Martin Liska <mliska@suse.cz>
Date: Fri Mar 5 14:31:15 2021 +0100
WIP path.
Diff:
---
gcc/c-family/c-pch.c | 2 +-
gcc/c-family/c-pragma.c | 9 ---
gcc/config/i386/i386-builtins.c | 27 ++++----
gcc/config/i386/i386-c.c | 24 +++----
gcc/config/i386/i386-options.c | 141 ++++++++--------------------------------
gcc/tree-core.h | 6 +-
gcc/tree.c | 34 +---------
gcc/tree.h | 15 ++---
8 files changed, 62 insertions(+), 196 deletions(-)
diff --git a/gcc/c-family/c-pch.c b/gcc/c-family/c-pch.c
index fd94c3799ac..ce615cd9875 100644
--- a/gcc/c-family/c-pch.c
+++ b/gcc/c-family/c-pch.c
@@ -170,7 +170,7 @@ c_common_write_pch (void)
(*debug_hooks->handle_pch) (1);
- prepare_target_option_nodes_for_pch ();
+ prepare_optimization_nodes_for_pch ();
cpp_write_pch_deps (parse_in, pch_outfile);
diff --git a/gcc/c-family/c-pragma.c b/gcc/c-family/c-pragma.c
index 87110659c9b..50e7e266bde 100644
--- a/gcc/c-family/c-pragma.c
+++ b/gcc/c-family/c-pragma.c
@@ -1000,7 +1000,6 @@ handle_pragma_optimize (cpp_reader *ARG_UNUSED(dummy))
strings that will be added to the function's attribute list. */
struct GTY(()) opt_stack {
struct opt_stack *prev;
- tree target_binary;
tree target_strings;
tree optimize_binary;
tree optimize_strings;
@@ -1037,8 +1036,6 @@ handle_pragma_push_options (cpp_reader *ARG_UNUSED(dummy))
}
p->optimize_binary = build_optimization_node (&global_options,
&global_options_set);
- p->target_binary = build_target_option_node (&global_options,
- &global_options_set);
/* Save optimization and target flags in string list format. */
p->optimize_strings = copy_list (current_optimize_pragma);
@@ -1073,12 +1070,6 @@ handle_pragma_pop_options (cpp_reader *ARG_UNUSED(dummy))
p = options_stack;
options_stack = p->prev;
- if (p->target_binary != target_option_current_node)
- {
- (void) targetm.target_option.pragma_parse (NULL_TREE, p->target_binary);
- target_option_current_node = p->target_binary;
- }
-
if (p->optimize_binary != optimization_current_node)
{
tree old_optimize = optimization_current_node;
diff --git a/gcc/config/i386/i386-builtins.c b/gcc/config/i386/i386-builtins.c
index 0b5cb6e725b..7df7620d3f8 100644
--- a/gcc/config/i386/i386-builtins.c
+++ b/gcc/config/i386/i386-builtins.c
@@ -1431,7 +1431,6 @@ ix86_builtin_decl (unsigned code, bool)
static tree ix86_get_builtin (enum ix86_builtins code)
{
- struct cl_target_option *opts;
tree target_tree = NULL_TREE;
/* Determine the isa flags of current_function_decl. */
@@ -1442,8 +1441,6 @@ static tree ix86_get_builtin (enum ix86_builtins code)
if (target_tree == NULL)
target_tree = target_option_default_node;
- opts = TREE_TARGET_OPTION (target_tree);
-
if ((ix86_builtins_isa[(int) code].isa & ix86_isa_flags)
|| (ix86_builtins_isa[(int) code].isa2 & ix86_isa_flags2))
return ix86_builtin_decl (code, true);
@@ -1838,9 +1835,9 @@ unsigned int
get_builtin_code_for_version (tree decl, tree *predicate_list)
{
tree attrs;
- struct cl_target_option cur_target;
- tree target_node;
- struct cl_target_option *new_target;
+ struct cl_optimization cur_optimization;
+ tree optimization_node;
+ struct cl_optimization *new_optimization;
const char *arg_str = NULL;
const char *attrs_str = NULL;
char *tok_str = NULL;
@@ -1875,17 +1872,17 @@ get_builtin_code_for_version (tree decl, tree *predicate_list)
before the ssse3 version. */
if (strstr (attrs_str, "arch=") != NULL)
{
- cl_target_option_save (&cur_target, &global_options,
- &global_options_set);
- target_node
+ cl_optimization_save (&cur_optimization, &global_options,
+ &global_options_set);
+ optimization_node
= ix86_valid_target_attribute_tree (decl, attrs, &global_options,
&global_options_set, 0);
- gcc_assert (target_node);
- if (target_node == error_mark_node)
+ gcc_assert (optimization_node);
+ if (optimization_node == error_mark_node)
return 0;
- new_target = TREE_TARGET_OPTION (target_node);
- gcc_assert (new_target);
+ new_optimization = TREE_OPTIMIZATION (optimization_node);
+ gcc_assert (new_optimization);
if (arch_specified && ix86_arch > 0)
for (i = 0; i < pta_size; i++)
@@ -1945,8 +1942,8 @@ get_builtin_code_for_version (tree decl, tree *predicate_list)
break;
}
- cl_target_option_restore (&global_options, &global_options_set,
- &cur_target);
+ cl_optimization_restore (&global_options, &global_options_set,
+ &cur_optimization);
if (predicate_list && arg_str == NULL)
{
diff --git a/gcc/config/i386/i386-c.c b/gcc/config/i386/i386-c.c
index 60de56f8ece..42d486cf602 100644
--- a/gcc/config/i386/i386-c.c
+++ b/gcc/config/i386/i386-c.c
@@ -631,10 +631,8 @@ static bool
ix86_pragma_target_parse (tree args, tree pop_target)
{
tree prev_tree
- = build_target_option_node (&global_options, &global_options_set);
+ = build_optimization_node (&global_options, &global_options_set);
tree cur_tree;
- struct cl_target_option *prev_opt;
- struct cl_target_option *cur_opt;
HOST_WIDE_INT prev_isa;
HOST_WIDE_INT cur_isa;
HOST_WIDE_INT diff_isa;
@@ -653,9 +651,9 @@ ix86_pragma_target_parse (tree args, tree pop_target)
if (! args)
{
- cur_tree = (pop_target ? pop_target : target_option_default_node);
- cl_target_option_restore (&global_options, &global_options_set,
- TREE_TARGET_OPTION (cur_tree));
+ cur_tree = (pop_target ? pop_target : optimization_default_node);
+ cl_optimization_restore (&global_options, &global_options_set,
+ TREE_OPTIMIZATION (cur_tree));
}
else
{
@@ -663,20 +661,18 @@ ix86_pragma_target_parse (tree args, tree pop_target)
&global_options,
&global_options_set, 0);
if (!cur_tree || cur_tree == error_mark_node)
- {
- cl_target_option_restore (&global_options, &global_options_set,
- TREE_TARGET_OPTION (prev_tree));
- return false;
- }
+ {
+ cl_optimization_restore (&global_options, &global_options_set,
+ TREE_OPTIMIZATION (prev_tree));
+ return false;
+ }
}
- target_option_current_node = cur_tree;
+ optimization_current_node = cur_tree;
enum fpmath_unit cur_fpmath = ix86_fpmath;
ix86_reset_previous_fndecl ();
/* Figure out the previous/current isa, arch, tune and the differences. */
- prev_opt = TREE_TARGET_OPTION (prev_tree);
- cur_opt = TREE_TARGET_OPTION (cur_tree);
cur_isa = ix86_isa_flags;
cur_isa2 = ix86_isa_flags2;
diff_isa = (prev_isa ^ cur_isa);
diff --git a/gcc/config/i386/i386-options.c b/gcc/config/i386/i386-options.c
index 99072512d29..bbd4ac26a47 100644
--- a/gcc/config/i386/i386-options.c
+++ b/gcc/config/i386/i386-options.c
@@ -771,15 +771,6 @@ ix86_function_specific_print (FILE *file, int indent,
-/* Release allocated strings. */
-static void
-release_options_strings (char **option_strings)
-{
- /* Free up memory allocated to hold the strings */
- for (unsigned i = 0; i < IX86_FUNCTION_SPECIFIC_MAX; i++)
- free (option_strings[i]);
-}
-
/* Return a TARGET_OPTION_NODE tree of the target options listed or NULL. */
tree
@@ -788,83 +779,19 @@ ix86_valid_target_attribute_tree (tree fndecl, tree args,
struct gcc_options *opts_set,
bool target_clone_attr)
{
- const char *orig_arch_string = opts->x_ix86_arch_string;
- const char *orig_tune_string = opts->x_ix86_tune_string;
- enum fpmath_unit orig_fpmath_set = opts_set->x_ix86_fpmath;
- int orig_tune_defaulted = ix86_tune_defaulted;
- int orig_arch_specified = ix86_arch_specified;
- char *option_strings[IX86_FUNCTION_SPECIFIC_MAX] = { NULL, NULL };
- tree t = NULL_TREE;
- struct cl_target_option *def
- = TREE_TARGET_OPTION (target_option_default_node);
- struct gcc_options enum_opts_set;
-
- memset (&enum_opts_set, 0, sizeof (enum_opts_set));
-
parse_optimize_and_target_options (opts, opts_set, args, true, true);
- /* If the changed options are different from the default, rerun
- ix86_option_override_internal, and then save the options away.
- The string options are attribute options, and will be undone
- when we copy the save structure. */
-// if (opts->x_ix86_isa_flags != def->x_ix86_isa_flags
-// || opts->x_ix86_isa_flags2 != def->x_ix86_isa_flags2
- // FIXME
- {
- /* If we are using the default tune= or arch=, undo the string assigned,
- and use the default. */
- if (option_strings[IX86_FUNCTION_SPECIFIC_ARCH])
- opts->x_ix86_arch_string
- = ggc_strdup (option_strings[IX86_FUNCTION_SPECIFIC_ARCH]);
- else if (!orig_arch_specified)
- opts->x_ix86_arch_string = NULL;
-
- if (option_strings[IX86_FUNCTION_SPECIFIC_TUNE])
- opts->x_ix86_tune_string
- = ggc_strdup (option_strings[IX86_FUNCTION_SPECIFIC_TUNE]);
- else if (orig_tune_defaulted)
- opts->x_ix86_tune_string = NULL;
-
- /* If fpmath= is not set, and we now have sse2 on 32-bit, use it. */
- if (enum_opts_set.x_ix86_fpmath)
- opts_set->x_ix86_fpmath = (enum fpmath_unit) 1;
- if (enum_opts_set.x_ix86_prefer_vector_width)
- opts_set->x_ix86_prefer_vector_width = (enum prefer_vector_width) 1;
-
- /* Do any overrides, such as arch=xxx, or tune=xxx support. */
- bool r = ix86_option_override_internal (false, opts, opts_set);
- if (!r)
- {
- release_options_strings (option_strings);
- return error_mark_node;
- }
-
- /* Add any builtin functions with the new isa if any. */
- ix86_add_new_builtins (opts->x_ix86_isa_flags, opts->x_ix86_isa_flags2);
-
- enum excess_precision orig_ix86_excess_precision
- = opts->x_ix86_excess_precision;
- bool orig_ix86_unsafe_math_optimizations
- = opts->x_ix86_unsafe_math_optimizations;
- opts->x_ix86_excess_precision = opts->x_flag_excess_precision;
- opts->x_ix86_unsafe_math_optimizations
- = opts->x_flag_unsafe_math_optimizations;
-
- /* Save the current options unless we are validating options for
- #pragma. */
- t = build_target_option_node (opts, opts_set);
+ /* Do any overrides, such as arch=xxx, or tune=xxx support. */
+ bool r = ix86_option_override_internal (false, opts, opts_set);
+ if (!r)
+ return error_mark_node;
- opts->x_ix86_arch_string = orig_arch_string;
- opts->x_ix86_tune_string = orig_tune_string;
- opts_set->x_ix86_fpmath = orig_fpmath_set;
- opts->x_ix86_excess_precision = orig_ix86_excess_precision;
- opts->x_ix86_unsafe_math_optimizations
- = orig_ix86_unsafe_math_optimizations;
-
- release_options_strings (option_strings);
- }
+ /* Add any builtin functions with the new isa if any. */
+ ix86_add_new_builtins (opts->x_ix86_isa_flags, opts->x_ix86_isa_flags2);
- return t;
+ /* Save the current options unless we are validating options for
+#pragma. */
+ return build_optimization_node (opts, opts_set);
}
/* Hook to validate attribute((target("string"))). */
@@ -905,29 +832,17 @@ ix86_valid_target_attribute_p (tree fndecl,
cl_optimization_restore (&func_options, &func_options_set,
TREE_OPTIMIZATION (func_optimize));
- /* Initialize func_options to the default before its target options can
- be set. */
- cl_target_option_restore (&func_options, &func_options_set,
- TREE_TARGET_OPTION (target_option_default_node));
-
/* FLAGS == 1 is used for target_clones attribute. */
- new_target
+ new_optimize
= ix86_valid_target_attribute_tree (fndecl, args, &func_options,
&func_options_set, flags == 1);
- new_optimize = build_optimization_node (&func_options, &func_options_set);
-
// FIXME
- if (new_target == error_mark_node)
+ if (new_optimize == error_mark_node)
ret = false;
- else if (fndecl && new_target)
- {
- DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_target;
-
- if (old_optimize != new_optimize)
- DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) = new_optimize;
- }
+ else if (fndecl && new_optimize)
+ DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) = new_optimize;
return ret;
}
@@ -2491,8 +2406,8 @@ ix86_option_override_internal (bool main_args_p,
= opts->x_flag_excess_precision;
opts->x_ix86_unsafe_math_optimizations
= opts->x_flag_unsafe_math_optimizations;
- target_option_default_node = target_option_current_node
- = build_target_option_node (opts, opts_set);
+ optimization_default_node = optimization_current_node
+ = build_optimization_node (opts, opts_set);
}
if (opts->x_flag_cf_protection != CF_NONE)
@@ -2535,15 +2450,15 @@ static GTY(()) tree ix86_previous_fndecl;
void
ix86_reset_previous_fndecl (void)
{
- tree new_tree = target_option_current_node;
- cl_target_option_restore (&global_options, &global_options_set,
- TREE_TARGET_OPTION (new_tree));
- if (TREE_TARGET_GLOBALS (new_tree))
- restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
- else if (new_tree == target_option_default_node)
+ tree new_tree = optimization_current_node;
+ cl_optimization_restore (&global_options, &global_options_set,
+ TREE_OPTIMIZATION (new_tree));
+ if (TREE_OPTIMIZATION_GLOBALS (new_tree))
+ restore_target_globals (TREE_OPTIMIZATION_GLOBALS (new_tree));
+ else if (new_tree == optimization_default_node)
restore_target_globals (&default_target_globals);
else
- TREE_TARGET_GLOBALS (new_tree) = save_target_globals_default_opts ();
+ TREE_OPTIMIZATION_GLOBALS (new_tree) = save_target_globals_default_opts ();
ix86_previous_fndecl = NULL_TREE;
}
@@ -2798,12 +2713,12 @@ ix86_set_current_function (tree fndecl)
{
cl_target_option_restore (&global_options, &global_options_set,
TREE_TARGET_OPTION (new_tree));
- if (TREE_TARGET_GLOBALS (new_tree))
- restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
+ if (TREE_OPTIMIZATION_GLOBALS (new_tree))
+ restore_target_globals (TREE_OPTIMIZATION_GLOBALS (new_tree));
else if (new_tree == target_option_default_node)
restore_target_globals (&default_target_globals);
else
- TREE_TARGET_GLOBALS (new_tree) = save_target_globals_default_opts ();
+ TREE_OPTIMIZATION_GLOBALS (new_tree) = save_target_globals_default_opts ();
}
/* FIXME
else if (flag_unsafe_math_optimizations
@@ -2817,12 +2732,12 @@ ix86_set_current_function (tree fndecl)
ix86_unsafe_math_optimizations = flag_unsafe_math_optimizations;
DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_tree
= build_target_option_node (&global_options, &global_options_set);
- if (TREE_TARGET_GLOBALS (new_tree))
- restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
+ if (TREE_OPTIMIZATION_GLOBALS (new_tree))
+ restore_target_globals (TREE_OPTIMIZATION_GLOBALS (new_tree));
else if (new_tree == target_option_default_node)
restore_target_globals (&default_target_globals);
else
- TREE_TARGET_GLOBALS (new_tree) = save_target_globals_default_opts ();
+ TREE_OPTIMIZATION_GLOBALS (new_tree) = save_target_globals_default_opts ();
}
*/
ix86_previous_fndecl = fndecl;
diff --git a/gcc/tree-core.h b/gcc/tree-core.h
index d2e6c895e42..6d1ebe844f0 100644
--- a/gcc/tree-core.h
+++ b/gcc/tree-core.h
@@ -1952,6 +1952,9 @@ struct GTY(()) tree_optimization_option {
/* The optimization options used by the user. */
struct cl_optimization *opts;
+ /* Target globals for the corresponding target option. */
+ class target_globals *globals;
+
/* Target optabs for this set of optimization options. This is of
type `struct target_optabs *'. */
void *GTY ((atomic)) optabs;
@@ -1970,9 +1973,6 @@ class GTY(()) target_globals;
struct GTY(()) tree_target_option {
struct tree_base base;
- /* Target globals for the corresponding target option. */
- class target_globals *globals;
-
/* The optimization options used by the user. */
struct cl_target_option *opts;
};
diff --git a/gcc/tree.c b/gcc/tree.c
index 8fa99951df7..6edf4058c10 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -12748,44 +12748,16 @@ build_optimization_node (struct gcc_options *opts,
return t;
}
-/* Build a TARGET_OPTION_NODE based on the options in OPTS and OPTS_SET. */
-
-tree
-build_target_option_node (struct gcc_options *opts,
- struct gcc_options *opts_set)
-{
- tree t;
-
- /* Use the cache of optimization nodes. */
-
- cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node),
- opts, opts_set);
-
- tree *slot = cl_option_hash_table->find_slot (cl_target_option_node, INSERT);
- t = *slot;
- if (!t)
- {
- /* Insert this one into the hash table. */
- t = cl_target_option_node;
- *slot = t;
-
- /* Make a new node for next time round. */
- cl_target_option_node = make_node (TARGET_OPTION_NODE);
- }
-
- return t;
-}
-
/* Clear TREE_TARGET_GLOBALS of all TARGET_OPTION_NODE trees,
so that they aren't saved during PCH writing. */
void
-prepare_target_option_nodes_for_pch (void)
+prepare_optimization_nodes_for_pch (void)
{
hash_table<cl_option_hasher>::iterator iter = cl_option_hash_table->begin ();
for (; iter != cl_option_hash_table->end (); ++iter)
- if (TREE_CODE (*iter) == TARGET_OPTION_NODE)
- TREE_TARGET_GLOBALS (*iter) = NULL;
+ if (TREE_CODE (*iter) == OPTIMIZATION_NODE)
+ TREE_OPTIMIZATION_GLOBALS (*iter) = NULL;
}
/* Determine the "ultimate origin" of a block. */
diff --git a/gcc/tree.h b/gcc/tree.h
index f00ea2ef0af..63a6e418772 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -3326,6 +3326,11 @@ extern vec<tree, va_gc> **decl_debug_args_insert (tree);
#define TREE_OPTIMIZATION_BASE_OPTABS(NODE) \
(OPTIMIZATION_NODE_CHECK (NODE)->optimization.base_optabs)
+#define TREE_OPTIMIZATION_GLOBALS(NODE) \
+ (OPTIMIZATION_NODE_CHECK (NODE)->optimization.globals)
+
+extern void prepare_optimization_nodes_for_pch (void);
+
/* Return a tree node that encapsulates the optimization options in OPTS
and OPTS_SET. */
extern tree build_optimization_node (struct gcc_options *opts,
@@ -3334,16 +3339,6 @@ extern tree build_optimization_node (struct gcc_options *opts,
#define TREE_TARGET_OPTION(NODE) \
(TARGET_OPTION_NODE_CHECK (NODE)->target_option.opts)
-#define TREE_TARGET_GLOBALS(NODE) \
- (TARGET_OPTION_NODE_CHECK (NODE)->target_option.globals)
-
-/* Return a tree node that encapsulates the target options in OPTS and
- OPTS_SET. */
-extern tree build_target_option_node (struct gcc_options *opts,
- struct gcc_options *opts_set);
-
-extern void prepare_target_option_nodes_for_pch (void);
-
#if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
inline tree
More information about the Gcc-cvs
mailing list