2003-09-04 Eric Christopher <echristo@redhat.com>
[official-gcc.git] / gcc / toplev.c
blobb7d23b2ee438fea40a1ab330315ccec1aa266be2
1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5 This file is part of GCC.
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.
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.
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. */
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. */
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>
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
37 #endif
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
41 #endif
43 #include "input.h"
44 #include "tree.h"
45 #include "rtl.h"
46 #include "tm_p.h"
47 #include "flags.h"
48 #include "insn-attr.h"
49 #include "insn-config.h"
50 #include "insn-flags.h"
51 #include "hard-reg-set.h"
52 #include "recog.h"
53 #include "output.h"
54 #include "except.h"
55 #include "function.h"
56 #include "toplev.h"
57 #include "expr.h"
58 #include "basic-block.h"
59 #include "intl.h"
60 #include "ggc.h"
61 #include "graph.h"
62 #include "loop.h"
63 #include "regs.h"
64 #include "timevar.h"
65 #include "diagnostic.h"
66 #include "ssa.h"
67 #include "params.h"
68 #include "reload.h"
69 #include "dwarf2asm.h"
70 #include "integrate.h"
71 #include "real.h"
72 #include "debug.h"
73 #include "target.h"
74 #include "langhooks.h"
75 #include "cfglayout.h"
76 #include "cfgloop.h"
77 #include "hosthooks.h"
78 #include "cgraph.h"
79 #include "opts.h"
80 #include "coverage.h"
82 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
83 #include "dwarf2out.h"
84 #endif
86 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
87 #include "dbxout.h"
88 #endif
90 #ifdef SDB_DEBUGGING_INFO
91 #include "sdbout.h"
92 #endif
94 #ifdef XCOFF_DEBUGGING_INFO
95 #include "xcoffout.h" /* Needed for external data
96 declarations for e.g. AIX 4.x. */
97 #endif
99 /* Carry information from ASM_DECLARE_OBJECT_NAME
100 to ASM_FINISH_DECLARE_OBJECT. */
102 extern int size_directive_output;
103 extern tree last_assemble_variable_decl;
105 extern void reg_alloc (void);
107 static void general_init (const char *);
108 static void do_compile (void);
109 static void process_options (void);
110 static void backend_init (void);
111 static int lang_dependent_init (const char *);
112 static void init_asm_output (const char *);
113 static void finalize (void);
115 static void crash_signal (int) ATTRIBUTE_NORETURN;
116 static void setup_core_dumping (void);
117 static void compile_file (void);
119 static int print_single_switch (FILE *, int, int, const char *,
120 const char *, const char *,
121 const char *, const char *);
122 static void print_switch_values (FILE *, int, int, const char *,
123 const char *, const char *);
125 /* Rest of compilation helper functions. */
126 static bool rest_of_handle_inlining (tree);
127 static rtx rest_of_handle_ssa (tree, rtx);
128 static void rest_of_handle_cse (tree, rtx);
129 static void rest_of_handle_cse2 (tree, rtx);
130 static void rest_of_handle_gcse (tree, rtx);
131 static void rest_of_handle_life (tree, rtx);
132 static void rest_of_handle_loop_optimize (tree, rtx);
133 static void rest_of_handle_loop2 (tree, rtx);
134 static void rest_of_handle_jump_bypass (tree, rtx);
135 static void rest_of_handle_sibling_calls (rtx);
136 static void rest_of_handle_null_pointer (tree, rtx);
137 static void rest_of_handle_addressof (tree, rtx);
138 static void rest_of_handle_cfg (tree, rtx);
139 static void rest_of_handle_branch_prob (tree, rtx);
140 static void rest_of_handle_if_conversion (tree, rtx);
141 static void rest_of_handle_if_after_combine (tree, rtx);
142 static void rest_of_handle_tracer (tree, rtx);
143 static void rest_of_handle_combine (tree, rtx);
144 static void rest_of_handle_regmove (tree, rtx);
145 #ifdef INSN_SCHEDULING
146 static void rest_of_handle_sched (tree, rtx);
147 static void rest_of_handle_sched2 (tree, rtx);
148 #endif
149 static bool rest_of_handle_new_regalloc (tree, rtx, int *);
150 static bool rest_of_handle_old_regalloc (tree, rtx, int *);
151 static void rest_of_handle_regrename (tree, rtx);
152 static void rest_of_handle_reorder_blocks (tree, rtx);
153 #ifdef STACK_REGS
154 static void rest_of_handle_stack_regs (tree, rtx);
155 #endif
156 static void rest_of_handle_machine_reorg (tree, rtx);
157 #ifdef DELAY_SLOTS
158 static void rest_of_handle_delay_slots (tree, rtx);
159 #endif
160 static void rest_of_handle_final (tree, rtx);
162 /* Nonzero to dump debug info whilst parsing (-dy option). */
163 static int set_yydebug;
165 /* True if we don't need a backend (e.g. preprocessing only). */
166 static bool no_backend;
168 /* Length of line when printing switch values. */
169 #define MAX_LINE 75
171 /* Name of program invoked, sans directories. */
173 const char *progname;
175 /* Copy of argument vector to toplev_main. */
176 static const char **save_argv;
178 /* Name of top-level original source file (what was input to cpp).
179 This comes from the #-command at the beginning of the actual input.
180 If there isn't any there, then this is the cc1 input file name. */
182 const char *main_input_filename;
184 /* Current position in real source file. */
186 location_t input_location;
188 /* Nonzero if it is unsafe to create any new pseudo registers. */
189 int no_new_pseudos;
191 /* Stack of currently pending input files. */
193 struct file_stack *input_file_stack;
195 /* Incremented on each change to input_file_stack. */
196 int input_file_stack_tick;
198 /* Name to use as base of names for dump output files. */
200 const char *dump_base_name;
202 /* Name to use as a base for auxiliary output files. */
204 const char *aux_base_name;
206 /* Format to use to print dumpfile index value */
207 #ifndef DUMPFILE_FORMAT
208 #define DUMPFILE_FORMAT ".%02d."
209 #endif
211 /* Bit flags that specify the machine subtype we are compiling for.
212 Bits are tested using macros TARGET_... defined in the tm.h file
213 and set by `-m...' switches. Must be defined in rtlanal.c. */
215 extern int target_flags;
217 /* A mask of target_flags that includes bit X if X was set or cleared
218 on the command line. */
220 int target_flags_explicit;
222 /* Debug hooks - dependent upon command line options. */
224 const struct gcc_debug_hooks *debug_hooks;
226 /* Describes a dump file. */
228 struct dump_file_info
230 /* The unique extension to apply, e.g. ".jump". */
231 const char *const extension;
233 /* The -d<c> character that enables this dump file. */
234 char const debug_switch;
236 /* True if there is a corresponding graph dump file. */
237 char const graph_dump_p;
239 /* True if the user selected this dump. */
240 char enabled;
242 /* True if the files have been initialized (ie truncated). */
243 char initialized;
246 /* Enumerate the extant dump files. */
248 enum dump_file_index
250 DFI_cgraph,
251 DFI_rtl,
252 DFI_sibling,
253 DFI_eh,
254 DFI_jump,
255 DFI_ssa,
256 DFI_ssa_ccp,
257 DFI_ssa_dce,
258 DFI_ussa,
259 DFI_null,
260 DFI_cse,
261 DFI_addressof,
262 DFI_gcse,
263 DFI_loop,
264 DFI_bypass,
265 DFI_cfg,
266 DFI_bp,
267 DFI_ce1,
268 DFI_tracer,
269 DFI_loop2,
270 DFI_cse2,
271 DFI_life,
272 DFI_combine,
273 DFI_ce2,
274 DFI_regmove,
275 DFI_sched,
276 DFI_lreg,
277 DFI_greg,
278 DFI_postreload,
279 DFI_flow2,
280 DFI_peephole2,
281 DFI_rnreg,
282 DFI_bbro,
283 DFI_ce3,
284 DFI_branch_target_load,
285 DFI_sched2,
286 DFI_stack,
287 DFI_mach,
288 DFI_dbr,
289 DFI_MAX
292 /* Describes all the dump files. Should be kept in order of the
293 pass and in sync with dump_file_index above.
295 Remaining -d letters:
297 " m q "
298 " JK O Q V YZ"
301 static struct dump_file_info dump_file[DFI_MAX] =
303 { "cgraph", 'U', 0, 0, 0 },
304 { "rtl", 'r', 0, 0, 0 },
305 { "sibling", 'i', 0, 0, 0 },
306 { "eh", 'h', 0, 0, 0 },
307 { "jump", 'j', 0, 0, 0 },
308 { "ssa", 'e', 1, 0, 0 },
309 { "ssaccp", 'W', 1, 0, 0 },
310 { "ssadce", 'X', 1, 0, 0 },
311 { "ussa", 'e', 1, 0, 0 }, /* Yes, duplicate enable switch. */
312 { "null", 'u', 0, 0, 0 },
313 { "cse", 's', 0, 0, 0 },
314 { "addressof", 'F', 0, 0, 0 },
315 { "gcse", 'G', 1, 0, 0 },
316 { "loop", 'L', 1, 0, 0 },
317 { "bypass", 'G', 1, 0, 0 }, /* Yes, duplicate enable switch. */
318 { "cfg", 'f', 1, 0, 0 },
319 { "bp", 'b', 1, 0, 0 },
320 { "ce1", 'C', 1, 0, 0 },
321 { "tracer", 'T', 1, 0, 0 },
322 { "loop2", 'L', 1, 0, 0 },
323 { "cse2", 't', 1, 0, 0 },
324 { "life", 'f', 1, 0, 0 }, /* Yes, duplicate enable switch. */
325 { "combine", 'c', 1, 0, 0 },
326 { "ce2", 'C', 1, 0, 0 },
327 { "regmove", 'N', 1, 0, 0 },
328 { "sched", 'S', 1, 0, 0 },
329 { "lreg", 'l', 1, 0, 0 },
330 { "greg", 'g', 1, 0, 0 },
331 { "postreload", 'o', 1, 0, 0 },
332 { "flow2", 'w', 1, 0, 0 },
333 { "peephole2", 'z', 1, 0, 0 },
334 { "rnreg", 'n', 1, 0, 0 },
335 { "bbro", 'B', 1, 0, 0 },
336 { "ce3", 'E', 1, 0, 0 },
337 { "btl", 'd', 1, 0, 0 }, /* Yes, duplicate enable switch. */
338 { "sched2", 'R', 1, 0, 0 },
339 { "stack", 'k', 1, 0, 0 },
340 { "mach", 'M', 1, 0, 0 },
341 { "dbr", 'd', 0, 0, 0 },
344 static int open_dump_file (enum dump_file_index, tree);
345 static void close_dump_file (enum dump_file_index,
346 void (*) (FILE *, rtx), rtx);
348 /* Other flags saying which kinds of debugging dump have been requested. */
350 int rtl_dump_and_exit;
351 int flag_print_asm_name;
352 enum graph_dump_types graph_dump_format;
354 /* Name for output file of assembly code, specified with -o. */
356 const char *asm_file_name;
358 /* Nonzero means do optimizations. -O.
359 Particular numeric values stand for particular amounts of optimization;
360 thus, -O2 stores 2 here. However, the optimizations beyond the basic
361 ones are not controlled directly by this variable. Instead, they are
362 controlled by individual `flag_...' variables that are defaulted
363 based on this variable. */
365 int optimize = 0;
367 /* Nonzero means optimize for size. -Os.
368 The only valid values are zero and nonzero. When optimize_size is
369 nonzero, optimize defaults to 2, but certain individual code
370 bloating optimizations are disabled. */
372 int optimize_size = 0;
374 /* The FUNCTION_DECL for the function currently being compiled,
375 or 0 if between functions. */
376 tree current_function_decl;
378 /* Set to the FUNC_BEGIN label of the current function, or NULL_TREE
379 if none. */
380 tree current_function_func_begin_label;
382 /* Nonzero if doing dwarf2 duplicate elimination. */
384 int flag_eliminate_dwarf2_dups = 0;
386 /* Nonzero if doing unused type elimination. */
388 int flag_eliminate_unused_debug_types = 1;
390 /* Nonzero means emit debugging information only for symbols which are used. */
391 int flag_debug_only_used_symbols = 0;
393 /* Nonzero if generating code to do profiling. */
395 int profile_flag = 0;
397 /* Nonzero if generating code to profile program flow graph arcs. */
399 int profile_arc_flag = 0;
401 /* Nonzero if value histograms should be measured. */
403 int flag_profile_values = 0;
405 /* Nonzero if generating info for gcov to calculate line test coverage. */
407 int flag_test_coverage = 0;
409 /* Nonzero indicates that branch taken probabilities should be calculated. */
411 int flag_branch_probabilities = 0;
413 /* Nonzero if basic blocks should be reordered. */
415 int flag_reorder_blocks = 0;
417 /* Nonzero if functions should be reordered. */
419 int flag_reorder_functions = 0;
421 /* Nonzero if registers should be renamed. */
423 int flag_rename_registers = 0;
424 int flag_cprop_registers = 0;
426 /* Nonzero for -pedantic switch: warn about anything
427 that standard spec forbids. */
429 int pedantic = 0;
431 /* Temporarily suppress certain warnings.
432 This is set while reading code from a system header file. */
434 int in_system_header = 0;
436 /* Don't print functions as they are compiled. -quiet. */
438 int quiet_flag = 0;
440 /* Print times taken by the various passes. -ftime-report. */
442 int time_report = 0;
444 /* Print memory still in use at end of compilation (which may have little
445 to do with peak memory consumption). -fmem-report. */
447 int mem_report = 0;
449 /* Nonzero means to collect statistics which might be expensive
450 and to print them when we are done. */
451 int flag_detailed_statistics = 0;
453 /* A random sequence of characters, unless overridden by user. */
454 const char *flag_random_seed;
456 /* A local time stamp derived from the time of compilation. It will be
457 zero if the system cannot provide a time. It will be -1u, if the
458 user has specified a particular random seed. */
459 unsigned local_tick;
461 /* -f flags. */
463 /* Nonzero means `char' should be signed. */
465 int flag_signed_char;
467 /* Nonzero means give an enum type only as many bytes as it needs. */
469 int flag_short_enums;
471 /* Nonzero for -fcaller-saves: allocate values in regs that need to
472 be saved across function calls, if that produces overall better code.
473 Optional now, so people can test it. */
475 #ifdef DEFAULT_CALLER_SAVES
476 int flag_caller_saves = 1;
477 #else
478 int flag_caller_saves = 0;
479 #endif
481 /* Nonzero if structures and unions should be returned in memory.
483 This should only be defined if compatibility with another compiler or
484 with an ABI is needed, because it results in slower code. */
486 #ifndef DEFAULT_PCC_STRUCT_RETURN
487 #define DEFAULT_PCC_STRUCT_RETURN 1
488 #endif
490 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
492 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
494 /* Nonzero for -fforce-mem: load memory value into a register
495 before arithmetic on it. This makes better cse but slower compilation. */
497 int flag_force_mem = 0;
499 /* Nonzero for -fforce-addr: load memory address into a register before
500 reference to memory. This makes better cse but slower compilation. */
502 int flag_force_addr = 0;
504 /* Nonzero for -fdefer-pop: don't pop args after each function call;
505 instead save them up to pop many calls' args with one insns. */
507 int flag_defer_pop = 0;
509 /* Nonzero for -ffloat-store: don't allocate floats and doubles
510 in extended-precision registers. */
512 int flag_float_store = 0;
514 /* Nonzero for -fcse-follow-jumps:
515 have cse follow jumps to do a more extensive job. */
517 int flag_cse_follow_jumps;
519 /* Nonzero for -fcse-skip-blocks:
520 have cse follow a branch around a block. */
521 int flag_cse_skip_blocks;
523 /* Nonzero for -fexpensive-optimizations:
524 perform miscellaneous relatively-expensive optimizations. */
525 int flag_expensive_optimizations;
527 /* Nonzero for -fthread-jumps:
528 have jump optimize output of loop. */
530 int flag_thread_jumps;
532 /* Nonzero enables strength-reduction in loop.c. */
534 int flag_strength_reduce = 0;
536 /* Nonzero enables loop unrolling in unroll.c. Only loops for which the
537 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
538 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
539 unrolled. */
541 int flag_old_unroll_loops;
543 /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
544 This is generally not a win. */
546 int flag_old_unroll_all_loops;
548 /* Enables unrolling of simple loops in loop-unroll.c. */
549 int flag_unroll_loops;
551 /* Enables unrolling of all loops in loop-unroll.c. */
552 int flag_unroll_all_loops;
554 /* Nonzero enables loop peeling. */
555 int flag_peel_loops;
557 /* Nonzero enables loop unswitching. */
558 int flag_unswitch_loops;
560 /* Nonzero enables prefetch optimizations for arrays in loops. */
562 int flag_prefetch_loop_arrays;
564 /* Nonzero forces all invariant computations in loops to be moved
565 outside the loop. */
567 int flag_move_all_movables = 0;
569 /* Nonzero forces all general induction variables in loops to be
570 strength reduced. */
572 int flag_reduce_all_givs = 0;
574 /* Nonzero to perform full register move optimization passes. This is the
575 default for -O2. */
577 int flag_regmove = 0;
579 /* Nonzero for -fwritable-strings:
580 store string constants in data segment and don't uniquize them. */
582 int flag_writable_strings = 0;
584 /* Nonzero means don't put addresses of constant functions in registers.
585 Used for compiling the Unix kernel, where strange substitutions are
586 done on the assembly output. */
588 int flag_no_function_cse = 0;
590 /* Nonzero for -fomit-frame-pointer:
591 don't make a frame pointer in simple functions that don't require one. */
593 int flag_omit_frame_pointer = 0;
595 /* Nonzero means place each function into its own section on those platforms
596 which support arbitrary section names and unlimited numbers of sections. */
598 int flag_function_sections = 0;
600 /* ... and similar for data. */
602 int flag_data_sections = 0;
604 /* Nonzero to inhibit use of define_optimization peephole opts. */
606 int flag_no_peephole = 0;
608 /* Nonzero allows GCC to optimize sibling and tail recursive calls. */
610 int flag_optimize_sibling_calls = 0;
612 /* Nonzero means the front end generally wants `errno' maintained by math
613 operations, like built-in SQRT. */
615 int flag_errno_math = 1;
617 /* Nonzero means that unsafe floating-point math optimizations are allowed
618 for the sake of speed. IEEE compliance is not guaranteed, and operations
619 are allowed to assume that their arguments and results are "normal"
620 (e.g., nonnegative for SQRT). */
622 int flag_unsafe_math_optimizations = 0;
624 /* Nonzero means that no NaNs or +-Infs are expected. */
626 int flag_finite_math_only = 0;
628 /* Zero means that floating-point math operations cannot generate a
629 (user-visible) trap. This is the case, for example, in nonstop
630 IEEE 754 arithmetic. Trapping conditions include division by zero,
631 overflow, underflow, invalid and inexact, but does not include
632 operations on signaling NaNs (see below). */
634 int flag_trapping_math = 1;
636 /* Nonzero means disable transformations that assume default floating
637 point rounding behavior. */
639 int flag_rounding_math = 0;
641 /* Nonzero means disable transformations observable by signaling NaNs.
642 This option implies that any operation on an IEEE signaling NaN can
643 generate a (user-visible) trap. */
645 int flag_signaling_nans = 0;
647 /* 0 means straightforward implementation of complex divide acceptable.
648 1 means wide ranges of inputs must work for complex divide.
649 2 means C99-like requirements for complex divide (not yet implemented). */
651 int flag_complex_divide_method = 0;
653 /* Nonzero means just do syntax checking; don't output anything. */
655 int flag_syntax_only = 0;
657 /* Nonzero means perform loop optimizer. */
659 int flag_loop_optimize;
661 /* Nonzero means perform crossjumping. */
663 int flag_crossjumping;
665 /* Nonzero means perform if conversion. */
667 int flag_if_conversion;
669 /* Nonzero means perform if conversion after reload. */
671 int flag_if_conversion2;
673 /* Nonzero means to use global dataflow analysis to eliminate
674 useless null pointer tests. */
676 int flag_delete_null_pointer_checks;
678 /* Nonzero means perform global CSE. */
680 int flag_gcse = 0;
682 /* Nonzero means to do the enhanced load motion during gcse, which trys
683 to hoist loads by not killing them when a store to the same location
684 is seen. */
686 int flag_gcse_lm = 1;
688 /* Nonzero means to perform store motion after gcse, which will try to
689 move stores closer to the exit block. Its not very effective without
690 flag_gcse_lm. */
692 int flag_gcse_sm = 1;
694 /* Perform target register optimization before prologue / epilogue
695 threading. */
697 int flag_branch_target_load_optimize = 0;
699 /* Perform target register optimization after prologue / epilogue
700 threading and jump2. */
702 int flag_branch_target_load_optimize2 = 0;
704 /* Nonzero means to rerun cse after loop optimization. This increases
705 compilation time about 20% and picks up a few more common expressions. */
707 int flag_rerun_cse_after_loop;
709 /* Nonzero means to run loop optimizations twice. */
711 int flag_rerun_loop_opt;
713 /* Nonzero for -finline-functions: ok to inline functions that look like
714 good inline candidates. */
716 int flag_inline_functions;
718 /* Nonzero for -fkeep-inline-functions: even if we make a function
719 go inline everywhere, keep its definition around for debugging
720 purposes. */
722 int flag_keep_inline_functions;
724 /* Nonzero means that functions will not be inlined. */
726 int flag_no_inline = 2;
728 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
729 not just because the tree inliner turned us off. */
731 int flag_really_no_inline = 2;
733 /* Nonzero means that we should emit static const variables
734 regardless of whether or not optimization is turned on. */
736 int flag_keep_static_consts = 1;
738 /* Nonzero means we should be saving declaration info into a .X file. */
740 int flag_gen_aux_info = 0;
742 /* Specified name of aux-info file. */
744 const char *aux_info_file_name;
746 /* Nonzero means make the text shared if supported. */
748 int flag_shared_data;
750 /* Nonzero means schedule into delayed branch slots if supported. */
752 int flag_delayed_branch;
754 /* Nonzero if we are compiling pure (sharable) code.
755 Value is 1 if we are doing "small" pic; value is 2 if we're doing
756 "large" pic. */
758 int flag_pic;
760 /* Nonzero if we are compiling position independent code for executable.
761 The value is 1 if we are doing "small" pic; value is 2 if we're doing
762 "large" pic. */
764 int flag_pie;
766 /* Nonzero if we are compiling code for a shared library, zero for
767 executable. */
769 int flag_shlib;
771 /* Set to the default thread-local storage (tls) model to use. */
773 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
775 /* Nonzero means generate extra code for exception handling and enable
776 exception handling. */
778 int flag_exceptions;
780 /* Nonzero means generate frame unwind info table when supported. */
782 int flag_unwind_tables = 0;
784 /* Nonzero means generate frame unwind info table exact at each insn
785 boundary. */
787 int flag_asynchronous_unwind_tables = 0;
789 /* Nonzero means don't place uninitialized global data in common storage
790 by default. */
792 int flag_no_common;
794 /* Nonzero means change certain warnings into errors.
795 Usually these are warnings about failure to conform to some standard. */
797 int flag_pedantic_errors = 0;
799 /* flag_schedule_insns means schedule insns within basic blocks (before
800 local_alloc).
801 flag_schedule_insns_after_reload means schedule insns after
802 global_alloc. */
804 int flag_schedule_insns = 0;
805 int flag_schedule_insns_after_reload = 0;
807 /* When flag_schedule_insns_after_reload is set, use EBB scheduler. */
808 int flag_sched2_use_superblocks = 0;
810 /* When flag_schedule_insns_after_reload is set, construct traces and EBB
811 scheduler. */
812 int flag_sched2_use_traces = 0;
814 /* The following flags have effect only for scheduling before register
815 allocation:
817 flag_schedule_interblock means schedule insns across basic blocks.
818 flag_schedule_speculative means allow speculative motion of non-load insns.
819 flag_schedule_speculative_load means allow speculative motion of some
820 load insns.
821 flag_schedule_speculative_load_dangerous allows speculative motion of more
822 load insns. */
824 int flag_schedule_interblock = 1;
825 int flag_schedule_speculative = 1;
826 int flag_schedule_speculative_load = 0;
827 int flag_schedule_speculative_load_dangerous = 0;
829 int flag_single_precision_constant;
831 /* flag_branch_on_count_reg means try to replace add-1,compare,branch tupple
832 by a cheaper branch on a count register. */
833 int flag_branch_on_count_reg = 1;
835 /* -finhibit-size-directive inhibits output of .size for ELF.
836 This is used only for compiling crtstuff.c,
837 and it may be extended to other effects
838 needed for crtstuff.c on other systems. */
839 int flag_inhibit_size_directive = 0;
841 /* -fverbose-asm causes extra commentary information to be produced in
842 the generated assembly code (to make it more readable). This option
843 is generally only of use to those who actually need to read the
844 generated assembly code (perhaps while debugging the compiler itself).
845 -fno-verbose-asm, the default, causes the extra information
846 to be omitted and is useful when comparing two assembler files. */
848 int flag_verbose_asm = 0;
850 /* -dA causes debug commentary information to be produced in
851 the generated assembly code (to make it more readable). This option
852 is generally only of use to those who actually need to read the
853 generated assembly code (perhaps while debugging the compiler itself).
854 Currently, this switch is only used by dwarfout.c; however, it is intended
855 to be a catchall for printing debug information in the assembler file. */
857 int flag_debug_asm = 0;
859 /* -dP causes the rtl to be emitted as a comment in assembly. */
861 int flag_dump_rtl_in_asm = 0;
863 /* -fgnu-linker specifies use of the GNU linker for initializations.
864 (Or, more generally, a linker that handles initializations.)
865 -fno-gnu-linker says that collect2 will be used. */
866 #ifdef USE_COLLECT2
867 int flag_gnu_linker = 0;
868 #else
869 int flag_gnu_linker = 1;
870 #endif
872 /* Nonzero means put zero initialized data in the bss section. */
873 int flag_zero_initialized_in_bss = 1;
875 /* Enable SSA. */
876 int flag_ssa = 0;
878 /* Enable ssa conditional constant propagation. */
879 int flag_ssa_ccp = 0;
881 /* Enable ssa aggressive dead code elimination. */
882 int flag_ssa_dce = 0;
884 /* Tag all structures with __attribute__(packed). */
885 int flag_pack_struct = 0;
887 /* Emit code to check for stack overflow; also may cause large objects
888 to be allocated dynamically. */
889 int flag_stack_check;
891 /* When non-NULL, indicates that whenever space is allocated on the
892 stack, the resulting stack pointer must not pass this
893 address---that is, for stacks that grow downward, the stack pointer
894 must always be greater than or equal to this address; for stacks
895 that grow upward, the stack pointer must be less than this address.
896 At present, the rtx may be either a REG or a SYMBOL_REF, although
897 the support provided depends on the backend. */
898 rtx stack_limit_rtx;
900 /* 0 if pointer arguments may alias each other. True in C.
901 1 if pointer arguments may not alias each other but may alias
902 global variables.
903 2 if pointer arguments may not alias each other and may not
904 alias global variables. True in Fortran.
905 This defaults to 0 for C. */
906 int flag_argument_noalias = 0;
908 /* Nonzero if we should do (language-dependent) alias analysis.
909 Typically, this analysis will assume that expressions of certain
910 types do not alias expressions of certain other types. Only used
911 if alias analysis (in general) is enabled. */
912 int flag_strict_aliasing = 0;
914 /* Instrument functions with calls at entry and exit, for profiling. */
915 int flag_instrument_function_entry_exit = 0;
917 /* Nonzero means ignore `#ident' directives. 0 means handle them.
918 On SVR4 targets, it also controls whether or not to emit a
919 string identifying the compiler. */
921 int flag_no_ident = 0;
923 /* This will perform a peephole pass before sched2. */
924 int flag_peephole2 = 0;
926 /* This will try to guess branch probabilities. */
927 int flag_guess_branch_prob = 0;
929 /* -fcheck-bounds causes gcc to generate array bounds checks.
930 For C, C++, ObjC: defaults to off.
931 For Java: defaults to on.
932 For Fortran: defaults to off. */
933 int flag_bounds_check = 0;
935 /* This will attempt to merge constant section constants, if 1 only
936 string constants and constants from constant pool, if 2 also constant
937 variables. */
938 int flag_merge_constants = 1;
940 /* If one, renumber instruction UIDs to reduce the number of
941 unused UIDs if there are a lot of instructions. If greater than
942 one, unconditionally renumber instruction UIDs. */
943 int flag_renumber_insns = 1;
945 /* If nonzero, use the graph coloring register allocator. */
946 int flag_new_regalloc = 0;
948 /* Nonzero if we perform superblock formation. */
950 int flag_tracer = 0;
952 /* Nonzero if we perform whole unit at a time compilation. */
954 int flag_unit_at_a_time = 0;
956 /* Values of the -falign-* flags: how much to align labels in code.
957 0 means `use default', 1 means `don't align'.
958 For each variable, there is an _log variant which is the power
959 of two not less than the variable, for .align output. */
961 int align_loops;
962 int align_loops_log;
963 int align_loops_max_skip;
964 int align_jumps;
965 int align_jumps_log;
966 int align_jumps_max_skip;
967 int align_labels;
968 int align_labels_log;
969 int align_labels_max_skip;
970 int align_functions;
971 int align_functions_log;
973 /* Like align_functions_log above, but used by front-ends to force the
974 minimum function alignment. Zero means no alignment is forced. */
975 int force_align_functions_log;
977 typedef struct
979 const char *const string;
980 int *const variable;
981 const int on_value;
983 lang_independent_options;
985 /* Nonzero if signed arithmetic overflow should trap. */
986 int flag_trapv = 0;
988 /* Nonzero if signed arithmetic overflow should wrap around. */
989 int flag_wrapv = 0;
991 /* Add or remove a leading underscore from user symbols. */
992 int flag_leading_underscore = -1;
994 /* The user symbol prefix after having resolved same. */
995 const char *user_label_prefix;
997 static const param_info lang_independent_params[] = {
998 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT) \
999 { OPTION, DEFAULT, HELP },
1000 #include "params.def"
1001 #undef DEFPARAM
1002 { NULL, 0, NULL }
1005 /* Table of language-independent -f options.
1006 STRING is the option name. VARIABLE is the address of the variable.
1007 ON_VALUE is the value to store in VARIABLE
1008 if `-fSTRING' is seen as an option.
1009 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
1011 static const lang_independent_options f_options[] =
1013 {"eliminate-dwarf2-dups", &flag_eliminate_dwarf2_dups, 1 },
1014 {"eliminate-unused-debug-symbols", &flag_debug_only_used_symbols, 1 },
1015 {"eliminate-unused-debug-types", &flag_eliminate_unused_debug_types, 1 },
1016 {"float-store", &flag_float_store, 1 },
1017 {"defer-pop", &flag_defer_pop, 1 },
1018 {"omit-frame-pointer", &flag_omit_frame_pointer, 1 },
1019 {"optimize-sibling-calls", &flag_optimize_sibling_calls, 1 },
1020 {"tracer", &flag_tracer, 1 },
1021 {"unit-at-a-time", &flag_unit_at_a_time, 1 },
1022 {"cse-follow-jumps", &flag_cse_follow_jumps, 1 },
1023 {"cse-skip-blocks", &flag_cse_skip_blocks, 1 },
1024 {"expensive-optimizations", &flag_expensive_optimizations, 1 },
1025 {"thread-jumps", &flag_thread_jumps, 1 },
1026 {"strength-reduce", &flag_strength_reduce, 1 },
1027 {"unroll-loops", &flag_unroll_loops, 1 },
1028 {"unroll-all-loops", &flag_unroll_all_loops, 1 },
1029 {"old-unroll-loops", &flag_old_unroll_loops, 1 },
1030 {"old-unroll-all-loops", &flag_old_unroll_all_loops, 1 },
1031 {"peel-loops", &flag_peel_loops, 1 },
1032 {"unswitch-loops", &flag_unswitch_loops, 1 },
1033 {"prefetch-loop-arrays", &flag_prefetch_loop_arrays, 1 },
1034 {"move-all-movables", &flag_move_all_movables, 1 },
1035 {"reduce-all-givs", &flag_reduce_all_givs, 1 },
1036 {"writable-strings", &flag_writable_strings, 1 },
1037 {"peephole", &flag_no_peephole, 0 },
1038 {"force-mem", &flag_force_mem, 1 },
1039 {"force-addr", &flag_force_addr, 1 },
1040 {"function-cse", &flag_no_function_cse, 0 },
1041 {"inline-functions", &flag_inline_functions, 1 },
1042 {"keep-inline-functions", &flag_keep_inline_functions, 1 },
1043 {"inline", &flag_no_inline, 0 },
1044 {"keep-static-consts", &flag_keep_static_consts, 1 },
1045 {"syntax-only", &flag_syntax_only, 1 },
1046 {"shared-data", &flag_shared_data, 1 },
1047 {"caller-saves", &flag_caller_saves, 1 },
1048 {"pcc-struct-return", &flag_pcc_struct_return, 1 },
1049 {"reg-struct-return", &flag_pcc_struct_return, 0 },
1050 {"delayed-branch", &flag_delayed_branch, 1 },
1051 {"gcse", &flag_gcse, 1 },
1052 {"gcse-lm", &flag_gcse_lm, 1 },
1053 {"gcse-sm", &flag_gcse_sm, 1 },
1054 {"branch-target-load-optimize", &flag_branch_target_load_optimize, 1 },
1055 {"branch-target-load-optimize2", &flag_branch_target_load_optimize2, 1 },
1056 {"loop-optimize", &flag_loop_optimize, 1 },
1057 {"crossjumping", &flag_crossjumping, 1 },
1058 {"if-conversion", &flag_if_conversion, 1 },
1059 {"if-conversion2", &flag_if_conversion2, 1 },
1060 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1 },
1061 {"rerun-loop-opt", &flag_rerun_loop_opt, 1 },
1062 {"delete-null-pointer-checks", &flag_delete_null_pointer_checks, 1 },
1063 {"schedule-insns", &flag_schedule_insns, 1 },
1064 {"schedule-insns2", &flag_schedule_insns_after_reload, 1 },
1065 {"sched-interblock",&flag_schedule_interblock, 1 },
1066 {"sched-spec",&flag_schedule_speculative, 1 },
1067 {"sched-spec-load",&flag_schedule_speculative_load, 1 },
1068 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1 },
1069 {"sched2-use-superblocks", &flag_sched2_use_superblocks, 1 },
1070 {"sched2-use-traces", &flag_sched2_use_traces, 1 },
1071 {"branch-count-reg",&flag_branch_on_count_reg, 1 },
1072 {"pic", &flag_pic, 1 },
1073 {"PIC", &flag_pic, 2 },
1074 {"pie", &flag_pie, 1 },
1075 {"PIE", &flag_pie, 2 },
1076 {"exceptions", &flag_exceptions, 1 },
1077 {"unwind-tables", &flag_unwind_tables, 1 },
1078 {"asynchronous-unwind-tables", &flag_asynchronous_unwind_tables, 1 },
1079 {"non-call-exceptions", &flag_non_call_exceptions, 1 },
1080 {"profile-arcs", &profile_arc_flag, 1 },
1081 {"test-coverage", &flag_test_coverage, 1 },
1082 {"branch-probabilities", &flag_branch_probabilities, 1 },
1083 {"profile", &profile_flag, 1 },
1084 {"reorder-blocks", &flag_reorder_blocks, 1 },
1085 {"reorder-functions", &flag_reorder_functions, 1 },
1086 {"rename-registers", &flag_rename_registers, 1 },
1087 {"cprop-registers", &flag_cprop_registers, 1 },
1088 {"common", &flag_no_common, 0 },
1089 {"inhibit-size-directive", &flag_inhibit_size_directive, 1 },
1090 {"function-sections", &flag_function_sections, 1 },
1091 {"data-sections", &flag_data_sections, 1 },
1092 {"verbose-asm", &flag_verbose_asm, 1 },
1093 {"gnu-linker", &flag_gnu_linker, 1 },
1094 {"regmove", &flag_regmove, 1 },
1095 {"optimize-register-move", &flag_regmove, 1 },
1096 {"pack-struct", &flag_pack_struct, 1 },
1097 {"stack-check", &flag_stack_check, 1 },
1098 {"argument-alias", &flag_argument_noalias, 0 },
1099 {"argument-noalias", &flag_argument_noalias, 1 },
1100 {"argument-noalias-global", &flag_argument_noalias, 2 },
1101 {"strict-aliasing", &flag_strict_aliasing, 1 },
1102 {"align-loops", &align_loops, 0 },
1103 {"align-jumps", &align_jumps, 0 },
1104 {"align-labels", &align_labels, 0 },
1105 {"align-functions", &align_functions, 0 },
1106 {"merge-constants", &flag_merge_constants, 1 },
1107 {"merge-all-constants", &flag_merge_constants, 2 },
1108 {"dump-unnumbered", &flag_dump_unnumbered, 1 },
1109 {"instrument-functions", &flag_instrument_function_entry_exit, 1 },
1110 {"zero-initialized-in-bss", &flag_zero_initialized_in_bss, 1 },
1111 {"ssa", &flag_ssa, 1 },
1112 {"ssa-ccp", &flag_ssa_ccp, 1 },
1113 {"ssa-dce", &flag_ssa_dce, 1 },
1114 {"leading-underscore", &flag_leading_underscore, 1 },
1115 {"ident", &flag_no_ident, 0 },
1116 { "peephole2", &flag_peephole2, 1 },
1117 {"finite-math-only", &flag_finite_math_only, 1 },
1118 { "guess-branch-probability", &flag_guess_branch_prob, 1 },
1119 {"math-errno", &flag_errno_math, 1 },
1120 {"trapping-math", &flag_trapping_math, 1 },
1121 {"rounding-math", &flag_rounding_math, 1 },
1122 {"unsafe-math-optimizations", &flag_unsafe_math_optimizations, 1 },
1123 {"signaling-nans", &flag_signaling_nans, 1 },
1124 {"bounds-check", &flag_bounds_check, 1 },
1125 {"single-precision-constant", &flag_single_precision_constant, 1 },
1126 {"time-report", &time_report, 1 },
1127 {"mem-report", &mem_report, 1 },
1128 { "trapv", &flag_trapv, 1 },
1129 { "wrapv", &flag_wrapv, 1 },
1130 { "new-ra", &flag_new_regalloc, 1 }
1133 /* Here is a table, controlled by the tm.h file, listing each -m switch
1134 and which bits in `target_switches' it should set or clear.
1135 If VALUE is positive, it is bits to set.
1136 If VALUE is negative, -VALUE is bits to clear.
1137 (The sign bit is not used so there is no confusion.) */
1139 static const struct
1141 const char *const name;
1142 const int value;
1143 const char *const description;
1145 target_switches[] = TARGET_SWITCHES;
1147 /* This table is similar, but allows the switch to have a value. */
1149 #ifdef TARGET_OPTIONS
1150 static const struct
1152 const char *const prefix;
1153 const char **const variable;
1154 const char *const description;
1155 const char *const value;
1157 target_options[] = TARGET_OPTIONS;
1158 #endif
1160 /* Nonzero means warn about function definitions that default the return type
1161 or that use a null return and have a return-type other than void. */
1163 int warn_return_type;
1165 /* Output files for assembler code (real compiler output)
1166 and debugging dumps. */
1168 FILE *asm_out_file;
1169 FILE *aux_info_file;
1170 FILE *rtl_dump_file = NULL;
1171 FILE *cgraph_dump_file = NULL;
1173 /* The current working directory of a translation. It's generally the
1174 directory from which compilation was initiated, but a preprocessed
1175 file may specify the original directory in which it was
1176 created. */
1178 static const char *src_pwd;
1180 /* Initialize src_pwd with the given string, and return true. If it
1181 was already initialized, return false. As a special case, it may
1182 be called with a NULL argument to test whether src_pwd has NOT been
1183 initialized yet. */
1185 bool
1186 set_src_pwd (const char *pwd)
1188 if (src_pwd)
1189 return false;
1191 src_pwd = xstrdup (pwd);
1192 return true;
1195 /* Return the directory from which the translation unit was initiated,
1196 in case set_src_pwd() was not called before to assign it a
1197 different value. */
1199 const char *
1200 get_src_pwd (void)
1202 if (! src_pwd)
1203 src_pwd = getpwd ();
1205 return src_pwd;
1208 /* Set up a default flag_random_seed and local_tick, unless the user
1209 already specified one. */
1211 static void
1212 randomize (void)
1214 if (!flag_random_seed)
1216 unsigned HOST_WIDE_INT value;
1217 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
1219 /* Get some more or less random data. */
1220 #ifdef HAVE_GETTIMEOFDAY
1222 struct timeval tv;
1224 gettimeofday (&tv, NULL);
1225 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
1227 #else
1229 time_t now = time (NULL);
1231 if (now != (time_t)-1)
1232 local_tick = (unsigned) now;
1234 #endif
1235 value = local_tick ^ getpid ();
1237 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
1238 flag_random_seed = random_seed;
1240 else if (!local_tick)
1241 local_tick = -1;
1245 /* Decode the string P as an integral parameter.
1246 If the string is indeed an integer return its numeric value else
1247 issue an Invalid Option error for the option PNAME and return DEFVAL.
1248 If PNAME is zero just return DEFVAL, do not call error. */
1251 read_integral_parameter (const char *p, const char *pname, const int defval)
1253 const char *endp = p;
1255 while (*endp)
1257 if (ISDIGIT (*endp))
1258 endp++;
1259 else
1260 break;
1263 if (*endp != 0)
1265 if (pname != 0)
1266 error ("invalid option argument `%s'", pname);
1267 return defval;
1270 return atoi (p);
1273 /* Return the logarithm of X, base 2, considering X unsigned,
1274 if X is a power of 2. Otherwise, returns -1.
1276 This should be used via the `exact_log2' macro. */
1279 exact_log2_wide (unsigned HOST_WIDE_INT x)
1281 int log = 0;
1282 /* Test for 0 or a power of 2. */
1283 if (x == 0 || x != (x & -x))
1284 return -1;
1285 while ((x >>= 1) != 0)
1286 log++;
1287 return log;
1290 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1291 If X is 0, return -1.
1293 This should be used via the floor_log2 macro. */
1296 floor_log2_wide (unsigned HOST_WIDE_INT x)
1298 int log = -1;
1299 while (x != 0)
1300 log++,
1301 x >>= 1;
1302 return log;
1305 /* Handler for fatal signals, such as SIGSEGV. These are transformed
1306 into ICE messages, which is much more user friendly. In case the
1307 error printer crashes, reset the signal to prevent infinite recursion. */
1309 static void
1310 crash_signal (int signo)
1312 signal (signo, SIG_DFL);
1313 internal_error ("%s", strsignal (signo));
1316 /* Arrange to dump core on error. (The regular error message is still
1317 printed first, except in the case of abort().) */
1319 static void
1320 setup_core_dumping (void)
1322 #ifdef SIGABRT
1323 signal (SIGABRT, SIG_DFL);
1324 #endif
1325 #if defined(HAVE_SETRLIMIT)
1327 struct rlimit rlim;
1328 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
1329 fatal_error ("getting core file size maximum limit: %m");
1330 rlim.rlim_cur = rlim.rlim_max;
1331 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
1332 fatal_error ("setting core file size limit to maximum: %m");
1334 #endif
1335 diagnostic_abort_on_error (global_dc);
1339 /* Strip off a legitimate source ending from the input string NAME of
1340 length LEN. Rather than having to know the names used by all of
1341 our front ends, we strip off an ending of a period followed by
1342 up to five characters. (Java uses ".class".) */
1344 void
1345 strip_off_ending (char *name, int len)
1347 int i;
1348 for (i = 2; i < 6 && len > i; i++)
1350 if (name[len - i] == '.')
1352 name[len - i] = '\0';
1353 break;
1358 /* Output a quoted string. */
1360 void
1361 output_quoted_string (FILE *asm_file, const char *string)
1363 #ifdef OUTPUT_QUOTED_STRING
1364 OUTPUT_QUOTED_STRING (asm_file, string);
1365 #else
1366 char c;
1368 putc ('\"', asm_file);
1369 while ((c = *string++) != 0)
1371 if (ISPRINT (c))
1373 if (c == '\"' || c == '\\')
1374 putc ('\\', asm_file);
1375 putc (c, asm_file);
1377 else
1378 fprintf (asm_file, "\\%03o", (unsigned char) c);
1380 putc ('\"', asm_file);
1381 #endif
1384 /* Output a file name in the form wanted by System V. */
1386 void
1387 output_file_directive (FILE *asm_file, const char *input_name)
1389 int len = strlen (input_name);
1390 const char *na = input_name + len;
1392 /* NA gets INPUT_NAME sans directory names. */
1393 while (na > input_name)
1395 if (IS_DIR_SEPARATOR (na[-1]))
1396 break;
1397 na--;
1400 #ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
1401 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
1402 #else
1403 #ifdef ASM_OUTPUT_SOURCE_FILENAME
1404 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
1405 #else
1406 fprintf (asm_file, "\t.file\t");
1407 output_quoted_string (asm_file, na);
1408 fputc ('\n', asm_file);
1409 #endif
1410 #endif
1413 /* Routine to open a dump file. Return true if the dump file is enabled. */
1415 static int
1416 open_dump_file (enum dump_file_index index, tree decl)
1418 char *dump_name;
1419 const char *open_arg;
1420 char seq[16];
1422 if (! dump_file[index].enabled)
1423 return 0;
1425 timevar_push (TV_DUMP);
1426 if (rtl_dump_file != NULL)
1427 fclose (rtl_dump_file);
1429 sprintf (seq, DUMPFILE_FORMAT, index);
1431 if (! dump_file[index].initialized)
1433 /* If we've not initialized the files, do so now. */
1434 if (graph_dump_format != no_graph
1435 && dump_file[index].graph_dump_p)
1437 dump_name = concat (seq, dump_file[index].extension, NULL);
1438 clean_graph_dump_file (dump_base_name, dump_name);
1439 free (dump_name);
1441 dump_file[index].initialized = 1;
1442 open_arg = "w";
1444 else
1445 open_arg = "a";
1447 dump_name = concat (dump_base_name, seq,
1448 dump_file[index].extension, NULL);
1450 rtl_dump_file = fopen (dump_name, open_arg);
1451 if (rtl_dump_file == NULL)
1452 fatal_error ("can't open %s: %m", dump_name);
1454 free (dump_name);
1456 if (decl)
1457 fprintf (rtl_dump_file, "\n;; Function %s%s\n\n",
1458 (*lang_hooks.decl_printable_name) (decl, 2),
1459 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
1460 ? " (hot)"
1461 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
1462 ? " (unlikely executed)"
1463 : "");
1465 timevar_pop (TV_DUMP);
1466 return 1;
1469 /* Routine to close a dump file. */
1471 static void
1472 close_dump_file (enum dump_file_index index,
1473 void (*func) (FILE *, rtx),
1474 rtx insns)
1476 if (! rtl_dump_file)
1477 return;
1479 timevar_push (TV_DUMP);
1480 if (insns
1481 && graph_dump_format != no_graph
1482 && dump_file[index].graph_dump_p)
1484 char seq[16];
1485 char *suffix;
1487 sprintf (seq, DUMPFILE_FORMAT, index);
1488 suffix = concat (seq, dump_file[index].extension, NULL);
1489 print_rtl_graph_with_bb (dump_base_name, suffix, insns);
1490 free (suffix);
1493 if (func && insns)
1494 func (rtl_dump_file, insns);
1496 fflush (rtl_dump_file);
1497 fclose (rtl_dump_file);
1499 rtl_dump_file = NULL;
1500 timevar_pop (TV_DUMP);
1503 /* Do any final processing required for the declarations in VEC, of
1504 which there are LEN. We write out inline functions and variables
1505 that have been deferred until this point, but which are required.
1506 Returns nonzero if anything was put out. */
1509 wrapup_global_declarations (tree *vec, int len)
1511 tree decl;
1512 int i;
1513 int reconsider;
1514 int output_something = 0;
1516 for (i = 0; i < len; i++)
1518 decl = vec[i];
1520 /* We're not deferring this any longer. Assignment is
1521 conditional to avoid needlessly dirtying PCH pages. */
1522 if (DECL_DEFER_OUTPUT (decl) != 0)
1523 DECL_DEFER_OUTPUT (decl) = 0;
1525 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
1526 (*lang_hooks.finish_incomplete_decl) (decl);
1529 /* Now emit any global variables or functions that we have been
1530 putting off. We need to loop in case one of the things emitted
1531 here references another one which comes earlier in the list. */
1534 reconsider = 0;
1535 for (i = 0; i < len; i++)
1537 decl = vec[i];
1539 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
1540 continue;
1542 /* Don't write out static consts, unless we still need them.
1544 We also keep static consts if not optimizing (for debugging),
1545 unless the user specified -fno-keep-static-consts.
1546 ??? They might be better written into the debug information.
1547 This is possible when using DWARF.
1549 A language processor that wants static constants to be always
1550 written out (even if it is not used) is responsible for
1551 calling rest_of_decl_compilation itself. E.g. the C front-end
1552 calls rest_of_decl_compilation from finish_decl.
1553 One motivation for this is that is conventional in some
1554 environments to write things like:
1555 static const char rcsid[] = "... version string ...";
1556 intending to force the string to be in the executable.
1558 A language processor that would prefer to have unneeded
1559 static constants "optimized away" would just defer writing
1560 them out until here. E.g. C++ does this, because static
1561 constants are often defined in header files.
1563 ??? A tempting alternative (for both C and C++) would be
1564 to force a constant to be written if and only if it is
1565 defined in a main file, as opposed to an include file. */
1567 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
1569 bool needed = 1;
1571 if (flag_unit_at_a_time
1572 && cgraph_varpool_node (decl)->finalized)
1573 needed = 0;
1574 else if ((flag_unit_at_a_time && !cgraph_global_info_ready)
1575 && (TREE_USED (decl)
1576 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
1577 /* needed */;
1578 else if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1579 /* needed */;
1580 else if (DECL_COMDAT (decl))
1581 needed = 0;
1582 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
1583 && (optimize || !flag_keep_static_consts
1584 || DECL_ARTIFICIAL (decl)))
1585 needed = 0;
1587 if (needed)
1589 reconsider = 1;
1590 rest_of_decl_compilation (decl, NULL, 1, 1);
1594 if (TREE_CODE (decl) == FUNCTION_DECL
1595 && DECL_INITIAL (decl) != 0
1596 && DECL_SAVED_INSNS (decl) != 0
1597 && DECL_SAVED_INSNS (decl)->saved_for_inline
1598 && (flag_keep_inline_functions
1599 || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
1600 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
1602 reconsider = 1;
1603 output_inline_function (decl);
1607 if (reconsider)
1608 output_something = 1;
1610 while (reconsider);
1612 return output_something;
1615 /* Issue appropriate warnings for the global declarations in VEC (of
1616 which there are LEN). Output debugging information for them. */
1618 void
1619 check_global_declarations (tree *vec, int len)
1621 tree decl;
1622 int i;
1624 for (i = 0; i < len; i++)
1626 decl = vec[i];
1628 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
1629 && ! TREE_ASM_WRITTEN (decl))
1630 /* Cancel the RTL for this decl so that, if debugging info
1631 output for global variables is still to come,
1632 this one will be omitted. */
1633 SET_DECL_RTL (decl, NULL_RTX);
1635 /* Warn about any function
1636 declared static but not defined.
1637 We don't warn about variables,
1638 because many programs have static variables
1639 that exist only to get some text into the object file. */
1640 if (TREE_CODE (decl) == FUNCTION_DECL
1641 && (warn_unused_function
1642 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1643 && DECL_INITIAL (decl) == 0
1644 && DECL_EXTERNAL (decl)
1645 && ! DECL_ARTIFICIAL (decl)
1646 && ! TREE_PUBLIC (decl))
1648 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1649 pedwarn ("%H'%F' used but never defined",
1650 &DECL_SOURCE_LOCATION (decl), decl);
1651 else
1652 warning ("%H'%F' declared `static' but never defined",
1653 &DECL_SOURCE_LOCATION (decl), decl);
1654 /* This symbol is effectively an "extern" declaration now. */
1655 TREE_PUBLIC (decl) = 1;
1656 assemble_external (decl);
1659 /* Warn about static fns or vars defined but not used. */
1660 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
1661 || (warn_unused_variable && TREE_CODE (decl) == VAR_DECL))
1662 && ! TREE_USED (decl)
1663 /* The TREE_USED bit for file-scope decls is kept in the identifier,
1664 to handle multiple external decls in different scopes. */
1665 && ! TREE_USED (DECL_NAME (decl))
1666 && ! DECL_EXTERNAL (decl)
1667 && ! TREE_PUBLIC (decl)
1668 /* A volatile variable might be used in some non-obvious way. */
1669 && ! TREE_THIS_VOLATILE (decl)
1670 /* Global register variables must be declared to reserve them. */
1671 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
1672 /* Otherwise, ask the language. */
1673 && (*lang_hooks.decls.warn_unused_global) (decl))
1674 warning ("%H'%D' defined but not used",
1675 &DECL_SOURCE_LOCATION (decl), decl);
1677 /* Avoid confusing the debug information machinery when there are
1678 errors. */
1679 if (errorcount == 0 && sorrycount == 0)
1681 timevar_push (TV_SYMOUT);
1682 (*debug_hooks->global_decl) (decl);
1683 timevar_pop (TV_SYMOUT);
1688 /* Save the current INPUT_LOCATION on the top entry in the
1689 INPUT_FILE_STACK. Push a new entry for FILE and LINE, and set the
1690 INPUT_LOCATION accordingly. */
1692 void
1693 push_srcloc (const char *file, int line)
1695 struct file_stack *fs;
1697 fs = xmalloc (sizeof (struct file_stack));
1698 fs->location = input_location;
1699 fs->next = input_file_stack;
1700 input_filename = file;
1701 input_line = line;
1702 input_file_stack = fs;
1703 input_file_stack_tick++;
1706 /* Pop the top entry off the stack of presently open source files.
1707 Restore the INPUT_LOCATION from the new topmost entry on the
1708 stack. */
1710 void
1711 pop_srcloc (void)
1713 struct file_stack *fs;
1715 fs = input_file_stack;
1716 input_location = fs->location;
1717 input_file_stack = fs->next;
1718 free (fs);
1719 input_file_stack_tick++;
1722 /* Compile an entire translation unit. Write a file of assembly
1723 output and various debugging dumps. */
1725 static void
1726 compile_file (void)
1728 /* Initialize yet another pass. */
1730 init_final (main_input_filename);
1731 coverage_init (aux_base_name);
1733 timevar_push (TV_PARSE);
1735 /* Call the parser, which parses the entire file (calling
1736 rest_of_compilation for each function). */
1737 (*lang_hooks.parse_file) (set_yydebug);
1739 /* In case there were missing block closers,
1740 get us back to the global binding level. */
1741 (*lang_hooks.clear_binding_stack) ();
1743 /* Compilation is now finished except for writing
1744 what's left of the symbol table output. */
1745 timevar_pop (TV_PARSE);
1747 if (flag_syntax_only)
1748 return;
1750 (*lang_hooks.decls.final_write_globals)();
1752 cgraph_varpool_assemble_pending_decls ();
1754 /* This must occur after the loop to output deferred functions.
1755 Else the coverage initializer would not be emitted if all the
1756 functions in this compilation unit were deferred. */
1757 coverage_finish ();
1759 /* Write out any pending weak symbol declarations. */
1761 weak_finish ();
1763 /* Do dbx symbols. */
1764 timevar_push (TV_SYMOUT);
1766 #ifdef DWARF2_UNWIND_INFO
1767 if (dwarf2out_do_frame ())
1768 dwarf2out_frame_finish ();
1769 #endif
1771 (*debug_hooks->finish) (main_input_filename);
1772 timevar_pop (TV_SYMOUT);
1774 /* Output some stuff at end of file if nec. */
1776 dw2_output_indirect_constants ();
1778 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
1780 timevar_push (TV_DUMP);
1781 open_dump_file (DFI_bp, NULL);
1783 end_branch_prob ();
1785 close_dump_file (DFI_bp, NULL, NULL_RTX);
1786 timevar_pop (TV_DUMP);
1789 targetm.asm_out.file_end ();
1791 /* Attach a special .ident directive to the end of the file to identify
1792 the version of GCC which compiled this code. The format of the .ident
1793 string is patterned after the ones produced by native SVR4 compilers. */
1794 #ifdef IDENT_ASM_OP
1795 if (!flag_no_ident)
1796 fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
1797 IDENT_ASM_OP, version_string);
1798 #endif
1800 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
1802 timevar_push (TV_DUMP);
1803 dump_combine_total_stats (rtl_dump_file);
1804 close_dump_file (DFI_combine, NULL, NULL_RTX);
1805 timevar_pop (TV_DUMP);
1809 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
1810 and TYPE_DECL nodes.
1812 This does nothing for local (non-static) variables, unless the
1813 variable is a register variable with an ASMSPEC. In that case, or
1814 if the variable is not an automatic, it sets up the RTL and
1815 outputs any assembler code (label definition, storage allocation
1816 and initialization).
1818 DECL is the declaration. If ASMSPEC is nonzero, it specifies
1819 the assembler symbol name to be used. TOP_LEVEL is nonzero
1820 if this declaration is not within a function. */
1822 void
1823 rest_of_decl_compilation (tree decl,
1824 const char *asmspec,
1825 int top_level,
1826 int at_end)
1828 /* We deferred calling assemble_alias so that we could collect
1829 other attributes such as visibility. Emit the alias now. */
1831 tree alias;
1832 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
1833 if (alias)
1835 alias = TREE_VALUE (TREE_VALUE (alias));
1836 alias = get_identifier (TREE_STRING_POINTER (alias));
1837 assemble_alias (decl, alias);
1841 /* Forward declarations for nested functions are not "external",
1842 but we need to treat them as if they were. */
1843 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
1844 || TREE_CODE (decl) == FUNCTION_DECL)
1846 timevar_push (TV_VARCONST);
1848 if (asmspec)
1849 make_decl_rtl (decl, asmspec);
1851 /* Don't output anything when a tentative file-scope definition
1852 is seen. But at end of compilation, do output code for them. */
1853 if (at_end || !DECL_DEFER_OUTPUT (decl))
1855 if (flag_unit_at_a_time && !cgraph_global_info_ready
1856 && TREE_CODE (decl) != FUNCTION_DECL && top_level)
1857 cgraph_varpool_finalize_decl (decl);
1858 else
1859 assemble_variable (decl, top_level, at_end, 0);
1862 #ifdef ASM_FINISH_DECLARE_OBJECT
1863 if (decl == last_assemble_variable_decl)
1865 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
1866 top_level, at_end);
1868 #endif
1870 timevar_pop (TV_VARCONST);
1872 else if (DECL_REGISTER (decl) && asmspec != 0)
1874 if (decode_reg_name (asmspec) >= 0)
1876 SET_DECL_RTL (decl, NULL_RTX);
1877 make_decl_rtl (decl, asmspec);
1879 else
1881 error ("invalid register name `%s' for register variable", asmspec);
1882 DECL_REGISTER (decl) = 0;
1883 if (!top_level)
1884 expand_decl (decl);
1887 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1888 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1889 && TREE_CODE (decl) == TYPE_DECL)
1891 timevar_push (TV_SYMOUT);
1892 dbxout_symbol (decl, 0);
1893 timevar_pop (TV_SYMOUT);
1895 #endif
1896 #ifdef SDB_DEBUGGING_INFO
1897 else if (write_symbols == SDB_DEBUG && top_level
1898 && TREE_CODE (decl) == TYPE_DECL)
1900 timevar_push (TV_SYMOUT);
1901 sdbout_symbol (decl, 0);
1902 timevar_pop (TV_SYMOUT);
1904 #endif
1905 #ifdef DWARF2_DEBUGGING_INFO
1906 else if ((write_symbols == DWARF2_DEBUG
1907 || write_symbols == VMS_AND_DWARF2_DEBUG)
1908 && top_level
1909 && TREE_CODE (decl) == TYPE_DECL)
1911 timevar_push (TV_SYMOUT);
1912 dwarf2out_decl (decl);
1913 timevar_pop (TV_SYMOUT);
1915 #endif
1918 /* Called after finishing a record, union or enumeral type. */
1920 void
1921 rest_of_type_compilation (
1922 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) \
1923 || defined (SDB_DEBUGGING_INFO) || defined (DWARF2_DEBUGGING_INFO)
1924 tree type,
1925 int toplev
1926 #else
1927 tree type ATTRIBUTE_UNUSED,
1928 int toplev ATTRIBUTE_UNUSED
1929 #endif
1932 /* Avoid confusing the debug information machinery when there are
1933 errors. */
1934 if (errorcount != 0 || sorrycount != 0)
1935 return;
1937 timevar_push (TV_SYMOUT);
1938 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1939 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1940 dbxout_symbol (TYPE_STUB_DECL (type), !toplev);
1941 #endif
1942 #ifdef SDB_DEBUGGING_INFO
1943 if (write_symbols == SDB_DEBUG)
1944 sdbout_symbol (TYPE_STUB_DECL (type), !toplev);
1945 #endif
1946 #ifdef DWARF2_DEBUGGING_INFO
1947 if ((write_symbols == DWARF2_DEBUG
1948 || write_symbols == VMS_AND_DWARF2_DEBUG)
1949 && toplev)
1950 dwarf2out_decl (TYPE_STUB_DECL (type));
1951 #endif
1952 timevar_pop (TV_SYMOUT);
1955 /* Turn the RTL into assembly. */
1956 static void
1957 rest_of_handle_final (tree decl, rtx insns)
1959 timevar_push (TV_FINAL);
1961 rtx x;
1962 const char *fnname;
1964 /* Get the function's name, as described by its RTL. This may be
1965 different from the DECL_NAME name used in the source file. */
1967 x = DECL_RTL (decl);
1968 if (GET_CODE (x) != MEM)
1969 abort ();
1970 x = XEXP (x, 0);
1971 if (GET_CODE (x) != SYMBOL_REF)
1972 abort ();
1973 fnname = XSTR (x, 0);
1975 assemble_start_function (decl, fnname);
1976 final_start_function (insns, asm_out_file, optimize);
1977 final (insns, asm_out_file, optimize, 0);
1978 final_end_function ();
1980 #ifdef IA64_UNWIND_INFO
1981 /* ??? The IA-64 ".handlerdata" directive must be issued before
1982 the ".endp" directive that closes the procedure descriptor. */
1983 output_function_exception_table ();
1984 #endif
1986 assemble_end_function (decl, fnname);
1988 #ifndef IA64_UNWIND_INFO
1989 /* Otherwise, it feels unclean to switch sections in the middle. */
1990 output_function_exception_table ();
1991 #endif
1993 if (! quiet_flag)
1994 fflush (asm_out_file);
1996 /* Release all memory allocated by flow. */
1997 free_basic_block_vars (0);
1999 /* Release all memory held by regsets now. */
2000 regset_release_memory ();
2002 timevar_pop (TV_FINAL);
2004 ggc_collect ();
2007 #ifdef DELAY_SLOTS
2008 /* Run delay slot optimization. */
2009 static void
2010 rest_of_handle_delay_slots (tree decl, rtx insns)
2012 timevar_push (TV_DBR_SCHED);
2013 open_dump_file (DFI_dbr, decl);
2015 dbr_schedule (insns, rtl_dump_file);
2017 close_dump_file (DFI_dbr, print_rtl, insns);
2018 timevar_pop (TV_DBR_SCHED);
2020 ggc_collect ();
2022 #endif
2024 #ifdef STACK_REGS
2025 /* Convert register usage from flat register file usage to a stack
2026 register file. */
2027 static void
2028 rest_of_handle_stack_regs (tree decl, rtx insns)
2030 timevar_push (TV_REG_STACK);
2031 open_dump_file (DFI_stack, decl);
2033 if (reg_to_stack (insns, rtl_dump_file) && optimize)
2035 if (cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
2036 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0))
2037 && flag_reorder_blocks)
2039 reorder_basic_blocks ();
2040 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
2044 close_dump_file (DFI_stack, print_rtl_with_bb, insns);
2045 timevar_pop (TV_REG_STACK);
2047 ggc_collect ();
2049 #endif
2052 /* Machine independent reorg pass. */
2053 static void
2054 rest_of_handle_machine_reorg (tree decl, rtx insns)
2056 timevar_push (TV_MACH_DEP);
2057 open_dump_file (DFI_mach, decl);
2059 (*targetm.machine_dependent_reorg) ();
2061 close_dump_file (DFI_mach, print_rtl, insns);
2062 timevar_pop (TV_MACH_DEP);
2064 ggc_collect ();
2068 /* Run new register allocator. Return TRUE if we must exit
2069 rest_of_compilation upon return. */
2070 static bool
2071 rest_of_handle_new_regalloc (tree decl, rtx insns, int *rebuild_notes)
2073 int failure;
2075 delete_trivially_dead_insns (insns, max_reg_num ());
2076 reg_alloc ();
2078 timevar_pop (TV_LOCAL_ALLOC);
2079 if (dump_file[DFI_lreg].enabled)
2081 timevar_push (TV_DUMP);
2083 close_dump_file (DFI_lreg, NULL, NULL);
2084 timevar_pop (TV_DUMP);
2087 /* XXX clean up the whole mess to bring live info in shape again. */
2088 timevar_push (TV_GLOBAL_ALLOC);
2089 open_dump_file (DFI_greg, decl);
2091 build_insn_chain (insns);
2092 failure = reload (insns, 0);
2094 timevar_pop (TV_GLOBAL_ALLOC);
2096 if (dump_file[DFI_greg].enabled)
2098 timevar_push (TV_DUMP);
2100 dump_global_regs (rtl_dump_file);
2102 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2103 timevar_pop (TV_DUMP);
2106 if (failure)
2107 return true;
2109 reload_completed = 1;
2110 *rebuild_notes = 0;
2112 return false;
2115 /* Run old register allocator. Return TRUE if we must exit
2116 rest_of_compilation upon return. */
2117 static bool
2118 rest_of_handle_old_regalloc (tree decl, rtx insns, int *rebuild_notes)
2120 int failure;
2122 /* Allocate the reg_renumber array. */
2123 allocate_reg_info (max_regno, FALSE, TRUE);
2125 /* And the reg_equiv_memory_loc array. */
2126 reg_equiv_memory_loc = xcalloc (max_regno, sizeof (rtx));
2128 allocate_initial_values (reg_equiv_memory_loc);
2130 regclass (insns, max_reg_num (), rtl_dump_file);
2131 *rebuild_notes = local_alloc ();
2133 timevar_pop (TV_LOCAL_ALLOC);
2135 if (dump_file[DFI_lreg].enabled)
2137 timevar_push (TV_DUMP);
2139 dump_flow_info (rtl_dump_file);
2140 dump_local_alloc (rtl_dump_file);
2142 close_dump_file (DFI_lreg, print_rtl_with_bb, insns);
2143 timevar_pop (TV_DUMP);
2146 ggc_collect ();
2148 timevar_push (TV_GLOBAL_ALLOC);
2149 open_dump_file (DFI_greg, decl);
2151 /* If optimizing, allocate remaining pseudo-regs. Do the reload
2152 pass fixing up any insns that are invalid. */
2154 if (optimize)
2155 failure = global_alloc (rtl_dump_file);
2156 else
2158 build_insn_chain (insns);
2159 failure = reload (insns, 0);
2162 timevar_pop (TV_GLOBAL_ALLOC);
2164 if (dump_file[DFI_greg].enabled)
2166 timevar_push (TV_DUMP);
2168 dump_global_regs (rtl_dump_file);
2170 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2171 timevar_pop (TV_DUMP);
2174 return failure;
2177 /* Run the regrename and cprop passes. */
2178 static void
2179 rest_of_handle_regrename (tree decl, rtx insns)
2181 timevar_push (TV_RENAME_REGISTERS);
2182 open_dump_file (DFI_rnreg, decl);
2184 if (flag_rename_registers)
2185 regrename_optimize ();
2186 if (flag_cprop_registers)
2187 copyprop_hardreg_forward ();
2189 close_dump_file (DFI_rnreg, print_rtl_with_bb, insns);
2190 timevar_pop (TV_RENAME_REGISTERS);
2193 /* Reorder basic blocks. */
2194 static void
2195 rest_of_handle_reorder_blocks (tree decl, rtx insns)
2197 timevar_push (TV_REORDER_BLOCKS);
2198 open_dump_file (DFI_bbro, decl);
2200 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
2201 splitting possibly introduced more crossjumping opportunities. */
2202 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
2203 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
2205 if (flag_sched2_use_traces && flag_schedule_insns_after_reload)
2206 tracer ();
2207 if (flag_reorder_blocks)
2208 reorder_basic_blocks ();
2209 if (flag_reorder_blocks
2210 || (flag_sched2_use_traces && flag_schedule_insns_after_reload))
2211 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2213 close_dump_file (DFI_bbro, print_rtl_with_bb, insns);
2214 timevar_pop (TV_REORDER_BLOCKS);
2217 #ifdef INSN_SCHEDULING
2218 /* Run instruction scheduler. */
2219 static void
2220 rest_of_handle_sched (tree decl, rtx insns)
2222 timevar_push (TV_SCHED);
2224 /* Print function header into sched dump now
2225 because doing the sched analysis makes some of the dump. */
2226 if (optimize > 0 && flag_schedule_insns)
2228 open_dump_file (DFI_sched, decl);
2230 /* Do control and data sched analysis,
2231 and write some of the results to dump file. */
2233 schedule_insns (rtl_dump_file);
2235 close_dump_file (DFI_sched, print_rtl_with_bb, insns);
2237 timevar_pop (TV_SCHED);
2239 ggc_collect ();
2242 /* Run second scheduling pass after reload. */
2243 static void
2244 rest_of_handle_sched2 (tree decl, rtx insns)
2246 timevar_push (TV_SCHED2);
2247 open_dump_file (DFI_sched2, decl);
2249 /* Do control and data sched analysis again,
2250 and write some more of the results to dump file. */
2252 split_all_insns (1);
2254 if (flag_sched2_use_superblocks || flag_sched2_use_traces)
2256 schedule_ebbs (rtl_dump_file);
2257 /* No liveness updating code yet, but it should be easy to do.
2258 reg-stack recompute the liveness when needed for now. */
2259 count_or_remove_death_notes (NULL, 1);
2260 cleanup_cfg (CLEANUP_EXPENSIVE);
2262 else
2263 schedule_insns (rtl_dump_file);
2265 close_dump_file (DFI_sched2, print_rtl_with_bb, insns);
2266 timevar_pop (TV_SCHED2);
2268 ggc_collect ();
2270 #endif
2272 /* Register allocation pre-pass, to reduce number of moves necessary
2273 for two-address machines. */
2274 static void
2275 rest_of_handle_regmove (tree decl, rtx insns)
2277 timevar_push (TV_REGMOVE);
2278 open_dump_file (DFI_regmove, decl);
2280 regmove_optimize (insns, max_reg_num (), rtl_dump_file);
2282 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2283 close_dump_file (DFI_regmove, print_rtl_with_bb, insns);
2284 timevar_pop (TV_REGMOVE);
2286 ggc_collect ();
2289 /* Run tracer. */
2290 static void
2291 rest_of_handle_tracer (tree decl, rtx insns)
2293 timevar_push (TV_TRACER);
2294 open_dump_file (DFI_tracer, decl);
2295 if (rtl_dump_file)
2296 dump_flow_info (rtl_dump_file);
2297 tracer ();
2298 cleanup_cfg (CLEANUP_EXPENSIVE);
2299 reg_scan (insns, max_reg_num (), 0);
2300 close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ());
2301 timevar_pop (TV_TRACER);
2304 /* If-conversion and CFG cleanup. */
2305 static void
2306 rest_of_handle_if_conversion (tree decl, rtx insns)
2308 open_dump_file (DFI_ce1, decl);
2309 if (flag_if_conversion)
2311 timevar_push (TV_IFCVT);
2312 if (rtl_dump_file)
2313 dump_flow_info (rtl_dump_file);
2314 cleanup_cfg (CLEANUP_EXPENSIVE);
2315 reg_scan (insns, max_reg_num (), 0);
2316 if_convert (0);
2317 timevar_pop (TV_IFCVT);
2319 timevar_push (TV_JUMP);
2320 cleanup_cfg (CLEANUP_EXPENSIVE);
2321 reg_scan (insns, max_reg_num (), 0);
2322 timevar_pop (TV_JUMP);
2323 close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ());
2326 /* Rerun if-conversion, as combine may have simplified things enough
2327 to now meet sequence length restrictions. */
2328 static void
2329 rest_of_handle_if_after_combine (tree decl, rtx insns)
2331 timevar_push (TV_IFCVT);
2332 open_dump_file (DFI_ce2, decl);
2334 no_new_pseudos = 0;
2335 if_convert (1);
2336 no_new_pseudos = 1;
2338 close_dump_file (DFI_ce2, print_rtl_with_bb, insns);
2339 timevar_pop (TV_IFCVT);
2342 /* Do branch profiling and static profile estimation passes. */
2343 static void
2344 rest_of_handle_branch_prob (tree decl, rtx insns)
2346 struct loops loops;
2348 timevar_push (TV_BRANCH_PROB);
2349 open_dump_file (DFI_bp, decl);
2350 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
2351 branch_prob ();
2353 /* Discover and record the loop depth at the head of each basic
2354 block. The loop infrastructure does the real job for us. */
2355 flow_loops_find (&loops, LOOP_TREE);
2357 if (rtl_dump_file)
2358 flow_loops_dump (&loops, rtl_dump_file, NULL, 0);
2360 /* Estimate using heuristics if no profiling info is available. */
2361 if (flag_guess_branch_prob)
2362 estimate_probability (&loops);
2364 flow_loops_free (&loops);
2365 close_dump_file (DFI_bp, print_rtl_with_bb, insns);
2366 timevar_pop (TV_BRANCH_PROB);
2369 /* Do control and data flow analysis; write some of the results to the
2370 dump file. */
2371 static void
2372 rest_of_handle_cfg (tree decl, rtx insns)
2374 open_dump_file (DFI_cfg, decl);
2375 if (rtl_dump_file)
2376 dump_flow_info (rtl_dump_file);
2377 if (optimize)
2378 cleanup_cfg (CLEANUP_EXPENSIVE
2379 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2381 /* It may make more sense to mark constant functions after dead code is
2382 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
2383 may insert code making function non-constant, but we still must consider
2384 it as constant, otherwise -fbranch-probabilities will not read data back.
2386 life_analysis rarely eliminates modification of external memory.
2388 if (optimize)
2389 mark_constant_function ();
2391 close_dump_file (DFI_cfg, print_rtl_with_bb, insns);
2394 /* Purge addressofs. */
2395 static void
2396 rest_of_handle_addressof (tree decl, rtx insns)
2398 open_dump_file (DFI_addressof, decl);
2400 purge_addressof (insns);
2401 if (optimize && purge_all_dead_edges (0))
2402 delete_unreachable_blocks ();
2403 reg_scan (insns, max_reg_num (), 1);
2405 close_dump_file (DFI_addressof, print_rtl, insns);
2408 /* We may have potential sibling or tail recursion sites. Select one
2409 (of possibly multiple) methods of performing the call. */
2410 static void
2411 rest_of_handle_sibling_calls (rtx insns)
2413 rtx insn;
2414 optimize_sibling_and_tail_recursive_calls ();
2416 /* Recompute the CFG as sibling optimization clobbers it randomly. */
2417 free_bb_for_insn ();
2418 find_exception_handler_labels ();
2419 rebuild_jump_labels (insns);
2420 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2422 /* There is pass ordering problem - we must lower NOTE_INSN_PREDICTION
2423 notes before simplifying cfg and we must do lowering after sibcall
2424 that unhides parts of RTL chain and cleans up the CFG.
2426 Until sibcall is replaced by tree-level optimizer, lets just
2427 sweep away the NOTE_INSN_PREDICTION notes that leaked out. */
2428 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2429 if (GET_CODE (insn) == NOTE
2430 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_PREDICTION)
2431 delete_insn (insn);
2433 close_dump_file (DFI_sibling, print_rtl, get_insns ());
2436 /* Perform jump bypassing and control flow optimizations. */
2437 static void
2438 rest_of_handle_jump_bypass (tree decl, rtx insns)
2440 timevar_push (TV_BYPASS);
2441 open_dump_file (DFI_bypass, decl);
2443 cleanup_cfg (CLEANUP_EXPENSIVE);
2445 if (bypass_jumps (rtl_dump_file))
2447 rebuild_jump_labels (insns);
2448 cleanup_cfg (CLEANUP_EXPENSIVE);
2449 delete_trivially_dead_insns (insns, max_reg_num ());
2452 close_dump_file (DFI_bypass, print_rtl_with_bb, insns);
2453 timevar_pop (TV_BYPASS);
2455 ggc_collect ();
2457 #ifdef ENABLE_CHECKING
2458 verify_flow_info ();
2459 #endif
2462 /* Handle inlining of functions in rest_of_compilation. Return TRUE
2463 if we must exit rest_of_compilation upon return. */
2464 static bool
2465 rest_of_handle_inlining (tree decl)
2467 rtx insns;
2468 int inlinable = 0;
2469 tree parent;
2470 const char *lose;
2472 /* If we are reconsidering an inline function at the end of
2473 compilation, skip the stuff for making it inline. */
2474 if (cfun->rtl_inline_init)
2475 return 0;
2476 cfun->rtl_inline_init = 1;
2478 /* If this is nested inside an inlined external function, pretend
2479 it was only declared. Since we cannot inline such functions,
2480 generating code for this one is not only not necessary but will
2481 confuse some debugging output writers. */
2482 for (parent = DECL_CONTEXT (current_function_decl);
2483 parent != NULL_TREE;
2484 parent = get_containing_scope (parent))
2485 if (TREE_CODE (parent) == FUNCTION_DECL
2486 && DECL_INLINE (parent) && DECL_EXTERNAL (parent))
2488 DECL_INITIAL (decl) = 0;
2489 return true;
2491 else if (TYPE_P (parent))
2492 /* A function in a local class should be treated normally. */
2493 break;
2495 /* If requested, consider whether to make this function inline. */
2496 if ((DECL_INLINE (decl) && !flag_no_inline)
2497 || flag_inline_functions)
2499 timevar_push (TV_INTEGRATION);
2500 lose = function_cannot_inline_p (decl);
2501 timevar_pop (TV_INTEGRATION);
2502 if (lose || ! optimize)
2504 if (warn_inline && lose && DECL_INLINE (decl))
2506 char *msg = xmalloc (2 + strlen (lose) + 1);
2507 msg[0] = '%';
2508 msg[1] = 'H';
2509 strcpy(msg + 2, lose);
2510 warning (msg, &DECL_SOURCE_LOCATION (decl));
2511 free (msg);
2513 DECL_ABSTRACT_ORIGIN (decl) = 0;
2514 /* Don't really compile an extern inline function.
2515 If we can't make it inline, pretend
2516 it was only declared. */
2517 if (DECL_EXTERNAL (decl))
2519 DECL_INITIAL (decl) = 0;
2520 return true;
2523 else
2524 inlinable = DECL_INLINE (decl) = 1;
2527 insns = get_insns ();
2529 /* Dump the rtl code if we are dumping rtl. */
2531 if (open_dump_file (DFI_rtl, decl))
2533 if (DECL_SAVED_INSNS (decl) && DECL_SAVED_INSNS (decl)->saved_for_inline)
2534 fprintf (rtl_dump_file, ";; (integrable)\n\n");
2535 close_dump_file (DFI_rtl, print_rtl, insns);
2538 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
2539 sorts of eh initialization. Delay this until after the
2540 initial rtl dump so that we can see the original nesting. */
2541 convert_from_eh_region_ranges ();
2543 /* If function is inline, and we don't yet know whether to
2544 compile it by itself, defer decision till end of compilation.
2545 wrapup_global_declarations will (indirectly) call
2546 rest_of_compilation again for those functions that need to
2547 be output. Also defer those functions that we are supposed
2548 to defer. */
2550 if (inlinable
2551 || (DECL_INLINE (decl)
2552 && flag_inline_functions
2553 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2554 && ! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
2555 && ! flag_keep_inline_functions)
2556 || DECL_EXTERNAL (decl))))
2557 DECL_DEFER_OUTPUT (decl) = 1;
2559 if (DECL_INLINE (decl))
2560 /* DWARF wants separate debugging info for abstract and
2561 concrete instances of all inline functions, including those
2562 declared inline but not inlined, and those inlined even
2563 though they weren't declared inline. Conveniently, that's
2564 what DECL_INLINE means at this point. */
2565 (*debug_hooks->deferred_inline_function) (decl);
2567 if (DECL_DEFER_OUTPUT (decl))
2569 /* If -Wreturn-type, we have to do a bit of compilation. We just
2570 want to call cleanup the cfg to figure out whether or not we can
2571 fall off the end of the function; we do the minimum amount of
2572 work necessary to make that safe. */
2573 if (warn_return_type)
2575 int saved_optimize = optimize;
2577 optimize = 0;
2578 rebuild_jump_labels (insns);
2579 find_exception_handler_labels ();
2580 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2581 cleanup_cfg (CLEANUP_PRE_SIBCALL | CLEANUP_PRE_LOOP);
2582 optimize = saved_optimize;
2584 /* CFG is no longer maintained up-to-date. */
2585 free_bb_for_insn ();
2588 set_nothrow_function_flags ();
2589 if (current_function_nothrow)
2590 /* Now we know that this can't throw; set the flag for the benefit
2591 of other functions later in this translation unit. */
2592 TREE_NOTHROW (current_function_decl) = 1;
2594 timevar_push (TV_INTEGRATION);
2595 save_for_inline (decl);
2596 timevar_pop (TV_INTEGRATION);
2597 DECL_SAVED_INSNS (decl)->inlinable = inlinable;
2598 return true;
2601 /* If specified extern inline but we aren't inlining it, we are
2602 done. This goes for anything that gets here with DECL_EXTERNAL
2603 set, not just things with DECL_INLINE. */
2604 return (bool) DECL_EXTERNAL (decl);
2607 /* Rest of compilation helper to convert the rtl to SSA form. */
2608 static rtx
2609 rest_of_handle_ssa (tree decl, rtx insns)
2611 timevar_push (TV_TO_SSA);
2612 open_dump_file (DFI_ssa, decl);
2614 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2615 convert_to_ssa ();
2617 close_dump_file (DFI_ssa, print_rtl_with_bb, insns);
2618 timevar_pop (TV_TO_SSA);
2620 /* Perform sparse conditional constant propagation, if requested. */
2621 if (flag_ssa_ccp)
2623 timevar_push (TV_SSA_CCP);
2624 open_dump_file (DFI_ssa_ccp, decl);
2626 ssa_const_prop ();
2628 close_dump_file (DFI_ssa_ccp, print_rtl_with_bb, get_insns ());
2629 timevar_pop (TV_SSA_CCP);
2632 /* It would be useful to cleanup the CFG at this point, but block
2633 merging and possibly other transformations might leave a PHI
2634 node in the middle of a basic block, which is a strict no-no. */
2636 /* The SSA implementation uses basic block numbers in its phi
2637 nodes. Thus, changing the control-flow graph or the basic
2638 blocks, e.g., calling find_basic_blocks () or cleanup_cfg (),
2639 may cause problems. */
2641 if (flag_ssa_dce)
2643 /* Remove dead code. */
2645 timevar_push (TV_SSA_DCE);
2646 open_dump_file (DFI_ssa_dce, decl);
2648 insns = get_insns ();
2649 ssa_eliminate_dead_code ();
2651 close_dump_file (DFI_ssa_dce, print_rtl_with_bb, insns);
2652 timevar_pop (TV_SSA_DCE);
2655 /* Convert from SSA form. */
2657 timevar_push (TV_FROM_SSA);
2658 open_dump_file (DFI_ussa, decl);
2660 convert_from_ssa ();
2661 /* New registers have been created. Rescan their usage. */
2662 reg_scan (insns, max_reg_num (), 1);
2664 close_dump_file (DFI_ussa, print_rtl_with_bb, insns);
2665 timevar_pop (TV_FROM_SSA);
2667 ggc_collect ();
2669 return insns;
2672 /* Try to identify useless null pointer tests and delete them. */
2673 static void
2674 rest_of_handle_null_pointer (tree decl, rtx insns)
2676 open_dump_file (DFI_null, decl);
2677 if (rtl_dump_file)
2678 dump_flow_info (rtl_dump_file);
2680 if (delete_null_pointer_checks (insns))
2681 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2683 close_dump_file (DFI_null, print_rtl_with_bb, insns);
2686 /* Try combining insns through substitution. */
2687 static void
2688 rest_of_handle_combine (tree decl, rtx insns)
2690 int rebuild_jump_labels_after_combine = 0;
2692 timevar_push (TV_COMBINE);
2693 open_dump_file (DFI_combine, decl);
2695 rebuild_jump_labels_after_combine
2696 = combine_instructions (insns, max_reg_num ());
2698 /* Combining insns may have turned an indirect jump into a
2699 direct jump. Rebuild the JUMP_LABEL fields of jumping
2700 instructions. */
2701 if (rebuild_jump_labels_after_combine)
2703 timevar_push (TV_JUMP);
2704 rebuild_jump_labels (insns);
2705 timevar_pop (TV_JUMP);
2707 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2710 close_dump_file (DFI_combine, print_rtl_with_bb, insns);
2711 timevar_pop (TV_COMBINE);
2713 ggc_collect ();
2716 /* Perform life analysis. */
2717 static void
2718 rest_of_handle_life (tree decl, rtx insns)
2720 open_dump_file (DFI_life, decl);
2721 regclass_init ();
2723 #ifdef ENABLE_CHECKING
2724 verify_flow_info ();
2725 #endif
2726 life_analysis (insns, rtl_dump_file, PROP_FINAL);
2727 if (optimize)
2728 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_UPDATE_LIFE
2729 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2730 timevar_pop (TV_FLOW);
2732 if (warn_uninitialized)
2734 uninitialized_vars_warning (DECL_INITIAL (decl));
2735 if (extra_warnings)
2736 setjmp_args_warning ();
2739 if (optimize)
2741 if (!flag_new_regalloc && initialize_uninitialized_subregs ())
2743 /* Insns were inserted, and possibly pseudos created, so
2744 things might look a bit different. */
2745 insns = get_insns ();
2746 allocate_reg_life_data ();
2747 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
2748 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
2752 no_new_pseudos = 1;
2754 close_dump_file (DFI_life, print_rtl_with_bb, insns);
2756 ggc_collect ();
2759 /* Perform common subexpression elimination. Nonzero value from
2760 `cse_main' means that jumps were simplified and some code may now
2761 be unreachable, so do jump optimization again. */
2762 static void
2763 rest_of_handle_cse (tree decl, rtx insns)
2765 int tem;
2767 open_dump_file (DFI_cse, decl);
2768 if (rtl_dump_file)
2769 dump_flow_info (rtl_dump_file);
2770 timevar_push (TV_CSE);
2772 reg_scan (insns, max_reg_num (), 1);
2774 tem = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2775 if (tem)
2776 rebuild_jump_labels (insns);
2777 purge_all_dead_edges (0);
2779 delete_trivially_dead_insns (insns, max_reg_num ());
2781 /* If we are not running more CSE passes, then we are no longer
2782 expecting CSE to be run. But always rerun it in a cheap mode. */
2783 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
2785 if (tem || optimize > 1)
2786 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2787 /* Try to identify useless null pointer tests and delete them. */
2788 if (flag_delete_null_pointer_checks)
2790 timevar_push (TV_JUMP);
2792 if (delete_null_pointer_checks (insns))
2793 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2794 timevar_pop (TV_JUMP);
2797 /* The second pass of jump optimization is likely to have
2798 removed a bunch more instructions. */
2799 renumber_insns (rtl_dump_file);
2801 timevar_pop (TV_CSE);
2802 close_dump_file (DFI_cse, print_rtl_with_bb, insns);
2805 /* Run second CSE pass after loop optimizations. */
2806 static void
2807 rest_of_handle_cse2 (tree decl, rtx insns)
2809 int tem;
2811 timevar_push (TV_CSE2);
2812 open_dump_file (DFI_cse2, decl);
2813 if (rtl_dump_file)
2814 dump_flow_info (rtl_dump_file);
2815 /* CFG is no longer maintained up-to-date. */
2816 tem = cse_main (insns, max_reg_num (), 1, rtl_dump_file);
2817 purge_all_dead_edges (0);
2818 delete_trivially_dead_insns (insns, max_reg_num ());
2820 if (tem)
2822 timevar_push (TV_JUMP);
2823 rebuild_jump_labels (insns);
2824 cleanup_cfg (CLEANUP_EXPENSIVE);
2825 timevar_pop (TV_JUMP);
2827 reg_scan (insns, max_reg_num (), 0);
2828 close_dump_file (DFI_cse2, print_rtl_with_bb, insns);
2829 ggc_collect ();
2830 timevar_pop (TV_CSE2);
2833 /* Perform global cse. */
2834 static void
2835 rest_of_handle_gcse (tree decl, rtx insns)
2837 int save_csb, save_cfj;
2838 int tem2 = 0, tem;
2840 timevar_push (TV_GCSE);
2841 open_dump_file (DFI_gcse, decl);
2843 tem = gcse_main (insns, rtl_dump_file);
2844 rebuild_jump_labels (insns);
2845 delete_trivially_dead_insns (insns, max_reg_num ());
2847 save_csb = flag_cse_skip_blocks;
2848 save_cfj = flag_cse_follow_jumps;
2849 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
2851 /* Instantiate any remaining CONSTANT_P_RTX nodes. */
2852 if (current_function_calls_constant_p)
2853 purge_builtin_constant_p ();
2855 /* If -fexpensive-optimizations, re-run CSE to clean up things done
2856 by gcse. */
2857 if (flag_expensive_optimizations)
2859 timevar_push (TV_CSE);
2860 reg_scan (insns, max_reg_num (), 1);
2861 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2862 purge_all_dead_edges (0);
2863 delete_trivially_dead_insns (insns, max_reg_num ());
2864 timevar_pop (TV_CSE);
2865 cse_not_expected = !flag_rerun_cse_after_loop;
2868 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
2869 things up. Then possibly re-run CSE again. */
2870 while (tem || tem2)
2872 tem = tem2 = 0;
2873 timevar_push (TV_JUMP);
2874 rebuild_jump_labels (insns);
2875 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2876 timevar_pop (TV_JUMP);
2878 if (flag_expensive_optimizations)
2880 timevar_push (TV_CSE);
2881 reg_scan (insns, max_reg_num (), 1);
2882 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2883 purge_all_dead_edges (0);
2884 delete_trivially_dead_insns (insns, max_reg_num ());
2885 timevar_pop (TV_CSE);
2889 close_dump_file (DFI_gcse, print_rtl_with_bb, insns);
2890 timevar_pop (TV_GCSE);
2892 ggc_collect ();
2893 flag_cse_skip_blocks = save_csb;
2894 flag_cse_follow_jumps = save_cfj;
2895 #ifdef ENABLE_CHECKING
2896 verify_flow_info ();
2897 #endif
2900 /* Move constant computations out of loops. */
2901 static void
2902 rest_of_handle_loop_optimize (tree decl, rtx insns)
2904 int do_unroll, do_prefetch;
2906 timevar_push (TV_LOOP);
2907 delete_dead_jumptables ();
2908 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2909 open_dump_file (DFI_loop, decl);
2911 /* CFG is no longer maintained up-to-date. */
2912 free_bb_for_insn ();
2914 if (flag_unroll_loops)
2915 do_unroll = 0; /* Having two unrollers is useless. */
2916 else
2917 do_unroll = flag_old_unroll_loops ? LOOP_UNROLL : LOOP_AUTO_UNROLL;
2918 do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
2920 if (flag_rerun_loop_opt)
2922 cleanup_barriers ();
2924 /* We only want to perform unrolling once. */
2925 loop_optimize (insns, rtl_dump_file, do_unroll);
2926 do_unroll = 0;
2928 /* The first call to loop_optimize makes some instructions
2929 trivially dead. We delete those instructions now in the
2930 hope that doing so will make the heuristics in loop work
2931 better and possibly speed up compilation. */
2932 delete_trivially_dead_insns (insns, max_reg_num ());
2934 /* The regscan pass is currently necessary as the alias
2935 analysis code depends on this information. */
2936 reg_scan (insns, max_reg_num (), 1);
2938 cleanup_barriers ();
2939 loop_optimize (insns, rtl_dump_file, do_unroll | LOOP_BCT | do_prefetch);
2941 /* Loop can create trivially dead instructions. */
2942 delete_trivially_dead_insns (insns, max_reg_num ());
2943 close_dump_file (DFI_loop, print_rtl, insns);
2944 timevar_pop (TV_LOOP);
2945 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2947 ggc_collect ();
2950 /* Perform loop optimizations. It might be better to do them a bit
2951 sooner, but we want the profile feedback to work more
2952 efficiently. */
2953 static void
2954 rest_of_handle_loop2 (tree decl, rtx insns)
2956 struct loops *loops;
2957 timevar_push (TV_LOOP);
2958 open_dump_file (DFI_loop2, decl);
2959 if (rtl_dump_file)
2960 dump_flow_info (rtl_dump_file);
2962 loops = loop_optimizer_init (rtl_dump_file);
2964 if (loops)
2966 /* The optimizations: */
2967 if (flag_unswitch_loops)
2968 unswitch_loops (loops);
2970 if (flag_peel_loops || flag_unroll_loops)
2971 unroll_and_peel_loops (loops,
2972 (flag_peel_loops ? UAP_PEEL : 0) |
2973 (flag_unroll_loops ? UAP_UNROLL : 0) |
2974 (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0));
2976 loop_optimizer_finalize (loops, rtl_dump_file);
2979 cleanup_cfg (CLEANUP_EXPENSIVE);
2980 delete_trivially_dead_insns (insns, max_reg_num ());
2981 reg_scan (insns, max_reg_num (), 0);
2982 if (rtl_dump_file)
2983 dump_flow_info (rtl_dump_file);
2984 close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
2985 timevar_pop (TV_LOOP);
2986 ggc_collect ();
2989 /* This is called from finish_function (within langhooks.parse_file)
2990 after each top-level definition is parsed.
2991 It is supposed to compile that function or variable
2992 and output the assembler code for it.
2993 After we return, the tree storage is freed. */
2995 void
2996 rest_of_compilation (tree decl)
2998 rtx insns;
2999 int rebuild_label_notes_after_reload;
3001 timevar_push (TV_REST_OF_COMPILATION);
3003 /* Register rtl specific functions for cfg. */
3004 rtl_register_cfg_hooks ();
3006 /* Now that we're out of the frontend, we shouldn't have any more
3007 CONCATs anywhere. */
3008 generating_concat_p = 0;
3010 /* When processing delayed functions, prepare_function_start() won't
3011 have been run to re-initialize it. */
3012 cse_not_expected = ! optimize;
3014 /* First, make sure that NOTE_BLOCK is set correctly for each
3015 NOTE_INSN_BLOCK_BEG/NOTE_INSN_BLOCK_END note. */
3016 if (!cfun->x_whole_function_mode_p)
3017 identify_blocks ();
3019 /* In function-at-a-time mode, we do not attempt to keep the BLOCK
3020 tree in sensible shape. So, we just recalculate it here. */
3021 if (cfun->x_whole_function_mode_p)
3022 reorder_blocks ();
3024 init_flow ();
3026 if (rest_of_handle_inlining (decl))
3027 goto exit_rest_of_compilation;
3029 /* If we're emitting a nested function, make sure its parent gets
3030 emitted as well. Doing otherwise confuses debug info. */
3032 tree parent;
3033 for (parent = DECL_CONTEXT (current_function_decl);
3034 parent != NULL_TREE;
3035 parent = get_containing_scope (parent))
3036 if (TREE_CODE (parent) == FUNCTION_DECL)
3037 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
3040 /* We are now committed to emitting code for this function. Do any
3041 preparation, such as emitting abstract debug info for the inline
3042 before it gets mangled by optimization. */
3043 if (DECL_INLINE (decl))
3044 (*debug_hooks->outlining_inline_function) (decl);
3046 /* Remove any notes we don't need. That will make iterating
3047 over the instruction sequence faster, and allow the garbage
3048 collector to reclaim the memory used by the notes. */
3049 remove_unnecessary_notes ();
3050 reorder_blocks ();
3052 ggc_collect ();
3054 /* Initialize some variables used by the optimizers. */
3055 init_function_for_compilation ();
3057 if (! DECL_DEFER_OUTPUT (decl))
3058 TREE_ASM_WRITTEN (decl) = 1;
3060 /* Now that integrate will no longer see our rtl, we need not
3061 distinguish between the return value of this function and the
3062 return value of called functions. Also, we can remove all SETs
3063 of subregs of hard registers; they are only here because of
3064 integrate. Also, we can now initialize pseudos intended to
3065 carry magic hard reg data throughout the function. */
3066 rtx_equal_function_value_matters = 0;
3067 purge_hard_subreg_sets (get_insns ());
3069 /* Early return if there were errors. We can run afoul of our
3070 consistency checks, and there's not really much point in fixing them.
3071 Don't return yet if -Wreturn-type; we need to do cleanup_cfg. */
3072 if (((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
3073 || errorcount || sorrycount)
3074 goto exit_rest_of_compilation;
3076 timevar_push (TV_JUMP);
3077 open_dump_file (DFI_sibling, decl);
3078 insns = get_insns ();
3079 rebuild_jump_labels (insns);
3080 find_exception_handler_labels ();
3081 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3083 delete_unreachable_blocks ();
3085 /* We have to issue these warnings now already, because CFG cleanups
3086 further down may destroy the required information. */
3087 check_function_return_warnings ();
3089 /* Turn NOTE_INSN_PREDICTIONs into branch predictions. */
3090 if (flag_guess_branch_prob)
3092 timevar_push (TV_BRANCH_PROB);
3093 note_prediction_to_br_prob ();
3094 timevar_pop (TV_BRANCH_PROB);
3097 if (flag_optimize_sibling_calls)
3098 rest_of_handle_sibling_calls (insns);
3100 timevar_pop (TV_JUMP);
3102 insn_locators_initialize ();
3103 /* Complete generation of exception handling code. */
3104 if (doing_eh (0))
3106 timevar_push (TV_JUMP);
3107 open_dump_file (DFI_eh, decl);
3109 finish_eh_generation ();
3111 close_dump_file (DFI_eh, print_rtl, get_insns ());
3112 timevar_pop (TV_JUMP);
3115 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
3116 generation, which might create new sets. */
3117 emit_initial_value_sets ();
3119 #ifdef FINALIZE_PIC
3120 /* If we are doing position-independent code generation, now
3121 is the time to output special prologues and epilogues.
3122 We do not want to do this earlier, because it just clutters
3123 up inline functions with meaningless insns. */
3124 if (flag_pic)
3125 FINALIZE_PIC;
3126 #endif
3128 insns = get_insns ();
3130 /* Copy any shared structure that should not be shared. */
3131 unshare_all_rtl (current_function_decl, insns);
3133 #ifdef SETJMP_VIA_SAVE_AREA
3134 /* This must be performed before virtual register instantiation.
3135 Please be aware the everything in the compiler that can look
3136 at the RTL up to this point must understand that REG_SAVE_AREA
3137 is just like a use of the REG contained inside. */
3138 if (current_function_calls_alloca)
3139 optimize_save_area_alloca (insns);
3140 #endif
3142 /* Instantiate all virtual registers. */
3143 instantiate_virtual_regs (current_function_decl, insns);
3145 open_dump_file (DFI_jump, decl);
3147 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3148 are initialized and to compute whether control can drop off the end
3149 of the function. */
3151 timevar_push (TV_JUMP);
3152 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
3153 before jump optimization switches branch directions. */
3154 if (flag_guess_branch_prob)
3155 expected_value_to_br_prob ();
3157 reg_scan (insns, max_reg_num (), 0);
3158 rebuild_jump_labels (insns);
3159 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3160 delete_trivially_dead_insns (insns, max_reg_num ());
3161 if (rtl_dump_file)
3162 dump_flow_info (rtl_dump_file);
3163 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
3164 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
3166 if (optimize)
3168 free_bb_for_insn ();
3169 copy_loop_headers (insns);
3170 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3172 purge_line_number_notes (insns);
3174 timevar_pop (TV_JUMP);
3175 close_dump_file (DFI_jump, print_rtl, insns);
3177 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
3178 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
3179 goto exit_rest_of_compilation;
3181 /* Long term, this should probably move before the jump optimizer too,
3182 but I didn't want to disturb the rtl_dump_and_exit and related
3183 stuff at this time. */
3184 if (optimize > 0 && flag_ssa)
3185 insns = rest_of_handle_ssa (decl, insns);
3187 timevar_push (TV_JUMP);
3189 if (optimize)
3190 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3192 if (flag_delete_null_pointer_checks)
3193 rest_of_handle_null_pointer (decl, insns);
3195 /* Jump optimization, and the removal of NULL pointer checks, may
3196 have reduced the number of instructions substantially. CSE, and
3197 future passes, allocate arrays whose dimensions involve the
3198 maximum instruction UID, so if we can reduce the maximum UID
3199 we'll save big on memory. */
3200 renumber_insns (rtl_dump_file);
3201 timevar_pop (TV_JUMP);
3203 close_dump_file (DFI_jump, print_rtl_with_bb, insns);
3205 ggc_collect ();
3207 if (optimize > 0)
3208 rest_of_handle_cse (decl, insns);
3210 rest_of_handle_addressof (decl, insns);
3212 ggc_collect ();
3214 if (optimize > 0)
3216 if (flag_gcse)
3217 rest_of_handle_gcse (decl, insns);
3219 if (flag_loop_optimize)
3220 rest_of_handle_loop_optimize (decl, insns);
3222 if (flag_gcse)
3223 rest_of_handle_jump_bypass (decl, insns);
3226 timevar_push (TV_FLOW);
3228 rest_of_handle_cfg (decl, insns);
3230 if (optimize > 0
3231 || profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
3232 rest_of_handle_branch_prob (decl, insns);
3234 if (optimize > 0)
3235 rest_of_handle_if_conversion (decl, insns);
3237 if (flag_tracer)
3238 rest_of_handle_tracer (decl, insns);
3240 if (optimize > 0
3241 && (flag_unswitch_loops
3242 || flag_peel_loops
3243 || flag_unroll_loops))
3244 rest_of_handle_loop2 (decl, insns);
3246 if (flag_rerun_cse_after_loop)
3247 rest_of_handle_cse2 (decl, insns);
3249 cse_not_expected = 1;
3251 rest_of_handle_life (decl, insns);
3253 if (optimize > 0)
3254 rest_of_handle_combine (decl, insns);
3256 if (flag_if_conversion)
3257 rest_of_handle_if_after_combine (decl, insns);
3259 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
3260 rest_of_handle_regmove (decl, insns);
3262 /* Do unconditional splitting before register allocation to allow machine
3263 description to add extra information not needed previously. */
3264 split_all_insns (1);
3266 #ifdef OPTIMIZE_MODE_SWITCHING
3267 timevar_push (TV_MODE_SWITCH);
3269 no_new_pseudos = 0;
3270 optimize_mode_switching (NULL);
3271 no_new_pseudos = 1;
3273 timevar_pop (TV_MODE_SWITCH);
3274 #endif
3276 /* Any of the several passes since flow1 will have munged register
3277 lifetime data a bit. We need it to be up to date for scheduling
3278 (see handling of reg_known_equiv in init_alias_analysis). */
3279 recompute_reg_usage (insns, !optimize_size);
3281 #ifdef INSN_SCHEDULING
3282 rest_of_handle_sched (decl, insns);
3283 #endif
3285 /* Determine if the current function is a leaf before running reload
3286 since this can impact optimizations done by the prologue and
3287 epilogue thus changing register elimination offsets. */
3288 current_function_is_leaf = leaf_function_p ();
3290 timevar_push (TV_LOCAL_ALLOC);
3291 open_dump_file (DFI_lreg, decl);
3293 if (flag_new_regalloc)
3295 if (rest_of_handle_new_regalloc (decl, insns,
3296 &rebuild_label_notes_after_reload))
3297 goto exit_rest_of_compilation;
3299 else
3301 if (rest_of_handle_old_regalloc (decl, insns,
3302 &rebuild_label_notes_after_reload))
3303 goto exit_rest_of_compilation;
3306 ggc_collect ();
3308 open_dump_file (DFI_postreload, decl);
3310 /* Do a very simple CSE pass over just the hard registers. */
3311 if (optimize > 0)
3313 timevar_push (TV_RELOAD_CSE_REGS);
3314 reload_cse_regs (insns);
3315 timevar_pop (TV_RELOAD_CSE_REGS);
3318 /* Register allocation and reloading may have turned an indirect jump into
3319 a direct jump. If so, we must rebuild the JUMP_LABEL fields of
3320 jumping instructions. */
3321 if (rebuild_label_notes_after_reload)
3323 timevar_push (TV_JUMP);
3325 rebuild_jump_labels (insns);
3326 purge_all_dead_edges (0);
3328 timevar_pop (TV_JUMP);
3331 close_dump_file (DFI_postreload, print_rtl_with_bb, insns);
3333 /* Re-create the death notes which were deleted during reload. */
3334 timevar_push (TV_FLOW2);
3335 open_dump_file (DFI_flow2, decl);
3337 #ifdef ENABLE_CHECKING
3338 verify_flow_info ();
3339 #endif
3341 /* If optimizing, then go ahead and split insns now. */
3342 #ifndef STACK_REGS
3343 if (optimize > 0)
3344 #endif
3345 split_all_insns (0);
3347 if (flag_branch_target_load_optimize)
3349 open_dump_file (DFI_branch_target_load, decl);
3351 branch_target_load_optimize (insns, false);
3353 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3355 ggc_collect ();
3358 if (optimize)
3359 cleanup_cfg (CLEANUP_EXPENSIVE);
3361 /* On some machines, the prologue and epilogue code, or parts thereof,
3362 can be represented as RTL. Doing so lets us schedule insns between
3363 it and the rest of the code and also allows delayed branch
3364 scheduling to operate in the epilogue. */
3365 thread_prologue_and_epilogue_insns (insns);
3366 epilogue_completed = 1;
3368 if (optimize)
3370 life_analysis (insns, rtl_dump_file, PROP_FINAL);
3371 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
3372 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
3374 /* This is kind of a heuristic. We need to run combine_stack_adjustments
3375 even for machines with possibly nonzero RETURN_POPS_ARGS
3376 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
3377 push instructions will have popping returns. */
3378 #ifndef PUSH_ROUNDING
3379 if (!ACCUMULATE_OUTGOING_ARGS)
3380 #endif
3381 combine_stack_adjustments ();
3383 ggc_collect ();
3386 flow2_completed = 1;
3388 close_dump_file (DFI_flow2, print_rtl_with_bb, insns);
3389 timevar_pop (TV_FLOW2);
3391 #ifdef HAVE_peephole2
3392 if (optimize > 0 && flag_peephole2)
3394 timevar_push (TV_PEEPHOLE2);
3395 open_dump_file (DFI_peephole2, decl);
3397 peephole2_optimize (rtl_dump_file);
3399 close_dump_file (DFI_peephole2, print_rtl_with_bb, insns);
3400 timevar_pop (TV_PEEPHOLE2);
3402 #endif
3404 if (optimize > 0)
3406 if (flag_rename_registers || flag_cprop_registers)
3407 rest_of_handle_regrename (decl, insns);
3409 rest_of_handle_reorder_blocks (decl, insns);
3412 if (flag_if_conversion2)
3414 timevar_push (TV_IFCVT2);
3415 open_dump_file (DFI_ce3, decl);
3417 if_convert (1);
3419 close_dump_file (DFI_ce3, print_rtl_with_bb, insns);
3420 timevar_pop (TV_IFCVT2);
3423 if (flag_branch_target_load_optimize2)
3425 /* Leave this a warning for now so that it is possible to experiment
3426 with running this pass twice. In 3.6, we should either make this
3427 an error, or use separate dump files. */
3428 if (flag_branch_target_load_optimize)
3429 warning ("branch target register load optimization is not intended "
3430 "to be run twice");
3432 open_dump_file (DFI_branch_target_load, decl);
3434 branch_target_load_optimize (insns, true);
3436 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3438 ggc_collect ();
3441 #ifdef INSN_SCHEDULING
3442 if (optimize > 0 && flag_schedule_insns_after_reload)
3443 rest_of_handle_sched2 (decl, insns);
3444 #endif
3446 #ifdef LEAF_REGISTERS
3447 current_function_uses_only_leaf_regs
3448 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
3449 #endif
3451 #ifdef STACK_REGS
3452 rest_of_handle_stack_regs (decl, insns);
3453 #endif
3455 compute_alignments ();
3457 /* CFG is no longer maintained up-to-date. */
3458 free_bb_for_insn ();
3460 if (targetm.machine_dependent_reorg != 0)
3461 rest_of_handle_machine_reorg (decl, insns);
3463 purge_line_number_notes (insns);
3464 cleanup_barriers ();
3466 #ifdef DELAY_SLOTS
3467 if (optimize > 0 && flag_delayed_branch)
3468 rest_of_handle_delay_slots (decl, insns);
3469 #endif
3471 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3472 timevar_push (TV_SHORTEN_BRANCH);
3473 split_all_insns_noflow ();
3474 timevar_pop (TV_SHORTEN_BRANCH);
3475 #endif
3477 convert_to_eh_region_ranges ();
3479 /* Shorten branches. */
3480 timevar_push (TV_SHORTEN_BRANCH);
3481 shorten_branches (get_insns ());
3482 timevar_pop (TV_SHORTEN_BRANCH);
3484 set_nothrow_function_flags ();
3485 if (current_function_nothrow)
3486 /* Now we know that this can't throw; set the flag for the benefit
3487 of other functions later in this translation unit. */
3488 TREE_NOTHROW (current_function_decl) = 1;
3490 rest_of_handle_final (decl, insns);
3492 /* Write DBX symbols if requested. */
3494 /* Note that for those inline functions where we don't initially
3495 know for certain that we will be generating an out-of-line copy,
3496 the first invocation of this routine (rest_of_compilation) will
3497 skip over this code by doing a `goto exit_rest_of_compilation;'.
3498 Later on, wrapup_global_declarations will (indirectly) call
3499 rest_of_compilation again for those inline functions that need
3500 to have out-of-line copies generated. During that call, we
3501 *will* be routed past here. */
3503 timevar_push (TV_SYMOUT);
3504 (*debug_hooks->function_decl) (decl);
3505 timevar_pop (TV_SYMOUT);
3507 exit_rest_of_compilation:
3509 coverage_end_function ();
3511 /* In case the function was not output,
3512 don't leave any temporary anonymous types
3513 queued up for sdb output. */
3514 #ifdef SDB_DEBUGGING_INFO
3515 if (write_symbols == SDB_DEBUG)
3516 sdbout_types (NULL_TREE);
3517 #endif
3519 reload_completed = 0;
3520 epilogue_completed = 0;
3521 flow2_completed = 0;
3522 no_new_pseudos = 0;
3524 timevar_push (TV_FINAL);
3526 /* Clear out the insn_length contents now that they are no
3527 longer valid. */
3528 init_insn_lengths ();
3530 /* Show no temporary slots allocated. */
3531 init_temp_slots ();
3533 free_basic_block_vars (0);
3534 free_bb_for_insn ();
3536 timevar_pop (TV_FINAL);
3538 if ((*targetm.binds_local_p) (current_function_decl))
3540 int pref = cfun->preferred_stack_boundary;
3541 if (cfun->recursive_call_emit
3542 && cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
3543 pref = cfun->stack_alignment_needed;
3544 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
3545 = pref;
3548 /* Make sure volatile mem refs aren't considered valid operands for
3549 arithmetic insns. We must call this here if this is a nested inline
3550 function, since the above code leaves us in the init_recog state
3551 (from final.c), and the function context push/pop code does not
3552 save/restore volatile_ok.
3554 ??? Maybe it isn't necessary for expand_start_function to call this
3555 anymore if we do it here? */
3557 init_recog_no_volatile ();
3559 /* We're done with this function. Free up memory if we can. */
3560 free_after_parsing (cfun);
3561 if (! DECL_DEFER_OUTPUT (decl))
3563 free_after_compilation (cfun);
3564 DECL_SAVED_INSNS (decl) = 0;
3566 cfun = 0;
3568 ggc_collect ();
3570 timevar_pop (TV_REST_OF_COMPILATION);
3573 /* Display help for target options. */
3574 void
3575 display_target_options (void)
3577 int undoc, i;
3578 static bool displayed = false;
3580 /* Avoid double printing for --help --target-help. */
3581 if (displayed)
3582 return;
3584 displayed = true;
3586 if (ARRAY_SIZE (target_switches) > 1
3587 #ifdef TARGET_OPTIONS
3588 || ARRAY_SIZE (target_options) > 1
3589 #endif
3592 int doc = 0;
3594 undoc = 0;
3596 printf (_("\nTarget specific options:\n"));
3598 for (i = ARRAY_SIZE (target_switches); i--;)
3600 const char *option = target_switches[i].name;
3601 const char *description = target_switches[i].description;
3603 if (option == NULL || *option == 0)
3604 continue;
3605 else if (description == NULL)
3607 undoc = 1;
3609 if (extra_warnings)
3610 printf (_(" -m%-23s [undocumented]\n"), option);
3612 else if (*description != 0)
3613 doc += printf (" -m%-23s %s\n", option, _(description));
3616 #ifdef TARGET_OPTIONS
3617 for (i = ARRAY_SIZE (target_options); i--;)
3619 const char *option = target_options[i].prefix;
3620 const char *description = target_options[i].description;
3622 if (option == NULL || *option == 0)
3623 continue;
3624 else if (description == NULL)
3626 undoc = 1;
3628 if (extra_warnings)
3629 printf (_(" -m%-23s [undocumented]\n"), option);
3631 else if (*description != 0)
3632 doc += printf (" -m%-23s %s\n", option, _(description));
3634 #endif
3635 if (undoc)
3637 if (doc)
3638 printf (_("\nThere are undocumented target specific options as well.\n"));
3639 else
3640 printf (_(" They exist, but they are not documented.\n"));
3645 /* Parse a -d... command line switch. */
3647 void
3648 decode_d_option (const char *arg)
3650 int i, c, matched;
3652 while (*arg)
3653 switch (c = *arg++)
3655 case 'a':
3656 for (i = 0; i < (int) DFI_MAX; ++i)
3657 dump_file[i].enabled = 1;
3658 break;
3659 case 'A':
3660 flag_debug_asm = 1;
3661 break;
3662 case 'p':
3663 flag_print_asm_name = 1;
3664 break;
3665 case 'P':
3666 flag_dump_rtl_in_asm = 1;
3667 flag_print_asm_name = 1;
3668 break;
3669 case 'v':
3670 graph_dump_format = vcg;
3671 break;
3672 case 'x':
3673 rtl_dump_and_exit = 1;
3674 break;
3675 case 'y':
3676 set_yydebug = 1;
3677 break;
3678 case 'D': /* These are handled by the preprocessor. */
3679 case 'I':
3680 break;
3681 case 'H':
3682 setup_core_dumping();
3683 break;
3685 default:
3686 matched = 0;
3687 for (i = 0; i < (int) DFI_MAX; ++i)
3688 if (c == dump_file[i].debug_switch)
3690 dump_file[i].enabled = 1;
3691 matched = 1;
3694 if (! matched)
3695 warning ("unrecognized gcc debugging option: %c", c);
3696 break;
3700 /* Indexed by enum debug_info_type. */
3701 const char *const debug_type_names[] =
3703 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
3706 /* Decode -m switches. */
3707 /* Decode the switch -mNAME. */
3709 void
3710 set_target_switch (const char *name)
3712 size_t j;
3713 int valid_target_option = 0;
3715 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
3716 if (!strcmp (target_switches[j].name, name))
3718 if (target_switches[j].value < 0)
3719 target_flags &= ~-target_switches[j].value;
3720 else
3721 target_flags |= target_switches[j].value;
3722 if (name[0] != 0)
3724 if (target_switches[j].value < 0)
3725 target_flags_explicit |= -target_switches[j].value;
3726 else
3727 target_flags_explicit |= target_switches[j].value;
3729 valid_target_option = 1;
3732 #ifdef TARGET_OPTIONS
3733 if (!valid_target_option)
3734 for (j = 0; j < ARRAY_SIZE (target_options); j++)
3736 int len = strlen (target_options[j].prefix);
3737 if (target_options[j].value)
3739 if (!strcmp (target_options[j].prefix, name))
3741 *target_options[j].variable = target_options[j].value;
3742 valid_target_option = 1;
3745 else
3747 if (!strncmp (target_options[j].prefix, name, len))
3749 *target_options[j].variable = name + len;
3750 valid_target_option = 1;
3754 #endif
3756 if (!valid_target_option)
3757 error ("invalid option `%s'", name);
3760 /* Print version information to FILE.
3761 Each line begins with INDENT (for the case where FILE is the
3762 assembler output file). */
3764 void
3765 print_version (FILE *file, const char *indent)
3767 #ifndef __VERSION__
3768 #define __VERSION__ "[?]"
3769 #endif
3770 fnotice (file,
3771 #ifdef __GNUC__
3772 "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
3773 #else
3774 "%s%s%s version %s (%s) compiled by CC.\n"
3775 #endif
3776 , indent, *indent != 0 ? " " : "",
3777 lang_hooks.name, version_string, TARGET_NAME,
3778 indent, __VERSION__);
3779 fnotice (file, "%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n",
3780 indent, *indent != 0 ? " " : "",
3781 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
3784 /* Print an option value and return the adjusted position in the line.
3785 ??? We don't handle error returns from fprintf (disk full); presumably
3786 other code will catch a disk full though. */
3788 static int
3789 print_single_switch (FILE *file, int pos, int max,
3790 const char *indent, const char *sep, const char *term,
3791 const char *type, const char *name)
3793 /* The ultrix fprintf returns 0 on success, so compute the result we want
3794 here since we need it for the following test. */
3795 int len = strlen (sep) + strlen (type) + strlen (name);
3797 if (pos != 0
3798 && pos + len > max)
3800 fprintf (file, "%s", term);
3801 pos = 0;
3803 if (pos == 0)
3805 fprintf (file, "%s", indent);
3806 pos = strlen (indent);
3808 fprintf (file, "%s%s%s", sep, type, name);
3809 pos += len;
3810 return pos;
3813 /* Print active target switches to FILE.
3814 POS is the current cursor position and MAX is the size of a "line".
3815 Each line begins with INDENT and ends with TERM.
3816 Each switch is separated from the next by SEP. */
3818 static void
3819 print_switch_values (FILE *file, int pos, int max,
3820 const char *indent, const char *sep, const char *term)
3822 size_t j;
3823 const char **p;
3825 /* Fill in the -frandom-seed option, if the user didn't pass it, so
3826 that it can be printed below. This helps reproducibility. */
3827 randomize ();
3829 /* Print the options as passed. */
3830 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
3831 _("options passed: "), "");
3833 for (p = &save_argv[1]; *p != NULL; p++)
3834 if (**p == '-')
3836 /* Ignore these. */
3837 if (strcmp (*p, "-o") == 0)
3839 if (p[1] != NULL)
3840 p++;
3841 continue;
3843 if (strcmp (*p, "-quiet") == 0)
3844 continue;
3845 if (strcmp (*p, "-version") == 0)
3846 continue;
3847 if ((*p)[1] == 'd')
3848 continue;
3850 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
3852 if (pos > 0)
3853 fprintf (file, "%s", term);
3855 /* Print the -f and -m options that have been enabled.
3856 We don't handle language specific options but printing argv
3857 should suffice. */
3859 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
3860 _("options enabled: "), "");
3862 for (j = 0; j < ARRAY_SIZE (f_options); j++)
3863 if (*f_options[j].variable == f_options[j].on_value)
3864 pos = print_single_switch (file, pos, max, indent, sep, term,
3865 "-f", f_options[j].string);
3867 /* Print target specific options. */
3869 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
3870 if (target_switches[j].name[0] != '\0'
3871 && target_switches[j].value > 0
3872 && ((target_switches[j].value & target_flags)
3873 == target_switches[j].value))
3875 pos = print_single_switch (file, pos, max, indent, sep, term,
3876 "-m", target_switches[j].name);
3879 #ifdef TARGET_OPTIONS
3880 for (j = 0; j < ARRAY_SIZE (target_options); j++)
3881 if (*target_options[j].variable != NULL)
3883 char prefix[256];
3884 sprintf (prefix, "-m%s", target_options[j].prefix);
3885 pos = print_single_switch (file, pos, max, indent, sep, term,
3886 prefix, *target_options[j].variable);
3888 #endif
3890 fprintf (file, "%s", term);
3893 /* Open assembly code output file. Do this even if -fsyntax-only is
3894 on, because then the driver will have provided the name of a
3895 temporary file or bit bucket for us. NAME is the file specified on
3896 the command line, possibly NULL. */
3897 static void
3898 init_asm_output (const char *name)
3900 if (name == NULL && asm_file_name == 0)
3901 asm_out_file = stdout;
3902 else
3904 if (asm_file_name == 0)
3906 int len = strlen (dump_base_name);
3907 char *dumpname = xmalloc (len + 6);
3908 memcpy (dumpname, dump_base_name, len + 1);
3909 strip_off_ending (dumpname, len);
3910 strcat (dumpname, ".s");
3911 asm_file_name = dumpname;
3913 if (!strcmp (asm_file_name, "-"))
3914 asm_out_file = stdout;
3915 else
3916 asm_out_file = fopen (asm_file_name, "w+");
3917 if (asm_out_file == 0)
3918 fatal_error ("can't open %s for writing: %m", asm_file_name);
3921 #ifdef IO_BUFFER_SIZE
3922 setvbuf (asm_out_file, xmalloc (IO_BUFFER_SIZE),
3923 _IOFBF, IO_BUFFER_SIZE);
3924 #endif
3926 if (!flag_syntax_only)
3928 targetm.asm_out.file_start ();
3930 #ifdef ASM_COMMENT_START
3931 if (flag_verbose_asm)
3933 /* Print the list of options in effect. */
3934 print_version (asm_out_file, ASM_COMMENT_START);
3935 print_switch_values (asm_out_file, 0, MAX_LINE,
3936 ASM_COMMENT_START, " ", "\n");
3937 /* Add a blank line here so it appears in assembler output but not
3938 screen output. */
3939 fprintf (asm_out_file, "\n");
3941 #endif
3945 /* Default tree printer. Handles declarations only. */
3946 static bool
3947 default_tree_printer (pretty_printer * pp, text_info *text)
3949 switch (*text->format_spec)
3951 case 'D':
3952 case 'F':
3953 case 'T':
3955 tree t = va_arg (*text->args_ptr, tree);
3956 const char *n = DECL_NAME (t)
3957 ? (*lang_hooks.decl_printable_name) (t, 2)
3958 : "<anonymous>";
3959 pp_string (pp, n);
3961 return true;
3963 default:
3964 return false;
3968 /* Initialization of the front end environment, before command line
3969 options are parsed. Signal handlers, internationalization etc.
3970 ARGV0 is main's argv[0]. */
3971 static void
3972 general_init (const char *argv0)
3974 const char *p;
3976 p = argv0 + strlen (argv0);
3977 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
3978 --p;
3979 progname = p;
3981 xmalloc_set_program_name (progname);
3983 hex_init ();
3985 gcc_init_libintl ();
3987 /* Initialize the diagnostics reporting machinery, so option parsing
3988 can give warnings and errors. */
3989 diagnostic_initialize (global_dc);
3990 /* Set a default printer. Language specific initializations will
3991 override it later. */
3992 pp_format_decoder (global_dc->printer) = &default_tree_printer;
3994 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
3995 #ifdef SIGSEGV
3996 signal (SIGSEGV, crash_signal);
3997 #endif
3998 #ifdef SIGILL
3999 signal (SIGILL, crash_signal);
4000 #endif
4001 #ifdef SIGBUS
4002 signal (SIGBUS, crash_signal);
4003 #endif
4004 #ifdef SIGABRT
4005 signal (SIGABRT, crash_signal);
4006 #endif
4007 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
4008 signal (SIGIOT, crash_signal);
4009 #endif
4010 #ifdef SIGFPE
4011 signal (SIGFPE, crash_signal);
4012 #endif
4014 /* Other host-specific signal setup. */
4015 (*host_hooks.extra_signals)();
4017 /* Initialize the garbage-collector, string pools and tree type hash
4018 table. */
4019 init_ggc ();
4020 init_stringpool ();
4021 init_ttree ();
4023 /* Initialize register usage now so switches may override. */
4024 init_reg_sets ();
4026 /* Register the language-independent parameters. */
4027 add_params (lang_independent_params, LAST_PARAM);
4029 /* This must be done after add_params but before argument processing. */
4030 init_ggc_heuristics();
4033 /* Process the options that have been parsed. */
4034 static void
4035 process_options (void)
4037 /* Allow the front end to perform consistency checks and do further
4038 initialization based on the command line options. This hook also
4039 sets the original filename if appropriate (e.g. foo.i -> foo.c)
4040 so we can correctly initialize debug output. */
4041 no_backend = (*lang_hooks.post_options) (&main_input_filename);
4042 input_filename = main_input_filename;
4044 #ifdef OVERRIDE_OPTIONS
4045 /* Some machines may reject certain combinations of options. */
4046 OVERRIDE_OPTIONS;
4047 #endif
4049 /* Set aux_base_name if not already set. */
4050 if (aux_base_name)
4052 else if (main_input_filename)
4054 char *name = xstrdup (lbasename (main_input_filename));
4056 strip_off_ending (name, strlen (name));
4057 aux_base_name = name;
4059 else
4060 aux_base_name = "gccaux";
4062 /* Set up the align_*_log variables, defaulting them to 1 if they
4063 were still unset. */
4064 if (align_loops <= 0) align_loops = 1;
4065 if (align_loops_max_skip > align_loops || !align_loops)
4066 align_loops_max_skip = align_loops - 1;
4067 align_loops_log = floor_log2 (align_loops * 2 - 1);
4068 if (align_jumps <= 0) align_jumps = 1;
4069 if (align_jumps_max_skip > align_jumps || !align_jumps)
4070 align_jumps_max_skip = align_jumps - 1;
4071 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
4072 if (align_labels <= 0) align_labels = 1;
4073 align_labels_log = floor_log2 (align_labels * 2 - 1);
4074 if (align_labels_max_skip > align_labels || !align_labels)
4075 align_labels_max_skip = align_labels - 1;
4076 if (align_functions <= 0) align_functions = 1;
4077 align_functions_log = floor_log2 (align_functions * 2 - 1);
4079 /* Unrolling all loops implies that standard loop unrolling must also
4080 be done. */
4081 if (flag_unroll_all_loops)
4082 flag_unroll_loops = 1;
4084 if (flag_unroll_loops)
4086 flag_old_unroll_loops = 0;
4087 flag_old_unroll_all_loops = 0;
4090 if (flag_old_unroll_all_loops)
4091 flag_old_unroll_loops = 1;
4093 /* Old loop unrolling requires that strength_reduction be on also. Silently
4094 turn on strength reduction here if it isn't already on. Also, the loop
4095 unrolling code assumes that cse will be run after loop, so that must
4096 be turned on also. */
4097 if (flag_old_unroll_loops)
4099 flag_strength_reduce = 1;
4100 flag_rerun_cse_after_loop = 1;
4102 if (flag_unroll_loops || flag_peel_loops)
4103 flag_rerun_cse_after_loop = 1;
4105 if (flag_non_call_exceptions)
4106 flag_asynchronous_unwind_tables = 1;
4107 if (flag_asynchronous_unwind_tables)
4108 flag_unwind_tables = 1;
4110 /* Disable unit-at-a-time mode for frontends not supporting callgraph
4111 interface. */
4112 if (flag_unit_at_a_time && ! lang_hooks.callgraph.expand_function)
4113 flag_unit_at_a_time = 0;
4115 /* Warn about options that are not supported on this machine. */
4116 #ifndef INSN_SCHEDULING
4117 if (flag_schedule_insns || flag_schedule_insns_after_reload)
4118 warning ("instruction scheduling not supported on this target machine");
4119 #endif
4120 #ifndef DELAY_SLOTS
4121 if (flag_delayed_branch)
4122 warning ("this target machine does not have delayed branches");
4123 #endif
4125 user_label_prefix = USER_LABEL_PREFIX;
4126 if (flag_leading_underscore != -1)
4128 /* If the default prefix is more complicated than "" or "_",
4129 issue a warning and ignore this option. */
4130 if (user_label_prefix[0] == 0 ||
4131 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
4133 user_label_prefix = flag_leading_underscore ? "_" : "";
4135 else
4136 warning ("-f%sleading-underscore not supported on this target machine",
4137 flag_leading_underscore ? "" : "no-");
4140 /* If we are in verbose mode, write out the version and maybe all the
4141 option flags in use. */
4142 if (version_flag)
4144 print_version (stderr, "");
4145 if (! quiet_flag)
4146 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
4149 if (flag_syntax_only)
4151 write_symbols = NO_DEBUG;
4152 profile_flag = 0;
4155 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
4156 level is 0. */
4157 if (debug_info_level == DINFO_LEVEL_NONE)
4158 write_symbols = NO_DEBUG;
4160 /* Now we know write_symbols, set up the debug hooks based on it.
4161 By default we do nothing for debug output. */
4162 if (write_symbols == NO_DEBUG)
4163 debug_hooks = &do_nothing_debug_hooks;
4164 #if defined(DBX_DEBUGGING_INFO)
4165 else if (write_symbols == DBX_DEBUG)
4166 debug_hooks = &dbx_debug_hooks;
4167 #endif
4168 #if defined(XCOFF_DEBUGGING_INFO)
4169 else if (write_symbols == XCOFF_DEBUG)
4170 debug_hooks = &xcoff_debug_hooks;
4171 #endif
4172 #ifdef SDB_DEBUGGING_INFO
4173 else if (write_symbols == SDB_DEBUG)
4174 debug_hooks = &sdb_debug_hooks;
4175 #endif
4176 #ifdef DWARF_DEBUGGING_INFO
4177 else if (write_symbols == DWARF_DEBUG)
4178 debug_hooks = &dwarf_debug_hooks;
4179 #endif
4180 #ifdef DWARF2_DEBUGGING_INFO
4181 else if (write_symbols == DWARF2_DEBUG)
4182 debug_hooks = &dwarf2_debug_hooks;
4183 #endif
4184 #ifdef VMS_DEBUGGING_INFO
4185 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
4186 debug_hooks = &vmsdbg_debug_hooks;
4187 #endif
4188 else
4189 error ("target system does not support the \"%s\" debug format",
4190 debug_type_names[write_symbols]);
4192 /* If auxiliary info generation is desired, open the output file.
4193 This goes in the same directory as the source file--unlike
4194 all the other output files. */
4195 if (flag_gen_aux_info)
4197 aux_info_file = fopen (aux_info_file_name, "w");
4198 if (aux_info_file == 0)
4199 fatal_error ("can't open %s: %m", aux_info_file_name);
4202 if (! targetm.have_named_sections)
4204 if (flag_function_sections)
4206 warning ("-ffunction-sections not supported for this target");
4207 flag_function_sections = 0;
4209 if (flag_data_sections)
4211 warning ("-fdata-sections not supported for this target");
4212 flag_data_sections = 0;
4216 if (flag_function_sections && profile_flag)
4218 warning ("-ffunction-sections disabled; it makes profiling impossible");
4219 flag_function_sections = 0;
4222 #ifndef HAVE_prefetch
4223 if (flag_prefetch_loop_arrays)
4225 warning ("-fprefetch-loop-arrays not supported for this target");
4226 flag_prefetch_loop_arrays = 0;
4228 #else
4229 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
4231 warning ("-fprefetch-loop-arrays not supported for this target (try -march switches)");
4232 flag_prefetch_loop_arrays = 0;
4234 #endif
4236 /* This combination of options isn't handled for i386 targets and doesn't
4237 make much sense anyway, so don't allow it. */
4238 if (flag_prefetch_loop_arrays && optimize_size)
4240 warning ("-fprefetch-loop-arrays is not supported with -Os");
4241 flag_prefetch_loop_arrays = 0;
4244 #ifndef OBJECT_FORMAT_ELF
4245 if (flag_function_sections && write_symbols != NO_DEBUG)
4246 warning ("-ffunction-sections may affect debugging on some targets");
4247 #endif
4249 /* The presence of IEEE signaling NaNs, implies all math can trap. */
4250 if (flag_signaling_nans)
4251 flag_trapping_math = 1;
4254 /* Initialize the compiler back end. */
4255 static void
4256 backend_init (void)
4258 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
4259 || debug_info_level == DINFO_LEVEL_VERBOSE
4260 #ifdef VMS_DEBUGGING_INFO
4261 /* Enable line number info for traceback. */
4262 || debug_info_level > DINFO_LEVEL_NONE
4263 #endif
4264 || flag_test_coverage
4265 || warn_notreached);
4267 init_regs ();
4268 init_fake_stack_mems ();
4269 init_alias_once ();
4270 init_loop ();
4271 init_reload ();
4272 init_function_once ();
4273 init_varasm_once ();
4275 /* The following initialization functions need to generate rtl, so
4276 provide a dummy function context for them. */
4277 init_dummy_function_start ();
4278 init_expmed ();
4279 if (flag_caller_saves)
4280 init_caller_save ();
4281 expand_dummy_function_end ();
4284 /* Language-dependent initialization. Returns nonzero on success. */
4285 static int
4286 lang_dependent_init (const char *name)
4288 if (dump_base_name == 0)
4289 dump_base_name = name ? name : "gccdump";
4291 /* Other front-end initialization. */
4292 if ((*lang_hooks.init) () == 0)
4293 return 0;
4295 init_asm_output (name);
4297 /* These create various _DECL nodes, so need to be called after the
4298 front end is initialized. */
4299 init_eh ();
4300 init_optabs ();
4302 /* The following initialization functions need to generate rtl, so
4303 provide a dummy function context for them. */
4304 init_dummy_function_start ();
4305 init_expr_once ();
4306 expand_dummy_function_end ();
4308 /* If dbx symbol table desired, initialize writing it and output the
4309 predefined types. */
4310 timevar_push (TV_SYMOUT);
4312 #ifdef DWARF2_UNWIND_INFO
4313 if (dwarf2out_do_frame ())
4314 dwarf2out_frame_init ();
4315 #endif
4317 /* Now we have the correct original filename, we can initialize
4318 debug output. */
4319 (*debug_hooks->init) (name);
4321 timevar_pop (TV_SYMOUT);
4323 return 1;
4326 /* Clean up: close opened files, etc. */
4328 static void
4329 finalize (void)
4331 /* Close the dump files. */
4332 if (flag_gen_aux_info)
4334 fclose (aux_info_file);
4335 if (errorcount)
4336 unlink (aux_info_file_name);
4339 /* Close non-debugging input and output files. Take special care to note
4340 whether fclose returns an error, since the pages might still be on the
4341 buffer chain while the file is open. */
4343 if (asm_out_file)
4345 if (ferror (asm_out_file) != 0)
4346 fatal_error ("error writing to %s: %m", asm_file_name);
4347 if (fclose (asm_out_file) != 0)
4348 fatal_error ("error closing %s: %m", asm_file_name);
4351 /* Do whatever is necessary to finish printing the graphs. */
4352 if (graph_dump_format != no_graph)
4354 int i;
4356 for (i = 0; i < (int) DFI_MAX; ++i)
4357 if (dump_file[i].initialized && dump_file[i].graph_dump_p)
4359 char seq[16];
4360 char *suffix;
4362 sprintf (seq, DUMPFILE_FORMAT, i);
4363 suffix = concat (seq, dump_file[i].extension, NULL);
4364 finish_graph_dump_file (dump_base_name, suffix);
4365 free (suffix);
4369 if (mem_report)
4371 ggc_print_statistics ();
4372 stringpool_statistics ();
4373 dump_tree_statistics ();
4376 /* Free up memory for the benefit of leak detectors. */
4377 free_reg_info ();
4379 /* Language-specific end of compilation actions. */
4380 (*lang_hooks.finish) ();
4383 /* Initialize the compiler, and compile the input file. */
4384 static void
4385 do_compile (void)
4387 /* Initialize timing first. The C front ends read the main file in
4388 the post_options hook, and C++ does file timings. */
4389 if (time_report || !quiet_flag || flag_detailed_statistics)
4390 timevar_init ();
4391 timevar_start (TV_TOTAL);
4393 process_options ();
4395 /* Don't do any more if an error has already occurred. */
4396 if (!errorcount)
4398 /* Set up the back-end if requested. */
4399 if (!no_backend)
4400 backend_init ();
4402 /* Language-dependent initialization. Returns true on success. */
4403 if (lang_dependent_init (main_input_filename))
4405 if (flag_unit_at_a_time)
4407 open_dump_file (DFI_cgraph, NULL);
4408 cgraph_dump_file = rtl_dump_file;
4409 rtl_dump_file = NULL;
4412 compile_file ();
4414 if (flag_unit_at_a_time)
4416 rtl_dump_file = cgraph_dump_file;
4417 cgraph_dump_file = NULL;
4418 close_dump_file (DFI_cgraph, NULL, NULL_RTX);
4422 finalize ();
4425 /* Stop timing and print the times. */
4426 timevar_stop (TV_TOTAL);
4427 timevar_print (stderr);
4430 /* Entry point of cc1, cc1plus, jc1, f771, etc.
4431 Exit code is FATAL_EXIT_CODE if can't open files or if there were
4432 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
4434 It is not safe to call this function more than once. */
4437 toplev_main (unsigned int argc, const char **argv)
4439 save_argv = argv;
4441 /* Initialization of GCC's environment, and diagnostics. */
4442 general_init (argv[0]);
4444 /* Parse the options and do minimal processing; basically just
4445 enough to default flags appropriately. */
4446 decode_options (argc, argv);
4448 randomize ();
4450 /* Exit early if we can (e.g. -help). */
4451 if (!exit_after_options)
4452 do_compile ();
4454 if (errorcount || sorrycount)
4455 return (FATAL_EXIT_CODE);
4457 return (SUCCESS_EXIT_CODE);