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"
34 /* Append the option piece OPT to the COLLECT_GCC_OPTIONS string
35 set up by OB, appropriately quoted and separated by spaces
39 append_to_collect_gcc_options (struct obstack
*ob
,
40 bool *first_p
, const char *opt
)
42 const char *p
, *q
= opt
;
44 obstack_grow (ob
, " ", 1);
45 obstack_grow (ob
, "'", 1);
46 while ((p
= strchr (q
, '\'')))
48 obstack_grow (ob
, q
, p
- q
);
49 obstack_grow (ob
, "'\\''", 4);
52 obstack_grow (ob
, q
, strlen (q
));
53 obstack_grow (ob
, "'", 1);
57 /* Write currently held options to an LTO IL section. */
60 lto_write_options (void)
63 struct obstack temporary_obstack
;
68 section_name
= lto_get_section_name (LTO_section_opts
, NULL
, NULL
);
69 lto_begin_section (section_name
, false);
71 obstack_init (&temporary_obstack
);
73 /* Output options that affect GIMPLE IL semantics and are implicitly
74 enabled by the frontend.
75 This for now includes an explicit set of options that we also handle
76 explicitly in lto-wrapper.c. In the end the effects on GIMPLE IL
77 semantics should be explicitely encoded in the IL or saved per
78 function rather than per compilation unit. */
79 /* -fexceptions causes the EH machinery to be initialized, enabling
80 generation of unwind data so that explicit throw() calls work. */
81 if (!global_options_set
.x_flag_exceptions
82 && global_options
.x_flag_exceptions
)
83 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
85 /* -fnon-call-exceptions changes the generation of exception
86 regions. It is enabled implicitly by the Go frontend. */
87 if (!global_options_set
.x_flag_non_call_exceptions
88 && global_options
.x_flag_non_call_exceptions
)
89 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
90 "-fnon-call-exceptions");
91 /* The default -ffp-contract changes depending on the language
92 standard. Pass thru conservative standard settings. */
93 if (!global_options_set
.x_flag_fp_contract_mode
)
94 switch (global_options
.x_flag_fp_contract_mode
)
97 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
101 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
104 case FP_CONTRACT_FAST
:
105 /* Nothing. That merges conservatively and is the default for LTO. */
110 /* The default -fmath-errno, -fsigned-zeros and -ftrapping-math change
111 depending on the language (they can be disabled by the Ada and Java
112 front-ends). Pass thru conservative standard settings. */
113 if (!global_options_set
.x_flag_errno_math
)
114 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
115 global_options
.x_flag_errno_math
117 : "-fno-math-errno");
118 if (!global_options_set
.x_flag_signed_zeros
)
119 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
120 global_options
.x_flag_signed_zeros
122 : "-fno-signed-zeros");
123 if (!global_options_set
.x_flag_trapping_math
)
124 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
125 global_options
.x_flag_trapping_math
127 : "-fno-trapping-math");
128 /* We need to merge -f[no-]strict-overflow, -f[no-]wrapv and -f[no-]trapv
129 conservatively, so stream out their defaults. */
130 if (!global_options_set
.x_flag_wrapv
131 && global_options
.x_flag_wrapv
)
132 append_to_collect_gcc_options (&temporary_obstack
, &first_p
, "-fwrapv");
133 if (!global_options_set
.x_flag_trapv
134 && !global_options
.x_flag_trapv
)
135 append_to_collect_gcc_options (&temporary_obstack
, &first_p
, "-fno-trapv");
136 if (!global_options_set
.x_flag_strict_overflow
137 && !global_options
.x_flag_strict_overflow
)
138 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
139 "-fno-strict-overflow");
141 if (!global_options_set
.x_flag_openmp
142 && !global_options
.x_flag_openmp
)
143 append_to_collect_gcc_options (&temporary_obstack
, &first_p
, "-fno-openmp");
144 if (!global_options_set
.x_flag_openacc
145 && !global_options
.x_flag_openacc
)
146 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
149 /* Append options from target hook and store them to offload_lto section. */
150 if (lto_stream_offload_p
)
152 char *offload_opts
= targetm
.offload_options ();
153 char *offload_ptr
= offload_opts
;
156 char *next
= strchr (offload_ptr
, ' ');
159 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
166 /* Output explicitly passed options. */
167 for (i
= 1; i
< save_decoded_options_count
; ++i
)
169 struct cl_decoded_option
*option
= &save_decoded_options
[i
];
171 /* Skip explicitly some common options that we do not need. */
172 switch (option
->opt_index
)
175 case OPT_SPECIAL_unknown
:
176 case OPT_SPECIAL_ignore
:
177 case OPT_SPECIAL_program_name
:
178 case OPT_SPECIAL_input_file
:
185 /* Skip frontend and driver specific options here. */
186 if (!(cl_options
[option
->opt_index
].flags
& (CL_COMMON
|CL_TARGET
|CL_LTO
)))
189 /* Do not store target-specific options in offload_lto section. */
190 if ((cl_options
[option
->opt_index
].flags
& CL_TARGET
)
191 && lto_stream_offload_p
)
194 /* Drop options created from the gcc driver that will be rejected
195 when passed on to the driver again. */
196 if (cl_options
[option
->opt_index
].cl_reject_driver
)
199 /* Also drop all options that are handled by the driver as well,
200 which includes things like -o and -v or -fhelp for example.
201 We do not need those. The only exception is -foffload option, if we
202 write it in offload_lto section. Also drop all diagnostic options. */
203 if ((cl_options
[option
->opt_index
].flags
& (CL_DRIVER
|CL_WARNING
))
204 && (!lto_stream_offload_p
|| option
->opt_index
!= OPT_foffload_
))
207 for (j
= 0; j
< option
->canonical_option_num_elements
; ++j
)
208 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
209 option
->canonical_option
[j
]);
211 obstack_grow (&temporary_obstack
, "\0", 1);
212 args
= XOBFINISH (&temporary_obstack
, char *);
213 lto_write_data (args
, strlen (args
) + 1);
216 obstack_free (&temporary_obstack
, NULL
);