2013-05-03 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / toplev.c
blobd41283de93133353b7086269e16064479e3ca3f4
1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* This is the top level of cc1/c++.
21 It parses command args, opens files, invokes the various passes
22 in the proper order, and counts the time used by each.
23 Error messages and low-level interface to malloc also handled here. */
25 #include "config.h"
26 #include "system.h"
27 #include "coretypes.h"
28 #include "tm.h"
29 #include "line-map.h"
30 #include "input.h"
31 #include "tree.h"
32 #include "realmpfr.h" /* For GMP/MPFR/MPC versions, in print_version. */
33 #include "version.h"
34 #include "rtl.h"
35 #include "tm_p.h"
36 #include "flags.h"
37 #include "insn-attr.h"
38 #include "insn-config.h"
39 #include "insn-flags.h"
40 #include "hard-reg-set.h"
41 #include "recog.h"
42 #include "output.h"
43 #include "except.h"
44 #include "function.h"
45 #include "toplev.h"
46 #include "expr.h"
47 #include "basic-block.h"
48 #include "intl.h"
49 #include "ggc.h"
50 #include "regs.h"
51 #include "timevar.h"
52 #include "diagnostic.h"
53 #include "tree-diagnostic.h"
54 #include "tree-pretty-print.h"
55 #include "params.h"
56 #include "reload.h"
57 #include "ira.h"
58 #include "dwarf2asm.h"
59 #include "debug.h"
60 #include "target.h"
61 #include "common/common-target.h"
62 #include "langhooks.h"
63 #include "cfgloop.h" /* for init_set_costs */
64 #include "hosthooks.h"
65 #include "cgraph.h"
66 #include "opts.h"
67 #include "opts-diagnostic.h"
68 #include "coverage.h"
69 #include "value-prof.h"
70 #include "alloc-pool.h"
71 #include "tree-mudflap.h"
72 #include "asan.h"
73 #include "tsan.h"
74 #include "gimple.h"
75 #include "tree-ssa-alias.h"
76 #include "plugin.h"
77 #include "diagnostic-color.h"
79 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
80 #include "dbxout.h"
81 #endif
83 #ifdef SDB_DEBUGGING_INFO
84 #include "sdbout.h"
85 #endif
87 #ifdef XCOFF_DEBUGGING_INFO
88 #include "xcoffout.h" /* Needed for external data
89 declarations for e.g. AIX 4.x. */
90 #endif
92 static void general_init (const char *);
93 static void do_compile (void);
94 static void process_options (void);
95 static void backend_init (void);
96 static int lang_dependent_init (const char *);
97 static void init_asm_output (const char *);
98 static void finalize (bool);
100 static void crash_signal (int) ATTRIBUTE_NORETURN;
101 static void compile_file (void);
103 /* True if we don't need a backend (e.g. preprocessing only). */
104 static bool no_backend;
106 /* Length of line when printing switch values. */
107 #define MAX_LINE 75
109 /* Decoded options, and number of such options. */
110 struct cl_decoded_option *save_decoded_options;
111 unsigned int save_decoded_options_count;
113 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
114 to optimize in process_options (). */
115 #define AUTODETECT_VALUE 2
117 /* Debug hooks - dependent upon command line options. */
119 const struct gcc_debug_hooks *debug_hooks;
121 /* The FUNCTION_DECL for the function currently being compiled,
122 or 0 if between functions. */
123 tree current_function_decl;
125 /* Set to the FUNC_BEGIN label of the current function, or NULL
126 if none. */
127 const char * current_function_func_begin_label;
129 /* A random sequence of characters, unless overridden by user. */
130 static const char *flag_random_seed;
132 /* A local time stamp derived from the time of compilation. It will be
133 zero if the system cannot provide a time. It will be -1u, if the
134 user has specified a particular random seed. */
135 unsigned local_tick;
137 /* Random number for this compilation */
138 HOST_WIDE_INT random_seed;
140 /* -f flags. */
142 /* When non-NULL, indicates that whenever space is allocated on the
143 stack, the resulting stack pointer must not pass this
144 address---that is, for stacks that grow downward, the stack pointer
145 must always be greater than or equal to this address; for stacks
146 that grow upward, the stack pointer must be less than this address.
147 At present, the rtx may be either a REG or a SYMBOL_REF, although
148 the support provided depends on the backend. */
149 rtx stack_limit_rtx;
151 /* True if the user has tagged the function with the 'section'
152 attribute. */
154 bool user_defined_section_attribute = false;
156 struct target_flag_state default_target_flag_state;
157 #if SWITCHABLE_TARGET
158 struct target_flag_state *this_target_flag_state = &default_target_flag_state;
159 #else
160 #define this_target_flag_state (&default_target_flag_state)
161 #endif
163 /* The user symbol prefix after having resolved same. */
164 const char *user_label_prefix;
166 /* Output files for assembler code (real compiler output)
167 and debugging dumps. */
169 FILE *asm_out_file;
170 FILE *aux_info_file;
171 FILE *stack_usage_file = NULL;
173 /* The current working directory of a translation. It's generally the
174 directory from which compilation was initiated, but a preprocessed
175 file may specify the original directory in which it was
176 created. */
178 static const char *src_pwd;
180 /* Initialize src_pwd with the given string, and return true. If it
181 was already initialized, return false. As a special case, it may
182 be called with a NULL argument to test whether src_pwd has NOT been
183 initialized yet. */
185 bool
186 set_src_pwd (const char *pwd)
188 if (src_pwd)
190 if (strcmp (src_pwd, pwd) == 0)
191 return true;
192 else
193 return false;
196 src_pwd = xstrdup (pwd);
197 return true;
200 /* Return the directory from which the translation unit was initiated,
201 in case set_src_pwd() was not called before to assign it a
202 different value. */
204 const char *
205 get_src_pwd (void)
207 if (! src_pwd)
209 src_pwd = getpwd ();
210 if (!src_pwd)
211 src_pwd = ".";
214 return src_pwd;
217 /* Called when the start of a function definition is parsed,
218 this function prints on stderr the name of the function. */
219 void
220 announce_function (tree decl)
222 if (!quiet_flag)
224 if (rtl_dump_and_exit)
225 fprintf (stderr, "%s ",
226 identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))));
227 else
228 fprintf (stderr, " %s",
229 identifier_to_locale (lang_hooks.decl_printable_name (decl, 2)));
230 fflush (stderr);
231 pp_needs_newline (global_dc->printer) = true;
232 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
236 /* Initialize local_tick with a random number or -1 if
237 flag_random_seed is set. */
239 static void
240 init_local_tick (void)
242 if (!flag_random_seed)
244 /* Try urandom first. Time of day is too likely to collide.
245 In case of any error we just use the local tick. */
247 int fd = open ("/dev/urandom", O_RDONLY);
248 if (fd >= 0)
250 read (fd, &random_seed, sizeof (random_seed));
251 close (fd);
254 /* Now get the tick anyways */
255 #ifdef HAVE_GETTIMEOFDAY
257 struct timeval tv;
259 gettimeofday (&tv, NULL);
260 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
262 #else
264 time_t now = time (NULL);
266 if (now != (time_t)-1)
267 local_tick = (unsigned) now;
269 #endif
271 else
272 local_tick = -1;
275 /* Set up a default flag_random_seed and local_tick, unless the user
276 already specified one. Must be called after init_local_tick. */
278 static void
279 init_random_seed (void)
281 if (flag_random_seed)
283 char *endp;
285 /* When the driver passed in a hex number don't crc it again */
286 random_seed = strtoul (flag_random_seed, &endp, 0);
287 if (!(endp > flag_random_seed && *endp == 0))
288 random_seed = crc32_string (0, flag_random_seed);
290 else if (!random_seed)
291 random_seed = local_tick ^ getpid (); /* Old racey fallback method */
294 /* Obtain the random_seed. Unless NOINIT, initialize it if
295 it's not provided in the command line. */
297 HOST_WIDE_INT
298 get_random_seed (bool noinit)
300 if (!flag_random_seed && !noinit)
301 init_random_seed ();
302 return random_seed;
305 /* Modify the random_seed string to VAL. Return its previous
306 value. */
308 const char *
309 set_random_seed (const char *val)
311 const char *old = flag_random_seed;
312 flag_random_seed = val;
313 return old;
316 /* Handler for fatal signals, such as SIGSEGV. These are transformed
317 into ICE messages, which is much more user friendly. In case the
318 error printer crashes, reset the signal to prevent infinite recursion. */
320 static void
321 crash_signal (int signo)
323 signal (signo, SIG_DFL);
325 /* If we crashed while processing an ASM statement, then be a little more
326 graceful. It's most likely the user's fault. */
327 if (this_is_asm_operands)
329 output_operand_lossage ("unrecoverable error");
330 exit (FATAL_EXIT_CODE);
333 internal_error ("%s", strsignal (signo));
336 /* A subroutine of wrapup_global_declarations. We've come to the end of
337 the compilation unit. All deferred variables should be undeferred,
338 and all incomplete decls should be finalized. */
340 void
341 wrapup_global_declaration_1 (tree decl)
343 /* We're not deferring this any longer. Assignment is conditional to
344 avoid needlessly dirtying PCH pages. */
345 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
346 && DECL_DEFER_OUTPUT (decl) != 0)
347 DECL_DEFER_OUTPUT (decl) = 0;
349 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
350 lang_hooks.finish_incomplete_decl (decl);
353 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
354 needs to be output. Return true if it is output. */
356 bool
357 wrapup_global_declaration_2 (tree decl)
359 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl)
360 || (TREE_CODE (decl) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (decl)))
361 return false;
363 /* Don't write out static consts, unless we still need them.
365 We also keep static consts if not optimizing (for debugging),
366 unless the user specified -fno-keep-static-consts.
367 ??? They might be better written into the debug information.
368 This is possible when using DWARF.
370 A language processor that wants static constants to be always
371 written out (even if it is not used) is responsible for
372 calling rest_of_decl_compilation itself. E.g. the C front-end
373 calls rest_of_decl_compilation from finish_decl.
374 One motivation for this is that is conventional in some
375 environments to write things like:
376 static const char rcsid[] = "... version string ...";
377 intending to force the string to be in the executable.
379 A language processor that would prefer to have unneeded
380 static constants "optimized away" would just defer writing
381 them out until here. E.g. C++ does this, because static
382 constants are often defined in header files.
384 ??? A tempting alternative (for both C and C++) would be
385 to force a constant to be written if and only if it is
386 defined in a main file, as opposed to an include file. */
388 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
390 struct varpool_node *node;
391 bool needed = true;
392 node = varpool_get_node (decl);
394 if (!node && flag_ltrans)
395 needed = false;
396 else if (node && node->finalized)
397 needed = false;
398 else if (node && node->alias)
399 needed = false;
400 else if (!cgraph_global_info_ready
401 && (TREE_USED (decl)
402 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
403 /* needed */;
404 else if (node && node->analyzed)
405 /* needed */;
406 else if (DECL_COMDAT (decl))
407 needed = false;
408 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
409 && (optimize || !flag_keep_static_consts
410 || DECL_ARTIFICIAL (decl)))
411 needed = false;
413 if (needed)
415 rest_of_decl_compilation (decl, 1, 1);
416 return true;
420 return false;
423 /* Do any final processing required for the declarations in VEC, of
424 which there are LEN. We write out inline functions and variables
425 that have been deferred until this point, but which are required.
426 Returns nonzero if anything was put out. */
428 bool
429 wrapup_global_declarations (tree *vec, int len)
431 bool reconsider, output_something = false;
432 int i;
434 for (i = 0; i < len; i++)
435 wrapup_global_declaration_1 (vec[i]);
437 /* Now emit any global variables or functions that we have been
438 putting off. We need to loop in case one of the things emitted
439 here references another one which comes earlier in the list. */
442 reconsider = false;
443 for (i = 0; i < len; i++)
444 reconsider |= wrapup_global_declaration_2 (vec[i]);
445 if (reconsider)
446 output_something = true;
448 while (reconsider);
450 return output_something;
453 /* A subroutine of check_global_declarations. Issue appropriate warnings
454 for the global declaration DECL. */
456 void
457 check_global_declaration_1 (tree decl)
459 /* Warn about any function declared static but not defined. We don't
460 warn about variables, because many programs have static variables
461 that exist only to get some text into the object file. */
462 if (TREE_CODE (decl) == FUNCTION_DECL
463 && DECL_INITIAL (decl) == 0
464 && DECL_EXTERNAL (decl)
465 && ! DECL_ARTIFICIAL (decl)
466 && ! TREE_NO_WARNING (decl)
467 && ! TREE_PUBLIC (decl)
468 && (warn_unused_function
469 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
471 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
472 pedwarn (input_location, 0, "%q+F used but never defined", decl);
473 else
474 warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
475 /* This symbol is effectively an "extern" declaration now. */
476 TREE_PUBLIC (decl) = 1;
479 /* Warn about static fns or vars defined but not used. */
480 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
481 /* We don't warn about "static const" variables because the
482 "rcs_id" idiom uses that construction. */
483 || (warn_unused_variable
484 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
485 && ! DECL_IN_SYSTEM_HEADER (decl)
486 && ! TREE_USED (decl)
487 /* The TREE_USED bit for file-scope decls is kept in the identifier,
488 to handle multiple external decls in different scopes. */
489 && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
490 && ! DECL_EXTERNAL (decl)
491 && ! TREE_PUBLIC (decl)
492 /* A volatile variable might be used in some non-obvious way. */
493 && ! TREE_THIS_VOLATILE (decl)
494 /* Global register variables must be declared to reserve them. */
495 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
496 /* Otherwise, ask the language. */
497 && lang_hooks.decls.warn_unused_global (decl))
498 warning ((TREE_CODE (decl) == FUNCTION_DECL)
499 ? OPT_Wunused_function
500 : OPT_Wunused_variable,
501 "%q+D defined but not used", decl);
504 /* Issue appropriate warnings for the global declarations in V (of
505 which there are LEN). */
507 void
508 check_global_declarations (tree *v, int len)
510 int i;
512 for (i = 0; i < len; i++)
513 check_global_declaration_1 (v[i]);
516 /* Emit debugging information for all global declarations in VEC. */
518 void
519 emit_debug_global_declarations (tree *vec, int len)
521 int i;
523 /* Avoid confusing the debug information machinery when there are errors. */
524 if (seen_error ())
525 return;
527 timevar_push (TV_SYMOUT);
528 for (i = 0; i < len; i++)
529 debug_hooks->global_decl (vec[i]);
530 timevar_pop (TV_SYMOUT);
533 /* Compile an entire translation unit. Write a file of assembly
534 output and various debugging dumps. */
536 static void
537 compile_file (void)
539 timevar_start (TV_PHASE_PARSING);
540 timevar_push (TV_PARSE_GLOBAL);
542 /* Call the parser, which parses the entire file (calling
543 rest_of_compilation for each function). */
544 lang_hooks.parse_file ();
546 timevar_pop (TV_PARSE_GLOBAL);
547 timevar_stop (TV_PHASE_PARSING);
549 /* Compilation is now finished except for writing
550 what's left of the symbol table output. */
552 if (flag_syntax_only || flag_wpa)
553 return;
555 ggc_protect_identifiers = false;
557 /* This must also call finalize_compilation_unit. */
558 lang_hooks.decls.final_write_globals ();
560 if (seen_error ())
561 return;
563 timevar_start (TV_PHASE_LATE_ASM);
565 /* Compilation unit is finalized. When producing non-fat LTO object, we are
566 basically finished. */
567 if (in_lto_p || !flag_lto || flag_fat_lto_objects)
569 /* Likewise for mudflap static object registrations. */
570 if (flag_mudflap)
571 mudflap_finish_file ();
573 /* File-scope initialization for AddressSanitizer. */
574 if (flag_asan)
575 asan_finish_file ();
577 if (flag_tsan)
578 tsan_finish_file ();
580 output_shared_constant_pool ();
581 output_object_blocks ();
582 finish_tm_clone_pairs ();
584 /* Write out any pending weak symbol declarations. */
585 weak_finish ();
587 /* This must be at the end before unwind and debug info.
588 Some target ports emit PIC setup thunks here. */
589 targetm.asm_out.code_end ();
591 /* Do dbx symbols. */
592 timevar_push (TV_SYMOUT);
594 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
595 if (dwarf2out_do_frame ())
596 dwarf2out_frame_finish ();
597 #endif
599 (*debug_hooks->finish) (main_input_filename);
600 timevar_pop (TV_SYMOUT);
602 /* Output some stuff at end of file if nec. */
604 dw2_output_indirect_constants ();
606 /* Flush any pending external directives. */
607 process_pending_assemble_externals ();
610 /* Emit LTO marker if LTO info has been previously emitted. This is
611 used by collect2 to determine whether an object file contains IL.
612 We used to emit an undefined reference here, but this produces
613 link errors if an object file with IL is stored into a shared
614 library without invoking lto1. */
615 if (flag_generate_lto)
617 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
618 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE,
619 "__gnu_lto_v1",
620 (unsigned HOST_WIDE_INT) 1, 8);
621 #elif defined ASM_OUTPUT_ALIGNED_COMMON
622 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_v1",
623 (unsigned HOST_WIDE_INT) 1, 8);
624 #else
625 ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_v1",
626 (unsigned HOST_WIDE_INT) 1,
627 (unsigned HOST_WIDE_INT) 1);
628 #endif
629 /* Let linker plugin know that this is a slim object and must be LTOed
630 even when user did not ask for it. */
631 if (!flag_fat_lto_objects)
633 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
634 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE,
635 "__gnu_lto_slim",
636 (unsigned HOST_WIDE_INT) 1, 8);
637 #elif defined ASM_OUTPUT_ALIGNED_COMMON
638 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_slim",
639 (unsigned HOST_WIDE_INT) 1, 8);
640 #else
641 ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_slim",
642 (unsigned HOST_WIDE_INT) 1,
643 (unsigned HOST_WIDE_INT) 1);
644 #endif
648 /* Attach a special .ident directive to the end of the file to identify
649 the version of GCC which compiled this code. The format of the .ident
650 string is patterned after the ones produced by native SVR4 compilers. */
651 if (!flag_no_ident)
653 const char *pkg_version = "(GNU) ";
654 char *ident_str;
656 if (strcmp ("(GCC) ", pkgversion_string))
657 pkg_version = pkgversion_string;
659 ident_str = ACONCAT (("GCC: ", pkg_version, version_string, NULL));
660 targetm.asm_out.output_ident (ident_str);
663 /* Invoke registered plugin callbacks. */
664 invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
666 /* This must be at the end. Some target ports emit end of file directives
667 into the assembly file here, and hence we can not output anything to the
668 assembly file after this point. */
669 targetm.asm_out.file_end ();
671 timevar_stop (TV_PHASE_LATE_ASM);
674 /* Print version information to FILE.
675 Each line begins with INDENT (for the case where FILE is the
676 assembler output file). */
678 void
679 print_version (FILE *file, const char *indent)
681 static const char fmt1[] =
682 #ifdef __GNUC__
683 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
684 #else
685 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
686 #endif
688 static const char fmt2[] =
689 N_("GMP version %s, MPFR version %s, MPC version %s\n");
690 static const char fmt3[] =
691 N_("%s%swarning: %s header version %s differs from library version %s.\n");
692 static const char fmt4[] =
693 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
694 #ifndef __VERSION__
695 #define __VERSION__ "[?]"
696 #endif
697 fprintf (file,
698 file == stderr ? _(fmt1) : fmt1,
699 indent, *indent != 0 ? " " : "",
700 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
701 indent, __VERSION__);
703 /* We need to stringify the GMP macro values. Ugh, gmp_version has
704 two string formats, "i.j.k" and "i.j" when k is zero. As of
705 gmp-4.3.0, GMP always uses the 3 number format. */
706 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
707 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
708 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
709 #define GCC_GMP_VERSION \
710 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
711 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
712 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
713 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
714 #else
715 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
716 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
717 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
718 #endif
719 fprintf (file,
720 file == stderr ? _(fmt2) : fmt2,
721 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING, MPC_VERSION_STRING);
722 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
723 fprintf (file,
724 file == stderr ? _(fmt3) : fmt3,
725 indent, *indent != 0 ? " " : "",
726 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
727 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
728 fprintf (file,
729 file == stderr ? _(fmt3) : fmt3,
730 indent, *indent != 0 ? " " : "",
731 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
732 if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
733 fprintf (file,
734 file == stderr ? _(fmt3) : fmt3,
735 indent, *indent != 0 ? " " : "",
736 "MPC", MPC_VERSION_STRING, mpc_get_version ());
737 fprintf (file,
738 file == stderr ? _(fmt4) : fmt4,
739 indent, *indent != 0 ? " " : "",
740 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
742 print_plugins_versions (file, indent);
745 static int
746 print_to_asm_out_file (print_switch_type type, const char * text)
748 bool prepend_sep = true;
750 switch (type)
752 case SWITCH_TYPE_LINE_END:
753 putc ('\n', asm_out_file);
754 return 1;
756 case SWITCH_TYPE_LINE_START:
757 fputs (ASM_COMMENT_START, asm_out_file);
758 return strlen (ASM_COMMENT_START);
760 case SWITCH_TYPE_DESCRIPTIVE:
761 if (ASM_COMMENT_START[0] == 0)
762 prepend_sep = false;
763 /* Drop through. */
764 case SWITCH_TYPE_PASSED:
765 case SWITCH_TYPE_ENABLED:
766 if (prepend_sep)
767 fputc (' ', asm_out_file);
768 fputs (text, asm_out_file);
769 /* No need to return the length here as
770 print_single_switch has already done it. */
771 return 0;
773 default:
774 return -1;
778 static int
779 print_to_stderr (print_switch_type type, const char * text)
781 switch (type)
783 case SWITCH_TYPE_LINE_END:
784 putc ('\n', stderr);
785 return 1;
787 case SWITCH_TYPE_LINE_START:
788 return 0;
790 case SWITCH_TYPE_PASSED:
791 case SWITCH_TYPE_ENABLED:
792 fputc (' ', stderr);
793 /* Drop through. */
795 case SWITCH_TYPE_DESCRIPTIVE:
796 fputs (text, stderr);
797 /* No need to return the length here as
798 print_single_switch has already done it. */
799 return 0;
801 default:
802 return -1;
806 /* Print an option value and return the adjusted position in the line.
807 ??? print_fn doesn't handle errors, eg disk full; presumably other
808 code will catch a disk full though. */
810 static int
811 print_single_switch (print_switch_fn_type print_fn,
812 int pos,
813 print_switch_type type,
814 const char * text)
816 /* The ultrix fprintf returns 0 on success, so compute the result
817 we want here since we need it for the following test. The +1
818 is for the separator character that will probably be emitted. */
819 int len = strlen (text) + 1;
821 if (pos != 0
822 && pos + len > MAX_LINE)
824 print_fn (SWITCH_TYPE_LINE_END, NULL);
825 pos = 0;
828 if (pos == 0)
829 pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
831 print_fn (type, text);
832 return pos + len;
835 /* Print active target switches using PRINT_FN.
836 POS is the current cursor position and MAX is the size of a "line".
837 Each line begins with INDENT and ends with TERM.
838 Each switch is separated from the next by SEP. */
840 static void
841 print_switch_values (print_switch_fn_type print_fn)
843 int pos = 0;
844 size_t j;
846 /* Fill in the -frandom-seed option, if the user didn't pass it, so
847 that it can be printed below. This helps reproducibility. */
848 if (!flag_random_seed)
849 init_random_seed ();
851 /* Print the options as passed. */
852 pos = print_single_switch (print_fn, pos,
853 SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
855 for (j = 1; j < save_decoded_options_count; j++)
857 switch (save_decoded_options[j].opt_index)
859 case OPT_o:
860 case OPT_d:
861 case OPT_dumpbase:
862 case OPT_dumpdir:
863 case OPT_auxbase:
864 case OPT_quiet:
865 case OPT_version:
866 /* Ignore these. */
867 continue;
870 pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED,
871 save_decoded_options[j].orig_option_with_args_text);
874 if (pos > 0)
875 print_fn (SWITCH_TYPE_LINE_END, NULL);
877 /* Print the -f and -m options that have been enabled.
878 We don't handle language specific options but printing argv
879 should suffice. */
880 pos = print_single_switch (print_fn, 0,
881 SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
883 for (j = 0; j < cl_options_count; j++)
884 if (cl_options[j].cl_report
885 && option_enabled (j, &global_options) > 0)
886 pos = print_single_switch (print_fn, pos,
887 SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
889 print_fn (SWITCH_TYPE_LINE_END, NULL);
892 /* Open assembly code output file. Do this even if -fsyntax-only is
893 on, because then the driver will have provided the name of a
894 temporary file or bit bucket for us. NAME is the file specified on
895 the command line, possibly NULL. */
896 static void
897 init_asm_output (const char *name)
899 if (name == NULL && asm_file_name == 0)
900 asm_out_file = stdout;
901 else
903 if (asm_file_name == 0)
905 int len = strlen (dump_base_name);
906 char *dumpname = XNEWVEC (char, len + 6);
908 memcpy (dumpname, dump_base_name, len + 1);
909 strip_off_ending (dumpname, len);
910 strcat (dumpname, ".s");
911 asm_file_name = dumpname;
913 if (!strcmp (asm_file_name, "-"))
914 asm_out_file = stdout;
915 else
916 asm_out_file = fopen (asm_file_name, "w");
917 if (asm_out_file == 0)
918 fatal_error ("can%'t open %s for writing: %m", asm_file_name);
921 if (!flag_syntax_only)
923 targetm.asm_out.file_start ();
925 if (flag_record_gcc_switches)
927 if (targetm.asm_out.record_gcc_switches)
929 /* Let the target know that we are about to start recording. */
930 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
931 NULL);
932 /* Now record the switches. */
933 print_switch_values (targetm.asm_out.record_gcc_switches);
934 /* Let the target know that the recording is over. */
935 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
936 NULL);
938 else
939 inform (input_location, "-frecord-gcc-switches is not supported by the current target");
942 if (flag_verbose_asm)
944 /* Print the list of switches in effect
945 into the assembler file as comments. */
946 print_version (asm_out_file, ASM_COMMENT_START);
947 print_switch_values (print_to_asm_out_file);
948 putc ('\n', asm_out_file);
953 /* A helper function; used as the reallocator function for cpp's line
954 table. */
955 static void *
956 realloc_for_line_map (void *ptr, size_t len)
958 return GGC_RESIZEVAR (void, ptr, len);
961 /* A helper function: used as the allocator function for
962 identifier_to_locale. */
963 static void *
964 alloc_for_identifier_to_locale (size_t len)
966 return ggc_alloc_atomic (len);
969 /* Output stack usage information. */
970 void
971 output_stack_usage (void)
973 static bool warning_issued = false;
974 enum stack_usage_kind_type { STATIC = 0, DYNAMIC, DYNAMIC_BOUNDED };
975 const char *stack_usage_kind_str[] = {
976 "static",
977 "dynamic",
978 "dynamic,bounded"
980 HOST_WIDE_INT stack_usage = current_function_static_stack_size;
981 enum stack_usage_kind_type stack_usage_kind;
983 if (stack_usage < 0)
985 if (!warning_issued)
987 warning (0, "stack usage computation not supported for this target");
988 warning_issued = true;
990 return;
993 stack_usage_kind = STATIC;
995 /* Add the maximum amount of space pushed onto the stack. */
996 if (current_function_pushed_stack_size > 0)
998 stack_usage += current_function_pushed_stack_size;
999 stack_usage_kind = DYNAMIC_BOUNDED;
1002 /* Now on to the tricky part: dynamic stack allocation. */
1003 if (current_function_allocates_dynamic_stack_space)
1005 if (current_function_has_unbounded_dynamic_stack_size)
1006 stack_usage_kind = DYNAMIC;
1007 else
1008 stack_usage_kind = DYNAMIC_BOUNDED;
1010 /* Add the size even in the unbounded case, this can't hurt. */
1011 stack_usage += current_function_dynamic_stack_size;
1014 if (flag_stack_usage)
1016 expanded_location loc
1017 = expand_location (DECL_SOURCE_LOCATION (current_function_decl));
1018 const char *raw_id, *id;
1020 /* Strip the scope prefix if any. */
1021 raw_id = lang_hooks.decl_printable_name (current_function_decl, 2);
1022 id = strrchr (raw_id, '.');
1023 if (id)
1024 id++;
1025 else
1026 id = raw_id;
1028 fprintf (stack_usage_file,
1029 "%s:%d:%d:%s\t"HOST_WIDE_INT_PRINT_DEC"\t%s\n",
1030 lbasename (loc.file),
1031 loc.line,
1032 loc.column,
1034 stack_usage,
1035 stack_usage_kind_str[stack_usage_kind]);
1038 if (warn_stack_usage >= 0)
1040 if (stack_usage_kind == DYNAMIC)
1041 warning (OPT_Wstack_usage_, "stack usage might be unbounded");
1042 else if (stack_usage > warn_stack_usage)
1044 if (stack_usage_kind == DYNAMIC_BOUNDED)
1045 warning (OPT_Wstack_usage_, "stack usage might be %wd bytes",
1046 stack_usage);
1047 else
1048 warning (OPT_Wstack_usage_, "stack usage is %wd bytes",
1049 stack_usage);
1054 /* Open an auxiliary output file. */
1055 static FILE *
1056 open_auxiliary_file (const char *ext)
1058 char *filename;
1059 FILE *file;
1061 filename = concat (aux_base_name, ".", ext, NULL);
1062 file = fopen (filename, "w");
1063 if (!file)
1064 fatal_error ("can%'t open %s for writing: %m", filename);
1065 free (filename);
1066 return file;
1069 /* Initialization of the front end environment, before command line
1070 options are parsed. Signal handlers, internationalization etc.
1071 ARGV0 is main's argv[0]. */
1072 static void
1073 general_init (const char *argv0)
1075 const char *p;
1077 p = argv0 + strlen (argv0);
1078 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1079 --p;
1080 progname = p;
1082 xmalloc_set_program_name (progname);
1084 hex_init ();
1086 /* Unlock the stdio streams. */
1087 unlock_std_streams ();
1089 gcc_init_libintl ();
1091 identifier_to_locale_alloc = alloc_for_identifier_to_locale;
1092 identifier_to_locale_free = ggc_free;
1094 /* Initialize the diagnostics reporting machinery, so option parsing
1095 can give warnings and errors. */
1096 diagnostic_initialize (global_dc, N_OPTS);
1097 /* Set a default printer. Language specific initializations will
1098 override it later. */
1099 tree_diagnostics_defaults (global_dc);
1100 /* FIXME: This should probably be moved to C-family
1101 language-specific initializations. */
1102 /* By default print macro expansion contexts in the diagnostic
1103 finalizer -- for tokens resulting from macro expansion. */
1104 diagnostic_finalizer (global_dc) = virt_loc_aware_diagnostic_finalizer;
1106 global_dc->show_caret
1107 = global_options_init.x_flag_diagnostics_show_caret;
1108 global_dc->show_option_requested
1109 = global_options_init.x_flag_diagnostics_show_option;
1110 global_dc->show_column
1111 = global_options_init.x_flag_show_column;
1112 global_dc->internal_error = plugins_internal_error_function;
1113 global_dc->option_enabled = option_enabled;
1114 global_dc->option_state = &global_options;
1115 global_dc->option_name = option_name;
1117 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1118 #ifdef SIGSEGV
1119 signal (SIGSEGV, crash_signal);
1120 #endif
1121 #ifdef SIGILL
1122 signal (SIGILL, crash_signal);
1123 #endif
1124 #ifdef SIGBUS
1125 signal (SIGBUS, crash_signal);
1126 #endif
1127 #ifdef SIGABRT
1128 signal (SIGABRT, crash_signal);
1129 #endif
1130 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1131 signal (SIGIOT, crash_signal);
1132 #endif
1133 #ifdef SIGFPE
1134 signal (SIGFPE, crash_signal);
1135 #endif
1137 /* Other host-specific signal setup. */
1138 (*host_hooks.extra_signals)();
1140 /* Initialize the garbage-collector, string pools and tree type hash
1141 table. */
1142 init_ggc ();
1143 init_stringpool ();
1144 line_table = ggc_alloc_line_maps ();
1145 linemap_init (line_table);
1146 line_table->reallocator = realloc_for_line_map;
1147 line_table->round_alloc_size = ggc_round_alloc_size;
1148 init_ttree ();
1150 /* Initialize register usage now so switches may override. */
1151 init_reg_sets ();
1153 /* Register the language-independent parameters. */
1154 global_init_params ();
1156 /* This must be done after global_init_params but before argument
1157 processing. */
1158 init_ggc_heuristics();
1159 init_optimization_passes ();
1160 statistics_early_init ();
1161 finish_params ();
1164 /* Return true if the current target supports -fsection-anchors. */
1166 static bool
1167 target_supports_section_anchors_p (void)
1169 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1170 return false;
1172 if (targetm.asm_out.output_anchor == NULL)
1173 return false;
1175 return true;
1178 /* Default the align_* variables to 1 if they're still unset, and
1179 set up the align_*_log variables. */
1180 static void
1181 init_alignments (void)
1183 if (align_loops <= 0)
1184 align_loops = 1;
1185 if (align_loops_max_skip > align_loops)
1186 align_loops_max_skip = align_loops - 1;
1187 align_loops_log = floor_log2 (align_loops * 2 - 1);
1188 if (align_jumps <= 0)
1189 align_jumps = 1;
1190 if (align_jumps_max_skip > align_jumps)
1191 align_jumps_max_skip = align_jumps - 1;
1192 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1193 if (align_labels <= 0)
1194 align_labels = 1;
1195 align_labels_log = floor_log2 (align_labels * 2 - 1);
1196 if (align_labels_max_skip > align_labels)
1197 align_labels_max_skip = align_labels - 1;
1198 if (align_functions <= 0)
1199 align_functions = 1;
1200 align_functions_log = floor_log2 (align_functions * 2 - 1);
1203 /* Process the options that have been parsed. */
1204 static void
1205 process_options (void)
1207 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1208 This can happen with incorrect pre-processed input. */
1209 debug_hooks = &do_nothing_debug_hooks;
1211 maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT;
1213 /* Default to -fdiagnostics-color=auto if GCC_COLORS is in the environment,
1214 otherwise default to -fdiagnostics-color=never. */
1215 if (!global_options_set.x_flag_diagnostics_show_color
1216 && getenv ("GCC_COLORS"))
1217 pp_show_color (global_dc->printer)
1218 = colorize_init (DIAGNOSTICS_COLOR_AUTO);
1220 /* Allow the front end to perform consistency checks and do further
1221 initialization based on the command line options. This hook also
1222 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1223 so we can correctly initialize debug output. */
1224 no_backend = lang_hooks.post_options (&main_input_filename);
1226 /* Some machines may reject certain combinations of options. */
1227 targetm.target_option.override ();
1229 /* Avoid any informative notes in the second run of -fcompare-debug. */
1230 if (flag_compare_debug)
1231 diagnostic_inhibit_notes (global_dc);
1233 if (flag_section_anchors && !target_supports_section_anchors_p ())
1235 warning (OPT_fsection_anchors,
1236 "this target does not support %qs", "-fsection-anchors");
1237 flag_section_anchors = 0;
1240 if (flag_short_enums == 2)
1241 flag_short_enums = targetm.default_short_enums ();
1243 /* Set aux_base_name if not already set. */
1244 if (aux_base_name)
1246 else if (main_input_filename)
1248 char *name = xstrdup (lbasename (main_input_filename));
1250 strip_off_ending (name, strlen (name));
1251 aux_base_name = name;
1253 else
1254 aux_base_name = "gccaux";
1256 #ifndef HAVE_cloog
1257 if (flag_graphite
1258 || flag_graphite_identity
1259 || flag_loop_block
1260 || flag_loop_interchange
1261 || flag_loop_strip_mine
1262 || flag_loop_parallelize_all)
1263 sorry ("Graphite loop optimizations cannot be used (-fgraphite, "
1264 "-fgraphite-identity, -floop-block, "
1265 "-floop-interchange, -floop-strip-mine, -floop-parallelize-all, "
1266 "and -ftree-loop-linear)");
1267 #endif
1269 if (flag_mudflap && flag_lto)
1270 sorry ("mudflap cannot be used together with link-time optimization");
1272 /* One region RA really helps to decrease the code size. */
1273 if (flag_ira_region == IRA_REGION_AUTODETECT)
1274 flag_ira_region
1275 = optimize_size || !optimize ? IRA_REGION_ONE : IRA_REGION_MIXED;
1277 if (flag_strict_volatile_bitfields > 0 && !abi_version_at_least (2))
1279 warning (0, "-fstrict-volatile-bitfields disabled; "
1280 "it is incompatible with ABI versions < 2");
1281 flag_strict_volatile_bitfields = 0;
1284 /* Unrolling all loops implies that standard loop unrolling must also
1285 be done. */
1286 if (flag_unroll_all_loops)
1287 flag_unroll_loops = 1;
1289 /* web and rename-registers help when run after loop unrolling. */
1290 if (flag_web == AUTODETECT_VALUE)
1291 flag_web = flag_unroll_loops || flag_peel_loops;
1293 if (flag_rename_registers == AUTODETECT_VALUE)
1294 flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1296 if (flag_non_call_exceptions)
1297 flag_asynchronous_unwind_tables = 1;
1298 if (flag_asynchronous_unwind_tables)
1299 flag_unwind_tables = 1;
1301 if (flag_value_profile_transformations)
1302 flag_profile_values = 1;
1304 /* Warn about options that are not supported on this machine. */
1305 #ifndef INSN_SCHEDULING
1306 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1307 warning (0, "instruction scheduling not supported on this target machine");
1308 #endif
1309 #ifndef DELAY_SLOTS
1310 if (flag_delayed_branch)
1311 warning (0, "this target machine does not have delayed branches");
1312 #endif
1314 user_label_prefix = USER_LABEL_PREFIX;
1315 if (flag_leading_underscore != -1)
1317 /* If the default prefix is more complicated than "" or "_",
1318 issue a warning and ignore this option. */
1319 if (user_label_prefix[0] == 0 ||
1320 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1322 user_label_prefix = flag_leading_underscore ? "_" : "";
1324 else
1325 warning (0, "-f%sleading-underscore not supported on this target machine",
1326 flag_leading_underscore ? "" : "no-");
1329 /* If we are in verbose mode, write out the version and maybe all the
1330 option flags in use. */
1331 if (version_flag)
1333 print_version (stderr, "");
1334 if (! quiet_flag)
1335 print_switch_values (print_to_stderr);
1338 if (flag_syntax_only)
1340 write_symbols = NO_DEBUG;
1341 profile_flag = 0;
1344 if (flag_gtoggle)
1346 if (debug_info_level == DINFO_LEVEL_NONE)
1348 debug_info_level = DINFO_LEVEL_NORMAL;
1350 if (write_symbols == NO_DEBUG)
1351 write_symbols = PREFERRED_DEBUGGING_TYPE;
1353 else
1354 debug_info_level = DINFO_LEVEL_NONE;
1357 if (flag_dump_final_insns && !flag_syntax_only && !no_backend)
1359 FILE *final_output = fopen (flag_dump_final_insns, "w");
1360 if (!final_output)
1362 error ("could not open final insn dump file %qs: %m",
1363 flag_dump_final_insns);
1364 flag_dump_final_insns = NULL;
1366 else if (fclose (final_output))
1368 error ("could not close zeroed insn dump file %qs: %m",
1369 flag_dump_final_insns);
1370 flag_dump_final_insns = NULL;
1374 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1375 level is 0. */
1376 if (debug_info_level == DINFO_LEVEL_NONE)
1377 write_symbols = NO_DEBUG;
1379 if (write_symbols == NO_DEBUG)
1381 #if defined(DBX_DEBUGGING_INFO)
1382 else if (write_symbols == DBX_DEBUG)
1383 debug_hooks = &dbx_debug_hooks;
1384 #endif
1385 #if defined(XCOFF_DEBUGGING_INFO)
1386 else if (write_symbols == XCOFF_DEBUG)
1387 debug_hooks = &xcoff_debug_hooks;
1388 #endif
1389 #ifdef SDB_DEBUGGING_INFO
1390 else if (write_symbols == SDB_DEBUG)
1391 debug_hooks = &sdb_debug_hooks;
1392 #endif
1393 #ifdef DWARF2_DEBUGGING_INFO
1394 else if (write_symbols == DWARF2_DEBUG)
1395 debug_hooks = &dwarf2_debug_hooks;
1396 #endif
1397 #ifdef VMS_DEBUGGING_INFO
1398 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1399 debug_hooks = &vmsdbg_debug_hooks;
1400 #endif
1401 else
1402 error ("target system does not support the \"%s\" debug format",
1403 debug_type_names[write_symbols]);
1405 /* We know which debug output will be used so we can set flag_var_tracking
1406 and flag_var_tracking_uninit if the user has not specified them. */
1407 if (debug_info_level < DINFO_LEVEL_NORMAL
1408 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1410 if (flag_var_tracking == 1
1411 || flag_var_tracking_uninit == 1)
1413 if (debug_info_level < DINFO_LEVEL_NORMAL)
1414 warning (0, "variable tracking requested, but useless unless "
1415 "producing debug info");
1416 else
1417 warning (0, "variable tracking requested, but not supported "
1418 "by this debug format");
1420 flag_var_tracking = 0;
1421 flag_var_tracking_uninit = 0;
1424 /* The debug hooks are used to implement -fdump-go-spec because it
1425 gives a simple and stable API for all the information we need to
1426 dump. */
1427 if (flag_dump_go_spec != NULL)
1428 debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks);
1430 /* If the user specifically requested variable tracking with tagging
1431 uninitialized variables, we need to turn on variable tracking.
1432 (We already determined above that variable tracking is feasible.) */
1433 if (flag_var_tracking_uninit == 1)
1434 flag_var_tracking = 1;
1436 if (flag_var_tracking == AUTODETECT_VALUE)
1437 flag_var_tracking = optimize >= 1;
1439 if (flag_var_tracking_uninit == AUTODETECT_VALUE)
1440 flag_var_tracking_uninit = flag_var_tracking;
1442 if (flag_var_tracking_assignments == AUTODETECT_VALUE)
1443 flag_var_tracking_assignments = flag_var_tracking
1444 && !(flag_selective_scheduling || flag_selective_scheduling2);
1446 if (flag_var_tracking_assignments_toggle)
1447 flag_var_tracking_assignments = !flag_var_tracking_assignments;
1449 if (flag_var_tracking_assignments && !flag_var_tracking)
1450 flag_var_tracking = flag_var_tracking_assignments = -1;
1452 if (flag_var_tracking_assignments
1453 && (flag_selective_scheduling || flag_selective_scheduling2))
1454 warning (0, "var-tracking-assignments changes selective scheduling");
1456 if (flag_tree_cselim == AUTODETECT_VALUE)
1457 #ifdef HAVE_conditional_move
1458 flag_tree_cselim = 1;
1459 #else
1460 flag_tree_cselim = 0;
1461 #endif
1463 /* If auxiliary info generation is desired, open the output file.
1464 This goes in the same directory as the source file--unlike
1465 all the other output files. */
1466 if (flag_gen_aux_info)
1468 aux_info_file = fopen (aux_info_file_name, "w");
1469 if (aux_info_file == 0)
1470 fatal_error ("can%'t open %s: %m", aux_info_file_name);
1473 if (!targetm_common.have_named_sections)
1475 if (flag_function_sections)
1477 warning (0, "-ffunction-sections not supported for this target");
1478 flag_function_sections = 0;
1480 if (flag_data_sections)
1482 warning (0, "-fdata-sections not supported for this target");
1483 flag_data_sections = 0;
1487 #ifndef HAVE_prefetch
1488 if (flag_prefetch_loop_arrays > 0)
1490 warning (0, "-fprefetch-loop-arrays not supported for this target");
1491 flag_prefetch_loop_arrays = 0;
1493 #else
1494 if (flag_prefetch_loop_arrays > 0 && !HAVE_prefetch)
1496 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
1497 flag_prefetch_loop_arrays = 0;
1499 #endif
1501 /* This combination of options isn't handled for i386 targets and doesn't
1502 make much sense anyway, so don't allow it. */
1503 if (flag_prefetch_loop_arrays > 0 && optimize_size)
1505 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
1506 flag_prefetch_loop_arrays = 0;
1509 /* The presence of IEEE signaling NaNs, implies all math can trap. */
1510 if (flag_signaling_nans)
1511 flag_trapping_math = 1;
1513 /* We cannot reassociate if we want traps or signed zeros. */
1514 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
1516 warning (0, "-fassociative-math disabled; other options take precedence");
1517 flag_associative_math = 0;
1520 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
1521 if (flag_cx_limited_range)
1522 flag_complex_method = 0;
1524 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
1525 if (flag_cx_fortran_rules)
1526 flag_complex_method = 1;
1528 /* Targets must be able to place spill slots at lower addresses. If the
1529 target already uses a soft frame pointer, the transition is trivial. */
1530 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
1532 warning (0, "-fstack-protector not supported for this target");
1533 flag_stack_protect = 0;
1535 if (!flag_stack_protect)
1536 warn_stack_protect = 0;
1538 /* Address Sanitizer needs porting to each target architecture. */
1539 if (flag_asan
1540 && (targetm.asan_shadow_offset == NULL
1541 || !FRAME_GROWS_DOWNWARD))
1543 warning (0, "-fsanitize=address not supported for this target");
1544 flag_asan = 0;
1547 /* Enable -Werror=coverage-mismatch when -Werror and -Wno-error
1548 have not been set. */
1549 if (!global_options_set.x_warnings_are_errors
1550 && warn_coverage_mismatch
1551 && (global_dc->classify_diagnostic[OPT_Wcoverage_mismatch] ==
1552 DK_UNSPECIFIED))
1553 diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch,
1554 DK_ERROR, UNKNOWN_LOCATION);
1556 /* Save the current optimization options. */
1557 optimization_default_node = build_optimization_node ();
1558 optimization_current_node = optimization_default_node;
1561 /* This function can be called multiple times to reinitialize the compiler
1562 back end when register classes or instruction sets have changed,
1563 before each function. */
1564 static void
1565 backend_init_target (void)
1567 /* Initialize alignment variables. */
1568 init_alignments ();
1570 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
1571 to initialize reg_raw_mode[]. */
1572 init_emit_regs ();
1574 /* This invokes target hooks to set fixed_reg[] etc, which is
1575 mode-dependent. */
1576 init_regs ();
1578 /* This depends on stack_pointer_rtx. */
1579 init_fake_stack_mems ();
1581 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
1582 mode-dependent. */
1583 init_alias_target ();
1585 /* Depends on HARD_FRAME_POINTER_REGNUM. */
1586 init_reload ();
1588 /* The following initialization functions need to generate rtl, so
1589 provide a dummy function context for them. */
1590 init_dummy_function_start ();
1592 /* rtx_cost is mode-dependent, so cached values need to be recomputed
1593 on a mode change. */
1594 init_expmed ();
1595 init_lower_subreg ();
1597 /* We may need to recompute regno_save_code[] and regno_restore_code[]
1598 after a mode change as well. */
1599 caller_save_initialized_p = false;
1601 expand_dummy_function_end ();
1604 /* Initialize the compiler back end. This function is called only once,
1605 when starting the compiler. */
1606 static void
1607 backend_init (void)
1609 init_emit_once ();
1611 init_rtlanal ();
1612 init_inline_once ();
1613 init_varasm_once ();
1614 save_register_info ();
1616 /* Initialize the target-specific back end pieces. */
1617 ira_init_once ();
1618 backend_init_target ();
1621 /* Initialize excess precision settings. */
1622 static void
1623 init_excess_precision (void)
1625 /* Adjust excess precision handling based on the target options. If
1626 the front end cannot handle it, flag_excess_precision_cmdline
1627 will already have been set accordingly in the post_options
1628 hook. */
1629 gcc_assert (flag_excess_precision_cmdline != EXCESS_PRECISION_DEFAULT);
1630 flag_excess_precision = flag_excess_precision_cmdline;
1631 if (flag_unsafe_math_optimizations)
1632 flag_excess_precision = EXCESS_PRECISION_FAST;
1633 if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
1635 int flt_eval_method = TARGET_FLT_EVAL_METHOD;
1636 switch (flt_eval_method)
1638 case -1:
1639 case 0:
1640 /* Either the target acts unpredictably (-1) or has all the
1641 operations required not to have excess precision (0). */
1642 flag_excess_precision = EXCESS_PRECISION_FAST;
1643 break;
1644 case 1:
1645 case 2:
1646 /* In these cases, predictable excess precision makes
1647 sense. */
1648 break;
1649 default:
1650 /* Any other implementation-defined FLT_EVAL_METHOD values
1651 require the compiler to handle the associated excess
1652 precision rules in excess_precision_type. */
1653 gcc_unreachable ();
1658 /* Initialize things that are both lang-dependent and target-dependent.
1659 This function can be called more than once if target parameters change. */
1660 static void
1661 lang_dependent_init_target (void)
1663 /* This determines excess precision settings. */
1664 init_excess_precision ();
1666 /* This creates various _DECL nodes, so needs to be called after the
1667 front end is initialized. It also depends on the HAVE_xxx macros
1668 generated from the target machine description. */
1669 init_optabs ();
1671 /* The following initialization functions need to generate rtl, so
1672 provide a dummy function context for them. */
1673 init_dummy_function_start ();
1675 /* Do the target-specific parts of expr initialization. */
1676 init_expr_target ();
1678 /* Although the actions of these functions are language-independent,
1679 they use optabs, so we cannot call them from backend_init. */
1680 init_set_costs ();
1681 ira_init ();
1683 expand_dummy_function_end ();
1686 /* Language-dependent initialization. Returns nonzero on success. */
1687 static int
1688 lang_dependent_init (const char *name)
1690 location_t save_loc = input_location;
1691 if (dump_base_name == 0)
1692 dump_base_name = name && name[0] ? name : "gccdump";
1694 /* Other front-end initialization. */
1695 input_location = BUILTINS_LOCATION;
1696 if (lang_hooks.init () == 0)
1697 return 0;
1698 input_location = save_loc;
1700 if (!flag_wpa)
1702 init_asm_output (name);
1704 /* If stack usage information is desired, open the output file. */
1705 if (flag_stack_usage)
1706 stack_usage_file = open_auxiliary_file ("su");
1709 /* This creates various _DECL nodes, so needs to be called after the
1710 front end is initialized. */
1711 init_eh ();
1713 /* Do the target-specific parts of the initialization. */
1714 lang_dependent_init_target ();
1716 if (!flag_wpa)
1718 /* If dbx symbol table desired, initialize writing it and output the
1719 predefined types. */
1720 timevar_push (TV_SYMOUT);
1722 /* Now we have the correct original filename, we can initialize
1723 debug output. */
1724 (*debug_hooks->init) (name);
1726 timevar_pop (TV_SYMOUT);
1729 return 1;
1733 /* Reinitialize everything when target parameters, such as register usage,
1734 have changed. */
1735 void
1736 target_reinit (void)
1738 struct rtl_data saved_x_rtl;
1739 rtx *saved_regno_reg_rtx;
1741 /* Save *crtl and regno_reg_rtx around the reinitialization
1742 to allow target_reinit being called even after prepare_function_start. */
1743 saved_regno_reg_rtx = regno_reg_rtx;
1744 if (saved_regno_reg_rtx)
1746 saved_x_rtl = *crtl;
1747 memset (crtl, '\0', sizeof (*crtl));
1748 regno_reg_rtx = NULL;
1751 /* Reinitialize RTL backend. */
1752 backend_init_target ();
1754 /* Reinitialize lang-dependent parts. */
1755 lang_dependent_init_target ();
1757 /* And restore it at the end, as free_after_compilation from
1758 expand_dummy_function_end clears it. */
1759 if (saved_regno_reg_rtx)
1761 *crtl = saved_x_rtl;
1762 regno_reg_rtx = saved_regno_reg_rtx;
1763 saved_regno_reg_rtx = NULL;
1767 void
1768 dump_memory_report (bool final)
1770 dump_line_table_statistics ();
1771 ggc_print_statistics ();
1772 stringpool_statistics ();
1773 dump_tree_statistics ();
1774 dump_gimple_statistics ();
1775 dump_rtx_statistics ();
1776 dump_alloc_pool_statistics ();
1777 dump_bitmap_statistics ();
1778 dump_vec_loc_statistics ();
1779 dump_ggc_loc_statistics (final);
1780 dump_alias_stats (stderr);
1781 dump_pta_stats (stderr);
1784 /* Clean up: close opened files, etc. */
1786 static void
1787 finalize (bool no_backend)
1789 /* Close the dump files. */
1790 if (flag_gen_aux_info)
1792 fclose (aux_info_file);
1793 if (seen_error ())
1794 unlink (aux_info_file_name);
1797 /* Close non-debugging input and output files. Take special care to note
1798 whether fclose returns an error, since the pages might still be on the
1799 buffer chain while the file is open. */
1801 if (asm_out_file)
1803 if (ferror (asm_out_file) != 0)
1804 fatal_error ("error writing to %s: %m", asm_file_name);
1805 if (fclose (asm_out_file) != 0)
1806 fatal_error ("error closing %s: %m", asm_file_name);
1809 if (stack_usage_file)
1810 fclose (stack_usage_file);
1812 if (!no_backend)
1814 statistics_fini ();
1816 finish_optimization_passes ();
1818 ira_finish_once ();
1821 if (mem_report)
1822 dump_memory_report (true);
1824 if (profile_report)
1825 dump_profile_report ();
1827 /* Language-specific end of compilation actions. */
1828 lang_hooks.finish ();
1831 /* Initialize the compiler, and compile the input file. */
1832 static void
1833 do_compile (void)
1835 /* Initialize timing first. The C front ends read the main file in
1836 the post_options hook, and C++ does file timings. */
1837 if (time_report || !quiet_flag || flag_detailed_statistics)
1838 timevar_init ();
1839 timevar_start (TV_TOTAL);
1841 process_options ();
1843 /* Don't do any more if an error has already occurred. */
1844 if (!seen_error ())
1846 timevar_start (TV_PHASE_SETUP);
1848 /* This must be run always, because it is needed to compute the FP
1849 predefined macros, such as __LDBL_MAX__, for targets using non
1850 default FP formats. */
1851 init_adjust_machine_modes ();
1853 /* Set up the back-end if requested. */
1854 if (!no_backend)
1855 backend_init ();
1857 /* Language-dependent initialization. Returns true on success. */
1858 if (lang_dependent_init (main_input_filename))
1860 /* Initialize yet another pass. */
1862 ggc_protect_identifiers = true;
1864 init_cgraph ();
1865 init_final (main_input_filename);
1866 coverage_init (aux_base_name);
1867 statistics_init ();
1868 invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
1870 timevar_stop (TV_PHASE_SETUP);
1872 compile_file ();
1874 else
1876 timevar_stop (TV_PHASE_SETUP);
1879 timevar_start (TV_PHASE_FINALIZE);
1881 finalize (no_backend);
1883 timevar_stop (TV_PHASE_FINALIZE);
1886 /* Stop timing and print the times. */
1887 timevar_stop (TV_TOTAL);
1888 timevar_print (stderr);
1891 /* Entry point of cc1, cc1plus, jc1, f771, etc.
1892 Exit code is FATAL_EXIT_CODE if can't open files or if there were
1893 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
1895 It is not safe to call this function more than once. */
1898 toplev_main (int argc, char **argv)
1900 /* Parsing and gimplification sometimes need quite large stack.
1901 Increase stack size limits if possible. */
1902 stack_limit_increase (64 * 1024 * 1024);
1904 expandargv (&argc, &argv);
1906 /* Initialization of GCC's environment, and diagnostics. */
1907 general_init (argv[0]);
1909 /* One-off initialization of options that does not need to be
1910 repeated when options are added for particular functions. */
1911 init_options_once ();
1913 /* Initialize global options structures; this must be repeated for
1914 each structure used for parsing options. */
1915 init_options_struct (&global_options, &global_options_set);
1916 lang_hooks.init_options_struct (&global_options);
1918 /* Convert the options to an array. */
1919 decode_cmdline_options_to_array_default_mask (argc,
1920 CONST_CAST2 (const char **,
1921 char **, argv),
1922 &save_decoded_options,
1923 &save_decoded_options_count);
1925 /* Perform language-specific options initialization. */
1926 lang_hooks.init_options (save_decoded_options_count, save_decoded_options);
1928 /* Parse the options and do minimal processing; basically just
1929 enough to default flags appropriately. */
1930 decode_options (&global_options, &global_options_set,
1931 save_decoded_options, save_decoded_options_count,
1932 UNKNOWN_LOCATION, global_dc);
1934 handle_common_deferred_options ();
1936 init_local_tick ();
1938 initialize_plugins ();
1940 if (version_flag)
1941 print_version (stderr, "");
1943 if (help_flag)
1944 print_plugins_help (stderr, "");
1946 /* Exit early if we can (e.g. -help). */
1947 if (!exit_after_options)
1948 do_compile ();
1950 if (warningcount || errorcount || werrorcount)
1951 print_ignored_options ();
1952 diagnostic_finish (global_dc);
1954 /* Invoke registered plugin callbacks if any. */
1955 invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
1957 finalize_plugins ();
1958 location_adhoc_data_fini (line_table);
1959 if (seen_error () || werrorcount)
1960 return (FATAL_EXIT_CODE);
1962 return (SUCCESS_EXIT_CODE);