Enable dumping of alias graphs.
[official-gcc/Ramakrishna.git] / gcc / toplev.c
blobdc387c0a5059fbc3a7807cf05faf1b514b79a6cd
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
4 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 #undef FLOAT /* This is for hpux. They should change hpux. */
29 #undef FFS /* Some systems define this in param.h. */
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tm.h"
33 #include <signal.h>
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
37 #endif
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
41 #endif
43 #include "line-map.h"
44 #include "input.h"
45 #include "tree.h"
46 #include "version.h"
47 #include "rtl.h"
48 #include "tm_p.h"
49 #include "flags.h"
50 #include "insn-attr.h"
51 #include "insn-config.h"
52 #include "insn-flags.h"
53 #include "hard-reg-set.h"
54 #include "recog.h"
55 #include "output.h"
56 #include "except.h"
57 #include "function.h"
58 #include "toplev.h"
59 #include "expr.h"
60 #include "basic-block.h"
61 #include "intl.h"
62 #include "ggc.h"
63 #include "graph.h"
64 #include "regs.h"
65 #include "timevar.h"
66 #include "diagnostic.h"
67 #include "params.h"
68 #include "reload.h"
69 #include "ira.h"
70 #include "dwarf2asm.h"
71 #include "integrate.h"
72 #include "real.h"
73 #include "debug.h"
74 #include "target.h"
75 #include "langhooks.h"
76 #include "cfglayout.h"
77 #include "cfgloop.h"
78 #include "hosthooks.h"
79 #include "cgraph.h"
80 #include "opts.h"
81 #include "coverage.h"
82 #include "value-prof.h"
83 #include "alloc-pool.h"
84 #include "tree-mudflap.h"
85 #include "tree-pass.h"
86 #include "gimple.h"
87 #include "tree-ssa-alias.h"
88 #include "plugin.h"
90 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
91 #include "dwarf2out.h"
92 #endif
94 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
95 #include "dbxout.h"
96 #endif
98 #ifdef SDB_DEBUGGING_INFO
99 #include "sdbout.h"
100 #endif
102 #ifdef XCOFF_DEBUGGING_INFO
103 #include "xcoffout.h" /* Needed for external data
104 declarations for e.g. AIX 4.x. */
105 #endif
107 static void general_init (const char *);
108 static void do_compile (void);
109 static void process_options (void);
110 static void backend_init (void);
111 static int lang_dependent_init (const char *);
112 static void init_asm_output (const char *);
113 static void finalize (void);
115 static void crash_signal (int) ATTRIBUTE_NORETURN;
116 static void setup_core_dumping (void);
117 static void compile_file (void);
119 /* Nonzero to dump debug info whilst parsing (-dy option). */
120 static int set_yydebug;
122 /* True if we don't need a backend (e.g. preprocessing only). */
123 static bool no_backend;
125 /* Length of line when printing switch values. */
126 #define MAX_LINE 75
128 /* Name of program invoked, sans directories. */
130 const char *progname;
132 /* Copy of argument vector to toplev_main. */
133 static const char **save_argv;
135 /* Name of top-level original source file (what was input to cpp).
136 This comes from the #-command at the beginning of the actual input.
137 If there isn't any there, then this is the cc1 input file name. */
139 const char *main_input_filename;
141 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
142 to optimize and default_debug_hooks in process_options (). */
143 #define AUTODETECT_VALUE 2
145 /* Current position in real source file. */
147 location_t input_location;
149 struct line_maps *line_table;
151 /* Name to use as base of names for dump output files. */
153 const char *dump_base_name;
155 /* Name to use as a base for auxiliary output files. */
157 const char *aux_base_name;
159 /* Prefix for profile data files */
160 const char *profile_data_prefix;
162 /* A mask of target_flags that includes bit X if X was set or cleared
163 on the command line. */
165 int target_flags_explicit;
167 /* Debug hooks - dependent upon command line options. */
169 const struct gcc_debug_hooks *debug_hooks;
171 /* Debug hooks - target default. */
173 static const struct gcc_debug_hooks *default_debug_hooks;
175 /* Other flags saying which kinds of debugging dump have been requested. */
177 int rtl_dump_and_exit;
178 int flag_print_asm_name;
179 enum graph_dump_types graph_dump_format;
181 /* Name for output file of assembly code, specified with -o. */
183 const char *asm_file_name;
185 /* Nonzero means do optimizations. -O.
186 Particular numeric values stand for particular amounts of optimization;
187 thus, -O2 stores 2 here. However, the optimizations beyond the basic
188 ones are not controlled directly by this variable. Instead, they are
189 controlled by individual `flag_...' variables that are defaulted
190 based on this variable. */
192 int optimize = 0;
194 /* Nonzero means optimize for size. -Os.
195 The only valid values are zero and nonzero. When optimize_size is
196 nonzero, optimize defaults to 2, but certain individual code
197 bloating optimizations are disabled. */
199 int optimize_size = 0;
201 /* The FUNCTION_DECL for the function currently being compiled,
202 or 0 if between functions. */
203 tree current_function_decl;
205 /* Set to the FUNC_BEGIN label of the current function, or NULL
206 if none. */
207 const char * current_function_func_begin_label;
209 /* Nonzero means to collect statistics which might be expensive
210 and to print them when we are done. */
211 int flag_detailed_statistics = 0;
213 /* A random sequence of characters, unless overridden by user. */
214 static const char *flag_random_seed;
216 /* A local time stamp derived from the time of compilation. It will be
217 zero if the system cannot provide a time. It will be -1u, if the
218 user has specified a particular random seed. */
219 unsigned local_tick;
221 /* -f flags. */
223 /* Nonzero means `char' should be signed. */
225 int flag_signed_char;
227 /* Nonzero means give an enum type only as many bytes as it needs. A value
228 of 2 means it has not yet been initialized. */
230 int flag_short_enums;
232 /* Nonzero if structures and unions should be returned in memory.
234 This should only be defined if compatibility with another compiler or
235 with an ABI is needed, because it results in slower code. */
237 #ifndef DEFAULT_PCC_STRUCT_RETURN
238 #define DEFAULT_PCC_STRUCT_RETURN 1
239 #endif
241 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
243 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
245 /* 0 means straightforward implementation of complex divide acceptable.
246 1 means wide ranges of inputs must work for complex divide.
247 2 means C99-like requirements for complex multiply and divide. */
249 int flag_complex_method = 1;
251 /* Nonzero means we should be saving declaration info into a .X file. */
253 int flag_gen_aux_info = 0;
255 /* Specified name of aux-info file. */
257 const char *aux_info_file_name;
259 /* Nonzero if we are compiling code for a shared library, zero for
260 executable. */
262 int flag_shlib;
264 /* Generate code for GNU or NeXT Objective-C runtime environment. */
266 #ifdef NEXT_OBJC_RUNTIME
267 int flag_next_runtime = 1;
268 #else
269 int flag_next_runtime = 0;
270 #endif
272 /* Set to the default thread-local storage (tls) model to use. */
274 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
276 /* Set the default region and algorithm for the integrated register
277 allocator. */
279 enum ira_algorithm flag_ira_algorithm = IRA_ALGORITHM_CB;
280 enum ira_region flag_ira_region = IRA_REGION_MIXED;
282 /* Set the default value for -fira-verbose. */
284 unsigned int flag_ira_verbose = 5;
286 /* Set the default for excess precision. */
288 enum excess_precision flag_excess_precision_cmdline = EXCESS_PRECISION_DEFAULT;
289 enum excess_precision flag_excess_precision = EXCESS_PRECISION_DEFAULT;
291 /* Nonzero means change certain warnings into errors.
292 Usually these are warnings about failure to conform to some standard. */
294 int flag_pedantic_errors = 0;
296 /* Nonzero means make permerror produce warnings instead of errors. */
298 int flag_permissive = 0;
300 /* -dA causes debug commentary information to be produced in
301 the generated assembly code (to make it more readable). This option
302 is generally only of use to those who actually need to read the
303 generated assembly code (perhaps while debugging the compiler itself).
304 Currently, this switch is only used by dwarfout.c; however, it is intended
305 to be a catchall for printing debug information in the assembler file. */
307 int flag_debug_asm = 0;
309 /* -dP causes the rtl to be emitted as a comment in assembly. */
311 int flag_dump_rtl_in_asm = 0;
313 /* When non-NULL, indicates that whenever space is allocated on the
314 stack, the resulting stack pointer must not pass this
315 address---that is, for stacks that grow downward, the stack pointer
316 must always be greater than or equal to this address; for stacks
317 that grow upward, the stack pointer must be less than this address.
318 At present, the rtx may be either a REG or a SYMBOL_REF, although
319 the support provided depends on the backend. */
320 rtx stack_limit_rtx;
322 /* Positive if we should track variables, negative if we should run
323 the var-tracking pass only to discard debug annotations, zero if
324 we're not to run it. When flag_var_tracking == AUTODETECT_VALUE it
325 will be set according to optimize, debug_info_level and debug_hooks
326 in process_options (). */
327 int flag_var_tracking = AUTODETECT_VALUE;
329 /* Positive if we should track variables at assignments, negative if
330 we should run the var-tracking pass only to discard debug
331 annotations. When flag_var_tracking_assignments ==
332 AUTODETECT_VALUE it will be set according to flag_var_tracking. */
333 int flag_var_tracking_assignments = AUTODETECT_VALUE;
335 /* Nonzero if we should toggle flag_var_tracking_assignments after
336 processing options and computing its default. */
337 int flag_var_tracking_assignments_toggle = 0;
339 /* Type of stack check. */
340 enum stack_check_type flag_stack_check = NO_STACK_CHECK;
342 /* True if the user has tagged the function with the 'section'
343 attribute. */
345 bool user_defined_section_attribute = false;
347 /* Values of the -falign-* flags: how much to align labels in code.
348 0 means `use default', 1 means `don't align'.
349 For each variable, there is an _log variant which is the power
350 of two not less than the variable, for .align output. */
352 int align_loops_log;
353 int align_loops_max_skip;
354 int align_jumps_log;
355 int align_jumps_max_skip;
356 int align_labels_log;
357 int align_labels_max_skip;
358 int align_functions_log;
360 typedef struct
362 const char *const string;
363 int *const variable;
364 const int on_value;
366 lang_independent_options;
368 /* Nonzero if subexpressions must be evaluated from left-to-right. */
369 int flag_evaluation_order = 0;
371 /* The user symbol prefix after having resolved same. */
372 const char *user_label_prefix;
374 static const param_info lang_independent_params[] = {
375 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
376 { OPTION, DEFAULT, false, MIN, MAX, HELP },
377 #include "params.def"
378 #undef DEFPARAM
379 { NULL, 0, false, 0, 0, NULL }
382 /* Output files for assembler code (real compiler output)
383 and debugging dumps. */
385 FILE *asm_out_file;
386 FILE *graphite_out_file;
387 FILE *graphite_in_file;
388 FILE *aux_info_file;
389 FILE *dump_file = NULL;
390 const char *dump_file_name;
392 /* The current working directory of a translation. It's generally the
393 directory from which compilation was initiated, but a preprocessed
394 file may specify the original directory in which it was
395 created. */
397 static const char *src_pwd;
399 /* Initialize src_pwd with the given string, and return true. If it
400 was already initialized, return false. As a special case, it may
401 be called with a NULL argument to test whether src_pwd has NOT been
402 initialized yet. */
404 bool
405 set_src_pwd (const char *pwd)
407 if (src_pwd)
409 if (strcmp (src_pwd, pwd) == 0)
410 return true;
411 else
412 return false;
415 src_pwd = xstrdup (pwd);
416 return true;
419 /* Return the directory from which the translation unit was initiated,
420 in case set_src_pwd() was not called before to assign it a
421 different value. */
423 const char *
424 get_src_pwd (void)
426 if (! src_pwd)
428 src_pwd = getpwd ();
429 if (!src_pwd)
430 src_pwd = ".";
433 return src_pwd;
436 /* Called when the start of a function definition is parsed,
437 this function prints on stderr the name of the function. */
438 void
439 announce_function (tree decl)
441 if (!quiet_flag)
443 if (rtl_dump_and_exit)
444 fprintf (stderr, "%s ",
445 identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))));
446 else
447 fprintf (stderr, " %s",
448 identifier_to_locale (lang_hooks.decl_printable_name (decl, 2)));
449 fflush (stderr);
450 pp_needs_newline (global_dc->printer) = true;
451 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
455 /* Initialize local_tick with the time of day, or -1 if
456 flag_random_seed is set. */
458 static void
459 init_local_tick (void)
461 if (!flag_random_seed)
463 /* Get some more or less random data. */
464 #ifdef HAVE_GETTIMEOFDAY
466 struct timeval tv;
468 gettimeofday (&tv, NULL);
469 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
471 #else
473 time_t now = time (NULL);
475 if (now != (time_t)-1)
476 local_tick = (unsigned) now;
478 #endif
480 else
481 local_tick = -1;
484 /* Set up a default flag_random_seed and local_tick, unless the user
485 already specified one. Must be called after init_local_tick. */
487 static void
488 init_random_seed (void)
490 unsigned HOST_WIDE_INT value;
491 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
493 value = local_tick ^ getpid ();
495 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
496 flag_random_seed = random_seed;
499 /* Obtain the random_seed string. Unless NOINIT, initialize it if
500 it's not provided in the command line. */
502 const char *
503 get_random_seed (bool noinit)
505 if (!flag_random_seed && !noinit)
506 init_random_seed ();
507 return flag_random_seed;
510 /* Modify the random_seed string to VAL. Return its previous
511 value. */
513 const char *
514 set_random_seed (const char *val)
516 const char *old = flag_random_seed;
517 flag_random_seed = val;
518 return old;
521 /* Decode the string P as an integral parameter.
522 If the string is indeed an integer return its numeric value else
523 issue an Invalid Option error for the option PNAME and return DEFVAL.
524 If PNAME is zero just return DEFVAL, do not call error. */
527 read_integral_parameter (const char *p, const char *pname, const int defval)
529 const char *endp = p;
531 while (*endp)
533 if (ISDIGIT (*endp))
534 endp++;
535 else
536 break;
539 if (*endp != 0)
541 if (pname != 0)
542 error ("invalid option argument %qs", pname);
543 return defval;
546 return atoi (p);
549 #if GCC_VERSION < 3004
551 /* The functions floor_log2 and exact_log2 are defined as inline
552 functions in toplev.h if GCC_VERSION >= 3004. The definitions here
553 are used for older versions of gcc. */
555 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
556 If X is 0, return -1. */
559 floor_log2 (unsigned HOST_WIDE_INT x)
561 int t = 0;
563 if (x == 0)
564 return -1;
566 if (HOST_BITS_PER_WIDE_INT > 64)
567 if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
568 t += 64;
569 if (HOST_BITS_PER_WIDE_INT > 32)
570 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
571 t += 32;
572 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
573 t += 16;
574 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8))
575 t += 8;
576 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4))
577 t += 4;
578 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2))
579 t += 2;
580 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
581 t += 1;
583 return t;
586 /* Return the logarithm of X, base 2, considering X unsigned,
587 if X is a power of 2. Otherwise, returns -1. */
590 exact_log2 (unsigned HOST_WIDE_INT x)
592 if (x != (x & -x))
593 return -1;
594 return floor_log2 (x);
597 #endif /* GCC_VERSION < 3004 */
599 /* Handler for fatal signals, such as SIGSEGV. These are transformed
600 into ICE messages, which is much more user friendly. In case the
601 error printer crashes, reset the signal to prevent infinite recursion. */
603 static void
604 crash_signal (int signo)
606 signal (signo, SIG_DFL);
608 /* If we crashed while processing an ASM statement, then be a little more
609 graceful. It's most likely the user's fault. */
610 if (this_is_asm_operands)
612 output_operand_lossage ("unrecoverable error");
613 exit (FATAL_EXIT_CODE);
616 internal_error ("%s", strsignal (signo));
619 /* Arrange to dump core on error. (The regular error message is still
620 printed first, except in the case of abort().) */
622 static void
623 setup_core_dumping (void)
625 #ifdef SIGABRT
626 signal (SIGABRT, SIG_DFL);
627 #endif
628 #if defined(HAVE_SETRLIMIT)
630 struct rlimit rlim;
631 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
632 fatal_error ("getting core file size maximum limit: %m");
633 rlim.rlim_cur = rlim.rlim_max;
634 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
635 fatal_error ("setting core file size limit to maximum: %m");
637 #endif
638 diagnostic_abort_on_error (global_dc);
642 /* Strip off a legitimate source ending from the input string NAME of
643 length LEN. Rather than having to know the names used by all of
644 our front ends, we strip off an ending of a period followed by
645 up to five characters. (Java uses ".class".) */
647 void
648 strip_off_ending (char *name, int len)
650 int i;
651 for (i = 2; i < 6 && len > i; i++)
653 if (name[len - i] == '.')
655 name[len - i] = '\0';
656 break;
661 /* Output a quoted string. */
663 void
664 output_quoted_string (FILE *asm_file, const char *string)
666 #ifdef OUTPUT_QUOTED_STRING
667 OUTPUT_QUOTED_STRING (asm_file, string);
668 #else
669 char c;
671 putc ('\"', asm_file);
672 while ((c = *string++) != 0)
674 if (ISPRINT (c))
676 if (c == '\"' || c == '\\')
677 putc ('\\', asm_file);
678 putc (c, asm_file);
680 else
681 fprintf (asm_file, "\\%03o", (unsigned char) c);
683 putc ('\"', asm_file);
684 #endif
687 /* Output a file name in the form wanted by System V. */
689 void
690 output_file_directive (FILE *asm_file, const char *input_name)
692 int len;
693 const char *na;
695 if (input_name == NULL)
696 input_name = "<stdin>";
697 else
698 input_name = remap_debug_filename (input_name);
700 len = strlen (input_name);
701 na = input_name + len;
703 /* NA gets INPUT_NAME sans directory names. */
704 while (na > input_name)
706 if (IS_DIR_SEPARATOR (na[-1]))
707 break;
708 na--;
711 #ifdef ASM_OUTPUT_SOURCE_FILENAME
712 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
713 #else
714 fprintf (asm_file, "\t.file\t");
715 output_quoted_string (asm_file, na);
716 fputc ('\n', asm_file);
717 #endif
720 /* A subroutine of wrapup_global_declarations. We've come to the end of
721 the compilation unit. All deferred variables should be undeferred,
722 and all incomplete decls should be finalized. */
724 void
725 wrapup_global_declaration_1 (tree decl)
727 /* We're not deferring this any longer. Assignment is conditional to
728 avoid needlessly dirtying PCH pages. */
729 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
730 && DECL_DEFER_OUTPUT (decl) != 0)
731 DECL_DEFER_OUTPUT (decl) = 0;
733 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
734 lang_hooks.finish_incomplete_decl (decl);
737 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
738 needs to be output. Return true if it is output. */
740 bool
741 wrapup_global_declaration_2 (tree decl)
743 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
744 return false;
746 /* Don't write out static consts, unless we still need them.
748 We also keep static consts if not optimizing (for debugging),
749 unless the user specified -fno-keep-static-consts.
750 ??? They might be better written into the debug information.
751 This is possible when using DWARF.
753 A language processor that wants static constants to be always
754 written out (even if it is not used) is responsible for
755 calling rest_of_decl_compilation itself. E.g. the C front-end
756 calls rest_of_decl_compilation from finish_decl.
757 One motivation for this is that is conventional in some
758 environments to write things like:
759 static const char rcsid[] = "... version string ...";
760 intending to force the string to be in the executable.
762 A language processor that would prefer to have unneeded
763 static constants "optimized away" would just defer writing
764 them out until here. E.g. C++ does this, because static
765 constants are often defined in header files.
767 ??? A tempting alternative (for both C and C++) would be
768 to force a constant to be written if and only if it is
769 defined in a main file, as opposed to an include file. */
771 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
773 struct varpool_node *node;
774 bool needed = true;
775 node = varpool_node (decl);
777 if (node->finalized)
778 needed = false;
779 else if (node->alias)
780 needed = false;
781 else if (!cgraph_global_info_ready
782 && (TREE_USED (decl)
783 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
784 /* needed */;
785 else if (node->needed)
786 /* needed */;
787 else if (DECL_COMDAT (decl))
788 needed = false;
789 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
790 && (optimize || !flag_keep_static_consts
791 || DECL_ARTIFICIAL (decl)))
792 needed = false;
794 if (needed)
796 rest_of_decl_compilation (decl, 1, 1);
797 return true;
801 return false;
804 /* Do any final processing required for the declarations in VEC, of
805 which there are LEN. We write out inline functions and variables
806 that have been deferred until this point, but which are required.
807 Returns nonzero if anything was put out. */
809 bool
810 wrapup_global_declarations (tree *vec, int len)
812 bool reconsider, output_something = false;
813 int i;
815 for (i = 0; i < len; i++)
816 wrapup_global_declaration_1 (vec[i]);
818 /* Now emit any global variables or functions that we have been
819 putting off. We need to loop in case one of the things emitted
820 here references another one which comes earlier in the list. */
823 reconsider = false;
824 for (i = 0; i < len; i++)
825 reconsider |= wrapup_global_declaration_2 (vec[i]);
826 if (reconsider)
827 output_something = true;
829 while (reconsider);
831 return output_something;
834 /* A subroutine of check_global_declarations. Issue appropriate warnings
835 for the global declaration DECL. */
837 void
838 check_global_declaration_1 (tree decl)
840 /* Warn about any function declared static but not defined. We don't
841 warn about variables, because many programs have static variables
842 that exist only to get some text into the object file. */
843 if (TREE_CODE (decl) == FUNCTION_DECL
844 && DECL_INITIAL (decl) == 0
845 && DECL_EXTERNAL (decl)
846 && ! DECL_ARTIFICIAL (decl)
847 && ! TREE_NO_WARNING (decl)
848 && ! TREE_PUBLIC (decl)
849 && (warn_unused_function
850 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
852 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
853 pedwarn (input_location, 0, "%q+F used but never defined", decl);
854 else
855 warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
856 /* This symbol is effectively an "extern" declaration now. */
857 TREE_PUBLIC (decl) = 1;
858 assemble_external (decl);
861 /* Warn about static fns or vars defined but not used. */
862 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
863 /* We don't warn about "static const" variables because the
864 "rcs_id" idiom uses that construction. */
865 || (warn_unused_variable
866 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
867 && ! DECL_IN_SYSTEM_HEADER (decl)
868 && ! TREE_USED (decl)
869 /* The TREE_USED bit for file-scope decls is kept in the identifier,
870 to handle multiple external decls in different scopes. */
871 && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
872 && ! DECL_EXTERNAL (decl)
873 && ! TREE_PUBLIC (decl)
874 /* A volatile variable might be used in some non-obvious way. */
875 && ! TREE_THIS_VOLATILE (decl)
876 /* Global register variables must be declared to reserve them. */
877 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
878 /* Otherwise, ask the language. */
879 && lang_hooks.decls.warn_unused_global (decl))
880 warning ((TREE_CODE (decl) == FUNCTION_DECL)
881 ? OPT_Wunused_function
882 : OPT_Wunused_variable,
883 "%q+D defined but not used", decl);
886 /* Issue appropriate warnings for the global declarations in VEC (of
887 which there are LEN). */
889 void
890 check_global_declarations (tree *vec, int len)
892 int i;
894 for (i = 0; i < len; i++)
895 check_global_declaration_1 (vec[i]);
898 /* Emit debugging information for all global declarations in VEC. */
900 void
901 emit_debug_global_declarations (tree *vec, int len)
903 int i;
905 /* Avoid confusing the debug information machinery when there are errors. */
906 if (errorcount != 0 || sorrycount != 0)
907 return;
909 timevar_push (TV_SYMOUT);
910 for (i = 0; i < len; i++)
911 debug_hooks->global_decl (vec[i]);
912 timevar_pop (TV_SYMOUT);
915 /* Warn about a use of an identifier which was marked deprecated. */
916 void
917 warn_deprecated_use (tree node, tree attr)
919 const char *msg;
921 if (node == 0 || !warn_deprecated_decl)
922 return;
924 if (!attr)
926 if (DECL_P (node))
927 attr = DECL_ATTRIBUTES (node);
928 else if (TYPE_P (node))
930 tree decl = TYPE_STUB_DECL (node);
931 if (decl)
932 attr = lookup_attribute ("deprecated",
933 TYPE_ATTRIBUTES (TREE_TYPE (decl)));
937 if (attr)
938 attr = lookup_attribute ("deprecated", attr);
940 if (attr)
941 msg = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
942 else
943 msg = NULL;
945 if (DECL_P (node))
947 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
948 if (msg)
949 warning (OPT_Wdeprecated_declarations,
950 "%qD is deprecated (declared at %s:%d): %s",
951 node, xloc.file, xloc.line, msg);
952 else
953 warning (OPT_Wdeprecated_declarations,
954 "%qD is deprecated (declared at %s:%d)",
955 node, xloc.file, xloc.line);
957 else if (TYPE_P (node))
959 tree what = NULL_TREE;
960 tree decl = TYPE_STUB_DECL (node);
962 if (TYPE_NAME (node))
964 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
965 what = TYPE_NAME (node);
966 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
967 && DECL_NAME (TYPE_NAME (node)))
968 what = DECL_NAME (TYPE_NAME (node));
971 if (decl)
973 expanded_location xloc
974 = expand_location (DECL_SOURCE_LOCATION (decl));
975 if (what)
977 if (msg)
978 warning (OPT_Wdeprecated_declarations,
979 "%qE is deprecated (declared at %s:%d): %s",
980 what, xloc.file, xloc.line, msg);
981 else
982 warning (OPT_Wdeprecated_declarations,
983 "%qE is deprecated (declared at %s:%d)", what,
984 xloc.file, xloc.line);
986 else
988 if (msg)
989 warning (OPT_Wdeprecated_declarations,
990 "type is deprecated (declared at %s:%d): %s",
991 xloc.file, xloc.line, msg);
992 else
993 warning (OPT_Wdeprecated_declarations,
994 "type is deprecated (declared at %s:%d)",
995 xloc.file, xloc.line);
998 else
1000 if (what)
1002 if (msg)
1003 warning (OPT_Wdeprecated_declarations, "%qE is deprecated: %s",
1004 what, msg);
1005 else
1006 warning (OPT_Wdeprecated_declarations, "%qE is deprecated", what);
1008 else
1010 if (msg)
1011 warning (OPT_Wdeprecated_declarations, "type is deprecated: %s",
1012 msg);
1013 else
1014 warning (OPT_Wdeprecated_declarations, "type is deprecated");
1020 /* Compile an entire translation unit. Write a file of assembly
1021 output and various debugging dumps. */
1023 static void
1024 compile_file (void)
1026 /* Initialize yet another pass. */
1028 ggc_protect_identifiers = true;
1030 init_cgraph ();
1031 init_final (main_input_filename);
1032 coverage_init (aux_base_name);
1033 statistics_init ();
1034 invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
1036 timevar_push (TV_PARSE);
1038 /* Call the parser, which parses the entire file (calling
1039 rest_of_compilation for each function). */
1040 lang_hooks.parse_file (set_yydebug);
1042 /* Compilation is now finished except for writing
1043 what's left of the symbol table output. */
1044 timevar_pop (TV_PARSE);
1046 if (flag_syntax_only)
1047 return;
1049 ggc_protect_identifiers = false;
1051 /* This must also call cgraph_finalize_compilation_unit. */
1052 lang_hooks.decls.final_write_globals ();
1054 if (errorcount || sorrycount)
1055 return;
1057 varpool_assemble_pending_decls ();
1058 finish_aliases_2 ();
1060 /* Likewise for mudflap static object registrations. */
1061 if (flag_mudflap)
1062 mudflap_finish_file ();
1064 /* Likewise for emulated thread-local storage. */
1065 if (!targetm.have_tls)
1066 emutls_finish ();
1068 output_shared_constant_pool ();
1069 output_object_blocks ();
1071 /* Write out any pending weak symbol declarations. */
1072 weak_finish ();
1074 /* Do dbx symbols. */
1075 timevar_push (TV_SYMOUT);
1077 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
1078 if (dwarf2out_do_frame ())
1079 dwarf2out_frame_finish ();
1080 #endif
1082 (*debug_hooks->finish) (main_input_filename);
1083 timevar_pop (TV_SYMOUT);
1085 /* Output some stuff at end of file if nec. */
1087 dw2_output_indirect_constants ();
1089 /* Flush any pending external directives. */
1090 process_pending_assemble_externals ();
1092 /* Attach a special .ident directive to the end of the file to identify
1093 the version of GCC which compiled this code. The format of the .ident
1094 string is patterned after the ones produced by native SVR4 compilers. */
1095 #ifdef IDENT_ASM_OP
1096 if (!flag_no_ident)
1098 const char *pkg_version = "(GNU) ";
1100 if (strcmp ("(GCC) ", pkgversion_string))
1101 pkg_version = pkgversion_string;
1102 fprintf (asm_out_file, "%s\"GCC: %s%s\"\n",
1103 IDENT_ASM_OP, pkg_version, version_string);
1105 #endif
1107 /* Invoke registered plugin callbacks. */
1108 invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
1110 /* This must be at the end. Some target ports emit end of file directives
1111 into the assembly file here, and hence we can not output anything to the
1112 assembly file after this point. */
1113 targetm.asm_out.file_end ();
1116 /* Parse a -d... command line switch. */
1118 void
1119 decode_d_option (const char *arg)
1121 int c;
1123 while (*arg)
1124 switch (c = *arg++)
1126 case 'A':
1127 flag_debug_asm = 1;
1128 break;
1129 case 'p':
1130 flag_print_asm_name = 1;
1131 break;
1132 case 'P':
1133 flag_dump_rtl_in_asm = 1;
1134 flag_print_asm_name = 1;
1135 break;
1136 case 'v':
1137 graph_dump_format = vcg;
1138 break;
1139 case 'x':
1140 rtl_dump_and_exit = 1;
1141 break;
1142 case 'y':
1143 set_yydebug = 1;
1144 break;
1145 case 'D': /* These are handled by the preprocessor. */
1146 case 'I':
1147 case 'M':
1148 case 'N':
1149 case 'U':
1150 break;
1151 case 'H':
1152 setup_core_dumping();
1153 break;
1154 case 'a':
1155 enable_rtl_dump_file ();
1156 break;
1158 default:
1159 warning (0, "unrecognized gcc debugging option: %c", c);
1160 break;
1164 /* Indexed by enum debug_info_type. */
1165 const char *const debug_type_names[] =
1167 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
1170 /* Print version information to FILE.
1171 Each line begins with INDENT (for the case where FILE is the
1172 assembler output file). */
1174 void
1175 print_version (FILE *file, const char *indent)
1177 static const char fmt1[] =
1178 #ifdef __GNUC__
1179 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
1180 #else
1181 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
1182 #endif
1184 #ifdef HAVE_mpc
1185 static const char fmt2[] =
1186 N_("GMP version %s, MPFR version %s, MPC version %s\n");
1187 #else
1188 static const char fmt2[] =
1189 N_("GMP version %s, MPFR version %s\n");
1190 #endif
1191 static const char fmt3[] =
1192 N_("%s%swarning: %s header version %s differs from library version %s.\n");
1193 static const char fmt4[] =
1194 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
1195 #ifndef __VERSION__
1196 #define __VERSION__ "[?]"
1197 #endif
1198 fprintf (file,
1199 file == stderr ? _(fmt1) : fmt1,
1200 indent, *indent != 0 ? " " : "",
1201 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
1202 indent, __VERSION__);
1204 /* We need to stringify the GMP macro values. Ugh, gmp_version has
1205 two string formats, "i.j.k" and "i.j" when k is zero. As of
1206 gmp-4.3.0, GMP always uses the 3 number format. */
1207 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
1208 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
1209 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
1210 #define GCC_GMP_VERSION \
1211 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
1212 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
1213 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1214 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
1215 #else
1216 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1217 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
1218 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
1219 #endif
1220 fprintf (file,
1221 file == stderr ? _(fmt2) : fmt2,
1222 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING
1223 #ifdef HAVE_mpc
1224 , MPC_VERSION_STRING
1225 #endif
1227 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
1228 fprintf (file,
1229 file == stderr ? _(fmt3) : fmt3,
1230 indent, *indent != 0 ? " " : "",
1231 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
1232 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
1233 fprintf (file,
1234 file == stderr ? _(fmt3) : fmt3,
1235 indent, *indent != 0 ? " " : "",
1236 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
1237 #ifdef HAVE_mpc
1238 if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
1239 fprintf (file,
1240 file == stderr ? _(fmt3) : fmt3,
1241 indent, *indent != 0 ? " " : "",
1242 "MPC", MPC_VERSION_STRING, mpc_get_version ());
1243 #endif
1244 fprintf (file,
1245 file == stderr ? _(fmt4) : fmt4,
1246 indent, *indent != 0 ? " " : "",
1247 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
1249 print_plugins_versions (file, indent);
1252 #ifdef ASM_COMMENT_START
1253 static int
1254 print_to_asm_out_file (print_switch_type type, const char * text)
1256 bool prepend_sep = true;
1258 switch (type)
1260 case SWITCH_TYPE_LINE_END:
1261 putc ('\n', asm_out_file);
1262 return 1;
1264 case SWITCH_TYPE_LINE_START:
1265 fputs (ASM_COMMENT_START, asm_out_file);
1266 return strlen (ASM_COMMENT_START);
1268 case SWITCH_TYPE_DESCRIPTIVE:
1269 if (ASM_COMMENT_START[0] == 0)
1270 prepend_sep = false;
1271 /* Drop through. */
1272 case SWITCH_TYPE_PASSED:
1273 case SWITCH_TYPE_ENABLED:
1274 if (prepend_sep)
1275 fputc (' ', asm_out_file);
1276 fprintf (asm_out_file, text);
1277 /* No need to return the length here as
1278 print_single_switch has already done it. */
1279 return 0;
1281 default:
1282 return -1;
1285 #endif
1287 static int
1288 print_to_stderr (print_switch_type type, const char * text)
1290 switch (type)
1292 case SWITCH_TYPE_LINE_END:
1293 putc ('\n', stderr);
1294 return 1;
1296 case SWITCH_TYPE_LINE_START:
1297 return 0;
1299 case SWITCH_TYPE_PASSED:
1300 case SWITCH_TYPE_ENABLED:
1301 fputc (' ', stderr);
1302 /* Drop through. */
1304 case SWITCH_TYPE_DESCRIPTIVE:
1305 fprintf (stderr, text);
1306 /* No need to return the length here as
1307 print_single_switch has already done it. */
1308 return 0;
1310 default:
1311 return -1;
1315 /* Print an option value and return the adjusted position in the line.
1316 ??? print_fn doesn't handle errors, eg disk full; presumably other
1317 code will catch a disk full though. */
1319 static int
1320 print_single_switch (print_switch_fn_type print_fn,
1321 int pos,
1322 print_switch_type type,
1323 const char * text)
1325 /* The ultrix fprintf returns 0 on success, so compute the result
1326 we want here since we need it for the following test. The +1
1327 is for the separator character that will probably be emitted. */
1328 int len = strlen (text) + 1;
1330 if (pos != 0
1331 && pos + len > MAX_LINE)
1333 print_fn (SWITCH_TYPE_LINE_END, NULL);
1334 pos = 0;
1337 if (pos == 0)
1338 pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
1340 print_fn (type, text);
1341 return pos + len;
1344 /* Print active target switches using PRINT_FN.
1345 POS is the current cursor position and MAX is the size of a "line".
1346 Each line begins with INDENT and ends with TERM.
1347 Each switch is separated from the next by SEP. */
1349 static void
1350 print_switch_values (print_switch_fn_type print_fn)
1352 int pos = 0;
1353 size_t j;
1354 const char **p;
1356 /* Fill in the -frandom-seed option, if the user didn't pass it, so
1357 that it can be printed below. This helps reproducibility. */
1358 if (!flag_random_seed)
1359 init_random_seed ();
1361 /* Print the options as passed. */
1362 pos = print_single_switch (print_fn, pos,
1363 SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
1365 for (p = &save_argv[1]; *p != NULL; p++)
1367 if (**p == '-')
1369 /* Ignore these. */
1370 if (strcmp (*p, "-o") == 0
1371 || strcmp (*p, "-dumpbase") == 0
1372 || strcmp (*p, "-auxbase") == 0)
1374 if (p[1] != NULL)
1375 p++;
1376 continue;
1379 if (strcmp (*p, "-quiet") == 0
1380 || strcmp (*p, "-version") == 0)
1381 continue;
1383 if ((*p)[1] == 'd')
1384 continue;
1387 pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED, *p);
1390 if (pos > 0)
1391 print_fn (SWITCH_TYPE_LINE_END, NULL);
1393 /* Print the -f and -m options that have been enabled.
1394 We don't handle language specific options but printing argv
1395 should suffice. */
1396 pos = print_single_switch (print_fn, 0,
1397 SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
1399 for (j = 0; j < cl_options_count; j++)
1400 if ((cl_options[j].flags & CL_REPORT)
1401 && option_enabled (j) > 0)
1402 pos = print_single_switch (print_fn, pos,
1403 SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
1405 print_fn (SWITCH_TYPE_LINE_END, NULL);
1408 /* Open assembly code output file. Do this even if -fsyntax-only is
1409 on, because then the driver will have provided the name of a
1410 temporary file or bit bucket for us. NAME is the file specified on
1411 the command line, possibly NULL. */
1412 static void
1413 init_asm_output (const char *name)
1415 if (name == NULL && asm_file_name == 0)
1416 asm_out_file = stdout;
1417 else
1419 if (asm_file_name == 0)
1421 int len = strlen (dump_base_name);
1422 char *dumpname = XNEWVEC (char, len + 6);
1424 memcpy (dumpname, dump_base_name, len + 1);
1425 strip_off_ending (dumpname, len);
1426 strcat (dumpname, ".s");
1427 asm_file_name = dumpname;
1429 if (!strcmp (asm_file_name, "-"))
1430 asm_out_file = stdout;
1431 else
1432 asm_out_file = fopen (asm_file_name, "w+b");
1433 if (asm_out_file == 0)
1434 fatal_error ("can%'t open %s for writing: %m", asm_file_name);
1437 if (flag_graphite_read)
1439 int len = strlen (dump_base_name);
1440 char *dumpname = XNEWVEC (char, len + 10);
1442 gcc_assert (!flag_graphite_write);
1444 memcpy (dumpname, dump_base_name, len + 1);
1445 strip_off_ending (dumpname, len);
1446 strcat (dumpname, ".graphite");
1447 graphite_in_file = fopen (dumpname, "r+b");
1448 if (graphite_in_file == 0)
1449 fatal_error ("can%'t open %s for writing: %m", dumpname);
1450 free (dumpname);
1453 if (flag_graphite_write)
1455 int len = strlen (dump_base_name);
1456 char *dumpname = XNEWVEC (char, len + 10);
1458 gcc_assert (!flag_graphite_read);
1460 memcpy (dumpname, dump_base_name, len + 1);
1461 strip_off_ending (dumpname, len);
1462 strcat (dumpname, ".graphite");
1463 graphite_out_file = fopen (dumpname, "w+b");
1464 if (graphite_out_file == 0)
1465 fatal_error ("can%'t open %s for writing: %m", dumpname);
1466 free (dumpname);
1469 if (!flag_syntax_only)
1471 targetm.asm_out.file_start ();
1473 if (flag_record_gcc_switches)
1475 if (targetm.asm_out.record_gcc_switches)
1477 /* Let the target know that we are about to start recording. */
1478 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1479 NULL);
1480 /* Now record the switches. */
1481 print_switch_values (targetm.asm_out.record_gcc_switches);
1482 /* Let the target know that the recording is over. */
1483 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1484 NULL);
1486 else
1487 inform (input_location, "-frecord-gcc-switches is not supported by the current target");
1490 #ifdef ASM_COMMENT_START
1491 if (flag_verbose_asm)
1493 /* Print the list of switches in effect
1494 into the assembler file as comments. */
1495 print_version (asm_out_file, ASM_COMMENT_START);
1496 print_switch_values (print_to_asm_out_file);
1497 fprintf (asm_out_file, "\n");
1499 #endif
1503 /* Return true if the state of option OPTION should be stored in PCH files
1504 and checked by default_pch_valid_p. Store the option's current state
1505 in STATE if so. */
1507 static inline bool
1508 option_affects_pch_p (int option, struct cl_option_state *state)
1510 if ((cl_options[option].flags & CL_TARGET) == 0)
1511 return false;
1512 if (cl_options[option].flag_var == &target_flags)
1513 if (targetm.check_pch_target_flags)
1514 return false;
1515 return get_option_state (option, state);
1518 /* Default version of get_pch_validity.
1519 By default, every flag difference is fatal; that will be mostly right for
1520 most targets, but completely right for very few. */
1522 void *
1523 default_get_pch_validity (size_t *len)
1525 struct cl_option_state state;
1526 size_t i;
1527 char *result, *r;
1529 *len = 2;
1530 if (targetm.check_pch_target_flags)
1531 *len += sizeof (target_flags);
1532 for (i = 0; i < cl_options_count; i++)
1533 if (option_affects_pch_p (i, &state))
1534 *len += state.size;
1536 result = r = XNEWVEC (char, *len);
1537 r[0] = flag_pic;
1538 r[1] = flag_pie;
1539 r += 2;
1540 if (targetm.check_pch_target_flags)
1542 memcpy (r, &target_flags, sizeof (target_flags));
1543 r += sizeof (target_flags);
1546 for (i = 0; i < cl_options_count; i++)
1547 if (option_affects_pch_p (i, &state))
1549 memcpy (r, state.data, state.size);
1550 r += state.size;
1553 return result;
1556 /* Return a message which says that a PCH file was created with a different
1557 setting of OPTION. */
1559 static const char *
1560 pch_option_mismatch (const char *option)
1562 char *r;
1564 asprintf (&r, _("created and used with differing settings of '%s'"), option);
1565 if (r == NULL)
1566 return _("out of memory");
1567 return r;
1570 /* Default version of pch_valid_p. */
1572 const char *
1573 default_pch_valid_p (const void *data_p, size_t len)
1575 struct cl_option_state state;
1576 const char *data = (const char *)data_p;
1577 size_t i;
1579 /* -fpic and -fpie also usually make a PCH invalid. */
1580 if (data[0] != flag_pic)
1581 return _("created and used with different settings of -fpic");
1582 if (data[1] != flag_pie)
1583 return _("created and used with different settings of -fpie");
1584 data += 2;
1586 /* Check target_flags. */
1587 if (targetm.check_pch_target_flags)
1589 int tf;
1590 const char *r;
1592 memcpy (&tf, data, sizeof (target_flags));
1593 data += sizeof (target_flags);
1594 len -= sizeof (target_flags);
1595 r = targetm.check_pch_target_flags (tf);
1596 if (r != NULL)
1597 return r;
1600 for (i = 0; i < cl_options_count; i++)
1601 if (option_affects_pch_p (i, &state))
1603 if (memcmp (data, state.data, state.size) != 0)
1604 return pch_option_mismatch (cl_options[i].opt_text);
1605 data += state.size;
1606 len -= state.size;
1609 return NULL;
1612 /* Default tree printer. Handles declarations only. */
1613 bool
1614 default_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
1615 int precision, bool wide, bool set_locus, bool hash)
1617 tree t;
1619 /* FUTURE: %+x should set the locus. */
1620 if (precision != 0 || wide || hash)
1621 return false;
1623 switch (*spec)
1625 case 'E':
1626 t = va_arg (*text->args_ptr, tree);
1627 if (TREE_CODE (t) == IDENTIFIER_NODE)
1629 pp_identifier (pp, IDENTIFIER_POINTER (t));
1630 return true;
1632 break;
1634 case 'D':
1635 t = va_arg (*text->args_ptr, tree);
1636 if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
1637 t = DECL_DEBUG_EXPR (t);
1638 break;
1640 case 'F':
1641 case 'T':
1642 t = va_arg (*text->args_ptr, tree);
1643 break;
1645 default:
1646 return false;
1649 if (set_locus && text->locus)
1650 *text->locus = DECL_SOURCE_LOCATION (t);
1652 if (DECL_P (t))
1654 const char *n = DECL_NAME (t)
1655 ? identifier_to_locale (lang_hooks.decl_printable_name (t, 2))
1656 : _("<anonymous>");
1657 pp_string (pp, n);
1659 else
1660 dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0);
1662 return true;
1665 /* A helper function; used as the reallocator function for cpp's line
1666 table. */
1667 static void *
1668 realloc_for_line_map (void *ptr, size_t len)
1670 return ggc_realloc (ptr, len);
1673 /* Initialization of the front end environment, before command line
1674 options are parsed. Signal handlers, internationalization etc.
1675 ARGV0 is main's argv[0]. */
1676 static void
1677 general_init (const char *argv0)
1679 const char *p;
1681 p = argv0 + strlen (argv0);
1682 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1683 --p;
1684 progname = p;
1686 xmalloc_set_program_name (progname);
1688 hex_init ();
1690 /* Unlock the stdio streams. */
1691 unlock_std_streams ();
1693 gcc_init_libintl ();
1695 /* Initialize the diagnostics reporting machinery, so option parsing
1696 can give warnings and errors. */
1697 diagnostic_initialize (global_dc);
1698 /* Set a default printer. Language specific initializations will
1699 override it later. */
1700 pp_format_decoder (global_dc->printer) = &default_tree_printer;
1702 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1703 #ifdef SIGSEGV
1704 signal (SIGSEGV, crash_signal);
1705 #endif
1706 #ifdef SIGILL
1707 signal (SIGILL, crash_signal);
1708 #endif
1709 #ifdef SIGBUS
1710 signal (SIGBUS, crash_signal);
1711 #endif
1712 #ifdef SIGABRT
1713 signal (SIGABRT, crash_signal);
1714 #endif
1715 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1716 signal (SIGIOT, crash_signal);
1717 #endif
1718 #ifdef SIGFPE
1719 signal (SIGFPE, crash_signal);
1720 #endif
1722 /* Other host-specific signal setup. */
1723 (*host_hooks.extra_signals)();
1725 /* Initialize the garbage-collector, string pools and tree type hash
1726 table. */
1727 init_ggc ();
1728 init_stringpool ();
1729 line_table = GGC_NEW (struct line_maps);
1730 linemap_init (line_table);
1731 line_table->reallocator = realloc_for_line_map;
1732 init_ttree ();
1734 /* Initialize register usage now so switches may override. */
1735 init_reg_sets ();
1737 /* Register the language-independent parameters. */
1738 add_params (lang_independent_params, LAST_PARAM);
1740 /* This must be done after add_params but before argument processing. */
1741 init_ggc_heuristics();
1742 init_optimization_passes ();
1743 statistics_early_init ();
1746 /* Return true if the current target supports -fsection-anchors. */
1748 static bool
1749 target_supports_section_anchors_p (void)
1751 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1752 return false;
1754 if (targetm.asm_out.output_anchor == NULL)
1755 return false;
1757 return true;
1760 /* Default the align_* variables to 1 if they're still unset, and
1761 set up the align_*_log variables. */
1762 static void
1763 init_alignments (void)
1765 if (align_loops <= 0)
1766 align_loops = 1;
1767 if (align_loops_max_skip > align_loops)
1768 align_loops_max_skip = align_loops - 1;
1769 align_loops_log = floor_log2 (align_loops * 2 - 1);
1770 if (align_jumps <= 0)
1771 align_jumps = 1;
1772 if (align_jumps_max_skip > align_jumps)
1773 align_jumps_max_skip = align_jumps - 1;
1774 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1775 if (align_labels <= 0)
1776 align_labels = 1;
1777 align_labels_log = floor_log2 (align_labels * 2 - 1);
1778 if (align_labels_max_skip > align_labels)
1779 align_labels_max_skip = align_labels - 1;
1780 if (align_functions <= 0)
1781 align_functions = 1;
1782 align_functions_log = floor_log2 (align_functions * 2 - 1);
1785 /* Process the options that have been parsed. */
1786 static void
1787 process_options (void)
1789 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1790 This can happen with incorrect pre-processed input. */
1791 debug_hooks = &do_nothing_debug_hooks;
1793 /* This replaces set_Wunused. */
1794 if (warn_unused_function == -1)
1795 warn_unused_function = warn_unused;
1796 if (warn_unused_label == -1)
1797 warn_unused_label = warn_unused;
1798 /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled. */
1799 if (warn_unused_parameter == -1)
1800 warn_unused_parameter = (warn_unused && extra_warnings);
1801 if (warn_unused_variable == -1)
1802 warn_unused_variable = warn_unused;
1803 if (warn_unused_value == -1)
1804 warn_unused_value = warn_unused;
1806 /* This replaces set_Wextra. */
1807 if (warn_uninitialized == -1)
1808 warn_uninitialized = extra_warnings;
1810 /* Allow the front end to perform consistency checks and do further
1811 initialization based on the command line options. This hook also
1812 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1813 so we can correctly initialize debug output. */
1814 no_backend = lang_hooks.post_options (&main_input_filename);
1816 #ifdef OVERRIDE_OPTIONS
1817 /* Some machines may reject certain combinations of options. */
1818 OVERRIDE_OPTIONS;
1819 #endif
1821 if (flag_section_anchors && !target_supports_section_anchors_p ())
1823 warning (OPT_fsection_anchors,
1824 "this target does not support %qs", "-fsection-anchors");
1825 flag_section_anchors = 0;
1828 if (flag_short_enums == 2)
1829 flag_short_enums = targetm.default_short_enums ();
1831 /* Set aux_base_name if not already set. */
1832 if (aux_base_name)
1834 else if (main_input_filename)
1836 char *name = xstrdup (lbasename (main_input_filename));
1838 strip_off_ending (name, strlen (name));
1839 aux_base_name = name;
1841 else
1842 aux_base_name = "gccaux";
1844 #ifndef HAVE_cloog
1845 if (flag_graphite
1846 || flag_loop_block
1847 || flag_loop_interchange
1848 || flag_loop_strip_mine
1849 || flag_graphite_identity
1850 || flag_loop_parallelize_all)
1851 sorry ("Graphite loop optimizations cannot be used");
1852 #endif
1854 /* Unrolling all loops implies that standard loop unrolling must also
1855 be done. */
1856 if (flag_unroll_all_loops)
1857 flag_unroll_loops = 1;
1859 /* The loop unrolling code assumes that cse will be run after loop.
1860 web and rename-registers also help when run after loop unrolling. */
1862 if (flag_rerun_cse_after_loop == AUTODETECT_VALUE)
1863 flag_rerun_cse_after_loop = flag_unroll_loops || flag_peel_loops;
1864 if (flag_web == AUTODETECT_VALUE)
1865 flag_web = flag_unroll_loops || flag_peel_loops;
1866 if (flag_rename_registers == AUTODETECT_VALUE)
1867 flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1869 if (flag_non_call_exceptions)
1870 flag_asynchronous_unwind_tables = 1;
1871 if (flag_asynchronous_unwind_tables)
1872 flag_unwind_tables = 1;
1874 if (flag_value_profile_transformations)
1875 flag_profile_values = 1;
1877 /* Warn about options that are not supported on this machine. */
1878 #ifndef INSN_SCHEDULING
1879 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1880 warning (0, "instruction scheduling not supported on this target machine");
1881 #endif
1882 #ifndef DELAY_SLOTS
1883 if (flag_delayed_branch)
1884 warning (0, "this target machine does not have delayed branches");
1885 #endif
1887 user_label_prefix = USER_LABEL_PREFIX;
1888 if (flag_leading_underscore != -1)
1890 /* If the default prefix is more complicated than "" or "_",
1891 issue a warning and ignore this option. */
1892 if (user_label_prefix[0] == 0 ||
1893 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1895 user_label_prefix = flag_leading_underscore ? "_" : "";
1897 else
1898 warning (0, "-f%sleading-underscore not supported on this target machine",
1899 flag_leading_underscore ? "" : "no-");
1902 /* If we are in verbose mode, write out the version and maybe all the
1903 option flags in use. */
1904 if (version_flag)
1906 print_version (stderr, "");
1907 if (! quiet_flag)
1908 print_switch_values (print_to_stderr);
1911 if (flag_syntax_only)
1913 write_symbols = NO_DEBUG;
1914 profile_flag = 0;
1917 if (flag_gtoggle)
1919 if (debug_info_level == DINFO_LEVEL_NONE)
1920 debug_info_level = DINFO_LEVEL_NORMAL;
1921 else
1922 debug_info_level = DINFO_LEVEL_NONE;
1925 if (flag_dump_final_insns && !flag_syntax_only && !no_backend)
1927 FILE *final_output = fopen (flag_dump_final_insns, "w");
1928 if (!final_output)
1930 error ("could not open final insn dump file %qs: %s",
1931 flag_dump_final_insns, strerror (errno));
1932 flag_dump_final_insns = NULL;
1934 else if (fclose (final_output))
1936 error ("could not close zeroed insn dump file %qs: %s",
1937 flag_dump_final_insns, strerror (errno));
1938 flag_dump_final_insns = NULL;
1942 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1943 level is 0. */
1944 if (debug_info_level == DINFO_LEVEL_NONE)
1945 write_symbols = NO_DEBUG;
1947 /* Now we know write_symbols, set up the debug hooks based on it.
1948 By default we do nothing for debug output. */
1949 if (PREFERRED_DEBUGGING_TYPE == NO_DEBUG)
1950 default_debug_hooks = &do_nothing_debug_hooks;
1951 #if defined(DBX_DEBUGGING_INFO)
1952 else if (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG)
1953 default_debug_hooks = &dbx_debug_hooks;
1954 #endif
1955 #if defined(XCOFF_DEBUGGING_INFO)
1956 else if (PREFERRED_DEBUGGING_TYPE == XCOFF_DEBUG)
1957 default_debug_hooks = &xcoff_debug_hooks;
1958 #endif
1959 #ifdef SDB_DEBUGGING_INFO
1960 else if (PREFERRED_DEBUGGING_TYPE == SDB_DEBUG)
1961 default_debug_hooks = &sdb_debug_hooks;
1962 #endif
1963 #ifdef DWARF2_DEBUGGING_INFO
1964 else if (PREFERRED_DEBUGGING_TYPE == DWARF2_DEBUG)
1965 default_debug_hooks = &dwarf2_debug_hooks;
1966 #endif
1967 #ifdef VMS_DEBUGGING_INFO
1968 else if (PREFERRED_DEBUGGING_TYPE == VMS_DEBUG
1969 || PREFERRED_DEBUGGING_TYPE == VMS_AND_DWARF2_DEBUG)
1970 default_debug_hooks = &vmsdbg_debug_hooks;
1971 #endif
1973 if (write_symbols == NO_DEBUG)
1975 #if defined(DBX_DEBUGGING_INFO)
1976 else if (write_symbols == DBX_DEBUG)
1977 debug_hooks = &dbx_debug_hooks;
1978 #endif
1979 #if defined(XCOFF_DEBUGGING_INFO)
1980 else if (write_symbols == XCOFF_DEBUG)
1981 debug_hooks = &xcoff_debug_hooks;
1982 #endif
1983 #ifdef SDB_DEBUGGING_INFO
1984 else if (write_symbols == SDB_DEBUG)
1985 debug_hooks = &sdb_debug_hooks;
1986 #endif
1987 #ifdef DWARF2_DEBUGGING_INFO
1988 else if (write_symbols == DWARF2_DEBUG)
1989 debug_hooks = &dwarf2_debug_hooks;
1990 #endif
1991 #ifdef VMS_DEBUGGING_INFO
1992 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1993 debug_hooks = &vmsdbg_debug_hooks;
1994 #endif
1995 else
1996 error ("target system does not support the \"%s\" debug format",
1997 debug_type_names[write_symbols]);
1999 /* Now we know which debug output will be used so we can set
2000 flag_var_tracking, flag_rename_registers if the user has
2001 not specified them. */
2002 if (debug_info_level < DINFO_LEVEL_NORMAL
2003 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
2005 if (flag_var_tracking == 1
2006 || flag_var_tracking_uninit == 1)
2008 if (debug_info_level < DINFO_LEVEL_NORMAL)
2009 warning (0, "variable tracking requested, but useless unless "
2010 "producing debug info");
2011 else
2012 warning (0, "variable tracking requested, but not supported "
2013 "by this debug format");
2015 flag_var_tracking = 0;
2016 flag_var_tracking_uninit = 0;
2019 if (flag_rename_registers == AUTODETECT_VALUE)
2020 flag_rename_registers = default_debug_hooks->var_location
2021 != do_nothing_debug_hooks.var_location;
2023 if (flag_var_tracking == AUTODETECT_VALUE)
2024 flag_var_tracking = optimize >= 1;
2026 if (flag_var_tracking_assignments == AUTODETECT_VALUE)
2027 flag_var_tracking_assignments = 0;
2029 if (flag_var_tracking_assignments_toggle)
2030 flag_var_tracking_assignments = !flag_var_tracking_assignments;
2032 if (flag_var_tracking_assignments && !flag_var_tracking)
2033 flag_var_tracking = flag_var_tracking_assignments = -1;
2035 if (flag_tree_cselim == AUTODETECT_VALUE)
2036 #ifdef HAVE_conditional_move
2037 flag_tree_cselim = 1;
2038 #else
2039 flag_tree_cselim = 0;
2040 #endif
2042 /* If the user specifically requested variable tracking with tagging
2043 uninitialized variables, we need to turn on variable tracking.
2044 (We already determined above that variable tracking is feasible.) */
2045 if (flag_var_tracking_uninit)
2046 flag_var_tracking = 1;
2048 /* If auxiliary info generation is desired, open the output file.
2049 This goes in the same directory as the source file--unlike
2050 all the other output files. */
2051 if (flag_gen_aux_info)
2053 aux_info_file = fopen (aux_info_file_name, "w");
2054 if (aux_info_file == 0)
2055 fatal_error ("can%'t open %s: %m", aux_info_file_name);
2058 if (! targetm.have_named_sections)
2060 if (flag_function_sections)
2062 warning (0, "-ffunction-sections not supported for this target");
2063 flag_function_sections = 0;
2065 if (flag_data_sections)
2067 warning (0, "-fdata-sections not supported for this target");
2068 flag_data_sections = 0;
2072 if (flag_function_sections && profile_flag)
2074 warning (0, "-ffunction-sections disabled; it makes profiling impossible");
2075 flag_function_sections = 0;
2078 #ifndef HAVE_prefetch
2079 if (flag_prefetch_loop_arrays)
2081 warning (0, "-fprefetch-loop-arrays not supported for this target");
2082 flag_prefetch_loop_arrays = 0;
2084 #else
2085 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
2087 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
2088 flag_prefetch_loop_arrays = 0;
2090 #endif
2092 /* This combination of options isn't handled for i386 targets and doesn't
2093 make much sense anyway, so don't allow it. */
2094 if (flag_prefetch_loop_arrays && optimize_size)
2096 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
2097 flag_prefetch_loop_arrays = 0;
2100 /* The presence of IEEE signaling NaNs, implies all math can trap. */
2101 if (flag_signaling_nans)
2102 flag_trapping_math = 1;
2104 /* We cannot reassociate if we want traps or signed zeros. */
2105 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
2107 warning (0, "-fassociative-math disabled; other options take precedence");
2108 flag_associative_math = 0;
2111 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
2112 if (flag_cx_limited_range)
2113 flag_complex_method = 0;
2115 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
2116 if (flag_cx_fortran_rules)
2117 flag_complex_method = 1;
2119 /* Targets must be able to place spill slots at lower addresses. If the
2120 target already uses a soft frame pointer, the transition is trivial. */
2121 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
2123 warning (0, "-fstack-protector not supported for this target");
2124 flag_stack_protect = 0;
2126 if (!flag_stack_protect)
2127 warn_stack_protect = 0;
2129 /* ??? Unwind info is not correct around the CFG unless either a frame
2130 pointer is present or A_O_A is set. Fixing this requires rewriting
2131 unwind info generation to be aware of the CFG and propagating states
2132 around edges. */
2133 if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS
2134 && flag_omit_frame_pointer)
2136 warning (0, "unwind tables currently require a frame pointer "
2137 "for correctness");
2138 flag_omit_frame_pointer = 0;
2142 /* This function can be called multiple times to reinitialize the compiler
2143 back end when register classes or instruction sets have changed,
2144 before each function. */
2145 static void
2146 backend_init_target (void)
2148 /* Initialize alignment variables. */
2149 init_alignments ();
2151 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
2152 to initialize reg_raw_mode[]. */
2153 init_emit_regs ();
2155 /* This invokes target hooks to set fixed_reg[] etc, which is
2156 mode-dependent. */
2157 init_regs ();
2159 /* This depends on stack_pointer_rtx. */
2160 init_fake_stack_mems ();
2162 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
2163 mode-dependent. */
2164 init_alias_target ();
2166 /* Depends on HARD_FRAME_POINTER_REGNUM. */
2167 init_reload ();
2169 /* The following initialization functions need to generate rtl, so
2170 provide a dummy function context for them. */
2171 init_dummy_function_start ();
2173 /* rtx_cost is mode-dependent, so cached values need to be recomputed
2174 on a mode change. */
2175 init_expmed ();
2177 /* We may need to recompute regno_save_code[] and regno_restore_code[]
2178 after a mode change as well. */
2179 if (flag_caller_saves)
2180 init_caller_save ();
2181 expand_dummy_function_end ();
2184 /* Initialize the compiler back end. This function is called only once,
2185 when starting the compiler. */
2186 static void
2187 backend_init (void)
2189 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
2190 || debug_info_level == DINFO_LEVEL_VERBOSE
2191 #ifdef VMS_DEBUGGING_INFO
2192 /* Enable line number info for traceback. */
2193 || debug_info_level > DINFO_LEVEL_NONE
2194 #endif
2195 || flag_test_coverage);
2197 init_rtlanal ();
2198 init_inline_once ();
2199 init_varasm_once ();
2200 save_register_info ();
2202 /* Initialize the target-specific back end pieces. */
2203 ira_init_once ();
2204 backend_init_target ();
2207 /* Initialize excess precision settings. */
2208 static void
2209 init_excess_precision (void)
2211 /* Adjust excess precision handling based on the target options. If
2212 the front end cannot handle it, flag_excess_precision_cmdline
2213 will already have been set accordingly in the post_options
2214 hook. */
2215 gcc_assert (flag_excess_precision_cmdline != EXCESS_PRECISION_DEFAULT);
2216 flag_excess_precision = flag_excess_precision_cmdline;
2217 if (flag_unsafe_math_optimizations)
2218 flag_excess_precision = EXCESS_PRECISION_FAST;
2219 if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
2221 int flt_eval_method = TARGET_FLT_EVAL_METHOD;
2222 switch (flt_eval_method)
2224 case -1:
2225 case 0:
2226 /* Either the target acts unpredictably (-1) or has all the
2227 operations required not to have excess precision (0). */
2228 flag_excess_precision = EXCESS_PRECISION_FAST;
2229 break;
2230 case 1:
2231 case 2:
2232 /* In these cases, predictable excess precision makes
2233 sense. */
2234 break;
2235 default:
2236 /* Any other implementation-defined FLT_EVAL_METHOD values
2237 require the compiler to handle the associated excess
2238 precision rules in excess_precision_type. */
2239 gcc_unreachable ();
2244 /* Initialize things that are both lang-dependent and target-dependent.
2245 This function can be called more than once if target parameters change. */
2246 static void
2247 lang_dependent_init_target (void)
2249 /* This determines excess precision settings. */
2250 init_excess_precision ();
2252 /* This creates various _DECL nodes, so needs to be called after the
2253 front end is initialized. It also depends on the HAVE_xxx macros
2254 generated from the target machine description. */
2255 init_optabs ();
2257 /* The following initialization functions need to generate rtl, so
2258 provide a dummy function context for them. */
2259 init_dummy_function_start ();
2261 /* Do the target-specific parts of expr initialization. */
2262 init_expr_target ();
2264 /* Although the actions of these functions are language-independent,
2265 they use optabs, so we cannot call them from backend_init. */
2266 init_set_costs ();
2267 ira_init ();
2269 expand_dummy_function_end ();
2272 /* Language-dependent initialization. Returns nonzero on success. */
2273 static int
2274 lang_dependent_init (const char *name)
2276 location_t save_loc = input_location;
2277 if (dump_base_name == 0)
2278 dump_base_name = name && name[0] ? name : "gccdump";
2280 /* Other front-end initialization. */
2281 input_location = BUILTINS_LOCATION;
2282 if (lang_hooks.init () == 0)
2283 return 0;
2284 input_location = save_loc;
2286 init_asm_output (name);
2288 /* This creates various _DECL nodes, so needs to be called after the
2289 front end is initialized. */
2290 init_eh ();
2292 /* Do the target-specific parts of the initialization. */
2293 lang_dependent_init_target ();
2295 /* If dbx symbol table desired, initialize writing it and output the
2296 predefined types. */
2297 timevar_push (TV_SYMOUT);
2299 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2300 if (dwarf2out_do_frame ())
2301 dwarf2out_frame_init ();
2302 #endif
2304 /* Now we have the correct original filename, we can initialize
2305 debug output. */
2306 (*debug_hooks->init) (name);
2308 timevar_pop (TV_SYMOUT);
2310 return 1;
2314 /* Reinitialize everything when target parameters, such as register usage,
2315 have changed. */
2316 void
2317 target_reinit (void)
2319 /* Reinitialize RTL backend. */
2320 backend_init_target ();
2322 /* Reinitialize lang-dependent parts. */
2323 lang_dependent_init_target ();
2326 void
2327 dump_memory_report (bool final)
2329 ggc_print_statistics ();
2330 stringpool_statistics ();
2331 dump_tree_statistics ();
2332 dump_gimple_statistics ();
2333 dump_rtx_statistics ();
2334 dump_varray_statistics ();
2335 dump_alloc_pool_statistics ();
2336 dump_bitmap_statistics ();
2337 dump_vec_loc_statistics ();
2338 dump_ggc_loc_statistics (final);
2339 dump_alias_stats (stderr);
2340 dump_pta_stats (stderr);
2343 /* Clean up: close opened files, etc. */
2345 static void
2346 finalize (void)
2348 /* Close the dump files. */
2349 if (flag_gen_aux_info)
2351 fclose (aux_info_file);
2352 if (errorcount)
2353 unlink (aux_info_file_name);
2356 /* Close non-debugging input and output files. Take special care to note
2357 whether fclose returns an error, since the pages might still be on the
2358 buffer chain while the file is open. */
2360 if (asm_out_file)
2362 if (ferror (asm_out_file) != 0)
2363 fatal_error ("error writing to %s: %m", asm_file_name);
2364 if (fclose (asm_out_file) != 0)
2365 fatal_error ("error closing %s: %m", asm_file_name);
2368 statistics_fini ();
2369 finish_optimization_passes ();
2371 ira_finish_once ();
2373 if (mem_report)
2374 dump_memory_report (true);
2376 /* Language-specific end of compilation actions. */
2377 lang_hooks.finish ();
2380 /* Initialize the compiler, and compile the input file. */
2381 static void
2382 do_compile (void)
2384 /* Initialize timing first. The C front ends read the main file in
2385 the post_options hook, and C++ does file timings. */
2386 if (time_report || !quiet_flag || flag_detailed_statistics)
2387 timevar_init ();
2388 timevar_start (TV_TOTAL);
2390 process_options ();
2392 /* Don't do any more if an error has already occurred. */
2393 if (!errorcount)
2395 /* This must be run always, because it is needed to compute the FP
2396 predefined macros, such as __LDBL_MAX__, for targets using non
2397 default FP formats. */
2398 init_adjust_machine_modes ();
2400 /* Set up the back-end if requested. */
2401 if (!no_backend)
2402 backend_init ();
2404 /* Language-dependent initialization. Returns true on success. */
2405 if (lang_dependent_init (main_input_filename))
2406 compile_file ();
2408 finalize ();
2411 /* Stop timing and print the times. */
2412 timevar_stop (TV_TOTAL);
2413 timevar_print (stderr);
2416 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2417 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2418 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2420 It is not safe to call this function more than once. */
2423 toplev_main (int argc, char **argv)
2425 expandargv (&argc, &argv);
2427 save_argv = CONST_CAST2 (const char **, char **, argv);
2429 /* Initialization of GCC's environment, and diagnostics. */
2430 general_init (argv[0]);
2432 /* Parse the options and do minimal processing; basically just
2433 enough to default flags appropriately. */
2434 decode_options (argc, CONST_CAST2 (const char **, char **, argv));
2436 init_local_tick ();
2438 initialize_plugins ();
2440 if (version_flag)
2441 print_version (stderr, "");
2443 if (help_flag)
2444 print_plugins_help (stderr, "");
2446 /* Exit early if we can (e.g. -help). */
2447 if (!exit_after_options)
2448 do_compile ();
2450 if (warningcount || errorcount)
2451 print_ignored_options ();
2453 /* Invoke registered plugin callbacks if any. */
2454 invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
2456 finalize_plugins ();
2457 if (errorcount || sorrycount)
2458 return (FATAL_EXIT_CODE);
2460 return (SUCCESS_EXIT_CODE);