gcov: make profile merging smarter
[official-gcc.git] / gcc / toplev.c
blob81546b19e91017510b5b86073169f18b09ee4c08
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 "ipa-param-manipulation.h"
90 #include "dbgcnt.h"
92 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
93 #include "dbxout.h"
94 #endif
96 #ifdef XCOFF_DEBUGGING_INFO
97 #include "xcoffout.h" /* Needed for external data declarations. */
98 #endif
100 #include "selftest.h"
102 #ifdef HAVE_isl
103 #include <isl/version.h>
104 #endif
106 static void general_init (const char *, bool);
107 static void backend_init (void);
108 static int lang_dependent_init (const char *);
109 static void init_asm_output (const char *);
110 static void finalize (bool);
112 static void crash_signal (int) ATTRIBUTE_NORETURN;
113 static void compile_file (void);
115 /* Decoded options, and number of such options. */
116 struct cl_decoded_option *save_decoded_options;
117 unsigned int save_decoded_options_count;
119 /* Vector of saved Optimization decoded command line options. */
120 vec<cl_decoded_option> *save_opt_decoded_options;
122 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
123 to optimize in process_options (). */
124 #define AUTODETECT_VALUE 2
126 /* Debug hooks - dependent upon command line options. */
128 const struct gcc_debug_hooks *debug_hooks;
130 /* The FUNCTION_DECL for the function currently being compiled,
131 or 0 if between functions. */
132 tree current_function_decl;
134 /* Set to the FUNC_BEGIN label of the current function, or NULL
135 if none. */
136 const char * current_function_func_begin_label;
138 /* A random sequence of characters, unless overridden by user. */
139 static const char *flag_random_seed;
141 /* A local time stamp derived from the time of compilation. It will be
142 zero if the system cannot provide a time. It will be -1u, if the
143 user has specified a particular random seed. */
144 unsigned local_tick;
146 /* Random number for this compilation */
147 HOST_WIDE_INT random_seed;
149 /* -f flags. */
151 /* When non-NULL, indicates that whenever space is allocated on the
152 stack, the resulting stack pointer must not pass this
153 address---that is, for stacks that grow downward, the stack pointer
154 must always be greater than or equal to this address; for stacks
155 that grow upward, the stack pointer must be less than this address.
156 At present, the rtx may be either a REG or a SYMBOL_REF, although
157 the support provided depends on the backend. */
158 rtx stack_limit_rtx;
160 class target_flag_state default_target_flag_state;
161 #if SWITCHABLE_TARGET
162 class target_flag_state *this_target_flag_state = &default_target_flag_state;
163 #else
164 #define this_target_flag_state (&default_target_flag_state)
165 #endif
167 /* The user symbol prefix after having resolved same. */
168 const char *user_label_prefix;
170 /* Output files for assembler code (real compiler output)
171 and debugging dumps. */
173 FILE *asm_out_file;
174 FILE *aux_info_file;
175 FILE *callgraph_info_file = NULL;
176 static bitmap callgraph_info_external_printed;
177 FILE *stack_usage_file = NULL;
179 /* The current working directory of a translation. It's generally the
180 directory from which compilation was initiated, but a preprocessed
181 file may specify the original directory in which it was
182 created. */
184 static const char *src_pwd;
186 /* Initialize src_pwd with the given string, and return true. If it
187 was already initialized, return false. As a special case, it may
188 be called with a NULL argument to test whether src_pwd has NOT been
189 initialized yet. */
191 bool
192 set_src_pwd (const char *pwd)
194 if (src_pwd)
196 if (strcmp (src_pwd, pwd) == 0)
197 return true;
198 else
199 return false;
202 src_pwd = xstrdup (pwd);
203 return true;
206 /* Return the directory from which the translation unit was initiated,
207 in case set_src_pwd() was not called before to assign it a
208 different value. */
210 const char *
211 get_src_pwd (void)
213 if (! src_pwd)
215 src_pwd = getpwd ();
216 if (!src_pwd)
217 src_pwd = ".";
220 return src_pwd;
223 /* Called when the start of a function definition is parsed,
224 this function prints on stderr the name of the function. */
225 void
226 announce_function (tree decl)
228 if (!quiet_flag)
230 if (rtl_dump_and_exit)
231 fprintf (stderr, "%s ",
232 identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))));
233 else
234 fprintf (stderr, " %s",
235 identifier_to_locale (lang_hooks.decl_printable_name (decl, 2)));
236 fflush (stderr);
237 pp_needs_newline (global_dc->printer) = true;
238 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
242 /* Initialize local_tick with the time of day, or -1 if
243 flag_random_seed is set. */
245 static void
246 init_local_tick (void)
248 if (!flag_random_seed)
250 #ifdef HAVE_GETTIMEOFDAY
252 struct timeval tv;
254 gettimeofday (&tv, NULL);
255 local_tick = (unsigned) tv.tv_sec * 1000 + tv.tv_usec / 1000;
257 #else
259 time_t now = time (NULL);
261 if (now != (time_t)-1)
262 local_tick = (unsigned) now;
264 #endif
266 else
267 local_tick = -1;
270 /* Obtain the random_seed. Unless NOINIT, initialize it if
271 it's not provided in the command line. */
273 HOST_WIDE_INT
274 get_random_seed (bool noinit)
276 if (!random_seed && !noinit)
278 int fd = open ("/dev/urandom", O_RDONLY);
279 if (fd >= 0)
281 if (read (fd, &random_seed, sizeof (random_seed))
282 != sizeof (random_seed))
283 random_seed = 0;
284 close (fd);
286 if (!random_seed)
287 random_seed = local_tick ^ getpid ();
289 return random_seed;
292 /* Set flag_random_seed to VAL, and if non-null, reinitialize random_seed. */
294 void
295 set_random_seed (const char *val)
297 flag_random_seed = val;
298 if (flag_random_seed)
300 char *endp;
302 /* When the driver passed in a hex number don't crc it again */
303 random_seed = strtoul (flag_random_seed, &endp, 0);
304 if (!(endp > flag_random_seed && *endp == 0))
305 random_seed = crc32_string (0, flag_random_seed);
309 /* Handler for fatal signals, such as SIGSEGV. These are transformed
310 into ICE messages, which is much more user friendly. In case the
311 error printer crashes, reset the signal to prevent infinite recursion. */
313 static void
314 crash_signal (int signo)
316 signal (signo, SIG_DFL);
318 /* If we crashed while processing an ASM statement, then be a little more
319 graceful. It's most likely the user's fault. */
320 if (this_is_asm_operands)
322 output_operand_lossage ("unrecoverable error");
323 exit (FATAL_EXIT_CODE);
326 internal_error ("%s", strsignal (signo));
329 /* A subroutine of wrapup_global_declarations. We've come to the end of
330 the compilation unit. All deferred variables should be undeferred,
331 and all incomplete decls should be finalized. */
333 void
334 wrapup_global_declaration_1 (tree decl)
336 /* We're not deferring this any longer. Assignment is conditional to
337 avoid needlessly dirtying PCH pages. */
338 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
339 && DECL_DEFER_OUTPUT (decl) != 0)
340 DECL_DEFER_OUTPUT (decl) = 0;
342 if (VAR_P (decl) && DECL_SIZE (decl) == 0)
343 lang_hooks.finish_incomplete_decl (decl);
346 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
347 needs to be output. Return true if it is output. */
349 bool
350 wrapup_global_declaration_2 (tree decl)
352 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl)
353 || (VAR_P (decl) && DECL_HAS_VALUE_EXPR_P (decl)))
354 return false;
356 /* Don't write out static consts, unless we still need them.
358 We also keep static consts if not optimizing (for debugging),
359 unless the user specified -fno-keep-static-consts.
360 ??? They might be better written into the debug information.
361 This is possible when using DWARF.
363 A language processor that wants static constants to be always
364 written out (even if it is not used) is responsible for
365 calling rest_of_decl_compilation itself. E.g. the C front-end
366 calls rest_of_decl_compilation from finish_decl.
367 One motivation for this is that is conventional in some
368 environments to write things like:
369 static const char rcsid[] = "... version string ...";
370 intending to force the string to be in the executable.
372 A language processor that would prefer to have unneeded
373 static constants "optimized away" would just defer writing
374 them out until here. E.g. C++ does this, because static
375 constants are often defined in header files.
377 ??? A tempting alternative (for both C and C++) would be
378 to force a constant to be written if and only if it is
379 defined in a main file, as opposed to an include file. */
381 if (VAR_P (decl) && TREE_STATIC (decl))
383 varpool_node *node;
384 bool needed = true;
385 node = varpool_node::get (decl);
387 if (!node && flag_ltrans)
388 needed = false;
389 else if (node && node->definition)
390 needed = false;
391 else if (node && node->alias)
392 needed = false;
393 else if (!symtab->global_info_ready
394 && (TREE_USED (decl)
395 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
396 /* needed */;
397 else if (node && node->analyzed)
398 /* needed */;
399 else if (DECL_COMDAT (decl))
400 needed = false;
401 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
402 && (optimize || !flag_keep_static_consts
403 || DECL_ARTIFICIAL (decl)))
404 needed = false;
406 if (needed)
408 rest_of_decl_compilation (decl, 1, 1);
409 return true;
413 return false;
416 /* Do any final processing required for the declarations in VEC, of
417 which there are LEN. We write out inline functions and variables
418 that have been deferred until this point, but which are required.
419 Returns nonzero if anything was put out. */
421 bool
422 wrapup_global_declarations (tree *vec, int len)
424 bool reconsider, output_something = false;
425 int i;
427 for (i = 0; i < len; i++)
428 wrapup_global_declaration_1 (vec[i]);
430 /* Now emit any global variables or functions that we have been
431 putting off. We need to loop in case one of the things emitted
432 here references another one which comes earlier in the list. */
435 reconsider = false;
436 for (i = 0; i < len; i++)
437 reconsider |= wrapup_global_declaration_2 (vec[i]);
438 if (reconsider)
439 output_something = true;
441 while (reconsider);
443 return output_something;
446 /* Compile an entire translation unit. Write a file of assembly
447 output and various debugging dumps. */
449 static void
450 compile_file (void)
452 timevar_start (TV_PHASE_PARSING);
453 timevar_push (TV_PARSE_GLOBAL);
455 /* Parse entire file and generate initial debug information. */
456 lang_hooks.parse_file ();
458 timevar_pop (TV_PARSE_GLOBAL);
459 timevar_stop (TV_PHASE_PARSING);
461 if (flag_dump_locations)
462 dump_location_info (stderr);
464 /* Compilation is now finished except for writing
465 what's left of the symbol table output. */
467 if (flag_syntax_only || flag_wpa)
468 return;
470 /* Reset maximum_field_alignment, it can be adjusted by #pragma pack
471 and this shouldn't influence any types built by the middle-end
472 from now on (like gcov_info_type). */
473 maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT;
475 ggc_protect_identifiers = false;
477 /* Run the actual compilation process. */
478 if (!in_lto_p)
480 timevar_start (TV_PHASE_OPT_GEN);
481 symtab->finalize_compilation_unit ();
482 timevar_stop (TV_PHASE_OPT_GEN);
485 /* Perform any post compilation-proper parser cleanups and
486 processing. This is currently only needed for the C++ parser,
487 which can be hopefully cleaned up so this hook is no longer
488 necessary. */
489 if (lang_hooks.decls.post_compilation_parsing_cleanups)
490 lang_hooks.decls.post_compilation_parsing_cleanups ();
492 dump_context::get ().finish_any_json_writer ();
494 if (seen_error ())
495 return;
497 timevar_start (TV_PHASE_LATE_ASM);
499 /* Compilation unit is finalized. When producing non-fat LTO object, we are
500 basically finished. */
501 if ((in_lto_p && flag_incremental_link != INCREMENTAL_LINK_LTO)
502 || !flag_lto || flag_fat_lto_objects)
504 /* File-scope initialization for AddressSanitizer. */
505 if (flag_sanitize & SANITIZE_ADDRESS)
506 asan_finish_file ();
508 if (flag_sanitize & SANITIZE_THREAD)
509 tsan_finish_file ();
511 if (gate_hwasan ())
512 hwasan_finish_file ();
514 omp_finish_file ();
516 output_shared_constant_pool ();
517 output_object_blocks ();
518 finish_tm_clone_pairs ();
520 /* Write out any pending weak symbol declarations. */
521 weak_finish ();
523 /* This must be at the end before unwind and debug info.
524 Some target ports emit PIC setup thunks here. */
525 insn_locations_init ();
526 targetm.asm_out.code_end ();
528 /* Do dbx symbols. */
529 timevar_push (TV_SYMOUT);
531 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
532 dwarf2out_frame_finish ();
533 #endif
535 debuginfo_start ();
536 (*debug_hooks->finish) (main_input_filename);
537 debuginfo_stop ();
538 timevar_pop (TV_SYMOUT);
540 /* Output some stuff at end of file if nec. */
542 dw2_output_indirect_constants ();
544 /* Flush any pending external directives. */
545 process_pending_assemble_externals ();
548 /* Let linker plugin know that this is a slim object and must be LTOed
549 even when user did not ask for it. */
550 if (flag_generate_lto && !flag_fat_lto_objects)
552 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
553 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE, "__gnu_lto_slim",
554 HOST_WIDE_INT_1U, 8);
555 #elif defined ASM_OUTPUT_ALIGNED_COMMON
556 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_slim",
557 HOST_WIDE_INT_1U, 8);
558 #else
559 ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_slim",
560 HOST_WIDE_INT_1U,
561 HOST_WIDE_INT_1U);
562 #endif
565 /* Attach a special .ident directive to the end of the file to identify
566 the version of GCC which compiled this code. The format of the .ident
567 string is patterned after the ones produced by native SVR4 compilers. */
568 if (!flag_no_ident)
570 const char *pkg_version = "(GNU) ";
571 char *ident_str;
573 if (strcmp ("(GCC) ", pkgversion_string))
574 pkg_version = pkgversion_string;
576 ident_str = ACONCAT (("GCC: ", pkg_version, version_string, NULL));
577 targetm.asm_out.output_ident (ident_str);
580 /* Auto profile finalization. */
581 if (flag_auto_profile)
582 end_auto_profile ();
584 /* Invoke registered plugin callbacks. */
585 invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
587 /* This must be at the end. Some target ports emit end of file directives
588 into the assembly file here, and hence we cannot output anything to the
589 assembly file after this point. */
590 targetm.asm_out.file_end ();
592 timevar_stop (TV_PHASE_LATE_ASM);
595 /* Print version information to FILE.
596 Each line begins with INDENT (for the case where FILE is the
597 assembler output file).
599 If SHOW_GLOBAL_STATE is true (for cc1 etc), we are within the compiler
600 proper and can print pertinent state (e.g. params and plugins).
602 If SHOW_GLOBAL_STATE is false (for use by libgccjit), we are outside the
603 compiler, and we don't hold the mutex on the compiler's global state:
604 we can't print params and plugins, since they might not be initialized,
605 or might be being manipulated by a compile running in another
606 thread. */
608 void
609 print_version (FILE *file, const char *indent, bool show_global_state)
611 static const char fmt1[] =
612 #ifdef __GNUC__
613 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
614 #else
615 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
616 #endif
618 static const char fmt2[] =
619 N_("GMP version %s, MPFR version %s, MPC version %s, isl version %s\n");
620 static const char fmt3[] =
621 N_("%s%swarning: %s header version %s differs from library version %s.\n");
622 static const char fmt4[] =
623 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
624 #ifndef __VERSION__
625 #define __VERSION__ "[?]"
626 #endif
627 fprintf (file,
628 file == stderr ? _(fmt1) : fmt1,
629 indent, *indent != 0 ? " " : "",
630 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
631 indent, __VERSION__);
633 /* We need to stringify the GMP macro values. Ugh, gmp_version has
634 two string formats, "i.j.k" and "i.j" when k is zero. As of
635 gmp-4.3.0, GMP always uses the 3 number format. */
636 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
637 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3 (X)
638 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
639 #define GCC_GMP_VERSION \
640 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
641 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
642 #define GCC_GMP_STRINGIFY_VERSION \
643 GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION) "." \
644 GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION_MINOR)
645 #else
646 #define GCC_GMP_STRINGIFY_VERSION \
647 GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION) "." \
648 GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION_MINOR) "." \
649 GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION_PATCHLEVEL)
650 #endif
651 fprintf (file,
652 file == stderr ? _(fmt2) : fmt2,
653 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING, MPC_VERSION_STRING,
654 #ifndef HAVE_isl
655 "none"
656 #else
657 isl_version ()
658 #endif
660 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
661 fprintf (file,
662 file == stderr ? _(fmt3) : fmt3,
663 indent, *indent != 0 ? " " : "",
664 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
665 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
666 fprintf (file,
667 file == stderr ? _(fmt3) : fmt3,
668 indent, *indent != 0 ? " " : "",
669 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
670 if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
671 fprintf (file,
672 file == stderr ? _(fmt3) : fmt3,
673 indent, *indent != 0 ? " " : "",
674 "MPC", MPC_VERSION_STRING, mpc_get_version ());
676 if (show_global_state)
678 fprintf (file,
679 file == stderr ? _(fmt4) : fmt4,
680 indent, *indent != 0 ? " " : "",
681 param_ggc_min_expand, param_ggc_min_heapsize);
683 print_plugins_versions (file, indent);
689 /* Open assembly code output file. Do this even if -fsyntax-only is
690 on, because then the driver will have provided the name of a
691 temporary file or bit bucket for us. NAME is the file specified on
692 the command line, possibly NULL. */
693 static void
694 init_asm_output (const char *name)
696 if (name == NULL && asm_file_name == 0)
697 asm_out_file = stdout;
698 else
700 if (asm_file_name == 0)
702 int len = strlen (dump_base_name);
703 char *dumpname = XNEWVEC (char, len + 6);
705 memcpy (dumpname, dump_base_name, len + 1);
706 strip_off_ending (dumpname, len);
707 strcat (dumpname, ".s");
708 asm_file_name = dumpname;
710 if (!strcmp (asm_file_name, "-"))
711 asm_out_file = stdout;
712 else if (!canonical_filename_eq (asm_file_name, name)
713 || !strcmp (asm_file_name, HOST_BIT_BUCKET))
714 asm_out_file = fopen (asm_file_name, "w");
715 else
716 /* Use UNKOWN_LOCATION to prevent gcc from printing the first
717 line in the current file. */
718 fatal_error (UNKNOWN_LOCATION,
719 "input file %qs is the same as output file",
720 asm_file_name);
721 if (asm_out_file == 0)
722 fatal_error (UNKNOWN_LOCATION,
723 "cannot open %qs for writing: %m", asm_file_name);
726 if (!flag_syntax_only)
728 targetm.asm_out.file_start ();
730 if (flag_record_gcc_switches)
732 if (targetm.asm_out.record_gcc_switches)
734 const char *str
735 = gen_producer_string (lang_hooks.name,
736 save_decoded_options,
737 save_decoded_options_count);
738 targetm.asm_out.record_gcc_switches (str);
740 else
741 inform (UNKNOWN_LOCATION,
742 "%<-frecord-gcc-switches%> is not supported by "
743 "the current target");
746 if (flag_verbose_asm)
748 print_version (asm_out_file, ASM_COMMENT_START, true);
749 fputs (ASM_COMMENT_START, asm_out_file);
750 fputs (" options passed: ", asm_out_file);
751 char *cmdline = gen_command_line_string (save_decoded_options,
752 save_decoded_options_count);
753 fputs (cmdline, asm_out_file);
754 free (cmdline);
755 fputc ('\n', asm_out_file);
760 /* A helper function; used as the reallocator function for cpp's line
761 table. */
762 static void *
763 realloc_for_line_map (void *ptr, size_t len)
765 return ggc_realloc (ptr, len);
768 /* A helper function: used as the allocator function for
769 identifier_to_locale. */
770 static void *
771 alloc_for_identifier_to_locale (size_t len)
773 return ggc_alloc_atomic (len);
776 /* Output stack usage information. */
777 static void
778 output_stack_usage_1 (FILE *cf)
780 static bool warning_issued = false;
781 enum stack_usage_kind_type { STATIC = 0, DYNAMIC, DYNAMIC_BOUNDED };
782 const char *stack_usage_kind_str[] = {
783 "static",
784 "dynamic",
785 "dynamic,bounded"
787 HOST_WIDE_INT stack_usage = current_function_static_stack_size;
788 enum stack_usage_kind_type stack_usage_kind;
790 if (stack_usage < 0)
792 if (!warning_issued)
794 warning (0, "stack usage computation not supported for this target");
795 warning_issued = true;
797 return;
800 stack_usage_kind = STATIC;
802 /* Add the maximum amount of space pushed onto the stack. */
803 if (maybe_ne (current_function_pushed_stack_size, 0))
805 HOST_WIDE_INT extra;
806 if (current_function_pushed_stack_size.is_constant (&extra))
808 stack_usage += extra;
809 stack_usage_kind = DYNAMIC_BOUNDED;
811 else
813 extra = constant_lower_bound (current_function_pushed_stack_size);
814 stack_usage += extra;
815 stack_usage_kind = DYNAMIC;
819 /* Now on to the tricky part: dynamic stack allocation. */
820 if (current_function_allocates_dynamic_stack_space)
822 if (stack_usage_kind != DYNAMIC)
824 if (current_function_has_unbounded_dynamic_stack_size)
825 stack_usage_kind = DYNAMIC;
826 else
827 stack_usage_kind = DYNAMIC_BOUNDED;
830 /* Add the size even in the unbounded case, this can't hurt. */
831 stack_usage += current_function_dynamic_stack_size;
834 if (cf && flag_callgraph_info & CALLGRAPH_INFO_STACK_USAGE)
835 fprintf (cf, "\\n" HOST_WIDE_INT_PRINT_DEC " bytes (%s)",
836 stack_usage,
837 stack_usage_kind_str[stack_usage_kind]);
839 if (stack_usage_file)
841 print_decl_identifier (stack_usage_file, current_function_decl,
842 PRINT_DECL_ORIGIN | PRINT_DECL_NAME);
843 fprintf (stack_usage_file, "\t" HOST_WIDE_INT_PRINT_DEC"\t%s\n",
844 stack_usage, stack_usage_kind_str[stack_usage_kind]);
847 if (warn_stack_usage >= 0 && warn_stack_usage < HOST_WIDE_INT_MAX)
849 const location_t loc = DECL_SOURCE_LOCATION (current_function_decl);
851 if (stack_usage_kind == DYNAMIC)
852 warning_at (loc, OPT_Wstack_usage_, "stack usage might be unbounded");
853 else if (stack_usage > warn_stack_usage)
855 if (stack_usage_kind == DYNAMIC_BOUNDED)
856 warning_at (loc,
857 OPT_Wstack_usage_, "stack usage might be %wu bytes",
858 stack_usage);
859 else
860 warning_at (loc, OPT_Wstack_usage_, "stack usage is %wu bytes",
861 stack_usage);
866 /* Dump placeholder node for indirect calls in VCG format. */
868 #define INDIRECT_CALL_NAME "__indirect_call"
870 static void
871 dump_final_node_vcg_start (FILE *f, tree decl)
873 fputs ("node: { title: \"", f);
874 if (decl)
875 print_decl_identifier (f, decl, PRINT_DECL_UNIQUE_NAME);
876 else
877 fputs (INDIRECT_CALL_NAME, f);
878 fputs ("\" label: \"", f);
879 if (decl)
881 print_decl_identifier (f, decl, PRINT_DECL_NAME);
882 fputs ("\\n", f);
883 print_decl_identifier (f, decl, PRINT_DECL_ORIGIN);
885 else
886 fputs ("Indirect Call Placeholder", f);
889 /* Dump final cgraph edge in VCG format. */
891 static void
892 dump_final_callee_vcg (FILE *f, location_t location, tree callee)
894 if ((!callee || DECL_EXTERNAL (callee))
895 && bitmap_set_bit (callgraph_info_external_printed,
896 callee ? DECL_UID (callee) + 1 : 0))
898 dump_final_node_vcg_start (f, callee);
899 fputs ("\" shape : ellipse }\n", f);
902 fputs ("edge: { sourcename: \"", f);
903 print_decl_identifier (f, current_function_decl, PRINT_DECL_UNIQUE_NAME);
904 fputs ("\" targetname: \"", f);
905 if (callee)
906 print_decl_identifier (f, callee, PRINT_DECL_UNIQUE_NAME);
907 else
908 fputs (INDIRECT_CALL_NAME, f);
909 if (LOCATION_LOCUS (location) != UNKNOWN_LOCATION)
911 expanded_location loc;
912 fputs ("\" label: \"", f);
913 loc = expand_location (location);
914 fprintf (f, "%s:%d:%d", loc.file, loc.line, loc.column);
916 fputs ("\" }\n", f);
919 /* Dump final cgraph node in VCG format. */
921 static void
922 dump_final_node_vcg (FILE *f)
924 dump_final_node_vcg_start (f, current_function_decl);
926 if (flag_stack_usage_info
927 || (flag_callgraph_info & CALLGRAPH_INFO_STACK_USAGE))
928 output_stack_usage_1 (f);
930 if (flag_callgraph_info & CALLGRAPH_INFO_DYNAMIC_ALLOC)
932 fprintf (f, "\\n%u dynamic objects", vec_safe_length (cfun->su->dallocs));
934 unsigned i;
935 callinfo_dalloc *cda;
936 FOR_EACH_VEC_SAFE_ELT (cfun->su->dallocs, i, cda)
938 expanded_location loc = expand_location (cda->location);
939 fprintf (f, "\\n %s", cda->name);
940 fprintf (f, " %s:%d:%d", loc.file, loc.line, loc.column);
943 vec_free (cfun->su->dallocs);
944 cfun->su->dallocs = NULL;
947 fputs ("\" }\n", f);
949 unsigned i;
950 callinfo_callee *c;
951 FOR_EACH_VEC_SAFE_ELT (cfun->su->callees, i, c)
952 dump_final_callee_vcg (f, c->location, c->decl);
953 vec_free (cfun->su->callees);
954 cfun->su->callees = NULL;
957 /* Output stack usage and callgraph info, as requested. */
958 void
959 output_stack_usage (void)
961 if (flag_callgraph_info)
962 dump_final_node_vcg (callgraph_info_file);
963 else
964 output_stack_usage_1 (NULL);
967 /* Open an auxiliary output file. */
968 static FILE *
969 open_auxiliary_file (const char *ext)
971 char *filename;
972 FILE *file;
974 filename = concat (aux_base_name, ".", ext, NULL);
975 file = fopen (filename, "w");
976 if (!file)
977 fatal_error (input_location, "cannot open %s for writing: %m", filename);
978 free (filename);
979 return file;
982 /* Alternative diagnostics callback for reentered ICE reporting. */
984 static void
985 internal_error_reentered (diagnostic_context *, const char *, va_list *)
987 /* Flush the dump file if emergency_dump_function itself caused an ICE. */
988 if (dump_file)
989 fflush (dump_file);
992 /* Auxiliary callback for the diagnostics code. */
994 static void
995 internal_error_function (diagnostic_context *, const char *, va_list *)
997 global_dc->internal_error = internal_error_reentered;
998 warn_if_plugins ();
999 emergency_dump_function ();
1002 /* Initialization of the front end environment, before command line
1003 options are parsed. Signal handlers, internationalization etc.
1004 ARGV0 is main's argv[0]. */
1005 static void
1006 general_init (const char *argv0, bool init_signals)
1008 const char *p;
1010 p = argv0 + strlen (argv0);
1011 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1012 --p;
1013 progname = p;
1015 xmalloc_set_program_name (progname);
1017 hex_init ();
1019 /* Unlock the stdio streams. */
1020 unlock_std_streams ();
1022 gcc_init_libintl ();
1024 identifier_to_locale_alloc = alloc_for_identifier_to_locale;
1025 identifier_to_locale_free = ggc_free;
1027 /* Initialize the diagnostics reporting machinery, so option parsing
1028 can give warnings and errors. */
1029 diagnostic_initialize (global_dc, N_OPTS);
1030 global_dc->lang_mask = lang_hooks.option_lang_mask ();
1031 /* Set a default printer. Language specific initializations will
1032 override it later. */
1033 tree_diagnostics_defaults (global_dc);
1035 global_dc->show_caret
1036 = global_options_init.x_flag_diagnostics_show_caret;
1037 global_dc->show_labels_p
1038 = global_options_init.x_flag_diagnostics_show_labels;
1039 global_dc->show_line_numbers_p
1040 = global_options_init.x_flag_diagnostics_show_line_numbers;
1041 global_dc->show_cwe
1042 = global_options_init.x_flag_diagnostics_show_cwe;
1043 global_dc->path_format
1044 = (enum diagnostic_path_format)global_options_init.x_flag_diagnostics_path_format;
1045 global_dc->show_path_depths
1046 = global_options_init.x_flag_diagnostics_show_path_depths;
1047 global_dc->show_option_requested
1048 = global_options_init.x_flag_diagnostics_show_option;
1049 global_dc->min_margin_width
1050 = global_options_init.x_diagnostics_minimum_margin_width;
1051 global_dc->show_column
1052 = global_options_init.x_flag_show_column;
1053 global_dc->internal_error = internal_error_function;
1054 global_dc->option_enabled = option_enabled;
1055 global_dc->option_state = &global_options;
1056 global_dc->option_name = option_name;
1057 global_dc->get_option_url = get_option_url;
1059 if (init_signals)
1061 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1062 #ifdef SIGSEGV
1063 signal (SIGSEGV, crash_signal);
1064 #endif
1065 #ifdef SIGILL
1066 signal (SIGILL, crash_signal);
1067 #endif
1068 #ifdef SIGBUS
1069 signal (SIGBUS, crash_signal);
1070 #endif
1071 #ifdef SIGABRT
1072 signal (SIGABRT, crash_signal);
1073 #endif
1074 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1075 signal (SIGIOT, crash_signal);
1076 #endif
1077 #ifdef SIGFPE
1078 signal (SIGFPE, crash_signal);
1079 #endif
1081 /* Other host-specific signal setup. */
1082 (*host_hooks.extra_signals)();
1085 /* Initialize the garbage-collector, string pools and tree type hash
1086 table. */
1087 init_ggc ();
1088 init_stringpool ();
1089 input_location = UNKNOWN_LOCATION;
1090 line_table = ggc_alloc<line_maps> ();
1091 linemap_init (line_table, BUILTINS_LOCATION);
1092 line_table->reallocator = realloc_for_line_map;
1093 line_table->round_alloc_size = ggc_round_alloc_size;
1094 line_table->default_range_bits = 5;
1095 init_ttree ();
1097 /* Initialize register usage now so switches may override. */
1098 init_reg_sets ();
1100 /* Create the singleton holder for global state. This creates the
1101 dump manager. */
1102 g = new gcc::context ();
1104 /* Allow languages and middle-end to register their dumps before the
1105 optimization passes. */
1106 g->get_dumps ()->register_dumps ();
1108 /* Create the passes. */
1109 g->set_passes (new gcc::pass_manager (g));
1111 symtab = new (ggc_alloc <symbol_table> ()) symbol_table ();
1113 statistics_early_init ();
1114 debuginfo_early_init ();
1117 /* Return true if the current target supports -fsection-anchors. */
1119 static bool
1120 target_supports_section_anchors_p (void)
1122 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1123 return false;
1125 if (targetm.asm_out.output_anchor == NULL)
1126 return false;
1128 return true;
1131 /* Parse "N[:M][:...]" into struct align_flags A.
1132 VALUES contains parsed values (in reverse order), all processed
1133 values are popped. */
1135 static void
1136 read_log_maxskip (auto_vec<unsigned> &values, align_flags_tuple *a)
1138 unsigned n = values.pop ();
1139 if (n != 0)
1140 a->log = floor_log2 (n * 2 - 1);
1142 if (values.is_empty ())
1143 a->maxskip = n ? n - 1 : 0;
1144 else
1146 unsigned m = values.pop ();
1147 /* -falign-foo=N:M means M-1 max bytes of padding, not M. */
1148 if (m > 0)
1149 m--;
1150 a->maxskip = m;
1153 /* Normalize the tuple. */
1154 a->normalize ();
1157 /* Parse "N[:M[:N2[:M2]]]" string FLAG into a pair of struct align_flags. */
1159 static void
1160 parse_N_M (const char *flag, align_flags &a)
1162 if (flag)
1164 static hash_map <nofree_string_hash, align_flags> cache;
1165 align_flags *entry = cache.get (flag);
1166 if (entry)
1168 a = *entry;
1169 return;
1172 auto_vec<unsigned> result_values;
1173 bool r = parse_and_check_align_values (flag, NULL, result_values, false,
1174 UNKNOWN_LOCATION);
1175 if (!r)
1176 return;
1178 /* Reverse values for easier manipulation. */
1179 result_values.reverse ();
1181 read_log_maxskip (result_values, &a.levels[0]);
1182 if (!result_values.is_empty ())
1183 read_log_maxskip (result_values, &a.levels[1]);
1184 #ifdef SUBALIGN_LOG
1185 else
1187 /* N2[:M2] is not specified. This arch has a default for N2.
1188 Before -falign-foo=N:M:N2:M2 was introduced, x86 had a tweak.
1189 -falign-functions=N with N > 8 was adding secondary alignment.
1190 -falign-functions=10 was emitting this before every function:
1191 .p2align 4,,9
1192 .p2align 3
1193 Now this behavior (and more) can be explicitly requested:
1194 -falign-functions=16:10:8
1195 Retain old behavior if N2 is missing: */
1197 int align = 1 << a.levels[0].log;
1198 int subalign = 1 << SUBALIGN_LOG;
1200 if (a.levels[0].log > SUBALIGN_LOG
1201 && a.levels[0].maxskip >= subalign - 1)
1203 /* Set N2 unless subalign can never have any effect. */
1204 if (align > a.levels[0].maxskip + 1)
1206 a.levels[1].log = SUBALIGN_LOG;
1207 a.levels[1].normalize ();
1211 #endif
1213 /* Cache seen value. */
1214 cache.put (flag, a);
1218 /* Process -falign-foo=N[:M[:N2[:M2]]] options. */
1220 void
1221 parse_alignment_opts (void)
1223 parse_N_M (str_align_loops, align_loops);
1224 parse_N_M (str_align_jumps, align_jumps);
1225 parse_N_M (str_align_labels, align_labels);
1226 parse_N_M (str_align_functions, align_functions);
1229 /* Process the options that have been parsed. */
1230 static void
1231 process_options (bool no_backend)
1233 const char *language_string = lang_hooks.name;
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 /* Some machines may reject certain combinations of options. */
1241 location_t saved_location = input_location;
1242 input_location = UNKNOWN_LOCATION;
1243 targetm.target_option.override ();
1244 input_location = saved_location;
1246 if (flag_diagnostics_generate_patch)
1247 global_dc->edit_context_ptr = new edit_context ();
1249 /* Avoid any informative notes in the second run of -fcompare-debug. */
1250 if (flag_compare_debug)
1251 diagnostic_inhibit_notes (global_dc);
1253 if (flag_section_anchors && !target_supports_section_anchors_p ())
1255 warning_at (UNKNOWN_LOCATION, OPT_fsection_anchors,
1256 "this target does not support %qs",
1257 "-fsection-anchors");
1258 flag_section_anchors = 0;
1261 if (flag_short_enums == 2)
1262 flag_short_enums = targetm.default_short_enums ();
1264 /* Set aux_base_name if not already set. */
1265 if (aux_base_name)
1267 else if (dump_base_name)
1269 const char *name = dump_base_name;
1270 int nlen, len;
1272 if (dump_base_ext && (len = strlen (dump_base_ext))
1273 && (nlen = strlen (name)) && nlen > len
1274 && strcmp (name + nlen - len, dump_base_ext) == 0)
1276 char *p = xstrndup (name, nlen - len);
1277 name = p;
1280 aux_base_name = name;
1282 else
1283 aux_base_name = "gccaux";
1285 #ifndef HAVE_isl
1286 if (flag_graphite
1287 || flag_loop_nest_optimize
1288 || flag_graphite_identity
1289 || flag_loop_parallelize_all)
1290 sorry ("Graphite loop optimizations cannot be used (isl is not available) "
1291 "(%<-fgraphite%>, %<-fgraphite-identity%>, "
1292 "%<-floop-nest-optimize%>, %<-floop-parallelize-all%>)");
1293 #endif
1295 if (flag_cf_protection != CF_NONE
1296 && !(flag_cf_protection & CF_SET))
1298 if (flag_cf_protection == CF_FULL)
1300 error_at (UNKNOWN_LOCATION,
1301 "%<-fcf-protection=full%> is not supported for this "
1302 "target");
1303 flag_cf_protection = CF_NONE;
1305 if (flag_cf_protection == CF_BRANCH)
1307 error_at (UNKNOWN_LOCATION,
1308 "%<-fcf-protection=branch%> is not supported for this "
1309 "target");
1310 flag_cf_protection = CF_NONE;
1312 if (flag_cf_protection == CF_RETURN)
1314 error_at (UNKNOWN_LOCATION,
1315 "%<-fcf-protection=return%> is not supported for this "
1316 "target");
1317 flag_cf_protection = CF_NONE;
1321 /* One region RA really helps to decrease the code size. */
1322 if (!OPTION_SET_P (flag_ira_region))
1323 flag_ira_region
1324 = optimize_size || !optimize ? IRA_REGION_ONE : IRA_REGION_MIXED;
1326 if (!abi_version_at_least (2))
1328 /* -fabi-version=1 support was removed after GCC 4.9. */
1329 error_at (UNKNOWN_LOCATION,
1330 "%<-fabi-version=1%> is no longer supported");
1331 flag_abi_version = 2;
1334 if (flag_non_call_exceptions)
1335 flag_asynchronous_unwind_tables = 1;
1336 if (flag_asynchronous_unwind_tables)
1337 flag_unwind_tables = 1;
1339 if (flag_value_profile_transformations)
1340 flag_profile_values = 1;
1342 /* Warn about options that are not supported on this machine. */
1343 #ifndef INSN_SCHEDULING
1344 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1345 warning_at (UNKNOWN_LOCATION, 0,
1346 "instruction scheduling not supported on this target machine");
1347 #endif
1348 if (!DELAY_SLOTS && flag_delayed_branch)
1349 warning_at (UNKNOWN_LOCATION, 0,
1350 "this target machine does not have delayed branches");
1352 user_label_prefix = USER_LABEL_PREFIX;
1353 if (flag_leading_underscore != -1)
1355 /* If the default prefix is more complicated than "" or "_",
1356 issue a warning and ignore this option. */
1357 if (user_label_prefix[0] == 0 ||
1358 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1360 user_label_prefix = flag_leading_underscore ? "_" : "";
1362 else
1363 warning_at (UNKNOWN_LOCATION, 0,
1364 "%<-f%sleading-underscore%> not supported on this "
1365 "target machine", flag_leading_underscore ? "" : "no-");
1368 /* If we are in verbose mode, write out the version and maybe all the
1369 option flags in use. */
1370 if (version_flag)
1372 print_version (stderr, "", true);
1373 if (!quiet_flag)
1375 fputs ("options passed: ", stderr);
1376 char *cmdline = gen_command_line_string (save_decoded_options,
1377 save_decoded_options_count);
1379 fputs (cmdline, stderr);
1380 free (cmdline);
1381 fputc ('\n', stderr);
1385 if (flag_syntax_only)
1387 write_symbols = NO_DEBUG;
1388 profile_flag = 0;
1391 if (flag_gtoggle)
1393 if (debug_info_level == DINFO_LEVEL_NONE)
1395 debug_info_level = DINFO_LEVEL_NORMAL;
1397 if (write_symbols == NO_DEBUG)
1398 write_symbols = PREFERRED_DEBUGGING_TYPE;
1400 else
1401 debug_info_level = DINFO_LEVEL_NONE;
1404 /* CTF is supported for only C at this time. */
1405 if (!lang_GNU_C ()
1406 && ctf_debug_info_level > CTFINFO_LEVEL_NONE)
1408 /* Compiling with -flto results in frontend language of GNU GIMPLE. It
1409 is not useful to warn in that case. */
1410 if (!startswith (lang_hooks.name, "GNU GIMPLE"))
1411 inform (UNKNOWN_LOCATION,
1412 "CTF debug info requested, but not supported for %qs frontend",
1413 language_string);
1414 ctf_debug_info_level = CTFINFO_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 && ctf_debug_info_level == CTFINFO_LEVEL_NONE)
1440 write_symbols = NO_DEBUG;
1442 if (write_symbols == NO_DEBUG)
1444 #if defined(DBX_DEBUGGING_INFO)
1445 else if (write_symbols == DBX_DEBUG)
1446 debug_hooks = &dbx_debug_hooks;
1447 #endif
1448 #if defined(XCOFF_DEBUGGING_INFO)
1449 else if (write_symbols == XCOFF_DEBUG)
1450 debug_hooks = &xcoff_debug_hooks;
1451 #endif
1452 #ifdef DWARF2_DEBUGGING_INFO
1453 else if (dwarf_debuginfo_p ())
1454 debug_hooks = &dwarf2_debug_hooks;
1455 #endif
1456 #ifdef CTF_DEBUGGING_INFO
1457 else if (ctf_debuginfo_p ())
1458 debug_hooks = &dwarf2_debug_hooks;
1459 #endif
1460 #ifdef BTF_DEBUGGING_INFO
1461 else if (btf_debuginfo_p ())
1462 debug_hooks = &dwarf2_debug_hooks;
1463 #endif
1464 #ifdef VMS_DEBUGGING_INFO
1465 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1466 debug_hooks = &vmsdbg_debug_hooks;
1467 #endif
1468 #ifdef DWARF2_LINENO_DEBUGGING_INFO
1469 else if (write_symbols == DWARF2_DEBUG)
1470 debug_hooks = &dwarf2_lineno_debug_hooks;
1471 #endif
1472 else
1474 gcc_assert (debug_set_count (write_symbols) <= 1);
1475 error_at (UNKNOWN_LOCATION,
1476 "target system does not support the %qs debug format",
1477 debug_type_names[debug_set_to_format (write_symbols)]);
1480 /* We know which debug output will be used so we can set flag_var_tracking
1481 and flag_var_tracking_uninit if the user has not specified them. */
1482 if (debug_info_level < DINFO_LEVEL_NORMAL
1483 || !dwarf_debuginfo_p ()
1484 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1486 if (flag_var_tracking == 1
1487 || flag_var_tracking_uninit == 1)
1489 if (debug_info_level < DINFO_LEVEL_NORMAL)
1490 warning_at (UNKNOWN_LOCATION, 0,
1491 "variable tracking requested, but useless unless "
1492 "producing debug info");
1493 else
1494 warning_at (UNKNOWN_LOCATION, 0,
1495 "variable tracking requested, but not supported "
1496 "by this debug format");
1498 flag_var_tracking = 0;
1499 flag_var_tracking_uninit = 0;
1502 /* The debug hooks are used to implement -fdump-go-spec because it
1503 gives a simple and stable API for all the information we need to
1504 dump. */
1505 if (flag_dump_go_spec != NULL)
1506 debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks);
1508 /* If the user specifically requested variable tracking with tagging
1509 uninitialized variables, we need to turn on variable tracking.
1510 (We already determined above that variable tracking is feasible.) */
1511 if (flag_var_tracking_uninit == 1)
1512 flag_var_tracking = 1;
1514 if (flag_var_tracking == AUTODETECT_VALUE)
1515 flag_var_tracking = optimize >= 1;
1517 if (flag_var_tracking_uninit == AUTODETECT_VALUE)
1518 flag_var_tracking_uninit = flag_var_tracking;
1520 if (flag_var_tracking_assignments == AUTODETECT_VALUE)
1521 flag_var_tracking_assignments
1522 = (flag_var_tracking
1523 && !(flag_selective_scheduling || flag_selective_scheduling2));
1525 if (flag_var_tracking_assignments_toggle)
1526 flag_var_tracking_assignments = !flag_var_tracking_assignments;
1528 if (flag_var_tracking_assignments && !flag_var_tracking)
1529 flag_var_tracking = flag_var_tracking_assignments = -1;
1531 if (flag_var_tracking_assignments
1532 && (flag_selective_scheduling || flag_selective_scheduling2))
1533 warning_at (UNKNOWN_LOCATION, 0,
1534 "var-tracking-assignments changes selective scheduling");
1536 if (debug_nonbind_markers_p == AUTODETECT_VALUE)
1537 debug_nonbind_markers_p
1538 = (optimize
1539 && debug_info_level >= DINFO_LEVEL_NORMAL
1540 && dwarf_debuginfo_p ()
1541 && !(flag_selective_scheduling || flag_selective_scheduling2));
1543 if (dwarf2out_as_loc_support == AUTODETECT_VALUE)
1544 dwarf2out_as_loc_support
1545 = dwarf2out_default_as_loc_support ();
1546 if (dwarf2out_as_locview_support == AUTODETECT_VALUE)
1547 dwarf2out_as_locview_support
1548 = dwarf2out_default_as_locview_support ();
1550 if (debug_variable_location_views == AUTODETECT_VALUE)
1552 debug_variable_location_views
1553 = (flag_var_tracking
1554 && debug_info_level >= DINFO_LEVEL_NORMAL
1555 && dwarf_debuginfo_p ()
1556 && !dwarf_strict
1557 && dwarf2out_as_loc_support
1558 && dwarf2out_as_locview_support);
1560 else if (debug_variable_location_views == -1 && dwarf_version != 5)
1562 warning_at (UNKNOWN_LOCATION, 0,
1563 "without %<-gdwarf-5%>, "
1564 "%<-gvariable-location-views=incompat5%> "
1565 "is equivalent to %<-gvariable-location-views%>");
1566 debug_variable_location_views = 1;
1569 if (debug_internal_reset_location_views == 2)
1571 debug_internal_reset_location_views
1572 = (debug_variable_location_views
1573 && targetm.reset_location_view);
1575 else if (debug_internal_reset_location_views
1576 && !debug_variable_location_views)
1578 warning_at (UNKNOWN_LOCATION, 0,
1579 "%<-ginternal-reset-location-views%> is forced disabled "
1580 "without %<-gvariable-location-views%>");
1581 debug_internal_reset_location_views = 0;
1584 if (debug_inline_points == AUTODETECT_VALUE)
1585 debug_inline_points = debug_variable_location_views;
1586 else if (debug_inline_points && !debug_nonbind_markers_p)
1588 warning_at (UNKNOWN_LOCATION, 0,
1589 "%<-ginline-points%> is forced disabled without "
1590 "%<-gstatement-frontiers%>");
1591 debug_inline_points = 0;
1594 if (!OPTION_SET_P (flag_tree_cselim))
1596 if (HAVE_conditional_move)
1597 flag_tree_cselim = 1;
1598 else
1599 flag_tree_cselim = 0;
1602 /* If auxiliary info generation is desired, open the output file.
1603 This goes in the same directory as the source file--unlike
1604 all the other output files. */
1605 if (flag_gen_aux_info)
1607 aux_info_file = fopen (aux_info_file_name, "w");
1608 if (aux_info_file == 0)
1609 fatal_error (UNKNOWN_LOCATION,
1610 "cannot open %s: %m", aux_info_file_name);
1613 if (!targetm_common.have_named_sections)
1615 if (flag_function_sections)
1617 warning_at (UNKNOWN_LOCATION, 0,
1618 "%<-ffunction-sections%> not supported for this target");
1619 flag_function_sections = 0;
1621 if (flag_data_sections)
1623 warning_at (UNKNOWN_LOCATION, 0,
1624 "%<-fdata-sections%> not supported for this target");
1625 flag_data_sections = 0;
1629 if (flag_prefetch_loop_arrays > 0 && !targetm.code_for_prefetch)
1631 warning_at (UNKNOWN_LOCATION, 0,
1632 "%<-fprefetch-loop-arrays%> not supported for this target");
1633 flag_prefetch_loop_arrays = 0;
1635 else if (flag_prefetch_loop_arrays > 0 && !targetm.have_prefetch ())
1637 warning_at (UNKNOWN_LOCATION, 0,
1638 "%<-fprefetch-loop-arrays%> not supported for this target "
1639 "(try %<-march%> switches)");
1640 flag_prefetch_loop_arrays = 0;
1643 /* This combination of options isn't handled for i386 targets and doesn't
1644 make much sense anyway, so don't allow it. */
1645 if (flag_prefetch_loop_arrays > 0 && optimize_size)
1647 warning_at (UNKNOWN_LOCATION, 0,
1648 "%<-fprefetch-loop-arrays%> is not supported with %<-Os%>");
1649 flag_prefetch_loop_arrays = 0;
1652 /* The presence of IEEE signaling NaNs, implies all math can trap. */
1653 if (flag_signaling_nans)
1654 flag_trapping_math = 1;
1656 /* We cannot reassociate if we want traps or signed zeros. */
1657 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
1659 warning_at (UNKNOWN_LOCATION, 0,
1660 "%<-fassociative-math%> disabled; other options take "
1661 "precedence");
1662 flag_associative_math = 0;
1665 /* -fstack-clash-protection is not currently supported on targets
1666 where the stack grows up. */
1667 if (flag_stack_clash_protection && !STACK_GROWS_DOWNWARD)
1669 warning_at (UNKNOWN_LOCATION, 0,
1670 "%<-fstack-clash-protection%> is not supported on targets "
1671 "where the stack grows from lower to higher addresses");
1672 flag_stack_clash_protection = 0;
1675 /* We cannot support -fstack-check= and -fstack-clash-protection at
1676 the same time. */
1677 if (flag_stack_check != NO_STACK_CHECK && flag_stack_clash_protection)
1679 warning_at (UNKNOWN_LOCATION, 0,
1680 "%<-fstack-check=%> and %<-fstack-clash_protection%> are "
1681 "mutually exclusive; disabling %<-fstack-check=%>");
1682 flag_stack_check = NO_STACK_CHECK;
1685 /* Targets must be able to place spill slots at lower addresses. If the
1686 target already uses a soft frame pointer, the transition is trivial. */
1687 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
1689 warning_at (UNKNOWN_LOCATION, 0,
1690 "%<-fstack-protector%> not supported for this target");
1691 flag_stack_protect = 0;
1693 if (!flag_stack_protect)
1694 warn_stack_protect = 0;
1696 /* Address Sanitizer needs porting to each target architecture. */
1698 if ((flag_sanitize & SANITIZE_ADDRESS)
1699 && !FRAME_GROWS_DOWNWARD)
1701 warning_at (UNKNOWN_LOCATION, 0,
1702 "%<-fsanitize=address%> and %<-fsanitize=kernel-address%> "
1703 "are not supported for this target");
1704 flag_sanitize &= ~SANITIZE_ADDRESS;
1707 if ((flag_sanitize & SANITIZE_USER_ADDRESS)
1708 && ((targetm.asan_shadow_offset == NULL)
1709 || (targetm.asan_shadow_offset () == 0)))
1711 warning_at (UNKNOWN_LOCATION, 0,
1712 "%<-fsanitize=address%> not supported for this target");
1713 flag_sanitize &= ~SANITIZE_ADDRESS;
1716 if ((flag_sanitize & SANITIZE_KERNEL_ADDRESS)
1717 && (targetm.asan_shadow_offset == NULL
1718 && !asan_shadow_offset_set_p ()))
1720 warning_at (UNKNOWN_LOCATION, 0,
1721 "%<-fsanitize=kernel-address%> with stack protection "
1722 "is not supported without %<-fasan-shadow-offset=%> "
1723 "for this target");
1724 flag_sanitize &= ~SANITIZE_ADDRESS;
1727 /* HWAsan requires top byte ignore feature in the backend. */
1728 if (flag_sanitize & SANITIZE_HWADDRESS
1729 && ! targetm.memtag.can_tag_addresses ())
1731 warning_at (UNKNOWN_LOCATION, 0, "%qs is not supported for this target",
1732 "-fsanitize=hwaddress");
1733 flag_sanitize &= ~SANITIZE_HWADDRESS;
1736 HOST_WIDE_INT patch_area_size, patch_area_start;
1737 parse_and_check_patch_area (flag_patchable_function_entry, false,
1738 &patch_area_size, &patch_area_start);
1740 /* Do not use IPA optimizations for register allocation if profiler is active
1741 or patchable function entries are inserted for run-time instrumentation
1742 or port does not emit prologue and epilogue as RTL. */
1743 if (profile_flag || patch_area_size
1744 || !targetm.have_prologue () || !targetm.have_epilogue ())
1745 flag_ipa_ra = 0;
1747 /* Enable -Werror=coverage-mismatch when -Werror and -Wno-error
1748 have not been set. */
1749 if (!OPTION_SET_P (warnings_are_errors))
1751 if (warn_coverage_mismatch
1752 && (global_dc->classify_diagnostic[OPT_Wcoverage_mismatch] ==
1753 DK_UNSPECIFIED))
1754 diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch,
1755 DK_ERROR, UNKNOWN_LOCATION);
1756 if (warn_coverage_invalid_linenum
1757 && (global_dc->classify_diagnostic[OPT_Wcoverage_invalid_line_number] ==
1758 DK_UNSPECIFIED))
1759 diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_invalid_line_number,
1760 DK_ERROR, UNKNOWN_LOCATION);
1763 /* Save the current optimization options. */
1764 optimization_default_node
1765 = build_optimization_node (&global_options, &global_options_set);
1766 optimization_current_node = optimization_default_node;
1768 if (flag_checking >= 2)
1769 hash_table_sanitize_eq_limit
1770 = param_hash_table_verification_limit;
1772 if (flag_large_source_files)
1773 line_table->default_range_bits = 0;
1775 /* Please don't change global_options after this point, those changes won't
1776 be reflected in optimization_{default,current}_node. */
1779 /* This function can be called multiple times to reinitialize the compiler
1780 back end when register classes or instruction sets have changed,
1781 before each function. */
1782 static void
1783 backend_init_target (void)
1785 /* This depends on stack_pointer_rtx. */
1786 init_fake_stack_mems ();
1788 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
1789 mode-dependent. */
1790 init_alias_target ();
1792 /* Depends on HARD_FRAME_POINTER_REGNUM. */
1793 if (!ira_use_lra_p)
1794 init_reload ();
1796 /* Depends on the enabled attribute. */
1797 recog_init ();
1799 /* The following initialization functions need to generate rtl, so
1800 provide a dummy function context for them. */
1801 init_dummy_function_start ();
1803 /* rtx_cost is mode-dependent, so cached values need to be recomputed
1804 on a mode change. */
1805 init_expmed ();
1806 init_lower_subreg ();
1807 init_set_costs ();
1809 init_expr_target ();
1810 ira_init ();
1812 /* We may need to recompute regno_save_code[] and regno_restore_code[]
1813 after a mode change as well. */
1814 caller_save_initialized_p = false;
1816 expand_dummy_function_end ();
1819 /* Initialize the compiler back end. This function is called only once,
1820 when starting the compiler. */
1821 static void
1822 backend_init (void)
1824 init_emit_once ();
1826 init_rtlanal ();
1827 init_inline_once ();
1828 init_varasm_once ();
1829 save_register_info ();
1831 /* Middle end needs this initialization for default mem attributes
1832 used by early calls to make_decl_rtl. */
1833 init_emit_regs ();
1835 /* Middle end needs this initialization for mode tables used to assign
1836 modes to vector variables. */
1837 init_regs ();
1840 /* Initialize things that are both lang-dependent and target-dependent.
1841 This function can be called more than once if target parameters change. */
1842 static void
1843 lang_dependent_init_target (void)
1845 /* This creates various _DECL nodes, so needs to be called after the
1846 front end is initialized. It also depends on the HAVE_xxx macros
1847 generated from the target machine description. */
1848 init_optabs ();
1850 gcc_assert (!this_target_rtl->target_specific_initialized);
1853 /* Perform initializations that are lang-dependent or target-dependent.
1854 but matters only for late optimizations and RTL generation. */
1856 static int rtl_initialized;
1858 void
1859 initialize_rtl (void)
1861 auto_timevar tv (g_timer, TV_INITIALIZE_RTL);
1863 /* Initialization done just once per compilation, but delayed
1864 till code generation. */
1865 if (!rtl_initialized)
1866 ira_init_once ();
1867 rtl_initialized = true;
1869 /* Target specific RTL backend initialization. */
1870 if (!this_target_rtl->target_specific_initialized)
1872 backend_init_target ();
1873 this_target_rtl->target_specific_initialized = true;
1877 /* Language-dependent initialization. Returns nonzero on success. */
1878 static int
1879 lang_dependent_init (const char *name)
1881 location_t save_loc = input_location;
1882 if (!dump_base_name)
1884 dump_base_name = name && name[0] ? name : "gccdump";
1886 /* We do not want to derive a non-empty dumpbase-ext from an
1887 explicit -dumpbase argument, only from a defaulted
1888 dumpbase. */
1889 if (!dump_base_ext)
1891 const char *base = lbasename (dump_base_name);
1892 const char *ext = strrchr (base, '.');
1893 if (ext)
1894 dump_base_ext = ext;
1898 /* Other front-end initialization. */
1899 input_location = BUILTINS_LOCATION;
1900 if (lang_hooks.init () == 0)
1901 return 0;
1902 input_location = save_loc;
1904 if (!flag_wpa)
1906 init_asm_output (name);
1908 if (!flag_generate_lto && !flag_compare_debug)
1910 /* If stack usage information is desired, open the output file. */
1911 if (flag_stack_usage)
1912 stack_usage_file = open_auxiliary_file ("su");
1914 /* If call graph information is desired, open the output file. */
1915 if (flag_callgraph_info)
1917 callgraph_info_file = open_auxiliary_file ("ci");
1918 /* Write the file header. */
1919 fprintf (callgraph_info_file,
1920 "graph: { title: \"%s\"\n", main_input_filename);
1921 bitmap_obstack_initialize (NULL);
1922 callgraph_info_external_printed = BITMAP_ALLOC (NULL);
1925 else
1926 flag_stack_usage = flag_callgraph_info = false;
1929 /* This creates various _DECL nodes, so needs to be called after the
1930 front end is initialized. */
1931 init_eh ();
1933 /* Do the target-specific parts of the initialization. */
1934 lang_dependent_init_target ();
1936 if (!flag_wpa)
1938 /* If dbx symbol table desired, initialize writing it and output the
1939 predefined types. */
1940 timevar_push (TV_SYMOUT);
1942 /* Now we have the correct original filename, we can initialize
1943 debug output. */
1944 (*debug_hooks->init) (name);
1946 timevar_pop (TV_SYMOUT);
1949 return 1;
1953 /* Reinitialize everything when target parameters, such as register usage,
1954 have changed. */
1955 void
1956 target_reinit (void)
1958 struct rtl_data saved_x_rtl;
1959 rtx *saved_regno_reg_rtx;
1960 tree saved_optimization_current_node;
1961 struct target_optabs *saved_this_fn_optabs;
1963 /* Temporarily switch to the default optimization node, so that
1964 *this_target_optabs is set to the default, not reflecting
1965 whatever a previous function used for the optimize
1966 attribute. */
1967 saved_optimization_current_node = optimization_current_node;
1968 saved_this_fn_optabs = this_fn_optabs;
1969 if (saved_optimization_current_node != optimization_default_node)
1971 optimization_current_node = optimization_default_node;
1972 cl_optimization_restore
1973 (&global_options, &global_options_set,
1974 TREE_OPTIMIZATION (optimization_default_node));
1976 this_fn_optabs = this_target_optabs;
1978 /* Save *crtl and regno_reg_rtx around the reinitialization
1979 to allow target_reinit being called even after prepare_function_start. */
1980 saved_regno_reg_rtx = regno_reg_rtx;
1981 if (saved_regno_reg_rtx)
1983 saved_x_rtl = *crtl;
1984 memset (crtl, '\0', sizeof (*crtl));
1985 regno_reg_rtx = NULL;
1988 this_target_rtl->target_specific_initialized = false;
1990 /* This initializes hard_frame_pointer, and calls init_reg_modes_target()
1991 to initialize reg_raw_mode[]. */
1992 init_emit_regs ();
1994 /* This invokes target hooks to set fixed_reg[] etc, which is
1995 mode-dependent. */
1996 init_regs ();
1998 /* Reinitialize lang-dependent parts. */
1999 lang_dependent_init_target ();
2001 /* Restore the original optimization node. */
2002 if (saved_optimization_current_node != optimization_default_node)
2004 optimization_current_node = saved_optimization_current_node;
2005 cl_optimization_restore (&global_options, &global_options_set,
2006 TREE_OPTIMIZATION (optimization_current_node));
2008 this_fn_optabs = saved_this_fn_optabs;
2010 /* Restore regno_reg_rtx at the end, as free_after_compilation from
2011 expand_dummy_function_end clears it. */
2012 if (saved_regno_reg_rtx)
2014 *crtl = saved_x_rtl;
2015 regno_reg_rtx = saved_regno_reg_rtx;
2016 saved_regno_reg_rtx = NULL;
2020 void
2021 dump_memory_report (const char *header)
2023 /* Print significant header. */
2024 fputc ('\n', stderr);
2025 for (unsigned i = 0; i < 80; i++)
2026 fputc ('#', stderr);
2027 fprintf (stderr, "\n# %-77s#\n", header);
2028 for (unsigned i = 0; i < 80; i++)
2029 fputc ('#', stderr);
2030 fputs ("\n\n", stderr);
2032 dump_line_table_statistics ();
2033 ggc_print_statistics ();
2034 stringpool_statistics ();
2035 dump_tree_statistics ();
2036 dump_gimple_statistics ();
2037 dump_rtx_statistics ();
2038 dump_alloc_pool_statistics ();
2039 dump_bitmap_statistics ();
2040 dump_hash_table_loc_statistics ();
2041 dump_vec_loc_statistics ();
2042 dump_ggc_loc_statistics ();
2043 dump_alias_stats (stderr);
2044 dump_pta_stats (stderr);
2047 /* Clean up: close opened files, etc. */
2049 static void
2050 finalize (bool no_backend)
2052 /* Close the dump files. */
2053 if (flag_gen_aux_info)
2055 fclose (aux_info_file);
2056 aux_info_file = NULL;
2057 if (seen_error ())
2058 unlink (aux_info_file_name);
2061 /* Close non-debugging input and output files. Take special care to note
2062 whether fclose returns an error, since the pages might still be on the
2063 buffer chain while the file is open. */
2065 if (asm_out_file)
2067 if (ferror (asm_out_file) != 0)
2068 fatal_error (input_location, "error writing to %s: %m", asm_file_name);
2069 if (fclose (asm_out_file) != 0)
2070 fatal_error (input_location, "error closing %s: %m", asm_file_name);
2071 asm_out_file = NULL;
2074 if (stack_usage_file)
2076 fclose (stack_usage_file);
2077 stack_usage_file = NULL;
2080 if (callgraph_info_file)
2082 fputs ("}\n", callgraph_info_file);
2083 fclose (callgraph_info_file);
2084 callgraph_info_file = NULL;
2085 BITMAP_FREE (callgraph_info_external_printed);
2086 bitmap_obstack_release (NULL);
2089 if (seen_error ())
2090 coverage_remove_note_file ();
2092 if (!no_backend)
2094 statistics_fini ();
2095 debuginfo_fini ();
2097 g->get_passes ()->finish_optimization_passes ();
2099 lra_finish_once ();
2102 if (mem_report)
2103 dump_memory_report ("Final");
2105 if (profile_report)
2106 dump_profile_report ();
2108 if (flag_dbg_cnt_list)
2109 dbg_cnt_list_all_counters ();
2111 /* Language-specific end of compilation actions. */
2112 lang_hooks.finish ();
2115 static bool
2116 standard_type_bitsize (int bitsize)
2118 /* As a special exception, we always want __int128 enabled if possible. */
2119 if (bitsize == 128)
2120 return false;
2121 if (bitsize == CHAR_TYPE_SIZE
2122 || bitsize == SHORT_TYPE_SIZE
2123 || bitsize == INT_TYPE_SIZE
2124 || bitsize == LONG_TYPE_SIZE
2125 || bitsize == LONG_LONG_TYPE_SIZE)
2126 return true;
2127 return false;
2130 /* Initialize the compiler, and compile the input file. */
2131 static void
2132 do_compile (bool no_backend)
2134 /* Don't do any more if an error has already occurred. */
2135 if (!seen_error ())
2137 int i;
2139 timevar_start (TV_PHASE_SETUP);
2141 if (flag_save_optimization_record)
2143 dump_context::get ().set_json_writer (new optrecord_json_writer ());
2146 /* This must be run always, because it is needed to compute the FP
2147 predefined macros, such as __LDBL_MAX__, for targets using non
2148 default FP formats. */
2149 init_adjust_machine_modes ();
2150 init_derived_machine_modes ();
2152 /* This must happen after the backend has a chance to process
2153 command line options, but before the parsers are
2154 initialized. */
2155 for (i = 0; i < NUM_INT_N_ENTS; i ++)
2156 if (targetm.scalar_mode_supported_p (int_n_data[i].m)
2157 && ! standard_type_bitsize (int_n_data[i].bitsize))
2158 int_n_enabled_p[i] = true;
2159 else
2160 int_n_enabled_p[i] = false;
2162 /* Initialize mpfrs exponent range. This is important to get
2163 underflow/overflow in a reasonable timeframe. */
2164 machine_mode mode;
2165 int min_exp = -1;
2166 int max_exp = 1;
2167 FOR_EACH_MODE_IN_CLASS (mode, MODE_FLOAT)
2168 if (SCALAR_FLOAT_MODE_P (mode))
2170 const real_format *fmt = REAL_MODE_FORMAT (mode);
2171 if (fmt)
2173 /* fmt->emin - fmt->p + 1 should be enough but the
2174 back-and-forth dance in real_to_decimal_for_mode we
2175 do for checking fails due to rounding effects then. */
2176 if ((fmt->emin - fmt->p) < min_exp)
2177 min_exp = fmt->emin - fmt->p;
2178 if (fmt->emax > max_exp)
2179 max_exp = fmt->emax;
2182 /* E.g. mpc_norm assumes it can square a number without bothering with
2183 with range scaling, so until that is fixed, double the minimum
2184 and maximum exponents, plus add some buffer for arithmetics
2185 on the squared numbers. */
2186 if (mpfr_set_emin (2 * (min_exp - 1))
2187 || mpfr_set_emax (2 * (max_exp + 1)))
2188 sorry ("mpfr not configured to handle all floating modes");
2190 /* Set up the back-end if requested. */
2191 if (!no_backend)
2192 backend_init ();
2194 /* Language-dependent initialization. Returns true on success. */
2195 if (lang_dependent_init (main_input_filename))
2197 /* Initialize yet another pass. */
2199 ggc_protect_identifiers = true;
2201 symtab->initialize ();
2202 init_final (main_input_filename);
2203 coverage_init (aux_base_name);
2204 statistics_init ();
2205 debuginfo_init ();
2206 invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
2208 timevar_stop (TV_PHASE_SETUP);
2210 compile_file ();
2212 else
2214 timevar_stop (TV_PHASE_SETUP);
2217 timevar_start (TV_PHASE_FINALIZE);
2219 finalize (no_backend);
2221 timevar_stop (TV_PHASE_FINALIZE);
2225 toplev::toplev (timer *external_timer,
2226 bool init_signals)
2227 : m_use_TV_TOTAL (external_timer == NULL),
2228 m_init_signals (init_signals)
2230 if (external_timer)
2231 g_timer = external_timer;
2234 toplev::~toplev ()
2236 if (g_timer && m_use_TV_TOTAL)
2238 g_timer->stop (TV_TOTAL);
2239 g_timer->print (stderr);
2240 delete g_timer;
2241 g_timer = NULL;
2245 /* Potentially call timevar_init (which will create g_timevars if it
2246 doesn't already exist). */
2248 void
2249 toplev::start_timevars ()
2251 if (time_report || !quiet_flag || flag_detailed_statistics)
2252 timevar_init ();
2254 timevar_start (TV_TOTAL);
2257 /* Handle -fself-test. */
2259 void
2260 toplev::run_self_tests ()
2262 #if CHECKING_P
2263 /* Reset some state. */
2264 input_location = UNKNOWN_LOCATION;
2265 bitmap_obstack_initialize (NULL);
2267 /* Run the tests; any failures will lead to an abort of the process.
2268 Use "make selftests-gdb" to run under the debugger. */
2269 ::selftest::run_tests ();
2271 /* Cleanup. */
2272 bitmap_obstack_release (NULL);
2273 #else
2274 inform (UNKNOWN_LOCATION, "self-tests are not enabled in this build");
2275 #endif /* #if CHECKING_P */
2278 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2279 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2280 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2282 It is not safe to call this function more than once. */
2285 toplev::main (int argc, char **argv)
2287 /* Parsing and gimplification sometimes need quite large stack.
2288 Increase stack size limits if possible. */
2289 stack_limit_increase (64 * 1024 * 1024);
2291 expandargv (&argc, &argv);
2293 /* Initialization of GCC's environment, and diagnostics. */
2294 general_init (argv[0], m_init_signals);
2296 /* One-off initialization of options that does not need to be
2297 repeated when options are added for particular functions. */
2298 init_options_once ();
2299 init_opts_obstack ();
2301 /* Initialize global options structures; this must be repeated for
2302 each structure used for parsing options. */
2303 init_options_struct (&global_options, &global_options_set);
2304 lang_hooks.init_options_struct (&global_options);
2306 /* Init GGC heuristics must be caller after we initialize
2307 options. */
2308 init_ggc_heuristics ();
2310 /* Convert the options to an array. */
2311 decode_cmdline_options_to_array_default_mask (argc,
2312 CONST_CAST2 (const char **,
2313 char **, argv),
2314 &save_decoded_options,
2315 &save_decoded_options_count);
2317 /* Save Optimization decoded options. */
2318 save_opt_decoded_options = new vec<cl_decoded_option> ();
2319 for (unsigned i = 1; i < save_decoded_options_count; ++i)
2320 if (save_decoded_options[i].opt_index < cl_options_count
2321 && cl_options[save_decoded_options[i].opt_index].flags & CL_OPTIMIZATION)
2322 save_opt_decoded_options->safe_push (save_decoded_options[i]);
2324 /* Perform language-specific options initialization. */
2325 lang_hooks.init_options (save_decoded_options_count, save_decoded_options);
2327 /* Parse the options and do minimal processing; basically just
2328 enough to default flags appropriately. */
2329 decode_options (&global_options, &global_options_set,
2330 save_decoded_options, save_decoded_options_count,
2331 UNKNOWN_LOCATION, global_dc,
2332 targetm.target_option.override);
2334 handle_common_deferred_options ();
2336 init_local_tick ();
2338 initialize_plugins ();
2340 if (version_flag)
2341 print_version (stderr, "", true);
2343 if (help_flag)
2344 print_plugins_help (stderr, "");
2346 /* Exit early if we can (e.g. -help). */
2347 if (!exit_after_options)
2349 /* Allow the front end to perform consistency checks and do further
2350 initialization based on the command line options. This hook also
2351 sets the original filename if appropriate (e.g. foo.i -> foo.c)
2352 so we can correctly initialize debug output. */
2353 bool no_backend = lang_hooks.post_options (&main_input_filename);
2355 process_options (no_backend);
2357 if (m_use_TV_TOTAL)
2358 start_timevars ();
2359 do_compile (no_backend);
2361 if (flag_self_test)
2363 if (no_backend)
2364 error_at (UNKNOWN_LOCATION, "self-tests incompatible with %<-E%>");
2365 else
2366 run_self_tests ();
2370 if (warningcount || errorcount || werrorcount)
2371 print_ignored_options ();
2373 /* Invoke registered plugin callbacks if any. Some plugins could
2374 emit some diagnostics here. */
2375 invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
2377 if (flag_diagnostics_generate_patch)
2379 gcc_assert (global_dc->edit_context_ptr);
2381 pretty_printer pp;
2382 pp_show_color (&pp) = pp_show_color (global_dc->printer);
2383 global_dc->edit_context_ptr->print_diff (&pp, true);
2384 pp_flush (&pp);
2387 diagnostic_finish (global_dc);
2389 finalize_plugins ();
2391 after_memory_report = true;
2393 if (seen_error () || werrorcount)
2394 return (FATAL_EXIT_CODE);
2396 return (SUCCESS_EXIT_CODE);
2399 /* For those that want to, this function aims to clean up enough state that
2400 you can call toplev::main again. */
2401 void
2402 toplev::finalize (void)
2404 rtl_initialized = false;
2405 this_target_rtl->target_specific_initialized = false;
2407 /* Needs to be called before cgraph_c_finalize since it uses symtab. */
2408 ipa_reference_c_finalize ();
2409 ipa_fnsummary_c_finalize ();
2410 ipa_modref_c_finalize ();
2411 ipa_edge_modifications_finalize ();
2413 cgraph_c_finalize ();
2414 cgraphunit_c_finalize ();
2415 symtab_thunks_cc_finalize ();
2416 dwarf2out_c_finalize ();
2417 gcse_c_finalize ();
2418 ipa_cp_c_finalize ();
2419 ira_costs_c_finalize ();
2421 /* save_decoded_options uses opts_obstack, so these must
2422 be cleaned up together. */
2423 obstack_free (&opts_obstack, NULL);
2424 XDELETEVEC (save_decoded_options);
2425 save_decoded_options = NULL;
2426 save_decoded_options_count = 0;
2428 /* Clean up the context (and pass_manager etc). */
2429 delete g;
2430 g = NULL;