annotate gcc/lto-opts.c @ 128:fe568345ddd5

fix CbC-example
author mir3636
date Wed, 11 Apr 2018 19:32:28 +0900
parents 04ced10e8804
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* LTO IL options.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
111
kono
parents: 67
diff changeset
3 Copyright (C) 2009-2017 Free Software Foundation, Inc.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 Contributed by Simon Baldwin <simonb@google.com>
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 This file is part of GCC.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 GCC is free software; you can redistribute it and/or modify it under
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 the terms of the GNU General Public License as published by the Free
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 Software Foundation; either version 3, or (at your option) any later
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 version.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 for more details.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 along with GCC; see the file COPYING3. If not see
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 <http://www.gnu.org/licenses/>. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #include "config.h"
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 #include "system.h"
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 #include "coretypes.h"
111
kono
parents: 67
diff changeset
25 #include "backend.h"
kono
parents: 67
diff changeset
26 #include "target.h"
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 #include "tree.h"
111
kono
parents: 67
diff changeset
28 #include "gimple.h"
kono
parents: 67
diff changeset
29 #include "cgraph.h"
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 #include "lto-streamer.h"
111
kono
parents: 67
diff changeset
31 #include "opts.h"
kono
parents: 67
diff changeset
32 #include "toplev.h"
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
111
kono
parents: 67
diff changeset
34 /* Append the option piece OPT to the COLLECT_GCC_OPTIONS string
kono
parents: 67
diff changeset
35 set up by OB, appropriately quoted and separated by spaces
kono
parents: 67
diff changeset
36 (if !*FIRST_P). */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 static void
111
kono
parents: 67
diff changeset
39 append_to_collect_gcc_options (struct obstack *ob,
kono
parents: 67
diff changeset
40 bool *first_p, const char *opt)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 {
111
kono
parents: 67
diff changeset
42 const char *p, *q = opt;
kono
parents: 67
diff changeset
43 if (!*first_p)
kono
parents: 67
diff changeset
44 obstack_grow (ob, " ", 1);
kono
parents: 67
diff changeset
45 obstack_grow (ob, "'", 1);
kono
parents: 67
diff changeset
46 while ((p = strchr (q, '\'')))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 {
111
kono
parents: 67
diff changeset
48 obstack_grow (ob, q, p - q);
kono
parents: 67
diff changeset
49 obstack_grow (ob, "'\\''", 4);
kono
parents: 67
diff changeset
50 q = ++p;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 }
111
kono
parents: 67
diff changeset
52 obstack_grow (ob, q, strlen (q));
kono
parents: 67
diff changeset
53 obstack_grow (ob, "'", 1);
kono
parents: 67
diff changeset
54 *first_p = false;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 /* Write currently held options to an LTO IL section. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 void
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 lto_write_options (void)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 {
111
kono
parents: 67
diff changeset
62 char *section_name;
kono
parents: 67
diff changeset
63 struct obstack temporary_obstack;
kono
parents: 67
diff changeset
64 unsigned int i, j;
kono
parents: 67
diff changeset
65 char *args;
kono
parents: 67
diff changeset
66 bool first_p = true;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67
111
kono
parents: 67
diff changeset
68 section_name = lto_get_section_name (LTO_section_opts, NULL, NULL);
kono
parents: 67
diff changeset
69 lto_begin_section (section_name, false);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
111
kono
parents: 67
diff changeset
71 obstack_init (&temporary_obstack);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
111
kono
parents: 67
diff changeset
73 /* Output options that affect GIMPLE IL semantics and are implicitly
kono
parents: 67
diff changeset
74 enabled by the frontend.
kono
parents: 67
diff changeset
75 This for now includes an explicit set of options that we also handle
kono
parents: 67
diff changeset
76 explicitly in lto-wrapper.c. In the end the effects on GIMPLE IL
kono
parents: 67
diff changeset
77 semantics should be explicitely encoded in the IL or saved per
kono
parents: 67
diff changeset
78 function rather than per compilation unit. */
kono
parents: 67
diff changeset
79 /* -fexceptions causes the EH machinery to be initialized, enabling
kono
parents: 67
diff changeset
80 generation of unwind data so that explicit throw() calls work. */
kono
parents: 67
diff changeset
81 if (!global_options_set.x_flag_exceptions
kono
parents: 67
diff changeset
82 && global_options.x_flag_exceptions)
kono
parents: 67
diff changeset
83 append_to_collect_gcc_options (&temporary_obstack, &first_p,
kono
parents: 67
diff changeset
84 "-fexceptions");
kono
parents: 67
diff changeset
85 /* -fnon-call-exceptions changes the generation of exception
kono
parents: 67
diff changeset
86 regions. It is enabled implicitly by the Go frontend. */
kono
parents: 67
diff changeset
87 if (!global_options_set.x_flag_non_call_exceptions
kono
parents: 67
diff changeset
88 && global_options.x_flag_non_call_exceptions)
kono
parents: 67
diff changeset
89 append_to_collect_gcc_options (&temporary_obstack, &first_p,
kono
parents: 67
diff changeset
90 "-fnon-call-exceptions");
kono
parents: 67
diff changeset
91 /* The default -ffp-contract changes depending on the language
kono
parents: 67
diff changeset
92 standard. Pass thru conservative standard settings. */
kono
parents: 67
diff changeset
93 if (!global_options_set.x_flag_fp_contract_mode)
kono
parents: 67
diff changeset
94 switch (global_options.x_flag_fp_contract_mode)
kono
parents: 67
diff changeset
95 {
kono
parents: 67
diff changeset
96 case FP_CONTRACT_OFF:
kono
parents: 67
diff changeset
97 append_to_collect_gcc_options (&temporary_obstack, &first_p,
kono
parents: 67
diff changeset
98 "-ffp-contract=off");
kono
parents: 67
diff changeset
99 break;
kono
parents: 67
diff changeset
100 case FP_CONTRACT_ON:
kono
parents: 67
diff changeset
101 append_to_collect_gcc_options (&temporary_obstack, &first_p,
kono
parents: 67
diff changeset
102 "-ffp-contract=on");
kono
parents: 67
diff changeset
103 break;
kono
parents: 67
diff changeset
104 case FP_CONTRACT_FAST:
kono
parents: 67
diff changeset
105 /* Nothing. That merges conservatively and is the default for LTO. */
kono
parents: 67
diff changeset
106 break;
kono
parents: 67
diff changeset
107 default:
kono
parents: 67
diff changeset
108 gcc_unreachable ();
kono
parents: 67
diff changeset
109 }
kono
parents: 67
diff changeset
110 /* The default -fmath-errno, -fsigned-zeros and -ftrapping-math change
kono
parents: 67
diff changeset
111 depending on the language (they can be disabled by the Ada front-end).
kono
parents: 67
diff changeset
112 Pass thru conservative standard settings. */
kono
parents: 67
diff changeset
113 if (!global_options_set.x_flag_errno_math)
kono
parents: 67
diff changeset
114 append_to_collect_gcc_options (&temporary_obstack, &first_p,
kono
parents: 67
diff changeset
115 global_options.x_flag_errno_math
kono
parents: 67
diff changeset
116 ? "-fmath-errno"
kono
parents: 67
diff changeset
117 : "-fno-math-errno");
kono
parents: 67
diff changeset
118 if (!global_options_set.x_flag_signed_zeros)
kono
parents: 67
diff changeset
119 append_to_collect_gcc_options (&temporary_obstack, &first_p,
kono
parents: 67
diff changeset
120 global_options.x_flag_signed_zeros
kono
parents: 67
diff changeset
121 ? "-fsigned-zeros"
kono
parents: 67
diff changeset
122 : "-fno-signed-zeros");
kono
parents: 67
diff changeset
123 if (!global_options_set.x_flag_trapping_math)
kono
parents: 67
diff changeset
124 append_to_collect_gcc_options (&temporary_obstack, &first_p,
kono
parents: 67
diff changeset
125 global_options.x_flag_trapping_math
kono
parents: 67
diff changeset
126 ? "-ftrapping-math"
kono
parents: 67
diff changeset
127 : "-fno-trapping-math");
kono
parents: 67
diff changeset
128 /* We need to merge -f[no-]strict-overflow, -f[no-]wrapv and -f[no-]trapv
kono
parents: 67
diff changeset
129 conservatively, so stream out their defaults. */
kono
parents: 67
diff changeset
130 if (!global_options_set.x_flag_wrapv
kono
parents: 67
diff changeset
131 && global_options.x_flag_wrapv)
kono
parents: 67
diff changeset
132 append_to_collect_gcc_options (&temporary_obstack, &first_p, "-fwrapv");
kono
parents: 67
diff changeset
133 if (!global_options_set.x_flag_trapv
kono
parents: 67
diff changeset
134 && !global_options.x_flag_trapv)
kono
parents: 67
diff changeset
135 append_to_collect_gcc_options (&temporary_obstack, &first_p, "-fno-trapv");
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136
111
kono
parents: 67
diff changeset
137 if (!global_options_set.x_flag_openmp
kono
parents: 67
diff changeset
138 && !global_options.x_flag_openmp)
kono
parents: 67
diff changeset
139 append_to_collect_gcc_options (&temporary_obstack, &first_p, "-fno-openmp");
kono
parents: 67
diff changeset
140 if (!global_options_set.x_flag_openacc
kono
parents: 67
diff changeset
141 && !global_options.x_flag_openacc)
kono
parents: 67
diff changeset
142 append_to_collect_gcc_options (&temporary_obstack, &first_p,
kono
parents: 67
diff changeset
143 "-fno-openacc");
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144
111
kono
parents: 67
diff changeset
145 /* Append options from target hook and store them to offload_lto section. */
kono
parents: 67
diff changeset
146 if (lto_stream_offload_p)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 {
111
kono
parents: 67
diff changeset
148 char *offload_opts = targetm.offload_options ();
kono
parents: 67
diff changeset
149 char *offload_ptr = offload_opts;
kono
parents: 67
diff changeset
150 while (offload_ptr)
kono
parents: 67
diff changeset
151 {
kono
parents: 67
diff changeset
152 char *next = strchr (offload_ptr, ' ');
kono
parents: 67
diff changeset
153 if (next)
kono
parents: 67
diff changeset
154 *next++ = '\0';
kono
parents: 67
diff changeset
155 append_to_collect_gcc_options (&temporary_obstack, &first_p,
kono
parents: 67
diff changeset
156 offload_ptr);
kono
parents: 67
diff changeset
157 offload_ptr = next;
kono
parents: 67
diff changeset
158 }
kono
parents: 67
diff changeset
159 free (offload_opts);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161
111
kono
parents: 67
diff changeset
162 /* Output explicitly passed options. */
kono
parents: 67
diff changeset
163 for (i = 1; i < save_decoded_options_count; ++i)
kono
parents: 67
diff changeset
164 {
kono
parents: 67
diff changeset
165 struct cl_decoded_option *option = &save_decoded_options[i];
kono
parents: 67
diff changeset
166
kono
parents: 67
diff changeset
167 /* Skip explicitly some common options that we do not need. */
kono
parents: 67
diff changeset
168 switch (option->opt_index)
kono
parents: 67
diff changeset
169 {
kono
parents: 67
diff changeset
170 case OPT_dumpbase:
kono
parents: 67
diff changeset
171 case OPT_SPECIAL_unknown:
kono
parents: 67
diff changeset
172 case OPT_SPECIAL_ignore:
kono
parents: 67
diff changeset
173 case OPT_SPECIAL_program_name:
kono
parents: 67
diff changeset
174 case OPT_SPECIAL_input_file:
kono
parents: 67
diff changeset
175 continue;
kono
parents: 67
diff changeset
176
kono
parents: 67
diff changeset
177 default:
kono
parents: 67
diff changeset
178 break;
kono
parents: 67
diff changeset
179 }
kono
parents: 67
diff changeset
180
kono
parents: 67
diff changeset
181 /* Skip frontend and driver specific options here. */
kono
parents: 67
diff changeset
182 if (!(cl_options[option->opt_index].flags & (CL_COMMON|CL_TARGET|CL_LTO)))
kono
parents: 67
diff changeset
183 continue;
kono
parents: 67
diff changeset
184
kono
parents: 67
diff changeset
185 /* Do not store target-specific options in offload_lto section. */
kono
parents: 67
diff changeset
186 if ((cl_options[option->opt_index].flags & CL_TARGET)
kono
parents: 67
diff changeset
187 && lto_stream_offload_p)
kono
parents: 67
diff changeset
188 continue;
kono
parents: 67
diff changeset
189
kono
parents: 67
diff changeset
190 /* Drop options created from the gcc driver that will be rejected
kono
parents: 67
diff changeset
191 when passed on to the driver again. */
kono
parents: 67
diff changeset
192 if (cl_options[option->opt_index].cl_reject_driver)
kono
parents: 67
diff changeset
193 continue;
kono
parents: 67
diff changeset
194
kono
parents: 67
diff changeset
195 /* Also drop all options that are handled by the driver as well,
kono
parents: 67
diff changeset
196 which includes things like -o and -v or -fhelp for example.
kono
parents: 67
diff changeset
197 We do not need those. The only exception is -foffload option, if we
kono
parents: 67
diff changeset
198 write it in offload_lto section. Also drop all diagnostic options. */
kono
parents: 67
diff changeset
199 if ((cl_options[option->opt_index].flags & (CL_DRIVER|CL_WARNING))
kono
parents: 67
diff changeset
200 && (!lto_stream_offload_p || option->opt_index != OPT_foffload_))
kono
parents: 67
diff changeset
201 continue;
kono
parents: 67
diff changeset
202
kono
parents: 67
diff changeset
203 for (j = 0; j < option->canonical_option_num_elements; ++j)
kono
parents: 67
diff changeset
204 append_to_collect_gcc_options (&temporary_obstack, &first_p,
kono
parents: 67
diff changeset
205 option->canonical_option[j]);
kono
parents: 67
diff changeset
206 }
kono
parents: 67
diff changeset
207 obstack_grow (&temporary_obstack, "\0", 1);
kono
parents: 67
diff changeset
208 args = XOBFINISH (&temporary_obstack, char *);
kono
parents: 67
diff changeset
209 lto_write_data (args, strlen (args) + 1);
kono
parents: 67
diff changeset
210 lto_end_section ();
kono
parents: 67
diff changeset
211
kono
parents: 67
diff changeset
212 obstack_free (&temporary_obstack, NULL);
kono
parents: 67
diff changeset
213 free (section_name);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 }