Merge from trunk: 215733-215743
[official-gcc.git] / gcc-4_7 / gcc / toplev.c
blob70f0d348fafb466a2e2f3c0debc24a323f5c1106
1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4 2011 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* This is the top level of cc1/c++.
23 It parses command args, opens files, invokes the various passes
24 in the proper order, and counts the time used by each.
25 Error messages and low-level interface to malloc also handled here. */
27 #include "config.h"
28 #include "system.h"
29 #include "coretypes.h"
30 #include "tm.h"
31 #include "line-map.h"
32 #include "input.h"
33 #include "tree.h"
34 #include "realmpfr.h" /* For GMP/MPFR/MPC versions, in print_version. */
35 #include "version.h"
36 #include "rtl.h"
37 #include "tm_p.h"
38 #include "flags.h"
39 #include "insn-attr.h"
40 #include "insn-config.h"
41 #include "insn-flags.h"
42 #include "hard-reg-set.h"
43 #include "recog.h"
44 #include "output.h"
45 #include "except.h"
46 #include "function.h"
47 #include "toplev.h"
48 #include "expr.h"
49 #include "basic-block.h"
50 #include "intl.h"
51 #include "ggc.h"
52 #include "graph.h"
53 #include "regs.h"
54 #include "timevar.h"
55 #include "diagnostic.h"
56 #include "tree-diagnostic.h"
57 #include "tree-pretty-print.h"
58 #include "params.h"
59 #include "reload.h"
60 #include "ira.h"
61 #include "dwarf2asm.h"
62 #include "integrate.h"
63 #include "debug.h"
64 #include "target.h"
65 #include "common/common-target.h"
66 #include "langhooks.h"
67 #include "cfglayout.h"
68 #include "cfgloop.h"
69 #include "hosthooks.h"
70 #include "cgraph.h"
71 #include "opts.h"
72 #include "opts-diagnostic.h"
73 #include "coverage.h"
74 #include "value-prof.h"
75 #include "alloc-pool.h"
76 #include "tree-mudflap.h"
77 #include "tree-asan.h"
78 #include "tree-tsan.h"
79 #include "tree-pass.h"
80 #include "gimple.h"
81 #include "tree-ssa-alias.h"
82 #include "plugin.h"
83 #include "tree-threadsafe-analyze.h"
84 #include "auto-profile.h"
86 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
87 #include "dwarf2out.h"
88 #endif
90 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
91 #include "dbxout.h"
92 #endif
94 #ifdef SDB_DEBUGGING_INFO
95 #include "sdbout.h"
96 #endif
98 #ifdef XCOFF_DEBUGGING_INFO
99 #include "xcoffout.h" /* Needed for external data
100 declarations for e.g. AIX 4.x. */
101 #endif
103 static void general_init (const char *);
104 static void do_compile (void);
105 static void process_options (void);
106 static void backend_init (void);
107 static int lang_dependent_init (const char *);
108 static void init_asm_output (const char *);
109 static void finalize (bool);
111 static void crash_signal (int) ATTRIBUTE_NORETURN;
112 static void compile_file (void);
114 /* True if we don't need a backend (e.g. preprocessing only). */
115 static bool no_backend;
117 /* Length of line when printing switch values. */
118 #define MAX_LINE 75
120 /* Decoded options, and number of such options. */
121 struct cl_decoded_option *save_decoded_options;
122 unsigned int save_decoded_options_count;
124 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
125 to optimize in process_options (). */
126 #define AUTODETECT_VALUE 2
128 /* Debug hooks - dependent upon command line options. */
130 const struct gcc_debug_hooks *debug_hooks;
132 /* The FUNCTION_DECL for the function currently being compiled,
133 or 0 if between functions. */
134 tree current_function_decl;
136 /* Set to the FUNC_BEGIN label of the current function, or NULL
137 if none. */
138 const char * current_function_func_begin_label;
140 /* A random sequence of characters, unless overridden by user. */
141 static const char *flag_random_seed;
143 /* A local time stamp derived from the time of compilation. It will be
144 zero if the system cannot provide a time. It will be -1u, if the
145 user has specified a particular random seed. */
146 unsigned local_tick;
148 /* Random number for this compilation */
149 HOST_WIDE_INT random_seed;
151 /* -f flags. */
153 /* Nonzero means make permerror produce warnings instead of errors. */
155 int flag_permissive = 0;
157 /* When non-NULL, indicates that whenever space is allocated on the
158 stack, the resulting stack pointer must not pass this
159 address---that is, for stacks that grow downward, the stack pointer
160 must always be greater than or equal to this address; for stacks
161 that grow upward, the stack pointer must be less than this address.
162 At present, the rtx may be either a REG or a SYMBOL_REF, although
163 the support provided depends on the backend. */
164 rtx stack_limit_rtx;
166 /* True if the user has tagged the function with the 'section'
167 attribute. */
169 bool user_defined_section_attribute = false;
171 struct target_flag_state default_target_flag_state;
172 #if SWITCHABLE_TARGET
173 struct target_flag_state *this_target_flag_state = &default_target_flag_state;
174 #else
175 #define this_target_flag_state (&default_target_flag_state)
176 #endif
178 /* The user symbol prefix after having resolved same. */
179 const char *user_label_prefix;
181 /* Output files for assembler code (real compiler output)
182 and debugging dumps. */
184 FILE *asm_out_file;
185 FILE *aux_info_file;
186 FILE *stack_usage_file = NULL;
187 FILE *dump_file = NULL;
188 const char *dump_file_name;
190 /* The current working directory of a translation. It's generally the
191 directory from which compilation was initiated, but a preprocessed
192 file may specify the original directory in which it was
193 created. */
195 static const char *src_pwd;
197 /* Primary module's id (non-zero). If no module-info was read in, this will
198 be zero. */
200 unsigned primary_module_id = 0;
202 /* Current module id. */
204 unsigned current_module_id = 0;
206 /* Include all auxiliary modules specified in the profile. This
207 will bypass the ggc_memory limit check. */
208 bool include_all_aux = 0;
210 /* Initialize src_pwd with the given string, and return true. If it
211 was already initialized, return false. As a special case, it may
212 be called with a NULL argument to test whether src_pwd has NOT been
213 initialized yet. */
215 bool
216 set_src_pwd (const char *pwd)
218 if (src_pwd)
220 if (strcmp (src_pwd, pwd) == 0)
221 return true;
222 else
223 return false;
226 src_pwd = xstrdup (pwd);
227 return true;
230 /* Return the directory from which the translation unit was initiated,
231 in case set_src_pwd() was not called before to assign it a
232 different value. */
234 const char *
235 get_src_pwd (void)
237 if (! src_pwd)
239 src_pwd = getpwd ();
240 if (!src_pwd)
241 src_pwd = ".";
244 return src_pwd;
247 /* Called when the start of a function definition is parsed,
248 this function prints on stderr the name of the function. */
249 void
250 announce_function (tree decl)
252 if (!quiet_flag)
254 if (rtl_dump_and_exit)
255 fprintf (stderr, "%s ",
256 identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))));
257 else
258 fprintf (stderr, " %s",
259 identifier_to_locale (lang_hooks.decl_printable_name (decl, 2)));
260 fflush (stderr);
261 pp_needs_newline (global_dc->printer) = true;
262 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
266 /* Initialize local_tick with a random number or -1 if
267 flag_random_seed is set. */
269 static void
270 init_local_tick (void)
272 if (!flag_random_seed)
274 /* Try urandom first. Time of day is too likely to collide.
275 In case of any error we just use the local tick. */
277 int fd = open ("/dev/urandom", O_RDONLY);
278 if (fd >= 0)
280 read (fd, &random_seed, sizeof (random_seed));
281 close (fd);
284 /* Now get the tick anyways */
285 #ifdef HAVE_GETTIMEOFDAY
287 struct timeval tv;
289 gettimeofday (&tv, NULL);
290 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
292 #else
294 time_t now = time (NULL);
296 if (now != (time_t)-1)
297 local_tick = (unsigned) now;
299 #endif
301 else
302 local_tick = -1;
305 /* Set up a default flag_random_seed and local_tick, unless the user
306 already specified one. Must be called after init_local_tick. */
308 static void
309 init_random_seed (void)
311 if (flag_random_seed)
313 char *endp;
315 /* When the driver passed in a hex number don't crc it again */
316 random_seed = strtoul (flag_random_seed, &endp, 0);
317 if (!(endp > flag_random_seed && *endp == 0))
318 random_seed = crc32_string (0, flag_random_seed);
320 else if (!random_seed)
321 random_seed = local_tick ^ getpid (); /* Old racey fallback method */
324 /* Obtain the random_seed. Unless NOINIT, initialize it if
325 it's not provided in the command line. */
327 HOST_WIDE_INT
328 get_random_seed (bool noinit)
330 if (!flag_random_seed && !noinit)
331 init_random_seed ();
332 return random_seed;
335 /* Modify the random_seed string to VAL. Return its previous
336 value. */
338 const char *
339 set_random_seed (const char *val)
341 const char *old = flag_random_seed;
342 flag_random_seed = val;
343 return old;
346 /* Handler for fatal signals, such as SIGSEGV. These are transformed
347 into ICE messages, which is much more user friendly. In case the
348 error printer crashes, reset the signal to prevent infinite recursion. */
350 static void
351 crash_signal (int signo)
353 signal (signo, SIG_DFL);
355 /* If we crashed while processing an ASM statement, then be a little more
356 graceful. It's most likely the user's fault. */
357 if (this_is_asm_operands)
359 output_operand_lossage ("unrecoverable error");
360 exit (FATAL_EXIT_CODE);
363 internal_error ("%s", strsignal (signo));
366 /* A subroutine of wrapup_global_declarations. We've come to the end of
367 the compilation unit. All deferred variables should be undeferred,
368 and all incomplete decls should be finalized. */
370 void
371 wrapup_global_declaration_1 (tree decl)
373 /* We're not deferring this any longer. Assignment is conditional to
374 avoid needlessly dirtying PCH pages. */
375 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
376 && DECL_DEFER_OUTPUT (decl) != 0)
377 DECL_DEFER_OUTPUT (decl) = 0;
379 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
380 lang_hooks.finish_incomplete_decl (decl);
383 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
384 needs to be output. Return true if it is output. */
386 bool
387 wrapup_global_declaration_2 (tree decl)
389 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
390 return false;
392 /* Don't write out static consts, unless we still need them.
394 We also keep static consts if not optimizing (for debugging),
395 unless the user specified -fno-keep-static-consts.
396 ??? They might be better written into the debug information.
397 This is possible when using DWARF.
399 A language processor that wants static constants to be always
400 written out (even if it is not used) is responsible for
401 calling rest_of_decl_compilation itself. E.g. the C front-end
402 calls rest_of_decl_compilation from finish_decl.
403 One motivation for this is that is conventional in some
404 environments to write things like:
405 static const char rcsid[] = "... version string ...";
406 intending to force the string to be in the executable.
408 A language processor that would prefer to have unneeded
409 static constants "optimized away" would just defer writing
410 them out until here. E.g. C++ does this, because static
411 constants are often defined in header files.
413 ??? A tempting alternative (for both C and C++) would be
414 to force a constant to be written if and only if it is
415 defined in a main file, as opposed to an include file. */
417 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
419 struct varpool_node *node;
420 bool needed = true;
421 node = varpool_get_node (decl);
423 if (!node && flag_ltrans)
424 needed = false;
425 else if (node && node->finalized)
426 needed = false;
427 else if (node && node->alias)
428 needed = false;
429 else if (!cgraph_global_info_ready
430 && (TREE_USED (decl)
431 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
432 /* needed */;
433 else if (node && node->needed)
434 /* needed */;
435 else if (DECL_COMDAT (decl))
436 needed = false;
437 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
438 && (optimize || !flag_keep_static_consts
439 || DECL_ARTIFICIAL (decl)))
440 needed = false;
442 if (needed)
444 rest_of_decl_compilation (decl, 1, 1);
445 return true;
449 return false;
452 /* Do any final processing required for the declarations in VEC, of
453 which there are LEN. We write out inline functions and variables
454 that have been deferred until this point, but which are required.
455 Returns nonzero if anything was put out. */
457 bool
458 wrapup_global_declarations (tree *vec, int len)
460 bool reconsider, output_something = false;
461 int i;
463 for (i = 0; i < len; i++)
464 wrapup_global_declaration_1 (vec[i]);
466 /* Now emit any global variables or functions that we have been
467 putting off. We need to loop in case one of the things emitted
468 here references another one which comes earlier in the list. */
471 reconsider = false;
472 for (i = 0; i < len; i++)
473 reconsider |= wrapup_global_declaration_2 (vec[i]);
474 if (reconsider)
475 output_something = true;
477 while (reconsider);
479 return output_something;
482 /* A subroutine of check_global_declarations. Issue appropriate warnings
483 for the global declaration DECL. */
485 void
486 check_global_declaration_1 (tree decl)
488 /* Warn about any function declared static but not defined. We don't
489 warn about variables, because many programs have static variables
490 that exist only to get some text into the object file. */
491 if (TREE_CODE (decl) == FUNCTION_DECL
492 && DECL_INITIAL (decl) == 0
493 && DECL_EXTERNAL (decl)
494 && ! DECL_ARTIFICIAL (decl)
495 && ! TREE_NO_WARNING (decl)
496 && ! TREE_PUBLIC (decl)
497 && (warn_unused_function
498 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
500 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
501 pedwarn (input_location, 0, "%q+F used but never defined", decl);
502 else
503 warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
504 /* This symbol is effectively an "extern" declaration now. */
505 TREE_PUBLIC (decl) = 1;
506 assemble_external (decl);
509 /* Warn about static fns or vars defined but not used. */
510 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
511 /* We don't warn about "static const" variables because the
512 "rcs_id" idiom uses that construction. */
513 || (warn_unused_variable
514 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
515 && ! DECL_IN_SYSTEM_HEADER (decl)
516 && ! TREE_USED (decl)
517 /* The TREE_USED bit for file-scope decls is kept in the identifier,
518 to handle multiple external decls in different scopes. */
519 && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
520 && ! DECL_EXTERNAL (decl)
521 && ! TREE_PUBLIC (decl)
522 /* A volatile variable might be used in some non-obvious way. */
523 && ! TREE_THIS_VOLATILE (decl)
524 /* Global register variables must be declared to reserve them. */
525 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
526 /* Otherwise, ask the language. */
527 && lang_hooks.decls.warn_unused_global (decl))
528 warning ((TREE_CODE (decl) == FUNCTION_DECL)
529 ? OPT_Wunused_function
530 : OPT_Wunused_variable,
531 "%q+D defined but not used", decl);
534 /* Issue appropriate warnings for the global declarations in VEC (of
535 which there are LEN). */
537 void
538 check_global_declarations (tree *vec, int len)
540 int i;
542 for (i = 0; i < len; i++)
543 check_global_declaration_1 (vec[i]);
546 /* Emit debugging information for all global declarations in VEC. */
548 void
549 emit_debug_global_declarations (tree *vec, int len)
551 int i;
553 /* Avoid confusing the debug information machinery when there are errors. */
554 if (seen_error ())
555 return;
557 timevar_push (TV_SYMOUT);
558 for (i = 0; i < len; i++)
559 debug_hooks->global_decl (vec[i]);
560 timevar_pop (TV_SYMOUT);
563 /* Compile an entire translation unit. Write a file of assembly
564 output and various debugging dumps. */
566 static void
567 compile_file (void)
569 timevar_start (TV_PHASE_PARSING);
570 timevar_push (TV_PARSE_GLOBAL);
572 /* Call the parser, which parses the entire file (calling
573 rest_of_compilation for each function). */
574 lang_hooks.parse_file ();
576 timevar_pop (TV_PARSE_GLOBAL);
577 timevar_stop (TV_PHASE_PARSING);
579 /* Compilation is now finished except for writing
580 what's left of the symbol table output. */
582 if (flag_syntax_only || flag_wpa)
583 return;
585 timevar_start (TV_PHASE_GENERATE);
587 ggc_protect_identifiers = false;
589 /* This must also call cgraph_finalize_compilation_unit. */
590 lang_hooks.decls.final_write_globals ();
592 if (seen_error ())
594 timevar_stop (TV_PHASE_GENERATE);
595 return;
598 /* Clean up the global data structures used by the thread safety
599 analysis. */
600 if (warn_thread_safety)
601 clean_up_threadsafe_analysis ();
603 if (flag_dyn_ipa)
604 coverage_finish ();
606 /* Compilation unit is finalized. When producing non-fat LTO object, we are
607 basically finished. */
608 if (in_lto_p || !flag_lto || flag_fat_lto_objects)
610 varpool_assemble_pending_decls ();
611 finish_aliases_2 ();
613 /* Likewise for mudflap static object registrations. */
614 if (flag_mudflap)
615 mudflap_finish_file ();
617 /* File-scope initialization for AddressSanitizer. */
618 if (flag_asan)
619 asan_finish_file ();
621 /* File-scope initialization for ThreadSanitizer. */
622 if (flag_tsan)
623 tsan_finish_file ();
625 output_shared_constant_pool ();
626 output_object_blocks ();
627 finish_tm_clone_pairs ();
629 /* Write out any pending weak symbol declarations. */
630 weak_finish ();
632 /* This must be at the end before unwind and debug info.
633 Some target ports emit PIC setup thunks here. */
634 targetm.asm_out.code_end ();
636 /* Do dbx symbols. */
637 timevar_push (TV_SYMOUT);
639 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
640 if (dwarf2out_do_frame ())
641 dwarf2out_frame_finish ();
642 #endif
644 (*debug_hooks->finish) (main_input_filename);
645 timevar_pop (TV_SYMOUT);
647 /* Output some stuff at end of file if nec. */
649 dw2_output_indirect_constants ();
651 /* Flush any pending external directives. */
652 process_pending_assemble_externals ();
655 /* Emit LTO marker if LTO info has been previously emitted. This is
656 used by collect2 to determine whether an object file contains IL.
657 We used to emit an undefined reference here, but this produces
658 link errors if an object file with IL is stored into a shared
659 library without invoking lto1. */
660 if (flag_generate_lto)
662 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
663 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE,
664 "__gnu_lto_v1",
665 (unsigned HOST_WIDE_INT) 1, 8);
666 #elif defined ASM_OUTPUT_ALIGNED_COMMON
667 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_v1",
668 (unsigned HOST_WIDE_INT) 1, 8);
669 #else
670 ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_v1",
671 (unsigned HOST_WIDE_INT) 1,
672 (unsigned HOST_WIDE_INT) 1);
673 #endif
674 /* Let linker plugin know that this is a slim object and must be LTOed
675 even when user did not ask for it. */
676 if (!flag_fat_lto_objects)
678 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
679 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE,
680 "__gnu_lto_slim",
681 (unsigned HOST_WIDE_INT) 1, 8);
682 #elif defined ASM_OUTPUT_ALIGNED_COMMON
683 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_slim",
684 (unsigned HOST_WIDE_INT) 1, 8);
685 #else
686 ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_slim",
687 (unsigned HOST_WIDE_INT) 1,
688 (unsigned HOST_WIDE_INT) 1);
689 #endif
693 /* Attach a special .ident directive to the end of the file to identify
694 the version of GCC which compiled this code. The format of the .ident
695 string is patterned after the ones produced by native SVR4 compilers. */
696 #ifdef IDENT_ASM_OP
697 if (!flag_no_ident)
699 const char *pkg_version = "(GNU) ";
701 if (strcmp ("(GCC) ", pkgversion_string))
702 pkg_version = pkgversion_string;
703 fprintf (asm_out_file, "%s\"GCC: %s%s\"\n",
704 IDENT_ASM_OP, pkg_version, version_string);
706 #endif
708 /* Auto profile finalization. */
709 if (flag_auto_profile)
710 end_auto_profile ();
712 /* Invoke registered plugin callbacks. */
713 invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
715 /* This must be at the end. Some target ports emit end of file directives
716 into the assembly file here, and hence we can not output anything to the
717 assembly file after this point. */
718 targetm.asm_out.file_end ();
720 timevar_stop (TV_PHASE_GENERATE);
723 /* Print version information to FILE.
724 Each line begins with INDENT (for the case where FILE is the
725 assembler output file). */
727 void
728 print_version (FILE *file, const char *indent)
730 static const char fmt1[] =
731 #ifdef __GNUC__
732 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
733 #else
734 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
735 #endif
737 static const char fmt2[] =
738 N_("GMP version %s, MPFR version %s, MPC version %s\n");
739 static const char fmt3[] =
740 N_("%s%swarning: %s header version %s differs from library version %s.\n");
741 static const char fmt4[] =
742 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
743 #ifndef __VERSION__
744 #define __VERSION__ "[?]"
745 #endif
746 fprintf (file,
747 file == stderr ? _(fmt1) : fmt1,
748 indent, *indent != 0 ? " " : "",
749 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
750 indent, __VERSION__);
752 /* We need to stringify the GMP macro values. Ugh, gmp_version has
753 two string formats, "i.j.k" and "i.j" when k is zero. As of
754 gmp-4.3.0, GMP always uses the 3 number format. */
755 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
756 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
757 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
758 #define GCC_GMP_VERSION \
759 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
760 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
761 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
762 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
763 #else
764 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
765 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
766 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
767 #endif
768 fprintf (file,
769 file == stderr ? _(fmt2) : fmt2,
770 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING, MPC_VERSION_STRING);
771 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
772 fprintf (file,
773 file == stderr ? _(fmt3) : fmt3,
774 indent, *indent != 0 ? " " : "",
775 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
776 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
777 fprintf (file,
778 file == stderr ? _(fmt3) : fmt3,
779 indent, *indent != 0 ? " " : "",
780 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
781 if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
782 fprintf (file,
783 file == stderr ? _(fmt3) : fmt3,
784 indent, *indent != 0 ? " " : "",
785 "MPC", MPC_VERSION_STRING, mpc_get_version ());
786 fprintf (file,
787 file == stderr ? _(fmt4) : fmt4,
788 indent, *indent != 0 ? " " : "",
789 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
791 print_plugins_versions (file, indent);
794 static int
795 print_to_asm_out_file (print_switch_type type, const char * text)
797 bool prepend_sep = true;
799 switch (type)
801 case SWITCH_TYPE_LINE_END:
802 putc ('\n', asm_out_file);
803 return 1;
805 case SWITCH_TYPE_LINE_START:
806 fputs (ASM_COMMENT_START, asm_out_file);
807 return strlen (ASM_COMMENT_START);
809 case SWITCH_TYPE_DESCRIPTIVE:
810 if (ASM_COMMENT_START[0] == 0)
811 prepend_sep = false;
812 /* Drop through. */
813 case SWITCH_TYPE_PASSED:
814 case SWITCH_TYPE_ENABLED:
815 if (prepend_sep)
816 fputc (' ', asm_out_file);
817 fputs (text, asm_out_file);
818 /* No need to return the length here as
819 print_single_switch has already done it. */
820 return 0;
822 default:
823 return -1;
827 static int
828 print_to_stderr (print_switch_type type, const char * text)
830 switch (type)
832 case SWITCH_TYPE_LINE_END:
833 putc ('\n', stderr);
834 return 1;
836 case SWITCH_TYPE_LINE_START:
837 return 0;
839 case SWITCH_TYPE_PASSED:
840 case SWITCH_TYPE_ENABLED:
841 fputc (' ', stderr);
842 /* Drop through. */
844 case SWITCH_TYPE_DESCRIPTIVE:
845 fputs (text, stderr);
846 /* No need to return the length here as
847 print_single_switch has already done it. */
848 return 0;
850 default:
851 return -1;
855 /* Print an option value and return the adjusted position in the line.
856 ??? print_fn doesn't handle errors, eg disk full; presumably other
857 code will catch a disk full though. */
859 static int
860 print_single_switch (print_switch_fn_type print_fn,
861 int pos,
862 print_switch_type type,
863 const char * text)
865 /* The ultrix fprintf returns 0 on success, so compute the result
866 we want here since we need it for the following test. The +1
867 is for the separator character that will probably be emitted. */
868 int len = strlen (text) + 1;
870 if (pos != 0
871 && pos + len > MAX_LINE)
873 print_fn (SWITCH_TYPE_LINE_END, NULL);
874 pos = 0;
877 if (pos == 0)
878 pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
880 print_fn (type, text);
881 return pos + len;
884 /* Print active target switches using PRINT_FN.
885 POS is the current cursor position and MAX is the size of a "line".
886 Each line begins with INDENT and ends with TERM.
887 Each switch is separated from the next by SEP. */
889 static void
890 print_switch_values (print_switch_fn_type print_fn)
892 int pos = 0;
893 size_t j;
895 /* Fill in the -frandom-seed option, if the user didn't pass it, so
896 that it can be printed below. This helps reproducibility. */
897 if (!flag_random_seed)
898 init_random_seed ();
900 /* Print the options as passed. */
901 pos = print_single_switch (print_fn, pos,
902 SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
904 for (j = 1; j < save_decoded_options_count; j++)
906 switch (save_decoded_options[j].opt_index)
908 case OPT_o:
909 case OPT_d:
910 case OPT_dumpbase:
911 case OPT_dumpdir:
912 case OPT_auxbase:
913 case OPT_quiet:
914 case OPT_version:
915 /* Ignore these. */
916 continue;
919 pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED,
920 save_decoded_options[j].orig_option_with_args_text);
923 if (pos > 0)
924 print_fn (SWITCH_TYPE_LINE_END, NULL);
926 /* Print the -f and -m options that have been enabled.
927 We don't handle language specific options but printing argv
928 should suffice. */
929 pos = print_single_switch (print_fn, 0,
930 SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
932 for (j = 0; j < cl_options_count; j++)
933 if (cl_options[j].cl_report
934 && option_enabled (j, &global_options) > 0)
935 pos = print_single_switch (print_fn, pos,
936 SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
938 print_fn (SWITCH_TYPE_LINE_END, NULL);
941 /* Open assembly code output file. Do this even if -fsyntax-only is
942 on, because then the driver will have provided the name of a
943 temporary file or bit bucket for us. NAME is the file specified on
944 the command line, possibly NULL. */
945 static void
946 init_asm_output (const char *name)
948 if (name == NULL && asm_file_name == 0)
949 asm_out_file = stdout;
950 else
952 if (asm_file_name == 0)
954 int len = strlen (dump_base_name);
955 char *dumpname = XNEWVEC (char, len + 6);
957 memcpy (dumpname, dump_base_name, len + 1);
958 strip_off_ending (dumpname, len);
959 strcat (dumpname, ".s");
960 asm_file_name = dumpname;
962 if (!strcmp (asm_file_name, "-"))
963 asm_out_file = stdout;
964 else
965 asm_out_file = fopen (asm_file_name, "w+b");
966 if (asm_out_file == 0)
967 fatal_error ("can%'t open %s for writing: %m", asm_file_name);
970 if (!flag_syntax_only)
972 targetm.asm_out.file_start ();
974 if (flag_record_gcc_switches)
976 if (targetm.asm_out.record_gcc_switches)
978 /* Let the target know that we are about to start recording. */
979 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
980 NULL);
981 /* Now record the switches. */
982 print_switch_values (targetm.asm_out.record_gcc_switches);
983 /* Let the target know that the recording is over. */
984 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
985 NULL);
987 else
988 inform (input_location, "-frecord-gcc-switches is not supported by the current target");
991 if (flag_verbose_asm)
993 /* Print the list of switches in effect
994 into the assembler file as comments. */
995 print_version (asm_out_file, ASM_COMMENT_START);
996 print_switch_values (print_to_asm_out_file);
997 putc ('\n', asm_out_file);
1002 /* Default tree printer. Handles declarations only. */
1003 bool
1004 default_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
1005 int precision, bool wide, bool set_locus, bool hash)
1007 tree t;
1009 /* FUTURE: %+x should set the locus. */
1010 if (precision != 0 || wide || hash)
1011 return false;
1013 switch (*spec)
1015 case 'E':
1016 t = va_arg (*text->args_ptr, tree);
1017 if (TREE_CODE (t) == IDENTIFIER_NODE)
1019 pp_identifier (pp, IDENTIFIER_POINTER (t));
1020 return true;
1022 break;
1024 case 'D':
1025 t = va_arg (*text->args_ptr, tree);
1026 if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
1027 t = DECL_DEBUG_EXPR (t);
1028 break;
1030 case 'F':
1031 case 'T':
1032 t = va_arg (*text->args_ptr, tree);
1033 break;
1035 case 'K':
1036 percent_K_format (text);
1037 return true;
1039 default:
1040 return false;
1043 if (set_locus && text->locus)
1044 *text->locus = DECL_SOURCE_LOCATION (t);
1046 if (DECL_P (t))
1048 const char *n = DECL_NAME (t)
1049 ? identifier_to_locale (lang_hooks.decl_printable_name (t, 2))
1050 : _("<anonymous>");
1051 pp_string (pp, n);
1053 else
1054 dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0);
1056 return true;
1059 /* A helper function; used as the reallocator function for cpp's line
1060 table. */
1061 static void *
1062 realloc_for_line_map (void *ptr, size_t len)
1064 return GGC_RESIZEVAR (void, ptr, len);
1067 /* A helper function: used as the allocator function for
1068 identifier_to_locale. */
1069 static void *
1070 alloc_for_identifier_to_locale (size_t len)
1072 return ggc_alloc_atomic (len);
1075 /* Output stack usage information. */
1076 void
1077 output_stack_usage (void)
1079 static bool warning_issued = false;
1080 enum stack_usage_kind_type { STATIC = 0, DYNAMIC, DYNAMIC_BOUNDED };
1081 const char *stack_usage_kind_str[] = {
1082 "static",
1083 "dynamic",
1084 "dynamic,bounded"
1086 HOST_WIDE_INT stack_usage = current_function_static_stack_size;
1087 enum stack_usage_kind_type stack_usage_kind;
1089 if (stack_usage < 0)
1091 if (!warning_issued)
1093 warning (0, "stack usage computation not supported for this target");
1094 warning_issued = true;
1096 return;
1099 stack_usage_kind = STATIC;
1101 /* Add the maximum amount of space pushed onto the stack. */
1102 if (current_function_pushed_stack_size > 0)
1104 stack_usage += current_function_pushed_stack_size;
1105 stack_usage_kind = DYNAMIC_BOUNDED;
1108 /* Now on to the tricky part: dynamic stack allocation. */
1109 if (current_function_allocates_dynamic_stack_space)
1111 if (current_function_has_unbounded_dynamic_stack_size)
1112 stack_usage_kind = DYNAMIC;
1113 else
1114 stack_usage_kind = DYNAMIC_BOUNDED;
1116 /* Add the size even in the unbounded case, this can't hurt. */
1117 stack_usage += current_function_dynamic_stack_size;
1120 if (flag_stack_usage)
1122 expanded_location loc
1123 = expand_location (DECL_SOURCE_LOCATION (current_function_decl));
1124 const char *raw_id, *id;
1126 /* Strip the scope prefix if any. */
1127 raw_id = lang_hooks.decl_printable_name (current_function_decl, 2);
1128 id = strrchr (raw_id, '.');
1129 if (id)
1130 id++;
1131 else
1132 id = raw_id;
1134 fprintf (stack_usage_file,
1135 "%s:%d:%d:%s\t"HOST_WIDE_INT_PRINT_DEC"\t%s\n",
1136 lbasename (loc.file),
1137 loc.line,
1138 loc.column,
1140 stack_usage,
1141 stack_usage_kind_str[stack_usage_kind]);
1144 if (warn_stack_usage >= 0)
1146 if (stack_usage_kind == DYNAMIC)
1147 warning (OPT_Wstack_usage_, "stack usage might be unbounded");
1148 else if (stack_usage > warn_stack_usage)
1150 if (stack_usage_kind == DYNAMIC_BOUNDED)
1151 warning (OPT_Wstack_usage_, "stack usage might be %wd bytes",
1152 stack_usage);
1153 else
1154 warning (OPT_Wstack_usage_, "stack usage is %wd bytes",
1155 stack_usage);
1160 /* Open an auxiliary output file. */
1161 static FILE *
1162 open_auxiliary_file (const char *ext)
1164 char *filename;
1165 FILE *file;
1167 filename = concat (aux_base_name, ".", ext, NULL);
1168 file = fopen (filename, "w");
1169 if (!file)
1170 fatal_error ("can%'t open %s for writing: %m", filename);
1171 free (filename);
1172 return file;
1175 /* Initialization of the front end environment, before command line
1176 options are parsed. Signal handlers, internationalization etc.
1177 ARGV0 is main's argv[0]. */
1178 static void
1179 general_init (const char *argv0)
1181 const char *p;
1183 p = argv0 + strlen (argv0);
1184 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1185 --p;
1186 progname = p;
1188 xmalloc_set_program_name (progname);
1190 hex_init ();
1192 /* Unlock the stdio streams. */
1193 unlock_std_streams ();
1195 gcc_init_libintl ();
1197 identifier_to_locale_alloc = alloc_for_identifier_to_locale;
1198 identifier_to_locale_free = ggc_free;
1200 /* Initialize the diagnostics reporting machinery, so option parsing
1201 can give warnings and errors. */
1202 diagnostic_initialize (global_dc, N_OPTS);
1203 diagnostic_starter (global_dc) = default_tree_diagnostic_starter;
1204 /* By default print macro expansion contexts in the diagnostic
1205 finalizer -- for tokens resulting from macro macro expansion. */
1206 diagnostic_finalizer (global_dc) = virt_loc_aware_diagnostic_finalizer;
1207 /* Set a default printer. Language specific initializations will
1208 override it later. */
1209 pp_format_decoder (global_dc->printer) = &default_tree_printer;
1210 global_dc->show_option_requested
1211 = global_options_init.x_flag_diagnostics_show_option;
1212 global_dc->show_column
1213 = global_options_init.x_flag_show_column;
1214 global_dc->internal_error = plugins_internal_error_function;
1215 global_dc->option_enabled = option_enabled;
1216 global_dc->option_state = &global_options;
1217 global_dc->option_name = option_name;
1219 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1220 #ifdef SIGSEGV
1221 signal (SIGSEGV, crash_signal);
1222 #endif
1223 #ifdef SIGILL
1224 signal (SIGILL, crash_signal);
1225 #endif
1226 #ifdef SIGBUS
1227 signal (SIGBUS, crash_signal);
1228 #endif
1229 #ifdef SIGABRT
1230 signal (SIGABRT, crash_signal);
1231 #endif
1232 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1233 signal (SIGIOT, crash_signal);
1234 #endif
1235 #ifdef SIGFPE
1236 signal (SIGFPE, crash_signal);
1237 #endif
1239 /* Other host-specific signal setup. */
1240 (*host_hooks.extra_signals)();
1242 /* Initialize the garbage-collector, string pools and tree type hash
1243 table. */
1244 init_ggc ();
1245 init_stringpool ();
1246 line_table = ggc_alloc_line_maps ();
1247 linemap_init (line_table);
1248 line_table->reallocator = realloc_for_line_map;
1249 line_table->round_alloc_size = ggc_round_alloc_size;
1250 init_ttree ();
1252 /* Initialize register usage now so switches may override. */
1253 init_reg_sets ();
1255 /* Register the language-independent parameters. */
1256 global_init_params ();
1258 /* This must be done after global_init_params but before argument
1259 processing. */
1260 init_ggc_heuristics();
1261 init_optimization_passes ();
1262 statistics_early_init ();
1263 finish_params ();
1266 /* Return true if the current target supports -fsection-anchors. */
1268 static bool
1269 target_supports_section_anchors_p (void)
1271 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1272 return false;
1274 if (targetm.asm_out.output_anchor == NULL)
1275 return false;
1277 return true;
1280 /* Default the align_* variables to 1 if they're still unset, and
1281 set up the align_*_log variables. */
1282 static void
1283 init_alignments (void)
1285 if (align_loops <= 0)
1286 align_loops = 1;
1287 if (align_loops_max_skip > align_loops)
1288 align_loops_max_skip = align_loops - 1;
1289 align_loops_log = floor_log2 (align_loops * 2 - 1);
1290 if (align_jumps <= 0)
1291 align_jumps = 1;
1292 if (align_jumps_max_skip > align_jumps)
1293 align_jumps_max_skip = align_jumps - 1;
1294 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1295 if (align_labels <= 0)
1296 align_labels = 1;
1297 align_labels_log = floor_log2 (align_labels * 2 - 1);
1298 if (align_labels_max_skip > align_labels)
1299 align_labels_max_skip = align_labels - 1;
1300 if (align_functions <= 0)
1301 align_functions = 1;
1302 align_functions_log = floor_log2 (align_functions * 2 - 1);
1305 /* Process the options that have been parsed. */
1306 static void
1307 process_options (void)
1309 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1310 This can happen with incorrect pre-processed input. */
1311 debug_hooks = &do_nothing_debug_hooks;
1313 maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT;
1315 /* Allow the front end to perform consistency checks and do further
1316 initialization based on the command line options. This hook also
1317 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1318 so we can correctly initialize debug output. */
1319 no_backend = lang_hooks.post_options (&main_input_filename);
1321 /* Some machines may reject certain combinations of options. */
1322 targetm.target_option.override ();
1324 /* Avoid any informative notes in the second run of -fcompare-debug. */
1325 if (flag_compare_debug)
1326 diagnostic_inhibit_notes (global_dc);
1328 if (flag_section_anchors && !target_supports_section_anchors_p ())
1330 warning (OPT_fsection_anchors,
1331 "this target does not support %qs", "-fsection-anchors");
1332 flag_section_anchors = 0;
1335 if (flag_short_enums == 2)
1336 flag_short_enums = targetm.default_short_enums ();
1338 /* Set aux_base_name if not already set. */
1339 if (aux_base_name)
1341 else if (main_input_filename)
1343 char *name = xstrdup (lbasename (main_input_filename));
1345 strip_off_ending (name, strlen (name));
1346 aux_base_name = name;
1348 else
1349 aux_base_name = "gccaux";
1351 #ifndef HAVE_cloog
1352 if (flag_graphite
1353 || flag_graphite_identity
1354 || flag_loop_block
1355 || flag_loop_flatten
1356 || flag_loop_interchange
1357 || flag_loop_strip_mine
1358 || flag_loop_parallelize_all)
1359 sorry ("Graphite loop optimizations cannot be used (-fgraphite, "
1360 "-fgraphite-identity, -floop-block, -floop-flatten, "
1361 "-floop-interchange, -floop-strip-mine, -floop-parallelize-all, "
1362 "and -ftree-loop-linear)");
1363 #endif
1365 if (flag_mudflap && flag_lto)
1366 sorry ("mudflap cannot be used together with link-time optimization");
1368 /* One region RA really helps to decrease the code size. */
1369 if (flag_ira_region == IRA_REGION_AUTODETECT)
1370 flag_ira_region
1371 = optimize_size || !optimize ? IRA_REGION_ONE : IRA_REGION_MIXED;
1373 if (flag_strict_volatile_bitfields > 0 && !abi_version_at_least (2))
1375 warning (0, "-fstrict-volatile-bitfields disabled; "
1376 "it is incompatible with ABI versions < 2");
1377 flag_strict_volatile_bitfields = 0;
1380 /* Unrolling all loops implies that standard loop unrolling must also
1381 be done. */
1382 if (flag_unroll_all_loops)
1383 flag_unroll_loops = 1;
1385 /* web and rename-registers help when run after loop unrolling. */
1386 if (flag_web == AUTODETECT_VALUE)
1387 flag_web = flag_unroll_loops || flag_peel_loops;
1389 if (flag_rename_registers == AUTODETECT_VALUE)
1390 flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1392 if (flag_non_call_exceptions)
1393 flag_asynchronous_unwind_tables = 1;
1394 if (flag_asynchronous_unwind_tables)
1395 flag_unwind_tables = 1;
1397 if (flag_value_profile_transformations)
1398 flag_profile_values = 1;
1400 /* Warn about options that are not supported on this machine. */
1401 #ifndef INSN_SCHEDULING
1402 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1403 warning (0, "instruction scheduling not supported on this target machine");
1404 #endif
1405 #ifndef DELAY_SLOTS
1406 if (flag_delayed_branch)
1407 warning (0, "this target machine does not have delayed branches");
1408 #endif
1410 user_label_prefix = USER_LABEL_PREFIX;
1411 if (flag_leading_underscore != -1)
1413 /* If the default prefix is more complicated than "" or "_",
1414 issue a warning and ignore this option. */
1415 if (user_label_prefix[0] == 0 ||
1416 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1418 user_label_prefix = flag_leading_underscore ? "_" : "";
1420 else
1421 warning (0, "-f%sleading-underscore not supported on this target machine",
1422 flag_leading_underscore ? "" : "no-");
1425 /* If we are in verbose mode, write out the version and maybe all the
1426 option flags in use. */
1427 if (version_flag)
1429 print_version (stderr, "");
1430 if (! quiet_flag)
1431 print_switch_values (print_to_stderr);
1434 if (flag_syntax_only)
1436 write_symbols = NO_DEBUG;
1437 profile_flag = 0;
1440 if (flag_gtoggle)
1442 if (debug_info_level == DINFO_LEVEL_NONE)
1444 debug_info_level = DINFO_LEVEL_NORMAL;
1446 if (write_symbols == NO_DEBUG)
1447 write_symbols = PREFERRED_DEBUGGING_TYPE;
1449 else
1450 debug_info_level = DINFO_LEVEL_NONE;
1453 if (flag_dump_final_insns && !flag_syntax_only && !no_backend)
1455 FILE *final_output = fopen (flag_dump_final_insns, "w");
1456 if (!final_output)
1458 error ("could not open final insn dump file %qs: %m",
1459 flag_dump_final_insns);
1460 flag_dump_final_insns = NULL;
1462 else if (fclose (final_output))
1464 error ("could not close zeroed insn dump file %qs: %m",
1465 flag_dump_final_insns);
1466 flag_dump_final_insns = NULL;
1470 /* Unless over-ridden for the target, assume that all DWARF levels
1471 may be emitted, if DWARF2_DEBUG is selected. */
1472 if (dwarf_strict < 0)
1473 dwarf_strict = 0;
1475 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1476 level is 0. */
1477 if (debug_info_level == DINFO_LEVEL_NONE)
1478 write_symbols = NO_DEBUG;
1480 if (write_symbols == NO_DEBUG)
1482 #if defined(DBX_DEBUGGING_INFO)
1483 else if (write_symbols == DBX_DEBUG)
1484 debug_hooks = &dbx_debug_hooks;
1485 #endif
1486 #if defined(XCOFF_DEBUGGING_INFO)
1487 else if (write_symbols == XCOFF_DEBUG)
1488 debug_hooks = &xcoff_debug_hooks;
1489 #endif
1490 #ifdef SDB_DEBUGGING_INFO
1491 else if (write_symbols == SDB_DEBUG)
1492 debug_hooks = &sdb_debug_hooks;
1493 #endif
1494 #ifdef DWARF2_DEBUGGING_INFO
1495 else if (write_symbols == DWARF2_DEBUG)
1496 debug_hooks = &dwarf2_debug_hooks;
1497 #endif
1498 #ifdef VMS_DEBUGGING_INFO
1499 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1500 debug_hooks = &vmsdbg_debug_hooks;
1501 #endif
1502 else
1503 error ("target system does not support the \"%s\" debug format",
1504 debug_type_names[write_symbols]);
1506 if (flag_auto_profile && debug_info_level == DINFO_LEVEL_NONE)
1507 debug_hooks = &auto_profile_debug_hooks;
1509 /* We know which debug output will be used so we can set flag_var_tracking
1510 and flag_var_tracking_uninit if the user has not specified them. */
1511 if (debug_info_level < DINFO_LEVEL_NORMAL
1512 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1514 if (flag_var_tracking == 1
1515 || flag_var_tracking_uninit == 1)
1517 if (debug_info_level < DINFO_LEVEL_NORMAL)
1518 warning (0, "variable tracking requested, but useless unless "
1519 "producing debug info");
1520 else
1521 warning (0, "variable tracking requested, but not supported "
1522 "by this debug format");
1524 flag_var_tracking = 0;
1525 flag_var_tracking_uninit = 0;
1528 /* The debug hooks are used to implement -fdump-go-spec because it
1529 gives a simple and stable API for all the information we need to
1530 dump. */
1531 if (flag_dump_go_spec != NULL)
1532 debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks);
1534 /* If the user specifically requested variable tracking with tagging
1535 uninitialized variables, we need to turn on variable tracking.
1536 (We already determined above that variable tracking is feasible.) */
1537 if (flag_var_tracking_uninit == 1)
1538 flag_var_tracking = 1;
1540 if (flag_var_tracking == AUTODETECT_VALUE)
1541 flag_var_tracking = optimize >= 1;
1543 if (flag_var_tracking_uninit == AUTODETECT_VALUE)
1544 flag_var_tracking_uninit = flag_var_tracking;
1546 if (flag_var_tracking_assignments == AUTODETECT_VALUE)
1547 flag_var_tracking_assignments = flag_var_tracking
1548 && !(flag_selective_scheduling || flag_selective_scheduling2);
1550 if (flag_var_tracking_assignments_toggle)
1551 flag_var_tracking_assignments = !flag_var_tracking_assignments;
1553 if (flag_var_tracking_assignments && !flag_var_tracking)
1554 flag_var_tracking = flag_var_tracking_assignments = -1;
1556 if (flag_var_tracking_assignments
1557 && (flag_selective_scheduling || flag_selective_scheduling2))
1558 warning (0, "var-tracking-assignments changes selective scheduling");
1560 if (flag_tree_cselim == AUTODETECT_VALUE)
1561 #ifdef HAVE_conditional_move
1562 flag_tree_cselim = 1;
1563 #else
1564 flag_tree_cselim = 0;
1565 #endif
1567 /* If auxiliary info generation is desired, open the output file.
1568 This goes in the same directory as the source file--unlike
1569 all the other output files. */
1570 if (flag_gen_aux_info)
1572 aux_info_file = fopen (aux_info_file_name, "w");
1573 if (aux_info_file == 0)
1574 fatal_error ("can%'t open %s: %m", aux_info_file_name);
1577 if (!targetm_common.have_named_sections)
1579 if (flag_function_sections)
1581 warning (0, "-ffunction-sections not supported for this target");
1582 flag_function_sections = 0;
1584 if (flag_data_sections)
1586 warning (0, "-fdata-sections not supported for this target");
1587 flag_data_sections = 0;
1591 #ifndef HAVE_prefetch
1592 if (flag_prefetch_loop_arrays > 0)
1594 warning (0, "-fprefetch-loop-arrays not supported for this target");
1595 flag_prefetch_loop_arrays = 0;
1597 #else
1598 if (flag_prefetch_loop_arrays > 0 && !HAVE_prefetch)
1600 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
1601 flag_prefetch_loop_arrays = 0;
1603 #endif
1605 /* This combination of options isn't handled for i386 targets and doesn't
1606 make much sense anyway, so don't allow it. */
1607 if (flag_prefetch_loop_arrays > 0 && optimize_size)
1609 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
1610 flag_prefetch_loop_arrays = 0;
1613 /* The presence of IEEE signaling NaNs, implies all math can trap. */
1614 if (flag_signaling_nans)
1615 flag_trapping_math = 1;
1617 /* We cannot reassociate if we want traps or signed zeros. */
1618 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
1620 warning (0, "-fassociative-math disabled; other options take precedence");
1621 flag_associative_math = 0;
1624 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
1625 if (flag_cx_limited_range)
1626 flag_complex_method = 0;
1628 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
1629 if (flag_cx_fortran_rules)
1630 flag_complex_method = 1;
1632 /* Targets must be able to place spill slots at lower addresses. If the
1633 target already uses a soft frame pointer, the transition is trivial. */
1634 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
1636 warning (0, "-fstack-protector not supported for this target");
1637 flag_stack_protect = 0;
1639 if (!flag_stack_protect)
1640 warn_stack_protect = 0;
1642 /* Enable -Werror=coverage-mismatch when -Werror and -Wno-error
1643 have not been set. */
1644 if (!global_options_set.x_warnings_are_errors
1645 && warn_coverage_mismatch
1646 && (global_dc->classify_diagnostic[OPT_Wcoverage_mismatch] ==
1647 DK_UNSPECIFIED))
1648 diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch,
1649 DK_ERROR, UNKNOWN_LOCATION);
1651 /* Save the current optimization options. */
1652 optimization_default_node = build_optimization_node ();
1653 optimization_current_node = optimization_default_node;
1656 /* This function can be called multiple times to reinitialize the compiler
1657 back end when register classes or instruction sets have changed,
1658 before each function. */
1659 static void
1660 backend_init_target (void)
1662 /* Initialize alignment variables. */
1663 init_alignments ();
1665 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
1666 to initialize reg_raw_mode[]. */
1667 init_emit_regs ();
1669 /* This invokes target hooks to set fixed_reg[] etc, which is
1670 mode-dependent. */
1671 init_regs ();
1673 /* This depends on stack_pointer_rtx. */
1674 init_fake_stack_mems ();
1676 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
1677 mode-dependent. */
1678 init_alias_target ();
1680 /* Depends on HARD_FRAME_POINTER_REGNUM. */
1681 init_reload ();
1683 /* The following initialization functions need to generate rtl, so
1684 provide a dummy function context for them. */
1685 init_dummy_function_start ();
1687 /* rtx_cost is mode-dependent, so cached values need to be recomputed
1688 on a mode change. */
1689 init_expmed ();
1691 /* We may need to recompute regno_save_code[] and regno_restore_code[]
1692 after a mode change as well. */
1693 caller_save_initialized_p = false;
1695 expand_dummy_function_end ();
1698 /* Initialize the compiler back end. This function is called only once,
1699 when starting the compiler. */
1700 static void
1701 backend_init (void)
1703 init_emit_once ();
1705 init_rtlanal ();
1706 init_inline_once ();
1707 init_varasm_once ();
1708 save_register_info ();
1710 /* Initialize the target-specific back end pieces. */
1711 ira_init_once ();
1712 backend_init_target ();
1715 /* Initialize excess precision settings. */
1716 static void
1717 init_excess_precision (void)
1719 /* Adjust excess precision handling based on the target options. If
1720 the front end cannot handle it, flag_excess_precision_cmdline
1721 will already have been set accordingly in the post_options
1722 hook. */
1723 gcc_assert (flag_excess_precision_cmdline != EXCESS_PRECISION_DEFAULT);
1724 flag_excess_precision = flag_excess_precision_cmdline;
1725 if (flag_unsafe_math_optimizations)
1726 flag_excess_precision = EXCESS_PRECISION_FAST;
1727 if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
1729 int flt_eval_method = TARGET_FLT_EVAL_METHOD;
1730 switch (flt_eval_method)
1732 case -1:
1733 case 0:
1734 /* Either the target acts unpredictably (-1) or has all the
1735 operations required not to have excess precision (0). */
1736 flag_excess_precision = EXCESS_PRECISION_FAST;
1737 break;
1738 case 1:
1739 case 2:
1740 /* In these cases, predictable excess precision makes
1741 sense. */
1742 break;
1743 default:
1744 /* Any other implementation-defined FLT_EVAL_METHOD values
1745 require the compiler to handle the associated excess
1746 precision rules in excess_precision_type. */
1747 gcc_unreachable ();
1752 /* Initialize things that are both lang-dependent and target-dependent.
1753 This function can be called more than once if target parameters change. */
1754 static void
1755 lang_dependent_init_target (void)
1757 /* This determines excess precision settings. */
1758 init_excess_precision ();
1760 /* This creates various _DECL nodes, so needs to be called after the
1761 front end is initialized. It also depends on the HAVE_xxx macros
1762 generated from the target machine description. */
1763 init_optabs ();
1765 /* The following initialization functions need to generate rtl, so
1766 provide a dummy function context for them. */
1767 init_dummy_function_start ();
1769 /* Do the target-specific parts of expr initialization. */
1770 init_expr_target ();
1772 /* Although the actions of these functions are language-independent,
1773 they use optabs, so we cannot call them from backend_init. */
1774 init_set_costs ();
1775 ira_init ();
1777 expand_dummy_function_end ();
1780 /* Language-dependent initialization. Returns nonzero on success. */
1781 static int
1782 lang_dependent_init (const char *name)
1784 location_t save_loc = input_location;
1785 if (dump_base_name == 0)
1786 dump_base_name = name && name[0] ? name : "gccdump";
1788 /* Other front-end initialization. */
1789 input_location = BUILTINS_LOCATION;
1790 if (lang_hooks.init () == 0)
1791 return 0;
1792 input_location = save_loc;
1794 if (!flag_wpa)
1796 init_asm_output (name);
1798 /* If stack usage information is desired, open the output file. */
1799 if (flag_stack_usage)
1800 stack_usage_file = open_auxiliary_file ("su");
1803 /* This creates various _DECL nodes, so needs to be called after the
1804 front end is initialized. */
1805 init_eh ();
1807 /* Do the target-specific parts of the initialization. */
1808 lang_dependent_init_target ();
1810 if (!flag_wpa)
1812 /* If dbx symbol table desired, initialize writing it and output the
1813 predefined types. */
1814 timevar_push (TV_SYMOUT);
1816 /* Now we have the correct original filename, we can initialize
1817 debug output. */
1818 (*debug_hooks->init) (name);
1820 timevar_pop (TV_SYMOUT);
1823 return 1;
1827 /* Reinitialize everything when target parameters, such as register usage,
1828 have changed. */
1829 void
1830 target_reinit (void)
1832 struct rtl_data saved_x_rtl;
1833 rtx *saved_regno_reg_rtx;
1835 /* Save *crtl and regno_reg_rtx around the reinitialization
1836 to allow target_reinit being called even after prepare_function_start. */
1837 saved_regno_reg_rtx = regno_reg_rtx;
1838 if (saved_regno_reg_rtx)
1840 saved_x_rtl = *crtl;
1841 memset (crtl, '\0', sizeof (*crtl));
1842 regno_reg_rtx = NULL;
1845 /* Reinitialize RTL backend. */
1846 backend_init_target ();
1848 /* Reinitialize lang-dependent parts. */
1849 lang_dependent_init_target ();
1851 /* And restore it at the end, as free_after_compilation from
1852 expand_dummy_function_end clears it. */
1853 if (saved_regno_reg_rtx)
1855 *crtl = saved_x_rtl;
1856 regno_reg_rtx = saved_regno_reg_rtx;
1857 saved_regno_reg_rtx = NULL;
1861 void
1862 dump_memory_report (bool final)
1864 dump_line_table_statistics ();
1865 ggc_print_statistics ();
1866 stringpool_statistics ();
1867 dump_tree_statistics ();
1868 dump_gimple_statistics ();
1869 dump_rtx_statistics ();
1870 dump_alloc_pool_statistics ();
1871 dump_bitmap_statistics ();
1872 dump_vec_loc_statistics ();
1873 dump_ggc_loc_statistics (final);
1874 dump_alias_stats (stderr);
1875 dump_pta_stats (stderr);
1878 /* Clean up: close opened files, etc. */
1880 static void
1881 finalize (bool no_backend)
1883 /* Close the dump files. */
1884 if (flag_gen_aux_info)
1886 fclose (aux_info_file);
1887 if (seen_error ())
1888 unlink (aux_info_file_name);
1891 /* Close non-debugging input and output files. Take special care to note
1892 whether fclose returns an error, since the pages might still be on the
1893 buffer chain while the file is open. */
1895 if (asm_out_file)
1897 if (ferror (asm_out_file) != 0)
1898 fatal_error ("error writing to %s: %m", asm_file_name);
1899 if (fclose (asm_out_file) != 0)
1900 fatal_error ("error closing %s: %m", asm_file_name);
1903 if (stack_usage_file)
1904 fclose (stack_usage_file);
1906 if (!no_backend)
1908 statistics_fini ();
1910 finish_optimization_passes ();
1912 ira_finish_once ();
1915 if (mem_report)
1916 dump_memory_report (true);
1918 /* Language-specific end of compilation actions. */
1919 lang_hooks.finish ();
1922 /* Initialize the compiler, and compile the input file. */
1923 static void
1924 do_compile (void)
1926 /* Initialize timing first. The C front ends read the main file in
1927 the post_options hook, and C++ does file timings. */
1928 if (time_report || !quiet_flag || flag_detailed_statistics)
1929 timevar_init ();
1930 timevar_start (TV_TOTAL);
1932 process_options ();
1934 /* Don't do any more if an error has already occurred. */
1935 if (!seen_error ())
1937 timevar_start (TV_PHASE_SETUP);
1939 /* This must be run always, because it is needed to compute the FP
1940 predefined macros, such as __LDBL_MAX__, for targets using non
1941 default FP formats. */
1942 init_adjust_machine_modes ();
1944 /* Set up the back-end if requested. */
1945 if (!no_backend)
1946 backend_init ();
1948 /* Language-dependent initialization. Returns true on success. */
1949 if (lang_dependent_init (main_input_filename))
1951 /* Initialize yet another pass. */
1953 ggc_protect_identifiers = true;
1955 init_cgraph ();
1956 init_final (main_input_filename);
1957 coverage_init (aux_base_name, main_input_filename);
1958 statistics_init ();
1959 invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
1961 timevar_stop (TV_PHASE_SETUP);
1963 compile_file ();
1964 if (flag_record_compilation_info_in_elf)
1965 write_compilation_info_to_asm ();
1967 else
1969 timevar_stop (TV_PHASE_SETUP);
1972 timevar_start (TV_PHASE_FINALIZE);
1974 finalize (no_backend);
1976 timevar_stop (TV_PHASE_FINALIZE);
1979 /* Stop timing and print the times. */
1980 timevar_stop (TV_TOTAL);
1981 timevar_print (stderr);
1984 /* Entry point of cc1, cc1plus, jc1, f771, etc.
1985 Exit code is FATAL_EXIT_CODE if can't open files or if there were
1986 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
1988 It is not safe to call this function more than once. */
1991 toplev_main (int argc, char **argv)
1993 /* Parsing and gimplification sometimes need quite large stack.
1994 Increase stack size limits if possible. */
1995 stack_limit_increase (64 * 1024 * 1024);
1997 expandargv (&argc, &argv);
1999 /* Initialization of GCC's environment, and diagnostics. */
2000 general_init (argv[0]);
2002 /* One-off initialization of options that does not need to be
2003 repeated when options are added for particular functions. */
2004 init_options_once ();
2006 /* Initialize global options structures; this must be repeated for
2007 each structure used for parsing options. */
2008 init_options_struct (&global_options, &global_options_set);
2009 lang_hooks.init_options_struct (&global_options);
2011 /* Convert the options to an array. */
2012 decode_cmdline_options_to_array_default_mask (argc,
2013 CONST_CAST2 (const char **,
2014 char **, argv),
2015 &save_decoded_options,
2016 &save_decoded_options_count);
2018 /* Perform language-specific options initialization. */
2019 lang_hooks.init_options (save_decoded_options_count, save_decoded_options);
2021 /* Parse the options and do minimal processing; basically just
2022 enough to default flags appropriately. */
2023 decode_options (&global_options, &global_options_set,
2024 save_decoded_options, save_decoded_options_count,
2025 UNKNOWN_LOCATION, global_dc);
2027 handle_common_deferred_options ();
2029 init_local_tick ();
2031 initialize_plugins ();
2033 if (version_flag)
2034 print_version (stderr, "");
2036 if (help_flag)
2037 print_plugins_help (stderr, "");
2039 /* Exit early if we can (e.g. -help). */
2040 if (!exit_after_options)
2041 do_compile ();
2043 if (warningcount || errorcount)
2044 print_ignored_options ();
2045 diagnostic_finish (global_dc);
2047 /* Invoke registered plugin callbacks if any. */
2048 invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
2050 finalize_plugins ();
2051 location_adhoc_data_fini (line_table);
2052 if (seen_error ())
2053 return (FATAL_EXIT_CODE);
2055 return (SUCCESS_EXIT_CODE);