OSDN Git Service

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