]>
Commit | Line | Data |
---|---|---|
d7f09764 DN |
1 | /* LTO IL options. |
2 | ||
23a5b65a | 3 | Copyright (C) 2009-2014 Free Software Foundation, Inc. |
d7f09764 DN |
4 | Contributed by Simon Baldwin <simonb@google.com> |
5 | ||
6 | This file is part of GCC. | |
7 | ||
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. | |
12 | ||
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. | |
17 | ||
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/>. */ | |
21 | ||
22 | #include "config.h" | |
23 | #include "system.h" | |
24 | #include "coretypes.h" | |
25 | #include "tree.h" | |
2fb9a547 AM |
26 | #include "basic-block.h" |
27 | #include "tree-ssa-alias.h" | |
28 | #include "internal-fn.h" | |
29 | #include "gimple-expr.h" | |
30 | #include "is-a.h" | |
8e9055ae | 31 | #include "gimple.h" |
d7f09764 | 32 | #include "hashtab.h" |
d7f09764 DN |
33 | #include "bitmap.h" |
34 | #include "flags.h" | |
35 | #include "opts.h" | |
36 | #include "options.h" | |
677f3fa8 | 37 | #include "common/common-target.h" |
1ebe4b4f | 38 | #include "diagnostic.h" |
d7f09764 | 39 | #include "lto-streamer.h" |
52a35ef7 | 40 | #include "toplev.h" |
d7f09764 | 41 | |
a456676f RG |
42 | /* Append the option piece OPT to the COLLECT_GCC_OPTIONS string |
43 | set up by OB, appropriately quoted and separated by spaces | |
44 | (if !*FIRST_P). */ | |
45 | ||
46 | static void | |
47 | append_to_collect_gcc_options (struct obstack *ob, | |
48 | bool *first_p, const char *opt) | |
49 | { | |
50 | const char *p, *q = opt; | |
0b8c30f9 | 51 | if (!*first_p) |
a456676f RG |
52 | obstack_grow (ob, " ", 1); |
53 | obstack_grow (ob, "'", 1); | |
54 | while ((p = strchr (q, '\''))) | |
55 | { | |
56 | obstack_grow (ob, q, p - q); | |
57 | obstack_grow (ob, "'\\''", 4); | |
58 | q = ++p; | |
59 | } | |
60 | obstack_grow (ob, q, strlen (q)); | |
61 | obstack_grow (ob, "'", 1); | |
62 | *first_p = false; | |
63 | } | |
64 | ||
d7f09764 DN |
65 | /* Write currently held options to an LTO IL section. */ |
66 | ||
67 | void | |
68 | lto_write_options (void) | |
69 | { | |
d7f09764 | 70 | struct lto_output_stream stream; |
52a35ef7 RG |
71 | char *section_name; |
72 | struct obstack temporary_obstack; | |
73 | unsigned int i, j; | |
74 | char *args; | |
a456676f | 75 | bool first_p = true; |
d7f09764 | 76 | |
52a35ef7 RG |
77 | section_name = lto_get_section_name (LTO_section_opts, NULL, NULL); |
78 | lto_begin_section (section_name, false); | |
d7f09764 | 79 | memset (&stream, 0, sizeof (stream)); |
d7f09764 | 80 | |
52a35ef7 | 81 | obstack_init (&temporary_obstack); |
a456676f | 82 | |
2a5145b0 | 83 | /* Output options that affect GIMPLE IL semantics and are implicitly |
a456676f RG |
84 | enabled by the frontend. |
85 | This for now includes an explicit set of options that we also handle | |
86 | explicitly in lto-wrapper.c. In the end the effects on GIMPLE IL | |
87 | semantics should be explicitely encoded in the IL or saved per | |
88 | function rather than per compilation unit. */ | |
89 | /* -fexceptions causes the EH machinery to be initialized, enabling | |
90 | generation of unwind data so that explicit throw() calls work. */ | |
5d1a0108 RB |
91 | if (!global_options_set.x_flag_exceptions |
92 | && global_options.x_flag_exceptions) | |
a456676f RG |
93 | append_to_collect_gcc_options (&temporary_obstack, &first_p, |
94 | "-fexceptions"); | |
2a5145b0 ILT |
95 | /* -fnon-call-exceptions changes the generation of exception |
96 | regions. It is enabled implicitly by the Go frontend. */ | |
5d1a0108 RB |
97 | if (!global_options_set.x_flag_non_call_exceptions |
98 | && global_options.x_flag_non_call_exceptions) | |
2a5145b0 ILT |
99 | append_to_collect_gcc_options (&temporary_obstack, &first_p, |
100 | "-fnon-call-exceptions"); | |
5d1a0108 RB |
101 | /* The default -ffp-contract changes depending on the language |
102 | standard. Pass thru conservative standard settings. */ | |
103 | if (!global_options_set.x_flag_fp_contract_mode) | |
104 | switch (global_options.x_flag_fp_contract_mode) | |
105 | { | |
106 | case FP_CONTRACT_OFF: | |
107 | append_to_collect_gcc_options (&temporary_obstack, &first_p, | |
108 | "-ffp-contract=off"); | |
109 | break; | |
110 | case FP_CONTRACT_ON: | |
111 | append_to_collect_gcc_options (&temporary_obstack, &first_p, | |
112 | "-ffp-contract=on"); | |
113 | break; | |
114 | case FP_CONTRACT_FAST: | |
115 | /* Nothing. That merges conservatively and is the default for LTO. */ | |
116 | break; | |
117 | default: | |
118 | gcc_unreachable (); | |
119 | } | |
4094757e RB |
120 | /* We need to merge -f[no-]strict-overflow, -f[no-]wrapv and -f[no-]trapv |
121 | conservatively, so stream out their defaults. */ | |
122 | if (!global_options_set.x_flag_wrapv | |
123 | && global_options.x_flag_wrapv) | |
124 | append_to_collect_gcc_options (&temporary_obstack, &first_p, "-fwrapv"); | |
125 | if (!global_options_set.x_flag_trapv | |
126 | && !global_options.x_flag_trapv) | |
127 | append_to_collect_gcc_options (&temporary_obstack, &first_p, "-fno-trapv"); | |
128 | if (!global_options_set.x_flag_strict_overflow | |
129 | && !global_options.x_flag_strict_overflow) | |
130 | append_to_collect_gcc_options (&temporary_obstack, &first_p, | |
131 | "-fno-strict-overflow"); | |
a456676f | 132 | |
2a5145b0 | 133 | /* Output explicitly passed options. */ |
52a35ef7 | 134 | for (i = 1; i < save_decoded_options_count; ++i) |
d7f09764 | 135 | { |
52a35ef7 | 136 | struct cl_decoded_option *option = &save_decoded_options[i]; |
52a35ef7 | 137 | |
169d8507 L |
138 | /* Skip explicitly some common options that we do not need. */ |
139 | switch (option->opt_index) | |
140 | { | |
141 | case OPT_dumpbase: | |
142 | case OPT_SPECIAL_unknown: | |
143 | case OPT_SPECIAL_ignore: | |
144 | case OPT_SPECIAL_program_name: | |
145 | case OPT_SPECIAL_input_file: | |
146 | continue; | |
147 | ||
148 | default: | |
149 | break; | |
150 | } | |
151 | ||
52a35ef7 RG |
152 | /* Skip frontend and driver specific options here. */ |
153 | if (!(cl_options[option->opt_index].flags & (CL_COMMON|CL_TARGET|CL_LTO))) | |
154 | continue; | |
155 | ||
156 | /* Drop options created from the gcc driver that will be rejected | |
157 | when passed on to the driver again. */ | |
158 | if (cl_options[option->opt_index].cl_reject_driver) | |
159 | continue; | |
160 | ||
161 | /* Also drop all options that are handled by the driver as well, | |
162 | which includes things like -o and -v or -fhelp for example. | |
163 | We do not need those. Also drop all diagnostic options. */ | |
164 | if (cl_options[option->opt_index].flags & (CL_DRIVER|CL_WARNING)) | |
165 | continue; | |
166 | ||
a456676f RG |
167 | for (j = 0; j < option->canonical_option_num_elements; ++j) |
168 | append_to_collect_gcc_options (&temporary_obstack, &first_p, | |
169 | option->canonical_option[j]); | |
d7f09764 | 170 | } |
52a35ef7 RG |
171 | obstack_grow (&temporary_obstack, "\0", 1); |
172 | args = XOBFINISH (&temporary_obstack, char *); | |
173 | lto_output_data_stream (&stream, args, strlen (args) + 1); | |
d7f09764 | 174 | |
52a35ef7 RG |
175 | lto_write_stream (&stream); |
176 | lto_end_section (); | |
177 | ||
178 | obstack_free (&temporary_obstack, NULL); | |
179 | free (section_name); | |
d7f09764 | 180 | } |