gcc/gcc/lto-opts.c
Joseph Myers 677f3fa815 target-def.h (TARGET_HAVE_NAMED_SECTIONS): Move to common/common-target-def.h.
* target-def.h (TARGET_HAVE_NAMED_SECTIONS): Move to
	common/common-target-def.h.
	* target.def (default_target_flags, handle_option,
	supports_split_stack, optimization_table, init_struct,
	except_unwind_info, unwind_tables_default, have_named_sections):
	Move to common/common-target.def.
	* target.h (enum opt_levels, struct default_options): Move to
	common/common-target.h.
	* targhooks.c (default_except_unwind_info,
	dwarf2_except_unwind_info, sjlj_except_unwind_info,
	default_target_handle_option, empty_optimization_table): Move to
	common/common-targhooks.c.
	* targhooks.h (default_except_unwind_info,
	dwarf2_except_unwind_info, sjlj_except_unwind_info,
	default_target_handle_option, empty_optimization_table): Move to
	common/common-targhooks.h.
	* common/common-target-def.h: Include common/common-targhooks.h.
	(TARGET_HAVE_NAMED_SECTIONS): Define if TARGET_ASM_NAMED_SECTION
	defined.
	* common/common-target.def (handle_option, option_init_struct,
	option_optimization_table, default_target_flags,
	except_unwind_info, supports_split_stack, unwind_tables_default,
	have_named_sections): Move from target.def.
	(HOOK_PREFIX): Undefine at end of file.
	* common/common-target.h: Include input.h.
	(enum opt_levels, struct default_options): Move from target.h.
	* common/common-targhooks.c, common/common-targhooks.h: New.
	* config.gcc (target_has_targetm_common): Default to yes.
	(moxie*): Set target_has_targetm_common=no.
	(hppa*-*-*): Don't set target_has_targetm_common=yes.
	* doc/tm.texi: Regenerate.
	* Makefile.in (COMMON_TARGET_H): Add $(INPUT_H).
	(C_TARGET_DEF_H): Add common/common-targhooks.h.
	(GCC_OBJS): Remove vec.o.
	(OBJS): Remove hooks.o and vec.o.
	(OBJS-libcommon-target): Add vec.o, hooks.o and
	common/common-targhooks.o.
	(c-family/c-common.o, c-family/c-cppbuiltin.o, lto-opts.o, tree.o,
	tree-tailcall.o, opts.o, toplev.o, varasm.o, function.o, except.o,
	expr.o, explow.o, dbxout.o, dwarf2out.o, cfgrtl.o, haifa-sched.o,
	cfglayout.o, $(out_object_file), $(common_out_object_file)):
	Update dependencies.
	(common/common-targhooks.o): New.
	* common/config/default-common.c: Include tm.h.  Add FIXME
	comment.
	* common/config/pa/pa-common.c: Include more headers.  Take
	copyright dates from pa.c.
	(pa_option_optimization_table, pa_handle_option,
	TARGET_OPTION_OPTIMIZATION_TABLE, TARGET_DEFAULT_TARGET_FLAGS,
	TARGET_HANDLE_OPTION): Move from pa.c.
	* common/config/alpha/alpha-common.c,
	common/config/arm/arm-common.c, common/config/avr/avr-common.c,
	common/config/bfin/bfin-common.c,
	common/config/cris/cris-common.c,
	common/config/fr30/fr30-common.c, common/config/frv/frv-common.c,
	common/config/h8300/h8300-common.c,
	common/config/i386/i386-common.c,
	common/config/ia64/ia64-common.c,
	common/config/iq2000/iq2000-common.c,
	common/config/lm32/lm32-common.c,
	common/config/m32c/m32c-common.c,
	common/config/m32r/m32r-common.c,
	common/config/m68k/m68k-common.c,
	common/config/mcore/mcore-common.c,
	common/config/mep/mep-common.c,
	common/config/microblaze/microblaze-common.c,
	common/config/mips/mips-common.c,
	common/config/mmix/mmix-common.c,
	common/config/mn10300/mn10300-common.c,
	common/config/pdp11/pdp11-common.c,
	common/config/picochip/picochip-common.c,
	common/config/rs6000/rs6000-common.c,
	common/config/rx/rx-common.c, common/config/s390/s390-common.c,
	common/config/score/score-common.c, common/config/sh/sh-common.c,
	common/config/sparc/sparc-common.c,
	common/config/spu/spu-common.c, common/config/v850/v850-common.c,
	common/config/vax/vax-common.c,
	common/config/xstormy16/xstormy16-common.c,
	common/config/xtensa/xtensa-common.c: New.
	* config/alpha/alpha.c: Include common/common-target.h.
	(alpha_option_optimization_table, alpha_handle_option,
	TARGET_DEFAULT_TARGET_FLAGS, TARGET_HANDLE_OPTION,
	TARGET_OPTION_OPTIMIZATION_TABLE): Move to alpha-common.c.
	* config/arm/arm-protos.h (arm_except_unwind_info): Declare.
	* config/arm/arm.c (arm_option_optimization_table,
	TARGET_DEFAULT_TARGET_FLAGS, TARGET_OPTION_OPTIMIZATION_TABLE,
	TARGET_EXCEPT_UNWIND_INFO, arm_except_unwind_info): Move to
	arm-common.c.
	* config/avr/avr.c (avr_option_optimization_table,
	TARGET_OPTION_OPTIMIZATION_TABLE, TARGET_EXCEPT_UNWIND_INFO): Move
	to avr-common.c.
	* config/bfin/bfin.c (struct bfin_cpu): Move to bfin.h.
	(bfin_cpus, bfin_handle_option, TARGET_HANDLE_OPTION,
	TARGET_DEFAULT_TARGET_FLAGS): Move to bfin-common.c.
	* config/bfin/bfin.h struct bfin_cpu): Move from bfin.c.
	* config/cris/cris.c (cris_option_optimization_table,
	TARGET_DEFAULT_TARGET_FLAGS, TARGET_HANDLE_OPTION,
	TARGET_OPTION_OPTIMIZATION_TABLE, cris_handle_option): Move to
	cris-common.c.
	* config/fr30/fr30.c (fr30_option_optimization_table,
	TARGET_EXCEPT_UNWIND_INFO, TARGET_OPTION_OPTIMIZATION_TABLE): Move
	to fr30-common.c.
	* config/frv/frv.c (frv_option_optimization_table,
	MASK_DEFAULT_ALLOC_CC, TARGET_DEFAULT_TARGET_FLAGS,
	TARGET_OPTION_OPTIMIZATION_TABLE): Move to frv-common.c.
	* config/h8300/h8300.c (h8300_option_optimization_table,
	TARGET_DEFAULT_TARGET_FLAGS, TARGET_OPTION_OPTIMIZATION_TABLE,
	TARGET_EXCEPT_UNWIND_INFO): Move to h8300-common.c.
	* config/i386/i386-protos.h (ix86_handle_option): Declare.
	* config/i386/i386.c: Include common/common-target.h.
	(OPTION_MASK_ISA_MMX_SET, OPTION_MASK_ISA_3DNOW_SET,
	OPTION_MASK_ISA_SSE_SET, OPTION_MASK_ISA_SSE2_SET,
	OPTION_MASK_ISA_SSE3_SET, OPTION_MASK_ISA_SSSE3_SET,
	OPTION_MASK_ISA_SSE4_1_SET, OPTION_MASK_ISA_SSE4_2_SET,
	OPTION_MASK_ISA_AVX_SET, OPTION_MASK_ISA_FMA_SET,
	OPTION_MASK_ISA_SSE4_SET, OPTION_MASK_ISA_SSE4A_SET,
	OPTION_MASK_ISA_FMA4_SET, OPTION_MASK_ISA_XOP_SET,
	OPTION_MASK_ISA_LWP_SET, OPTION_MASK_ISA_AES_SET,
	OPTION_MASK_ISA_PCLMUL_SET, OPTION_MASK_ISA_ABM_SET,
	OPTION_MASK_ISA_BMI_SET, OPTION_MASK_ISA_TBM_SET,
	OPTION_MASK_ISA_POPCNT_SET, OPTION_MASK_ISA_CX16_SET,
	OPTION_MASK_ISA_SAHF_SET, OPTION_MASK_ISA_MOVBE_SET,
	OPTION_MASK_ISA_CRC32_SET, OPTION_MASK_ISA_FSGSBASE_SET,
	OPTION_MASK_ISA_RDRND_SET, OPTION_MASK_ISA_F16C_SET,
	OPTION_MASK_ISA_MMX_UNSET, OPTION_MASK_ISA_3DNOW_UNSET,
	OPTION_MASK_ISA_3DNOW_A_UNSET, OPTION_MASK_ISA_SSE_UNSET,
	OPTION_MASK_ISA_SSE2_UNSET, OPTION_MASK_ISA_SSE3_UNSET,
	OPTION_MASK_ISA_SSSE3_UNSET, OPTION_MASK_ISA_SSE4_1_UNSET,
	OPTION_MASK_ISA_SSE4_2_UNSET, OPTION_MASK_ISA_AVX_UNSET,
	OPTION_MASK_ISA_FMA_UNSET, OPTION_MASK_ISA_SSE4_UNSET,
	OPTION_MASK_ISA_SSE4A_UNSET, OPTION_MASK_ISA_FMA4_UNSET,
	OPTION_MASK_ISA_XOP_UNSET, OPTION_MASK_ISA_LWP_UNSET,
	OPTION_MASK_ISA_AES_UNSET, OPTION_MASK_ISA_PCLMUL_UNSET,
	OPTION_MASK_ISA_ABM_UNSET, OPTION_MASK_ISA_BMI_UNSET,
	OPTION_MASK_ISA_TBM_UNSET, OPTION_MASK_ISA_POPCNT_UNSET,
	OPTION_MASK_ISA_CX16_UNSET, OPTION_MASK_ISA_SAHF_UNSET,
	OPTION_MASK_ISA_MOVBE_UNSET, OPTION_MASK_ISA_CRC32_UNSET,
	OPTION_MASK_ISA_FSGSBASE_UNSET, OPTION_MASK_ISA_RDRND_UNSET,
	OPTION_MASK_ISA_F16C_UNSET, ix86_handle_option,
	ix86_option_optimization_table, ix86_option_init_struct,
	ix86_supports_split_stack, TARGET_DEFAULT_TARGET_FLAGS,
	TARGET_HANDLE_OPTION, TARGET_OPTION_OPTIMIZATION_TABLE,
	TARGET_OPTION_INIT_STRUCT, TARGET_SUPPORTS_SPLIT_STACK): Move to
	i386-common.c.
	* config/i386/t-i386 (i386.o): Update dependencies.
	* config/ia64/ia64-protos.h (ia64_except_unwind_info): Declare.
	* config/ia64/ia64.c (ia64_option_optimization_table,
	TARGET_OPTION_OPTIMIZATION_TABLE, TARGET_EXCEPT_UNWIND_INFO,
	TARGET_DEFAULT_TARGET_FLAGS, TARGET_HANDLE_OPTION,
	ia64_handle_option): Move to ia64-common.c.
	* config/iq2000/iq2000.c (iq2000_option_optimization_table,
	TARGET_OPTION_OPTIMIZATION_TABLE): Move to iq2000-common.c.
	* config/lm32/lm32.c (lm32_option_optimization_table,
	TARGET_OPTION_OPTIMIZATION_TABLE, TARGET_EXCEPT_UNWIND_INFO): Move
	to lm32-common.c.
	* config/m32c/m32c.c (TARGET_HAVE_NAMED_SECTIONS): Move to
	m32c-common.c.
	* config/m32r/m32r.c (m32r_option_optimization_table,
	TARGET_DEFAULT_TARGET_FLAGS, TARGET_HANDLE_OPTION,
	TARGET_OPTION_OPTIMIZATION_TABLE, TARGET_EXCEPT_UNWIND_INFO,
	m32r_handle_option): Move to m32r-common.c.
	(m32r_memory_move_cost): Remove comment referring to
	TARGET_HANDLE_OPTION.
	* config/m68k/m68k.c (TARGET_HANDLE_OPTION, m68k_handle_option):
	Move to m68k-common.c.
	* config/mcore/mcore.c (mcore_option_optimization_table,
	TARGET_DEFAULT_TARGET_FLAGS, TARGET_OPTION_OPTIMIZATION_TABLE,
	TARGET_EXCEPT_UNWIND_INFO): Move to mcore-common.c.
	* config/mep/mep.c (mep_option_optimization_table,
	mep_handle_option, TARGET_HANDLE_OPTION,
	TARGET_OPTION_OPTIMIZATION_TABLE, TARGET_DEFAULT_TARGET_FLAGS):
	Move to mep-common.c.
	* config/microblaze/microblaze.c
	(microblaze_option_optimization_table,
	TARGET_DEFAULT_TARGET_FLAGS, TARGET_OPTION_OPTIMIZATION_TABLE,
	TARGET_EXCEPT_UNWIND_INFO): Move to microblaze-common.c.
	* config/mips/mips.c (mips_handle_option,
	mips_option_optimization_table, TARGET_OPTION_OPTIMIZATION_TABLE,
	TARGET_DEFAULT_TARGET_FLAGS, TARGET_HANDLE_OPTION): Move to
	mips-common.c.
	* config/mmix/mmix.c (mmix_option_optimization_table,
	TARGET_DEFAULT_TARGET_FLAGS, TARGET_OPTION_OPTIMIZATION_TABLE):
	Move to mmix-common.c.
	* config/mn10300/mn10300.c (mn10300_option_optimization_table,
	mn10300_handle_option, TARGET_EXCEPT_UNWIND_INFO,
	TARGET_DEFAULT_TARGET_FLAGS, TARGET_HANDLE_OPTION,
	TARGET_OPTION_OPTIMIZATION_TABLE): Move to mn10300-common.c.
	* config/pa/pa.c: Include common/common-target.h.
	(pa_option_optimization_table, TARGET_OPTION_OPTIMIZATION_TABLE,
	TARGET_DEFAULT_TARGET_FLAGS, TARGET_HANDLE_OPTION,
	pa_handle_option): Move to pa-common.c.
	(pa_option_override): Use targetm_common.except_unwind_info.
	(pa_asm_output_mi_thunk, pa_function_section): Use
	targetm_common.have_named_sections.
	* config/pdp11/pdp11.c (pdp11_option_optimization_table,
	TARGET_DEFAULT_TARGET_FLAGS, TARGET_HANDLE_OPTION,
	TARGET_OPTION_OPTIMIZATION_TABLE, TARGET_OPTION_INIT_STRUCT,
	pdp11_handle_option, pdp11_option_init_struct): Move to
	pdp11-common.c.
	* config/picochip/picochip.c (picochip_option_optimization_table,
	TARGET_HAVE_NAMED_SECTIONS, TARGET_OPTION_OPTIMIZATION_TABLE,
	TARGET_EXCEPT_UNWIND_INFO): Move to picochip-common.c.
	* config/rs6000/rs6000.c: Include common/common-target.h.
	(rs6000_option_optimization_table, TARGET_HANDLE_OPTION,
	TARGET_OPTION_INIT_STRUCT, TARGET_OPTION_OPTIMIZATION_TABLE,
	TARGET_DEFAULT_TARGET_FLAGS, rs6000_option_init_struct,
	rs6000_handle_option): Move to rs6000-common.c.
	* config/rs6000/t-rs6000 (rs6000.o): Update dependencies.
	* config/rx/rx.c (rx_handle_option, rx_option_optimization_table,
	TARGET_HANDLE_OPTION, TARGET_OPTION_OPTIMIZATION_TABLE,
	TARGET_EXCEPT_UNWIND_INFO): Move to rx-common.c.
	* config/s390/s390.c (processor_flags_table,
	s390_option_optimization_table, s390_option_init_struct,
	s390_handle_option, TARGET_DEFAULT_TARGET_FLAGS,
	TARGET_HANDLE_OPTION, TARGET_OPTION_OPTIMIZATION_TABLE,
	TARGET_OPTION_INIT_STRUCT): Move to s390-common.c.
	* config/s390/s390.h (processor_flags_table): Declare.
	* config/score/score.c (score_option_optimization_table,
	TARGET_DEFAULT_TARGET_FLAGS, TARGET_HANDLE_OPTION,
	TARGET_OPTION_OPTIMIZATION_TABLE, MASK_ALL_CPU_BITS,
	score_handle_option): Move to score-common.c.
	* config/sh/sh.c (sh_option_optimization_table,
	TARGET_OPTION_OPTIMIZATION_TABLE, TARGET_OPTION_INIT_STRUCT,
	TARGET_DEFAULT_TARGET_FLAGS, TARGET_HANDLE_OPTION,
	sh_handle_option, sh_option_init_struct): Move to sh-common.c.
	* config/sparc/sparc.c: Include common/common-target.h.
	(sparc_option_optimization_table, TARGET_DEFAULT_TARGET_FLAGS,
	TARGET_OPTION_OPTIMIZATION_TABLE): Move to sparc-common.c.
	* config/spu/spu.c (TARGET_DEFAULT_TARGET_FLAGS,
	TARGET_OPTION_INIT_STRUCT, TARGET_EXCEPT_UNWIND_INFO,
	spu_option_init_struct): Move to spu-common.c.
	* config/stormy16/stormy16.c (xstorym16_option_optimization_table,
	TARGET_OPTION_OPTIMIZATION_TABLE): Move to xstormy16-common.c.
	* config/v850/v850.c (small_memory_physical_max,
	v850_handle_memory_optionn v850_handle_option,
	v850_option_optimization_table, TARGET_DEFAULT_TARGET_FLAGS,
	TARGET_HANDLE_OPTION, TARGET_OPTION_OPTIMIZATION_TABLE): Move to
	v850-common.c.
	* config/vax/vax.c (TARGET_DEFAULT_TARGET_FLAGS): Move to
	vax-common.c.
	* config/xtensa/xtensa.c (xtensa_option_optimization_table,
	TARGET_DEFAULT_TARGET_FLAGS, TARGET_OPTION_OPTIMIZATION_TABLE):
	Move to xtensa-common.c.
	* cfglayout.c: Include common/common-target.h.
	(fixup_reorder_chain): Use targetm_common.have_named_sections.
	* cfgrtl.c: Include common/common-target.h.
	(force_nonfallthru_and_redirect, commit_one_edge_insertion): Use
	targetm_common.have_named_sections.
	* dbxout.c: Include common/common-target.h.
	(dbxout_function_end): Use targetm_common.have_named_sections.
	* defaults.h (STACK_OLD_CHECK_PROTECT, STACK_CHECK_PROTECT): Use
	targetm_common.except_unwind_info.
	* dwarf2out.c: Include common/common-target.h.
	(dwarf2out_do_frame, dwarf2out_do_cfi_asm,
	dwarf2out_begin_prologue, dwarf2out_frame_init,
	dwarf2out_frame_finish, dwarf2out_assembly_start): Use
	targetm_common.except_unwind_info.
	* except.c: Include common/common-target.h.
	(init_eh, finish_eh_generation,
	output_one_function_exception_table): Use
	targetm_common.except_unwind_info.
	(switch_to_exception_section): Use
	targetm_common.have_named_sections.
	* explow.c: Include common/common-target.h.
	* expr.c: Include common/common-target.h.
	(build_personality_function): Use
	targetm_common.except_unwind_info.
	* function.c: Include common/common-target.h.
	(expand_function_end): Use targetm_common.except_unwind_info.
	* haifa-sched.c: Include common/common-target.h.
	(sched_create_recovery_edges): Use
	targetm_common.have_named_sections.
	* lto-opts.c: Include common/common-target.h instead of target.h.
	(lto_reissue_options): Use targetm_common.handle_option.
	* opts.c: Include common/common-target.h.
	(target_handle_option): Use targetm_common.handle_option.
	(init_options_struct): Update comment referring to
	targetm.target_option.optimization.  Use
	targetm_common.default_target_flags,
	targetm_common.unwind_tables_default and
	targetm_common.option_init_struct.
	(default_options_optimization): Use
	targetm_common.option_optimization_table.
	(finish_options): Use targetm_common.except_unwind_info,
	targetm_common.unwind_tables_default,
	targetm_common.have_named_sections and
	targetm_common.supports_split_stack.
	* toplev.c: Include common/common-target.h.
	(process_options): Use targetm_common.have_named_sections.
	* tree-tailcall.c: Include common/common-target.h.
	(suitable_for_tail_call_opt_p): Use
	targetm_common.except_unwind_info.
	* tree.c: Include common/common-target.h.
	(build_common_builtin_nodes): Use
	targetm_common.except_unwind_info.
	* varasm.c: Include common/common-target.h.
	(resolve_unique_section, hot_function_section,
	default_function_section): Use targetm_common.have_named_sections.

