OSDN Git Service

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