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