OSDN Git Service

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