OSDN Git Service

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