OSDN Git Service

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