OSDN Git Service

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