2014-11-06 Steve Ellcey <sellcey@imgtec.com>
[official-gcc.git] / gcc / lto-opts.c
blobd1d153d04087f6f2db221b7608c61bc243642a32
1 /* LTO IL options.
3 Copyright (C) 2009-2014 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
11 version.
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
16 for more details.
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/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tree.h"
26 #include "predict.h"
27 #include "vec.h"
28 #include "hashtab.h"
29 #include "hash-set.h"
30 #include "machmode.h"
31 #include "tm.h"
32 #include "hard-reg-set.h"
33 #include "input.h"
34 #include "function.h"
35 #include "basic-block.h"
36 #include "tree-ssa-alias.h"
37 #include "internal-fn.h"
38 #include "gimple-expr.h"
39 #include "is-a.h"
40 #include "gimple.h"
41 #include "bitmap.h"
42 #include "flags.h"
43 #include "opts.h"
44 #include "options.h"
45 #include "common/common-target.h"
46 #include "diagnostic.h"
47 #include "hash-map.h"
48 #include "plugin-api.h"
49 #include "ipa-ref.h"
50 #include "cgraph.h"
51 #include "lto-streamer.h"
52 #include "toplev.h"
54 /* Append the option piece OPT to the COLLECT_GCC_OPTIONS string
55 set up by OB, appropriately quoted and separated by spaces
56 (if !*FIRST_P). */
58 static void
59 append_to_collect_gcc_options (struct obstack *ob,
60 bool *first_p, const char *opt)
62 const char *p, *q = opt;
63 if (!*first_p)
64 obstack_grow (ob, " ", 1);
65 obstack_grow (ob, "'", 1);
66 while ((p = strchr (q, '\'')))
68 obstack_grow (ob, q, p - q);
69 obstack_grow (ob, "'\\''", 4);
70 q = ++p;
72 obstack_grow (ob, q, strlen (q));
73 obstack_grow (ob, "'", 1);
74 *first_p = false;
77 /* Write currently held options to an LTO IL section. */
79 void
80 lto_write_options (void)
82 char *section_name;
83 struct obstack temporary_obstack;
84 unsigned int i, j;
85 char *args;
86 bool first_p = true;
88 section_name = lto_get_section_name (LTO_section_opts, NULL, NULL);
89 lto_begin_section (section_name, false);
91 obstack_init (&temporary_obstack);
93 /* Output options that affect GIMPLE IL semantics and are implicitly
94 enabled by the frontend.
95 This for now includes an explicit set of options that we also handle
96 explicitly in lto-wrapper.c. In the end the effects on GIMPLE IL
97 semantics should be explicitely encoded in the IL or saved per
98 function rather than per compilation unit. */
99 /* -fexceptions causes the EH machinery to be initialized, enabling
100 generation of unwind data so that explicit throw() calls work. */
101 if (!global_options_set.x_flag_exceptions
102 && global_options.x_flag_exceptions)
103 append_to_collect_gcc_options (&temporary_obstack, &first_p,
104 "-fexceptions");
105 /* -fnon-call-exceptions changes the generation of exception
106 regions. It is enabled implicitly by the Go frontend. */
107 if (!global_options_set.x_flag_non_call_exceptions
108 && global_options.x_flag_non_call_exceptions)
109 append_to_collect_gcc_options (&temporary_obstack, &first_p,
110 "-fnon-call-exceptions");
111 /* The default -ffp-contract changes depending on the language
112 standard. Pass thru conservative standard settings. */
113 if (!global_options_set.x_flag_fp_contract_mode)
114 switch (global_options.x_flag_fp_contract_mode)
116 case FP_CONTRACT_OFF:
117 append_to_collect_gcc_options (&temporary_obstack, &first_p,
118 "-ffp-contract=off");
119 break;
120 case FP_CONTRACT_ON:
121 append_to_collect_gcc_options (&temporary_obstack, &first_p,
122 "-ffp-contract=on");
123 break;
124 case FP_CONTRACT_FAST:
125 /* Nothing. That merges conservatively and is the default for LTO. */
126 break;
127 default:
128 gcc_unreachable ();
130 /* The default -fmath-errno, -fsigned-zeros and -ftrapping-math change
131 depending on the language (they can be disabled by the Ada and Java
132 front-ends). Pass thru conservative standard settings. */
133 if (!global_options_set.x_flag_errno_math)
134 append_to_collect_gcc_options (&temporary_obstack, &first_p,
135 global_options.x_flag_errno_math
136 ? "-fmath-errno"
137 : "-fno-math-errno");
138 if (!global_options_set.x_flag_signed_zeros)
139 append_to_collect_gcc_options (&temporary_obstack, &first_p,
140 global_options.x_flag_signed_zeros
141 ? "-fsigned-zeros"
142 : "-fno-signed-zeros");
143 if (!global_options_set.x_flag_trapping_math)
144 append_to_collect_gcc_options (&temporary_obstack, &first_p,
145 global_options.x_flag_trapping_math
146 ? "-ftrapping-math"
147 : "-fno-trapping-math");
148 /* We need to merge -f[no-]strict-overflow, -f[no-]wrapv and -f[no-]trapv
149 conservatively, so stream out their defaults. */
150 if (!global_options_set.x_flag_wrapv
151 && global_options.x_flag_wrapv)
152 append_to_collect_gcc_options (&temporary_obstack, &first_p, "-fwrapv");
153 if (!global_options_set.x_flag_trapv
154 && !global_options.x_flag_trapv)
155 append_to_collect_gcc_options (&temporary_obstack, &first_p, "-fno-trapv");
156 if (!global_options_set.x_flag_strict_overflow
157 && !global_options.x_flag_strict_overflow)
158 append_to_collect_gcc_options (&temporary_obstack, &first_p,
159 "-fno-strict-overflow");
161 /* Output explicitly passed options. */
162 for (i = 1; i < save_decoded_options_count; ++i)
164 struct cl_decoded_option *option = &save_decoded_options[i];
166 /* Skip explicitly some common options that we do not need. */
167 switch (option->opt_index)
169 case OPT_dumpbase:
170 case OPT_SPECIAL_unknown:
171 case OPT_SPECIAL_ignore:
172 case OPT_SPECIAL_program_name:
173 case OPT_SPECIAL_input_file:
174 continue;
176 default:
177 break;
180 /* Skip frontend and driver specific options here. */
181 if (!(cl_options[option->opt_index].flags & (CL_COMMON|CL_TARGET|CL_LTO)))
182 continue;
184 /* Drop options created from the gcc driver that will be rejected
185 when passed on to the driver again. */
186 if (cl_options[option->opt_index].cl_reject_driver)
187 continue;
189 /* Also drop all options that are handled by the driver as well,
190 which includes things like -o and -v or -fhelp for example.
191 We do not need those. Also drop all diagnostic options. */
192 if (cl_options[option->opt_index].flags & (CL_DRIVER|CL_WARNING))
193 continue;
195 for (j = 0; j < option->canonical_option_num_elements; ++j)
196 append_to_collect_gcc_options (&temporary_obstack, &first_p,
197 option->canonical_option[j]);
199 obstack_grow (&temporary_obstack, "\0", 1);
200 args = XOBFINISH (&temporary_obstack, char *);
201 lto_write_data (args, strlen (args) + 1);
202 lto_end_section ();
204 obstack_free (&temporary_obstack, NULL);
205 free (section_name);