ada:
	* gcc-interface/Make-lang.in (gnatbind$(exeext)): Use ggc-none.o.
	(ada/utils.o): Update dependencies.
	* gcc-interface/Makefile.in (EXTRA_GNATTOOLS_OBJS): Add
	../../../libcpp/libcpp.a.
	* gcc-interface/utils.c: Include common/common-target.h.
	(process_attributes): Use targetm_common.have_named_sections.

c-family:
	* c-common.c: Include common/common-target.h.
	(handle_section_attribute): Use
	targetm_common.have_named_sections.
	* c-cppbuiltin.c: Include common/common-target.h.
	(c_cpp_builtins): Use targetm_common.except_unwind_info.

cp:
	* Make-lang.in (cp/method.o): Update dependencies.
	* method.c: Include common/common-target.h.
	(use_thunk): Use targetm_common.have_named_sections.

go:
	* Make-lang.in (go/go-lang.o, go/go-backend.o): Update
	dependencies.
	* go-backend.c: Include common/common-target.h.
	(go_write_export_data): Use targetm_common.have_named_sections.
	* go-lang.c: Include common/common-target.h.
	(go_langhook_init_options_struct): Use
	targetm_common.supports_split_stack.

po:
	* exgettext: Handle common/ directory and subdirectories.

From-SVN: r175064
2011-06-15 00:11:35 +01:00

