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
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
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
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. */
28 #undef FLOAT /* This is for hpux. They should change hpux. */
29 #undef FFS /* Some systems define this in param.h. */
31 #include "coretypes.h"
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
48 #include "insn-attr.h"
49 #include "insn-config.h"
50 #include "insn-flags.h"
51 #include "hard-reg-set.h"
58 #include "basic-block.h"
65 #include "diagnostic.h"
69 #include "dwarf2asm.h"
70 #include "integrate.h"
74 #include "langhooks.h"
75 #include "cfglayout.h"
77 #include "hosthooks.h"
82 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
83 #include "dwarf2out.h"
86 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
90 #ifdef SDB_DEBUGGING_INFO
94 #ifdef XCOFF_DEBUGGING_INFO
95 #include "xcoffout.h" /* Needed for external data
96 declarations for e.g. AIX 4.x. */
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);
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);
154 static void rest_of_handle_stack_regs (tree, rtx);
156 static void rest_of_handle_machine_reorg (tree, rtx);
158 static void rest_of_handle_delay_slots (tree, rtx);
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. */
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. */
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."
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. */
242 /* True if the files have been initialized (ie truncated). */
246 /* Enumerate the extant dump files. */
284 DFI_branch_target_load,
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:
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. */
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
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. */
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. */
440 /* Print times taken by the various passes. -ftime-report. */
444 /* Print memory still in use at end of compilation (which may have little
445 to do with peak memory consumption). -fmem-report. */
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. */
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;
478 int flag_caller_saves = 0;
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
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
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. */
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
567 int flag_move_all_movables = 0;
569 /* Nonzero forces all general induction variables in loops to be
572 int flag_reduce_all_givs = 0;
574 /* Nonzero to perform full register move optimization passes. This is the
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. */
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
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
692 int flag_gcse_sm = 1;
694 /* Perform target register optimization before prologue / epilogue
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
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
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
766 /* Nonzero if we are compiling code for a shared library, zero for
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. */
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
787 int flag_asynchronous_unwind_tables = 0;
789 /* Nonzero means don't place uninitialized global data in common storage
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
801 flag_schedule_insns_after_reload means schedule insns after
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
812 int flag_sched2_use_traces = 0;
814 /* The following flags have effect only for scheduling before register
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
821 flag_schedule_speculative_load_dangerous allows speculative motion of more
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. */
867 int flag_gnu_linker = 0;
869 int flag_gnu_linker = 1;
872 /* Nonzero means put zero initialized data in the bss section. */
873 int flag_zero_initialized_in_bss = 1;
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. */
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
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
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. */
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. */
963 int align_loops_max_skip;
966 int align_jumps_max_skip;
968 int align_labels_log;
969 int align_labels_max_skip;
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;
979 const char *const string;
983 lang_independent_options;
985 /* Nonzero if signed arithmetic overflow should trap. */
988 /* Nonzero if signed arithmetic overflow should wrap around. */
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"
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.) */
1141 const char *const name;
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
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;
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. */
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
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
1186 set_src_pwd (const char *pwd)
1191 src_pwd = xstrdup (pwd);
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
1203 src_pwd = getpwd ();
1208 /* Called when the start of a function definition is parsed,
1209 this function prints on stderr the name of the function. */
1211 announce_function (tree decl)
1215 if (rtl_dump_and_exit)
1216 verbatim ("%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1218 verbatim (" %s", (*lang_hooks.decl_printable_name) (decl, 2));
1220 pp_needs_newline (global_dc->printer) = true;
1221 diagnostic_set_last_function (global_dc);
1225 /* Set up a default flag_random_seed and local_tick, unless the user
1226 already specified one. */
1231 if (!flag_random_seed)
1233 unsigned HOST_WIDE_INT value;
1234 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
1236 /* Get some more or less random data. */
1237 #ifdef HAVE_GETTIMEOFDAY
1241 gettimeofday (&tv, NULL);
1242 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
1246 time_t now = time (NULL);
1248 if (now != (time_t)-1)
1249 local_tick = (unsigned) now;
1252 value = local_tick ^ getpid ();
1254 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
1255 flag_random_seed = random_seed;
1257 else if (!local_tick)
1262 /* Decode the string P as an integral parameter.
1263 If the string is indeed an integer return its numeric value else
1264 issue an Invalid Option error for the option PNAME and return DEFVAL.
1265 If PNAME is zero just return DEFVAL, do not call error. */
1268 read_integral_parameter (const char *p, const char *pname, const int defval)
1270 const char *endp = p;
1274 if (ISDIGIT (*endp))
1283 error ("invalid option argument `%s'", pname);
1290 /* Return the logarithm of X, base 2, considering X unsigned,
1291 if X is a power of 2. Otherwise, returns -1.
1293 This should be used via the `exact_log2' macro. */
1296 exact_log2_wide (unsigned HOST_WIDE_INT x)
1299 /* Test for 0 or a power of 2. */
1300 if (x == 0 || x != (x & -x))
1302 while ((x >>= 1) != 0)
1307 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1308 If X is 0, return -1.
1310 This should be used via the floor_log2 macro. */
1313 floor_log2_wide (unsigned HOST_WIDE_INT x)
1322 /* Handler for fatal signals, such as SIGSEGV. These are transformed
1323 into ICE messages, which is much more user friendly. In case the
1324 error printer crashes, reset the signal to prevent infinite recursion. */
1327 crash_signal (int signo)
1329 signal (signo, SIG_DFL);
1330 internal_error ("%s", strsignal (signo));
1333 /* Arrange to dump core on error. (The regular error message is still
1334 printed first, except in the case of abort().) */
1337 setup_core_dumping (void)
1340 signal (SIGABRT, SIG_DFL);
1342 #if defined(HAVE_SETRLIMIT)
1345 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
1346 fatal_error ("getting core file size maximum limit: %m");
1347 rlim.rlim_cur = rlim.rlim_max;
1348 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
1349 fatal_error ("setting core file size limit to maximum: %m");
1352 diagnostic_abort_on_error (global_dc);
1356 /* Strip off a legitimate source ending from the input string NAME of
1357 length LEN. Rather than having to know the names used by all of
1358 our front ends, we strip off an ending of a period followed by
1359 up to five characters. (Java uses ".class".) */
1362 strip_off_ending (char *name, int len)
1365 for (i = 2; i < 6 && len > i; i++)
1367 if (name[len - i] == '.')
1369 name[len - i] = '\0';
1375 /* Output a quoted string. */
1378 output_quoted_string (FILE *asm_file, const char *string)
1380 #ifdef OUTPUT_QUOTED_STRING
1381 OUTPUT_QUOTED_STRING (asm_file, string);
1385 putc ('\"', asm_file);
1386 while ((c = *string++) != 0)
1390 if (c == '\"' || c == '\\')
1391 putc ('\\', asm_file);
1395 fprintf (asm_file, "\\%03o", (unsigned char) c);
1397 putc ('\"', asm_file);
1401 /* Output a file name in the form wanted by System V. */
1404 output_file_directive (FILE *asm_file, const char *input_name)
1406 int len = strlen (input_name);
1407 const char *na = input_name + len;
1409 /* NA gets INPUT_NAME sans directory names. */
1410 while (na > input_name)
1412 if (IS_DIR_SEPARATOR (na[-1]))
1417 #ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
1418 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
1420 #ifdef ASM_OUTPUT_SOURCE_FILENAME
1421 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
1423 fprintf (asm_file, "\t.file\t");
1424 output_quoted_string (asm_file, na);
1425 fputc ('\n', asm_file);
1430 /* Routine to open a dump file. Return true if the dump file is enabled. */
1433 open_dump_file (enum dump_file_index index, tree decl)
1436 const char *open_arg;
1439 if (! dump_file[index].enabled)
1442 timevar_push (TV_DUMP);
1443 if (rtl_dump_file != NULL)
1444 fclose (rtl_dump_file);
1446 sprintf (seq, DUMPFILE_FORMAT, index);
1448 if (! dump_file[index].initialized)
1450 /* If we've not initialized the files, do so now. */
1451 if (graph_dump_format != no_graph
1452 && dump_file[index].graph_dump_p)
1454 dump_name = concat (seq, dump_file[index].extension, NULL);
1455 clean_graph_dump_file (dump_base_name, dump_name);
1458 dump_file[index].initialized = 1;
1464 dump_name = concat (dump_base_name, seq,
1465 dump_file[index].extension, NULL);
1467 rtl_dump_file = fopen (dump_name, open_arg);
1468 if (rtl_dump_file == NULL)
1469 fatal_error ("can't open %s: %m", dump_name);
1474 fprintf (rtl_dump_file, "\n;; Function %s%s\n\n",
1475 (*lang_hooks.decl_printable_name) (decl, 2),
1476 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
1478 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
1479 ? " (unlikely executed)"
1482 timevar_pop (TV_DUMP);
1486 /* Routine to close a dump file. */
1489 close_dump_file (enum dump_file_index index,
1490 void (*func) (FILE *, rtx),
1493 if (! rtl_dump_file)
1496 timevar_push (TV_DUMP);
1498 && graph_dump_format != no_graph
1499 && dump_file[index].graph_dump_p)
1504 sprintf (seq, DUMPFILE_FORMAT, index);
1505 suffix = concat (seq, dump_file[index].extension, NULL);
1506 print_rtl_graph_with_bb (dump_base_name, suffix, insns);
1511 func (rtl_dump_file, insns);
1513 fflush (rtl_dump_file);
1514 fclose (rtl_dump_file);
1516 rtl_dump_file = NULL;
1517 timevar_pop (TV_DUMP);
1520 /* Do any final processing required for the declarations in VEC, of
1521 which there are LEN. We write out inline functions and variables
1522 that have been deferred until this point, but which are required.
1523 Returns nonzero if anything was put out. */
1526 wrapup_global_declarations (tree *vec, int len)
1531 int output_something = 0;
1533 for (i = 0; i < len; i++)
1537 /* We're not deferring this any longer. Assignment is
1538 conditional to avoid needlessly dirtying PCH pages. */
1539 if (DECL_DEFER_OUTPUT (decl) != 0)
1540 DECL_DEFER_OUTPUT (decl) = 0;
1542 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
1543 (*lang_hooks.finish_incomplete_decl) (decl);
1546 /* Now emit any global variables or functions that we have been
1547 putting off. We need to loop in case one of the things emitted
1548 here references another one which comes earlier in the list. */
1552 for (i = 0; i < len; i++)
1556 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
1559 /* Don't write out static consts, unless we still need them.
1561 We also keep static consts if not optimizing (for debugging),
1562 unless the user specified -fno-keep-static-consts.
1563 ??? They might be better written into the debug information.
1564 This is possible when using DWARF.
1566 A language processor that wants static constants to be always
1567 written out (even if it is not used) is responsible for
1568 calling rest_of_decl_compilation itself. E.g. the C front-end
1569 calls rest_of_decl_compilation from finish_decl.
1570 One motivation for this is that is conventional in some
1571 environments to write things like:
1572 static const char rcsid[] = "... version string ...";
1573 intending to force the string to be in the executable.
1575 A language processor that would prefer to have unneeded
1576 static constants "optimized away" would just defer writing
1577 them out until here. E.g. C++ does this, because static
1578 constants are often defined in header files.
1580 ??? A tempting alternative (for both C and C++) would be
1581 to force a constant to be written if and only if it is
1582 defined in a main file, as opposed to an include file. */
1584 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
1588 if (flag_unit_at_a_time
1589 && cgraph_varpool_node (decl)->finalized)
1591 else if ((flag_unit_at_a_time && !cgraph_global_info_ready)
1592 && (TREE_USED (decl)
1593 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
1595 else if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1597 else if (DECL_COMDAT (decl))
1599 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
1600 && (optimize || !flag_keep_static_consts
1601 || DECL_ARTIFICIAL (decl)))
1607 rest_of_decl_compilation (decl, NULL, 1, 1);
1611 if (TREE_CODE (decl) == FUNCTION_DECL
1612 && DECL_INITIAL (decl) != 0
1613 && DECL_SAVED_INSNS (decl) != 0
1614 && DECL_SAVED_INSNS (decl)->saved_for_inline
1615 && (flag_keep_inline_functions
1616 || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
1617 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
1620 output_inline_function (decl);
1625 output_something = 1;
1629 return output_something;
1632 /* Issue appropriate warnings for the global declarations in VEC (of
1633 which there are LEN). Output debugging information for them. */
1636 check_global_declarations (tree *vec, int len)
1641 for (i = 0; i < len; i++)
1645 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
1646 && ! TREE_ASM_WRITTEN (decl))
1647 /* Cancel the RTL for this decl so that, if debugging info
1648 output for global variables is still to come,
1649 this one will be omitted. */
1650 SET_DECL_RTL (decl, NULL_RTX);
1652 /* Warn about any function
1653 declared static but not defined.
1654 We don't warn about variables,
1655 because many programs have static variables
1656 that exist only to get some text into the object file. */
1657 if (TREE_CODE (decl) == FUNCTION_DECL
1658 && (warn_unused_function
1659 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1660 && DECL_INITIAL (decl) == 0
1661 && DECL_EXTERNAL (decl)
1662 && ! DECL_ARTIFICIAL (decl)
1663 && ! TREE_PUBLIC (decl))
1665 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1666 pedwarn ("%J'%F' used but never defined", decl, decl);
1668 warning ("%J'%F' declared `static' but never defined", decl, decl);
1669 /* This symbol is effectively an "extern" declaration now. */
1670 TREE_PUBLIC (decl) = 1;
1671 assemble_external (decl);
1674 /* Warn about static fns or vars defined but not used. */
1675 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
1676 || (warn_unused_variable && TREE_CODE (decl) == VAR_DECL))
1677 && ! TREE_USED (decl)
1678 /* The TREE_USED bit for file-scope decls is kept in the identifier,
1679 to handle multiple external decls in different scopes. */
1680 && ! TREE_USED (DECL_NAME (decl))
1681 && ! DECL_EXTERNAL (decl)
1682 && ! TREE_PUBLIC (decl)
1683 /* A volatile variable might be used in some non-obvious way. */
1684 && ! TREE_THIS_VOLATILE (decl)
1685 /* Global register variables must be declared to reserve them. */
1686 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
1687 /* Otherwise, ask the language. */
1688 && (*lang_hooks.decls.warn_unused_global) (decl))
1689 warning ("%J'%D' defined but not used", decl, decl);
1691 /* Avoid confusing the debug information machinery when there are
1693 if (errorcount == 0 && sorrycount == 0)
1695 timevar_push (TV_SYMOUT);
1696 (*debug_hooks->global_decl) (decl);
1697 timevar_pop (TV_SYMOUT);
1702 /* Warn about a use of an identifier which was marked deprecated. */
1704 warn_deprecated_use (tree node)
1706 if (node == 0 || !warn_deprecated_decl)
1710 warning ("`%s' is deprecated (declared at %s:%d)",
1711 IDENTIFIER_POINTER (DECL_NAME (node)),
1712 DECL_SOURCE_FILE (node), DECL_SOURCE_LINE (node));
1713 else if (TYPE_P (node))
1715 const char *what = NULL;
1716 tree decl = TYPE_STUB_DECL (node);
1718 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
1719 what = IDENTIFIER_POINTER (TYPE_NAME (node));
1720 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
1721 && DECL_NAME (TYPE_NAME (node)))
1722 what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
1727 warning ("`%s' is deprecated (declared at %s:%d)", what,
1728 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1730 warning ("`%s' is deprecated", what);
1733 warning ("type is deprecated (declared at %s:%d)",
1734 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1736 warning ("type is deprecated");
1740 /* Save the current INPUT_LOCATION on the top entry in the
1741 INPUT_FILE_STACK. Push a new entry for FILE and LINE, and set the
1742 INPUT_LOCATION accordingly. */
1745 push_srcloc (const char *file, int line)
1747 struct file_stack *fs;
1749 fs = xmalloc (sizeof (struct file_stack));
1750 fs->location = input_location;
1751 fs->next = input_file_stack;
1752 input_filename = file;
1754 input_file_stack = fs;
1755 input_file_stack_tick++;
1758 /* Pop the top entry off the stack of presently open source files.
1759 Restore the INPUT_LOCATION from the new topmost entry on the
1765 struct file_stack *fs;
1767 fs = input_file_stack;
1768 input_location = fs->location;
1769 input_file_stack = fs->next;
1771 input_file_stack_tick++;
1774 /* Compile an entire translation unit. Write a file of assembly
1775 output and various debugging dumps. */
1780 /* Initialize yet another pass. */
1782 init_final (main_input_filename);
1783 coverage_init (aux_base_name);
1785 timevar_push (TV_PARSE);
1787 /* Call the parser, which parses the entire file (calling
1788 rest_of_compilation for each function). */
1789 (*lang_hooks.parse_file) (set_yydebug);
1791 /* In case there were missing block closers,
1792 get us back to the global binding level. */
1793 (*lang_hooks.clear_binding_stack) ();
1795 /* Compilation is now finished except for writing
1796 what's left of the symbol table output. */
1797 timevar_pop (TV_PARSE);
1799 if (flag_syntax_only)
1802 (*lang_hooks.decls.final_write_globals)();
1804 cgraph_varpool_assemble_pending_decls ();
1806 /* This must occur after the loop to output deferred functions.
1807 Else the coverage initializer would not be emitted if all the
1808 functions in this compilation unit were deferred. */
1811 /* Write out any pending weak symbol declarations. */
1815 /* Do dbx symbols. */
1816 timevar_push (TV_SYMOUT);
1818 #ifdef DWARF2_UNWIND_INFO
1819 if (dwarf2out_do_frame ())
1820 dwarf2out_frame_finish ();
1823 (*debug_hooks->finish) (main_input_filename);
1824 timevar_pop (TV_SYMOUT);
1826 /* Output some stuff at end of file if nec. */
1828 dw2_output_indirect_constants ();
1830 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
1832 timevar_push (TV_DUMP);
1833 open_dump_file (DFI_bp, NULL);
1837 close_dump_file (DFI_bp, NULL, NULL_RTX);
1838 timevar_pop (TV_DUMP);
1841 targetm.asm_out.file_end ();
1843 /* Attach a special .ident directive to the end of the file to identify
1844 the version of GCC which compiled this code. The format of the .ident
1845 string is patterned after the ones produced by native SVR4 compilers. */
1848 fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
1849 IDENT_ASM_OP, version_string);
1852 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
1854 timevar_push (TV_DUMP);
1855 dump_combine_total_stats (rtl_dump_file);
1856 close_dump_file (DFI_combine, NULL, NULL_RTX);
1857 timevar_pop (TV_DUMP);
1861 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
1862 and TYPE_DECL nodes.
1864 This does nothing for local (non-static) variables, unless the
1865 variable is a register variable with an ASMSPEC. In that case, or
1866 if the variable is not an automatic, it sets up the RTL and
1867 outputs any assembler code (label definition, storage allocation
1868 and initialization).
1870 DECL is the declaration. If ASMSPEC is nonzero, it specifies
1871 the assembler symbol name to be used. TOP_LEVEL is nonzero
1872 if this declaration is not within a function. */
1875 rest_of_decl_compilation (tree decl,
1876 const char *asmspec,
1880 /* We deferred calling assemble_alias so that we could collect
1881 other attributes such as visibility. Emit the alias now. */
1884 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
1887 alias = TREE_VALUE (TREE_VALUE (alias));
1888 alias = get_identifier (TREE_STRING_POINTER (alias));
1889 assemble_alias (decl, alias);
1893 /* Forward declarations for nested functions are not "external",
1894 but we need to treat them as if they were. */
1895 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
1896 || TREE_CODE (decl) == FUNCTION_DECL)
1898 timevar_push (TV_VARCONST);
1901 make_decl_rtl (decl, asmspec);
1903 /* Don't output anything when a tentative file-scope definition
1904 is seen. But at end of compilation, do output code for them. */
1905 if ((at_end || !DECL_DEFER_OUTPUT (decl)) && !DECL_EXTERNAL (decl))
1907 if (flag_unit_at_a_time && !cgraph_global_info_ready
1908 && TREE_CODE (decl) != FUNCTION_DECL && top_level)
1909 cgraph_varpool_finalize_decl (decl);
1911 assemble_variable (decl, top_level, at_end, 0);
1914 #ifdef ASM_FINISH_DECLARE_OBJECT
1915 if (decl == last_assemble_variable_decl)
1917 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
1922 timevar_pop (TV_VARCONST);
1924 else if (DECL_REGISTER (decl) && asmspec != 0)
1926 if (decode_reg_name (asmspec) >= 0)
1928 SET_DECL_RTL (decl, NULL_RTX);
1929 make_decl_rtl (decl, asmspec);
1933 error ("invalid register name `%s' for register variable", asmspec);
1934 DECL_REGISTER (decl) = 0;
1939 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1940 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1941 && TREE_CODE (decl) == TYPE_DECL)
1943 timevar_push (TV_SYMOUT);
1944 dbxout_symbol (decl, 0);
1945 timevar_pop (TV_SYMOUT);
1948 #ifdef SDB_DEBUGGING_INFO
1949 else if (write_symbols == SDB_DEBUG && top_level
1950 && TREE_CODE (decl) == TYPE_DECL)
1952 timevar_push (TV_SYMOUT);
1953 sdbout_symbol (decl, 0);
1954 timevar_pop (TV_SYMOUT);
1957 #ifdef DWARF2_DEBUGGING_INFO
1958 else if ((write_symbols == DWARF2_DEBUG
1959 || write_symbols == VMS_AND_DWARF2_DEBUG)
1961 && TREE_CODE (decl) == TYPE_DECL)
1963 timevar_push (TV_SYMOUT);
1964 dwarf2out_decl (decl);
1965 timevar_pop (TV_SYMOUT);
1970 /* Called after finishing a record, union or enumeral type. */
1973 rest_of_type_compilation (
1974 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) \
1975 || defined (SDB_DEBUGGING_INFO) || defined (DWARF2_DEBUGGING_INFO)
1979 tree type ATTRIBUTE_UNUSED,
1980 int toplev ATTRIBUTE_UNUSED
1984 /* Avoid confusing the debug information machinery when there are
1986 if (errorcount != 0 || sorrycount != 0)
1989 timevar_push (TV_SYMOUT);
1990 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1991 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1992 dbxout_symbol (TYPE_STUB_DECL (type), !toplev);
1994 #ifdef SDB_DEBUGGING_INFO
1995 if (write_symbols == SDB_DEBUG)
1996 sdbout_symbol (TYPE_STUB_DECL (type), !toplev);
1998 #ifdef DWARF2_DEBUGGING_INFO
1999 if ((write_symbols == DWARF2_DEBUG
2000 || write_symbols == VMS_AND_DWARF2_DEBUG)
2002 dwarf2out_decl (TYPE_STUB_DECL (type));
2004 timevar_pop (TV_SYMOUT);
2007 /* Turn the RTL into assembly. */
2009 rest_of_handle_final (tree decl, rtx insns)
2011 timevar_push (TV_FINAL);
2016 /* Get the function's name, as described by its RTL. This may be
2017 different from the DECL_NAME name used in the source file. */
2019 x = DECL_RTL (decl);
2020 if (GET_CODE (x) != MEM)
2023 if (GET_CODE (x) != SYMBOL_REF)
2025 fnname = XSTR (x, 0);
2027 assemble_start_function (decl, fnname);
2028 final_start_function (insns, asm_out_file, optimize);
2029 final (insns, asm_out_file, optimize, 0);
2030 final_end_function ();
2032 #ifdef IA64_UNWIND_INFO
2033 /* ??? The IA-64 ".handlerdata" directive must be issued before
2034 the ".endp" directive that closes the procedure descriptor. */
2035 output_function_exception_table ();
2038 assemble_end_function (decl, fnname);
2040 #ifndef IA64_UNWIND_INFO
2041 /* Otherwise, it feels unclean to switch sections in the middle. */
2042 output_function_exception_table ();
2046 fflush (asm_out_file);
2048 /* Release all memory allocated by flow. */
2049 free_basic_block_vars (0);
2051 /* Release all memory held by regsets now. */
2052 regset_release_memory ();
2054 timevar_pop (TV_FINAL);
2060 /* Run delay slot optimization. */
2062 rest_of_handle_delay_slots (tree decl, rtx insns)
2064 timevar_push (TV_DBR_SCHED);
2065 open_dump_file (DFI_dbr, decl);
2067 dbr_schedule (insns, rtl_dump_file);
2069 close_dump_file (DFI_dbr, print_rtl, insns);
2070 timevar_pop (TV_DBR_SCHED);
2077 /* Convert register usage from flat register file usage to a stack
2080 rest_of_handle_stack_regs (tree decl, rtx insns)
2082 #if defined (HAVE_ATTR_length)
2083 /* If flow2 creates new instructions which need splitting
2084 and scheduling after reload is not done, they might not be
2085 splitten until final which doesn't allow splitting
2086 if HAVE_ATTR_length. */
2087 #ifdef INSN_SCHEDULING
2088 if (optimize && !flag_schedule_insns_after_reload)
2093 timevar_push (TV_SHORTEN_BRANCH);
2094 split_all_insns (1);
2095 timevar_pop (TV_SHORTEN_BRANCH);
2099 timevar_push (TV_REG_STACK);
2100 open_dump_file (DFI_stack, decl);
2102 if (reg_to_stack (insns, rtl_dump_file) && optimize)
2104 if (cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
2105 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0))
2106 && flag_reorder_blocks)
2108 reorder_basic_blocks ();
2109 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
2113 close_dump_file (DFI_stack, print_rtl_with_bb, insns);
2114 timevar_pop (TV_REG_STACK);
2121 /* Machine independent reorg pass. */
2123 rest_of_handle_machine_reorg (tree decl, rtx insns)
2125 timevar_push (TV_MACH_DEP);
2126 open_dump_file (DFI_mach, decl);
2128 (*targetm.machine_dependent_reorg) ();
2130 close_dump_file (DFI_mach, print_rtl, insns);
2131 timevar_pop (TV_MACH_DEP);
2137 /* Run new register allocator. Return TRUE if we must exit
2138 rest_of_compilation upon return. */
2140 rest_of_handle_new_regalloc (tree decl, rtx insns, int *rebuild_notes)
2144 delete_trivially_dead_insns (insns, max_reg_num ());
2147 timevar_pop (TV_LOCAL_ALLOC);
2148 if (dump_file[DFI_lreg].enabled)
2150 timevar_push (TV_DUMP);
2152 close_dump_file (DFI_lreg, NULL, NULL);
2153 timevar_pop (TV_DUMP);
2156 /* XXX clean up the whole mess to bring live info in shape again. */
2157 timevar_push (TV_GLOBAL_ALLOC);
2158 open_dump_file (DFI_greg, decl);
2160 build_insn_chain (insns);
2161 failure = reload (insns, 0);
2163 timevar_pop (TV_GLOBAL_ALLOC);
2165 if (dump_file[DFI_greg].enabled)
2167 timevar_push (TV_DUMP);
2169 dump_global_regs (rtl_dump_file);
2171 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2172 timevar_pop (TV_DUMP);
2178 reload_completed = 1;
2184 /* Run old register allocator. Return TRUE if we must exit
2185 rest_of_compilation upon return. */
2187 rest_of_handle_old_regalloc (tree decl, rtx insns, int *rebuild_notes)
2191 /* Allocate the reg_renumber array. */
2192 allocate_reg_info (max_regno, FALSE, TRUE);
2194 /* And the reg_equiv_memory_loc array. */
2195 reg_equiv_memory_loc = xcalloc (max_regno, sizeof (rtx));
2197 allocate_initial_values (reg_equiv_memory_loc);
2199 regclass (insns, max_reg_num (), rtl_dump_file);
2200 *rebuild_notes = local_alloc ();
2202 timevar_pop (TV_LOCAL_ALLOC);
2204 if (dump_file[DFI_lreg].enabled)
2206 timevar_push (TV_DUMP);
2208 dump_flow_info (rtl_dump_file);
2209 dump_local_alloc (rtl_dump_file);
2211 close_dump_file (DFI_lreg, print_rtl_with_bb, insns);
2212 timevar_pop (TV_DUMP);
2217 timevar_push (TV_GLOBAL_ALLOC);
2218 open_dump_file (DFI_greg, decl);
2220 /* If optimizing, allocate remaining pseudo-regs. Do the reload
2221 pass fixing up any insns that are invalid. */
2224 failure = global_alloc (rtl_dump_file);
2227 build_insn_chain (insns);
2228 failure = reload (insns, 0);
2231 timevar_pop (TV_GLOBAL_ALLOC);
2233 if (dump_file[DFI_greg].enabled)
2235 timevar_push (TV_DUMP);
2237 dump_global_regs (rtl_dump_file);
2239 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2240 timevar_pop (TV_DUMP);
2246 /* Run the regrename and cprop passes. */
2248 rest_of_handle_regrename (tree decl, rtx insns)
2250 timevar_push (TV_RENAME_REGISTERS);
2251 open_dump_file (DFI_rnreg, decl);
2253 if (flag_rename_registers)
2254 regrename_optimize ();
2255 if (flag_cprop_registers)
2256 copyprop_hardreg_forward ();
2258 close_dump_file (DFI_rnreg, print_rtl_with_bb, insns);
2259 timevar_pop (TV_RENAME_REGISTERS);
2262 /* Reorder basic blocks. */
2264 rest_of_handle_reorder_blocks (tree decl, rtx insns)
2266 timevar_push (TV_REORDER_BLOCKS);
2267 open_dump_file (DFI_bbro, decl);
2269 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
2270 splitting possibly introduced more crossjumping opportunities. */
2271 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
2272 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
2274 if (flag_sched2_use_traces && flag_schedule_insns_after_reload)
2276 if (flag_reorder_blocks)
2277 reorder_basic_blocks ();
2278 if (flag_reorder_blocks
2279 || (flag_sched2_use_traces && flag_schedule_insns_after_reload))
2280 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2282 close_dump_file (DFI_bbro, print_rtl_with_bb, insns);
2283 timevar_pop (TV_REORDER_BLOCKS);
2286 #ifdef INSN_SCHEDULING
2287 /* Run instruction scheduler. */
2289 rest_of_handle_sched (tree decl, rtx insns)
2291 timevar_push (TV_SCHED);
2293 /* Print function header into sched dump now
2294 because doing the sched analysis makes some of the dump. */
2295 if (optimize > 0 && flag_schedule_insns)
2297 open_dump_file (DFI_sched, decl);
2299 /* Do control and data sched analysis,
2300 and write some of the results to dump file. */
2302 schedule_insns (rtl_dump_file);
2304 close_dump_file (DFI_sched, print_rtl_with_bb, insns);
2306 timevar_pop (TV_SCHED);
2311 /* Run second scheduling pass after reload. */
2313 rest_of_handle_sched2 (tree decl, rtx insns)
2315 timevar_push (TV_SCHED2);
2316 open_dump_file (DFI_sched2, decl);
2318 /* Do control and data sched analysis again,
2319 and write some more of the results to dump file. */
2321 split_all_insns (1);
2323 if (flag_sched2_use_superblocks || flag_sched2_use_traces)
2325 schedule_ebbs (rtl_dump_file);
2326 /* No liveness updating code yet, but it should be easy to do.
2327 reg-stack recompute the liveness when needed for now. */
2328 count_or_remove_death_notes (NULL, 1);
2329 cleanup_cfg (CLEANUP_EXPENSIVE);
2332 schedule_insns (rtl_dump_file);
2334 close_dump_file (DFI_sched2, print_rtl_with_bb, insns);
2335 timevar_pop (TV_SCHED2);
2341 /* Register allocation pre-pass, to reduce number of moves necessary
2342 for two-address machines. */
2344 rest_of_handle_regmove (tree decl, rtx insns)
2346 timevar_push (TV_REGMOVE);
2347 open_dump_file (DFI_regmove, decl);
2349 regmove_optimize (insns, max_reg_num (), rtl_dump_file);
2351 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2352 close_dump_file (DFI_regmove, print_rtl_with_bb, insns);
2353 timevar_pop (TV_REGMOVE);
2360 rest_of_handle_tracer (tree decl, rtx insns)
2362 timevar_push (TV_TRACER);
2363 open_dump_file (DFI_tracer, decl);
2365 dump_flow_info (rtl_dump_file);
2367 cleanup_cfg (CLEANUP_EXPENSIVE);
2368 reg_scan (insns, max_reg_num (), 0);
2369 close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ());
2370 timevar_pop (TV_TRACER);
2373 /* If-conversion and CFG cleanup. */
2375 rest_of_handle_if_conversion (tree decl, rtx insns)
2377 open_dump_file (DFI_ce1, decl);
2378 if (flag_if_conversion)
2380 timevar_push (TV_IFCVT);
2382 dump_flow_info (rtl_dump_file);
2383 cleanup_cfg (CLEANUP_EXPENSIVE);
2384 reg_scan (insns, max_reg_num (), 0);
2386 timevar_pop (TV_IFCVT);
2388 timevar_push (TV_JUMP);
2389 cleanup_cfg (CLEANUP_EXPENSIVE);
2390 reg_scan (insns, max_reg_num (), 0);
2391 timevar_pop (TV_JUMP);
2392 close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ());
2395 /* Rerun if-conversion, as combine may have simplified things enough
2396 to now meet sequence length restrictions. */
2398 rest_of_handle_if_after_combine (tree decl, rtx insns)
2400 timevar_push (TV_IFCVT);
2401 open_dump_file (DFI_ce2, decl);
2407 close_dump_file (DFI_ce2, print_rtl_with_bb, insns);
2408 timevar_pop (TV_IFCVT);
2411 /* Do branch profiling and static profile estimation passes. */
2413 rest_of_handle_branch_prob (tree decl, rtx insns)
2417 timevar_push (TV_BRANCH_PROB);
2418 open_dump_file (DFI_bp, decl);
2419 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
2422 /* Discover and record the loop depth at the head of each basic
2423 block. The loop infrastructure does the real job for us. */
2424 flow_loops_find (&loops, LOOP_TREE);
2427 flow_loops_dump (&loops, rtl_dump_file, NULL, 0);
2429 /* Estimate using heuristics if no profiling info is available. */
2430 if (flag_guess_branch_prob)
2431 estimate_probability (&loops);
2433 flow_loops_free (&loops);
2434 close_dump_file (DFI_bp, print_rtl_with_bb, insns);
2435 timevar_pop (TV_BRANCH_PROB);
2438 /* Do control and data flow analysis; write some of the results to the
2441 rest_of_handle_cfg (tree decl, rtx insns)
2443 open_dump_file (DFI_cfg, decl);
2445 dump_flow_info (rtl_dump_file);
2447 cleanup_cfg (CLEANUP_EXPENSIVE
2448 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2450 /* It may make more sense to mark constant functions after dead code is
2451 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
2452 may insert code making function non-constant, but we still must consider
2453 it as constant, otherwise -fbranch-probabilities will not read data back.
2455 life_analysis rarely eliminates modification of external memory.
2458 mark_constant_function ();
2460 close_dump_file (DFI_cfg, print_rtl_with_bb, insns);
2463 /* Purge addressofs. */
2465 rest_of_handle_addressof (tree decl, rtx insns)
2467 open_dump_file (DFI_addressof, decl);
2469 purge_addressof (insns);
2470 if (optimize && purge_all_dead_edges (0))
2471 delete_unreachable_blocks ();
2472 reg_scan (insns, max_reg_num (), 1);
2474 close_dump_file (DFI_addressof, print_rtl, insns);
2477 /* We may have potential sibling or tail recursion sites. Select one
2478 (of possibly multiple) methods of performing the call. */
2480 rest_of_handle_sibling_calls (rtx insns)
2483 optimize_sibling_and_tail_recursive_calls ();
2485 /* Recompute the CFG as sibling optimization clobbers it randomly. */
2486 free_bb_for_insn ();
2487 find_exception_handler_labels ();
2488 rebuild_jump_labels (insns);
2489 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2491 /* There is pass ordering problem - we must lower NOTE_INSN_PREDICTION
2492 notes before simplifying cfg and we must do lowering after sibcall
2493 that unhides parts of RTL chain and cleans up the CFG.
2495 Until sibcall is replaced by tree-level optimizer, lets just
2496 sweep away the NOTE_INSN_PREDICTION notes that leaked out. */
2497 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2498 if (GET_CODE (insn) == NOTE
2499 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_PREDICTION)
2502 close_dump_file (DFI_sibling, print_rtl, get_insns ());
2505 /* Perform jump bypassing and control flow optimizations. */
2507 rest_of_handle_jump_bypass (tree decl, rtx insns)
2509 timevar_push (TV_BYPASS);
2510 open_dump_file (DFI_bypass, decl);
2512 cleanup_cfg (CLEANUP_EXPENSIVE);
2514 if (bypass_jumps (rtl_dump_file))
2516 rebuild_jump_labels (insns);
2517 cleanup_cfg (CLEANUP_EXPENSIVE);
2518 delete_trivially_dead_insns (insns, max_reg_num ());
2521 close_dump_file (DFI_bypass, print_rtl_with_bb, insns);
2522 timevar_pop (TV_BYPASS);
2526 #ifdef ENABLE_CHECKING
2527 verify_flow_info ();
2531 /* Handle inlining of functions in rest_of_compilation. Return TRUE
2532 if we must exit rest_of_compilation upon return. */
2534 rest_of_handle_inlining (tree decl)
2541 /* If we are reconsidering an inline function at the end of
2542 compilation, skip the stuff for making it inline. */
2543 if (cfun->rtl_inline_init)
2545 cfun->rtl_inline_init = 1;
2547 /* If this is nested inside an inlined external function, pretend
2548 it was only declared. Since we cannot inline such functions,
2549 generating code for this one is not only not necessary but will
2550 confuse some debugging output writers. */
2551 for (parent = DECL_CONTEXT (current_function_decl);
2552 parent != NULL_TREE;
2553 parent = get_containing_scope (parent))
2554 if (TREE_CODE (parent) == FUNCTION_DECL
2555 && DECL_INLINE (parent) && DECL_EXTERNAL (parent))
2557 DECL_INITIAL (decl) = 0;
2560 else if (TYPE_P (parent))
2561 /* A function in a local class should be treated normally. */
2564 /* If requested, consider whether to make this function inline. */
2565 if ((DECL_INLINE (decl) && !flag_no_inline)
2566 || flag_inline_functions)
2568 timevar_push (TV_INTEGRATION);
2569 lose = function_cannot_inline_p (decl);
2570 timevar_pop (TV_INTEGRATION);
2571 if (lose || ! optimize)
2573 if (warn_inline && lose && DECL_INLINE (decl))
2575 char *msg = concat ("%J", lose, NULL);
2576 warning (msg, decl);
2579 DECL_ABSTRACT_ORIGIN (decl) = 0;
2580 /* Don't really compile an extern inline function.
2581 If we can't make it inline, pretend
2582 it was only declared. */
2583 if (DECL_EXTERNAL (decl))
2585 DECL_INITIAL (decl) = 0;
2590 inlinable = DECL_INLINE (decl) = 1;
2593 insns = get_insns ();
2595 /* Dump the rtl code if we are dumping rtl. */
2597 if (open_dump_file (DFI_rtl, decl))
2599 if (DECL_SAVED_INSNS (decl) && DECL_SAVED_INSNS (decl)->saved_for_inline)
2600 fprintf (rtl_dump_file, ";; (integrable)\n\n");
2601 close_dump_file (DFI_rtl, print_rtl, insns);
2604 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
2605 sorts of eh initialization. Delay this until after the
2606 initial rtl dump so that we can see the original nesting. */
2607 convert_from_eh_region_ranges ();
2609 /* If function is inline, and we don't yet know whether to
2610 compile it by itself, defer decision till end of compilation.
2611 wrapup_global_declarations will (indirectly) call
2612 rest_of_compilation again for those functions that need to
2613 be output. Also defer those functions that we are supposed
2617 || (DECL_INLINE (decl)
2618 && flag_inline_functions
2619 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2620 && ! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
2621 && ! flag_keep_inline_functions)
2622 || DECL_EXTERNAL (decl))))
2623 DECL_DEFER_OUTPUT (decl) = 1;
2625 if (DECL_INLINE (decl))
2626 /* DWARF wants separate debugging info for abstract and
2627 concrete instances of all inline functions, including those
2628 declared inline but not inlined, and those inlined even
2629 though they weren't declared inline. Conveniently, that's
2630 what DECL_INLINE means at this point. */
2631 (*debug_hooks->deferred_inline_function) (decl);
2633 if (DECL_DEFER_OUTPUT (decl))
2635 /* If -Wreturn-type, we have to do a bit of compilation. We just
2636 want to call cleanup the cfg to figure out whether or not we can
2637 fall off the end of the function; we do the minimum amount of
2638 work necessary to make that safe. */
2639 if (warn_return_type)
2641 int saved_optimize = optimize;
2644 rebuild_jump_labels (insns);
2645 find_exception_handler_labels ();
2646 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2647 cleanup_cfg (CLEANUP_PRE_SIBCALL | CLEANUP_PRE_LOOP);
2648 optimize = saved_optimize;
2650 /* CFG is no longer maintained up-to-date. */
2651 free_bb_for_insn ();
2654 set_nothrow_function_flags ();
2655 if (current_function_nothrow)
2656 /* Now we know that this can't throw; set the flag for the benefit
2657 of other functions later in this translation unit. */
2658 TREE_NOTHROW (current_function_decl) = 1;
2660 timevar_push (TV_INTEGRATION);
2661 save_for_inline (decl);
2662 timevar_pop (TV_INTEGRATION);
2663 DECL_SAVED_INSNS (decl)->inlinable = inlinable;
2667 /* If specified extern inline but we aren't inlining it, we are
2668 done. This goes for anything that gets here with DECL_EXTERNAL
2669 set, not just things with DECL_INLINE. */
2670 return (bool) DECL_EXTERNAL (decl);
2673 /* Rest of compilation helper to convert the rtl to SSA form. */
2675 rest_of_handle_ssa (tree decl, rtx insns)
2677 timevar_push (TV_TO_SSA);
2678 open_dump_file (DFI_ssa, decl);
2680 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2683 close_dump_file (DFI_ssa, print_rtl_with_bb, insns);
2684 timevar_pop (TV_TO_SSA);
2686 /* Perform sparse conditional constant propagation, if requested. */
2689 timevar_push (TV_SSA_CCP);
2690 open_dump_file (DFI_ssa_ccp, decl);
2694 close_dump_file (DFI_ssa_ccp, print_rtl_with_bb, get_insns ());
2695 timevar_pop (TV_SSA_CCP);
2698 /* It would be useful to cleanup the CFG at this point, but block
2699 merging and possibly other transformations might leave a PHI
2700 node in the middle of a basic block, which is a strict no-no. */
2702 /* The SSA implementation uses basic block numbers in its phi
2703 nodes. Thus, changing the control-flow graph or the basic
2704 blocks, e.g., calling find_basic_blocks () or cleanup_cfg (),
2705 may cause problems. */
2709 /* Remove dead code. */
2711 timevar_push (TV_SSA_DCE);
2712 open_dump_file (DFI_ssa_dce, decl);
2714 insns = get_insns ();
2715 ssa_eliminate_dead_code ();
2717 close_dump_file (DFI_ssa_dce, print_rtl_with_bb, insns);
2718 timevar_pop (TV_SSA_DCE);
2721 /* Convert from SSA form. */
2723 timevar_push (TV_FROM_SSA);
2724 open_dump_file (DFI_ussa, decl);
2726 convert_from_ssa ();
2727 /* New registers have been created. Rescan their usage. */
2728 reg_scan (insns, max_reg_num (), 1);
2730 close_dump_file (DFI_ussa, print_rtl_with_bb, insns);
2731 timevar_pop (TV_FROM_SSA);
2738 /* Try to identify useless null pointer tests and delete them. */
2740 rest_of_handle_null_pointer (tree decl, rtx insns)
2742 open_dump_file (DFI_null, decl);
2744 dump_flow_info (rtl_dump_file);
2746 if (delete_null_pointer_checks (insns))
2747 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2749 close_dump_file (DFI_null, print_rtl_with_bb, insns);
2752 /* Try combining insns through substitution. */
2754 rest_of_handle_combine (tree decl, rtx insns)
2756 int rebuild_jump_labels_after_combine = 0;
2758 timevar_push (TV_COMBINE);
2759 open_dump_file (DFI_combine, decl);
2761 rebuild_jump_labels_after_combine
2762 = combine_instructions (insns, max_reg_num ());
2764 /* Combining insns may have turned an indirect jump into a
2765 direct jump. Rebuild the JUMP_LABEL fields of jumping
2767 if (rebuild_jump_labels_after_combine)
2769 timevar_push (TV_JUMP);
2770 rebuild_jump_labels (insns);
2771 timevar_pop (TV_JUMP);
2773 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2776 close_dump_file (DFI_combine, print_rtl_with_bb, insns);
2777 timevar_pop (TV_COMBINE);
2782 /* Perform life analysis. */
2784 rest_of_handle_life (tree decl, rtx insns)
2786 open_dump_file (DFI_life, decl);
2789 #ifdef ENABLE_CHECKING
2790 verify_flow_info ();
2792 life_analysis (insns, rtl_dump_file, PROP_FINAL);
2794 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_UPDATE_LIFE
2795 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2796 timevar_pop (TV_FLOW);
2798 if (warn_uninitialized)
2800 uninitialized_vars_warning (DECL_INITIAL (decl));
2802 setjmp_args_warning ();
2807 if (!flag_new_regalloc && initialize_uninitialized_subregs ())
2809 /* Insns were inserted, and possibly pseudos created, so
2810 things might look a bit different. */
2811 insns = get_insns ();
2812 allocate_reg_life_data ();
2813 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
2814 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
2820 close_dump_file (DFI_life, print_rtl_with_bb, insns);
2825 /* Perform common subexpression elimination. Nonzero value from
2826 `cse_main' means that jumps were simplified and some code may now
2827 be unreachable, so do jump optimization again. */
2829 rest_of_handle_cse (tree decl, rtx insns)
2833 open_dump_file (DFI_cse, decl);
2835 dump_flow_info (rtl_dump_file);
2836 timevar_push (TV_CSE);
2838 reg_scan (insns, max_reg_num (), 1);
2840 tem = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2842 rebuild_jump_labels (insns);
2843 if (purge_all_dead_edges (0))
2844 delete_unreachable_blocks ();
2846 delete_trivially_dead_insns (insns, max_reg_num ());
2848 /* If we are not running more CSE passes, then we are no longer
2849 expecting CSE to be run. But always rerun it in a cheap mode. */
2850 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
2852 if (tem || optimize > 1)
2853 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2854 /* Try to identify useless null pointer tests and delete them. */
2855 if (flag_delete_null_pointer_checks)
2857 timevar_push (TV_JUMP);
2859 if (delete_null_pointer_checks (insns))
2860 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2861 timevar_pop (TV_JUMP);
2864 /* The second pass of jump optimization is likely to have
2865 removed a bunch more instructions. */
2866 renumber_insns (rtl_dump_file);
2868 timevar_pop (TV_CSE);
2869 close_dump_file (DFI_cse, print_rtl_with_bb, insns);
2872 /* Run second CSE pass after loop optimizations. */
2874 rest_of_handle_cse2 (tree decl, rtx insns)
2878 timevar_push (TV_CSE2);
2879 open_dump_file (DFI_cse2, decl);
2881 dump_flow_info (rtl_dump_file);
2882 /* CFG is no longer maintained up-to-date. */
2883 tem = cse_main (insns, max_reg_num (), 1, rtl_dump_file);
2884 purge_all_dead_edges (0);
2885 delete_trivially_dead_insns (insns, max_reg_num ());
2889 timevar_push (TV_JUMP);
2890 rebuild_jump_labels (insns);
2891 cleanup_cfg (CLEANUP_EXPENSIVE);
2892 timevar_pop (TV_JUMP);
2894 reg_scan (insns, max_reg_num (), 0);
2895 close_dump_file (DFI_cse2, print_rtl_with_bb, insns);
2897 timevar_pop (TV_CSE2);
2900 /* Perform global cse. */
2902 rest_of_handle_gcse (tree decl, rtx insns)
2904 int save_csb, save_cfj;
2907 timevar_push (TV_GCSE);
2908 open_dump_file (DFI_gcse, decl);
2910 tem = gcse_main (insns, rtl_dump_file);
2911 rebuild_jump_labels (insns);
2912 delete_trivially_dead_insns (insns, max_reg_num ());
2914 save_csb = flag_cse_skip_blocks;
2915 save_cfj = flag_cse_follow_jumps;
2916 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
2918 /* Instantiate any remaining CONSTANT_P_RTX nodes. */
2919 if (current_function_calls_constant_p)
2920 purge_builtin_constant_p ();
2922 /* If -fexpensive-optimizations, re-run CSE to clean up things done
2924 if (flag_expensive_optimizations)
2926 timevar_push (TV_CSE);
2927 reg_scan (insns, max_reg_num (), 1);
2928 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2929 purge_all_dead_edges (0);
2930 delete_trivially_dead_insns (insns, max_reg_num ());
2931 timevar_pop (TV_CSE);
2932 cse_not_expected = !flag_rerun_cse_after_loop;
2935 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
2936 things up. Then possibly re-run CSE again. */
2940 timevar_push (TV_JUMP);
2941 rebuild_jump_labels (insns);
2942 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2943 timevar_pop (TV_JUMP);
2945 if (flag_expensive_optimizations)
2947 timevar_push (TV_CSE);
2948 reg_scan (insns, max_reg_num (), 1);
2949 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2950 purge_all_dead_edges (0);
2951 delete_trivially_dead_insns (insns, max_reg_num ());
2952 timevar_pop (TV_CSE);
2956 close_dump_file (DFI_gcse, print_rtl_with_bb, insns);
2957 timevar_pop (TV_GCSE);
2960 flag_cse_skip_blocks = save_csb;
2961 flag_cse_follow_jumps = save_cfj;
2962 #ifdef ENABLE_CHECKING
2963 verify_flow_info ();
2967 /* Move constant computations out of loops. */
2969 rest_of_handle_loop_optimize (tree decl, rtx insns)
2971 int do_unroll, do_prefetch;
2973 timevar_push (TV_LOOP);
2974 delete_dead_jumptables ();
2975 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2976 open_dump_file (DFI_loop, decl);
2978 /* CFG is no longer maintained up-to-date. */
2979 free_bb_for_insn ();
2981 if (flag_unroll_loops)
2982 do_unroll = 0; /* Having two unrollers is useless. */
2984 do_unroll = flag_old_unroll_loops ? LOOP_UNROLL : LOOP_AUTO_UNROLL;
2985 do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
2987 if (flag_rerun_loop_opt)
2989 cleanup_barriers ();
2991 /* We only want to perform unrolling once. */
2992 loop_optimize (insns, rtl_dump_file, do_unroll);
2995 /* The first call to loop_optimize makes some instructions
2996 trivially dead. We delete those instructions now in the
2997 hope that doing so will make the heuristics in loop work
2998 better and possibly speed up compilation. */
2999 delete_trivially_dead_insns (insns, max_reg_num ());
3001 /* The regscan pass is currently necessary as the alias
3002 analysis code depends on this information. */
3003 reg_scan (insns, max_reg_num (), 1);
3005 cleanup_barriers ();
3006 loop_optimize (insns, rtl_dump_file, do_unroll | LOOP_BCT | do_prefetch);
3008 /* Loop can create trivially dead instructions. */
3009 delete_trivially_dead_insns (insns, max_reg_num ());
3010 close_dump_file (DFI_loop, print_rtl, insns);
3011 timevar_pop (TV_LOOP);
3012 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3017 /* Perform loop optimizations. It might be better to do them a bit
3018 sooner, but we want the profile feedback to work more
3021 rest_of_handle_loop2 (tree decl, rtx insns)
3023 struct loops *loops;
3024 timevar_push (TV_LOOP);
3025 open_dump_file (DFI_loop2, decl);
3027 dump_flow_info (rtl_dump_file);
3029 loops = loop_optimizer_init (rtl_dump_file);
3033 /* The optimizations: */
3034 if (flag_unswitch_loops)
3035 unswitch_loops (loops);
3037 if (flag_peel_loops || flag_unroll_loops)
3038 unroll_and_peel_loops (loops,
3039 (flag_peel_loops ? UAP_PEEL : 0) |
3040 (flag_unroll_loops ? UAP_UNROLL : 0) |
3041 (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0));
3043 loop_optimizer_finalize (loops, rtl_dump_file);
3046 cleanup_cfg (CLEANUP_EXPENSIVE);
3047 delete_trivially_dead_insns (insns, max_reg_num ());
3048 reg_scan (insns, max_reg_num (), 0);
3050 dump_flow_info (rtl_dump_file);
3051 close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
3052 timevar_pop (TV_LOOP);
3056 /* This is called from finish_function (within langhooks.parse_file)
3057 after each top-level definition is parsed.
3058 It is supposed to compile that function or variable
3059 and output the assembler code for it.
3060 After we return, the tree storage is freed. */
3063 rest_of_compilation (tree decl)
3066 int rebuild_label_notes_after_reload;
3068 timevar_push (TV_REST_OF_COMPILATION);
3070 /* Register rtl specific functions for cfg. */
3071 rtl_register_cfg_hooks ();
3073 /* Now that we're out of the frontend, we shouldn't have any more
3074 CONCATs anywhere. */
3075 generating_concat_p = 0;
3077 /* When processing delayed functions, prepare_function_start() won't
3078 have been run to re-initialize it. */
3079 cse_not_expected = ! optimize;
3081 /* First, make sure that NOTE_BLOCK is set correctly for each
3082 NOTE_INSN_BLOCK_BEG/NOTE_INSN_BLOCK_END note. */
3083 if (!cfun->x_whole_function_mode_p)
3086 /* In function-at-a-time mode, we do not attempt to keep the BLOCK
3087 tree in sensible shape. So, we just recalculate it here. */
3088 if (cfun->x_whole_function_mode_p)
3093 if (rest_of_handle_inlining (decl))
3094 goto exit_rest_of_compilation;
3096 /* If we're emitting a nested function, make sure its parent gets
3097 emitted as well. Doing otherwise confuses debug info. */
3100 for (parent = DECL_CONTEXT (current_function_decl);
3101 parent != NULL_TREE;
3102 parent = get_containing_scope (parent))
3103 if (TREE_CODE (parent) == FUNCTION_DECL)
3104 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
3107 /* We are now committed to emitting code for this function. Do any
3108 preparation, such as emitting abstract debug info for the inline
3109 before it gets mangled by optimization. */
3110 if (DECL_INLINE (decl))
3111 (*debug_hooks->outlining_inline_function) (decl);
3113 /* Remove any notes we don't need. That will make iterating
3114 over the instruction sequence faster, and allow the garbage
3115 collector to reclaim the memory used by the notes. */
3116 remove_unnecessary_notes ();
3121 /* Initialize some variables used by the optimizers. */
3122 init_function_for_compilation ();
3124 if (! DECL_DEFER_OUTPUT (decl))
3125 TREE_ASM_WRITTEN (decl) = 1;
3127 /* Now that integrate will no longer see our rtl, we need not
3128 distinguish between the return value of this function and the
3129 return value of called functions. Also, we can remove all SETs
3130 of subregs of hard registers; they are only here because of
3131 integrate. Also, we can now initialize pseudos intended to
3132 carry magic hard reg data throughout the function. */
3133 rtx_equal_function_value_matters = 0;
3134 purge_hard_subreg_sets (get_insns ());
3136 /* Early return if there were errors. We can run afoul of our
3137 consistency checks, and there's not really much point in fixing them.
3138 Don't return yet if -Wreturn-type; we need to do cleanup_cfg. */
3139 if (((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
3140 || errorcount || sorrycount)
3141 goto exit_rest_of_compilation;
3143 timevar_push (TV_JUMP);
3144 open_dump_file (DFI_sibling, decl);
3145 insns = get_insns ();
3146 rebuild_jump_labels (insns);
3147 find_exception_handler_labels ();
3148 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3150 delete_unreachable_blocks ();
3152 /* We have to issue these warnings now already, because CFG cleanups
3153 further down may destroy the required information. */
3154 check_function_return_warnings ();
3156 /* Turn NOTE_INSN_PREDICTIONs into branch predictions. */
3157 if (flag_guess_branch_prob)
3159 timevar_push (TV_BRANCH_PROB);
3160 note_prediction_to_br_prob ();
3161 timevar_pop (TV_BRANCH_PROB);
3164 if (flag_optimize_sibling_calls)
3165 rest_of_handle_sibling_calls (insns);
3167 timevar_pop (TV_JUMP);
3169 insn_locators_initialize ();
3170 /* Complete generation of exception handling code. */
3173 timevar_push (TV_JUMP);
3174 open_dump_file (DFI_eh, decl);
3176 finish_eh_generation ();
3178 close_dump_file (DFI_eh, print_rtl, get_insns ());
3179 timevar_pop (TV_JUMP);
3182 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
3183 generation, which might create new sets. */
3184 emit_initial_value_sets ();
3187 /* If we are doing position-independent code generation, now
3188 is the time to output special prologues and epilogues.
3189 We do not want to do this earlier, because it just clutters
3190 up inline functions with meaningless insns. */
3195 insns = get_insns ();
3197 /* Copy any shared structure that should not be shared. */
3198 unshare_all_rtl (current_function_decl, insns);
3200 #ifdef SETJMP_VIA_SAVE_AREA
3201 /* This must be performed before virtual register instantiation.
3202 Please be aware the everything in the compiler that can look
3203 at the RTL up to this point must understand that REG_SAVE_AREA
3204 is just like a use of the REG contained inside. */
3205 if (current_function_calls_alloca)
3206 optimize_save_area_alloca (insns);
3209 /* Instantiate all virtual registers. */
3210 instantiate_virtual_regs (current_function_decl, insns);
3212 open_dump_file (DFI_jump, decl);
3214 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3215 are initialized and to compute whether control can drop off the end
3218 timevar_push (TV_JUMP);
3219 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
3220 before jump optimization switches branch directions. */
3221 if (flag_guess_branch_prob)
3222 expected_value_to_br_prob ();
3224 reg_scan (insns, max_reg_num (), 0);
3225 rebuild_jump_labels (insns);
3226 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3227 delete_trivially_dead_insns (insns, max_reg_num ());
3229 dump_flow_info (rtl_dump_file);
3230 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
3231 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
3235 free_bb_for_insn ();
3236 copy_loop_headers (insns);
3237 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3239 purge_line_number_notes (insns);
3241 timevar_pop (TV_JUMP);
3242 close_dump_file (DFI_jump, print_rtl, insns);
3244 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
3245 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
3246 goto exit_rest_of_compilation;
3248 /* Long term, this should probably move before the jump optimizer too,
3249 but I didn't want to disturb the rtl_dump_and_exit and related
3250 stuff at this time. */
3251 if (optimize > 0 && flag_ssa)
3252 insns = rest_of_handle_ssa (decl, insns);
3254 timevar_push (TV_JUMP);
3257 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3259 if (flag_delete_null_pointer_checks)
3260 rest_of_handle_null_pointer (decl, insns);
3262 /* Jump optimization, and the removal of NULL pointer checks, may
3263 have reduced the number of instructions substantially. CSE, and
3264 future passes, allocate arrays whose dimensions involve the
3265 maximum instruction UID, so if we can reduce the maximum UID
3266 we'll save big on memory. */
3267 renumber_insns (rtl_dump_file);
3268 timevar_pop (TV_JUMP);
3270 close_dump_file (DFI_jump, print_rtl_with_bb, insns);
3275 rest_of_handle_cse (decl, insns);
3277 rest_of_handle_addressof (decl, insns);
3284 rest_of_handle_gcse (decl, insns);
3286 if (flag_loop_optimize)
3287 rest_of_handle_loop_optimize (decl, insns);
3290 rest_of_handle_jump_bypass (decl, insns);
3293 timevar_push (TV_FLOW);
3295 rest_of_handle_cfg (decl, insns);
3298 || profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
3299 rest_of_handle_branch_prob (decl, insns);
3302 rest_of_handle_if_conversion (decl, insns);
3305 rest_of_handle_tracer (decl, insns);
3308 && (flag_unswitch_loops
3310 || flag_unroll_loops))
3311 rest_of_handle_loop2 (decl, insns);
3313 if (flag_rerun_cse_after_loop)
3314 rest_of_handle_cse2 (decl, insns);
3316 cse_not_expected = 1;
3318 rest_of_handle_life (decl, insns);
3321 rest_of_handle_combine (decl, insns);
3323 if (flag_if_conversion)
3324 rest_of_handle_if_after_combine (decl, insns);
3326 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
3327 rest_of_handle_regmove (decl, insns);
3329 /* Do unconditional splitting before register allocation to allow machine
3330 description to add extra information not needed previously. */
3331 split_all_insns (1);
3333 #ifdef OPTIMIZE_MODE_SWITCHING
3334 timevar_push (TV_MODE_SWITCH);
3337 optimize_mode_switching (NULL);
3340 timevar_pop (TV_MODE_SWITCH);
3343 /* Any of the several passes since flow1 will have munged register
3344 lifetime data a bit. We need it to be up to date for scheduling
3345 (see handling of reg_known_equiv in init_alias_analysis). */
3346 recompute_reg_usage (insns, !optimize_size);
3348 #ifdef INSN_SCHEDULING
3349 rest_of_handle_sched (decl, insns);
3352 /* Determine if the current function is a leaf before running reload
3353 since this can impact optimizations done by the prologue and
3354 epilogue thus changing register elimination offsets. */
3355 current_function_is_leaf = leaf_function_p ();
3357 timevar_push (TV_LOCAL_ALLOC);
3358 open_dump_file (DFI_lreg, decl);
3360 if (flag_new_regalloc)
3362 if (rest_of_handle_new_regalloc (decl, insns,
3363 &rebuild_label_notes_after_reload))
3364 goto exit_rest_of_compilation;
3368 if (rest_of_handle_old_regalloc (decl, insns,
3369 &rebuild_label_notes_after_reload))
3370 goto exit_rest_of_compilation;
3375 open_dump_file (DFI_postreload, decl);
3377 /* Do a very simple CSE pass over just the hard registers. */
3380 timevar_push (TV_RELOAD_CSE_REGS);
3381 reload_cse_regs (insns);
3382 timevar_pop (TV_RELOAD_CSE_REGS);
3385 /* Register allocation and reloading may have turned an indirect jump into
3386 a direct jump. If so, we must rebuild the JUMP_LABEL fields of
3387 jumping instructions. */
3388 if (rebuild_label_notes_after_reload)
3390 timevar_push (TV_JUMP);
3392 rebuild_jump_labels (insns);
3393 purge_all_dead_edges (0);
3395 timevar_pop (TV_JUMP);
3398 close_dump_file (DFI_postreload, print_rtl_with_bb, insns);
3400 /* Re-create the death notes which were deleted during reload. */
3401 timevar_push (TV_FLOW2);
3402 open_dump_file (DFI_flow2, decl);
3404 #ifdef ENABLE_CHECKING
3405 verify_flow_info ();
3408 /* If optimizing, then go ahead and split insns now. */
3412 split_all_insns (0);
3414 if (flag_branch_target_load_optimize)
3416 open_dump_file (DFI_branch_target_load, decl);
3418 branch_target_load_optimize (insns, false);
3420 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3426 cleanup_cfg (CLEANUP_EXPENSIVE);
3428 /* On some machines, the prologue and epilogue code, or parts thereof,
3429 can be represented as RTL. Doing so lets us schedule insns between
3430 it and the rest of the code and also allows delayed branch
3431 scheduling to operate in the epilogue. */
3432 thread_prologue_and_epilogue_insns (insns);
3433 epilogue_completed = 1;
3437 life_analysis (insns, rtl_dump_file, PROP_FINAL);
3438 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
3439 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
3441 /* This is kind of a heuristic. We need to run combine_stack_adjustments
3442 even for machines with possibly nonzero RETURN_POPS_ARGS
3443 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
3444 push instructions will have popping returns. */
3445 #ifndef PUSH_ROUNDING
3446 if (!ACCUMULATE_OUTGOING_ARGS)
3448 combine_stack_adjustments ();
3453 flow2_completed = 1;
3455 close_dump_file (DFI_flow2, print_rtl_with_bb, insns);
3456 timevar_pop (TV_FLOW2);
3458 #ifdef HAVE_peephole2
3459 if (optimize > 0 && flag_peephole2)
3461 timevar_push (TV_PEEPHOLE2);
3462 open_dump_file (DFI_peephole2, decl);
3464 peephole2_optimize (rtl_dump_file);
3466 close_dump_file (DFI_peephole2, print_rtl_with_bb, insns);
3467 timevar_pop (TV_PEEPHOLE2);
3473 if (flag_rename_registers || flag_cprop_registers)
3474 rest_of_handle_regrename (decl, insns);
3476 rest_of_handle_reorder_blocks (decl, insns);
3479 if (flag_if_conversion2)
3481 timevar_push (TV_IFCVT2);
3482 open_dump_file (DFI_ce3, decl);
3486 close_dump_file (DFI_ce3, print_rtl_with_bb, insns);
3487 timevar_pop (TV_IFCVT2);
3490 if (flag_branch_target_load_optimize2)
3492 /* Leave this a warning for now so that it is possible to experiment
3493 with running this pass twice. In 3.6, we should either make this
3494 an error, or use separate dump files. */
3495 if (flag_branch_target_load_optimize)
3496 warning ("branch target register load optimization is not intended "
3499 open_dump_file (DFI_branch_target_load, decl);
3501 branch_target_load_optimize (insns, true);
3503 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3508 #ifdef INSN_SCHEDULING
3509 if (optimize > 0 && flag_schedule_insns_after_reload)
3510 rest_of_handle_sched2 (decl, insns);
3513 #ifdef LEAF_REGISTERS
3514 current_function_uses_only_leaf_regs
3515 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
3519 rest_of_handle_stack_regs (decl, insns);
3522 compute_alignments ();
3524 /* CFG is no longer maintained up-to-date. */
3525 free_bb_for_insn ();
3527 if (targetm.machine_dependent_reorg != 0)
3528 rest_of_handle_machine_reorg (decl, insns);
3530 purge_line_number_notes (insns);
3531 cleanup_barriers ();
3534 if (optimize > 0 && flag_delayed_branch)
3535 rest_of_handle_delay_slots (decl, insns);
3538 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3539 timevar_push (TV_SHORTEN_BRANCH);
3540 split_all_insns_noflow ();
3541 timevar_pop (TV_SHORTEN_BRANCH);
3544 convert_to_eh_region_ranges ();
3546 /* Shorten branches. */
3547 timevar_push (TV_SHORTEN_BRANCH);
3548 shorten_branches (get_insns ());
3549 timevar_pop (TV_SHORTEN_BRANCH);
3551 set_nothrow_function_flags ();
3552 if (current_function_nothrow)
3553 /* Now we know that this can't throw; set the flag for the benefit
3554 of other functions later in this translation unit. */
3555 TREE_NOTHROW (current_function_decl) = 1;
3557 rest_of_handle_final (decl, insns);
3559 /* Write DBX symbols if requested. */
3561 /* Note that for those inline functions where we don't initially
3562 know for certain that we will be generating an out-of-line copy,
3563 the first invocation of this routine (rest_of_compilation) will
3564 skip over this code by doing a `goto exit_rest_of_compilation;'.
3565 Later on, wrapup_global_declarations will (indirectly) call
3566 rest_of_compilation again for those inline functions that need
3567 to have out-of-line copies generated. During that call, we
3568 *will* be routed past here. */
3570 timevar_push (TV_SYMOUT);
3571 (*debug_hooks->function_decl) (decl);
3572 timevar_pop (TV_SYMOUT);
3574 exit_rest_of_compilation:
3576 coverage_end_function ();
3578 /* In case the function was not output,
3579 don't leave any temporary anonymous types
3580 queued up for sdb output. */
3581 #ifdef SDB_DEBUGGING_INFO
3582 if (write_symbols == SDB_DEBUG)
3583 sdbout_types (NULL_TREE);
3586 reload_completed = 0;
3587 epilogue_completed = 0;
3588 flow2_completed = 0;
3591 timevar_push (TV_FINAL);
3593 /* Clear out the insn_length contents now that they are no
3595 init_insn_lengths ();
3597 /* Show no temporary slots allocated. */
3600 free_basic_block_vars (0);
3601 free_bb_for_insn ();
3603 timevar_pop (TV_FINAL);
3605 if ((*targetm.binds_local_p) (current_function_decl))
3607 int pref = cfun->preferred_stack_boundary;
3608 if (cfun->recursive_call_emit
3609 && cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
3610 pref = cfun->stack_alignment_needed;
3611 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
3615 /* Make sure volatile mem refs aren't considered valid operands for
3616 arithmetic insns. We must call this here if this is a nested inline
3617 function, since the above code leaves us in the init_recog state
3618 (from final.c), and the function context push/pop code does not
3619 save/restore volatile_ok.
3621 ??? Maybe it isn't necessary for expand_start_function to call this
3622 anymore if we do it here? */
3624 init_recog_no_volatile ();
3626 /* We're done with this function. Free up memory if we can. */
3627 free_after_parsing (cfun);
3628 if (! DECL_DEFER_OUTPUT (decl))
3630 free_after_compilation (cfun);
3631 DECL_SAVED_INSNS (decl) = 0;
3637 timevar_pop (TV_REST_OF_COMPILATION);
3640 /* Display help for target options. */
3642 display_target_options (void)
3645 static bool displayed = false;
3647 /* Avoid double printing for --help --target-help. */
3653 if (ARRAY_SIZE (target_switches) > 1
3654 #ifdef TARGET_OPTIONS
3655 || ARRAY_SIZE (target_options) > 1
3663 printf (_("\nTarget specific options:\n"));
3665 for (i = ARRAY_SIZE (target_switches); i--;)
3667 const char *option = target_switches[i].name;
3668 const char *description = target_switches[i].description;
3670 if (option == NULL || *option == 0)
3672 else if (description == NULL)
3677 printf (_(" -m%-23s [undocumented]\n"), option);
3679 else if (*description != 0)
3680 doc += printf (" -m%-23s %s\n", option, _(description));
3683 #ifdef TARGET_OPTIONS
3684 for (i = ARRAY_SIZE (target_options); i--;)
3686 const char *option = target_options[i].prefix;
3687 const char *description = target_options[i].description;
3689 if (option == NULL || *option == 0)
3691 else if (description == NULL)
3696 printf (_(" -m%-23s [undocumented]\n"), option);
3698 else if (*description != 0)
3699 doc += printf (" -m%-23s %s\n", option, _(description));
3705 printf (_("\nThere are undocumented target specific options as well.\n"));
3707 printf (_(" They exist, but they are not documented.\n"));
3712 /* Parse a -d... command line switch. */
3715 decode_d_option (const char *arg)
3723 for (i = 0; i < (int) DFI_MAX; ++i)
3724 dump_file[i].enabled = 1;
3730 flag_print_asm_name = 1;
3733 flag_dump_rtl_in_asm = 1;
3734 flag_print_asm_name = 1;
3737 graph_dump_format = vcg;
3740 rtl_dump_and_exit = 1;
3745 case 'D': /* These are handled by the preprocessor. */
3749 setup_core_dumping();
3754 for (i = 0; i < (int) DFI_MAX; ++i)
3755 if (c == dump_file[i].debug_switch)
3757 dump_file[i].enabled = 1;
3762 warning ("unrecognized gcc debugging option: %c", c);
3767 /* Indexed by enum debug_info_type. */
3768 const char *const debug_type_names[] =
3770 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
3773 /* Decode -m switches. */
3774 /* Decode the switch -mNAME. */
3777 set_target_switch (const char *name)
3780 int valid_target_option = 0;
3782 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
3783 if (!strcmp (target_switches[j].name, name))
3785 if (target_switches[j].value < 0)
3786 target_flags &= ~-target_switches[j].value;
3788 target_flags |= target_switches[j].value;
3791 if (target_switches[j].value < 0)
3792 target_flags_explicit |= -target_switches[j].value;
3794 target_flags_explicit |= target_switches[j].value;
3796 valid_target_option = 1;
3799 #ifdef TARGET_OPTIONS
3800 if (!valid_target_option)
3801 for (j = 0; j < ARRAY_SIZE (target_options); j++)
3803 int len = strlen (target_options[j].prefix);
3804 if (target_options[j].value)
3806 if (!strcmp (target_options[j].prefix, name))
3808 *target_options[j].variable = target_options[j].value;
3809 valid_target_option = 1;
3814 if (!strncmp (target_options[j].prefix, name, len))
3816 *target_options[j].variable = name + len;
3817 valid_target_option = 1;
3823 if (!valid_target_option)
3824 error ("invalid option `%s'", name);
3827 /* Print version information to FILE.
3828 Each line begins with INDENT (for the case where FILE is the
3829 assembler output file). */
3832 print_version (FILE *file, const char *indent)
3835 #define __VERSION__ "[?]"
3839 "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
3841 "%s%s%s version %s (%s) compiled by CC.\n"
3843 , indent, *indent != 0 ? " " : "",
3844 lang_hooks.name, version_string, TARGET_NAME,
3845 indent, __VERSION__);
3846 fnotice (file, "%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n",
3847 indent, *indent != 0 ? " " : "",
3848 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
3851 /* Print an option value and return the adjusted position in the line.
3852 ??? We don't handle error returns from fprintf (disk full); presumably
3853 other code will catch a disk full though. */
3856 print_single_switch (FILE *file, int pos, int max,
3857 const char *indent, const char *sep, const char *term,
3858 const char *type, const char *name)
3860 /* The ultrix fprintf returns 0 on success, so compute the result we want
3861 here since we need it for the following test. */
3862 int len = strlen (sep) + strlen (type) + strlen (name);
3867 fprintf (file, "%s", term);
3872 fprintf (file, "%s", indent);
3873 pos = strlen (indent);
3875 fprintf (file, "%s%s%s", sep, type, name);
3880 /* Print active target switches to FILE.
3881 POS is the current cursor position and MAX is the size of a "line".
3882 Each line begins with INDENT and ends with TERM.
3883 Each switch is separated from the next by SEP. */
3886 print_switch_values (FILE *file, int pos, int max,
3887 const char *indent, const char *sep, const char *term)
3892 /* Fill in the -frandom-seed option, if the user didn't pass it, so
3893 that it can be printed below. This helps reproducibility. */
3896 /* Print the options as passed. */
3897 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
3898 _("options passed: "), "");
3900 for (p = &save_argv[1]; *p != NULL; p++)
3904 if (strcmp (*p, "-o") == 0)
3910 if (strcmp (*p, "-quiet") == 0)
3912 if (strcmp (*p, "-version") == 0)
3917 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
3920 fprintf (file, "%s", term);
3922 /* Print the -f and -m options that have been enabled.
3923 We don't handle language specific options but printing argv
3926 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
3927 _("options enabled: "), "");
3929 for (j = 0; j < ARRAY_SIZE (f_options); j++)
3930 if (*f_options[j].variable == f_options[j].on_value)
3931 pos = print_single_switch (file, pos, max, indent, sep, term,
3932 "-f", f_options[j].string);
3934 /* Print target specific options. */
3936 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
3937 if (target_switches[j].name[0] != '\0'
3938 && target_switches[j].value > 0
3939 && ((target_switches[j].value & target_flags)
3940 == target_switches[j].value))
3942 pos = print_single_switch (file, pos, max, indent, sep, term,
3943 "-m", target_switches[j].name);
3946 #ifdef TARGET_OPTIONS
3947 for (j = 0; j < ARRAY_SIZE (target_options); j++)
3948 if (*target_options[j].variable != NULL)
3951 sprintf (prefix, "-m%s", target_options[j].prefix);
3952 pos = print_single_switch (file, pos, max, indent, sep, term,
3953 prefix, *target_options[j].variable);
3957 fprintf (file, "%s", term);
3960 /* Open assembly code output file. Do this even if -fsyntax-only is
3961 on, because then the driver will have provided the name of a
3962 temporary file or bit bucket for us. NAME is the file specified on
3963 the command line, possibly NULL. */
3965 init_asm_output (const char *name)
3967 if (name == NULL && asm_file_name == 0)
3968 asm_out_file = stdout;
3971 if (asm_file_name == 0)
3973 int len = strlen (dump_base_name);
3974 char *dumpname = xmalloc (len + 6);
3975 memcpy (dumpname, dump_base_name, len + 1);
3976 strip_off_ending (dumpname, len);
3977 strcat (dumpname, ".s");
3978 asm_file_name = dumpname;
3980 if (!strcmp (asm_file_name, "-"))
3981 asm_out_file = stdout;
3983 asm_out_file = fopen (asm_file_name, "w+");
3984 if (asm_out_file == 0)
3985 fatal_error ("can't open %s for writing: %m", asm_file_name);
3988 #ifdef IO_BUFFER_SIZE
3989 setvbuf (asm_out_file, xmalloc (IO_BUFFER_SIZE),
3990 _IOFBF, IO_BUFFER_SIZE);
3993 if (!flag_syntax_only)
3995 targetm.asm_out.file_start ();
3997 #ifdef ASM_COMMENT_START
3998 if (flag_verbose_asm)
4000 /* Print the list of options in effect. */
4001 print_version (asm_out_file, ASM_COMMENT_START);
4002 print_switch_values (asm_out_file, 0, MAX_LINE,
4003 ASM_COMMENT_START, " ", "\n");
4004 /* Add a blank line here so it appears in assembler output but not
4006 fprintf (asm_out_file, "\n");
4012 /* Default tree printer. Handles declarations only. */
4014 default_tree_printer (pretty_printer * pp, text_info *text)
4016 switch (*text->format_spec)
4022 tree t = va_arg (*text->args_ptr, tree);
4023 const char *n = DECL_NAME (t)
4024 ? (*lang_hooks.decl_printable_name) (t, 2)
4035 /* Initialization of the front end environment, before command line
4036 options are parsed. Signal handlers, internationalization etc.
4037 ARGV0 is main's argv[0]. */
4039 general_init (const char *argv0)
4043 p = argv0 + strlen (argv0);
4044 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
4048 xmalloc_set_program_name (progname);
4052 gcc_init_libintl ();
4054 /* Initialize the diagnostics reporting machinery, so option parsing
4055 can give warnings and errors. */
4056 diagnostic_initialize (global_dc);
4057 /* Set a default printer. Language specific initializations will
4058 override it later. */
4059 pp_format_decoder (global_dc->printer) = &default_tree_printer;
4061 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
4063 signal (SIGSEGV, crash_signal);
4066 signal (SIGILL, crash_signal);
4069 signal (SIGBUS, crash_signal);
4072 signal (SIGABRT, crash_signal);
4074 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
4075 signal (SIGIOT, crash_signal);
4078 signal (SIGFPE, crash_signal);
4081 /* Other host-specific signal setup. */
4082 (*host_hooks.extra_signals)();
4084 /* Initialize the garbage-collector, string pools and tree type hash
4090 /* Initialize register usage now so switches may override. */
4093 /* Register the language-independent parameters. */
4094 add_params (lang_independent_params, LAST_PARAM);
4096 /* This must be done after add_params but before argument processing. */
4097 init_ggc_heuristics();
4100 /* Process the options that have been parsed. */
4102 process_options (void)
4104 /* Allow the front end to perform consistency checks and do further
4105 initialization based on the command line options. This hook also
4106 sets the original filename if appropriate (e.g. foo.i -> foo.c)
4107 so we can correctly initialize debug output. */
4108 no_backend = (*lang_hooks.post_options) (&main_input_filename);
4109 input_filename = main_input_filename;
4111 #ifdef OVERRIDE_OPTIONS
4112 /* Some machines may reject certain combinations of options. */
4116 /* Set aux_base_name if not already set. */
4119 else if (main_input_filename)
4121 char *name = xstrdup (lbasename (main_input_filename));
4123 strip_off_ending (name, strlen (name));
4124 aux_base_name = name;
4127 aux_base_name = "gccaux";
4129 /* Set up the align_*_log variables, defaulting them to 1 if they
4130 were still unset. */
4131 if (align_loops <= 0) align_loops = 1;
4132 if (align_loops_max_skip > align_loops || !align_loops)
4133 align_loops_max_skip = align_loops - 1;
4134 align_loops_log = floor_log2 (align_loops * 2 - 1);
4135 if (align_jumps <= 0) align_jumps = 1;
4136 if (align_jumps_max_skip > align_jumps || !align_jumps)
4137 align_jumps_max_skip = align_jumps - 1;
4138 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
4139 if (align_labels <= 0) align_labels = 1;
4140 align_labels_log = floor_log2 (align_labels * 2 - 1);
4141 if (align_labels_max_skip > align_labels || !align_labels)
4142 align_labels_max_skip = align_labels - 1;
4143 if (align_functions <= 0) align_functions = 1;
4144 align_functions_log = floor_log2 (align_functions * 2 - 1);
4146 /* Unrolling all loops implies that standard loop unrolling must also
4148 if (flag_unroll_all_loops)
4149 flag_unroll_loops = 1;
4151 if (flag_unroll_loops)
4153 flag_old_unroll_loops = 0;
4154 flag_old_unroll_all_loops = 0;
4157 if (flag_old_unroll_all_loops)
4158 flag_old_unroll_loops = 1;
4160 /* Old loop unrolling requires that strength_reduction be on also. Silently
4161 turn on strength reduction here if it isn't already on. Also, the loop
4162 unrolling code assumes that cse will be run after loop, so that must
4163 be turned on also. */
4164 if (flag_old_unroll_loops)
4166 flag_strength_reduce = 1;
4167 flag_rerun_cse_after_loop = 1;
4169 if (flag_unroll_loops || flag_peel_loops)
4170 flag_rerun_cse_after_loop = 1;
4172 if (flag_non_call_exceptions)
4173 flag_asynchronous_unwind_tables = 1;
4174 if (flag_asynchronous_unwind_tables)
4175 flag_unwind_tables = 1;
4177 /* Disable unit-at-a-time mode for frontends not supporting callgraph
4179 if (flag_unit_at_a_time && ! lang_hooks.callgraph.expand_function)
4180 flag_unit_at_a_time = 0;
4182 /* Warn about options that are not supported on this machine. */
4183 #ifndef INSN_SCHEDULING
4184 if (flag_schedule_insns || flag_schedule_insns_after_reload)
4185 warning ("instruction scheduling not supported on this target machine");
4188 if (flag_delayed_branch)
4189 warning ("this target machine does not have delayed branches");
4192 user_label_prefix = USER_LABEL_PREFIX;
4193 if (flag_leading_underscore != -1)
4195 /* If the default prefix is more complicated than "" or "_",
4196 issue a warning and ignore this option. */
4197 if (user_label_prefix[0] == 0 ||
4198 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
4200 user_label_prefix = flag_leading_underscore ? "_" : "";
4203 warning ("-f%sleading-underscore not supported on this target machine",
4204 flag_leading_underscore ? "" : "no-");
4207 /* If we are in verbose mode, write out the version and maybe all the
4208 option flags in use. */
4211 print_version (stderr, "");
4213 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
4216 if (flag_syntax_only)
4218 write_symbols = NO_DEBUG;
4222 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
4224 if (debug_info_level == DINFO_LEVEL_NONE)
4225 write_symbols = NO_DEBUG;
4227 /* Now we know write_symbols, set up the debug hooks based on it.
4228 By default we do nothing for debug output. */
4229 if (write_symbols == NO_DEBUG)
4230 debug_hooks = &do_nothing_debug_hooks;
4231 #if defined(DBX_DEBUGGING_INFO)
4232 else if (write_symbols == DBX_DEBUG)
4233 debug_hooks = &dbx_debug_hooks;
4235 #if defined(XCOFF_DEBUGGING_INFO)
4236 else if (write_symbols == XCOFF_DEBUG)
4237 debug_hooks = &xcoff_debug_hooks;
4239 #ifdef SDB_DEBUGGING_INFO
4240 else if (write_symbols == SDB_DEBUG)
4241 debug_hooks = &sdb_debug_hooks;
4243 #ifdef DWARF_DEBUGGING_INFO
4244 else if (write_symbols == DWARF_DEBUG)
4245 debug_hooks = &dwarf_debug_hooks;
4247 #ifdef DWARF2_DEBUGGING_INFO
4248 else if (write_symbols == DWARF2_DEBUG)
4249 debug_hooks = &dwarf2_debug_hooks;
4251 #ifdef VMS_DEBUGGING_INFO
4252 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
4253 debug_hooks = &vmsdbg_debug_hooks;
4256 error ("target system does not support the \"%s\" debug format",
4257 debug_type_names[write_symbols]);
4259 /* If auxiliary info generation is desired, open the output file.
4260 This goes in the same directory as the source file--unlike
4261 all the other output files. */
4262 if (flag_gen_aux_info)
4264 aux_info_file = fopen (aux_info_file_name, "w");
4265 if (aux_info_file == 0)
4266 fatal_error ("can't open %s: %m", aux_info_file_name);
4269 if (! targetm.have_named_sections)
4271 if (flag_function_sections)
4273 warning ("-ffunction-sections not supported for this target");
4274 flag_function_sections = 0;
4276 if (flag_data_sections)
4278 warning ("-fdata-sections not supported for this target");
4279 flag_data_sections = 0;
4283 if (flag_function_sections && profile_flag)
4285 warning ("-ffunction-sections disabled; it makes profiling impossible");
4286 flag_function_sections = 0;
4289 #ifndef HAVE_prefetch
4290 if (flag_prefetch_loop_arrays)
4292 warning ("-fprefetch-loop-arrays not supported for this target");
4293 flag_prefetch_loop_arrays = 0;
4296 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
4298 warning ("-fprefetch-loop-arrays not supported for this target (try -march switches)");
4299 flag_prefetch_loop_arrays = 0;
4303 /* This combination of options isn't handled for i386 targets and doesn't
4304 make much sense anyway, so don't allow it. */
4305 if (flag_prefetch_loop_arrays && optimize_size)
4307 warning ("-fprefetch-loop-arrays is not supported with -Os");
4308 flag_prefetch_loop_arrays = 0;
4311 #ifndef OBJECT_FORMAT_ELF
4312 if (flag_function_sections && write_symbols != NO_DEBUG)
4313 warning ("-ffunction-sections may affect debugging on some targets");
4316 /* The presence of IEEE signaling NaNs, implies all math can trap. */
4317 if (flag_signaling_nans)
4318 flag_trapping_math = 1;
4321 /* Initialize the compiler back end. */
4325 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
4326 || debug_info_level == DINFO_LEVEL_VERBOSE
4327 #ifdef VMS_DEBUGGING_INFO
4328 /* Enable line number info for traceback. */
4329 || debug_info_level > DINFO_LEVEL_NONE
4331 || flag_test_coverage
4332 || warn_notreached);
4335 init_fake_stack_mems ();
4339 init_function_once ();
4340 init_varasm_once ();
4342 /* The following initialization functions need to generate rtl, so
4343 provide a dummy function context for them. */
4344 init_dummy_function_start ();
4346 if (flag_caller_saves)
4347 init_caller_save ();
4348 expand_dummy_function_end ();
4351 /* Language-dependent initialization. Returns nonzero on success. */
4353 lang_dependent_init (const char *name)
4355 if (dump_base_name == 0)
4356 dump_base_name = name ? name : "gccdump";
4358 /* Other front-end initialization. */
4359 if ((*lang_hooks.init) () == 0)
4362 init_asm_output (name);
4364 /* These create various _DECL nodes, so need to be called after the
4365 front end is initialized. */
4369 /* The following initialization functions need to generate rtl, so
4370 provide a dummy function context for them. */
4371 init_dummy_function_start ();
4373 expand_dummy_function_end ();
4375 /* If dbx symbol table desired, initialize writing it and output the
4376 predefined types. */
4377 timevar_push (TV_SYMOUT);
4379 #ifdef DWARF2_UNWIND_INFO
4380 if (dwarf2out_do_frame ())
4381 dwarf2out_frame_init ();
4384 /* Now we have the correct original filename, we can initialize
4386 (*debug_hooks->init) (name);
4388 timevar_pop (TV_SYMOUT);
4393 /* Clean up: close opened files, etc. */
4398 /* Close the dump files. */
4399 if (flag_gen_aux_info)
4401 fclose (aux_info_file);
4403 unlink (aux_info_file_name);
4406 /* Close non-debugging input and output files. Take special care to note
4407 whether fclose returns an error, since the pages might still be on the
4408 buffer chain while the file is open. */
4412 if (ferror (asm_out_file) != 0)
4413 fatal_error ("error writing to %s: %m", asm_file_name);
4414 if (fclose (asm_out_file) != 0)
4415 fatal_error ("error closing %s: %m", asm_file_name);
4418 /* Do whatever is necessary to finish printing the graphs. */
4419 if (graph_dump_format != no_graph)
4423 for (i = 0; i < (int) DFI_MAX; ++i)
4424 if (dump_file[i].initialized && dump_file[i].graph_dump_p)
4429 sprintf (seq, DUMPFILE_FORMAT, i);
4430 suffix = concat (seq, dump_file[i].extension, NULL);
4431 finish_graph_dump_file (dump_base_name, suffix);
4438 ggc_print_statistics ();
4439 stringpool_statistics ();
4440 dump_tree_statistics ();
4443 /* Free up memory for the benefit of leak detectors. */
4446 /* Language-specific end of compilation actions. */
4447 (*lang_hooks.finish) ();
4450 /* Initialize the compiler, and compile the input file. */
4454 /* Initialize timing first. The C front ends read the main file in
4455 the post_options hook, and C++ does file timings. */
4456 if (time_report || !quiet_flag || flag_detailed_statistics)
4458 timevar_start (TV_TOTAL);
4462 /* Don't do any more if an error has already occurred. */
4465 /* Set up the back-end if requested. */
4469 /* Language-dependent initialization. Returns true on success. */
4470 if (lang_dependent_init (main_input_filename))
4472 if (flag_unit_at_a_time)
4474 open_dump_file (DFI_cgraph, NULL);
4475 cgraph_dump_file = rtl_dump_file;
4476 rtl_dump_file = NULL;
4481 if (flag_unit_at_a_time)
4483 rtl_dump_file = cgraph_dump_file;
4484 cgraph_dump_file = NULL;
4485 close_dump_file (DFI_cgraph, NULL, NULL_RTX);
4492 /* Stop timing and print the times. */
4493 timevar_stop (TV_TOTAL);
4494 timevar_print (stderr);
4497 /* Entry point of cc1, cc1plus, jc1, f771, etc.
4498 Exit code is FATAL_EXIT_CODE if can't open files or if there were
4499 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
4501 It is not safe to call this function more than once. */
4504 toplev_main (unsigned int argc, const char **argv)
4508 /* Initialization of GCC's environment, and diagnostics. */
4509 general_init (argv[0]);
4511 /* Parse the options and do minimal processing; basically just
4512 enough to default flags appropriately. */
4513 decode_options (argc, argv);
4517 /* Exit early if we can (e.g. -help). */
4518 if (!exit_after_options)
4521 if (errorcount || sorrycount)
4522 return (FATAL_EXIT_CODE);
4524 return (SUCCESS_EXIT_CODE);