2015-10-28 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / toplev.c
blob0083d81670159d8cc719ebd9b39d4a0e36ee1a48
1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987-2015 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 "tree.h"
30 #include "gimple.h"
31 #include "rtl.h"
32 #include "alias.h"
33 #include "fold-const.h"
34 #include "varasm.h"
35 #include "tree-inline.h"
36 #include "realmpfr.h" /* For GMP/MPFR/MPC versions, in print_version. */
37 #include "version.h"
38 #include "tm_p.h"
39 #include "flags.h"
40 #include "insn-attr.h"
41 #include "insn-config.h"
42 #include "insn-flags.h"
43 #include "recog.h"
44 #include "output.h"
45 #include "except.h"
46 #include "toplev.h"
47 #include "expmed.h"
48 #include "dojump.h"
49 #include "explow.h"
50 #include "calls.h"
51 #include "emit-rtl.h"
52 #include "stmt.h"
53 #include "expr.h"
54 #include "intl.h"
55 #include "regs.h"
56 #include "timevar.h"
57 #include "diagnostic.h"
58 #include "tree-diagnostic.h"
59 #include "tree-pretty-print.h"
60 #include "params.h"
61 #include "reload.h"
62 #include "ira.h"
63 #include "lra.h"
64 #include "dwarf2asm.h"
65 #include "debug.h"
66 #include "target.h"
67 #include "common/common-target.h"
68 #include "langhooks.h"
69 #include "cfgloop.h" /* for init_set_costs */
70 #include "hosthooks.h"
71 #include "cgraph.h"
72 #include "opts.h"
73 #include "opts-diagnostic.h"
74 #include "coverage.h"
75 #include "value-prof.h"
76 #include "alloc-pool.h"
77 #include "asan.h"
78 #include "tsan.h"
79 #include "internal-fn.h"
80 #include "plugin.h"
81 #include "context.h"
82 #include "pass_manager.h"
83 #include "auto-profile.h"
84 #include "dwarf2out.h"
85 #include "ipa-reference.h"
86 #include "symbol-summary.h"
87 #include "ipa-prop.h"
88 #include "gcse.h"
89 #include "insn-codes.h"
90 #include "optabs-query.h"
91 #include "optabs-libfuncs.h"
92 #include "tree-chkp.h"
93 #include "omp-low.h"
95 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
96 #include "dbxout.h"
97 #endif
99 #ifdef SDB_DEBUGGING_INFO
100 #include "sdbout.h"
101 #endif
103 #ifdef XCOFF_DEBUGGING_INFO
104 #include "xcoffout.h" /* Needed for external data
105 declarations for e.g. AIX 4.x. */
106 #endif
108 #include <new>
110 static void general_init (const char *, bool);
111 static void do_compile ();
112 static void process_options (void);
113 static void backend_init (void);
114 static int lang_dependent_init (const char *);
115 static void init_asm_output (const char *);
116 static void finalize (bool);
118 static void crash_signal (int) ATTRIBUTE_NORETURN;
119 static void compile_file (void);
121 /* True if we don't need a backend (e.g. preprocessing only). */
122 static bool no_backend;
124 /* Length of line when printing switch values. */
125 #define MAX_LINE 75
127 /* Decoded options, and number of such options. */
128 struct cl_decoded_option *save_decoded_options;
129 unsigned int save_decoded_options_count;
131 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
132 to optimize in process_options (). */
133 #define AUTODETECT_VALUE 2
135 /* Debug hooks - dependent upon command line options. */
137 const struct gcc_debug_hooks *debug_hooks;
139 /* The FUNCTION_DECL for the function currently being compiled,
140 or 0 if between functions. */
141 tree current_function_decl;
143 /* Set to the FUNC_BEGIN label of the current function, or NULL
144 if none. */
145 const char * current_function_func_begin_label;
147 /* A random sequence of characters, unless overridden by user. */
148 static const char *flag_random_seed;
150 /* A local time stamp derived from the time of compilation. It will be
151 zero if the system cannot provide a time. It will be -1u, if the
152 user has specified a particular random seed. */
153 unsigned local_tick;
155 /* Random number for this compilation */
156 HOST_WIDE_INT random_seed;
158 /* -f flags. */
160 /* When non-NULL, indicates that whenever space is allocated on the
161 stack, the resulting stack pointer must not pass this
162 address---that is, for stacks that grow downward, the stack pointer
163 must always be greater than or equal to this address; for stacks
164 that grow upward, the stack pointer must be less than this address.
165 At present, the rtx may be either a REG or a SYMBOL_REF, although
166 the support provided depends on the backend. */
167 rtx stack_limit_rtx;
169 /* True if the user has tagged the function with the 'section'
170 attribute. */
172 bool user_defined_section_attribute = false;
174 struct target_flag_state default_target_flag_state;
175 #if SWITCHABLE_TARGET
176 struct target_flag_state *this_target_flag_state = &default_target_flag_state;
177 #else
178 #define this_target_flag_state (&default_target_flag_state)
179 #endif
181 /* The user symbol prefix after having resolved same. */
182 const char *user_label_prefix;
184 /* Output files for assembler code (real compiler output)
185 and debugging dumps. */
187 FILE *asm_out_file;
188 FILE *aux_info_file;
189 FILE *stack_usage_file = NULL;
191 /* The current working directory of a translation. It's generally the
192 directory from which compilation was initiated, but a preprocessed
193 file may specify the original directory in which it was
194 created. */
196 static const char *src_pwd;
198 /* Initialize src_pwd with the given string, and return true. If it
199 was already initialized, return false. As a special case, it may
200 be called with a NULL argument to test whether src_pwd has NOT been
201 initialized yet. */
203 bool
204 set_src_pwd (const char *pwd)
206 if (src_pwd)
208 if (strcmp (src_pwd, pwd) == 0)
209 return true;
210 else
211 return false;
214 src_pwd = xstrdup (pwd);
215 return true;
218 /* Return the directory from which the translation unit was initiated,
219 in case set_src_pwd() was not called before to assign it a
220 different value. */
222 const char *
223 get_src_pwd (void)
225 if (! src_pwd)
227 src_pwd = getpwd ();
228 if (!src_pwd)
229 src_pwd = ".";
232 return src_pwd;
235 /* Called when the start of a function definition is parsed,
236 this function prints on stderr the name of the function. */
237 void
238 announce_function (tree decl)
240 if (!quiet_flag)
242 if (rtl_dump_and_exit)
243 fprintf (stderr, "%s ",
244 identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))));
245 else
246 fprintf (stderr, " %s",
247 identifier_to_locale (lang_hooks.decl_printable_name (decl, 2)));
248 fflush (stderr);
249 pp_needs_newline (global_dc->printer) = true;
250 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
254 /* Initialize local_tick with a random number or -1 if
255 flag_random_seed is set. */
257 static void
258 init_local_tick (void)
260 if (!flag_random_seed)
262 /* Try urandom first. Time of day is too likely to collide.
263 In case of any error we just use the local tick. */
265 int fd = open ("/dev/urandom", O_RDONLY);
266 if (fd >= 0)
268 if (read (fd, &random_seed, sizeof (random_seed))
269 != sizeof (random_seed))
270 random_seed = 0;
271 close (fd);
274 /* Now get the tick anyways */
275 #ifdef HAVE_GETTIMEOFDAY
277 struct timeval tv;
279 gettimeofday (&tv, NULL);
280 local_tick = (unsigned) tv.tv_sec * 1000 + tv.tv_usec / 1000;
282 #else
284 time_t now = time (NULL);
286 if (now != (time_t)-1)
287 local_tick = (unsigned) now;
289 #endif
291 else
292 local_tick = -1;
295 /* Set up a default flag_random_seed and local_tick, unless the user
296 already specified one. Must be called after init_local_tick. */
298 static void
299 init_random_seed (void)
301 if (!random_seed)
302 random_seed = local_tick ^ getpid (); /* Old racey fallback method */
305 /* Obtain the random_seed. Unless NOINIT, initialize it if
306 it's not provided in the command line. */
308 HOST_WIDE_INT
309 get_random_seed (bool noinit)
311 if (!flag_random_seed && !noinit)
312 init_random_seed ();
313 return random_seed;
316 /* Modify the random_seed string to VAL. Return its previous
317 value. */
319 const char *
320 set_random_seed (const char *val)
322 const char *old = flag_random_seed;
323 flag_random_seed = val;
324 if (flag_random_seed)
326 char *endp;
328 /* When the driver passed in a hex number don't crc it again */
329 random_seed = strtoul (flag_random_seed, &endp, 0);
330 if (!(endp > flag_random_seed && *endp == 0))
331 random_seed = crc32_string (0, flag_random_seed);
333 return old;
336 /* Handler for fatal signals, such as SIGSEGV. These are transformed
337 into ICE messages, which is much more user friendly. In case the
338 error printer crashes, reset the signal to prevent infinite recursion. */
340 static void
341 crash_signal (int signo)
343 signal (signo, SIG_DFL);
345 /* If we crashed while processing an ASM statement, then be a little more
346 graceful. It's most likely the user's fault. */
347 if (this_is_asm_operands)
349 output_operand_lossage ("unrecoverable error");
350 exit (FATAL_EXIT_CODE);
353 internal_error ("%s", strsignal (signo));
356 /* A subroutine of wrapup_global_declarations. We've come to the end of
357 the compilation unit. All deferred variables should be undeferred,
358 and all incomplete decls should be finalized. */
360 void
361 wrapup_global_declaration_1 (tree decl)
363 /* We're not deferring this any longer. Assignment is conditional to
364 avoid needlessly dirtying PCH pages. */
365 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
366 && DECL_DEFER_OUTPUT (decl) != 0)
367 DECL_DEFER_OUTPUT (decl) = 0;
369 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
370 lang_hooks.finish_incomplete_decl (decl);
373 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
374 needs to be output. Return true if it is output. */
376 bool
377 wrapup_global_declaration_2 (tree decl)
379 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl)
380 || (TREE_CODE (decl) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (decl)))
381 return false;
383 /* Don't write out static consts, unless we still need them.
385 We also keep static consts if not optimizing (for debugging),
386 unless the user specified -fno-keep-static-consts.
387 ??? They might be better written into the debug information.
388 This is possible when using DWARF.
390 A language processor that wants static constants to be always
391 written out (even if it is not used) is responsible for
392 calling rest_of_decl_compilation itself. E.g. the C front-end
393 calls rest_of_decl_compilation from finish_decl.
394 One motivation for this is that is conventional in some
395 environments to write things like:
396 static const char rcsid[] = "... version string ...";
397 intending to force the string to be in the executable.
399 A language processor that would prefer to have unneeded
400 static constants "optimized away" would just defer writing
401 them out until here. E.g. C++ does this, because static
402 constants are often defined in header files.
404 ??? A tempting alternative (for both C and C++) would be
405 to force a constant to be written if and only if it is
406 defined in a main file, as opposed to an include file. */
408 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
410 varpool_node *node;
411 bool needed = true;
412 node = varpool_node::get (decl);
414 if (!node && flag_ltrans)
415 needed = false;
416 else if (node && node->definition)
417 needed = false;
418 else if (node && node->alias)
419 needed = false;
420 else if (!symtab->global_info_ready
421 && (TREE_USED (decl)
422 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
423 /* needed */;
424 else if (node && node->analyzed)
425 /* needed */;
426 else if (DECL_COMDAT (decl))
427 needed = false;
428 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
429 && (optimize || !flag_keep_static_consts
430 || DECL_ARTIFICIAL (decl)))
431 needed = false;
433 if (needed)
435 rest_of_decl_compilation (decl, 1, 1);
436 return true;
440 return false;
443 /* Do any final processing required for the declarations in VEC, of
444 which there are LEN. We write out inline functions and variables
445 that have been deferred until this point, but which are required.
446 Returns nonzero if anything was put out. */
448 bool
449 wrapup_global_declarations (tree *vec, int len)
451 bool reconsider, output_something = false;
452 int i;
454 for (i = 0; i < len; i++)
455 wrapup_global_declaration_1 (vec[i]);
457 /* Now emit any global variables or functions that we have been
458 putting off. We need to loop in case one of the things emitted
459 here references another one which comes earlier in the list. */
462 reconsider = false;
463 for (i = 0; i < len; i++)
464 reconsider |= wrapup_global_declaration_2 (vec[i]);
465 if (reconsider)
466 output_something = true;
468 while (reconsider);
470 return output_something;
473 /* Compile an entire translation unit. Write a file of assembly
474 output and various debugging dumps. */
476 static void
477 compile_file (void)
479 timevar_start (TV_PHASE_PARSING);
480 timevar_push (TV_PARSE_GLOBAL);
482 /* Parse entire file and generate initial debug information. */
483 lang_hooks.parse_file ();
485 timevar_pop (TV_PARSE_GLOBAL);
486 timevar_stop (TV_PHASE_PARSING);
488 if (flag_dump_locations)
489 dump_location_info (stderr);
491 /* Compilation is now finished except for writing
492 what's left of the symbol table output. */
494 if (flag_syntax_only || flag_wpa)
495 return;
497 /* Reset maximum_field_alignment, it can be adjusted by #pragma pack
498 and this shouldn't influence any types built by the middle-end
499 from now on (like gcov_info_type). */
500 maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT;
502 ggc_protect_identifiers = false;
504 /* Run the actual compilation process. */
505 if (!in_lto_p)
507 timevar_start (TV_PHASE_OPT_GEN);
508 symtab->finalize_compilation_unit ();
509 timevar_stop (TV_PHASE_OPT_GEN);
512 /* Perform any post compilation-proper parser cleanups and
513 processing. This is currently only needed for the C++ parser,
514 which can be hopefully cleaned up so this hook is no longer
515 necessary. */
516 if (lang_hooks.decls.post_compilation_parsing_cleanups)
517 lang_hooks.decls.post_compilation_parsing_cleanups ();
519 if (seen_error ())
520 return;
522 timevar_start (TV_PHASE_LATE_ASM);
524 /* Compilation unit is finalized. When producing non-fat LTO object, we are
525 basically finished. */
526 if (in_lto_p || !flag_lto || flag_fat_lto_objects)
528 /* File-scope initialization for AddressSanitizer. */
529 if (flag_sanitize & SANITIZE_ADDRESS)
530 asan_finish_file ();
532 if (flag_sanitize & SANITIZE_THREAD)
533 tsan_finish_file ();
535 if (flag_check_pointer_bounds)
536 chkp_finish_file ();
538 omp_finish_file ();
540 output_shared_constant_pool ();
541 output_object_blocks ();
542 finish_tm_clone_pairs ();
544 /* Write out any pending weak symbol declarations. */
545 weak_finish ();
547 /* This must be at the end before unwind and debug info.
548 Some target ports emit PIC setup thunks here. */
549 targetm.asm_out.code_end ();
551 /* Do dbx symbols. */
552 timevar_push (TV_SYMOUT);
554 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
555 if (dwarf2out_do_frame ())
556 dwarf2out_frame_finish ();
557 #endif
559 (*debug_hooks->finish) (main_input_filename);
560 timevar_pop (TV_SYMOUT);
562 /* Output some stuff at end of file if nec. */
564 dw2_output_indirect_constants ();
566 /* Flush any pending external directives. */
567 process_pending_assemble_externals ();
570 /* Emit LTO marker if LTO info has been previously emitted. This is
571 used by collect2 to determine whether an object file contains IL.
572 We used to emit an undefined reference here, but this produces
573 link errors if an object file with IL is stored into a shared
574 library without invoking lto1. */
575 if (flag_generate_lto || flag_generate_offload)
577 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
578 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE,
579 "__gnu_lto_v1",
580 (unsigned HOST_WIDE_INT) 1, 8);
581 #elif defined ASM_OUTPUT_ALIGNED_COMMON
582 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_v1",
583 (unsigned HOST_WIDE_INT) 1, 8);
584 #else
585 ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_v1",
586 (unsigned HOST_WIDE_INT) 1,
587 (unsigned HOST_WIDE_INT) 1);
588 #endif
591 /* Let linker plugin know that this is a slim object and must be LTOed
592 even when user did not ask for it. */
593 if (flag_generate_lto && !flag_fat_lto_objects)
595 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
596 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE, "__gnu_lto_slim",
597 (unsigned HOST_WIDE_INT) 1, 8);
598 #elif defined ASM_OUTPUT_ALIGNED_COMMON
599 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_slim",
600 (unsigned HOST_WIDE_INT) 1, 8);
601 #else
602 ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_slim",
603 (unsigned HOST_WIDE_INT) 1,
604 (unsigned HOST_WIDE_INT) 1);
605 #endif
608 /* Attach a special .ident directive to the end of the file to identify
609 the version of GCC which compiled this code. The format of the .ident
610 string is patterned after the ones produced by native SVR4 compilers. */
611 if (!flag_no_ident)
613 const char *pkg_version = "(GNU) ";
614 char *ident_str;
616 if (strcmp ("(GCC) ", pkgversion_string))
617 pkg_version = pkgversion_string;
619 ident_str = ACONCAT (("GCC: ", pkg_version, version_string, NULL));
620 targetm.asm_out.output_ident (ident_str);
623 /* Auto profile finalization. */
624 if (flag_auto_profile)
625 end_auto_profile ();
627 /* Invoke registered plugin callbacks. */
628 invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
630 /* This must be at the end. Some target ports emit end of file directives
631 into the assembly file here, and hence we can not output anything to the
632 assembly file after this point. */
633 targetm.asm_out.file_end ();
635 timevar_stop (TV_PHASE_LATE_ASM);
638 /* Print version information to FILE.
639 Each line begins with INDENT (for the case where FILE is the
640 assembler output file).
642 If SHOW_GLOBAL_STATE is true (for cc1 etc), we are within the compiler
643 proper and can print pertinent state (e.g. params and plugins).
645 If SHOW_GLOBAL_STATE is false (for use by libgccjit), we are outside the
646 compiler, and we don't hold the mutex on the compiler's global state:
647 we can't print params and plugins, since they might not be initialized,
648 or might be being manipulated by a compile running in another
649 thread. */
651 void
652 print_version (FILE *file, const char *indent, bool show_global_state)
654 static const char fmt1[] =
655 #ifdef __GNUC__
656 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
657 #else
658 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
659 #endif
661 static const char fmt2[] =
662 N_("GMP version %s, MPFR version %s, MPC version %s\n");
663 static const char fmt3[] =
664 N_("%s%swarning: %s header version %s differs from library version %s.\n");
665 static const char fmt4[] =
666 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
667 #ifndef __VERSION__
668 #define __VERSION__ "[?]"
669 #endif
670 fprintf (file,
671 file == stderr ? _(fmt1) : fmt1,
672 indent, *indent != 0 ? " " : "",
673 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
674 indent, __VERSION__);
676 /* We need to stringify the GMP macro values. Ugh, gmp_version has
677 two string formats, "i.j.k" and "i.j" when k is zero. As of
678 gmp-4.3.0, GMP always uses the 3 number format. */
679 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
680 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3 (X)
681 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
682 #define GCC_GMP_VERSION \
683 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
684 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
685 #define GCC_GMP_STRINGIFY_VERSION \
686 GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION) "." \
687 GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION_MINOR)
688 #else
689 #define GCC_GMP_STRINGIFY_VERSION \
690 GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION) "." \
691 GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION_MINOR) "." \
692 GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION_PATCHLEVEL)
693 #endif
694 fprintf (file,
695 file == stderr ? _(fmt2) : fmt2,
696 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING, MPC_VERSION_STRING);
697 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
698 fprintf (file,
699 file == stderr ? _(fmt3) : fmt3,
700 indent, *indent != 0 ? " " : "",
701 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
702 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
703 fprintf (file,
704 file == stderr ? _(fmt3) : fmt3,
705 indent, *indent != 0 ? " " : "",
706 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
707 if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
708 fprintf (file,
709 file == stderr ? _(fmt3) : fmt3,
710 indent, *indent != 0 ? " " : "",
711 "MPC", MPC_VERSION_STRING, mpc_get_version ());
713 if (show_global_state)
715 fprintf (file,
716 file == stderr ? _(fmt4) : fmt4,
717 indent, *indent != 0 ? " " : "",
718 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
720 print_plugins_versions (file, indent);
724 static int
725 print_to_asm_out_file (print_switch_type type, const char * text)
727 bool prepend_sep = true;
729 switch (type)
731 case SWITCH_TYPE_LINE_END:
732 putc ('\n', asm_out_file);
733 return 1;
735 case SWITCH_TYPE_LINE_START:
736 fputs (ASM_COMMENT_START, asm_out_file);
737 return strlen (ASM_COMMENT_START);
739 case SWITCH_TYPE_DESCRIPTIVE:
740 if (ASM_COMMENT_START[0] == 0)
741 prepend_sep = false;
742 /* Drop through. */
743 case SWITCH_TYPE_PASSED:
744 case SWITCH_TYPE_ENABLED:
745 if (prepend_sep)
746 fputc (' ', asm_out_file);
747 fputs (text, asm_out_file);
748 /* No need to return the length here as
749 print_single_switch has already done it. */
750 return 0;
752 default:
753 return -1;
757 static int
758 print_to_stderr (print_switch_type type, const char * text)
760 switch (type)
762 case SWITCH_TYPE_LINE_END:
763 putc ('\n', stderr);
764 return 1;
766 case SWITCH_TYPE_LINE_START:
767 return 0;
769 case SWITCH_TYPE_PASSED:
770 case SWITCH_TYPE_ENABLED:
771 fputc (' ', stderr);
772 /* Drop through. */
774 case SWITCH_TYPE_DESCRIPTIVE:
775 fputs (text, stderr);
776 /* No need to return the length here as
777 print_single_switch has already done it. */
778 return 0;
780 default:
781 return -1;
785 /* Print an option value and return the adjusted position in the line.
786 ??? print_fn doesn't handle errors, eg disk full; presumably other
787 code will catch a disk full though. */
789 static int
790 print_single_switch (print_switch_fn_type print_fn,
791 int pos,
792 print_switch_type type,
793 const char * text)
795 /* The ultrix fprintf returns 0 on success, so compute the result
796 we want here since we need it for the following test. The +1
797 is for the separator character that will probably be emitted. */
798 int len = strlen (text) + 1;
800 if (pos != 0
801 && pos + len > MAX_LINE)
803 print_fn (SWITCH_TYPE_LINE_END, NULL);
804 pos = 0;
807 if (pos == 0)
808 pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
810 print_fn (type, text);
811 return pos + len;
814 /* Print active target switches using PRINT_FN.
815 POS is the current cursor position and MAX is the size of a "line".
816 Each line begins with INDENT and ends with TERM.
817 Each switch is separated from the next by SEP. */
819 static void
820 print_switch_values (print_switch_fn_type print_fn)
822 int pos = 0;
823 size_t j;
825 /* Fill in the -frandom-seed option, if the user didn't pass it, so
826 that it can be printed below. This helps reproducibility. */
827 if (!flag_random_seed)
828 init_random_seed ();
830 /* Print the options as passed. */
831 pos = print_single_switch (print_fn, pos,
832 SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
834 for (j = 1; j < save_decoded_options_count; j++)
836 switch (save_decoded_options[j].opt_index)
838 case OPT_o:
839 case OPT_d:
840 case OPT_dumpbase:
841 case OPT_dumpdir:
842 case OPT_auxbase:
843 case OPT_quiet:
844 case OPT_version:
845 /* Ignore these. */
846 continue;
849 pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED,
850 save_decoded_options[j].orig_option_with_args_text);
853 if (pos > 0)
854 print_fn (SWITCH_TYPE_LINE_END, NULL);
856 /* Print the -f and -m options that have been enabled.
857 We don't handle language specific options but printing argv
858 should suffice. */
859 pos = print_single_switch (print_fn, 0,
860 SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
862 for (j = 0; j < cl_options_count; j++)
863 if (cl_options[j].cl_report
864 && option_enabled (j, &global_options) > 0)
865 pos = print_single_switch (print_fn, pos,
866 SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
868 print_fn (SWITCH_TYPE_LINE_END, NULL);
871 /* Open assembly code output file. Do this even if -fsyntax-only is
872 on, because then the driver will have provided the name of a
873 temporary file or bit bucket for us. NAME is the file specified on
874 the command line, possibly NULL. */
875 static void
876 init_asm_output (const char *name)
878 if (name == NULL && asm_file_name == 0)
879 asm_out_file = stdout;
880 else
882 if (asm_file_name == 0)
884 int len = strlen (dump_base_name);
885 char *dumpname = XNEWVEC (char, len + 6);
887 memcpy (dumpname, dump_base_name, len + 1);
888 strip_off_ending (dumpname, len);
889 strcat (dumpname, ".s");
890 asm_file_name = dumpname;
892 if (!strcmp (asm_file_name, "-"))
893 asm_out_file = stdout;
894 else if (!canonical_filename_eq (asm_file_name, name)
895 || !strcmp (asm_file_name, HOST_BIT_BUCKET))
896 asm_out_file = fopen (asm_file_name, "w");
897 else
898 /* Use UNKOWN_LOCATION to prevent gcc from printing the first
899 line in the current file. */
900 fatal_error (UNKNOWN_LOCATION,
901 "input file %qs is the same as output file",
902 asm_file_name);
903 if (asm_out_file == 0)
904 fatal_error (UNKNOWN_LOCATION,
905 "can%'t open %qs for writing: %m", asm_file_name);
908 if (!flag_syntax_only)
910 targetm.asm_out.file_start ();
912 if (flag_record_gcc_switches)
914 if (targetm.asm_out.record_gcc_switches)
916 /* Let the target know that we are about to start recording. */
917 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
918 NULL);
919 /* Now record the switches. */
920 print_switch_values (targetm.asm_out.record_gcc_switches);
921 /* Let the target know that the recording is over. */
922 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
923 NULL);
925 else
926 inform (input_location, "-frecord-gcc-switches is not supported by the current target");
929 if (flag_verbose_asm)
931 /* Print the list of switches in effect
932 into the assembler file as comments. */
933 print_version (asm_out_file, ASM_COMMENT_START, true);
934 print_switch_values (print_to_asm_out_file);
935 putc ('\n', asm_out_file);
940 /* A helper function; used as the reallocator function for cpp's line
941 table. */
942 static void *
943 realloc_for_line_map (void *ptr, size_t len)
945 return ggc_realloc (ptr, len);
948 /* A helper function: used as the allocator function for
949 identifier_to_locale. */
950 static void *
951 alloc_for_identifier_to_locale (size_t len)
953 return ggc_alloc_atomic (len);
956 /* Output stack usage information. */
957 void
958 output_stack_usage (void)
960 static bool warning_issued = false;
961 enum stack_usage_kind_type { STATIC = 0, DYNAMIC, DYNAMIC_BOUNDED };
962 const char *stack_usage_kind_str[] = {
963 "static",
964 "dynamic",
965 "dynamic,bounded"
967 HOST_WIDE_INT stack_usage = current_function_static_stack_size;
968 enum stack_usage_kind_type stack_usage_kind;
970 if (stack_usage < 0)
972 if (!warning_issued)
974 warning (0, "stack usage computation not supported for this target");
975 warning_issued = true;
977 return;
980 stack_usage_kind = STATIC;
982 /* Add the maximum amount of space pushed onto the stack. */
983 if (current_function_pushed_stack_size > 0)
985 stack_usage += current_function_pushed_stack_size;
986 stack_usage_kind = DYNAMIC_BOUNDED;
989 /* Now on to the tricky part: dynamic stack allocation. */
990 if (current_function_allocates_dynamic_stack_space)
992 if (current_function_has_unbounded_dynamic_stack_size)
993 stack_usage_kind = DYNAMIC;
994 else
995 stack_usage_kind = DYNAMIC_BOUNDED;
997 /* Add the size even in the unbounded case, this can't hurt. */
998 stack_usage += current_function_dynamic_stack_size;
1001 if (flag_stack_usage)
1003 expanded_location loc
1004 = expand_location (DECL_SOURCE_LOCATION (current_function_decl));
1005 /* We don't want to print the full qualified name because it can be long,
1006 so we strip the scope prefix, but we may need to deal with the suffix
1007 created by the compiler. */
1008 const char *suffix
1009 = strchr (IDENTIFIER_POINTER (DECL_NAME (current_function_decl)), '.');
1010 const char *name
1011 = lang_hooks.decl_printable_name (current_function_decl, 2);
1012 if (suffix)
1014 const char *dot = strchr (name, '.');
1015 while (dot && strcasecmp (dot, suffix) != 0)
1017 name = dot + 1;
1018 dot = strchr (name, '.');
1021 else
1023 const char *dot = strrchr (name, '.');
1024 if (dot)
1025 name = dot + 1;
1028 fprintf (stack_usage_file,
1029 "%s:%d:%d:%s\t" HOST_WIDE_INT_PRINT_DEC"\t%s\n",
1030 lbasename (loc.file),
1031 loc.line,
1032 loc.column,
1033 name,
1034 stack_usage,
1035 stack_usage_kind_str[stack_usage_kind]);
1038 if (warn_stack_usage >= 0)
1040 const location_t loc = DECL_SOURCE_LOCATION (current_function_decl);
1042 if (stack_usage_kind == DYNAMIC)
1043 warning_at (loc, OPT_Wstack_usage_, "stack usage might be unbounded");
1044 else if (stack_usage > warn_stack_usage)
1046 if (stack_usage_kind == DYNAMIC_BOUNDED)
1047 warning_at (loc,
1048 OPT_Wstack_usage_, "stack usage might be %wd bytes",
1049 stack_usage);
1050 else
1051 warning_at (loc, OPT_Wstack_usage_, "stack usage is %wd bytes",
1052 stack_usage);
1057 /* Open an auxiliary output file. */
1058 static FILE *
1059 open_auxiliary_file (const char *ext)
1061 char *filename;
1062 FILE *file;
1064 filename = concat (aux_base_name, ".", ext, NULL);
1065 file = fopen (filename, "w");
1066 if (!file)
1067 fatal_error (input_location, "can%'t open %s for writing: %m", filename);
1068 free (filename);
1069 return file;
1072 /* Initialization of the front end environment, before command line
1073 options are parsed. Signal handlers, internationalization etc.
1074 ARGV0 is main's argv[0]. */
1075 static void
1076 general_init (const char *argv0, bool init_signals)
1078 const char *p;
1080 p = argv0 + strlen (argv0);
1081 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1082 --p;
1083 progname = p;
1085 xmalloc_set_program_name (progname);
1087 hex_init ();
1089 /* Unlock the stdio streams. */
1090 unlock_std_streams ();
1092 gcc_init_libintl ();
1094 identifier_to_locale_alloc = alloc_for_identifier_to_locale;
1095 identifier_to_locale_free = ggc_free;
1097 /* Initialize the diagnostics reporting machinery, so option parsing
1098 can give warnings and errors. */
1099 diagnostic_initialize (global_dc, N_OPTS);
1100 /* Set a default printer. Language specific initializations will
1101 override it later. */
1102 tree_diagnostics_defaults (global_dc);
1104 global_dc->show_caret
1105 = global_options_init.x_flag_diagnostics_show_caret;
1106 global_dc->show_option_requested
1107 = global_options_init.x_flag_diagnostics_show_option;
1108 global_dc->show_column
1109 = global_options_init.x_flag_show_column;
1110 global_dc->internal_error = plugins_internal_error_function;
1111 global_dc->option_enabled = option_enabled;
1112 global_dc->option_state = &global_options;
1113 global_dc->option_name = option_name;
1115 if (init_signals)
1117 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1118 #ifdef SIGSEGV
1119 signal (SIGSEGV, crash_signal);
1120 #endif
1121 #ifdef SIGILL
1122 signal (SIGILL, crash_signal);
1123 #endif
1124 #ifdef SIGBUS
1125 signal (SIGBUS, crash_signal);
1126 #endif
1127 #ifdef SIGABRT
1128 signal (SIGABRT, crash_signal);
1129 #endif
1130 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1131 signal (SIGIOT, crash_signal);
1132 #endif
1133 #ifdef SIGFPE
1134 signal (SIGFPE, crash_signal);
1135 #endif
1137 /* Other host-specific signal setup. */
1138 (*host_hooks.extra_signals)();
1141 /* Initialize the garbage-collector, string pools and tree type hash
1142 table. */
1143 init_ggc ();
1144 init_stringpool ();
1145 input_location = UNKNOWN_LOCATION;
1146 line_table = ggc_alloc<line_maps> ();
1147 linemap_init (line_table, BUILTINS_LOCATION);
1148 line_table->reallocator = realloc_for_line_map;
1149 line_table->round_alloc_size = ggc_round_alloc_size;
1150 init_ttree ();
1152 /* Initialize register usage now so switches may override. */
1153 init_reg_sets ();
1155 /* Register the language-independent parameters. */
1156 global_init_params ();
1158 /* This must be done after global_init_params but before argument
1159 processing. */
1160 init_ggc_heuristics ();
1162 /* Create the singleton holder for global state.
1163 Doing so also creates the pass manager and with it the passes. */
1164 g = new gcc::context ();
1165 symtab = new (ggc_cleared_alloc <symbol_table> ()) symbol_table ();
1167 statistics_early_init ();
1168 finish_params ();
1171 /* Return true if the current target supports -fsection-anchors. */
1173 static bool
1174 target_supports_section_anchors_p (void)
1176 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1177 return false;
1179 if (targetm.asm_out.output_anchor == NULL)
1180 return false;
1182 return true;
1185 /* Default the align_* variables to 1 if they're still unset, and
1186 set up the align_*_log variables. */
1187 static void
1188 init_alignments (void)
1190 if (align_loops <= 0)
1191 align_loops = 1;
1192 if (align_loops_max_skip > align_loops)
1193 align_loops_max_skip = align_loops - 1;
1194 align_loops_log = floor_log2 (align_loops * 2 - 1);
1195 if (align_jumps <= 0)
1196 align_jumps = 1;
1197 if (align_jumps_max_skip > align_jumps)
1198 align_jumps_max_skip = align_jumps - 1;
1199 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1200 if (align_labels <= 0)
1201 align_labels = 1;
1202 align_labels_log = floor_log2 (align_labels * 2 - 1);
1203 if (align_labels_max_skip > align_labels)
1204 align_labels_max_skip = align_labels - 1;
1205 if (align_functions <= 0)
1206 align_functions = 1;
1207 align_functions_log = floor_log2 (align_functions * 2 - 1);
1210 /* Process the options that have been parsed. */
1211 static void
1212 process_options (void)
1214 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1215 This can happen with incorrect pre-processed input. */
1216 debug_hooks = &do_nothing_debug_hooks;
1218 maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT;
1220 /* Allow the front end to perform consistency checks and do further
1221 initialization based on the command line options. This hook also
1222 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1223 so we can correctly initialize debug output. */
1224 no_backend = lang_hooks.post_options (&main_input_filename);
1226 /* Some machines may reject certain combinations of options. */
1227 targetm.target_option.override ();
1229 /* Avoid any informative notes in the second run of -fcompare-debug. */
1230 if (flag_compare_debug)
1231 diagnostic_inhibit_notes (global_dc);
1233 if (flag_section_anchors && !target_supports_section_anchors_p ())
1235 warning (OPT_fsection_anchors,
1236 "this target does not support %qs", "-fsection-anchors");
1237 flag_section_anchors = 0;
1240 if (flag_short_enums == 2)
1241 flag_short_enums = targetm.default_short_enums ();
1243 /* Set aux_base_name if not already set. */
1244 if (aux_base_name)
1246 else if (main_input_filename)
1248 char *name = xstrdup (lbasename (main_input_filename));
1250 strip_off_ending (name, strlen (name));
1251 aux_base_name = name;
1253 else
1254 aux_base_name = "gccaux";
1256 #ifndef HAVE_isl
1257 if (flag_graphite
1258 || flag_loop_optimize_isl
1259 || flag_graphite_identity
1260 || flag_loop_parallelize_all)
1261 sorry ("Graphite loop optimizations cannot be used (ISL is not available)"
1262 "(-fgraphite, -fgraphite-identity, -floop-block, "
1263 "-floop-interchange, -floop-strip-mine, -floop-parallelize-all, "
1264 "-floop-unroll-and-jam, and -ftree-loop-linear)");
1265 #endif
1267 if (flag_check_pointer_bounds)
1269 if (targetm.chkp_bound_mode () == VOIDmode)
1271 error ("-fcheck-pointer-bounds is not supported for this target");
1272 flag_check_pointer_bounds = 0;
1275 if (flag_sanitize & SANITIZE_ADDRESS)
1277 error ("-fcheck-pointer-bounds is not supported with "
1278 "Address Sanitizer");
1279 flag_check_pointer_bounds = 0;
1283 /* One region RA really helps to decrease the code size. */
1284 if (flag_ira_region == IRA_REGION_AUTODETECT)
1285 flag_ira_region
1286 = optimize_size || !optimize ? IRA_REGION_ONE : IRA_REGION_MIXED;
1288 if (!abi_version_at_least (2))
1290 /* -fabi-version=1 support was removed after GCC 4.9. */
1291 error ("%<-fabi-version=1%> is no longer supported");
1292 flag_abi_version = 2;
1295 /* Unrolling all loops implies that standard loop unrolling must also
1296 be done. */
1297 if (flag_unroll_all_loops)
1298 flag_unroll_loops = 1;
1300 /* web and rename-registers help when run after loop unrolling. */
1301 if (flag_web == AUTODETECT_VALUE)
1302 flag_web = flag_unroll_loops || flag_peel_loops;
1304 if (flag_rename_registers == AUTODETECT_VALUE)
1305 flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1307 if (flag_non_call_exceptions)
1308 flag_asynchronous_unwind_tables = 1;
1309 if (flag_asynchronous_unwind_tables)
1310 flag_unwind_tables = 1;
1312 if (flag_value_profile_transformations)
1313 flag_profile_values = 1;
1315 /* Warn about options that are not supported on this machine. */
1316 #ifndef INSN_SCHEDULING
1317 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1318 warning (0, "instruction scheduling not supported on this target machine");
1319 #endif
1320 if (!DELAY_SLOTS && flag_delayed_branch)
1321 warning (0, "this target machine does not have delayed branches");
1323 user_label_prefix = USER_LABEL_PREFIX;
1324 if (flag_leading_underscore != -1)
1326 /* If the default prefix is more complicated than "" or "_",
1327 issue a warning and ignore this option. */
1328 if (user_label_prefix[0] == 0 ||
1329 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1331 user_label_prefix = flag_leading_underscore ? "_" : "";
1333 else
1334 warning (0, "-f%sleading-underscore not supported on this target machine",
1335 flag_leading_underscore ? "" : "no-");
1338 /* If we are in verbose mode, write out the version and maybe all the
1339 option flags in use. */
1340 if (version_flag)
1342 print_version (stderr, "", true);
1343 if (! quiet_flag)
1344 print_switch_values (print_to_stderr);
1347 if (flag_syntax_only)
1349 write_symbols = NO_DEBUG;
1350 profile_flag = 0;
1353 if (flag_gtoggle)
1355 if (debug_info_level == DINFO_LEVEL_NONE)
1357 debug_info_level = DINFO_LEVEL_NORMAL;
1359 if (write_symbols == NO_DEBUG)
1360 write_symbols = PREFERRED_DEBUGGING_TYPE;
1362 else
1363 debug_info_level = DINFO_LEVEL_NONE;
1366 if (flag_dump_final_insns && !flag_syntax_only && !no_backend)
1368 FILE *final_output = fopen (flag_dump_final_insns, "w");
1369 if (!final_output)
1371 error ("could not open final insn dump file %qs: %m",
1372 flag_dump_final_insns);
1373 flag_dump_final_insns = NULL;
1375 else if (fclose (final_output))
1377 error ("could not close zeroed insn dump file %qs: %m",
1378 flag_dump_final_insns);
1379 flag_dump_final_insns = NULL;
1383 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1384 level is 0. */
1385 if (debug_info_level == DINFO_LEVEL_NONE)
1386 write_symbols = NO_DEBUG;
1388 if (write_symbols == NO_DEBUG)
1390 #if defined(DBX_DEBUGGING_INFO)
1391 else if (write_symbols == DBX_DEBUG)
1392 debug_hooks = &dbx_debug_hooks;
1393 #endif
1394 #if defined(XCOFF_DEBUGGING_INFO)
1395 else if (write_symbols == XCOFF_DEBUG)
1396 debug_hooks = &xcoff_debug_hooks;
1397 #endif
1398 #ifdef SDB_DEBUGGING_INFO
1399 else if (write_symbols == SDB_DEBUG)
1400 debug_hooks = &sdb_debug_hooks;
1401 #endif
1402 #ifdef DWARF2_DEBUGGING_INFO
1403 else if (write_symbols == DWARF2_DEBUG)
1404 debug_hooks = &dwarf2_debug_hooks;
1405 #endif
1406 #ifdef VMS_DEBUGGING_INFO
1407 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1408 debug_hooks = &vmsdbg_debug_hooks;
1409 #endif
1410 #ifdef DWARF2_LINENO_DEBUGGING_INFO
1411 else if (write_symbols == DWARF2_DEBUG)
1412 debug_hooks = &dwarf2_lineno_debug_hooks;
1413 #endif
1414 else
1415 error ("target system does not support the %qs debug format",
1416 debug_type_names[write_symbols]);
1418 /* We know which debug output will be used so we can set flag_var_tracking
1419 and flag_var_tracking_uninit if the user has not specified them. */
1420 if (debug_info_level < DINFO_LEVEL_NORMAL
1421 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1423 if (flag_var_tracking == 1
1424 || flag_var_tracking_uninit == 1)
1426 if (debug_info_level < DINFO_LEVEL_NORMAL)
1427 warning (0, "variable tracking requested, but useless unless "
1428 "producing debug info");
1429 else
1430 warning (0, "variable tracking requested, but not supported "
1431 "by this debug format");
1433 flag_var_tracking = 0;
1434 flag_var_tracking_uninit = 0;
1437 /* The debug hooks are used to implement -fdump-go-spec because it
1438 gives a simple and stable API for all the information we need to
1439 dump. */
1440 if (flag_dump_go_spec != NULL)
1441 debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks);
1443 /* If the user specifically requested variable tracking with tagging
1444 uninitialized variables, we need to turn on variable tracking.
1445 (We already determined above that variable tracking is feasible.) */
1446 if (flag_var_tracking_uninit == 1)
1447 flag_var_tracking = 1;
1449 if (flag_var_tracking == AUTODETECT_VALUE)
1450 flag_var_tracking = optimize >= 1;
1452 if (flag_var_tracking_uninit == AUTODETECT_VALUE)
1453 flag_var_tracking_uninit = flag_var_tracking;
1455 if (flag_var_tracking_assignments == AUTODETECT_VALUE)
1456 flag_var_tracking_assignments = flag_var_tracking
1457 && !(flag_selective_scheduling || flag_selective_scheduling2);
1459 if (flag_var_tracking_assignments_toggle)
1460 flag_var_tracking_assignments = !flag_var_tracking_assignments;
1462 if (flag_var_tracking_assignments && !flag_var_tracking)
1463 flag_var_tracking = flag_var_tracking_assignments = -1;
1465 if (flag_var_tracking_assignments
1466 && (flag_selective_scheduling || flag_selective_scheduling2))
1467 warning (0, "var-tracking-assignments changes selective scheduling");
1469 if (flag_tree_cselim == AUTODETECT_VALUE)
1471 if (HAVE_conditional_move)
1472 flag_tree_cselim = 1;
1473 else
1474 flag_tree_cselim = 0;
1477 /* If auxiliary info generation is desired, open the output file.
1478 This goes in the same directory as the source file--unlike
1479 all the other output files. */
1480 if (flag_gen_aux_info)
1482 aux_info_file = fopen (aux_info_file_name, "w");
1483 if (aux_info_file == 0)
1484 fatal_error (input_location, "can%'t open %s: %m", aux_info_file_name);
1487 if (!targetm_common.have_named_sections)
1489 if (flag_function_sections)
1491 warning (0, "-ffunction-sections not supported for this target");
1492 flag_function_sections = 0;
1494 if (flag_data_sections)
1496 warning (0, "-fdata-sections not supported for this target");
1497 flag_data_sections = 0;
1501 if (flag_prefetch_loop_arrays > 0 && !targetm.code_for_prefetch)
1503 warning (0, "-fprefetch-loop-arrays not supported for this target");
1504 flag_prefetch_loop_arrays = 0;
1506 else if (flag_prefetch_loop_arrays > 0 && !targetm.have_prefetch ())
1508 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
1509 flag_prefetch_loop_arrays = 0;
1512 /* This combination of options isn't handled for i386 targets and doesn't
1513 make much sense anyway, so don't allow it. */
1514 if (flag_prefetch_loop_arrays > 0 && optimize_size)
1516 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
1517 flag_prefetch_loop_arrays = 0;
1520 /* The presence of IEEE signaling NaNs, implies all math can trap. */
1521 if (flag_signaling_nans)
1522 flag_trapping_math = 1;
1524 /* We cannot reassociate if we want traps or signed zeros. */
1525 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
1527 warning (0, "-fassociative-math disabled; other options take precedence");
1528 flag_associative_math = 0;
1531 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
1532 if (flag_cx_limited_range)
1533 flag_complex_method = 0;
1535 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
1536 if (flag_cx_fortran_rules)
1537 flag_complex_method = 1;
1539 /* Targets must be able to place spill slots at lower addresses. If the
1540 target already uses a soft frame pointer, the transition is trivial. */
1541 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
1543 warning (0, "-fstack-protector not supported for this target");
1544 flag_stack_protect = 0;
1546 if (!flag_stack_protect)
1547 warn_stack_protect = 0;
1549 /* Address Sanitizer needs porting to each target architecture. */
1551 if ((flag_sanitize & SANITIZE_ADDRESS)
1552 && !FRAME_GROWS_DOWNWARD)
1554 warning (0,
1555 "-fsanitize=address and -fsanitize=kernel-address "
1556 "are not supported for this target");
1557 flag_sanitize &= ~SANITIZE_ADDRESS;
1560 if ((flag_sanitize & SANITIZE_USER_ADDRESS)
1561 && targetm.asan_shadow_offset == NULL)
1563 warning (0, "-fsanitize=address not supported for this target");
1564 flag_sanitize &= ~SANITIZE_ADDRESS;
1567 /* Do not use IPA optimizations for register allocation if profiler is active
1568 or port does not emit prologue and epilogue as RTL. */
1569 if (profile_flag || !targetm.have_prologue () || !targetm.have_epilogue ())
1570 flag_ipa_ra = 0;
1572 /* Enable -Werror=coverage-mismatch when -Werror and -Wno-error
1573 have not been set. */
1574 if (!global_options_set.x_warnings_are_errors
1575 && warn_coverage_mismatch
1576 && (global_dc->classify_diagnostic[OPT_Wcoverage_mismatch] ==
1577 DK_UNSPECIFIED))
1578 diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch,
1579 DK_ERROR, UNKNOWN_LOCATION);
1581 /* Save the current optimization options. */
1582 optimization_default_node = build_optimization_node (&global_options);
1583 optimization_current_node = optimization_default_node;
1585 /* Please don't change global_options after this point, those changes won't
1586 be reflected in optimization_{default,current}_node. */
1589 /* This function can be called multiple times to reinitialize the compiler
1590 back end when register classes or instruction sets have changed,
1591 before each function. */
1592 static void
1593 backend_init_target (void)
1595 /* Initialize alignment variables. */
1596 init_alignments ();
1598 /* This depends on stack_pointer_rtx. */
1599 init_fake_stack_mems ();
1601 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
1602 mode-dependent. */
1603 init_alias_target ();
1605 /* Depends on HARD_FRAME_POINTER_REGNUM. */
1606 init_reload ();
1608 /* Depends on the enabled attribute. */
1609 recog_init ();
1611 /* The following initialization functions need to generate rtl, so
1612 provide a dummy function context for them. */
1613 init_dummy_function_start ();
1615 /* rtx_cost is mode-dependent, so cached values need to be recomputed
1616 on a mode change. */
1617 init_expmed ();
1618 init_lower_subreg ();
1619 init_set_costs ();
1621 init_expr_target ();
1622 ira_init ();
1624 /* We may need to recompute regno_save_code[] and regno_restore_code[]
1625 after a mode change as well. */
1626 caller_save_initialized_p = false;
1628 expand_dummy_function_end ();
1631 /* Initialize the compiler back end. This function is called only once,
1632 when starting the compiler. */
1633 static void
1634 backend_init (void)
1636 init_emit_once ();
1638 init_rtlanal ();
1639 init_inline_once ();
1640 init_varasm_once ();
1641 save_register_info ();
1643 /* Middle end needs this initialization for default mem attributes
1644 used by early calls to make_decl_rtl. */
1645 init_emit_regs ();
1647 /* Middle end needs this initialization for mode tables used to assign
1648 modes to vector variables. */
1649 init_regs ();
1652 /* Initialize excess precision settings. */
1653 static void
1654 init_excess_precision (void)
1656 /* Adjust excess precision handling based on the target options. If
1657 the front end cannot handle it, flag_excess_precision_cmdline
1658 will already have been set accordingly in the post_options
1659 hook. */
1660 gcc_assert (flag_excess_precision_cmdline != EXCESS_PRECISION_DEFAULT);
1661 flag_excess_precision = flag_excess_precision_cmdline;
1662 if (flag_unsafe_math_optimizations)
1663 flag_excess_precision = EXCESS_PRECISION_FAST;
1664 if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
1666 int flt_eval_method = TARGET_FLT_EVAL_METHOD;
1667 switch (flt_eval_method)
1669 case -1:
1670 case 0:
1671 /* Either the target acts unpredictably (-1) or has all the
1672 operations required not to have excess precision (0). */
1673 flag_excess_precision = EXCESS_PRECISION_FAST;
1674 break;
1675 case 1:
1676 case 2:
1677 /* In these cases, predictable excess precision makes
1678 sense. */
1679 break;
1680 default:
1681 /* Any other implementation-defined FLT_EVAL_METHOD values
1682 require the compiler to handle the associated excess
1683 precision rules in excess_precision_type. */
1684 gcc_unreachable ();
1689 /* Initialize things that are both lang-dependent and target-dependent.
1690 This function can be called more than once if target parameters change. */
1691 static void
1692 lang_dependent_init_target (void)
1694 /* This determines excess precision settings. */
1695 init_excess_precision ();
1697 /* This creates various _DECL nodes, so needs to be called after the
1698 front end is initialized. It also depends on the HAVE_xxx macros
1699 generated from the target machine description. */
1700 init_optabs ();
1702 gcc_assert (!this_target_rtl->target_specific_initialized);
1705 /* Perform initializations that are lang-dependent or target-dependent.
1706 but matters only for late optimizations and RTL generation. */
1708 static int rtl_initialized;
1710 void
1711 initialize_rtl (void)
1713 auto_timevar tv (g_timer, TV_INITIALIZE_RTL);
1715 /* Initialization done just once per compilation, but delayed
1716 till code generation. */
1717 if (!rtl_initialized)
1718 ira_init_once ();
1719 rtl_initialized = true;
1721 /* Target specific RTL backend initialization. */
1722 if (!this_target_rtl->target_specific_initialized)
1724 backend_init_target ();
1725 this_target_rtl->target_specific_initialized = true;
1729 /* Language-dependent initialization. Returns nonzero on success. */
1730 static int
1731 lang_dependent_init (const char *name)
1733 location_t save_loc = input_location;
1734 if (dump_base_name == 0)
1735 dump_base_name = name && name[0] ? name : "gccdump";
1737 /* Other front-end initialization. */
1738 input_location = BUILTINS_LOCATION;
1739 if (lang_hooks.init () == 0)
1740 return 0;
1741 input_location = save_loc;
1743 if (!flag_wpa)
1745 init_asm_output (name);
1747 /* If stack usage information is desired, open the output file. */
1748 if (flag_stack_usage)
1749 stack_usage_file = open_auxiliary_file ("su");
1752 /* This creates various _DECL nodes, so needs to be called after the
1753 front end is initialized. */
1754 init_eh ();
1756 /* Do the target-specific parts of the initialization. */
1757 lang_dependent_init_target ();
1759 if (!flag_wpa)
1761 /* If dbx symbol table desired, initialize writing it and output the
1762 predefined types. */
1763 timevar_push (TV_SYMOUT);
1765 /* Now we have the correct original filename, we can initialize
1766 debug output. */
1767 (*debug_hooks->init) (name);
1769 timevar_pop (TV_SYMOUT);
1772 return 1;
1776 /* Reinitialize everything when target parameters, such as register usage,
1777 have changed. */
1778 void
1779 target_reinit (void)
1781 struct rtl_data saved_x_rtl;
1782 rtx *saved_regno_reg_rtx;
1783 tree saved_optimization_current_node;
1784 struct target_optabs *saved_this_fn_optabs;
1786 /* Temporarily switch to the default optimization node, so that
1787 *this_target_optabs is set to the default, not reflecting
1788 whatever a previous function used for the optimize
1789 attribute. */
1790 saved_optimization_current_node = optimization_current_node;
1791 saved_this_fn_optabs = this_fn_optabs;
1792 if (saved_optimization_current_node != optimization_default_node)
1794 optimization_current_node = optimization_default_node;
1795 cl_optimization_restore
1796 (&global_options,
1797 TREE_OPTIMIZATION (optimization_default_node));
1799 this_fn_optabs = this_target_optabs;
1801 /* Save *crtl and regno_reg_rtx around the reinitialization
1802 to allow target_reinit being called even after prepare_function_start. */
1803 saved_regno_reg_rtx = regno_reg_rtx;
1804 if (saved_regno_reg_rtx)
1806 saved_x_rtl = *crtl;
1807 memset (crtl, '\0', sizeof (*crtl));
1808 regno_reg_rtx = NULL;
1811 this_target_rtl->target_specific_initialized = false;
1813 /* This initializes hard_frame_pointer, and calls init_reg_modes_target()
1814 to initialize reg_raw_mode[]. */
1815 init_emit_regs ();
1817 /* This invokes target hooks to set fixed_reg[] etc, which is
1818 mode-dependent. */
1819 init_regs ();
1821 /* Reinitialize lang-dependent parts. */
1822 lang_dependent_init_target ();
1824 /* Restore the original optimization node. */
1825 if (saved_optimization_current_node != optimization_default_node)
1827 optimization_current_node = saved_optimization_current_node;
1828 cl_optimization_restore (&global_options,
1829 TREE_OPTIMIZATION (optimization_current_node));
1831 this_fn_optabs = saved_this_fn_optabs;
1833 /* Restore regno_reg_rtx at the end, as free_after_compilation from
1834 expand_dummy_function_end clears it. */
1835 if (saved_regno_reg_rtx)
1837 *crtl = saved_x_rtl;
1838 regno_reg_rtx = saved_regno_reg_rtx;
1839 saved_regno_reg_rtx = NULL;
1843 void
1844 dump_memory_report (bool final)
1846 dump_line_table_statistics ();
1847 ggc_print_statistics ();
1848 stringpool_statistics ();
1849 dump_tree_statistics ();
1850 dump_gimple_statistics ();
1851 dump_rtx_statistics ();
1852 dump_alloc_pool_statistics ();
1853 dump_bitmap_statistics ();
1854 dump_hash_table_loc_statistics ();
1855 dump_vec_loc_statistics ();
1856 dump_ggc_loc_statistics (final);
1857 dump_alias_stats (stderr);
1858 dump_pta_stats (stderr);
1861 /* Clean up: close opened files, etc. */
1863 static void
1864 finalize (bool no_backend)
1866 /* Close the dump files. */
1867 if (flag_gen_aux_info)
1869 fclose (aux_info_file);
1870 if (seen_error ())
1871 unlink (aux_info_file_name);
1874 /* Close non-debugging input and output files. Take special care to note
1875 whether fclose returns an error, since the pages might still be on the
1876 buffer chain while the file is open. */
1878 if (asm_out_file)
1880 if (ferror (asm_out_file) != 0)
1881 fatal_error (input_location, "error writing to %s: %m", asm_file_name);
1882 if (fclose (asm_out_file) != 0)
1883 fatal_error (input_location, "error closing %s: %m", asm_file_name);
1886 if (stack_usage_file)
1887 fclose (stack_usage_file);
1889 if (!no_backend)
1891 statistics_fini ();
1893 g->get_passes ()->finish_optimization_passes ();
1895 lra_finish_once ();
1898 if (mem_report)
1899 dump_memory_report (true);
1901 if (profile_report)
1902 dump_profile_report ();
1904 /* Language-specific end of compilation actions. */
1905 lang_hooks.finish ();
1908 static bool
1909 standard_type_bitsize (int bitsize)
1911 /* As a special exception, we always want __int128 enabled if possible. */
1912 if (bitsize == 128)
1913 return false;
1914 if (bitsize == CHAR_TYPE_SIZE
1915 || bitsize == SHORT_TYPE_SIZE
1916 || bitsize == INT_TYPE_SIZE
1917 || bitsize == LONG_TYPE_SIZE
1918 || bitsize == LONG_LONG_TYPE_SIZE)
1919 return true;
1920 return false;
1923 /* Initialize the compiler, and compile the input file. */
1924 static void
1925 do_compile ()
1927 process_options ();
1929 /* Don't do any more if an error has already occurred. */
1930 if (!seen_error ())
1932 int i;
1934 timevar_start (TV_PHASE_SETUP);
1936 /* This must be run always, because it is needed to compute the FP
1937 predefined macros, such as __LDBL_MAX__, for targets using non
1938 default FP formats. */
1939 init_adjust_machine_modes ();
1940 init_derived_machine_modes ();
1942 /* This must happen after the backend has a chance to process
1943 command line options, but before the parsers are
1944 initialized. */
1945 for (i = 0; i < NUM_INT_N_ENTS; i ++)
1946 if (targetm.scalar_mode_supported_p (int_n_data[i].m)
1947 && ! standard_type_bitsize (int_n_data[i].bitsize))
1948 int_n_enabled_p[i] = true;
1949 else
1950 int_n_enabled_p[i] = false;
1952 /* Set up the back-end if requested. */
1953 if (!no_backend)
1954 backend_init ();
1956 /* Language-dependent initialization. Returns true on success. */
1957 if (lang_dependent_init (main_input_filename))
1959 /* Initialize yet another pass. */
1961 ggc_protect_identifiers = true;
1963 symtab->initialize ();
1964 init_final (main_input_filename);
1965 coverage_init (aux_base_name);
1966 statistics_init ();
1967 invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
1969 timevar_stop (TV_PHASE_SETUP);
1971 compile_file ();
1973 else
1975 timevar_stop (TV_PHASE_SETUP);
1978 timevar_start (TV_PHASE_FINALIZE);
1980 finalize (no_backend);
1982 timevar_stop (TV_PHASE_FINALIZE);
1986 toplev::toplev (timer *external_timer,
1987 bool init_signals)
1988 : m_use_TV_TOTAL (external_timer == NULL),
1989 m_init_signals (init_signals)
1991 if (external_timer)
1992 g_timer = external_timer;
1995 toplev::~toplev ()
1997 if (g_timer && m_use_TV_TOTAL)
1999 g_timer->stop (TV_TOTAL);
2000 g_timer->print (stderr);
2001 delete g_timer;
2002 g_timer = NULL;
2006 /* Potentially call timevar_init (which will create g_timevars if it
2007 doesn't already exist). */
2009 void
2010 toplev::start_timevars ()
2012 if (time_report || !quiet_flag || flag_detailed_statistics)
2013 timevar_init ();
2015 timevar_start (TV_TOTAL);
2018 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2019 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2020 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2022 It is not safe to call this function more than once. */
2025 toplev::main (int argc, char **argv)
2027 /* Parsing and gimplification sometimes need quite large stack.
2028 Increase stack size limits if possible. */
2029 stack_limit_increase (64 * 1024 * 1024);
2031 expandargv (&argc, &argv);
2033 /* Initialization of GCC's environment, and diagnostics. */
2034 general_init (argv[0], m_init_signals);
2036 /* One-off initialization of options that does not need to be
2037 repeated when options are added for particular functions. */
2038 init_options_once ();
2040 /* Initialize global options structures; this must be repeated for
2041 each structure used for parsing options. */
2042 init_options_struct (&global_options, &global_options_set);
2043 lang_hooks.init_options_struct (&global_options);
2045 /* Convert the options to an array. */
2046 decode_cmdline_options_to_array_default_mask (argc,
2047 CONST_CAST2 (const char **,
2048 char **, argv),
2049 &save_decoded_options,
2050 &save_decoded_options_count);
2052 /* Perform language-specific options initialization. */
2053 lang_hooks.init_options (save_decoded_options_count, save_decoded_options);
2055 /* Parse the options and do minimal processing; basically just
2056 enough to default flags appropriately. */
2057 decode_options (&global_options, &global_options_set,
2058 save_decoded_options, save_decoded_options_count,
2059 UNKNOWN_LOCATION, global_dc);
2061 handle_common_deferred_options ();
2063 init_local_tick ();
2065 initialize_plugins ();
2067 if (version_flag)
2068 print_version (stderr, "", true);
2070 if (help_flag)
2071 print_plugins_help (stderr, "");
2073 /* Exit early if we can (e.g. -help). */
2074 if (!exit_after_options)
2076 if (m_use_TV_TOTAL)
2077 start_timevars ();
2078 do_compile ();
2081 if (warningcount || errorcount || werrorcount)
2082 print_ignored_options ();
2084 /* Invoke registered plugin callbacks if any. Some plugins could
2085 emit some diagnostics here. */
2086 invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
2088 diagnostic_finish (global_dc);
2090 finalize_plugins ();
2091 location_adhoc_data_fini (line_table);
2092 if (seen_error () || werrorcount)
2093 return (FATAL_EXIT_CODE);
2095 return (SUCCESS_EXIT_CODE);
2098 /* For those that want to, this function aims to clean up enough state that
2099 you can call toplev::main again. */
2100 void
2101 toplev::finalize (void)
2103 rtl_initialized = false;
2104 this_target_rtl->target_specific_initialized = false;
2106 /* Needs to be called before cgraph_c_finalize since it uses symtab. */
2107 ipa_reference_c_finalize ();
2109 cgraph_c_finalize ();
2110 cgraphunit_c_finalize ();
2111 dwarf2out_c_finalize ();
2112 gcse_c_finalize ();
2113 ipa_cp_c_finalize ();
2114 ira_costs_c_finalize ();
2115 params_c_finalize ();
2117 finalize_options_struct (&global_options);
2118 finalize_options_struct (&global_options_set);
2120 XDELETEVEC (save_decoded_options);
2122 /* Clean up the context (and pass_manager etc). */
2123 delete g;
2124 g = NULL;
2126 obstack_free (&opts_obstack, NULL);