OSDN Git Service

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