OSDN Git Service

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