For obj-c stage-final re-use the checksum from the previous stage
[official-gcc.git] / gcc / toplev.c
blob6a6ebe9bb8cd7143cc40fc68641a387a9eff03c0
1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987-2021 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 "backend.h"
29 #include "target.h"
30 #include "rtl.h"
31 #include "tree.h"
32 #include "gimple.h"
33 #include "alloc-pool.h"
34 #include "timevar.h"
35 #include "memmodel.h"
36 #include "tm_p.h"
37 #include "optabs-libfuncs.h"
38 #include "insn-config.h"
39 #include "ira.h"
40 #include "recog.h"
41 #include "cgraph.h"
42 #include "coverage.h"
43 #include "diagnostic.h"
44 #include "varasm.h"
45 #include "tree-inline.h"
46 #include "realmpfr.h" /* For GMP/MPFR/MPC versions, in print_version. */
47 #include "version.h"
48 #include "flags.h"
49 #include "insn-attr.h"
50 #include "output.h"
51 #include "toplev.h"
52 #include "expr.h"
53 #include "intl.h"
54 #include "tree-diagnostic.h"
55 #include "reload.h"
56 #include "lra.h"
57 #include "dwarf2asm.h"
58 #include "debug.h"
59 #include "common/common-target.h"
60 #include "langhooks.h"
61 #include "cfgloop.h" /* for init_set_costs */
62 #include "hosthooks.h"
63 #include "opts.h"
64 #include "opts-diagnostic.h"
65 #include "stringpool.h"
66 #include "attribs.h"
67 #include "asan.h"
68 #include "tsan.h"
69 #include "plugin.h"
70 #include "context.h"
71 #include "pass_manager.h"
72 #include "auto-profile.h"
73 #include "dwarf2out.h"
74 #include "ipa-reference.h"
75 #include "symbol-summary.h"
76 #include "tree-vrp.h"
77 #include "ipa-prop.h"
78 #include "gcse.h"
79 #include "omp-offload.h"
80 #include "edit-context.h"
81 #include "tree-pass.h"
82 #include "dumpfile.h"
83 #include "ipa-fnsummary.h"
84 #include "dump-context.h"
85 #include "print-tree.h"
86 #include "optinfo-emit-json.h"
87 #include "ipa-modref-tree.h"
88 #include "ipa-modref.h"
89 #include "dbgcnt.h"
91 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
92 #include "dbxout.h"
93 #endif
95 #ifdef XCOFF_DEBUGGING_INFO
96 #include "xcoffout.h" /* Needed for external data declarations. */
97 #endif
99 #include "selftest.h"
101 #ifdef HAVE_isl
102 #include <isl/version.h>
103 #endif
105 static void general_init (const char *, bool);
106 static void do_compile ();
107 static void process_options (void);
108 static void backend_init (void);
109 static int lang_dependent_init (const char *);
110 static void init_asm_output (const char *);
111 static void finalize (bool);
113 static void crash_signal (int) ATTRIBUTE_NORETURN;
114 static void compile_file (void);
116 /* True if we don't need a backend (e.g. preprocessing only). */
117 static bool no_backend;
119 /* Decoded options, and number of such options. */
120 struct cl_decoded_option *save_decoded_options;
121 unsigned int save_decoded_options_count;
123 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
124 to optimize in process_options (). */
125 #define AUTODETECT_VALUE 2
127 /* Debug hooks - dependent upon command line options. */
129 const struct gcc_debug_hooks *debug_hooks;
131 /* The FUNCTION_DECL for the function currently being compiled,
132 or 0 if between functions. */
133 tree current_function_decl;
135 /* Set to the FUNC_BEGIN label of the current function, or NULL
136 if none. */
137 const char * current_function_func_begin_label;
139 /* A random sequence of characters, unless overridden by user. */
140 static const char *flag_random_seed;
142 /* A local time stamp derived from the time of compilation. It will be
143 zero if the system cannot provide a time. It will be -1u, if the
144 user has specified a particular random seed. */
145 unsigned local_tick;
147 /* Random number for this compilation */
148 HOST_WIDE_INT random_seed;
150 /* -f flags. */
152 /* When non-NULL, indicates that whenever space is allocated on the
153 stack, the resulting stack pointer must not pass this
154 address---that is, for stacks that grow downward, the stack pointer
155 must always be greater than or equal to this address; for stacks
156 that grow upward, the stack pointer must be less than this address.
157 At present, the rtx may be either a REG or a SYMBOL_REF, although
158 the support provided depends on the backend. */
159 rtx stack_limit_rtx;
161 class target_flag_state default_target_flag_state;
162 #if SWITCHABLE_TARGET
163 class target_flag_state *this_target_flag_state = &default_target_flag_state;
164 #else
165 #define this_target_flag_state (&default_target_flag_state)
166 #endif
168 /* The user symbol prefix after having resolved same. */
169 const char *user_label_prefix;
171 /* Output files for assembler code (real compiler output)
172 and debugging dumps. */
174 FILE *asm_out_file;
175 FILE *aux_info_file;
176 FILE *callgraph_info_file = NULL;
177 static bitmap callgraph_info_external_printed;
178 FILE *stack_usage_file = NULL;
180 /* The current working directory of a translation. It's generally the
181 directory from which compilation was initiated, but a preprocessed
182 file may specify the original directory in which it was
183 created. */
185 static const char *src_pwd;
187 /* Initialize src_pwd with the given string, and return true. If it
188 was already initialized, return false. As a special case, it may
189 be called with a NULL argument to test whether src_pwd has NOT been
190 initialized yet. */
192 bool
193 set_src_pwd (const char *pwd)
195 if (src_pwd)
197 if (strcmp (src_pwd, pwd) == 0)
198 return true;
199 else
200 return false;
203 src_pwd = xstrdup (pwd);
204 return true;
207 /* Return the directory from which the translation unit was initiated,
208 in case set_src_pwd() was not called before to assign it a
209 different value. */
211 const char *
212 get_src_pwd (void)
214 if (! src_pwd)
216 src_pwd = getpwd ();
217 if (!src_pwd)
218 src_pwd = ".";
221 return src_pwd;
224 /* Called when the start of a function definition is parsed,
225 this function prints on stderr the name of the function. */
226 void
227 announce_function (tree decl)
229 if (!quiet_flag)
231 if (rtl_dump_and_exit)
232 fprintf (stderr, "%s ",
233 identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))));
234 else
235 fprintf (stderr, " %s",
236 identifier_to_locale (lang_hooks.decl_printable_name (decl, 2)));
237 fflush (stderr);
238 pp_needs_newline (global_dc->printer) = true;
239 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
243 /* Initialize local_tick with the time of day, or -1 if
244 flag_random_seed is set. */
246 static void
247 init_local_tick (void)
249 if (!flag_random_seed)
251 #ifdef HAVE_GETTIMEOFDAY
253 struct timeval tv;
255 gettimeofday (&tv, NULL);
256 local_tick = (unsigned) tv.tv_sec * 1000 + tv.tv_usec / 1000;
258 #else
260 time_t now = time (NULL);
262 if (now != (time_t)-1)
263 local_tick = (unsigned) now;
265 #endif
267 else
268 local_tick = -1;
271 /* Obtain the random_seed. Unless NOINIT, initialize it if
272 it's not provided in the command line. */
274 HOST_WIDE_INT
275 get_random_seed (bool noinit)
277 if (!random_seed && !noinit)
279 int fd = open ("/dev/urandom", O_RDONLY);
280 if (fd >= 0)
282 if (read (fd, &random_seed, sizeof (random_seed))
283 != sizeof (random_seed))
284 random_seed = 0;
285 close (fd);
287 if (!random_seed)
288 random_seed = local_tick ^ getpid ();
290 return random_seed;
293 /* Set flag_random_seed to VAL, and if non-null, reinitialize random_seed. */
295 void
296 set_random_seed (const char *val)
298 flag_random_seed = val;
299 if (flag_random_seed)
301 char *endp;
303 /* When the driver passed in a hex number don't crc it again */
304 random_seed = strtoul (flag_random_seed, &endp, 0);
305 if (!(endp > flag_random_seed && *endp == 0))
306 random_seed = crc32_string (0, flag_random_seed);
310 /* Handler for fatal signals, such as SIGSEGV. These are transformed
311 into ICE messages, which is much more user friendly. In case the
312 error printer crashes, reset the signal to prevent infinite recursion. */
314 static void
315 crash_signal (int signo)
317 signal (signo, SIG_DFL);
319 /* If we crashed while processing an ASM statement, then be a little more
320 graceful. It's most likely the user's fault. */
321 if (this_is_asm_operands)
323 output_operand_lossage ("unrecoverable error");
324 exit (FATAL_EXIT_CODE);
327 internal_error ("%s", strsignal (signo));
330 /* A subroutine of wrapup_global_declarations. We've come to the end of
331 the compilation unit. All deferred variables should be undeferred,
332 and all incomplete decls should be finalized. */
334 void
335 wrapup_global_declaration_1 (tree decl)
337 /* We're not deferring this any longer. Assignment is conditional to
338 avoid needlessly dirtying PCH pages. */
339 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
340 && DECL_DEFER_OUTPUT (decl) != 0)
341 DECL_DEFER_OUTPUT (decl) = 0;
343 if (VAR_P (decl) && DECL_SIZE (decl) == 0)
344 lang_hooks.finish_incomplete_decl (decl);
347 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
348 needs to be output. Return true if it is output. */
350 bool
351 wrapup_global_declaration_2 (tree decl)
353 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl)
354 || (VAR_P (decl) && DECL_HAS_VALUE_EXPR_P (decl)))
355 return false;
357 /* Don't write out static consts, unless we still need them.
359 We also keep static consts if not optimizing (for debugging),
360 unless the user specified -fno-keep-static-consts.
361 ??? They might be better written into the debug information.
362 This is possible when using DWARF.
364 A language processor that wants static constants to be always
365 written out (even if it is not used) is responsible for
366 calling rest_of_decl_compilation itself. E.g. the C front-end
367 calls rest_of_decl_compilation from finish_decl.
368 One motivation for this is that is conventional in some
369 environments to write things like:
370 static const char rcsid[] = "... version string ...";
371 intending to force the string to be in the executable.
373 A language processor that would prefer to have unneeded
374 static constants "optimized away" would just defer writing
375 them out until here. E.g. C++ does this, because static
376 constants are often defined in header files.
378 ??? A tempting alternative (for both C and C++) would be
379 to force a constant to be written if and only if it is
380 defined in a main file, as opposed to an include file. */
382 if (VAR_P (decl) && TREE_STATIC (decl))
384 varpool_node *node;
385 bool needed = true;
386 node = varpool_node::get (decl);
388 if (!node && flag_ltrans)
389 needed = false;
390 else if (node && node->definition)
391 needed = false;
392 else if (node && node->alias)
393 needed = false;
394 else if (!symtab->global_info_ready
395 && (TREE_USED (decl)
396 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
397 /* needed */;
398 else if (node && node->analyzed)
399 /* needed */;
400 else if (DECL_COMDAT (decl))
401 needed = false;
402 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
403 && (optimize || !flag_keep_static_consts
404 || DECL_ARTIFICIAL (decl)))
405 needed = false;
407 if (needed)
409 rest_of_decl_compilation (decl, 1, 1);
410 return true;
414 return false;
417 /* Do any final processing required for the declarations in VEC, of
418 which there are LEN. We write out inline functions and variables
419 that have been deferred until this point, but which are required.
420 Returns nonzero if anything was put out. */
422 bool
423 wrapup_global_declarations (tree *vec, int len)
425 bool reconsider, output_something = false;
426 int i;
428 for (i = 0; i < len; i++)
429 wrapup_global_declaration_1 (vec[i]);
431 /* Now emit any global variables or functions that we have been
432 putting off. We need to loop in case one of the things emitted
433 here references another one which comes earlier in the list. */
436 reconsider = false;
437 for (i = 0; i < len; i++)
438 reconsider |= wrapup_global_declaration_2 (vec[i]);
439 if (reconsider)
440 output_something = true;
442 while (reconsider);
444 return output_something;
447 /* Compile an entire translation unit. Write a file of assembly
448 output and various debugging dumps. */
450 static void
451 compile_file (void)
453 timevar_start (TV_PHASE_PARSING);
454 timevar_push (TV_PARSE_GLOBAL);
456 /* Parse entire file and generate initial debug information. */
457 lang_hooks.parse_file ();
459 timevar_pop (TV_PARSE_GLOBAL);
460 timevar_stop (TV_PHASE_PARSING);
462 if (flag_dump_locations)
463 dump_location_info (stderr);
465 /* Compilation is now finished except for writing
466 what's left of the symbol table output. */
468 if (flag_syntax_only || flag_wpa)
469 return;
471 /* Reset maximum_field_alignment, it can be adjusted by #pragma pack
472 and this shouldn't influence any types built by the middle-end
473 from now on (like gcov_info_type). */
474 maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT;
476 ggc_protect_identifiers = false;
478 /* Run the actual compilation process. */
479 if (!in_lto_p)
481 timevar_start (TV_PHASE_OPT_GEN);
482 symtab->finalize_compilation_unit ();
483 timevar_stop (TV_PHASE_OPT_GEN);
486 /* Perform any post compilation-proper parser cleanups and
487 processing. This is currently only needed for the C++ parser,
488 which can be hopefully cleaned up so this hook is no longer
489 necessary. */
490 if (lang_hooks.decls.post_compilation_parsing_cleanups)
491 lang_hooks.decls.post_compilation_parsing_cleanups ();
493 dump_context::get ().finish_any_json_writer ();
495 if (seen_error ())
496 return;
498 timevar_start (TV_PHASE_LATE_ASM);
500 /* Compilation unit is finalized. When producing non-fat LTO object, we are
501 basically finished. */
502 if ((in_lto_p && flag_incremental_link != INCREMENTAL_LINK_LTO)
503 || !flag_lto || flag_fat_lto_objects)
505 /* File-scope initialization for AddressSanitizer. */
506 if (flag_sanitize & SANITIZE_ADDRESS)
507 asan_finish_file ();
509 if (flag_sanitize & SANITIZE_THREAD)
510 tsan_finish_file ();
512 if (gate_hwasan ())
513 hwasan_finish_file ();
515 omp_finish_file ();
517 output_shared_constant_pool ();
518 output_object_blocks ();
519 finish_tm_clone_pairs ();
521 /* Write out any pending weak symbol declarations. */
522 weak_finish ();
524 /* This must be at the end before unwind and debug info.
525 Some target ports emit PIC setup thunks here. */
526 insn_locations_init ();
527 targetm.asm_out.code_end ();
529 /* Do dbx symbols. */
530 timevar_push (TV_SYMOUT);
532 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
533 dwarf2out_frame_finish ();
534 #endif
536 debuginfo_start ();
537 (*debug_hooks->finish) (main_input_filename);
538 debuginfo_stop ();
539 timevar_pop (TV_SYMOUT);
541 /* Output some stuff at end of file if nec. */
543 dw2_output_indirect_constants ();
545 /* Flush any pending external directives. */
546 process_pending_assemble_externals ();
549 /* Let linker plugin know that this is a slim object and must be LTOed
550 even when user did not ask for it. */
551 if (flag_generate_lto && !flag_fat_lto_objects)
553 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
554 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE, "__gnu_lto_slim",
555 HOST_WIDE_INT_1U, 8);
556 #elif defined ASM_OUTPUT_ALIGNED_COMMON
557 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_slim",
558 HOST_WIDE_INT_1U, 8);
559 #else
560 ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_slim",
561 HOST_WIDE_INT_1U,
562 HOST_WIDE_INT_1U);
563 #endif
566 /* Attach a special .ident directive to the end of the file to identify
567 the version of GCC which compiled this code. The format of the .ident
568 string is patterned after the ones produced by native SVR4 compilers. */
569 if (!flag_no_ident)
571 const char *pkg_version = "(GNU) ";
572 char *ident_str;
574 if (strcmp ("(GCC) ", pkgversion_string))
575 pkg_version = pkgversion_string;
577 ident_str = ACONCAT (("GCC: ", pkg_version, version_string, NULL));
578 targetm.asm_out.output_ident (ident_str);
581 /* Auto profile finalization. */
582 if (flag_auto_profile)
583 end_auto_profile ();
585 /* Invoke registered plugin callbacks. */
586 invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
588 /* This must be at the end. Some target ports emit end of file directives
589 into the assembly file here, and hence we cannot output anything to the
590 assembly file after this point. */
591 targetm.asm_out.file_end ();
593 timevar_stop (TV_PHASE_LATE_ASM);
596 /* Print version information to FILE.
597 Each line begins with INDENT (for the case where FILE is the
598 assembler output file).
600 If SHOW_GLOBAL_STATE is true (for cc1 etc), we are within the compiler
601 proper and can print pertinent state (e.g. params and plugins).
603 If SHOW_GLOBAL_STATE is false (for use by libgccjit), we are outside the
604 compiler, and we don't hold the mutex on the compiler's global state:
605 we can't print params and plugins, since they might not be initialized,
606 or might be being manipulated by a compile running in another
607 thread. */
609 void
610 print_version (FILE *file, const char *indent, bool show_global_state)
612 static const char fmt1[] =
613 #ifdef __GNUC__
614 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
615 #else
616 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
617 #endif
619 static const char fmt2[] =
620 N_("GMP version %s, MPFR version %s, MPC version %s, isl version %s\n");
621 static const char fmt3[] =
622 N_("%s%swarning: %s header version %s differs from library version %s.\n");
623 static const char fmt4[] =
624 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
625 #ifndef __VERSION__
626 #define __VERSION__ "[?]"
627 #endif
628 fprintf (file,
629 file == stderr ? _(fmt1) : fmt1,
630 indent, *indent != 0 ? " " : "",
631 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
632 indent, __VERSION__);
634 /* We need to stringify the GMP macro values. Ugh, gmp_version has
635 two string formats, "i.j.k" and "i.j" when k is zero. As of
636 gmp-4.3.0, GMP always uses the 3 number format. */
637 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
638 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3 (X)
639 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
640 #define GCC_GMP_VERSION \
641 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
642 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
643 #define GCC_GMP_STRINGIFY_VERSION \
644 GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION) "." \
645 GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION_MINOR)
646 #else
647 #define GCC_GMP_STRINGIFY_VERSION \
648 GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION) "." \
649 GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION_MINOR) "." \
650 GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION_PATCHLEVEL)
651 #endif
652 fprintf (file,
653 file == stderr ? _(fmt2) : fmt2,
654 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING, MPC_VERSION_STRING,
655 #ifndef HAVE_isl
656 "none"
657 #else
658 isl_version ()
659 #endif
661 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
662 fprintf (file,
663 file == stderr ? _(fmt3) : fmt3,
664 indent, *indent != 0 ? " " : "",
665 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
666 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
667 fprintf (file,
668 file == stderr ? _(fmt3) : fmt3,
669 indent, *indent != 0 ? " " : "",
670 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
671 if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
672 fprintf (file,
673 file == stderr ? _(fmt3) : fmt3,
674 indent, *indent != 0 ? " " : "",
675 "MPC", MPC_VERSION_STRING, mpc_get_version ());
677 if (show_global_state)
679 fprintf (file,
680 file == stderr ? _(fmt4) : fmt4,
681 indent, *indent != 0 ? " " : "",
682 param_ggc_min_expand, param_ggc_min_heapsize);
684 print_plugins_versions (file, indent);
690 /* Open assembly code output file. Do this even if -fsyntax-only is
691 on, because then the driver will have provided the name of a
692 temporary file or bit bucket for us. NAME is the file specified on
693 the command line, possibly NULL. */
694 static void
695 init_asm_output (const char *name)
697 if (name == NULL && asm_file_name == 0)
698 asm_out_file = stdout;
699 else
701 if (asm_file_name == 0)
703 int len = strlen (dump_base_name);
704 char *dumpname = XNEWVEC (char, len + 6);
706 memcpy (dumpname, dump_base_name, len + 1);
707 strip_off_ending (dumpname, len);
708 strcat (dumpname, ".s");
709 asm_file_name = dumpname;
711 if (!strcmp (asm_file_name, "-"))
712 asm_out_file = stdout;
713 else if (!canonical_filename_eq (asm_file_name, name)
714 || !strcmp (asm_file_name, HOST_BIT_BUCKET))
715 asm_out_file = fopen (asm_file_name, "w");
716 else
717 /* Use UNKOWN_LOCATION to prevent gcc from printing the first
718 line in the current file. */
719 fatal_error (UNKNOWN_LOCATION,
720 "input file %qs is the same as output file",
721 asm_file_name);
722 if (asm_out_file == 0)
723 fatal_error (UNKNOWN_LOCATION,
724 "cannot open %qs for writing: %m", asm_file_name);
727 if (!flag_syntax_only)
729 targetm.asm_out.file_start ();
731 if (flag_record_gcc_switches)
733 if (targetm.asm_out.record_gcc_switches)
735 const char *str
736 = gen_producer_string (lang_hooks.name,
737 save_decoded_options,
738 save_decoded_options_count);
739 targetm.asm_out.record_gcc_switches (str);
741 else
742 inform (UNKNOWN_LOCATION,
743 "%<-frecord-gcc-switches%> is not supported by "
744 "the current target");
747 if (flag_verbose_asm)
749 print_version (asm_out_file, ASM_COMMENT_START, true);
750 fputs (ASM_COMMENT_START, asm_out_file);
751 fputs (" options passed: ", asm_out_file);
752 char *cmdline = gen_command_line_string (save_decoded_options,
753 save_decoded_options_count);
754 fputs (cmdline, asm_out_file);
755 free (cmdline);
756 fputc ('\n', asm_out_file);
761 /* A helper function; used as the reallocator function for cpp's line
762 table. */
763 static void *
764 realloc_for_line_map (void *ptr, size_t len)
766 return ggc_realloc (ptr, len);
769 /* A helper function: used as the allocator function for
770 identifier_to_locale. */
771 static void *
772 alloc_for_identifier_to_locale (size_t len)
774 return ggc_alloc_atomic (len);
777 /* Output stack usage information. */
778 static void
779 output_stack_usage_1 (FILE *cf)
781 static bool warning_issued = false;
782 enum stack_usage_kind_type { STATIC = 0, DYNAMIC, DYNAMIC_BOUNDED };
783 const char *stack_usage_kind_str[] = {
784 "static",
785 "dynamic",
786 "dynamic,bounded"
788 HOST_WIDE_INT stack_usage = current_function_static_stack_size;
789 enum stack_usage_kind_type stack_usage_kind;
791 if (stack_usage < 0)
793 if (!warning_issued)
795 warning (0, "stack usage computation not supported for this target");
796 warning_issued = true;
798 return;
801 stack_usage_kind = STATIC;
803 /* Add the maximum amount of space pushed onto the stack. */
804 if (maybe_ne (current_function_pushed_stack_size, 0))
806 HOST_WIDE_INT extra;
807 if (current_function_pushed_stack_size.is_constant (&extra))
809 stack_usage += extra;
810 stack_usage_kind = DYNAMIC_BOUNDED;
812 else
814 extra = constant_lower_bound (current_function_pushed_stack_size);
815 stack_usage += extra;
816 stack_usage_kind = DYNAMIC;
820 /* Now on to the tricky part: dynamic stack allocation. */
821 if (current_function_allocates_dynamic_stack_space)
823 if (stack_usage_kind != DYNAMIC)
825 if (current_function_has_unbounded_dynamic_stack_size)
826 stack_usage_kind = DYNAMIC;
827 else
828 stack_usage_kind = DYNAMIC_BOUNDED;
831 /* Add the size even in the unbounded case, this can't hurt. */
832 stack_usage += current_function_dynamic_stack_size;
835 if (cf && flag_callgraph_info & CALLGRAPH_INFO_STACK_USAGE)
836 fprintf (cf, "\\n" HOST_WIDE_INT_PRINT_DEC " bytes (%s)",
837 stack_usage,
838 stack_usage_kind_str[stack_usage_kind]);
840 if (stack_usage_file)
842 print_decl_identifier (stack_usage_file, current_function_decl,
843 PRINT_DECL_ORIGIN | PRINT_DECL_NAME);
844 fprintf (stack_usage_file, "\t" HOST_WIDE_INT_PRINT_DEC"\t%s\n",
845 stack_usage, stack_usage_kind_str[stack_usage_kind]);
848 if (warn_stack_usage >= 0 && warn_stack_usage < HOST_WIDE_INT_MAX)
850 const location_t loc = DECL_SOURCE_LOCATION (current_function_decl);
852 if (stack_usage_kind == DYNAMIC)
853 warning_at (loc, OPT_Wstack_usage_, "stack usage might be unbounded");
854 else if (stack_usage > warn_stack_usage)
856 if (stack_usage_kind == DYNAMIC_BOUNDED)
857 warning_at (loc,
858 OPT_Wstack_usage_, "stack usage might be %wu bytes",
859 stack_usage);
860 else
861 warning_at (loc, OPT_Wstack_usage_, "stack usage is %wu bytes",
862 stack_usage);
867 /* Dump placeholder node for indirect calls in VCG format. */
869 #define INDIRECT_CALL_NAME "__indirect_call"
871 static void
872 dump_final_node_vcg_start (FILE *f, tree decl)
874 fputs ("node: { title: \"", f);
875 if (decl)
876 print_decl_identifier (f, decl, PRINT_DECL_UNIQUE_NAME);
877 else
878 fputs (INDIRECT_CALL_NAME, f);
879 fputs ("\" label: \"", f);
880 if (decl)
882 print_decl_identifier (f, decl, PRINT_DECL_NAME);
883 fputs ("\\n", f);
884 print_decl_identifier (f, decl, PRINT_DECL_ORIGIN);
886 else
887 fputs ("Indirect Call Placeholder", f);
890 /* Dump final cgraph edge in VCG format. */
892 static void
893 dump_final_callee_vcg (FILE *f, location_t location, tree callee)
895 if ((!callee || DECL_EXTERNAL (callee))
896 && bitmap_set_bit (callgraph_info_external_printed,
897 callee ? DECL_UID (callee) + 1 : 0))
899 dump_final_node_vcg_start (f, callee);
900 fputs ("\" shape : ellipse }\n", f);
903 fputs ("edge: { sourcename: \"", f);
904 print_decl_identifier (f, current_function_decl, PRINT_DECL_UNIQUE_NAME);
905 fputs ("\" targetname: \"", f);
906 if (callee)
907 print_decl_identifier (f, callee, PRINT_DECL_UNIQUE_NAME);
908 else
909 fputs (INDIRECT_CALL_NAME, f);
910 if (LOCATION_LOCUS (location) != UNKNOWN_LOCATION)
912 expanded_location loc;
913 fputs ("\" label: \"", f);
914 loc = expand_location (location);
915 fprintf (f, "%s:%d:%d", loc.file, loc.line, loc.column);
917 fputs ("\" }\n", f);
920 /* Dump final cgraph node in VCG format. */
922 static void
923 dump_final_node_vcg (FILE *f)
925 dump_final_node_vcg_start (f, current_function_decl);
927 if (flag_stack_usage_info
928 || (flag_callgraph_info & CALLGRAPH_INFO_STACK_USAGE))
929 output_stack_usage_1 (f);
931 if (flag_callgraph_info & CALLGRAPH_INFO_DYNAMIC_ALLOC)
933 fprintf (f, "\\n%u dynamic objects", vec_safe_length (cfun->su->dallocs));
935 unsigned i;
936 callinfo_dalloc *cda;
937 FOR_EACH_VEC_SAFE_ELT (cfun->su->dallocs, i, cda)
939 expanded_location loc = expand_location (cda->location);
940 fprintf (f, "\\n %s", cda->name);
941 fprintf (f, " %s:%d:%d", loc.file, loc.line, loc.column);
944 vec_free (cfun->su->dallocs);
945 cfun->su->dallocs = NULL;
948 fputs ("\" }\n", f);
950 unsigned i;
951 callinfo_callee *c;
952 FOR_EACH_VEC_SAFE_ELT (cfun->su->callees, i, c)
953 dump_final_callee_vcg (f, c->location, c->decl);
954 vec_free (cfun->su->callees);
955 cfun->su->callees = NULL;
958 /* Output stack usage and callgraph info, as requested. */
959 void
960 output_stack_usage (void)
962 if (flag_callgraph_info)
963 dump_final_node_vcg (callgraph_info_file);
964 else
965 output_stack_usage_1 (NULL);
968 /* Open an auxiliary output file. */
969 static FILE *
970 open_auxiliary_file (const char *ext)
972 char *filename;
973 FILE *file;
975 filename = concat (aux_base_name, ".", ext, NULL);
976 file = fopen (filename, "w");
977 if (!file)
978 fatal_error (input_location, "cannot open %s for writing: %m", filename);
979 free (filename);
980 return file;
983 /* Alternative diagnostics callback for reentered ICE reporting. */
985 static void
986 internal_error_reentered (diagnostic_context *, const char *, va_list *)
988 /* Flush the dump file if emergency_dump_function itself caused an ICE. */
989 if (dump_file)
990 fflush (dump_file);
993 /* Auxiliary callback for the diagnostics code. */
995 static void
996 internal_error_function (diagnostic_context *, const char *, va_list *)
998 global_dc->internal_error = internal_error_reentered;
999 warn_if_plugins ();
1000 emergency_dump_function ();
1003 /* Initialization of the front end environment, before command line
1004 options are parsed. Signal handlers, internationalization etc.
1005 ARGV0 is main's argv[0]. */
1006 static void
1007 general_init (const char *argv0, bool init_signals)
1009 const char *p;
1011 p = argv0 + strlen (argv0);
1012 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1013 --p;
1014 progname = p;
1016 xmalloc_set_program_name (progname);
1018 hex_init ();
1020 /* Unlock the stdio streams. */
1021 unlock_std_streams ();
1023 gcc_init_libintl ();
1025 identifier_to_locale_alloc = alloc_for_identifier_to_locale;
1026 identifier_to_locale_free = ggc_free;
1028 /* Initialize the diagnostics reporting machinery, so option parsing
1029 can give warnings and errors. */
1030 diagnostic_initialize (global_dc, N_OPTS);
1031 global_dc->lang_mask = lang_hooks.option_lang_mask ();
1032 /* Set a default printer. Language specific initializations will
1033 override it later. */
1034 tree_diagnostics_defaults (global_dc);
1036 global_dc->show_caret
1037 = global_options_init.x_flag_diagnostics_show_caret;
1038 global_dc->show_labels_p
1039 = global_options_init.x_flag_diagnostics_show_labels;
1040 global_dc->show_line_numbers_p
1041 = global_options_init.x_flag_diagnostics_show_line_numbers;
1042 global_dc->show_cwe
1043 = global_options_init.x_flag_diagnostics_show_cwe;
1044 global_dc->path_format
1045 = (enum diagnostic_path_format)global_options_init.x_flag_diagnostics_path_format;
1046 global_dc->show_path_depths
1047 = global_options_init.x_flag_diagnostics_show_path_depths;
1048 global_dc->show_option_requested
1049 = global_options_init.x_flag_diagnostics_show_option;
1050 global_dc->min_margin_width
1051 = global_options_init.x_diagnostics_minimum_margin_width;
1052 global_dc->show_column
1053 = global_options_init.x_flag_show_column;
1054 global_dc->internal_error = internal_error_function;
1055 global_dc->option_enabled = option_enabled;
1056 global_dc->option_state = &global_options;
1057 global_dc->option_name = option_name;
1058 global_dc->get_option_url = get_option_url;
1060 if (init_signals)
1062 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1063 #ifdef SIGSEGV
1064 signal (SIGSEGV, crash_signal);
1065 #endif
1066 #ifdef SIGILL
1067 signal (SIGILL, crash_signal);
1068 #endif
1069 #ifdef SIGBUS
1070 signal (SIGBUS, crash_signal);
1071 #endif
1072 #ifdef SIGABRT
1073 signal (SIGABRT, crash_signal);
1074 #endif
1075 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1076 signal (SIGIOT, crash_signal);
1077 #endif
1078 #ifdef SIGFPE
1079 signal (SIGFPE, crash_signal);
1080 #endif
1082 /* Other host-specific signal setup. */
1083 (*host_hooks.extra_signals)();
1086 /* Initialize the garbage-collector, string pools and tree type hash
1087 table. */
1088 init_ggc ();
1089 init_stringpool ();
1090 input_location = UNKNOWN_LOCATION;
1091 line_table = ggc_alloc<line_maps> ();
1092 linemap_init (line_table, BUILTINS_LOCATION);
1093 line_table->reallocator = realloc_for_line_map;
1094 line_table->round_alloc_size = ggc_round_alloc_size;
1095 line_table->default_range_bits = 5;
1096 init_ttree ();
1098 /* Initialize register usage now so switches may override. */
1099 init_reg_sets ();
1101 /* Create the singleton holder for global state. This creates the
1102 dump manager. */
1103 g = new gcc::context ();
1105 /* Allow languages and middle-end to register their dumps before the
1106 optimization passes. */
1107 g->get_dumps ()->register_dumps ();
1109 /* Create the passes. */
1110 g->set_passes (new gcc::pass_manager (g));
1112 symtab = new (ggc_alloc <symbol_table> ()) symbol_table ();
1114 statistics_early_init ();
1115 debuginfo_early_init ();
1118 /* Return true if the current target supports -fsection-anchors. */
1120 static bool
1121 target_supports_section_anchors_p (void)
1123 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1124 return false;
1126 if (targetm.asm_out.output_anchor == NULL)
1127 return false;
1129 return true;
1132 /* Parse "N[:M][:...]" into struct align_flags A.
1133 VALUES contains parsed values (in reverse order), all processed
1134 values are popped. */
1136 static void
1137 read_log_maxskip (auto_vec<unsigned> &values, align_flags_tuple *a)
1139 unsigned n = values.pop ();
1140 if (n != 0)
1141 a->log = floor_log2 (n * 2 - 1);
1143 if (values.is_empty ())
1144 a->maxskip = n ? n - 1 : 0;
1145 else
1147 unsigned m = values.pop ();
1148 /* -falign-foo=N:M means M-1 max bytes of padding, not M. */
1149 if (m > 0)
1150 m--;
1151 a->maxskip = m;
1154 /* Normalize the tuple. */
1155 a->normalize ();
1158 /* Parse "N[:M[:N2[:M2]]]" string FLAG into a pair of struct align_flags. */
1160 static void
1161 parse_N_M (const char *flag, align_flags &a)
1163 if (flag)
1165 static hash_map <nofree_string_hash, align_flags> cache;
1166 align_flags *entry = cache.get (flag);
1167 if (entry)
1169 a = *entry;
1170 return;
1173 auto_vec<unsigned> result_values;
1174 bool r = parse_and_check_align_values (flag, NULL, result_values, false,
1175 UNKNOWN_LOCATION);
1176 if (!r)
1177 return;
1179 /* Reverse values for easier manipulation. */
1180 result_values.reverse ();
1182 read_log_maxskip (result_values, &a.levels[0]);
1183 if (!result_values.is_empty ())
1184 read_log_maxskip (result_values, &a.levels[1]);
1185 #ifdef SUBALIGN_LOG
1186 else
1188 /* N2[:M2] is not specified. This arch has a default for N2.
1189 Before -falign-foo=N:M:N2:M2 was introduced, x86 had a tweak.
1190 -falign-functions=N with N > 8 was adding secondary alignment.
1191 -falign-functions=10 was emitting this before every function:
1192 .p2align 4,,9
1193 .p2align 3
1194 Now this behavior (and more) can be explicitly requested:
1195 -falign-functions=16:10:8
1196 Retain old behavior if N2 is missing: */
1198 int align = 1 << a.levels[0].log;
1199 int subalign = 1 << SUBALIGN_LOG;
1201 if (a.levels[0].log > SUBALIGN_LOG
1202 && a.levels[0].maxskip >= subalign - 1)
1204 /* Set N2 unless subalign can never have any effect. */
1205 if (align > a.levels[0].maxskip + 1)
1207 a.levels[1].log = SUBALIGN_LOG;
1208 a.levels[1].normalize ();
1212 #endif
1214 /* Cache seen value. */
1215 cache.put (flag, a);
1219 /* Process -falign-foo=N[:M[:N2[:M2]]] options. */
1221 void
1222 parse_alignment_opts (void)
1224 parse_N_M (str_align_loops, align_loops);
1225 parse_N_M (str_align_jumps, align_jumps);
1226 parse_N_M (str_align_labels, align_labels);
1227 parse_N_M (str_align_functions, align_functions);
1230 /* Process the options that have been parsed. */
1231 static void
1232 process_options (void)
1234 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1235 This can happen with incorrect pre-processed input. */
1236 debug_hooks = &do_nothing_debug_hooks;
1238 maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT;
1240 /* Allow the front end to perform consistency checks and do further
1241 initialization based on the command line options. This hook also
1242 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1243 so we can correctly initialize debug output. */
1244 no_backend = lang_hooks.post_options (&main_input_filename);
1246 /* Some machines may reject certain combinations of options. */
1247 location_t saved_location = input_location;
1248 input_location = UNKNOWN_LOCATION;
1249 targetm.target_option.override ();
1250 input_location = saved_location;
1252 if (flag_diagnostics_generate_patch)
1253 global_dc->edit_context_ptr = new edit_context ();
1255 /* Avoid any informative notes in the second run of -fcompare-debug. */
1256 if (flag_compare_debug)
1257 diagnostic_inhibit_notes (global_dc);
1259 if (flag_section_anchors && !target_supports_section_anchors_p ())
1261 warning_at (UNKNOWN_LOCATION, OPT_fsection_anchors,
1262 "this target does not support %qs",
1263 "-fsection-anchors");
1264 flag_section_anchors = 0;
1267 if (flag_short_enums == 2)
1268 flag_short_enums = targetm.default_short_enums ();
1270 /* Set aux_base_name if not already set. */
1271 if (aux_base_name)
1273 else if (dump_base_name)
1275 const char *name = dump_base_name;
1276 int nlen, len;
1278 if (dump_base_ext && (len = strlen (dump_base_ext))
1279 && (nlen = strlen (name)) && nlen > len
1280 && strcmp (name + nlen - len, dump_base_ext) == 0)
1282 char *p = xstrndup (name, nlen - len);
1283 name = p;
1286 aux_base_name = name;
1288 else
1289 aux_base_name = "gccaux";
1291 #ifndef HAVE_isl
1292 if (flag_graphite
1293 || flag_loop_nest_optimize
1294 || flag_graphite_identity
1295 || flag_loop_parallelize_all)
1296 sorry ("Graphite loop optimizations cannot be used (isl is not available) "
1297 "(%<-fgraphite%>, %<-fgraphite-identity%>, "
1298 "%<-floop-nest-optimize%>, %<-floop-parallelize-all%>)");
1299 #endif
1301 if (flag_cf_protection != CF_NONE
1302 && !(flag_cf_protection & CF_SET))
1304 if (flag_cf_protection == CF_FULL)
1306 error_at (UNKNOWN_LOCATION,
1307 "%<-fcf-protection=full%> is not supported for this "
1308 "target");
1309 flag_cf_protection = CF_NONE;
1311 if (flag_cf_protection == CF_BRANCH)
1313 error_at (UNKNOWN_LOCATION,
1314 "%<-fcf-protection=branch%> is not supported for this "
1315 "target");
1316 flag_cf_protection = CF_NONE;
1318 if (flag_cf_protection == CF_RETURN)
1320 error_at (UNKNOWN_LOCATION,
1321 "%<-fcf-protection=return%> is not supported for this "
1322 "target");
1323 flag_cf_protection = CF_NONE;
1327 /* One region RA really helps to decrease the code size. */
1328 if (flag_ira_region == IRA_REGION_AUTODETECT)
1329 flag_ira_region
1330 = optimize_size || !optimize ? IRA_REGION_ONE : IRA_REGION_MIXED;
1332 if (!abi_version_at_least (2))
1334 /* -fabi-version=1 support was removed after GCC 4.9. */
1335 error_at (UNKNOWN_LOCATION,
1336 "%<-fabi-version=1%> is no longer supported");
1337 flag_abi_version = 2;
1340 /* web and rename-registers help when run after loop unrolling. */
1341 if (flag_web == AUTODETECT_VALUE)
1342 flag_web = flag_unroll_loops;
1344 if (flag_rename_registers == AUTODETECT_VALUE)
1345 flag_rename_registers = flag_unroll_loops;
1347 if (flag_non_call_exceptions)
1348 flag_asynchronous_unwind_tables = 1;
1349 if (flag_asynchronous_unwind_tables)
1350 flag_unwind_tables = 1;
1352 if (flag_value_profile_transformations)
1353 flag_profile_values = 1;
1355 /* Warn about options that are not supported on this machine. */
1356 #ifndef INSN_SCHEDULING
1357 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1358 warning_at (UNKNOWN_LOCATION, 0,
1359 "instruction scheduling not supported on this target machine");
1360 #endif
1361 if (!DELAY_SLOTS && flag_delayed_branch)
1362 warning_at (UNKNOWN_LOCATION, 0,
1363 "this target machine does not have delayed branches");
1365 user_label_prefix = USER_LABEL_PREFIX;
1366 if (flag_leading_underscore != -1)
1368 /* If the default prefix is more complicated than "" or "_",
1369 issue a warning and ignore this option. */
1370 if (user_label_prefix[0] == 0 ||
1371 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1373 user_label_prefix = flag_leading_underscore ? "_" : "";
1375 else
1376 warning_at (UNKNOWN_LOCATION, 0,
1377 "%<-f%sleading-underscore%> not supported on this "
1378 "target machine", flag_leading_underscore ? "" : "no-");
1381 /* If we are in verbose mode, write out the version and maybe all the
1382 option flags in use. */
1383 if (version_flag)
1385 print_version (stderr, "", true);
1386 if (!quiet_flag)
1388 fputs ("options passed: ", stderr);
1389 char *cmdline = gen_command_line_string (save_decoded_options,
1390 save_decoded_options_count);
1392 fputs (cmdline, stderr);
1393 free (cmdline);
1394 fputc ('\n', stderr);
1398 if (flag_syntax_only)
1400 write_symbols = NO_DEBUG;
1401 profile_flag = 0;
1404 if (flag_gtoggle)
1406 if (debug_info_level == DINFO_LEVEL_NONE)
1408 debug_info_level = DINFO_LEVEL_NORMAL;
1410 if (write_symbols == NO_DEBUG)
1411 write_symbols = PREFERRED_DEBUGGING_TYPE;
1413 else
1414 debug_info_level = DINFO_LEVEL_NONE;
1417 if (flag_dump_final_insns && !flag_syntax_only && !no_backend)
1419 FILE *final_output = fopen (flag_dump_final_insns, "w");
1420 if (!final_output)
1422 error_at (UNKNOWN_LOCATION,
1423 "could not open final insn dump file %qs: %m",
1424 flag_dump_final_insns);
1425 flag_dump_final_insns = NULL;
1427 else if (fclose (final_output))
1429 error_at (UNKNOWN_LOCATION,
1430 "could not close zeroed insn dump file %qs: %m",
1431 flag_dump_final_insns);
1432 flag_dump_final_insns = NULL;
1436 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1437 level is 0. */
1438 if (debug_info_level == DINFO_LEVEL_NONE)
1439 write_symbols = NO_DEBUG;
1441 if (write_symbols == NO_DEBUG)
1443 #if defined(DBX_DEBUGGING_INFO)
1444 else if (write_symbols == DBX_DEBUG)
1445 debug_hooks = &dbx_debug_hooks;
1446 #endif
1447 #if defined(XCOFF_DEBUGGING_INFO)
1448 else if (write_symbols == XCOFF_DEBUG)
1449 debug_hooks = &xcoff_debug_hooks;
1450 #endif
1451 #ifdef DWARF2_DEBUGGING_INFO
1452 else if (write_symbols == DWARF2_DEBUG)
1453 debug_hooks = &dwarf2_debug_hooks;
1454 #endif
1455 #ifdef VMS_DEBUGGING_INFO
1456 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1457 debug_hooks = &vmsdbg_debug_hooks;
1458 #endif
1459 #ifdef DWARF2_LINENO_DEBUGGING_INFO
1460 else if (write_symbols == DWARF2_DEBUG)
1461 debug_hooks = &dwarf2_lineno_debug_hooks;
1462 #endif
1463 else
1465 gcc_assert (debug_set_count (write_symbols) <= 1);
1466 error_at (UNKNOWN_LOCATION,
1467 "target system does not support the %qs debug format",
1468 debug_type_names[debug_set_to_format (write_symbols)]);
1471 /* We know which debug output will be used so we can set flag_var_tracking
1472 and flag_var_tracking_uninit if the user has not specified them. */
1473 if (debug_info_level < DINFO_LEVEL_NORMAL
1474 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1476 if (flag_var_tracking == 1
1477 || flag_var_tracking_uninit == 1)
1479 if (debug_info_level < DINFO_LEVEL_NORMAL)
1480 warning_at (UNKNOWN_LOCATION, 0,
1481 "variable tracking requested, but useless unless "
1482 "producing debug info");
1483 else
1484 warning_at (UNKNOWN_LOCATION, 0,
1485 "variable tracking requested, but not supported "
1486 "by this debug format");
1488 flag_var_tracking = 0;
1489 flag_var_tracking_uninit = 0;
1492 /* The debug hooks are used to implement -fdump-go-spec because it
1493 gives a simple and stable API for all the information we need to
1494 dump. */
1495 if (flag_dump_go_spec != NULL)
1496 debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks);
1498 /* If the user specifically requested variable tracking with tagging
1499 uninitialized variables, we need to turn on variable tracking.
1500 (We already determined above that variable tracking is feasible.) */
1501 if (flag_var_tracking_uninit == 1)
1502 flag_var_tracking = 1;
1504 if (flag_var_tracking == AUTODETECT_VALUE)
1505 flag_var_tracking = optimize >= 1;
1507 if (flag_var_tracking_uninit == AUTODETECT_VALUE)
1508 flag_var_tracking_uninit = flag_var_tracking;
1510 if (flag_var_tracking_assignments == AUTODETECT_VALUE)
1511 flag_var_tracking_assignments
1512 = (flag_var_tracking
1513 && !(flag_selective_scheduling || flag_selective_scheduling2));
1515 if (flag_var_tracking_assignments_toggle)
1516 flag_var_tracking_assignments = !flag_var_tracking_assignments;
1518 if (flag_var_tracking_assignments && !flag_var_tracking)
1519 flag_var_tracking = flag_var_tracking_assignments = -1;
1521 if (flag_var_tracking_assignments
1522 && (flag_selective_scheduling || flag_selective_scheduling2))
1523 warning_at (UNKNOWN_LOCATION, 0,
1524 "var-tracking-assignments changes selective scheduling");
1526 if (debug_nonbind_markers_p == AUTODETECT_VALUE)
1527 debug_nonbind_markers_p
1528 = (optimize
1529 && debug_info_level >= DINFO_LEVEL_NORMAL
1530 && dwarf_debuginfo_p ()
1531 && !(flag_selective_scheduling || flag_selective_scheduling2));
1533 if (dwarf2out_as_loc_support == AUTODETECT_VALUE)
1534 dwarf2out_as_loc_support
1535 = dwarf2out_default_as_loc_support ();
1536 if (dwarf2out_as_locview_support == AUTODETECT_VALUE)
1537 dwarf2out_as_locview_support
1538 = dwarf2out_default_as_locview_support ();
1540 if (debug_variable_location_views == AUTODETECT_VALUE)
1542 debug_variable_location_views
1543 = (flag_var_tracking
1544 && debug_info_level >= DINFO_LEVEL_NORMAL
1545 && dwarf_debuginfo_p ()
1546 && !dwarf_strict
1547 && dwarf2out_as_loc_support
1548 && dwarf2out_as_locview_support);
1550 else if (debug_variable_location_views == -1 && dwarf_version != 5)
1552 warning_at (UNKNOWN_LOCATION, 0,
1553 "without %<-gdwarf-5%>, "
1554 "%<-gvariable-location-views=incompat5%> "
1555 "is equivalent to %<-gvariable-location-views%>");
1556 debug_variable_location_views = 1;
1559 if (debug_internal_reset_location_views == 2)
1561 debug_internal_reset_location_views
1562 = (debug_variable_location_views
1563 && targetm.reset_location_view);
1565 else if (debug_internal_reset_location_views
1566 && !debug_variable_location_views)
1568 warning_at (UNKNOWN_LOCATION, 0,
1569 "%<-ginternal-reset-location-views%> is forced disabled "
1570 "without %<-gvariable-location-views%>");
1571 debug_internal_reset_location_views = 0;
1574 if (debug_inline_points == AUTODETECT_VALUE)
1575 debug_inline_points = debug_variable_location_views;
1576 else if (debug_inline_points && !debug_nonbind_markers_p)
1578 warning_at (UNKNOWN_LOCATION, 0,
1579 "%<-ginline-points%> is forced disabled without "
1580 "%<-gstatement-frontiers%>");
1581 debug_inline_points = 0;
1584 if (flag_tree_cselim == AUTODETECT_VALUE)
1586 if (HAVE_conditional_move)
1587 flag_tree_cselim = 1;
1588 else
1589 flag_tree_cselim = 0;
1592 /* If auxiliary info generation is desired, open the output file.
1593 This goes in the same directory as the source file--unlike
1594 all the other output files. */
1595 if (flag_gen_aux_info)
1597 aux_info_file = fopen (aux_info_file_name, "w");
1598 if (aux_info_file == 0)
1599 fatal_error (UNKNOWN_LOCATION,
1600 "cannot open %s: %m", aux_info_file_name);
1603 if (!targetm_common.have_named_sections)
1605 if (flag_function_sections)
1607 warning_at (UNKNOWN_LOCATION, 0,
1608 "%<-ffunction-sections%> not supported for this target");
1609 flag_function_sections = 0;
1611 if (flag_data_sections)
1613 warning_at (UNKNOWN_LOCATION, 0,
1614 "%<-fdata-sections%> not supported for this target");
1615 flag_data_sections = 0;
1619 if (flag_prefetch_loop_arrays > 0 && !targetm.code_for_prefetch)
1621 warning_at (UNKNOWN_LOCATION, 0,
1622 "%<-fprefetch-loop-arrays%> not supported for this target");
1623 flag_prefetch_loop_arrays = 0;
1625 else if (flag_prefetch_loop_arrays > 0 && !targetm.have_prefetch ())
1627 warning_at (UNKNOWN_LOCATION, 0,
1628 "%<-fprefetch-loop-arrays%> not supported for this target "
1629 "(try %<-march%> switches)");
1630 flag_prefetch_loop_arrays = 0;
1633 /* This combination of options isn't handled for i386 targets and doesn't
1634 make much sense anyway, so don't allow it. */
1635 if (flag_prefetch_loop_arrays > 0 && optimize_size)
1637 warning_at (UNKNOWN_LOCATION, 0,
1638 "%<-fprefetch-loop-arrays%> is not supported with %<-Os%>");
1639 flag_prefetch_loop_arrays = 0;
1642 /* The presence of IEEE signaling NaNs, implies all math can trap. */
1643 if (flag_signaling_nans)
1644 flag_trapping_math = 1;
1646 /* We cannot reassociate if we want traps or signed zeros. */
1647 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
1649 warning_at (UNKNOWN_LOCATION, 0,
1650 "%<-fassociative-math%> disabled; other options take "
1651 "precedence");
1652 flag_associative_math = 0;
1655 /* -fstack-clash-protection is not currently supported on targets
1656 where the stack grows up. */
1657 if (flag_stack_clash_protection && !STACK_GROWS_DOWNWARD)
1659 warning_at (UNKNOWN_LOCATION, 0,
1660 "%<-fstack-clash-protection%> is not supported on targets "
1661 "where the stack grows from lower to higher addresses");
1662 flag_stack_clash_protection = 0;
1665 /* We cannot support -fstack-check= and -fstack-clash-protection at
1666 the same time. */
1667 if (flag_stack_check != NO_STACK_CHECK && flag_stack_clash_protection)
1669 warning_at (UNKNOWN_LOCATION, 0,
1670 "%<-fstack-check=%> and %<-fstack-clash_protection%> are "
1671 "mutually exclusive; disabling %<-fstack-check=%>");
1672 flag_stack_check = NO_STACK_CHECK;
1675 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
1676 if (flag_cx_limited_range)
1677 flag_complex_method = 0;
1679 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
1680 if (flag_cx_fortran_rules)
1681 flag_complex_method = 1;
1683 /* Targets must be able to place spill slots at lower addresses. If the
1684 target already uses a soft frame pointer, the transition is trivial. */
1685 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
1687 warning_at (UNKNOWN_LOCATION, 0,
1688 "%<-fstack-protector%> not supported for this target");
1689 flag_stack_protect = 0;
1691 if (!flag_stack_protect)
1692 warn_stack_protect = 0;
1694 /* Address Sanitizer needs porting to each target architecture. */
1696 if ((flag_sanitize & SANITIZE_ADDRESS)
1697 && !FRAME_GROWS_DOWNWARD)
1699 warning_at (UNKNOWN_LOCATION, 0,
1700 "%<-fsanitize=address%> and %<-fsanitize=kernel-address%> "
1701 "are not supported for this target");
1702 flag_sanitize &= ~SANITIZE_ADDRESS;
1705 if ((flag_sanitize & SANITIZE_USER_ADDRESS)
1706 && ((targetm.asan_shadow_offset == NULL)
1707 || (targetm.asan_shadow_offset () == 0)))
1709 warning_at (UNKNOWN_LOCATION, 0,
1710 "%<-fsanitize=address%> not supported for this target");
1711 flag_sanitize &= ~SANITIZE_ADDRESS;
1714 if ((flag_sanitize & SANITIZE_KERNEL_ADDRESS)
1715 && (targetm.asan_shadow_offset == NULL
1716 && !asan_shadow_offset_set_p ()))
1718 warning_at (UNKNOWN_LOCATION, 0,
1719 "%<-fsanitize=kernel-address%> with stack protection "
1720 "is not supported without %<-fasan-shadow-offset=%> "
1721 "for this target");
1722 flag_sanitize &= ~SANITIZE_ADDRESS;
1725 /* HWAsan requires top byte ignore feature in the backend. */
1726 if (flag_sanitize & SANITIZE_HWADDRESS
1727 && ! targetm.memtag.can_tag_addresses ())
1729 warning_at (UNKNOWN_LOCATION, 0, "%qs is not supported for this target",
1730 "-fsanitize=hwaddress");
1731 flag_sanitize &= ~SANITIZE_HWADDRESS;
1734 HOST_WIDE_INT patch_area_size, patch_area_start;
1735 parse_and_check_patch_area (flag_patchable_function_entry, false,
1736 &patch_area_size, &patch_area_start);
1738 /* Do not use IPA optimizations for register allocation if profiler is active
1739 or patchable function entries are inserted for run-time instrumentation
1740 or port does not emit prologue and epilogue as RTL. */
1741 if (profile_flag || patch_area_size
1742 || !targetm.have_prologue () || !targetm.have_epilogue ())
1743 flag_ipa_ra = 0;
1745 /* Enable -Werror=coverage-mismatch when -Werror and -Wno-error
1746 have not been set. */
1747 if (!global_options_set.x_warnings_are_errors
1748 && warn_coverage_mismatch
1749 && (global_dc->classify_diagnostic[OPT_Wcoverage_mismatch] ==
1750 DK_UNSPECIFIED))
1751 diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch,
1752 DK_ERROR, UNKNOWN_LOCATION);
1754 /* Save the current optimization options. */
1755 optimization_default_node
1756 = build_optimization_node (&global_options, &global_options_set);
1757 optimization_current_node = optimization_default_node;
1759 if (flag_checking >= 2)
1760 hash_table_sanitize_eq_limit
1761 = param_hash_table_verification_limit;
1763 if (flag_large_source_files)
1764 line_table->default_range_bits = 0;
1766 /* Please don't change global_options after this point, those changes won't
1767 be reflected in optimization_{default,current}_node. */
1770 /* This function can be called multiple times to reinitialize the compiler
1771 back end when register classes or instruction sets have changed,
1772 before each function. */
1773 static void
1774 backend_init_target (void)
1776 /* This depends on stack_pointer_rtx. */
1777 init_fake_stack_mems ();
1779 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
1780 mode-dependent. */
1781 init_alias_target ();
1783 /* Depends on HARD_FRAME_POINTER_REGNUM. */
1784 if (!ira_use_lra_p)
1785 init_reload ();
1787 /* Depends on the enabled attribute. */
1788 recog_init ();
1790 /* The following initialization functions need to generate rtl, so
1791 provide a dummy function context for them. */
1792 init_dummy_function_start ();
1794 /* rtx_cost is mode-dependent, so cached values need to be recomputed
1795 on a mode change. */
1796 init_expmed ();
1797 init_lower_subreg ();
1798 init_set_costs ();
1800 init_expr_target ();
1801 ira_init ();
1803 /* We may need to recompute regno_save_code[] and regno_restore_code[]
1804 after a mode change as well. */
1805 caller_save_initialized_p = false;
1807 expand_dummy_function_end ();
1810 /* Initialize the compiler back end. This function is called only once,
1811 when starting the compiler. */
1812 static void
1813 backend_init (void)
1815 init_emit_once ();
1817 init_rtlanal ();
1818 init_inline_once ();
1819 init_varasm_once ();
1820 save_register_info ();
1822 /* Middle end needs this initialization for default mem attributes
1823 used by early calls to make_decl_rtl. */
1824 init_emit_regs ();
1826 /* Middle end needs this initialization for mode tables used to assign
1827 modes to vector variables. */
1828 init_regs ();
1831 /* Initialize things that are both lang-dependent and target-dependent.
1832 This function can be called more than once if target parameters change. */
1833 static void
1834 lang_dependent_init_target (void)
1836 /* This creates various _DECL nodes, so needs to be called after the
1837 front end is initialized. It also depends on the HAVE_xxx macros
1838 generated from the target machine description. */
1839 init_optabs ();
1841 gcc_assert (!this_target_rtl->target_specific_initialized);
1844 /* Perform initializations that are lang-dependent or target-dependent.
1845 but matters only for late optimizations and RTL generation. */
1847 static int rtl_initialized;
1849 void
1850 initialize_rtl (void)
1852 auto_timevar tv (g_timer, TV_INITIALIZE_RTL);
1854 /* Initialization done just once per compilation, but delayed
1855 till code generation. */
1856 if (!rtl_initialized)
1857 ira_init_once ();
1858 rtl_initialized = true;
1860 /* Target specific RTL backend initialization. */
1861 if (!this_target_rtl->target_specific_initialized)
1863 backend_init_target ();
1864 this_target_rtl->target_specific_initialized = true;
1868 /* Language-dependent initialization. Returns nonzero on success. */
1869 static int
1870 lang_dependent_init (const char *name)
1872 location_t save_loc = input_location;
1873 if (!dump_base_name)
1875 dump_base_name = name && name[0] ? name : "gccdump";
1877 /* We do not want to derive a non-empty dumpbase-ext from an
1878 explicit -dumpbase argument, only from a defaulted
1879 dumpbase. */
1880 if (!dump_base_ext)
1882 const char *base = lbasename (dump_base_name);
1883 const char *ext = strrchr (base, '.');
1884 if (ext)
1885 dump_base_ext = ext;
1889 /* Other front-end initialization. */
1890 input_location = BUILTINS_LOCATION;
1891 if (lang_hooks.init () == 0)
1892 return 0;
1893 input_location = save_loc;
1895 if (!flag_wpa)
1897 init_asm_output (name);
1899 if (!flag_generate_lto && !flag_compare_debug)
1901 /* If stack usage information is desired, open the output file. */
1902 if (flag_stack_usage)
1903 stack_usage_file = open_auxiliary_file ("su");
1905 /* If call graph information is desired, open the output file. */
1906 if (flag_callgraph_info)
1908 callgraph_info_file = open_auxiliary_file ("ci");
1909 /* Write the file header. */
1910 fprintf (callgraph_info_file,
1911 "graph: { title: \"%s\"\n", main_input_filename);
1912 bitmap_obstack_initialize (NULL);
1913 callgraph_info_external_printed = BITMAP_ALLOC (NULL);
1916 else
1917 flag_stack_usage = flag_callgraph_info = false;
1920 /* This creates various _DECL nodes, so needs to be called after the
1921 front end is initialized. */
1922 init_eh ();
1924 /* Do the target-specific parts of the initialization. */
1925 lang_dependent_init_target ();
1927 if (!flag_wpa)
1929 /* If dbx symbol table desired, initialize writing it and output the
1930 predefined types. */
1931 timevar_push (TV_SYMOUT);
1933 /* Now we have the correct original filename, we can initialize
1934 debug output. */
1935 (*debug_hooks->init) (name);
1937 timevar_pop (TV_SYMOUT);
1940 return 1;
1944 /* Reinitialize everything when target parameters, such as register usage,
1945 have changed. */
1946 void
1947 target_reinit (void)
1949 struct rtl_data saved_x_rtl;
1950 rtx *saved_regno_reg_rtx;
1951 tree saved_optimization_current_node;
1952 struct target_optabs *saved_this_fn_optabs;
1954 /* Temporarily switch to the default optimization node, so that
1955 *this_target_optabs is set to the default, not reflecting
1956 whatever a previous function used for the optimize
1957 attribute. */
1958 saved_optimization_current_node = optimization_current_node;
1959 saved_this_fn_optabs = this_fn_optabs;
1960 if (saved_optimization_current_node != optimization_default_node)
1962 optimization_current_node = optimization_default_node;
1963 cl_optimization_restore
1964 (&global_options, &global_options_set,
1965 TREE_OPTIMIZATION (optimization_default_node));
1967 this_fn_optabs = this_target_optabs;
1969 /* Save *crtl and regno_reg_rtx around the reinitialization
1970 to allow target_reinit being called even after prepare_function_start. */
1971 saved_regno_reg_rtx = regno_reg_rtx;
1972 if (saved_regno_reg_rtx)
1974 saved_x_rtl = *crtl;
1975 memset (crtl, '\0', sizeof (*crtl));
1976 regno_reg_rtx = NULL;
1979 this_target_rtl->target_specific_initialized = false;
1981 /* This initializes hard_frame_pointer, and calls init_reg_modes_target()
1982 to initialize reg_raw_mode[]. */
1983 init_emit_regs ();
1985 /* This invokes target hooks to set fixed_reg[] etc, which is
1986 mode-dependent. */
1987 init_regs ();
1989 /* Reinitialize lang-dependent parts. */
1990 lang_dependent_init_target ();
1992 /* Restore the original optimization node. */
1993 if (saved_optimization_current_node != optimization_default_node)
1995 optimization_current_node = saved_optimization_current_node;
1996 cl_optimization_restore (&global_options, &global_options_set,
1997 TREE_OPTIMIZATION (optimization_current_node));
1999 this_fn_optabs = saved_this_fn_optabs;
2001 /* Restore regno_reg_rtx at the end, as free_after_compilation from
2002 expand_dummy_function_end clears it. */
2003 if (saved_regno_reg_rtx)
2005 *crtl = saved_x_rtl;
2006 regno_reg_rtx = saved_regno_reg_rtx;
2007 saved_regno_reg_rtx = NULL;
2011 void
2012 dump_memory_report (const char *header)
2014 /* Print significant header. */
2015 fputc ('\n', stderr);
2016 for (unsigned i = 0; i < 80; i++)
2017 fputc ('#', stderr);
2018 fprintf (stderr, "\n# %-77s#\n", header);
2019 for (unsigned i = 0; i < 80; i++)
2020 fputc ('#', stderr);
2021 fputs ("\n\n", stderr);
2023 dump_line_table_statistics ();
2024 ggc_print_statistics ();
2025 stringpool_statistics ();
2026 dump_tree_statistics ();
2027 dump_gimple_statistics ();
2028 dump_rtx_statistics ();
2029 dump_alloc_pool_statistics ();
2030 dump_bitmap_statistics ();
2031 dump_hash_table_loc_statistics ();
2032 dump_vec_loc_statistics ();
2033 dump_ggc_loc_statistics ();
2034 dump_alias_stats (stderr);
2035 dump_pta_stats (stderr);
2038 /* Clean up: close opened files, etc. */
2040 static void
2041 finalize (bool no_backend)
2043 /* Close the dump files. */
2044 if (flag_gen_aux_info)
2046 fclose (aux_info_file);
2047 aux_info_file = NULL;
2048 if (seen_error ())
2049 unlink (aux_info_file_name);
2052 /* Close non-debugging input and output files. Take special care to note
2053 whether fclose returns an error, since the pages might still be on the
2054 buffer chain while the file is open. */
2056 if (asm_out_file)
2058 if (ferror (asm_out_file) != 0)
2059 fatal_error (input_location, "error writing to %s: %m", asm_file_name);
2060 if (fclose (asm_out_file) != 0)
2061 fatal_error (input_location, "error closing %s: %m", asm_file_name);
2062 asm_out_file = NULL;
2065 if (stack_usage_file)
2067 fclose (stack_usage_file);
2068 stack_usage_file = NULL;
2071 if (callgraph_info_file)
2073 fputs ("}\n", callgraph_info_file);
2074 fclose (callgraph_info_file);
2075 callgraph_info_file = NULL;
2076 BITMAP_FREE (callgraph_info_external_printed);
2077 bitmap_obstack_release (NULL);
2080 if (seen_error ())
2081 coverage_remove_note_file ();
2083 if (!no_backend)
2085 statistics_fini ();
2086 debuginfo_fini ();
2088 g->get_passes ()->finish_optimization_passes ();
2090 lra_finish_once ();
2093 if (mem_report)
2094 dump_memory_report ("Final");
2096 if (profile_report)
2097 dump_profile_report ();
2099 if (flag_dbg_cnt_list)
2100 dbg_cnt_list_all_counters ();
2102 /* Language-specific end of compilation actions. */
2103 lang_hooks.finish ();
2106 static bool
2107 standard_type_bitsize (int bitsize)
2109 /* As a special exception, we always want __int128 enabled if possible. */
2110 if (bitsize == 128)
2111 return false;
2112 if (bitsize == CHAR_TYPE_SIZE
2113 || bitsize == SHORT_TYPE_SIZE
2114 || bitsize == INT_TYPE_SIZE
2115 || bitsize == LONG_TYPE_SIZE
2116 || bitsize == LONG_LONG_TYPE_SIZE)
2117 return true;
2118 return false;
2121 /* Initialize the compiler, and compile the input file. */
2122 static void
2123 do_compile ()
2125 process_options ();
2127 /* Don't do any more if an error has already occurred. */
2128 if (!seen_error ())
2130 int i;
2132 timevar_start (TV_PHASE_SETUP);
2134 if (flag_save_optimization_record)
2136 dump_context::get ().set_json_writer (new optrecord_json_writer ());
2139 /* This must be run always, because it is needed to compute the FP
2140 predefined macros, such as __LDBL_MAX__, for targets using non
2141 default FP formats. */
2142 init_adjust_machine_modes ();
2143 init_derived_machine_modes ();
2145 /* This must happen after the backend has a chance to process
2146 command line options, but before the parsers are
2147 initialized. */
2148 for (i = 0; i < NUM_INT_N_ENTS; i ++)
2149 if (targetm.scalar_mode_supported_p (int_n_data[i].m)
2150 && ! standard_type_bitsize (int_n_data[i].bitsize))
2151 int_n_enabled_p[i] = true;
2152 else
2153 int_n_enabled_p[i] = false;
2155 /* Initialize mpfrs exponent range. This is important to get
2156 underflow/overflow in a reasonable timeframe. */
2157 machine_mode mode;
2158 int min_exp = -1;
2159 int max_exp = 1;
2160 FOR_EACH_MODE_IN_CLASS (mode, MODE_FLOAT)
2161 if (SCALAR_FLOAT_MODE_P (mode))
2163 const real_format *fmt = REAL_MODE_FORMAT (mode);
2164 if (fmt)
2166 /* fmt->emin - fmt->p + 1 should be enough but the
2167 back-and-forth dance in real_to_decimal_for_mode we
2168 do for checking fails due to rounding effects then. */
2169 if ((fmt->emin - fmt->p) < min_exp)
2170 min_exp = fmt->emin - fmt->p;
2171 if (fmt->emax > max_exp)
2172 max_exp = fmt->emax;
2175 /* E.g. mpc_norm assumes it can square a number without bothering with
2176 with range scaling, so until that is fixed, double the minimum
2177 and maximum exponents, plus add some buffer for arithmetics
2178 on the squared numbers. */
2179 if (mpfr_set_emin (2 * (min_exp - 1))
2180 || mpfr_set_emax (2 * (max_exp + 1)))
2181 sorry ("mpfr not configured to handle all floating modes");
2183 /* Set up the back-end if requested. */
2184 if (!no_backend)
2185 backend_init ();
2187 /* Language-dependent initialization. Returns true on success. */
2188 if (lang_dependent_init (main_input_filename))
2190 /* Initialize yet another pass. */
2192 ggc_protect_identifiers = true;
2194 symtab->initialize ();
2195 init_final (main_input_filename);
2196 coverage_init (aux_base_name);
2197 statistics_init ();
2198 debuginfo_init ();
2199 invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
2201 timevar_stop (TV_PHASE_SETUP);
2203 compile_file ();
2205 else
2207 timevar_stop (TV_PHASE_SETUP);
2210 timevar_start (TV_PHASE_FINALIZE);
2212 finalize (no_backend);
2214 timevar_stop (TV_PHASE_FINALIZE);
2218 toplev::toplev (timer *external_timer,
2219 bool init_signals)
2220 : m_use_TV_TOTAL (external_timer == NULL),
2221 m_init_signals (init_signals)
2223 if (external_timer)
2224 g_timer = external_timer;
2227 toplev::~toplev ()
2229 if (g_timer && m_use_TV_TOTAL)
2231 g_timer->stop (TV_TOTAL);
2232 g_timer->print (stderr);
2233 delete g_timer;
2234 g_timer = NULL;
2238 /* Potentially call timevar_init (which will create g_timevars if it
2239 doesn't already exist). */
2241 void
2242 toplev::start_timevars ()
2244 if (time_report || !quiet_flag || flag_detailed_statistics)
2245 timevar_init ();
2247 timevar_start (TV_TOTAL);
2250 /* Handle -fself-test. */
2252 void
2253 toplev::run_self_tests ()
2255 if (no_backend)
2257 error_at (UNKNOWN_LOCATION, "self-tests incompatible with %<-E%>");
2258 return;
2260 #if CHECKING_P
2261 /* Reset some state. */
2262 input_location = UNKNOWN_LOCATION;
2263 bitmap_obstack_initialize (NULL);
2265 /* Run the tests; any failures will lead to an abort of the process.
2266 Use "make selftests-gdb" to run under the debugger. */
2267 ::selftest::run_tests ();
2269 /* Cleanup. */
2270 bitmap_obstack_release (NULL);
2271 #else
2272 inform (UNKNOWN_LOCATION, "self-tests are not enabled in this build");
2273 #endif /* #if CHECKING_P */
2276 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2277 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2278 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2280 It is not safe to call this function more than once. */
2283 toplev::main (int argc, char **argv)
2285 /* Parsing and gimplification sometimes need quite large stack.
2286 Increase stack size limits if possible. */
2287 stack_limit_increase (64 * 1024 * 1024);
2289 expandargv (&argc, &argv);
2291 /* Initialization of GCC's environment, and diagnostics. */
2292 general_init (argv[0], m_init_signals);
2294 /* One-off initialization of options that does not need to be
2295 repeated when options are added for particular functions. */
2296 init_options_once ();
2297 init_opts_obstack ();
2299 /* Initialize global options structures; this must be repeated for
2300 each structure used for parsing options. */
2301 init_options_struct (&global_options, &global_options_set);
2302 lang_hooks.init_options_struct (&global_options);
2304 /* Init GGC heuristics must be caller after we initialize
2305 options. */
2306 init_ggc_heuristics ();
2308 /* Convert the options to an array. */
2309 decode_cmdline_options_to_array_default_mask (argc,
2310 CONST_CAST2 (const char **,
2311 char **, argv),
2312 &save_decoded_options,
2313 &save_decoded_options_count);
2315 /* Perform language-specific options initialization. */
2316 lang_hooks.init_options (save_decoded_options_count, save_decoded_options);
2318 /* Parse the options and do minimal processing; basically just
2319 enough to default flags appropriately. */
2320 decode_options (&global_options, &global_options_set,
2321 save_decoded_options, save_decoded_options_count,
2322 UNKNOWN_LOCATION, global_dc,
2323 targetm.target_option.override);
2325 handle_common_deferred_options ();
2327 init_local_tick ();
2329 initialize_plugins ();
2331 if (version_flag)
2332 print_version (stderr, "", true);
2334 if (help_flag)
2335 print_plugins_help (stderr, "");
2337 /* Exit early if we can (e.g. -help). */
2338 if (!exit_after_options)
2340 if (m_use_TV_TOTAL)
2341 start_timevars ();
2342 do_compile ();
2345 if (warningcount || errorcount || werrorcount)
2346 print_ignored_options ();
2348 if (flag_self_test)
2349 run_self_tests ();
2351 /* Invoke registered plugin callbacks if any. Some plugins could
2352 emit some diagnostics here. */
2353 invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
2355 if (flag_diagnostics_generate_patch)
2357 gcc_assert (global_dc->edit_context_ptr);
2359 pretty_printer pp;
2360 pp_show_color (&pp) = pp_show_color (global_dc->printer);
2361 global_dc->edit_context_ptr->print_diff (&pp, true);
2362 pp_flush (&pp);
2365 diagnostic_finish (global_dc);
2367 finalize_plugins ();
2369 after_memory_report = true;
2371 if (seen_error () || werrorcount)
2372 return (FATAL_EXIT_CODE);
2374 return (SUCCESS_EXIT_CODE);
2377 /* For those that want to, this function aims to clean up enough state that
2378 you can call toplev::main again. */
2379 void
2380 toplev::finalize (void)
2382 rtl_initialized = false;
2383 this_target_rtl->target_specific_initialized = false;
2385 /* Needs to be called before cgraph_c_finalize since it uses symtab. */
2386 ipa_reference_c_finalize ();
2387 ipa_fnsummary_c_finalize ();
2388 ipa_modref_c_finalize ();
2390 cgraph_c_finalize ();
2391 cgraphunit_c_finalize ();
2392 symtab_thunks_cc_finalize ();
2393 dwarf2out_c_finalize ();
2394 gcse_c_finalize ();
2395 ipa_cp_c_finalize ();
2396 ira_costs_c_finalize ();
2398 /* save_decoded_options uses opts_obstack, so these must
2399 be cleaned up together. */
2400 obstack_free (&opts_obstack, NULL);
2401 XDELETEVEC (save_decoded_options);
2402 save_decoded_options = NULL;
2403 save_decoded_options_count = 0;
2405 /* Clean up the context (and pass_manager etc). */
2406 delete g;
2407 g = NULL;