OSDN Git Service

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