423 lines
12 KiB
C

/* LTO IL options.
Copyright 2009, 2010, 2011 Free Software Foundation, Inc.
Contributed by Simon Baldwin <simonb@google.com>
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 "tree.h"
#include "hashtab.h"
#include "ggc.h"
#include "vec.h"
#include "bitmap.h"
#include "flags.h"
#include "opts.h"
#include "options.h"
#include "common/common-target.h"
#include "diagnostic.h"
#include "lto-streamer.h"
/* When a file is initially compiled, the options used when generating
the IL are not necessarily the same as those used when linking the
objects into the final executable. In general, most build systems
will proceed with something along the lines of:
$ gcc <cc-flags> -flto -c f1.c -o f1.o
$ gcc <cc-flags> -flto -c f2.c -o f2.o
...
$ gcc <cc-flags> -flto -c fN.c -o fN.o
And the final link may or may not include the same <cc-flags> used
to generate the initial object files:
$ gcc <ld-flags> -flto -o prog f1.o ... fN.o
Since we will be generating final code during the link step, some
of the flags used during the compile step need to be re-applied
during the link step. For instance, flags in the -m family.
The idea is to save a selected set of <cc-flags> in a special
section of the initial object files. This section is then read
during linking and the options re-applied.
FIXME lto. Currently the scheme is limited in that only the
options saved on the first object file (f1.o) are read back during
the link step. This means that the options used to compile f1.o
will be applied to ALL the object files in the final link step.
More work needs to be done to implement a merging and validation
mechanism, as this will not be enough for all cases. */
/* Saved options hold the type of the option (currently CL_TARGET or
CL_COMMON), and the code, argument, and value. */
typedef struct GTY(()) opt_d
{
unsigned int type;
size_t code;
char *arg;
int value;
} opt_t;
DEF_VEC_O (opt_t);
DEF_VEC_ALLOC_O (opt_t, heap);
/* Options are held in two vectors, one for those registered by
command line handling code, and the other for those read in from
any LTO IL input. */
static VEC(opt_t, heap) *user_options = NULL;
static VEC(opt_t, heap) *file_options = NULL;
/* Iterate FROM in reverse, writing option codes not yet in CODES into *TO.
Mark each new option code encountered in CODES. */
static void
reverse_iterate_options (VEC(opt_t, heap) *from, VEC(opt_t, heap) **to,
bitmap codes)
{
int i;
for (i = VEC_length (opt_t, from); i > 0; i--)
{
const opt_t *const o = VEC_index (opt_t, from, i - 1);
if (bitmap_set_bit (codes, o->code))
VEC_safe_push (opt_t, heap, *to, o);
}
}
/* Concatenate options vectors FIRST and SECOND, rationalize so that only the
final of any given option remains, and return the result. */
static VEC(opt_t, heap) *
concatenate_options (VEC(opt_t, heap) *first, VEC(opt_t, heap) *second)
{
VEC(opt_t, heap) *results = NULL;
bitmap codes = lto_bitmap_alloc ();
reverse_iterate_options (second, &results, codes);
reverse_iterate_options (first, &results, codes);
lto_bitmap_free (codes);
return results;
}
/* Clear the options vector in *OPTS_P and set it to NULL. */
static void
clear_options (VEC(opt_t, heap) **opts_p)
{
int i;
opt_t *o;
FOR_EACH_VEC_ELT (opt_t, *opts_p, i, o)
free (o->arg);
VEC_free (opt_t, heap, *opts_p);
}
/* Write LENGTH bytes from ADDR to STREAM. */
static void
output_data_stream (struct lto_output_stream *stream,
const void *addr, size_t length)
{
lto_output_data_stream (stream, addr, length);
}
/* Write string STRING to STREAM. */
static void
output_string_stream (struct lto_output_stream *stream, const char *string)
{
bool flag = false;
if (string != NULL)
{
const size_t length = strlen (string);
flag = true;
output_data_stream (stream, &flag, sizeof (flag));
output_data_stream (stream, &length, sizeof (length));
output_data_stream (stream, string, length);
}
else
output_data_stream (stream, &flag, sizeof (flag));
}
/* Return a string from IB. The string is allocated, and the caller is
responsible for freeing it. */
static char *
input_string_block (struct lto_input_block *ib)
{
bool flag;
lto_input_data_block (ib, &flag, sizeof (flag));
if (flag)
{
size_t length;
char *string;
lto_input_data_block (ib, &length, sizeof (length));
string = (char *) xcalloc (1, length + 1);
lto_input_data_block (ib, string, length);
return string;
}
else
return NULL;
}
/* Return true if this option is one we need to save in LTO output files.
At present, we pass along all target options, and common options that
involve position independent code.
TODO This list of options requires expansion and rationalization.
Among others, optimization options may well be appropriate here. */
static bool
register_user_option_p (size_t code, unsigned int type)
{
if (type == CL_TARGET)
return true;
else if (type == CL_COMMON)
{
return (code == OPT_fPIC
|| code == OPT_fpic
|| code == OPT_fPIE
|| code == OPT_fpie
|| code == OPT_fcommon
|| code == OPT_fexceptions);
}
return false;
}
/* Note command line option with the given TYPE and CODE, ARG, and VALUE.
If relevant to LTO, save it in the user options vector. */
void
lto_register_user_option (size_t code, const char *arg, int value,
unsigned int type)
{
if (register_user_option_p (code, type))
{
opt_t o;
o.type = type;
o.code = code;
if (arg != NULL)
{
o.arg = (char *) xmalloc (strlen (arg) + 1);
strcpy (o.arg, arg);
}
else
o.arg = NULL;
o.value = value;
VEC_safe_push (opt_t, heap, user_options, &o);
}
}
/* Empty the saved user options vector. */
void
lto_clear_user_options (void)
{
clear_options (&user_options);
}
/* Empty the saved file options vector. */
void
lto_clear_file_options (void)
{
clear_options (&file_options);
}
/* Concatenate the user options and any file options read from an LTO IL
file, and serialize them to STREAM. File options precede user options
so that the latter override the former when reissued. */
static void
output_options (struct lto_output_stream *stream)
{
VEC(opt_t, heap) *opts = concatenate_options (file_options, user_options);
const size_t length = VEC_length (opt_t, opts);
int i;
opt_t *o;
output_data_stream (stream, &length, sizeof (length));
FOR_EACH_VEC_ELT (opt_t, opts, i, o)
{
output_data_stream (stream, &o->type, sizeof (o->type));
output_data_stream (stream, &o->code, sizeof (o->code));
output_string_stream (stream, o->arg);
output_data_stream (stream, &o->value, sizeof (o->value));
}
VEC_free (opt_t, heap, opts);
}
/* Write currently held options to an LTO IL section. */
void
lto_write_options (void)
{
char *const section_name = lto_get_section_name (LTO_section_opts, NULL, NULL);
struct lto_output_stream stream;
struct lto_simple_header header;
struct lto_output_stream *header_stream;
/* Targets and languages can provide defaults for -fexceptions but
we only process user options from the command-line. Until we
serialize out a white list of options from the new global state
explicitly append important options as user options here. */
if (flag_exceptions)
lto_register_user_option (OPT_fexceptions, NULL, 1, CL_COMMON);
lto_begin_section (section_name, !flag_wpa);
free (section_name);
memset (&stream, 0, sizeof (stream));
output_options (&stream);
memset (&header, 0, sizeof (header));
header.lto_header.major_version = LTO_major_version;
header.lto_header.minor_version = LTO_minor_version;
header.lto_header.section_type = LTO_section_opts;
header.compressed_size = 0;
header.main_size = stream.total_size;
header_stream = ((struct lto_output_stream *)
xcalloc (1, sizeof (*header_stream)));
lto_output_data_stream (header_stream, &header, sizeof (header));
lto_write_stream (header_stream);
free (header_stream);
lto_write_stream (&stream);
lto_end_section ();
}
/* Unserialize an options vector from IB, and append to file_options. */
static void
input_options (struct lto_input_block *ib)
{
size_t length, i;
lto_input_data_block (ib, &length, sizeof (length));
for (i = 0; i < length; i++)
{
opt_t o;
lto_input_data_block (ib, &o.type, sizeof (o.type));
lto_input_data_block (ib, &o.code, sizeof (o.code));
o.arg = input_string_block (ib);
lto_input_data_block (ib, &o.value, sizeof (o.value));
VEC_safe_push (opt_t, heap, file_options, &o);
}
}
/* Read options from an LTO IL section. */
void
lto_read_file_options (struct lto_file_decl_data *file_data)
{
size_t len, l, skip;
const char *data, *p;
const struct lto_simple_header *header;
int32_t opts_offset;
struct lto_input_block ib;
data = lto_get_section_data (file_data, LTO_section_opts, NULL, &len);
if (!data)
return;
/* Option could be multiple sections merged (through ld -r)
Keep reading all options. This is ok right now because
the options just get mashed together anyways.
This will have to be done differently once lto-opts knows
how to associate options with different files. */
l = len;
p = data;
do
{
header = (const struct lto_simple_header *) p;
opts_offset = sizeof (*header);
lto_check_version (header->lto_header.major_version,
header->lto_header.minor_version);
LTO_INIT_INPUT_BLOCK (ib, p + opts_offset, 0, header->main_size);
input_options (&ib);
skip = header->main_size + opts_offset;
l -= skip;
p += skip;
}
while (l > 0);
lto_free_section_data (file_data, LTO_section_opts, 0, data, len);
}
/* Concatenate the user options and any file options read from an LTO IL
file, and reissue them as if all had just been read in from the command
line. As with serialization, file options precede user options. */
void
lto_reissue_options (void)
{
VEC(opt_t, heap) *opts = concatenate_options (file_options, user_options);
int i;
opt_t *o;
FOR_EACH_VEC_ELT (opt_t, opts, i, o)
{
void *flag_var = option_flag_var (o->code, &global_options);
if (flag_var)
set_option (&global_options, &global_options_set,
o->code, o->value, o->arg,
DK_UNSPECIFIED, UNKNOWN_LOCATION, global_dc);
if (o->type == CL_TARGET)
{
struct cl_decoded_option decoded;
generate_option (o->code, o->arg, o->value, CL_TARGET, &decoded);
targetm_common.handle_option (&global_options, &global_options_set,
&decoded, UNKNOWN_LOCATION);
}
else if (o->type == CL_COMMON)
gcc_assert (flag_var);
else
gcc_unreachable ();
}
/* Flag_shlib is usually set by finish_options, but we are issuing flag_pic
too late. */
if (flag_pic && !flag_pie)
flag_shlib = 1;
VEC_free (opt_t, heap, opts);
}