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_addresof (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 = &do_nothing_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 /* Type(s) of debugging information we are producing (if any).
359 See flags.h for the definitions of the different possible
360 types of debugging information. */
361 enum debug_info_type write_symbols = NO_DEBUG;
363 /* Level of debugging information we are producing. See flags.h
364 for the definitions of the different possible levels. */
365 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
367 /* Nonzero means use GNU-only extensions in the generated symbolic
368 debugging information. */
369 /* Currently, this only has an effect when write_symbols is set to
370 DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
371 int use_gnu_debug_info_extensions = 0;
373 /* Nonzero means do optimizations. -O.
374 Particular numeric values stand for particular amounts of optimization;
375 thus, -O2 stores 2 here. However, the optimizations beyond the basic
376 ones are not controlled directly by this variable. Instead, they are
377 controlled by individual `flag_...' variables that are defaulted
378 based on this variable. */
382 /* Nonzero means optimize for size. -Os.
383 The only valid values are zero and nonzero. When optimize_size is
384 nonzero, optimize defaults to 2, but certain individual code
385 bloating optimizations are disabled. */
387 int optimize_size = 0;
389 /* The FUNCTION_DECL for the function currently being compiled,
390 or 0 if between functions. */
391 tree current_function_decl;
393 /* Set to the FUNC_BEGIN label of the current function, or NULL_TREE
395 tree current_function_func_begin_label;
397 /* Nonzero if doing dwarf2 duplicate elimination. */
399 int flag_eliminate_dwarf2_dups = 0;
401 /* Nonzero if doing unused type elimination. */
403 int flag_eliminate_unused_debug_types = 1;
405 /* Nonzero means emit debugging information only for symbols which are used. */
406 int flag_debug_only_used_symbols = 0;
408 /* Nonzero if generating code to do profiling. */
410 int profile_flag = 0;
412 /* Nonzero if generating code to profile program flow graph arcs. */
414 int profile_arc_flag = 0;
416 /* Nonzero if value histograms should be measured. */
418 int flag_profile_values = 0;
420 /* Nonzero if generating info for gcov to calculate line test coverage. */
422 int flag_test_coverage = 0;
424 /* Nonzero indicates that branch taken probabilities should be calculated. */
426 int flag_branch_probabilities = 0;
428 /* Nonzero if basic blocks should be reordered. */
430 int flag_reorder_blocks = 0;
432 /* Nonzero if functions should be reordered. */
434 int flag_reorder_functions = 0;
436 /* Nonzero if registers should be renamed. */
438 int flag_rename_registers = 0;
439 int flag_cprop_registers = 0;
441 /* Nonzero for -pedantic switch: warn about anything
442 that standard spec forbids. */
446 /* Temporarily suppress certain warnings.
447 This is set while reading code from a system header file. */
449 int in_system_header = 0;
451 /* Don't print functions as they are compiled. -quiet. */
455 /* Print times taken by the various passes. -ftime-report. */
459 /* Print memory still in use at end of compilation (which may have little
460 to do with peak memory consumption). -fmem-report. */
464 /* Nonzero means to collect statistics which might be expensive
465 and to print them when we are done. */
466 int flag_detailed_statistics = 0;
468 /* A random sequence of characters, unless overridden by user. */
469 const char *flag_random_seed;
471 /* A local time stamp derived from the time of compilation. It will be
472 zero if the system cannot provide a time. It will be -1u, if the
473 user has specified a particular random seed. */
478 /* Nonzero means `char' should be signed. */
480 int flag_signed_char;
482 /* Nonzero means give an enum type only as many bytes as it needs. */
484 int flag_short_enums;
486 /* Nonzero for -fcaller-saves: allocate values in regs that need to
487 be saved across function calls, if that produces overall better code.
488 Optional now, so people can test it. */
490 #ifdef DEFAULT_CALLER_SAVES
491 int flag_caller_saves = 1;
493 int flag_caller_saves = 0;
496 /* Nonzero if structures and unions should be returned in memory.
498 This should only be defined if compatibility with another compiler or
499 with an ABI is needed, because it results in slower code. */
501 #ifndef DEFAULT_PCC_STRUCT_RETURN
502 #define DEFAULT_PCC_STRUCT_RETURN 1
505 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
507 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
509 /* Nonzero for -fforce-mem: load memory value into a register
510 before arithmetic on it. This makes better cse but slower compilation. */
512 int flag_force_mem = 0;
514 /* Nonzero for -fforce-addr: load memory address into a register before
515 reference to memory. This makes better cse but slower compilation. */
517 int flag_force_addr = 0;
519 /* Nonzero for -fdefer-pop: don't pop args after each function call;
520 instead save them up to pop many calls' args with one insns. */
522 int flag_defer_pop = 0;
524 /* Nonzero for -ffloat-store: don't allocate floats and doubles
525 in extended-precision registers. */
527 int flag_float_store = 0;
529 /* Nonzero for -fcse-follow-jumps:
530 have cse follow jumps to do a more extensive job. */
532 int flag_cse_follow_jumps;
534 /* Nonzero for -fcse-skip-blocks:
535 have cse follow a branch around a block. */
536 int flag_cse_skip_blocks;
538 /* Nonzero for -fexpensive-optimizations:
539 perform miscellaneous relatively-expensive optimizations. */
540 int flag_expensive_optimizations;
542 /* Nonzero for -fthread-jumps:
543 have jump optimize output of loop. */
545 int flag_thread_jumps;
547 /* Nonzero enables strength-reduction in loop.c. */
549 int flag_strength_reduce = 0;
551 /* Nonzero enables loop unrolling in unroll.c. Only loops for which the
552 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
553 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
556 int flag_old_unroll_loops;
558 /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
559 This is generally not a win. */
561 int flag_old_unroll_all_loops;
563 /* Enables unrolling of simple loops in loop-unroll.c. */
564 int flag_unroll_loops;
566 /* Enables unrolling of all loops in loop-unroll.c. */
567 int flag_unroll_all_loops;
569 /* Nonzero enables loop peeling. */
572 /* Nonzero enables loop unswitching. */
573 int flag_unswitch_loops;
575 /* Nonzero enables prefetch optimizations for arrays in loops. */
577 int flag_prefetch_loop_arrays;
579 /* Nonzero forces all invariant computations in loops to be moved
582 int flag_move_all_movables = 0;
584 /* Nonzero forces all general induction variables in loops to be
587 int flag_reduce_all_givs = 0;
589 /* Nonzero to perform full register move optimization passes. This is the
592 int flag_regmove = 0;
594 /* Nonzero for -fwritable-strings:
595 store string constants in data segment and don't uniquize them. */
597 int flag_writable_strings = 0;
599 /* Nonzero means don't put addresses of constant functions in registers.
600 Used for compiling the Unix kernel, where strange substitutions are
601 done on the assembly output. */
603 int flag_no_function_cse = 0;
605 /* Nonzero for -fomit-frame-pointer:
606 don't make a frame pointer in simple functions that don't require one. */
608 int flag_omit_frame_pointer = 0;
610 /* Nonzero means place each function into its own section on those platforms
611 which support arbitrary section names and unlimited numbers of sections. */
613 int flag_function_sections = 0;
615 /* ... and similar for data. */
617 int flag_data_sections = 0;
619 /* Nonzero to inhibit use of define_optimization peephole opts. */
621 int flag_no_peephole = 0;
623 /* Nonzero allows GCC to optimize sibling and tail recursive calls. */
625 int flag_optimize_sibling_calls = 0;
627 /* Nonzero means the front end generally wants `errno' maintained by math
628 operations, like built-in SQRT. */
630 int flag_errno_math = 1;
632 /* Nonzero means that unsafe floating-point math optimizations are allowed
633 for the sake of speed. IEEE compliance is not guaranteed, and operations
634 are allowed to assume that their arguments and results are "normal"
635 (e.g., nonnegative for SQRT). */
637 int flag_unsafe_math_optimizations = 0;
639 /* Nonzero means that no NaNs or +-Infs are expected. */
641 int flag_finite_math_only = 0;
643 /* Zero means that floating-point math operations cannot generate a
644 (user-visible) trap. This is the case, for example, in nonstop
645 IEEE 754 arithmetic. Trapping conditions include division by zero,
646 overflow, underflow, invalid and inexact, but does not include
647 operations on signaling NaNs (see below). */
649 int flag_trapping_math = 1;
651 /* Nonzero means disable transformations observable by signaling NaNs.
652 This option implies that any operation on an IEEE signaling NaN can
653 generate a (user-visible) trap. */
655 int flag_signaling_nans = 0;
657 /* 0 means straightforward implementation of complex divide acceptable.
658 1 means wide ranges of inputs must work for complex divide.
659 2 means C99-like requirements for complex divide (not yet implemented). */
661 int flag_complex_divide_method = 0;
663 /* Nonzero means just do syntax checking; don't output anything. */
665 int flag_syntax_only = 0;
667 /* Nonzero means perform loop optimizer. */
669 int flag_loop_optimize;
671 /* Nonzero means perform crossjumping. */
673 int flag_crossjumping;
675 /* Nonzero means perform if conversion. */
677 int flag_if_conversion;
679 /* Nonzero means perform if conversion after reload. */
681 int flag_if_conversion2;
683 /* Nonzero means to use global dataflow analysis to eliminate
684 useless null pointer tests. */
686 int flag_delete_null_pointer_checks;
688 /* Nonzero means perform global CSE. */
692 /* Nonzero means to do the enhanced load motion during gcse, which trys
693 to hoist loads by not killing them when a store to the same location
696 int flag_gcse_lm = 1;
698 /* Nonzero means to perform store motion after gcse, which will try to
699 move stores closer to the exit block. Its not very effective without
702 int flag_gcse_sm = 1;
704 /* Perform target register optimization before prologue / epilogue
707 int flag_branch_target_load_optimize = 0;
709 /* Perform target register optimization after prologue / epilogue
710 threading and jump2. */
712 int flag_branch_target_load_optimize2 = 0;
714 /* Nonzero means to rerun cse after loop optimization. This increases
715 compilation time about 20% and picks up a few more common expressions. */
717 int flag_rerun_cse_after_loop;
719 /* Nonzero means to run loop optimizations twice. */
721 int flag_rerun_loop_opt;
723 /* Nonzero for -finline-functions: ok to inline functions that look like
724 good inline candidates. */
726 int flag_inline_functions;
728 /* Nonzero for -fkeep-inline-functions: even if we make a function
729 go inline everywhere, keep its definition around for debugging
732 int flag_keep_inline_functions;
734 /* Nonzero means that functions will not be inlined. */
736 int flag_no_inline = 2;
738 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
739 not just because the tree inliner turned us off. */
741 int flag_really_no_inline = 2;
743 /* Nonzero means that we should emit static const variables
744 regardless of whether or not optimization is turned on. */
746 int flag_keep_static_consts = 1;
748 /* Nonzero means we should be saving declaration info into a .X file. */
750 int flag_gen_aux_info = 0;
752 /* Specified name of aux-info file. */
754 const char *aux_info_file_name;
756 /* Nonzero means make the text shared if supported. */
758 int flag_shared_data;
760 /* Nonzero means schedule into delayed branch slots if supported. */
762 int flag_delayed_branch;
764 /* Nonzero if we are compiling pure (sharable) code.
765 Value is 1 if we are doing "small" pic; value is 2 if we're doing
770 /* Nonzero if we are compiling position independent code for executable.
771 The value is 1 if we are doing "small" pic; value is 2 if we're doing
776 /* Nonzero if we are compiling code for a shared library, zero for
781 /* Set to the default thread-local storage (tls) model to use. */
783 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
785 /* Nonzero means generate extra code for exception handling and enable
786 exception handling. */
790 /* Nonzero means generate frame unwind info table when supported. */
792 int flag_unwind_tables = 0;
794 /* Nonzero means generate frame unwind info table exact at each insn
797 int flag_asynchronous_unwind_tables = 0;
799 /* Nonzero means don't place uninitialized global data in common storage
804 /* Nonzero means change certain warnings into errors.
805 Usually these are warnings about failure to conform to some standard. */
807 int flag_pedantic_errors = 0;
809 /* flag_schedule_insns means schedule insns within basic blocks (before
811 flag_schedule_insns_after_reload means schedule insns after
814 int flag_schedule_insns = 0;
815 int flag_schedule_insns_after_reload = 0;
817 /* When flag_schedule_insns_after_reload is set, use EBB scheduler. */
818 int flag_sched2_use_superblocks = 0;
820 /* When flag_schedule_insns_after_reload is set, construct traces and EBB
822 int flag_sched2_use_traces = 0;
824 /* The following flags have effect only for scheduling before register
827 flag_schedule_interblock means schedule insns across basic blocks.
828 flag_schedule_speculative means allow speculative motion of non-load insns.
829 flag_schedule_speculative_load means allow speculative motion of some
831 flag_schedule_speculative_load_dangerous allows speculative motion of more
834 int flag_schedule_interblock = 1;
835 int flag_schedule_speculative = 1;
836 int flag_schedule_speculative_load = 0;
837 int flag_schedule_speculative_load_dangerous = 0;
839 int flag_single_precision_constant;
841 /* flag_branch_on_count_reg means try to replace add-1,compare,branch tupple
842 by a cheaper branch on a count register. */
843 int flag_branch_on_count_reg = 1;
845 /* -finhibit-size-directive inhibits output of .size for ELF.
846 This is used only for compiling crtstuff.c,
847 and it may be extended to other effects
848 needed for crtstuff.c on other systems. */
849 int flag_inhibit_size_directive = 0;
851 /* -fverbose-asm causes extra commentary information to be produced in
852 the generated assembly code (to make it more readable). This option
853 is generally only of use to those who actually need to read the
854 generated assembly code (perhaps while debugging the compiler itself).
855 -fno-verbose-asm, the default, causes the extra information
856 to be omitted and is useful when comparing two assembler files. */
858 int flag_verbose_asm = 0;
860 /* -dA causes debug commentary information to be produced in
861 the generated assembly code (to make it more readable). This option
862 is generally only of use to those who actually need to read the
863 generated assembly code (perhaps while debugging the compiler itself).
864 Currently, this switch is only used by dwarfout.c; however, it is intended
865 to be a catchall for printing debug information in the assembler file. */
867 int flag_debug_asm = 0;
869 /* -dP causes the rtl to be emitted as a comment in assembly. */
871 int flag_dump_rtl_in_asm = 0;
873 /* -fgnu-linker specifies use of the GNU linker for initializations.
874 (Or, more generally, a linker that handles initializations.)
875 -fno-gnu-linker says that collect2 will be used. */
877 int flag_gnu_linker = 0;
879 int flag_gnu_linker = 1;
882 /* Nonzero means put zero initialized data in the bss section. */
883 int flag_zero_initialized_in_bss = 1;
888 /* Enable ssa conditional constant propagation. */
889 int flag_ssa_ccp = 0;
891 /* Enable ssa aggressive dead code elimination. */
892 int flag_ssa_dce = 0;
894 /* Tag all structures with __attribute__(packed). */
895 int flag_pack_struct = 0;
897 /* Emit code to check for stack overflow; also may cause large objects
898 to be allocated dynamically. */
899 int flag_stack_check;
901 /* When non-NULL, indicates that whenever space is allocated on the
902 stack, the resulting stack pointer must not pass this
903 address---that is, for stacks that grow downward, the stack pointer
904 must always be greater than or equal to this address; for stacks
905 that grow upward, the stack pointer must be less than this address.
906 At present, the rtx may be either a REG or a SYMBOL_REF, although
907 the support provided depends on the backend. */
910 /* 0 if pointer arguments may alias each other. True in C.
911 1 if pointer arguments may not alias each other but may alias
913 2 if pointer arguments may not alias each other and may not
914 alias global variables. True in Fortran.
915 This defaults to 0 for C. */
916 int flag_argument_noalias = 0;
918 /* Nonzero if we should do (language-dependent) alias analysis.
919 Typically, this analysis will assume that expressions of certain
920 types do not alias expressions of certain other types. Only used
921 if alias analysis (in general) is enabled. */
922 int flag_strict_aliasing = 0;
924 /* Instrument functions with calls at entry and exit, for profiling. */
925 int flag_instrument_function_entry_exit = 0;
927 /* Nonzero means ignore `#ident' directives. 0 means handle them.
928 On SVR4 targets, it also controls whether or not to emit a
929 string identifying the compiler. */
931 int flag_no_ident = 0;
933 /* This will perform a peephole pass before sched2. */
934 int flag_peephole2 = 0;
936 /* This will try to guess branch probabilities. */
937 int flag_guess_branch_prob = 0;
939 /* -fcheck-bounds causes gcc to generate array bounds checks.
940 For C, C++, ObjC: defaults to off.
941 For Java: defaults to on.
942 For Fortran: defaults to off. */
943 int flag_bounds_check = 0;
945 /* This will attempt to merge constant section constants, if 1 only
946 string constants and constants from constant pool, if 2 also constant
948 int flag_merge_constants = 1;
950 /* If one, renumber instruction UIDs to reduce the number of
951 unused UIDs if there are a lot of instructions. If greater than
952 one, unconditionally renumber instruction UIDs. */
953 int flag_renumber_insns = 1;
955 /* If nonzero, use the graph coloring register allocator. */
956 int flag_new_regalloc = 0;
958 /* Nonzero if we perform superblock formation. */
962 /* Nonzero if we perform whole unit at a time compilation. */
964 int flag_unit_at_a_time = 0;
966 /* Values of the -falign-* flags: how much to align labels in code.
967 0 means `use default', 1 means `don't align'.
968 For each variable, there is an _log variant which is the power
969 of two not less than the variable, for .align output. */
973 int align_loops_max_skip;
976 int align_jumps_max_skip;
978 int align_labels_log;
979 int align_labels_max_skip;
981 int align_functions_log;
983 /* Like align_functions_log above, but used by front-ends to force the
984 minimum function alignment. Zero means no alignment is forced. */
985 int force_align_functions_log;
987 /* Table of supported debugging formats. */
990 const char *const arg;
991 /* Since PREFERRED_DEBUGGING_TYPE isn't necessarily a
992 constant expression, we use NO_DEBUG in its place. */
993 const enum debug_info_type debug_type;
994 const int use_extensions_p;
995 const char *const description;
999 { "", NO_DEBUG, DEFAULT_GDB_EXTENSIONS,
1000 N_("Generate debugging info in default format") },
1001 { "gdb", NO_DEBUG, 1, N_("Generate debugging info in default extended format") },
1002 #ifdef DBX_DEBUGGING_INFO
1003 { "stabs", DBX_DEBUG, 0, N_("Generate STABS format debug info") },
1004 { "stabs+", DBX_DEBUG, 1, N_("Generate extended STABS format debug info") },
1006 #ifdef DWARF_DEBUGGING_INFO
1007 { "dwarf", DWARF_DEBUG, 0, N_("Generate DWARF-1 format debug info") },
1008 { "dwarf+", DWARF_DEBUG, 1,
1009 N_("Generate extended DWARF-1 format debug info") },
1011 #ifdef DWARF2_DEBUGGING_INFO
1012 { "dwarf-2", DWARF2_DEBUG, 0, N_("Generate DWARF-2 debug info") },
1014 #ifdef XCOFF_DEBUGGING_INFO
1015 { "xcoff", XCOFF_DEBUG, 0, N_("Generate XCOFF format debug info") },
1016 { "xcoff+", XCOFF_DEBUG, 1, N_("Generate extended XCOFF format debug info") },
1018 #ifdef SDB_DEBUGGING_INFO
1019 { "coff", SDB_DEBUG, 0, N_("Generate COFF format debug info") },
1021 #ifdef VMS_DEBUGGING_INFO
1022 { "vms", VMS_DEBUG, 0, N_("Generate VMS format debug info") },
1029 const char *const string;
1030 int *const variable;
1033 lang_independent_options;
1035 /* Nonzero if signed arithmetic overflow should trap. */
1038 /* Nonzero if signed arithmetic overflow should wrap around. */
1041 /* Add or remove a leading underscore from user symbols. */
1042 int flag_leading_underscore = -1;
1044 /* The user symbol prefix after having resolved same. */
1045 const char *user_label_prefix;
1047 static const param_info lang_independent_params[] = {
1048 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT) \
1049 { OPTION, DEFAULT, HELP },
1050 #include "params.def"
1055 /* Table of language-independent -f options.
1056 STRING is the option name. VARIABLE is the address of the variable.
1057 ON_VALUE is the value to store in VARIABLE
1058 if `-fSTRING' is seen as an option.
1059 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
1061 static const lang_independent_options f_options[] =
1063 {"eliminate-dwarf2-dups", &flag_eliminate_dwarf2_dups, 1 },
1064 {"eliminate-unused-debug-symbols", &flag_debug_only_used_symbols, 1 },
1065 {"eliminate-unused-debug-types", &flag_eliminate_unused_debug_types, 1 },
1066 {"float-store", &flag_float_store, 1 },
1067 {"defer-pop", &flag_defer_pop, 1 },
1068 {"omit-frame-pointer", &flag_omit_frame_pointer, 1 },
1069 {"optimize-sibling-calls", &flag_optimize_sibling_calls, 1 },
1070 {"tracer", &flag_tracer, 1 },
1071 {"unit-at-a-time", &flag_unit_at_a_time, 1 },
1072 {"cse-follow-jumps", &flag_cse_follow_jumps, 1 },
1073 {"cse-skip-blocks", &flag_cse_skip_blocks, 1 },
1074 {"expensive-optimizations", &flag_expensive_optimizations, 1 },
1075 {"thread-jumps", &flag_thread_jumps, 1 },
1076 {"strength-reduce", &flag_strength_reduce, 1 },
1077 {"unroll-loops", &flag_unroll_loops, 1 },
1078 {"unroll-all-loops", &flag_unroll_all_loops, 1 },
1079 {"old-unroll-loops", &flag_old_unroll_loops, 1 },
1080 {"old-unroll-all-loops", &flag_old_unroll_all_loops, 1 },
1081 {"peel-loops", &flag_peel_loops, 1 },
1082 {"unswitch-loops", &flag_unswitch_loops, 1 },
1083 {"prefetch-loop-arrays", &flag_prefetch_loop_arrays, 1 },
1084 {"move-all-movables", &flag_move_all_movables, 1 },
1085 {"reduce-all-givs", &flag_reduce_all_givs, 1 },
1086 {"writable-strings", &flag_writable_strings, 1 },
1087 {"peephole", &flag_no_peephole, 0 },
1088 {"force-mem", &flag_force_mem, 1 },
1089 {"force-addr", &flag_force_addr, 1 },
1090 {"function-cse", &flag_no_function_cse, 0 },
1091 {"inline-functions", &flag_inline_functions, 1 },
1092 {"keep-inline-functions", &flag_keep_inline_functions, 1 },
1093 {"inline", &flag_no_inline, 0 },
1094 {"keep-static-consts", &flag_keep_static_consts, 1 },
1095 {"syntax-only", &flag_syntax_only, 1 },
1096 {"shared-data", &flag_shared_data, 1 },
1097 {"caller-saves", &flag_caller_saves, 1 },
1098 {"pcc-struct-return", &flag_pcc_struct_return, 1 },
1099 {"reg-struct-return", &flag_pcc_struct_return, 0 },
1100 {"delayed-branch", &flag_delayed_branch, 1 },
1101 {"gcse", &flag_gcse, 1 },
1102 {"gcse-lm", &flag_gcse_lm, 1 },
1103 {"gcse-sm", &flag_gcse_sm, 1 },
1104 {"branch-target-load-optimize", &flag_branch_target_load_optimize, 1 },
1105 {"branch-target-load-optimize2", &flag_branch_target_load_optimize2, 1 },
1106 {"loop-optimize", &flag_loop_optimize, 1 },
1107 {"crossjumping", &flag_crossjumping, 1 },
1108 {"if-conversion", &flag_if_conversion, 1 },
1109 {"if-conversion2", &flag_if_conversion2, 1 },
1110 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1 },
1111 {"rerun-loop-opt", &flag_rerun_loop_opt, 1 },
1112 {"delete-null-pointer-checks", &flag_delete_null_pointer_checks, 1 },
1113 {"schedule-insns", &flag_schedule_insns, 1 },
1114 {"schedule-insns2", &flag_schedule_insns_after_reload, 1 },
1115 {"sched-interblock",&flag_schedule_interblock, 1 },
1116 {"sched-spec",&flag_schedule_speculative, 1 },
1117 {"sched-spec-load",&flag_schedule_speculative_load, 1 },
1118 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1 },
1119 {"sched2-use-superblocks", &flag_sched2_use_superblocks, 1 },
1120 {"sched2-use-traces", &flag_sched2_use_traces, 1 },
1121 {"branch-count-reg",&flag_branch_on_count_reg, 1 },
1122 {"pic", &flag_pic, 1 },
1123 {"PIC", &flag_pic, 2 },
1124 {"pie", &flag_pie, 1 },
1125 {"PIE", &flag_pie, 2 },
1126 {"exceptions", &flag_exceptions, 1 },
1127 {"unwind-tables", &flag_unwind_tables, 1 },
1128 {"asynchronous-unwind-tables", &flag_asynchronous_unwind_tables, 1 },
1129 {"non-call-exceptions", &flag_non_call_exceptions, 1 },
1130 {"profile-arcs", &profile_arc_flag, 1 },
1131 {"test-coverage", &flag_test_coverage, 1 },
1132 {"branch-probabilities", &flag_branch_probabilities, 1 },
1133 {"profile", &profile_flag, 1 },
1134 {"reorder-blocks", &flag_reorder_blocks, 1 },
1135 {"reorder-functions", &flag_reorder_functions, 1 },
1136 {"rename-registers", &flag_rename_registers, 1 },
1137 {"cprop-registers", &flag_cprop_registers, 1 },
1138 {"common", &flag_no_common, 0 },
1139 {"inhibit-size-directive", &flag_inhibit_size_directive, 1 },
1140 {"function-sections", &flag_function_sections, 1 },
1141 {"data-sections", &flag_data_sections, 1 },
1142 {"verbose-asm", &flag_verbose_asm, 1 },
1143 {"gnu-linker", &flag_gnu_linker, 1 },
1144 {"regmove", &flag_regmove, 1 },
1145 {"optimize-register-move", &flag_regmove, 1 },
1146 {"pack-struct", &flag_pack_struct, 1 },
1147 {"stack-check", &flag_stack_check, 1 },
1148 {"argument-alias", &flag_argument_noalias, 0 },
1149 {"argument-noalias", &flag_argument_noalias, 1 },
1150 {"argument-noalias-global", &flag_argument_noalias, 2 },
1151 {"strict-aliasing", &flag_strict_aliasing, 1 },
1152 {"align-loops", &align_loops, 0 },
1153 {"align-jumps", &align_jumps, 0 },
1154 {"align-labels", &align_labels, 0 },
1155 {"align-functions", &align_functions, 0 },
1156 {"merge-constants", &flag_merge_constants, 1 },
1157 {"merge-all-constants", &flag_merge_constants, 2 },
1158 {"dump-unnumbered", &flag_dump_unnumbered, 1 },
1159 {"instrument-functions", &flag_instrument_function_entry_exit, 1 },
1160 {"zero-initialized-in-bss", &flag_zero_initialized_in_bss, 1 },
1161 {"ssa", &flag_ssa, 1 },
1162 {"ssa-ccp", &flag_ssa_ccp, 1 },
1163 {"ssa-dce", &flag_ssa_dce, 1 },
1164 {"leading-underscore", &flag_leading_underscore, 1 },
1165 {"ident", &flag_no_ident, 0 },
1166 { "peephole2", &flag_peephole2, 1 },
1167 {"finite-math-only", &flag_finite_math_only, 1 },
1168 { "guess-branch-probability", &flag_guess_branch_prob, 1 },
1169 {"math-errno", &flag_errno_math, 1 },
1170 {"trapping-math", &flag_trapping_math, 1 },
1171 {"unsafe-math-optimizations", &flag_unsafe_math_optimizations, 1 },
1172 {"signaling-nans", &flag_signaling_nans, 1 },
1173 {"bounds-check", &flag_bounds_check, 1 },
1174 {"single-precision-constant", &flag_single_precision_constant, 1 },
1175 {"time-report", &time_report, 1 },
1176 {"mem-report", &mem_report, 1 },
1177 { "trapv", &flag_trapv, 1 },
1178 { "wrapv", &flag_wrapv, 1 },
1179 { "new-ra", &flag_new_regalloc, 1 }
1182 /* Table of language-specific options. */
1184 static const struct lang_opt
1186 const char *const option;
1187 const char *const description;
1189 documented_lang_options[] =
1191 /* In order not to overload the --help output, the convention
1192 used here is to only describe those options which are not
1193 enabled by default. */
1196 N_("Compile just for ISO C90") },
1198 N_("Determine language standard") },
1200 { "-fsigned-bitfields", "" },
1201 { "-funsigned-bitfields",
1202 N_("Make bit-fields by unsigned by default") },
1203 { "-fno-signed-bitfields", "" },
1204 { "-fno-unsigned-bitfields","" },
1206 N_("Make 'char' be signed by default") },
1207 { "-funsigned-char",
1208 N_("Make 'char' be unsigned by default") },
1209 { "-fno-signed-char", "" },
1210 { "-fno-unsigned-char", "" },
1214 N_("Do not recognize the 'asm' keyword") },
1215 { "-fbuiltin", "" },
1217 N_("Do not recognize any built in functions") },
1219 N_("Assume normal C execution environment") },
1220 { "-fno-hosted", "" },
1222 N_("Assume that standard libraries & main might not exist") },
1223 { "-fno-freestanding", "" },
1224 { "-fcond-mismatch",
1225 N_("Allow different types as args of ? operator") },
1226 { "-fno-cond-mismatch", "" },
1227 { "-fdollars-in-identifiers",
1228 N_("Allow the use of $ inside identifiers") },
1229 { "-fno-dollars-in-identifiers", "" },
1230 { "-fpreprocessed", "" },
1231 { "-fno-preprocessed", "" },
1233 N_("Use the same size for double as for float") },
1234 { "-fno-short-double", "" },
1236 N_("Use the smallest fitting integer to hold enums") },
1237 { "-fno-short-enums", "" },
1239 N_("Override the underlying type for wchar_t to `unsigned short'") },
1240 { "-fno-short-wchar", "" },
1243 N_("Enable most warning messages") },
1244 { "-Wbad-function-cast",
1245 N_("Warn about casting functions to incompatible types") },
1246 { "-Wno-bad-function-cast", "" },
1247 { "-Wmissing-format-attribute",
1248 N_("Warn about functions which might be candidates for format attributes") },
1249 { "-Wno-missing-format-attribute", "" },
1251 N_("Warn about casts which discard qualifiers") },
1252 { "-Wno-cast-qual", "" },
1253 { "-Wchar-subscripts",
1254 N_("Warn about subscripts whose type is 'char'") },
1255 { "-Wno-char-subscripts", "" },
1257 N_("Warn if nested comments are detected") },
1258 { "-Wno-comment", "" },
1260 N_("Warn if nested comments are detected") },
1261 { "-Wno-comments", "" },
1263 N_("Warn about possibly confusing type conversions") },
1264 { "-Wno-conversion", "" },
1265 { "-Wdiv-by-zero", "" },
1266 { "-Wno-div-by-zero",
1267 N_("Do not warn about compile-time integer division by zero") },
1269 N_("Warn about testing equality of floating point numbers") },
1270 { "-Wno-float-equal", "" },
1272 N_("Warn about printf/scanf/strftime/strfmon format anomalies") },
1273 { "-Wno-format", "" },
1274 { "-Wformat-extra-args", "" },
1275 { "-Wno-format-extra-args",
1276 N_("Don't warn about too many arguments to format functions") },
1277 { "-Wformat-nonliteral",
1278 N_("Warn about non-string-literal format strings") },
1279 { "-Wno-format-nonliteral", "" },
1280 { "-Wformat-security",
1281 N_("Warn about possible security problems with format functions") },
1282 { "-Wno-format-security", "" },
1283 { "-Wformat-y2k", "" },
1284 { "-Wno-format-y2k",
1285 N_("Don't warn about strftime formats yielding 2 digit years") },
1286 { "-Wimplicit-function-declaration",
1287 N_("Warn about implicit function declarations") },
1288 { "-Wno-implicit-function-declaration", "" },
1289 { "-Werror-implicit-function-declaration", "" },
1291 N_("Warn when a declaration does not specify a type") },
1292 { "-Wno-implicit-int", "" },
1293 { "-Wimplicit", "" },
1294 { "-Wno-implicit", "" },
1296 N_("Warn about the use of the #import directive") },
1297 { "-Wno-import", "" },
1299 N_("Warn about PCH files that are found but not used") },
1300 { "-Wlong-long","" },
1302 N_("Do not warn about using 'long long' when -pedantic") },
1304 N_("Warn about suspicious declarations of main") },
1305 { "-Wno-main", "" },
1306 { "-Wmissing-braces",
1307 N_("Warn about possibly missing braces around initializers") },
1308 { "-Wno-missing-braces", "" },
1309 { "-Wmissing-declarations",
1310 N_("Warn about global funcs without previous declarations") },
1311 { "-Wno-missing-declarations", "" },
1312 { "-Wmissing-prototypes",
1313 N_("Warn about global funcs without prototypes") },
1314 { "-Wno-missing-prototypes", "" },
1316 N_("Warn about use of multicharacter literals") },
1317 { "-Wno-multichar", "" },
1318 { "-Wnested-externs",
1319 N_("Warn about externs not at file scope level") },
1320 { "-Wno-nested-externs", "" },
1322 N_("Warn about possible missing parentheses") },
1323 { "-Wno-parentheses", "" },
1324 { "-Wpointer-arith",
1325 N_("Warn about function pointer arithmetic") },
1326 { "-Wno-pointer-arith", "" },
1327 { "-Wredundant-decls",
1328 N_("Warn about multiple declarations of the same object") },
1329 { "-Wno-redundant-decls", "" },
1331 N_("Warn whenever a function's return-type defaults to int") },
1332 { "-Wno-return-type", "" },
1333 { "-Wsequence-point",
1334 N_("Warn about possible violations of sequence point rules") },
1335 { "-Wno-sequence-point", "" },
1337 N_("Warn about signed/unsigned comparisons") },
1338 { "-Wno-sign-compare", "" },
1339 { "-Wstrict-prototypes",
1340 N_("Warn about non-prototyped function decls") },
1341 { "-Wno-strict-prototypes", "" },
1343 N_("Warn about constructs whose meanings change in ISO C") },
1344 { "-Wno-traditional", "" },
1346 N_("Warn when trigraphs are encountered") },
1347 { "-Wno-trigraphs", "" },
1349 { "-Wno-undef", "" },
1350 { "-Wunknown-pragmas",
1351 N_("Warn about unrecognized pragmas") },
1352 { "-Wno-unknown-pragmas", "" },
1353 { "-Wwrite-strings",
1354 N_("Mark strings as 'const char *'") },
1355 { "-Wno-write-strings", "" },
1357 #define DEFINE_LANG_NAME(NAME) { NULL, NAME },
1359 #include "options_.h"
1363 /* Here is a table, controlled by the tm.h file, listing each -m switch
1364 and which bits in `target_switches' it should set or clear.
1365 If VALUE is positive, it is bits to set.
1366 If VALUE is negative, -VALUE is bits to clear.
1367 (The sign bit is not used so there is no confusion.) */
1371 const char *const name;
1373 const char *const description;
1375 target_switches[] = TARGET_SWITCHES;
1377 /* This table is similar, but allows the switch to have a value. */
1379 #ifdef TARGET_OPTIONS
1382 const char *const prefix;
1383 const char **const variable;
1384 const char *const description;
1385 const char *const value;
1387 target_options[] = TARGET_OPTIONS;
1390 /* Nonzero means warn about function definitions that default the return type
1391 or that use a null return and have a return-type other than void. */
1393 int warn_return_type;
1395 /* Output files for assembler code (real compiler output)
1396 and debugging dumps. */
1399 FILE *aux_info_file;
1400 FILE *rtl_dump_file = NULL;
1401 FILE *cgraph_dump_file = NULL;
1403 /* Set up a default flag_random_seed and local_tick, unless the user
1404 already specified one. */
1409 if (!flag_random_seed)
1411 unsigned HOST_WIDE_INT value;
1412 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
1414 /* Get some more or less random data. */
1415 #ifdef HAVE_GETTIMEOFDAY
1419 gettimeofday (&tv, NULL);
1420 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
1424 time_t now = time (NULL);
1426 if (now != (time_t)-1)
1427 local_tick = (unsigned) now;
1430 value = local_tick ^ getpid ();
1432 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
1433 flag_random_seed = random_seed;
1435 else if (!local_tick)
1440 /* Decode the string P as an integral parameter.
1441 If the string is indeed an integer return its numeric value else
1442 issue an Invalid Option error for the option PNAME and return DEFVAL.
1443 If PNAME is zero just return DEFVAL, do not call error. */
1446 read_integral_parameter (const char *p, const char *pname, const int defval)
1448 const char *endp = p;
1452 if (ISDIGIT (*endp))
1461 error ("invalid option argument `%s'", pname);
1468 /* Return the logarithm of X, base 2, considering X unsigned,
1469 if X is a power of 2. Otherwise, returns -1.
1471 This should be used via the `exact_log2' macro. */
1474 exact_log2_wide (unsigned HOST_WIDE_INT x)
1477 /* Test for 0 or a power of 2. */
1478 if (x == 0 || x != (x & -x))
1480 while ((x >>= 1) != 0)
1485 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1486 If X is 0, return -1.
1488 This should be used via the floor_log2 macro. */
1491 floor_log2_wide (unsigned HOST_WIDE_INT x)
1500 /* Handler for fatal signals, such as SIGSEGV. These are transformed
1501 into ICE messages, which is much more user friendly. In case the
1502 error printer crashes, reset the signal to prevent infinite recursion. */
1505 crash_signal (int signo)
1507 signal (signo, SIG_DFL);
1508 internal_error ("%s", strsignal (signo));
1511 /* Arrange to dump core on error. (The regular error message is still
1512 printed first, except in the case of abort().) */
1515 setup_core_dumping (void)
1518 signal (SIGABRT, SIG_DFL);
1520 #if defined(HAVE_SETRLIMIT)
1523 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
1524 fatal_error ("getting core file size maximum limit: %m");
1525 rlim.rlim_cur = rlim.rlim_max;
1526 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
1527 fatal_error ("setting core file size limit to maximum: %m");
1530 diagnostic_abort_on_error (global_dc);
1534 /* Strip off a legitimate source ending from the input string NAME of
1535 length LEN. Rather than having to know the names used by all of
1536 our front ends, we strip off an ending of a period followed by
1537 up to five characters. (Java uses ".class".) */
1540 strip_off_ending (char *name, int len)
1543 for (i = 2; i < 6 && len > i; i++)
1545 if (name[len - i] == '.')
1547 name[len - i] = '\0';
1553 /* Output a quoted string. */
1556 output_quoted_string (FILE *asm_file, const char *string)
1558 #ifdef OUTPUT_QUOTED_STRING
1559 OUTPUT_QUOTED_STRING (asm_file, string);
1563 putc ('\"', asm_file);
1564 while ((c = *string++) != 0)
1568 if (c == '\"' || c == '\\')
1569 putc ('\\', asm_file);
1573 fprintf (asm_file, "\\%03o", (unsigned char) c);
1575 putc ('\"', asm_file);
1579 /* Output a file name in the form wanted by System V. */
1582 output_file_directive (FILE *asm_file, const char *input_name)
1584 int len = strlen (input_name);
1585 const char *na = input_name + len;
1587 /* NA gets INPUT_NAME sans directory names. */
1588 while (na > input_name)
1590 if (IS_DIR_SEPARATOR (na[-1]))
1595 #ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
1596 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
1598 #ifdef ASM_OUTPUT_SOURCE_FILENAME
1599 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
1601 fprintf (asm_file, "\t.file\t");
1602 output_quoted_string (asm_file, na);
1603 fputc ('\n', asm_file);
1608 /* Routine to open a dump file. Return true if the dump file is enabled. */
1611 open_dump_file (enum dump_file_index index, tree decl)
1614 const char *open_arg;
1617 if (! dump_file[index].enabled)
1620 timevar_push (TV_DUMP);
1621 if (rtl_dump_file != NULL)
1622 fclose (rtl_dump_file);
1624 sprintf (seq, DUMPFILE_FORMAT, index);
1626 if (! dump_file[index].initialized)
1628 /* If we've not initialized the files, do so now. */
1629 if (graph_dump_format != no_graph
1630 && dump_file[index].graph_dump_p)
1632 dump_name = concat (seq, dump_file[index].extension, NULL);
1633 clean_graph_dump_file (dump_base_name, dump_name);
1636 dump_file[index].initialized = 1;
1642 dump_name = concat (dump_base_name, seq,
1643 dump_file[index].extension, NULL);
1645 rtl_dump_file = fopen (dump_name, open_arg);
1646 if (rtl_dump_file == NULL)
1647 fatal_error ("can't open %s: %m", dump_name);
1652 fprintf (rtl_dump_file, "\n;; Function %s%s\n\n",
1653 (*lang_hooks.decl_printable_name) (decl, 2),
1654 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
1656 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
1657 ? " (unlikely executed)"
1660 timevar_pop (TV_DUMP);
1664 /* Routine to close a dump file. */
1667 close_dump_file (enum dump_file_index index,
1668 void (*func) (FILE *, rtx),
1671 if (! rtl_dump_file)
1674 timevar_push (TV_DUMP);
1676 && graph_dump_format != no_graph
1677 && dump_file[index].graph_dump_p)
1682 sprintf (seq, DUMPFILE_FORMAT, index);
1683 suffix = concat (seq, dump_file[index].extension, NULL);
1684 print_rtl_graph_with_bb (dump_base_name, suffix, insns);
1689 func (rtl_dump_file, insns);
1691 fflush (rtl_dump_file);
1692 fclose (rtl_dump_file);
1694 rtl_dump_file = NULL;
1695 timevar_pop (TV_DUMP);
1698 /* Do any final processing required for the declarations in VEC, of
1699 which there are LEN. We write out inline functions and variables
1700 that have been deferred until this point, but which are required.
1701 Returns nonzero if anything was put out. */
1704 wrapup_global_declarations (tree *vec, int len)
1709 int output_something = 0;
1711 for (i = 0; i < len; i++)
1715 /* We're not deferring this any longer. Assignment is
1716 conditional to avoid needlessly dirtying PCH pages. */
1717 if (DECL_DEFER_OUTPUT (decl) != 0)
1718 DECL_DEFER_OUTPUT (decl) = 0;
1720 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
1721 (*lang_hooks.finish_incomplete_decl) (decl);
1724 /* Now emit any global variables or functions that we have been
1725 putting off. We need to loop in case one of the things emitted
1726 here references another one which comes earlier in the list. */
1730 for (i = 0; i < len; i++)
1734 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
1737 /* Don't write out static consts, unless we still need them.
1739 We also keep static consts if not optimizing (for debugging),
1740 unless the user specified -fno-keep-static-consts.
1741 ??? They might be better written into the debug information.
1742 This is possible when using DWARF.
1744 A language processor that wants static constants to be always
1745 written out (even if it is not used) is responsible for
1746 calling rest_of_decl_compilation itself. E.g. the C front-end
1747 calls rest_of_decl_compilation from finish_decl.
1748 One motivation for this is that is conventional in some
1749 environments to write things like:
1750 static const char rcsid[] = "... version string ...";
1751 intending to force the string to be in the executable.
1753 A language processor that would prefer to have unneeded
1754 static constants "optimized away" would just defer writing
1755 them out until here. E.g. C++ does this, because static
1756 constants are often defined in header files.
1758 ??? A tempting alternative (for both C and C++) would be
1759 to force a constant to be written if and only if it is
1760 defined in a main file, as opposed to an include file. */
1762 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
1766 if (flag_unit_at_a_time
1767 && cgraph_varpool_node (decl)->finalized)
1769 else if (flag_unit_at_a_time
1770 && (TREE_USED (decl)
1771 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
1773 else if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1775 else if (DECL_COMDAT (decl))
1777 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
1778 && (optimize || !flag_keep_static_consts
1779 || DECL_ARTIFICIAL (decl)))
1785 rest_of_decl_compilation (decl, NULL, 1, 1);
1789 if (TREE_CODE (decl) == FUNCTION_DECL
1790 && DECL_INITIAL (decl) != 0
1791 && DECL_SAVED_INSNS (decl) != 0
1792 && (flag_keep_inline_functions
1793 || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
1794 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
1797 output_inline_function (decl);
1802 output_something = 1;
1806 return output_something;
1809 /* Issue appropriate warnings for the global declarations in VEC (of
1810 which there are LEN). Output debugging information for them. */
1813 check_global_declarations (tree *vec, int len)
1818 for (i = 0; i < len; i++)
1822 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
1823 && ! TREE_ASM_WRITTEN (decl))
1824 /* Cancel the RTL for this decl so that, if debugging info
1825 output for global variables is still to come,
1826 this one will be omitted. */
1827 SET_DECL_RTL (decl, NULL_RTX);
1829 /* Warn about any function
1830 declared static but not defined.
1831 We don't warn about variables,
1832 because many programs have static variables
1833 that exist only to get some text into the object file. */
1834 if (TREE_CODE (decl) == FUNCTION_DECL
1835 && (warn_unused_function
1836 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1837 && DECL_INITIAL (decl) == 0
1838 && DECL_EXTERNAL (decl)
1839 && ! DECL_ARTIFICIAL (decl)
1840 && ! TREE_PUBLIC (decl))
1842 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1843 pedwarn_with_decl (decl,
1844 "`%s' used but never defined");
1846 warning_with_decl (decl,
1847 "`%s' declared `static' but never defined");
1848 /* This symbol is effectively an "extern" declaration now. */
1849 TREE_PUBLIC (decl) = 1;
1850 assemble_external (decl);
1853 /* Warn about static fns or vars defined but not used. */
1854 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
1855 || (warn_unused_variable && TREE_CODE (decl) == VAR_DECL))
1856 && ! TREE_USED (decl)
1857 /* The TREE_USED bit for file-scope decls is kept in the identifier,
1858 to handle multiple external decls in different scopes. */
1859 && ! TREE_USED (DECL_NAME (decl))
1860 && ! DECL_EXTERNAL (decl)
1861 && ! TREE_PUBLIC (decl)
1862 /* A volatile variable might be used in some non-obvious way. */
1863 && ! TREE_THIS_VOLATILE (decl)
1864 /* Global register variables must be declared to reserve them. */
1865 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
1866 /* Otherwise, ask the language. */
1867 && (*lang_hooks.decls.warn_unused_global) (decl))
1868 warning_with_decl (decl, "`%s' defined but not used");
1870 /* Avoid confusing the debug information machinery when there are
1872 if (errorcount == 0 && sorrycount == 0)
1874 timevar_push (TV_SYMOUT);
1875 (*debug_hooks->global_decl) (decl);
1876 timevar_pop (TV_SYMOUT);
1881 /* Save the current INPUT_LOCATION on the top entry in the
1882 INPUT_FILE_STACK. Push a new entry for FILE and LINE, and set the
1883 INPUT_LOCATION accordingly. */
1886 push_srcloc (const char *file, int line)
1888 struct file_stack *fs;
1890 fs = (struct file_stack *) xmalloc (sizeof (struct file_stack));
1891 fs->location = input_location;
1892 fs->next = input_file_stack;
1893 input_filename = file;
1895 input_file_stack = fs;
1896 input_file_stack_tick++;
1899 /* Pop the top entry off the stack of presently open source files.
1900 Restore the INPUT_LOCATION from the new topmost entry on the
1906 struct file_stack *fs;
1908 fs = input_file_stack;
1909 input_location = fs->location;
1910 input_file_stack = fs->next;
1912 input_file_stack_tick++;
1915 /* Compile an entire translation unit. Write a file of assembly
1916 output and various debugging dumps. */
1921 /* Initialize yet another pass. */
1923 init_final (main_input_filename);
1924 coverage_init (aux_base_name);
1926 timevar_push (TV_PARSE);
1928 /* Call the parser, which parses the entire file (calling
1929 rest_of_compilation for each function). */
1930 (*lang_hooks.parse_file) (set_yydebug);
1932 /* In case there were missing block closers,
1933 get us back to the global binding level. */
1934 (*lang_hooks.clear_binding_stack) ();
1936 /* Compilation is now finished except for writing
1937 what's left of the symbol table output. */
1938 timevar_pop (TV_PARSE);
1940 if (flag_syntax_only)
1943 (*lang_hooks.decls.final_write_globals)();
1945 cgraph_varpool_assemble_pending_decls ();
1947 /* This must occur after the loop to output deferred functions.
1948 Else the coverage initializer would not be emitted if all the
1949 functions in this compilation unit were deferred. */
1952 /* Write out any pending weak symbol declarations. */
1956 /* Do dbx symbols. */
1957 timevar_push (TV_SYMOUT);
1959 #ifdef DWARF2_UNWIND_INFO
1960 if (dwarf2out_do_frame ())
1961 dwarf2out_frame_finish ();
1964 (*debug_hooks->finish) (main_input_filename);
1965 timevar_pop (TV_SYMOUT);
1967 /* Output some stuff at end of file if nec. */
1969 dw2_output_indirect_constants ();
1971 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
1973 timevar_push (TV_DUMP);
1974 open_dump_file (DFI_bp, NULL);
1978 close_dump_file (DFI_bp, NULL, NULL_RTX);
1979 timevar_pop (TV_DUMP);
1982 targetm.asm_out.file_end ();
1984 /* Attach a special .ident directive to the end of the file to identify
1985 the version of GCC which compiled this code. The format of the .ident
1986 string is patterned after the ones produced by native SVR4 compilers. */
1989 fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
1990 IDENT_ASM_OP, version_string);
1993 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
1995 timevar_push (TV_DUMP);
1996 dump_combine_total_stats (rtl_dump_file);
1997 close_dump_file (DFI_combine, NULL, NULL_RTX);
1998 timevar_pop (TV_DUMP);
2002 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
2003 and TYPE_DECL nodes.
2005 This does nothing for local (non-static) variables, unless the
2006 variable is a register variable with an ASMSPEC. In that case, or
2007 if the variable is not an automatic, it sets up the RTL and
2008 outputs any assembler code (label definition, storage allocation
2009 and initialization).
2011 DECL is the declaration. If ASMSPEC is nonzero, it specifies
2012 the assembler symbol name to be used. TOP_LEVEL is nonzero
2013 if this declaration is not within a function. */
2016 rest_of_decl_compilation (tree decl,
2017 const char *asmspec,
2021 /* We deferred calling assemble_alias so that we could collect
2022 other attributes such as visibility. Emit the alias now. */
2025 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
2028 alias = TREE_VALUE (TREE_VALUE (alias));
2029 alias = get_identifier (TREE_STRING_POINTER (alias));
2030 assemble_alias (decl, alias);
2034 /* Forward declarations for nested functions are not "external",
2035 but we need to treat them as if they were. */
2036 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
2037 || TREE_CODE (decl) == FUNCTION_DECL)
2039 timevar_push (TV_VARCONST);
2042 make_decl_rtl (decl, asmspec);
2044 /* Don't output anything when a tentative file-scope definition
2045 is seen. But at end of compilation, do output code for them. */
2046 if (at_end || !DECL_DEFER_OUTPUT (decl))
2048 if (flag_unit_at_a_time && !cgraph_global_info_ready
2049 && TREE_CODE (decl) != FUNCTION_DECL && top_level)
2050 cgraph_varpool_finalize_decl (decl);
2052 assemble_variable (decl, top_level, at_end, 0);
2055 #ifdef ASM_FINISH_DECLARE_OBJECT
2056 if (decl == last_assemble_variable_decl)
2058 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
2063 timevar_pop (TV_VARCONST);
2065 else if (DECL_REGISTER (decl) && asmspec != 0)
2067 if (decode_reg_name (asmspec) >= 0)
2069 SET_DECL_RTL (decl, NULL_RTX);
2070 make_decl_rtl (decl, asmspec);
2074 error ("invalid register name `%s' for register variable", asmspec);
2075 DECL_REGISTER (decl) = 0;
2080 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2081 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2082 && TREE_CODE (decl) == TYPE_DECL)
2084 timevar_push (TV_SYMOUT);
2085 dbxout_symbol (decl, 0);
2086 timevar_pop (TV_SYMOUT);
2089 #ifdef SDB_DEBUGGING_INFO
2090 else if (write_symbols == SDB_DEBUG && top_level
2091 && TREE_CODE (decl) == TYPE_DECL)
2093 timevar_push (TV_SYMOUT);
2094 sdbout_symbol (decl, 0);
2095 timevar_pop (TV_SYMOUT);
2098 #ifdef DWARF2_DEBUGGING_INFO
2099 else if ((write_symbols == DWARF2_DEBUG
2100 || write_symbols == VMS_AND_DWARF2_DEBUG)
2102 && TREE_CODE (decl) == TYPE_DECL)
2104 timevar_push (TV_SYMOUT);
2105 dwarf2out_decl (decl);
2106 timevar_pop (TV_SYMOUT);
2111 /* Called after finishing a record, union or enumeral type. */
2114 rest_of_type_compilation (
2115 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) \
2116 || defined (SDB_DEBUGGING_INFO) || defined (DWARF2_DEBUGGING_INFO)
2120 tree type ATTRIBUTE_UNUSED,
2121 int toplev ATTRIBUTE_UNUSED
2125 /* Avoid confusing the debug information machinery when there are
2127 if (errorcount != 0 || sorrycount != 0)
2130 timevar_push (TV_SYMOUT);
2131 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2132 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2133 dbxout_symbol (TYPE_STUB_DECL (type), !toplev);
2135 #ifdef SDB_DEBUGGING_INFO
2136 if (write_symbols == SDB_DEBUG)
2137 sdbout_symbol (TYPE_STUB_DECL (type), !toplev);
2139 #ifdef DWARF2_DEBUGGING_INFO
2140 if ((write_symbols == DWARF2_DEBUG
2141 || write_symbols == VMS_AND_DWARF2_DEBUG)
2143 dwarf2out_decl (TYPE_STUB_DECL (type));
2145 timevar_pop (TV_SYMOUT);
2148 /* Turn the RTL into assembly. */
2150 rest_of_handle_final (tree decl, rtx insns)
2152 timevar_push (TV_FINAL);
2157 /* Get the function's name, as described by its RTL. This may be
2158 different from the DECL_NAME name used in the source file. */
2160 x = DECL_RTL (decl);
2161 if (GET_CODE (x) != MEM)
2164 if (GET_CODE (x) != SYMBOL_REF)
2166 fnname = XSTR (x, 0);
2168 assemble_start_function (decl, fnname);
2169 final_start_function (insns, asm_out_file, optimize);
2170 final (insns, asm_out_file, optimize, 0);
2171 final_end_function ();
2173 #ifdef IA64_UNWIND_INFO
2174 /* ??? The IA-64 ".handlerdata" directive must be issued before
2175 the ".endp" directive that closes the procedure descriptor. */
2176 output_function_exception_table ();
2179 assemble_end_function (decl, fnname);
2181 #ifndef IA64_UNWIND_INFO
2182 /* Otherwise, it feels unclean to switch sections in the middle. */
2183 output_function_exception_table ();
2187 fflush (asm_out_file);
2189 /* Release all memory allocated by flow. */
2190 free_basic_block_vars (0);
2192 /* Release all memory held by regsets now. */
2193 regset_release_memory ();
2195 timevar_pop (TV_FINAL);
2201 /* Run delay slot optimization. */
2203 rest_of_handle_delay_slots (tree decl, rtx insns)
2205 timevar_push (TV_DBR_SCHED);
2206 open_dump_file (DFI_dbr, decl);
2208 dbr_schedule (insns, rtl_dump_file);
2210 close_dump_file (DFI_dbr, print_rtl, insns);
2211 timevar_pop (TV_DBR_SCHED);
2218 /* Convert register usage from flat register file usage to a stack
2221 rest_of_handle_stack_regs (tree decl, rtx insns)
2223 timevar_push (TV_REG_STACK);
2224 open_dump_file (DFI_stack, decl);
2226 if (reg_to_stack (insns, rtl_dump_file) && optimize)
2228 if (cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
2229 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0))
2230 && flag_reorder_blocks)
2232 reorder_basic_blocks ();
2233 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
2237 close_dump_file (DFI_stack, print_rtl_with_bb, insns);
2238 timevar_pop (TV_REG_STACK);
2245 /* Machine independent reorg pass. */
2247 rest_of_handle_machine_reorg (tree decl, rtx insns)
2249 timevar_push (TV_MACH_DEP);
2250 open_dump_file (DFI_mach, decl);
2252 (*targetm.machine_dependent_reorg) ();
2254 close_dump_file (DFI_mach, print_rtl, insns);
2255 timevar_pop (TV_MACH_DEP);
2261 /* Run new register allocator. Return TRUE if we must exit
2262 rest_of_compilation upon return. */
2264 rest_of_handle_new_regalloc (tree decl, rtx insns, int *rebuild_notes)
2268 delete_trivially_dead_insns (insns, max_reg_num ());
2271 timevar_pop (TV_LOCAL_ALLOC);
2272 if (dump_file[DFI_lreg].enabled)
2274 timevar_push (TV_DUMP);
2276 close_dump_file (DFI_lreg, NULL, NULL);
2277 timevar_pop (TV_DUMP);
2280 /* XXX clean up the whole mess to bring live info in shape again. */
2281 timevar_push (TV_GLOBAL_ALLOC);
2282 open_dump_file (DFI_greg, decl);
2284 build_insn_chain (insns);
2285 failure = reload (insns, 0);
2287 timevar_pop (TV_GLOBAL_ALLOC);
2289 if (dump_file[DFI_greg].enabled)
2291 timevar_push (TV_DUMP);
2293 dump_global_regs (rtl_dump_file);
2295 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2296 timevar_pop (TV_DUMP);
2302 reload_completed = 1;
2308 /* Run old register allocator. Return TRUE if we must exit
2309 rest_of_compilation upon return. */
2311 rest_of_handle_old_regalloc (tree decl, rtx insns, int *rebuild_notes)
2315 /* Allocate the reg_renumber array. */
2316 allocate_reg_info (max_regno, FALSE, TRUE);
2318 /* And the reg_equiv_memory_loc array. */
2319 reg_equiv_memory_loc = (rtx *) xcalloc (max_regno, sizeof (rtx));
2321 allocate_initial_values (reg_equiv_memory_loc);
2323 regclass (insns, max_reg_num (), rtl_dump_file);
2324 *rebuild_notes = local_alloc ();
2326 timevar_pop (TV_LOCAL_ALLOC);
2328 if (dump_file[DFI_lreg].enabled)
2330 timevar_push (TV_DUMP);
2332 dump_flow_info (rtl_dump_file);
2333 dump_local_alloc (rtl_dump_file);
2335 close_dump_file (DFI_lreg, print_rtl_with_bb, insns);
2336 timevar_pop (TV_DUMP);
2341 timevar_push (TV_GLOBAL_ALLOC);
2342 open_dump_file (DFI_greg, decl);
2344 /* If optimizing, allocate remaining pseudo-regs. Do the reload
2345 pass fixing up any insns that are invalid. */
2348 failure = global_alloc (rtl_dump_file);
2351 build_insn_chain (insns);
2352 failure = reload (insns, 0);
2355 timevar_pop (TV_GLOBAL_ALLOC);
2357 if (dump_file[DFI_greg].enabled)
2359 timevar_push (TV_DUMP);
2361 dump_global_regs (rtl_dump_file);
2363 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2364 timevar_pop (TV_DUMP);
2370 /* Run the regrename and cprop passes. */
2372 rest_of_handle_regrename (tree decl, rtx insns)
2374 timevar_push (TV_RENAME_REGISTERS);
2375 open_dump_file (DFI_rnreg, decl);
2377 if (flag_rename_registers)
2378 regrename_optimize ();
2379 if (flag_cprop_registers)
2380 copyprop_hardreg_forward ();
2382 close_dump_file (DFI_rnreg, print_rtl_with_bb, insns);
2383 timevar_pop (TV_RENAME_REGISTERS);
2386 /* Reorder basic blocks. */
2388 rest_of_handle_reorder_blocks (tree decl, rtx insns)
2390 timevar_push (TV_REORDER_BLOCKS);
2391 open_dump_file (DFI_bbro, decl);
2393 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
2394 splitting possibly introduced more crossjumping opportunities. */
2395 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
2396 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
2398 if (flag_sched2_use_traces && flag_schedule_insns_after_reload)
2400 if (flag_reorder_blocks)
2401 reorder_basic_blocks ();
2402 if (flag_reorder_blocks
2403 || (flag_sched2_use_traces && flag_schedule_insns_after_reload))
2404 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2406 close_dump_file (DFI_bbro, print_rtl_with_bb, insns);
2407 timevar_pop (TV_REORDER_BLOCKS);
2410 #ifdef INSN_SCHEDULING
2411 /* Run instruction scheduler. */
2413 rest_of_handle_sched (tree decl, rtx insns)
2415 timevar_push (TV_SCHED);
2417 /* Print function header into sched dump now
2418 because doing the sched analysis makes some of the dump. */
2419 if (optimize > 0 && flag_schedule_insns)
2421 open_dump_file (DFI_sched, decl);
2423 /* Do control and data sched analysis,
2424 and write some of the results to dump file. */
2426 schedule_insns (rtl_dump_file);
2428 close_dump_file (DFI_sched, print_rtl_with_bb, insns);
2430 timevar_pop (TV_SCHED);
2435 /* Run second scheduling pass after reload. */
2437 rest_of_handle_sched2 (tree decl, rtx insns)
2439 timevar_push (TV_SCHED2);
2440 open_dump_file (DFI_sched2, decl);
2442 /* Do control and data sched analysis again,
2443 and write some more of the results to dump file. */
2445 split_all_insns (1);
2447 if (flag_sched2_use_superblocks || flag_sched2_use_traces)
2449 schedule_ebbs (rtl_dump_file);
2450 /* No liveness updating code yet, but it should be easy to do.
2451 reg-stack recompute the liveness when needed for now. */
2452 count_or_remove_death_notes (NULL, 1);
2453 cleanup_cfg (CLEANUP_EXPENSIVE);
2456 schedule_insns (rtl_dump_file);
2458 close_dump_file (DFI_sched2, print_rtl_with_bb, insns);
2459 timevar_pop (TV_SCHED2);
2465 /* Register allocation pre-pass, to reduce number of moves necessary
2466 for two-address machines. */
2468 rest_of_handle_regmove (tree decl, rtx insns)
2470 timevar_push (TV_REGMOVE);
2471 open_dump_file (DFI_regmove, decl);
2473 regmove_optimize (insns, max_reg_num (), rtl_dump_file);
2475 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2476 close_dump_file (DFI_regmove, print_rtl_with_bb, insns);
2477 timevar_pop (TV_REGMOVE);
2484 rest_of_handle_tracer (tree decl, rtx insns)
2486 timevar_push (TV_TRACER);
2487 open_dump_file (DFI_tracer, decl);
2489 dump_flow_info (rtl_dump_file);
2491 cleanup_cfg (CLEANUP_EXPENSIVE);
2492 reg_scan (insns, max_reg_num (), 0);
2493 close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ());
2494 timevar_pop (TV_TRACER);
2497 /* If-conversion and CFG cleanup. */
2499 rest_of_handle_if_conversion (tree decl, rtx insns)
2501 open_dump_file (DFI_ce1, decl);
2502 if (flag_if_conversion)
2504 timevar_push (TV_IFCVT);
2506 dump_flow_info (rtl_dump_file);
2507 cleanup_cfg (CLEANUP_EXPENSIVE);
2508 reg_scan (insns, max_reg_num (), 0);
2510 timevar_pop (TV_IFCVT);
2512 timevar_push (TV_JUMP);
2513 cleanup_cfg (CLEANUP_EXPENSIVE);
2514 reg_scan (insns, max_reg_num (), 0);
2515 timevar_pop (TV_JUMP);
2516 close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ());
2519 /* Rerun if-conversion, as combine may have simplified things enough
2520 to now meet sequence length restrictions. */
2522 rest_of_handle_if_after_combine (tree decl, rtx insns)
2524 timevar_push (TV_IFCVT);
2525 open_dump_file (DFI_ce2, decl);
2531 close_dump_file (DFI_ce2, print_rtl_with_bb, insns);
2532 timevar_pop (TV_IFCVT);
2535 /* Do branch profiling and static profile estimation passes. */
2537 rest_of_handle_branch_prob (tree decl, rtx insns)
2541 timevar_push (TV_BRANCH_PROB);
2542 open_dump_file (DFI_bp, decl);
2543 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
2546 /* Discover and record the loop depth at the head of each basic
2547 block. The loop infrastructure does the real job for us. */
2548 flow_loops_find (&loops, LOOP_TREE);
2551 flow_loops_dump (&loops, rtl_dump_file, NULL, 0);
2553 /* Estimate using heuristics if no profiling info is available. */
2554 if (flag_guess_branch_prob)
2555 estimate_probability (&loops);
2557 flow_loops_free (&loops);
2558 close_dump_file (DFI_bp, print_rtl_with_bb, insns);
2559 timevar_pop (TV_BRANCH_PROB);
2562 /* Do control and data flow analysis; write some of the results to the
2565 rest_of_handle_cfg (tree decl, rtx insns)
2567 open_dump_file (DFI_cfg, decl);
2569 dump_flow_info (rtl_dump_file);
2571 cleanup_cfg (CLEANUP_EXPENSIVE
2572 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2574 /* It may make more sense to mark constant functions after dead code is
2575 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
2576 may insert code making function non-constant, but we still must consider
2577 it as constant, otherwise -fbranch-probabilities will not read data back.
2579 life_analysis rarely eliminates modification of external memory.
2582 mark_constant_function ();
2584 close_dump_file (DFI_cfg, print_rtl_with_bb, insns);
2587 /* Purge addressofs. */
2589 rest_of_handle_addresof (tree decl, rtx insns)
2591 open_dump_file (DFI_addressof, decl);
2593 purge_addressof (insns);
2595 purge_all_dead_edges (0);
2596 reg_scan (insns, max_reg_num (), 1);
2598 close_dump_file (DFI_addressof, print_rtl, insns);
2601 /* We may have potential sibling or tail recursion sites. Select one
2602 (of possibly multiple) methods of performing the call. */
2604 rest_of_handle_sibling_calls (rtx insns)
2607 optimize_sibling_and_tail_recursive_calls ();
2609 /* Recompute the CFG as sibling optimization clobbers it randomly. */
2610 free_bb_for_insn ();
2611 find_exception_handler_labels ();
2612 rebuild_jump_labels (insns);
2613 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2615 /* There is pass ordering problem - we must lower NOTE_INSN_PREDICTION
2616 notes before simplifying cfg and we must do lowering after sibcall
2617 that unhides parts of RTL chain and cleans up the CFG.
2619 Until sibcall is replaced by tree-level optimizer, lets just
2620 sweep away the NOTE_INSN_PREDICTION notes that leaked out. */
2621 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2622 if (GET_CODE (insn) == NOTE
2623 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_PREDICTION)
2626 close_dump_file (DFI_sibling, print_rtl, get_insns ());
2629 /* Perform jump bypassing and control flow optimizations. */
2631 rest_of_handle_jump_bypass (tree decl, rtx insns)
2633 timevar_push (TV_BYPASS);
2634 open_dump_file (DFI_bypass, decl);
2636 cleanup_cfg (CLEANUP_EXPENSIVE);
2638 if (bypass_jumps (rtl_dump_file))
2640 rebuild_jump_labels (insns);
2641 cleanup_cfg (CLEANUP_EXPENSIVE);
2642 delete_trivially_dead_insns (insns, max_reg_num ());
2645 close_dump_file (DFI_bypass, print_rtl_with_bb, insns);
2646 timevar_pop (TV_BYPASS);
2650 #ifdef ENABLE_CHECKING
2651 verify_flow_info ();
2655 /* Handle inlining of functions in rest_of_compilation. Return TRUE
2656 if we must exit rest_of_compilation upon return. */
2658 rest_of_handle_inlining (tree decl)
2665 /* If we are reconsidering an inline function at the end of
2666 compilation, skip the stuff for making it inline. */
2667 if (DECL_SAVED_INSNS (decl) != 0)
2670 /* If this is nested inside an inlined external function, pretend
2671 it was only declared. Since we cannot inline such functions,
2672 generating code for this one is not only not necessary but will
2673 confuse some debugging output writers. */
2674 for (parent = DECL_CONTEXT (current_function_decl);
2675 parent != NULL_TREE;
2676 parent = get_containing_scope (parent))
2677 if (TREE_CODE (parent) == FUNCTION_DECL
2678 && DECL_INLINE (parent) && DECL_EXTERNAL (parent))
2680 DECL_INITIAL (decl) = 0;
2683 else if (TYPE_P (parent))
2684 /* A function in a local class should be treated normally. */
2687 /* If requested, consider whether to make this function inline. */
2688 if ((DECL_INLINE (decl) && !flag_no_inline)
2689 || flag_inline_functions)
2691 timevar_push (TV_INTEGRATION);
2692 lose = function_cannot_inline_p (decl);
2693 timevar_pop (TV_INTEGRATION);
2694 if (lose || ! optimize)
2696 if (warn_inline && DECL_INLINE (decl))
2697 warning_with_decl (decl, lose);
2698 DECL_ABSTRACT_ORIGIN (decl) = 0;
2699 /* Don't really compile an extern inline function.
2700 If we can't make it inline, pretend
2701 it was only declared. */
2702 if (DECL_EXTERNAL (decl))
2704 DECL_INITIAL (decl) = 0;
2709 /* ??? Note that we used to just make it look like if
2710 the "inline" keyword was specified when we decide
2711 to inline it (because of -finline-functions).
2712 garloff@suse.de, 2002-04-24: Add another flag to
2713 actually record this piece of information. */
2714 if (!DECL_INLINE (decl))
2715 DID_INLINE_FUNC (decl) = 1;
2716 inlinable = DECL_INLINE (decl) = 1;
2720 insns = get_insns ();
2722 /* Dump the rtl code if we are dumping rtl. */
2724 if (open_dump_file (DFI_rtl, decl))
2726 if (DECL_SAVED_INSNS (decl))
2727 fprintf (rtl_dump_file, ";; (integrable)\n\n");
2728 close_dump_file (DFI_rtl, print_rtl, insns);
2731 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
2732 sorts of eh initialization. Delay this until after the
2733 initial rtl dump so that we can see the original nesting. */
2734 convert_from_eh_region_ranges ();
2736 /* If function is inline, and we don't yet know whether to
2737 compile it by itself, defer decision till end of compilation.
2738 wrapup_global_declarations will (indirectly) call
2739 rest_of_compilation again for those functions that need to
2740 be output. Also defer those functions that we are supposed
2744 || (DECL_INLINE (decl)
2745 && flag_inline_functions
2746 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2747 && ! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
2748 && ! flag_keep_inline_functions)
2749 || DECL_EXTERNAL (decl))))
2750 DECL_DEFER_OUTPUT (decl) = 1;
2752 if (DECL_INLINE (decl))
2753 /* DWARF wants separate debugging info for abstract and
2754 concrete instances of all inline functions, including those
2755 declared inline but not inlined, and those inlined even
2756 though they weren't declared inline. Conveniently, that's
2757 what DECL_INLINE means at this point. */
2758 (*debug_hooks->deferred_inline_function) (decl);
2760 if (DECL_DEFER_OUTPUT (decl))
2762 /* If -Wreturn-type, we have to do a bit of compilation. We just
2763 want to call cleanup the cfg to figure out whether or not we can
2764 fall off the end of the function; we do the minimum amount of
2765 work necessary to make that safe. */
2766 if (warn_return_type)
2768 int saved_optimize = optimize;
2771 rebuild_jump_labels (insns);
2772 find_exception_handler_labels ();
2773 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2774 cleanup_cfg (CLEANUP_PRE_SIBCALL | CLEANUP_PRE_LOOP);
2775 optimize = saved_optimize;
2777 /* CFG is no longer maintained up-to-date. */
2778 free_bb_for_insn ();
2781 set_nothrow_function_flags ();
2782 if (current_function_nothrow)
2783 /* Now we know that this can't throw; set the flag for the benefit
2784 of other functions later in this translation unit. */
2785 TREE_NOTHROW (current_function_decl) = 1;
2787 timevar_push (TV_INTEGRATION);
2788 save_for_inline (decl);
2789 timevar_pop (TV_INTEGRATION);
2790 DECL_SAVED_INSNS (decl)->inlinable = inlinable;
2794 /* If specified extern inline but we aren't inlining it, we are
2795 done. This goes for anything that gets here with DECL_EXTERNAL
2796 set, not just things with DECL_INLINE. */
2797 return (bool) DECL_EXTERNAL (decl);
2800 /* Rest of compilation helper to convert the rtl to SSA form. */
2802 rest_of_handle_ssa (tree decl, rtx insns)
2804 timevar_push (TV_TO_SSA);
2805 open_dump_file (DFI_ssa, decl);
2807 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2810 close_dump_file (DFI_ssa, print_rtl_with_bb, insns);
2811 timevar_pop (TV_TO_SSA);
2813 /* Perform sparse conditional constant propagation, if requested. */
2816 timevar_push (TV_SSA_CCP);
2817 open_dump_file (DFI_ssa_ccp, decl);
2821 close_dump_file (DFI_ssa_ccp, print_rtl_with_bb, get_insns ());
2822 timevar_pop (TV_SSA_CCP);
2825 /* It would be useful to cleanup the CFG at this point, but block
2826 merging and possibly other transformations might leave a PHI
2827 node in the middle of a basic block, which is a strict no-no. */
2829 /* The SSA implementation uses basic block numbers in its phi
2830 nodes. Thus, changing the control-flow graph or the basic
2831 blocks, e.g., calling find_basic_blocks () or cleanup_cfg (),
2832 may cause problems. */
2836 /* Remove dead code. */
2838 timevar_push (TV_SSA_DCE);
2839 open_dump_file (DFI_ssa_dce, decl);
2841 insns = get_insns ();
2842 ssa_eliminate_dead_code ();
2844 close_dump_file (DFI_ssa_dce, print_rtl_with_bb, insns);
2845 timevar_pop (TV_SSA_DCE);
2848 /* Convert from SSA form. */
2850 timevar_push (TV_FROM_SSA);
2851 open_dump_file (DFI_ussa, decl);
2853 convert_from_ssa ();
2854 /* New registers have been created. Rescan their usage. */
2855 reg_scan (insns, max_reg_num (), 1);
2857 close_dump_file (DFI_ussa, print_rtl_with_bb, insns);
2858 timevar_pop (TV_FROM_SSA);
2865 /* Try to identify useless null pointer tests and delete them. */
2867 rest_of_handle_null_pointer (tree decl, rtx insns)
2869 open_dump_file (DFI_null, decl);
2871 dump_flow_info (rtl_dump_file);
2873 if (delete_null_pointer_checks (insns))
2874 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2876 close_dump_file (DFI_null, print_rtl_with_bb, insns);
2879 /* Try combining insns through substitution. */
2881 rest_of_handle_combine (tree decl, rtx insns)
2883 int rebuild_jump_labels_after_combine = 0;
2885 timevar_push (TV_COMBINE);
2886 open_dump_file (DFI_combine, decl);
2888 rebuild_jump_labels_after_combine
2889 = combine_instructions (insns, max_reg_num ());
2891 /* Combining insns may have turned an indirect jump into a
2892 direct jump. Rebuild the JUMP_LABEL fields of jumping
2894 if (rebuild_jump_labels_after_combine)
2896 timevar_push (TV_JUMP);
2897 rebuild_jump_labels (insns);
2898 timevar_pop (TV_JUMP);
2900 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2903 close_dump_file (DFI_combine, print_rtl_with_bb, insns);
2904 timevar_pop (TV_COMBINE);
2909 /* Perform life analysis. */
2911 rest_of_handle_life (tree decl, rtx insns)
2913 open_dump_file (DFI_life, decl);
2916 #ifdef ENABLE_CHECKING
2917 verify_flow_info ();
2919 life_analysis (insns, rtl_dump_file, PROP_FINAL);
2921 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_UPDATE_LIFE
2922 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2923 timevar_pop (TV_FLOW);
2925 if (warn_uninitialized)
2927 uninitialized_vars_warning (DECL_INITIAL (decl));
2929 setjmp_args_warning ();
2934 if (!flag_new_regalloc && initialize_uninitialized_subregs ())
2936 /* Insns were inserted, and possibly pseudos created, so
2937 things might look a bit different. */
2938 insns = get_insns ();
2939 allocate_reg_life_data ();
2940 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
2941 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
2947 close_dump_file (DFI_life, print_rtl_with_bb, insns);
2952 /* Perform common subexpression elimination. Nonzero value from
2953 `cse_main' means that jumps were simplified and some code may now
2954 be unreachable, so do jump optimization again. */
2956 rest_of_handle_cse (tree decl, rtx insns)
2960 open_dump_file (DFI_cse, decl);
2962 dump_flow_info (rtl_dump_file);
2963 timevar_push (TV_CSE);
2965 reg_scan (insns, max_reg_num (), 1);
2967 tem = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2969 rebuild_jump_labels (insns);
2970 purge_all_dead_edges (0);
2972 delete_trivially_dead_insns (insns, max_reg_num ());
2974 /* If we are not running more CSE passes, then we are no longer
2975 expecting CSE to be run. But always rerun it in a cheap mode. */
2976 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
2978 if (tem || optimize > 1)
2979 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2980 /* Try to identify useless null pointer tests and delete them. */
2981 if (flag_delete_null_pointer_checks)
2983 timevar_push (TV_JUMP);
2985 if (delete_null_pointer_checks (insns))
2986 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2987 timevar_pop (TV_JUMP);
2990 /* The second pass of jump optimization is likely to have
2991 removed a bunch more instructions. */
2992 renumber_insns (rtl_dump_file);
2994 timevar_pop (TV_CSE);
2995 close_dump_file (DFI_cse, print_rtl_with_bb, insns);
2998 /* Run second CSE pass after loop optimizations. */
3000 rest_of_handle_cse2 (tree decl, rtx insns)
3004 timevar_push (TV_CSE2);
3005 open_dump_file (DFI_cse2, decl);
3007 dump_flow_info (rtl_dump_file);
3008 /* CFG is no longer maintained up-to-date. */
3009 tem = cse_main (insns, max_reg_num (), 1, rtl_dump_file);
3010 purge_all_dead_edges (0);
3011 delete_trivially_dead_insns (insns, max_reg_num ());
3015 timevar_push (TV_JUMP);
3016 rebuild_jump_labels (insns);
3017 cleanup_cfg (CLEANUP_EXPENSIVE);
3018 timevar_pop (TV_JUMP);
3020 reg_scan (insns, max_reg_num (), 0);
3021 close_dump_file (DFI_cse2, print_rtl_with_bb, insns);
3023 timevar_pop (TV_CSE2);
3026 /* Perform global cse. */
3028 rest_of_handle_gcse (tree decl, rtx insns)
3030 int save_csb, save_cfj;
3033 timevar_push (TV_GCSE);
3034 open_dump_file (DFI_gcse, decl);
3036 tem = gcse_main (insns, rtl_dump_file);
3037 rebuild_jump_labels (insns);
3038 delete_trivially_dead_insns (insns, max_reg_num ());
3040 save_csb = flag_cse_skip_blocks;
3041 save_cfj = flag_cse_follow_jumps;
3042 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
3044 /* Instantiate any remaining CONSTANT_P_RTX nodes. */
3045 if (current_function_calls_constant_p)
3046 purge_builtin_constant_p ();
3048 /* If -fexpensive-optimizations, re-run CSE to clean up things done
3050 if (flag_expensive_optimizations)
3052 timevar_push (TV_CSE);
3053 reg_scan (insns, max_reg_num (), 1);
3054 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
3055 purge_all_dead_edges (0);
3056 delete_trivially_dead_insns (insns, max_reg_num ());
3057 timevar_pop (TV_CSE);
3058 cse_not_expected = !flag_rerun_cse_after_loop;
3061 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
3062 things up. Then possibly re-run CSE again. */
3066 timevar_push (TV_JUMP);
3067 rebuild_jump_labels (insns);
3068 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3069 timevar_pop (TV_JUMP);
3071 if (flag_expensive_optimizations)
3073 timevar_push (TV_CSE);
3074 reg_scan (insns, max_reg_num (), 1);
3075 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
3076 purge_all_dead_edges (0);
3077 delete_trivially_dead_insns (insns, max_reg_num ());
3078 timevar_pop (TV_CSE);
3082 close_dump_file (DFI_gcse, print_rtl_with_bb, insns);
3083 timevar_pop (TV_GCSE);
3086 flag_cse_skip_blocks = save_csb;
3087 flag_cse_follow_jumps = save_cfj;
3088 #ifdef ENABLE_CHECKING
3089 verify_flow_info ();
3093 /* Move constant computations out of loops. */
3095 rest_of_handle_loop_optimize (tree decl, rtx insns)
3097 int do_unroll, do_prefetch;
3099 timevar_push (TV_LOOP);
3100 delete_dead_jumptables ();
3101 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3102 open_dump_file (DFI_loop, decl);
3104 /* CFG is no longer maintained up-to-date. */
3105 free_bb_for_insn ();
3107 if (flag_unroll_loops)
3108 do_unroll = 0; /* Having two unrollers is useless. */
3110 do_unroll = flag_old_unroll_loops ? LOOP_UNROLL : LOOP_AUTO_UNROLL;
3111 do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
3113 if (flag_rerun_loop_opt)
3115 cleanup_barriers ();
3117 /* We only want to perform unrolling once. */
3118 loop_optimize (insns, rtl_dump_file, do_unroll);
3121 /* The first call to loop_optimize makes some instructions
3122 trivially dead. We delete those instructions now in the
3123 hope that doing so will make the heuristics in loop work
3124 better and possibly speed up compilation. */
3125 delete_trivially_dead_insns (insns, max_reg_num ());
3127 /* The regscan pass is currently necessary as the alias
3128 analysis code depends on this information. */
3129 reg_scan (insns, max_reg_num (), 1);
3131 cleanup_barriers ();
3132 loop_optimize (insns, rtl_dump_file, do_unroll | LOOP_BCT | do_prefetch);
3134 /* Loop can create trivially dead instructions. */
3135 delete_trivially_dead_insns (insns, max_reg_num ());
3136 close_dump_file (DFI_loop, print_rtl, insns);
3137 timevar_pop (TV_LOOP);
3138 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3143 /* Perform loop optimizations. It might be better to do them a bit
3144 sooner, but we want the profile feedback to work more
3147 rest_of_handle_loop2 (tree decl, rtx insns)
3149 struct loops *loops;
3150 timevar_push (TV_LOOP);
3151 open_dump_file (DFI_loop2, decl);
3153 dump_flow_info (rtl_dump_file);
3155 loops = loop_optimizer_init (rtl_dump_file);
3159 /* The optimizations: */
3160 if (flag_unswitch_loops)
3161 unswitch_loops (loops);
3163 if (flag_peel_loops || flag_unroll_loops)
3164 unroll_and_peel_loops (loops,
3165 (flag_peel_loops ? UAP_PEEL : 0) |
3166 (flag_unroll_loops ? UAP_UNROLL : 0) |
3167 (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0));
3169 loop_optimizer_finalize (loops, rtl_dump_file);
3172 cleanup_cfg (CLEANUP_EXPENSIVE);
3173 delete_trivially_dead_insns (insns, max_reg_num ());
3174 reg_scan (insns, max_reg_num (), 0);
3176 dump_flow_info (rtl_dump_file);
3177 close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
3178 timevar_pop (TV_LOOP);
3182 /* This is called from finish_function (within langhooks.parse_file)
3183 after each top-level definition is parsed.
3184 It is supposed to compile that function or variable
3185 and output the assembler code for it.
3186 After we return, the tree storage is freed. */
3189 rest_of_compilation (tree decl)
3192 int rebuild_label_notes_after_reload;
3194 timevar_push (TV_REST_OF_COMPILATION);
3196 /* Register rtl specific functions for cfg. */
3197 rtl_register_cfg_hooks ();
3199 /* Now that we're out of the frontend, we shouldn't have any more
3200 CONCATs anywhere. */
3201 generating_concat_p = 0;
3203 /* When processing delayed functions, prepare_function_start() won't
3204 have been run to re-initialize it. */
3205 cse_not_expected = ! optimize;
3207 /* First, make sure that NOTE_BLOCK is set correctly for each
3208 NOTE_INSN_BLOCK_BEG/NOTE_INSN_BLOCK_END note. */
3209 if (!cfun->x_whole_function_mode_p)
3212 /* In function-at-a-time mode, we do not attempt to keep the BLOCK
3213 tree in sensible shape. So, we just recalculate it here. */
3214 if (cfun->x_whole_function_mode_p)
3219 if (rest_of_handle_inlining (decl))
3220 goto exit_rest_of_compilation;
3222 /* If we're emitting a nested function, make sure its parent gets
3223 emitted as well. Doing otherwise confuses debug info. */
3226 for (parent = DECL_CONTEXT (current_function_decl);
3227 parent != NULL_TREE;
3228 parent = get_containing_scope (parent))
3229 if (TREE_CODE (parent) == FUNCTION_DECL)
3230 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
3233 /* We are now committed to emitting code for this function. Do any
3234 preparation, such as emitting abstract debug info for the inline
3235 before it gets mangled by optimization. */
3236 if (DECL_INLINE (decl))
3237 (*debug_hooks->outlining_inline_function) (decl);
3239 /* Remove any notes we don't need. That will make iterating
3240 over the instruction sequence faster, and allow the garbage
3241 collector to reclaim the memory used by the notes. */
3242 remove_unnecessary_notes ();
3247 /* Initialize some variables used by the optimizers. */
3248 init_function_for_compilation ();
3250 if (! DECL_DEFER_OUTPUT (decl))
3251 TREE_ASM_WRITTEN (decl) = 1;
3253 /* Now that integrate will no longer see our rtl, we need not
3254 distinguish between the return value of this function and the
3255 return value of called functions. Also, we can remove all SETs
3256 of subregs of hard registers; they are only here because of
3257 integrate. Also, we can now initialize pseudos intended to
3258 carry magic hard reg data throughout the function. */
3259 rtx_equal_function_value_matters = 0;
3260 purge_hard_subreg_sets (get_insns ());
3262 /* Early return if there were errors. We can run afoul of our
3263 consistency checks, and there's not really much point in fixing them.
3264 Don't return yet if -Wreturn-type; we need to do cleanup_cfg. */
3265 if (((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
3266 || errorcount || sorrycount)
3267 goto exit_rest_of_compilation;
3269 timevar_push (TV_JUMP);
3270 open_dump_file (DFI_sibling, decl);
3271 insns = get_insns ();
3272 rebuild_jump_labels (insns);
3273 find_exception_handler_labels ();
3274 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3276 delete_unreachable_blocks ();
3278 /* We have to issue these warnings now already, because CFG cleanups
3279 further down may destroy the required information. */
3280 check_function_return_warnings ();
3282 /* Turn NOTE_INSN_PREDICTIONs into branch predictions. */
3283 if (flag_guess_branch_prob)
3285 timevar_push (TV_BRANCH_PROB);
3286 note_prediction_to_br_prob ();
3287 timevar_pop (TV_BRANCH_PROB);
3290 if (flag_optimize_sibling_calls)
3291 rest_of_handle_sibling_calls (insns);
3293 timevar_pop (TV_JUMP);
3295 insn_locators_initialize ();
3296 /* Complete generation of exception handling code. */
3299 timevar_push (TV_JUMP);
3300 open_dump_file (DFI_eh, decl);
3302 finish_eh_generation ();
3304 close_dump_file (DFI_eh, print_rtl, get_insns ());
3305 timevar_pop (TV_JUMP);
3308 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
3309 generation, which might create new sets. */
3310 emit_initial_value_sets ();
3313 /* If we are doing position-independent code generation, now
3314 is the time to output special prologues and epilogues.
3315 We do not want to do this earlier, because it just clutters
3316 up inline functions with meaningless insns. */
3321 insns = get_insns ();
3323 /* Copy any shared structure that should not be shared. */
3324 unshare_all_rtl (current_function_decl, insns);
3326 #ifdef SETJMP_VIA_SAVE_AREA
3327 /* This must be performed before virtual register instantiation.
3328 Please be aware the everything in the compiler that can look
3329 at the RTL up to this point must understand that REG_SAVE_AREA
3330 is just like a use of the REG contained inside. */
3331 if (current_function_calls_alloca)
3332 optimize_save_area_alloca (insns);
3335 /* Instantiate all virtual registers. */
3336 instantiate_virtual_regs (current_function_decl, insns);
3338 open_dump_file (DFI_jump, decl);
3340 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3341 are initialized and to compute whether control can drop off the end
3344 timevar_push (TV_JUMP);
3345 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
3346 before jump optimization switches branch directions. */
3347 if (flag_guess_branch_prob)
3348 expected_value_to_br_prob ();
3350 reg_scan (insns, max_reg_num (), 0);
3351 rebuild_jump_labels (insns);
3352 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3353 delete_trivially_dead_insns (insns, max_reg_num ());
3355 dump_flow_info (rtl_dump_file);
3356 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
3357 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
3361 free_bb_for_insn ();
3362 copy_loop_headers (insns);
3363 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3365 purge_line_number_notes (insns);
3367 timevar_pop (TV_JUMP);
3368 close_dump_file (DFI_jump, print_rtl, insns);
3370 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
3371 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
3372 goto exit_rest_of_compilation;
3374 /* Long term, this should probably move before the jump optimizer too,
3375 but I didn't want to disturb the rtl_dump_and_exit and related
3376 stuff at this time. */
3377 if (optimize > 0 && flag_ssa)
3378 insns = rest_of_handle_ssa (decl, insns);
3380 timevar_push (TV_JUMP);
3383 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3385 if (flag_delete_null_pointer_checks)
3386 rest_of_handle_null_pointer (decl, insns);
3388 /* Jump optimization, and the removal of NULL pointer checks, may
3389 have reduced the number of instructions substantially. CSE, and
3390 future passes, allocate arrays whose dimensions involve the
3391 maximum instruction UID, so if we can reduce the maximum UID
3392 we'll save big on memory. */
3393 renumber_insns (rtl_dump_file);
3394 timevar_pop (TV_JUMP);
3396 close_dump_file (DFI_jump, print_rtl_with_bb, insns);
3401 rest_of_handle_cse (decl, insns);
3403 rest_of_handle_addresof (decl, insns);
3410 rest_of_handle_gcse (decl, insns);
3412 if (flag_loop_optimize)
3413 rest_of_handle_loop_optimize (decl, insns);
3416 rest_of_handle_jump_bypass (decl, insns);
3419 timevar_push (TV_FLOW);
3421 rest_of_handle_cfg (decl, insns);
3424 || profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
3425 rest_of_handle_branch_prob (decl, insns);
3428 rest_of_handle_if_conversion (decl, insns);
3431 rest_of_handle_tracer (decl, insns);
3434 && (flag_unswitch_loops
3436 || flag_unroll_loops))
3437 rest_of_handle_loop2 (decl, insns);
3439 if (flag_rerun_cse_after_loop)
3440 rest_of_handle_cse2 (decl, insns);
3442 cse_not_expected = 1;
3444 rest_of_handle_life (decl, insns);
3447 rest_of_handle_combine (decl, insns);
3449 if (flag_if_conversion)
3450 rest_of_handle_if_after_combine (decl, insns);
3452 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
3453 rest_of_handle_regmove (decl, insns);
3455 /* Do unconditional splitting before register allocation to allow machine
3456 description to add extra information not needed previously. */
3457 split_all_insns (1);
3459 #ifdef OPTIMIZE_MODE_SWITCHING
3460 timevar_push (TV_MODE_SWITCH);
3463 optimize_mode_switching (NULL);
3466 timevar_pop (TV_MODE_SWITCH);
3469 /* Any of the several passes since flow1 will have munged register
3470 lifetime data a bit. We need it to be up to date for scheduling
3471 (see handling of reg_known_equiv in init_alias_analysis). */
3472 recompute_reg_usage (insns, !optimize_size);
3474 #ifdef INSN_SCHEDULING
3475 rest_of_handle_sched (decl, insns);
3478 /* Determine if the current function is a leaf before running reload
3479 since this can impact optimizations done by the prologue and
3480 epilogue thus changing register elimination offsets. */
3481 current_function_is_leaf = leaf_function_p ();
3483 timevar_push (TV_LOCAL_ALLOC);
3484 open_dump_file (DFI_lreg, decl);
3486 if (flag_new_regalloc)
3488 if (rest_of_handle_new_regalloc (decl, insns,
3489 &rebuild_label_notes_after_reload))
3490 goto exit_rest_of_compilation;
3494 if (rest_of_handle_old_regalloc (decl, insns,
3495 &rebuild_label_notes_after_reload))
3496 goto exit_rest_of_compilation;
3501 open_dump_file (DFI_postreload, decl);
3503 /* Do a very simple CSE pass over just the hard registers. */
3506 timevar_push (TV_RELOAD_CSE_REGS);
3507 reload_cse_regs (insns);
3508 timevar_pop (TV_RELOAD_CSE_REGS);
3511 /* Register allocation and reloading may have turned an indirect jump into
3512 a direct jump. If so, we must rebuild the JUMP_LABEL fields of
3513 jumping instructions. */
3514 if (rebuild_label_notes_after_reload)
3516 timevar_push (TV_JUMP);
3518 rebuild_jump_labels (insns);
3519 purge_all_dead_edges (0);
3521 timevar_pop (TV_JUMP);
3524 close_dump_file (DFI_postreload, print_rtl_with_bb, insns);
3526 /* Re-create the death notes which were deleted during reload. */
3527 timevar_push (TV_FLOW2);
3528 open_dump_file (DFI_flow2, decl);
3530 #ifdef ENABLE_CHECKING
3531 verify_flow_info ();
3534 /* If optimizing, then go ahead and split insns now. */
3538 split_all_insns (0);
3540 if (flag_branch_target_load_optimize)
3542 open_dump_file (DFI_branch_target_load, decl);
3544 branch_target_load_optimize (insns, false);
3546 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3552 cleanup_cfg (CLEANUP_EXPENSIVE);
3554 /* On some machines, the prologue and epilogue code, or parts thereof,
3555 can be represented as RTL. Doing so lets us schedule insns between
3556 it and the rest of the code and also allows delayed branch
3557 scheduling to operate in the epilogue. */
3558 thread_prologue_and_epilogue_insns (insns);
3559 epilogue_completed = 1;
3563 life_analysis (insns, rtl_dump_file, PROP_FINAL);
3564 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
3565 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
3567 /* This is kind of a heuristic. We need to run combine_stack_adjustments
3568 even for machines with possibly nonzero RETURN_POPS_ARGS
3569 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
3570 push instructions will have popping returns. */
3571 #ifndef PUSH_ROUNDING
3572 if (!ACCUMULATE_OUTGOING_ARGS)
3574 combine_stack_adjustments ();
3579 flow2_completed = 1;
3581 close_dump_file (DFI_flow2, print_rtl_with_bb, insns);
3582 timevar_pop (TV_FLOW2);
3584 #ifdef HAVE_peephole2
3585 if (optimize > 0 && flag_peephole2)
3587 timevar_push (TV_PEEPHOLE2);
3588 open_dump_file (DFI_peephole2, decl);
3590 peephole2_optimize (rtl_dump_file);
3592 close_dump_file (DFI_peephole2, print_rtl_with_bb, insns);
3593 timevar_pop (TV_PEEPHOLE2);
3599 if (flag_rename_registers || flag_cprop_registers)
3600 rest_of_handle_regrename (decl, insns);
3602 rest_of_handle_reorder_blocks (decl, insns);
3605 if (flag_if_conversion2)
3607 timevar_push (TV_IFCVT2);
3608 open_dump_file (DFI_ce3, decl);
3612 close_dump_file (DFI_ce3, print_rtl_with_bb, insns);
3613 timevar_pop (TV_IFCVT2);
3616 if (flag_branch_target_load_optimize2)
3618 /* Leave this a warning for now so that it is possible to experiment
3619 with running this pass twice. In 3.6, we should either make this
3620 an error, or use separate dump files. */
3621 if (flag_branch_target_load_optimize)
3622 warning ("branch target register load optimization is not intended "
3625 open_dump_file (DFI_branch_target_load, decl);
3627 branch_target_load_optimize (insns, true);
3629 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3634 #ifdef INSN_SCHEDULING
3635 if (optimize > 0 && flag_schedule_insns_after_reload)
3636 rest_of_handle_sched2 (decl, insns);
3639 #ifdef LEAF_REGISTERS
3640 current_function_uses_only_leaf_regs
3641 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
3645 rest_of_handle_stack_regs (decl, insns);
3648 compute_alignments ();
3650 /* CFG is no longer maintained up-to-date. */
3651 free_bb_for_insn ();
3653 if (targetm.machine_dependent_reorg != 0)
3654 rest_of_handle_machine_reorg (decl, insns);
3656 purge_line_number_notes (insns);
3657 cleanup_barriers ();
3660 if (optimize > 0 && flag_delayed_branch)
3661 rest_of_handle_delay_slots (decl, insns);
3664 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3665 timevar_push (TV_SHORTEN_BRANCH);
3666 split_all_insns_noflow ();
3667 timevar_pop (TV_SHORTEN_BRANCH);
3670 convert_to_eh_region_ranges ();
3672 /* Shorten branches. */
3673 timevar_push (TV_SHORTEN_BRANCH);
3674 shorten_branches (get_insns ());
3675 timevar_pop (TV_SHORTEN_BRANCH);
3677 set_nothrow_function_flags ();
3678 if (current_function_nothrow)
3679 /* Now we know that this can't throw; set the flag for the benefit
3680 of other functions later in this translation unit. */
3681 TREE_NOTHROW (current_function_decl) = 1;
3683 rest_of_handle_final (decl, insns);
3685 /* Write DBX symbols if requested. */
3687 /* Note that for those inline functions where we don't initially
3688 know for certain that we will be generating an out-of-line copy,
3689 the first invocation of this routine (rest_of_compilation) will
3690 skip over this code by doing a `goto exit_rest_of_compilation;'.
3691 Later on, wrapup_global_declarations will (indirectly) call
3692 rest_of_compilation again for those inline functions that need
3693 to have out-of-line copies generated. During that call, we
3694 *will* be routed past here. */
3696 timevar_push (TV_SYMOUT);
3697 (*debug_hooks->function_decl) (decl);
3698 timevar_pop (TV_SYMOUT);
3700 exit_rest_of_compilation:
3702 coverage_end_function ();
3704 /* In case the function was not output,
3705 don't leave any temporary anonymous types
3706 queued up for sdb output. */
3707 #ifdef SDB_DEBUGGING_INFO
3708 if (write_symbols == SDB_DEBUG)
3709 sdbout_types (NULL_TREE);
3712 reload_completed = 0;
3713 epilogue_completed = 0;
3714 flow2_completed = 0;
3717 timevar_push (TV_FINAL);
3719 /* Clear out the insn_length contents now that they are no
3721 init_insn_lengths ();
3723 /* Show no temporary slots allocated. */
3726 free_basic_block_vars (0);
3727 free_bb_for_insn ();
3729 timevar_pop (TV_FINAL);
3731 if ((*targetm.binds_local_p) (current_function_decl))
3733 int pref = cfun->preferred_stack_boundary;
3734 if (cfun->recursive_call_emit
3735 && cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
3736 pref = cfun->stack_alignment_needed;
3737 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
3741 /* Make sure volatile mem refs aren't considered valid operands for
3742 arithmetic insns. We must call this here if this is a nested inline
3743 function, since the above code leaves us in the init_recog state
3744 (from final.c), and the function context push/pop code does not
3745 save/restore volatile_ok.
3747 ??? Maybe it isn't necessary for expand_start_function to call this
3748 anymore if we do it here? */
3750 init_recog_no_volatile ();
3752 /* We're done with this function. Free up memory if we can. */
3753 free_after_parsing (cfun);
3754 if (! DECL_DEFER_OUTPUT (decl))
3756 free_after_compilation (cfun);
3758 /* Clear integrate.c's pointer to the cfun structure we just
3760 DECL_SAVED_INSNS (decl) = 0;
3766 timevar_pop (TV_REST_OF_COMPILATION);
3769 /* Display help for generic options. */
3777 for (i = LAST_PARAM; i--;)
3779 const char *description = compiler_params[i].help;
3780 const int length = 21 - strlen (compiler_params[i].option);
3782 if (description != NULL && *description != 0)
3783 printf (" --param %s=<value>%.*s%s\n",
3784 compiler_params[i].option,
3785 length > 0 ? length : 1, " ",
3789 for (i = ARRAY_SIZE (debug_args); i--;)
3791 if (debug_args[i].description != NULL)
3792 printf (" -g%-21s %s\n",
3793 debug_args[i].arg, _(debug_args[i].description));
3799 /* Display descriptions of language specific options.
3800 If there is no description, note that there is an undocumented option.
3801 If the description is empty, do not display anything. (This allows
3802 options to be deliberately undocumented, for whatever reason).
3803 If the option string is missing, then this is a marker, indicating
3804 that the description string is in fact the name of a language, whose
3805 language specific options are to follow. */
3807 if (ARRAY_SIZE (documented_lang_options) > 1)
3809 printf (_("\nLanguage specific options:\n"));
3811 for (i = 0; i < ARRAY_SIZE (documented_lang_options); i++)
3813 const char *description = documented_lang_options[i].description;
3814 const char *option = documented_lang_options[i].option;
3816 if (description == NULL)
3821 printf (_(" %-23s [undocumented]\n"), option);
3823 else if (*description == 0)
3825 else if (option == NULL)
3829 (_("\nThere are undocumented %s specific options as well.\n"),
3833 printf (_("\n Options for %s:\n"), description);
3838 printf (" %-23s %s\n", option, _(description));
3843 printf (_("\nThere are undocumented %s specific options as well.\n"),
3846 display_target_options ();
3849 /* Display help for target options. */
3851 display_target_options (void)
3854 static bool displayed = false;
3856 /* Avoid double printing for --help --target-help. */
3862 if (ARRAY_SIZE (target_switches) > 1
3863 #ifdef TARGET_OPTIONS
3864 || ARRAY_SIZE (target_options) > 1
3872 printf (_("\nTarget specific options:\n"));
3874 for (i = ARRAY_SIZE (target_switches); i--;)
3876 const char *option = target_switches[i].name;
3877 const char *description = target_switches[i].description;
3879 if (option == NULL || *option == 0)
3881 else if (description == NULL)
3886 printf (_(" -m%-23s [undocumented]\n"), option);
3888 else if (*description != 0)
3889 doc += printf (" -m%-23s %s\n", option, _(description));
3892 #ifdef TARGET_OPTIONS
3893 for (i = ARRAY_SIZE (target_options); i--;)
3895 const char *option = target_options[i].prefix;
3896 const char *description = target_options[i].description;
3898 if (option == NULL || *option == 0)
3900 else if (description == NULL)
3905 printf (_(" -m%-23s [undocumented]\n"), option);
3907 else if (*description != 0)
3908 doc += printf (" -m%-23s %s\n", option, _(description));
3914 printf (_("\nThere are undocumented target specific options as well.\n"));
3916 printf (_(" They exist, but they are not documented.\n"));
3921 /* Parse a -d... command line switch. */
3924 decode_d_option (const char *arg)
3932 for (i = 0; i < (int) DFI_MAX; ++i)
3933 dump_file[i].enabled = 1;
3939 flag_print_asm_name = 1;
3942 flag_dump_rtl_in_asm = 1;
3943 flag_print_asm_name = 1;
3946 graph_dump_format = vcg;
3949 rtl_dump_and_exit = 1;
3954 case 'D': /* These are handled by the preprocessor. */
3958 setup_core_dumping();
3963 for (i = 0; i < (int) DFI_MAX; ++i)
3964 if (c == dump_file[i].debug_switch)
3966 dump_file[i].enabled = 1;
3971 warning ("unrecognized gcc debugging option: %c", c);
3976 /* Indexed by enum debug_info_type. */
3977 const char *const debug_type_names[] =
3979 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
3982 /* Parse a -g... command line switch. ARG is the value after the -g.
3983 It is safe to access 'ARG - 2' to generate the full switch name.
3984 Return the number of strings consumed. */
3987 decode_g_option (const char *arg)
3989 static unsigned level = 0;
3990 /* A lot of code assumes write_symbols == NO_DEBUG if the
3991 debugging level is 0 (thus -gstabs1 -gstabs0 would lose track
3992 of what debugging type has been selected). This records the
3993 selected type. It is an error to specify more than one
3995 static enum debug_info_type selected_debug_type = NO_DEBUG;
3996 /* Nonzero if debugging format has been explicitly set.
3997 -g and -ggdb don't explicitly set the debugging format so
3998 -gdwarf -g3 is equivalent to -gdwarf3. */
3999 static int type_explicitly_set_p = 0;
4001 /* The maximum admissible debug level value. */
4002 static const unsigned max_debug_level = 3;
4004 /* Look up ARG in the table. */
4005 for (da = debug_args; da->arg; da++)
4007 const int da_len = strlen (da->arg);
4009 if (da_len == 0 || ! strncmp (arg, da->arg, da_len))
4011 enum debug_info_type type = da->debug_type;
4012 const char *p = arg + da_len;
4014 if (*p && ! ISDIGIT (*p))
4017 /* A debug flag without a level defaults to level 2.
4018 Note we do not want to call read_integral_parameter
4019 for that case since it will call atoi which
4022 ??? We may want to generalize the interface to
4023 read_integral_parameter to better handle this case
4024 if this case shows up often. */
4026 level = read_integral_parameter (p, 0, max_debug_level + 1);
4028 level = (level == 0) ? 2 : level;
4030 if (da_len > 1 && *p && !strncmp (arg, "dwarf", da_len))
4032 error ("use -gdwarf -g%d for DWARF v1, level %d",
4035 error ("use -gdwarf-2 for DWARF v2");
4038 if (level > max_debug_level)
4041 ignoring option `%s' due to invalid debug level specification",
4043 level = debug_info_level;
4046 if (type == NO_DEBUG)
4048 type = PREFERRED_DEBUGGING_TYPE;
4050 if (da_len > 1 && strncmp (arg, "gdb", da_len) == 0)
4052 #ifdef DWARF2_DEBUGGING_INFO
4053 type = DWARF2_DEBUG;
4055 #ifdef DBX_DEBUGGING_INFO
4062 if (type == NO_DEBUG)
4063 warning ("`%s': unknown or unsupported -g option", arg - 2);
4065 /* Does it conflict with an already selected type? */
4066 if (type_explicitly_set_p
4067 /* -g/-ggdb don't conflict with anything. */
4068 && da->debug_type != NO_DEBUG
4069 && type != selected_debug_type)
4070 warning ("`%s' ignored, conflicts with `-g%s'",
4071 arg - 2, debug_type_names[(int) selected_debug_type]);
4074 /* If the format has already been set, -g/-ggdb
4075 only change the debug level. */
4076 if (type_explicitly_set_p && da->debug_type == NO_DEBUG)
4077 /* Don't change debugging type. */
4081 selected_debug_type = type;
4082 type_explicitly_set_p = da->debug_type != NO_DEBUG;
4085 write_symbols = (level == 0
4087 : selected_debug_type);
4088 use_gnu_debug_info_extensions = da->use_extensions_p;
4089 debug_info_level = (enum debug_info_level) level;
4097 warning ("`-g%s': unknown or unsupported -g option", arg);
4100 /* Decode -m switches. */
4101 /* Decode the switch -mNAME. */
4104 set_target_switch (const char *name)
4107 int valid_target_option = 0;
4109 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
4110 if (!strcmp (target_switches[j].name, name))
4112 if (target_switches[j].value < 0)
4113 target_flags &= ~-target_switches[j].value;
4115 target_flags |= target_switches[j].value;
4118 if (target_switches[j].value < 0)
4119 target_flags_explicit |= -target_switches[j].value;
4121 target_flags_explicit |= target_switches[j].value;
4123 valid_target_option = 1;
4126 #ifdef TARGET_OPTIONS
4127 if (!valid_target_option)
4128 for (j = 0; j < ARRAY_SIZE (target_options); j++)
4130 int len = strlen (target_options[j].prefix);
4131 if (target_options[j].value)
4133 if (!strcmp (target_options[j].prefix, name))
4135 *target_options[j].variable = target_options[j].value;
4136 valid_target_option = 1;
4141 if (!strncmp (target_options[j].prefix, name, len))
4143 *target_options[j].variable = name + len;
4144 valid_target_option = 1;
4150 if (!valid_target_option)
4151 error ("invalid option `%s'", name);
4154 /* Print version information to FILE.
4155 Each line begins with INDENT (for the case where FILE is the
4156 assembler output file). */
4159 print_version (FILE *file, const char *indent)
4162 #define __VERSION__ "[?]"
4166 "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
4168 "%s%s%s version %s (%s) compiled by CC.\n"
4170 , indent, *indent != 0 ? " " : "",
4171 lang_hooks.name, version_string, TARGET_NAME,
4172 indent, __VERSION__);
4173 fnotice (file, "%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n",
4174 indent, *indent != 0 ? " " : "",
4175 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
4178 /* Print an option value and return the adjusted position in the line.
4179 ??? We don't handle error returns from fprintf (disk full); presumably
4180 other code will catch a disk full though. */
4183 print_single_switch (FILE *file, int pos, int max,
4184 const char *indent, const char *sep, const char *term,
4185 const char *type, const char *name)
4187 /* The ultrix fprintf returns 0 on success, so compute the result we want
4188 here since we need it for the following test. */
4189 int len = strlen (sep) + strlen (type) + strlen (name);
4194 fprintf (file, "%s", term);
4199 fprintf (file, "%s", indent);
4200 pos = strlen (indent);
4202 fprintf (file, "%s%s%s", sep, type, name);
4207 /* Print active target switches to FILE.
4208 POS is the current cursor position and MAX is the size of a "line".
4209 Each line begins with INDENT and ends with TERM.
4210 Each switch is separated from the next by SEP. */
4213 print_switch_values (FILE *file, int pos, int max,
4214 const char *indent, const char *sep, const char *term)
4219 /* Fill in the -frandom-seed option, if the user didn't pass it, so
4220 that it can be printed below. This helps reproducibility. */
4223 /* Print the options as passed. */
4224 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
4225 _("options passed: "), "");
4227 for (p = &save_argv[1]; *p != NULL; p++)
4231 if (strcmp (*p, "-o") == 0)
4237 if (strcmp (*p, "-quiet") == 0)
4239 if (strcmp (*p, "-version") == 0)
4244 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
4247 fprintf (file, "%s", term);
4249 /* Print the -f and -m options that have been enabled.
4250 We don't handle language specific options but printing argv
4253 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
4254 _("options enabled: "), "");
4256 for (j = 0; j < ARRAY_SIZE (f_options); j++)
4257 if (*f_options[j].variable == f_options[j].on_value)
4258 pos = print_single_switch (file, pos, max, indent, sep, term,
4259 "-f", f_options[j].string);
4261 /* Print target specific options. */
4263 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
4264 if (target_switches[j].name[0] != '\0'
4265 && target_switches[j].value > 0
4266 && ((target_switches[j].value & target_flags)
4267 == target_switches[j].value))
4269 pos = print_single_switch (file, pos, max, indent, sep, term,
4270 "-m", target_switches[j].name);
4273 #ifdef TARGET_OPTIONS
4274 for (j = 0; j < ARRAY_SIZE (target_options); j++)
4275 if (*target_options[j].variable != NULL)
4278 sprintf (prefix, "-m%s", target_options[j].prefix);
4279 pos = print_single_switch (file, pos, max, indent, sep, term,
4280 prefix, *target_options[j].variable);
4284 fprintf (file, "%s", term);
4287 /* Open assembly code output file. Do this even if -fsyntax-only is
4288 on, because then the driver will have provided the name of a
4289 temporary file or bit bucket for us. NAME is the file specified on
4290 the command line, possibly NULL. */
4292 init_asm_output (const char *name)
4294 if (name == NULL && asm_file_name == 0)
4295 asm_out_file = stdout;
4298 if (asm_file_name == 0)
4300 int len = strlen (dump_base_name);
4301 char *dumpname = (char *) xmalloc (len + 6);
4302 memcpy (dumpname, dump_base_name, len + 1);
4303 strip_off_ending (dumpname, len);
4304 strcat (dumpname, ".s");
4305 asm_file_name = dumpname;
4307 if (!strcmp (asm_file_name, "-"))
4308 asm_out_file = stdout;
4310 asm_out_file = fopen (asm_file_name, "w+");
4311 if (asm_out_file == 0)
4312 fatal_error ("can't open %s for writing: %m", asm_file_name);
4315 #ifdef IO_BUFFER_SIZE
4316 setvbuf (asm_out_file, (char *) xmalloc (IO_BUFFER_SIZE),
4317 _IOFBF, IO_BUFFER_SIZE);
4320 if (!flag_syntax_only)
4322 targetm.asm_out.file_start ();
4324 #ifdef ASM_COMMENT_START
4325 if (flag_verbose_asm)
4327 /* Print the list of options in effect. */
4328 print_version (asm_out_file, ASM_COMMENT_START);
4329 print_switch_values (asm_out_file, 0, MAX_LINE,
4330 ASM_COMMENT_START, " ", "\n");
4331 /* Add a blank line here so it appears in assembler output but not
4333 fprintf (asm_out_file, "\n");
4339 /* Initialization of the front end environment, before command line
4340 options are parsed. Signal handlers, internationalization etc.
4341 ARGV0 is main's argv[0]. */
4343 general_init (const char *argv0)
4347 p = argv0 + strlen (argv0);
4348 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
4352 xmalloc_set_program_name (progname);
4356 gcc_init_libintl ();
4358 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
4360 signal (SIGSEGV, crash_signal);
4363 signal (SIGILL, crash_signal);
4366 signal (SIGBUS, crash_signal);
4369 signal (SIGABRT, crash_signal);
4371 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
4372 signal (SIGIOT, crash_signal);
4375 signal (SIGFPE, crash_signal);
4378 /* Other host-specific signal setup. */
4379 (*host_hooks.extra_signals)();
4381 /* Initialize the diagnostics reporting machinery, so option parsing
4382 can give warnings and errors. */
4383 diagnostic_initialize (global_dc);
4385 /* Initialize the garbage-collector, string pools and tree type hash
4391 /* Initialize register usage now so switches may override. */
4394 /* Register the language-independent parameters. */
4395 add_params (lang_independent_params, LAST_PARAM);
4397 /* This must be done after add_params but before argument processing. */
4398 init_ggc_heuristics();
4401 /* Process the options that have been parsed. */
4403 process_options (void)
4405 /* Allow the front end to perform consistency checks and do further
4406 initialization based on the command line options. This hook also
4407 sets the original filename if appropriate (e.g. foo.i -> foo.c)
4408 so we can correctly initialize debug output. */
4409 no_backend = (*lang_hooks.post_options) (&main_input_filename);
4410 input_filename = main_input_filename;
4412 #ifdef OVERRIDE_OPTIONS
4413 /* Some machines may reject certain combinations of options. */
4417 /* Set aux_base_name if not already set. */
4420 else if (main_input_filename)
4422 char *name = xstrdup (lbasename (main_input_filename));
4424 strip_off_ending (name, strlen (name));
4425 aux_base_name = name;
4428 aux_base_name = "gccaux";
4430 /* Set up the align_*_log variables, defaulting them to 1 if they
4431 were still unset. */
4432 if (align_loops <= 0) align_loops = 1;
4433 if (align_loops_max_skip > align_loops || !align_loops)
4434 align_loops_max_skip = align_loops - 1;
4435 align_loops_log = floor_log2 (align_loops * 2 - 1);
4436 if (align_jumps <= 0) align_jumps = 1;
4437 if (align_jumps_max_skip > align_jumps || !align_jumps)
4438 align_jumps_max_skip = align_jumps - 1;
4439 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
4440 if (align_labels <= 0) align_labels = 1;
4441 align_labels_log = floor_log2 (align_labels * 2 - 1);
4442 if (align_labels_max_skip > align_labels || !align_labels)
4443 align_labels_max_skip = align_labels - 1;
4444 if (align_functions <= 0) align_functions = 1;
4445 align_functions_log = floor_log2 (align_functions * 2 - 1);
4447 /* Unrolling all loops implies that standard loop unrolling must also
4449 if (flag_unroll_all_loops)
4450 flag_unroll_loops = 1;
4452 if (flag_unroll_loops)
4454 flag_old_unroll_loops = 0;
4455 flag_old_unroll_all_loops = 0;
4458 if (flag_old_unroll_all_loops)
4459 flag_old_unroll_loops = 1;
4461 /* Old loop unrolling requires that strength_reduction be on also. Silently
4462 turn on strength reduction here if it isn't already on. Also, the loop
4463 unrolling code assumes that cse will be run after loop, so that must
4464 be turned on also. */
4465 if (flag_old_unroll_loops)
4467 flag_strength_reduce = 1;
4468 flag_rerun_cse_after_loop = 1;
4470 if (flag_unroll_loops || flag_peel_loops)
4471 flag_rerun_cse_after_loop = 1;
4473 if (flag_non_call_exceptions)
4474 flag_asynchronous_unwind_tables = 1;
4475 if (flag_asynchronous_unwind_tables)
4476 flag_unwind_tables = 1;
4478 /* Disable unit-at-a-time mode for frontends not supporting callgraph
4480 if (flag_unit_at_a_time && ! lang_hooks.callgraph.expand_function)
4481 flag_unit_at_a_time = 0;
4483 /* Warn about options that are not supported on this machine. */
4484 #ifndef INSN_SCHEDULING
4485 if (flag_schedule_insns || flag_schedule_insns_after_reload)
4486 warning ("instruction scheduling not supported on this target machine");
4489 if (flag_delayed_branch)
4490 warning ("this target machine does not have delayed branches");
4493 user_label_prefix = USER_LABEL_PREFIX;
4494 if (flag_leading_underscore != -1)
4496 /* If the default prefix is more complicated than "" or "_",
4497 issue a warning and ignore this option. */
4498 if (user_label_prefix[0] == 0 ||
4499 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
4501 user_label_prefix = flag_leading_underscore ? "_" : "";
4504 warning ("-f%sleading-underscore not supported on this target machine",
4505 flag_leading_underscore ? "" : "no-");
4508 /* If we are in verbose mode, write out the version and maybe all the
4509 option flags in use. */
4512 print_version (stderr, "");
4514 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
4517 if (flag_syntax_only)
4519 write_symbols = NO_DEBUG;
4523 /* Now we know write_symbols, set up the debug hooks based on it.
4524 By default we do nothing for debug output. */
4525 #if defined(DBX_DEBUGGING_INFO)
4526 if (write_symbols == DBX_DEBUG)
4527 debug_hooks = &dbx_debug_hooks;
4529 #if defined(XCOFF_DEBUGGING_INFO)
4530 if (write_symbols == XCOFF_DEBUG)
4531 debug_hooks = &xcoff_debug_hooks;
4533 #ifdef SDB_DEBUGGING_INFO
4534 if (write_symbols == SDB_DEBUG)
4535 debug_hooks = &sdb_debug_hooks;
4537 #ifdef DWARF_DEBUGGING_INFO
4538 if (write_symbols == DWARF_DEBUG)
4539 debug_hooks = &dwarf_debug_hooks;
4541 #ifdef DWARF2_DEBUGGING_INFO
4542 if (write_symbols == DWARF2_DEBUG)
4543 debug_hooks = &dwarf2_debug_hooks;
4545 #ifdef VMS_DEBUGGING_INFO
4546 if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
4547 debug_hooks = &vmsdbg_debug_hooks;
4550 /* If auxiliary info generation is desired, open the output file.
4551 This goes in the same directory as the source file--unlike
4552 all the other output files. */
4553 if (flag_gen_aux_info)
4555 aux_info_file = fopen (aux_info_file_name, "w");
4556 if (aux_info_file == 0)
4557 fatal_error ("can't open %s: %m", aux_info_file_name);
4560 if (! targetm.have_named_sections)
4562 if (flag_function_sections)
4564 warning ("-ffunction-sections not supported for this target");
4565 flag_function_sections = 0;
4567 if (flag_data_sections)
4569 warning ("-fdata-sections not supported for this target");
4570 flag_data_sections = 0;
4574 if (flag_function_sections && profile_flag)
4576 warning ("-ffunction-sections disabled; it makes profiling impossible");
4577 flag_function_sections = 0;
4580 #ifndef HAVE_prefetch
4581 if (flag_prefetch_loop_arrays)
4583 warning ("-fprefetch-loop-arrays not supported for this target");
4584 flag_prefetch_loop_arrays = 0;
4587 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
4589 warning ("-fprefetch-loop-arrays not supported for this target (try -march switches)");
4590 flag_prefetch_loop_arrays = 0;
4594 /* This combination of options isn't handled for i386 targets and doesn't
4595 make much sense anyway, so don't allow it. */
4596 if (flag_prefetch_loop_arrays && optimize_size)
4598 warning ("-fprefetch-loop-arrays is not supported with -Os");
4599 flag_prefetch_loop_arrays = 0;
4602 #ifndef OBJECT_FORMAT_ELF
4603 if (flag_function_sections && write_symbols != NO_DEBUG)
4604 warning ("-ffunction-sections may affect debugging on some targets");
4607 /* The presence of IEEE signaling NaNs, implies all math can trap. */
4608 if (flag_signaling_nans)
4609 flag_trapping_math = 1;
4612 /* Initialize the compiler back end. */
4616 /* init_emit_once uses reg_raw_mode and therefore must be called
4617 after init_regs which initialized reg_raw_mode. */
4619 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
4620 || debug_info_level == DINFO_LEVEL_VERBOSE
4621 #ifdef VMS_DEBUGGING_INFO
4622 /* Enable line number info for traceback. */
4623 || debug_info_level > DINFO_LEVEL_NONE
4625 || flag_test_coverage
4626 || warn_notreached);
4627 init_fake_stack_mems ();
4631 init_function_once ();
4632 init_varasm_once ();
4634 /* The following initialization functions need to generate rtl, so
4635 provide a dummy function context for them. */
4636 init_dummy_function_start ();
4638 if (flag_caller_saves)
4639 init_caller_save ();
4640 expand_dummy_function_end ();
4643 /* Language-dependent initialization. Returns nonzero on success. */
4645 lang_dependent_init (const char *name)
4647 if (dump_base_name == 0)
4648 dump_base_name = name ? name : "gccdump";
4650 /* Other front-end initialization. */
4651 if ((*lang_hooks.init) () == 0)
4654 init_asm_output (name);
4656 /* These create various _DECL nodes, so need to be called after the
4657 front end is initialized. */
4661 /* The following initialization functions need to generate rtl, so
4662 provide a dummy function context for them. */
4663 init_dummy_function_start ();
4665 expand_dummy_function_end ();
4667 /* If dbx symbol table desired, initialize writing it and output the
4668 predefined types. */
4669 timevar_push (TV_SYMOUT);
4671 #ifdef DWARF2_UNWIND_INFO
4672 if (dwarf2out_do_frame ())
4673 dwarf2out_frame_init ();
4676 /* Now we have the correct original filename, we can initialize
4678 (*debug_hooks->init) (name);
4680 timevar_pop (TV_SYMOUT);
4685 /* Clean up: close opened files, etc. */
4690 /* Close the dump files. */
4691 if (flag_gen_aux_info)
4693 fclose (aux_info_file);
4695 unlink (aux_info_file_name);
4698 /* Close non-debugging input and output files. Take special care to note
4699 whether fclose returns an error, since the pages might still be on the
4700 buffer chain while the file is open. */
4704 if (ferror (asm_out_file) != 0)
4705 fatal_error ("error writing to %s: %m", asm_file_name);
4706 if (fclose (asm_out_file) != 0)
4707 fatal_error ("error closing %s: %m", asm_file_name);
4710 /* Do whatever is necessary to finish printing the graphs. */
4711 if (graph_dump_format != no_graph)
4715 for (i = 0; i < (int) DFI_MAX; ++i)
4716 if (dump_file[i].initialized && dump_file[i].graph_dump_p)
4721 sprintf (seq, DUMPFILE_FORMAT, i);
4722 suffix = concat (seq, dump_file[i].extension, NULL);
4723 finish_graph_dump_file (dump_base_name, suffix);
4730 ggc_print_statistics ();
4731 stringpool_statistics ();
4732 dump_tree_statistics ();
4735 /* Free up memory for the benefit of leak detectors. */
4738 /* Language-specific end of compilation actions. */
4739 (*lang_hooks.finish) ();
4742 /* Initialize the compiler, and compile the input file. */
4746 /* Initialize timing first. The C front ends read the main file in
4747 the post_options hook, and C++ does file timings. */
4748 if (time_report || !quiet_flag || flag_detailed_statistics)
4750 timevar_start (TV_TOTAL);
4754 /* Don't do any more if an error has already occurred. */
4757 /* Set up the back-end if requested. */
4761 /* Language-dependent initialization. Returns true on success. */
4762 if (lang_dependent_init (main_input_filename))
4764 if (flag_unit_at_a_time)
4766 open_dump_file (DFI_cgraph, NULL);
4767 cgraph_dump_file = rtl_dump_file;
4768 rtl_dump_file = NULL;
4773 if (flag_unit_at_a_time)
4775 rtl_dump_file = cgraph_dump_file;
4776 cgraph_dump_file = NULL;
4777 close_dump_file (DFI_cgraph, NULL, NULL_RTX);
4784 /* Stop timing and print the times. */
4785 timevar_stop (TV_TOTAL);
4786 timevar_print (stderr);
4789 /* Entry point of cc1, cc1plus, jc1, f771, etc.
4790 Decode command args, then call compile_file.
4791 Exit code is FATAL_EXIT_CODE if can't open files or if there were
4792 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
4794 It is not safe to call this function more than once. */
4797 toplev_main (unsigned int argc, const char **argv)
4801 /* Initialization of GCC's environment, and diagnostics. */
4802 general_init (argv[0]);
4804 /* Parse the options and do minimal processing; basically just
4805 enough to default flags appropriately. */
4806 decode_options (argc, argv);
4810 /* Exit early if we can (e.g. -help). */
4811 if (!exit_after_options)
4814 if (errorcount || sorrycount)
4815 return (FATAL_EXIT_CODE);
4817 return (SUCCESS_EXIT_CODE);