OSDN Git Service

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