OSDN Git Service

fa8af755fdbe508567ebd5730fee4e26aeef8d63
[pf3gnuchains/gcc-fork.git] / gcc / toplev.c
1 /* Top level of GNU C compiler
2    Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3    1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
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 <signal.h>
32 #include <setjmp.h>
33
34 #ifdef HAVE_SYS_RESOURCE_H
35 # include <sys/resource.h>
36 #endif
37
38 #ifdef HAVE_SYS_TIMES_H
39 # include <sys/times.h>
40 #endif
41
42 #include "input.h"
43 #include "tree.h"
44 #include "rtl.h"
45 #include "tm_p.h"
46 #include "flags.h"
47 #include "insn-attr.h"
48 #include "insn-config.h"
49 #include "insn-flags.h"
50 #include "hard-reg-set.h"
51 #include "recog.h"
52 #include "output.h"
53 #include "except.h"
54 #include "function.h"
55 #include "toplev.h"
56 #include "expr.h"
57 #include "basic-block.h"
58 #include "intl.h"
59 #include "ggc.h"
60 #include "graph.h"
61 #include "loop.h"
62 #include "regs.h"
63 #include "timevar.h"
64 #include "diagnostic.h"
65 #include "ssa.h"
66 #include "params.h"
67 #include "reload.h"
68 #include "dwarf2asm.h"
69 #include "integrate.h"
70 #include "debug.h"
71 #include "target.h"
72 #include "langhooks.h"
73
74 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
75 #include "dwarf2out.h"
76 #endif
77
78 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
79 #include "dbxout.h"
80 #endif
81
82 #ifdef SDB_DEBUGGING_INFO
83 #include "sdbout.h"
84 #endif
85
86 #ifdef XCOFF_DEBUGGING_INFO
87 #include "xcoffout.h"           /* Needed for external data
88                                    declarations for e.g. AIX 4.x.  */
89 #endif
90
91 #ifdef HALF_PIC_DEBUG
92 #include "halfpic.h"
93 #endif
94 \f
95 /* Carry information from ASM_DECLARE_OBJECT_NAME
96    to ASM_FINISH_DECLARE_OBJECT.  */
97
98 extern int size_directive_output;
99 extern tree last_assemble_variable_decl;
100
101 static void general_init PARAMS ((char *));
102 static void parse_options_and_default_flags PARAMS ((int, char **));
103 static void do_compile PARAMS ((void));
104 static void process_options PARAMS ((void));
105 static void lang_independent_init PARAMS ((void));
106 static int lang_dependent_init PARAMS ((const char *));
107 static void init_asm_output PARAMS ((const char *));
108 static void finalize PARAMS ((void));
109
110 static void set_target_switch PARAMS ((const char *));
111 static const char *decl_name PARAMS ((tree, int));
112
113 static void float_signal PARAMS ((int)) ATTRIBUTE_NORETURN;
114 static void crash_signal PARAMS ((int)) ATTRIBUTE_NORETURN;
115 static void set_float_handler PARAMS ((jmp_buf));
116 static void compile_file PARAMS ((void));
117 static void display_help PARAMS ((void));
118 static void display_target_options PARAMS ((void));
119
120 static void decode_d_option PARAMS ((const char *));
121 static int decode_f_option PARAMS ((const char *));
122 static int decode_W_option PARAMS ((const char *));
123 static int decode_g_option PARAMS ((const char *));
124 static unsigned int independent_decode_option PARAMS ((int, char **));
125
126 static void print_version PARAMS ((FILE *, const char *));
127 static int print_single_switch PARAMS ((FILE *, int, int, const char *,
128                                       const char *, const char *,
129                                       const char *, const char *));
130 static void print_switch_values PARAMS ((FILE *, int, int, const char *,
131                                        const char *, const char *));
132
133 /* Length of line when printing switch values.  */
134 #define MAX_LINE 75
135
136 /* Name of program invoked, sans directories.  */
137
138 const char *progname;
139
140 /* Copy of arguments to toplev_main.  */
141 int save_argc;
142 char **save_argv;
143 \f
144 /* Name of current original source file (what was input to cpp).
145    This comes from each #-command in the actual input.  */
146
147 const char *input_filename;
148
149 /* Name of top-level original source file (what was input to cpp).
150    This comes from the #-command at the beginning of the actual input.
151    If there isn't any there, then this is the cc1 input file name.  */
152
153 const char *main_input_filename;
154
155 /* Current line number in real source file.  */
156
157 int lineno;
158
159 /* Nonzero if it is unsafe to create any new pseudo registers.  */
160 int no_new_pseudos;
161
162 /* Stack of currently pending input files.  */
163
164 struct file_stack *input_file_stack;
165
166 /* Incremented on each change to input_file_stack.  */
167 int input_file_stack_tick;
168
169 /* Name to use as base of names for dump output files.  */
170
171 const char *dump_base_name;
172
173 /* Format to use to print dumpfile index value */
174 #ifndef DUMPFILE_FORMAT
175 #define DUMPFILE_FORMAT ".%02d."
176 #endif
177
178 /* Bit flags that specify the machine subtype we are compiling for.
179    Bits are tested using macros TARGET_... defined in the tm.h file
180    and set by `-m...' switches.  Must be defined in rtlanal.c.  */
181
182 extern int target_flags;
183
184 /* Debug hooks - dependent upon command line options.  */
185
186 const struct gcc_debug_hooks *debug_hooks = &do_nothing_debug_hooks;
187
188 /* Describes a dump file.  */
189
190 struct dump_file_info
191 {
192   /* The unique extension to apply, e.g. ".jump".  */
193   const char *const extension;
194
195   /* The -d<c> character that enables this dump file.  */
196   char const debug_switch;
197
198   /* True if there is a corresponding graph dump file.  */
199   char const graph_dump_p;
200
201   /* True if the user selected this dump.  */
202   char enabled;
203
204   /* True if the files have been initialized (ie truncated).  */
205   char initialized;
206 };
207
208 /* Enumerate the extant dump files.  */
209
210 enum dump_file_index
211 {
212   DFI_rtl,
213   DFI_sibling,
214   DFI_eh,
215   DFI_jump,
216   DFI_ssa,
217   DFI_ssa_ccp,
218   DFI_ssa_dce,
219   DFI_ussa,
220   DFI_null,
221   DFI_cse,
222   DFI_addressof,
223   DFI_gcse,
224   DFI_loop,
225   DFI_cfg,
226   DFI_bp,
227   DFI_cse2,
228   DFI_life,
229   DFI_combine,
230   DFI_ce,
231   DFI_regmove,
232   DFI_sched,
233   DFI_lreg,
234   DFI_greg,
235   DFI_postreload,
236   DFI_flow2,
237   DFI_peephole2,
238   DFI_rnreg,
239   DFI_ce2,
240   DFI_sched2,
241   DFI_stack,
242   DFI_bbro,
243   DFI_mach,
244   DFI_dbr,
245   DFI_MAX
246 };
247
248 /* Describes all the dump files.  Should be kept in order of the
249    pass and in sync with dump_file_index above.
250
251    Remaining -d letters:
252
253         "              o q         "
254         "       H JK   OPQ  TUV  YZ"
255 */
256
257 static struct dump_file_info dump_file[DFI_MAX] =
258 {
259   { "rtl",      'r', 0, 0, 0 },
260   { "sibling",  'i', 0, 0, 0 },
261   { "eh",       'h', 0, 0, 0 },
262   { "jump",     'j', 0, 0, 0 },
263   { "ssa",      'e', 1, 0, 0 },
264   { "ssaccp",   'W', 1, 0, 0 },
265   { "ssadce",   'X', 1, 0, 0 },
266   { "ussa",     'e', 1, 0, 0 }, /* Yes, duplicate enable switch.  */
267   { "null",     'u', 0, 0, 0 },
268   { "cse",      's', 0, 0, 0 },
269   { "addressof", 'F', 0, 0, 0 },
270   { "gcse",     'G', 1, 0, 0 },
271   { "loop",     'L', 1, 0, 0 },
272   { "cfg",      'f', 1, 0, 0 },
273   { "bp",       'b', 1, 0, 0 },
274   { "cse2",     't', 1, 0, 0 },
275   { "life",     'f', 1, 0, 0 }, /* Yes, duplicate enable switch.  */
276   { "combine",  'c', 1, 0, 0 },
277   { "ce",       'C', 1, 0, 0 },
278   { "regmove",  'N', 1, 0, 0 },
279   { "sched",    'S', 1, 0, 0 },
280   { "lreg",     'l', 1, 0, 0 },
281   { "greg",     'g', 1, 0, 0 },
282   { "postreload", 'o', 1, 0, 0 },
283   { "flow2",    'w', 1, 0, 0 },
284   { "peephole2", 'z', 1, 0, 0 },
285   { "rnreg",    'n', 1, 0, 0 },
286   { "ce2",      'E', 1, 0, 0 },
287   { "sched2",   'R', 1, 0, 0 },
288   { "stack",    'k', 1, 0, 0 },
289   { "bbro",     'B', 1, 0, 0 },
290   { "mach",     'M', 1, 0, 0 },
291   { "dbr",      'd', 0, 0, 0 },
292 };
293
294 static int open_dump_file PARAMS ((enum dump_file_index, tree));
295 static void close_dump_file PARAMS ((enum dump_file_index,
296                                      void (*) (FILE *, rtx), rtx));
297
298 /* Other flags saying which kinds of debugging dump have been requested.  */
299
300 int rtl_dump_and_exit;
301 int flag_print_asm_name;
302 static int version_flag;
303 static char *filename;
304 enum graph_dump_types graph_dump_format;
305
306 /* Name for output file of assembly code, specified with -o.  */
307
308 char *asm_file_name;
309
310 /* Value of the -G xx switch, and whether it was passed or not.  */
311 int g_switch_value;
312 int g_switch_set;
313
314 /* Type(s) of debugging information we are producing (if any).
315    See flags.h for the definitions of the different possible
316    types of debugging information.  */
317 enum debug_info_type write_symbols = NO_DEBUG;
318
319 /* Level of debugging information we are producing.  See flags.h
320    for the definitions of the different possible levels.  */
321 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
322
323 /* Nonzero means use GNU-only extensions in the generated symbolic
324    debugging information.  */
325 /* Currently, this only has an effect when write_symbols is set to
326    DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG.  */
327 int use_gnu_debug_info_extensions = 0;
328
329 /* Nonzero means do optimizations.  -O.
330    Particular numeric values stand for particular amounts of optimization;
331    thus, -O2 stores 2 here.  However, the optimizations beyond the basic
332    ones are not controlled directly by this variable.  Instead, they are
333    controlled by individual `flag_...' variables that are defaulted
334    based on this variable.  */
335
336 int optimize = 0;
337
338 /* Nonzero means optimize for size.  -Os.
339    The only valid values are zero and non-zero. When optimize_size is
340    non-zero, optimize defaults to 2, but certain individual code
341    bloating optimizations are disabled.  */
342
343 int optimize_size = 0;
344
345 /* Nonzero if we should exit after parsing options.  */
346 static int exit_after_options = 0;
347
348 /* The FUNCTION_DECL for the function currently being compiled,
349    or 0 if between functions.  */
350 tree current_function_decl;
351
352 /* Set to the FUNC_BEGIN label of the current function, or NULL_TREE
353    if none.  */
354 tree current_function_func_begin_label;
355
356 /* Pointer to function to compute the name to use to print a declaration.
357    DECL is the declaration in question.
358    VERBOSITY determines what information will be printed:
359      0: DECL_NAME, demangled as necessary.
360      1: and scope information.
361      2: and any other information that might be interesting, such as function
362         parameter types in C++.  */
363
364 const char *(*decl_printable_name)      PARAMS ((tree, int));
365
366 /* Pointer to function to compute rtl for a language-specific tree code.  */
367
368 typedef rtx (*lang_expand_expr_t)
369   PARAMS ((union tree_node *, rtx, enum machine_mode,
370           enum expand_modifier modifier));
371
372 lang_expand_expr_t lang_expand_expr = 0;
373
374 /* Pointer to function to finish handling an incomplete decl at the
375    end of compilation.  */
376
377 void (*incomplete_decl_finalize_hook) PARAMS ((tree)) = 0;
378
379 /* Nonzero if doing dwarf2 duplicate elimination.  */
380
381 int flag_eliminate_dwarf2_dups = 0;
382
383 /* Nonzero if generating code to do profiling.  */
384
385 int profile_flag = 0;
386
387 /* Nonzero if generating code to profile program flow graph arcs.  */
388
389 int profile_arc_flag = 0;
390
391 /* Nonzero if generating info for gcov to calculate line test coverage.  */
392
393 int flag_test_coverage = 0;
394
395 /* Nonzero indicates that branch taken probabilities should be calculated.  */
396
397 int flag_branch_probabilities = 0;
398
399 /* Nonzero if basic blocks should be reordered.  */
400
401 int flag_reorder_blocks = 0;
402
403 /* Nonzero if registers should be renamed.  */
404
405 int flag_rename_registers = 0;
406 int flag_cprop_registers = 0;
407
408 /* Nonzero for -pedantic switch: warn about anything
409    that standard spec forbids.  */
410
411 int pedantic = 0;
412
413 /* Temporarily suppress certain warnings.
414    This is set while reading code from a system header file.  */
415
416 int in_system_header = 0;
417
418 /* Don't print functions as they are compiled.  -quiet.  */
419
420 int quiet_flag = 0;
421
422 /* Print times taken by the various passes.  -ftime-report.  */
423
424 int time_report = 0;
425
426 /* Print memory still in use at end of compilation (which may have little
427    to do with peak memory consumption).  -fmem-report.  */
428
429 int mem_report = 0;
430
431 /* Non-zero means to collect statistics which might be expensive
432    and to print them when we are done.  */
433 int flag_detailed_statistics = 0;
434
435 \f
436 /* -f flags.  */
437
438 /* Nonzero means `char' should be signed.  */
439
440 int flag_signed_char;
441
442 /* Nonzero means give an enum type only as many bytes as it needs.  */
443
444 int flag_short_enums;
445
446 /* Nonzero for -fcaller-saves: allocate values in regs that need to
447    be saved across function calls, if that produces overall better code.
448    Optional now, so people can test it.  */
449
450 #ifdef DEFAULT_CALLER_SAVES
451 int flag_caller_saves = 1;
452 #else
453 int flag_caller_saves = 0;
454 #endif
455
456 /* Nonzero if structures and unions should be returned in memory.
457
458    This should only be defined if compatibility with another compiler or
459    with an ABI is needed, because it results in slower code.  */
460
461 #ifndef DEFAULT_PCC_STRUCT_RETURN
462 #define DEFAULT_PCC_STRUCT_RETURN 1
463 #endif
464
465 /* Nonzero for -fpcc-struct-return: return values the same way PCC does.  */
466
467 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
468
469 /* Nonzero for -fforce-mem: load memory value into a register
470    before arithmetic on it.  This makes better cse but slower compilation.  */
471
472 int flag_force_mem = 0;
473
474 /* Nonzero for -fforce-addr: load memory address into a register before
475    reference to memory.  This makes better cse but slower compilation.  */
476
477 int flag_force_addr = 0;
478
479 /* Nonzero for -fdefer-pop: don't pop args after each function call;
480    instead save them up to pop many calls' args with one insns.  */
481
482 int flag_defer_pop = 0;
483
484 /* Nonzero for -ffloat-store: don't allocate floats and doubles
485    in extended-precision registers.  */
486
487 int flag_float_store = 0;
488
489 /* Nonzero for -fcse-follow-jumps:
490    have cse follow jumps to do a more extensive job.  */
491
492 int flag_cse_follow_jumps;
493
494 /* Nonzero for -fcse-skip-blocks:
495    have cse follow a branch around a block.  */
496 int flag_cse_skip_blocks;
497
498 /* Nonzero for -fexpensive-optimizations:
499    perform miscellaneous relatively-expensive optimizations.  */
500 int flag_expensive_optimizations;
501
502 /* Nonzero for -fthread-jumps:
503    have jump optimize output of loop.  */
504
505 int flag_thread_jumps;
506
507 /* Nonzero enables strength-reduction in loop.c.  */
508
509 int flag_strength_reduce = 0;
510
511 /* Nonzero enables loop unrolling in unroll.c.  Only loops for which the
512    number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
513    UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
514    unrolled.  */
515
516 int flag_unroll_loops;
517
518 /* Nonzero enables loop unrolling in unroll.c.  All loops are unrolled.
519    This is generally not a win.  */
520
521 int flag_unroll_all_loops;
522
523 /* Nonzero enables prefetch optimizations for arrays in loops.  */
524
525 int flag_prefetch_loop_arrays;
526
527 /* Nonzero forces all invariant computations in loops to be moved
528    outside the loop.  */
529
530 int flag_move_all_movables = 0;
531
532 /* Nonzero forces all general induction variables in loops to be
533    strength reduced.  */
534
535 int flag_reduce_all_givs = 0;
536
537 /* Nonzero to perform full register move optimization passes.  This is the
538    default for -O2.  */
539
540 int flag_regmove = 0;
541
542 /* Nonzero for -fwritable-strings:
543    store string constants in data segment and don't uniquize them.  */
544
545 int flag_writable_strings = 0;
546
547 /* Nonzero means don't put addresses of constant functions in registers.
548    Used for compiling the Unix kernel, where strange substitutions are
549    done on the assembly output.  */
550
551 int flag_no_function_cse = 0;
552
553 /* Nonzero for -fomit-frame-pointer:
554    don't make a frame pointer in simple functions that don't require one.  */
555
556 int flag_omit_frame_pointer = 0;
557
558 /* Nonzero means place each function into its own section on those platforms
559    which support arbitrary section names and unlimited numbers of sections.  */
560
561 int flag_function_sections = 0;
562
563 /* ... and similar for data.  */
564
565 int flag_data_sections = 0;
566
567 /* Nonzero to inhibit use of define_optimization peephole opts.  */
568
569 int flag_no_peephole = 0;
570
571 /* Nonzero allows GCC to optimize sibling and tail recursive calls.  */
572
573 int flag_optimize_sibling_calls = 0;
574
575 /* Nonzero means the front end generally wants `errno' maintained by math
576    operations, like built-in SQRT.  */
577
578 int flag_errno_math = 1;
579
580 /* Nonzero means that unsafe floating-point math optimizations are allowed
581    for the sake of speed.  IEEE compliance is not guaranteed, and operations
582    are allowed to assume that their arguments and results are "normal"
583    (e.g., nonnegative for SQRT).  */
584
585 int flag_unsafe_math_optimizations = 0;
586
587 /* Zero means that floating-point math operations cannot generate a
588    (user-visible) trap.  This is the case, for example, in nonstop
589    IEEE 754 arithmetic.  */
590
591 int flag_trapping_math = 1;
592
593 /* 0 means straightforward implementation of complex divide acceptable.
594    1 means wide ranges of inputs must work for complex divide.
595    2 means C99-like requirements for complex divide (not yet implemented).  */
596
597 int flag_complex_divide_method = 0;
598
599 /* Nonzero means all references through pointers are volatile.  */
600
601 int flag_volatile;
602
603 /* Nonzero means treat all global and extern variables as volatile.  */
604
605 int flag_volatile_global;
606
607 /* Nonzero means treat all static variables as volatile.  */
608
609 int flag_volatile_static;
610
611 /* Nonzero means just do syntax checking; don't output anything.  */
612
613 int flag_syntax_only = 0;
614
615 /* Nonzero means perform global cse.  */
616
617 static int flag_gcse;
618
619 /* Nonzero means to use global dataflow analysis to eliminate
620    useless null pointer tests.  */
621
622 static int flag_delete_null_pointer_checks;
623
624 /* Nonzero means to do the enhanced load motion during gcse, which trys
625    to hoist loads by not killing them when a store to the same location
626    is seen.  */
627
628 int flag_gcse_lm = 1;
629
630 /* Nonzero means to perform store motion after gcse, which will try to
631    move stores closer to the exit block.  Its not very effective without
632    flag_gcse_lm.  */
633
634 int flag_gcse_sm = 1;
635
636 /* Nonzero means to rerun cse after loop optimization.  This increases
637    compilation time about 20% and picks up a few more common expressions.  */
638
639 static int flag_rerun_cse_after_loop;
640
641 /* Nonzero means to run loop optimizations twice.  */
642
643 int flag_rerun_loop_opt;
644
645 /* Nonzero for -finline-functions: ok to inline functions that look like
646    good inline candidates.  */
647
648 int flag_inline_functions;
649
650 /* Nonzero for -fkeep-inline-functions: even if we make a function
651    go inline everywhere, keep its definition around for debugging
652    purposes.  */
653
654 int flag_keep_inline_functions;
655
656 /* Nonzero means that functions will not be inlined.  */
657
658 int flag_no_inline;
659
660 /* Nonzero means that we should emit static const variables
661    regardless of whether or not optimization is turned on.  */
662
663 int flag_keep_static_consts = 1;
664
665 /* Nonzero means we should be saving declaration info into a .X file.  */
666
667 int flag_gen_aux_info = 0;
668
669 /* Specified name of aux-info file.  */
670
671 static char *aux_info_file_name;
672
673 /* Nonzero means make the text shared if supported.  */
674
675 int flag_shared_data;
676
677 /* Nonzero means schedule into delayed branch slots if supported.  */
678
679 int flag_delayed_branch;
680
681 /* Nonzero if we are compiling pure (sharable) code.
682    Value is 1 if we are doing reasonable (i.e. simple
683    offset into offset table) pic.  Value is 2 if we can
684    only perform register offsets.  */
685
686 int flag_pic;
687
688 /* Nonzero means generate extra code for exception handling and enable
689    exception handling.  */
690
691 int flag_exceptions;
692
693 /* Nonzero means generate frame unwind info table when supported.  */
694
695 int flag_unwind_tables = 0;
696
697 /* Nonzero means generate frame unwind info table exact at each insn boundary */
698
699 int flag_asynchronous_unwind_tables = 0;
700
701 /* Nonzero means don't place uninitialized global data in common storage
702    by default.  */
703
704 int flag_no_common;
705
706 /* Nonzero means change certain warnings into errors.
707    Usually these are warnings about failure to conform to some standard.  */
708
709 int flag_pedantic_errors = 0;
710
711 /* flag_schedule_insns means schedule insns within basic blocks (before
712    local_alloc).
713    flag_schedule_insns_after_reload means schedule insns after
714    global_alloc.  */
715
716 int flag_schedule_insns = 0;
717 int flag_schedule_insns_after_reload = 0;
718
719 /* The following flags have effect only for scheduling before register
720    allocation:
721
722    flag_schedule_interblock means schedule insns accross basic blocks.
723    flag_schedule_speculative means allow speculative motion of non-load insns.
724    flag_schedule_speculative_load means allow speculative motion of some
725    load insns.
726    flag_schedule_speculative_load_dangerous allows speculative motion of more
727    load insns.  */
728
729 int flag_schedule_interblock = 1;
730 int flag_schedule_speculative = 1;
731 int flag_schedule_speculative_load = 0;
732 int flag_schedule_speculative_load_dangerous = 0;
733
734 int flag_single_precision_constant;
735
736 /* flag_branch_on_count_reg means try to replace add-1,compare,branch tupple
737    by a cheaper branch on a count register.  */
738 int flag_branch_on_count_reg = 1;
739
740 /* -finhibit-size-directive inhibits output of .size for ELF.
741    This is used only for compiling crtstuff.c,
742    and it may be extended to other effects
743    needed for crtstuff.c on other systems.  */
744 int flag_inhibit_size_directive = 0;
745
746 /* -fverbose-asm causes extra commentary information to be produced in
747    the generated assembly code (to make it more readable).  This option
748    is generally only of use to those who actually need to read the
749    generated assembly code (perhaps while debugging the compiler itself).
750    -fno-verbose-asm, the default, causes the extra information
751    to be omitted and is useful when comparing two assembler files.  */
752
753 int flag_verbose_asm = 0;
754
755 /* -dA causes debug commentary information to be produced in
756    the generated assembly code (to make it more readable).  This option
757    is generally only of use to those who actually need to read the
758    generated assembly code (perhaps while debugging the compiler itself).
759    Currently, this switch is only used by dwarfout.c; however, it is intended
760    to be a catchall for printing debug information in the assembler file.  */
761
762 int flag_debug_asm = 0;
763
764 /* -dP causes the rtl to be emitted as a comment in assembly.  */
765
766 int flag_dump_rtl_in_asm = 0;
767
768 /* -fgnu-linker specifies use of the GNU linker for initializations.
769    (Or, more generally, a linker that handles initializations.)
770    -fno-gnu-linker says that collect2 will be used.  */
771 #ifdef USE_COLLECT2
772 int flag_gnu_linker = 0;
773 #else
774 int flag_gnu_linker = 1;
775 #endif
776
777 /* Nonzero means put zero initialized data in the bss section.  */
778 int flag_zero_initialized_in_bss = 1;
779
780 /* Enable SSA.  */
781 int flag_ssa = 0;
782
783 /* Enable ssa conditional constant propagation.  */
784 int flag_ssa_ccp = 0;
785
786 /* Enable ssa aggressive dead code elimination.  */
787 int flag_ssa_dce = 0;
788
789 /* Tag all structures with __attribute__(packed).  */
790 int flag_pack_struct = 0;
791
792 /* Emit code to check for stack overflow; also may cause large objects
793    to be allocated dynamically.  */
794 int flag_stack_check;
795
796 /* When non-NULL, indicates that whenever space is allocated on the
797    stack, the resulting stack pointer must not pass this
798    address---that is, for stacks that grow downward, the stack pointer
799    must always be greater than or equal to this address; for stacks
800    that grow upward, the stack pointer must be less than this address.
801    At present, the rtx may be either a REG or a SYMBOL_REF, although
802    the support provided depends on the backend.  */
803 rtx stack_limit_rtx;
804
805 /* 0 if pointer arguments may alias each other.  True in C.
806    1 if pointer arguments may not alias each other but may alias
807    global variables.
808    2 if pointer arguments may not alias each other and may not
809    alias global variables.  True in Fortran.
810    This defaults to 0 for C.  */
811 int flag_argument_noalias = 0;
812
813 /* Nonzero if we should do (language-dependent) alias analysis.
814    Typically, this analysis will assume that expressions of certain
815    types do not alias expressions of certain other types.  Only used
816    if alias analysis (in general) is enabled.  */
817 int flag_strict_aliasing = 0;
818
819 /* Instrument functions with calls at entry and exit, for profiling.  */
820 int flag_instrument_function_entry_exit = 0;
821
822 /* Nonzero means ignore `#ident' directives.  0 means handle them.
823    On SVR4 targets, it also controls whether or not to emit a
824    string identifying the compiler.  */
825
826 int flag_no_ident = 0;
827
828 /* This will perform a peephole pass before sched2.  */
829 int flag_peephole2 = 0;
830
831 /* This will try to guess branch probabilities.  */
832 int flag_guess_branch_prob = 0;
833
834 /* -fbounded-pointers causes gcc to compile pointers as composite
835    objects occupying three words: the pointer value, the base address
836    of the referent object, and the address immediately beyond the end
837    of the referent object.  The base and extent allow us to perform
838    runtime bounds checking.  -fbounded-pointers implies -fcheck-bounds.  */
839 int flag_bounded_pointers = 0;
840
841 /* -fcheck-bounds causes gcc to generate array bounds checks.
842    For C, C++: defaults to value of flag_bounded_pointers.
843    For ObjC: defaults to off.
844    For Java: defaults to on.
845    For Fortran: defaults to off.
846    For CHILL: defaults to off.  */
847 int flag_bounds_check = 0;
848
849 /* This will attempt to merge constant section constants, if 1 only
850    string constants and constants from constant pool, if 2 also constant
851    variables.  */
852 int flag_merge_constants = 1;
853
854 /* If one, renumber instruction UIDs to reduce the number of
855    unused UIDs if there are a lot of instructions.  If greater than
856    one, unconditionally renumber instruction UIDs.  */
857 int flag_renumber_insns = 1;
858
859 /* Values of the -falign-* flags: how much to align labels in code.
860    0 means `use default', 1 means `don't align'.
861    For each variable, there is an _log variant which is the power
862    of two not less than the variable, for .align output.  */
863
864 int align_loops;
865 int align_loops_log;
866 int align_loops_max_skip;
867 int align_jumps;
868 int align_jumps_log;
869 int align_jumps_max_skip;
870 int align_labels;
871 int align_labels_log;
872 int align_labels_max_skip;
873 int align_functions;
874 int align_functions_log;
875
876 /* Table of supported debugging formats.  */
877 static const struct
878 {
879   const char *const arg;
880   /* Since PREFERRED_DEBUGGING_TYPE isn't necessarily a
881      constant expression, we use NO_DEBUG in its place.  */
882   const enum debug_info_type debug_type;
883   const int use_extensions_p;
884   const char *const description;
885 } *da,
886 debug_args[] =
887 {
888   { "",       NO_DEBUG, DEFAULT_GDB_EXTENSIONS,
889     N_("Generate debugging info in default format") },
890   { "gdb",    NO_DEBUG, 1, N_("Generate debugging info in default extended format") },
891 #ifdef DBX_DEBUGGING_INFO
892   { "stabs",  DBX_DEBUG, 0, N_("Generate STABS format debug info") },
893   { "stabs+", DBX_DEBUG, 1, N_("Generate extended STABS format debug info") },
894 #endif
895 #ifdef DWARF_DEBUGGING_INFO
896   { "dwarf",  DWARF_DEBUG, 0, N_("Generate DWARF-1 format debug info") },
897   { "dwarf+", DWARF_DEBUG, 1,
898     N_("Generate extended DWARF-1 format debug info") },
899 #endif
900 #ifdef DWARF2_DEBUGGING_INFO
901   { "dwarf-2", DWARF2_DEBUG, 0, N_("Generate DWARF-2 debug info") },
902 #endif
903 #ifdef XCOFF_DEBUGGING_INFO
904   { "xcoff",  XCOFF_DEBUG, 0, N_("Generate XCOFF format debug info") },
905   { "xcoff+", XCOFF_DEBUG, 1, N_("Generate extended XCOFF format debug info") },
906 #endif
907 #ifdef SDB_DEBUGGING_INFO
908   { "coff", SDB_DEBUG, 0, N_("Generate COFF format debug info") },
909 #endif
910 #ifdef VMS_DEBUGGING_INFO
911   { "vms", VMS_DEBUG, 0, N_("Generate VMS format debug info") },
912 #endif
913   { 0, 0, 0, 0 }
914 };
915
916 typedef struct
917 {
918   const char *const string;
919   int *const variable;
920   const int on_value;
921   const char *const description;
922 }
923 lang_independent_options;
924
925 int flag_trapv = 0;
926
927 /* Add or remove a leading underscore from user symbols.  */
928 int flag_leading_underscore = -1;
929
930 /* The user symbol prefix after having resolved same.  */
931 const char *user_label_prefix;
932
933 static const param_info lang_independent_params[] = {
934 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT) \
935   { OPTION, DEFAULT, HELP },
936 #include "params.def"
937 #undef DEFPARAM
938   { NULL, 0, NULL }
939 };
940
941 /* A default for same.  */
942 #ifndef USER_LABEL_PREFIX
943 #define USER_LABEL_PREFIX ""
944 #endif
945
946 /* Table of language-independent -f options.
947    STRING is the option name.  VARIABLE is the address of the variable.
948    ON_VALUE is the value to store in VARIABLE
949     if `-fSTRING' is seen as an option.
950    (If `-fno-STRING' is seen as an option, the opposite value is stored.)  */
951
952 static const lang_independent_options f_options[] =
953 {
954   {"eliminate-dwarf2-dups", &flag_eliminate_dwarf2_dups, 1,
955    N_("Perform DWARF2 duplicate elimination") },
956   {"float-store", &flag_float_store, 1,
957    N_("Do not store floats in registers") },
958   {"volatile", &flag_volatile, 1,
959    N_("Consider all mem refs through pointers as volatile") },
960   {"volatile-global", &flag_volatile_global, 1,
961    N_("Consider all mem refs to global data to be volatile") },
962   {"volatile-static", &flag_volatile_static, 1,
963    N_("Consider all mem refs to static data to be volatile") },
964   {"defer-pop", &flag_defer_pop, 1,
965    N_("Defer popping functions args from stack until later") },
966   {"omit-frame-pointer", &flag_omit_frame_pointer, 1,
967    N_("When possible do not generate stack frames") },
968   {"optimize-sibling-calls", &flag_optimize_sibling_calls, 1,
969    N_("Optimize sibling and tail recursive calls") },
970   {"cse-follow-jumps", &flag_cse_follow_jumps, 1,
971    N_("When running CSE, follow jumps to their targets") },
972   {"cse-skip-blocks", &flag_cse_skip_blocks, 1,
973    N_("When running CSE, follow conditional jumps") },
974   {"expensive-optimizations", &flag_expensive_optimizations, 1,
975    N_("Perform a number of minor, expensive optimizations") },
976   {"thread-jumps", &flag_thread_jumps, 1,
977    N_("Perform jump threading optimizations") },
978   {"strength-reduce", &flag_strength_reduce, 1,
979    N_("Perform strength reduction optimizations") },
980   {"unroll-loops", &flag_unroll_loops, 1,
981    N_("Perform loop unrolling when iteration count is known") },
982   {"unroll-all-loops", &flag_unroll_all_loops, 1,
983    N_("Perform loop unrolling for all loops") },
984   {"prefetch-loop-arrays", &flag_prefetch_loop_arrays, 1,
985    N_("Generate prefetch instructions, if available, for arrays in loops") },
986   {"move-all-movables", &flag_move_all_movables, 1,
987    N_("Force all loop invariant computations out of loops") },
988   {"reduce-all-givs", &flag_reduce_all_givs, 1,
989    N_("Strength reduce all loop general induction variables") },
990   {"writable-strings", &flag_writable_strings, 1,
991    N_("Store strings in writable data section") },
992   {"peephole", &flag_no_peephole, 0,
993    N_("Enable machine specific peephole optimizations") },
994   {"force-mem", &flag_force_mem, 1,
995    N_("Copy memory operands into registers before using") },
996   {"force-addr", &flag_force_addr, 1,
997    N_("Copy memory address constants into regs before using") },
998   {"function-cse", &flag_no_function_cse, 0,
999    N_("Allow function addresses to be held in registers") },
1000   {"inline-functions", &flag_inline_functions, 1,
1001    N_("Integrate simple functions into their callers") },
1002   {"keep-inline-functions", &flag_keep_inline_functions, 1,
1003    N_("Generate code for funcs even if they are fully inlined") },
1004   {"inline", &flag_no_inline, 0,
1005    N_("Pay attention to the 'inline' keyword") },
1006   {"keep-static-consts", &flag_keep_static_consts, 1,
1007    N_("Emit static const variables even if they are not used") },
1008   {"syntax-only", &flag_syntax_only, 1,
1009    N_("Check for syntax errors, then stop") },
1010   {"shared-data", &flag_shared_data, 1,
1011    N_("Mark data as shared rather than private") },
1012   {"caller-saves", &flag_caller_saves, 1,
1013    N_("Enable saving registers around function calls") },
1014   {"pcc-struct-return", &flag_pcc_struct_return, 1,
1015    N_("Return 'short' aggregates in memory, not registers") },
1016   {"reg-struct-return", &flag_pcc_struct_return, 0,
1017    N_("Return 'short' aggregates in registers") },
1018   {"delayed-branch", &flag_delayed_branch, 1,
1019    N_("Attempt to fill delay slots of branch instructions") },
1020   {"gcse", &flag_gcse, 1,
1021    N_("Perform the global common subexpression elimination") },
1022   {"gcse-lm", &flag_gcse_lm, 1,
1023    N_("Perform enhanced load motion during global subexpression elimination") },
1024   {"gcse-sm", &flag_gcse_sm, 1,
1025    N_("Perform store motion after global subexpression elimination") },
1026   {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1,
1027    N_("Run CSE pass after loop optimizations") },
1028   {"rerun-loop-opt", &flag_rerun_loop_opt, 1,
1029    N_("Run the loop optimizer twice") },
1030   {"delete-null-pointer-checks", &flag_delete_null_pointer_checks, 1,
1031    N_("Delete useless null pointer checks") },
1032   {"schedule-insns", &flag_schedule_insns, 1,
1033    N_("Reschedule instructions before register allocation") },
1034   {"schedule-insns2", &flag_schedule_insns_after_reload, 1,
1035    N_("Reschedule instructions after register allocation") },
1036   {"sched-interblock",&flag_schedule_interblock, 1,
1037    N_("Enable scheduling across basic blocks") },
1038   {"sched-spec",&flag_schedule_speculative, 1,
1039    N_("Allow speculative motion of non-loads") },
1040   {"sched-spec-load",&flag_schedule_speculative_load, 1,
1041    N_("Allow speculative motion of some loads") },
1042   {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1,
1043    N_("Allow speculative motion of more loads") },
1044   {"branch-count-reg",&flag_branch_on_count_reg, 1,
1045    N_("Replace add,compare,branch with branch on count reg") },
1046   {"pic", &flag_pic, 1,
1047    N_("Generate position independent code, if possible") },
1048   {"PIC", &flag_pic, 2, ""},
1049   {"exceptions", &flag_exceptions, 1,
1050    N_("Enable exception handling") },
1051   {"unwind-tables", &flag_unwind_tables, 1,
1052    N_("Just generate unwind tables for exception handling") },
1053   {"asynchronous-unwind-tables", &flag_asynchronous_unwind_tables, 1,
1054    N_("Generate unwind tables exact at each instruction boundary") },
1055   {"non-call-exceptions", &flag_non_call_exceptions, 1,
1056    N_("Support synchronous non-call exceptions") },
1057   {"profile-arcs", &profile_arc_flag, 1,
1058    N_("Insert arc based program profiling code") },
1059   {"test-coverage", &flag_test_coverage, 1,
1060    N_("Create data files needed by gcov") },
1061   {"branch-probabilities", &flag_branch_probabilities, 1,
1062    N_("Use profiling information for branch probabilities") },
1063   {"reorder-blocks", &flag_reorder_blocks, 1,
1064    N_("Reorder basic blocks to improve code placement") },
1065   {"rename-registers", &flag_rename_registers, 1,
1066    N_("Do the register renaming optimization pass") },
1067   {"cprop-registers", &flag_cprop_registers, 1,
1068    N_("Do the register copy-propagation optimization pass") },
1069   {"common", &flag_no_common, 0,
1070    N_("Do not put uninitialized globals in the common section") },
1071   {"inhibit-size-directive", &flag_inhibit_size_directive, 1,
1072    N_("Do not generate .size directives") },
1073   {"function-sections", &flag_function_sections, 1,
1074    N_("place each function into its own section") },
1075   {"data-sections", &flag_data_sections, 1,
1076    N_("place data items into their own section") },
1077   {"verbose-asm", &flag_verbose_asm, 1,
1078    N_("Add extra commentry to assembler output") },
1079   {"gnu-linker", &flag_gnu_linker, 1,
1080    N_("Output GNU ld formatted global initializers") },
1081   {"regmove", &flag_regmove, 1,
1082    N_("Enables a register move optimization") },
1083   {"optimize-register-move", &flag_regmove, 1,
1084    N_("Do the full regmove optimization pass") },
1085   {"pack-struct", &flag_pack_struct, 1,
1086    N_("Pack structure members together without holes") },
1087   {"stack-check", &flag_stack_check, 1,
1088    N_("Insert stack checking code into the program") },
1089   {"argument-alias", &flag_argument_noalias, 0,
1090    N_("Specify that arguments may alias each other & globals") },
1091   {"argument-noalias", &flag_argument_noalias, 1,
1092    N_("Assume arguments may alias globals but not each other") },
1093   {"argument-noalias-global", &flag_argument_noalias, 2,
1094    N_("Assume arguments do not alias each other or globals") },
1095   {"strict-aliasing", &flag_strict_aliasing, 1,
1096    N_("Assume strict aliasing rules apply") },
1097   {"align-loops", &align_loops, 0,
1098    N_("Align the start of loops") },
1099   {"align-jumps", &align_jumps, 0,
1100    N_("Align labels which are only reached by jumping") },
1101   {"align-labels", &align_labels, 0,
1102    N_("Align all labels") },
1103   {"align-functions", &align_functions, 0,
1104    N_("Align the start of functions") },
1105   {"merge-constants", &flag_merge_constants, 1,
1106    N_("Attempt to merge identical constants accross compilation units") },
1107   {"merge-all-constants", &flag_merge_constants, 2,
1108    N_("Attempt to merge identical constants and constant variables") },
1109   {"dump-unnumbered", &flag_dump_unnumbered, 1,
1110    N_("Suppress output of instruction numbers and line number notes in debugging dumps") },
1111   {"instrument-functions", &flag_instrument_function_entry_exit, 1,
1112    N_("Instrument function entry/exit with profiling calls") },
1113   {"zero-initialized-in-bss", &flag_zero_initialized_in_bss, 1,
1114    N_("Put zero initialized data in the bss section") },
1115   {"ssa", &flag_ssa, 1,
1116    N_("Enable SSA optimizations") },
1117   {"ssa-ccp", &flag_ssa_ccp, 1,
1118    N_("Enable SSA conditional constant propagation") },
1119   {"ssa-dce", &flag_ssa_dce, 1,
1120    N_("Enable aggressive SSA dead code elimination") },
1121   {"leading-underscore", &flag_leading_underscore, 1,
1122    N_("External symbols have a leading underscore") },
1123   {"ident", &flag_no_ident, 0,
1124    N_("Process #ident directives") },
1125   { "peephole2", &flag_peephole2, 1,
1126    N_("Enables an rtl peephole pass run before sched2") },
1127   { "guess-branch-probability", &flag_guess_branch_prob, 1,
1128    N_("Enables guessing of branch probabilities") },
1129   {"math-errno", &flag_errno_math, 1,
1130    N_("Set errno after built-in math functions") },
1131   {"trapping-math", &flag_trapping_math, 1,
1132    N_("Floating-point operations can trap") },
1133   {"unsafe-math-optimizations", &flag_unsafe_math_optimizations, 1,
1134    N_("Allow math optimizations that may violate IEEE or ANSI standards") },
1135   {"bounded-pointers", &flag_bounded_pointers, 1,
1136    N_("Compile pointers as triples: value, base & end") },
1137   {"bounds-check", &flag_bounds_check, 1,
1138    N_("Generate code to check bounds before dereferencing pointers and arrays") },
1139   {"single-precision-constant", &flag_single_precision_constant, 1,
1140    N_("Convert floating point constant to single precision constant") },
1141   {"time-report", &time_report, 1,
1142    N_("Report time taken by each compiler pass at end of run") },
1143   {"mem-report", &mem_report, 1,
1144    N_("Report on permanent memory allocation at end of run") },
1145   { "trapv", &flag_trapv, 1,
1146    N_("Trap for signed overflow in addition / subtraction / multiplication") },
1147 };
1148
1149 /* Table of language-specific options.  */
1150
1151 static const struct lang_opt
1152 {
1153   const char *const option;
1154   const char *const description;
1155 }
1156 documented_lang_options[] =
1157 {
1158   /* In order not to overload the --help output, the convention
1159      used here is to only describe those options which are not
1160      enabled by default.  */
1161
1162   { "-ansi", 
1163     N_("Compile just for ISO C89") },
1164   { "-std= ", 
1165     N_("Determine language standard") },
1166
1167   { "-fsigned-bitfields", "" },
1168   { "-funsigned-bitfields",
1169     N_("Make bit-fields by unsigned by default") },
1170   { "-fno-signed-bitfields", "" },
1171   { "-fno-unsigned-bitfields","" },
1172   { "-fsigned-char", 
1173     N_("Make 'char' be signed by default") },
1174   { "-funsigned-char", 
1175     N_("Make 'char' be unsigned by default") },
1176   { "-fno-signed-char", "" },
1177   { "-fno-unsigned-char", "" },
1178
1179   { "-fasm", "" },
1180   { "-fno-asm", 
1181     N_("Do not recognize the 'asm' keyword") },
1182   { "-fbuiltin", "" },
1183   { "-fno-builtin", 
1184     N_("Do not recognize any built in functions") },
1185   { "-fhosted", 
1186     N_("Assume normal C execution environment") },
1187   { "-fno-hosted", "" },
1188   { "-ffreestanding",
1189     N_("Assume that standard libraries & main might not exist") },
1190   { "-fno-freestanding", "" },
1191   { "-fcond-mismatch", 
1192     N_("Allow different types as args of ? operator") },
1193   { "-fno-cond-mismatch", "" },
1194   { "-fdollars-in-identifiers", 
1195     N_("Allow the use of $ inside identifiers") },
1196   { "-fno-dollars-in-identifiers", "" },
1197   { "-fpreprocessed", "" },
1198   { "-fno-preprocessed", "" },
1199   { "-fshort-double", 
1200     N_("Use the same size for double as for float") },
1201   { "-fno-short-double", "" },
1202   { "-fshort-enums", 
1203     N_("Use the smallest fitting integer to hold enums") },
1204   { "-fno-short-enums", "" },
1205   { "-fshort-wchar", 
1206     N_("Override the underlying type for wchar_t to `unsigned short'") },
1207   { "-fno-short-wchar", "" },
1208
1209   { "-Wall", 
1210     N_("Enable most warning messages") },
1211   { "-Wbad-function-cast",
1212     N_("Warn about casting functions to incompatible types") },
1213   { "-Wno-bad-function-cast", "" },
1214   { "-Wmissing-format-attribute",
1215     N_("Warn about functions which might be candidates for format attributes") },
1216   { "-Wno-missing-format-attribute", "" },
1217   { "-Wcast-qual", 
1218     N_("Warn about casts which discard qualifiers") },
1219   { "-Wno-cast-qual", "" },
1220   { "-Wchar-subscripts", 
1221     N_("Warn about subscripts whose type is 'char'") },
1222   { "-Wno-char-subscripts", "" },
1223   { "-Wcomment", 
1224     N_("Warn if nested comments are detected") },
1225   { "-Wno-comment", "" },
1226   { "-Wcomments", 
1227     N_("Warn if nested comments are detected") },
1228   { "-Wno-comments", "" },
1229   { "-Wconversion", 
1230     N_("Warn about possibly confusing type conversions") },
1231   { "-Wno-conversion", "" },
1232   { "-Wdiv-by-zero", "" },
1233   { "-Wno-div-by-zero", 
1234     N_("Do not warn about compile-time integer division by zero") },
1235   { "-Wfloat-equal", 
1236     N_("Warn about testing equality of floating point numbers") },
1237   { "-Wno-float-equal", "" },
1238   { "-Wformat", 
1239     N_("Warn about printf/scanf/strftime/strfmon format anomalies") },
1240   { "-Wno-format", "" },
1241   { "-Wformat-extra-args", "" },
1242   { "-Wno-format-extra-args",
1243     N_("Don't warn about too many arguments to format functions") },
1244   { "-Wformat-nonliteral", 
1245     N_("Warn about non-string-literal format strings") },
1246   { "-Wno-format-nonliteral", "" },
1247   { "-Wformat-security",
1248     N_("Warn about possible security problems with format functions") },
1249   { "-Wno-format-security", "" },
1250   { "-Wformat-y2k", "" },
1251   { "-Wno-format-y2k",
1252     N_("Don't warn about strftime formats yielding 2 digit years") },
1253   { "-Wimplicit-function-declaration",
1254     N_("Warn about implicit function declarations") },
1255   { "-Wno-implicit-function-declaration", "" },
1256   { "-Werror-implicit-function-declaration", "" },
1257   { "-Wimplicit-int", 
1258     N_("Warn when a declaration does not specify a type") },
1259   { "-Wno-implicit-int", "" },
1260   { "-Wimplicit", "" },
1261   { "-Wno-implicit", "" },
1262   { "-Wimport", 
1263     N_("Warn about the use of the #import directive") },
1264   { "-Wno-import", "" },
1265   { "-Wlong-long","" },
1266   { "-Wno-long-long", 
1267     N_("Do not warn about using 'long long' when -pedantic") },
1268   { "-Wmain", 
1269     N_("Warn about suspicious declarations of main") },
1270   { "-Wno-main", "" },
1271   { "-Wmissing-braces",
1272     N_("Warn about possibly missing braces around initializers") },
1273   { "-Wno-missing-braces", "" },
1274   { "-Wmissing-declarations",
1275     N_("Warn about global funcs without previous declarations") },
1276   { "-Wno-missing-declarations", "" },
1277   { "-Wmissing-prototypes", 
1278     N_("Warn about global funcs without prototypes") },
1279   { "-Wno-missing-prototypes", "" },
1280   { "-Wmultichar", 
1281     N_("Warn about use of multicharacter literals") },
1282   { "-Wno-multichar", "" },
1283   { "-Wnested-externs", 
1284     N_("Warn about externs not at file scope level") },
1285   { "-Wno-nested-externs", "" },
1286   { "-Wparentheses", 
1287     N_("Warn about possible missing parentheses") },
1288   { "-Wno-parentheses", "" },
1289   { "-Wpointer-arith", 
1290     N_("Warn about function pointer arithmetic") },
1291   { "-Wno-pointer-arith", "" },
1292   { "-Wredundant-decls",
1293     N_("Warn about multiple declarations of the same object") },
1294   { "-Wno-redundant-decls", "" },
1295   { "-Wreturn-type",
1296     N_("Warn whenever a function's return-type defaults to int") },
1297   { "-Wno-return-type", "" },
1298   { "-Wsequence-point",
1299     N_("Warn about possible violations of sequence point rules") },
1300   { "-Wno-sequence-point", "" },
1301   { "-Wsign-compare", 
1302     N_("Warn about signed/unsigned comparisons") },
1303   { "-Wno-sign-compare", "" },
1304   { "-Wstrict-prototypes", 
1305     N_("Warn about non-prototyped function decls") },
1306   { "-Wno-strict-prototypes", "" },
1307   { "-Wtraditional", 
1308     N_("Warn about constructs whose meanings change in ISO C") },
1309   { "-Wno-traditional", "" },
1310   { "-Wtrigraphs", 
1311     N_("Warn when trigraphs are encountered") },
1312   { "-Wno-trigraphs", "" },
1313   { "-Wundef", "" },
1314   { "-Wno-undef", "" },
1315   { "-Wunknown-pragmas", 
1316     N_("Warn about unrecognized pragmas") },
1317   { "-Wno-unknown-pragmas", "" },
1318   { "-Wwrite-strings", 
1319     N_("Mark strings as 'const char *'") },
1320   { "-Wno-write-strings", "" },
1321
1322 #define DEFINE_LANG_NAME(NAME) { NULL, NAME },
1323
1324 #include "options.h"
1325
1326 };
1327
1328 /* Here is a table, controlled by the tm.h file, listing each -m switch
1329    and which bits in `target_switches' it should set or clear.
1330    If VALUE is positive, it is bits to set.
1331    If VALUE is negative, -VALUE is bits to clear.
1332    (The sign bit is not used so there is no confusion.)  */
1333
1334 static const struct
1335 {
1336   const char *const name;
1337   const int value;
1338   const char *const description;
1339 }
1340 target_switches [] = TARGET_SWITCHES;
1341
1342 /* This table is similar, but allows the switch to have a value.  */
1343
1344 #ifdef TARGET_OPTIONS
1345 static const struct
1346 {
1347   const char *const prefix;
1348   const char **const variable;
1349   const char *const description;
1350 }
1351 target_options [] = TARGET_OPTIONS;
1352 #endif
1353 \f
1354 /* Options controlling warnings.  */
1355
1356 /* Don't print warning messages.  -w.  */
1357
1358 int inhibit_warnings = 0;
1359
1360 /* Don't suppress warnings from system headers.  -Wsystem-headers.  */
1361
1362 int warn_system_headers = 0;
1363
1364 /* Print various extra warnings.  -W.  */
1365
1366 int extra_warnings = 0;
1367
1368 /* Treat warnings as errors.  -Werror.  */
1369
1370 int warnings_are_errors = 0;
1371
1372 /* Nonzero to warn about unused variables, functions et.al.  */
1373
1374 int warn_unused_function;
1375 int warn_unused_label;
1376 int warn_unused_parameter;
1377 int warn_unused_variable;
1378 int warn_unused_value;
1379
1380 /* Nonzero to warn about code which is never reached.  */
1381
1382 int warn_notreached;
1383
1384 /* Nonzero to warn about variables used before they are initialized.  */
1385
1386 int warn_uninitialized;
1387
1388 /* Nonzero means warn about all declarations which shadow others.  */
1389
1390 int warn_shadow;
1391
1392 /* Warn if a switch on an enum fails to have a case for every enum value.  */
1393
1394 int warn_switch;
1395
1396 /* Nonzero means warn about function definitions that default the return type
1397    or that use a null return and have a return-type other than void.  */
1398
1399 int warn_return_type;
1400
1401 /* Nonzero means warn about pointer casts that increase the required
1402    alignment of the target type (and might therefore lead to a crash
1403    due to a misaligned access).  */
1404
1405 int warn_cast_align;
1406
1407 /* Nonzero means warn about any objects definitions whose size is larger
1408    than N bytes.  Also want about function definitions whose returned
1409    values are larger than N bytes. The value N is in `larger_than_size'.  */
1410
1411 int warn_larger_than;
1412 HOST_WIDE_INT larger_than_size;
1413
1414 /* Nonzero means warn if inline function is too large.  */
1415
1416 int warn_inline;
1417
1418 /* Warn if a function returns an aggregate,
1419    since there are often incompatible calling conventions for doing this.  */
1420
1421 int warn_aggregate_return;
1422
1423 /* Warn if packed attribute on struct is unnecessary and inefficient.  */
1424
1425 int warn_packed;
1426
1427 /* Warn when gcc pads a structure to an alignment boundary.  */
1428
1429 int warn_padded;
1430
1431 /* Warn when an optimization pass is disabled.  */
1432
1433 int warn_disabled_optimization;
1434
1435 /* Warn about functions which might be candidates for attribute noreturn.  */
1436
1437 int warn_missing_noreturn;
1438
1439 /* Nonzero means warn about uses of __attribute__((deprecated)) 
1440    declarations.  */
1441
1442 int warn_deprecated_decl = 1;
1443
1444 /* Likewise for -W.  */
1445
1446 static const lang_independent_options W_options[] =
1447 {
1448   {"unused-function", &warn_unused_function, 1,
1449    N_("Warn when a function is unused") },
1450   {"unused-label", &warn_unused_label, 1,
1451    N_("Warn when a label is unused") },
1452   {"unused-parameter", &warn_unused_parameter, 1,
1453    N_("Warn when a function parameter is unused") },
1454   {"unused-variable", &warn_unused_variable, 1,
1455    N_("Warn when a variable is unused") },
1456   {"unused-value", &warn_unused_value, 1,
1457    N_("Warn when an expression value is unused") },
1458   {"system-headers", &warn_system_headers, 1,
1459    N_("Do not suppress warnings from system headers") },
1460   {"error", &warnings_are_errors, 1,
1461    N_("Treat all warnings as errors") },
1462   {"shadow", &warn_shadow, 1,
1463    N_("Warn when one local variable shadows another") },
1464   {"switch", &warn_switch, 1,
1465    N_("Warn about enumerated switches missing a specific case") },
1466   {"aggregate-return", &warn_aggregate_return, 1,
1467    N_("Warn about returning structures, unions or arrays") },
1468   {"cast-align", &warn_cast_align, 1,
1469    N_("Warn about pointer casts which increase alignment") },
1470   {"unreachable-code", &warn_notreached, 1,
1471    N_("Warn about code that will never be executed") },
1472   {"uninitialized", &warn_uninitialized, 1,
1473    N_("Warn about uninitialized automatic variables") },
1474   {"inline", &warn_inline, 1,
1475    N_("Warn when an inlined function cannot be inlined") },
1476   {"packed", &warn_packed, 1,
1477    N_("Warn when the packed attribute has no effect on struct layout") },
1478   {"padded", &warn_padded, 1,
1479    N_("Warn when padding is required to align struct members") },
1480   {"disabled-optimization", &warn_disabled_optimization, 1,
1481    N_("Warn when an optimization pass is disabled") },
1482   {"deprecated-declarations", &warn_deprecated_decl, 1,
1483    N_("Warn about uses of __attribute__((deprecated)) declarations") },
1484   {"missing-noreturn", &warn_missing_noreturn, 1,
1485    N_("Warn about functions which might be candidates for attribute noreturn") }
1486 };
1487
1488 void
1489 set_Wunused (setting)
1490      int setting;
1491 {
1492   warn_unused_function = setting;
1493   warn_unused_label = setting;
1494   /* Unused function parameter warnings are reported when either ``-W
1495      -Wunused'' or ``-Wunused-parameter'' is specified.  Differentiate
1496      -Wunused by setting WARN_UNUSED_PARAMETER to -1.  */
1497   if (!setting)
1498     warn_unused_parameter = 0;
1499   else if (!warn_unused_parameter)
1500     warn_unused_parameter = -1;
1501   warn_unused_variable = setting;
1502   warn_unused_value = setting;
1503 }
1504
1505 /* The following routines are useful in setting all the flags that
1506    -ffast-math and -fno-fast-math imply.  */
1507
1508 void
1509 set_fast_math_flags ()
1510 {
1511   flag_trapping_math = 0;
1512   flag_unsafe_math_optimizations = 1;
1513   flag_errno_math = 0;
1514 }
1515
1516 void
1517 set_no_fast_math_flags ()
1518 {
1519   flag_trapping_math = 1;
1520   flag_unsafe_math_optimizations = 0;
1521   flag_errno_math = 1;
1522 }
1523
1524 \f
1525 /* Output files for assembler code (real compiler output)
1526    and debugging dumps.  */
1527
1528 FILE *asm_out_file;
1529 FILE *aux_info_file;
1530 FILE *rtl_dump_file = NULL;
1531
1532 /* Decode the string P as an integral parameter.
1533    If the string is indeed an integer return its numeric value else
1534    issue an Invalid Option error for the option PNAME and return DEFVAL.
1535    If PNAME is zero just return DEFVAL, do not call error.  */
1536
1537 int
1538 read_integral_parameter (p, pname, defval)
1539      const char *p;
1540      const char *pname;
1541      const int  defval;
1542 {
1543   const char *endp = p;
1544
1545   while (*endp)
1546     {
1547       if (ISDIGIT (*endp))
1548         endp++;
1549       else
1550         break;
1551     }
1552
1553   if (*endp != 0)
1554     {
1555       if (pname != 0)
1556         error ("invalid option `%s'", pname);
1557       return defval;
1558     }
1559
1560   return atoi (p);
1561 }
1562
1563 \f
1564 /* This is the default decl_printable_name function.  */
1565
1566 static const char *
1567 decl_name (decl, verbosity)
1568      tree decl;
1569      int verbosity ATTRIBUTE_UNUSED;
1570 {
1571   return IDENTIFIER_POINTER (DECL_NAME (decl));
1572 }
1573 \f
1574
1575 /* This calls abort and is used to avoid problems when abort if a macro.
1576    It is used when we need to pass the address of abort.  */
1577
1578 void
1579 do_abort ()
1580 {
1581   abort ();
1582 }
1583
1584 /* When `malloc.c' is compiled with `rcheck' defined,
1585    it calls this function to report clobberage.  */
1586
1587 void
1588 botch (s)
1589      const char *s ATTRIBUTE_UNUSED;
1590 {
1591   abort ();
1592 }
1593 \f
1594 /* Return the logarithm of X, base 2, considering X unsigned,
1595    if X is a power of 2.  Otherwise, returns -1.
1596
1597    This should be used via the `exact_log2' macro.  */
1598
1599 int
1600 exact_log2_wide (x)
1601      unsigned HOST_WIDE_INT x;
1602 {
1603   int log = 0;
1604   /* Test for 0 or a power of 2.  */
1605   if (x == 0 || x != (x & -x))
1606     return -1;
1607   while ((x >>= 1) != 0)
1608     log++;
1609   return log;
1610 }
1611
1612 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1613    If X is 0, return -1.
1614
1615    This should be used via the floor_log2 macro.  */
1616
1617 int
1618 floor_log2_wide (x)
1619      unsigned HOST_WIDE_INT x;
1620 {
1621   int log = -1;
1622   while (x != 0)
1623     log++,
1624     x >>= 1;
1625   return log;
1626 }
1627
1628 static int float_handler_set;
1629 int float_handled;
1630 jmp_buf float_handler;
1631
1632 /* Signals actually come here.  */
1633
1634 static void
1635 float_signal (signo)
1636      /* If this is missing, some compilers complain.  */
1637      int signo ATTRIBUTE_UNUSED;
1638 {
1639   if (float_handled == 0)
1640     crash_signal (signo);
1641   float_handled = 0;
1642
1643   /* On System-V derived systems, we must reinstall the signal handler.
1644      This is harmless on BSD-derived systems.  */
1645   signal (SIGFPE, float_signal);
1646   longjmp (float_handler, 1);
1647 }
1648
1649 /* Specify where to longjmp to when a floating arithmetic error happens.
1650    If HANDLER is 0, it means don't handle the errors any more.  */
1651
1652 static void
1653 set_float_handler (handler)
1654      jmp_buf handler;
1655 {
1656   float_handled = (handler != 0);
1657   if (handler)
1658     memcpy (float_handler, handler, sizeof (float_handler));
1659
1660   if (float_handled && ! float_handler_set)
1661     {
1662       signal (SIGFPE, float_signal);
1663       float_handler_set = 1;
1664     }
1665 }
1666
1667 /* This is a wrapper function for code which might elicit an
1668    arithmetic exception.  That code should be passed in as a function
1669    pointer FN, and one argument DATA.  DATA is usually a struct which
1670    contains the real input and output for function FN.  This function
1671    returns 0 (failure) if longjmp was called (i.e. an exception
1672    occurred.)  It returns 1 (success) otherwise.  */
1673
1674 int
1675 do_float_handler (fn, data)
1676      void (*fn) PARAMS ((PTR));
1677      PTR data;
1678 {
1679   jmp_buf buf;
1680
1681   if (setjmp (buf))
1682     {
1683       /* We got here via longjmp () caused by an exception in function
1684          fn ().  */
1685       set_float_handler (NULL);
1686       return 0;
1687     }
1688
1689   set_float_handler (buf);
1690   (*fn)(data);
1691   set_float_handler (NULL);
1692   return 1;
1693 }
1694
1695 /* Handler for fatal signals, such as SIGSEGV.  These are transformed
1696    into ICE messages, which is much more user friendly.  */
1697
1698 static void
1699 crash_signal (signo)
1700      int signo;
1701 {
1702   internal_error ("internal error: %s", strsignal (signo));
1703 }
1704
1705 /* Strip off a legitimate source ending from the input string NAME of
1706    length LEN.  Rather than having to know the names used by all of
1707    our front ends, we strip off an ending of a period followed by
1708    up to five characters.  (Java uses ".class".)  */
1709
1710 void
1711 strip_off_ending (name, len)
1712      char *name;
1713      int len;
1714 {
1715   int i;
1716   for (i = 2;  i < 6 && len > i;  i++)
1717     {
1718       if (name[len - i] == '.')
1719         {
1720           name[len - i] = '\0';
1721           break;
1722         }
1723     }
1724 }
1725
1726 /* Output a quoted string.  */
1727
1728 void
1729 output_quoted_string (asm_file, string)
1730      FILE *asm_file;
1731      const char *string;
1732 {
1733 #ifdef OUTPUT_QUOTED_STRING
1734   OUTPUT_QUOTED_STRING (asm_file, string);
1735 #else
1736   char c;
1737
1738   putc ('\"', asm_file);
1739   while ((c = *string++) != 0)
1740     {
1741       if (ISPRINT (c))
1742         {
1743           if (c == '\"' || c == '\\')
1744             putc ('\\', asm_file);
1745           putc (c, asm_file);
1746         }
1747       else
1748         fprintf (asm_file, "\\%03o", c);
1749     }
1750   putc ('\"', asm_file);
1751 #endif
1752 }
1753
1754 /* Output a file name in the form wanted by System V.  */
1755
1756 void
1757 output_file_directive (asm_file, input_name)
1758      FILE *asm_file;
1759      const char *input_name;
1760 {
1761   int len = strlen (input_name);
1762   const char *na = input_name + len;
1763
1764   /* NA gets INPUT_NAME sans directory names.  */
1765   while (na > input_name)
1766     {
1767       if (IS_DIR_SEPARATOR (na[-1]))
1768         break;
1769       na--;
1770     }
1771
1772 #ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
1773   ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
1774 #else
1775 #ifdef ASM_OUTPUT_SOURCE_FILENAME
1776   ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
1777 #else
1778   fprintf (asm_file, "\t.file\t");
1779   output_quoted_string (asm_file, na);
1780   fputc ('\n', asm_file);
1781 #endif
1782 #endif
1783 }
1784 \f
1785 /* Routine to open a dump file.  Return true if the dump file is enabled.  */
1786
1787 static int
1788 open_dump_file (index, decl)
1789      enum dump_file_index index;
1790      tree decl;
1791 {
1792   char *dump_name;
1793   const char *open_arg;
1794   char seq[16];
1795
1796   if (! dump_file[index].enabled)
1797     return 0;
1798
1799   timevar_push (TV_DUMP);
1800   if (rtl_dump_file != NULL)
1801     fclose (rtl_dump_file);
1802
1803   sprintf (seq, DUMPFILE_FORMAT, index);
1804
1805   if (! dump_file[index].initialized)
1806     {
1807       /* If we've not initialized the files, do so now.  */
1808       if (graph_dump_format != no_graph
1809           && dump_file[index].graph_dump_p)
1810         {
1811           dump_name = concat (seq, dump_file[index].extension, NULL);
1812           clean_graph_dump_file (dump_base_name, dump_name);
1813           free (dump_name);
1814         }
1815       dump_file[index].initialized = 1;
1816       open_arg = "w";
1817     }
1818   else
1819     open_arg = "a";
1820
1821   dump_name = concat (dump_base_name, seq,
1822                       dump_file[index].extension, NULL);
1823
1824   rtl_dump_file = fopen (dump_name, open_arg);
1825   if (rtl_dump_file == NULL)
1826     fatal_io_error ("can't open %s", dump_name);
1827
1828   free (dump_name);
1829
1830   if (decl)
1831     fprintf (rtl_dump_file, "\n;; Function %s\n\n",
1832              decl_printable_name (decl, 2));
1833
1834   timevar_pop (TV_DUMP);
1835   return 1;
1836 }
1837
1838 /* Routine to close a dump file.  */
1839
1840 static void
1841 close_dump_file (index, func, insns)
1842      enum dump_file_index index;
1843      void (*func) PARAMS ((FILE *, rtx));
1844      rtx insns;
1845 {
1846   if (! rtl_dump_file)
1847     return;
1848
1849   timevar_push (TV_DUMP);
1850   if (insns
1851       && graph_dump_format != no_graph
1852       && dump_file[index].graph_dump_p)
1853     {
1854       char seq[16];
1855       char *suffix;
1856
1857       sprintf (seq, DUMPFILE_FORMAT, index);
1858       suffix = concat (seq, dump_file[index].extension, NULL);
1859       print_rtl_graph_with_bb (dump_base_name, suffix, insns);
1860       free (suffix);
1861     }
1862
1863   if (func && insns)
1864     func (rtl_dump_file, insns);
1865
1866   fflush (rtl_dump_file);
1867   fclose (rtl_dump_file);
1868
1869   rtl_dump_file = NULL;
1870   timevar_pop (TV_DUMP);
1871 }
1872
1873 /* Do any final processing required for the declarations in VEC, of
1874    which there are LEN.  We write out inline functions and variables
1875    that have been deferred until this point, but which are required.
1876    Returns non-zero if anything was put out.  */
1877
1878 int
1879 wrapup_global_declarations (vec, len)
1880      tree *vec;
1881      int len;
1882 {
1883   tree decl;
1884   int i;
1885   int reconsider;
1886   int output_something = 0;
1887
1888   for (i = 0; i < len; i++)
1889     {
1890       decl = vec[i];
1891
1892       /* We're not deferring this any longer.  */
1893       DECL_DEFER_OUTPUT (decl) = 0;
1894
1895       if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0
1896           && incomplete_decl_finalize_hook != 0)
1897         (*incomplete_decl_finalize_hook) (decl);
1898     }
1899
1900   /* Now emit any global variables or functions that we have been
1901      putting off.  We need to loop in case one of the things emitted
1902      here references another one which comes earlier in the list.  */
1903   do
1904     {
1905       reconsider = 0;
1906       for (i = 0; i < len; i++)
1907         {
1908           decl = vec[i];
1909
1910           if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
1911             continue;
1912
1913           /* Don't write out static consts, unless we still need them.
1914
1915              We also keep static consts if not optimizing (for debugging),
1916              unless the user specified -fno-keep-static-consts.
1917              ??? They might be better written into the debug information.
1918              This is possible when using DWARF.
1919
1920              A language processor that wants static constants to be always
1921              written out (even if it is not used) is responsible for
1922              calling rest_of_decl_compilation itself.  E.g. the C front-end
1923              calls rest_of_decl_compilation from finish_decl.
1924              One motivation for this is that is conventional in some
1925              environments to write things like:
1926              static const char rcsid[] = "... version string ...";
1927              intending to force the string to be in the executable.
1928
1929              A language processor that would prefer to have unneeded
1930              static constants "optimized away" would just defer writing
1931              them out until here.  E.g. C++ does this, because static
1932              constants are often defined in header files.
1933
1934              ??? A tempting alternative (for both C and C++) would be
1935              to force a constant to be written if and only if it is
1936              defined in a main file, as opposed to an include file.  */
1937
1938           if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
1939               && (((! TREE_READONLY (decl) || TREE_PUBLIC (decl))
1940                    && !DECL_COMDAT (decl))
1941                   || (!optimize
1942                       && flag_keep_static_consts
1943                       && !DECL_ARTIFICIAL (decl))
1944                   || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
1945             {
1946               reconsider = 1;
1947               rest_of_decl_compilation (decl, NULL, 1, 1);
1948             }
1949
1950           if (TREE_CODE (decl) == FUNCTION_DECL
1951               && DECL_INITIAL (decl) != 0
1952               && DECL_SAVED_INSNS (decl) != 0
1953               && (flag_keep_inline_functions
1954                   || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
1955                   || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
1956             {
1957               reconsider = 1;
1958               output_inline_function (decl);
1959             }
1960         }
1961
1962       if (reconsider)
1963         output_something = 1;
1964     }
1965   while (reconsider);
1966
1967   return output_something;
1968 }
1969
1970 /* Issue appropriate warnings for the global declarations in VEC (of
1971    which there are LEN).  Output debugging information for them.  */
1972
1973 void
1974 check_global_declarations (vec, len)
1975      tree *vec;
1976      int len;
1977 {
1978   tree decl;
1979   int i;
1980
1981   for (i = 0; i < len; i++)
1982     {
1983       decl = vec[i];
1984
1985       if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
1986           && ! TREE_ASM_WRITTEN (decl))
1987         /* Cancel the RTL for this decl so that, if debugging info
1988            output for global variables is still to come,
1989            this one will be omitted.  */
1990         SET_DECL_RTL (decl, NULL_RTX);
1991
1992       /* Warn about any function
1993          declared static but not defined.
1994          We don't warn about variables,
1995          because many programs have static variables
1996          that exist only to get some text into the object file.  */
1997       if (TREE_CODE (decl) == FUNCTION_DECL
1998           && (warn_unused_function
1999               || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2000           && DECL_INITIAL (decl) == 0
2001           && DECL_EXTERNAL (decl)
2002           && ! DECL_ARTIFICIAL (decl)
2003           && ! TREE_PUBLIC (decl))
2004         {
2005           if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2006             pedwarn_with_decl (decl,
2007                                "`%s' used but never defined");
2008           else
2009             warning_with_decl (decl,
2010                                "`%s' declared `static' but never defined");
2011           /* This symbol is effectively an "extern" declaration now.  */
2012           TREE_PUBLIC (decl) = 1;
2013           assemble_external (decl);
2014         }
2015
2016       /* Warn about static fns or vars defined but not used,
2017          but not about inline functions or static consts
2018          since defining those in header files is normal practice.  */
2019       if (((warn_unused_function
2020             && TREE_CODE (decl) == FUNCTION_DECL && ! DECL_INLINE (decl))
2021            || (warn_unused_variable
2022                && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
2023           && ! DECL_IN_SYSTEM_HEADER (decl)
2024           && ! DECL_EXTERNAL (decl)
2025           && ! TREE_PUBLIC (decl)
2026           && ! TREE_USED (decl)
2027           && (TREE_CODE (decl) == FUNCTION_DECL || ! DECL_REGISTER (decl))
2028           /* The TREE_USED bit for file-scope decls
2029              is kept in the identifier, to handle multiple
2030              external decls in different scopes.  */
2031           && ! TREE_USED (DECL_NAME (decl)))
2032         warning_with_decl (decl, "`%s' defined but not used");
2033
2034       timevar_push (TV_SYMOUT);
2035       (*debug_hooks->global_decl) (decl);
2036       timevar_pop (TV_SYMOUT);
2037     }
2038 }
2039
2040 /* Save the current INPUT_FILENAME and LINENO on the top entry in the
2041    INPUT_FILE_STACK.  Push a new entry for FILE and LINE, and set the
2042    INPUT_FILENAME and LINENO accordingly.  */
2043
2044 void
2045 push_srcloc (file, line)
2046      const char *file;
2047      int line;
2048 {
2049   struct file_stack *fs;
2050
2051   if (input_file_stack)
2052     {
2053       input_file_stack->name = input_filename;
2054       input_file_stack->line = lineno;
2055     }
2056
2057   fs = (struct file_stack *) xmalloc (sizeof (struct file_stack));
2058   fs->name = input_filename = file;
2059   fs->line = lineno = line;
2060   fs->indent_level = 0;
2061   fs->next = input_file_stack;
2062   input_file_stack = fs;
2063   input_file_stack_tick++;
2064 }
2065
2066 /* Pop the top entry off the stack of presently open source files.
2067    Restore the INPUT_FILENAME and LINENO from the new topmost entry on
2068    the stack.  */
2069
2070 void
2071 pop_srcloc ()
2072 {
2073   struct file_stack *fs;
2074
2075   fs = input_file_stack;
2076   input_file_stack = fs->next;
2077   free (fs);
2078   input_file_stack_tick++;
2079   /* The initial source file is never popped.  */
2080   if (!input_file_stack)
2081     abort ();
2082   input_filename = input_file_stack->name;
2083   lineno = input_file_stack->line;
2084 }
2085
2086 /* Compile an entire translation unit.  Write a file of assembly
2087    output and various debugging dumps.  */
2088
2089 static void
2090 compile_file ()
2091 {
2092   tree globals;
2093
2094   /* Initialize yet another pass.  */
2095
2096   init_final (main_input_filename);
2097   init_branch_prob (dump_base_name);
2098
2099   timevar_push (TV_PARSE);
2100
2101   /* Call the parser, which parses the entire file
2102      (calling rest_of_compilation for each function).  */
2103   yyparse ();
2104
2105   /* In case there were missing block closers,
2106      get us back to the global binding level.  */
2107   (*lang_hooks.clear_binding_stack) ();
2108
2109   /* Compilation is now finished except for writing
2110      what's left of the symbol table output.  */
2111
2112   timevar_pop (TV_PARSE);
2113
2114   if (flag_syntax_only)
2115     return;
2116
2117   globals = getdecls ();
2118
2119   /* Really define vars that have had only a tentative definition.
2120      Really output inline functions that must actually be callable
2121      and have not been output so far.  */
2122
2123   {
2124     int len = list_length (globals);
2125     tree *vec = (tree *) xmalloc (sizeof (tree) * len);
2126     int i;
2127     tree decl;
2128
2129     /* Process the decls in reverse order--earliest first.
2130        Put them into VEC from back to front, then take out from front.  */
2131
2132     for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
2133       vec[len - i - 1] = decl;
2134
2135     wrapup_global_declarations (vec, len);
2136
2137     /* This must occur after the loop to output deferred functions.  Else
2138        the profiler initializer would not be emitted if all the functions
2139        in this compilation unit were deferred.
2140
2141        output_func_start_profiler can not cause any additional functions or
2142        data to need to be output, so it need not be in the deferred function
2143        loop above.  */
2144     output_func_start_profiler ();
2145
2146     check_global_declarations (vec, len);
2147
2148     /* Clean up.  */
2149     free (vec);
2150   }
2151
2152   /* Write out any pending weak symbol declarations.  */
2153
2154   weak_finish ();
2155
2156   /* Do dbx symbols.  */
2157   timevar_push (TV_SYMOUT);
2158
2159 #ifdef DWARF2_UNWIND_INFO
2160   if (dwarf2out_do_frame ())
2161     dwarf2out_frame_finish ();
2162 #endif
2163
2164   (*debug_hooks->finish) (main_input_filename);
2165   timevar_pop (TV_SYMOUT);
2166
2167   /* Output some stuff at end of file if nec.  */
2168
2169   dw2_output_indirect_constants ();
2170
2171   end_final (dump_base_name);
2172
2173   if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
2174     {
2175       timevar_push (TV_DUMP);
2176       open_dump_file (DFI_bp, NULL);
2177
2178       end_branch_prob ();
2179
2180       close_dump_file (DFI_bp, NULL, NULL_RTX);
2181       timevar_pop (TV_DUMP);
2182     }
2183
2184 #ifdef ASM_FILE_END
2185   ASM_FILE_END (asm_out_file);
2186 #endif
2187
2188   /* Attach a special .ident directive to the end of the file to identify
2189      the version of GCC which compiled this code.  The format of the .ident
2190      string is patterned after the ones produced by native SVR4 compilers.  */
2191 #ifdef IDENT_ASM_OP
2192   if (!flag_no_ident)
2193     fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
2194              IDENT_ASM_OP, version_string);
2195 #endif
2196
2197   if (optimize > 0 && open_dump_file (DFI_combine, NULL))
2198     {
2199       timevar_push (TV_DUMP);
2200       dump_combine_total_stats (rtl_dump_file);
2201       close_dump_file (DFI_combine, NULL, NULL_RTX);
2202       timevar_pop (TV_DUMP);
2203     }
2204 }
2205 \f
2206 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
2207    and TYPE_DECL nodes.
2208
2209    This does nothing for local (non-static) variables, unless the
2210    variable is a register variable with an ASMSPEC.  In that case, or
2211    if the variable is not an automatic, it sets up the RTL and
2212    outputs any assembler code (label definition, storage allocation
2213    and initialization).
2214
2215    DECL is the declaration.  If ASMSPEC is nonzero, it specifies
2216    the assembler symbol name to be used.  TOP_LEVEL is nonzero
2217    if this declaration is not within a function.  */
2218
2219 void
2220 rest_of_decl_compilation (decl, asmspec, top_level, at_end)
2221      tree decl;
2222      const char *asmspec;
2223      int top_level;
2224      int at_end;
2225 {
2226   /* Declarations of variables, and of functions defined elsewhere.  */
2227
2228 /* The most obvious approach, to put an #ifndef around where
2229    this macro is used, doesn't work since it's inside a macro call.  */
2230 #ifndef ASM_FINISH_DECLARE_OBJECT
2231 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP, END)
2232 #endif
2233
2234   /* We deferred calling assemble_alias so that we could collect
2235      other attributes such as visibility.  Emit the alias now.  */
2236   {
2237     tree alias;
2238     alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
2239     if (alias)
2240       {
2241         alias = TREE_VALUE (TREE_VALUE (alias));
2242         alias = get_identifier (TREE_STRING_POINTER (alias));
2243         assemble_alias (decl, alias);
2244       }
2245   }
2246
2247   /* Forward declarations for nested functions are not "external",
2248      but we need to treat them as if they were.  */
2249   if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
2250       || TREE_CODE (decl) == FUNCTION_DECL)
2251     {
2252       timevar_push (TV_VARCONST);
2253
2254       if (asmspec)
2255         make_decl_rtl (decl, asmspec);
2256
2257       /* Don't output anything when a tentative file-scope definition
2258          is seen.  But at end of compilation, do output code for them.  */
2259       if (at_end || !DECL_DEFER_OUTPUT (decl))
2260         assemble_variable (decl, top_level, at_end, 0);
2261       if (decl == last_assemble_variable_decl)
2262         {
2263           ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
2264                                      top_level, at_end);
2265         }
2266
2267       timevar_pop (TV_VARCONST);
2268     }
2269   else if (DECL_REGISTER (decl) && asmspec != 0)
2270     {
2271       if (decode_reg_name (asmspec) >= 0)
2272         {
2273           SET_DECL_RTL (decl, NULL_RTX);
2274           make_decl_rtl (decl, asmspec);
2275         }
2276       else
2277         {
2278           error ("invalid register name `%s' for register variable", asmspec);
2279           DECL_REGISTER (decl) = 0;
2280           if (!top_level)
2281             expand_decl (decl);
2282         }
2283     }
2284 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2285   else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2286            && TREE_CODE (decl) == TYPE_DECL)
2287     {
2288       timevar_push (TV_SYMOUT);
2289       dbxout_symbol (decl, 0);
2290       timevar_pop (TV_SYMOUT);
2291     }
2292 #endif
2293 #ifdef SDB_DEBUGGING_INFO
2294   else if (write_symbols == SDB_DEBUG && top_level
2295            && TREE_CODE (decl) == TYPE_DECL)
2296     {
2297       timevar_push (TV_SYMOUT);
2298       sdbout_symbol (decl, 0);
2299       timevar_pop (TV_SYMOUT);
2300     }
2301 #endif
2302 }
2303
2304 /* Called after finishing a record, union or enumeral type.  */
2305
2306 void
2307 rest_of_type_compilation (type, toplev)
2308 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO) || defined (SDB_DEBUGGING_INFO)
2309      tree type;
2310      int toplev;
2311 #else
2312      tree type ATTRIBUTE_UNUSED;
2313      int toplev ATTRIBUTE_UNUSED;
2314 #endif
2315 {
2316   timevar_push (TV_SYMOUT);
2317 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2318   if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2319     dbxout_symbol (TYPE_STUB_DECL (type), !toplev);
2320 #endif
2321 #ifdef SDB_DEBUGGING_INFO
2322   if (write_symbols == SDB_DEBUG)
2323     sdbout_symbol (TYPE_STUB_DECL (type), !toplev);
2324 #endif
2325 #ifdef DWARF2_DEBUGGING_INFO
2326   if ((write_symbols == DWARF2_DEBUG
2327        || write_symbols == VMS_AND_DWARF2_DEBUG)
2328       && toplev)
2329     dwarf2out_decl (TYPE_STUB_DECL (type));
2330 #endif
2331   timevar_pop (TV_SYMOUT);
2332 }
2333
2334 /* This is called from finish_function (within yyparse)
2335    after each top-level definition is parsed.
2336    It is supposed to compile that function or variable
2337    and output the assembler code for it.
2338    After we return, the tree storage is freed.  */
2339
2340 void
2341 rest_of_compilation (decl)
2342      tree decl;
2343 {
2344   rtx insns;
2345   int tem;
2346   int failure = 0;
2347   int rebuild_label_notes_after_reload;
2348   int register_life_up_to_date;
2349
2350   timevar_push (TV_REST_OF_COMPILATION);
2351
2352   /* Now that we're out of the frontend, we shouldn't have any more
2353      CONCATs anywhere.  */
2354   generating_concat_p = 0;
2355
2356   /* When processing delayed functions, prepare_function_start() won't
2357      have been run to re-initialize it.  */
2358   cse_not_expected = ! optimize;
2359
2360   /* First, make sure that NOTE_BLOCK is set correctly for each
2361      NOTE_INSN_BLOCK_BEG/NOTE_INSN_BLOCK_END note.  */
2362   if (!cfun->x_whole_function_mode_p)
2363     identify_blocks ();
2364
2365   /* In function-at-a-time mode, we do not attempt to keep the BLOCK
2366      tree in sensible shape.  So, we just recalculate it here.  */
2367   if (cfun->x_whole_function_mode_p)
2368     reorder_blocks ();
2369
2370   init_flow ();
2371
2372   /* If we are reconsidering an inline function
2373      at the end of compilation, skip the stuff for making it inline.  */
2374
2375   if (DECL_SAVED_INSNS (decl) == 0)
2376     {
2377       int inlinable = 0;
2378       tree parent;
2379       const char *lose;
2380
2381       /* If this is nested inside an inlined external function, pretend
2382          it was only declared.  Since we cannot inline such functions,
2383          generating code for this one is not only not necessary but will
2384          confuse some debugging output writers.  */
2385       for (parent = DECL_CONTEXT (current_function_decl);
2386            parent != NULL_TREE;
2387            parent = get_containing_scope (parent))
2388         if (TREE_CODE (parent) == FUNCTION_DECL
2389             && DECL_INLINE (parent) && DECL_EXTERNAL (parent))
2390           {
2391             DECL_INITIAL (decl) = 0;
2392             goto exit_rest_of_compilation;
2393           }
2394
2395       /* If requested, consider whether to make this function inline.  */
2396       if ((DECL_INLINE (decl) && !flag_no_inline)
2397           || flag_inline_functions)
2398         {
2399           timevar_push (TV_INTEGRATION);
2400           lose = function_cannot_inline_p (decl);
2401           timevar_pop (TV_INTEGRATION);
2402           if (lose || ! optimize)
2403             {
2404               if (warn_inline && DECL_INLINE (decl))
2405                 warning_with_decl (decl, lose);
2406               DECL_ABSTRACT_ORIGIN (decl) = 0;
2407               /* Don't really compile an extern inline function.
2408                  If we can't make it inline, pretend
2409                  it was only declared.  */
2410               if (DECL_EXTERNAL (decl))
2411                 {
2412                   DECL_INITIAL (decl) = 0;
2413                   goto exit_rest_of_compilation;
2414                 }
2415             }
2416           else
2417             /* ??? Note that this has the effect of making it look
2418                  like "inline" was specified for a function if we choose
2419                  to inline it.  This isn't quite right, but it's
2420                  probably not worth the trouble to fix.  */
2421             inlinable = DECL_INLINE (decl) = 1;
2422         }
2423
2424       insns = get_insns ();
2425
2426       /* Dump the rtl code if we are dumping rtl.  */
2427
2428       if (open_dump_file (DFI_rtl, decl))
2429         {
2430           if (DECL_SAVED_INSNS (decl))
2431             fprintf (rtl_dump_file, ";; (integrable)\n\n");
2432           close_dump_file (DFI_rtl, print_rtl, insns);
2433         }
2434
2435       /* Convert from NOTE_INSN_EH_REGION style notes, and do other
2436          sorts of eh initialization.  Delay this until after the
2437          initial rtl dump so that we can see the original nesting.  */
2438       convert_from_eh_region_ranges ();
2439
2440       /* If function is inline, and we don't yet know whether to
2441          compile it by itself, defer decision till end of compilation.
2442          finish_compilation will call rest_of_compilation again
2443          for those functions that need to be output.  Also defer those
2444          functions that we are supposed to defer.  */
2445
2446       if (inlinable
2447           || (DECL_INLINE (decl)
2448               && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2449                    && ! flag_keep_inline_functions)
2450                   || DECL_EXTERNAL (decl))))
2451         DECL_DEFER_OUTPUT (decl) = 1;
2452
2453       if (DECL_INLINE (decl))
2454         /* DWARF wants separate debugging info for abstract and
2455            concrete instances of all inline functions, including those
2456            declared inline but not inlined, and those inlined even
2457            though they weren't declared inline.  Conveniently, that's
2458            what DECL_INLINE means at this point.  */
2459         (*debug_hooks->deferred_inline_function) (decl);
2460
2461       if (DECL_DEFER_OUTPUT (decl))
2462         {
2463           /* If -Wreturn-type, we have to do a bit of compilation.  We just
2464              want to call cleanup the cfg to figure out whether or not we can
2465              fall off the end of the function; we do the minimum amount of
2466              work necessary to make that safe.  */
2467           if (warn_return_type)
2468             {
2469               int saved_optimize = optimize;
2470
2471               optimize = 0;
2472               rebuild_jump_labels (insns);
2473               find_exception_handler_labels ();
2474               find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2475               cleanup_cfg (CLEANUP_PRE_SIBCALL | CLEANUP_PRE_LOOP);
2476               optimize = saved_optimize;
2477
2478               /* CFG is no longer maintained up-to-date.  */
2479               free_bb_for_insn ();
2480             }
2481
2482           current_function_nothrow = nothrow_function_p ();
2483           if (current_function_nothrow)
2484             /* Now we know that this can't throw; set the flag for the benefit
2485                of other functions later in this translation unit.  */
2486             TREE_NOTHROW (current_function_decl) = 1;
2487
2488           timevar_push (TV_INTEGRATION);
2489           save_for_inline (decl);
2490           timevar_pop (TV_INTEGRATION);
2491           DECL_SAVED_INSNS (decl)->inlinable = inlinable;
2492           goto exit_rest_of_compilation;
2493         }
2494
2495       /* If specified extern inline but we aren't inlining it, we are
2496          done.  This goes for anything that gets here with DECL_EXTERNAL
2497          set, not just things with DECL_INLINE.  */
2498       if (DECL_EXTERNAL (decl))
2499         goto exit_rest_of_compilation;
2500     }
2501
2502   /* If we're emitting a nested function, make sure its parent gets
2503      emitted as well.  Doing otherwise confuses debug info.  */
2504   {
2505     tree parent;
2506     for (parent = DECL_CONTEXT (current_function_decl);
2507          parent != NULL_TREE;
2508          parent = get_containing_scope (parent))
2509       if (TREE_CODE (parent) == FUNCTION_DECL)
2510         TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
2511   }
2512
2513   /* We are now committed to emitting code for this function.  Do any
2514      preparation, such as emitting abstract debug info for the inline
2515      before it gets mangled by optimization.  */
2516   if (DECL_INLINE (decl))
2517     (*debug_hooks->outlining_inline_function) (decl);
2518
2519   /* Remove any notes we don't need.  That will make iterating
2520      over the instruction sequence faster, and allow the garbage
2521      collector to reclaim the memory used by the notes.  */
2522   remove_unnecessary_notes ();
2523   reorder_blocks ();
2524
2525   ggc_collect ();
2526
2527   /* Initialize some variables used by the optimizers.  */
2528   init_function_for_compilation ();
2529
2530   if (! DECL_DEFER_OUTPUT (decl))
2531     TREE_ASM_WRITTEN (decl) = 1;
2532
2533   /* Now that integrate will no longer see our rtl, we need not
2534      distinguish between the return value of this function and the
2535      return value of called functions.  Also, we can remove all SETs
2536      of subregs of hard registers; they are only here because of
2537      integrate.  Also, we can now initialize pseudos intended to 
2538      carry magic hard reg data throughout the function.  */
2539   rtx_equal_function_value_matters = 0;
2540   purge_hard_subreg_sets (get_insns ());
2541   emit_initial_value_sets ();
2542
2543   /* Early return if there were errors.  We can run afoul of our
2544      consistency checks, and there's not really much point in fixing them.
2545      Don't return yet if -Wreturn-type; we need to do cleanup_cfg.  */
2546   if (((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
2547       || errorcount || sorrycount)
2548     goto exit_rest_of_compilation;
2549
2550   /* We may have potential sibling or tail recursion sites.  Select one
2551      (of possibly multiple) methods of performing the call.  */
2552   if (flag_optimize_sibling_calls)
2553     {
2554       timevar_push (TV_JUMP);
2555       open_dump_file (DFI_sibling, decl);
2556
2557       optimize_sibling_and_tail_recursive_calls ();
2558
2559       close_dump_file (DFI_sibling, print_rtl, get_insns ());
2560       timevar_pop (TV_JUMP);
2561     }
2562
2563   /* Complete generation of exception handling code.  */
2564   find_exception_handler_labels ();
2565   if (doing_eh (0))
2566     {
2567       timevar_push (TV_JUMP);
2568       open_dump_file (DFI_eh, decl);
2569
2570       finish_eh_generation ();
2571
2572       close_dump_file (DFI_eh, print_rtl, get_insns ());
2573       timevar_pop (TV_JUMP);
2574     }
2575
2576 #ifdef FINALIZE_PIC
2577   /* If we are doing position-independent code generation, now
2578      is the time to output special prologues and epilogues.
2579      We do not want to do this earlier, because it just clutters
2580      up inline functions with meaningless insns.  */
2581   if (flag_pic)
2582     FINALIZE_PIC;
2583 #endif
2584
2585   insns = get_insns ();
2586
2587   /* Copy any shared structure that should not be shared.  */
2588   unshare_all_rtl (current_function_decl, insns);
2589
2590 #ifdef SETJMP_VIA_SAVE_AREA
2591   /* This must be performed before virtual register instantiation.  */
2592   if (current_function_calls_alloca)
2593     optimize_save_area_alloca (insns);
2594 #endif
2595
2596   /* Instantiate all virtual registers.  */
2597   instantiate_virtual_regs (current_function_decl, insns);
2598
2599   open_dump_file (DFI_jump, decl);
2600
2601   /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
2602      are initialized and to compute whether control can drop off the end
2603      of the function.  */
2604
2605   timevar_push (TV_JUMP);
2606   /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB.  Do this
2607      before jump optimization switches branch directions.  */
2608   expected_value_to_br_prob ();
2609
2610   reg_scan (insns, max_reg_num (), 0);
2611   rebuild_jump_labels (insns);
2612   find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2613   if (rtl_dump_file)
2614     dump_flow_info (rtl_dump_file);
2615   cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
2616                | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2617
2618   /* CFG is no longer maintained up-to-date.  */
2619   free_bb_for_insn ();
2620   copy_loop_headers (insns);
2621   purge_line_number_notes (insns);
2622
2623   timevar_pop (TV_JUMP);
2624   close_dump_file (DFI_jump, print_rtl, insns);
2625
2626   /* Now is when we stop if -fsyntax-only and -Wreturn-type.  */
2627   if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
2628     {
2629       goto exit_rest_of_compilation;
2630     }
2631
2632   /* Long term, this should probably move before the jump optimizer too,
2633      but I didn't want to disturb the rtl_dump_and_exit and related
2634      stuff at this time.  */
2635   if (optimize > 0 && flag_ssa)
2636     {
2637       /* Convert to SSA form.  */
2638
2639       timevar_push (TV_TO_SSA);
2640       open_dump_file (DFI_ssa, decl);
2641
2642       find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2643       cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2644       convert_to_ssa ();
2645
2646       close_dump_file (DFI_ssa, print_rtl_with_bb, insns);
2647       timevar_pop (TV_TO_SSA);
2648
2649       /* Perform sparse conditional constant propagation, if requested.  */
2650       if (flag_ssa_ccp)
2651         {
2652           timevar_push (TV_SSA_CCP);
2653           open_dump_file (DFI_ssa_ccp, decl);
2654
2655           ssa_const_prop ();
2656
2657           close_dump_file (DFI_ssa_ccp, print_rtl_with_bb, get_insns ());
2658           timevar_pop (TV_SSA_CCP);
2659         }
2660
2661       /* It would be useful to cleanup the CFG at this point, but block
2662          merging and possibly other transformations might leave a PHI
2663          node in the middle of a basic block, which is a strict no-no.  */
2664
2665       /* The SSA implementation uses basic block numbers in its phi
2666          nodes.  Thus, changing the control-flow graph or the basic
2667          blocks, e.g., calling find_basic_blocks () or cleanup_cfg (),
2668          may cause problems.  */
2669
2670       if (flag_ssa_dce)
2671         {
2672           /* Remove dead code.  */
2673
2674           timevar_push (TV_SSA_DCE);
2675           open_dump_file (DFI_ssa_dce, decl);
2676
2677           insns = get_insns ();
2678           ssa_eliminate_dead_code();
2679
2680           close_dump_file (DFI_ssa_dce, print_rtl_with_bb, insns);
2681           timevar_pop (TV_SSA_DCE);
2682         }
2683
2684       /* Convert from SSA form.  */
2685
2686       timevar_push (TV_FROM_SSA);
2687       open_dump_file (DFI_ussa, decl);
2688
2689       convert_from_ssa ();
2690       /* New registers have been created.  Rescan their usage.  */
2691       reg_scan (insns, max_reg_num (), 1);
2692
2693       close_dump_file (DFI_ussa, print_rtl_with_bb, insns);
2694       timevar_pop (TV_FROM_SSA);
2695
2696       ggc_collect ();
2697       /* CFG is no longer maintained up-to-date.  */
2698       free_bb_for_insn ();
2699     }
2700
2701   timevar_push (TV_JUMP);
2702
2703   if (optimize > 0)
2704     {
2705       open_dump_file (DFI_null, decl);
2706       find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2707       if (rtl_dump_file)
2708         dump_flow_info (rtl_dump_file);
2709       cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2710
2711       /* Try to identify useless null pointer tests and delete them.  */
2712       if (flag_delete_null_pointer_checks)
2713         delete_null_pointer_checks (insns);
2714
2715       timevar_push (TV_IFCVT);
2716       if_convert (0);
2717       timevar_pop (TV_IFCVT);
2718       cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2719       close_dump_file (DFI_null, print_rtl_with_bb, insns);
2720     }
2721
2722   /* Jump optimization, and the removal of NULL pointer checks, may
2723      have reduced the number of instructions substantially.  CSE, and
2724      future passes, allocate arrays whose dimensions involve the
2725      maximum instruction UID, so if we can reduce the maximum UID
2726      we'll save big on memory.  */
2727   renumber_insns (rtl_dump_file);
2728   if (optimize)
2729     compute_bb_for_insn (get_max_uid ());
2730   timevar_pop (TV_JUMP);
2731
2732   close_dump_file (DFI_jump, print_rtl_with_bb, insns);
2733
2734   ggc_collect ();
2735
2736   /* Perform common subexpression elimination.
2737      Nonzero value from `cse_main' means that jumps were simplified
2738      and some code may now be unreachable, so do
2739      jump optimization again.  */
2740
2741   if (optimize > 0)
2742     {
2743       open_dump_file (DFI_cse, decl);
2744       if (rtl_dump_file)
2745         dump_flow_info (rtl_dump_file);
2746       timevar_push (TV_CSE);
2747
2748       reg_scan (insns, max_reg_num (), 1);
2749
2750       tem = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2751       if (tem)
2752         rebuild_jump_labels (insns);
2753       purge_all_dead_edges (0);
2754
2755       delete_trivially_dead_insns (insns, max_reg_num ());
2756
2757       /* If we are not running more CSE passes, then we are no longer
2758          expecting CSE to be run.  But always rerun it in a cheap mode.  */
2759       cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
2760
2761       if (tem || optimize > 1)
2762         cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2763       /* Try to identify useless null pointer tests and delete them.  */
2764       if (flag_delete_null_pointer_checks || flag_thread_jumps)
2765         {
2766           timevar_push (TV_JUMP);
2767
2768           if (flag_delete_null_pointer_checks)
2769             delete_null_pointer_checks (insns);
2770           /* CFG is no longer maintained up-to-date.  */
2771           timevar_pop (TV_JUMP);
2772         }
2773
2774       /* The second pass of jump optimization is likely to have
2775          removed a bunch more instructions.  */
2776       renumber_insns (rtl_dump_file);
2777       compute_bb_for_insn (get_max_uid ());
2778
2779       timevar_pop (TV_CSE);
2780       close_dump_file (DFI_cse, print_rtl_with_bb, insns);
2781     }
2782
2783   open_dump_file (DFI_addressof, decl);
2784
2785   purge_addressof (insns);
2786   if (optimize)
2787     purge_all_dead_edges (0);
2788   reg_scan (insns, max_reg_num (), 1);
2789
2790   close_dump_file (DFI_addressof, print_rtl, insns);
2791
2792   ggc_collect ();
2793
2794   /* Perform global cse.  */
2795
2796   if (optimize > 0 && flag_gcse)
2797     {
2798       int save_csb, save_cfj;
2799       int tem2 = 0;
2800
2801       timevar_push (TV_GCSE);
2802       open_dump_file (DFI_gcse, decl);
2803
2804       cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2805       tem = gcse_main (insns, rtl_dump_file);
2806       rebuild_jump_labels (insns);
2807       delete_trivially_dead_insns (insns, max_reg_num ());
2808
2809       save_csb = flag_cse_skip_blocks;
2810       save_cfj = flag_cse_follow_jumps;
2811       flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
2812
2813       /* If -fexpensive-optimizations, re-run CSE to clean up things done
2814          by gcse.  */
2815       if (flag_expensive_optimizations)
2816         {
2817           timevar_push (TV_CSE);
2818           reg_scan (insns, max_reg_num (), 1);
2819           tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2820           purge_all_dead_edges (0);
2821           delete_trivially_dead_insns (insns, max_reg_num ());
2822           timevar_pop (TV_CSE);
2823           cse_not_expected = !flag_rerun_cse_after_loop;
2824         }
2825
2826       /* If gcse or cse altered any jumps, rerun jump optimizations to clean
2827          things up.  Then possibly re-run CSE again.  */
2828       while (tem || tem2)
2829         {
2830           tem = tem2 = 0;
2831           timevar_push (TV_JUMP);
2832           rebuild_jump_labels (insns);
2833           cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2834           timevar_pop (TV_JUMP);
2835
2836           if (flag_expensive_optimizations)
2837             {
2838               timevar_push (TV_CSE);
2839               reg_scan (insns, max_reg_num (), 1);
2840               tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2841               purge_all_dead_edges (0);
2842               delete_trivially_dead_insns (insns, max_reg_num ());
2843               timevar_pop (TV_CSE);
2844             }
2845         }
2846
2847       close_dump_file (DFI_gcse, print_rtl_with_bb, insns);
2848       timevar_pop (TV_GCSE);
2849
2850       ggc_collect ();
2851       flag_cse_skip_blocks = save_csb;
2852       flag_cse_follow_jumps = save_cfj;
2853 #ifdef ENABLE_CHECKING
2854       verify_flow_info ();
2855 #endif
2856     }
2857
2858   /* Move constant computations out of loops.  */
2859
2860   if (optimize > 0)
2861     {
2862       timevar_push (TV_LOOP);
2863       delete_dead_jumptables ();
2864       cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2865       open_dump_file (DFI_loop, decl);
2866       /* CFG is no longer maintained up-to-date.  */
2867       free_bb_for_insn ();
2868
2869       if (flag_rerun_loop_opt)
2870         {
2871           cleanup_barriers ();
2872
2873           /* We only want to perform unrolling once.  */
2874
2875           loop_optimize (insns, rtl_dump_file, 0);
2876
2877           /* The first call to loop_optimize makes some instructions
2878              trivially dead.  We delete those instructions now in the
2879              hope that doing so will make the heuristics in loop work
2880              better and possibly speed up compilation.  */
2881           delete_trivially_dead_insns (insns, max_reg_num ());
2882
2883           /* The regscan pass is currently necessary as the alias
2884                   analysis code depends on this information.  */
2885           reg_scan (insns, max_reg_num (), 1);
2886         }
2887       cleanup_barriers ();
2888       loop_optimize (insns, rtl_dump_file,
2889                      (flag_unroll_loops ? LOOP_UNROLL : 0) | LOOP_BCT
2890                      | (flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0));
2891
2892       /* Loop can create trivially dead instructions.  */
2893       delete_trivially_dead_insns (insns, max_reg_num ());
2894       close_dump_file (DFI_loop, print_rtl, insns);
2895       timevar_pop (TV_LOOP);
2896
2897       ggc_collect ();
2898     }
2899
2900   /* Do control and data flow analysis; wrote some of the results to
2901      the dump file.  */
2902
2903   timevar_push (TV_FLOW);
2904   open_dump_file (DFI_cfg, decl);
2905
2906   find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2907   if (rtl_dump_file)
2908     dump_flow_info (rtl_dump_file);
2909   cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0)
2910                | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2911
2912   /* It may make more sense to mark constant functions after dead code is
2913      eliminated by life_analyzis, but we need to do it early, as -fprofile-arcs
2914      may insert code making function non-constant, but we still must consider
2915      it as constant, otherwise -fbranch-probabilities will not read data back.
2916
2917      life_analyzis rarely eliminates modification of external memory.
2918    */
2919   mark_constant_function ();
2920
2921   close_dump_file (DFI_cfg, print_rtl_with_bb, insns);
2922
2923   /* Do branch profiling and static profile estimation passes.  */
2924   if (optimize > 0 || profile_arc_flag || flag_test_coverage
2925       || flag_branch_probabilities)
2926     {
2927       struct loops loops;
2928
2929       timevar_push (TV_BRANCH_PROB);
2930       open_dump_file (DFI_bp, decl);
2931       if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
2932         branch_prob ();
2933
2934       /* Discover and record the loop depth at the head of each basic
2935          block.  The loop infrastructure does the real job for us.  */
2936       flow_loops_find (&loops, LOOP_TREE);
2937
2938       /* Estimate using heuristics if no profiling info is available.  */
2939       if (flag_guess_branch_prob)
2940         estimate_probability (&loops);
2941
2942       if (rtl_dump_file)
2943         flow_loops_dump (&loops, rtl_dump_file, NULL, 0);
2944
2945       flow_loops_free (&loops);
2946       close_dump_file (DFI_bp, print_rtl_with_bb, insns);
2947       timevar_pop (TV_BRANCH_PROB);
2948     }
2949
2950   if (optimize > 0)
2951     {
2952       timevar_push (TV_CSE2);
2953       open_dump_file (DFI_cse2, decl);
2954       if (rtl_dump_file)
2955         dump_flow_info (rtl_dump_file);
2956
2957       if (flag_rerun_cse_after_loop)
2958         {
2959           timevar_push (TV_JUMP);
2960
2961           reg_scan (insns, max_reg_num (), 0);
2962
2963           timevar_push (TV_IFCVT);
2964           cleanup_cfg (CLEANUP_EXPENSIVE);
2965           if_convert (0);
2966           timevar_pop(TV_IFCVT);
2967
2968           timevar_pop (TV_JUMP);
2969           /* CFG is no longer maintained up-to-date.  */
2970           reg_scan (insns, max_reg_num (), 0);
2971           tem = cse_main (insns, max_reg_num (), 1, rtl_dump_file);
2972           purge_all_dead_edges (0);
2973           delete_trivially_dead_insns (insns, max_reg_num ());
2974
2975           if (tem)
2976             {
2977               timevar_push (TV_JUMP);
2978               rebuild_jump_labels (insns);
2979               cleanup_cfg (CLEANUP_EXPENSIVE);
2980               timevar_pop (TV_JUMP);
2981             }
2982         }
2983
2984       close_dump_file (DFI_cse2, print_rtl_with_bb, insns);
2985       timevar_pop (TV_CSE2);
2986
2987       ggc_collect ();
2988     }
2989
2990   cse_not_expected = 1;
2991
2992   open_dump_file (DFI_life, decl);
2993   regclass_init ();
2994
2995   check_function_return_warnings ();
2996
2997 #ifdef ENABLE_CHECKING
2998   verify_flow_info ();
2999 #endif
3000   life_analysis (insns, rtl_dump_file, PROP_FINAL);
3001   if (optimize)
3002     cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_UPDATE_LIFE
3003                  | (flag_thread_jumps ? CLEANUP_THREADING : 0));
3004   timevar_pop (TV_FLOW);
3005
3006   no_new_pseudos = 1;
3007
3008   if (warn_uninitialized || extra_warnings)
3009     {
3010       uninitialized_vars_warning (DECL_INITIAL (decl));
3011       if (extra_warnings)
3012         setjmp_args_warning ();
3013     }
3014
3015   if (optimize)
3016     {
3017       clear_bb_flags ();
3018       if (initialize_uninitialized_subregs ())
3019         {
3020           /* Insns were inserted, so things might look a bit different.  */
3021           insns = get_insns ();
3022           update_life_info_in_dirty_blocks (UPDATE_LIFE_GLOBAL_RM_NOTES,
3023                                             PROP_LOG_LINKS | PROP_REG_INFO
3024                                             | PROP_DEATH_NOTES);
3025         }
3026     }
3027
3028   close_dump_file (DFI_life, print_rtl_with_bb, insns);
3029
3030   ggc_collect ();
3031
3032   /* If -opt, try combining insns through substitution.  */
3033
3034   if (optimize > 0)
3035     {
3036       int rebuild_jump_labels_after_combine = 0;
3037
3038       timevar_push (TV_COMBINE);
3039       open_dump_file (DFI_combine, decl);
3040
3041       rebuild_jump_labels_after_combine
3042         = combine_instructions (insns, max_reg_num ());
3043
3044       /* Combining insns may have turned an indirect jump into a
3045          direct jump.  Rebuid the JUMP_LABEL fields of jumping
3046          instructions.  */
3047       if (rebuild_jump_labels_after_combine)
3048         {
3049           timevar_push (TV_JUMP);
3050           rebuild_jump_labels (insns);
3051           timevar_pop (TV_JUMP);
3052
3053           cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
3054         }
3055
3056       close_dump_file (DFI_combine, print_rtl_with_bb, insns);
3057       timevar_pop (TV_COMBINE);
3058
3059       ggc_collect ();
3060     }
3061
3062   /* Rerun if-conversion, as combine may have simplified things enough to
3063      now meet sequence length restrictions.  */
3064   if (optimize > 0)
3065     {
3066       timevar_push (TV_IFCVT);
3067       open_dump_file (DFI_ce, decl);
3068
3069       no_new_pseudos = 0;
3070       if_convert (1);
3071       no_new_pseudos = 1;
3072
3073       close_dump_file (DFI_ce, print_rtl_with_bb, insns);
3074       timevar_pop (TV_IFCVT);
3075     }
3076
3077   /* Register allocation pre-pass, to reduce number of moves
3078      necessary for two-address machines.  */
3079   if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
3080     {
3081       timevar_push (TV_REGMOVE);
3082       open_dump_file (DFI_regmove, decl);
3083
3084       regmove_optimize (insns, max_reg_num (), rtl_dump_file);
3085
3086       cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
3087       close_dump_file (DFI_regmove, print_rtl_with_bb, insns);
3088       timevar_pop (TV_REGMOVE);
3089
3090       ggc_collect ();
3091     }
3092
3093   /* Do unconditional splitting before register allocation to allow machine
3094      description to add extra information not needed previously.  */
3095   split_all_insns (1);
3096
3097   /* Any of the several passes since flow1 will have munged register
3098      lifetime data a bit.  */
3099   register_life_up_to_date = 0;
3100
3101 #ifdef OPTIMIZE_MODE_SWITCHING
3102   timevar_push (TV_MODE_SWITCH);
3103
3104   no_new_pseudos = 0;
3105   optimize_mode_switching (NULL);
3106   no_new_pseudos = 1;
3107
3108   timevar_pop (TV_MODE_SWITCH);
3109 #endif
3110
3111   timevar_push (TV_SCHED);
3112
3113 #ifdef INSN_SCHEDULING
3114
3115   /* Print function header into sched dump now
3116      because doing the sched analysis makes some of the dump.  */
3117   if (optimize > 0 && flag_schedule_insns)
3118     {
3119       open_dump_file (DFI_sched, decl);
3120
3121       /* Do control and data sched analysis,
3122          and write some of the results to dump file.  */
3123
3124       schedule_insns (rtl_dump_file);
3125
3126       close_dump_file (DFI_sched, print_rtl_with_bb, insns);
3127
3128       /* Register lifetime information was updated as part of verifying
3129          the schedule.  */
3130       register_life_up_to_date = 1;
3131     }
3132 #endif
3133   timevar_pop (TV_SCHED);
3134
3135   ggc_collect ();
3136
3137   /* Determine if the current function is a leaf before running reload
3138      since this can impact optimizations done by the prologue and
3139      epilogue thus changing register elimination offsets.  */
3140   current_function_is_leaf = leaf_function_p ();
3141
3142   timevar_push (TV_LOCAL_ALLOC);
3143   open_dump_file (DFI_lreg, decl);
3144
3145   /* Allocate pseudo-regs that are used only within 1 basic block.
3146
3147      RUN_JUMP_AFTER_RELOAD records whether or not we need to rerun the
3148      jump optimizer after register allocation and reloading are finished.  */
3149
3150   if (! register_life_up_to_date)
3151     recompute_reg_usage (insns, ! optimize_size);
3152
3153   /* Allocate the reg_renumber array.  */
3154   allocate_reg_info (max_regno, FALSE, TRUE);
3155
3156   /* And the reg_equiv_memory_loc array.  */
3157   reg_equiv_memory_loc = (rtx *) xcalloc (max_regno, sizeof (rtx));
3158
3159   allocate_initial_values (reg_equiv_memory_loc);
3160
3161   regclass (insns, max_reg_num (), rtl_dump_file);
3162   rebuild_label_notes_after_reload = local_alloc ();
3163
3164   timevar_pop (TV_LOCAL_ALLOC);
3165
3166   if (dump_file[DFI_lreg].enabled)
3167     {
3168       timevar_push (TV_DUMP);
3169
3170       dump_flow_info (rtl_dump_file);
3171       dump_local_alloc (rtl_dump_file);
3172
3173       close_dump_file (DFI_lreg, print_rtl_with_bb, insns);
3174       timevar_pop (TV_DUMP);
3175     }
3176
3177   ggc_collect ();
3178
3179   timevar_push (TV_GLOBAL_ALLOC);
3180   open_dump_file (DFI_greg, decl);
3181
3182   /* If optimizing, allocate remaining pseudo-regs.  Do the reload
3183      pass fixing up any insns that are invalid.  */
3184
3185   if (optimize)
3186     failure = global_alloc (rtl_dump_file);
3187   else
3188     {
3189       build_insn_chain (insns);
3190       failure = reload (insns, 0);
3191     }
3192
3193   timevar_pop (TV_GLOBAL_ALLOC);
3194
3195   if (dump_file[DFI_greg].enabled)
3196     {
3197       timevar_push (TV_DUMP);
3198
3199       dump_global_regs (rtl_dump_file);
3200
3201       close_dump_file (DFI_greg, print_rtl_with_bb, insns);
3202       timevar_pop (TV_DUMP);
3203     }
3204
3205   if (failure)
3206     goto exit_rest_of_compilation;
3207
3208   ggc_collect ();
3209
3210   open_dump_file (DFI_postreload, decl);
3211
3212   /* Do a very simple CSE pass over just the hard registers.  */
3213   if (optimize > 0)
3214     {
3215       timevar_push (TV_RELOAD_CSE_REGS);
3216       reload_cse_regs (insns);
3217       timevar_pop (TV_RELOAD_CSE_REGS);
3218     }
3219
3220   /* Register allocation and reloading may have turned an indirect jump into
3221      a direct jump.  If so, we must rebuild the JUMP_LABEL fields of
3222      jumping instructions.  */
3223   if (rebuild_label_notes_after_reload)
3224     {
3225       timevar_push (TV_JUMP);
3226
3227       rebuild_jump_labels (insns);
3228       purge_all_dead_edges (0);
3229
3230       timevar_pop (TV_JUMP);
3231     }
3232
3233   close_dump_file (DFI_postreload, print_rtl_with_bb, insns);
3234
3235   /* Re-create the death notes which were deleted during reload.  */
3236   timevar_push (TV_FLOW2);
3237   open_dump_file (DFI_flow2, decl);
3238
3239 #ifdef ENABLE_CHECKING
3240   verify_flow_info ();
3241 #endif
3242
3243   /* If optimizing, then go ahead and split insns now.  */
3244   if (optimize > 0)
3245     split_all_insns (0);
3246
3247   cleanup_cfg (optimize ? CLEANUP_EXPENSIVE : 0);
3248
3249   /* On some machines, the prologue and epilogue code, or parts thereof,
3250      can be represented as RTL.  Doing so lets us schedule insns between
3251      it and the rest of the code and also allows delayed branch
3252      scheduling to operate in the epilogue.  */
3253   thread_prologue_and_epilogue_insns (insns);
3254
3255   if (optimize)
3256     {
3257       life_analysis (insns, rtl_dump_file, PROP_FINAL);
3258       cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_CROSSJUMP | CLEANUP_UPDATE_LIFE);
3259
3260       /* This is kind of a heuristic.  We need to run combine_stack_adjustments
3261          even for machines with possibly nonzero RETURN_POPS_ARGS
3262          and ACCUMULATE_OUTGOING_ARGS.  We expect that only ports having
3263          push instructions will have popping returns.  */
3264 #ifndef PUSH_ROUNDING
3265       if (!ACCUMULATE_OUTGOING_ARGS)
3266 #endif
3267         combine_stack_adjustments ();
3268
3269       ggc_collect ();
3270     }
3271
3272   flow2_completed = 1;
3273
3274   close_dump_file (DFI_flow2, print_rtl_with_bb, insns);
3275   timevar_pop (TV_FLOW2);
3276
3277 #ifdef HAVE_peephole2
3278   if (optimize > 0 && flag_peephole2)
3279     {
3280       timevar_push (TV_PEEPHOLE2);
3281       open_dump_file (DFI_peephole2, decl);
3282
3283       peephole2_optimize (rtl_dump_file);
3284
3285       close_dump_file (DFI_peephole2, print_rtl_with_bb, insns);
3286       timevar_pop (TV_PEEPHOLE2);
3287     }
3288 #endif
3289
3290   if (flag_rename_registers || flag_cprop_registers)
3291     {
3292       timevar_push (TV_RENAME_REGISTERS);
3293       open_dump_file (DFI_rnreg, decl);
3294
3295       if (flag_rename_registers)
3296         regrename_optimize ();
3297       if (flag_cprop_registers)
3298         copyprop_hardreg_forward ();
3299
3300       close_dump_file (DFI_rnreg, print_rtl_with_bb, insns);
3301       timevar_pop (TV_RENAME_REGISTERS);
3302     }
3303
3304   if (optimize > 0)
3305     {
3306       timevar_push (TV_IFCVT2);
3307       open_dump_file (DFI_ce2, decl);
3308
3309       if_convert (1);
3310
3311       close_dump_file (DFI_ce2, print_rtl_with_bb, insns);
3312       timevar_pop (TV_IFCVT2);
3313     }
3314 #ifdef STACK_REGS
3315   if (optimize)
3316     split_all_insns (1);
3317 #endif
3318
3319 #ifdef INSN_SCHEDULING
3320   if (optimize > 0 && flag_schedule_insns_after_reload)
3321     {
3322       timevar_push (TV_SCHED2);
3323       open_dump_file (DFI_sched2, decl);
3324
3325       /* Do control and data sched analysis again,
3326          and write some more of the results to dump file.  */
3327
3328       split_all_insns (1);
3329
3330       schedule_insns (rtl_dump_file);
3331
3332       close_dump_file (DFI_sched2, print_rtl_with_bb, insns);
3333       timevar_pop (TV_SCHED2);
3334
3335       ggc_collect ();
3336     }
3337 #endif
3338
3339 #ifdef LEAF_REGISTERS
3340   current_function_uses_only_leaf_regs
3341     = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
3342 #endif
3343
3344 #ifdef STACK_REGS
3345   timevar_push (TV_REG_STACK);
3346   open_dump_file (DFI_stack, decl);
3347
3348   reg_to_stack (insns, rtl_dump_file);
3349
3350   close_dump_file (DFI_stack, print_rtl_with_bb, insns);
3351   timevar_pop (TV_REG_STACK);
3352
3353   ggc_collect ();
3354 #endif
3355   if (optimize > 0)
3356     {
3357       timevar_push (TV_REORDER_BLOCKS);
3358       open_dump_file (DFI_bbro, decl);
3359
3360       /* Last attempt to optimize CFG, as scheduling, peepholing
3361          and insn splitting possibly introduced more crossjumping
3362          oppurtuntities.  */
3363       cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
3364                    | CLEANUP_CROSSJUMP);
3365       if (flag_reorder_blocks)
3366         {
3367           reorder_basic_blocks ();
3368           cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
3369         }
3370
3371       close_dump_file (DFI_bbro, print_rtl_with_bb, insns);
3372       timevar_pop (TV_REORDER_BLOCKS);
3373     }
3374   compute_alignments ();
3375
3376   /* CFG is no longer maintained up-to-date.  */
3377   free_bb_for_insn ();
3378
3379   /* If a machine dependent reorganization is needed, call it.  */
3380 #ifdef MACHINE_DEPENDENT_REORG
3381   timevar_push (TV_MACH_DEP);
3382   open_dump_file (DFI_mach, decl);
3383
3384   MACHINE_DEPENDENT_REORG (insns);
3385
3386   close_dump_file (DFI_mach, print_rtl, insns);
3387   timevar_pop (TV_MACH_DEP);
3388
3389   ggc_collect ();
3390 #endif
3391
3392   purge_line_number_notes (insns);
3393   cleanup_barriers ();
3394
3395   /* If a scheduling pass for delayed branches is to be done,
3396      call the scheduling code.  */
3397
3398 #ifdef DELAY_SLOTS
3399   if (optimize > 0 && flag_delayed_branch)
3400     {
3401       timevar_push (TV_DBR_SCHED);
3402       open_dump_file (DFI_dbr, decl);
3403
3404       dbr_schedule (insns, rtl_dump_file);
3405
3406       close_dump_file (DFI_dbr, print_rtl, insns);
3407       timevar_pop (TV_DBR_SCHED);
3408
3409       ggc_collect ();
3410     }
3411 #endif
3412
3413 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3414   timevar_push (TV_SHORTEN_BRANCH);
3415   split_all_insns_noflow ();
3416   timevar_pop (TV_SHORTEN_BRANCH);
3417 #endif
3418
3419   convert_to_eh_region_ranges ();
3420
3421   /* Shorten branches.  */
3422   timevar_push (TV_SHORTEN_BRANCH);
3423   shorten_branches (get_insns ());
3424   timevar_pop (TV_SHORTEN_BRANCH);
3425
3426   current_function_nothrow = nothrow_function_p ();
3427   if (current_function_nothrow)
3428     /* Now we know that this can't throw; set the flag for the benefit
3429        of other functions later in this translation unit.  */
3430     TREE_NOTHROW (current_function_decl) = 1;
3431
3432   /* Now turn the rtl into assembler code.  */
3433
3434   timevar_push (TV_FINAL);
3435   {
3436     rtx x;
3437     const char *fnname;
3438
3439     /* Get the function's name, as described by its RTL.  This may be
3440        different from the DECL_NAME name used in the source file.  */
3441
3442     x = DECL_RTL (decl);
3443     if (GET_CODE (x) != MEM)
3444       abort ();
3445     x = XEXP (x, 0);
3446     if (GET_CODE (x) != SYMBOL_REF)
3447       abort ();
3448     fnname = XSTR (x, 0);
3449
3450     assemble_start_function (decl, fnname);
3451     final_start_function (insns, asm_out_file, optimize);
3452     final (insns, asm_out_file, optimize, 0);
3453     final_end_function ();
3454
3455 #ifdef IA64_UNWIND_INFO
3456     /* ??? The IA-64 ".handlerdata" directive must be issued before
3457        the ".endp" directive that closes the procedure descriptor.  */
3458     output_function_exception_table ();
3459 #endif
3460
3461     assemble_end_function (decl, fnname);
3462
3463 #ifndef IA64_UNWIND_INFO
3464     /* Otherwise, it feels unclean to switch sections in the middle.  */
3465     output_function_exception_table ();
3466 #endif
3467
3468     if (! quiet_flag)
3469       fflush (asm_out_file);
3470
3471     /* Release all memory allocated by flow.  */
3472     free_basic_block_vars (0);
3473
3474     /* Release all memory held by regsets now.  */
3475     regset_release_memory ();
3476   }
3477   timevar_pop (TV_FINAL);
3478
3479   ggc_collect ();
3480
3481   /* Write DBX symbols if requested.  */
3482
3483   /* Note that for those inline functions where we don't initially
3484      know for certain that we will be generating an out-of-line copy,
3485      the first invocation of this routine (rest_of_compilation) will
3486      skip over this code by doing a `goto exit_rest_of_compilation;'.
3487      Later on, finish_compilation will call rest_of_compilation again
3488      for those inline functions that need to have out-of-line copies
3489      generated.  During that call, we *will* be routed past here.  */
3490
3491   timevar_push (TV_SYMOUT);
3492   (*debug_hooks->function_decl) (decl);
3493   timevar_pop (TV_SYMOUT);
3494
3495  exit_rest_of_compilation:
3496
3497   /* In case the function was not output,
3498      don't leave any temporary anonymous types
3499      queued up for sdb output.  */
3500 #ifdef SDB_DEBUGGING_INFO
3501   if (write_symbols == SDB_DEBUG)
3502     sdbout_types (NULL_TREE);
3503 #endif
3504
3505   reload_completed = 0;
3506   flow2_completed = 0;
3507   no_new_pseudos = 0;
3508
3509   timevar_push (TV_FINAL);
3510
3511   /* Clear out the insn_length contents now that they are no
3512      longer valid.  */
3513   init_insn_lengths ();
3514
3515   /* Clear out the real_constant_chain before some of the rtx's
3516      it runs through become garbage.  */
3517   clear_const_double_mem ();
3518
3519   /* Show no temporary slots allocated.  */
3520   init_temp_slots ();
3521
3522   free_basic_block_vars (0);
3523   free_bb_for_insn ();
3524
3525   timevar_pop (TV_FINAL);
3526
3527   /* Make sure volatile mem refs aren't considered valid operands for
3528      arithmetic insns.  We must call this here if this is a nested inline
3529      function, since the above code leaves us in the init_recog state
3530      (from final.c), and the function context push/pop code does not
3531      save/restore volatile_ok.
3532
3533      ??? Maybe it isn't necessary for expand_start_function to call this
3534      anymore if we do it here?  */
3535
3536   init_recog_no_volatile ();
3537
3538   /* We're done with this function.  Free up memory if we can.  */
3539   free_after_parsing (cfun);
3540   if (! DECL_DEFER_OUTPUT (decl))
3541     {
3542       free_after_compilation (cfun);
3543
3544       /* Clear integrate.c's pointer to the cfun structure we just
3545          destroyed.  */
3546       DECL_SAVED_INSNS (decl) = 0;
3547     }
3548   cfun = 0;
3549
3550   ggc_collect ();
3551
3552   timevar_pop (TV_REST_OF_COMPILATION);
3553 }
3554 \f
3555 static void
3556 display_help ()
3557 {
3558   int undoc;
3559   unsigned long i;
3560   const char *lang;
3561
3562   printf (_("  -ffixed-<register>      Mark <register> as being unavailable to the compiler\n"));
3563   printf (_("  -fcall-used-<register>  Mark <register> as being corrupted by function calls\n"));
3564   printf (_("  -fcall-saved-<register> Mark <register> as being preserved across functions\n"));
3565   printf (_("  -finline-limit=<number> Limits the size of inlined functions to <number>\n"));
3566   printf (_("  -fmessage-length=<number> Limits diagnostics messages lengths to <number> characters per line.  0 suppresses line-wrapping\n"));
3567   printf (_("  -fdiagnostics-show-location=[once | every-line] Indicates how often source location information should be emitted, as prefix, at the beginning of diagnostics when line-wrapping\n"));
3568
3569   for (i = ARRAY_SIZE (f_options); i--;)
3570     {
3571       const char *description = f_options[i].description;
3572
3573       if (description != NULL && * description != 0)
3574         printf ("  -f%-21s %s\n",
3575                 f_options[i].string, _(description));
3576     }
3577
3578   printf (_("  -O[number]              Set optimization level to [number]\n"));
3579   printf (_("  -Os                     Optimize for space rather than speed\n"));
3580   for (i = LAST_PARAM; i--;)
3581     {
3582       const char *description = compiler_params[i].help;
3583       const int length = 21-strlen(compiler_params[i].option);
3584
3585       if (description != NULL && * description != 0)
3586         printf ("  --param %s=<value>%.*s%s\n",
3587                 compiler_params[i].option,
3588                 length > 0 ? length : 1, "                     ",
3589                 _(description));
3590     }
3591   printf (_("  -pedantic               Issue warnings needed by strict compliance to ISO C\n"));
3592   printf (_("  -pedantic-errors        Like -pedantic except that errors are produced\n"));
3593   printf (_("  -w                      Suppress warnings\n"));
3594   printf (_("  -W                      Enable extra warnings\n"));
3595
3596   for (i = ARRAY_SIZE (W_options); i--;)
3597     {
3598       const char *description = W_options[i].description;
3599
3600       if (description != NULL && * description != 0)
3601         printf ("  -W%-21s %s\n",
3602                 W_options[i].string, _(description));
3603     }
3604
3605   printf (_("  -Wunused                Enable unused warnings\n"));
3606   printf (_("  -Wlarger-than-<number>  Warn if an object is larger than <number> bytes\n"));
3607   printf (_("  -p                      Enable function profiling\n"));
3608 #if defined (BLOCK_PROFILER) || defined (FUNCTION_BLOCK_PROFILER)
3609   printf (_("  -a                      Enable block profiling \n"));
3610 #endif
3611 #if defined (BLOCK_PROFILER) || defined (FUNCTION_BLOCK_PROFILER) || defined FUNCTION_BLOCK_PROFILER_EXIT
3612   printf (_("  -ax                     Enable jump profiling \n"));
3613 #endif
3614   printf (_("  -o <file>               Place output into <file> \n"));
3615   printf (_("\
3616   -G <number>             Put global and static data smaller than <number>\n\
3617                           bytes into a special section (on some targets)\n"));
3618
3619   for (i = ARRAY_SIZE (debug_args); i--;)
3620     {
3621       if (debug_args[i].description != NULL)
3622         printf ("  -g%-21s %s\n",
3623                 debug_args[i].arg, _(debug_args[i].description));
3624     }
3625
3626   printf (_("  -aux-info <file>        Emit declaration info into <file>\n"));
3627   printf (_("  -quiet                  Do not display functions compiled or elapsed time\n"));
3628   printf (_("  -version                Display the compiler's version\n"));
3629   printf (_("  -d[letters]             Enable dumps from specific passes of the compiler\n"));
3630   printf (_("  -dumpbase <file>        Base name to be used for dumps from specific passes\n"));
3631 #if defined INSN_SCHEDULING
3632   printf (_("  -fsched-verbose=<number> Set the verbosity level of the scheduler\n"));
3633 #endif
3634   printf (_("  --help                  Display this information\n"));
3635
3636   undoc = 0;
3637   lang  = "language";
3638
3639   /* Display descriptions of language specific options.
3640      If there is no description, note that there is an undocumented option.
3641      If the description is empty, do not display anything.  (This allows
3642      options to be deliberately undocumented, for whatever reason).
3643      If the option string is missing, then this is a marker, indicating
3644      that the description string is in fact the name of a language, whose
3645      language specific options are to follow.  */
3646
3647   if (ARRAY_SIZE (documented_lang_options) > 1)
3648     {
3649       printf (_("\nLanguage specific options:\n"));
3650
3651       for (i = 0; i < ARRAY_SIZE (documented_lang_options); i++)
3652         {
3653           const char *description = documented_lang_options[i].description;
3654           const char *option      = documented_lang_options[i].option;
3655
3656           if (description == NULL)
3657             {
3658               undoc = 1;
3659
3660               if (extra_warnings)
3661                 printf (_("  %-23.23s [undocumented]\n"), option);
3662             }
3663           else if (*description == 0)
3664             continue;
3665           else if (option == NULL)
3666             {
3667               if (undoc)
3668                 printf
3669                   (_("\nThere are undocumented %s specific options as well.\n"),
3670                         lang);
3671               undoc = 0;
3672
3673               printf (_("\n Options for %s:\n"), description);
3674
3675               lang = description;
3676             }
3677           else
3678             printf ("  %-23.23s %s\n", option, _(description));
3679         }
3680     }
3681
3682   if (undoc)
3683     printf (_("\nThere are undocumented %s specific options as well.\n"),
3684             lang);
3685
3686   display_target_options ();
3687 }
3688
3689 static void
3690 display_target_options ()
3691 {
3692   int undoc, i;
3693   static bool displayed = false;
3694
3695   /* Avoid double printing for --help --target-help.  */
3696   if (displayed)
3697     return;
3698   displayed = true;
3699
3700   if (ARRAY_SIZE (target_switches) > 1
3701 #ifdef TARGET_OPTIONS
3702       || ARRAY_SIZE (target_options) > 1
3703 #endif
3704       )
3705     {
3706       int doc = 0;
3707
3708       undoc = 0;
3709
3710       printf (_("\nTarget specific options:\n"));
3711
3712       for (i = ARRAY_SIZE (target_switches); i--;)
3713         {
3714           const char *option      = target_switches[i].name;
3715           const char *description = target_switches[i].description;
3716
3717           if (option == NULL || *option == 0)
3718             continue;
3719           else if (description == NULL)
3720             {
3721               undoc = 1;
3722
3723               if (extra_warnings)
3724                 printf (_("  -m%-23.23s [undocumented]\n"), option);
3725             }
3726           else if (* description != 0)
3727             doc += printf ("  -m%-23.23s %s\n", option, _(description));
3728         }
3729
3730 #ifdef TARGET_OPTIONS
3731       for (i = ARRAY_SIZE (target_options); i--;)
3732         {
3733           const char *option      = target_options[i].prefix;
3734           const char *description = target_options[i].description;
3735
3736           if (option == NULL || *option == 0)
3737             continue;
3738           else if (description == NULL)
3739             {
3740               undoc = 1;
3741
3742               if (extra_warnings)
3743                 printf (_("  -m%-23.23s [undocumented]\n"), option);
3744             }
3745           else if (* description != 0)
3746             doc += printf ("  -m%-23.23s %s\n", option, _(description));
3747         }
3748 #endif
3749       if (undoc)
3750         {
3751           if (doc)
3752             printf (_("\nThere are undocumented target specific options as well.\n"));
3753           else
3754             printf (_("  They exist, but they are not documented.\n"));
3755         }
3756     }
3757 }
3758 \f
3759 /* Parse a -d... command line switch.  */
3760
3761 static void
3762 decode_d_option (arg)
3763      const char *arg;
3764 {
3765   int i, c, matched;
3766
3767   while (*arg)
3768     switch (c = *arg++)
3769       {
3770       case 'a':
3771         for (i = 0; i < (int) DFI_MAX; ++i)
3772           dump_file[i].enabled = 1;
3773         break;
3774       case 'A':
3775         flag_debug_asm = 1;
3776         break;
3777       case 'p':
3778         flag_print_asm_name = 1;
3779         break;
3780       case 'P':
3781         flag_dump_rtl_in_asm = 1;
3782         flag_print_asm_name = 1;
3783         break;
3784       case 'v':
3785         graph_dump_format = vcg;
3786         break;
3787       case 'x':
3788         rtl_dump_and_exit = 1;
3789         break;
3790       case 'y':
3791         (*lang_hooks.set_yydebug) (1);
3792         break;
3793       case 'D': /* These are handled by the preprocessor.  */
3794       case 'I':
3795         break;
3796
3797       default:
3798         matched = 0;
3799         for (i = 0; i < (int) DFI_MAX; ++i)
3800           if (c == dump_file[i].debug_switch)
3801             {
3802               dump_file[i].enabled = 1;
3803               matched = 1;
3804             }
3805
3806         if (! matched)
3807           warning ("unrecognized gcc debugging option: %c", c);
3808         break;
3809       }
3810 }
3811
3812 /* Parse a -f... command line switch.  ARG is the value after the -f.
3813    It is safe to access 'ARG - 2' to generate the full switch name.
3814    Return the number of strings consumed.  */
3815
3816 static int
3817 decode_f_option (arg)
3818      const char *arg;
3819 {
3820   int j;
3821   const char *option_value = NULL;
3822
3823   /* Search for the option in the table of binary f options.  */
3824   for (j = ARRAY_SIZE (f_options); j--;)
3825     {
3826       if (!strcmp (arg, f_options[j].string))
3827         {
3828           *f_options[j].variable = f_options[j].on_value;
3829           return 1;
3830         }
3831
3832       if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-'
3833           && ! strcmp (arg + 3, f_options[j].string))
3834         {
3835           *f_options[j].variable = ! f_options[j].on_value;
3836           return 1;
3837         }
3838     }
3839
3840   if (!strcmp (arg, "fast-math"))
3841     set_fast_math_flags ();
3842   else if (!strcmp (arg, "no-fast-math"))
3843     set_no_fast_math_flags ();
3844   else if ((option_value = skip_leading_substring (arg, "inline-limit-"))
3845            || (option_value = skip_leading_substring (arg, "inline-limit=")))
3846     {
3847       int val =
3848         read_integral_parameter (option_value, arg - 2,
3849                                  MAX_INLINE_INSNS);
3850       set_param_value ("max-inline-insns", val);
3851     }
3852 #ifdef INSN_SCHEDULING
3853   else if ((option_value = skip_leading_substring (arg, "sched-verbose=")))
3854     fix_sched_param ("verbose", option_value);
3855 #endif
3856   else if ((option_value = skip_leading_substring (arg, "fixed-")))
3857     fix_register (option_value, 1, 1);
3858   else if ((option_value = skip_leading_substring (arg, "call-used-")))
3859     fix_register (option_value, 0, 1);
3860   else if ((option_value = skip_leading_substring (arg, "call-saved-")))
3861     fix_register (option_value, 0, 0);
3862   else if ((option_value = skip_leading_substring (arg, "align-loops=")))
3863     align_loops = read_integral_parameter (option_value, arg - 2, align_loops);
3864   else if ((option_value = skip_leading_substring (arg, "align-functions=")))
3865     align_functions
3866       = read_integral_parameter (option_value, arg - 2, align_functions);
3867   else if ((option_value = skip_leading_substring (arg, "align-jumps=")))
3868     align_jumps = read_integral_parameter (option_value, arg - 2, align_jumps);
3869   else if ((option_value = skip_leading_substring (arg, "align-labels=")))
3870     align_labels
3871       = read_integral_parameter (option_value, arg - 2, align_labels);
3872   else if ((option_value
3873             = skip_leading_substring (arg, "stack-limit-register=")))
3874     {
3875       int reg = decode_reg_name (option_value);
3876       if (reg < 0)
3877         error ("unrecognized register name `%s'", option_value);
3878       else
3879         stack_limit_rtx = gen_rtx_REG (Pmode, reg);
3880     }
3881   else if ((option_value
3882             = skip_leading_substring (arg, "stack-limit-symbol=")))
3883     {
3884       const char *nm;
3885       nm = ggc_strdup (option_value);
3886       stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, nm);
3887     }
3888   else if ((option_value
3889             = skip_leading_substring (arg, "message-length=")))
3890     output_set_maximum_length
3891       (&global_dc->buffer, read_integral_parameter
3892        (option_value, arg - 2, diagnostic_line_cutoff (global_dc)));
3893   else if ((option_value
3894             = skip_leading_substring (arg, "diagnostics-show-location=")))
3895     {
3896       if (!strcmp (option_value, "once"))
3897         diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
3898       else if (!strcmp (option_value, "every-line"))
3899         diagnostic_prefixing_rule (global_dc)
3900           = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
3901       else
3902         error ("unrecognized option `%s'", arg - 2);
3903     }
3904   else if (!strcmp (arg, "no-stack-limit"))
3905     stack_limit_rtx = NULL_RTX;
3906   else if (!strcmp (arg, "preprocessed"))
3907     /* Recognise this switch but do nothing.  This prevents warnings
3908        about an unrecognized switch if cpplib has not been linked in.  */
3909     ;
3910   else
3911     return 0;
3912
3913   return 1;
3914 }
3915
3916 /* Parse a -W... command line switch.  ARG is the value after the -W.
3917    It is safe to access 'ARG - 2' to generate the full switch name.
3918    Return the number of strings consumed.  */
3919
3920 static int
3921 decode_W_option (arg)
3922      const char *arg;
3923 {
3924   const char *option_value = NULL;
3925   int j;
3926
3927   /* Search for the option in the table of binary W options.  */
3928
3929   for (j = ARRAY_SIZE (W_options); j--;)
3930     {
3931       if (!strcmp (arg, W_options[j].string))
3932         {
3933           *W_options[j].variable = W_options[j].on_value;
3934           return 1;
3935         }
3936
3937       if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-'
3938           && ! strcmp (arg + 3, W_options[j].string))
3939         {
3940           *W_options[j].variable = ! W_options[j].on_value;
3941           return 1;
3942         }
3943     }
3944
3945   if ((option_value = skip_leading_substring (arg, "id-clash-")))
3946     warning ("-Wid-clash-LEN is no longer supported");
3947   else if ((option_value = skip_leading_substring (arg, "larger-than-")))
3948     {
3949       larger_than_size = read_integral_parameter (option_value, arg - 2, -1);
3950
3951       warn_larger_than = larger_than_size != -1;
3952     }
3953   else if (!strcmp (arg, "unused"))
3954     {
3955       set_Wunused (1);
3956     }
3957   else if (!strcmp (arg, "no-unused"))
3958     {
3959       set_Wunused (0);
3960     }
3961   else
3962     return 0;
3963
3964   return 1;
3965 }
3966
3967 /* Parse a -g... command line switch.  ARG is the value after the -g.
3968    It is safe to access 'ARG - 2' to generate the full switch name.
3969    Return the number of strings consumed.  */
3970
3971 static int
3972 decode_g_option (arg)
3973      const char *arg;
3974 {
3975   static unsigned level=0;
3976   /* A lot of code assumes write_symbols == NO_DEBUG if the
3977      debugging level is 0 (thus -gstabs1 -gstabs0 would lose track
3978      of what debugging type has been selected).  This records the
3979      selected type.  It is an error to specify more than one
3980      debugging type.  */
3981   static enum debug_info_type selected_debug_type = NO_DEBUG;
3982   /* Non-zero if debugging format has been explicitly set.
3983      -g and -ggdb don't explicitly set the debugging format so
3984      -gdwarf -g3 is equivalent to -gdwarf3.  */
3985   static int type_explicitly_set_p = 0;
3986   /* Indexed by enum debug_info_type.  */
3987   static const char *const debug_type_names[] =
3988   {
3989     "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
3990   };
3991
3992   /* The maximum admissible debug level value.  */
3993   static const unsigned max_debug_level = 3;
3994
3995   /* Look up ARG in the table.  */
3996   for (da = debug_args; da->arg; da++)
3997     {
3998       const int da_len = strlen (da->arg);
3999
4000       if (da_len == 0 || ! strncmp (arg, da->arg, da_len))
4001         {
4002           enum debug_info_type type = da->debug_type;
4003           const char *p = arg + da_len;
4004
4005           if (*p && ! ISDIGIT (*p))
4006             continue;
4007
4008           /* A debug flag without a level defaults to level 2.
4009              Note we do not want to call read_integral_parameter
4010              for that case since it will call atoi which
4011              will return zero.
4012
4013              ??? We may want to generalize the interface to
4014              read_integral_parameter to better handle this case
4015              if this case shows up often.  */
4016           if (*p)
4017             level = read_integral_parameter (p, 0, max_debug_level + 1);
4018           else
4019             level = (level == 0) ? 2 : level;
4020
4021           if (da_len > 1 && *p && !strncmp (arg, "dwarf", da_len))
4022             {
4023               error ("use -gdwarf -g%d for DWARF v1, level %d",
4024                      level, level);
4025               if (level == 2)
4026                 error ("use -gdwarf-2   for DWARF v2");
4027             }
4028
4029           if (level > max_debug_level)
4030             {
4031               warning ("\
4032 ignoring option `%s' due to invalid debug level specification",
4033                        arg - 2);
4034               level = debug_info_level;
4035             }
4036
4037           if (type == NO_DEBUG)
4038             {
4039               type = PREFERRED_DEBUGGING_TYPE;
4040
4041               if (da_len > 1 && strncmp (arg, "gdb", da_len) == 0)
4042                 {
4043 #if defined (DWARF2_DEBUGGING_INFO) && !defined (LINKER_DOES_NOT_WORK_WITH_DWARF2)
4044                   type = DWARF2_DEBUG;
4045 #else
4046 #ifdef DBX_DEBUGGING_INFO
4047                   type = DBX_DEBUG;
4048 #endif
4049 #endif
4050                 }
4051             }
4052
4053           if (type == NO_DEBUG)
4054             warning ("`%s': unknown or unsupported -g option", arg - 2);
4055
4056           /* Does it conflict with an already selected type?  */
4057           if (type_explicitly_set_p
4058               /* -g/-ggdb don't conflict with anything.  */
4059               && da->debug_type != NO_DEBUG
4060               && type != selected_debug_type)
4061             warning ("`%s' ignored, conflicts with `-g%s'",
4062                      arg - 2, debug_type_names[(int) selected_debug_type]);
4063           else
4064             {
4065               /* If the format has already been set, -g/-ggdb
4066                  only change the debug level.  */
4067               if (type_explicitly_set_p && da->debug_type == NO_DEBUG)
4068                 /* Don't change debugging type.  */
4069                 ;
4070               else
4071                 {
4072                   selected_debug_type = type;
4073                   type_explicitly_set_p = da->debug_type != NO_DEBUG;
4074                 }
4075
4076               write_symbols = (level == 0
4077                                ? NO_DEBUG
4078                                : selected_debug_type);
4079               use_gnu_debug_info_extensions = da->use_extensions_p;
4080               debug_info_level = (enum debug_info_level) level;
4081             }
4082
4083           break;
4084         }
4085     }
4086
4087   if (! da->arg)
4088     return 0;
4089
4090   return 1;
4091 }
4092
4093 /* Decode the first argument in the argv as a language-independent option.
4094    Return the number of strings consumed.  */
4095
4096 static unsigned int
4097 independent_decode_option (argc, argv)
4098      int argc;
4099      char **argv;
4100 {
4101   char *arg = argv[0];
4102
4103   if (arg[0] != '-' || arg[1] == 0)
4104     {
4105       if (arg[0] == '+')
4106         return 0;
4107
4108       filename = arg;
4109
4110       return 1;
4111     }
4112
4113   arg++;
4114
4115   if (!strcmp (arg, "-help"))
4116     {
4117       display_help ();
4118       exit_after_options = 1;
4119     }
4120
4121   if (!strcmp (arg, "-target-help"))
4122     {
4123       display_target_options ();
4124       exit_after_options = 1;
4125     }
4126
4127   if (!strcmp (arg, "-version"))
4128     {
4129       print_version (stderr, "");
4130       exit_after_options = 1;
4131     }
4132
4133   /* Handle '--param <name>=<value>'.  */
4134   if (strcmp (arg, "-param") == 0)
4135     {
4136       char *equal;
4137
4138       if (argc == 1)
4139         {
4140           error ("-param option missing argument");
4141           return 1;
4142         }
4143
4144       /* Get the '<name>=<value>' parameter.  */
4145       arg = argv[1];
4146       /* Look for the `='.  */
4147       equal = strchr (arg, '=');
4148       if (!equal)
4149         error ("invalid --param option: %s", arg);
4150       else
4151         {
4152           int val;
4153
4154           /* Zero out the `=' sign so that we get two separate strings.  */
4155           *equal = '\0';
4156           /* Figure out what value is specified.  */
4157           val = read_integral_parameter (equal + 1, NULL, INVALID_PARAM_VAL);
4158           if (val != INVALID_PARAM_VAL)
4159             set_param_value (arg, val);
4160           else
4161             error ("invalid parameter value `%s'", equal + 1);
4162         }
4163
4164       return 2;
4165     }
4166
4167   if (*arg == 'Y')
4168     arg++;
4169
4170   switch (*arg)
4171     {
4172     default:
4173       return 0;
4174
4175     case 'O':
4176       /* Already been treated in main (). Do nothing.  */
4177       break;
4178
4179     case 'm':
4180       set_target_switch (arg + 1);
4181       break;
4182
4183     case 'f':
4184       return decode_f_option (arg + 1);
4185
4186     case 'g':
4187       return decode_g_option (arg + 1);
4188
4189     case 'd':
4190       if (!strcmp (arg, "dumpbase"))
4191         {
4192           if (argc == 1)
4193             return 0;
4194
4195           dump_base_name = argv[1];
4196           return 2;
4197         }
4198       else
4199         decode_d_option (arg + 1);
4200       break;
4201
4202     case 'p':
4203       if (!strcmp (arg, "pedantic"))
4204         pedantic = 1;
4205       else if (!strcmp (arg, "pedantic-errors"))
4206         flag_pedantic_errors = pedantic = 1;
4207       else if (arg[1] == 0)
4208         profile_flag = 1;
4209       else
4210         return 0;
4211       break;
4212
4213     case 'q':
4214       if (!strcmp (arg, "quiet"))
4215         quiet_flag = 1;
4216       else
4217         return 0;
4218       break;
4219
4220     case 'v':
4221       if (!strcmp (arg, "version"))
4222         version_flag = 1;
4223       else
4224         return 0;
4225       break;
4226
4227     case 'w':
4228       if (arg[1] == 0)
4229         inhibit_warnings = 1;
4230       else
4231         return 0;
4232       break;
4233
4234     case 'W':
4235       if (arg[1] == 0)
4236         {
4237           extra_warnings = 1;
4238           /* We save the value of warn_uninitialized, since if they put
4239              -Wuninitialized on the command line, we need to generate a
4240              warning about not using it without also specifying -O.  */
4241           if (warn_uninitialized != 1)
4242             warn_uninitialized = 2;
4243         }
4244       else
4245         return decode_W_option (arg + 1);
4246       break;
4247
4248     case 'a':
4249       if (!strncmp (arg, "aux-info", 8))
4250         {
4251           if (arg[8] == '\0')
4252             {
4253               if (argc == 1)
4254                 return 0;
4255
4256               aux_info_file_name = argv[1];
4257               flag_gen_aux_info = 1;
4258               return 2;
4259             }
4260           else if (arg[8] == '=')
4261             {
4262               aux_info_file_name = arg + 9;
4263               flag_gen_aux_info = 1;
4264             }
4265           else
4266             return 0;
4267         }
4268       else
4269         return 0;
4270       break;
4271
4272     case 'o':
4273       if (arg[1] == 0)
4274         {
4275           if (argc == 1)
4276             return 0;
4277
4278           asm_file_name = argv[1];
4279           return 2;
4280         }
4281       return 0;
4282
4283     case 'G':
4284       {
4285         int g_switch_val;
4286         int return_val;
4287
4288         if (arg[1] == 0)
4289           {
4290             if (argc == 1)
4291               return 0;
4292
4293             g_switch_val = read_integral_parameter (argv[1], 0, -1);
4294             return_val = 2;
4295           }
4296         else
4297           {
4298             g_switch_val = read_integral_parameter (arg + 1, 0, -1);
4299             return_val = 1;
4300           }
4301
4302         if (g_switch_val == -1)
4303           return_val = 0;
4304         else
4305           {
4306             g_switch_set = TRUE;
4307             g_switch_value = g_switch_val;
4308           }
4309
4310         return return_val;
4311       }
4312     }
4313
4314   return 1;
4315 }
4316 \f
4317 /* Decode -m switches.  */
4318 /* Decode the switch -mNAME.  */
4319
4320 static void
4321 set_target_switch (name)
4322      const char *name;
4323 {
4324   size_t j;
4325   int valid_target_option = 0;
4326
4327   for (j = 0; j < ARRAY_SIZE (target_switches); j++)
4328     if (!strcmp (target_switches[j].name, name))
4329       {
4330         if (target_switches[j].value < 0)
4331           target_flags &= ~-target_switches[j].value;
4332         else
4333           target_flags |= target_switches[j].value;
4334         valid_target_option = 1;
4335       }
4336
4337 #ifdef TARGET_OPTIONS
4338   if (!valid_target_option)
4339     for (j = 0; j < ARRAY_SIZE (target_options); j++)
4340       {
4341         int len = strlen (target_options[j].prefix);
4342         if (!strncmp (target_options[j].prefix, name, len))
4343           {
4344             *target_options[j].variable = name + len;
4345             valid_target_option = 1;
4346           }
4347       }
4348 #endif
4349
4350   if (!valid_target_option)
4351     error ("invalid option `%s'", name);
4352 }
4353 \f
4354 /* Print version information to FILE.
4355    Each line begins with INDENT (for the case where FILE is the
4356    assembler output file).  */
4357
4358 static void
4359 print_version (file, indent)
4360      FILE *file;
4361      const char *indent;
4362 {
4363 #ifndef __VERSION__
4364 #define __VERSION__ "[?]"
4365 #endif
4366   fnotice (file,
4367 #ifdef __GNUC__
4368            "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
4369 #else
4370            "%s%s%s version %s (%s) compiled by CC.\n"
4371 #endif
4372            , indent, *indent != 0 ? " " : "",
4373            lang_hooks.name, version_string, TARGET_NAME,
4374            indent, __VERSION__);
4375 }
4376
4377 /* Print an option value and return the adjusted position in the line.
4378    ??? We don't handle error returns from fprintf (disk full); presumably
4379    other code will catch a disk full though.  */
4380
4381 static int
4382 print_single_switch (file, pos, max, indent, sep, term, type, name)
4383      FILE *file;
4384      int pos, max;
4385      const char *indent, *sep, *term, *type, *name;
4386 {
4387   /* The ultrix fprintf returns 0 on success, so compute the result we want
4388      here since we need it for the following test.  */
4389   int len = strlen (sep) + strlen (type) + strlen (name);
4390
4391   if (pos != 0
4392       && pos + len > max)
4393     {
4394       fprintf (file, "%s", term);
4395       pos = 0;
4396     }
4397   if (pos == 0)
4398     {
4399       fprintf (file, "%s", indent);
4400       pos = strlen (indent);
4401     }
4402   fprintf (file, "%s%s%s", sep, type, name);
4403   pos += len;
4404   return pos;
4405 }
4406
4407 /* Print active target switches to FILE.
4408    POS is the current cursor position and MAX is the size of a "line".
4409    Each line begins with INDENT and ends with TERM.
4410    Each switch is separated from the next by SEP.  */
4411
4412 static void
4413 print_switch_values (file, pos, max, indent, sep, term)
4414      FILE *file;
4415      int pos, max;
4416      const char *indent, *sep, *term;
4417 {
4418   size_t j;
4419   char **p;
4420
4421   /* Print the options as passed.  */
4422
4423   pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
4424                              _("options passed: "), "");
4425
4426   for (p = &save_argv[1]; *p != NULL; p++)
4427     if (**p == '-')
4428       {
4429         /* Ignore these.  */
4430         if (strcmp (*p, "-o") == 0)
4431           {
4432             if (p[1] != NULL)
4433               p++;
4434             continue;
4435           }
4436         if (strcmp (*p, "-quiet") == 0)
4437           continue;
4438         if (strcmp (*p, "-version") == 0)
4439           continue;
4440         if ((*p)[1] == 'd')
4441           continue;
4442
4443         pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
4444       }
4445   if (pos > 0)
4446     fprintf (file, "%s", term);
4447
4448   /* Print the -f and -m options that have been enabled.
4449      We don't handle language specific options but printing argv
4450      should suffice.  */
4451
4452   pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
4453                              _("options enabled: "), "");
4454
4455   for (j = 0; j < ARRAY_SIZE (f_options); j++)
4456     if (*f_options[j].variable == f_options[j].on_value)
4457       pos = print_single_switch (file, pos, max, indent, sep, term,
4458                                  "-f", f_options[j].string);
4459
4460   /* Print target specific options.  */
4461
4462   for (j = 0; j < ARRAY_SIZE (target_switches); j++)
4463     if (target_switches[j].name[0] != '\0'
4464         && target_switches[j].value > 0
4465         && ((target_switches[j].value & target_flags)
4466             == target_switches[j].value))
4467       {
4468         pos = print_single_switch (file, pos, max, indent, sep, term,
4469                                    "-m", target_switches[j].name);
4470       }
4471
4472 #ifdef TARGET_OPTIONS
4473   for (j = 0; j < ARRAY_SIZE (target_options); j++)
4474     if (*target_options[j].variable != NULL)
4475       {
4476         char prefix[256];
4477         sprintf (prefix, "-m%s", target_options[j].prefix);
4478         pos = print_single_switch (file, pos, max, indent, sep, term,
4479                                    prefix, *target_options[j].variable);
4480       }
4481 #endif
4482
4483   fprintf (file, "%s", term);
4484 }
4485 \f
4486 /* Open assembly code output file.  Do this even if -fsyntax-only is
4487    on, because then the driver will have provided the name of a
4488    temporary file or bit bucket for us.  NAME is the file specified on
4489    the command line, possibly NULL.  */
4490 static void
4491 init_asm_output (name)
4492      const char *name;
4493 {
4494   if (name == NULL && asm_file_name == 0)
4495     asm_out_file = stdout;
4496   else
4497     {
4498       if (asm_file_name == 0)
4499         {
4500           int len = strlen (dump_base_name);
4501           char *dumpname = (char *) xmalloc (len + 6);
4502           memcpy (dumpname, dump_base_name, len + 1);
4503           strip_off_ending (dumpname, len);
4504           strcat (dumpname, ".s");
4505           asm_file_name = dumpname;
4506         }
4507       if (!strcmp (asm_file_name, "-"))
4508         asm_out_file = stdout;
4509       else
4510         asm_out_file = fopen (asm_file_name, "w");
4511       if (asm_out_file == 0)
4512         fatal_io_error ("can't open %s for writing", asm_file_name);
4513     }
4514
4515 #ifdef IO_BUFFER_SIZE
4516   setvbuf (asm_out_file, (char *) xmalloc (IO_BUFFER_SIZE),
4517            _IOFBF, IO_BUFFER_SIZE);
4518 #endif
4519
4520   if (!flag_syntax_only)
4521     {
4522 #ifdef ASM_FILE_START
4523       ASM_FILE_START (asm_out_file);
4524 #endif
4525
4526 #ifdef ASM_COMMENT_START
4527       if (flag_verbose_asm)
4528         {
4529           /* Print the list of options in effect.  */
4530           print_version (asm_out_file, ASM_COMMENT_START);
4531           print_switch_values (asm_out_file, 0, MAX_LINE,
4532                                ASM_COMMENT_START, " ", "\n");
4533           /* Add a blank line here so it appears in assembler output but not
4534              screen output.  */
4535           fprintf (asm_out_file, "\n");
4536         }
4537 #endif
4538     }
4539 }
4540 \f
4541 /* Initialization of the front end environment, before command line
4542    options are parsed.  Signal handlers, internationalization etc.
4543    ARGV0 is main's argv[0].  */
4544 static void
4545 general_init (argv0)
4546      char *argv0;
4547 {
4548   char *p;
4549
4550   p = argv0 + strlen (argv0);
4551   while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
4552     --p;
4553   progname = p;
4554
4555   xmalloc_set_program_name (progname);
4556
4557   gcc_init_libintl ();
4558
4559   /* Install handler for SIGFPE, which may be received while we do
4560      compile-time floating point arithmetic.  */
4561   signal (SIGFPE, float_signal);
4562
4563   /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages.  */
4564 #ifdef SIGSEGV
4565   signal (SIGSEGV, crash_signal);
4566 #endif
4567 #ifdef SIGILL
4568   signal (SIGILL, crash_signal);
4569 #endif
4570 #ifdef SIGBUS
4571   signal (SIGBUS, crash_signal);
4572 #endif
4573 #ifdef SIGABRT
4574   signal (SIGABRT, crash_signal);
4575 #endif
4576 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
4577   signal (SIGIOT, crash_signal);
4578 #endif
4579
4580   /* Initialize the diagnostics reporting machinery, so option parsing
4581      can give warnings and errors.  */
4582   diagnostic_initialize (global_dc);
4583 }
4584 \f
4585 /* Parse command line options and set default flag values, called
4586    after language-independent option-independent initialization.  Do
4587    minimal options processing.  Outputting diagnostics is OK, but GC
4588    and identifier hashtables etc. are not initialized yet.  */
4589 static void
4590 parse_options_and_default_flags (argc, argv)
4591      int argc;
4592      char **argv;
4593 {
4594   int i;
4595
4596   /* Save in case md file wants to emit args as a comment.  */
4597   save_argc = argc;
4598   save_argv = argv;
4599
4600   /* Initialize register usage now so switches may override.  */
4601   init_reg_sets ();
4602
4603   /* Register the language-independent parameters.  */
4604   add_params (lang_independent_params, LAST_PARAM);
4605
4606   /* Perform language-specific options initialization.  */
4607   (*lang_hooks.init_options) ();
4608
4609   /* Scan to see what optimization level has been specified.  That will
4610      determine the default value of many flags.  */
4611   for (i = 1; i < argc; i++)
4612     {
4613       if (!strcmp (argv[i], "-O"))
4614         {
4615           optimize = 1;
4616           optimize_size = 0;
4617         }
4618       else if (argv[i][0] == '-' && argv[i][1] == 'O')
4619         {
4620           /* Handle -Os, -O2, -O3, -O69, ...  */
4621           char *p = &argv[i][2];
4622
4623           if ((p[0] == 's') && (p[1] == 0))
4624             {
4625               optimize_size = 1;
4626
4627               /* Optimizing for size forces optimize to be 2.  */
4628               optimize = 2;
4629             }
4630           else
4631             {
4632               const int optimize_val = read_integral_parameter (p, p - 2, -1);
4633               if (optimize_val != -1)
4634                 {
4635                   optimize = optimize_val;
4636                   optimize_size = 0;
4637                 }
4638             }
4639         }
4640     }
4641
4642   if (!optimize)
4643     {
4644       flag_merge_constants = 0;
4645     }
4646
4647   if (optimize >= 1)
4648     {
4649       flag_defer_pop = 1;
4650       flag_thread_jumps = 1;
4651 #ifdef DELAY_SLOTS
4652       flag_delayed_branch = 1;
4653 #endif
4654 #ifdef CAN_DEBUG_WITHOUT_FP
4655       flag_omit_frame_pointer = 1;
4656 #endif
4657       flag_guess_branch_prob = 1;
4658       flag_cprop_registers = 1;
4659     }
4660
4661   if (optimize >= 2)
4662     {
4663       flag_optimize_sibling_calls = 1;
4664       flag_cse_follow_jumps = 1;
4665       flag_cse_skip_blocks = 1;
4666       flag_gcse = 1;
4667       flag_expensive_optimizations = 1;
4668       flag_strength_reduce = 1;
4669       flag_rerun_cse_after_loop = 1;
4670       flag_rerun_loop_opt = 1;
4671       flag_caller_saves = 1;
4672       flag_force_mem = 1;
4673       flag_peephole2 = 1;
4674 #ifdef INSN_SCHEDULING
4675       flag_schedule_insns = 1;
4676       flag_schedule_insns_after_reload = 1;
4677 #endif
4678       flag_regmove = 1;
4679       flag_strict_aliasing = 1;
4680       flag_delete_null_pointer_checks = 1;
4681       flag_reorder_blocks = 1;
4682     }
4683
4684   if (optimize >= 3)
4685     {
4686       flag_inline_functions = 1;
4687       flag_rename_registers = 1;
4688     }
4689
4690   if (optimize < 2 || optimize_size)
4691     {
4692       align_loops = 1;
4693       align_jumps = 1;
4694       align_labels = 1;
4695       align_functions = 1;
4696     }
4697
4698   /* Initialize whether `char' is signed.  */
4699   flag_signed_char = DEFAULT_SIGNED_CHAR;
4700 #ifdef DEFAULT_SHORT_ENUMS
4701   /* Initialize how much space enums occupy, by default.  */
4702   flag_short_enums = DEFAULT_SHORT_ENUMS;
4703 #endif
4704
4705   /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
4706      modify it.  */
4707   target_flags = 0;
4708   set_target_switch ("");
4709
4710   /* Unwind tables are always present in an ABI-conformant IA-64
4711      object file, so the default should be ON.  */
4712 #ifdef IA64_UNWIND_INFO
4713   flag_unwind_tables = IA64_UNWIND_INFO;
4714 #endif
4715
4716 #ifdef OPTIMIZATION_OPTIONS
4717   /* Allow default optimizations to be specified on a per-machine basis.  */
4718   OPTIMIZATION_OPTIONS (optimize, optimize_size);
4719 #endif
4720
4721   /* Perform normal command line switch decoding.  */
4722   for (i = 1; i < argc;)
4723     {
4724       int lang_processed;
4725       int indep_processed;
4726
4727       /* Give the language a chance to decode the option for itself.  */
4728       lang_processed = (*lang_hooks.decode_option) (argc - i, argv + i);
4729
4730       if (lang_processed >= 0)
4731         /* Now see if the option also has a language independent meaning.
4732            Some options are both language specific and language independent,
4733            eg --help.  */
4734         indep_processed = independent_decode_option (argc - i, argv + i);
4735       else
4736         {
4737           lang_processed = -lang_processed;
4738           indep_processed = 0;
4739         }
4740
4741       if (lang_processed || indep_processed)
4742         i += MAX (lang_processed, indep_processed);
4743       else
4744         {
4745           const char *option = NULL;
4746           const char *lang = NULL;
4747           unsigned int j;
4748
4749           /* It is possible that the command line switch is not valid for the
4750              current language, but it is valid for another language.  In order
4751              to be compatible with previous versions of the compiler (which
4752              did not issue an error message in this case) we check for this
4753              possibility here.  If we do find a match, then if extra_warnings
4754              is set we generate a warning message, otherwise we will just
4755              ignore the option.  */
4756           for (j = 0; j < ARRAY_SIZE (documented_lang_options); j++)
4757             {
4758               option = documented_lang_options[j].option;
4759
4760               if (option == NULL)
4761                 lang = documented_lang_options[j].description;
4762               else if (! strncmp (argv[i], option, strlen (option)))
4763                 break;
4764             }
4765
4766           if (j != ARRAY_SIZE (documented_lang_options))
4767             {
4768               if (extra_warnings)
4769                 {
4770                   warning ("ignoring command line option '%s'", argv[i]);
4771                   if (lang)
4772                     warning
4773                       ("(it is valid for %s but not the selected language)",
4774                        lang);
4775                 }
4776             }
4777           else if (argv[i][0] == '-' && argv[i][1] == 'g')
4778             warning ("`%s': unknown or unsupported -g option", &argv[i][2]);
4779           else
4780             error ("unrecognized option `%s'", argv[i]);
4781
4782           i++;
4783         }
4784     }
4785
4786   /* Set flag_no_inline before the post_options () hook.  The C front
4787      ends use it to determine tree inlining defaults.  FIXME: such
4788      code should be lang-independent when all front ends use tree
4789      inlining, in which case it, and this condition, should be moved
4790      to the top of process_options() instead.  */
4791   if (optimize == 0)
4792     {
4793       /* Inlining does not work if not optimizing,
4794          so force it not to be done.  */
4795       flag_no_inline = 1;
4796       warn_inline = 0;
4797
4798       /* The c_decode_option function and decode_option hook set
4799          this to `2' if -Wall is used, so we can avoid giving out
4800          lots of errors for people who don't realize what -Wall does.  */
4801       if (warn_uninitialized == 1)
4802         warning ("-Wuninitialized is not supported without -O");
4803     }
4804
4805   /* All command line options have been parsed; allow the front end to
4806      perform consistency checks, etc.  */
4807   (*lang_hooks.post_options) ();
4808 }
4809 \f
4810 /* Process the options that have been parsed.  */
4811 static void
4812 process_options ()
4813 {
4814 #ifdef OVERRIDE_OPTIONS
4815   /* Some machines may reject certain combinations of options.  */
4816   OVERRIDE_OPTIONS;
4817 #endif
4818
4819   /* Set up the align_*_log variables, defaulting them to 1 if they
4820      were still unset.  */
4821   if (align_loops <= 0) align_loops = 1;
4822   if (align_loops_max_skip > align_loops || !align_loops)
4823     align_loops_max_skip = align_loops - 1;
4824   align_loops_log = floor_log2 (align_loops * 2 - 1);
4825   if (align_jumps <= 0) align_jumps = 1;
4826   if (align_jumps_max_skip > align_jumps || !align_jumps)
4827     align_jumps_max_skip = align_jumps - 1;
4828   align_jumps_log = floor_log2 (align_jumps * 2 - 1);
4829   if (align_labels <= 0) align_labels = 1;
4830   align_labels_log = floor_log2 (align_labels * 2 - 1);
4831   if (align_labels_max_skip > align_labels || !align_labels)
4832     align_labels_max_skip = align_labels - 1;
4833   if (align_functions <= 0) align_functions = 1;
4834   align_functions_log = floor_log2 (align_functions * 2 - 1);
4835
4836   /* Unrolling all loops implies that standard loop unrolling must also
4837      be done.  */
4838   if (flag_unroll_all_loops)
4839     flag_unroll_loops = 1;
4840   /* Loop unrolling requires that strength_reduction be on also.  Silently
4841      turn on strength reduction here if it isn't already on.  Also, the loop
4842      unrolling code assumes that cse will be run after loop, so that must
4843      be turned on also.  */
4844   if (flag_unroll_loops)
4845     {
4846       flag_strength_reduce = 1;
4847       flag_rerun_cse_after_loop = 1;
4848     }
4849
4850   if (flag_non_call_exceptions)
4851     flag_asynchronous_unwind_tables = 1;
4852   if (flag_asynchronous_unwind_tables)
4853     flag_unwind_tables = 1;
4854
4855   /* Warn about options that are not supported on this machine.  */
4856 #ifndef INSN_SCHEDULING
4857   if (flag_schedule_insns || flag_schedule_insns_after_reload)
4858     warning ("instruction scheduling not supported on this target machine");
4859 #endif
4860 #ifndef DELAY_SLOTS
4861   if (flag_delayed_branch)
4862     warning ("this target machine does not have delayed branches");
4863 #endif
4864
4865   /* Some operating systems do not allow profiling without a frame
4866      pointer.  */
4867   if (!TARGET_ALLOWS_PROFILING_WITHOUT_FRAME_POINTER
4868       && profile_flag
4869       && flag_omit_frame_pointer)
4870     {
4871       error ("profiling does not work without a frame pointer");
4872       flag_omit_frame_pointer = 0;
4873     }
4874     
4875   user_label_prefix = USER_LABEL_PREFIX;
4876   if (flag_leading_underscore != -1)
4877     {
4878       /* If the default prefix is more complicated than "" or "_",
4879          issue a warning and ignore this option.  */
4880       if (user_label_prefix[0] == 0 ||
4881           (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
4882         {
4883           user_label_prefix = flag_leading_underscore ? "_" : "";
4884         }
4885       else
4886         warning ("-f%sleading-underscore not supported on this target machine",
4887                  flag_leading_underscore ? "" : "no-");
4888     }
4889
4890   /* If we are in verbose mode, write out the version and maybe all the
4891      option flags in use.  */
4892   if (version_flag)
4893     {
4894       print_version (stderr, "");
4895       if (! quiet_flag)
4896         print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
4897     }
4898
4899   if (! quiet_flag)
4900     time_report = 1;
4901
4902   if (flag_syntax_only)
4903     {
4904       write_symbols = NO_DEBUG;
4905       profile_flag = 0;
4906     }
4907
4908   /* Now we know write_symbols, set up the debug hooks based on it.
4909      By default we do nothing for debug output.  */
4910 #if defined(DBX_DEBUGGING_INFO)
4911   if (write_symbols == DBX_DEBUG)
4912     debug_hooks = &dbx_debug_hooks;
4913 #endif
4914 #if defined(XCOFF_DEBUGGING_INFO)
4915   if (write_symbols == XCOFF_DEBUG)
4916     debug_hooks = &xcoff_debug_hooks;
4917 #endif
4918 #ifdef SDB_DEBUGGING_INFO
4919   if (write_symbols == SDB_DEBUG)
4920     debug_hooks = &sdb_debug_hooks;
4921 #endif
4922 #ifdef DWARF_DEBUGGING_INFO
4923   if (write_symbols == DWARF_DEBUG)
4924     debug_hooks = &dwarf_debug_hooks;
4925 #endif
4926 #ifdef DWARF2_DEBUGGING_INFO
4927   if (write_symbols == DWARF2_DEBUG)
4928     debug_hooks = &dwarf2_debug_hooks;
4929 #endif
4930 #ifdef VMS_DEBUGGING_INFO
4931   if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
4932     debug_hooks = &vmsdbg_debug_hooks;
4933 #endif
4934
4935   /* If auxiliary info generation is desired, open the output file.
4936      This goes in the same directory as the source file--unlike
4937      all the other output files.  */
4938   if (flag_gen_aux_info)
4939     {
4940       aux_info_file = fopen (aux_info_file_name, "w");
4941       if (aux_info_file == 0)
4942         fatal_io_error ("can't open %s", aux_info_file_name);
4943     }
4944
4945   if (! targetm.have_named_sections)
4946     {
4947       if (flag_function_sections)
4948         {
4949           warning ("-ffunction-sections not supported for this target");
4950           flag_function_sections = 0;
4951         }
4952       if (flag_data_sections)
4953         {
4954           warning ("-fdata-sections not supported for this target");
4955           flag_data_sections = 0;
4956         }
4957     }
4958
4959   if (flag_function_sections && profile_flag)
4960     {
4961       warning ("-ffunction-sections disabled; it makes profiling impossible");
4962       flag_function_sections = 0;
4963     }
4964
4965 #ifndef HAVE_prefetch
4966   if (flag_prefetch_loop_arrays)
4967     {
4968       warning ("-fprefetch-loop-arrays not supported for this target");
4969       flag_prefetch_loop_arrays = 0;
4970     }
4971 #else
4972   if (flag_prefetch_loop_arrays && !HAVE_prefetch)
4973     {
4974       warning ("-fprefetch-loop-arrays not supported for this target (try -march switches)");
4975       flag_prefetch_loop_arrays = 0;
4976     }
4977 #endif
4978
4979   /* This combination of options isn't handled for i386 targets and doesn't
4980      make much sense anyway, so don't allow it.  */
4981   if (flag_prefetch_loop_arrays && optimize_size)
4982     {
4983       warning ("-fprefetch-loop-arrays is not supported with -Os");
4984       flag_prefetch_loop_arrays = 0;
4985     }
4986
4987 #ifndef OBJECT_FORMAT_ELF
4988   if (flag_function_sections && write_symbols != NO_DEBUG)
4989     warning ("-ffunction-sections may affect debugging on some targets");
4990 #endif
4991 }
4992 \f
4993 /* Language-independent initialization, before language-dependent
4994    initialization.  */
4995 static void
4996 lang_independent_init ()
4997 {
4998   decl_printable_name = decl_name;
4999   lang_expand_expr = (lang_expand_expr_t) do_abort;
5000
5001   /* Initialize the garbage-collector, and string pools.  */
5002   init_ggc ();
5003   ggc_add_rtx_root (&stack_limit_rtx, 1);
5004   ggc_add_tree_root (&current_function_decl, 1);
5005   ggc_add_tree_root (&current_function_func_begin_label, 1);
5006
5007   init_stringpool ();
5008   init_obstacks ();
5009
5010   init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
5011                   || debug_info_level == DINFO_LEVEL_VERBOSE
5012 #ifdef VMS_DEBUGGING_INFO
5013                     /* Enable line number info for traceback */
5014                     || debug_info_level > DINFO_LEVEL_NONE
5015 #endif
5016                     || flag_test_coverage
5017                     || warn_notreached);
5018   init_regs ();
5019   init_alias_once ();
5020   init_stmt ();
5021   init_loop ();
5022   init_reload ();
5023   init_function_once ();
5024   init_stor_layout_once ();
5025   init_varasm_once ();
5026   init_EXPR_INSN_LIST_cache ();
5027
5028   /* The following initialization functions need to generate rtl, so
5029      provide a dummy function context for them.  */
5030   init_dummy_function_start ();
5031   init_expmed ();
5032   init_expr_once ();
5033   if (flag_caller_saves)
5034     init_caller_save ();
5035   expand_dummy_function_end ();
5036 }
5037 \f
5038 /* Language-dependent initialization.  Returns non-zero on success.  */
5039 static int
5040 lang_dependent_init (name)
5041      const char *name;
5042 {
5043   if (dump_base_name == 0)
5044     dump_base_name = name ? name : "gccdump";
5045
5046   /* Front-end initialization.  This hook can assume that GC,
5047      identifier hashes etc. are set up, but debug initialization is
5048      not done yet.  This routine must return the original filename
5049      (e.g. foo.i -> foo.c) so can correctly initialize debug output.  */
5050   name = (*lang_hooks.init) (name);
5051   if (name == NULL)
5052     return 0;
5053
5054   /* Is this duplication necessary?  */
5055   name = ggc_strdup (name);
5056   main_input_filename = input_filename = name;
5057   init_asm_output (name);
5058
5059   /* These create various _DECL nodes, so need to be called after the
5060      front end is initialized.  */
5061   init_eh ();
5062   init_optabs ();
5063
5064   /* Put an entry on the input file stack for the main input file.  */
5065   push_srcloc (input_filename, 0);
5066
5067   /* If dbx symbol table desired, initialize writing it and output the
5068      predefined types.  */
5069   timevar_push (TV_SYMOUT);
5070
5071 #ifdef DWARF2_UNWIND_INFO
5072   if (dwarf2out_do_frame ())
5073     dwarf2out_frame_init ();
5074 #endif
5075
5076   /* Now we have the correct original filename, we can initialize
5077      debug output.  */
5078   (*debug_hooks->init) (name);
5079
5080   timevar_pop (TV_SYMOUT);
5081
5082   return 1;
5083 }
5084 \f
5085 /* Clean up: close opened files, etc.  */
5086
5087 static void
5088 finalize ()
5089 {
5090   /* Close the dump files.  */
5091   if (flag_gen_aux_info)
5092     {
5093       fclose (aux_info_file);
5094       if (errorcount)
5095         unlink (aux_info_file_name);
5096     }
5097
5098   /* Close non-debugging input and output files.  Take special care to note
5099      whether fclose returns an error, since the pages might still be on the
5100      buffer chain while the file is open.  */
5101
5102   if (asm_out_file)
5103     {
5104       if (ferror (asm_out_file) != 0)
5105         fatal_io_error ("error writing to %s", asm_file_name);
5106       if (fclose (asm_out_file) != 0)
5107         fatal_io_error ("error closing %s", asm_file_name);
5108     }
5109
5110   /* Do whatever is necessary to finish printing the graphs.  */
5111   if (graph_dump_format != no_graph)
5112     {
5113       int i;
5114
5115       for (i = 0; i < (int) DFI_MAX; ++i)
5116         if (dump_file[i].initialized && dump_file[i].graph_dump_p)
5117           {
5118             char seq[16];
5119             char *suffix;
5120
5121             sprintf (seq, DUMPFILE_FORMAT, i);
5122             suffix = concat (seq, dump_file[i].extension, NULL);
5123             finish_graph_dump_file (dump_base_name, suffix);
5124             free (suffix);
5125           }
5126     }
5127
5128   if (mem_report)
5129     {
5130       ggc_print_statistics ();
5131       stringpool_statistics ();
5132       dump_tree_statistics ();
5133     }
5134
5135   /* Free up memory for the benefit of leak detectors.  */
5136   free_reg_info ();
5137
5138   /* Language-specific end of compilation actions.  */
5139   (*lang_hooks.finish) ();
5140 }
5141 \f
5142 /* Initialize the compiler, and compile the input file.  */
5143 static void
5144 do_compile ()
5145 {
5146   /* The bulk of command line switch processing.  */
5147   process_options ();
5148
5149   /* We cannot start timing until after options are processed since that
5150      says if we run timers or not.  */
5151   init_timevar ();
5152   timevar_start (TV_TOTAL);
5153
5154   /* Language-independent initialization.  Also sets up GC, identifier
5155      hashes etc.  */
5156   lang_independent_init ();
5157
5158   /* Language-dependent initialization.  Returns true on success.  */
5159   if (lang_dependent_init (filename))
5160     compile_file ();
5161
5162   finalize ();
5163
5164   /* Stop timing and print the times.  */
5165   timevar_stop (TV_TOTAL);
5166   timevar_print (stderr);
5167 }
5168 \f
5169 /* Entry point of cc1, cc1plus, jc1, f771, etc.
5170    Decode command args, then call compile_file.
5171    Exit code is FATAL_EXIT_CODE if can't open files or if there were
5172    any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
5173
5174    It is not safe to call this function more than once.  */
5175
5176 int
5177 toplev_main (argc, argv)
5178      int argc;
5179      char **argv;
5180 {
5181   hex_init ();
5182
5183   /* Initialization of GCC's environment, and diagnostics.  */
5184   general_init (argv [0]);
5185
5186   /* Parse the options and do minimal processing; basically just
5187      enough to default flags appropriately.  */
5188   parse_options_and_default_flags (argc, argv);
5189
5190   /* Exit early if we can (e.g. -help).  */
5191   if (!exit_after_options)
5192     do_compile ();
5193
5194   if (errorcount || sorrycount)
5195     return (FATAL_EXIT_CODE);
5196
5197   return (SUCCESS_EXIT_CODE);
5198 }