change a function argument from rtx to rtx_insn *
[official-gcc.git] / gcc / toplev.c
blob6d740d4233373479817fc0e21a38547215f5d56d
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 #ifndef DELAY_SLOTS
1321 if (flag_delayed_branch)
1322 warning (0, "this target machine does not have delayed branches");
1323 #endif
1325 user_label_prefix = USER_LABEL_PREFIX;
1326 if (flag_leading_underscore != -1)
1328 /* If the default prefix is more complicated than "" or "_",
1329 issue a warning and ignore this option. */
1330 if (user_label_prefix[0] == 0 ||
1331 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1333 user_label_prefix = flag_leading_underscore ? "_" : "";
1335 else
1336 warning (0, "-f%sleading-underscore not supported on this target machine",
1337 flag_leading_underscore ? "" : "no-");
1340 /* If we are in verbose mode, write out the version and maybe all the
1341 option flags in use. */
1342 if (version_flag)
1344 print_version (stderr, "", true);
1345 if (! quiet_flag)
1346 print_switch_values (print_to_stderr);
1349 if (flag_syntax_only)
1351 write_symbols = NO_DEBUG;
1352 profile_flag = 0;
1355 if (flag_gtoggle)
1357 if (debug_info_level == DINFO_LEVEL_NONE)
1359 debug_info_level = DINFO_LEVEL_NORMAL;
1361 if (write_symbols == NO_DEBUG)
1362 write_symbols = PREFERRED_DEBUGGING_TYPE;
1364 else
1365 debug_info_level = DINFO_LEVEL_NONE;
1368 if (flag_dump_final_insns && !flag_syntax_only && !no_backend)
1370 FILE *final_output = fopen (flag_dump_final_insns, "w");
1371 if (!final_output)
1373 error ("could not open final insn dump file %qs: %m",
1374 flag_dump_final_insns);
1375 flag_dump_final_insns = NULL;
1377 else if (fclose (final_output))
1379 error ("could not close zeroed insn dump file %qs: %m",
1380 flag_dump_final_insns);
1381 flag_dump_final_insns = NULL;
1385 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1386 level is 0. */
1387 if (debug_info_level == DINFO_LEVEL_NONE)
1388 write_symbols = NO_DEBUG;
1390 if (write_symbols == NO_DEBUG)
1392 #if defined(DBX_DEBUGGING_INFO)
1393 else if (write_symbols == DBX_DEBUG)
1394 debug_hooks = &dbx_debug_hooks;
1395 #endif
1396 #if defined(XCOFF_DEBUGGING_INFO)
1397 else if (write_symbols == XCOFF_DEBUG)
1398 debug_hooks = &xcoff_debug_hooks;
1399 #endif
1400 #ifdef SDB_DEBUGGING_INFO
1401 else if (write_symbols == SDB_DEBUG)
1402 debug_hooks = &sdb_debug_hooks;
1403 #endif
1404 #ifdef DWARF2_DEBUGGING_INFO
1405 else if (write_symbols == DWARF2_DEBUG)
1406 debug_hooks = &dwarf2_debug_hooks;
1407 #endif
1408 #ifdef VMS_DEBUGGING_INFO
1409 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1410 debug_hooks = &vmsdbg_debug_hooks;
1411 #endif
1412 #ifdef DWARF2_LINENO_DEBUGGING_INFO
1413 else if (write_symbols == DWARF2_DEBUG)
1414 debug_hooks = &dwarf2_lineno_debug_hooks;
1415 #endif
1416 else
1417 error ("target system does not support the %qs debug format",
1418 debug_type_names[write_symbols]);
1420 /* We know which debug output will be used so we can set flag_var_tracking
1421 and flag_var_tracking_uninit if the user has not specified them. */
1422 if (debug_info_level < DINFO_LEVEL_NORMAL
1423 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1425 if (flag_var_tracking == 1
1426 || flag_var_tracking_uninit == 1)
1428 if (debug_info_level < DINFO_LEVEL_NORMAL)
1429 warning (0, "variable tracking requested, but useless unless "
1430 "producing debug info");
1431 else
1432 warning (0, "variable tracking requested, but not supported "
1433 "by this debug format");
1435 flag_var_tracking = 0;
1436 flag_var_tracking_uninit = 0;
1439 /* The debug hooks are used to implement -fdump-go-spec because it
1440 gives a simple and stable API for all the information we need to
1441 dump. */
1442 if (flag_dump_go_spec != NULL)
1443 debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks);
1445 /* If the user specifically requested variable tracking with tagging
1446 uninitialized variables, we need to turn on variable tracking.
1447 (We already determined above that variable tracking is feasible.) */
1448 if (flag_var_tracking_uninit == 1)
1449 flag_var_tracking = 1;
1451 if (flag_var_tracking == AUTODETECT_VALUE)
1452 flag_var_tracking = optimize >= 1;
1454 if (flag_var_tracking_uninit == AUTODETECT_VALUE)
1455 flag_var_tracking_uninit = flag_var_tracking;
1457 if (flag_var_tracking_assignments == AUTODETECT_VALUE)
1458 flag_var_tracking_assignments = flag_var_tracking
1459 && !(flag_selective_scheduling || flag_selective_scheduling2);
1461 if (flag_var_tracking_assignments_toggle)
1462 flag_var_tracking_assignments = !flag_var_tracking_assignments;
1464 if (flag_var_tracking_assignments && !flag_var_tracking)
1465 flag_var_tracking = flag_var_tracking_assignments = -1;
1467 if (flag_var_tracking_assignments
1468 && (flag_selective_scheduling || flag_selective_scheduling2))
1469 warning (0, "var-tracking-assignments changes selective scheduling");
1471 if (flag_tree_cselim == AUTODETECT_VALUE)
1473 if (HAVE_conditional_move)
1474 flag_tree_cselim = 1;
1475 else
1476 flag_tree_cselim = 0;
1479 /* If auxiliary info generation is desired, open the output file.
1480 This goes in the same directory as the source file--unlike
1481 all the other output files. */
1482 if (flag_gen_aux_info)
1484 aux_info_file = fopen (aux_info_file_name, "w");
1485 if (aux_info_file == 0)
1486 fatal_error (input_location, "can%'t open %s: %m", aux_info_file_name);
1489 if (!targetm_common.have_named_sections)
1491 if (flag_function_sections)
1493 warning (0, "-ffunction-sections not supported for this target");
1494 flag_function_sections = 0;
1496 if (flag_data_sections)
1498 warning (0, "-fdata-sections not supported for this target");
1499 flag_data_sections = 0;
1503 if (flag_prefetch_loop_arrays > 0 && !targetm.code_for_prefetch)
1505 warning (0, "-fprefetch-loop-arrays not supported for this target");
1506 flag_prefetch_loop_arrays = 0;
1508 else if (flag_prefetch_loop_arrays > 0 && !targetm.have_prefetch ())
1510 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
1511 flag_prefetch_loop_arrays = 0;
1514 /* This combination of options isn't handled for i386 targets and doesn't
1515 make much sense anyway, so don't allow it. */
1516 if (flag_prefetch_loop_arrays > 0 && optimize_size)
1518 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
1519 flag_prefetch_loop_arrays = 0;
1522 /* The presence of IEEE signaling NaNs, implies all math can trap. */
1523 if (flag_signaling_nans)
1524 flag_trapping_math = 1;
1526 /* We cannot reassociate if we want traps or signed zeros. */
1527 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
1529 warning (0, "-fassociative-math disabled; other options take precedence");
1530 flag_associative_math = 0;
1533 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
1534 if (flag_cx_limited_range)
1535 flag_complex_method = 0;
1537 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
1538 if (flag_cx_fortran_rules)
1539 flag_complex_method = 1;
1541 /* Targets must be able to place spill slots at lower addresses. If the
1542 target already uses a soft frame pointer, the transition is trivial. */
1543 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
1545 warning (0, "-fstack-protector not supported for this target");
1546 flag_stack_protect = 0;
1548 if (!flag_stack_protect)
1549 warn_stack_protect = 0;
1551 /* Address Sanitizer needs porting to each target architecture. */
1553 if ((flag_sanitize & SANITIZE_ADDRESS)
1554 && !FRAME_GROWS_DOWNWARD)
1556 warning (0,
1557 "-fsanitize=address and -fsanitize=kernel-address "
1558 "are not supported for this target");
1559 flag_sanitize &= ~SANITIZE_ADDRESS;
1562 if ((flag_sanitize & SANITIZE_USER_ADDRESS)
1563 && targetm.asan_shadow_offset == NULL)
1565 warning (0, "-fsanitize=address not supported for this target");
1566 flag_sanitize &= ~SANITIZE_ADDRESS;
1569 /* Do not use IPA optimizations for register allocation if profiler is active
1570 or port does not emit prologue and epilogue as RTL. */
1571 if (profile_flag || !targetm.have_prologue () || !targetm.have_epilogue ())
1572 flag_ipa_ra = 0;
1574 /* Enable -Werror=coverage-mismatch when -Werror and -Wno-error
1575 have not been set. */
1576 if (!global_options_set.x_warnings_are_errors
1577 && warn_coverage_mismatch
1578 && (global_dc->classify_diagnostic[OPT_Wcoverage_mismatch] ==
1579 DK_UNSPECIFIED))
1580 diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch,
1581 DK_ERROR, UNKNOWN_LOCATION);
1583 /* Save the current optimization options. */
1584 optimization_default_node = build_optimization_node (&global_options);
1585 optimization_current_node = optimization_default_node;
1587 /* Please don't change global_options after this point, those changes won't
1588 be reflected in optimization_{default,current}_node. */
1591 /* This function can be called multiple times to reinitialize the compiler
1592 back end when register classes or instruction sets have changed,
1593 before each function. */
1594 static void
1595 backend_init_target (void)
1597 /* Initialize alignment variables. */
1598 init_alignments ();
1600 /* This depends on stack_pointer_rtx. */
1601 init_fake_stack_mems ();
1603 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
1604 mode-dependent. */
1605 init_alias_target ();
1607 /* Depends on HARD_FRAME_POINTER_REGNUM. */
1608 init_reload ();
1610 /* Depends on the enabled attribute. */
1611 recog_init ();
1613 /* The following initialization functions need to generate rtl, so
1614 provide a dummy function context for them. */
1615 init_dummy_function_start ();
1617 /* rtx_cost is mode-dependent, so cached values need to be recomputed
1618 on a mode change. */
1619 init_expmed ();
1620 init_lower_subreg ();
1621 init_set_costs ();
1623 init_expr_target ();
1624 ira_init ();
1626 /* We may need to recompute regno_save_code[] and regno_restore_code[]
1627 after a mode change as well. */
1628 caller_save_initialized_p = false;
1630 expand_dummy_function_end ();
1633 /* Initialize the compiler back end. This function is called only once,
1634 when starting the compiler. */
1635 static void
1636 backend_init (void)
1638 init_emit_once ();
1640 init_rtlanal ();
1641 init_inline_once ();
1642 init_varasm_once ();
1643 save_register_info ();
1645 /* Middle end needs this initialization for default mem attributes
1646 used by early calls to make_decl_rtl. */
1647 init_emit_regs ();
1649 /* Middle end needs this initialization for mode tables used to assign
1650 modes to vector variables. */
1651 init_regs ();
1654 /* Initialize excess precision settings. */
1655 static void
1656 init_excess_precision (void)
1658 /* Adjust excess precision handling based on the target options. If
1659 the front end cannot handle it, flag_excess_precision_cmdline
1660 will already have been set accordingly in the post_options
1661 hook. */
1662 gcc_assert (flag_excess_precision_cmdline != EXCESS_PRECISION_DEFAULT);
1663 flag_excess_precision = flag_excess_precision_cmdline;
1664 if (flag_unsafe_math_optimizations)
1665 flag_excess_precision = EXCESS_PRECISION_FAST;
1666 if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
1668 int flt_eval_method = TARGET_FLT_EVAL_METHOD;
1669 switch (flt_eval_method)
1671 case -1:
1672 case 0:
1673 /* Either the target acts unpredictably (-1) or has all the
1674 operations required not to have excess precision (0). */
1675 flag_excess_precision = EXCESS_PRECISION_FAST;
1676 break;
1677 case 1:
1678 case 2:
1679 /* In these cases, predictable excess precision makes
1680 sense. */
1681 break;
1682 default:
1683 /* Any other implementation-defined FLT_EVAL_METHOD values
1684 require the compiler to handle the associated excess
1685 precision rules in excess_precision_type. */
1686 gcc_unreachable ();
1691 /* Initialize things that are both lang-dependent and target-dependent.
1692 This function can be called more than once if target parameters change. */
1693 static void
1694 lang_dependent_init_target (void)
1696 /* This determines excess precision settings. */
1697 init_excess_precision ();
1699 /* This creates various _DECL nodes, so needs to be called after the
1700 front end is initialized. It also depends on the HAVE_xxx macros
1701 generated from the target machine description. */
1702 init_optabs ();
1704 gcc_assert (!this_target_rtl->target_specific_initialized);
1707 /* Perform initializations that are lang-dependent or target-dependent.
1708 but matters only for late optimizations and RTL generation. */
1710 static int rtl_initialized;
1712 void
1713 initialize_rtl (void)
1715 auto_timevar tv (g_timer, TV_INITIALIZE_RTL);
1717 /* Initialization done just once per compilation, but delayed
1718 till code generation. */
1719 if (!rtl_initialized)
1720 ira_init_once ();
1721 rtl_initialized = true;
1723 /* Target specific RTL backend initialization. */
1724 if (!this_target_rtl->target_specific_initialized)
1726 backend_init_target ();
1727 this_target_rtl->target_specific_initialized = true;
1731 /* Language-dependent initialization. Returns nonzero on success. */
1732 static int
1733 lang_dependent_init (const char *name)
1735 location_t save_loc = input_location;
1736 if (dump_base_name == 0)
1737 dump_base_name = name && name[0] ? name : "gccdump";
1739 /* Other front-end initialization. */
1740 input_location = BUILTINS_LOCATION;
1741 if (lang_hooks.init () == 0)
1742 return 0;
1743 input_location = save_loc;
1745 if (!flag_wpa)
1747 init_asm_output (name);
1749 /* If stack usage information is desired, open the output file. */
1750 if (flag_stack_usage)
1751 stack_usage_file = open_auxiliary_file ("su");
1754 /* This creates various _DECL nodes, so needs to be called after the
1755 front end is initialized. */
1756 init_eh ();
1758 /* Do the target-specific parts of the initialization. */
1759 lang_dependent_init_target ();
1761 if (!flag_wpa)
1763 /* If dbx symbol table desired, initialize writing it and output the
1764 predefined types. */
1765 timevar_push (TV_SYMOUT);
1767 /* Now we have the correct original filename, we can initialize
1768 debug output. */
1769 (*debug_hooks->init) (name);
1771 timevar_pop (TV_SYMOUT);
1774 return 1;
1778 /* Reinitialize everything when target parameters, such as register usage,
1779 have changed. */
1780 void
1781 target_reinit (void)
1783 struct rtl_data saved_x_rtl;
1784 rtx *saved_regno_reg_rtx;
1785 tree saved_optimization_current_node;
1786 struct target_optabs *saved_this_fn_optabs;
1788 /* Temporarily switch to the default optimization node, so that
1789 *this_target_optabs is set to the default, not reflecting
1790 whatever a previous function used for the optimize
1791 attribute. */
1792 saved_optimization_current_node = optimization_current_node;
1793 saved_this_fn_optabs = this_fn_optabs;
1794 if (saved_optimization_current_node != optimization_default_node)
1796 optimization_current_node = optimization_default_node;
1797 cl_optimization_restore
1798 (&global_options,
1799 TREE_OPTIMIZATION (optimization_default_node));
1801 this_fn_optabs = this_target_optabs;
1803 /* Save *crtl and regno_reg_rtx around the reinitialization
1804 to allow target_reinit being called even after prepare_function_start. */
1805 saved_regno_reg_rtx = regno_reg_rtx;
1806 if (saved_regno_reg_rtx)
1808 saved_x_rtl = *crtl;
1809 memset (crtl, '\0', sizeof (*crtl));
1810 regno_reg_rtx = NULL;
1813 this_target_rtl->target_specific_initialized = false;
1815 /* This initializes hard_frame_pointer, and calls init_reg_modes_target()
1816 to initialize reg_raw_mode[]. */
1817 init_emit_regs ();
1819 /* This invokes target hooks to set fixed_reg[] etc, which is
1820 mode-dependent. */
1821 init_regs ();
1823 /* Reinitialize lang-dependent parts. */
1824 lang_dependent_init_target ();
1826 /* Restore the original optimization node. */
1827 if (saved_optimization_current_node != optimization_default_node)
1829 optimization_current_node = saved_optimization_current_node;
1830 cl_optimization_restore (&global_options,
1831 TREE_OPTIMIZATION (optimization_current_node));
1833 this_fn_optabs = saved_this_fn_optabs;
1835 /* Restore regno_reg_rtx at the end, as free_after_compilation from
1836 expand_dummy_function_end clears it. */
1837 if (saved_regno_reg_rtx)
1839 *crtl = saved_x_rtl;
1840 regno_reg_rtx = saved_regno_reg_rtx;
1841 saved_regno_reg_rtx = NULL;
1845 void
1846 dump_memory_report (bool final)
1848 dump_line_table_statistics ();
1849 ggc_print_statistics ();
1850 stringpool_statistics ();
1851 dump_tree_statistics ();
1852 dump_gimple_statistics ();
1853 dump_rtx_statistics ();
1854 dump_alloc_pool_statistics ();
1855 dump_bitmap_statistics ();
1856 dump_hash_table_loc_statistics ();
1857 dump_vec_loc_statistics ();
1858 dump_ggc_loc_statistics (final);
1859 dump_alias_stats (stderr);
1860 dump_pta_stats (stderr);
1863 /* Clean up: close opened files, etc. */
1865 static void
1866 finalize (bool no_backend)
1868 /* Close the dump files. */
1869 if (flag_gen_aux_info)
1871 fclose (aux_info_file);
1872 if (seen_error ())
1873 unlink (aux_info_file_name);
1876 /* Close non-debugging input and output files. Take special care to note
1877 whether fclose returns an error, since the pages might still be on the
1878 buffer chain while the file is open. */
1880 if (asm_out_file)
1882 if (ferror (asm_out_file) != 0)
1883 fatal_error (input_location, "error writing to %s: %m", asm_file_name);
1884 if (fclose (asm_out_file) != 0)
1885 fatal_error (input_location, "error closing %s: %m", asm_file_name);
1888 if (stack_usage_file)
1889 fclose (stack_usage_file);
1891 if (!no_backend)
1893 statistics_fini ();
1895 g->get_passes ()->finish_optimization_passes ();
1897 lra_finish_once ();
1900 if (mem_report)
1901 dump_memory_report (true);
1903 if (profile_report)
1904 dump_profile_report ();
1906 /* Language-specific end of compilation actions. */
1907 lang_hooks.finish ();
1910 static bool
1911 standard_type_bitsize (int bitsize)
1913 /* As a special exception, we always want __int128 enabled if possible. */
1914 if (bitsize == 128)
1915 return false;
1916 if (bitsize == CHAR_TYPE_SIZE
1917 || bitsize == SHORT_TYPE_SIZE
1918 || bitsize == INT_TYPE_SIZE
1919 || bitsize == LONG_TYPE_SIZE
1920 || bitsize == LONG_LONG_TYPE_SIZE)
1921 return true;
1922 return false;
1925 /* Initialize the compiler, and compile the input file. */
1926 static void
1927 do_compile ()
1929 process_options ();
1931 /* Don't do any more if an error has already occurred. */
1932 if (!seen_error ())
1934 int i;
1936 timevar_start (TV_PHASE_SETUP);
1938 /* This must be run always, because it is needed to compute the FP
1939 predefined macros, such as __LDBL_MAX__, for targets using non
1940 default FP formats. */
1941 init_adjust_machine_modes ();
1942 init_derived_machine_modes ();
1944 /* This must happen after the backend has a chance to process
1945 command line options, but before the parsers are
1946 initialized. */
1947 for (i = 0; i < NUM_INT_N_ENTS; i ++)
1948 if (targetm.scalar_mode_supported_p (int_n_data[i].m)
1949 && ! standard_type_bitsize (int_n_data[i].bitsize))
1950 int_n_enabled_p[i] = true;
1951 else
1952 int_n_enabled_p[i] = false;
1954 /* Set up the back-end if requested. */
1955 if (!no_backend)
1956 backend_init ();
1958 /* Language-dependent initialization. Returns true on success. */
1959 if (lang_dependent_init (main_input_filename))
1961 /* Initialize yet another pass. */
1963 ggc_protect_identifiers = true;
1965 symtab->initialize ();
1966 init_final (main_input_filename);
1967 coverage_init (aux_base_name);
1968 statistics_init ();
1969 invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
1971 timevar_stop (TV_PHASE_SETUP);
1973 compile_file ();
1975 else
1977 timevar_stop (TV_PHASE_SETUP);
1980 timevar_start (TV_PHASE_FINALIZE);
1982 finalize (no_backend);
1984 timevar_stop (TV_PHASE_FINALIZE);
1988 toplev::toplev (timer *external_timer,
1989 bool init_signals)
1990 : m_use_TV_TOTAL (external_timer == NULL),
1991 m_init_signals (init_signals)
1993 if (external_timer)
1994 g_timer = external_timer;
1997 toplev::~toplev ()
1999 if (g_timer && m_use_TV_TOTAL)
2001 g_timer->stop (TV_TOTAL);
2002 g_timer->print (stderr);
2003 delete g_timer;
2004 g_timer = NULL;
2008 /* Potentially call timevar_init (which will create g_timevars if it
2009 doesn't already exist). */
2011 void
2012 toplev::start_timevars ()
2014 if (time_report || !quiet_flag || flag_detailed_statistics)
2015 timevar_init ();
2017 timevar_start (TV_TOTAL);
2020 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2021 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2022 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2024 It is not safe to call this function more than once. */
2027 toplev::main (int argc, char **argv)
2029 /* Parsing and gimplification sometimes need quite large stack.
2030 Increase stack size limits if possible. */
2031 stack_limit_increase (64 * 1024 * 1024);
2033 expandargv (&argc, &argv);
2035 /* Initialization of GCC's environment, and diagnostics. */
2036 general_init (argv[0], m_init_signals);
2038 /* One-off initialization of options that does not need to be
2039 repeated when options are added for particular functions. */
2040 init_options_once ();
2042 /* Initialize global options structures; this must be repeated for
2043 each structure used for parsing options. */
2044 init_options_struct (&global_options, &global_options_set);
2045 lang_hooks.init_options_struct (&global_options);
2047 /* Convert the options to an array. */
2048 decode_cmdline_options_to_array_default_mask (argc,
2049 CONST_CAST2 (const char **,
2050 char **, argv),
2051 &save_decoded_options,
2052 &save_decoded_options_count);
2054 /* Perform language-specific options initialization. */
2055 lang_hooks.init_options (save_decoded_options_count, save_decoded_options);
2057 /* Parse the options and do minimal processing; basically just
2058 enough to default flags appropriately. */
2059 decode_options (&global_options, &global_options_set,
2060 save_decoded_options, save_decoded_options_count,
2061 UNKNOWN_LOCATION, global_dc);
2063 handle_common_deferred_options ();
2065 init_local_tick ();
2067 initialize_plugins ();
2069 if (version_flag)
2070 print_version (stderr, "", true);
2072 if (help_flag)
2073 print_plugins_help (stderr, "");
2075 /* Exit early if we can (e.g. -help). */
2076 if (!exit_after_options)
2078 if (m_use_TV_TOTAL)
2079 start_timevars ();
2080 do_compile ();
2083 if (warningcount || errorcount || werrorcount)
2084 print_ignored_options ();
2086 /* Invoke registered plugin callbacks if any. Some plugins could
2087 emit some diagnostics here. */
2088 invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
2090 diagnostic_finish (global_dc);
2092 finalize_plugins ();
2093 location_adhoc_data_fini (line_table);
2094 if (seen_error () || werrorcount)
2095 return (FATAL_EXIT_CODE);
2097 return (SUCCESS_EXIT_CODE);
2100 /* For those that want to, this function aims to clean up enough state that
2101 you can call toplev::main again. */
2102 void
2103 toplev::finalize (void)
2105 rtl_initialized = false;
2106 this_target_rtl->target_specific_initialized = false;
2108 /* Needs to be called before cgraph_c_finalize since it uses symtab. */
2109 ipa_reference_c_finalize ();
2111 cgraph_c_finalize ();
2112 cgraphunit_c_finalize ();
2113 dwarf2out_c_finalize ();
2114 gcse_c_finalize ();
2115 ipa_cp_c_finalize ();
2116 ira_costs_c_finalize ();
2117 params_c_finalize ();
2119 finalize_options_struct (&global_options);
2120 finalize_options_struct (&global_options_set);
2122 XDELETEVEC (save_decoded_options);
2124 /* Clean up the context (and pass_manager etc). */
2125 delete g;
2126 g = NULL;
2128 obstack_free (&opts_obstack, NULL);