OSDN Git Service

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