OSDN Git Service

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