3 Copyright (C) 2009-2015 Free Software Foundation, Inc.
4 Contributed by Simon Baldwin <simonb@google.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
30 #include "lto-streamer.h"
32 #include "fold-const.h"
33 #include "internal-fn.h"
36 #include "common/common-target.h"
37 #include "lto-section-names.h"
40 /* Append the option piece OPT to the COLLECT_GCC_OPTIONS string
41 set up by OB, appropriately quoted and separated by spaces
45 append_to_collect_gcc_options (struct obstack
*ob
,
46 bool *first_p
, const char *opt
)
48 const char *p
, *q
= opt
;
50 obstack_grow (ob
, " ", 1);
51 obstack_grow (ob
, "'", 1);
52 while ((p
= strchr (q
, '\'')))
54 obstack_grow (ob
, q
, p
- q
);
55 obstack_grow (ob
, "'\\''", 4);
58 obstack_grow (ob
, q
, strlen (q
));
59 obstack_grow (ob
, "'", 1);
63 /* Write currently held options to an LTO IL section. */
66 lto_write_options (void)
69 struct obstack temporary_obstack
;
74 section_name
= lto_get_section_name (LTO_section_opts
, NULL
, NULL
);
75 lto_begin_section (section_name
, false);
77 obstack_init (&temporary_obstack
);
79 /* Output options that affect GIMPLE IL semantics and are implicitly
80 enabled by the frontend.
81 This for now includes an explicit set of options that we also handle
82 explicitly in lto-wrapper.c. In the end the effects on GIMPLE IL
83 semantics should be explicitely encoded in the IL or saved per
84 function rather than per compilation unit. */
85 /* -fexceptions causes the EH machinery to be initialized, enabling
86 generation of unwind data so that explicit throw() calls work. */
87 if (!global_options_set
.x_flag_exceptions
88 && global_options
.x_flag_exceptions
)
89 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
91 /* -fnon-call-exceptions changes the generation of exception
92 regions. It is enabled implicitly by the Go frontend. */
93 if (!global_options_set
.x_flag_non_call_exceptions
94 && global_options
.x_flag_non_call_exceptions
)
95 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
96 "-fnon-call-exceptions");
97 /* The default -ffp-contract changes depending on the language
98 standard. Pass thru conservative standard settings. */
99 if (!global_options_set
.x_flag_fp_contract_mode
)
100 switch (global_options
.x_flag_fp_contract_mode
)
102 case FP_CONTRACT_OFF
:
103 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
104 "-ffp-contract=off");
107 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
110 case FP_CONTRACT_FAST
:
111 /* Nothing. That merges conservatively and is the default for LTO. */
116 /* The default -fmath-errno, -fsigned-zeros and -ftrapping-math change
117 depending on the language (they can be disabled by the Ada and Java
118 front-ends). Pass thru conservative standard settings. */
119 if (!global_options_set
.x_flag_errno_math
)
120 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
121 global_options
.x_flag_errno_math
123 : "-fno-math-errno");
124 if (!global_options_set
.x_flag_signed_zeros
)
125 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
126 global_options
.x_flag_signed_zeros
128 : "-fno-signed-zeros");
129 if (!global_options_set
.x_flag_trapping_math
)
130 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
131 global_options
.x_flag_trapping_math
133 : "-fno-trapping-math");
134 /* We need to merge -f[no-]strict-overflow, -f[no-]wrapv and -f[no-]trapv
135 conservatively, so stream out their defaults. */
136 if (!global_options_set
.x_flag_wrapv
137 && global_options
.x_flag_wrapv
)
138 append_to_collect_gcc_options (&temporary_obstack
, &first_p
, "-fwrapv");
139 if (!global_options_set
.x_flag_trapv
140 && !global_options
.x_flag_trapv
)
141 append_to_collect_gcc_options (&temporary_obstack
, &first_p
, "-fno-trapv");
142 if (!global_options_set
.x_flag_strict_overflow
143 && !global_options
.x_flag_strict_overflow
)
144 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
145 "-fno-strict-overflow");
147 if (!global_options_set
.x_flag_openmp
148 && !global_options
.x_flag_openmp
)
149 append_to_collect_gcc_options (&temporary_obstack
, &first_p
, "-fno-openmp");
150 if (!global_options_set
.x_flag_openacc
151 && !global_options
.x_flag_openacc
)
152 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
155 /* Append options from target hook and store them to offload_lto section. */
156 if (lto_stream_offload_p
)
158 char *offload_opts
= targetm
.offload_options ();
159 char *offload_ptr
= offload_opts
;
162 char *next
= strchr (offload_ptr
, ' ');
165 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
172 /* Output explicitly passed options. */
173 for (i
= 1; i
< save_decoded_options_count
; ++i
)
175 struct cl_decoded_option
*option
= &save_decoded_options
[i
];
177 /* Skip explicitly some common options that we do not need. */
178 switch (option
->opt_index
)
181 case OPT_SPECIAL_unknown
:
182 case OPT_SPECIAL_ignore
:
183 case OPT_SPECIAL_program_name
:
184 case OPT_SPECIAL_input_file
:
191 /* Skip frontend and driver specific options here. */
192 if (!(cl_options
[option
->opt_index
].flags
& (CL_COMMON
|CL_TARGET
|CL_LTO
)))
195 /* Do not store target-specific options in offload_lto section. */
196 if ((cl_options
[option
->opt_index
].flags
& CL_TARGET
)
197 && lto_stream_offload_p
)
200 /* Drop options created from the gcc driver that will be rejected
201 when passed on to the driver again. */
202 if (cl_options
[option
->opt_index
].cl_reject_driver
)
205 /* Also drop all options that are handled by the driver as well,
206 which includes things like -o and -v or -fhelp for example.
207 We do not need those. The only exception is -foffload option, if we
208 write it in offload_lto section. Also drop all diagnostic options. */
209 if ((cl_options
[option
->opt_index
].flags
& (CL_DRIVER
|CL_WARNING
))
210 && (!lto_stream_offload_p
|| option
->opt_index
!= OPT_foffload_
))
213 for (j
= 0; j
< option
->canonical_option_num_elements
; ++j
)
214 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
215 option
->canonical_option
[j
]);
217 obstack_grow (&temporary_obstack
, "\0", 1);
218 args
= XOBFINISH (&temporary_obstack
, char *);
219 lto_write_data (args
, strlen (args
) + 1);
222 obstack_free (&temporary_obstack
, NULL
);