gcc/gcc/target-globals.c
Jakub Jelinek ba948b3776 options: Save and restore opts_set for Optimization and Target options
> Seems a latent issue.
> Neither cl_optimization_{save,restore} nor cl_target_option_{save,restore}
> (nor any of the target hooks they call) saves or restores any opts_set
> values, so I think opts_set can be trusted only during option processing (if
> at all), but not later.
> So, short term a fix would be IMHO just stop using opts_set altogether in
> arm_configure_build_target, it doesn't make much sense to me, it should test
> if those strings are non-NULL instead, or at least do that when it is
> invoked from arm_option_restore (e.g. could be done by calling it with
> opts instead of &global_options_set ).
> Longer term, the question is if cl_optimization_{save,restore} and
> cl_target_option_{save,restore} shouldn't be changed not to only
> save/restore the options, but also save the opts_set flags.
> It could be done e.g. by adding a bool array or set of bool members
> to struct cl_optimization and struct cl_target_option , or even more compact
> by using bitmasks, pack each 64 adjacent option flags into a UHWI element
> of an array.

So, I've tried under debugger how it behaves and seems global_options_set
is really an or of whether an option has been ever seen as explicit, either
on the command line or in any of the option pragmas or optimize/target
attributes seen so far, so it isn't something that can be relied on.

