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