1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* This is the top level of cc1/c++.
23 It parses command args, opens files, invokes the various passes
24 in the proper order, and counts the time used by each.
25 Error messages and low-level interface to malloc also handled here. */
28 #undef FLOAT /* This is for hpux. They should change hpux. */
29 #undef FFS /* Some systems define this in param.h. */
31 #include "coretypes.h"
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
48 #include "insn-attr.h"
49 #include "insn-config.h"
50 #include "insn-flags.h"
51 #include "hard-reg-set.h"
58 #include "basic-block.h"
65 #include "diagnostic.h"
69 #include "dwarf2asm.h"
70 #include "integrate.h"
74 #include "langhooks.h"
75 #include "cfglayout.h"
77 #include "hosthooks.h"
82 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
83 #include "dwarf2out.h"
86 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
90 #ifdef SDB_DEBUGGING_INFO
94 #ifdef XCOFF_DEBUGGING_INFO
95 #include "xcoffout.h" /* Needed for external data
96 declarations for e.g. AIX 4.x. */
99 /* Carry information from ASM_DECLARE_OBJECT_NAME
100 to ASM_FINISH_DECLARE_OBJECT. */
102 extern int size_directive_output;
103 extern tree last_assemble_variable_decl;
105 extern void reg_alloc (void);
107 static void general_init (const char *);
108 static void do_compile (void);
109 static void process_options (void);
110 static void backend_init (void);
111 static int lang_dependent_init (const char *);
112 static void init_asm_output (const char *);
113 static void finalize (void);
115 static void crash_signal (int) ATTRIBUTE_NORETURN;
116 static void setup_core_dumping (void);
117 static void compile_file (void);
119 static int print_single_switch (FILE *, int, int, const char *,
120 const char *, const char *,
121 const char *, const char *);
122 static void print_switch_values (FILE *, int, int, const char *,
123 const char *, const char *);
125 /* Rest of compilation helper functions. */
126 static bool rest_of_handle_inlining (tree);
127 static rtx rest_of_handle_ssa (tree, rtx);
128 static void rest_of_handle_cse (tree, rtx);
129 static void rest_of_handle_cse2 (tree, rtx);
130 static void rest_of_handle_gcse (tree, rtx);
131 static void rest_of_handle_life (tree, rtx);
132 static void rest_of_handle_loop_optimize (tree, rtx);
133 static void rest_of_handle_loop2 (tree, rtx);
134 static void rest_of_handle_jump_bypass (tree, rtx);
135 static void rest_of_handle_sibling_calls (rtx);
136 static void rest_of_handle_null_pointer (tree, rtx);
137 static void rest_of_handle_addressof (tree, rtx);
138 static void rest_of_handle_cfg (tree, rtx);
139 static void rest_of_handle_branch_prob (tree, rtx);
140 static void rest_of_handle_if_conversion (tree, rtx);
141 static void rest_of_handle_if_after_combine (tree, rtx);
142 static void rest_of_handle_tracer (tree, rtx);
143 static void rest_of_handle_combine (tree, rtx);
144 static void rest_of_handle_regmove (tree, rtx);
145 #ifdef INSN_SCHEDULING
146 static void rest_of_handle_sched (tree, rtx);
147 static void rest_of_handle_sched2 (tree, rtx);
149 static bool rest_of_handle_new_regalloc (tree, rtx, int *);
150 static bool rest_of_handle_old_regalloc (tree, rtx, int *);
151 static void rest_of_handle_regrename (tree, rtx);
152 static void rest_of_handle_reorder_blocks (tree, rtx);
154 static void rest_of_handle_stack_regs (tree, rtx);
156 static void rest_of_handle_machine_reorg (tree, rtx);
158 static void rest_of_handle_delay_slots (tree, rtx);
160 static void rest_of_handle_final (tree, rtx);
162 /* Nonzero to dump debug info whilst parsing (-dy option). */
163 static int set_yydebug;
165 /* True if we don't need a backend (e.g. preprocessing only). */
166 static bool no_backend;
168 /* Length of line when printing switch values. */
171 /* Name of program invoked, sans directories. */
173 const char *progname;
175 /* Copy of argument vector to toplev_main. */
176 static const char **save_argv;
178 /* Name of top-level original source file (what was input to cpp).
179 This comes from the #-command at the beginning of the actual input.
180 If there isn't any there, then this is the cc1 input file name. */
182 const char *main_input_filename;
184 /* Current position in real source file. */
186 location_t input_location;
188 /* Nonzero if it is unsafe to create any new pseudo registers. */
191 /* Stack of currently pending input files. */
193 struct file_stack *input_file_stack;
195 /* Incremented on each change to input_file_stack. */
196 int input_file_stack_tick;
198 /* Name to use as base of names for dump output files. */
200 const char *dump_base_name;
202 /* Name to use as a base for auxiliary output files. */
204 const char *aux_base_name;
206 /* Format to use to print dumpfile index value */
207 #ifndef DUMPFILE_FORMAT
208 #define DUMPFILE_FORMAT ".%02d."
211 /* Bit flags that specify the machine subtype we are compiling for.
212 Bits are tested using macros TARGET_... defined in the tm.h file
213 and set by `-m...' switches. Must be defined in rtlanal.c. */
215 extern int target_flags;
217 /* A mask of target_flags that includes bit X if X was set or cleared
218 on the command line. */
220 int target_flags_explicit;
222 /* Debug hooks - dependent upon command line options. */
224 const struct gcc_debug_hooks *debug_hooks;
226 /* Describes a dump file. */
228 struct dump_file_info
230 /* The unique extension to apply, e.g. ".jump". */
231 const char *const extension;
233 /* The -d<c> character that enables this dump file. */
234 char const debug_switch;
236 /* True if there is a corresponding graph dump file. */
237 char const graph_dump_p;
239 /* True if the user selected this dump. */
242 /* True if the files have been initialized (ie truncated). */
246 /* Enumerate the extant dump files. */
285 DFI_branch_target_load,
293 /* Describes all the dump files. Should be kept in order of the
294 pass and in sync with dump_file_index above.
296 Remaining -d letters:
302 static struct dump_file_info dump_file[DFI_MAX] =
304 { "cgraph", 'U', 0, 0, 0 },
305 { "rtl", 'r', 0, 0, 0 },
306 { "sibling", 'i', 0, 0, 0 },
307 { "eh", 'h', 0, 0, 0 },
308 { "jump", 'j', 0, 0, 0 },
309 { "ssa", 'e', 1, 0, 0 },
310 { "ssaccp", 'W', 1, 0, 0 },
311 { "ssadce", 'X', 1, 0, 0 },
312 { "ussa", 'e', 1, 0, 0 }, /* Yes, duplicate enable switch. */
313 { "null", 'u', 0, 0, 0 },
314 { "cse", 's', 0, 0, 0 },
315 { "addressof", 'F', 0, 0, 0 },
316 { "gcse", 'G', 1, 0, 0 },
317 { "loop", 'L', 1, 0, 0 },
318 { "bypass", 'G', 1, 0, 0 }, /* Yes, duplicate enable switch. */
319 { "cfg", 'f', 1, 0, 0 },
320 { "bp", 'b', 1, 0, 0 },
321 { "ce1", 'C', 1, 0, 0 },
322 { "tracer", 'T', 1, 0, 0 },
323 { "web", 'Z', 0, 0, 0 },
324 { "loop2", 'L', 1, 0, 0 },
325 { "cse2", 't', 1, 0, 0 },
326 { "life", 'f', 1, 0, 0 }, /* Yes, duplicate enable switch. */
327 { "combine", 'c', 1, 0, 0 },
328 { "ce2", 'C', 1, 0, 0 },
329 { "regmove", 'N', 1, 0, 0 },
330 { "sched", 'S', 1, 0, 0 },
331 { "lreg", 'l', 1, 0, 0 },
332 { "greg", 'g', 1, 0, 0 },
333 { "postreload", 'o', 1, 0, 0 },
334 { "flow2", 'w', 1, 0, 0 },
335 { "peephole2", 'z', 1, 0, 0 },
336 { "rnreg", 'n', 1, 0, 0 },
337 { "bbro", 'B', 1, 0, 0 },
338 { "ce3", 'E', 1, 0, 0 },
339 { "btl", 'd', 1, 0, 0 }, /* Yes, duplicate enable switch. */
340 { "sched2", 'R', 1, 0, 0 },
341 { "stack", 'k', 1, 0, 0 },
342 { "mach", 'M', 1, 0, 0 },
343 { "dbr", 'd', 0, 0, 0 },
346 static int open_dump_file (enum dump_file_index, tree);
347 static void close_dump_file (enum dump_file_index,
348 void (*) (FILE *, rtx), rtx);
350 /* Other flags saying which kinds of debugging dump have been requested. */
352 int rtl_dump_and_exit;
353 int flag_print_asm_name;
354 enum graph_dump_types graph_dump_format;
356 /* Name for output file of assembly code, specified with -o. */
358 const char *asm_file_name;
360 /* Nonzero means do optimizations. -O.
361 Particular numeric values stand for particular amounts of optimization;
362 thus, -O2 stores 2 here. However, the optimizations beyond the basic
363 ones are not controlled directly by this variable. Instead, they are
364 controlled by individual `flag_...' variables that are defaulted
365 based on this variable. */
369 /* Nonzero means optimize for size. -Os.
370 The only valid values are zero and nonzero. When optimize_size is
371 nonzero, optimize defaults to 2, but certain individual code
372 bloating optimizations are disabled. */
374 int optimize_size = 0;
376 /* The FUNCTION_DECL for the function currently being compiled,
377 or 0 if between functions. */
378 tree current_function_decl;
380 /* Set to the FUNC_BEGIN label of the current function, or NULL_TREE
382 tree current_function_func_begin_label;
384 /* Nonzero if doing dwarf2 duplicate elimination. */
386 int flag_eliminate_dwarf2_dups = 0;
388 /* Nonzero if doing unused type elimination. */
390 int flag_eliminate_unused_debug_types = 1;
392 /* Nonzero means emit debugging information only for symbols which are used. */
393 int flag_debug_only_used_symbols = 0;
395 /* Nonzero if generating code to do profiling. */
397 int profile_flag = 0;
399 /* Nonzero if generating code to profile program flow graph arcs. */
401 int profile_arc_flag = 0;
403 /* Nonzero if value histograms should be measured. */
405 int flag_profile_values = 0;
407 /* Nonzero if generating info for gcov to calculate line test coverage. */
409 int flag_test_coverage = 0;
411 /* Nonzero indicates that branch taken probabilities should be calculated. */
413 int flag_branch_probabilities = 0;
415 /* Nonzero if basic blocks should be reordered. */
417 int flag_reorder_blocks = 0;
419 /* Nonzero if functions should be reordered. */
421 int flag_reorder_functions = 0;
423 /* Nonzero if registers should be renamed. */
425 int flag_rename_registers = 0;
426 int flag_cprop_registers = 0;
428 /* Nonzero for -pedantic switch: warn about anything
429 that standard spec forbids. */
433 /* Temporarily suppress certain warnings.
434 This is set while reading code from a system header file. */
436 int in_system_header = 0;
438 /* Don't print functions as they are compiled. -quiet. */
442 /* Print times taken by the various passes. -ftime-report. */
446 /* Print memory still in use at end of compilation (which may have little
447 to do with peak memory consumption). -fmem-report. */
451 /* Nonzero means to collect statistics which might be expensive
452 and to print them when we are done. */
453 int flag_detailed_statistics = 0;
455 /* A random sequence of characters, unless overridden by user. */
456 const char *flag_random_seed;
458 /* A local time stamp derived from the time of compilation. It will be
459 zero if the system cannot provide a time. It will be -1u, if the
460 user has specified a particular random seed. */
465 /* Nonzero means `char' should be signed. */
467 int flag_signed_char;
469 /* Nonzero means give an enum type only as many bytes as it needs. */
471 int flag_short_enums;
473 /* Nonzero for -fcaller-saves: allocate values in regs that need to
474 be saved across function calls, if that produces overall better code.
475 Optional now, so people can test it. */
477 #ifdef DEFAULT_CALLER_SAVES
478 int flag_caller_saves = 1;
480 int flag_caller_saves = 0;
483 /* Nonzero if structures and unions should be returned in memory.
485 This should only be defined if compatibility with another compiler or
486 with an ABI is needed, because it results in slower code. */
488 #ifndef DEFAULT_PCC_STRUCT_RETURN
489 #define DEFAULT_PCC_STRUCT_RETURN 1
492 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
494 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
496 /* Nonzero for -fforce-mem: load memory value into a register
497 before arithmetic on it. This makes better cse but slower compilation. */
499 int flag_force_mem = 0;
501 /* Nonzero for -fforce-addr: load memory address into a register before
502 reference to memory. This makes better cse but slower compilation. */
504 int flag_force_addr = 0;
506 /* Nonzero for -fdefer-pop: don't pop args after each function call;
507 instead save them up to pop many calls' args with one insns. */
509 int flag_defer_pop = 0;
511 /* Nonzero for -ffloat-store: don't allocate floats and doubles
512 in extended-precision registers. */
514 int flag_float_store = 0;
516 /* Nonzero for -fcse-follow-jumps:
517 have cse follow jumps to do a more extensive job. */
519 int flag_cse_follow_jumps;
521 /* Nonzero for -fcse-skip-blocks:
522 have cse follow a branch around a block. */
523 int flag_cse_skip_blocks;
525 /* Nonzero for -fexpensive-optimizations:
526 perform miscellaneous relatively-expensive optimizations. */
527 int flag_expensive_optimizations;
529 /* Nonzero for -fthread-jumps:
530 have jump optimize output of loop. */
532 int flag_thread_jumps;
534 /* Nonzero enables strength-reduction in loop.c. */
536 int flag_strength_reduce = 0;
538 /* Nonzero enables loop unrolling in unroll.c. Only loops for which the
539 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
540 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
543 int flag_old_unroll_loops;
545 /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
546 This is generally not a win. */
548 int flag_old_unroll_all_loops;
550 /* Enables unrolling of simple loops in loop-unroll.c. */
551 int flag_unroll_loops;
553 /* Enables unrolling of all loops in loop-unroll.c. */
554 int flag_unroll_all_loops;
556 /* Nonzero enables loop peeling. */
559 /* Nonzero enables loop unswitching. */
560 int flag_unswitch_loops;
562 /* Nonzero enables prefetch optimizations for arrays in loops. */
564 int flag_prefetch_loop_arrays;
566 /* Nonzero forces all invariant computations in loops to be moved
569 int flag_move_all_movables = 0;
571 /* Nonzero forces all general induction variables in loops to be
574 int flag_reduce_all_givs = 0;
576 /* Nonzero to perform full register move optimization passes. This is the
579 int flag_regmove = 0;
581 /* Nonzero for -fwritable-strings:
582 store string constants in data segment and don't uniquize them. */
584 int flag_writable_strings = 0;
586 /* Nonzero means don't put addresses of constant functions in registers.
587 Used for compiling the Unix kernel, where strange substitutions are
588 done on the assembly output. */
590 int flag_no_function_cse = 0;
592 /* Nonzero for -fomit-frame-pointer:
593 don't make a frame pointer in simple functions that don't require one. */
595 int flag_omit_frame_pointer = 0;
597 /* Nonzero means place each function into its own section on those platforms
598 which support arbitrary section names and unlimited numbers of sections. */
600 int flag_function_sections = 0;
602 /* ... and similar for data. */
604 int flag_data_sections = 0;
606 /* Nonzero to inhibit use of define_optimization peephole opts. */
608 int flag_no_peephole = 0;
610 /* Nonzero allows GCC to optimize sibling and tail recursive calls. */
612 int flag_optimize_sibling_calls = 0;
614 /* Nonzero means the front end generally wants `errno' maintained by math
615 operations, like built-in SQRT. */
617 int flag_errno_math = 1;
619 /* Nonzero means that unsafe floating-point math optimizations are allowed
620 for the sake of speed. IEEE compliance is not guaranteed, and operations
621 are allowed to assume that their arguments and results are "normal"
622 (e.g., nonnegative for SQRT). */
624 int flag_unsafe_math_optimizations = 0;
626 /* Nonzero means that no NaNs or +-Infs are expected. */
628 int flag_finite_math_only = 0;
630 /* Zero means that floating-point math operations cannot generate a
631 (user-visible) trap. This is the case, for example, in nonstop
632 IEEE 754 arithmetic. Trapping conditions include division by zero,
633 overflow, underflow, invalid and inexact, but does not include
634 operations on signaling NaNs (see below). */
636 int flag_trapping_math = 1;
638 /* Nonzero means disable transformations that assume default floating
639 point rounding behavior. */
641 int flag_rounding_math = 0;
643 /* Nonzero means disable transformations observable by signaling NaNs.
644 This option implies that any operation on an IEEE signaling NaN can
645 generate a (user-visible) trap. */
647 int flag_signaling_nans = 0;
649 /* 0 means straightforward implementation of complex divide acceptable.
650 1 means wide ranges of inputs must work for complex divide.
651 2 means C99-like requirements for complex divide (not yet implemented). */
653 int flag_complex_divide_method = 0;
655 /* Nonzero means just do syntax checking; don't output anything. */
657 int flag_syntax_only = 0;
659 /* Nonzero means performs web construction pass. */
663 /* Nonzero means perform loop optimizer. */
665 int flag_loop_optimize;
667 /* Nonzero means perform crossjumping. */
669 int flag_crossjumping;
671 /* Nonzero means perform if conversion. */
673 int flag_if_conversion;
675 /* Nonzero means perform if conversion after reload. */
677 int flag_if_conversion2;
679 /* Nonzero means to use global dataflow analysis to eliminate
680 useless null pointer tests. */
682 int flag_delete_null_pointer_checks;
684 /* Nonzero means perform global CSE. */
688 /* Nonzero means to do the enhanced load motion during gcse, which trys
689 to hoist loads by not killing them when a store to the same location
692 int flag_gcse_lm = 1;
694 /* Nonzero means to perform store motion after gcse, which will try to
695 move stores closer to the exit block. Its not very effective without
698 int flag_gcse_sm = 1;
700 /* Perform target register optimization before prologue / epilogue
703 int flag_branch_target_load_optimize = 0;
705 /* Perform target register optimization after prologue / epilogue
706 threading and jump2. */
708 int flag_branch_target_load_optimize2 = 0;
710 /* Nonzero means to rerun cse after loop optimization. This increases
711 compilation time about 20% and picks up a few more common expressions. */
713 int flag_rerun_cse_after_loop;
715 /* Nonzero means to run loop optimizations twice. */
717 int flag_rerun_loop_opt;
719 /* Nonzero for -finline-functions: ok to inline functions that look like
720 good inline candidates. */
722 int flag_inline_functions;
724 /* Nonzero for -fkeep-inline-functions: even if we make a function
725 go inline everywhere, keep its definition around for debugging
728 int flag_keep_inline_functions;
730 /* Nonzero means that functions will not be inlined. */
732 int flag_no_inline = 2;
734 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
735 not just because the tree inliner turned us off. */
737 int flag_really_no_inline = 2;
739 /* Nonzero means that we should emit static const variables
740 regardless of whether or not optimization is turned on. */
742 int flag_keep_static_consts = 1;
744 /* Nonzero means we should be saving declaration info into a .X file. */
746 int flag_gen_aux_info = 0;
748 /* Specified name of aux-info file. */
750 const char *aux_info_file_name;
752 /* Nonzero means make the text shared if supported. */
754 int flag_shared_data;
756 /* Nonzero means schedule into delayed branch slots if supported. */
758 int flag_delayed_branch;
760 /* Nonzero if we are compiling pure (sharable) code.
761 Value is 1 if we are doing "small" pic; value is 2 if we're doing
766 /* Nonzero if we are compiling position independent code for executable.
767 The value is 1 if we are doing "small" pic; value is 2 if we're doing
772 /* Nonzero if we are compiling code for a shared library, zero for
777 /* Set to the default thread-local storage (tls) model to use. */
779 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
781 /* Nonzero means generate extra code for exception handling and enable
782 exception handling. */
786 /* Nonzero means generate frame unwind info table when supported. */
788 int flag_unwind_tables = 0;
790 /* Nonzero means generate frame unwind info table exact at each insn
793 int flag_asynchronous_unwind_tables = 0;
795 /* Nonzero means don't place uninitialized global data in common storage
800 /* Nonzero means change certain warnings into errors.
801 Usually these are warnings about failure to conform to some standard. */
803 int flag_pedantic_errors = 0;
805 /* flag_schedule_insns means schedule insns within basic blocks (before
807 flag_schedule_insns_after_reload means schedule insns after
810 int flag_schedule_insns = 0;
811 int flag_schedule_insns_after_reload = 0;
813 /* When flag_schedule_insns_after_reload is set, use EBB scheduler. */
814 int flag_sched2_use_superblocks = 0;
816 /* When flag_schedule_insns_after_reload is set, construct traces and EBB
818 int flag_sched2_use_traces = 0;
820 /* The following flags have effect only for scheduling before register
823 flag_schedule_interblock means schedule insns across basic blocks.
824 flag_schedule_speculative means allow speculative motion of non-load insns.
825 flag_schedule_speculative_load means allow speculative motion of some
827 flag_schedule_speculative_load_dangerous allows speculative motion of more
830 int flag_schedule_interblock = 1;
831 int flag_schedule_speculative = 1;
832 int flag_schedule_speculative_load = 0;
833 int flag_schedule_speculative_load_dangerous = 0;
835 /* The following flags have an effect during scheduling after register
838 flag_sched_stalled_insns means that insns can be moved prematurely from the queue
839 of stalled insns into the ready list.
841 flag_sched_stalled_insns_dep controls how many insn groups will be examined
842 for a dependency on a stalled insn that is candidate for premature removal
843 from the queue of stalled insns into the ready list (has an effect only if
844 the flag 'sched_stalled_insns' is set). */
846 int flag_sched_stalled_insns = 0;
847 int flag_sched_stalled_insns_dep = 1;
849 int flag_single_precision_constant;
851 /* flag_branch_on_count_reg means try to replace add-1,compare,branch tupple
852 by a cheaper branch on a count register. */
853 int flag_branch_on_count_reg = 1;
855 /* -finhibit-size-directive inhibits output of .size for ELF.
856 This is used only for compiling crtstuff.c,
857 and it may be extended to other effects
858 needed for crtstuff.c on other systems. */
859 int flag_inhibit_size_directive = 0;
861 /* -fverbose-asm causes extra commentary information to be produced in
862 the generated assembly code (to make it more readable). This option
863 is generally only of use to those who actually need to read the
864 generated assembly code (perhaps while debugging the compiler itself).
865 -fno-verbose-asm, the default, causes the extra information
866 to be omitted and is useful when comparing two assembler files. */
868 int flag_verbose_asm = 0;
870 /* -dA causes debug commentary information to be produced in
871 the generated assembly code (to make it more readable). This option
872 is generally only of use to those who actually need to read the
873 generated assembly code (perhaps while debugging the compiler itself).
874 Currently, this switch is only used by dwarfout.c; however, it is intended
875 to be a catchall for printing debug information in the assembler file. */
877 int flag_debug_asm = 0;
879 /* -dP causes the rtl to be emitted as a comment in assembly. */
881 int flag_dump_rtl_in_asm = 0;
883 /* -fgnu-linker specifies use of the GNU linker for initializations.
884 (Or, more generally, a linker that handles initializations.)
885 -fno-gnu-linker says that collect2 will be used. */
887 int flag_gnu_linker = 0;
889 int flag_gnu_linker = 1;
892 /* Nonzero means put zero initialized data in the bss section. */
893 int flag_zero_initialized_in_bss = 1;
898 /* Enable ssa conditional constant propagation. */
899 int flag_ssa_ccp = 0;
901 /* Enable ssa aggressive dead code elimination. */
902 int flag_ssa_dce = 0;
904 /* Tag all structures with __attribute__(packed). */
905 int flag_pack_struct = 0;
907 /* Emit code to check for stack overflow; also may cause large objects
908 to be allocated dynamically. */
909 int flag_stack_check;
911 /* When non-NULL, indicates that whenever space is allocated on the
912 stack, the resulting stack pointer must not pass this
913 address---that is, for stacks that grow downward, the stack pointer
914 must always be greater than or equal to this address; for stacks
915 that grow upward, the stack pointer must be less than this address.
916 At present, the rtx may be either a REG or a SYMBOL_REF, although
917 the support provided depends on the backend. */
920 /* 0 if pointer arguments may alias each other. True in C.
921 1 if pointer arguments may not alias each other but may alias
923 2 if pointer arguments may not alias each other and may not
924 alias global variables. True in Fortran.
925 This defaults to 0 for C. */
926 int flag_argument_noalias = 0;
928 /* Nonzero if we should do (language-dependent) alias analysis.
929 Typically, this analysis will assume that expressions of certain
930 types do not alias expressions of certain other types. Only used
931 if alias analysis (in general) is enabled. */
932 int flag_strict_aliasing = 0;
934 /* Instrument functions with calls at entry and exit, for profiling. */
935 int flag_instrument_function_entry_exit = 0;
937 /* Nonzero means ignore `#ident' directives. 0 means handle them.
938 On SVR4 targets, it also controls whether or not to emit a
939 string identifying the compiler. */
941 int flag_no_ident = 0;
943 /* This will perform a peephole pass before sched2. */
944 int flag_peephole2 = 0;
946 /* This will try to guess branch probabilities. */
947 int flag_guess_branch_prob = 0;
949 /* -fcheck-bounds causes gcc to generate array bounds checks.
950 For C, C++, ObjC: defaults to off.
951 For Java: defaults to on.
952 For Fortran: defaults to off. */
953 int flag_bounds_check = 0;
955 /* This will attempt to merge constant section constants, if 1 only
956 string constants and constants from constant pool, if 2 also constant
958 int flag_merge_constants = 1;
960 /* If one, renumber instruction UIDs to reduce the number of
961 unused UIDs if there are a lot of instructions. If greater than
962 one, unconditionally renumber instruction UIDs. */
963 int flag_renumber_insns = 1;
965 /* If nonzero, use the graph coloring register allocator. */
966 int flag_new_regalloc = 0;
968 /* Nonzero if we perform superblock formation. */
972 /* Nonzero if we perform whole unit at a time compilation. */
974 int flag_unit_at_a_time = 0;
976 /* Values of the -falign-* flags: how much to align labels in code.
977 0 means `use default', 1 means `don't align'.
978 For each variable, there is an _log variant which is the power
979 of two not less than the variable, for .align output. */
983 int align_loops_max_skip;
986 int align_jumps_max_skip;
988 int align_labels_log;
989 int align_labels_max_skip;
991 int align_functions_log;
993 /* Like align_functions_log above, but used by front-ends to force the
994 minimum function alignment. Zero means no alignment is forced. */
995 int force_align_functions_log;
999 const char *const string;
1000 int *const variable;
1003 lang_independent_options;
1005 /* Nonzero if signed arithmetic overflow should trap. */
1008 /* Nonzero if signed arithmetic overflow should wrap around. */
1011 /* Nonzero if subexpressions must be evaluated from left-to-right. */
1012 int flag_evaluation_order = 0;
1014 /* Add or remove a leading underscore from user symbols. */
1015 int flag_leading_underscore = -1;
1017 /* The user symbol prefix after having resolved same. */
1018 const char *user_label_prefix;
1020 static const param_info lang_independent_params[] = {
1021 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT) \
1022 { OPTION, DEFAULT, HELP },
1023 #include "params.def"
1028 /* Table of language-independent -f options.
1029 STRING is the option name. VARIABLE is the address of the variable.
1030 ON_VALUE is the value to store in VARIABLE
1031 if `-fSTRING' is seen as an option.
1032 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
1034 static const lang_independent_options f_options[] =
1036 {"eliminate-dwarf2-dups", &flag_eliminate_dwarf2_dups, 1 },
1037 {"eliminate-unused-debug-symbols", &flag_debug_only_used_symbols, 1 },
1038 {"eliminate-unused-debug-types", &flag_eliminate_unused_debug_types, 1 },
1039 {"float-store", &flag_float_store, 1 },
1040 {"defer-pop", &flag_defer_pop, 1 },
1041 {"omit-frame-pointer", &flag_omit_frame_pointer, 1 },
1042 {"optimize-sibling-calls", &flag_optimize_sibling_calls, 1 },
1043 {"tracer", &flag_tracer, 1 },
1044 {"unit-at-a-time", &flag_unit_at_a_time, 1 },
1045 {"cse-follow-jumps", &flag_cse_follow_jumps, 1 },
1046 {"cse-skip-blocks", &flag_cse_skip_blocks, 1 },
1047 {"expensive-optimizations", &flag_expensive_optimizations, 1 },
1048 {"thread-jumps", &flag_thread_jumps, 1 },
1049 {"strength-reduce", &flag_strength_reduce, 1 },
1050 {"unroll-loops", &flag_unroll_loops, 1 },
1051 {"unroll-all-loops", &flag_unroll_all_loops, 1 },
1052 {"old-unroll-loops", &flag_old_unroll_loops, 1 },
1053 {"old-unroll-all-loops", &flag_old_unroll_all_loops, 1 },
1054 {"peel-loops", &flag_peel_loops, 1 },
1055 {"unswitch-loops", &flag_unswitch_loops, 1 },
1056 {"prefetch-loop-arrays", &flag_prefetch_loop_arrays, 1 },
1057 {"move-all-movables", &flag_move_all_movables, 1 },
1058 {"reduce-all-givs", &flag_reduce_all_givs, 1 },
1059 {"writable-strings", &flag_writable_strings, 1 },
1060 {"peephole", &flag_no_peephole, 0 },
1061 {"force-mem", &flag_force_mem, 1 },
1062 {"force-addr", &flag_force_addr, 1 },
1063 {"function-cse", &flag_no_function_cse, 0 },
1064 {"inline-functions", &flag_inline_functions, 1 },
1065 {"keep-inline-functions", &flag_keep_inline_functions, 1 },
1066 {"inline", &flag_no_inline, 0 },
1067 {"keep-static-consts", &flag_keep_static_consts, 1 },
1068 {"syntax-only", &flag_syntax_only, 1 },
1069 {"shared-data", &flag_shared_data, 1 },
1070 {"caller-saves", &flag_caller_saves, 1 },
1071 {"pcc-struct-return", &flag_pcc_struct_return, 1 },
1072 {"reg-struct-return", &flag_pcc_struct_return, 0 },
1073 {"delayed-branch", &flag_delayed_branch, 1 },
1074 {"web", &flag_web, 1},
1075 {"gcse", &flag_gcse, 1 },
1076 {"gcse-lm", &flag_gcse_lm, 1 },
1077 {"gcse-sm", &flag_gcse_sm, 1 },
1078 {"branch-target-load-optimize", &flag_branch_target_load_optimize, 1 },
1079 {"branch-target-load-optimize2", &flag_branch_target_load_optimize2, 1 },
1080 {"loop-optimize", &flag_loop_optimize, 1 },
1081 {"crossjumping", &flag_crossjumping, 1 },
1082 {"if-conversion", &flag_if_conversion, 1 },
1083 {"if-conversion2", &flag_if_conversion2, 1 },
1084 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1 },
1085 {"rerun-loop-opt", &flag_rerun_loop_opt, 1 },
1086 {"delete-null-pointer-checks", &flag_delete_null_pointer_checks, 1 },
1087 {"schedule-insns", &flag_schedule_insns, 1 },
1088 {"schedule-insns2", &flag_schedule_insns_after_reload, 1 },
1089 {"sched-interblock",&flag_schedule_interblock, 1 },
1090 {"sched-spec",&flag_schedule_speculative, 1 },
1091 {"sched-spec-load",&flag_schedule_speculative_load, 1 },
1092 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1 },
1093 {"sched-stalled-insns", &flag_sched_stalled_insns, 0 },
1094 {"sched-stalled-insns-dep", &flag_sched_stalled_insns_dep, 1 },
1095 {"sched2-use-superblocks", &flag_sched2_use_superblocks, 1 },
1096 {"sched2-use-traces", &flag_sched2_use_traces, 1 },
1097 {"branch-count-reg",&flag_branch_on_count_reg, 1 },
1098 {"pic", &flag_pic, 1 },
1099 {"PIC", &flag_pic, 2 },
1100 {"pie", &flag_pie, 1 },
1101 {"PIE", &flag_pie, 2 },
1102 {"exceptions", &flag_exceptions, 1 },
1103 {"unwind-tables", &flag_unwind_tables, 1 },
1104 {"asynchronous-unwind-tables", &flag_asynchronous_unwind_tables, 1 },
1105 {"non-call-exceptions", &flag_non_call_exceptions, 1 },
1106 {"profile-arcs", &profile_arc_flag, 1 },
1107 {"test-coverage", &flag_test_coverage, 1 },
1108 {"branch-probabilities", &flag_branch_probabilities, 1 },
1109 {"profile", &profile_flag, 1 },
1110 {"reorder-blocks", &flag_reorder_blocks, 1 },
1111 {"reorder-functions", &flag_reorder_functions, 1 },
1112 {"rename-registers", &flag_rename_registers, 1 },
1113 {"cprop-registers", &flag_cprop_registers, 1 },
1114 {"common", &flag_no_common, 0 },
1115 {"inhibit-size-directive", &flag_inhibit_size_directive, 1 },
1116 {"function-sections", &flag_function_sections, 1 },
1117 {"data-sections", &flag_data_sections, 1 },
1118 {"verbose-asm", &flag_verbose_asm, 1 },
1119 {"gnu-linker", &flag_gnu_linker, 1 },
1120 {"regmove", &flag_regmove, 1 },
1121 {"optimize-register-move", &flag_regmove, 1 },
1122 {"pack-struct", &flag_pack_struct, 1 },
1123 {"stack-check", &flag_stack_check, 1 },
1124 {"argument-alias", &flag_argument_noalias, 0 },
1125 {"argument-noalias", &flag_argument_noalias, 1 },
1126 {"argument-noalias-global", &flag_argument_noalias, 2 },
1127 {"strict-aliasing", &flag_strict_aliasing, 1 },
1128 {"align-loops", &align_loops, 0 },
1129 {"align-jumps", &align_jumps, 0 },
1130 {"align-labels", &align_labels, 0 },
1131 {"align-functions", &align_functions, 0 },
1132 {"merge-constants", &flag_merge_constants, 1 },
1133 {"merge-all-constants", &flag_merge_constants, 2 },
1134 {"dump-unnumbered", &flag_dump_unnumbered, 1 },
1135 {"instrument-functions", &flag_instrument_function_entry_exit, 1 },
1136 {"zero-initialized-in-bss", &flag_zero_initialized_in_bss, 1 },
1137 {"ssa", &flag_ssa, 1 },
1138 {"ssa-ccp", &flag_ssa_ccp, 1 },
1139 {"ssa-dce", &flag_ssa_dce, 1 },
1140 {"leading-underscore", &flag_leading_underscore, 1 },
1141 {"ident", &flag_no_ident, 0 },
1142 { "peephole2", &flag_peephole2, 1 },
1143 {"finite-math-only", &flag_finite_math_only, 1 },
1144 { "guess-branch-probability", &flag_guess_branch_prob, 1 },
1145 {"math-errno", &flag_errno_math, 1 },
1146 {"trapping-math", &flag_trapping_math, 1 },
1147 {"rounding-math", &flag_rounding_math, 1 },
1148 {"unsafe-math-optimizations", &flag_unsafe_math_optimizations, 1 },
1149 {"signaling-nans", &flag_signaling_nans, 1 },
1150 {"bounds-check", &flag_bounds_check, 1 },
1151 {"single-precision-constant", &flag_single_precision_constant, 1 },
1152 {"time-report", &time_report, 1 },
1153 {"mem-report", &mem_report, 1 },
1154 { "trapv", &flag_trapv, 1 },
1155 { "wrapv", &flag_wrapv, 1 },
1156 { "new-ra", &flag_new_regalloc, 1 }
1159 /* Here is a table, controlled by the tm.h file, listing each -m switch
1160 and which bits in `target_switches' it should set or clear.
1161 If VALUE is positive, it is bits to set.
1162 If VALUE is negative, -VALUE is bits to clear.
1163 (The sign bit is not used so there is no confusion.) */
1167 const char *const name;
1169 const char *const description;
1171 target_switches[] = TARGET_SWITCHES;
1173 /* This table is similar, but allows the switch to have a value. */
1175 #ifdef TARGET_OPTIONS
1178 const char *const prefix;
1179 const char **const variable;
1180 const char *const description;
1181 const char *const value;
1183 target_options[] = TARGET_OPTIONS;
1186 /* Nonzero means warn about function definitions that default the return type
1187 or that use a null return and have a return-type other than void. */
1189 int warn_return_type;
1191 /* Output files for assembler code (real compiler output)
1192 and debugging dumps. */
1195 FILE *aux_info_file;
1196 FILE *rtl_dump_file = NULL;
1197 FILE *cgraph_dump_file = NULL;
1199 /* The current working directory of a translation. It's generally the
1200 directory from which compilation was initiated, but a preprocessed
1201 file may specify the original directory in which it was
1204 static const char *src_pwd;
1206 /* Initialize src_pwd with the given string, and return true. If it
1207 was already initialized, return false. As a special case, it may
1208 be called with a NULL argument to test whether src_pwd has NOT been
1212 set_src_pwd (const char *pwd)
1217 src_pwd = xstrdup (pwd);
1221 /* Return the directory from which the translation unit was initiated,
1222 in case set_src_pwd() was not called before to assign it a
1229 src_pwd = getpwd ();
1234 /* Called when the start of a function definition is parsed,
1235 this function prints on stderr the name of the function. */
1237 announce_function (tree decl)
1241 if (rtl_dump_and_exit)
1242 verbatim ("%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1244 verbatim (" %s", (*lang_hooks.decl_printable_name) (decl, 2));
1246 pp_needs_newline (global_dc->printer) = true;
1247 diagnostic_set_last_function (global_dc);
1251 /* Set up a default flag_random_seed and local_tick, unless the user
1252 already specified one. */
1257 if (!flag_random_seed)
1259 unsigned HOST_WIDE_INT value;
1260 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
1262 /* Get some more or less random data. */
1263 #ifdef HAVE_GETTIMEOFDAY
1267 gettimeofday (&tv, NULL);
1268 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
1272 time_t now = time (NULL);
1274 if (now != (time_t)-1)
1275 local_tick = (unsigned) now;
1278 value = local_tick ^ getpid ();
1280 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
1281 flag_random_seed = random_seed;
1283 else if (!local_tick)
1288 /* Decode the string P as an integral parameter.
1289 If the string is indeed an integer return its numeric value else
1290 issue an Invalid Option error for the option PNAME and return DEFVAL.
1291 If PNAME is zero just return DEFVAL, do not call error. */
1294 read_integral_parameter (const char *p, const char *pname, const int defval)
1296 const char *endp = p;
1300 if (ISDIGIT (*endp))
1309 error ("invalid option argument `%s'", pname);
1316 /* Return the logarithm of X, base 2, considering X unsigned,
1317 if X is a power of 2. Otherwise, returns -1.
1319 This should be used via the `exact_log2' macro. */
1322 exact_log2_wide (unsigned HOST_WIDE_INT x)
1325 /* Test for 0 or a power of 2. */
1326 if (x == 0 || x != (x & -x))
1328 while ((x >>= 1) != 0)
1333 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1334 If X is 0, return -1.
1336 This should be used via the floor_log2 macro. */
1339 floor_log2_wide (unsigned HOST_WIDE_INT x)
1348 /* Handler for fatal signals, such as SIGSEGV. These are transformed
1349 into ICE messages, which is much more user friendly. In case the
1350 error printer crashes, reset the signal to prevent infinite recursion. */
1353 crash_signal (int signo)
1355 signal (signo, SIG_DFL);
1356 internal_error ("%s", strsignal (signo));
1359 /* Arrange to dump core on error. (The regular error message is still
1360 printed first, except in the case of abort().) */
1363 setup_core_dumping (void)
1366 signal (SIGABRT, SIG_DFL);
1368 #if defined(HAVE_SETRLIMIT)
1371 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
1372 fatal_error ("getting core file size maximum limit: %m");
1373 rlim.rlim_cur = rlim.rlim_max;
1374 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
1375 fatal_error ("setting core file size limit to maximum: %m");
1378 diagnostic_abort_on_error (global_dc);
1382 /* Strip off a legitimate source ending from the input string NAME of
1383 length LEN. Rather than having to know the names used by all of
1384 our front ends, we strip off an ending of a period followed by
1385 up to five characters. (Java uses ".class".) */
1388 strip_off_ending (char *name, int len)
1391 for (i = 2; i < 6 && len > i; i++)
1393 if (name[len - i] == '.')
1395 name[len - i] = '\0';
1401 /* Output a quoted string. */
1404 output_quoted_string (FILE *asm_file, const char *string)
1406 #ifdef OUTPUT_QUOTED_STRING
1407 OUTPUT_QUOTED_STRING (asm_file, string);
1411 putc ('\"', asm_file);
1412 while ((c = *string++) != 0)
1416 if (c == '\"' || c == '\\')
1417 putc ('\\', asm_file);
1421 fprintf (asm_file, "\\%03o", (unsigned char) c);
1423 putc ('\"', asm_file);
1427 /* Output a file name in the form wanted by System V. */
1430 output_file_directive (FILE *asm_file, const char *input_name)
1432 int len = strlen (input_name);
1433 const char *na = input_name + len;
1435 /* NA gets INPUT_NAME sans directory names. */
1436 while (na > input_name)
1438 if (IS_DIR_SEPARATOR (na[-1]))
1443 #ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
1444 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
1446 #ifdef ASM_OUTPUT_SOURCE_FILENAME
1447 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
1449 fprintf (asm_file, "\t.file\t");
1450 output_quoted_string (asm_file, na);
1451 fputc ('\n', asm_file);
1456 /* Routine to open a dump file. Return true if the dump file is enabled. */
1459 open_dump_file (enum dump_file_index index, tree decl)
1462 const char *open_arg;
1465 if (! dump_file[index].enabled)
1468 timevar_push (TV_DUMP);
1469 if (rtl_dump_file != NULL)
1470 fclose (rtl_dump_file);
1472 sprintf (seq, DUMPFILE_FORMAT, index);
1474 if (! dump_file[index].initialized)
1476 /* If we've not initialized the files, do so now. */
1477 if (graph_dump_format != no_graph
1478 && dump_file[index].graph_dump_p)
1480 dump_name = concat (seq, dump_file[index].extension, NULL);
1481 clean_graph_dump_file (dump_base_name, dump_name);
1484 dump_file[index].initialized = 1;
1490 dump_name = concat (dump_base_name, seq,
1491 dump_file[index].extension, NULL);
1493 rtl_dump_file = fopen (dump_name, open_arg);
1494 if (rtl_dump_file == NULL)
1495 fatal_error ("can't open %s: %m", dump_name);
1500 fprintf (rtl_dump_file, "\n;; Function %s%s\n\n",
1501 (*lang_hooks.decl_printable_name) (decl, 2),
1502 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
1504 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
1505 ? " (unlikely executed)"
1508 timevar_pop (TV_DUMP);
1512 /* Routine to close a dump file. */
1515 close_dump_file (enum dump_file_index index,
1516 void (*func) (FILE *, rtx),
1519 if (! rtl_dump_file)
1522 timevar_push (TV_DUMP);
1524 && graph_dump_format != no_graph
1525 && dump_file[index].graph_dump_p)
1530 sprintf (seq, DUMPFILE_FORMAT, index);
1531 suffix = concat (seq, dump_file[index].extension, NULL);
1532 print_rtl_graph_with_bb (dump_base_name, suffix, insns);
1537 func (rtl_dump_file, insns);
1539 fflush (rtl_dump_file);
1540 fclose (rtl_dump_file);
1542 rtl_dump_file = NULL;
1543 timevar_pop (TV_DUMP);
1546 /* Do any final processing required for the declarations in VEC, of
1547 which there are LEN. We write out inline functions and variables
1548 that have been deferred until this point, but which are required.
1549 Returns nonzero if anything was put out. */
1552 wrapup_global_declarations (tree *vec, int len)
1557 int output_something = 0;
1559 for (i = 0; i < len; i++)
1563 /* We're not deferring this any longer. Assignment is
1564 conditional to avoid needlessly dirtying PCH pages. */
1565 if (DECL_DEFER_OUTPUT (decl) != 0)
1566 DECL_DEFER_OUTPUT (decl) = 0;
1568 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
1569 (*lang_hooks.finish_incomplete_decl) (decl);
1572 /* Now emit any global variables or functions that we have been
1573 putting off. We need to loop in case one of the things emitted
1574 here references another one which comes earlier in the list. */
1578 for (i = 0; i < len; i++)
1582 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
1585 /* Don't write out static consts, unless we still need them.
1587 We also keep static consts if not optimizing (for debugging),
1588 unless the user specified -fno-keep-static-consts.
1589 ??? They might be better written into the debug information.
1590 This is possible when using DWARF.
1592 A language processor that wants static constants to be always
1593 written out (even if it is not used) is responsible for
1594 calling rest_of_decl_compilation itself. E.g. the C front-end
1595 calls rest_of_decl_compilation from finish_decl.
1596 One motivation for this is that is conventional in some
1597 environments to write things like:
1598 static const char rcsid[] = "... version string ...";
1599 intending to force the string to be in the executable.
1601 A language processor that would prefer to have unneeded
1602 static constants "optimized away" would just defer writing
1603 them out until here. E.g. C++ does this, because static
1604 constants are often defined in header files.
1606 ??? A tempting alternative (for both C and C++) would be
1607 to force a constant to be written if and only if it is
1608 defined in a main file, as opposed to an include file. */
1610 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
1614 if (flag_unit_at_a_time
1615 && cgraph_varpool_node (decl)->finalized)
1617 else if ((flag_unit_at_a_time && !cgraph_global_info_ready)
1618 && (TREE_USED (decl)
1619 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
1621 else if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1623 else if (DECL_COMDAT (decl))
1625 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
1626 && (optimize || !flag_keep_static_consts
1627 || DECL_ARTIFICIAL (decl)))
1633 rest_of_decl_compilation (decl, NULL, 1, 1);
1637 if (TREE_CODE (decl) == FUNCTION_DECL
1638 && DECL_INITIAL (decl) != 0
1639 && DECL_SAVED_INSNS (decl) != 0
1640 && DECL_SAVED_INSNS (decl)->saved_for_inline
1641 && (flag_keep_inline_functions
1642 || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
1643 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
1646 output_inline_function (decl);
1651 output_something = 1;
1655 return output_something;
1658 /* Issue appropriate warnings for the global declarations in VEC (of
1659 which there are LEN). Output debugging information for them. */
1662 check_global_declarations (tree *vec, int len)
1667 for (i = 0; i < len; i++)
1671 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
1672 && ! TREE_ASM_WRITTEN (decl))
1673 /* Cancel the RTL for this decl so that, if debugging info
1674 output for global variables is still to come,
1675 this one will be omitted. */
1676 SET_DECL_RTL (decl, NULL_RTX);
1678 /* Warn about any function
1679 declared static but not defined.
1680 We don't warn about variables,
1681 because many programs have static variables
1682 that exist only to get some text into the object file. */
1683 if (TREE_CODE (decl) == FUNCTION_DECL
1684 && (warn_unused_function
1685 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1686 && DECL_INITIAL (decl) == 0
1687 && DECL_EXTERNAL (decl)
1688 && ! DECL_ARTIFICIAL (decl)
1689 && ! TREE_PUBLIC (decl))
1691 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1692 pedwarn ("%J'%F' used but never defined", decl, decl);
1694 warning ("%J'%F' declared `static' but never defined", decl, decl);
1695 /* This symbol is effectively an "extern" declaration now. */
1696 TREE_PUBLIC (decl) = 1;
1697 assemble_external (decl);
1700 /* Warn about static fns or vars defined but not used. */
1701 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
1702 || (warn_unused_variable && TREE_CODE (decl) == VAR_DECL))
1703 && ! TREE_USED (decl)
1704 /* The TREE_USED bit for file-scope decls is kept in the identifier,
1705 to handle multiple external decls in different scopes. */
1706 && ! TREE_USED (DECL_NAME (decl))
1707 && ! DECL_EXTERNAL (decl)
1708 && ! TREE_PUBLIC (decl)
1709 /* A volatile variable might be used in some non-obvious way. */
1710 && ! TREE_THIS_VOLATILE (decl)
1711 /* Global register variables must be declared to reserve them. */
1712 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
1713 /* Otherwise, ask the language. */
1714 && (*lang_hooks.decls.warn_unused_global) (decl))
1715 warning ("%J'%D' defined but not used", decl, decl);
1717 /* Avoid confusing the debug information machinery when there are
1719 if (errorcount == 0 && sorrycount == 0)
1721 timevar_push (TV_SYMOUT);
1722 (*debug_hooks->global_decl) (decl);
1723 timevar_pop (TV_SYMOUT);
1728 /* Warn about a use of an identifier which was marked deprecated. */
1730 warn_deprecated_use (tree node)
1732 if (node == 0 || !warn_deprecated_decl)
1736 warning ("`%s' is deprecated (declared at %s:%d)",
1737 IDENTIFIER_POINTER (DECL_NAME (node)),
1738 DECL_SOURCE_FILE (node), DECL_SOURCE_LINE (node));
1739 else if (TYPE_P (node))
1741 const char *what = NULL;
1742 tree decl = TYPE_STUB_DECL (node);
1744 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
1745 what = IDENTIFIER_POINTER (TYPE_NAME (node));
1746 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
1747 && DECL_NAME (TYPE_NAME (node)))
1748 what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
1753 warning ("`%s' is deprecated (declared at %s:%d)", what,
1754 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1756 warning ("`%s' is deprecated", what);
1759 warning ("type is deprecated (declared at %s:%d)",
1760 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1762 warning ("type is deprecated");
1766 /* Save the current INPUT_LOCATION on the top entry in the
1767 INPUT_FILE_STACK. Push a new entry for FILE and LINE, and set the
1768 INPUT_LOCATION accordingly. */
1771 push_srcloc (const char *file, int line)
1773 struct file_stack *fs;
1775 fs = xmalloc (sizeof (struct file_stack));
1776 fs->location = input_location;
1777 fs->next = input_file_stack;
1778 input_filename = file;
1780 input_file_stack = fs;
1781 input_file_stack_tick++;
1784 /* Pop the top entry off the stack of presently open source files.
1785 Restore the INPUT_LOCATION from the new topmost entry on the
1791 struct file_stack *fs;
1793 fs = input_file_stack;
1794 input_location = fs->location;
1795 input_file_stack = fs->next;
1797 input_file_stack_tick++;
1800 /* Compile an entire translation unit. Write a file of assembly
1801 output and various debugging dumps. */
1806 /* Initialize yet another pass. */
1808 init_final (main_input_filename);
1809 coverage_init (aux_base_name);
1811 timevar_push (TV_PARSE);
1813 /* Call the parser, which parses the entire file (calling
1814 rest_of_compilation for each function). */
1815 (*lang_hooks.parse_file) (set_yydebug);
1817 /* In case there were missing block closers,
1818 get us back to the global binding level. */
1819 (*lang_hooks.clear_binding_stack) ();
1821 /* Compilation is now finished except for writing
1822 what's left of the symbol table output. */
1823 timevar_pop (TV_PARSE);
1825 if (flag_syntax_only)
1828 (*lang_hooks.decls.final_write_globals)();
1830 cgraph_varpool_assemble_pending_decls ();
1832 /* This must occur after the loop to output deferred functions.
1833 Else the coverage initializer would not be emitted if all the
1834 functions in this compilation unit were deferred. */
1837 /* Write out any pending weak symbol declarations. */
1841 /* Do dbx symbols. */
1842 timevar_push (TV_SYMOUT);
1844 #ifdef DWARF2_UNWIND_INFO
1845 if (dwarf2out_do_frame ())
1846 dwarf2out_frame_finish ();
1849 (*debug_hooks->finish) (main_input_filename);
1850 timevar_pop (TV_SYMOUT);
1852 /* Output some stuff at end of file if nec. */
1854 dw2_output_indirect_constants ();
1856 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
1858 timevar_push (TV_DUMP);
1859 open_dump_file (DFI_bp, NULL);
1863 close_dump_file (DFI_bp, NULL, NULL_RTX);
1864 timevar_pop (TV_DUMP);
1867 targetm.asm_out.file_end ();
1869 /* Attach a special .ident directive to the end of the file to identify
1870 the version of GCC which compiled this code. The format of the .ident
1871 string is patterned after the ones produced by native SVR4 compilers. */
1874 fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
1875 IDENT_ASM_OP, version_string);
1878 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
1880 timevar_push (TV_DUMP);
1881 dump_combine_total_stats (rtl_dump_file);
1882 close_dump_file (DFI_combine, NULL, NULL_RTX);
1883 timevar_pop (TV_DUMP);
1887 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
1888 and TYPE_DECL nodes.
1890 This does nothing for local (non-static) variables, unless the
1891 variable is a register variable with an ASMSPEC. In that case, or
1892 if the variable is not an automatic, it sets up the RTL and
1893 outputs any assembler code (label definition, storage allocation
1894 and initialization).
1896 DECL is the declaration. If ASMSPEC is nonzero, it specifies
1897 the assembler symbol name to be used. TOP_LEVEL is nonzero
1898 if this declaration is not within a function. */
1901 rest_of_decl_compilation (tree decl,
1902 const char *asmspec,
1906 /* We deferred calling assemble_alias so that we could collect
1907 other attributes such as visibility. Emit the alias now. */
1910 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
1913 alias = TREE_VALUE (TREE_VALUE (alias));
1914 alias = get_identifier (TREE_STRING_POINTER (alias));
1915 assemble_alias (decl, alias);
1919 /* Forward declarations for nested functions are not "external",
1920 but we need to treat them as if they were. */
1921 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
1922 || TREE_CODE (decl) == FUNCTION_DECL)
1924 timevar_push (TV_VARCONST);
1927 make_decl_rtl (decl, asmspec);
1929 /* Don't output anything when a tentative file-scope definition
1930 is seen. But at end of compilation, do output code for them. */
1931 if ((at_end || !DECL_DEFER_OUTPUT (decl)) && !DECL_EXTERNAL (decl))
1933 if (flag_unit_at_a_time && !cgraph_global_info_ready
1934 && TREE_CODE (decl) != FUNCTION_DECL && top_level)
1935 cgraph_varpool_finalize_decl (decl);
1937 assemble_variable (decl, top_level, at_end, 0);
1940 #ifdef ASM_FINISH_DECLARE_OBJECT
1941 if (decl == last_assemble_variable_decl)
1943 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
1948 timevar_pop (TV_VARCONST);
1950 else if (DECL_REGISTER (decl) && asmspec != 0)
1952 if (decode_reg_name (asmspec) >= 0)
1954 SET_DECL_RTL (decl, NULL_RTX);
1955 make_decl_rtl (decl, asmspec);
1959 error ("invalid register name `%s' for register variable", asmspec);
1960 DECL_REGISTER (decl) = 0;
1965 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1966 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1967 && TREE_CODE (decl) == TYPE_DECL)
1969 timevar_push (TV_SYMOUT);
1970 dbxout_symbol (decl, 0);
1971 timevar_pop (TV_SYMOUT);
1974 #ifdef SDB_DEBUGGING_INFO
1975 else if (write_symbols == SDB_DEBUG && top_level
1976 && TREE_CODE (decl) == TYPE_DECL)
1978 timevar_push (TV_SYMOUT);
1979 sdbout_symbol (decl, 0);
1980 timevar_pop (TV_SYMOUT);
1983 #ifdef DWARF2_DEBUGGING_INFO
1984 else if ((write_symbols == DWARF2_DEBUG
1985 || write_symbols == VMS_AND_DWARF2_DEBUG)
1987 && TREE_CODE (decl) == TYPE_DECL)
1989 timevar_push (TV_SYMOUT);
1990 dwarf2out_decl (decl);
1991 timevar_pop (TV_SYMOUT);
1996 /* Called after finishing a record, union or enumeral type. */
1999 rest_of_type_compilation (
2000 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) \
2001 || defined (SDB_DEBUGGING_INFO) || defined (DWARF2_DEBUGGING_INFO)
2005 tree type ATTRIBUTE_UNUSED,
2006 int toplev ATTRIBUTE_UNUSED
2010 /* Avoid confusing the debug information machinery when there are
2012 if (errorcount != 0 || sorrycount != 0)
2015 timevar_push (TV_SYMOUT);
2016 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2017 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2018 dbxout_symbol (TYPE_STUB_DECL (type), !toplev);
2020 #ifdef SDB_DEBUGGING_INFO
2021 if (write_symbols == SDB_DEBUG)
2022 sdbout_symbol (TYPE_STUB_DECL (type), !toplev);
2024 #ifdef DWARF2_DEBUGGING_INFO
2025 if ((write_symbols == DWARF2_DEBUG
2026 || write_symbols == VMS_AND_DWARF2_DEBUG)
2028 dwarf2out_decl (TYPE_STUB_DECL (type));
2030 timevar_pop (TV_SYMOUT);
2033 /* Turn the RTL into assembly. */
2035 rest_of_handle_final (tree decl, rtx insns)
2037 timevar_push (TV_FINAL);
2042 /* Get the function's name, as described by its RTL. This may be
2043 different from the DECL_NAME name used in the source file. */
2045 x = DECL_RTL (decl);
2046 if (GET_CODE (x) != MEM)
2049 if (GET_CODE (x) != SYMBOL_REF)
2051 fnname = XSTR (x, 0);
2053 assemble_start_function (decl, fnname);
2054 final_start_function (insns, asm_out_file, optimize);
2055 final (insns, asm_out_file, optimize, 0);
2056 final_end_function ();
2058 #ifdef IA64_UNWIND_INFO
2059 /* ??? The IA-64 ".handlerdata" directive must be issued before
2060 the ".endp" directive that closes the procedure descriptor. */
2061 output_function_exception_table ();
2064 assemble_end_function (decl, fnname);
2066 #ifndef IA64_UNWIND_INFO
2067 /* Otherwise, it feels unclean to switch sections in the middle. */
2068 output_function_exception_table ();
2072 fflush (asm_out_file);
2074 /* Release all memory allocated by flow. */
2075 free_basic_block_vars (0);
2077 /* Release all memory held by regsets now. */
2078 regset_release_memory ();
2080 timevar_pop (TV_FINAL);
2086 /* Run delay slot optimization. */
2088 rest_of_handle_delay_slots (tree decl, rtx insns)
2090 timevar_push (TV_DBR_SCHED);
2091 open_dump_file (DFI_dbr, decl);
2093 dbr_schedule (insns, rtl_dump_file);
2095 close_dump_file (DFI_dbr, print_rtl, insns);
2096 timevar_pop (TV_DBR_SCHED);
2103 /* Convert register usage from flat register file usage to a stack
2106 rest_of_handle_stack_regs (tree decl, rtx insns)
2108 #if defined (HAVE_ATTR_length)
2109 /* If flow2 creates new instructions which need splitting
2110 and scheduling after reload is not done, they might not be
2111 splitten until final which doesn't allow splitting
2112 if HAVE_ATTR_length. */
2113 #ifdef INSN_SCHEDULING
2114 if (optimize && !flag_schedule_insns_after_reload)
2119 timevar_push (TV_SHORTEN_BRANCH);
2120 split_all_insns (1);
2121 timevar_pop (TV_SHORTEN_BRANCH);
2125 timevar_push (TV_REG_STACK);
2126 open_dump_file (DFI_stack, decl);
2128 if (reg_to_stack (insns, rtl_dump_file) && optimize)
2130 if (cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
2131 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0))
2132 && flag_reorder_blocks)
2134 reorder_basic_blocks ();
2135 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
2139 close_dump_file (DFI_stack, print_rtl_with_bb, insns);
2140 timevar_pop (TV_REG_STACK);
2147 /* Machine independent reorg pass. */
2149 rest_of_handle_machine_reorg (tree decl, rtx insns)
2151 timevar_push (TV_MACH_DEP);
2152 open_dump_file (DFI_mach, decl);
2154 (*targetm.machine_dependent_reorg) ();
2156 close_dump_file (DFI_mach, print_rtl, insns);
2157 timevar_pop (TV_MACH_DEP);
2163 /* Run new register allocator. Return TRUE if we must exit
2164 rest_of_compilation upon return. */
2166 rest_of_handle_new_regalloc (tree decl, rtx insns, int *rebuild_notes)
2170 delete_trivially_dead_insns (insns, max_reg_num ());
2173 timevar_pop (TV_LOCAL_ALLOC);
2174 if (dump_file[DFI_lreg].enabled)
2176 timevar_push (TV_DUMP);
2178 close_dump_file (DFI_lreg, NULL, NULL);
2179 timevar_pop (TV_DUMP);
2182 /* XXX clean up the whole mess to bring live info in shape again. */
2183 timevar_push (TV_GLOBAL_ALLOC);
2184 open_dump_file (DFI_greg, decl);
2186 build_insn_chain (insns);
2187 failure = reload (insns, 0);
2189 timevar_pop (TV_GLOBAL_ALLOC);
2191 if (dump_file[DFI_greg].enabled)
2193 timevar_push (TV_DUMP);
2195 dump_global_regs (rtl_dump_file);
2197 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2198 timevar_pop (TV_DUMP);
2204 reload_completed = 1;
2210 /* Run old register allocator. Return TRUE if we must exit
2211 rest_of_compilation upon return. */
2213 rest_of_handle_old_regalloc (tree decl, rtx insns, int *rebuild_notes)
2217 /* Allocate the reg_renumber array. */
2218 allocate_reg_info (max_regno, FALSE, TRUE);
2220 /* And the reg_equiv_memory_loc array. */
2221 reg_equiv_memory_loc = xcalloc (max_regno, sizeof (rtx));
2223 allocate_initial_values (reg_equiv_memory_loc);
2225 regclass (insns, max_reg_num (), rtl_dump_file);
2226 *rebuild_notes = local_alloc ();
2228 timevar_pop (TV_LOCAL_ALLOC);
2230 if (dump_file[DFI_lreg].enabled)
2232 timevar_push (TV_DUMP);
2234 dump_flow_info (rtl_dump_file);
2235 dump_local_alloc (rtl_dump_file);
2237 close_dump_file (DFI_lreg, print_rtl_with_bb, insns);
2238 timevar_pop (TV_DUMP);
2243 timevar_push (TV_GLOBAL_ALLOC);
2244 open_dump_file (DFI_greg, decl);
2246 /* If optimizing, allocate remaining pseudo-regs. Do the reload
2247 pass fixing up any insns that are invalid. */
2250 failure = global_alloc (rtl_dump_file);
2253 build_insn_chain (insns);
2254 failure = reload (insns, 0);
2257 timevar_pop (TV_GLOBAL_ALLOC);
2259 if (dump_file[DFI_greg].enabled)
2261 timevar_push (TV_DUMP);
2263 dump_global_regs (rtl_dump_file);
2265 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2266 timevar_pop (TV_DUMP);
2272 /* Run the regrename and cprop passes. */
2274 rest_of_handle_regrename (tree decl, rtx insns)
2276 timevar_push (TV_RENAME_REGISTERS);
2277 open_dump_file (DFI_rnreg, decl);
2279 if (flag_rename_registers)
2280 regrename_optimize ();
2281 if (flag_cprop_registers)
2282 copyprop_hardreg_forward ();
2284 close_dump_file (DFI_rnreg, print_rtl_with_bb, insns);
2285 timevar_pop (TV_RENAME_REGISTERS);
2288 /* Reorder basic blocks. */
2290 rest_of_handle_reorder_blocks (tree decl, rtx insns)
2292 timevar_push (TV_REORDER_BLOCKS);
2293 open_dump_file (DFI_bbro, decl);
2295 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
2296 splitting possibly introduced more crossjumping opportunities. */
2297 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
2298 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
2300 if (flag_sched2_use_traces && flag_schedule_insns_after_reload)
2302 if (flag_reorder_blocks)
2303 reorder_basic_blocks ();
2304 if (flag_reorder_blocks
2305 || (flag_sched2_use_traces && flag_schedule_insns_after_reload))
2306 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2308 close_dump_file (DFI_bbro, print_rtl_with_bb, insns);
2309 timevar_pop (TV_REORDER_BLOCKS);
2312 #ifdef INSN_SCHEDULING
2313 /* Run instruction scheduler. */
2315 rest_of_handle_sched (tree decl, rtx insns)
2317 timevar_push (TV_SCHED);
2319 /* Print function header into sched dump now
2320 because doing the sched analysis makes some of the dump. */
2321 if (optimize > 0 && flag_schedule_insns)
2323 open_dump_file (DFI_sched, decl);
2325 /* Do control and data sched analysis,
2326 and write some of the results to dump file. */
2328 schedule_insns (rtl_dump_file);
2330 close_dump_file (DFI_sched, print_rtl_with_bb, insns);
2332 timevar_pop (TV_SCHED);
2337 /* Run second scheduling pass after reload. */
2339 rest_of_handle_sched2 (tree decl, rtx insns)
2341 timevar_push (TV_SCHED2);
2342 open_dump_file (DFI_sched2, decl);
2344 /* Do control and data sched analysis again,
2345 and write some more of the results to dump file. */
2347 split_all_insns (1);
2349 if (flag_sched2_use_superblocks || flag_sched2_use_traces)
2351 schedule_ebbs (rtl_dump_file);
2352 /* No liveness updating code yet, but it should be easy to do.
2353 reg-stack recompute the liveness when needed for now. */
2354 count_or_remove_death_notes (NULL, 1);
2355 cleanup_cfg (CLEANUP_EXPENSIVE);
2358 schedule_insns (rtl_dump_file);
2360 close_dump_file (DFI_sched2, print_rtl_with_bb, insns);
2361 timevar_pop (TV_SCHED2);
2367 /* Register allocation pre-pass, to reduce number of moves necessary
2368 for two-address machines. */
2370 rest_of_handle_regmove (tree decl, rtx insns)
2372 timevar_push (TV_REGMOVE);
2373 open_dump_file (DFI_regmove, decl);
2375 regmove_optimize (insns, max_reg_num (), rtl_dump_file);
2377 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2378 close_dump_file (DFI_regmove, print_rtl_with_bb, insns);
2379 timevar_pop (TV_REGMOVE);
2386 rest_of_handle_tracer (tree decl, rtx insns)
2388 timevar_push (TV_TRACER);
2389 open_dump_file (DFI_tracer, decl);
2391 dump_flow_info (rtl_dump_file);
2393 cleanup_cfg (CLEANUP_EXPENSIVE);
2394 reg_scan (insns, max_reg_num (), 0);
2395 close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ());
2396 timevar_pop (TV_TRACER);
2399 /* If-conversion and CFG cleanup. */
2401 rest_of_handle_if_conversion (tree decl, rtx insns)
2403 open_dump_file (DFI_ce1, decl);
2404 if (flag_if_conversion)
2406 timevar_push (TV_IFCVT);
2408 dump_flow_info (rtl_dump_file);
2409 cleanup_cfg (CLEANUP_EXPENSIVE);
2410 reg_scan (insns, max_reg_num (), 0);
2412 timevar_pop (TV_IFCVT);
2414 timevar_push (TV_JUMP);
2415 cleanup_cfg (CLEANUP_EXPENSIVE);
2416 reg_scan (insns, max_reg_num (), 0);
2417 timevar_pop (TV_JUMP);
2418 close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ());
2421 /* Rerun if-conversion, as combine may have simplified things enough
2422 to now meet sequence length restrictions. */
2424 rest_of_handle_if_after_combine (tree decl, rtx insns)
2426 timevar_push (TV_IFCVT);
2427 open_dump_file (DFI_ce2, decl);
2433 close_dump_file (DFI_ce2, print_rtl_with_bb, insns);
2434 timevar_pop (TV_IFCVT);
2438 rest_of_handle_web (tree decl, rtx insns)
2440 open_dump_file (DFI_web, decl);
2441 timevar_push (TV_WEB);
2443 delete_trivially_dead_insns (insns, max_reg_num ());
2444 cleanup_cfg (CLEANUP_EXPENSIVE);
2446 timevar_pop (TV_WEB);
2447 close_dump_file (DFI_web, print_rtl_with_bb, insns);
2448 reg_scan (get_insns (), max_reg_num (), 0);
2451 /* Do branch profiling and static profile estimation passes. */
2453 rest_of_handle_branch_prob (tree decl, rtx insns)
2457 timevar_push (TV_BRANCH_PROB);
2458 open_dump_file (DFI_bp, decl);
2459 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
2462 /* Discover and record the loop depth at the head of each basic
2463 block. The loop infrastructure does the real job for us. */
2464 flow_loops_find (&loops, LOOP_TREE);
2467 flow_loops_dump (&loops, rtl_dump_file, NULL, 0);
2469 /* Estimate using heuristics if no profiling info is available. */
2470 if (flag_guess_branch_prob)
2471 estimate_probability (&loops);
2473 flow_loops_free (&loops);
2474 close_dump_file (DFI_bp, print_rtl_with_bb, insns);
2475 timevar_pop (TV_BRANCH_PROB);
2478 /* Do control and data flow analysis; write some of the results to the
2481 rest_of_handle_cfg (tree decl, rtx insns)
2483 open_dump_file (DFI_cfg, decl);
2485 dump_flow_info (rtl_dump_file);
2487 cleanup_cfg (CLEANUP_EXPENSIVE
2488 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2490 /* It may make more sense to mark constant functions after dead code is
2491 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
2492 may insert code making function non-constant, but we still must consider
2493 it as constant, otherwise -fbranch-probabilities will not read data back.
2495 life_analysis rarely eliminates modification of external memory.
2498 mark_constant_function ();
2500 close_dump_file (DFI_cfg, print_rtl_with_bb, insns);
2503 /* Purge addressofs. */
2505 rest_of_handle_addressof (tree decl, rtx insns)
2507 open_dump_file (DFI_addressof, decl);
2509 purge_addressof (insns);
2510 if (optimize && purge_all_dead_edges (0))
2511 delete_unreachable_blocks ();
2512 reg_scan (insns, max_reg_num (), 1);
2514 close_dump_file (DFI_addressof, print_rtl, insns);
2517 /* We may have potential sibling or tail recursion sites. Select one
2518 (of possibly multiple) methods of performing the call. */
2520 rest_of_handle_sibling_calls (rtx insns)
2523 optimize_sibling_and_tail_recursive_calls ();
2525 /* Recompute the CFG as sibling optimization clobbers it randomly. */
2526 free_bb_for_insn ();
2527 find_exception_handler_labels ();
2528 rebuild_jump_labels (insns);
2529 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2531 /* There is pass ordering problem - we must lower NOTE_INSN_PREDICTION
2532 notes before simplifying cfg and we must do lowering after sibcall
2533 that unhides parts of RTL chain and cleans up the CFG.
2535 Until sibcall is replaced by tree-level optimizer, lets just
2536 sweep away the NOTE_INSN_PREDICTION notes that leaked out. */
2537 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2538 if (GET_CODE (insn) == NOTE
2539 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_PREDICTION)
2542 close_dump_file (DFI_sibling, print_rtl, get_insns ());
2545 /* Perform jump bypassing and control flow optimizations. */
2547 rest_of_handle_jump_bypass (tree decl, rtx insns)
2549 timevar_push (TV_BYPASS);
2550 open_dump_file (DFI_bypass, decl);
2552 cleanup_cfg (CLEANUP_EXPENSIVE);
2554 if (bypass_jumps (rtl_dump_file))
2556 rebuild_jump_labels (insns);
2557 cleanup_cfg (CLEANUP_EXPENSIVE);
2558 delete_trivially_dead_insns (insns, max_reg_num ());
2561 close_dump_file (DFI_bypass, print_rtl_with_bb, insns);
2562 timevar_pop (TV_BYPASS);
2566 #ifdef ENABLE_CHECKING
2567 verify_flow_info ();
2571 /* Handle inlining of functions in rest_of_compilation. Return TRUE
2572 if we must exit rest_of_compilation upon return. */
2574 rest_of_handle_inlining (tree decl)
2581 /* If we are reconsidering an inline function at the end of
2582 compilation, skip the stuff for making it inline. */
2583 if (cfun->rtl_inline_init)
2585 cfun->rtl_inline_init = 1;
2587 /* If this is nested inside an inlined external function, pretend
2588 it was only declared. Since we cannot inline such functions,
2589 generating code for this one is not only not necessary but will
2590 confuse some debugging output writers. */
2591 for (parent = DECL_CONTEXT (current_function_decl);
2592 parent != NULL_TREE;
2593 parent = get_containing_scope (parent))
2594 if (TREE_CODE (parent) == FUNCTION_DECL
2595 && DECL_INLINE (parent) && DECL_EXTERNAL (parent))
2597 DECL_INITIAL (decl) = 0;
2600 else if (TYPE_P (parent))
2601 /* A function in a local class should be treated normally. */
2604 /* If requested, consider whether to make this function inline. */
2605 if ((DECL_INLINE (decl) && !flag_no_inline)
2606 || flag_inline_functions)
2608 timevar_push (TV_INTEGRATION);
2609 lose = function_cannot_inline_p (decl);
2610 timevar_pop (TV_INTEGRATION);
2611 if (lose || ! optimize)
2613 if (warn_inline && lose && DECL_INLINE (decl))
2615 char *msg = concat ("%J", lose, NULL);
2616 warning (msg, decl);
2619 DECL_ABSTRACT_ORIGIN (decl) = 0;
2620 /* Don't really compile an extern inline function.
2621 If we can't make it inline, pretend
2622 it was only declared. */
2623 if (DECL_EXTERNAL (decl))
2625 DECL_INITIAL (decl) = 0;
2630 inlinable = DECL_INLINE (decl) = 1;
2633 insns = get_insns ();
2635 /* Dump the rtl code if we are dumping rtl. */
2637 if (open_dump_file (DFI_rtl, decl))
2639 if (DECL_SAVED_INSNS (decl) && DECL_SAVED_INSNS (decl)->saved_for_inline)
2640 fprintf (rtl_dump_file, ";; (integrable)\n\n");
2641 close_dump_file (DFI_rtl, print_rtl, insns);
2644 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
2645 sorts of eh initialization. Delay this until after the
2646 initial rtl dump so that we can see the original nesting. */
2647 convert_from_eh_region_ranges ();
2649 /* If function is inline, and we don't yet know whether to
2650 compile it by itself, defer decision till end of compilation.
2651 wrapup_global_declarations will (indirectly) call
2652 rest_of_compilation again for those functions that need to
2653 be output. Also defer those functions that we are supposed
2657 || (DECL_INLINE (decl)
2658 && flag_inline_functions
2659 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2660 && ! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
2661 && ! flag_keep_inline_functions)
2662 || DECL_EXTERNAL (decl))))
2663 DECL_DEFER_OUTPUT (decl) = 1;
2665 if (DECL_INLINE (decl))
2666 /* DWARF wants separate debugging info for abstract and
2667 concrete instances of all inline functions, including those
2668 declared inline but not inlined, and those inlined even
2669 though they weren't declared inline. Conveniently, that's
2670 what DECL_INLINE means at this point. */
2671 (*debug_hooks->deferred_inline_function) (decl);
2673 if (DECL_DEFER_OUTPUT (decl))
2675 /* If -Wreturn-type, we have to do a bit of compilation. We just
2676 want to call cleanup the cfg to figure out whether or not we can
2677 fall off the end of the function; we do the minimum amount of
2678 work necessary to make that safe. */
2679 if (warn_return_type)
2681 int saved_optimize = optimize;
2684 rebuild_jump_labels (insns);
2685 find_exception_handler_labels ();
2686 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2687 cleanup_cfg (CLEANUP_PRE_SIBCALL | CLEANUP_PRE_LOOP);
2688 optimize = saved_optimize;
2690 /* CFG is no longer maintained up-to-date. */
2691 free_bb_for_insn ();
2694 set_nothrow_function_flags ();
2695 if (current_function_nothrow)
2696 /* Now we know that this can't throw; set the flag for the benefit
2697 of other functions later in this translation unit. */
2698 TREE_NOTHROW (current_function_decl) = 1;
2700 timevar_push (TV_INTEGRATION);
2701 save_for_inline (decl);
2702 timevar_pop (TV_INTEGRATION);
2703 DECL_SAVED_INSNS (decl)->inlinable = inlinable;
2707 /* If specified extern inline but we aren't inlining it, we are
2708 done. This goes for anything that gets here with DECL_EXTERNAL
2709 set, not just things with DECL_INLINE. */
2710 return (bool) DECL_EXTERNAL (decl);
2713 /* Rest of compilation helper to convert the rtl to SSA form. */
2715 rest_of_handle_ssa (tree decl, rtx insns)
2717 timevar_push (TV_TO_SSA);
2718 open_dump_file (DFI_ssa, decl);
2720 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2723 close_dump_file (DFI_ssa, print_rtl_with_bb, insns);
2724 timevar_pop (TV_TO_SSA);
2726 /* Perform sparse conditional constant propagation, if requested. */
2729 timevar_push (TV_SSA_CCP);
2730 open_dump_file (DFI_ssa_ccp, decl);
2734 close_dump_file (DFI_ssa_ccp, print_rtl_with_bb, get_insns ());
2735 timevar_pop (TV_SSA_CCP);
2738 /* It would be useful to cleanup the CFG at this point, but block
2739 merging and possibly other transformations might leave a PHI
2740 node in the middle of a basic block, which is a strict no-no. */
2742 /* The SSA implementation uses basic block numbers in its phi
2743 nodes. Thus, changing the control-flow graph or the basic
2744 blocks, e.g., calling find_basic_blocks () or cleanup_cfg (),
2745 may cause problems. */
2749 /* Remove dead code. */
2751 timevar_push (TV_SSA_DCE);
2752 open_dump_file (DFI_ssa_dce, decl);
2754 insns = get_insns ();
2755 ssa_eliminate_dead_code ();
2757 close_dump_file (DFI_ssa_dce, print_rtl_with_bb, insns);
2758 timevar_pop (TV_SSA_DCE);
2761 /* Convert from SSA form. */
2763 timevar_push (TV_FROM_SSA);
2764 open_dump_file (DFI_ussa, decl);
2766 convert_from_ssa ();
2767 /* New registers have been created. Rescan their usage. */
2768 reg_scan (insns, max_reg_num (), 1);
2770 close_dump_file (DFI_ussa, print_rtl_with_bb, insns);
2771 timevar_pop (TV_FROM_SSA);
2778 /* Try to identify useless null pointer tests and delete them. */
2780 rest_of_handle_null_pointer (tree decl, rtx insns)
2782 open_dump_file (DFI_null, decl);
2784 dump_flow_info (rtl_dump_file);
2786 if (delete_null_pointer_checks (insns))
2787 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2789 close_dump_file (DFI_null, print_rtl_with_bb, insns);
2792 /* Try combining insns through substitution. */
2794 rest_of_handle_combine (tree decl, rtx insns)
2796 int rebuild_jump_labels_after_combine = 0;
2798 timevar_push (TV_COMBINE);
2799 open_dump_file (DFI_combine, decl);
2801 rebuild_jump_labels_after_combine
2802 = combine_instructions (insns, max_reg_num ());
2804 /* Combining insns may have turned an indirect jump into a
2805 direct jump. Rebuild the JUMP_LABEL fields of jumping
2807 if (rebuild_jump_labels_after_combine)
2809 timevar_push (TV_JUMP);
2810 rebuild_jump_labels (insns);
2811 timevar_pop (TV_JUMP);
2813 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2816 close_dump_file (DFI_combine, print_rtl_with_bb, insns);
2817 timevar_pop (TV_COMBINE);
2822 /* Perform life analysis. */
2824 rest_of_handle_life (tree decl, rtx insns)
2826 open_dump_file (DFI_life, decl);
2829 #ifdef ENABLE_CHECKING
2830 verify_flow_info ();
2832 life_analysis (insns, rtl_dump_file, PROP_FINAL);
2834 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_UPDATE_LIFE
2835 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2836 timevar_pop (TV_FLOW);
2838 if (warn_uninitialized)
2840 uninitialized_vars_warning (DECL_INITIAL (decl));
2842 setjmp_args_warning ();
2847 if (!flag_new_regalloc && initialize_uninitialized_subregs ())
2849 /* Insns were inserted, and possibly pseudos created, so
2850 things might look a bit different. */
2851 insns = get_insns ();
2852 allocate_reg_life_data ();
2853 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
2854 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
2860 close_dump_file (DFI_life, print_rtl_with_bb, insns);
2865 /* Perform common subexpression elimination. Nonzero value from
2866 `cse_main' means that jumps were simplified and some code may now
2867 be unreachable, so do jump optimization again. */
2869 rest_of_handle_cse (tree decl, rtx insns)
2873 open_dump_file (DFI_cse, decl);
2875 dump_flow_info (rtl_dump_file);
2876 timevar_push (TV_CSE);
2878 reg_scan (insns, max_reg_num (), 1);
2880 tem = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2882 rebuild_jump_labels (insns);
2883 if (purge_all_dead_edges (0))
2884 delete_unreachable_blocks ();
2886 delete_trivially_dead_insns (insns, max_reg_num ());
2888 /* If we are not running more CSE passes, then we are no longer
2889 expecting CSE to be run. But always rerun it in a cheap mode. */
2890 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
2892 if (tem || optimize > 1)
2893 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2894 /* Try to identify useless null pointer tests and delete them. */
2895 if (flag_delete_null_pointer_checks)
2897 timevar_push (TV_JUMP);
2899 if (delete_null_pointer_checks (insns))
2900 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2901 timevar_pop (TV_JUMP);
2904 /* The second pass of jump optimization is likely to have
2905 removed a bunch more instructions. */
2906 renumber_insns (rtl_dump_file);
2908 timevar_pop (TV_CSE);
2909 close_dump_file (DFI_cse, print_rtl_with_bb, insns);
2912 /* Run second CSE pass after loop optimizations. */
2914 rest_of_handle_cse2 (tree decl, rtx insns)
2918 timevar_push (TV_CSE2);
2919 open_dump_file (DFI_cse2, decl);
2921 dump_flow_info (rtl_dump_file);
2922 /* CFG is no longer maintained up-to-date. */
2923 tem = cse_main (insns, max_reg_num (), 1, rtl_dump_file);
2924 purge_all_dead_edges (0);
2925 delete_trivially_dead_insns (insns, max_reg_num ());
2929 timevar_push (TV_JUMP);
2930 rebuild_jump_labels (insns);
2931 cleanup_cfg (CLEANUP_EXPENSIVE);
2932 timevar_pop (TV_JUMP);
2934 reg_scan (insns, max_reg_num (), 0);
2935 close_dump_file (DFI_cse2, print_rtl_with_bb, insns);
2937 timevar_pop (TV_CSE2);
2940 /* Perform global cse. */
2942 rest_of_handle_gcse (tree decl, rtx insns)
2944 int save_csb, save_cfj;
2947 timevar_push (TV_GCSE);
2948 open_dump_file (DFI_gcse, decl);
2950 tem = gcse_main (insns, rtl_dump_file);
2951 rebuild_jump_labels (insns);
2952 delete_trivially_dead_insns (insns, max_reg_num ());
2954 save_csb = flag_cse_skip_blocks;
2955 save_cfj = flag_cse_follow_jumps;
2956 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
2958 /* Instantiate any remaining CONSTANT_P_RTX nodes. */
2959 if (current_function_calls_constant_p)
2960 purge_builtin_constant_p ();
2962 /* If -fexpensive-optimizations, re-run CSE to clean up things done
2964 if (flag_expensive_optimizations)
2966 timevar_push (TV_CSE);
2967 reg_scan (insns, max_reg_num (), 1);
2968 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2969 purge_all_dead_edges (0);
2970 delete_trivially_dead_insns (insns, max_reg_num ());
2971 timevar_pop (TV_CSE);
2972 cse_not_expected = !flag_rerun_cse_after_loop;
2975 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
2976 things up. Then possibly re-run CSE again. */
2980 timevar_push (TV_JUMP);
2981 rebuild_jump_labels (insns);
2982 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2983 timevar_pop (TV_JUMP);
2985 if (flag_expensive_optimizations)
2987 timevar_push (TV_CSE);
2988 reg_scan (insns, max_reg_num (), 1);
2989 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2990 purge_all_dead_edges (0);
2991 delete_trivially_dead_insns (insns, max_reg_num ());
2992 timevar_pop (TV_CSE);
2996 close_dump_file (DFI_gcse, print_rtl_with_bb, insns);
2997 timevar_pop (TV_GCSE);
3000 flag_cse_skip_blocks = save_csb;
3001 flag_cse_follow_jumps = save_cfj;
3002 #ifdef ENABLE_CHECKING
3003 verify_flow_info ();
3007 /* Move constant computations out of loops. */
3009 rest_of_handle_loop_optimize (tree decl, rtx insns)
3011 int do_unroll, do_prefetch;
3013 timevar_push (TV_LOOP);
3014 delete_dead_jumptables ();
3015 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3016 open_dump_file (DFI_loop, decl);
3018 /* CFG is no longer maintained up-to-date. */
3019 free_bb_for_insn ();
3021 if (flag_unroll_loops)
3022 do_unroll = 0; /* Having two unrollers is useless. */
3024 do_unroll = flag_old_unroll_loops ? LOOP_UNROLL : LOOP_AUTO_UNROLL;
3025 do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
3027 if (flag_rerun_loop_opt)
3029 cleanup_barriers ();
3031 /* We only want to perform unrolling once. */
3032 loop_optimize (insns, rtl_dump_file, do_unroll);
3035 /* The first call to loop_optimize makes some instructions
3036 trivially dead. We delete those instructions now in the
3037 hope that doing so will make the heuristics in loop work
3038 better and possibly speed up compilation. */
3039 delete_trivially_dead_insns (insns, max_reg_num ());
3041 /* The regscan pass is currently necessary as the alias
3042 analysis code depends on this information. */
3043 reg_scan (insns, max_reg_num (), 1);
3045 cleanup_barriers ();
3046 loop_optimize (insns, rtl_dump_file, do_unroll | LOOP_BCT | do_prefetch);
3048 /* Loop can create trivially dead instructions. */
3049 delete_trivially_dead_insns (insns, max_reg_num ());
3050 close_dump_file (DFI_loop, print_rtl, insns);
3051 timevar_pop (TV_LOOP);
3052 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3057 /* Perform loop optimizations. It might be better to do them a bit
3058 sooner, but we want the profile feedback to work more
3061 rest_of_handle_loop2 (tree decl, rtx insns)
3063 struct loops *loops;
3064 timevar_push (TV_LOOP);
3065 open_dump_file (DFI_loop2, decl);
3067 dump_flow_info (rtl_dump_file);
3069 loops = loop_optimizer_init (rtl_dump_file);
3073 /* The optimizations: */
3074 if (flag_unswitch_loops)
3075 unswitch_loops (loops);
3077 if (flag_peel_loops || flag_unroll_loops)
3078 unroll_and_peel_loops (loops,
3079 (flag_peel_loops ? UAP_PEEL : 0) |
3080 (flag_unroll_loops ? UAP_UNROLL : 0) |
3081 (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0));
3083 loop_optimizer_finalize (loops, rtl_dump_file);
3086 cleanup_cfg (CLEANUP_EXPENSIVE);
3087 delete_trivially_dead_insns (insns, max_reg_num ());
3088 reg_scan (insns, max_reg_num (), 0);
3090 dump_flow_info (rtl_dump_file);
3091 close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
3092 timevar_pop (TV_LOOP);
3096 /* This is called from finish_function (within langhooks.parse_file)
3097 after each top-level definition is parsed.
3098 It is supposed to compile that function or variable
3099 and output the assembler code for it.
3100 After we return, the tree storage is freed. */
3103 rest_of_compilation (tree decl)
3106 int rebuild_label_notes_after_reload;
3108 timevar_push (TV_REST_OF_COMPILATION);
3110 /* Register rtl specific functions for cfg. */
3111 rtl_register_cfg_hooks ();
3113 /* Now that we're out of the frontend, we shouldn't have any more
3114 CONCATs anywhere. */
3115 generating_concat_p = 0;
3117 /* When processing delayed functions, prepare_function_start() won't
3118 have been run to re-initialize it. */
3119 cse_not_expected = ! optimize;
3121 /* First, make sure that NOTE_BLOCK is set correctly for each
3122 NOTE_INSN_BLOCK_BEG/NOTE_INSN_BLOCK_END note. */
3123 if (!cfun->x_whole_function_mode_p)
3126 /* In function-at-a-time mode, we do not attempt to keep the BLOCK
3127 tree in sensible shape. So, we just recalculate it here. */
3128 if (cfun->x_whole_function_mode_p)
3133 if (rest_of_handle_inlining (decl))
3134 goto exit_rest_of_compilation;
3136 /* If we're emitting a nested function, make sure its parent gets
3137 emitted as well. Doing otherwise confuses debug info. */
3140 for (parent = DECL_CONTEXT (current_function_decl);
3141 parent != NULL_TREE;
3142 parent = get_containing_scope (parent))
3143 if (TREE_CODE (parent) == FUNCTION_DECL)
3144 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
3147 /* We are now committed to emitting code for this function. Do any
3148 preparation, such as emitting abstract debug info for the inline
3149 before it gets mangled by optimization. */
3150 if (DECL_INLINE (decl))
3151 (*debug_hooks->outlining_inline_function) (decl);
3153 /* Remove any notes we don't need. That will make iterating
3154 over the instruction sequence faster, and allow the garbage
3155 collector to reclaim the memory used by the notes. */
3156 remove_unnecessary_notes ();
3161 /* Initialize some variables used by the optimizers. */
3162 init_function_for_compilation ();
3164 if (! DECL_DEFER_OUTPUT (decl))
3165 TREE_ASM_WRITTEN (decl) = 1;
3167 /* Now that integrate will no longer see our rtl, we need not
3168 distinguish between the return value of this function and the
3169 return value of called functions. Also, we can remove all SETs
3170 of subregs of hard registers; they are only here because of
3171 integrate. Also, we can now initialize pseudos intended to
3172 carry magic hard reg data throughout the function. */
3173 rtx_equal_function_value_matters = 0;
3174 purge_hard_subreg_sets (get_insns ());
3176 /* Early return if there were errors. We can run afoul of our
3177 consistency checks, and there's not really much point in fixing them.
3178 Don't return yet if -Wreturn-type; we need to do cleanup_cfg. */
3179 if (((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
3180 || errorcount || sorrycount)
3181 goto exit_rest_of_compilation;
3183 timevar_push (TV_JUMP);
3184 open_dump_file (DFI_sibling, decl);
3185 insns = get_insns ();
3186 rebuild_jump_labels (insns);
3187 find_exception_handler_labels ();
3188 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3190 delete_unreachable_blocks ();
3192 /* We have to issue these warnings now already, because CFG cleanups
3193 further down may destroy the required information. */
3194 check_function_return_warnings ();
3196 /* Turn NOTE_INSN_PREDICTIONs into branch predictions. */
3197 if (flag_guess_branch_prob)
3199 timevar_push (TV_BRANCH_PROB);
3200 note_prediction_to_br_prob ();
3201 timevar_pop (TV_BRANCH_PROB);
3204 if (flag_optimize_sibling_calls)
3205 rest_of_handle_sibling_calls (insns);
3207 timevar_pop (TV_JUMP);
3209 insn_locators_initialize ();
3210 /* Complete generation of exception handling code. */
3213 timevar_push (TV_JUMP);
3214 open_dump_file (DFI_eh, decl);
3216 finish_eh_generation ();
3218 close_dump_file (DFI_eh, print_rtl, get_insns ());
3219 timevar_pop (TV_JUMP);
3222 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
3223 generation, which might create new sets. */
3224 emit_initial_value_sets ();
3227 /* If we are doing position-independent code generation, now
3228 is the time to output special prologues and epilogues.
3229 We do not want to do this earlier, because it just clutters
3230 up inline functions with meaningless insns. */
3235 insns = get_insns ();
3237 /* Copy any shared structure that should not be shared. */
3238 unshare_all_rtl (current_function_decl, insns);
3240 #ifdef SETJMP_VIA_SAVE_AREA
3241 /* This must be performed before virtual register instantiation.
3242 Please be aware the everything in the compiler that can look
3243 at the RTL up to this point must understand that REG_SAVE_AREA
3244 is just like a use of the REG contained inside. */
3245 if (current_function_calls_alloca)
3246 optimize_save_area_alloca (insns);
3249 /* Instantiate all virtual registers. */
3250 instantiate_virtual_regs (current_function_decl, insns);
3252 open_dump_file (DFI_jump, decl);
3254 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3255 are initialized and to compute whether control can drop off the end
3258 timevar_push (TV_JUMP);
3259 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
3260 before jump optimization switches branch directions. */
3261 if (flag_guess_branch_prob)
3262 expected_value_to_br_prob ();
3264 reg_scan (insns, max_reg_num (), 0);
3265 rebuild_jump_labels (insns);
3266 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3267 delete_trivially_dead_insns (insns, max_reg_num ());
3269 dump_flow_info (rtl_dump_file);
3270 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
3271 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
3275 free_bb_for_insn ();
3276 copy_loop_headers (insns);
3277 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3279 purge_line_number_notes (insns);
3281 timevar_pop (TV_JUMP);
3282 close_dump_file (DFI_jump, print_rtl, insns);
3284 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
3285 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
3286 goto exit_rest_of_compilation;
3288 /* Long term, this should probably move before the jump optimizer too,
3289 but I didn't want to disturb the rtl_dump_and_exit and related
3290 stuff at this time. */
3291 if (optimize > 0 && flag_ssa)
3292 insns = rest_of_handle_ssa (decl, insns);
3294 timevar_push (TV_JUMP);
3297 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3299 if (flag_delete_null_pointer_checks)
3300 rest_of_handle_null_pointer (decl, insns);
3302 /* Jump optimization, and the removal of NULL pointer checks, may
3303 have reduced the number of instructions substantially. CSE, and
3304 future passes, allocate arrays whose dimensions involve the
3305 maximum instruction UID, so if we can reduce the maximum UID
3306 we'll save big on memory. */
3307 renumber_insns (rtl_dump_file);
3308 timevar_pop (TV_JUMP);
3310 close_dump_file (DFI_jump, print_rtl_with_bb, insns);
3315 rest_of_handle_cse (decl, insns);
3317 rest_of_handle_addressof (decl, insns);
3324 rest_of_handle_gcse (decl, insns);
3326 if (flag_loop_optimize)
3327 rest_of_handle_loop_optimize (decl, insns);
3330 rest_of_handle_jump_bypass (decl, insns);
3333 timevar_push (TV_FLOW);
3335 rest_of_handle_cfg (decl, insns);
3338 rest_of_handle_web (decl, insns);
3341 || profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
3342 rest_of_handle_branch_prob (decl, insns);
3345 rest_of_handle_if_conversion (decl, insns);
3348 rest_of_handle_tracer (decl, insns);
3351 && (flag_unswitch_loops
3353 || flag_unroll_loops))
3354 rest_of_handle_loop2 (decl, insns);
3356 if (flag_rerun_cse_after_loop)
3357 rest_of_handle_cse2 (decl, insns);
3359 cse_not_expected = 1;
3361 rest_of_handle_life (decl, insns);
3364 rest_of_handle_combine (decl, insns);
3366 if (flag_if_conversion)
3367 rest_of_handle_if_after_combine (decl, insns);
3369 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
3370 rest_of_handle_regmove (decl, insns);
3372 /* Do unconditional splitting before register allocation to allow machine
3373 description to add extra information not needed previously. */
3374 split_all_insns (1);
3376 #ifdef OPTIMIZE_MODE_SWITCHING
3377 timevar_push (TV_MODE_SWITCH);
3380 optimize_mode_switching (NULL);
3383 timevar_pop (TV_MODE_SWITCH);
3386 /* Any of the several passes since flow1 will have munged register
3387 lifetime data a bit. We need it to be up to date for scheduling
3388 (see handling of reg_known_equiv in init_alias_analysis). */
3389 recompute_reg_usage (insns, !optimize_size);
3391 #ifdef INSN_SCHEDULING
3392 rest_of_handle_sched (decl, insns);
3395 /* Determine if the current function is a leaf before running reload
3396 since this can impact optimizations done by the prologue and
3397 epilogue thus changing register elimination offsets. */
3398 current_function_is_leaf = leaf_function_p ();
3400 timevar_push (TV_LOCAL_ALLOC);
3401 open_dump_file (DFI_lreg, decl);
3403 if (flag_new_regalloc)
3405 if (rest_of_handle_new_regalloc (decl, insns,
3406 &rebuild_label_notes_after_reload))
3407 goto exit_rest_of_compilation;
3411 if (rest_of_handle_old_regalloc (decl, insns,
3412 &rebuild_label_notes_after_reload))
3413 goto exit_rest_of_compilation;
3418 open_dump_file (DFI_postreload, decl);
3420 /* Do a very simple CSE pass over just the hard registers. */
3423 timevar_push (TV_RELOAD_CSE_REGS);
3424 reload_cse_regs (insns);
3425 timevar_pop (TV_RELOAD_CSE_REGS);
3428 /* Register allocation and reloading may have turned an indirect jump into
3429 a direct jump. If so, we must rebuild the JUMP_LABEL fields of
3430 jumping instructions. */
3431 if (rebuild_label_notes_after_reload)
3433 timevar_push (TV_JUMP);
3435 rebuild_jump_labels (insns);
3436 purge_all_dead_edges (0);
3438 timevar_pop (TV_JUMP);
3441 close_dump_file (DFI_postreload, print_rtl_with_bb, insns);
3443 /* Re-create the death notes which were deleted during reload. */
3444 timevar_push (TV_FLOW2);
3445 open_dump_file (DFI_flow2, decl);
3447 #ifdef ENABLE_CHECKING
3448 verify_flow_info ();
3451 /* If optimizing, then go ahead and split insns now. */
3455 split_all_insns (0);
3457 if (flag_branch_target_load_optimize)
3459 open_dump_file (DFI_branch_target_load, decl);
3461 branch_target_load_optimize (insns, false);
3463 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3469 cleanup_cfg (CLEANUP_EXPENSIVE);
3471 /* On some machines, the prologue and epilogue code, or parts thereof,
3472 can be represented as RTL. Doing so lets us schedule insns between
3473 it and the rest of the code and also allows delayed branch
3474 scheduling to operate in the epilogue. */
3475 thread_prologue_and_epilogue_insns (insns);
3476 epilogue_completed = 1;
3480 life_analysis (insns, rtl_dump_file, PROP_FINAL);
3481 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
3482 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
3484 /* This is kind of a heuristic. We need to run combine_stack_adjustments
3485 even for machines with possibly nonzero RETURN_POPS_ARGS
3486 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
3487 push instructions will have popping returns. */
3488 #ifndef PUSH_ROUNDING
3489 if (!ACCUMULATE_OUTGOING_ARGS)
3491 combine_stack_adjustments ();
3496 flow2_completed = 1;
3498 close_dump_file (DFI_flow2, print_rtl_with_bb, insns);
3499 timevar_pop (TV_FLOW2);
3501 #ifdef HAVE_peephole2
3502 if (optimize > 0 && flag_peephole2)
3504 timevar_push (TV_PEEPHOLE2);
3505 open_dump_file (DFI_peephole2, decl);
3507 peephole2_optimize (rtl_dump_file);
3509 close_dump_file (DFI_peephole2, print_rtl_with_bb, insns);
3510 timevar_pop (TV_PEEPHOLE2);
3516 if (flag_rename_registers || flag_cprop_registers)
3517 rest_of_handle_regrename (decl, insns);
3519 rest_of_handle_reorder_blocks (decl, insns);
3522 if (flag_if_conversion2)
3524 timevar_push (TV_IFCVT2);
3525 open_dump_file (DFI_ce3, decl);
3529 close_dump_file (DFI_ce3, print_rtl_with_bb, insns);
3530 timevar_pop (TV_IFCVT2);
3533 if (flag_branch_target_load_optimize2)
3535 /* Leave this a warning for now so that it is possible to experiment
3536 with running this pass twice. In 3.6, we should either make this
3537 an error, or use separate dump files. */
3538 if (flag_branch_target_load_optimize)
3539 warning ("branch target register load optimization is not intended "
3542 open_dump_file (DFI_branch_target_load, decl);
3544 branch_target_load_optimize (insns, true);
3546 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3551 #ifdef INSN_SCHEDULING
3552 if (optimize > 0 && flag_schedule_insns_after_reload)
3553 rest_of_handle_sched2 (decl, insns);
3556 #ifdef LEAF_REGISTERS
3557 current_function_uses_only_leaf_regs
3558 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
3562 rest_of_handle_stack_regs (decl, insns);
3565 compute_alignments ();
3567 /* CFG is no longer maintained up-to-date. */
3568 free_bb_for_insn ();
3570 if (targetm.machine_dependent_reorg != 0)
3571 rest_of_handle_machine_reorg (decl, insns);
3573 purge_line_number_notes (insns);
3574 cleanup_barriers ();
3577 if (optimize > 0 && flag_delayed_branch)
3578 rest_of_handle_delay_slots (decl, insns);
3581 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3582 timevar_push (TV_SHORTEN_BRANCH);
3583 split_all_insns_noflow ();
3584 timevar_pop (TV_SHORTEN_BRANCH);
3587 convert_to_eh_region_ranges ();
3589 /* Shorten branches. */
3590 timevar_push (TV_SHORTEN_BRANCH);
3591 shorten_branches (get_insns ());
3592 timevar_pop (TV_SHORTEN_BRANCH);
3594 set_nothrow_function_flags ();
3595 if (current_function_nothrow)
3596 /* Now we know that this can't throw; set the flag for the benefit
3597 of other functions later in this translation unit. */
3598 TREE_NOTHROW (current_function_decl) = 1;
3600 rest_of_handle_final (decl, insns);
3602 /* Write DBX symbols if requested. */
3604 /* Note that for those inline functions where we don't initially
3605 know for certain that we will be generating an out-of-line copy,
3606 the first invocation of this routine (rest_of_compilation) will
3607 skip over this code by doing a `goto exit_rest_of_compilation;'.
3608 Later on, wrapup_global_declarations will (indirectly) call
3609 rest_of_compilation again for those inline functions that need
3610 to have out-of-line copies generated. During that call, we
3611 *will* be routed past here. */
3613 timevar_push (TV_SYMOUT);
3614 (*debug_hooks->function_decl) (decl);
3615 timevar_pop (TV_SYMOUT);
3617 exit_rest_of_compilation:
3619 coverage_end_function ();
3621 /* In case the function was not output,
3622 don't leave any temporary anonymous types
3623 queued up for sdb output. */
3624 #ifdef SDB_DEBUGGING_INFO
3625 if (write_symbols == SDB_DEBUG)
3626 sdbout_types (NULL_TREE);
3629 reload_completed = 0;
3630 epilogue_completed = 0;
3631 flow2_completed = 0;
3634 timevar_push (TV_FINAL);
3636 /* Clear out the insn_length contents now that they are no
3638 init_insn_lengths ();
3640 /* Show no temporary slots allocated. */
3643 free_basic_block_vars (0);
3644 free_bb_for_insn ();
3646 timevar_pop (TV_FINAL);
3648 if ((*targetm.binds_local_p) (current_function_decl))
3650 int pref = cfun->preferred_stack_boundary;
3651 if (cfun->recursive_call_emit
3652 && cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
3653 pref = cfun->stack_alignment_needed;
3654 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
3658 /* Make sure volatile mem refs aren't considered valid operands for
3659 arithmetic insns. We must call this here if this is a nested inline
3660 function, since the above code leaves us in the init_recog state
3661 (from final.c), and the function context push/pop code does not
3662 save/restore volatile_ok.
3664 ??? Maybe it isn't necessary for expand_start_function to call this
3665 anymore if we do it here? */
3667 init_recog_no_volatile ();
3669 /* We're done with this function. Free up memory if we can. */
3670 free_after_parsing (cfun);
3671 if (! DECL_DEFER_OUTPUT (decl))
3673 free_after_compilation (cfun);
3674 DECL_SAVED_INSNS (decl) = 0;
3680 timevar_pop (TV_REST_OF_COMPILATION);
3683 /* Display help for target options. */
3685 display_target_options (void)
3688 static bool displayed = false;
3690 /* Avoid double printing for --help --target-help. */
3696 if (ARRAY_SIZE (target_switches) > 1
3697 #ifdef TARGET_OPTIONS
3698 || ARRAY_SIZE (target_options) > 1
3706 printf (_("\nTarget specific options:\n"));
3708 for (i = ARRAY_SIZE (target_switches); i--;)
3710 const char *option = target_switches[i].name;
3711 const char *description = target_switches[i].description;
3713 if (option == NULL || *option == 0)
3715 else if (description == NULL)
3720 printf (_(" -m%-23s [undocumented]\n"), option);
3722 else if (*description != 0)
3723 doc += printf (" -m%-23s %s\n", option, _(description));
3726 #ifdef TARGET_OPTIONS
3727 for (i = ARRAY_SIZE (target_options); i--;)
3729 const char *option = target_options[i].prefix;
3730 const char *description = target_options[i].description;
3732 if (option == NULL || *option == 0)
3734 else if (description == NULL)
3739 printf (_(" -m%-23s [undocumented]\n"), option);
3741 else if (*description != 0)
3742 doc += printf (" -m%-23s %s\n", option, _(description));
3748 printf (_("\nThere are undocumented target specific options as well.\n"));
3750 printf (_(" They exist, but they are not documented.\n"));
3755 /* Parse a -d... command line switch. */
3758 decode_d_option (const char *arg)
3766 for (i = 0; i < (int) DFI_MAX; ++i)
3767 dump_file[i].enabled = 1;
3773 flag_print_asm_name = 1;
3776 flag_dump_rtl_in_asm = 1;
3777 flag_print_asm_name = 1;
3780 graph_dump_format = vcg;
3783 rtl_dump_and_exit = 1;
3788 case 'D': /* These are handled by the preprocessor. */
3792 setup_core_dumping();
3797 for (i = 0; i < (int) DFI_MAX; ++i)
3798 if (c == dump_file[i].debug_switch)
3800 dump_file[i].enabled = 1;
3805 warning ("unrecognized gcc debugging option: %c", c);
3810 /* Indexed by enum debug_info_type. */
3811 const char *const debug_type_names[] =
3813 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
3816 /* Decode -m switches. */
3817 /* Decode the switch -mNAME. */
3820 set_target_switch (const char *name)
3823 int valid_target_option = 0;
3825 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
3826 if (!strcmp (target_switches[j].name, name))
3828 if (target_switches[j].value < 0)
3829 target_flags &= ~-target_switches[j].value;
3831 target_flags |= target_switches[j].value;
3834 if (target_switches[j].value < 0)
3835 target_flags_explicit |= -target_switches[j].value;
3837 target_flags_explicit |= target_switches[j].value;
3839 valid_target_option = 1;
3842 #ifdef TARGET_OPTIONS
3843 if (!valid_target_option)
3844 for (j = 0; j < ARRAY_SIZE (target_options); j++)
3846 int len = strlen (target_options[j].prefix);
3847 if (target_options[j].value)
3849 if (!strcmp (target_options[j].prefix, name))
3851 *target_options[j].variable = target_options[j].value;
3852 valid_target_option = 1;
3857 if (!strncmp (target_options[j].prefix, name, len))
3859 *target_options[j].variable = name + len;
3860 valid_target_option = 1;
3866 if (!valid_target_option)
3867 error ("invalid option `%s'", name);
3870 /* Print version information to FILE.
3871 Each line begins with INDENT (for the case where FILE is the
3872 assembler output file). */
3875 print_version (FILE *file, const char *indent)
3878 #define __VERSION__ "[?]"
3882 "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
3884 "%s%s%s version %s (%s) compiled by CC.\n"
3886 , indent, *indent != 0 ? " " : "",
3887 lang_hooks.name, version_string, TARGET_NAME,
3888 indent, __VERSION__);
3889 fnotice (file, "%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n",
3890 indent, *indent != 0 ? " " : "",
3891 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
3894 /* Print an option value and return the adjusted position in the line.
3895 ??? We don't handle error returns from fprintf (disk full); presumably
3896 other code will catch a disk full though. */
3899 print_single_switch (FILE *file, int pos, int max,
3900 const char *indent, const char *sep, const char *term,
3901 const char *type, const char *name)
3903 /* The ultrix fprintf returns 0 on success, so compute the result we want
3904 here since we need it for the following test. */
3905 int len = strlen (sep) + strlen (type) + strlen (name);
3910 fprintf (file, "%s", term);
3915 fprintf (file, "%s", indent);
3916 pos = strlen (indent);
3918 fprintf (file, "%s%s%s", sep, type, name);
3923 /* Print active target switches to FILE.
3924 POS is the current cursor position and MAX is the size of a "line".
3925 Each line begins with INDENT and ends with TERM.
3926 Each switch is separated from the next by SEP. */
3929 print_switch_values (FILE *file, int pos, int max,
3930 const char *indent, const char *sep, const char *term)
3935 /* Fill in the -frandom-seed option, if the user didn't pass it, so
3936 that it can be printed below. This helps reproducibility. */
3939 /* Print the options as passed. */
3940 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
3941 _("options passed: "), "");
3943 for (p = &save_argv[1]; *p != NULL; p++)
3947 if (strcmp (*p, "-o") == 0)
3953 if (strcmp (*p, "-quiet") == 0)
3955 if (strcmp (*p, "-version") == 0)
3960 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
3963 fprintf (file, "%s", term);
3965 /* Print the -f and -m options that have been enabled.
3966 We don't handle language specific options but printing argv
3969 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
3970 _("options enabled: "), "");
3972 for (j = 0; j < ARRAY_SIZE (f_options); j++)
3973 if (*f_options[j].variable == f_options[j].on_value)
3974 pos = print_single_switch (file, pos, max, indent, sep, term,
3975 "-f", f_options[j].string);
3977 /* Print target specific options. */
3979 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
3980 if (target_switches[j].name[0] != '\0'
3981 && target_switches[j].value > 0
3982 && ((target_switches[j].value & target_flags)
3983 == target_switches[j].value))
3985 pos = print_single_switch (file, pos, max, indent, sep, term,
3986 "-m", target_switches[j].name);
3989 #ifdef TARGET_OPTIONS
3990 for (j = 0; j < ARRAY_SIZE (target_options); j++)
3991 if (*target_options[j].variable != NULL)
3994 sprintf (prefix, "-m%s", target_options[j].prefix);
3995 pos = print_single_switch (file, pos, max, indent, sep, term,
3996 prefix, *target_options[j].variable);
4000 fprintf (file, "%s", term);
4003 /* Open assembly code output file. Do this even if -fsyntax-only is
4004 on, because then the driver will have provided the name of a
4005 temporary file or bit bucket for us. NAME is the file specified on
4006 the command line, possibly NULL. */
4008 init_asm_output (const char *name)
4010 if (name == NULL && asm_file_name == 0)
4011 asm_out_file = stdout;
4014 if (asm_file_name == 0)
4016 int len = strlen (dump_base_name);
4017 char *dumpname = xmalloc (len + 6);
4018 memcpy (dumpname, dump_base_name, len + 1);
4019 strip_off_ending (dumpname, len);
4020 strcat (dumpname, ".s");
4021 asm_file_name = dumpname;
4023 if (!strcmp (asm_file_name, "-"))
4024 asm_out_file = stdout;
4026 asm_out_file = fopen (asm_file_name, "w+");
4027 if (asm_out_file == 0)
4028 fatal_error ("can't open %s for writing: %m", asm_file_name);
4031 #ifdef IO_BUFFER_SIZE
4032 setvbuf (asm_out_file, xmalloc (IO_BUFFER_SIZE),
4033 _IOFBF, IO_BUFFER_SIZE);
4036 if (!flag_syntax_only)
4038 targetm.asm_out.file_start ();
4040 #ifdef ASM_COMMENT_START
4041 if (flag_verbose_asm)
4043 /* Print the list of options in effect. */
4044 print_version (asm_out_file, ASM_COMMENT_START);
4045 print_switch_values (asm_out_file, 0, MAX_LINE,
4046 ASM_COMMENT_START, " ", "\n");
4047 /* Add a blank line here so it appears in assembler output but not
4049 fprintf (asm_out_file, "\n");
4055 /* Default tree printer. Handles declarations only. */
4057 default_tree_printer (pretty_printer * pp, text_info *text)
4059 switch (*text->format_spec)
4065 tree t = va_arg (*text->args_ptr, tree);
4066 const char *n = DECL_NAME (t)
4067 ? (*lang_hooks.decl_printable_name) (t, 2)
4078 /* Initialization of the front end environment, before command line
4079 options are parsed. Signal handlers, internationalization etc.
4080 ARGV0 is main's argv[0]. */
4082 general_init (const char *argv0)
4086 p = argv0 + strlen (argv0);
4087 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
4091 xmalloc_set_program_name (progname);
4095 gcc_init_libintl ();
4097 /* Initialize the diagnostics reporting machinery, so option parsing
4098 can give warnings and errors. */
4099 diagnostic_initialize (global_dc);
4100 /* Set a default printer. Language specific initializations will
4101 override it later. */
4102 pp_format_decoder (global_dc->printer) = &default_tree_printer;
4104 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
4106 signal (SIGSEGV, crash_signal);
4109 signal (SIGILL, crash_signal);
4112 signal (SIGBUS, crash_signal);
4115 signal (SIGABRT, crash_signal);
4117 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
4118 signal (SIGIOT, crash_signal);
4121 signal (SIGFPE, crash_signal);
4124 /* Other host-specific signal setup. */
4125 (*host_hooks.extra_signals)();
4127 /* Initialize the garbage-collector, string pools and tree type hash
4133 /* Initialize register usage now so switches may override. */
4136 /* Register the language-independent parameters. */
4137 add_params (lang_independent_params, LAST_PARAM);
4139 /* This must be done after add_params but before argument processing. */
4140 init_ggc_heuristics();
4143 /* Process the options that have been parsed. */
4145 process_options (void)
4147 /* Allow the front end to perform consistency checks and do further
4148 initialization based on the command line options. This hook also
4149 sets the original filename if appropriate (e.g. foo.i -> foo.c)
4150 so we can correctly initialize debug output. */
4151 no_backend = (*lang_hooks.post_options) (&main_input_filename);
4152 input_filename = main_input_filename;
4154 #ifdef OVERRIDE_OPTIONS
4155 /* Some machines may reject certain combinations of options. */
4159 /* Set aux_base_name if not already set. */
4162 else if (main_input_filename)
4164 char *name = xstrdup (lbasename (main_input_filename));
4166 strip_off_ending (name, strlen (name));
4167 aux_base_name = name;
4170 aux_base_name = "gccaux";
4172 /* Set up the align_*_log variables, defaulting them to 1 if they
4173 were still unset. */
4174 if (align_loops <= 0) align_loops = 1;
4175 if (align_loops_max_skip > align_loops || !align_loops)
4176 align_loops_max_skip = align_loops - 1;
4177 align_loops_log = floor_log2 (align_loops * 2 - 1);
4178 if (align_jumps <= 0) align_jumps = 1;
4179 if (align_jumps_max_skip > align_jumps || !align_jumps)
4180 align_jumps_max_skip = align_jumps - 1;
4181 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
4182 if (align_labels <= 0) align_labels = 1;
4183 align_labels_log = floor_log2 (align_labels * 2 - 1);
4184 if (align_labels_max_skip > align_labels || !align_labels)
4185 align_labels_max_skip = align_labels - 1;
4186 if (align_functions <= 0) align_functions = 1;
4187 align_functions_log = floor_log2 (align_functions * 2 - 1);
4189 /* Unrolling all loops implies that standard loop unrolling must also
4191 if (flag_unroll_all_loops)
4192 flag_unroll_loops = 1;
4194 if (flag_unroll_loops)
4196 flag_old_unroll_loops = 0;
4197 flag_old_unroll_all_loops = 0;
4200 if (flag_old_unroll_all_loops)
4201 flag_old_unroll_loops = 1;
4203 /* Old loop unrolling requires that strength_reduction be on also. Silently
4204 turn on strength reduction here if it isn't already on. Also, the loop
4205 unrolling code assumes that cse will be run after loop, so that must
4206 be turned on also. */
4207 if (flag_old_unroll_loops)
4209 flag_strength_reduce = 1;
4210 flag_rerun_cse_after_loop = 1;
4212 if (flag_unroll_loops || flag_peel_loops)
4213 flag_rerun_cse_after_loop = 1;
4215 if (flag_non_call_exceptions)
4216 flag_asynchronous_unwind_tables = 1;
4217 if (flag_asynchronous_unwind_tables)
4218 flag_unwind_tables = 1;
4220 /* Disable unit-at-a-time mode for frontends not supporting callgraph
4222 if (flag_unit_at_a_time && ! lang_hooks.callgraph.expand_function)
4223 flag_unit_at_a_time = 0;
4225 /* Warn about options that are not supported on this machine. */
4226 #ifndef INSN_SCHEDULING
4227 if (flag_schedule_insns || flag_schedule_insns_after_reload)
4228 warning ("instruction scheduling not supported on this target machine");
4231 if (flag_delayed_branch)
4232 warning ("this target machine does not have delayed branches");
4235 user_label_prefix = USER_LABEL_PREFIX;
4236 if (flag_leading_underscore != -1)
4238 /* If the default prefix is more complicated than "" or "_",
4239 issue a warning and ignore this option. */
4240 if (user_label_prefix[0] == 0 ||
4241 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
4243 user_label_prefix = flag_leading_underscore ? "_" : "";
4246 warning ("-f%sleading-underscore not supported on this target machine",
4247 flag_leading_underscore ? "" : "no-");
4250 /* If we are in verbose mode, write out the version and maybe all the
4251 option flags in use. */
4254 print_version (stderr, "");
4256 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
4259 if (flag_syntax_only)
4261 write_symbols = NO_DEBUG;
4265 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
4267 if (debug_info_level == DINFO_LEVEL_NONE)
4268 write_symbols = NO_DEBUG;
4270 /* Now we know write_symbols, set up the debug hooks based on it.
4271 By default we do nothing for debug output. */
4272 if (write_symbols == NO_DEBUG)
4273 debug_hooks = &do_nothing_debug_hooks;
4274 #if defined(DBX_DEBUGGING_INFO)
4275 else if (write_symbols == DBX_DEBUG)
4276 debug_hooks = &dbx_debug_hooks;
4278 #if defined(XCOFF_DEBUGGING_INFO)
4279 else if (write_symbols == XCOFF_DEBUG)
4280 debug_hooks = &xcoff_debug_hooks;
4282 #ifdef SDB_DEBUGGING_INFO
4283 else if (write_symbols == SDB_DEBUG)
4284 debug_hooks = &sdb_debug_hooks;
4286 #ifdef DWARF_DEBUGGING_INFO
4287 else if (write_symbols == DWARF_DEBUG)
4288 debug_hooks = &dwarf_debug_hooks;
4290 #ifdef DWARF2_DEBUGGING_INFO
4291 else if (write_symbols == DWARF2_DEBUG)
4292 debug_hooks = &dwarf2_debug_hooks;
4294 #ifdef VMS_DEBUGGING_INFO
4295 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
4296 debug_hooks = &vmsdbg_debug_hooks;
4299 error ("target system does not support the \"%s\" debug format",
4300 debug_type_names[write_symbols]);
4302 /* If auxiliary info generation is desired, open the output file.
4303 This goes in the same directory as the source file--unlike
4304 all the other output files. */
4305 if (flag_gen_aux_info)
4307 aux_info_file = fopen (aux_info_file_name, "w");
4308 if (aux_info_file == 0)
4309 fatal_error ("can't open %s: %m", aux_info_file_name);
4312 if (! targetm.have_named_sections)
4314 if (flag_function_sections)
4316 warning ("-ffunction-sections not supported for this target");
4317 flag_function_sections = 0;
4319 if (flag_data_sections)
4321 warning ("-fdata-sections not supported for this target");
4322 flag_data_sections = 0;
4326 if (flag_function_sections && profile_flag)
4328 warning ("-ffunction-sections disabled; it makes profiling impossible");
4329 flag_function_sections = 0;
4332 #ifndef HAVE_prefetch
4333 if (flag_prefetch_loop_arrays)
4335 warning ("-fprefetch-loop-arrays not supported for this target");
4336 flag_prefetch_loop_arrays = 0;
4339 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
4341 warning ("-fprefetch-loop-arrays not supported for this target (try -march switches)");
4342 flag_prefetch_loop_arrays = 0;
4346 /* This combination of options isn't handled for i386 targets and doesn't
4347 make much sense anyway, so don't allow it. */
4348 if (flag_prefetch_loop_arrays && optimize_size)
4350 warning ("-fprefetch-loop-arrays is not supported with -Os");
4351 flag_prefetch_loop_arrays = 0;
4354 #ifndef OBJECT_FORMAT_ELF
4355 if (flag_function_sections && write_symbols != NO_DEBUG)
4356 warning ("-ffunction-sections may affect debugging on some targets");
4359 /* The presence of IEEE signaling NaNs, implies all math can trap. */
4360 if (flag_signaling_nans)
4361 flag_trapping_math = 1;
4364 /* Initialize the compiler back end. */
4368 init_adjust_machine_modes ();
4370 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
4371 || debug_info_level == DINFO_LEVEL_VERBOSE
4372 #ifdef VMS_DEBUGGING_INFO
4373 /* Enable line number info for traceback. */
4374 || debug_info_level > DINFO_LEVEL_NONE
4376 || flag_test_coverage
4377 || warn_notreached);
4380 init_fake_stack_mems ();
4384 init_function_once ();
4385 init_varasm_once ();
4387 /* The following initialization functions need to generate rtl, so
4388 provide a dummy function context for them. */
4389 init_dummy_function_start ();
4391 if (flag_caller_saves)
4392 init_caller_save ();
4393 expand_dummy_function_end ();
4396 /* Language-dependent initialization. Returns nonzero on success. */
4398 lang_dependent_init (const char *name)
4400 if (dump_base_name == 0)
4401 dump_base_name = name ? name : "gccdump";
4403 /* Other front-end initialization. */
4404 if ((*lang_hooks.init) () == 0)
4407 init_asm_output (name);
4409 /* These create various _DECL nodes, so need to be called after the
4410 front end is initialized. */
4414 /* The following initialization functions need to generate rtl, so
4415 provide a dummy function context for them. */
4416 init_dummy_function_start ();
4418 expand_dummy_function_end ();
4420 /* If dbx symbol table desired, initialize writing it and output the
4421 predefined types. */
4422 timevar_push (TV_SYMOUT);
4424 #ifdef DWARF2_UNWIND_INFO
4425 if (dwarf2out_do_frame ())
4426 dwarf2out_frame_init ();
4429 /* Now we have the correct original filename, we can initialize
4431 (*debug_hooks->init) (name);
4433 timevar_pop (TV_SYMOUT);
4438 /* Clean up: close opened files, etc. */
4443 /* Close the dump files. */
4444 if (flag_gen_aux_info)
4446 fclose (aux_info_file);
4448 unlink (aux_info_file_name);
4451 /* Close non-debugging input and output files. Take special care to note
4452 whether fclose returns an error, since the pages might still be on the
4453 buffer chain while the file is open. */
4457 if (ferror (asm_out_file) != 0)
4458 fatal_error ("error writing to %s: %m", asm_file_name);
4459 if (fclose (asm_out_file) != 0)
4460 fatal_error ("error closing %s: %m", asm_file_name);
4463 /* Do whatever is necessary to finish printing the graphs. */
4464 if (graph_dump_format != no_graph)
4468 for (i = 0; i < (int) DFI_MAX; ++i)
4469 if (dump_file[i].initialized && dump_file[i].graph_dump_p)
4474 sprintf (seq, DUMPFILE_FORMAT, i);
4475 suffix = concat (seq, dump_file[i].extension, NULL);
4476 finish_graph_dump_file (dump_base_name, suffix);
4483 ggc_print_statistics ();
4484 stringpool_statistics ();
4485 dump_tree_statistics ();
4488 /* Free up memory for the benefit of leak detectors. */
4491 /* Language-specific end of compilation actions. */
4492 (*lang_hooks.finish) ();
4495 /* Initialize the compiler, and compile the input file. */
4499 /* Initialize timing first. The C front ends read the main file in
4500 the post_options hook, and C++ does file timings. */
4501 if (time_report || !quiet_flag || flag_detailed_statistics)
4503 timevar_start (TV_TOTAL);
4507 /* Don't do any more if an error has already occurred. */
4510 /* Set up the back-end if requested. */
4514 /* Language-dependent initialization. Returns true on success. */
4515 if (lang_dependent_init (main_input_filename))
4517 if (flag_unit_at_a_time)
4519 open_dump_file (DFI_cgraph, NULL);
4520 cgraph_dump_file = rtl_dump_file;
4521 rtl_dump_file = NULL;
4526 if (flag_unit_at_a_time)
4528 rtl_dump_file = cgraph_dump_file;
4529 cgraph_dump_file = NULL;
4530 close_dump_file (DFI_cgraph, NULL, NULL_RTX);
4537 /* Stop timing and print the times. */
4538 timevar_stop (TV_TOTAL);
4539 timevar_print (stderr);
4542 /* Entry point of cc1, cc1plus, jc1, f771, etc.
4543 Exit code is FATAL_EXIT_CODE if can't open files or if there were
4544 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
4546 It is not safe to call this function more than once. */
4549 toplev_main (unsigned int argc, const char **argv)
4553 /* Initialization of GCC's environment, and diagnostics. */
4554 general_init (argv[0]);
4556 /* Parse the options and do minimal processing; basically just
4557 enough to default flags appropriately. */
4558 decode_options (argc, argv);
4562 /* Exit early if we can (e.g. -help). */
4563 if (!exit_after_options)
4566 if (errorcount || sorrycount)
4567 return (FATAL_EXIT_CODE);
4569 return (SUCCESS_EXIT_CODE);