OSDN Git Service

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