OSDN Git Service

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