The following patch implements the saving/restoring of the opts_set bits
(though only for the options/variables saved by the generic options-save.c
code, for the target specific stuff that isn't handled by the generic code
the opts_set argument is now passed to the hook and the backends can choose
e.g. to use a TargetSave variable to save the flags either individually or
together in some bitmask (or ignore it if they never need opts_set for the
options).

This patch itself doesn't fix the testcase failing on arm, but a follow up
patch will.

2020-09-14  Jakub Jelinek  <jakub@redhat.com>

gcc/
	* opt-read.awk: Also initialize extra_target_var_types array.
	* opth-gen.awk: Emit explicit_mask arrays to struct cl_optimization
	and cl_target_option.  Adjust cl_optimization_save,
	cl_optimization_restore, cl_target_option_save and
	cl_target_option_restore declarations.
	* optc-save-gen.awk: Add opts_set argument to cl_optimization_save,
	cl_optimization_restore, cl_target_option_save and
	cl_target_option_restore functions and save or restore opts_set
	next to the opts values into or from explicit_mask arrays.
	In cl_target_option_eq and cl_optimization_option_eq compare
	explicit_mask arrays, in cl_target_option_hash and cl_optimization_hash
	hash them and in cl_target_option_stream_out,
	cl_target_option_stream_in, cl_optimization_stream_out and
	cl_optimization_stream_in stream them.
	* tree.h (build_optimization_node, build_target_option_node): Add
	opts_set argument.
	* tree.c (build_optimization_node): Add opts_set argument, pass it
	to cl_optimization_save.
	(build_target_option_node): Add opts_set argument, pass it to
	cl_target_option_save.
	* function.c (invoke_set_current_function_hook): Adjust
	cl_optimization_restore caller.
	* ipa-inline-transform.c (inline_call): Adjust cl_optimization_restore
	and build_optimization_node callers.
	* target.def (TARGET_OPTION_SAVE, TARGET_OPTION_RESTORE): Add opts_set
	argument.
	* target-globals.c (save_target_globals_default_opts): Adjust
	cl_optimization_restore callers.
	* toplev.c (process_options): Adjust build_optimization_node and
	cl_optimization_restore callers.
	(target_reinit): Adjust cl_optimization_restore caller.
	* tree-streamer-in.c (lto_input_ts_function_decl_tree_pointers):
	Adjust build_optimization_node and cl_optimization_restore callers.
	* doc/tm.texi: Updated.
	* config/aarch64/aarch64.c (aarch64_override_options): Adjust
	build_target_option_node caller.
	(aarch64_option_save, aarch64_option_restore): Add opts_set argument.
	(aarch64_set_current_function): Adjust cl_target_option_restore
	caller.
	(aarch64_option_valid_attribute_p): Adjust cl_target_option_save,
	cl_target_option_restore, cl_optimization_restore,
	build_optimization_node and build_target_option_node callers.
	* config/aarch64/aarch64-c.c (aarch64_pragma_target_parse): Adjust
	cl_target_option_restore and build_target_option_node callers.
	* config/arm/arm.c (arm_option_save, arm_option_restore): Add
	opts_set argument.
	(arm_option_override): Adjust cl_target_option_save,
	build_optimization_node and build_target_option_node callers.
	(arm_set_current_function): Adjust cl_target_option_restore caller.
	(arm_valid_target_attribute_tree): Adjust build_target_option_node
	caller.
	(add_attribute): Formatting fix.
	(arm_valid_target_attribute_p): Adjust cl_optimization_restore,
	cl_target_option_restore, arm_valid_target_attribute_tree and
	build_optimization_node callers.
	* config/arm/arm-c.c (arm_pragma_target_parse): Adjust
	cl_target_option_restore callers.
	* config/csky/csky.c (csky_option_override): Adjust
	build_target_option_node and cl_target_option_save callers.
	* config/gcn/gcn.c (gcn_fixup_accel_lto_options): Adjust
	build_optimization_node and cl_optimization_restore callers.
	* config/i386/i386-builtins.c (get_builtin_code_for_version):
	Adjust cl_target_option_save and cl_target_option_restore
	callers.
	* config/i386/i386-c.c (ix86_pragma_target_parse): Adjust
	build_target_option_node and cl_target_option_restore callers.
	* config/i386/i386-options.c (ix86_function_specific_save,
	ix86_function_specific_restore): Add opts_set arguments.
	(ix86_valid_target_attribute_tree): Adjust build_target_option_node
	caller.
	(ix86_valid_target_attribute_p): Adjust build_optimization_node,
	cl_optimization_restore, cl_target_option_restore,
	ix86_valid_target_attribute_tree and build_optimization_node callers.
	(ix86_option_override_internal): Adjust build_target_option_node
	caller.
	(ix86_reset_previous_fndecl, ix86_set_current_function): Adjust
	cl_target_option_restore callers.
	* config/i386/i386-options.h (ix86_function_specific_save,
	ix86_function_specific_restore): Add opts_set argument.
	* config/nios2/nios2.c (nios2_option_override): Adjust
	build_target_option_node caller.
	(nios2_option_save, nios2_option_restore): Add opts_set argument.
	(nios2_valid_target_attribute_tree): Adjust build_target_option_node
	caller.
	(nios2_valid_target_attribute_p): Adjust build_optimization_node,
	cl_optimization_restore, cl_target_option_save and
	cl_target_option_restore callers.
	(nios2_set_current_function, nios2_pragma_target_parse): Adjust
	cl_target_option_restore callers.
	* config/pru/pru.c (pru_option_override): Adjust
	build_target_option_node caller.
	(pru_set_current_function): Adjust cl_target_option_restore
	callers.
	* config/rs6000/rs6000.c (rs6000_debug_reg_global): Adjust
	cl_target_option_save caller.
	(rs6000_option_override_internal): Adjust build_target_option_node
	caller.
	(rs6000_valid_attribute_p): Adjust build_optimization_node,
	cl_optimization_restore, cl_target_option_save,
	cl_target_option_restore and build_target_option_node callers.
	(rs6000_pragma_target_parse): Adjust cl_target_option_restore and
	build_target_option_node callers.
	(rs6000_activate_target_options): Adjust cl_target_option_restore
	callers.
	(rs6000_function_specific_save, rs6000_function_specific_restore):
	Add opts_set argument.
	* config/s390/s390.c (s390_function_specific_restore): Likewise.
	(s390_option_override_internal): Adjust s390_function_specific_restore
	caller.
	(s390_option_override, s390_valid_target_attribute_tree): Adjust
	build_target_option_node caller.
	(s390_valid_target_attribute_p): Adjust build_optimization_node,
	cl_optimization_restore and cl_target_option_restore callers.
	(s390_activate_target_options): Adjust cl_target_option_restore
	caller.
	* config/s390/s390-c.c (s390_cpu_cpp_builtins): Adjust
	cl_target_option_save caller.
	(s390_pragma_target_parse): Adjust build_target_option_node and
	cl_target_option_restore callers.
gcc/c-family/
	* c-attribs.c (handle_optimize_attribute): Adjust
	cl_optimization_save, cl_optimization_restore and
	build_optimization_node callers.
	* c-pragma.c (handle_pragma_optimize): Adjust
	build_optimization_node caller.
	(handle_pragma_push_options): Adjust
	build_optimization_node and build_target_option_node callers.
	(handle_pragma_pop_options, handle_pragma_reset_options):
	Adjust cl_optimization_restore callers.
gcc/go/
	* go-gcc.cc (Gcc_backend::function): Adjust
	cl_optimization_save, cl_optimization_restore and
	build_optimization_node callers.
gcc/ada/
	* gcc-interface/trans.c (gigi): Adjust build_optimization_node
	caller.
2020-09-14 09:04:45 +02:00

148 lines
4.3 KiB
C

/* Target-dependent globals.
Copyright (C) 2010-2020 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "rtl.h"
#include "tree.h"
#include "expmed.h"
#include "optabs-query.h"
#include "insn-config.h"
#include "regs.h"
#include "memmodel.h"
#include "ira.h"
#include "ira-int.h"
#include "toplev.h"
#include "target-globals.h"
#include "flags.h"
#include "reload.h"
#include "libfuncs.h"
#include "cfgloop.h"
#include "builtins.h"
#include "gcse.h"
#include "bb-reorder.h"
#include "lower-subreg.h"
#include "function-abi.h"
#if SWITCHABLE_TARGET
class target_globals default_target_globals = {
&default_target_flag_state,
&default_target_regs,
&default_target_rtl,
&default_target_recog,
&default_target_hard_regs,
&default_target_function_abi_info,
&default_target_reload,
&default_target_expmed,
&default_target_optabs,
&default_target_libfuncs,
&default_target_cfgloop,
&default_target_ira,
&default_target_ira_int,
&default_target_builtins,
&default_target_gcse,
&default_target_bb_reorder,
&default_target_lower_subreg
};
class target_globals *
save_target_globals (void)
{
class target_globals *g = ggc_cleared_alloc <target_globals> ();
g->flag_state = XCNEW (class target_flag_state);
g->regs = XCNEW (struct target_regs);
g->rtl = ggc_cleared_alloc<target_rtl> ();
g->recog = XCNEW (struct target_recog);
g->hard_regs = XCNEW (struct target_hard_regs);
g->function_abi_info = XCNEW (struct target_function_abi_info);
g->reload = XCNEW (struct target_reload);
g->expmed = XCNEW (struct target_expmed);
g->optabs = XCNEW (struct target_optabs);
g->libfuncs = ggc_cleared_alloc<target_libfuncs> ();
g->cfgloop = XCNEW (struct target_cfgloop);
g->ira = XCNEW (struct target_ira);
g->ira_int = XCNEW (class target_ira_int);
g->builtins = XCNEW (struct target_builtins);
g->gcse = XCNEW (struct target_gcse);
g->bb_reorder = XCNEW (struct target_bb_reorder);
g->lower_subreg = XCNEW (struct target_lower_subreg);
restore_target_globals (g);
init_reg_sets ();
target_reinit ();
return g;
}
/* Like save_target_globals() above, but set *this_target_optabs
correctly when a previous function has changed
*this_target_optabs. */
class target_globals *
save_target_globals_default_opts ()
{
class target_globals *globals;
if (optimization_current_node != optimization_default_node)
{
tree opts = optimization_current_node;
/* Temporarily switch to the default optimization node, so that
*this_target_optabs is set to the default, not reflecting
whatever a previous function used for the optimize
attribute. */
optimization_current_node = optimization_default_node;
cl_optimization_restore
(&global_options, &global_options_set,
TREE_OPTIMIZATION (optimization_default_node));
globals = save_target_globals ();
optimization_current_node = opts;
cl_optimization_restore (&global_options, &global_options_set,
TREE_OPTIMIZATION (opts));
return globals;
}
return save_target_globals ();
}
target_globals::~target_globals ()
{
/* default_target_globals points to static data so shouldn't be freed. */
if (this != &default_target_globals)
{
ira_int->~target_ira_int ();
hard_regs->finalize ();
XDELETE (flag_state);
XDELETE (regs);
XDELETE (recog);
XDELETE (hard_regs);
XDELETE (function_abi_info);
XDELETE (reload);
XDELETE (expmed);
XDELETE (optabs);
XDELETE (cfgloop);
XDELETE (ira);
XDELETE (ira_int);
XDELETE (builtins);
XDELETE (gcse);
XDELETE (bb_reorder);
XDELETE (lower_subreg);
}
}
#endif