OSDN Git Service

2009-07-07 Manuel López-Ibáñez <manu@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / toplev.c
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.
5
6 This file is part of GCC.
7
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.
12
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.
17
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/>.  */
21
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.  */
26
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>
34
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
37 #endif
38
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
41 #endif
42
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"
89
90 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
91 #include "dwarf2out.h"
92 #endif
93
94 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
95 #include "dbxout.h"
96 #endif
97
98 #ifdef SDB_DEBUGGING_INFO
99 #include "sdbout.h"
100 #endif
101
102 #ifdef XCOFF_DEBUGGING_INFO
103 #include "xcoffout.h"           /* Needed for external data
104                                    declarations for e.g. AIX 4.x.  */
105 #endif
106
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);
114
115 static void crash_signal (int) ATTRIBUTE_NORETURN;
116 static void setup_core_dumping (void);
117 static void compile_file (void);
118
119 /* Nonzero to dump debug info whilst parsing (-dy option).  */
120 static int set_yydebug;
121
122 /* True if we don't need a backend (e.g. preprocessing only).  */
123 static bool no_backend;
124
125 /* Length of line when printing switch values.  */
126 #define MAX_LINE 75
127
128 /* Name of program invoked, sans directories.  */
129
130 const char *progname;
131
132 /* Copy of argument vector to toplev_main.  */
133 static const char **save_argv;
134
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.  */
138
139 const char *main_input_filename;
140
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
144
145 /* Current position in real source file.  */
146
147 location_t input_location;
148
149 struct line_maps *line_table;
150
151 /* Name to use as base of names for dump output files.  */
152
153 const char *dump_base_name;
154
155 /* Name to use as a base for auxiliary output files.  */
156
157 const char *aux_base_name;
158
159 /* Prefix for profile data files */
160 const char *profile_data_prefix;
161
162 /* A mask of target_flags that includes bit X if X was set or cleared
163    on the command line.  */
164
165 int target_flags_explicit;
166
167 /* Debug hooks - dependent upon command line options.  */
168
169 const struct gcc_debug_hooks *debug_hooks;
170
171 /* Debug hooks - target default.  */
172
173 static const struct gcc_debug_hooks *default_debug_hooks;
174
175 /* Other flags saying which kinds of debugging dump have been requested.  */
176
177 int rtl_dump_and_exit;
178 int flag_print_asm_name;
179 enum graph_dump_types graph_dump_format;
180
181 /* Name for output file of assembly code, specified with -o.  */
182
183 const char *asm_file_name;
184
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.  */
191
192 int optimize = 0;
193
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.  */
198
199 int optimize_size = 0;
200
201 /* The FUNCTION_DECL for the function currently being compiled,
202    or 0 if between functions.  */
203 tree current_function_decl;
204
205 /* Set to the FUNC_BEGIN label of the current function, or NULL
206    if none.  */
207 const char * current_function_func_begin_label;
208
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;
212
213 /* A random sequence of characters, unless overridden by user.  */
214 static const char *flag_random_seed;
215
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;
220
221 /* -f flags.  */
222
223 /* Nonzero means `char' should be signed.  */
224
225 int flag_signed_char;
226
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.  */
229
230 int flag_short_enums;
231
232 /* Nonzero if structures and unions should be returned in memory.
233
234    This should only be defined if compatibility with another compiler or
235    with an ABI is needed, because it results in slower code.  */
236
237 #ifndef DEFAULT_PCC_STRUCT_RETURN
238 #define DEFAULT_PCC_STRUCT_RETURN 1
239 #endif
240
241 /* Nonzero for -fpcc-struct-return: return values the same way PCC does.  */
242
243 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
244
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.  */
248
249 int flag_complex_method = 1;
250
251 /* Nonzero means we should be saving declaration info into a .X file.  */
252
253 int flag_gen_aux_info = 0;
254
255 /* Specified name of aux-info file.  */
256
257 const char *aux_info_file_name;
258
259 /* Nonzero if we are compiling code for a shared library, zero for
260    executable.  */
261
262 int flag_shlib;
263
264 /* Generate code for GNU or NeXT Objective-C runtime environment.  */
265
266 #ifdef NEXT_OBJC_RUNTIME
267 int flag_next_runtime = 1;
268 #else
269 int flag_next_runtime = 0;
270 #endif
271
272 /* Set to the default thread-local storage (tls) model to use.  */
273
274 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
275
276 /* Set the default region and algorithm for the integrated register
277    allocator.  */
278
279 enum ira_algorithm flag_ira_algorithm = IRA_ALGORITHM_CB;
280 enum ira_region flag_ira_region = IRA_REGION_MIXED;
281
282 /* Set the default value for -fira-verbose.  */
283
284 unsigned int flag_ira_verbose = 5;
285
286 /* Set the default for excess precision.  */
287
288 enum excess_precision flag_excess_precision_cmdline = EXCESS_PRECISION_DEFAULT;
289 enum excess_precision flag_excess_precision = EXCESS_PRECISION_DEFAULT;
290
291 /* Nonzero means change certain warnings into errors.
292    Usually these are warnings about failure to conform to some standard.  */
293
294 int flag_pedantic_errors = 0;
295
296 /* Nonzero means make permerror produce warnings instead of errors.  */
297
298 int flag_permissive = 0;
299
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.  */
306
307 int flag_debug_asm = 0;
308
309 /* -dP causes the rtl to be emitted as a comment in assembly.  */
310
311 int flag_dump_rtl_in_asm = 0;
312
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;
321
322 /* Nonzero if we should track variables.  When
323    flag_var_tracking == AUTODETECT_VALUE it will be set according
324    to optimize, debug_info_level and debug_hooks in process_options ().  */
325 int flag_var_tracking = AUTODETECT_VALUE;
326
327 /* Type of stack check.  */
328 enum stack_check_type flag_stack_check = NO_STACK_CHECK;
329
330 /* True if the user has tagged the function with the 'section'
331    attribute.  */
332
333 bool user_defined_section_attribute = false;
334
335 /* Values of the -falign-* flags: how much to align labels in code.
336    0 means `use default', 1 means `don't align'.
337    For each variable, there is an _log variant which is the power
338    of two not less than the variable, for .align output.  */
339
340 int align_loops_log;
341 int align_loops_max_skip;
342 int align_jumps_log;
343 int align_jumps_max_skip;
344 int align_labels_log;
345 int align_labels_max_skip;
346 int align_functions_log;
347
348 typedef struct
349 {
350   const char *const string;
351   int *const variable;
352   const int on_value;
353 }
354 lang_independent_options;
355
356 /* Nonzero if subexpressions must be evaluated from left-to-right.  */
357 int flag_evaluation_order = 0;
358
359 /* The user symbol prefix after having resolved same.  */
360 const char *user_label_prefix;
361
362 static const param_info lang_independent_params[] = {
363 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
364   { OPTION, DEFAULT, false, MIN, MAX, HELP },
365 #include "params.def"
366 #undef DEFPARAM
367   { NULL, 0, false, 0, 0, NULL }
368 };
369
370 /* Output files for assembler code (real compiler output)
371    and debugging dumps.  */
372
373 FILE *asm_out_file;
374 FILE *aux_info_file;
375 FILE *dump_file = NULL;
376 const char *dump_file_name;
377
378 /* The current working directory of a translation.  It's generally the
379    directory from which compilation was initiated, but a preprocessed
380    file may specify the original directory in which it was
381    created.  */
382
383 static const char *src_pwd;
384
385 /* Initialize src_pwd with the given string, and return true.  If it
386    was already initialized, return false.  As a special case, it may
387    be called with a NULL argument to test whether src_pwd has NOT been
388    initialized yet.  */
389
390 bool
391 set_src_pwd (const char *pwd)
392 {
393   if (src_pwd)
394     {
395       if (strcmp (src_pwd, pwd) == 0)
396         return true;
397       else
398         return false;
399     }
400
401   src_pwd = xstrdup (pwd);
402   return true;
403 }
404
405 /* Return the directory from which the translation unit was initiated,
406    in case set_src_pwd() was not called before to assign it a
407    different value.  */
408
409 const char *
410 get_src_pwd (void)
411 {
412   if (! src_pwd)
413     {
414       src_pwd = getpwd ();
415       if (!src_pwd)
416         src_pwd = ".";
417     }
418
419    return src_pwd;
420 }
421
422 /* Called when the start of a function definition is parsed,
423    this function prints on stderr the name of the function.  */
424 void
425 announce_function (tree decl)
426 {
427   if (!quiet_flag)
428     {
429       if (rtl_dump_and_exit)
430         fprintf (stderr, "%s ",
431                  identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))));
432       else
433         fprintf (stderr, " %s",
434                  identifier_to_locale (lang_hooks.decl_printable_name (decl, 2)));
435       fflush (stderr);
436       pp_needs_newline (global_dc->printer) = true;
437       diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
438     }
439 }
440
441 /* Initialize local_tick with the time of day, or -1 if
442    flag_random_seed is set.  */
443
444 static void
445 init_local_tick (void)
446 {
447   if (!flag_random_seed)
448     {
449       /* Get some more or less random data.  */
450 #ifdef HAVE_GETTIMEOFDAY
451       {
452         struct timeval tv;
453
454         gettimeofday (&tv, NULL);
455         local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
456       }
457 #else
458       {
459         time_t now = time (NULL);
460
461         if (now != (time_t)-1)
462           local_tick = (unsigned) now;
463       }
464 #endif
465     }
466   else
467     local_tick = -1;
468 }
469
470 /* Set up a default flag_random_seed and local_tick, unless the user
471    already specified one.  Must be called after init_local_tick.  */
472
473 static void
474 init_random_seed (void)
475 {
476   unsigned HOST_WIDE_INT value;
477   static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
478
479   value = local_tick ^ getpid ();
480
481   sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
482   flag_random_seed = random_seed;
483 }
484
485 /* Obtain the random_seed string.  Unless NOINIT, initialize it if
486    it's not provided in the command line.  */
487
488 const char *
489 get_random_seed (bool noinit)
490 {
491   if (!flag_random_seed && !noinit)
492     init_random_seed ();
493   return flag_random_seed;
494 }
495
496 /* Modify the random_seed string to VAL.  Return its previous
497    value.  */
498
499 const char *
500 set_random_seed (const char *val)
501 {
502   const char *old = flag_random_seed;
503   flag_random_seed = val;
504   return old;
505 }
506
507 /* Decode the string P as an integral parameter.
508    If the string is indeed an integer return its numeric value else
509    issue an Invalid Option error for the option PNAME and return DEFVAL.
510    If PNAME is zero just return DEFVAL, do not call error.  */
511
512 int
513 read_integral_parameter (const char *p, const char *pname, const int  defval)
514 {
515   const char *endp = p;
516
517   while (*endp)
518     {
519       if (ISDIGIT (*endp))
520         endp++;
521       else
522         break;
523     }
524
525   if (*endp != 0)
526     {
527       if (pname != 0)
528         error ("invalid option argument %qs", pname);
529       return defval;
530     }
531
532   return atoi (p);
533 }
534
535 #if GCC_VERSION < 3004
536
537 /* The functions floor_log2 and exact_log2 are defined as inline
538    functions in toplev.h if GCC_VERSION >= 3004.  The definitions here
539    are used for older versions of gcc.  */
540
541 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
542    If X is 0, return -1.  */
543
544 int
545 floor_log2 (unsigned HOST_WIDE_INT x)
546 {
547   int t = 0;
548
549   if (x == 0)
550     return -1;
551
552   if (HOST_BITS_PER_WIDE_INT > 64)
553     if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
554       t += 64;
555   if (HOST_BITS_PER_WIDE_INT > 32)
556     if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
557       t += 32;
558   if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
559     t += 16;
560   if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8))
561     t += 8;
562   if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4))
563     t += 4;
564   if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2))
565     t += 2;
566   if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
567     t += 1;
568
569   return t;
570 }
571
572 /* Return the logarithm of X, base 2, considering X unsigned,
573    if X is a power of 2.  Otherwise, returns -1.  */
574
575 int
576 exact_log2 (unsigned HOST_WIDE_INT x)
577 {
578   if (x != (x & -x))
579     return -1;
580   return floor_log2 (x);
581 }
582
583 #endif /* GCC_VERSION < 3004 */
584
585 /* Handler for fatal signals, such as SIGSEGV.  These are transformed
586    into ICE messages, which is much more user friendly.  In case the
587    error printer crashes, reset the signal to prevent infinite recursion.  */
588
589 static void
590 crash_signal (int signo)
591 {
592   signal (signo, SIG_DFL);
593
594   /* If we crashed while processing an ASM statement, then be a little more
595      graceful.  It's most likely the user's fault.  */
596   if (this_is_asm_operands)
597     {
598       output_operand_lossage ("unrecoverable error");
599       exit (FATAL_EXIT_CODE);
600     }
601
602   internal_error ("%s", strsignal (signo));
603 }
604
605 /* Arrange to dump core on error.  (The regular error message is still
606    printed first, except in the case of abort().)  */
607
608 static void
609 setup_core_dumping (void)
610 {
611 #ifdef SIGABRT
612   signal (SIGABRT, SIG_DFL);
613 #endif
614 #if defined(HAVE_SETRLIMIT)
615   {
616     struct rlimit rlim;
617     if (getrlimit (RLIMIT_CORE, &rlim) != 0)
618       fatal_error ("getting core file size maximum limit: %m");
619     rlim.rlim_cur = rlim.rlim_max;
620     if (setrlimit (RLIMIT_CORE, &rlim) != 0)
621       fatal_error ("setting core file size limit to maximum: %m");
622   }
623 #endif
624   diagnostic_abort_on_error (global_dc);
625 }
626
627
628 /* Strip off a legitimate source ending from the input string NAME of
629    length LEN.  Rather than having to know the names used by all of
630    our front ends, we strip off an ending of a period followed by
631    up to five characters.  (Java uses ".class".)  */
632
633 void
634 strip_off_ending (char *name, int len)
635 {
636   int i;
637   for (i = 2; i < 6 && len > i; i++)
638     {
639       if (name[len - i] == '.')
640         {
641           name[len - i] = '\0';
642           break;
643         }
644     }
645 }
646
647 /* Output a quoted string.  */
648
649 void
650 output_quoted_string (FILE *asm_file, const char *string)
651 {
652 #ifdef OUTPUT_QUOTED_STRING
653   OUTPUT_QUOTED_STRING (asm_file, string);
654 #else
655   char c;
656
657   putc ('\"', asm_file);
658   while ((c = *string++) != 0)
659     {
660       if (ISPRINT (c))
661         {
662           if (c == '\"' || c == '\\')
663             putc ('\\', asm_file);
664           putc (c, asm_file);
665         }
666       else
667         fprintf (asm_file, "\\%03o", (unsigned char) c);
668     }
669   putc ('\"', asm_file);
670 #endif
671 }
672
673 /* Output a file name in the form wanted by System V.  */
674
675 void
676 output_file_directive (FILE *asm_file, const char *input_name)
677 {
678   int len;
679   const char *na;
680
681   if (input_name == NULL)
682     input_name = "<stdin>";
683   else
684     input_name = remap_debug_filename (input_name);
685
686   len = strlen (input_name);
687   na = input_name + len;
688
689   /* NA gets INPUT_NAME sans directory names.  */
690   while (na > input_name)
691     {
692       if (IS_DIR_SEPARATOR (na[-1]))
693         break;
694       na--;
695     }
696
697 #ifdef ASM_OUTPUT_SOURCE_FILENAME
698   ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
699 #else
700   fprintf (asm_file, "\t.file\t");
701   output_quoted_string (asm_file, na);
702   fputc ('\n', asm_file);
703 #endif
704 }
705
706 /* A subroutine of wrapup_global_declarations.  We've come to the end of
707    the compilation unit.  All deferred variables should be undeferred,
708    and all incomplete decls should be finalized.  */
709
710 void
711 wrapup_global_declaration_1 (tree decl)
712 {
713   /* We're not deferring this any longer.  Assignment is conditional to
714      avoid needlessly dirtying PCH pages.  */
715   if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
716       && DECL_DEFER_OUTPUT (decl) != 0)
717     DECL_DEFER_OUTPUT (decl) = 0;
718
719   if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
720     lang_hooks.finish_incomplete_decl (decl);
721 }
722
723 /* A subroutine of wrapup_global_declarations.  Decide whether or not DECL
724    needs to be output.  Return true if it is output.  */
725
726 bool
727 wrapup_global_declaration_2 (tree decl)
728 {
729   if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
730     return false;
731
732   /* Don't write out static consts, unless we still need them.
733
734      We also keep static consts if not optimizing (for debugging),
735      unless the user specified -fno-keep-static-consts.
736      ??? They might be better written into the debug information.
737      This is possible when using DWARF.
738
739      A language processor that wants static constants to be always
740      written out (even if it is not used) is responsible for
741      calling rest_of_decl_compilation itself.  E.g. the C front-end
742      calls rest_of_decl_compilation from finish_decl.
743      One motivation for this is that is conventional in some
744      environments to write things like:
745      static const char rcsid[] = "... version string ...";
746      intending to force the string to be in the executable.
747
748      A language processor that would prefer to have unneeded
749      static constants "optimized away" would just defer writing
750      them out until here.  E.g. C++ does this, because static
751      constants are often defined in header files.
752
753      ??? A tempting alternative (for both C and C++) would be
754      to force a constant to be written if and only if it is
755      defined in a main file, as opposed to an include file.  */
756
757   if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
758     {
759       struct varpool_node *node;
760       bool needed = true;
761       node = varpool_node (decl);
762
763       if (node->finalized)
764         needed = false;
765       else if (node->alias)
766         needed = false;
767       else if (!cgraph_global_info_ready
768                && (TREE_USED (decl)
769                    || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
770         /* needed */;
771       else if (node->needed)
772         /* needed */;
773       else if (DECL_COMDAT (decl))
774         needed = false;
775       else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
776                && (optimize || !flag_keep_static_consts
777                    || DECL_ARTIFICIAL (decl)))
778         needed = false;
779
780       if (needed)
781         {
782           rest_of_decl_compilation (decl, 1, 1);
783           return true;
784         }
785     }
786
787   return false;
788 }
789
790 /* Do any final processing required for the declarations in VEC, of
791    which there are LEN.  We write out inline functions and variables
792    that have been deferred until this point, but which are required.
793    Returns nonzero if anything was put out.  */
794
795 bool
796 wrapup_global_declarations (tree *vec, int len)
797 {
798   bool reconsider, output_something = false;
799   int i;
800
801   for (i = 0; i < len; i++)
802     wrapup_global_declaration_1 (vec[i]);
803
804   /* Now emit any global variables or functions that we have been
805      putting off.  We need to loop in case one of the things emitted
806      here references another one which comes earlier in the list.  */
807   do
808     {
809       reconsider = false;
810       for (i = 0; i < len; i++)
811         reconsider |= wrapup_global_declaration_2 (vec[i]);
812       if (reconsider)
813         output_something = true;
814     }
815   while (reconsider);
816
817   return output_something;
818 }
819
820 /* A subroutine of check_global_declarations.  Issue appropriate warnings
821    for the global declaration DECL.  */
822
823 void
824 check_global_declaration_1 (tree decl)
825 {
826   /* Warn about any function declared static but not defined.  We don't
827      warn about variables, because many programs have static variables
828      that exist only to get some text into the object file.  */
829   if (TREE_CODE (decl) == FUNCTION_DECL
830       && DECL_INITIAL (decl) == 0
831       && DECL_EXTERNAL (decl)
832       && ! DECL_ARTIFICIAL (decl)
833       && ! TREE_NO_WARNING (decl)
834       && ! TREE_PUBLIC (decl)
835       && (warn_unused_function
836           || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
837     {
838       if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
839         pedwarn (input_location, 0, "%q+F used but never defined", decl);
840       else
841         warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
842       /* This symbol is effectively an "extern" declaration now.  */
843       TREE_PUBLIC (decl) = 1;
844       assemble_external (decl);
845     }
846
847   /* Warn about static fns or vars defined but not used.  */
848   if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
849        /* We don't warn about "static const" variables because the
850           "rcs_id" idiom uses that construction.  */
851        || (warn_unused_variable
852            && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
853       && ! DECL_IN_SYSTEM_HEADER (decl)
854       && ! TREE_USED (decl)
855       /* The TREE_USED bit for file-scope decls is kept in the identifier,
856          to handle multiple external decls in different scopes.  */
857       && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
858       && ! DECL_EXTERNAL (decl)
859       && ! TREE_PUBLIC (decl)
860       /* A volatile variable might be used in some non-obvious way.  */
861       && ! TREE_THIS_VOLATILE (decl)
862       /* Global register variables must be declared to reserve them.  */
863       && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
864       /* Otherwise, ask the language.  */
865       && lang_hooks.decls.warn_unused_global (decl))
866     warning ((TREE_CODE (decl) == FUNCTION_DECL) 
867              ? OPT_Wunused_function 
868              : OPT_Wunused_variable, 
869              "%q+D defined but not used", decl);
870 }
871
872 /* Issue appropriate warnings for the global declarations in VEC (of
873    which there are LEN).  */
874
875 void
876 check_global_declarations (tree *vec, int len)
877 {
878   int i;
879
880   for (i = 0; i < len; i++)
881     check_global_declaration_1 (vec[i]);
882 }
883
884 /* Emit debugging information for all global declarations in VEC.  */
885
886 void
887 emit_debug_global_declarations (tree *vec, int len)
888 {
889   int i;
890
891   /* Avoid confusing the debug information machinery when there are errors.  */
892   if (errorcount != 0 || sorrycount != 0)
893     return;
894
895   timevar_push (TV_SYMOUT);
896   for (i = 0; i < len; i++)
897     debug_hooks->global_decl (vec[i]);
898   timevar_pop (TV_SYMOUT);
899 }
900
901 /* Warn about a use of an identifier which was marked deprecated.  */
902 void
903 warn_deprecated_use (tree node, tree attr)
904 {
905   const char *msg;
906
907   if (node == 0 || !warn_deprecated_decl)
908     return;
909
910   if (!attr)
911     {
912       if (DECL_P (node))
913         attr = DECL_ATTRIBUTES (node);
914       else if (TYPE_P (node))
915         {
916           tree decl = TYPE_STUB_DECL (node);
917           if (decl)
918             attr = lookup_attribute ("deprecated",
919                                      TYPE_ATTRIBUTES (TREE_TYPE (decl)));
920         }
921     }
922
923   if (attr)
924     attr = lookup_attribute ("deprecated", attr);
925
926   if (attr)
927     msg = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
928   else
929     msg = NULL;
930
931   if (DECL_P (node))
932     {
933       expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
934       if (msg)
935         warning (OPT_Wdeprecated_declarations,
936                  "%qD is deprecated (declared at %s:%d): %s",
937                  node, xloc.file, xloc.line, msg);
938       else
939         warning (OPT_Wdeprecated_declarations,
940                  "%qD is deprecated (declared at %s:%d)",
941                  node, xloc.file, xloc.line);
942     }
943   else if (TYPE_P (node))
944     {
945       tree what = NULL_TREE;
946       tree decl = TYPE_STUB_DECL (node);
947
948       if (TYPE_NAME (node))
949         {
950           if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
951             what = TYPE_NAME (node);
952           else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
953                    && DECL_NAME (TYPE_NAME (node)))
954             what = DECL_NAME (TYPE_NAME (node));
955         }
956
957       if (decl)
958         {
959           expanded_location xloc
960             = expand_location (DECL_SOURCE_LOCATION (decl));
961           if (what)
962             {
963               if (msg)
964                 warning (OPT_Wdeprecated_declarations,
965                          "%qE is deprecated (declared at %s:%d): %s",
966                          what, xloc.file, xloc.line, msg);
967               else
968                 warning (OPT_Wdeprecated_declarations,
969                          "%qE is deprecated (declared at %s:%d)", what,
970                          xloc.file, xloc.line);
971             }
972           else
973             {
974               if (msg)
975                 warning (OPT_Wdeprecated_declarations,
976                          "type is deprecated (declared at %s:%d): %s",
977                          xloc.file, xloc.line, msg);
978               else
979                 warning (OPT_Wdeprecated_declarations,
980                          "type is deprecated (declared at %s:%d)",
981                          xloc.file, xloc.line);
982             }
983         }
984       else
985         {
986           if (what)
987             {
988               if (msg)
989                 warning (OPT_Wdeprecated_declarations, "%qE is deprecated: %s",
990                          what, msg);
991               else
992                 warning (OPT_Wdeprecated_declarations, "%qE is deprecated", what);
993             }
994           else
995             {
996               if (msg)
997                 warning (OPT_Wdeprecated_declarations, "type is deprecated: %s",
998                          msg);
999               else
1000                 warning (OPT_Wdeprecated_declarations, "type is deprecated");
1001             }
1002         }
1003     }
1004 }
1005
1006 /* Compile an entire translation unit.  Write a file of assembly
1007    output and various debugging dumps.  */
1008
1009 static void
1010 compile_file (void)
1011 {
1012   /* Initialize yet another pass.  */
1013
1014   ggc_protect_identifiers = true;
1015
1016   init_cgraph ();
1017   init_final (main_input_filename);
1018   coverage_init (aux_base_name);
1019   statistics_init ();
1020   invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
1021
1022   timevar_push (TV_PARSE);
1023
1024   /* Call the parser, which parses the entire file (calling
1025      rest_of_compilation for each function).  */
1026   lang_hooks.parse_file (set_yydebug);
1027
1028   /* Compilation is now finished except for writing
1029      what's left of the symbol table output.  */
1030   timevar_pop (TV_PARSE);
1031
1032   if (flag_syntax_only)
1033     return;
1034
1035   ggc_protect_identifiers = false;
1036
1037   lang_hooks.decls.final_write_globals ();
1038
1039   if (errorcount || sorrycount)
1040     return;
1041
1042   varpool_assemble_pending_decls ();
1043   finish_aliases_2 ();
1044
1045   /* Likewise for mudflap static object registrations.  */
1046   if (flag_mudflap)
1047     mudflap_finish_file ();
1048
1049   /* Likewise for emulated thread-local storage.  */
1050   if (!targetm.have_tls)
1051     emutls_finish ();
1052
1053   output_shared_constant_pool ();
1054   output_object_blocks ();
1055
1056   /* Write out any pending weak symbol declarations.  */
1057   weak_finish ();
1058
1059   /* Do dbx symbols.  */
1060   timevar_push (TV_SYMOUT);
1061
1062 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
1063   if (dwarf2out_do_frame ())
1064     dwarf2out_frame_finish ();
1065 #endif
1066
1067   (*debug_hooks->finish) (main_input_filename);
1068   timevar_pop (TV_SYMOUT);
1069
1070   /* Output some stuff at end of file if nec.  */
1071
1072   dw2_output_indirect_constants ();
1073
1074   /* Flush any pending external directives.  */
1075   process_pending_assemble_externals ();
1076
1077   /* Attach a special .ident directive to the end of the file to identify
1078      the version of GCC which compiled this code.  The format of the .ident
1079      string is patterned after the ones produced by native SVR4 compilers.  */
1080 #ifdef IDENT_ASM_OP
1081   if (!flag_no_ident)
1082     {
1083       const char *pkg_version = "(GNU) ";
1084
1085       if (strcmp ("(GCC) ", pkgversion_string))
1086         pkg_version = pkgversion_string;
1087       fprintf (asm_out_file, "%s\"GCC: %s%s\"\n",
1088                IDENT_ASM_OP, pkg_version, version_string);
1089     }
1090 #endif
1091
1092   /* This must be at the end.  Some target ports emit end of file directives
1093      into the assembly file here, and hence we can not output anything to the
1094      assembly file after this point.  */
1095   targetm.asm_out.file_end ();
1096 }
1097
1098 /* Parse a -d... command line switch.  */
1099
1100 void
1101 decode_d_option (const char *arg)
1102 {
1103   int c;
1104
1105   while (*arg)
1106     switch (c = *arg++)
1107       {
1108       case 'A':
1109         flag_debug_asm = 1;
1110         break;
1111       case 'p':
1112         flag_print_asm_name = 1;
1113         break;
1114       case 'P':
1115         flag_dump_rtl_in_asm = 1;
1116         flag_print_asm_name = 1;
1117         break;
1118       case 'v':
1119         graph_dump_format = vcg;
1120         break;
1121       case 'x':
1122         rtl_dump_and_exit = 1;
1123         break;
1124       case 'y':
1125         set_yydebug = 1;
1126         break;
1127       case 'D': /* These are handled by the preprocessor.  */
1128       case 'I':
1129       case 'M':
1130       case 'N':
1131       case 'U':
1132         break;
1133       case 'H':
1134         setup_core_dumping();
1135         break;
1136       case 'a':
1137         enable_rtl_dump_file ();
1138         break;
1139
1140       default:
1141           warning (0, "unrecognized gcc debugging option: %c", c);
1142         break;
1143       }
1144 }
1145
1146 /* Indexed by enum debug_info_type.  */
1147 const char *const debug_type_names[] =
1148 {
1149   "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
1150 };
1151
1152 /* Print version information to FILE.
1153    Each line begins with INDENT (for the case where FILE is the
1154    assembler output file).  */
1155
1156 void
1157 print_version (FILE *file, const char *indent)
1158 {
1159   static const char fmt1[] =
1160 #ifdef __GNUC__
1161     N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
1162 #else
1163     N_("%s%s%s %sversion %s (%s) compiled by CC, ")
1164 #endif
1165     ;
1166 #ifdef HAVE_mpc
1167   static const char fmt2[] =
1168     N_("GMP version %s, MPFR version %s, MPC version %s\n");
1169 #else
1170   static const char fmt2[] =
1171     N_("GMP version %s, MPFR version %s\n");
1172 #endif
1173   static const char fmt3[] =
1174     N_("%s%swarning: %s header version %s differs from library version %s.\n");
1175   static const char fmt4[] =
1176     N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
1177 #ifndef __VERSION__
1178 #define __VERSION__ "[?]"
1179 #endif
1180   fprintf (file,
1181            file == stderr ? _(fmt1) : fmt1,
1182            indent, *indent != 0 ? " " : "",
1183            lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
1184            indent, __VERSION__);
1185
1186   /* We need to stringify the GMP macro values.  Ugh, gmp_version has
1187      two string formats, "i.j.k" and "i.j" when k is zero.  As of
1188      gmp-4.3.0, GMP always uses the 3 number format.  */
1189 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
1190 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
1191 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
1192 #define GCC_GMP_VERSION \
1193   GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
1194 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
1195 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1196   GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
1197 #else
1198 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1199   GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
1200   GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
1201 #endif
1202   fprintf (file,
1203            file == stderr ? _(fmt2) : fmt2,
1204            GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING
1205 #ifdef HAVE_mpc
1206            , MPC_VERSION_STRING
1207 #endif
1208            );
1209   if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
1210     fprintf (file,
1211              file == stderr ? _(fmt3) : fmt3,
1212              indent, *indent != 0 ? " " : "",
1213              "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
1214   if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
1215     fprintf (file,
1216              file == stderr ? _(fmt3) : fmt3,
1217              indent, *indent != 0 ? " " : "",
1218              "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
1219 #ifdef HAVE_mpc
1220   if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
1221     fprintf (file,
1222              file == stderr ? _(fmt3) : fmt3,
1223              indent, *indent != 0 ? " " : "",
1224              "MPC", MPC_VERSION_STRING, mpc_get_version ());
1225 #endif
1226   fprintf (file,
1227            file == stderr ? _(fmt4) : fmt4,
1228            indent, *indent != 0 ? " " : "",
1229            PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
1230
1231   print_plugins_versions (file, indent);
1232 }
1233
1234 #ifdef ASM_COMMENT_START
1235 static int
1236 print_to_asm_out_file (print_switch_type type, const char * text)
1237 {
1238   bool prepend_sep = true;
1239
1240   switch (type)
1241     {
1242     case SWITCH_TYPE_LINE_END:
1243       putc ('\n', asm_out_file);
1244       return 1;
1245
1246     case SWITCH_TYPE_LINE_START:
1247       fputs (ASM_COMMENT_START, asm_out_file);
1248       return strlen (ASM_COMMENT_START);
1249
1250     case SWITCH_TYPE_DESCRIPTIVE:
1251       if (ASM_COMMENT_START[0] == 0)
1252         prepend_sep = false;
1253       /* Drop through.  */
1254     case SWITCH_TYPE_PASSED:
1255     case SWITCH_TYPE_ENABLED:
1256       if (prepend_sep)
1257         fputc (' ', asm_out_file);
1258       fprintf (asm_out_file, text);
1259       /* No need to return the length here as
1260          print_single_switch has already done it.  */
1261       return 0;
1262
1263     default:
1264       return -1;
1265     }
1266 }
1267 #endif
1268
1269 static int
1270 print_to_stderr (print_switch_type type, const char * text)
1271 {
1272   switch (type)
1273     {
1274     case SWITCH_TYPE_LINE_END:
1275       putc ('\n', stderr);
1276       return 1;
1277
1278     case SWITCH_TYPE_LINE_START:
1279       return 0;
1280       
1281     case SWITCH_TYPE_PASSED:
1282     case SWITCH_TYPE_ENABLED:
1283       fputc (' ', stderr);
1284       /* Drop through.  */
1285
1286     case SWITCH_TYPE_DESCRIPTIVE:
1287       fprintf (stderr, text);
1288       /* No need to return the length here as
1289          print_single_switch has already done it.  */
1290       return 0;
1291
1292     default:
1293       return -1;
1294     }
1295 }
1296
1297 /* Print an option value and return the adjusted position in the line.
1298    ??? print_fn doesn't handle errors, eg disk full; presumably other
1299    code will catch a disk full though.  */
1300
1301 static int
1302 print_single_switch (print_switch_fn_type print_fn,
1303                      int pos,
1304                      print_switch_type type,
1305                      const char * text)
1306 {
1307   /* The ultrix fprintf returns 0 on success, so compute the result
1308      we want here since we need it for the following test.  The +1
1309      is for the separator character that will probably be emitted.  */
1310   int len = strlen (text) + 1;
1311
1312   if (pos != 0
1313       && pos + len > MAX_LINE)
1314     {
1315       print_fn (SWITCH_TYPE_LINE_END, NULL);
1316       pos = 0;
1317     }
1318
1319   if (pos == 0)
1320     pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
1321
1322   print_fn (type, text);
1323   return pos + len;
1324 }
1325
1326 /* Print active target switches using PRINT_FN.
1327    POS is the current cursor position and MAX is the size of a "line".
1328    Each line begins with INDENT and ends with TERM.
1329    Each switch is separated from the next by SEP.  */
1330
1331 static void
1332 print_switch_values (print_switch_fn_type print_fn)
1333 {
1334   int pos = 0;
1335   size_t j;
1336   const char **p;
1337
1338   /* Fill in the -frandom-seed option, if the user didn't pass it, so
1339      that it can be printed below.  This helps reproducibility.  */
1340   if (!flag_random_seed)
1341     init_random_seed ();
1342
1343   /* Print the options as passed.  */
1344   pos = print_single_switch (print_fn, pos,
1345                              SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
1346
1347   for (p = &save_argv[1]; *p != NULL; p++)
1348     {
1349       if (**p == '-')
1350         {
1351           /* Ignore these.  */
1352           if (strcmp (*p, "-o") == 0
1353               || strcmp (*p, "-dumpbase") == 0
1354               || strcmp (*p, "-auxbase") == 0)
1355             {
1356               if (p[1] != NULL)
1357                 p++;
1358               continue;
1359             }
1360
1361           if (strcmp (*p, "-quiet") == 0
1362               || strcmp (*p, "-version") == 0)
1363             continue;
1364
1365           if ((*p)[1] == 'd')
1366             continue;
1367         }
1368
1369       pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED, *p);
1370     }
1371
1372   if (pos > 0)
1373     print_fn (SWITCH_TYPE_LINE_END, NULL);
1374
1375   /* Print the -f and -m options that have been enabled.
1376      We don't handle language specific options but printing argv
1377      should suffice.  */
1378   pos = print_single_switch (print_fn, 0,
1379                              SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
1380
1381   for (j = 0; j < cl_options_count; j++)
1382     if ((cl_options[j].flags & CL_REPORT)
1383         && option_enabled (j) > 0)
1384       pos = print_single_switch (print_fn, pos,
1385                                  SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
1386
1387   print_fn (SWITCH_TYPE_LINE_END, NULL);
1388 }
1389
1390 /* Open assembly code output file.  Do this even if -fsyntax-only is
1391    on, because then the driver will have provided the name of a
1392    temporary file or bit bucket for us.  NAME is the file specified on
1393    the command line, possibly NULL.  */
1394 static void
1395 init_asm_output (const char *name)
1396 {
1397   if (name == NULL && asm_file_name == 0)
1398     asm_out_file = stdout;
1399   else
1400     {
1401       if (asm_file_name == 0)
1402         {
1403           int len = strlen (dump_base_name);
1404           char *dumpname = XNEWVEC (char, len + 6);
1405
1406           memcpy (dumpname, dump_base_name, len + 1);
1407           strip_off_ending (dumpname, len);
1408           strcat (dumpname, ".s");
1409           asm_file_name = dumpname;
1410         }
1411       if (!strcmp (asm_file_name, "-"))
1412         asm_out_file = stdout;
1413       else
1414         asm_out_file = fopen (asm_file_name, "w+b");
1415       if (asm_out_file == 0)
1416         fatal_error ("can%'t open %s for writing: %m", asm_file_name);
1417     }
1418
1419   if (!flag_syntax_only)
1420     {
1421       targetm.asm_out.file_start ();
1422
1423       if (flag_record_gcc_switches)
1424         {
1425           if (targetm.asm_out.record_gcc_switches)
1426             {
1427               /* Let the target know that we are about to start recording.  */
1428               targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1429                                                    NULL);
1430               /* Now record the switches.  */
1431               print_switch_values (targetm.asm_out.record_gcc_switches);
1432               /* Let the target know that the recording is over.  */
1433               targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1434                                                    NULL);
1435             }
1436           else
1437             inform (input_location, "-frecord-gcc-switches is not supported by the current target");
1438         }
1439
1440 #ifdef ASM_COMMENT_START
1441       if (flag_verbose_asm)
1442         {
1443           /* Print the list of switches in effect
1444              into the assembler file as comments.  */
1445           print_version (asm_out_file, ASM_COMMENT_START);
1446           print_switch_values (print_to_asm_out_file);
1447           fprintf (asm_out_file, "\n");
1448         }
1449 #endif
1450     }
1451 }
1452
1453 /* Return true if the state of option OPTION should be stored in PCH files
1454    and checked by default_pch_valid_p.  Store the option's current state
1455    in STATE if so.  */
1456
1457 static inline bool
1458 option_affects_pch_p (int option, struct cl_option_state *state)
1459 {
1460   if ((cl_options[option].flags & CL_TARGET) == 0)
1461     return false;
1462   if (cl_options[option].flag_var == &target_flags)
1463     if (targetm.check_pch_target_flags)
1464       return false;
1465   return get_option_state (option, state);
1466 }
1467
1468 /* Default version of get_pch_validity.
1469    By default, every flag difference is fatal; that will be mostly right for
1470    most targets, but completely right for very few.  */
1471
1472 void *
1473 default_get_pch_validity (size_t *len)
1474 {
1475   struct cl_option_state state;
1476   size_t i;
1477   char *result, *r;
1478
1479   *len = 2;
1480   if (targetm.check_pch_target_flags)
1481     *len += sizeof (target_flags);
1482   for (i = 0; i < cl_options_count; i++)
1483     if (option_affects_pch_p (i, &state))
1484       *len += state.size;
1485
1486   result = r = XNEWVEC (char, *len);
1487   r[0] = flag_pic;
1488   r[1] = flag_pie;
1489   r += 2;
1490   if (targetm.check_pch_target_flags)
1491     {
1492       memcpy (r, &target_flags, sizeof (target_flags));
1493       r += sizeof (target_flags);
1494     }
1495
1496   for (i = 0; i < cl_options_count; i++)
1497     if (option_affects_pch_p (i, &state))
1498       {
1499         memcpy (r, state.data, state.size);
1500         r += state.size;
1501       }
1502
1503   return result;
1504 }
1505
1506 /* Return a message which says that a PCH file was created with a different
1507    setting of OPTION.  */
1508
1509 static const char *
1510 pch_option_mismatch (const char *option)
1511 {
1512   char *r;
1513
1514   asprintf (&r, _("created and used with differing settings of '%s'"), option);
1515   if (r == NULL)
1516     return _("out of memory");
1517   return r;
1518 }
1519
1520 /* Default version of pch_valid_p.  */
1521
1522 const char *
1523 default_pch_valid_p (const void *data_p, size_t len)
1524 {
1525   struct cl_option_state state;
1526   const char *data = (const char *)data_p;
1527   size_t i;
1528
1529   /* -fpic and -fpie also usually make a PCH invalid.  */
1530   if (data[0] != flag_pic)
1531     return _("created and used with different settings of -fpic");
1532   if (data[1] != flag_pie)
1533     return _("created and used with different settings of -fpie");
1534   data += 2;
1535
1536   /* Check target_flags.  */
1537   if (targetm.check_pch_target_flags)
1538     {
1539       int tf;
1540       const char *r;
1541
1542       memcpy (&tf, data, sizeof (target_flags));
1543       data += sizeof (target_flags);
1544       len -= sizeof (target_flags);
1545       r = targetm.check_pch_target_flags (tf);
1546       if (r != NULL)
1547         return r;
1548     }
1549
1550   for (i = 0; i < cl_options_count; i++)
1551     if (option_affects_pch_p (i, &state))
1552       {
1553         if (memcmp (data, state.data, state.size) != 0)
1554           return pch_option_mismatch (cl_options[i].opt_text);
1555         data += state.size;
1556         len -= state.size;
1557       }
1558
1559   return NULL;
1560 }
1561
1562 /* Default tree printer.   Handles declarations only.  */
1563 static bool
1564 default_tree_printer (pretty_printer * pp, text_info *text, const char *spec,
1565                       int precision, bool wide, bool set_locus, bool hash)
1566 {
1567   tree t;
1568
1569   /* FUTURE: %+x should set the locus.  */
1570   if (precision != 0 || wide || hash)
1571     return false;
1572
1573   switch (*spec)
1574     {
1575     case 'E':
1576       t = va_arg (*text->args_ptr, tree);
1577       if (TREE_CODE (t) == IDENTIFIER_NODE)
1578         {
1579           pp_identifier (pp, IDENTIFIER_POINTER (t));
1580           return true;
1581         }
1582       break;
1583
1584     case 'D':
1585       t = va_arg (*text->args_ptr, tree);
1586       if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
1587         t = DECL_DEBUG_EXPR (t);
1588       break;
1589
1590     case 'F':
1591     case 'T':
1592       t = va_arg (*text->args_ptr, tree);
1593       break;
1594
1595     default:
1596       return false;
1597     }
1598
1599   if (set_locus && text->locus)
1600     *text->locus = DECL_SOURCE_LOCATION (t);
1601
1602   if (DECL_P (t))
1603     {
1604       const char *n = DECL_NAME (t)
1605         ? identifier_to_locale (lang_hooks.decl_printable_name (t, 2))
1606         : _("<anonymous>");
1607       pp_string (pp, n);
1608     }
1609   else
1610     dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0);
1611
1612   return true;
1613 }
1614
1615 /* A helper function; used as the reallocator function for cpp's line
1616    table.  */
1617 static void *
1618 realloc_for_line_map (void *ptr, size_t len)
1619 {
1620   return ggc_realloc (ptr, len);
1621 }
1622
1623 /* Initialization of the front end environment, before command line
1624    options are parsed.  Signal handlers, internationalization etc.
1625    ARGV0 is main's argv[0].  */
1626 static void
1627 general_init (const char *argv0)
1628 {
1629   const char *p;
1630
1631   p = argv0 + strlen (argv0);
1632   while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1633     --p;
1634   progname = p;
1635
1636   xmalloc_set_program_name (progname);
1637
1638   hex_init ();
1639
1640   /* Unlock the stdio streams.  */
1641   unlock_std_streams ();
1642
1643   gcc_init_libintl ();
1644
1645   /* Initialize the diagnostics reporting machinery, so option parsing
1646      can give warnings and errors.  */
1647   diagnostic_initialize (global_dc);
1648   /* Set a default printer.  Language specific initializations will
1649      override it later.  */
1650   pp_format_decoder (global_dc->printer) = &default_tree_printer;
1651
1652   /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages.  */
1653 #ifdef SIGSEGV
1654   signal (SIGSEGV, crash_signal);
1655 #endif
1656 #ifdef SIGILL
1657   signal (SIGILL, crash_signal);
1658 #endif
1659 #ifdef SIGBUS
1660   signal (SIGBUS, crash_signal);
1661 #endif
1662 #ifdef SIGABRT
1663   signal (SIGABRT, crash_signal);
1664 #endif
1665 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1666   signal (SIGIOT, crash_signal);
1667 #endif
1668 #ifdef SIGFPE
1669   signal (SIGFPE, crash_signal);
1670 #endif
1671
1672   /* Other host-specific signal setup.  */
1673   (*host_hooks.extra_signals)();
1674
1675   /* Initialize the garbage-collector, string pools and tree type hash
1676      table.  */
1677   init_ggc ();
1678   init_stringpool ();
1679   line_table = GGC_NEW (struct line_maps);
1680   linemap_init (line_table);
1681   line_table->reallocator = realloc_for_line_map;
1682   init_ttree ();
1683
1684   /* Initialize register usage now so switches may override.  */
1685   init_reg_sets ();
1686
1687   /* Register the language-independent parameters.  */
1688   add_params (lang_independent_params, LAST_PARAM);
1689
1690   /* This must be done after add_params but before argument processing.  */
1691   init_ggc_heuristics();
1692   init_optimization_passes ();
1693   statistics_early_init ();
1694 }
1695
1696 /* Return true if the current target supports -fsection-anchors.  */
1697
1698 static bool
1699 target_supports_section_anchors_p (void)
1700 {
1701   if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1702     return false;
1703
1704   if (targetm.asm_out.output_anchor == NULL)
1705     return false;
1706
1707   return true;
1708 }
1709
1710 /* Default the align_* variables to 1 if they're still unset, and
1711    set up the align_*_log variables.  */
1712 static void
1713 init_alignments (void)
1714 {
1715   if (align_loops <= 0)
1716     align_loops = 1;
1717   if (align_loops_max_skip > align_loops)
1718     align_loops_max_skip = align_loops - 1;
1719   align_loops_log = floor_log2 (align_loops * 2 - 1);
1720   if (align_jumps <= 0)
1721     align_jumps = 1;
1722   if (align_jumps_max_skip > align_jumps)
1723     align_jumps_max_skip = align_jumps - 1;
1724   align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1725   if (align_labels <= 0)
1726     align_labels = 1;
1727   align_labels_log = floor_log2 (align_labels * 2 - 1);
1728   if (align_labels_max_skip > align_labels)
1729     align_labels_max_skip = align_labels - 1;
1730   if (align_functions <= 0)
1731     align_functions = 1;
1732   align_functions_log = floor_log2 (align_functions * 2 - 1);
1733 }
1734
1735 /* Process the options that have been parsed.  */
1736 static void
1737 process_options (void)
1738 {
1739   /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1740      This can happen with incorrect pre-processed input. */
1741   debug_hooks = &do_nothing_debug_hooks;
1742
1743   /* This replaces set_Wunused.  */
1744   if (warn_unused_function == -1)
1745     warn_unused_function = warn_unused;
1746   if (warn_unused_label == -1)
1747     warn_unused_label = warn_unused;
1748   /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled.  */
1749   if (warn_unused_parameter == -1)
1750     warn_unused_parameter = (warn_unused && extra_warnings);
1751   if (warn_unused_variable == -1)
1752     warn_unused_variable = warn_unused;
1753   if (warn_unused_value == -1)
1754     warn_unused_value = warn_unused;
1755
1756   /* This replaces set_Wextra.  */
1757   if (warn_uninitialized == -1)
1758     warn_uninitialized = extra_warnings;
1759
1760   /* Allow the front end to perform consistency checks and do further
1761      initialization based on the command line options.  This hook also
1762      sets the original filename if appropriate (e.g. foo.i -> foo.c)
1763      so we can correctly initialize debug output.  */
1764   no_backend = lang_hooks.post_options (&main_input_filename);
1765
1766 #ifdef OVERRIDE_OPTIONS
1767   /* Some machines may reject certain combinations of options.  */
1768   OVERRIDE_OPTIONS;
1769 #endif
1770
1771   if (flag_section_anchors && !target_supports_section_anchors_p ())
1772     {
1773       warning (OPT_fsection_anchors,
1774                "this target does not support %qs", "-fsection-anchors");
1775       flag_section_anchors = 0;
1776     }
1777
1778   if (flag_short_enums == 2)
1779     flag_short_enums = targetm.default_short_enums ();
1780
1781   /* Set aux_base_name if not already set.  */
1782   if (aux_base_name)
1783     ;
1784   else if (main_input_filename)
1785     {
1786       char *name = xstrdup (lbasename (main_input_filename));
1787
1788       strip_off_ending (name, strlen (name));
1789       aux_base_name = name;
1790     }
1791   else
1792     aux_base_name = "gccaux";
1793
1794 #ifndef HAVE_cloog
1795   if (flag_graphite
1796       || flag_loop_block
1797       || flag_loop_interchange
1798       || flag_loop_strip_mine
1799       || flag_graphite_identity)
1800     sorry ("Graphite loop optimizations cannot be used");
1801 #endif
1802
1803   /* Unrolling all loops implies that standard loop unrolling must also
1804      be done.  */
1805   if (flag_unroll_all_loops)
1806     flag_unroll_loops = 1;
1807
1808   /* The loop unrolling code assumes that cse will be run after loop.
1809      web and rename-registers also help when run after loop unrolling.  */
1810
1811   if (flag_rerun_cse_after_loop == AUTODETECT_VALUE)
1812     flag_rerun_cse_after_loop = flag_unroll_loops || flag_peel_loops;
1813   if (flag_web == AUTODETECT_VALUE)
1814     flag_web = flag_unroll_loops || flag_peel_loops;
1815   if (flag_rename_registers == AUTODETECT_VALUE)
1816     flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1817
1818   if (flag_non_call_exceptions)
1819     flag_asynchronous_unwind_tables = 1;
1820   if (flag_asynchronous_unwind_tables)
1821     flag_unwind_tables = 1;
1822
1823   if (flag_value_profile_transformations)
1824     flag_profile_values = 1;
1825
1826   /* Warn about options that are not supported on this machine.  */
1827 #ifndef INSN_SCHEDULING
1828   if (flag_schedule_insns || flag_schedule_insns_after_reload)
1829     warning (0, "instruction scheduling not supported on this target machine");
1830 #endif
1831 #ifndef DELAY_SLOTS
1832   if (flag_delayed_branch)
1833     warning (0, "this target machine does not have delayed branches");
1834 #endif
1835
1836   user_label_prefix = USER_LABEL_PREFIX;
1837   if (flag_leading_underscore != -1)
1838     {
1839       /* If the default prefix is more complicated than "" or "_",
1840          issue a warning and ignore this option.  */
1841       if (user_label_prefix[0] == 0 ||
1842           (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1843         {
1844           user_label_prefix = flag_leading_underscore ? "_" : "";
1845         }
1846       else
1847         warning (0, "-f%sleading-underscore not supported on this target machine",
1848                  flag_leading_underscore ? "" : "no-");
1849     }
1850
1851   /* If we are in verbose mode, write out the version and maybe all the
1852      option flags in use.  */
1853   if (version_flag)
1854     {
1855       print_version (stderr, "");
1856       if (! quiet_flag)
1857         print_switch_values (print_to_stderr);
1858     }
1859
1860   if (flag_syntax_only)
1861     {
1862       write_symbols = NO_DEBUG;
1863       profile_flag = 0;
1864     }
1865
1866   if (flag_gtoggle)
1867     {
1868       if (debug_info_level == DINFO_LEVEL_NONE)
1869         debug_info_level = DINFO_LEVEL_NORMAL;
1870       else
1871         debug_info_level = DINFO_LEVEL_NONE;
1872     }
1873
1874   if (flag_dump_final_insns)
1875     {
1876       FILE *final_output = fopen (flag_dump_final_insns, "w");
1877       if (!final_output)
1878         {
1879           error ("could not open final insn dump file %qs: %s",
1880                  flag_dump_final_insns, strerror (errno));
1881           flag_dump_final_insns = NULL;
1882         }
1883       else if (fclose (final_output))
1884         {
1885           error ("could not close zeroed insn dump file %qs: %s",
1886                  flag_dump_final_insns, strerror (errno));
1887           flag_dump_final_insns = NULL;
1888         }
1889     }
1890
1891   /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1892      level is 0.  */
1893   if (debug_info_level == DINFO_LEVEL_NONE)
1894     write_symbols = NO_DEBUG;
1895
1896   /* Now we know write_symbols, set up the debug hooks based on it.
1897      By default we do nothing for debug output.  */
1898   if (PREFERRED_DEBUGGING_TYPE == NO_DEBUG)
1899     default_debug_hooks = &do_nothing_debug_hooks;
1900 #if defined(DBX_DEBUGGING_INFO)
1901   else if (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG)
1902     default_debug_hooks = &dbx_debug_hooks;
1903 #endif
1904 #if defined(XCOFF_DEBUGGING_INFO)
1905   else if (PREFERRED_DEBUGGING_TYPE == XCOFF_DEBUG)
1906     default_debug_hooks = &xcoff_debug_hooks;
1907 #endif
1908 #ifdef SDB_DEBUGGING_INFO
1909   else if (PREFERRED_DEBUGGING_TYPE == SDB_DEBUG)
1910     default_debug_hooks = &sdb_debug_hooks;
1911 #endif
1912 #ifdef DWARF2_DEBUGGING_INFO
1913   else if (PREFERRED_DEBUGGING_TYPE == DWARF2_DEBUG)
1914     default_debug_hooks = &dwarf2_debug_hooks;
1915 #endif
1916 #ifdef VMS_DEBUGGING_INFO
1917   else if (PREFERRED_DEBUGGING_TYPE == VMS_DEBUG
1918            || PREFERRED_DEBUGGING_TYPE == VMS_AND_DWARF2_DEBUG)
1919     default_debug_hooks = &vmsdbg_debug_hooks;
1920 #endif
1921
1922   if (write_symbols == NO_DEBUG)
1923     ;
1924 #if defined(DBX_DEBUGGING_INFO)
1925   else if (write_symbols == DBX_DEBUG)
1926     debug_hooks = &dbx_debug_hooks;
1927 #endif
1928 #if defined(XCOFF_DEBUGGING_INFO)
1929   else if (write_symbols == XCOFF_DEBUG)
1930     debug_hooks = &xcoff_debug_hooks;
1931 #endif
1932 #ifdef SDB_DEBUGGING_INFO
1933   else if (write_symbols == SDB_DEBUG)
1934     debug_hooks = &sdb_debug_hooks;
1935 #endif
1936 #ifdef DWARF2_DEBUGGING_INFO
1937   else if (write_symbols == DWARF2_DEBUG)
1938     debug_hooks = &dwarf2_debug_hooks;
1939 #endif
1940 #ifdef VMS_DEBUGGING_INFO
1941   else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1942     debug_hooks = &vmsdbg_debug_hooks;
1943 #endif
1944   else
1945     error ("target system does not support the \"%s\" debug format",
1946            debug_type_names[write_symbols]);
1947
1948   /* Now we know which debug output will be used so we can set
1949      flag_var_tracking, flag_rename_registers if the user has
1950      not specified them.  */
1951   if (debug_info_level < DINFO_LEVEL_NORMAL
1952       || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1953     {
1954       if (flag_var_tracking == 1
1955           || flag_var_tracking_uninit == 1)
1956         {
1957           if (debug_info_level < DINFO_LEVEL_NORMAL)
1958             warning (0, "variable tracking requested, but useless unless "
1959                      "producing debug info");
1960           else
1961             warning (0, "variable tracking requested, but not supported "
1962                      "by this debug format");
1963         }
1964       flag_var_tracking = 0;
1965       flag_var_tracking_uninit = 0;
1966     }
1967
1968   if (flag_rename_registers == AUTODETECT_VALUE)
1969     flag_rename_registers = default_debug_hooks->var_location
1970                             != do_nothing_debug_hooks.var_location;
1971
1972   if (flag_var_tracking == AUTODETECT_VALUE)
1973     flag_var_tracking = optimize >= 1;
1974
1975   if (flag_tree_cselim == AUTODETECT_VALUE)
1976 #ifdef HAVE_conditional_move
1977     flag_tree_cselim = 1;
1978 #else
1979     flag_tree_cselim = 0;
1980 #endif
1981
1982   /* If the user specifically requested variable tracking with tagging
1983      uninitialized variables, we need to turn on variable tracking.
1984      (We already determined above that variable tracking is feasible.)  */
1985   if (flag_var_tracking_uninit)
1986     flag_var_tracking = 1;
1987
1988   /* If auxiliary info generation is desired, open the output file.
1989      This goes in the same directory as the source file--unlike
1990      all the other output files.  */
1991   if (flag_gen_aux_info)
1992     {
1993       aux_info_file = fopen (aux_info_file_name, "w");
1994       if (aux_info_file == 0)
1995         fatal_error ("can%'t open %s: %m", aux_info_file_name);
1996     }
1997
1998   if (! targetm.have_named_sections)
1999     {
2000       if (flag_function_sections)
2001         {
2002           warning (0, "-ffunction-sections not supported for this target");
2003           flag_function_sections = 0;
2004         }
2005       if (flag_data_sections)
2006         {
2007           warning (0, "-fdata-sections not supported for this target");
2008           flag_data_sections = 0;
2009         }
2010     }
2011
2012   if (flag_function_sections && profile_flag)
2013     {
2014       warning (0, "-ffunction-sections disabled; it makes profiling impossible");
2015       flag_function_sections = 0;
2016     }
2017
2018 #ifndef HAVE_prefetch
2019   if (flag_prefetch_loop_arrays)
2020     {
2021       warning (0, "-fprefetch-loop-arrays not supported for this target");
2022       flag_prefetch_loop_arrays = 0;
2023     }
2024 #else
2025   if (flag_prefetch_loop_arrays && !HAVE_prefetch)
2026     {
2027       warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
2028       flag_prefetch_loop_arrays = 0;
2029     }
2030 #endif
2031
2032   /* This combination of options isn't handled for i386 targets and doesn't
2033      make much sense anyway, so don't allow it.  */
2034   if (flag_prefetch_loop_arrays && optimize_size)
2035     {
2036       warning (0, "-fprefetch-loop-arrays is not supported with -Os");
2037       flag_prefetch_loop_arrays = 0;
2038     }
2039
2040   /* The presence of IEEE signaling NaNs, implies all math can trap.  */
2041   if (flag_signaling_nans)
2042     flag_trapping_math = 1;
2043
2044   /* We cannot reassociate if we want traps or signed zeros.  */
2045   if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
2046     {
2047       warning (0, "-fassociative-math disabled; other options take precedence");
2048       flag_associative_math = 0;
2049     }
2050
2051   /* With -fcx-limited-range, we do cheap and quick complex arithmetic.  */
2052   if (flag_cx_limited_range)
2053     flag_complex_method = 0;
2054
2055   /* With -fcx-fortran-rules, we do something in-between cheap and C99.  */
2056   if (flag_cx_fortran_rules)
2057     flag_complex_method = 1;
2058
2059   /* Targets must be able to place spill slots at lower addresses.  If the
2060      target already uses a soft frame pointer, the transition is trivial.  */
2061   if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
2062     {
2063       warning (0, "-fstack-protector not supported for this target");
2064       flag_stack_protect = 0;
2065     }
2066   if (!flag_stack_protect)
2067     warn_stack_protect = 0;
2068
2069   /* ??? Unwind info is not correct around the CFG unless either a frame
2070      pointer is present or A_O_A is set.  Fixing this requires rewriting
2071      unwind info generation to be aware of the CFG and propagating states
2072      around edges.  */
2073   if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS
2074       && flag_omit_frame_pointer)
2075     {
2076       warning (0, "unwind tables currently require a frame pointer "
2077                "for correctness");
2078       flag_omit_frame_pointer = 0;
2079     }
2080 }
2081
2082 /* This function can be called multiple times to reinitialize the compiler
2083    back end when register classes or instruction sets have changed,
2084    before each function.  */
2085 static void
2086 backend_init_target (void)
2087 {
2088   /* Initialize alignment variables.  */
2089   init_alignments ();
2090
2091   /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
2092      to initialize reg_raw_mode[].  */
2093   init_emit_regs ();
2094
2095   /* This invokes target hooks to set fixed_reg[] etc, which is
2096      mode-dependent.  */
2097   init_regs ();
2098
2099   /* This depends on stack_pointer_rtx.  */
2100   init_fake_stack_mems ();
2101
2102   /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
2103      mode-dependent.  */
2104   init_alias_target ();
2105
2106   /* Depends on HARD_FRAME_POINTER_REGNUM.  */
2107   init_reload ();
2108
2109   /* The following initialization functions need to generate rtl, so
2110      provide a dummy function context for them.  */
2111   init_dummy_function_start ();
2112
2113   /* rtx_cost is mode-dependent, so cached values need to be recomputed
2114      on a mode change.  */
2115   init_expmed ();
2116
2117   /* We may need to recompute regno_save_code[] and regno_restore_code[]
2118      after a mode change as well.  */
2119   if (flag_caller_saves)
2120     init_caller_save ();
2121   expand_dummy_function_end ();
2122 }
2123
2124 /* Initialize the compiler back end.  This function is called only once,
2125    when starting the compiler.  */
2126 static void
2127 backend_init (void)
2128 {
2129   init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
2130                   || debug_info_level == DINFO_LEVEL_VERBOSE
2131 #ifdef VMS_DEBUGGING_INFO
2132                     /* Enable line number info for traceback.  */
2133                     || debug_info_level > DINFO_LEVEL_NONE
2134 #endif
2135                     || flag_test_coverage);
2136
2137   init_rtlanal ();
2138   init_inline_once ();
2139   init_varasm_once ();
2140   save_register_info ();
2141
2142   /* Initialize the target-specific back end pieces.  */
2143   ira_init_once ();
2144   backend_init_target ();
2145 }
2146
2147 /* Initialize excess precision settings.  */
2148 static void
2149 init_excess_precision (void)
2150 {
2151   /* Adjust excess precision handling based on the target options.  If
2152      the front end cannot handle it, flag_excess_precision_cmdline
2153      will already have been set accordingly in the post_options
2154      hook.  */
2155   gcc_assert (flag_excess_precision_cmdline != EXCESS_PRECISION_DEFAULT);
2156   flag_excess_precision = flag_excess_precision_cmdline;
2157   if (flag_unsafe_math_optimizations)
2158     flag_excess_precision = EXCESS_PRECISION_FAST;
2159   if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
2160     {
2161       int flt_eval_method = TARGET_FLT_EVAL_METHOD;
2162       switch (flt_eval_method)
2163         {
2164         case -1:
2165         case 0:
2166           /* Either the target acts unpredictably (-1) or has all the
2167              operations required not to have excess precision (0).  */
2168           flag_excess_precision = EXCESS_PRECISION_FAST;
2169           break;
2170         case 1:
2171         case 2:
2172           /* In these cases, predictable excess precision makes
2173              sense.  */
2174           break;
2175         default:
2176           /* Any other implementation-defined FLT_EVAL_METHOD values
2177              require the compiler to handle the associated excess
2178              precision rules in excess_precision_type.  */
2179           gcc_unreachable ();
2180         }
2181     }
2182 }
2183
2184 /* Initialize things that are both lang-dependent and target-dependent.
2185    This function can be called more than once if target parameters change.  */
2186 static void
2187 lang_dependent_init_target (void)
2188 {
2189   /* This determines excess precision settings.  */
2190   init_excess_precision ();
2191
2192   /* This creates various _DECL nodes, so needs to be called after the
2193      front end is initialized.  It also depends on the HAVE_xxx macros
2194      generated from the target machine description.  */
2195   init_optabs ();
2196
2197   /* The following initialization functions need to generate rtl, so
2198      provide a dummy function context for them.  */
2199   init_dummy_function_start ();
2200
2201   /* Do the target-specific parts of expr initialization.  */
2202   init_expr_target ();
2203
2204   /* Although the actions of these functions are language-independent,
2205      they use optabs, so we cannot call them from backend_init.  */
2206   init_set_costs ();
2207   ira_init ();
2208
2209   expand_dummy_function_end ();
2210 }
2211
2212 /* Language-dependent initialization.  Returns nonzero on success.  */
2213 static int
2214 lang_dependent_init (const char *name)
2215 {
2216   location_t save_loc = input_location;
2217   if (dump_base_name == 0)
2218     dump_base_name = name && name[0] ? name : "gccdump";
2219
2220   /* Other front-end initialization.  */
2221   input_location = BUILTINS_LOCATION;
2222   if (lang_hooks.init () == 0)
2223     return 0;
2224   input_location = save_loc;
2225
2226   init_asm_output (name);
2227
2228   /* This creates various _DECL nodes, so needs to be called after the
2229      front end is initialized.  */
2230   init_eh ();
2231
2232   /* Do the target-specific parts of the initialization.  */
2233   lang_dependent_init_target ();
2234
2235   /* If dbx symbol table desired, initialize writing it and output the
2236      predefined types.  */
2237   timevar_push (TV_SYMOUT);
2238
2239 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2240   if (dwarf2out_do_frame ())
2241     dwarf2out_frame_init ();
2242 #endif
2243
2244   /* Now we have the correct original filename, we can initialize
2245      debug output.  */
2246   (*debug_hooks->init) (name);
2247
2248   timevar_pop (TV_SYMOUT);
2249
2250   return 1;
2251 }
2252
2253
2254 /* Reinitialize everything when target parameters, such as register usage,
2255    have changed.  */
2256 void
2257 target_reinit (void)
2258 {
2259   /* Reinitialize RTL backend.  */
2260   backend_init_target ();
2261
2262   /* Reinitialize lang-dependent parts.  */
2263   lang_dependent_init_target ();
2264 }
2265
2266 void
2267 dump_memory_report (bool final)
2268 {
2269   ggc_print_statistics ();
2270   stringpool_statistics ();
2271   dump_tree_statistics ();
2272   dump_gimple_statistics ();
2273   dump_rtx_statistics ();
2274   dump_varray_statistics ();
2275   dump_alloc_pool_statistics ();
2276   dump_bitmap_statistics ();
2277   dump_vec_loc_statistics ();
2278   dump_ggc_loc_statistics (final);
2279   dump_alias_stats (stderr);
2280   dump_pta_stats (stderr);
2281 }
2282
2283 /* Clean up: close opened files, etc.  */
2284
2285 static void
2286 finalize (void)
2287 {
2288   /* Close the dump files.  */
2289   if (flag_gen_aux_info)
2290     {
2291       fclose (aux_info_file);
2292       if (errorcount)
2293         unlink (aux_info_file_name);
2294     }
2295
2296   /* Close non-debugging input and output files.  Take special care to note
2297      whether fclose returns an error, since the pages might still be on the
2298      buffer chain while the file is open.  */
2299
2300   if (asm_out_file)
2301     {
2302       if (ferror (asm_out_file) != 0)
2303         fatal_error ("error writing to %s: %m", asm_file_name);
2304       if (fclose (asm_out_file) != 0)
2305         fatal_error ("error closing %s: %m", asm_file_name);
2306     }
2307
2308   statistics_fini ();
2309   finish_optimization_passes ();
2310
2311   ira_finish_once ();
2312
2313   if (mem_report)
2314     dump_memory_report (true);
2315
2316   /* Language-specific end of compilation actions.  */
2317   lang_hooks.finish ();
2318 }
2319
2320 /* Initialize the compiler, and compile the input file.  */
2321 static void
2322 do_compile (void)
2323 {
2324   /* Initialize timing first.  The C front ends read the main file in
2325      the post_options hook, and C++ does file timings.  */
2326   if (time_report || !quiet_flag  || flag_detailed_statistics)
2327     timevar_init ();
2328   timevar_start (TV_TOTAL);
2329
2330   process_options ();
2331
2332   /* Don't do any more if an error has already occurred.  */
2333   if (!errorcount)
2334     {
2335       /* This must be run always, because it is needed to compute the FP
2336          predefined macros, such as __LDBL_MAX__, for targets using non
2337          default FP formats.  */
2338       init_adjust_machine_modes ();
2339
2340       /* Set up the back-end if requested.  */
2341       if (!no_backend)
2342         backend_init ();
2343
2344       /* Language-dependent initialization.  Returns true on success.  */
2345       if (lang_dependent_init (main_input_filename))
2346         compile_file ();
2347
2348       finalize ();
2349
2350       /* Invoke registered plugin callbacks.  */
2351       invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
2352     }
2353
2354   /* Stop timing and print the times.  */
2355   timevar_stop (TV_TOTAL);
2356   timevar_print (stderr);
2357 }
2358
2359 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2360    Exit code is FATAL_EXIT_CODE if can't open files or if there were
2361    any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2362
2363    It is not safe to call this function more than once.  */
2364
2365 int
2366 toplev_main (int argc, char **argv)
2367 {
2368   expandargv (&argc, &argv);
2369
2370   save_argv = CONST_CAST2 (const char **, char **, argv);
2371
2372   /* Initialization of GCC's environment, and diagnostics.  */
2373   general_init (argv[0]);
2374
2375   /* Parse the options and do minimal processing; basically just
2376      enough to default flags appropriately.  */
2377   decode_options (argc, CONST_CAST2 (const char **, char **, argv));
2378
2379   init_local_tick ();
2380
2381   initialize_plugins ();
2382
2383   if (version_flag)
2384     print_version (stderr, "");
2385
2386   if (help_flag)
2387     print_plugins_help (stderr, "");
2388
2389   /* Exit early if we can (e.g. -help).  */
2390   if (!exit_after_options)
2391     do_compile ();
2392
2393   if (warningcount || errorcount) 
2394     print_ignored_options ();
2395
2396   /* Invoke registered plugin callbacks if any.  */
2397   invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
2398
2399   finalize_plugins ();
2400   if (errorcount || sorrycount)
2401     return (FATAL_EXIT_CODE);
2402
2403   return (SUCCESS_EXIT_CODE);
2404 }