]>
Commit | Line | Data |
---|---|---|
5e6908ea | 1 | /* Top level of GCC compilers (cc1, cc1plus, etc.) |
4559fd9e | 2 | Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
5a013dc4 | 3 | 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
3a3315f7 | 4 | Free Software Foundation, Inc. |
4291d9c8 | 5 | |
1322177d | 6 | This file is part of GCC. |
4291d9c8 | 7 | |
1322177d LB |
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 | |
9dcd6f09 | 10 | Software Foundation; either version 3, or (at your option) any later |
1322177d | 11 | version. |
4291d9c8 | 12 | |
1322177d LB |
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. | |
4291d9c8 RS |
17 | |
18 | You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
19 | along with GCC; see the file COPYING3. If not see |
20 | <http://www.gnu.org/licenses/>. */ | |
4291d9c8 | 21 | |
4291d9c8 RS |
22 | /* This is the top level of cc1/c++. |
23 | It parses command args, opens files, invokes the various passes | |
24 | in the proper order, and counts the time used by each. | |
25 | Error messages and low-level interface to malloc also handled here. */ | |
26 | ||
27 | #include "config.h" | |
670ee920 | 28 | #include "system.h" |
4977bab6 ZW |
29 | #include "coretypes.h" |
30 | #include "tm.h" | |
956d6950 JL |
31 | |
32 | #ifdef HAVE_SYS_TIMES_H | |
33 | # include <sys/times.h> | |
eb910b5a | 34 | #endif |
4291d9c8 | 35 | |
2ae5c785 | 36 | #include "line-map.h" |
4291d9c8 RS |
37 | #include "input.h" |
38 | #include "tree.h" | |
d49b6e1e | 39 | #include "realmpfr.h" /* For GMP/MPFR/MPC versions, in print_version. */ |
a757585a | 40 | #include "version.h" |
4291d9c8 | 41 | #include "rtl.h" |
6baf1cc8 | 42 | #include "tm_p.h" |
4291d9c8 RS |
43 | #include "flags.h" |
44 | #include "insn-attr.h" | |
e5e809f4 | 45 | #include "insn-config.h" |
0dd0e980 | 46 | #include "insn-flags.h" |
23280139 | 47 | #include "hard-reg-set.h" |
e5e809f4 | 48 | #include "recog.h" |
e14417fa | 49 | #include "output.h" |
3d195391 | 50 | #include "except.h" |
49ad7cfa | 51 | #include "function.h" |
a0c8e1b2 | 52 | #include "toplev.h" |
114791ea | 53 | #include "expr.h" |
b1eeb243 | 54 | #include "basic-block.h" |
ab87f8c8 | 55 | #include "intl.h" |
0a25f1f5 | 56 | #include "ggc.h" |
6a2cc2ac | 57 | #include "graph.h" |
d0af450d | 58 | #include "regs.h" |
2a9a326b | 59 | #include "timevar.h" |
764dbbf2 | 60 | #include "diagnostic.h" |
cf835838 JM |
61 | #include "tree-diagnostic.h" |
62 | #include "tree-pretty-print.h" | |
c6d9a88c | 63 | #include "params.h" |
8461e984 | 64 | #include "reload.h" |
058e97ec | 65 | #include "ira.h" |
5262d6b6 | 66 | #include "dwarf2asm.h" |
c0e7830f | 67 | #include "integrate.h" |
a51d908e | 68 | #include "debug.h" |
7c262518 | 69 | #include "target.h" |
d23c55c2 | 70 | #include "langhooks.h" |
0478a14c | 71 | #include "cfglayout.h" |
3d436d2a | 72 | #include "cfgloop.h" |
476d9098 | 73 | #include "hosthooks.h" |
b255a036 | 74 | #include "cgraph.h" |
2772ef3e | 75 | #include "opts.h" |
5f0f4a3b | 76 | #include "opts-diagnostic.h" |
5b0e2409 | 77 | #include "coverage.h" |
fca9dc00 | 78 | #include "value-prof.h" |
40ca90bf | 79 | #include "alloc-pool.h" |
ccab73c3 | 80 | #include "tree-mudflap.h" |
438d798f | 81 | #include "tree-pass.h" |
726a989a | 82 | #include "gimple.h" |
5006671f | 83 | #include "tree-ssa-alias.h" |
68a607d8 | 84 | #include "plugin.h" |
f246a305 | 85 | |
76ead72b RL |
86 | #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO) |
87 | #include "dwarf2out.h" | |
88 | #endif | |
89 | ||
4f70758f | 90 | #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO) |
76ead72b RL |
91 | #include "dbxout.h" |
92 | #endif | |
93 | ||
94 | #ifdef SDB_DEBUGGING_INFO | |
95 | #include "sdbout.h" | |
96 | #endif | |
440aabf8 NB |
97 | |
98 | #ifdef XCOFF_DEBUGGING_INFO | |
99 | #include "xcoffout.h" /* Needed for external data | |
100 | declarations for e.g. AIX 4.x. */ | |
101 | #endif | |
ddc9542b | 102 | |
b86f6cd9 | 103 | static void general_init (const char *); |
e25a75e6 AJ |
104 | static void do_compile (void); |
105 | static void process_options (void); | |
106 | static void backend_init (void); | |
107 | static int lang_dependent_init (const char *); | |
108 | static void init_asm_output (const char *); | |
109 | static void finalize (void); | |
110 | ||
e25a75e6 | 111 | static void crash_signal (int) ATTRIBUTE_NORETURN; |
e25a75e6 | 112 | static void compile_file (void); |
e25a75e6 | 113 | |
4bfec483 NB |
114 | /* True if we don't need a backend (e.g. preprocessing only). */ |
115 | static bool no_backend; | |
116 | ||
3d5cdd42 DE |
117 | /* Length of line when printing switch values. */ |
118 | #define MAX_LINE 75 | |
119 | ||
6e2f1956 | 120 | /* Decoded options, and number of such options. */ |
41804a5b TB |
121 | struct cl_decoded_option *save_decoded_options; |
122 | unsigned int save_decoded_options_count; | |
ddc9542b | 123 | |
4291d9c8 RS |
124 | /* Name of top-level original source file (what was input to cpp). |
125 | This comes from the #-command at the beginning of the actual input. | |
126 | If there isn't any there, then this is the cc1 input file name. */ | |
127 | ||
3b304f5b | 128 | const char *main_input_filename; |
4291d9c8 | 129 | |
69ccdddb JM |
130 | /* Pointer to base name in main_input_filename, with directories and a |
131 | single final extension removed, and the length of this base | |
132 | name. */ | |
133 | const char *main_input_basename; | |
134 | int main_input_baselength; | |
135 | ||
38d396e5 | 136 | /* Used to enable -fvar-tracking, -fweb and -frename-registers according |
6a080096 | 137 | to optimize in process_options (). */ |
2928d0f8 | 138 | #define AUTODETECT_VALUE 2 |
38d396e5 | 139 | |
a51d908e NB |
140 | /* Debug hooks - dependent upon command line options. */ |
141 | ||
df38ffef | 142 | const struct gcc_debug_hooks *debug_hooks; |
a51d908e | 143 | |
d7f09764 DN |
144 | /* True if this is the lto front end. This is used to disable |
145 | gimple generation and lowering passes that are normally run on the | |
146 | output of a front end. These passes must be bypassed for lto since | |
b8698a0f | 147 | they have already been done before the gimple was written. */ |
d7f09764 DN |
148 | |
149 | bool in_lto_p = false; | |
150 | ||
00262c8a ML |
151 | /* The FUNCTION_DECL for the function currently being compiled, |
152 | or 0 if between functions. */ | |
153 | tree current_function_decl; | |
154 | ||
375d2edc | 155 | /* Set to the FUNC_BEGIN label of the current function, or NULL |
00262c8a | 156 | if none. */ |
375d2edc | 157 | const char * current_function_func_begin_label; |
00262c8a | 158 | |
4ed43216 | 159 | /* A random sequence of characters, unless overridden by user. */ |
403d4851 | 160 | static const char *flag_random_seed; |
c07e5477 NS |
161 | |
162 | /* A local time stamp derived from the time of compilation. It will be | |
163 | zero if the system cannot provide a time. It will be -1u, if the | |
164 | user has specified a particular random seed. */ | |
165 | unsigned local_tick; | |
166 | ||
4291d9c8 RS |
167 | /* -f flags. */ |
168 | ||
43b3a5b1 ZL |
169 | /* Generate code for GNU or NeXT Objective-C runtime environment. */ |
170 | ||
171 | #ifdef NEXT_OBJC_RUNTIME | |
172 | int flag_next_runtime = 1; | |
173 | #else | |
174 | int flag_next_runtime = 0; | |
175 | #endif | |
176 | ||
393eda6a MLI |
177 | /* Nonzero means make permerror produce warnings instead of errors. */ |
178 | ||
179 | int flag_permissive = 0; | |
180 | ||
a157febd GK |
181 | /* When non-NULL, indicates that whenever space is allocated on the |
182 | stack, the resulting stack pointer must not pass this | |
183 | address---that is, for stacks that grow downward, the stack pointer | |
184 | must always be greater than or equal to this address; for stacks | |
185 | that grow upward, the stack pointer must be less than this address. | |
186 | At present, the rtx may be either a REG or a SYMBOL_REF, although | |
187 | the support provided depends on the backend. */ | |
188 | rtx stack_limit_rtx; | |
189 | ||
b38f3813 EB |
190 | /* Type of stack check. */ |
191 | enum stack_check_type flag_stack_check = NO_STACK_CHECK; | |
192 | ||
9fb32434 CT |
193 | /* True if the user has tagged the function with the 'section' |
194 | attribute. */ | |
195 | ||
196 | bool user_defined_section_attribute = false; | |
197 | ||
3bd36029 RS |
198 | struct target_flag_state default_target_flag_state; |
199 | #if SWITCHABLE_TARGET | |
200 | struct target_flag_state *this_target_flag_state = &default_target_flag_state; | |
201 | #else | |
202 | #define this_target_flag_state (&default_target_flag_state) | |
203 | #endif | |
efa3896a | 204 | |
b8468bc7 NC |
205 | typedef struct |
206 | { | |
c083a819 KG |
207 | const char *const string; |
208 | int *const variable; | |
209 | const int on_value; | |
b8468bc7 NC |
210 | } |
211 | lang_independent_options; | |
212 | ||
19283265 | 213 | /* The user symbol prefix after having resolved same. */ |
87e11268 | 214 | const char *user_label_prefix; |
19283265 | 215 | |
c6d9a88c | 216 | static const param_info lang_independent_params[] = { |
e06c0feb | 217 | #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \ |
48476d13 | 218 | { OPTION, DEFAULT, MIN, MAX, HELP }, |
c6d9a88c MM |
219 | #include "params.def" |
220 | #undef DEFPARAM | |
48476d13 | 221 | { NULL, 0, 0, 0, NULL } |
c6d9a88c MM |
222 | }; |
223 | ||
4291d9c8 RS |
224 | /* Output files for assembler code (real compiler output) |
225 | and debugging dumps. */ | |
226 | ||
227 | FILE *asm_out_file; | |
228 | FILE *aux_info_file; | |
d3c12306 | 229 | FILE *stack_usage_file = NULL; |
c263766c | 230 | FILE *dump_file = NULL; |
29c431a1 | 231 | const char *dump_file_name; |
4291d9c8 | 232 | |
b20d9f0c AO |
233 | /* The current working directory of a translation. It's generally the |
234 | directory from which compilation was initiated, but a preprocessed | |
235 | file may specify the original directory in which it was | |
236 | created. */ | |
237 | ||
238 | static const char *src_pwd; | |
239 | ||
240 | /* Initialize src_pwd with the given string, and return true. If it | |
241 | was already initialized, return false. As a special case, it may | |
242 | be called with a NULL argument to test whether src_pwd has NOT been | |
243 | initialized yet. */ | |
244 | ||
245 | bool | |
246 | set_src_pwd (const char *pwd) | |
247 | { | |
248 | if (src_pwd) | |
0855eab7 CT |
249 | { |
250 | if (strcmp (src_pwd, pwd) == 0) | |
251 | return true; | |
252 | else | |
253 | return false; | |
254 | } | |
b20d9f0c AO |
255 | |
256 | src_pwd = xstrdup (pwd); | |
257 | return true; | |
258 | } | |
259 | ||
260 | /* Return the directory from which the translation unit was initiated, | |
261 | in case set_src_pwd() was not called before to assign it a | |
262 | different value. */ | |
263 | ||
264 | const char * | |
265 | get_src_pwd (void) | |
266 | { | |
267 | if (! src_pwd) | |
5f0c48ed GK |
268 | { |
269 | src_pwd = getpwd (); | |
270 | if (!src_pwd) | |
271 | src_pwd = "."; | |
272 | } | |
b20d9f0c AO |
273 | |
274 | return src_pwd; | |
275 | } | |
276 | ||
0761f342 GDR |
277 | /* Called when the start of a function definition is parsed, |
278 | this function prints on stderr the name of the function. */ | |
279 | void | |
280 | announce_function (tree decl) | |
281 | { | |
282 | if (!quiet_flag) | |
283 | { | |
284 | if (rtl_dump_and_exit) | |
4f1e4960 JM |
285 | fprintf (stderr, "%s ", |
286 | identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl)))); | |
0761f342 | 287 | else |
4f1e4960 JM |
288 | fprintf (stderr, " %s", |
289 | identifier_to_locale (lang_hooks.decl_printable_name (decl, 2))); | |
0761f342 GDR |
290 | fflush (stderr); |
291 | pp_needs_newline (global_dc->printer) = true; | |
c94ed7a1 | 292 | diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL); |
0761f342 GDR |
293 | } |
294 | } | |
295 | ||
403d4851 AO |
296 | /* Initialize local_tick with the time of day, or -1 if |
297 | flag_random_seed is set. */ | |
c07e5477 NS |
298 | |
299 | static void | |
403d4851 | 300 | init_local_tick (void) |
c07e5477 NS |
301 | { |
302 | if (!flag_random_seed) | |
303 | { | |
c07e5477 NS |
304 | /* Get some more or less random data. */ |
305 | #ifdef HAVE_GETTIMEOFDAY | |
306 | { | |
403d4851 | 307 | struct timeval tv; |
fbfb16e2 | 308 | |
403d4851 | 309 | gettimeofday (&tv, NULL); |
c07e5477 NS |
310 | local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000; |
311 | } | |
312 | #else | |
313 | { | |
c163ddca | 314 | time_t now = time (NULL); |
c07e5477 NS |
315 | |
316 | if (now != (time_t)-1) | |
317 | local_tick = (unsigned) now; | |
318 | } | |
319 | #endif | |
c07e5477 | 320 | } |
403d4851 | 321 | else |
c07e5477 NS |
322 | local_tick = -1; |
323 | } | |
324 | ||
403d4851 AO |
325 | /* Set up a default flag_random_seed and local_tick, unless the user |
326 | already specified one. Must be called after init_local_tick. */ | |
327 | ||
328 | static void | |
329 | init_random_seed (void) | |
330 | { | |
331 | unsigned HOST_WIDE_INT value; | |
332 | static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3]; | |
333 | ||
334 | value = local_tick ^ getpid (); | |
335 | ||
336 | sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value); | |
337 | flag_random_seed = random_seed; | |
338 | } | |
339 | ||
340 | /* Obtain the random_seed string. Unless NOINIT, initialize it if | |
341 | it's not provided in the command line. */ | |
342 | ||
343 | const char * | |
344 | get_random_seed (bool noinit) | |
345 | { | |
346 | if (!flag_random_seed && !noinit) | |
347 | init_random_seed (); | |
348 | return flag_random_seed; | |
349 | } | |
350 | ||
351 | /* Modify the random_seed string to VAL. Return its previous | |
352 | value. */ | |
353 | ||
354 | const char * | |
355 | set_random_seed (const char *val) | |
356 | { | |
357 | const char *old = flag_random_seed; | |
358 | flag_random_seed = val; | |
359 | return old; | |
360 | } | |
c07e5477 | 361 | |
9c727c9a | 362 | #if GCC_VERSION < 3004 |
a8a4fe0c | 363 | |
bd95721f RH |
364 | /* The functions clz_hwi, ctz_hwi, ffs_hwi, floor_log2 and exact_log2 |
365 | are defined as inline functions in toplev.h if GCC_VERSION >= 3004. | |
366 | The definitions here are used for older versions of gcc. */ | |
a8a4fe0c | 367 | |
73d10efa | 368 | /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X. |
765d98c7 | 369 | If X is 0, return -1. */ |
4291d9c8 RS |
370 | |
371 | int | |
765d98c7 | 372 | floor_log2 (unsigned HOST_WIDE_INT x) |
4291d9c8 | 373 | { |
765d98c7 RH |
374 | int t = 0; |
375 | ||
73d10efa | 376 | if (x == 0) |
4291d9c8 | 377 | return -1; |
765d98c7 | 378 | |
765d98c7 | 379 | if (HOST_BITS_PER_WIDE_INT > 64) |
144cbad0 | 380 | if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64)) |
73d10efa | 381 | t += 64; |
765d98c7 | 382 | if (HOST_BITS_PER_WIDE_INT > 32) |
144cbad0 | 383 | if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32)) |
73d10efa | 384 | t += 32; |
144cbad0 | 385 | if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16)) |
73d10efa | 386 | t += 16; |
144cbad0 | 387 | if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8)) |
73d10efa | 388 | t += 8; |
144cbad0 | 389 | if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4)) |
73d10efa | 390 | t += 4; |
144cbad0 | 391 | if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2)) |
73d10efa | 392 | t += 2; |
144cbad0 | 393 | if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1)) |
73d10efa | 394 | t += 1; |
765d98c7 | 395 | |
73d10efa | 396 | return t; |
4291d9c8 RS |
397 | } |
398 | ||
73d10efa | 399 | /* Return the logarithm of X, base 2, considering X unsigned, |
765d98c7 | 400 | if X is a power of 2. Otherwise, returns -1. */ |
4291d9c8 RS |
401 | |
402 | int | |
765d98c7 | 403 | exact_log2 (unsigned HOST_WIDE_INT x) |
4291d9c8 | 404 | { |
765d98c7 | 405 | if (x != (x & -x)) |
73d10efa | 406 | return -1; |
765d98c7 | 407 | return floor_log2 (x); |
4291d9c8 RS |
408 | } |
409 | ||
bd95721f RH |
410 | /* Given X, an unsigned number, return the number of least significant bits |
411 | that are zero. When X == 0, the result is the word size. */ | |
412 | ||
413 | int | |
414 | ctz_hwi (unsigned HOST_WIDE_INT x) | |
415 | { | |
416 | return x ? floor_log2 (x & -x) : HOST_BITS_PER_WIDE_INT; | |
417 | } | |
418 | ||
419 | /* Similarly for most significant bits. */ | |
420 | ||
421 | int | |
422 | clz_hwi (unsigned HOST_WIDE_INT x) | |
423 | { | |
424 | return HOST_BITS_PER_WIDE_INT - 1 - floor_log2(x); | |
425 | } | |
426 | ||
427 | /* Similar to ctz_hwi, except that the least significant bit is numbered | |
428 | starting from 1, and X == 0 yields 0. */ | |
429 | ||
430 | int | |
431 | ffs_hwi (unsigned HOST_WIDE_INT x) | |
432 | { | |
433 | return 1 + floor_log2 (x & -x); | |
434 | } | |
435 | ||
9c727c9a | 436 | #endif /* GCC_VERSION < 3004 */ |
a8a4fe0c | 437 | |
a7023245 | 438 | /* Handler for fatal signals, such as SIGSEGV. These are transformed |
c770ac2b ZW |
439 | into ICE messages, which is much more user friendly. In case the |
440 | error printer crashes, reset the signal to prevent infinite recursion. */ | |
4291d9c8 RS |
441 | |
442 | static void | |
e25a75e6 | 443 | crash_signal (int signo) |
4291d9c8 | 444 | { |
c770ac2b | 445 | signal (signo, SIG_DFL); |
52351a5e RE |
446 | |
447 | /* If we crashed while processing an ASM statement, then be a little more | |
448 | graceful. It's most likely the user's fault. */ | |
449 | if (this_is_asm_operands) | |
450 | { | |
451 | output_operand_lossage ("unrecoverable error"); | |
452 | exit (FATAL_EXIT_CODE); | |
453 | } | |
454 | ||
9d533cb5 | 455 | internal_error ("%s", strsignal (signo)); |
4291d9c8 RS |
456 | } |
457 | ||
7dce5088 | 458 | /* Output a quoted string. */ |
0f41302f | 459 | |
7dce5088 | 460 | void |
e25a75e6 | 461 | output_quoted_string (FILE *asm_file, const char *string) |
7dce5088 | 462 | { |
e9a25f70 JL |
463 | #ifdef OUTPUT_QUOTED_STRING |
464 | OUTPUT_QUOTED_STRING (asm_file, string); | |
465 | #else | |
7dce5088 PE |
466 | char c; |
467 | ||
468 | putc ('\"', asm_file); | |
469 | while ((c = *string++) != 0) | |
470 | { | |
042cdf71 ZW |
471 | if (ISPRINT (c)) |
472 | { | |
473 | if (c == '\"' || c == '\\') | |
474 | putc ('\\', asm_file); | |
475 | putc (c, asm_file); | |
476 | } | |
477 | else | |
211a0cbe | 478 | fprintf (asm_file, "\\%03o", (unsigned char) c); |
7dce5088 PE |
479 | } |
480 | putc ('\"', asm_file); | |
e9a25f70 | 481 | #endif |
7dce5088 PE |
482 | } |
483 | ||
db5f8b93 RH |
484 | /* A subroutine of wrapup_global_declarations. We've come to the end of |
485 | the compilation unit. All deferred variables should be undeferred, | |
486 | and all incomplete decls should be finalized. */ | |
487 | ||
488 | void | |
489 | wrapup_global_declaration_1 (tree decl) | |
490 | { | |
491 | /* We're not deferring this any longer. Assignment is conditional to | |
492 | avoid needlessly dirtying PCH pages. */ | |
493 | if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS) | |
494 | && DECL_DEFER_OUTPUT (decl) != 0) | |
495 | DECL_DEFER_OUTPUT (decl) = 0; | |
496 | ||
497 | if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0) | |
498 | lang_hooks.finish_incomplete_decl (decl); | |
499 | } | |
500 | ||
501 | /* A subroutine of wrapup_global_declarations. Decide whether or not DECL | |
502 | needs to be output. Return true if it is output. */ | |
503 | ||
504 | bool | |
505 | wrapup_global_declaration_2 (tree decl) | |
506 | { | |
507 | if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl)) | |
508 | return false; | |
509 | ||
510 | /* Don't write out static consts, unless we still need them. | |
511 | ||
512 | We also keep static consts if not optimizing (for debugging), | |
513 | unless the user specified -fno-keep-static-consts. | |
514 | ??? They might be better written into the debug information. | |
515 | This is possible when using DWARF. | |
516 | ||
517 | A language processor that wants static constants to be always | |
518 | written out (even if it is not used) is responsible for | |
519 | calling rest_of_decl_compilation itself. E.g. the C front-end | |
520 | calls rest_of_decl_compilation from finish_decl. | |
521 | One motivation for this is that is conventional in some | |
522 | environments to write things like: | |
523 | static const char rcsid[] = "... version string ..."; | |
524 | intending to force the string to be in the executable. | |
525 | ||
526 | A language processor that would prefer to have unneeded | |
527 | static constants "optimized away" would just defer writing | |
528 | them out until here. E.g. C++ does this, because static | |
529 | constants are often defined in header files. | |
530 | ||
531 | ??? A tempting alternative (for both C and C++) would be | |
532 | to force a constant to be written if and only if it is | |
533 | defined in a main file, as opposed to an include file. */ | |
534 | ||
535 | if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)) | |
536 | { | |
8a4a83ed | 537 | struct varpool_node *node; |
db5f8b93 | 538 | bool needed = true; |
babf1701 | 539 | node = varpool_get_node (decl); |
db5f8b93 | 540 | |
babf1701 | 541 | if (!node && flag_ltrans) |
db5f8b93 | 542 | needed = false; |
babf1701 JH |
543 | else if (node && node->finalized) |
544 | needed = false; | |
545 | else if (node && node->alias) | |
db5f8b93 RH |
546 | needed = false; |
547 | else if (!cgraph_global_info_ready | |
548 | && (TREE_USED (decl) | |
549 | || TREE_USED (DECL_ASSEMBLER_NAME (decl)))) | |
550 | /* needed */; | |
babf1701 | 551 | else if (node && node->needed) |
db5f8b93 RH |
552 | /* needed */; |
553 | else if (DECL_COMDAT (decl)) | |
554 | needed = false; | |
555 | else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl) | |
556 | && (optimize || !flag_keep_static_consts | |
557 | || DECL_ARTIFICIAL (decl))) | |
558 | needed = false; | |
559 | ||
560 | if (needed) | |
561 | { | |
562 | rest_of_decl_compilation (decl, 1, 1); | |
563 | return true; | |
564 | } | |
565 | } | |
566 | ||
567 | return false; | |
568 | } | |
569 | ||
32291f94 MM |
570 | /* Do any final processing required for the declarations in VEC, of |
571 | which there are LEN. We write out inline functions and variables | |
572 | that have been deferred until this point, but which are required. | |
0e9e1e0a | 573 | Returns nonzero if anything was put out. */ |
854a97f0 | 574 | |
db5f8b93 | 575 | bool |
e25a75e6 | 576 | wrapup_global_declarations (tree *vec, int len) |
32291f94 | 577 | { |
db5f8b93 | 578 | bool reconsider, output_something = false; |
32291f94 | 579 | int i; |
32291f94 MM |
580 | |
581 | for (i = 0; i < len; i++) | |
db5f8b93 | 582 | wrapup_global_declaration_1 (vec[i]); |
32291f94 MM |
583 | |
584 | /* Now emit any global variables or functions that we have been | |
585 | putting off. We need to loop in case one of the things emitted | |
586 | here references another one which comes earlier in the list. */ | |
587 | do | |
588 | { | |
db5f8b93 | 589 | reconsider = false; |
32291f94 | 590 | for (i = 0; i < len; i++) |
db5f8b93 | 591 | reconsider |= wrapup_global_declaration_2 (vec[i]); |
32291f94 | 592 | if (reconsider) |
db5f8b93 | 593 | output_something = true; |
32291f94 MM |
594 | } |
595 | while (reconsider); | |
596 | ||
597 | return output_something; | |
598 | } | |
599 | ||
db5f8b93 RH |
600 | /* A subroutine of check_global_declarations. Issue appropriate warnings |
601 | for the global declaration DECL. */ | |
602 | ||
603 | void | |
604 | check_global_declaration_1 (tree decl) | |
605 | { | |
606 | /* Warn about any function declared static but not defined. We don't | |
607 | warn about variables, because many programs have static variables | |
608 | that exist only to get some text into the object file. */ | |
609 | if (TREE_CODE (decl) == FUNCTION_DECL | |
610 | && DECL_INITIAL (decl) == 0 | |
611 | && DECL_EXTERNAL (decl) | |
612 | && ! DECL_ARTIFICIAL (decl) | |
613 | && ! TREE_NO_WARNING (decl) | |
614 | && ! TREE_PUBLIC (decl) | |
615 | && (warn_unused_function | |
616 | || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))) | |
617 | { | |
618 | if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))) | |
509c9d60 | 619 | pedwarn (input_location, 0, "%q+F used but never defined", decl); |
db5f8b93 | 620 | else |
c5409249 | 621 | warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl); |
db5f8b93 RH |
622 | /* This symbol is effectively an "extern" declaration now. */ |
623 | TREE_PUBLIC (decl) = 1; | |
624 | assemble_external (decl); | |
625 | } | |
626 | ||
627 | /* Warn about static fns or vars defined but not used. */ | |
628 | if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL) | |
629 | /* We don't warn about "static const" variables because the | |
630 | "rcs_id" idiom uses that construction. */ | |
631 | || (warn_unused_variable | |
632 | && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl))) | |
633 | && ! DECL_IN_SYSTEM_HEADER (decl) | |
634 | && ! TREE_USED (decl) | |
635 | /* The TREE_USED bit for file-scope decls is kept in the identifier, | |
636 | to handle multiple external decls in different scopes. */ | |
eb2182e2 | 637 | && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl))) |
db5f8b93 RH |
638 | && ! DECL_EXTERNAL (decl) |
639 | && ! TREE_PUBLIC (decl) | |
640 | /* A volatile variable might be used in some non-obvious way. */ | |
641 | && ! TREE_THIS_VOLATILE (decl) | |
642 | /* Global register variables must be declared to reserve them. */ | |
643 | && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl)) | |
644 | /* Otherwise, ask the language. */ | |
645 | && lang_hooks.decls.warn_unused_global (decl)) | |
b8698a0f L |
646 | warning ((TREE_CODE (decl) == FUNCTION_DECL) |
647 | ? OPT_Wunused_function | |
648 | : OPT_Wunused_variable, | |
c5409249 | 649 | "%q+D defined but not used", decl); |
db5f8b93 RH |
650 | } |
651 | ||
32291f94 | 652 | /* Issue appropriate warnings for the global declarations in VEC (of |
db5f8b93 | 653 | which there are LEN). */ |
854a97f0 | 654 | |
32291f94 | 655 | void |
e25a75e6 | 656 | check_global_declarations (tree *vec, int len) |
32291f94 | 657 | { |
32291f94 MM |
658 | int i; |
659 | ||
660 | for (i = 0; i < len; i++) | |
db5f8b93 RH |
661 | check_global_declaration_1 (vec[i]); |
662 | } | |
32291f94 | 663 | |
db5f8b93 RH |
664 | /* Emit debugging information for all global declarations in VEC. */ |
665 | ||
666 | void | |
667 | emit_debug_global_declarations (tree *vec, int len) | |
668 | { | |
669 | int i; | |
670 | ||
671 | /* Avoid confusing the debug information machinery when there are errors. */ | |
1da2ed5f | 672 | if (seen_error ()) |
db5f8b93 RH |
673 | return; |
674 | ||
675 | timevar_push (TV_SYMOUT); | |
676 | for (i = 0; i < len; i++) | |
677 | debug_hooks->global_decl (vec[i]); | |
678 | timevar_pop (TV_SYMOUT); | |
32291f94 | 679 | } |
032713aa | 680 | |
43f9ce02 GDR |
681 | /* Warn about a use of an identifier which was marked deprecated. */ |
682 | void | |
9b86d6bb | 683 | warn_deprecated_use (tree node, tree attr) |
43f9ce02 | 684 | { |
9b86d6bb L |
685 | const char *msg; |
686 | ||
43f9ce02 GDR |
687 | if (node == 0 || !warn_deprecated_decl) |
688 | return; | |
689 | ||
9b86d6bb L |
690 | if (!attr) |
691 | { | |
692 | if (DECL_P (node)) | |
693 | attr = DECL_ATTRIBUTES (node); | |
694 | else if (TYPE_P (node)) | |
695 | { | |
696 | tree decl = TYPE_STUB_DECL (node); | |
697 | if (decl) | |
698 | attr = lookup_attribute ("deprecated", | |
699 | TYPE_ATTRIBUTES (TREE_TYPE (decl))); | |
700 | } | |
701 | } | |
702 | ||
703 | if (attr) | |
704 | attr = lookup_attribute ("deprecated", attr); | |
705 | ||
706 | if (attr) | |
707 | msg = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))); | |
708 | else | |
709 | msg = NULL; | |
710 | ||
43f9ce02 | 711 | if (DECL_P (node)) |
c1667470 PB |
712 | { |
713 | expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node)); | |
9b86d6bb L |
714 | if (msg) |
715 | warning (OPT_Wdeprecated_declarations, | |
716 | "%qD is deprecated (declared at %s:%d): %s", | |
717 | node, xloc.file, xloc.line, msg); | |
718 | else | |
719 | warning (OPT_Wdeprecated_declarations, | |
720 | "%qD is deprecated (declared at %s:%d)", | |
721 | node, xloc.file, xloc.line); | |
c1667470 | 722 | } |
43f9ce02 GDR |
723 | else if (TYPE_P (node)) |
724 | { | |
4f1e4960 | 725 | tree what = NULL_TREE; |
43f9ce02 GDR |
726 | tree decl = TYPE_STUB_DECL (node); |
727 | ||
108ebf88 JM |
728 | if (TYPE_NAME (node)) |
729 | { | |
730 | if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE) | |
4f1e4960 | 731 | what = TYPE_NAME (node); |
108ebf88 JM |
732 | else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL |
733 | && DECL_NAME (TYPE_NAME (node))) | |
4f1e4960 | 734 | what = DECL_NAME (TYPE_NAME (node)); |
108ebf88 | 735 | } |
43f9ce02 | 736 | |
c1667470 | 737 | if (decl) |
43f9ce02 | 738 | { |
c1667470 PB |
739 | expanded_location xloc |
740 | = expand_location (DECL_SOURCE_LOCATION (decl)); | |
741 | if (what) | |
9b86d6bb L |
742 | { |
743 | if (msg) | |
744 | warning (OPT_Wdeprecated_declarations, | |
745 | "%qE is deprecated (declared at %s:%d): %s", | |
746 | what, xloc.file, xloc.line, msg); | |
747 | else | |
748 | warning (OPT_Wdeprecated_declarations, | |
749 | "%qE is deprecated (declared at %s:%d)", what, | |
750 | xloc.file, xloc.line); | |
751 | } | |
43f9ce02 | 752 | else |
9b86d6bb L |
753 | { |
754 | if (msg) | |
755 | warning (OPT_Wdeprecated_declarations, | |
756 | "type is deprecated (declared at %s:%d): %s", | |
757 | xloc.file, xloc.line, msg); | |
758 | else | |
759 | warning (OPT_Wdeprecated_declarations, | |
760 | "type is deprecated (declared at %s:%d)", | |
761 | xloc.file, xloc.line); | |
762 | } | |
43f9ce02 | 763 | } |
43f9ce02 | 764 | else |
c1667470 PB |
765 | { |
766 | if (what) | |
9b86d6bb L |
767 | { |
768 | if (msg) | |
769 | warning (OPT_Wdeprecated_declarations, "%qE is deprecated: %s", | |
770 | what, msg); | |
771 | else | |
772 | warning (OPT_Wdeprecated_declarations, "%qE is deprecated", what); | |
773 | } | |
108ebf88 | 774 | else |
9b86d6bb L |
775 | { |
776 | if (msg) | |
777 | warning (OPT_Wdeprecated_declarations, "type is deprecated: %s", | |
778 | msg); | |
779 | else | |
780 | warning (OPT_Wdeprecated_declarations, "type is deprecated"); | |
781 | } | |
c1667470 | 782 | } |
43f9ce02 GDR |
783 | } |
784 | } | |
785 | ||
f5e99456 NB |
786 | /* Compile an entire translation unit. Write a file of assembly |
787 | output and various debugging dumps. */ | |
4291d9c8 RS |
788 | |
789 | static void | |
e25a75e6 | 790 | compile_file (void) |
4291d9c8 | 791 | { |
4291d9c8 RS |
792 | /* Initialize yet another pass. */ |
793 | ||
dae4174e TT |
794 | ggc_protect_identifiers = true; |
795 | ||
9b3e897d | 796 | init_cgraph (); |
b93a436e | 797 | init_final (main_input_filename); |
ca29da43 | 798 | coverage_init (aux_base_name); |
9fe0cb7d | 799 | statistics_init (); |
78bf7bd0 | 800 | invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL); |
4291d9c8 | 801 | |
2a9a326b | 802 | timevar_push (TV_PARSE); |
4291d9c8 | 803 | |
52dabb6c NB |
804 | /* Call the parser, which parses the entire file (calling |
805 | rest_of_compilation for each function). */ | |
b37421c6 | 806 | lang_hooks.parse_file (); |
4291d9c8 | 807 | |
4291d9c8 RS |
808 | /* Compilation is now finished except for writing |
809 | what's left of the symbol table output. */ | |
2a9a326b | 810 | timevar_pop (TV_PARSE); |
4291d9c8 | 811 | |
49ba8180 | 812 | if (flag_syntax_only || flag_wpa) |
22703ccc | 813 | return; |
1fe65c00 | 814 | |
dae4174e TT |
815 | ggc_protect_identifiers = false; |
816 | ||
2329c6f5 | 817 | /* This must also call cgraph_finalize_compilation_unit. */ |
ae2bcd98 | 818 | lang_hooks.decls.final_write_globals (); |
e4305460 | 819 | |
1da2ed5f | 820 | if (seen_error ()) |
e4305460 GK |
821 | return; |
822 | ||
8a4a83ed | 823 | varpool_assemble_pending_decls (); |
e4d5432a | 824 | finish_aliases_2 (); |
e69529cd | 825 | |
ccab73c3 FCE |
826 | /* Likewise for mudflap static object registrations. */ |
827 | if (flag_mudflap) | |
828 | mudflap_finish_file (); | |
829 | ||
1d3dbd99 | 830 | output_shared_constant_pool (); |
aacd3885 RS |
831 | output_object_blocks (); |
832 | ||
4b8af8d9 | 833 | /* Write out any pending weak symbol declarations. */ |
4b8af8d9 JM |
834 | weak_finish (); |
835 | ||
6d217c32 JJ |
836 | /* This must be at the end before unwind and debug info. |
837 | Some target ports emit PIC setup thunks here. */ | |
838 | targetm.asm_out.code_end (); | |
839 | ||
854a97f0 | 840 | /* Do dbx symbols. */ |
2a9a326b | 841 | timevar_push (TV_SYMOUT); |
7f905405 | 842 | |
658f32fd | 843 | #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO |
0021b564 JM |
844 | if (dwarf2out_do_frame ()) |
845 | dwarf2out_frame_finish (); | |
846 | #endif | |
847 | ||
e2a12aca | 848 | (*debug_hooks->finish) (main_input_filename); |
2a9a326b | 849 | timevar_pop (TV_SYMOUT); |
9a666dda | 850 | |
4291d9c8 RS |
851 | /* Output some stuff at end of file if nec. */ |
852 | ||
2a1ee410 RH |
853 | dw2_output_indirect_constants (); |
854 | ||
c47c29c8 | 855 | /* Flush any pending external directives. */ |
bc6d19ab ZW |
856 | process_pending_assemble_externals (); |
857 | ||
d7f09764 DN |
858 | /* Emit LTO marker if LTO info has been previously emitted. This is |
859 | used by collect2 to determine whether an object file contains IL. | |
860 | We used to emit an undefined reference here, but this produces | |
861 | link errors if an object file with IL is stored into a shared | |
862 | library without invoking lto1. */ | |
863 | if (flag_generate_lto) | |
5a013dc4 RG |
864 | { |
865 | #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON | |
866 | ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE, | |
867 | "__gnu_lto_v1", | |
868 | (unsigned HOST_WIDE_INT) 1, 8); | |
869 | #elif defined ASM_OUTPUT_ALIGNED_COMMON | |
870 | ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_v1", | |
871 | (unsigned HOST_WIDE_INT) 1, 8); | |
872 | #else | |
873 | ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_v1", | |
874 | (unsigned HOST_WIDE_INT) 1, | |
875 | (unsigned HOST_WIDE_INT) 1); | |
876 | #endif | |
877 | } | |
d7f09764 | 878 | |
acb0db7b ZW |
879 | /* Attach a special .ident directive to the end of the file to identify |
880 | the version of GCC which compiled this code. The format of the .ident | |
881 | string is patterned after the ones produced by native SVR4 compilers. */ | |
882 | #ifdef IDENT_ASM_OP | |
883 | if (!flag_no_ident) | |
2f41c1d6 PB |
884 | { |
885 | const char *pkg_version = "(GNU) "; | |
886 | ||
887 | if (strcmp ("(GCC) ", pkgversion_string)) | |
888 | pkg_version = pkgversion_string; | |
889 | fprintf (asm_out_file, "%s\"GCC: %s%s\"\n", | |
890 | IDENT_ASM_OP, pkg_version, version_string); | |
891 | } | |
acb0db7b | 892 | #endif |
57bef48e | 893 | |
9c8e65c3 OR |
894 | /* Invoke registered plugin callbacks. */ |
895 | invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL); | |
b8698a0f | 896 | |
57bef48e AP |
897 | /* This must be at the end. Some target ports emit end of file directives |
898 | into the assembly file here, and hence we can not output anything to the | |
899 | assembly file after this point. */ | |
900 | targetm.asm_out.file_end (); | |
4291d9c8 | 901 | } |
ddc9542b | 902 | |
f6db1481 RH |
903 | /* Indexed by enum debug_info_type. */ |
904 | const char *const debug_type_names[] = | |
4291d9c8 | 905 | { |
8f49f0f1 | 906 | "none", "stabs", "coff", "dwarf-2", "xcoff", "vms" |
f6db1481 | 907 | }; |
1b3d8f8a | 908 | |
f6db1481 RH |
909 | /* Print version information to FILE. |
910 | Each line begins with INDENT (for the case where FILE is the | |
911 | assembler output file). */ | |
3c030e88 | 912 | |
f6db1481 RH |
913 | void |
914 | print_version (FILE *file, const char *indent) | |
f5e99456 | 915 | { |
ab532386 | 916 | static const char fmt1[] = |
f5e99456 | 917 | #ifdef __GNUC__ |
2f41c1d6 | 918 | N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ") |
f5e99456 | 919 | #else |
2f41c1d6 | 920 | N_("%s%s%s %sversion %s (%s) compiled by CC, ") |
f5e99456 | 921 | #endif |
ab532386 JM |
922 | ; |
923 | static const char fmt2[] = | |
c128599a | 924 | N_("GMP version %s, MPFR version %s, MPC version %s\n"); |
0968bb3d | 925 | static const char fmt3[] = |
3a204175 | 926 | N_("%s%swarning: %s header version %s differs from library version %s.\n"); |
0968bb3d | 927 | static const char fmt4[] = |
ab532386 JM |
928 | N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n"); |
929 | #ifndef __VERSION__ | |
930 | #define __VERSION__ "[?]" | |
931 | #endif | |
932 | fprintf (file, | |
933 | file == stderr ? _(fmt1) : fmt1, | |
934 | indent, *indent != 0 ? " " : "", | |
2f41c1d6 | 935 | lang_hooks.name, pkgversion_string, version_string, TARGET_NAME, |
f5e99456 | 936 | indent, __VERSION__); |
0968bb3d KG |
937 | |
938 | /* We need to stringify the GMP macro values. Ugh, gmp_version has | |
04be270f KG |
939 | two string formats, "i.j.k" and "i.j" when k is zero. As of |
940 | gmp-4.3.0, GMP always uses the 3 number format. */ | |
0968bb3d KG |
941 | #define GCC_GMP_STRINGIFY_VERSION3(X) #X |
942 | #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X) | |
04be270f KG |
943 | #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z)) |
944 | #define GCC_GMP_VERSION \ | |
945 | GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL) | |
946 | #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0 | |
0968bb3d KG |
947 | #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \ |
948 | GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) | |
949 | #else | |
950 | #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \ | |
951 | GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \ | |
952 | GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL) | |
953 | #endif | |
ab532386 JM |
954 | fprintf (file, |
955 | file == stderr ? _(fmt2) : fmt2, | |
16a19648 | 956 | GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING, MPC_VERSION_STRING); |
0968bb3d KG |
957 | if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version)) |
958 | fprintf (file, | |
959 | file == stderr ? _(fmt3) : fmt3, | |
3a204175 | 960 | indent, *indent != 0 ? " " : "", |
0968bb3d KG |
961 | "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version); |
962 | if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ())) | |
963 | fprintf (file, | |
964 | file == stderr ? _(fmt3) : fmt3, | |
3a204175 | 965 | indent, *indent != 0 ? " " : "", |
0968bb3d | 966 | "MPFR", MPFR_VERSION_STRING, mpfr_get_version ()); |
c128599a KG |
967 | if (strcmp (MPC_VERSION_STRING, mpc_get_version ())) |
968 | fprintf (file, | |
969 | file == stderr ? _(fmt3) : fmt3, | |
970 | indent, *indent != 0 ? " " : "", | |
971 | "MPC", MPC_VERSION_STRING, mpc_get_version ()); | |
0968bb3d KG |
972 | fprintf (file, |
973 | file == stderr ? _(fmt4) : fmt4, | |
7a69a172 GB |
974 | indent, *indent != 0 ? " " : "", |
975 | PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE)); | |
44e9f006 RAE |
976 | |
977 | print_plugins_versions (file, indent); | |
f5e99456 NB |
978 | } |
979 | ||
e0d9d0dd NC |
980 | #ifdef ASM_COMMENT_START |
981 | static int | |
982 | print_to_asm_out_file (print_switch_type type, const char * text) | |
983 | { | |
984 | bool prepend_sep = true; | |
985 | ||
986 | switch (type) | |
987 | { | |
988 | case SWITCH_TYPE_LINE_END: | |
989 | putc ('\n', asm_out_file); | |
990 | return 1; | |
991 | ||
992 | case SWITCH_TYPE_LINE_START: | |
993 | fputs (ASM_COMMENT_START, asm_out_file); | |
994 | return strlen (ASM_COMMENT_START); | |
995 | ||
996 | case SWITCH_TYPE_DESCRIPTIVE: | |
997 | if (ASM_COMMENT_START[0] == 0) | |
998 | prepend_sep = false; | |
999 | /* Drop through. */ | |
1000 | case SWITCH_TYPE_PASSED: | |
1001 | case SWITCH_TYPE_ENABLED: | |
1002 | if (prepend_sep) | |
1003 | fputc (' ', asm_out_file); | |
edb30094 | 1004 | fputs (text, asm_out_file); |
e0d9d0dd NC |
1005 | /* No need to return the length here as |
1006 | print_single_switch has already done it. */ | |
1007 | return 0; | |
1008 | ||
1009 | default: | |
1010 | return -1; | |
1011 | } | |
1012 | } | |
1013 | #endif | |
1014 | ||
1015 | static int | |
1016 | print_to_stderr (print_switch_type type, const char * text) | |
1017 | { | |
1018 | switch (type) | |
1019 | { | |
1020 | case SWITCH_TYPE_LINE_END: | |
1021 | putc ('\n', stderr); | |
1022 | return 1; | |
1023 | ||
1024 | case SWITCH_TYPE_LINE_START: | |
1025 | return 0; | |
b8698a0f | 1026 | |
e0d9d0dd NC |
1027 | case SWITCH_TYPE_PASSED: |
1028 | case SWITCH_TYPE_ENABLED: | |
1029 | fputc (' ', stderr); | |
1030 | /* Drop through. */ | |
1031 | ||
1032 | case SWITCH_TYPE_DESCRIPTIVE: | |
edb30094 | 1033 | fputs (text, stderr); |
e0d9d0dd NC |
1034 | /* No need to return the length here as |
1035 | print_single_switch has already done it. */ | |
1036 | return 0; | |
1037 | ||
1038 | default: | |
1039 | return -1; | |
1040 | } | |
1041 | } | |
1042 | ||
f5e99456 | 1043 | /* Print an option value and return the adjusted position in the line. |
e0d9d0dd NC |
1044 | ??? print_fn doesn't handle errors, eg disk full; presumably other |
1045 | code will catch a disk full though. */ | |
f5e99456 NB |
1046 | |
1047 | static int | |
e0d9d0dd NC |
1048 | print_single_switch (print_switch_fn_type print_fn, |
1049 | int pos, | |
1050 | print_switch_type type, | |
1051 | const char * text) | |
f5e99456 | 1052 | { |
e0d9d0dd NC |
1053 | /* The ultrix fprintf returns 0 on success, so compute the result |
1054 | we want here since we need it for the following test. The +1 | |
2e226e66 | 1055 | is for the separator character that will probably be emitted. */ |
e0d9d0dd | 1056 | int len = strlen (text) + 1; |
f5e99456 NB |
1057 | |
1058 | if (pos != 0 | |
e0d9d0dd | 1059 | && pos + len > MAX_LINE) |
f5e99456 | 1060 | { |
e0d9d0dd | 1061 | print_fn (SWITCH_TYPE_LINE_END, NULL); |
f5e99456 NB |
1062 | pos = 0; |
1063 | } | |
e0d9d0dd | 1064 | |
f5e99456 | 1065 | if (pos == 0) |
e0d9d0dd NC |
1066 | pos += print_fn (SWITCH_TYPE_LINE_START, NULL); |
1067 | ||
1068 | print_fn (type, text); | |
1069 | return pos + len; | |
f5e99456 NB |
1070 | } |
1071 | ||
e0d9d0dd | 1072 | /* Print active target switches using PRINT_FN. |
f5e99456 NB |
1073 | POS is the current cursor position and MAX is the size of a "line". |
1074 | Each line begins with INDENT and ends with TERM. | |
1075 | Each switch is separated from the next by SEP. */ | |
1076 | ||
1077 | static void | |
e0d9d0dd | 1078 | print_switch_values (print_switch_fn_type print_fn) |
f5e99456 | 1079 | { |
e0d9d0dd | 1080 | int pos = 0; |
f5e99456 | 1081 | size_t j; |
f5e99456 | 1082 | |
a37db56b | 1083 | /* Fill in the -frandom-seed option, if the user didn't pass it, so |
c07e5477 | 1084 | that it can be printed below. This helps reproducibility. */ |
403d4851 AO |
1085 | if (!flag_random_seed) |
1086 | init_random_seed (); | |
a37db56b | 1087 | |
f5e99456 | 1088 | /* Print the options as passed. */ |
e0d9d0dd NC |
1089 | pos = print_single_switch (print_fn, pos, |
1090 | SWITCH_TYPE_DESCRIPTIVE, _("options passed: ")); | |
f5e99456 | 1091 | |
6e2f1956 | 1092 | for (j = 1; j < save_decoded_options_count; j++) |
e0d9d0dd | 1093 | { |
6e2f1956 | 1094 | switch (save_decoded_options[j].opt_index) |
e0d9d0dd | 1095 | { |
6e2f1956 JM |
1096 | case OPT_o: |
1097 | case OPT_d: | |
1098 | case OPT_dumpbase: | |
1099 | case OPT_dumpdir: | |
1100 | case OPT_auxbase: | |
1101 | case OPT_quiet: | |
1102 | case OPT_version: | |
e0d9d0dd | 1103 | /* Ignore these. */ |
6e2f1956 | 1104 | continue; |
e0d9d0dd NC |
1105 | } |
1106 | ||
6e2f1956 JM |
1107 | pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED, |
1108 | save_decoded_options[j].orig_option_with_args_text); | |
e0d9d0dd NC |
1109 | } |
1110 | ||
f5e99456 | 1111 | if (pos > 0) |
e0d9d0dd | 1112 | print_fn (SWITCH_TYPE_LINE_END, NULL); |
f5e99456 NB |
1113 | |
1114 | /* Print the -f and -m options that have been enabled. | |
1115 | We don't handle language specific options but printing argv | |
1116 | should suffice. */ | |
e0d9d0dd NC |
1117 | pos = print_single_switch (print_fn, 0, |
1118 | SWITCH_TYPE_DESCRIPTIVE, _("options enabled: ")); | |
f5e99456 | 1119 | |
50431bc4 | 1120 | for (j = 0; j < cl_options_count; j++) |
75685792 | 1121 | if ((cl_options[j].flags & CL_REPORT) |
46625112 | 1122 | && option_enabled (j, &global_options) > 0) |
e0d9d0dd NC |
1123 | pos = print_single_switch (print_fn, pos, |
1124 | SWITCH_TYPE_ENABLED, cl_options[j].opt_text); | |
f5e99456 | 1125 | |
e0d9d0dd | 1126 | print_fn (SWITCH_TYPE_LINE_END, NULL); |
f5e99456 | 1127 | } |
ddc9542b | 1128 | |
f5e99456 NB |
1129 | /* Open assembly code output file. Do this even if -fsyntax-only is |
1130 | on, because then the driver will have provided the name of a | |
1131 | temporary file or bit bucket for us. NAME is the file specified on | |
1132 | the command line, possibly NULL. */ | |
1133 | static void | |
e25a75e6 | 1134 | init_asm_output (const char *name) |
f5e99456 NB |
1135 | { |
1136 | if (name == NULL && asm_file_name == 0) | |
1137 | asm_out_file = stdout; | |
1138 | else | |
1139 | { | |
1140 | if (asm_file_name == 0) | |
9cabb1d8 KH |
1141 | { |
1142 | int len = strlen (dump_base_name); | |
a8a4fe0c | 1143 | char *dumpname = XNEWVEC (char, len + 6); |
e0d9d0dd | 1144 | |
9cabb1d8 KH |
1145 | memcpy (dumpname, dump_base_name, len + 1); |
1146 | strip_off_ending (dumpname, len); | |
1147 | strcat (dumpname, ".s"); | |
1148 | asm_file_name = dumpname; | |
1149 | } | |
f5e99456 | 1150 | if (!strcmp (asm_file_name, "-")) |
9cabb1d8 | 1151 | asm_out_file = stdout; |
f5e99456 | 1152 | else |
90aa6719 | 1153 | asm_out_file = fopen (asm_file_name, "w+b"); |
f5e99456 | 1154 | if (asm_out_file == 0) |
971801ff | 1155 | fatal_error ("can%'t open %s for writing: %m", asm_file_name); |
f5e99456 NB |
1156 | } |
1157 | ||
f5e99456 NB |
1158 | if (!flag_syntax_only) |
1159 | { | |
1bc7c5b6 | 1160 | targetm.asm_out.file_start (); |
f5e99456 | 1161 | |
e0d9d0dd NC |
1162 | if (flag_record_gcc_switches) |
1163 | { | |
1164 | if (targetm.asm_out.record_gcc_switches) | |
1165 | { | |
1166 | /* Let the target know that we are about to start recording. */ | |
1167 | targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE, | |
1168 | NULL); | |
1169 | /* Now record the switches. */ | |
1170 | print_switch_values (targetm.asm_out.record_gcc_switches); | |
1171 | /* Let the target know that the recording is over. */ | |
1172 | targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE, | |
1173 | NULL); | |
1174 | } | |
1175 | else | |
1f5b3869 | 1176 | inform (input_location, "-frecord-gcc-switches is not supported by the current target"); |
e0d9d0dd NC |
1177 | } |
1178 | ||
f5e99456 NB |
1179 | #ifdef ASM_COMMENT_START |
1180 | if (flag_verbose_asm) | |
1181 | { | |
e0d9d0dd NC |
1182 | /* Print the list of switches in effect |
1183 | into the assembler file as comments. */ | |
f5e99456 | 1184 | print_version (asm_out_file, ASM_COMMENT_START); |
e0d9d0dd | 1185 | print_switch_values (print_to_asm_out_file); |
edb30094 | 1186 | putc ('\n', asm_out_file); |
f5e99456 NB |
1187 | } |
1188 | #endif | |
1189 | } | |
1190 | } | |
ddc9542b | 1191 | |
5c60a017 RS |
1192 | /* Return true if the state of option OPTION should be stored in PCH files |
1193 | and checked by default_pch_valid_p. Store the option's current state | |
1194 | in STATE if so. */ | |
1195 | ||
1196 | static inline bool | |
1197 | option_affects_pch_p (int option, struct cl_option_state *state) | |
1198 | { | |
1199 | if ((cl_options[option].flags & CL_TARGET) == 0) | |
1200 | return false; | |
46625112 | 1201 | if (option_flag_var (option, &global_options) == &target_flags) |
5c60a017 RS |
1202 | if (targetm.check_pch_target_flags) |
1203 | return false; | |
46625112 | 1204 | return get_option_state (&global_options, option, state); |
5c60a017 RS |
1205 | } |
1206 | ||
7bb1ad93 GK |
1207 | /* Default version of get_pch_validity. |
1208 | By default, every flag difference is fatal; that will be mostly right for | |
1209 | most targets, but completely right for very few. */ | |
1210 | ||
1211 | void * | |
0678ade0 | 1212 | default_get_pch_validity (size_t *sz) |
7bb1ad93 | 1213 | { |
5c60a017 | 1214 | struct cl_option_state state; |
7bb1ad93 GK |
1215 | size_t i; |
1216 | char *result, *r; | |
fbfb16e2 | 1217 | |
0678ade0 | 1218 | *sz = 2; |
bacf5b96 | 1219 | if (targetm.check_pch_target_flags) |
0678ade0 | 1220 | *sz += sizeof (target_flags); |
5c60a017 RS |
1221 | for (i = 0; i < cl_options_count; i++) |
1222 | if (option_affects_pch_p (i, &state)) | |
0678ade0 | 1223 | *sz += state.size; |
7bb1ad93 | 1224 | |
0678ade0 | 1225 | result = r = XNEWVEC (char, *sz); |
7bb1ad93 GK |
1226 | r[0] = flag_pic; |
1227 | r[1] = flag_pie; | |
1228 | r += 2; | |
bacf5b96 | 1229 | if (targetm.check_pch_target_flags) |
7bb1ad93 | 1230 | { |
bacf5b96 RS |
1231 | memcpy (r, &target_flags, sizeof (target_flags)); |
1232 | r += sizeof (target_flags); | |
7bb1ad93 | 1233 | } |
bacf5b96 | 1234 | |
5c60a017 RS |
1235 | for (i = 0; i < cl_options_count; i++) |
1236 | if (option_affects_pch_p (i, &state)) | |
1237 | { | |
1238 | memcpy (r, state.data, state.size); | |
1239 | r += state.size; | |
1240 | } | |
7bb1ad93 GK |
1241 | |
1242 | return result; | |
1243 | } | |
1244 | ||
bacf5b96 RS |
1245 | /* Return a message which says that a PCH file was created with a different |
1246 | setting of OPTION. */ | |
1247 | ||
1248 | static const char * | |
1249 | pch_option_mismatch (const char *option) | |
1250 | { | |
1251 | char *r; | |
1252 | ||
1253 | asprintf (&r, _("created and used with differing settings of '%s'"), option); | |
1254 | if (r == NULL) | |
1255 | return _("out of memory"); | |
1256 | return r; | |
1257 | } | |
1258 | ||
7bb1ad93 GK |
1259 | /* Default version of pch_valid_p. */ |
1260 | ||
1261 | const char * | |
1262 | default_pch_valid_p (const void *data_p, size_t len) | |
1263 | { | |
5c60a017 | 1264 | struct cl_option_state state; |
7bb1ad93 | 1265 | const char *data = (const char *)data_p; |
7bb1ad93 | 1266 | size_t i; |
fbfb16e2 | 1267 | |
7bb1ad93 GK |
1268 | /* -fpic and -fpie also usually make a PCH invalid. */ |
1269 | if (data[0] != flag_pic) | |
1270 | return _("created and used with different settings of -fpic"); | |
1271 | if (data[1] != flag_pie) | |
1272 | return _("created and used with different settings of -fpie"); | |
1273 | data += 2; | |
1274 | ||
1275 | /* Check target_flags. */ | |
8d932be3 RS |
1276 | if (targetm.check_pch_target_flags) |
1277 | { | |
bacf5b96 RS |
1278 | int tf; |
1279 | const char *r; | |
1280 | ||
1281 | memcpy (&tf, data, sizeof (target_flags)); | |
1282 | data += sizeof (target_flags); | |
1283 | len -= sizeof (target_flags); | |
1284 | r = targetm.check_pch_target_flags (tf); | |
8d932be3 RS |
1285 | if (r != NULL) |
1286 | return r; | |
1287 | } | |
7bb1ad93 | 1288 | |
5c60a017 RS |
1289 | for (i = 0; i < cl_options_count; i++) |
1290 | if (option_affects_pch_p (i, &state)) | |
1291 | { | |
1292 | if (memcmp (data, state.data, state.size) != 0) | |
bacf5b96 | 1293 | return pch_option_mismatch (cl_options[i].opt_text); |
5c60a017 RS |
1294 | data += state.size; |
1295 | len -= state.size; | |
1296 | } | |
1297 | ||
7bb1ad93 | 1298 | return NULL; |
7bb1ad93 GK |
1299 | } |
1300 | ||
b6fe0bb8 | 1301 | /* Default tree printer. Handles declarations only. */ |
4537ec0c DN |
1302 | bool |
1303 | default_tree_printer (pretty_printer *pp, text_info *text, const char *spec, | |
dee15844 | 1304 | int precision, bool wide, bool set_locus, bool hash) |
b6fe0bb8 | 1305 | { |
dad2a933 RH |
1306 | tree t; |
1307 | ||
39ce81c9 | 1308 | /* FUTURE: %+x should set the locus. */ |
dee15844 | 1309 | if (precision != 0 || wide || hash) |
39ce81c9 ZW |
1310 | return false; |
1311 | ||
1312 | switch (*spec) | |
b6fe0bb8 | 1313 | { |
4e53d196 SB |
1314 | case 'E': |
1315 | t = va_arg (*text->args_ptr, tree); | |
1316 | if (TREE_CODE (t) == IDENTIFIER_NODE) | |
1317 | { | |
4f1e4960 | 1318 | pp_identifier (pp, IDENTIFIER_POINTER (t)); |
4e53d196 SB |
1319 | return true; |
1320 | } | |
1321 | break; | |
1322 | ||
b6fe0bb8 | 1323 | case 'D': |
dad2a933 | 1324 | t = va_arg (*text->args_ptr, tree); |
f991abd1 | 1325 | if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t)) |
dad2a933 RH |
1326 | t = DECL_DEBUG_EXPR (t); |
1327 | break; | |
1328 | ||
b6fe0bb8 GDR |
1329 | case 'F': |
1330 | case 'T': | |
dad2a933 RH |
1331 | t = va_arg (*text->args_ptr, tree); |
1332 | break; | |
b6fe0bb8 | 1333 | |
cf835838 JM |
1334 | case 'K': |
1335 | percent_K_format (text); | |
1336 | return true; | |
1337 | ||
b6fe0bb8 GDR |
1338 | default: |
1339 | return false; | |
1340 | } | |
dad2a933 | 1341 | |
dee15844 JM |
1342 | if (set_locus && text->locus) |
1343 | *text->locus = DECL_SOURCE_LOCATION (t); | |
1344 | ||
dad2a933 RH |
1345 | if (DECL_P (t)) |
1346 | { | |
1347 | const char *n = DECL_NAME (t) | |
4f1e4960 JM |
1348 | ? identifier_to_locale (lang_hooks.decl_printable_name (t, 2)) |
1349 | : _("<anonymous>"); | |
dad2a933 RH |
1350 | pp_string (pp, n); |
1351 | } | |
1352 | else | |
438d798f | 1353 | dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0); |
dad2a933 RH |
1354 | |
1355 | return true; | |
b6fe0bb8 GDR |
1356 | } |
1357 | ||
5ffeb913 TT |
1358 | /* A helper function; used as the reallocator function for cpp's line |
1359 | table. */ | |
1360 | static void * | |
1361 | realloc_for_line_map (void *ptr, size_t len) | |
1362 | { | |
a9429e29 | 1363 | return GGC_RESIZEVAR (void, ptr, len); |
5ffeb913 TT |
1364 | } |
1365 | ||
ab9b814d JM |
1366 | /* A helper function: used as the allocator function for |
1367 | identifier_to_locale. */ | |
1368 | static void * | |
1369 | alloc_for_identifier_to_locale (size_t len) | |
1370 | { | |
a9429e29 | 1371 | return ggc_alloc_atomic (len); |
ab9b814d JM |
1372 | } |
1373 | ||
d3c12306 EB |
1374 | /* Output stack usage information. */ |
1375 | void | |
1376 | output_stack_usage (void) | |
1377 | { | |
1378 | static bool warning_issued = false; | |
1379 | enum stack_usage_kind_type { STATIC = 0, DYNAMIC, DYNAMIC_BOUNDED }; | |
1380 | const char *stack_usage_kind_str[] = { | |
1381 | "static", | |
1382 | "dynamic", | |
1383 | "dynamic,bounded" | |
1384 | }; | |
1385 | HOST_WIDE_INT stack_usage = current_function_static_stack_size; | |
1386 | enum stack_usage_kind_type stack_usage_kind; | |
1387 | expanded_location loc; | |
1388 | const char *raw_id, *id; | |
1389 | ||
1390 | if (stack_usage < 0) | |
1391 | { | |
1392 | if (!warning_issued) | |
1393 | { | |
1394 | warning (0, "-fstack-usage not supported for this target"); | |
1395 | warning_issued = true; | |
1396 | } | |
1397 | return; | |
1398 | } | |
1399 | ||
1400 | stack_usage_kind = STATIC; | |
1401 | ||
1402 | /* Add the maximum amount of space pushed onto the stack. */ | |
1403 | if (current_function_pushed_stack_size > 0) | |
1404 | { | |
1405 | stack_usage += current_function_pushed_stack_size; | |
1406 | stack_usage_kind = DYNAMIC_BOUNDED; | |
1407 | } | |
1408 | ||
1409 | /* Now on to the tricky part: dynamic stack allocation. */ | |
1410 | if (current_function_allocates_dynamic_stack_space) | |
1411 | { | |
1412 | if (current_function_has_unbounded_dynamic_stack_size) | |
1413 | stack_usage_kind = DYNAMIC; | |
1414 | else | |
1415 | stack_usage_kind = DYNAMIC_BOUNDED; | |
1416 | ||
1417 | /* Add the size even in the unbounded case, this can't hurt. */ | |
1418 | stack_usage += current_function_dynamic_stack_size; | |
1419 | } | |
1420 | ||
1421 | loc = expand_location (DECL_SOURCE_LOCATION (current_function_decl)); | |
1422 | ||
1423 | /* Strip the scope prefix if any. */ | |
1424 | raw_id = lang_hooks.decl_printable_name (current_function_decl, 2); | |
1425 | id = strrchr (raw_id, '.'); | |
1426 | if (id) | |
1427 | id++; | |
1428 | else | |
1429 | id = raw_id; | |
1430 | ||
1431 | fprintf (stack_usage_file, | |
1432 | "%s:%d:%d:%s\t"HOST_WIDE_INT_PRINT_DEC"\t%s\n", | |
86923f6e | 1433 | lbasename (loc.file), |
d3c12306 EB |
1434 | loc.line, |
1435 | loc.column, | |
1436 | id, | |
1437 | stack_usage, | |
1438 | stack_usage_kind_str[stack_usage_kind]); | |
1439 | } | |
1440 | ||
1441 | /* Open an auxiliary output file. */ | |
1442 | static FILE * | |
1443 | open_auxiliary_file (const char *ext) | |
1444 | { | |
1445 | char *filename; | |
1446 | FILE *file; | |
1447 | ||
1448 | filename = concat (aux_base_name, ".", ext, NULL); | |
1449 | file = fopen (filename, "w"); | |
1450 | if (!file) | |
d8a07487 | 1451 | fatal_error ("can%'t open %s for writing: %m", filename); |
d3c12306 EB |
1452 | free (filename); |
1453 | return file; | |
1454 | } | |
1455 | ||
f5e99456 NB |
1456 | /* Initialization of the front end environment, before command line |
1457 | options are parsed. Signal handlers, internationalization etc. | |
1458 | ARGV0 is main's argv[0]. */ | |
1459 | static void | |
b86f6cd9 | 1460 | general_init (const char *argv0) |
f5e99456 | 1461 | { |
b86f6cd9 | 1462 | const char *p; |
f5e99456 NB |
1463 | |
1464 | p = argv0 + strlen (argv0); | |
1465 | while (p != argv0 && !IS_DIR_SEPARATOR (p[-1])) | |
1466 | --p; | |
1467 | progname = p; | |
1468 | ||
1469 | xmalloc_set_program_name (progname); | |
e1a132c6 | 1470 | |
5351f1ca NB |
1471 | hex_init (); |
1472 | ||
98a3dad4 | 1473 | /* Unlock the stdio streams. */ |
2653bb0c | 1474 | unlock_std_streams (); |
98a3dad4 | 1475 | |
191bf464 | 1476 | gcc_init_libintl (); |
ab87f8c8 | 1477 | |
ab9b814d JM |
1478 | identifier_to_locale_alloc = alloc_for_identifier_to_locale; |
1479 | identifier_to_locale_free = ggc_free; | |
1480 | ||
b6fe0bb8 GDR |
1481 | /* Initialize the diagnostics reporting machinery, so option parsing |
1482 | can give warnings and errors. */ | |
5f0f4a3b | 1483 | diagnostic_initialize (global_dc, N_OPTS); |
cf835838 | 1484 | diagnostic_starter (global_dc) = default_tree_diagnostic_starter; |
b6fe0bb8 GDR |
1485 | /* Set a default printer. Language specific initializations will |
1486 | override it later. */ | |
1487 | pp_format_decoder (global_dc->printer) = &default_tree_printer; | |
a75bfaa6 JM |
1488 | global_dc->show_option_requested |
1489 | = global_options_init.x_flag_diagnostics_show_option; | |
1490 | global_dc->show_column | |
1491 | = global_options_init.x_flag_show_column; | |
a13812e2 | 1492 | global_dc->internal_error = plugins_internal_error_function; |
5f0f4a3b | 1493 | global_dc->option_enabled = option_enabled; |
46625112 | 1494 | global_dc->option_state = &global_options; |
5f0f4a3b | 1495 | global_dc->option_name = option_name; |
b6fe0bb8 | 1496 | |
a7023245 ZW |
1497 | /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */ |
1498 | #ifdef SIGSEGV | |
1499 | signal (SIGSEGV, crash_signal); | |
935d4b07 | 1500 | #endif |
a7023245 ZW |
1501 | #ifdef SIGILL |
1502 | signal (SIGILL, crash_signal); | |
1503 | #endif | |
1504 | #ifdef SIGBUS | |
1505 | signal (SIGBUS, crash_signal); | |
1506 | #endif | |
1507 | #ifdef SIGABRT | |
1508 | signal (SIGABRT, crash_signal); | |
1509 | #endif | |
1510 | #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT) | |
1511 | signal (SIGIOT, crash_signal); | |
1512 | #endif | |
15e5ad76 ZW |
1513 | #ifdef SIGFPE |
1514 | signal (SIGFPE, crash_signal); | |
1515 | #endif | |
854a97f0 | 1516 | |
476d9098 GK |
1517 | /* Other host-specific signal setup. */ |
1518 | (*host_hooks.extra_signals)(); | |
1519 | ||
c79043f3 NB |
1520 | /* Initialize the garbage-collector, string pools and tree type hash |
1521 | table. */ | |
1522 | init_ggc (); | |
1523 | init_stringpool (); | |
a9429e29 | 1524 | line_table = ggc_alloc_line_maps (); |
5ffeb913 TT |
1525 | linemap_init (line_table); |
1526 | line_table->reallocator = realloc_for_line_map; | |
c79043f3 | 1527 | init_ttree (); |
6a08f7b3 | 1528 | |
f5e99456 NB |
1529 | /* Initialize register usage now so switches may override. */ |
1530 | init_reg_sets (); | |
764dbbf2 | 1531 | |
c6d9a88c MM |
1532 | /* Register the language-independent parameters. */ |
1533 | add_params (lang_independent_params, LAST_PARAM); | |
128dc8e2 | 1534 | targetm.target_option.default_params (); |
c6d9a88c | 1535 | |
9ac121af KG |
1536 | /* This must be done after add_params but before argument processing. */ |
1537 | init_ggc_heuristics(); | |
ef330312 | 1538 | init_optimization_passes (); |
9fe0cb7d | 1539 | statistics_early_init (); |
48476d13 | 1540 | finish_params (); |
a32274ad | 1541 | } |
ddc9542b | 1542 | |
aacd3885 RS |
1543 | /* Return true if the current target supports -fsection-anchors. */ |
1544 | ||
1545 | static bool | |
1546 | target_supports_section_anchors_p (void) | |
1547 | { | |
1548 | if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0) | |
1549 | return false; | |
1550 | ||
1551 | if (targetm.asm_out.output_anchor == NULL) | |
1552 | return false; | |
1553 | ||
1554 | return true; | |
1555 | } | |
1556 | ||
b5deb7b6 SL |
1557 | /* Default the align_* variables to 1 if they're still unset, and |
1558 | set up the align_*_log variables. */ | |
1559 | static void | |
1560 | init_alignments (void) | |
1561 | { | |
1562 | if (align_loops <= 0) | |
1563 | align_loops = 1; | |
1564 | if (align_loops_max_skip > align_loops) | |
1565 | align_loops_max_skip = align_loops - 1; | |
1566 | align_loops_log = floor_log2 (align_loops * 2 - 1); | |
1567 | if (align_jumps <= 0) | |
1568 | align_jumps = 1; | |
1569 | if (align_jumps_max_skip > align_jumps) | |
1570 | align_jumps_max_skip = align_jumps - 1; | |
1571 | align_jumps_log = floor_log2 (align_jumps * 2 - 1); | |
1572 | if (align_labels <= 0) | |
1573 | align_labels = 1; | |
1574 | align_labels_log = floor_log2 (align_labels * 2 - 1); | |
1575 | if (align_labels_max_skip > align_labels) | |
1576 | align_labels_max_skip = align_labels - 1; | |
1577 | if (align_functions <= 0) | |
1578 | align_functions = 1; | |
1579 | align_functions_log = floor_log2 (align_functions * 2 - 1); | |
1580 | } | |
1581 | ||
a32274ad NB |
1582 | /* Process the options that have been parsed. */ |
1583 | static void | |
e25a75e6 | 1584 | process_options (void) |
a32274ad | 1585 | { |
456b8ce5 UB |
1586 | /* Just in case lang_hooks.post_options ends up calling a debug_hook. |
1587 | This can happen with incorrect pre-processed input. */ | |
1588 | debug_hooks = &do_nothing_debug_hooks; | |
1589 | ||
299404a1 JM |
1590 | maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT; |
1591 | ||
e73f7547 MLI |
1592 | /* This replaces set_Wunused. */ |
1593 | if (warn_unused_function == -1) | |
1594 | warn_unused_function = warn_unused; | |
1595 | if (warn_unused_label == -1) | |
1596 | warn_unused_label = warn_unused; | |
1597 | /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled. */ | |
1598 | if (warn_unused_parameter == -1) | |
1599 | warn_unused_parameter = (warn_unused && extra_warnings); | |
1600 | if (warn_unused_variable == -1) | |
1601 | warn_unused_variable = warn_unused; | |
ebfbbdc5 JJ |
1602 | /* Wunused-but-set-parameter is enabled if both -Wunused -Wextra are |
1603 | enabled. */ | |
1604 | if (warn_unused_but_set_parameter == -1) | |
1605 | warn_unused_but_set_parameter = (warn_unused && extra_warnings); | |
1606 | if (warn_unused_but_set_variable == -1) | |
1607 | warn_unused_but_set_variable = warn_unused; | |
e73f7547 MLI |
1608 | if (warn_unused_value == -1) |
1609 | warn_unused_value = warn_unused; | |
1610 | ||
62a67c94 MLI |
1611 | /* This replaces set_Wextra. */ |
1612 | if (warn_uninitialized == -1) | |
1613 | warn_uninitialized = extra_warnings; | |
1614 | ||
4bfec483 NB |
1615 | /* Allow the front end to perform consistency checks and do further |
1616 | initialization based on the command line options. This hook also | |
1617 | sets the original filename if appropriate (e.g. foo.i -> foo.c) | |
1618 | so we can correctly initialize debug output. */ | |
ae2bcd98 | 1619 | no_backend = lang_hooks.post_options (&main_input_filename); |
4bfec483 | 1620 | |
4291d9c8 | 1621 | /* Some machines may reject certain combinations of options. */ |
74f7912a | 1622 | targetm.target_option.override (); |
4291d9c8 | 1623 | |
0e94b750 MLI |
1624 | /* Avoid any informative notes in the second run of -fcompare-debug. */ |
1625 | if (flag_compare_debug) | |
1626 | diagnostic_inhibit_notes (global_dc); | |
1627 | ||
aacd3885 RS |
1628 | if (flag_section_anchors && !target_supports_section_anchors_p ()) |
1629 | { | |
1630 | warning (OPT_fsection_anchors, | |
1631 | "this target does not support %qs", "-fsection-anchors"); | |
1632 | flag_section_anchors = 0; | |
1633 | } | |
1634 | ||
32770746 PB |
1635 | if (flag_short_enums == 2) |
1636 | flag_short_enums = targetm.default_short_enums (); | |
1637 | ||
b1cbe78c NB |
1638 | /* Set aux_base_name if not already set. */ |
1639 | if (aux_base_name) | |
1640 | ; | |
d7b42618 | 1641 | else if (main_input_filename) |
b1cbe78c | 1642 | { |
d7b42618 | 1643 | char *name = xstrdup (lbasename (main_input_filename)); |
e25a75e6 | 1644 | |
b1cbe78c NB |
1645 | strip_off_ending (name, strlen (name)); |
1646 | aux_base_name = name; | |
1647 | } | |
1648 | else | |
1649 | aux_base_name = "gccaux"; | |
1650 | ||
b70e9775 SP |
1651 | #ifndef HAVE_cloog |
1652 | if (flag_graphite | |
1653 | || flag_loop_block | |
1654 | || flag_loop_interchange | |
20ed8b32 | 1655 | || flag_loop_strip_mine |
204b560f | 1656 | || flag_graphite_identity |
3cf0e270 | 1657 | || flag_loop_parallelize_all) |
b70e9775 SP |
1658 | sorry ("Graphite loop optimizations cannot be used"); |
1659 | #endif | |
1660 | ||
4291d9c8 RS |
1661 | /* Unrolling all loops implies that standard loop unrolling must also |
1662 | be done. */ | |
1663 | if (flag_unroll_all_loops) | |
1664 | flag_unroll_loops = 1; | |
b17d5d7c | 1665 | |
3020190e | 1666 | /* web and rename-registers help when run after loop unrolling. */ |
2928d0f8 SE |
1667 | if (flag_web == AUTODETECT_VALUE) |
1668 | flag_web = flag_unroll_loops || flag_peel_loops; | |
37740cd3 | 1669 | |
2928d0f8 SE |
1670 | if (flag_rename_registers == AUTODETECT_VALUE) |
1671 | flag_rename_registers = flag_unroll_loops || flag_peel_loops; | |
4291d9c8 | 1672 | |
b932f770 JH |
1673 | if (flag_non_call_exceptions) |
1674 | flag_asynchronous_unwind_tables = 1; | |
1675 | if (flag_asynchronous_unwind_tables) | |
1676 | flag_unwind_tables = 1; | |
1677 | ||
fca9dc00 ZD |
1678 | if (flag_value_profile_transformations) |
1679 | flag_profile_values = 1; | |
1680 | ||
4291d9c8 RS |
1681 | /* Warn about options that are not supported on this machine. */ |
1682 | #ifndef INSN_SCHEDULING | |
1683 | if (flag_schedule_insns || flag_schedule_insns_after_reload) | |
d4ee4d25 | 1684 | warning (0, "instruction scheduling not supported on this target machine"); |
4291d9c8 RS |
1685 | #endif |
1686 | #ifndef DELAY_SLOTS | |
1687 | if (flag_delayed_branch) | |
d4ee4d25 | 1688 | warning (0, "this target machine does not have delayed branches"); |
4291d9c8 RS |
1689 | #endif |
1690 | ||
19283265 RH |
1691 | user_label_prefix = USER_LABEL_PREFIX; |
1692 | if (flag_leading_underscore != -1) | |
1693 | { | |
854a97f0 | 1694 | /* If the default prefix is more complicated than "" or "_", |
19283265 RH |
1695 | issue a warning and ignore this option. */ |
1696 | if (user_label_prefix[0] == 0 || | |
1697 | (user_label_prefix[0] == '_' && user_label_prefix[1] == 0)) | |
1698 | { | |
1699 | user_label_prefix = flag_leading_underscore ? "_" : ""; | |
1700 | } | |
1701 | else | |
d4ee4d25 | 1702 | warning (0, "-f%sleading-underscore not supported on this target machine", |
19283265 RH |
1703 | flag_leading_underscore ? "" : "no-"); |
1704 | } | |
1705 | ||
4291d9c8 RS |
1706 | /* If we are in verbose mode, write out the version and maybe all the |
1707 | option flags in use. */ | |
1708 | if (version_flag) | |
1709 | { | |
3d5cdd42 | 1710 | print_version (stderr, ""); |
4291d9c8 | 1711 | if (! quiet_flag) |
e0d9d0dd | 1712 | print_switch_values (print_to_stderr); |
4291d9c8 RS |
1713 | } |
1714 | ||
f5e99456 NB |
1715 | if (flag_syntax_only) |
1716 | { | |
1717 | write_symbols = NO_DEBUG; | |
1718 | profile_flag = 0; | |
f5e99456 | 1719 | } |
4291d9c8 | 1720 | |
2153915d AO |
1721 | if (flag_gtoggle) |
1722 | { | |
1723 | if (debug_info_level == DINFO_LEVEL_NONE) | |
6a57e634 AO |
1724 | { |
1725 | debug_info_level = DINFO_LEVEL_NORMAL; | |
1726 | ||
1727 | if (write_symbols == NO_DEBUG) | |
1728 | write_symbols = PREFERRED_DEBUGGING_TYPE; | |
1729 | } | |
2153915d AO |
1730 | else |
1731 | debug_info_level = DINFO_LEVEL_NONE; | |
1732 | } | |
1733 | ||
b5b8b0ac | 1734 | if (flag_dump_final_insns && !flag_syntax_only && !no_backend) |
2153915d AO |
1735 | { |
1736 | FILE *final_output = fopen (flag_dump_final_insns, "w"); | |
1737 | if (!final_output) | |
1738 | { | |
7ca92787 JM |
1739 | error ("could not open final insn dump file %qs: %m", |
1740 | flag_dump_final_insns); | |
2153915d AO |
1741 | flag_dump_final_insns = NULL; |
1742 | } | |
1743 | else if (fclose (final_output)) | |
1744 | { | |
7ca92787 JM |
1745 | error ("could not close zeroed insn dump file %qs: %m", |
1746 | flag_dump_final_insns); | |
2153915d AO |
1747 | flag_dump_final_insns = NULL; |
1748 | } | |
1749 | } | |
1750 | ||
047a3193 IS |
1751 | /* Unless over-ridden for the target, assume that all DWARF levels |
1752 | may be emitted, if DWARF2_DEBUG is selected. */ | |
b8698a0f | 1753 | if (dwarf_strict < 0) |
047a3193 IS |
1754 | dwarf_strict = 0; |
1755 | ||
df38ffef NB |
1756 | /* A lot of code assumes write_symbols == NO_DEBUG if the debugging |
1757 | level is 0. */ | |
1758 | if (debug_info_level == DINFO_LEVEL_NONE) | |
1759 | write_symbols = NO_DEBUG; | |
1760 | ||
df38ffef | 1761 | if (write_symbols == NO_DEBUG) |
93415288 | 1762 | ; |
f5e99456 | 1763 | #if defined(DBX_DEBUGGING_INFO) |
df38ffef | 1764 | else if (write_symbols == DBX_DEBUG) |
f5e99456 | 1765 | debug_hooks = &dbx_debug_hooks; |
4291d9c8 | 1766 | #endif |
f5e99456 | 1767 | #if defined(XCOFF_DEBUGGING_INFO) |
df38ffef | 1768 | else if (write_symbols == XCOFF_DEBUG) |
f5e99456 | 1769 | debug_hooks = &xcoff_debug_hooks; |
3d5cdd42 | 1770 | #endif |
f5e99456 | 1771 | #ifdef SDB_DEBUGGING_INFO |
df38ffef | 1772 | else if (write_symbols == SDB_DEBUG) |
f5e99456 NB |
1773 | debug_hooks = &sdb_debug_hooks; |
1774 | #endif | |
f5e99456 | 1775 | #ifdef DWARF2_DEBUGGING_INFO |
df38ffef | 1776 | else if (write_symbols == DWARF2_DEBUG) |
f5e99456 | 1777 | debug_hooks = &dwarf2_debug_hooks; |
3d5cdd42 | 1778 | #endif |
7a0c8d71 | 1779 | #ifdef VMS_DEBUGGING_INFO |
df38ffef | 1780 | else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG) |
7a0c8d71 DR |
1781 | debug_hooks = &vmsdbg_debug_hooks; |
1782 | #endif | |
df38ffef NB |
1783 | else |
1784 | error ("target system does not support the \"%s\" debug format", | |
1785 | debug_type_names[write_symbols]); | |
4291d9c8 | 1786 | |
37740cd3 EB |
1787 | /* We know which debug output will be used so we can set flag_var_tracking |
1788 | and flag_var_tracking_uninit if the user has not specified them. */ | |
38d396e5 PB |
1789 | if (debug_info_level < DINFO_LEVEL_NORMAL |
1790 | || debug_hooks->var_location == do_nothing_debug_hooks.var_location) | |
014a1138 | 1791 | { |
62760ffd CT |
1792 | if (flag_var_tracking == 1 |
1793 | || flag_var_tracking_uninit == 1) | |
38d396e5 PB |
1794 | { |
1795 | if (debug_info_level < DINFO_LEVEL_NORMAL) | |
d4ee4d25 | 1796 | warning (0, "variable tracking requested, but useless unless " |
38d396e5 PB |
1797 | "producing debug info"); |
1798 | else | |
d4ee4d25 | 1799 | warning (0, "variable tracking requested, but not supported " |
38d396e5 PB |
1800 | "by this debug format"); |
1801 | } | |
1802 | flag_var_tracking = 0; | |
62760ffd | 1803 | flag_var_tracking_uninit = 0; |
014a1138 JZ |
1804 | } |
1805 | ||
c6a13190 ILT |
1806 | /* The debug hooks are used to implement -fdump-go-spec because it |
1807 | gives a simple and stable API for all the information we need to | |
1808 | dump. */ | |
1809 | if (flag_dump_go_spec != NULL) | |
1810 | debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks); | |
1811 | ||
6751b6f6 AO |
1812 | /* If the user specifically requested variable tracking with tagging |
1813 | uninitialized variables, we need to turn on variable tracking. | |
1814 | (We already determined above that variable tracking is feasible.) */ | |
1815 | if (flag_var_tracking_uninit) | |
1816 | flag_var_tracking = 1; | |
38d396e5 | 1817 | |
2928d0f8 | 1818 | if (flag_var_tracking == AUTODETECT_VALUE) |
38d396e5 PB |
1819 | flag_var_tracking = optimize >= 1; |
1820 | ||
b5b8b0ac | 1821 | if (flag_var_tracking_assignments == AUTODETECT_VALUE) |
6751b6f6 AO |
1822 | flag_var_tracking_assignments = flag_var_tracking |
1823 | && !(flag_selective_scheduling || flag_selective_scheduling2); | |
b5b8b0ac AO |
1824 | |
1825 | if (flag_var_tracking_assignments_toggle) | |
1826 | flag_var_tracking_assignments = !flag_var_tracking_assignments; | |
1827 | ||
1828 | if (flag_var_tracking_assignments && !flag_var_tracking) | |
1829 | flag_var_tracking = flag_var_tracking_assignments = -1; | |
1830 | ||
6751b6f6 AO |
1831 | if (flag_var_tracking_assignments |
1832 | && (flag_selective_scheduling || flag_selective_scheduling2)) | |
1833 | warning (0, "var-tracking-assignments changes selective scheduling"); | |
1834 | ||
a5828d1e MM |
1835 | if (flag_tree_cselim == AUTODETECT_VALUE) |
1836 | #ifdef HAVE_conditional_move | |
1837 | flag_tree_cselim = 1; | |
1838 | #else | |
1839 | flag_tree_cselim = 0; | |
1840 | #endif | |
1841 | ||
f5e99456 NB |
1842 | /* If auxiliary info generation is desired, open the output file. |
1843 | This goes in the same directory as the source file--unlike | |
1844 | all the other output files. */ | |
1845 | if (flag_gen_aux_info) | |
1846 | { | |
1847 | aux_info_file = fopen (aux_info_file_name, "w"); | |
1848 | if (aux_info_file == 0) | |
971801ff | 1849 | fatal_error ("can%'t open %s: %m", aux_info_file_name); |
f5e99456 | 1850 | } |
309a8875 | 1851 | |
f5e99456 | 1852 | if (! targetm.have_named_sections) |
4291d9c8 | 1853 | { |
f5e99456 NB |
1854 | if (flag_function_sections) |
1855 | { | |
d4ee4d25 | 1856 | warning (0, "-ffunction-sections not supported for this target"); |
f5e99456 NB |
1857 | flag_function_sections = 0; |
1858 | } | |
1859 | if (flag_data_sections) | |
1860 | { | |
d4ee4d25 | 1861 | warning (0, "-fdata-sections not supported for this target"); |
f5e99456 NB |
1862 | flag_data_sections = 0; |
1863 | } | |
4291d9c8 | 1864 | } |
f5e99456 | 1865 | |
8456b95a | 1866 | if (flag_function_sections && profile_flag) |
3d5cdd42 | 1867 | { |
d4ee4d25 | 1868 | warning (0, "-ffunction-sections disabled; it makes profiling impossible"); |
f5e99456 | 1869 | flag_function_sections = 0; |
3d5cdd42 | 1870 | } |
f5e99456 | 1871 | |
0dd0e980 | 1872 | #ifndef HAVE_prefetch |
1fbb509a | 1873 | if (flag_prefetch_loop_arrays > 0) |
0dd0e980 | 1874 | { |
d4ee4d25 | 1875 | warning (0, "-fprefetch-loop-arrays not supported for this target"); |
0dd0e980 JH |
1876 | flag_prefetch_loop_arrays = 0; |
1877 | } | |
1878 | #else | |
1fbb509a | 1879 | if (flag_prefetch_loop_arrays > 0 && !HAVE_prefetch) |
0dd0e980 | 1880 | { |
d4ee4d25 | 1881 | warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)"); |
0dd0e980 JH |
1882 | flag_prefetch_loop_arrays = 0; |
1883 | } | |
1884 | #endif | |
1885 | ||
1398974c JJ |
1886 | /* This combination of options isn't handled for i386 targets and doesn't |
1887 | make much sense anyway, so don't allow it. */ | |
1fbb509a | 1888 | if (flag_prefetch_loop_arrays > 0 && optimize_size) |
1398974c | 1889 | { |
d4ee4d25 | 1890 | warning (0, "-fprefetch-loop-arrays is not supported with -Os"); |
1398974c JJ |
1891 | flag_prefetch_loop_arrays = 0; |
1892 | } | |
1893 | ||
6de9cd9a DN |
1894 | /* The presence of IEEE signaling NaNs, implies all math can trap. */ |
1895 | if (flag_signaling_nans) | |
1896 | flag_trapping_math = 1; | |
c7463669 | 1897 | |
204b560f | 1898 | /* We cannot reassociate if we want traps or signed zeros. */ |
c5edab65 EB |
1899 | if (flag_associative_math && (flag_trapping_math || flag_signed_zeros)) |
1900 | { | |
1901 | warning (0, "-fassociative-math disabled; other options take precedence"); | |
1902 | flag_associative_math = 0; | |
1903 | } | |
1904 | ||
c7463669 RH |
1905 | /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */ |
1906 | if (flag_cx_limited_range) | |
1907 | flag_complex_method = 0; | |
7d69de61 | 1908 | |
35085f76 JB |
1909 | /* With -fcx-fortran-rules, we do something in-between cheap and C99. */ |
1910 | if (flag_cx_fortran_rules) | |
1911 | flag_complex_method = 1; | |
1912 | ||
7d69de61 RH |
1913 | /* Targets must be able to place spill slots at lower addresses. If the |
1914 | target already uses a soft frame pointer, the transition is trivial. */ | |
fd5431bc | 1915 | if (!FRAME_GROWS_DOWNWARD && flag_stack_protect) |
7d69de61 RH |
1916 | { |
1917 | warning (0, "-fstack-protector not supported for this target"); | |
1918 | flag_stack_protect = 0; | |
1919 | } | |
7d69de61 RH |
1920 | if (!flag_stack_protect) |
1921 | warn_stack_protect = 0; | |
d3073c70 RH |
1922 | |
1923 | /* ??? Unwind info is not correct around the CFG unless either a frame | |
1924 | pointer is present or A_O_A is set. Fixing this requires rewriting | |
1925 | unwind info generation to be aware of the CFG and propagating states | |
1926 | around edges. */ | |
1927 | if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS | |
1928 | && flag_omit_frame_pointer) | |
1929 | { | |
772cf067 | 1930 | warning (0, "unwind tables currently require a frame pointer " |
d3073c70 RH |
1931 | "for correctness"); |
1932 | flag_omit_frame_pointer = 0; | |
1933 | } | |
3b34d92c JZ |
1934 | |
1935 | /* Save the current optimization options. */ | |
1936 | optimization_default_node = build_optimization_node (); | |
1937 | optimization_current_node = optimization_default_node; | |
4291d9c8 | 1938 | } |
ddc9542b | 1939 | |
b5deb7b6 SL |
1940 | /* This function can be called multiple times to reinitialize the compiler |
1941 | back end when register classes or instruction sets have changed, | |
1942 | before each function. */ | |
1943 | static void | |
1944 | backend_init_target (void) | |
1945 | { | |
1946 | /* Initialize alignment variables. */ | |
1947 | init_alignments (); | |
1948 | ||
1949 | /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target() | |
1950 | to initialize reg_raw_mode[]. */ | |
1951 | init_emit_regs (); | |
1952 | ||
1953 | /* This invokes target hooks to set fixed_reg[] etc, which is | |
1954 | mode-dependent. */ | |
1955 | init_regs (); | |
1956 | ||
1957 | /* This depends on stack_pointer_rtx. */ | |
1958 | init_fake_stack_mems (); | |
1959 | ||
1960 | /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is | |
1961 | mode-dependent. */ | |
1962 | init_alias_target (); | |
1963 | ||
1964 | /* Depends on HARD_FRAME_POINTER_REGNUM. */ | |
1965 | init_reload (); | |
1966 | ||
1967 | /* The following initialization functions need to generate rtl, so | |
1968 | provide a dummy function context for them. */ | |
1969 | init_dummy_function_start (); | |
1970 | ||
1971 | /* rtx_cost is mode-dependent, so cached values need to be recomputed | |
1972 | on a mode change. */ | |
1973 | init_expmed (); | |
1974 | ||
1975 | /* We may need to recompute regno_save_code[] and regno_restore_code[] | |
1976 | after a mode change as well. */ | |
dc12b70e JZ |
1977 | caller_save_initialized_p = false; |
1978 | ||
b5deb7b6 SL |
1979 | expand_dummy_function_end (); |
1980 | } | |
1981 | ||
1982 | /* Initialize the compiler back end. This function is called only once, | |
1983 | when starting the compiler. */ | |
f5e99456 | 1984 | static void |
e25a75e6 | 1985 | backend_init (void) |
f5e99456 | 1986 | { |
2d888286 | 1987 | init_emit_once (); |
28420116 | 1988 | |
cf94b0fc | 1989 | init_rtlanal (); |
7f9bc51b | 1990 | init_inline_once (); |
f5e99456 | 1991 | init_varasm_once (); |
fef511b5 | 1992 | save_register_info (); |
f5e99456 | 1993 | |
b5deb7b6 | 1994 | /* Initialize the target-specific back end pieces. */ |
058e97ec | 1995 | ira_init_once (); |
b5deb7b6 SL |
1996 | backend_init_target (); |
1997 | } | |
1998 | ||
8ce94e44 JM |
1999 | /* Initialize excess precision settings. */ |
2000 | static void | |
2001 | init_excess_precision (void) | |
2002 | { | |
2003 | /* Adjust excess precision handling based on the target options. If | |
2004 | the front end cannot handle it, flag_excess_precision_cmdline | |
2005 | will already have been set accordingly in the post_options | |
2006 | hook. */ | |
2007 | gcc_assert (flag_excess_precision_cmdline != EXCESS_PRECISION_DEFAULT); | |
2008 | flag_excess_precision = flag_excess_precision_cmdline; | |
2009 | if (flag_unsafe_math_optimizations) | |
2010 | flag_excess_precision = EXCESS_PRECISION_FAST; | |
2011 | if (flag_excess_precision == EXCESS_PRECISION_STANDARD) | |
2012 | { | |
2013 | int flt_eval_method = TARGET_FLT_EVAL_METHOD; | |
2014 | switch (flt_eval_method) | |
2015 | { | |
2016 | case -1: | |
2017 | case 0: | |
2018 | /* Either the target acts unpredictably (-1) or has all the | |
2019 | operations required not to have excess precision (0). */ | |
2020 | flag_excess_precision = EXCESS_PRECISION_FAST; | |
2021 | break; | |
2022 | case 1: | |
2023 | case 2: | |
2024 | /* In these cases, predictable excess precision makes | |
2025 | sense. */ | |
2026 | break; | |
2027 | default: | |
2028 | /* Any other implementation-defined FLT_EVAL_METHOD values | |
2029 | require the compiler to handle the associated excess | |
2030 | precision rules in excess_precision_type. */ | |
2031 | gcc_unreachable (); | |
2032 | } | |
2033 | } | |
2034 | } | |
2035 | ||
b5deb7b6 SL |
2036 | /* Initialize things that are both lang-dependent and target-dependent. |
2037 | This function can be called more than once if target parameters change. */ | |
2038 | static void | |
2039 | lang_dependent_init_target (void) | |
2040 | { | |
8ce94e44 JM |
2041 | /* This determines excess precision settings. */ |
2042 | init_excess_precision (); | |
2043 | ||
b5deb7b6 SL |
2044 | /* This creates various _DECL nodes, so needs to be called after the |
2045 | front end is initialized. It also depends on the HAVE_xxx macros | |
2046 | generated from the target machine description. */ | |
2047 | init_optabs (); | |
2048 | ||
f5e99456 NB |
2049 | /* The following initialization functions need to generate rtl, so |
2050 | provide a dummy function context for them. */ | |
2051 | init_dummy_function_start (); | |
b5deb7b6 SL |
2052 | |
2053 | /* Do the target-specific parts of expr initialization. */ | |
2054 | init_expr_target (); | |
2055 | ||
058e97ec VM |
2056 | /* Although the actions of these functions are language-independent, |
2057 | they use optabs, so we cannot call them from backend_init. */ | |
b5deb7b6 | 2058 | init_set_costs (); |
058e97ec | 2059 | ira_init (); |
b5deb7b6 | 2060 | |
f5e99456 NB |
2061 | expand_dummy_function_end (); |
2062 | } | |
ddc9542b | 2063 | |
0e9e1e0a | 2064 | /* Language-dependent initialization. Returns nonzero on success. */ |
22703ccc | 2065 | static int |
e25a75e6 | 2066 | lang_dependent_init (const char *name) |
4291d9c8 | 2067 | { |
c1667470 | 2068 | location_t save_loc = input_location; |
f5e99456 | 2069 | if (dump_base_name == 0) |
9f8628ba | 2070 | dump_base_name = name && name[0] ? name : "gccdump"; |
26182e15 | 2071 | |
4bfec483 | 2072 | /* Other front-end initialization. */ |
c1667470 | 2073 | input_location = BUILTINS_LOCATION; |
ae2bcd98 | 2074 | if (lang_hooks.init () == 0) |
22703ccc | 2075 | return 0; |
c1667470 | 2076 | input_location = save_loc; |
4291d9c8 | 2077 | |
f5e99456 | 2078 | init_asm_output (name); |
3d5cdd42 | 2079 | |
d3c12306 EB |
2080 | /* If stack usage information is desired, open the output file. */ |
2081 | if (flag_stack_usage) | |
2082 | stack_usage_file = open_auxiliary_file ("su"); | |
2083 | ||
b5deb7b6 | 2084 | /* This creates various _DECL nodes, so needs to be called after the |
f5e99456 NB |
2085 | front end is initialized. */ |
2086 | init_eh (); | |
c0d919fa | 2087 | |
b5deb7b6 SL |
2088 | /* Do the target-specific parts of the initialization. */ |
2089 | lang_dependent_init_target (); | |
3d5cdd42 | 2090 | |
f5e99456 NB |
2091 | /* If dbx symbol table desired, initialize writing it and output the |
2092 | predefined types. */ | |
2093 | timevar_push (TV_SYMOUT); | |
4291d9c8 | 2094 | |
658f32fd | 2095 | #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO |
f5e99456 NB |
2096 | if (dwarf2out_do_frame ()) |
2097 | dwarf2out_frame_init (); | |
2098 | #endif | |
4291d9c8 | 2099 | |
f5e99456 NB |
2100 | /* Now we have the correct original filename, we can initialize |
2101 | debug output. */ | |
2102 | (*debug_hooks->init) (name); | |
4291d9c8 | 2103 | |
f5e99456 | 2104 | timevar_pop (TV_SYMOUT); |
22703ccc NB |
2105 | |
2106 | return 1; | |
2107 | } | |
ddc9542b | 2108 | |
b5deb7b6 SL |
2109 | |
2110 | /* Reinitialize everything when target parameters, such as register usage, | |
2111 | have changed. */ | |
2112 | void | |
2113 | target_reinit (void) | |
2114 | { | |
84fbffb2 | 2115 | /* Reinitialize RTL backend. */ |
b5deb7b6 SL |
2116 | backend_init_target (); |
2117 | ||
2118 | /* Reinitialize lang-dependent parts. */ | |
2119 | lang_dependent_init_target (); | |
2120 | } | |
2121 | ||
a5573239 JH |
2122 | void |
2123 | dump_memory_report (bool final) | |
2124 | { | |
2125 | ggc_print_statistics (); | |
2126 | stringpool_statistics (); | |
2127 | dump_tree_statistics (); | |
726a989a | 2128 | dump_gimple_statistics (); |
a5573239 | 2129 | dump_rtx_statistics (); |
a5573239 JH |
2130 | dump_alloc_pool_statistics (); |
2131 | dump_bitmap_statistics (); | |
d3492572 | 2132 | dump_vec_loc_statistics (); |
a5573239 | 2133 | dump_ggc_loc_statistics (final); |
5006671f RG |
2134 | dump_alias_stats (stderr); |
2135 | dump_pta_stats (stderr); | |
a5573239 JH |
2136 | } |
2137 | ||
22703ccc NB |
2138 | /* Clean up: close opened files, etc. */ |
2139 | ||
2140 | static void | |
e25a75e6 | 2141 | finalize (void) |
22703ccc NB |
2142 | { |
2143 | /* Close the dump files. */ | |
2144 | if (flag_gen_aux_info) | |
2145 | { | |
2146 | fclose (aux_info_file); | |
1da2ed5f | 2147 | if (seen_error ()) |
22703ccc NB |
2148 | unlink (aux_info_file_name); |
2149 | } | |
2150 | ||
2151 | /* Close non-debugging input and output files. Take special care to note | |
2152 | whether fclose returns an error, since the pages might still be on the | |
2153 | buffer chain while the file is open. */ | |
2154 | ||
2155 | if (asm_out_file) | |
2156 | { | |
2157 | if (ferror (asm_out_file) != 0) | |
fa6ef813 | 2158 | fatal_error ("error writing to %s: %m", asm_file_name); |
22703ccc | 2159 | if (fclose (asm_out_file) != 0) |
fa6ef813 | 2160 | fatal_error ("error closing %s: %m", asm_file_name); |
d7f09764 DN |
2161 | if (flag_wpa) |
2162 | unlink_if_ordinary (asm_file_name); | |
22703ccc NB |
2163 | } |
2164 | ||
d3c12306 EB |
2165 | if (stack_usage_file) |
2166 | fclose (stack_usage_file); | |
2167 | ||
9fe0cb7d | 2168 | statistics_fini (); |
f6db1481 | 2169 | finish_optimization_passes (); |
22703ccc | 2170 | |
058e97ec VM |
2171 | ira_finish_once (); |
2172 | ||
22703ccc | 2173 | if (mem_report) |
a5573239 | 2174 | dump_memory_report (true); |
22703ccc | 2175 | |
22703ccc | 2176 | /* Language-specific end of compilation actions. */ |
ae2bcd98 | 2177 | lang_hooks.finish (); |
f5e99456 | 2178 | } |
ddc9542b | 2179 | |
4d6baafa NB |
2180 | /* Initialize the compiler, and compile the input file. */ |
2181 | static void | |
e25a75e6 | 2182 | do_compile (void) |
f5e99456 | 2183 | { |
09b04f2d NB |
2184 | /* Initialize timing first. The C front ends read the main file in |
2185 | the post_options hook, and C++ does file timings. */ | |
2186 | if (time_report || !quiet_flag || flag_detailed_statistics) | |
2187 | timevar_init (); | |
a9915c78 RK |
2188 | timevar_start (TV_TOTAL); |
2189 | ||
09b04f2d NB |
2190 | process_options (); |
2191 | ||
2192 | /* Don't do any more if an error has already occurred. */ | |
1da2ed5f | 2193 | if (!seen_error ()) |
09b04f2d | 2194 | { |
e59ba1bc JW |
2195 | /* This must be run always, because it is needed to compute the FP |
2196 | predefined macros, such as __LDBL_MAX__, for targets using non | |
2197 | default FP formats. */ | |
2198 | init_adjust_machine_modes (); | |
2199 | ||
09b04f2d NB |
2200 | /* Set up the back-end if requested. */ |
2201 | if (!no_backend) | |
2202 | backend_init (); | |
f5e99456 | 2203 | |
09b04f2d | 2204 | /* Language-dependent initialization. Returns true on success. */ |
d7b42618 | 2205 | if (lang_dependent_init (main_input_filename)) |
f6db1481 | 2206 | compile_file (); |
a194aa56 | 2207 | |
09b04f2d NB |
2208 | finalize (); |
2209 | } | |
f5e99456 NB |
2210 | |
2211 | /* Stop timing and print the times. */ | |
2212 | timevar_stop (TV_TOTAL); | |
2213 | timevar_print (stderr); | |
4d6baafa | 2214 | } |
ddc9542b | 2215 | |
4d6baafa | 2216 | /* Entry point of cc1, cc1plus, jc1, f771, etc. |
4d6baafa NB |
2217 | Exit code is FATAL_EXIT_CODE if can't open files or if there were |
2218 | any errors, or SUCCESS_EXIT_CODE if compilation succeeded. | |
2219 | ||
2220 | It is not safe to call this function more than once. */ | |
2221 | ||
2222 | int | |
5a691e98 | 2223 | toplev_main (int argc, char **argv) |
4d6baafa | 2224 | { |
5a691e98 RAE |
2225 | expandargv (&argc, &argv); |
2226 | ||
4d6baafa | 2227 | /* Initialization of GCC's environment, and diagnostics. */ |
9cabb1d8 | 2228 | general_init (argv[0]); |
4d6baafa | 2229 | |
a75bfaa6 JM |
2230 | /* One-off initialization of options that does not need to be |
2231 | repeated when options are added for particular functions. */ | |
2232 | init_options_once (); | |
2233 | ||
2234 | /* Initialize global options structures; this must be repeated for | |
2235 | each structure used for parsing options. */ | |
2236 | init_options_struct (&global_options, &global_options_set); | |
2237 | lang_hooks.init_options_struct (&global_options); | |
2238 | ||
2239 | /* Convert the options to an array. */ | |
2240 | decode_cmdline_options_to_array_default_mask (argc, | |
2241 | CONST_CAST2 (const char **, | |
2242 | char **, argv), | |
2243 | &save_decoded_options, | |
2244 | &save_decoded_options_count); | |
2245 | ||
2246 | /* Perform language-specific options initialization. */ | |
2247 | lang_hooks.init_options (save_decoded_options_count, save_decoded_options); | |
2248 | ||
4d6baafa NB |
2249 | /* Parse the options and do minimal processing; basically just |
2250 | enough to default flags appropriately. */ | |
a75bfaa6 | 2251 | decode_options (&global_options, &global_options_set, |
d5478783 | 2252 | save_decoded_options, save_decoded_options_count, |
a4d8c676 | 2253 | UNKNOWN_LOCATION, global_dc); |
4d6baafa | 2254 | |
21bf1558 JM |
2255 | handle_common_deferred_options (); |
2256 | ||
403d4851 | 2257 | init_local_tick (); |
c07e5477 | 2258 | |
44e9f006 RAE |
2259 | initialize_plugins (); |
2260 | ||
2261 | if (version_flag) | |
2262 | print_version (stderr, ""); | |
2263 | ||
02e819ff RAE |
2264 | if (help_flag) |
2265 | print_plugins_help (stderr, ""); | |
2266 | ||
4d6baafa | 2267 | /* Exit early if we can (e.g. -help). */ |
c79043f3 | 2268 | if (!exit_after_options) |
09b04f2d | 2269 | do_compile (); |
f5e99456 | 2270 | |
b8698a0f | 2271 | if (warningcount || errorcount) |
369dcbd9 | 2272 | print_ignored_options (); |
d0b8780d | 2273 | diagnostic_finish (global_dc); |
369dcbd9 | 2274 | |
68a607d8 DN |
2275 | /* Invoke registered plugin callbacks if any. */ |
2276 | invoke_plugin_callbacks (PLUGIN_FINISH, NULL); | |
2277 | ||
44e9f006 | 2278 | finalize_plugins (); |
1da2ed5f | 2279 | if (seen_error ()) |
f5e99456 NB |
2280 | return (FATAL_EXIT_CODE); |
2281 | ||
2282 | return (SUCCESS_EXIT_CODE); | |
4291d9c8 | 2283 | } |