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"
28 #include "double-int.h"
36 #include "fold-const.h"
39 #include "hard-reg-set.h"
42 #include "basic-block.h"
43 #include "tree-ssa-alias.h"
44 #include "internal-fn.h"
45 #include "gimple-expr.h"
52 #include "common/common-target.h"
53 #include "diagnostic.h"
55 #include "plugin-api.h"
58 #include "lto-streamer.h"
59 #include "lto-section-names.h"
62 /* Append the option piece OPT to the COLLECT_GCC_OPTIONS string
63 set up by OB, appropriately quoted and separated by spaces
67 append_to_collect_gcc_options (struct obstack
*ob
,
68 bool *first_p
, const char *opt
)
70 const char *p
, *q
= opt
;
72 obstack_grow (ob
, " ", 1);
73 obstack_grow (ob
, "'", 1);
74 while ((p
= strchr (q
, '\'')))
76 obstack_grow (ob
, q
, p
- q
);
77 obstack_grow (ob
, "'\\''", 4);
80 obstack_grow (ob
, q
, strlen (q
));
81 obstack_grow (ob
, "'", 1);
85 /* Write currently held options to an LTO IL section. */
88 lto_write_options (void)
91 struct obstack temporary_obstack
;
96 section_name
= lto_get_section_name (LTO_section_opts
, NULL
, NULL
);
97 lto_begin_section (section_name
, false);
99 obstack_init (&temporary_obstack
);
101 /* Output options that affect GIMPLE IL semantics and are implicitly
102 enabled by the frontend.
103 This for now includes an explicit set of options that we also handle
104 explicitly in lto-wrapper.c. In the end the effects on GIMPLE IL
105 semantics should be explicitely encoded in the IL or saved per
106 function rather than per compilation unit. */
107 /* -fexceptions causes the EH machinery to be initialized, enabling
108 generation of unwind data so that explicit throw() calls work. */
109 if (!global_options_set
.x_flag_exceptions
110 && global_options
.x_flag_exceptions
)
111 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
113 /* -fnon-call-exceptions changes the generation of exception
114 regions. It is enabled implicitly by the Go frontend. */
115 if (!global_options_set
.x_flag_non_call_exceptions
116 && global_options
.x_flag_non_call_exceptions
)
117 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
118 "-fnon-call-exceptions");
119 /* The default -ffp-contract changes depending on the language
120 standard. Pass thru conservative standard settings. */
121 if (!global_options_set
.x_flag_fp_contract_mode
)
122 switch (global_options
.x_flag_fp_contract_mode
)
124 case FP_CONTRACT_OFF
:
125 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
126 "-ffp-contract=off");
129 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
132 case FP_CONTRACT_FAST
:
133 /* Nothing. That merges conservatively and is the default for LTO. */
138 /* The default -fmath-errno, -fsigned-zeros and -ftrapping-math change
139 depending on the language (they can be disabled by the Ada and Java
140 front-ends). Pass thru conservative standard settings. */
141 if (!global_options_set
.x_flag_errno_math
)
142 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
143 global_options
.x_flag_errno_math
145 : "-fno-math-errno");
146 if (!global_options_set
.x_flag_signed_zeros
)
147 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
148 global_options
.x_flag_signed_zeros
150 : "-fno-signed-zeros");
151 if (!global_options_set
.x_flag_trapping_math
)
152 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
153 global_options
.x_flag_trapping_math
155 : "-fno-trapping-math");
156 /* We need to merge -f[no-]strict-overflow, -f[no-]wrapv and -f[no-]trapv
157 conservatively, so stream out their defaults. */
158 if (!global_options_set
.x_flag_wrapv
159 && global_options
.x_flag_wrapv
)
160 append_to_collect_gcc_options (&temporary_obstack
, &first_p
, "-fwrapv");
161 if (!global_options_set
.x_flag_trapv
162 && !global_options
.x_flag_trapv
)
163 append_to_collect_gcc_options (&temporary_obstack
, &first_p
, "-fno-trapv");
164 if (!global_options_set
.x_flag_strict_overflow
165 && !global_options
.x_flag_strict_overflow
)
166 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
167 "-fno-strict-overflow");
169 /* Append options from target hook and store them to offload_lto section. */
170 if (lto_stream_offload_p
)
172 char *offload_opts
= targetm
.offload_options ();
173 char *offload_ptr
= offload_opts
;
176 char *next
= strchr (offload_ptr
, ' ');
179 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
186 /* Output explicitly passed options. */
187 for (i
= 1; i
< save_decoded_options_count
; ++i
)
189 struct cl_decoded_option
*option
= &save_decoded_options
[i
];
191 /* Skip explicitly some common options that we do not need. */
192 switch (option
->opt_index
)
195 case OPT_SPECIAL_unknown
:
196 case OPT_SPECIAL_ignore
:
197 case OPT_SPECIAL_program_name
:
198 case OPT_SPECIAL_input_file
:
205 /* Skip frontend and driver specific options here. */
206 if (!(cl_options
[option
->opt_index
].flags
& (CL_COMMON
|CL_TARGET
|CL_LTO
)))
209 /* Do not store target-specific options in offload_lto section. */
210 if ((cl_options
[option
->opt_index
].flags
& CL_TARGET
)
211 && lto_stream_offload_p
)
214 /* Drop options created from the gcc driver that will be rejected
215 when passed on to the driver again. */
216 if (cl_options
[option
->opt_index
].cl_reject_driver
)
219 /* Also drop all options that are handled by the driver as well,
220 which includes things like -o and -v or -fhelp for example.
221 We do not need those. The only exception is -foffload option, if we
222 write it in offload_lto section. Also drop all diagnostic options. */
223 if ((cl_options
[option
->opt_index
].flags
& (CL_DRIVER
|CL_WARNING
))
224 && (!lto_stream_offload_p
|| option
->opt_index
!= OPT_foffload_
))
227 for (j
= 0; j
< option
->canonical_option_num_elements
; ++j
)
228 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
229 option
->canonical_option
[j
]);
231 obstack_grow (&temporary_obstack
, "\0", 1);
232 args
= XOBFINISH (&temporary_obstack
, char *);
233 lto_write_data (args
, strlen (args
) + 1);
236 obstack_free (&temporary_obstack
, NULL
);