OSDN Git Service

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