OSDN Git Service

Rename -fgraphite-force-parallel to -floop-parallelize-all.
[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   /* This must also call cgraph_finalize_compilation_unit and
1038      cgraph_optimize.  */
1039   lang_hooks.decls.final_write_globals ();
1040
1041   if (errorcount || sorrycount)
1042     return;
1043
1044   varpool_assemble_pending_decls ();
1045   finish_aliases_2 ();
1046
1047   /* Likewise for mudflap static object registrations.  */
1048   if (flag_mudflap)
1049     mudflap_finish_file ();
1050
1051   /* Likewise for emulated thread-local storage.  */
1052   if (!targetm.have_tls)
1053     emutls_finish ();
1054
1055   output_shared_constant_pool ();
1056   output_object_blocks ();
1057
1058   /* Write out any pending weak symbol declarations.  */
1059   weak_finish ();
1060
1061   /* Do dbx symbols.  */
1062   timevar_push (TV_SYMOUT);
1063
1064 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
1065   if (dwarf2out_do_frame ())
1066     dwarf2out_frame_finish ();
1067 #endif
1068
1069   (*debug_hooks->finish) (main_input_filename);
1070   timevar_pop (TV_SYMOUT);
1071
1072   /* Output some stuff at end of file if nec.  */
1073
1074   dw2_output_indirect_constants ();
1075
1076   /* Flush any pending external directives.  */
1077   process_pending_assemble_externals ();
1078
1079   /* Attach a special .ident directive to the end of the file to identify
1080      the version of GCC which compiled this code.  The format of the .ident
1081      string is patterned after the ones produced by native SVR4 compilers.  */
1082 #ifdef IDENT_ASM_OP
1083   if (!flag_no_ident)
1084     {
1085       const char *pkg_version = "(GNU) ";
1086
1087       if (strcmp ("(GCC) ", pkgversion_string))
1088         pkg_version = pkgversion_string;
1089       fprintf (asm_out_file, "%s\"GCC: %s%s\"\n",
1090                IDENT_ASM_OP, pkg_version, version_string);
1091     }
1092 #endif
1093
1094   /* Invoke registered plugin callbacks.  */
1095   invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
1096   
1097   /* This must be at the end.  Some target ports emit end of file directives
1098      into the assembly file here, and hence we can not output anything to the
1099      assembly file after this point.  */
1100   targetm.asm_out.file_end ();
1101 }
1102
1103 /* Parse a -d... command line switch.  */
1104
1105 void
1106 decode_d_option (const char *arg)
1107 {
1108   int c;
1109
1110   while (*arg)
1111     switch (c = *arg++)
1112       {
1113       case 'A':
1114         flag_debug_asm = 1;
1115         break;
1116       case 'p':
1117         flag_print_asm_name = 1;
1118         break;
1119       case 'P':
1120         flag_dump_rtl_in_asm = 1;
1121         flag_print_asm_name = 1;
1122         break;
1123       case 'v':
1124         graph_dump_format = vcg;
1125         break;
1126       case 'x':
1127         rtl_dump_and_exit = 1;
1128         break;
1129       case 'y':
1130         set_yydebug = 1;
1131         break;
1132       case 'D': /* These are handled by the preprocessor.  */
1133       case 'I':
1134       case 'M':
1135       case 'N':
1136       case 'U':
1137         break;
1138       case 'H':
1139         setup_core_dumping();
1140         break;
1141       case 'a':
1142         enable_rtl_dump_file ();
1143         break;
1144
1145       default:
1146           warning (0, "unrecognized gcc debugging option: %c", c);
1147         break;
1148       }
1149 }
1150
1151 /* Indexed by enum debug_info_type.  */
1152 const char *const debug_type_names[] =
1153 {
1154   "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
1155 };
1156
1157 /* Print version information to FILE.
1158    Each line begins with INDENT (for the case where FILE is the
1159    assembler output file).  */
1160
1161 void
1162 print_version (FILE *file, const char *indent)
1163 {
1164   static const char fmt1[] =
1165 #ifdef __GNUC__
1166     N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
1167 #else
1168     N_("%s%s%s %sversion %s (%s) compiled by CC, ")
1169 #endif
1170     ;
1171 #ifdef HAVE_mpc
1172   static const char fmt2[] =
1173     N_("GMP version %s, MPFR version %s, MPC version %s\n");
1174 #else
1175   static const char fmt2[] =
1176     N_("GMP version %s, MPFR version %s\n");
1177 #endif
1178   static const char fmt3[] =
1179     N_("%s%swarning: %s header version %s differs from library version %s.\n");
1180   static const char fmt4[] =
1181     N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
1182 #ifndef __VERSION__
1183 #define __VERSION__ "[?]"
1184 #endif
1185   fprintf (file,
1186            file == stderr ? _(fmt1) : fmt1,
1187            indent, *indent != 0 ? " " : "",
1188            lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
1189            indent, __VERSION__);
1190
1191   /* We need to stringify the GMP macro values.  Ugh, gmp_version has
1192      two string formats, "i.j.k" and "i.j" when k is zero.  As of
1193      gmp-4.3.0, GMP always uses the 3 number format.  */
1194 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
1195 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
1196 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
1197 #define GCC_GMP_VERSION \
1198   GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
1199 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
1200 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1201   GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
1202 #else
1203 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1204   GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
1205   GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
1206 #endif
1207   fprintf (file,
1208            file == stderr ? _(fmt2) : fmt2,
1209            GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING
1210 #ifdef HAVE_mpc
1211            , MPC_VERSION_STRING
1212 #endif
1213            );
1214   if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
1215     fprintf (file,
1216              file == stderr ? _(fmt3) : fmt3,
1217              indent, *indent != 0 ? " " : "",
1218              "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
1219   if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
1220     fprintf (file,
1221              file == stderr ? _(fmt3) : fmt3,
1222              indent, *indent != 0 ? " " : "",
1223              "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
1224 #ifdef HAVE_mpc
1225   if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
1226     fprintf (file,
1227              file == stderr ? _(fmt3) : fmt3,
1228              indent, *indent != 0 ? " " : "",
1229              "MPC", MPC_VERSION_STRING, mpc_get_version ());
1230 #endif
1231   fprintf (file,
1232            file == stderr ? _(fmt4) : fmt4,
1233            indent, *indent != 0 ? " " : "",
1234            PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
1235
1236   print_plugins_versions (file, indent);
1237 }
1238
1239 #ifdef ASM_COMMENT_START
1240 static int
1241 print_to_asm_out_file (print_switch_type type, const char * text)
1242 {
1243   bool prepend_sep = true;
1244
1245   switch (type)
1246     {
1247     case SWITCH_TYPE_LINE_END:
1248       putc ('\n', asm_out_file);
1249       return 1;
1250
1251     case SWITCH_TYPE_LINE_START:
1252       fputs (ASM_COMMENT_START, asm_out_file);
1253       return strlen (ASM_COMMENT_START);
1254
1255     case SWITCH_TYPE_DESCRIPTIVE:
1256       if (ASM_COMMENT_START[0] == 0)
1257         prepend_sep = false;
1258       /* Drop through.  */
1259     case SWITCH_TYPE_PASSED:
1260     case SWITCH_TYPE_ENABLED:
1261       if (prepend_sep)
1262         fputc (' ', asm_out_file);
1263       fprintf (asm_out_file, text);
1264       /* No need to return the length here as
1265          print_single_switch has already done it.  */
1266       return 0;
1267
1268     default:
1269       return -1;
1270     }
1271 }
1272 #endif
1273
1274 static int
1275 print_to_stderr (print_switch_type type, const char * text)
1276 {
1277   switch (type)
1278     {
1279     case SWITCH_TYPE_LINE_END:
1280       putc ('\n', stderr);
1281       return 1;
1282
1283     case SWITCH_TYPE_LINE_START:
1284       return 0;
1285       
1286     case SWITCH_TYPE_PASSED:
1287     case SWITCH_TYPE_ENABLED:
1288       fputc (' ', stderr);
1289       /* Drop through.  */
1290
1291     case SWITCH_TYPE_DESCRIPTIVE:
1292       fprintf (stderr, text);
1293       /* No need to return the length here as
1294          print_single_switch has already done it.  */
1295       return 0;
1296
1297     default:
1298       return -1;
1299     }
1300 }
1301
1302 /* Print an option value and return the adjusted position in the line.
1303    ??? print_fn doesn't handle errors, eg disk full; presumably other
1304    code will catch a disk full though.  */
1305
1306 static int
1307 print_single_switch (print_switch_fn_type print_fn,
1308                      int pos,
1309                      print_switch_type type,
1310                      const char * text)
1311 {
1312   /* The ultrix fprintf returns 0 on success, so compute the result
1313      we want here since we need it for the following test.  The +1
1314      is for the separator character that will probably be emitted.  */
1315   int len = strlen (text) + 1;
1316
1317   if (pos != 0
1318       && pos + len > MAX_LINE)
1319     {
1320       print_fn (SWITCH_TYPE_LINE_END, NULL);
1321       pos = 0;
1322     }
1323
1324   if (pos == 0)
1325     pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
1326
1327   print_fn (type, text);
1328   return pos + len;
1329 }
1330
1331 /* Print active target switches using PRINT_FN.
1332    POS is the current cursor position and MAX is the size of a "line".
1333    Each line begins with INDENT and ends with TERM.
1334    Each switch is separated from the next by SEP.  */
1335
1336 static void
1337 print_switch_values (print_switch_fn_type print_fn)
1338 {
1339   int pos = 0;
1340   size_t j;
1341   const char **p;
1342
1343   /* Fill in the -frandom-seed option, if the user didn't pass it, so
1344      that it can be printed below.  This helps reproducibility.  */
1345   if (!flag_random_seed)
1346     init_random_seed ();
1347
1348   /* Print the options as passed.  */
1349   pos = print_single_switch (print_fn, pos,
1350                              SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
1351
1352   for (p = &save_argv[1]; *p != NULL; p++)
1353     {
1354       if (**p == '-')
1355         {
1356           /* Ignore these.  */
1357           if (strcmp (*p, "-o") == 0
1358               || strcmp (*p, "-dumpbase") == 0
1359               || strcmp (*p, "-auxbase") == 0)
1360             {
1361               if (p[1] != NULL)
1362                 p++;
1363               continue;
1364             }
1365
1366           if (strcmp (*p, "-quiet") == 0
1367               || strcmp (*p, "-version") == 0)
1368             continue;
1369
1370           if ((*p)[1] == 'd')
1371             continue;
1372         }
1373
1374       pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED, *p);
1375     }
1376
1377   if (pos > 0)
1378     print_fn (SWITCH_TYPE_LINE_END, NULL);
1379
1380   /* Print the -f and -m options that have been enabled.
1381      We don't handle language specific options but printing argv
1382      should suffice.  */
1383   pos = print_single_switch (print_fn, 0,
1384                              SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
1385
1386   for (j = 0; j < cl_options_count; j++)
1387     if ((cl_options[j].flags & CL_REPORT)
1388         && option_enabled (j) > 0)
1389       pos = print_single_switch (print_fn, pos,
1390                                  SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
1391
1392   print_fn (SWITCH_TYPE_LINE_END, NULL);
1393 }
1394
1395 /* Open assembly code output file.  Do this even if -fsyntax-only is
1396    on, because then the driver will have provided the name of a
1397    temporary file or bit bucket for us.  NAME is the file specified on
1398    the command line, possibly NULL.  */
1399 static void
1400 init_asm_output (const char *name)
1401 {
1402   if (name == NULL && asm_file_name == 0)
1403     asm_out_file = stdout;
1404   else
1405     {
1406       if (asm_file_name == 0)
1407         {
1408           int len = strlen (dump_base_name);
1409           char *dumpname = XNEWVEC (char, len + 6);
1410
1411           memcpy (dumpname, dump_base_name, len + 1);
1412           strip_off_ending (dumpname, len);
1413           strcat (dumpname, ".s");
1414           asm_file_name = dumpname;
1415         }
1416       if (!strcmp (asm_file_name, "-"))
1417         asm_out_file = stdout;
1418       else
1419         asm_out_file = fopen (asm_file_name, "w+b");
1420       if (asm_out_file == 0)
1421         fatal_error ("can%'t open %s for writing: %m", asm_file_name);
1422     }
1423
1424   if (!flag_syntax_only)
1425     {
1426       targetm.asm_out.file_start ();
1427
1428       if (flag_record_gcc_switches)
1429         {
1430           if (targetm.asm_out.record_gcc_switches)
1431             {
1432               /* Let the target know that we are about to start recording.  */
1433               targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1434                                                    NULL);
1435               /* Now record the switches.  */
1436               print_switch_values (targetm.asm_out.record_gcc_switches);
1437               /* Let the target know that the recording is over.  */
1438               targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1439                                                    NULL);
1440             }
1441           else
1442             inform (input_location, "-frecord-gcc-switches is not supported by the current target");
1443         }
1444
1445 #ifdef ASM_COMMENT_START
1446       if (flag_verbose_asm)
1447         {
1448           /* Print the list of switches in effect
1449              into the assembler file as comments.  */
1450           print_version (asm_out_file, ASM_COMMENT_START);
1451           print_switch_values (print_to_asm_out_file);
1452           fprintf (asm_out_file, "\n");
1453         }
1454 #endif
1455     }
1456 }
1457
1458 /* Return true if the state of option OPTION should be stored in PCH files
1459    and checked by default_pch_valid_p.  Store the option's current state
1460    in STATE if so.  */
1461
1462 static inline bool
1463 option_affects_pch_p (int option, struct cl_option_state *state)
1464 {
1465   if ((cl_options[option].flags & CL_TARGET) == 0)
1466     return false;
1467   if (cl_options[option].flag_var == &target_flags)
1468     if (targetm.check_pch_target_flags)
1469       return false;
1470   return get_option_state (option, state);
1471 }
1472
1473 /* Default version of get_pch_validity.
1474    By default, every flag difference is fatal; that will be mostly right for
1475    most targets, but completely right for very few.  */
1476
1477 void *
1478 default_get_pch_validity (size_t *len)
1479 {
1480   struct cl_option_state state;
1481   size_t i;
1482   char *result, *r;
1483
1484   *len = 2;
1485   if (targetm.check_pch_target_flags)
1486     *len += sizeof (target_flags);
1487   for (i = 0; i < cl_options_count; i++)
1488     if (option_affects_pch_p (i, &state))
1489       *len += state.size;
1490
1491   result = r = XNEWVEC (char, *len);
1492   r[0] = flag_pic;
1493   r[1] = flag_pie;
1494   r += 2;
1495   if (targetm.check_pch_target_flags)
1496     {
1497       memcpy (r, &target_flags, sizeof (target_flags));
1498       r += sizeof (target_flags);
1499     }
1500
1501   for (i = 0; i < cl_options_count; i++)
1502     if (option_affects_pch_p (i, &state))
1503       {
1504         memcpy (r, state.data, state.size);
1505         r += state.size;
1506       }
1507
1508   return result;
1509 }
1510
1511 /* Return a message which says that a PCH file was created with a different
1512    setting of OPTION.  */
1513
1514 static const char *
1515 pch_option_mismatch (const char *option)
1516 {
1517   char *r;
1518
1519   asprintf (&r, _("created and used with differing settings of '%s'"), option);
1520   if (r == NULL)
1521     return _("out of memory");
1522   return r;
1523 }
1524
1525 /* Default version of pch_valid_p.  */
1526
1527 const char *
1528 default_pch_valid_p (const void *data_p, size_t len)
1529 {
1530   struct cl_option_state state;
1531   const char *data = (const char *)data_p;
1532   size_t i;
1533
1534   /* -fpic and -fpie also usually make a PCH invalid.  */
1535   if (data[0] != flag_pic)
1536     return _("created and used with different settings of -fpic");
1537   if (data[1] != flag_pie)
1538     return _("created and used with different settings of -fpie");
1539   data += 2;
1540
1541   /* Check target_flags.  */
1542   if (targetm.check_pch_target_flags)
1543     {
1544       int tf;
1545       const char *r;
1546
1547       memcpy (&tf, data, sizeof (target_flags));
1548       data += sizeof (target_flags);
1549       len -= sizeof (target_flags);
1550       r = targetm.check_pch_target_flags (tf);
1551       if (r != NULL)
1552         return r;
1553     }
1554
1555   for (i = 0; i < cl_options_count; i++)
1556     if (option_affects_pch_p (i, &state))
1557       {
1558         if (memcmp (data, state.data, state.size) != 0)
1559           return pch_option_mismatch (cl_options[i].opt_text);
1560         data += state.size;
1561         len -= state.size;
1562       }
1563
1564   return NULL;
1565 }
1566
1567 /* Default tree printer.   Handles declarations only.  */
1568 static bool
1569 default_tree_printer (pretty_printer * pp, text_info *text, const char *spec,
1570                       int precision, bool wide, bool set_locus, bool hash)
1571 {
1572   tree t;
1573
1574   /* FUTURE: %+x should set the locus.  */
1575   if (precision != 0 || wide || hash)
1576     return false;
1577
1578   switch (*spec)
1579     {
1580     case 'E':
1581       t = va_arg (*text->args_ptr, tree);
1582       if (TREE_CODE (t) == IDENTIFIER_NODE)
1583         {
1584           pp_identifier (pp, IDENTIFIER_POINTER (t));
1585           return true;
1586         }
1587       break;
1588
1589     case 'D':
1590       t = va_arg (*text->args_ptr, tree);
1591       if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
1592         t = DECL_DEBUG_EXPR (t);
1593       break;
1594
1595     case 'F':
1596     case 'T':
1597       t = va_arg (*text->args_ptr, tree);
1598       break;
1599
1600     default:
1601       return false;
1602     }
1603
1604   if (set_locus && text->locus)
1605     *text->locus = DECL_SOURCE_LOCATION (t);
1606
1607   if (DECL_P (t))
1608     {
1609       const char *n = DECL_NAME (t)
1610         ? identifier_to_locale (lang_hooks.decl_printable_name (t, 2))
1611         : _("<anonymous>");
1612       pp_string (pp, n);
1613     }
1614   else
1615     dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0);
1616
1617   return true;
1618 }
1619
1620 /* A helper function; used as the reallocator function for cpp's line
1621    table.  */
1622 static void *
1623 realloc_for_line_map (void *ptr, size_t len)
1624 {
1625   return ggc_realloc (ptr, len);
1626 }
1627
1628 /* Initialization of the front end environment, before command line
1629    options are parsed.  Signal handlers, internationalization etc.
1630    ARGV0 is main's argv[0].  */
1631 static void
1632 general_init (const char *argv0)
1633 {
1634   const char *p;
1635
1636   p = argv0 + strlen (argv0);
1637   while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1638     --p;
1639   progname = p;
1640
1641   xmalloc_set_program_name (progname);
1642
1643   hex_init ();
1644
1645   /* Unlock the stdio streams.  */
1646   unlock_std_streams ();
1647
1648   gcc_init_libintl ();
1649
1650   /* Initialize the diagnostics reporting machinery, so option parsing
1651      can give warnings and errors.  */
1652   diagnostic_initialize (global_dc);
1653   /* Set a default printer.  Language specific initializations will
1654      override it later.  */
1655   pp_format_decoder (global_dc->printer) = &default_tree_printer;
1656
1657   /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages.  */
1658 #ifdef SIGSEGV
1659   signal (SIGSEGV, crash_signal);
1660 #endif
1661 #ifdef SIGILL
1662   signal (SIGILL, crash_signal);
1663 #endif
1664 #ifdef SIGBUS
1665   signal (SIGBUS, crash_signal);
1666 #endif
1667 #ifdef SIGABRT
1668   signal (SIGABRT, crash_signal);
1669 #endif
1670 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1671   signal (SIGIOT, crash_signal);
1672 #endif
1673 #ifdef SIGFPE
1674   signal (SIGFPE, crash_signal);
1675 #endif
1676
1677   /* Other host-specific signal setup.  */
1678   (*host_hooks.extra_signals)();
1679
1680   /* Initialize the garbage-collector, string pools and tree type hash
1681      table.  */
1682   init_ggc ();
1683   init_stringpool ();
1684   line_table = GGC_NEW (struct line_maps);
1685   linemap_init (line_table);
1686   line_table->reallocator = realloc_for_line_map;
1687   init_ttree ();
1688
1689   /* Initialize register usage now so switches may override.  */
1690   init_reg_sets ();
1691
1692   /* Register the language-independent parameters.  */
1693   add_params (lang_independent_params, LAST_PARAM);
1694
1695   /* This must be done after add_params but before argument processing.  */
1696   init_ggc_heuristics();
1697   init_optimization_passes ();
1698   statistics_early_init ();
1699 }
1700
1701 /* Return true if the current target supports -fsection-anchors.  */
1702
1703 static bool
1704 target_supports_section_anchors_p (void)
1705 {
1706   if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1707     return false;
1708
1709   if (targetm.asm_out.output_anchor == NULL)
1710     return false;
1711
1712   return true;
1713 }
1714
1715 /* Default the align_* variables to 1 if they're still unset, and
1716    set up the align_*_log variables.  */
1717 static void
1718 init_alignments (void)
1719 {
1720   if (align_loops <= 0)
1721     align_loops = 1;
1722   if (align_loops_max_skip > align_loops)
1723     align_loops_max_skip = align_loops - 1;
1724   align_loops_log = floor_log2 (align_loops * 2 - 1);
1725   if (align_jumps <= 0)
1726     align_jumps = 1;
1727   if (align_jumps_max_skip > align_jumps)
1728     align_jumps_max_skip = align_jumps - 1;
1729   align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1730   if (align_labels <= 0)
1731     align_labels = 1;
1732   align_labels_log = floor_log2 (align_labels * 2 - 1);
1733   if (align_labels_max_skip > align_labels)
1734     align_labels_max_skip = align_labels - 1;
1735   if (align_functions <= 0)
1736     align_functions = 1;
1737   align_functions_log = floor_log2 (align_functions * 2 - 1);
1738 }
1739
1740 /* Process the options that have been parsed.  */
1741 static void
1742 process_options (void)
1743 {
1744   /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1745      This can happen with incorrect pre-processed input. */
1746   debug_hooks = &do_nothing_debug_hooks;
1747
1748   /* This replaces set_Wunused.  */
1749   if (warn_unused_function == -1)
1750     warn_unused_function = warn_unused;
1751   if (warn_unused_label == -1)
1752     warn_unused_label = warn_unused;
1753   /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled.  */
1754   if (warn_unused_parameter == -1)
1755     warn_unused_parameter = (warn_unused && extra_warnings);
1756   if (warn_unused_variable == -1)
1757     warn_unused_variable = warn_unused;
1758   if (warn_unused_value == -1)
1759     warn_unused_value = warn_unused;
1760
1761   /* This replaces set_Wextra.  */
1762   if (warn_uninitialized == -1)
1763     warn_uninitialized = extra_warnings;
1764
1765   /* Allow the front end to perform consistency checks and do further
1766      initialization based on the command line options.  This hook also
1767      sets the original filename if appropriate (e.g. foo.i -> foo.c)
1768      so we can correctly initialize debug output.  */
1769   no_backend = lang_hooks.post_options (&main_input_filename);
1770
1771 #ifdef OVERRIDE_OPTIONS
1772   /* Some machines may reject certain combinations of options.  */
1773   OVERRIDE_OPTIONS;
1774 #endif
1775
1776   if (flag_section_anchors && !target_supports_section_anchors_p ())
1777     {
1778       warning (OPT_fsection_anchors,
1779                "this target does not support %qs", "-fsection-anchors");
1780       flag_section_anchors = 0;
1781     }
1782
1783   if (flag_short_enums == 2)
1784     flag_short_enums = targetm.default_short_enums ();
1785
1786   /* Set aux_base_name if not already set.  */
1787   if (aux_base_name)
1788     ;
1789   else if (main_input_filename)
1790     {
1791       char *name = xstrdup (lbasename (main_input_filename));
1792
1793       strip_off_ending (name, strlen (name));
1794       aux_base_name = name;
1795     }
1796   else
1797     aux_base_name = "gccaux";
1798
1799 #ifndef HAVE_cloog
1800   if (flag_graphite
1801       || flag_loop_block
1802       || flag_loop_interchange
1803       || flag_loop_strip_mine
1804       || flag_graphite_identity
1805       || flag_loop_parallelize_all)
1806     sorry ("Graphite loop optimizations cannot be used");
1807 #endif
1808
1809   /* Unrolling all loops implies that standard loop unrolling must also
1810      be done.  */
1811   if (flag_unroll_all_loops)
1812     flag_unroll_loops = 1;
1813
1814   /* The loop unrolling code assumes that cse will be run after loop.
1815      web and rename-registers also help when run after loop unrolling.  */
1816
1817   if (flag_rerun_cse_after_loop == AUTODETECT_VALUE)
1818     flag_rerun_cse_after_loop = flag_unroll_loops || flag_peel_loops;
1819   if (flag_web == AUTODETECT_VALUE)
1820     flag_web = flag_unroll_loops || flag_peel_loops;
1821   if (flag_rename_registers == AUTODETECT_VALUE)
1822     flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1823
1824   if (flag_non_call_exceptions)
1825     flag_asynchronous_unwind_tables = 1;
1826   if (flag_asynchronous_unwind_tables)
1827     flag_unwind_tables = 1;
1828
1829   if (flag_value_profile_transformations)
1830     flag_profile_values = 1;
1831
1832   /* Warn about options that are not supported on this machine.  */
1833 #ifndef INSN_SCHEDULING
1834   if (flag_schedule_insns || flag_schedule_insns_after_reload)
1835     warning (0, "instruction scheduling not supported on this target machine");
1836 #endif
1837 #ifndef DELAY_SLOTS
1838   if (flag_delayed_branch)
1839     warning (0, "this target machine does not have delayed branches");
1840 #endif
1841
1842   user_label_prefix = USER_LABEL_PREFIX;
1843   if (flag_leading_underscore != -1)
1844     {
1845       /* If the default prefix is more complicated than "" or "_",
1846          issue a warning and ignore this option.  */
1847       if (user_label_prefix[0] == 0 ||
1848           (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1849         {
1850           user_label_prefix = flag_leading_underscore ? "_" : "";
1851         }
1852       else
1853         warning (0, "-f%sleading-underscore not supported on this target machine",
1854                  flag_leading_underscore ? "" : "no-");
1855     }
1856
1857   /* If we are in verbose mode, write out the version and maybe all the
1858      option flags in use.  */
1859   if (version_flag)
1860     {
1861       print_version (stderr, "");
1862       if (! quiet_flag)
1863         print_switch_values (print_to_stderr);
1864     }
1865
1866   if (flag_syntax_only)
1867     {
1868       write_symbols = NO_DEBUG;
1869       profile_flag = 0;
1870     }
1871
1872   if (flag_gtoggle)
1873     {
1874       if (debug_info_level == DINFO_LEVEL_NONE)
1875         debug_info_level = DINFO_LEVEL_NORMAL;
1876       else
1877         debug_info_level = DINFO_LEVEL_NONE;
1878     }
1879
1880   if (flag_dump_final_insns)
1881     {
1882       FILE *final_output = fopen (flag_dump_final_insns, "w");
1883       if (!final_output)
1884         {
1885           error ("could not open final insn dump file %qs: %s",
1886                  flag_dump_final_insns, strerror (errno));
1887           flag_dump_final_insns = NULL;
1888         }
1889       else if (fclose (final_output))
1890         {
1891           error ("could not close zeroed insn dump file %qs: %s",
1892                  flag_dump_final_insns, strerror (errno));
1893           flag_dump_final_insns = NULL;
1894         }
1895     }
1896
1897   /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1898      level is 0.  */
1899   if (debug_info_level == DINFO_LEVEL_NONE)
1900     write_symbols = NO_DEBUG;
1901
1902   /* Now we know write_symbols, set up the debug hooks based on it.
1903      By default we do nothing for debug output.  */
1904   if (PREFERRED_DEBUGGING_TYPE == NO_DEBUG)
1905     default_debug_hooks = &do_nothing_debug_hooks;
1906 #if defined(DBX_DEBUGGING_INFO)
1907   else if (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG)
1908     default_debug_hooks = &dbx_debug_hooks;
1909 #endif
1910 #if defined(XCOFF_DEBUGGING_INFO)
1911   else if (PREFERRED_DEBUGGING_TYPE == XCOFF_DEBUG)
1912     default_debug_hooks = &xcoff_debug_hooks;
1913 #endif
1914 #ifdef SDB_DEBUGGING_INFO
1915   else if (PREFERRED_DEBUGGING_TYPE == SDB_DEBUG)
1916     default_debug_hooks = &sdb_debug_hooks;
1917 #endif
1918 #ifdef DWARF2_DEBUGGING_INFO
1919   else if (PREFERRED_DEBUGGING_TYPE == DWARF2_DEBUG)
1920     default_debug_hooks = &dwarf2_debug_hooks;
1921 #endif
1922 #ifdef VMS_DEBUGGING_INFO
1923   else if (PREFERRED_DEBUGGING_TYPE == VMS_DEBUG
1924            || PREFERRED_DEBUGGING_TYPE == VMS_AND_DWARF2_DEBUG)
1925     default_debug_hooks = &vmsdbg_debug_hooks;
1926 #endif
1927
1928   if (write_symbols == NO_DEBUG)
1929     ;
1930 #if defined(DBX_DEBUGGING_INFO)
1931   else if (write_symbols == DBX_DEBUG)
1932     debug_hooks = &dbx_debug_hooks;
1933 #endif
1934 #if defined(XCOFF_DEBUGGING_INFO)
1935   else if (write_symbols == XCOFF_DEBUG)
1936     debug_hooks = &xcoff_debug_hooks;
1937 #endif
1938 #ifdef SDB_DEBUGGING_INFO
1939   else if (write_symbols == SDB_DEBUG)
1940     debug_hooks = &sdb_debug_hooks;
1941 #endif
1942 #ifdef DWARF2_DEBUGGING_INFO
1943   else if (write_symbols == DWARF2_DEBUG)
1944     debug_hooks = &dwarf2_debug_hooks;
1945 #endif
1946 #ifdef VMS_DEBUGGING_INFO
1947   else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1948     debug_hooks = &vmsdbg_debug_hooks;
1949 #endif
1950   else
1951     error ("target system does not support the \"%s\" debug format",
1952            debug_type_names[write_symbols]);
1953
1954   /* Now we know which debug output will be used so we can set
1955      flag_var_tracking, flag_rename_registers if the user has
1956      not specified them.  */
1957   if (debug_info_level < DINFO_LEVEL_NORMAL
1958       || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1959     {
1960       if (flag_var_tracking == 1
1961           || flag_var_tracking_uninit == 1)
1962         {
1963           if (debug_info_level < DINFO_LEVEL_NORMAL)
1964             warning (0, "variable tracking requested, but useless unless "
1965                      "producing debug info");
1966           else
1967             warning (0, "variable tracking requested, but not supported "
1968                      "by this debug format");
1969         }
1970       flag_var_tracking = 0;
1971       flag_var_tracking_uninit = 0;
1972     }
1973
1974   if (flag_rename_registers == AUTODETECT_VALUE)
1975     flag_rename_registers = default_debug_hooks->var_location
1976                             != do_nothing_debug_hooks.var_location;
1977
1978   if (flag_var_tracking == AUTODETECT_VALUE)
1979     flag_var_tracking = optimize >= 1;
1980
1981   if (flag_tree_cselim == AUTODETECT_VALUE)
1982 #ifdef HAVE_conditional_move
1983     flag_tree_cselim = 1;
1984 #else
1985     flag_tree_cselim = 0;
1986 #endif
1987
1988   /* If the user specifically requested variable tracking with tagging
1989      uninitialized variables, we need to turn on variable tracking.
1990      (We already determined above that variable tracking is feasible.)  */
1991   if (flag_var_tracking_uninit)
1992     flag_var_tracking = 1;
1993
1994   /* If auxiliary info generation is desired, open the output file.
1995      This goes in the same directory as the source file--unlike
1996      all the other output files.  */
1997   if (flag_gen_aux_info)
1998     {
1999       aux_info_file = fopen (aux_info_file_name, "w");
2000       if (aux_info_file == 0)
2001         fatal_error ("can%'t open %s: %m", aux_info_file_name);
2002     }
2003
2004   if (! targetm.have_named_sections)
2005     {
2006       if (flag_function_sections)
2007         {
2008           warning (0, "-ffunction-sections not supported for this target");
2009           flag_function_sections = 0;
2010         }
2011       if (flag_data_sections)
2012         {
2013           warning (0, "-fdata-sections not supported for this target");
2014           flag_data_sections = 0;
2015         }
2016     }
2017
2018   if (flag_function_sections && profile_flag)
2019     {
2020       warning (0, "-ffunction-sections disabled; it makes profiling impossible");
2021       flag_function_sections = 0;
2022     }
2023
2024 #ifndef HAVE_prefetch
2025   if (flag_prefetch_loop_arrays)
2026     {
2027       warning (0, "-fprefetch-loop-arrays not supported for this target");
2028       flag_prefetch_loop_arrays = 0;
2029     }
2030 #else
2031   if (flag_prefetch_loop_arrays && !HAVE_prefetch)
2032     {
2033       warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
2034       flag_prefetch_loop_arrays = 0;
2035     }
2036 #endif
2037
2038   /* This combination of options isn't handled for i386 targets and doesn't
2039      make much sense anyway, so don't allow it.  */
2040   if (flag_prefetch_loop_arrays && optimize_size)
2041     {
2042       warning (0, "-fprefetch-loop-arrays is not supported with -Os");
2043       flag_prefetch_loop_arrays = 0;
2044     }
2045
2046   /* The presence of IEEE signaling NaNs, implies all math can trap.  */
2047   if (flag_signaling_nans)
2048     flag_trapping_math = 1;
2049
2050   /* We cannot reassociate if we want traps or signed zeros.  */
2051   if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
2052     {
2053       warning (0, "-fassociative-math disabled; other options take precedence");
2054       flag_associative_math = 0;
2055     }
2056
2057   /* With -fcx-limited-range, we do cheap and quick complex arithmetic.  */
2058   if (flag_cx_limited_range)
2059     flag_complex_method = 0;
2060
2061   /* With -fcx-fortran-rules, we do something in-between cheap and C99.  */
2062   if (flag_cx_fortran_rules)
2063     flag_complex_method = 1;
2064
2065   /* Targets must be able to place spill slots at lower addresses.  If the
2066      target already uses a soft frame pointer, the transition is trivial.  */
2067   if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
2068     {
2069       warning (0, "-fstack-protector not supported for this target");
2070       flag_stack_protect = 0;
2071     }
2072   if (!flag_stack_protect)
2073     warn_stack_protect = 0;
2074
2075   /* ??? Unwind info is not correct around the CFG unless either a frame
2076      pointer is present or A_O_A is set.  Fixing this requires rewriting
2077      unwind info generation to be aware of the CFG and propagating states
2078      around edges.  */
2079   if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS
2080       && flag_omit_frame_pointer)
2081     {
2082       warning (0, "unwind tables currently require a frame pointer "
2083                "for correctness");
2084       flag_omit_frame_pointer = 0;
2085     }
2086 }
2087
2088 /* This function can be called multiple times to reinitialize the compiler
2089    back end when register classes or instruction sets have changed,
2090    before each function.  */
2091 static void
2092 backend_init_target (void)
2093 {
2094   /* Initialize alignment variables.  */
2095   init_alignments ();
2096
2097   /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
2098      to initialize reg_raw_mode[].  */
2099   init_emit_regs ();
2100
2101   /* This invokes target hooks to set fixed_reg[] etc, which is
2102      mode-dependent.  */
2103   init_regs ();
2104
2105   /* This depends on stack_pointer_rtx.  */
2106   init_fake_stack_mems ();
2107
2108   /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
2109      mode-dependent.  */
2110   init_alias_target ();
2111
2112   /* Depends on HARD_FRAME_POINTER_REGNUM.  */
2113   init_reload ();
2114
2115   /* The following initialization functions need to generate rtl, so
2116      provide a dummy function context for them.  */
2117   init_dummy_function_start ();
2118
2119   /* rtx_cost is mode-dependent, so cached values need to be recomputed
2120      on a mode change.  */
2121   init_expmed ();
2122
2123   /* We may need to recompute regno_save_code[] and regno_restore_code[]
2124      after a mode change as well.  */
2125   if (flag_caller_saves)
2126     init_caller_save ();
2127   expand_dummy_function_end ();
2128 }
2129
2130 /* Initialize the compiler back end.  This function is called only once,
2131    when starting the compiler.  */
2132 static void
2133 backend_init (void)
2134 {
2135   init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
2136                   || debug_info_level == DINFO_LEVEL_VERBOSE
2137 #ifdef VMS_DEBUGGING_INFO
2138                     /* Enable line number info for traceback.  */
2139                     || debug_info_level > DINFO_LEVEL_NONE
2140 #endif
2141                     || flag_test_coverage);
2142
2143   init_rtlanal ();
2144   init_inline_once ();
2145   init_varasm_once ();
2146   save_register_info ();
2147
2148   /* Initialize the target-specific back end pieces.  */
2149   ira_init_once ();
2150   backend_init_target ();
2151 }
2152
2153 /* Initialize excess precision settings.  */
2154 static void
2155 init_excess_precision (void)
2156 {
2157   /* Adjust excess precision handling based on the target options.  If
2158      the front end cannot handle it, flag_excess_precision_cmdline
2159      will already have been set accordingly in the post_options
2160      hook.  */
2161   gcc_assert (flag_excess_precision_cmdline != EXCESS_PRECISION_DEFAULT);
2162   flag_excess_precision = flag_excess_precision_cmdline;
2163   if (flag_unsafe_math_optimizations)
2164     flag_excess_precision = EXCESS_PRECISION_FAST;
2165   if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
2166     {
2167       int flt_eval_method = TARGET_FLT_EVAL_METHOD;
2168       switch (flt_eval_method)
2169         {
2170         case -1:
2171         case 0:
2172           /* Either the target acts unpredictably (-1) or has all the
2173              operations required not to have excess precision (0).  */
2174           flag_excess_precision = EXCESS_PRECISION_FAST;
2175           break;
2176         case 1:
2177         case 2:
2178           /* In these cases, predictable excess precision makes
2179              sense.  */
2180           break;
2181         default:
2182           /* Any other implementation-defined FLT_EVAL_METHOD values
2183              require the compiler to handle the associated excess
2184              precision rules in excess_precision_type.  */
2185           gcc_unreachable ();
2186         }
2187     }
2188 }
2189
2190 /* Initialize things that are both lang-dependent and target-dependent.
2191    This function can be called more than once if target parameters change.  */
2192 static void
2193 lang_dependent_init_target (void)
2194 {
2195   /* This determines excess precision settings.  */
2196   init_excess_precision ();
2197
2198   /* This creates various _DECL nodes, so needs to be called after the
2199      front end is initialized.  It also depends on the HAVE_xxx macros
2200      generated from the target machine description.  */
2201   init_optabs ();
2202
2203   /* The following initialization functions need to generate rtl, so
2204      provide a dummy function context for them.  */
2205   init_dummy_function_start ();
2206
2207   /* Do the target-specific parts of expr initialization.  */
2208   init_expr_target ();
2209
2210   /* Although the actions of these functions are language-independent,
2211      they use optabs, so we cannot call them from backend_init.  */
2212   init_set_costs ();
2213   ira_init ();
2214
2215   expand_dummy_function_end ();
2216 }
2217
2218 /* Language-dependent initialization.  Returns nonzero on success.  */
2219 static int
2220 lang_dependent_init (const char *name)
2221 {
2222   location_t save_loc = input_location;
2223   if (dump_base_name == 0)
2224     dump_base_name = name && name[0] ? name : "gccdump";
2225
2226   /* Other front-end initialization.  */
2227   input_location = BUILTINS_LOCATION;
2228   if (lang_hooks.init () == 0)
2229     return 0;
2230   input_location = save_loc;
2231
2232   init_asm_output (name);
2233
2234   /* This creates various _DECL nodes, so needs to be called after the
2235      front end is initialized.  */
2236   init_eh ();
2237
2238   /* Do the target-specific parts of the initialization.  */
2239   lang_dependent_init_target ();
2240
2241   /* If dbx symbol table desired, initialize writing it and output the
2242      predefined types.  */
2243   timevar_push (TV_SYMOUT);
2244
2245 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2246   if (dwarf2out_do_frame ())
2247     dwarf2out_frame_init ();
2248 #endif
2249
2250   /* Now we have the correct original filename, we can initialize
2251      debug output.  */
2252   (*debug_hooks->init) (name);
2253
2254   timevar_pop (TV_SYMOUT);
2255
2256   return 1;
2257 }
2258
2259
2260 /* Reinitialize everything when target parameters, such as register usage,
2261    have changed.  */
2262 void
2263 target_reinit (void)
2264 {
2265   /* Reinitialize RTL backend.  */
2266   backend_init_target ();
2267
2268   /* Reinitialize lang-dependent parts.  */
2269   lang_dependent_init_target ();
2270 }
2271
2272 void
2273 dump_memory_report (bool final)
2274 {
2275   ggc_print_statistics ();
2276   stringpool_statistics ();
2277   dump_tree_statistics ();
2278   dump_gimple_statistics ();
2279   dump_rtx_statistics ();
2280   dump_varray_statistics ();
2281   dump_alloc_pool_statistics ();
2282   dump_bitmap_statistics ();
2283   dump_vec_loc_statistics ();
2284   dump_ggc_loc_statistics (final);
2285   dump_alias_stats (stderr);
2286   dump_pta_stats (stderr);
2287 }
2288
2289 /* Clean up: close opened files, etc.  */
2290
2291 static void
2292 finalize (void)
2293 {
2294   /* Close the dump files.  */
2295   if (flag_gen_aux_info)
2296     {
2297       fclose (aux_info_file);
2298       if (errorcount)
2299         unlink (aux_info_file_name);
2300     }
2301
2302   /* Close non-debugging input and output files.  Take special care to note
2303      whether fclose returns an error, since the pages might still be on the
2304      buffer chain while the file is open.  */
2305
2306   if (asm_out_file)
2307     {
2308       if (ferror (asm_out_file) != 0)
2309         fatal_error ("error writing to %s: %m", asm_file_name);
2310       if (fclose (asm_out_file) != 0)
2311         fatal_error ("error closing %s: %m", asm_file_name);
2312     }
2313
2314   statistics_fini ();
2315   finish_optimization_passes ();
2316
2317   ira_finish_once ();
2318
2319   if (mem_report)
2320     dump_memory_report (true);
2321
2322   /* Language-specific end of compilation actions.  */
2323   lang_hooks.finish ();
2324 }
2325
2326 /* Initialize the compiler, and compile the input file.  */
2327 static void
2328 do_compile (void)
2329 {
2330   /* Initialize timing first.  The C front ends read the main file in
2331      the post_options hook, and C++ does file timings.  */
2332   if (time_report || !quiet_flag  || flag_detailed_statistics)
2333     timevar_init ();
2334   timevar_start (TV_TOTAL);
2335
2336   process_options ();
2337
2338   /* Don't do any more if an error has already occurred.  */
2339   if (!errorcount)
2340     {
2341       /* This must be run always, because it is needed to compute the FP
2342          predefined macros, such as __LDBL_MAX__, for targets using non
2343          default FP formats.  */
2344       init_adjust_machine_modes ();
2345
2346       /* Set up the back-end if requested.  */
2347       if (!no_backend)
2348         backend_init ();
2349
2350       /* Language-dependent initialization.  Returns true on success.  */
2351       if (lang_dependent_init (main_input_filename))
2352         compile_file ();
2353
2354       finalize ();
2355     }
2356
2357   /* Stop timing and print the times.  */
2358   timevar_stop (TV_TOTAL);
2359   timevar_print (stderr);
2360 }
2361
2362 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2363    Exit code is FATAL_EXIT_CODE if can't open files or if there were
2364    any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2365
2366    It is not safe to call this function more than once.  */
2367
2368 int
2369 toplev_main (int argc, char **argv)
2370 {
2371   expandargv (&argc, &argv);
2372
2373   save_argv = CONST_CAST2 (const char **, char **, argv);
2374
2375   /* Initialization of GCC's environment, and diagnostics.  */
2376   general_init (argv[0]);
2377
2378   /* Parse the options and do minimal processing; basically just
2379      enough to default flags appropriately.  */
2380   decode_options (argc, CONST_CAST2 (const char **, char **, argv));
2381
2382   init_local_tick ();
2383
2384   initialize_plugins ();
2385
2386   if (version_flag)
2387     print_version (stderr, "");
2388
2389   if (help_flag)
2390     print_plugins_help (stderr, "");
2391
2392   /* Exit early if we can (e.g. -help).  */
2393   if (!exit_after_options)
2394     do_compile ();
2395
2396   if (warningcount || errorcount) 
2397     print_ignored_options ();
2398
2399   /* Invoke registered plugin callbacks if any.  */
2400   invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
2401
2402   finalize_plugins ();
2403   if (errorcount || sorrycount)
2404     return (FATAL_EXIT_CODE);
2405
2406   return (SUCCESS_EXIT_CODE);
2407 }