OSDN Git Service

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