OSDN Git Service

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