OSDN Git Service

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