OSDN Git Service

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