OSDN Git Service

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