1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
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>
49 #include "insn-attr.h"
50 #include "insn-config.h"
51 #include "insn-flags.h"
52 #include "hard-reg-set.h"
59 #include "basic-block.h"
66 #include "diagnostic.h"
69 #include "dwarf2asm.h"
70 #include "integrate.h"
74 #include "langhooks.h"
75 #include "cfglayout.h"
77 #include "hosthooks.h"
81 #include "value-prof.h"
82 #include "alloc-pool.h"
84 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
85 #include "dwarf2out.h"
88 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
92 #ifdef SDB_DEBUGGING_INFO
96 #ifdef XCOFF_DEBUGGING_INFO
97 #include "xcoffout.h" /* Needed for external data
98 declarations for e.g. AIX 4.x. */
101 #ifndef HAVE_conditional_execution
102 #define HAVE_conditional_execution 0
105 /* Carry information from ASM_DECLARE_OBJECT_NAME
106 to ASM_FINISH_DECLARE_OBJECT. */
108 extern int size_directive_output;
109 extern tree last_assemble_variable_decl;
111 extern void reg_alloc (void);
113 static void general_init (const char *);
114 static void do_compile (void);
115 static void process_options (void);
116 static void backend_init (void);
117 static int lang_dependent_init (const char *);
118 static void init_asm_output (const char *);
119 static void finalize (void);
121 static void crash_signal (int) ATTRIBUTE_NORETURN;
122 static void setup_core_dumping (void);
123 static void compile_file (void);
125 static int print_single_switch (FILE *, int, int, const char *,
126 const char *, const char *,
127 const char *, const char *);
128 static void print_switch_values (FILE *, int, int, const char *,
129 const char *, const char *);
131 /* Rest of compilation helper functions. */
132 static bool rest_of_handle_inlining (tree);
133 static void rest_of_handle_cse (tree, rtx);
134 static void rest_of_handle_cse2 (tree, rtx);
135 static void rest_of_handle_gcse (tree, rtx);
136 static void rest_of_handle_life (tree, rtx);
137 static void rest_of_handle_loop_optimize (tree, rtx);
138 static void rest_of_handle_loop2 (tree, rtx);
139 static void rest_of_handle_jump_bypass (tree, rtx);
140 static void rest_of_handle_sibling_calls (rtx);
141 static void rest_of_handle_null_pointer (tree, rtx);
142 static void rest_of_handle_addressof (tree, rtx);
143 static void rest_of_handle_cfg (tree, rtx);
144 static void rest_of_handle_branch_prob (tree, rtx);
145 static void rest_of_handle_value_profile_transformations (tree, rtx);
146 static void rest_of_handle_if_conversion (tree, rtx);
147 static void rest_of_handle_if_after_combine (tree, rtx);
148 static void rest_of_handle_tracer (tree, rtx);
149 static void rest_of_handle_combine (tree, rtx);
150 static void rest_of_handle_regmove (tree, rtx);
151 #ifdef INSN_SCHEDULING
152 static void rest_of_handle_sched (tree, rtx);
153 static void rest_of_handle_sched2 (tree, rtx);
155 static bool rest_of_handle_new_regalloc (tree, rtx);
156 static bool rest_of_handle_old_regalloc (tree, rtx);
157 static void rest_of_handle_regrename (tree, rtx);
158 static void rest_of_handle_reorder_blocks (tree, rtx);
160 static void rest_of_handle_stack_regs (tree, rtx);
162 static void rest_of_handle_variable_tracking (tree, rtx);
163 static void rest_of_handle_machine_reorg (tree, rtx);
165 static void rest_of_handle_delay_slots (tree, rtx);
167 static void rest_of_handle_final (tree, rtx);
169 /* Nonzero to dump debug info whilst parsing (-dy option). */
170 static int set_yydebug;
172 /* True if we don't need a backend (e.g. preprocessing only). */
173 static bool no_backend;
175 /* Length of line when printing switch values. */
178 /* Name of program invoked, sans directories. */
180 const char *progname;
182 /* Copy of argument vector to toplev_main. */
183 static const char **save_argv;
185 /* Name of top-level original source file (what was input to cpp).
186 This comes from the #-command at the beginning of the actual input.
187 If there isn't any there, then this is the cc1 input file name. */
189 const char *main_input_filename;
191 /* Current position in real source file. */
193 location_t input_location;
195 struct line_maps line_table;
197 /* Nonzero if it is unsafe to create any new pseudo registers. */
200 /* Stack of currently pending input files. */
202 struct file_stack *input_file_stack;
204 /* Incremented on each change to input_file_stack. */
205 int input_file_stack_tick;
207 /* Name to use as base of names for dump output files. */
209 const char *dump_base_name;
211 /* Name to use as a base for auxiliary output files. */
213 const char *aux_base_name;
215 /* Format to use to print dumpfile index value */
216 #ifndef DUMPFILE_FORMAT
217 #define DUMPFILE_FORMAT ".%02d."
220 /* Bit flags that specify the machine subtype we are compiling for.
221 Bits are tested using macros TARGET_... defined in the tm.h file
222 and set by `-m...' switches. Must be defined in rtlanal.c. */
224 extern int target_flags;
226 /* A mask of target_flags that includes bit X if X was set or cleared
227 on the command line. */
229 int target_flags_explicit;
231 /* Debug hooks - dependent upon command line options. */
233 const struct gcc_debug_hooks *debug_hooks;
235 /* Describes a dump file. */
237 struct dump_file_info
239 /* The unique extension to apply, e.g. ".jump". */
240 const char *const extension;
242 /* The -d<c> character that enables this dump file. */
243 char const debug_switch;
245 /* True if there is a corresponding graph dump file. */
246 char const graph_dump_p;
248 /* True if the user selected this dump. */
251 /* True if the files have been initialized (ie truncated). */
255 /* Enumerate the extant dump files. */
291 DFI_branch_target_load,
300 /* Describes all the dump files. Should be kept in order of the
301 pass and in sync with dump_file_index above.
303 Remaining -d letters:
309 static struct dump_file_info dump_file[DFI_MAX] =
311 { "cgraph", 'U', 0, 0, 0 },
312 { "rtl", 'r', 0, 0, 0 },
313 { "sibling", 'i', 0, 0, 0 },
314 { "eh", 'h', 0, 0, 0 },
315 { "jump", 'j', 0, 0, 0 },
316 { "null", 'u', 0, 0, 0 },
317 { "cse", 's', 0, 0, 0 },
318 { "addressof", 'F', 0, 0, 0 },
319 { "gcse", 'G', 1, 0, 0 },
320 { "loop", 'L', 1, 0, 0 },
321 { "bypass", 'G', 1, 0, 0 }, /* Yes, duplicate enable switch. */
322 { "cfg", 'f', 1, 0, 0 },
323 { "bp", 'b', 1, 0, 0 },
324 { "vpt", 'V', 1, 0, 0 },
325 { "ce1", 'C', 1, 0, 0 },
326 { "tracer", 'T', 1, 0, 0 },
327 { "loop2", 'L', 1, 0, 0 },
328 { "web", 'Z', 0, 0, 0 },
329 { "cse2", 't', 1, 0, 0 },
330 { "life", 'f', 1, 0, 0 }, /* Yes, duplicate enable switch. */
331 { "combine", 'c', 1, 0, 0 },
332 { "ce2", 'C', 1, 0, 0 },
333 { "regmove", 'N', 1, 0, 0 },
334 { "sched", 'S', 1, 0, 0 },
335 { "lreg", 'l', 1, 0, 0 },
336 { "greg", 'g', 1, 0, 0 },
337 { "postreload", 'o', 1, 0, 0 },
338 { "flow2", 'w', 1, 0, 0 },
339 { "peephole2", 'z', 1, 0, 0 },
340 { "ce3", 'E', 1, 0, 0 },
341 { "rnreg", 'n', 1, 0, 0 },
342 { "bbro", 'B', 1, 0, 0 },
343 { "btl", 'd', 1, 0, 0 }, /* Yes, duplicate enable switch. */
344 { "sched2", 'R', 1, 0, 0 },
345 { "stack", 'k', 1, 0, 0 },
346 { "vartrack", 'V', 1, 0, 0 }, /* Yes, duplicate enable switch. */
347 { "mach", 'M', 1, 0, 0 },
348 { "dbr", 'd', 0, 0, 0 },
351 static int open_dump_file (enum dump_file_index, tree);
352 static void close_dump_file (enum dump_file_index,
353 void (*) (FILE *, rtx), rtx);
355 /* Other flags saying which kinds of debugging dump have been requested. */
357 int rtl_dump_and_exit;
358 int flag_print_asm_name;
359 enum graph_dump_types graph_dump_format;
361 /* Name for output file of assembly code, specified with -o. */
363 const char *asm_file_name;
365 /* Nonzero means do optimizations. -O.
366 Particular numeric values stand for particular amounts of optimization;
367 thus, -O2 stores 2 here. However, the optimizations beyond the basic
368 ones are not controlled directly by this variable. Instead, they are
369 controlled by individual `flag_...' variables that are defaulted
370 based on this variable. */
374 /* Nonzero means optimize for size. -Os.
375 The only valid values are zero and nonzero. When optimize_size is
376 nonzero, optimize defaults to 2, but certain individual code
377 bloating optimizations are disabled. */
379 int optimize_size = 0;
381 /* The FUNCTION_DECL for the function currently being compiled,
382 or 0 if between functions. */
383 tree current_function_decl;
385 /* Set to the FUNC_BEGIN label of the current function, or NULL_TREE
387 tree current_function_func_begin_label;
389 /* Nonzero if doing dwarf2 duplicate elimination. */
391 int flag_eliminate_dwarf2_dups = 0;
393 /* Nonzero if doing unused type elimination. */
395 int flag_eliminate_unused_debug_types = 1;
397 /* Nonzero means emit debugging information only for symbols which are used. */
398 int flag_debug_only_used_symbols = 0;
400 /* Nonzero if generating code to do profiling. */
402 int profile_flag = 0;
404 /* Nonzero if generating code to profile program flow graph arcs. */
406 int profile_arc_flag = 0;
408 /* Nonzero if value histograms should be measured. */
410 int flag_profile_values = 0;
412 /* Nonzero if value histograms should be used to optimize code. */
413 int flag_value_profile_transformations = 0;
415 /* Nonzero if generating info for gcov to calculate line test coverage. */
417 int flag_test_coverage = 0;
419 /* Nonzero indicates that branch taken probabilities should be calculated. */
421 int flag_branch_probabilities = 0;
423 /* Nonzero if basic blocks should be reordered. */
425 int flag_reorder_blocks = 0;
427 /* Nonzero if functions should be reordered. */
429 int flag_reorder_functions = 0;
431 /* Nonzero if registers should be renamed. */
433 int flag_rename_registers = 0;
434 int flag_cprop_registers = 0;
436 /* Nonzero for -pedantic switch: warn about anything
437 that standard spec forbids. */
441 /* Temporarily suppress certain warnings.
442 This is set while reading code from a system header file. */
444 int in_system_header = 0;
446 /* Don't print functions as they are compiled. -quiet. */
450 /* Print times taken by the various passes. -ftime-report. */
454 /* Print memory still in use at end of compilation (which may have little
455 to do with peak memory consumption). -fmem-report. */
459 /* Nonzero means to collect statistics which might be expensive
460 and to print them when we are done. */
461 int flag_detailed_statistics = 0;
463 /* A random sequence of characters, unless overridden by user. */
464 const char *flag_random_seed;
466 /* A local time stamp derived from the time of compilation. It will be
467 zero if the system cannot provide a time. It will be -1u, if the
468 user has specified a particular random seed. */
473 /* Nonzero means `char' should be signed. */
475 int flag_signed_char;
477 /* Nonzero means give an enum type only as many bytes as it needs. */
479 int flag_short_enums;
481 /* Nonzero for -fcaller-saves: allocate values in regs that need to
482 be saved across function calls, if that produces overall better code.
483 Optional now, so people can test it. */
485 int flag_caller_saves = 0;
487 /* Nonzero if structures and unions should be returned in memory.
489 This should only be defined if compatibility with another compiler or
490 with an ABI is needed, because it results in slower code. */
492 #ifndef DEFAULT_PCC_STRUCT_RETURN
493 #define DEFAULT_PCC_STRUCT_RETURN 1
496 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
498 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
500 /* Nonzero for -fforce-mem: load memory value into a register
501 before arithmetic on it. This makes better cse but slower compilation. */
503 int flag_force_mem = 0;
505 /* Nonzero for -fforce-addr: load memory address into a register before
506 reference to memory. This makes better cse but slower compilation. */
508 int flag_force_addr = 0;
510 /* Nonzero for -fdefer-pop: don't pop args after each function call;
511 instead save them up to pop many calls' args with one insns. */
513 int flag_defer_pop = 0;
515 /* Nonzero for -ffloat-store: don't allocate floats and doubles
516 in extended-precision registers. */
518 int flag_float_store = 0;
520 /* Nonzero for -fcse-follow-jumps:
521 have cse follow jumps to do a more extensive job. */
523 int flag_cse_follow_jumps;
525 /* Nonzero for -fcse-skip-blocks:
526 have cse follow a branch around a block. */
527 int flag_cse_skip_blocks;
529 /* Nonzero for -fexpensive-optimizations:
530 perform miscellaneous relatively-expensive optimizations. */
531 int flag_expensive_optimizations;
533 /* Nonzero for -fthread-jumps:
534 have jump optimize output of loop. */
536 int flag_thread_jumps;
538 /* Nonzero enables strength-reduction in loop.c. */
540 int flag_strength_reduce = 0;
542 /* Nonzero enables loop unrolling in unroll.c. Only loops for which the
543 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
544 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
547 int flag_old_unroll_loops;
549 /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
550 This is generally not a win. */
552 int flag_old_unroll_all_loops;
554 /* Enables unrolling of simple loops in loop-unroll.c. */
555 int flag_unroll_loops;
557 /* Enables unrolling of all loops in loop-unroll.c. */
558 int flag_unroll_all_loops;
560 /* Nonzero enables loop peeling. */
563 /* Nonzero enables loop unswitching. */
564 int flag_unswitch_loops;
566 /* Nonzero enables prefetch optimizations for arrays in loops. */
568 int flag_prefetch_loop_arrays;
570 /* Nonzero forces all invariant computations in loops to be moved
573 int flag_move_all_movables = 0;
575 /* Nonzero forces all general induction variables in loops to be
578 int flag_reduce_all_givs = 0;
580 /* Nonzero to perform full register move optimization passes. This is the
583 int flag_regmove = 0;
585 /* Nonzero for -fwritable-strings:
586 store string constants in data segment and don't uniquize them. */
588 int flag_writable_strings = 0;
590 /* Nonzero means don't put addresses of constant functions in registers.
591 Used for compiling the Unix kernel, where strange substitutions are
592 done on the assembly output. */
594 int flag_no_function_cse = 0;
596 /* Nonzero for -fomit-frame-pointer:
597 don't make a frame pointer in simple functions that don't require one. */
599 int flag_omit_frame_pointer = 0;
601 /* Nonzero means place each function into its own section on those platforms
602 which support arbitrary section names and unlimited numbers of sections. */
604 int flag_function_sections = 0;
606 /* ... and similar for data. */
608 int flag_data_sections = 0;
610 /* Nonzero to inhibit use of define_optimization peephole opts. */
612 int flag_no_peephole = 0;
614 /* Nonzero allows GCC to optimize sibling and tail recursive calls. */
616 int flag_optimize_sibling_calls = 0;
618 /* Nonzero means the front end generally wants `errno' maintained by math
619 operations, like built-in SQRT. */
621 int flag_errno_math = 1;
623 /* Nonzero means that unsafe floating-point math optimizations are allowed
624 for the sake of speed. IEEE compliance is not guaranteed, and operations
625 are allowed to assume that their arguments and results are "normal"
626 (e.g., nonnegative for SQRT). */
628 int flag_unsafe_math_optimizations = 0;
630 /* Nonzero means that no NaNs or +-Infs are expected. */
632 int flag_finite_math_only = 0;
634 /* Zero means that floating-point math operations cannot generate a
635 (user-visible) trap. This is the case, for example, in nonstop
636 IEEE 754 arithmetic. Trapping conditions include division by zero,
637 overflow, underflow, invalid and inexact, but does not include
638 operations on signaling NaNs (see below). */
640 int flag_trapping_math = 1;
642 /* Nonzero means disable transformations that assume default floating
643 point rounding behavior. */
645 int flag_rounding_math = 0;
647 /* Nonzero means disable transformations observable by signaling NaNs.
648 This option implies that any operation on an IEEE signaling NaN can
649 generate a (user-visible) trap. */
651 int flag_signaling_nans = 0;
653 /* 0 means straightforward implementation of complex divide acceptable.
654 1 means wide ranges of inputs must work for complex divide.
655 2 means C99-like requirements for complex divide (not yet implemented). */
657 int flag_complex_divide_method = 0;
659 /* Nonzero means just do syntax checking; don't output anything. */
661 int flag_syntax_only = 0;
663 /* Nonzero means performs web construction pass. */
667 /* Nonzero means perform loop optimizer. */
669 int flag_loop_optimize;
671 /* Nonzero means perform crossjumping. */
673 int flag_crossjumping;
675 /* Nonzero means perform if conversion. */
677 int flag_if_conversion;
679 /* Nonzero means perform if conversion after reload. */
681 int flag_if_conversion2;
683 /* Nonzero means to use global dataflow analysis to eliminate
684 useless null pointer tests. */
686 int flag_delete_null_pointer_checks;
688 /* Nonzero means perform global CSE. */
692 /* Nonzero means to do the enhanced load motion during gcse, which trys
693 to hoist loads by not killing them when a store to the same location
696 int flag_gcse_lm = 1;
698 /* Nonzero means to perform store motion after gcse, which will try to
699 move stores closer to the exit block. Its not very effective without
702 int flag_gcse_sm = 1;
704 /* Nonzero if we want to perfrom redundant load after store elimination
707 int flag_gcse_las = 1;
709 /* Perform target register optimization before prologue / epilogue
712 int flag_branch_target_load_optimize = 0;
714 /* Perform target register optimization after prologue / epilogue
715 threading and jump2. */
717 int flag_branch_target_load_optimize2 = 0;
719 /* For the bt-load pass, nonzero means don't re-use branch target registers
720 in any basic block. */
722 int flag_btr_bb_exclusive;
724 /* Nonzero means to rerun cse after loop optimization. This increases
725 compilation time about 20% and picks up a few more common expressions. */
727 int flag_rerun_cse_after_loop;
729 /* Nonzero means to run loop optimizations twice. */
731 int flag_rerun_loop_opt;
733 /* Nonzero for -finline-functions: ok to inline functions that look like
734 good inline candidates. */
736 int flag_inline_functions;
738 /* Nonzero for -fkeep-inline-functions: even if we make a function
739 go inline everywhere, keep its definition around for debugging
742 int flag_keep_inline_functions;
744 /* Nonzero means that functions will not be inlined. */
746 int flag_no_inline = 2;
748 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
749 not just because the tree inliner turned us off. */
751 int flag_really_no_inline = 2;
753 /* Nonzero means that we should emit static const variables
754 regardless of whether or not optimization is turned on. */
756 int flag_keep_static_consts = 1;
758 /* Nonzero means we should be saving declaration info into a .X file. */
760 int flag_gen_aux_info = 0;
762 /* Specified name of aux-info file. */
764 const char *aux_info_file_name;
766 /* Nonzero means make the text shared if supported. */
768 int flag_shared_data;
770 /* Nonzero means schedule into delayed branch slots if supported. */
772 int flag_delayed_branch;
774 /* Nonzero if we are compiling pure (sharable) code.
775 Value is 1 if we are doing "small" pic; value is 2 if we're doing
780 /* Nonzero if we are compiling position independent code for executable.
781 The value is 1 if we are doing "small" pic; value is 2 if we're doing
786 /* Nonzero if we are compiling code for a shared library, zero for
791 /* Set to the default thread-local storage (tls) model to use. */
793 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
795 /* Nonzero means generate extra code for exception handling and enable
796 exception handling. */
800 /* Nonzero means generate frame unwind info table when supported. */
802 int flag_unwind_tables = 0;
804 /* Nonzero means generate frame unwind info table exact at each insn
807 int flag_asynchronous_unwind_tables = 0;
809 /* Nonzero means don't place uninitialized global data in common storage
814 /* Nonzero means change certain warnings into errors.
815 Usually these are warnings about failure to conform to some standard. */
817 int flag_pedantic_errors = 0;
819 /* flag_schedule_insns means schedule insns within basic blocks (before
821 flag_schedule_insns_after_reload means schedule insns after
824 int flag_schedule_insns = 0;
825 int flag_schedule_insns_after_reload = 0;
827 /* When flag_schedule_insns_after_reload is set, use EBB scheduler. */
828 int flag_sched2_use_superblocks = 0;
830 /* When flag_schedule_insns_after_reload is set, construct traces and EBB
832 int flag_sched2_use_traces = 0;
834 /* The following flags have effect only for scheduling before register
837 flag_schedule_interblock means schedule insns across basic blocks.
838 flag_schedule_speculative means allow speculative motion of non-load insns.
839 flag_schedule_speculative_load means allow speculative motion of some
841 flag_schedule_speculative_load_dangerous allows speculative motion of more
844 int flag_schedule_interblock = 1;
845 int flag_schedule_speculative = 1;
846 int flag_schedule_speculative_load = 0;
847 int flag_schedule_speculative_load_dangerous = 0;
849 /* The following flags have an effect during scheduling after register
852 flag_sched_stalled_insns means that insns can be moved prematurely from the queue
853 of stalled insns into the ready list.
855 flag_sched_stalled_insns_dep controls how many insn groups will be examined
856 for a dependency on a stalled insn that is candidate for premature removal
857 from the queue of stalled insns into the ready list (has an effect only if
858 the flag 'sched_stalled_insns' is set). */
860 int flag_sched_stalled_insns = 0;
861 int flag_sched_stalled_insns_dep = 1;
863 int flag_single_precision_constant;
865 /* flag_branch_on_count_reg means try to replace add-1,compare,branch tupple
866 by a cheaper branch on a count register. */
867 int flag_branch_on_count_reg = 1;
869 /* -finhibit-size-directive inhibits output of .size for ELF.
870 This is used only for compiling crtstuff.c,
871 and it may be extended to other effects
872 needed for crtstuff.c on other systems. */
873 int flag_inhibit_size_directive = 0;
875 /* -fverbose-asm causes extra commentary information to be produced in
876 the generated assembly code (to make it more readable). This option
877 is generally only of use to those who actually need to read the
878 generated assembly code (perhaps while debugging the compiler itself).
879 -fno-verbose-asm, the default, causes the extra information
880 to be omitted and is useful when comparing two assembler files. */
882 int flag_verbose_asm = 0;
884 /* -dA causes debug commentary information to be produced in
885 the generated assembly code (to make it more readable). This option
886 is generally only of use to those who actually need to read the
887 generated assembly code (perhaps while debugging the compiler itself).
888 Currently, this switch is only used by dwarfout.c; however, it is intended
889 to be a catchall for printing debug information in the assembler file. */
891 int flag_debug_asm = 0;
893 /* -dP causes the rtl to be emitted as a comment in assembly. */
895 int flag_dump_rtl_in_asm = 0;
897 /* Nonzero means put zero initialized data in the bss section. */
898 int flag_zero_initialized_in_bss = 1;
900 /* Tag all structures with __attribute__(packed). */
901 int flag_pack_struct = 0;
903 /* Emit code to check for stack overflow; also may cause large objects
904 to be allocated dynamically. */
905 int flag_stack_check;
907 /* When non-NULL, indicates that whenever space is allocated on the
908 stack, the resulting stack pointer must not pass this
909 address---that is, for stacks that grow downward, the stack pointer
910 must always be greater than or equal to this address; for stacks
911 that grow upward, the stack pointer must be less than this address.
912 At present, the rtx may be either a REG or a SYMBOL_REF, although
913 the support provided depends on the backend. */
916 /* 0 if pointer arguments may alias each other. True in C.
917 1 if pointer arguments may not alias each other but may alias
919 2 if pointer arguments may not alias each other and may not
920 alias global variables. True in Fortran.
921 This defaults to 0 for C. */
922 int flag_argument_noalias = 0;
924 /* Nonzero if we should do (language-dependent) alias analysis.
925 Typically, this analysis will assume that expressions of certain
926 types do not alias expressions of certain other types. Only used
927 if alias analysis (in general) is enabled. */
928 int flag_strict_aliasing = 0;
930 /* Instrument functions with calls at entry and exit, for profiling. */
931 int flag_instrument_function_entry_exit = 0;
933 /* Nonzero means ignore `#ident' directives. 0 means handle them.
934 On SVR4 targets, it also controls whether or not to emit a
935 string identifying the compiler. */
937 int flag_no_ident = 0;
939 /* This will perform a peephole pass before sched2. */
940 int flag_peephole2 = 0;
942 /* This will try to guess branch probabilities. */
943 int flag_guess_branch_prob = 0;
945 /* -fcheck-bounds causes gcc to generate array bounds checks.
946 For C, C++, ObjC: defaults to off.
947 For Java: defaults to on.
948 For Fortran: defaults to off. */
949 int flag_bounds_check = 0;
951 /* This will attempt to merge constant section constants, if 1 only
952 string constants and constants from constant pool, if 2 also constant
954 int flag_merge_constants = 1;
956 /* If one, renumber instruction UIDs to reduce the number of
957 unused UIDs if there are a lot of instructions. If greater than
958 one, unconditionally renumber instruction UIDs. */
959 int flag_renumber_insns = 1;
961 /* If nonzero, use the graph coloring register allocator. */
962 int flag_new_regalloc = 0;
964 /* Nonzero if we perform superblock formation. */
968 /* Nonzero if we perform whole unit at a time compilation. */
970 int flag_unit_at_a_time = 0;
972 /* Nonzero if we should track variables. When
973 flag_var_tracking == AUTODETECT_FLAG_VAR_TRACKING it will be set according
974 to optimize, debug_info_level and debug_hooks in process_options (). */
976 #define AUTODETECT_FLAG_VAR_TRACKING 2
977 int flag_var_tracking = AUTODETECT_FLAG_VAR_TRACKING;
979 /* Values of the -falign-* flags: how much to align labels in code.
980 0 means `use default', 1 means `don't align'.
981 For each variable, there is an _log variant which is the power
982 of two not less than the variable, for .align output. */
986 int align_loops_max_skip;
989 int align_jumps_max_skip;
991 int align_labels_log;
992 int align_labels_max_skip;
994 int align_functions_log;
996 /* Like align_functions_log above, but used by front-ends to force the
997 minimum function alignment. Zero means no alignment is forced. */
998 int force_align_functions_log;
1002 const char *const string;
1003 int *const variable;
1006 lang_independent_options;
1008 /* Nonzero if signed arithmetic overflow should trap. */
1011 /* Nonzero if signed arithmetic overflow should wrap around. */
1014 /* Nonzero if subexpressions must be evaluated from left-to-right. */
1015 int flag_evaluation_order = 0;
1017 /* Add or remove a leading underscore from user symbols. */
1018 int flag_leading_underscore = -1;
1020 /* The version of the C++ ABI in use. The following values are
1023 0: The version of the ABI believed most conformant with the
1024 C++ ABI specification. This ABI may change as bugs are
1025 discovered and fixed. Therefore, 0 will not necessarily
1026 indicate the same ABI in different versions of G++.
1028 1: The version of the ABI first used in G++ 3.2.
1030 2: The version of the ABI first used in G++ 3.4.
1032 Additional positive integers will be assigned as new versions of
1033 the ABI become the default version of the ABI. */
1035 int flag_abi_version = 2;
1037 /* The user symbol prefix after having resolved same. */
1038 const char *user_label_prefix;
1040 static const param_info lang_independent_params[] = {
1041 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT) \
1042 { OPTION, DEFAULT, HELP },
1043 #include "params.def"
1048 /* Table of language-independent -f options.
1049 STRING is the option name. VARIABLE is the address of the variable.
1050 ON_VALUE is the value to store in VARIABLE
1051 if `-fSTRING' is seen as an option.
1052 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
1054 static const lang_independent_options f_options[] =
1056 {"eliminate-dwarf2-dups", &flag_eliminate_dwarf2_dups, 1 },
1057 {"eliminate-unused-debug-symbols", &flag_debug_only_used_symbols, 1 },
1058 {"eliminate-unused-debug-types", &flag_eliminate_unused_debug_types, 1 },
1059 {"float-store", &flag_float_store, 1 },
1060 {"defer-pop", &flag_defer_pop, 1 },
1061 {"omit-frame-pointer", &flag_omit_frame_pointer, 1 },
1062 {"optimize-sibling-calls", &flag_optimize_sibling_calls, 1 },
1063 {"tracer", &flag_tracer, 1 },
1064 {"unit-at-a-time", &flag_unit_at_a_time, 1 },
1065 {"cse-follow-jumps", &flag_cse_follow_jumps, 1 },
1066 {"cse-skip-blocks", &flag_cse_skip_blocks, 1 },
1067 {"expensive-optimizations", &flag_expensive_optimizations, 1 },
1068 {"thread-jumps", &flag_thread_jumps, 1 },
1069 {"strength-reduce", &flag_strength_reduce, 1 },
1070 {"unroll-loops", &flag_unroll_loops, 1 },
1071 {"unroll-all-loops", &flag_unroll_all_loops, 1 },
1072 {"old-unroll-loops", &flag_old_unroll_loops, 1 },
1073 {"old-unroll-all-loops", &flag_old_unroll_all_loops, 1 },
1074 {"peel-loops", &flag_peel_loops, 1 },
1075 {"unswitch-loops", &flag_unswitch_loops, 1 },
1076 {"prefetch-loop-arrays", &flag_prefetch_loop_arrays, 1 },
1077 {"move-all-movables", &flag_move_all_movables, 1 },
1078 {"reduce-all-givs", &flag_reduce_all_givs, 1 },
1079 {"writable-strings", &flag_writable_strings, 1 },
1080 {"peephole", &flag_no_peephole, 0 },
1081 {"force-mem", &flag_force_mem, 1 },
1082 {"force-addr", &flag_force_addr, 1 },
1083 {"function-cse", &flag_no_function_cse, 0 },
1084 {"inline-functions", &flag_inline_functions, 1 },
1085 {"keep-inline-functions", &flag_keep_inline_functions, 1 },
1086 {"inline", &flag_no_inline, 0 },
1087 {"keep-static-consts", &flag_keep_static_consts, 1 },
1088 {"syntax-only", &flag_syntax_only, 1 },
1089 {"shared-data", &flag_shared_data, 1 },
1090 {"caller-saves", &flag_caller_saves, 1 },
1091 {"pcc-struct-return", &flag_pcc_struct_return, 1 },
1092 {"reg-struct-return", &flag_pcc_struct_return, 0 },
1093 {"delayed-branch", &flag_delayed_branch, 1 },
1094 {"web", &flag_web, 1},
1095 {"gcse", &flag_gcse, 1 },
1096 {"gcse-lm", &flag_gcse_lm, 1 },
1097 {"gcse-sm", &flag_gcse_sm, 1 },
1098 {"gcse-las", &flag_gcse_las, 1 },
1099 {"branch-target-load-optimize", &flag_branch_target_load_optimize, 1 },
1100 {"branch-target-load-optimize2", &flag_branch_target_load_optimize2, 1 },
1101 {"btr-bb-exclusive", &flag_btr_bb_exclusive, 1 },
1102 {"loop-optimize", &flag_loop_optimize, 1 },
1103 {"crossjumping", &flag_crossjumping, 1 },
1104 {"if-conversion", &flag_if_conversion, 1 },
1105 {"if-conversion2", &flag_if_conversion2, 1 },
1106 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1 },
1107 {"rerun-loop-opt", &flag_rerun_loop_opt, 1 },
1108 {"delete-null-pointer-checks", &flag_delete_null_pointer_checks, 1 },
1109 {"schedule-insns", &flag_schedule_insns, 1 },
1110 {"schedule-insns2", &flag_schedule_insns_after_reload, 1 },
1111 {"sched-interblock",&flag_schedule_interblock, 1 },
1112 {"sched-spec",&flag_schedule_speculative, 1 },
1113 {"sched-spec-load",&flag_schedule_speculative_load, 1 },
1114 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1 },
1115 {"sched-stalled-insns", &flag_sched_stalled_insns, 0 },
1116 {"sched-stalled-insns-dep", &flag_sched_stalled_insns_dep, 1 },
1117 {"sched2-use-superblocks", &flag_sched2_use_superblocks, 1 },
1118 {"sched2-use-traces", &flag_sched2_use_traces, 1 },
1119 {"branch-count-reg",&flag_branch_on_count_reg, 1 },
1120 {"pic", &flag_pic, 1 },
1121 {"PIC", &flag_pic, 2 },
1122 {"pie", &flag_pie, 1 },
1123 {"PIE", &flag_pie, 2 },
1124 {"exceptions", &flag_exceptions, 1 },
1125 {"unwind-tables", &flag_unwind_tables, 1 },
1126 {"asynchronous-unwind-tables", &flag_asynchronous_unwind_tables, 1 },
1127 {"non-call-exceptions", &flag_non_call_exceptions, 1 },
1128 {"profile-arcs", &profile_arc_flag, 1 },
1129 {"profile-values", &flag_profile_values, 1 },
1130 {"vpt", &flag_value_profile_transformations, 1 },
1131 {"test-coverage", &flag_test_coverage, 1 },
1132 {"branch-probabilities", &flag_branch_probabilities, 1 },
1133 {"profile", &profile_flag, 1 },
1134 {"reorder-blocks", &flag_reorder_blocks, 1 },
1135 {"reorder-functions", &flag_reorder_functions, 1 },
1136 {"rename-registers", &flag_rename_registers, 1 },
1137 {"cprop-registers", &flag_cprop_registers, 1 },
1138 {"common", &flag_no_common, 0 },
1139 {"inhibit-size-directive", &flag_inhibit_size_directive, 1 },
1140 {"function-sections", &flag_function_sections, 1 },
1141 {"data-sections", &flag_data_sections, 1 },
1142 {"verbose-asm", &flag_verbose_asm, 1 },
1143 {"regmove", &flag_regmove, 1 },
1144 {"optimize-register-move", &flag_regmove, 1 },
1145 {"pack-struct", &flag_pack_struct, 1 },
1146 {"stack-check", &flag_stack_check, 1 },
1147 {"argument-alias", &flag_argument_noalias, 0 },
1148 {"argument-noalias", &flag_argument_noalias, 1 },
1149 {"argument-noalias-global", &flag_argument_noalias, 2 },
1150 {"strict-aliasing", &flag_strict_aliasing, 1 },
1151 {"align-loops", &align_loops, 0 },
1152 {"align-jumps", &align_jumps, 0 },
1153 {"align-labels", &align_labels, 0 },
1154 {"align-functions", &align_functions, 0 },
1155 {"merge-constants", &flag_merge_constants, 1 },
1156 {"merge-all-constants", &flag_merge_constants, 2 },
1157 {"dump-unnumbered", &flag_dump_unnumbered, 1 },
1158 {"instrument-functions", &flag_instrument_function_entry_exit, 1 },
1159 {"zero-initialized-in-bss", &flag_zero_initialized_in_bss, 1 },
1160 {"leading-underscore", &flag_leading_underscore, 1 },
1161 {"ident", &flag_no_ident, 0 },
1162 { "peephole2", &flag_peephole2, 1 },
1163 {"finite-math-only", &flag_finite_math_only, 1 },
1164 { "guess-branch-probability", &flag_guess_branch_prob, 1 },
1165 {"math-errno", &flag_errno_math, 1 },
1166 {"trapping-math", &flag_trapping_math, 1 },
1167 {"rounding-math", &flag_rounding_math, 1 },
1168 {"unsafe-math-optimizations", &flag_unsafe_math_optimizations, 1 },
1169 {"signaling-nans", &flag_signaling_nans, 1 },
1170 {"bounds-check", &flag_bounds_check, 1 },
1171 {"single-precision-constant", &flag_single_precision_constant, 1 },
1172 {"time-report", &time_report, 1 },
1173 {"mem-report", &mem_report, 1 },
1174 { "trapv", &flag_trapv, 1 },
1175 { "wrapv", &flag_wrapv, 1 },
1176 { "new-ra", &flag_new_regalloc, 1 },
1177 { "var-tracking", &flag_var_tracking, 1}
1180 /* Here is a table, controlled by the tm.h file, listing each -m switch
1181 and which bits in `target_switches' it should set or clear.
1182 If VALUE is positive, it is bits to set.
1183 If VALUE is negative, -VALUE is bits to clear.
1184 (The sign bit is not used so there is no confusion.) */
1188 const char *const name;
1190 const char *const description;
1192 target_switches[] = TARGET_SWITCHES;
1194 /* This table is similar, but allows the switch to have a value. */
1196 #ifdef TARGET_OPTIONS
1199 const char *const prefix;
1200 const char **const variable;
1201 const char *const description;
1202 const char *const value;
1204 target_options[] = TARGET_OPTIONS;
1207 /* Nonzero means warn about function definitions that default the return type
1208 or that use a null return and have a return-type other than void. */
1210 int warn_return_type;
1212 /* Output files for assembler code (real compiler output)
1213 and debugging dumps. */
1216 FILE *aux_info_file;
1217 FILE *rtl_dump_file = NULL;
1218 FILE *cgraph_dump_file = NULL;
1220 /* The current working directory of a translation. It's generally the
1221 directory from which compilation was initiated, but a preprocessed
1222 file may specify the original directory in which it was
1225 static const char *src_pwd;
1227 /* Initialize src_pwd with the given string, and return true. If it
1228 was already initialized, return false. As a special case, it may
1229 be called with a NULL argument to test whether src_pwd has NOT been
1233 set_src_pwd (const char *pwd)
1238 src_pwd = xstrdup (pwd);
1242 /* Return the directory from which the translation unit was initiated,
1243 in case set_src_pwd() was not called before to assign it a
1250 src_pwd = getpwd ();
1255 /* Called when the start of a function definition is parsed,
1256 this function prints on stderr the name of the function. */
1258 announce_function (tree decl)
1262 if (rtl_dump_and_exit)
1263 verbatim ("%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1265 verbatim (" %s", (*lang_hooks.decl_printable_name) (decl, 2));
1267 pp_needs_newline (global_dc->printer) = true;
1268 diagnostic_set_last_function (global_dc);
1272 /* Set up a default flag_random_seed and local_tick, unless the user
1273 already specified one. */
1278 if (!flag_random_seed)
1280 unsigned HOST_WIDE_INT value;
1281 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
1283 /* Get some more or less random data. */
1284 #ifdef HAVE_GETTIMEOFDAY
1288 gettimeofday (&tv, NULL);
1289 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
1293 time_t now = time (NULL);
1295 if (now != (time_t)-1)
1296 local_tick = (unsigned) now;
1299 value = local_tick ^ getpid ();
1301 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
1302 flag_random_seed = random_seed;
1304 else if (!local_tick)
1309 /* Decode the string P as an integral parameter.
1310 If the string is indeed an integer return its numeric value else
1311 issue an Invalid Option error for the option PNAME and return DEFVAL.
1312 If PNAME is zero just return DEFVAL, do not call error. */
1315 read_integral_parameter (const char *p, const char *pname, const int defval)
1317 const char *endp = p;
1321 if (ISDIGIT (*endp))
1330 error ("invalid option argument `%s'", pname);
1337 /* Return the logarithm of X, base 2, considering X unsigned,
1338 if X is a power of 2. Otherwise, returns -1.
1340 This should be used via the `exact_log2' macro. */
1343 exact_log2_wide (unsigned HOST_WIDE_INT x)
1346 /* Test for 0 or a power of 2. */
1347 if (x == 0 || x != (x & -x))
1349 while ((x >>= 1) != 0)
1354 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1355 If X is 0, return -1.
1357 This should be used via the floor_log2 macro. */
1360 floor_log2_wide (unsigned HOST_WIDE_INT x)
1369 /* Handler for fatal signals, such as SIGSEGV. These are transformed
1370 into ICE messages, which is much more user friendly. In case the
1371 error printer crashes, reset the signal to prevent infinite recursion. */
1374 crash_signal (int signo)
1376 signal (signo, SIG_DFL);
1377 internal_error ("%s", strsignal (signo));
1380 /* Arrange to dump core on error. (The regular error message is still
1381 printed first, except in the case of abort().) */
1384 setup_core_dumping (void)
1387 signal (SIGABRT, SIG_DFL);
1389 #if defined(HAVE_SETRLIMIT)
1392 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
1393 fatal_error ("getting core file size maximum limit: %m");
1394 rlim.rlim_cur = rlim.rlim_max;
1395 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
1396 fatal_error ("setting core file size limit to maximum: %m");
1399 diagnostic_abort_on_error (global_dc);
1403 /* Strip off a legitimate source ending from the input string NAME of
1404 length LEN. Rather than having to know the names used by all of
1405 our front ends, we strip off an ending of a period followed by
1406 up to five characters. (Java uses ".class".) */
1409 strip_off_ending (char *name, int len)
1412 for (i = 2; i < 6 && len > i; i++)
1414 if (name[len - i] == '.')
1416 name[len - i] = '\0';
1422 /* Output a quoted string. */
1425 output_quoted_string (FILE *asm_file, const char *string)
1427 #ifdef OUTPUT_QUOTED_STRING
1428 OUTPUT_QUOTED_STRING (asm_file, string);
1432 putc ('\"', asm_file);
1433 while ((c = *string++) != 0)
1437 if (c == '\"' || c == '\\')
1438 putc ('\\', asm_file);
1442 fprintf (asm_file, "\\%03o", (unsigned char) c);
1444 putc ('\"', asm_file);
1448 /* Output a file name in the form wanted by System V. */
1451 output_file_directive (FILE *asm_file, const char *input_name)
1456 if (input_name == NULL)
1457 input_name = "<stdin>";
1459 len = strlen (input_name);
1460 na = input_name + len;
1462 /* NA gets INPUT_NAME sans directory names. */
1463 while (na > input_name)
1465 if (IS_DIR_SEPARATOR (na[-1]))
1470 #ifdef ASM_OUTPUT_SOURCE_FILENAME
1471 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
1473 fprintf (asm_file, "\t.file\t");
1474 output_quoted_string (asm_file, na);
1475 fputc ('\n', asm_file);
1479 /* Routine to open a dump file. Return true if the dump file is enabled. */
1482 open_dump_file (enum dump_file_index index, tree decl)
1485 const char *open_arg;
1488 if (! dump_file[index].enabled)
1491 timevar_push (TV_DUMP);
1492 if (rtl_dump_file != NULL)
1493 fclose (rtl_dump_file);
1495 sprintf (seq, DUMPFILE_FORMAT, index);
1497 if (! dump_file[index].initialized)
1499 /* If we've not initialized the files, do so now. */
1500 if (graph_dump_format != no_graph
1501 && dump_file[index].graph_dump_p)
1503 dump_name = concat (seq, dump_file[index].extension, NULL);
1504 clean_graph_dump_file (dump_base_name, dump_name);
1507 dump_file[index].initialized = 1;
1513 dump_name = concat (dump_base_name, seq,
1514 dump_file[index].extension, NULL);
1516 rtl_dump_file = fopen (dump_name, open_arg);
1517 if (rtl_dump_file == NULL)
1518 fatal_error ("can't open %s: %m", dump_name);
1523 fprintf (rtl_dump_file, "\n;; Function %s%s\n\n",
1524 (*lang_hooks.decl_printable_name) (decl, 2),
1525 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
1527 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
1528 ? " (unlikely executed)"
1531 timevar_pop (TV_DUMP);
1535 /* Routine to close a dump file. */
1538 close_dump_file (enum dump_file_index index,
1539 void (*func) (FILE *, rtx),
1542 if (! rtl_dump_file)
1545 timevar_push (TV_DUMP);
1547 && graph_dump_format != no_graph
1548 && dump_file[index].graph_dump_p)
1553 sprintf (seq, DUMPFILE_FORMAT, index);
1554 suffix = concat (seq, dump_file[index].extension, NULL);
1555 print_rtl_graph_with_bb (dump_base_name, suffix, insns);
1560 func (rtl_dump_file, insns);
1562 fflush (rtl_dump_file);
1563 fclose (rtl_dump_file);
1565 rtl_dump_file = NULL;
1566 timevar_pop (TV_DUMP);
1569 /* Do any final processing required for the declarations in VEC, of
1570 which there are LEN. We write out inline functions and variables
1571 that have been deferred until this point, but which are required.
1572 Returns nonzero if anything was put out. */
1575 wrapup_global_declarations (tree *vec, int len)
1580 int output_something = 0;
1582 for (i = 0; i < len; i++)
1586 /* We're not deferring this any longer. Assignment is
1587 conditional to avoid needlessly dirtying PCH pages. */
1588 if (DECL_DEFER_OUTPUT (decl) != 0)
1589 DECL_DEFER_OUTPUT (decl) = 0;
1591 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
1592 (*lang_hooks.finish_incomplete_decl) (decl);
1595 /* Now emit any global variables or functions that we have been
1596 putting off. We need to loop in case one of the things emitted
1597 here references another one which comes earlier in the list. */
1601 for (i = 0; i < len; i++)
1605 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
1608 /* Don't write out static consts, unless we still need them.
1610 We also keep static consts if not optimizing (for debugging),
1611 unless the user specified -fno-keep-static-consts.
1612 ??? They might be better written into the debug information.
1613 This is possible when using DWARF.
1615 A language processor that wants static constants to be always
1616 written out (even if it is not used) is responsible for
1617 calling rest_of_decl_compilation itself. E.g. the C front-end
1618 calls rest_of_decl_compilation from finish_decl.
1619 One motivation for this is that is conventional in some
1620 environments to write things like:
1621 static const char rcsid[] = "... version string ...";
1622 intending to force the string to be in the executable.
1624 A language processor that would prefer to have unneeded
1625 static constants "optimized away" would just defer writing
1626 them out until here. E.g. C++ does this, because static
1627 constants are often defined in header files.
1629 ??? A tempting alternative (for both C and C++) would be
1630 to force a constant to be written if and only if it is
1631 defined in a main file, as opposed to an include file. */
1633 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
1637 if (flag_unit_at_a_time
1638 && cgraph_varpool_node (decl)->finalized)
1640 else if ((flag_unit_at_a_time && !cgraph_global_info_ready)
1641 && (TREE_USED (decl)
1642 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
1644 else if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1646 else if (DECL_COMDAT (decl))
1648 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
1649 && (optimize || !flag_keep_static_consts
1650 || DECL_ARTIFICIAL (decl)))
1656 rest_of_decl_compilation (decl, NULL, 1, 1);
1660 if (TREE_CODE (decl) == FUNCTION_DECL
1661 && DECL_INITIAL (decl) != 0
1662 && DECL_STRUCT_FUNCTION (decl) != 0
1663 && DECL_STRUCT_FUNCTION (decl)->saved_for_inline
1664 && (flag_keep_inline_functions
1665 || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
1666 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
1669 output_inline_function (decl);
1674 output_something = 1;
1678 return output_something;
1681 /* Issue appropriate warnings for the global declarations in VEC (of
1682 which there are LEN). Output debugging information for them. */
1685 check_global_declarations (tree *vec, int len)
1690 for (i = 0; i < len; i++)
1694 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
1695 && ! TREE_ASM_WRITTEN (decl))
1696 /* Cancel the RTL for this decl so that, if debugging info
1697 output for global variables is still to come,
1698 this one will be omitted. */
1699 SET_DECL_RTL (decl, NULL_RTX);
1701 /* Warn about any function
1702 declared static but not defined.
1703 We don't warn about variables,
1704 because many programs have static variables
1705 that exist only to get some text into the object file. */
1706 if (TREE_CODE (decl) == FUNCTION_DECL
1707 && (warn_unused_function
1708 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1709 && DECL_INITIAL (decl) == 0
1710 && DECL_EXTERNAL (decl)
1711 && ! DECL_ARTIFICIAL (decl)
1712 && ! TREE_PUBLIC (decl))
1714 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1715 pedwarn ("%J'%F' used but never defined", decl, decl);
1717 warning ("%J'%F' declared `static' but never defined", decl, decl);
1718 /* This symbol is effectively an "extern" declaration now. */
1719 TREE_PUBLIC (decl) = 1;
1720 assemble_external (decl);
1723 /* Warn about static fns or vars defined but not used. */
1724 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
1725 /* We don't warn about "static const" variables because the
1726 "rcs_id" idiom uses that construction. */
1727 || (warn_unused_variable
1728 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
1729 && ! DECL_IN_SYSTEM_HEADER (decl)
1730 && ! TREE_USED (decl)
1731 /* The TREE_USED bit for file-scope decls is kept in the identifier,
1732 to handle multiple external decls in different scopes. */
1733 && ! TREE_USED (DECL_NAME (decl))
1734 && ! DECL_EXTERNAL (decl)
1735 && ! TREE_PUBLIC (decl)
1736 /* A volatile variable might be used in some non-obvious way. */
1737 && ! TREE_THIS_VOLATILE (decl)
1738 /* Global register variables must be declared to reserve them. */
1739 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
1740 /* Otherwise, ask the language. */
1741 && (*lang_hooks.decls.warn_unused_global) (decl))
1742 warning ("%J'%D' defined but not used", decl, decl);
1744 /* Avoid confusing the debug information machinery when there are
1746 if (errorcount == 0 && sorrycount == 0)
1748 timevar_push (TV_SYMOUT);
1749 (*debug_hooks->global_decl) (decl);
1750 timevar_pop (TV_SYMOUT);
1755 /* Warn about a use of an identifier which was marked deprecated. */
1757 warn_deprecated_use (tree node)
1759 if (node == 0 || !warn_deprecated_decl)
1763 warning ("`%s' is deprecated (declared at %s:%d)",
1764 IDENTIFIER_POINTER (DECL_NAME (node)),
1765 DECL_SOURCE_FILE (node), DECL_SOURCE_LINE (node));
1766 else if (TYPE_P (node))
1768 const char *what = NULL;
1769 tree decl = TYPE_STUB_DECL (node);
1771 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
1772 what = IDENTIFIER_POINTER (TYPE_NAME (node));
1773 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
1774 && DECL_NAME (TYPE_NAME (node)))
1775 what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
1780 warning ("`%s' is deprecated (declared at %s:%d)", what,
1781 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1783 warning ("`%s' is deprecated", what);
1786 warning ("type is deprecated (declared at %s:%d)",
1787 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1789 warning ("type is deprecated");
1793 /* Save the current INPUT_LOCATION on the top entry in the
1794 INPUT_FILE_STACK. Push a new entry for FILE and LINE, and set the
1795 INPUT_LOCATION accordingly. */
1798 push_srcloc (const char *file, int line)
1800 struct file_stack *fs;
1802 fs = xmalloc (sizeof (struct file_stack));
1803 fs->location = input_location;
1804 fs->next = input_file_stack;
1805 input_filename = file;
1807 input_file_stack = fs;
1808 input_file_stack_tick++;
1811 /* Pop the top entry off the stack of presently open source files.
1812 Restore the INPUT_LOCATION from the new topmost entry on the
1818 struct file_stack *fs;
1820 fs = input_file_stack;
1821 input_location = fs->location;
1822 input_file_stack = fs->next;
1824 input_file_stack_tick++;
1827 /* Compile an entire translation unit. Write a file of assembly
1828 output and various debugging dumps. */
1833 /* Initialize yet another pass. */
1835 init_final (main_input_filename);
1836 coverage_init (aux_base_name);
1838 timevar_push (TV_PARSE);
1840 /* Call the parser, which parses the entire file (calling
1841 rest_of_compilation for each function). */
1842 (*lang_hooks.parse_file) (set_yydebug);
1844 /* In case there were missing block closers,
1845 get us back to the global binding level. */
1846 (*lang_hooks.clear_binding_stack) ();
1848 /* Compilation is now finished except for writing
1849 what's left of the symbol table output. */
1850 timevar_pop (TV_PARSE);
1852 if (flag_syntax_only)
1855 (*lang_hooks.decls.final_write_globals)();
1857 cgraph_varpool_assemble_pending_decls ();
1859 /* This must occur after the loop to output deferred functions.
1860 Else the coverage initializer would not be emitted if all the
1861 functions in this compilation unit were deferred. */
1864 /* Write out any pending weak symbol declarations. */
1868 /* Do dbx symbols. */
1869 timevar_push (TV_SYMOUT);
1871 #ifdef DWARF2_UNWIND_INFO
1872 if (dwarf2out_do_frame ())
1873 dwarf2out_frame_finish ();
1876 (*debug_hooks->finish) (main_input_filename);
1877 timevar_pop (TV_SYMOUT);
1879 /* Output some stuff at end of file if nec. */
1881 dw2_output_indirect_constants ();
1883 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
1885 timevar_push (TV_DUMP);
1886 open_dump_file (DFI_bp, NULL);
1890 close_dump_file (DFI_bp, NULL, NULL_RTX);
1891 timevar_pop (TV_DUMP);
1894 targetm.asm_out.file_end ();
1896 /* Attach a special .ident directive to the end of the file to identify
1897 the version of GCC which compiled this code. The format of the .ident
1898 string is patterned after the ones produced by native SVR4 compilers. */
1901 fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
1902 IDENT_ASM_OP, version_string);
1905 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
1907 timevar_push (TV_DUMP);
1908 dump_combine_total_stats (rtl_dump_file);
1909 close_dump_file (DFI_combine, NULL, NULL_RTX);
1910 timevar_pop (TV_DUMP);
1914 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
1915 and TYPE_DECL nodes.
1917 This does nothing for local (non-static) variables, unless the
1918 variable is a register variable with an ASMSPEC. In that case, or
1919 if the variable is not an automatic, it sets up the RTL and
1920 outputs any assembler code (label definition, storage allocation
1921 and initialization).
1923 DECL is the declaration. If ASMSPEC is nonzero, it specifies
1924 the assembler symbol name to be used. TOP_LEVEL is nonzero
1925 if this declaration is not within a function. */
1928 rest_of_decl_compilation (tree decl,
1929 const char *asmspec,
1933 /* We deferred calling assemble_alias so that we could collect
1934 other attributes such as visibility. Emit the alias now. */
1937 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
1940 alias = TREE_VALUE (TREE_VALUE (alias));
1941 alias = get_identifier (TREE_STRING_POINTER (alias));
1942 assemble_alias (decl, alias);
1946 /* Forward declarations for nested functions are not "external",
1947 but we need to treat them as if they were. */
1948 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
1949 || TREE_CODE (decl) == FUNCTION_DECL)
1951 timevar_push (TV_VARCONST);
1954 make_decl_rtl (decl, asmspec);
1956 /* Don't output anything when a tentative file-scope definition
1957 is seen. But at end of compilation, do output code for them.
1959 We do output all variables when unit-at-a-time is active and rely on
1960 callgraph code to defer them except for forward declarations
1961 (see gcc.c-torture/compile/920624-1.c) */
1963 || !DECL_DEFER_OUTPUT (decl)
1964 || (flag_unit_at_a_time && DECL_INITIAL (decl)))
1965 && !DECL_EXTERNAL (decl))
1967 if (flag_unit_at_a_time && !cgraph_global_info_ready
1968 && TREE_CODE (decl) != FUNCTION_DECL && top_level)
1969 cgraph_varpool_finalize_decl (decl);
1971 assemble_variable (decl, top_level, at_end, 0);
1974 #ifdef ASM_FINISH_DECLARE_OBJECT
1975 if (decl == last_assemble_variable_decl)
1977 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
1982 timevar_pop (TV_VARCONST);
1984 else if (DECL_REGISTER (decl) && asmspec != 0)
1986 if (decode_reg_name (asmspec) >= 0)
1988 SET_DECL_RTL (decl, NULL_RTX);
1989 make_decl_rtl (decl, asmspec);
1993 error ("invalid register name `%s' for register variable", asmspec);
1994 DECL_REGISTER (decl) = 0;
1999 else if (TREE_CODE (decl) == TYPE_DECL)
2001 timevar_push (TV_SYMOUT);
2002 debug_hooks->type_decl (decl, !top_level);
2003 timevar_pop (TV_SYMOUT);
2007 /* Called after finishing a record, union or enumeral type. */
2010 rest_of_type_compilation (tree type, int toplev)
2012 /* Avoid confusing the debug information machinery when there are
2014 if (errorcount != 0 || sorrycount != 0)
2017 timevar_push (TV_SYMOUT);
2018 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
2019 timevar_pop (TV_SYMOUT);
2022 /* Turn the RTL into assembly. */
2024 rest_of_handle_final (tree decl, rtx insns)
2026 timevar_push (TV_FINAL);
2031 /* Get the function's name, as described by its RTL. This may be
2032 different from the DECL_NAME name used in the source file. */
2034 x = DECL_RTL (decl);
2035 if (GET_CODE (x) != MEM)
2038 if (GET_CODE (x) != SYMBOL_REF)
2040 fnname = XSTR (x, 0);
2042 assemble_start_function (decl, fnname);
2043 final_start_function (insns, asm_out_file, optimize);
2044 final (insns, asm_out_file, optimize, 0);
2045 final_end_function ();
2047 #ifdef IA64_UNWIND_INFO
2048 /* ??? The IA-64 ".handlerdata" directive must be issued before
2049 the ".endp" directive that closes the procedure descriptor. */
2050 output_function_exception_table ();
2053 assemble_end_function (decl, fnname);
2055 #ifndef IA64_UNWIND_INFO
2056 /* Otherwise, it feels unclean to switch sections in the middle. */
2057 output_function_exception_table ();
2061 fflush (asm_out_file);
2063 /* Release all memory allocated by flow. */
2064 free_basic_block_vars (0);
2066 /* Release all memory held by regsets now. */
2067 regset_release_memory ();
2069 timevar_pop (TV_FINAL);
2075 /* Run delay slot optimization. */
2077 rest_of_handle_delay_slots (tree decl, rtx insns)
2079 timevar_push (TV_DBR_SCHED);
2080 open_dump_file (DFI_dbr, decl);
2082 dbr_schedule (insns, rtl_dump_file);
2084 close_dump_file (DFI_dbr, print_rtl, insns);
2085 timevar_pop (TV_DBR_SCHED);
2092 /* Convert register usage from flat register file usage to a stack
2095 rest_of_handle_stack_regs (tree decl, rtx insns)
2097 #if defined (HAVE_ATTR_length)
2098 /* If flow2 creates new instructions which need splitting
2099 and scheduling after reload is not done, they might not be
2100 split until final which doesn't allow splitting
2101 if HAVE_ATTR_length. */
2102 #ifdef INSN_SCHEDULING
2103 if (optimize && !flag_schedule_insns_after_reload)
2108 timevar_push (TV_SHORTEN_BRANCH);
2109 split_all_insns (1);
2110 timevar_pop (TV_SHORTEN_BRANCH);
2114 timevar_push (TV_REG_STACK);
2115 open_dump_file (DFI_stack, decl);
2117 if (reg_to_stack (insns, rtl_dump_file) && optimize)
2119 if (cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
2120 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0))
2121 && flag_reorder_blocks)
2123 reorder_basic_blocks ();
2124 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
2128 close_dump_file (DFI_stack, print_rtl_with_bb, insns);
2129 timevar_pop (TV_REG_STACK);
2135 /* Track the variables, ie. compute where the variable is stored at each position in function. */
2137 rest_of_handle_variable_tracking (tree decl, rtx insns)
2139 timevar_push (TV_VAR_TRACKING);
2140 open_dump_file (DFI_vartrack, decl);
2142 variable_tracking_main ();
2144 close_dump_file (DFI_vartrack, print_rtl_with_bb, insns);
2145 timevar_pop (TV_VAR_TRACKING);
2148 /* Machine independent reorg pass. */
2150 rest_of_handle_machine_reorg (tree decl, rtx insns)
2152 timevar_push (TV_MACH_DEP);
2153 open_dump_file (DFI_mach, decl);
2155 (*targetm.machine_dependent_reorg) ();
2157 close_dump_file (DFI_mach, print_rtl, insns);
2158 timevar_pop (TV_MACH_DEP);
2164 /* Run new register allocator. Return TRUE if we must exit
2165 rest_of_compilation upon return. */
2167 rest_of_handle_new_regalloc (tree decl, rtx insns)
2171 delete_trivially_dead_insns (insns, max_reg_num ());
2174 timevar_pop (TV_LOCAL_ALLOC);
2175 if (dump_file[DFI_lreg].enabled)
2177 timevar_push (TV_DUMP);
2179 close_dump_file (DFI_lreg, NULL, NULL);
2180 timevar_pop (TV_DUMP);
2183 /* XXX clean up the whole mess to bring live info in shape again. */
2184 timevar_push (TV_GLOBAL_ALLOC);
2185 open_dump_file (DFI_greg, decl);
2187 build_insn_chain (insns);
2188 failure = reload (insns, 0);
2190 timevar_pop (TV_GLOBAL_ALLOC);
2192 if (dump_file[DFI_greg].enabled)
2194 timevar_push (TV_DUMP);
2196 dump_global_regs (rtl_dump_file);
2198 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2199 timevar_pop (TV_DUMP);
2205 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)
2218 /* Allocate the reg_renumber array. */
2219 allocate_reg_info (max_regno, FALSE, TRUE);
2221 /* And the reg_equiv_memory_loc array. */
2222 reg_equiv_memory_loc = xcalloc (max_regno, sizeof (rtx));
2224 allocate_initial_values (reg_equiv_memory_loc);
2226 regclass (insns, max_reg_num (), rtl_dump_file);
2227 rebuild_notes = local_alloc ();
2229 timevar_pop (TV_LOCAL_ALLOC);
2231 /* Local allocation may have turned an indirect jump into a direct
2232 jump. If so, we must rebuild the JUMP_LABEL fields of jumping
2236 timevar_push (TV_JUMP);
2238 rebuild_jump_labels (insns);
2239 purge_all_dead_edges (0);
2241 timevar_pop (TV_JUMP);
2244 if (dump_file[DFI_lreg].enabled)
2246 timevar_push (TV_DUMP);
2248 dump_flow_info (rtl_dump_file);
2249 dump_local_alloc (rtl_dump_file);
2251 close_dump_file (DFI_lreg, print_rtl_with_bb, insns);
2252 timevar_pop (TV_DUMP);
2257 timevar_push (TV_GLOBAL_ALLOC);
2258 open_dump_file (DFI_greg, decl);
2260 /* If optimizing, allocate remaining pseudo-regs. Do the reload
2261 pass fixing up any insns that are invalid. */
2264 failure = global_alloc (rtl_dump_file);
2267 build_insn_chain (insns);
2268 failure = reload (insns, 0);
2271 timevar_pop (TV_GLOBAL_ALLOC);
2273 if (dump_file[DFI_greg].enabled)
2275 timevar_push (TV_DUMP);
2277 dump_global_regs (rtl_dump_file);
2279 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2280 timevar_pop (TV_DUMP);
2286 /* Run the regrename and cprop passes. */
2288 rest_of_handle_regrename (tree decl, rtx insns)
2290 timevar_push (TV_RENAME_REGISTERS);
2291 open_dump_file (DFI_rnreg, decl);
2293 if (flag_rename_registers)
2294 regrename_optimize ();
2295 if (flag_cprop_registers)
2296 copyprop_hardreg_forward ();
2298 close_dump_file (DFI_rnreg, print_rtl_with_bb, insns);
2299 timevar_pop (TV_RENAME_REGISTERS);
2302 /* Reorder basic blocks. */
2304 rest_of_handle_reorder_blocks (tree decl, rtx insns)
2307 open_dump_file (DFI_bbro, decl);
2309 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
2310 splitting possibly introduced more crossjumping opportunities. */
2311 changed = cleanup_cfg (CLEANUP_EXPENSIVE
2312 | (!HAVE_conditional_execution
2313 ? CLEANUP_UPDATE_LIFE : 0));
2315 if (flag_sched2_use_traces && flag_schedule_insns_after_reload)
2317 if (flag_reorder_blocks)
2318 reorder_basic_blocks ();
2319 if (flag_reorder_blocks
2320 || (flag_sched2_use_traces && flag_schedule_insns_after_reload))
2321 changed |= cleanup_cfg (CLEANUP_EXPENSIVE
2322 | (!HAVE_conditional_execution
2323 ? CLEANUP_UPDATE_LIFE : 0));
2325 /* On conditional execution targets we can not update the life cheaply, so
2326 we deffer the updating to after both cleanups. This may lose some cases
2327 but should not be terribly bad. */
2328 if (changed && HAVE_conditional_execution)
2329 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
2331 close_dump_file (DFI_bbro, print_rtl_with_bb, insns);
2334 #ifdef INSN_SCHEDULING
2335 /* Run instruction scheduler. */
2337 rest_of_handle_sched (tree decl, rtx insns)
2339 timevar_push (TV_SCHED);
2341 /* Print function header into sched dump now
2342 because doing the sched analysis makes some of the dump. */
2343 if (optimize > 0 && flag_schedule_insns)
2345 open_dump_file (DFI_sched, decl);
2347 /* Do control and data sched analysis,
2348 and write some of the results to dump file. */
2350 schedule_insns (rtl_dump_file);
2352 close_dump_file (DFI_sched, print_rtl_with_bb, insns);
2354 timevar_pop (TV_SCHED);
2359 /* Run second scheduling pass after reload. */
2361 rest_of_handle_sched2 (tree decl, rtx insns)
2363 timevar_push (TV_SCHED2);
2364 open_dump_file (DFI_sched2, decl);
2366 /* Do control and data sched analysis again,
2367 and write some more of the results to dump file. */
2369 split_all_insns (1);
2371 if (flag_sched2_use_superblocks || flag_sched2_use_traces)
2373 schedule_ebbs (rtl_dump_file);
2374 /* No liveness updating code yet, but it should be easy to do.
2375 reg-stack recompute the liveness when needed for now. */
2376 count_or_remove_death_notes (NULL, 1);
2377 cleanup_cfg (CLEANUP_EXPENSIVE);
2380 schedule_insns (rtl_dump_file);
2382 close_dump_file (DFI_sched2, print_rtl_with_bb, insns);
2383 timevar_pop (TV_SCHED2);
2389 /* Register allocation pre-pass, to reduce number of moves necessary
2390 for two-address machines. */
2392 rest_of_handle_regmove (tree decl, rtx insns)
2394 timevar_push (TV_REGMOVE);
2395 open_dump_file (DFI_regmove, decl);
2397 regmove_optimize (insns, max_reg_num (), rtl_dump_file);
2399 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2400 close_dump_file (DFI_regmove, print_rtl_with_bb, insns);
2401 timevar_pop (TV_REGMOVE);
2408 rest_of_handle_tracer (tree decl, rtx insns)
2410 open_dump_file (DFI_tracer, decl);
2412 dump_flow_info (rtl_dump_file);
2414 cleanup_cfg (CLEANUP_EXPENSIVE);
2415 reg_scan (insns, max_reg_num (), 0);
2416 close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ());
2419 /* If-conversion and CFG cleanup. */
2421 rest_of_handle_if_conversion (tree decl, rtx insns)
2423 open_dump_file (DFI_ce1, decl);
2424 if (flag_if_conversion)
2426 timevar_push (TV_IFCVT);
2428 dump_flow_info (rtl_dump_file);
2429 cleanup_cfg (CLEANUP_EXPENSIVE);
2430 reg_scan (insns, max_reg_num (), 0);
2432 timevar_pop (TV_IFCVT);
2434 timevar_push (TV_JUMP);
2435 cleanup_cfg (CLEANUP_EXPENSIVE);
2436 reg_scan (insns, max_reg_num (), 0);
2437 timevar_pop (TV_JUMP);
2438 close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ());
2441 /* Rerun if-conversion, as combine may have simplified things enough
2442 to now meet sequence length restrictions. */
2444 rest_of_handle_if_after_combine (tree decl, rtx insns)
2446 timevar_push (TV_IFCVT);
2447 open_dump_file (DFI_ce2, decl);
2453 close_dump_file (DFI_ce2, print_rtl_with_bb, insns);
2454 timevar_pop (TV_IFCVT);
2458 rest_of_handle_web (tree decl, rtx insns)
2460 open_dump_file (DFI_web, decl);
2461 timevar_push (TV_WEB);
2463 delete_trivially_dead_insns (insns, max_reg_num ());
2464 cleanup_cfg (CLEANUP_EXPENSIVE);
2466 timevar_pop (TV_WEB);
2467 close_dump_file (DFI_web, print_rtl_with_bb, insns);
2468 reg_scan (get_insns (), max_reg_num (), 0);
2471 /* Do branch profiling and static profile estimation passes. */
2473 rest_of_handle_branch_prob (tree decl, rtx insns)
2477 timevar_push (TV_BRANCH_PROB);
2478 open_dump_file (DFI_bp, decl);
2480 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
2483 /* Discover and record the loop depth at the head of each basic
2484 block. The loop infrastructure does the real job for us. */
2485 flow_loops_find (&loops, LOOP_TREE);
2488 flow_loops_dump (&loops, rtl_dump_file, NULL, 0);
2490 /* Estimate using heuristics if no profiling info is available. */
2491 if (flag_guess_branch_prob)
2492 estimate_probability (&loops);
2494 flow_loops_free (&loops);
2495 free_dominance_info (CDI_DOMINATORS);
2496 close_dump_file (DFI_bp, print_rtl_with_bb, insns);
2497 timevar_pop (TV_BRANCH_PROB);
2500 /* Do optimizations based on expression value profiles. */
2502 rest_of_handle_value_profile_transformations (tree decl, rtx insns)
2504 open_dump_file (DFI_vpt, decl);
2505 timevar_push (TV_VPT);
2507 if (value_profile_transformations ())
2508 cleanup_cfg (CLEANUP_EXPENSIVE);
2510 timevar_pop (TV_VPT);
2511 close_dump_file (DFI_vpt, print_rtl_with_bb, insns);
2514 /* Do control and data flow analysis; write some of the results to the
2517 rest_of_handle_cfg (tree decl, rtx insns)
2519 open_dump_file (DFI_cfg, decl);
2521 dump_flow_info (rtl_dump_file);
2523 cleanup_cfg (CLEANUP_EXPENSIVE
2524 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2526 /* It may make more sense to mark constant functions after dead code is
2527 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
2528 may insert code making function non-constant, but we still must consider
2529 it as constant, otherwise -fbranch-probabilities will not read data back.
2531 life_analysis rarely eliminates modification of external memory.
2535 /* Alias analysis depends on this information and mark_constant_function
2536 depends on alias analysis. */
2537 reg_scan (insns, max_reg_num (), 1);
2538 mark_constant_function ();
2541 close_dump_file (DFI_cfg, print_rtl_with_bb, insns);
2544 /* Purge addressofs. */
2546 rest_of_handle_addressof (tree decl, rtx insns)
2548 open_dump_file (DFI_addressof, decl);
2550 purge_addressof (insns);
2551 if (optimize && purge_all_dead_edges (0))
2552 delete_unreachable_blocks ();
2553 reg_scan (insns, max_reg_num (), 1);
2555 close_dump_file (DFI_addressof, print_rtl, insns);
2558 /* We may have potential sibling or tail recursion sites. Select one
2559 (of possibly multiple) methods of performing the call. */
2561 rest_of_handle_sibling_calls (rtx insns)
2564 optimize_sibling_and_tail_recursive_calls ();
2566 /* Recompute the CFG as sibling optimization clobbers it randomly. */
2567 free_bb_for_insn ();
2568 find_exception_handler_labels ();
2569 rebuild_jump_labels (insns);
2570 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2572 /* There is pass ordering problem - we must lower NOTE_INSN_PREDICTION
2573 notes before simplifying cfg and we must do lowering after sibcall
2574 that unhides parts of RTL chain and cleans up the CFG.
2576 Until sibcall is replaced by tree-level optimizer, lets just
2577 sweep away the NOTE_INSN_PREDICTION notes that leaked out. */
2578 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2579 if (GET_CODE (insn) == NOTE
2580 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_PREDICTION)
2583 close_dump_file (DFI_sibling, print_rtl, get_insns ());
2586 /* Perform jump bypassing and control flow optimizations. */
2588 rest_of_handle_jump_bypass (tree decl, rtx insns)
2590 timevar_push (TV_BYPASS);
2591 open_dump_file (DFI_bypass, decl);
2593 cleanup_cfg (CLEANUP_EXPENSIVE);
2594 reg_scan (insns, max_reg_num (), 1);
2596 if (bypass_jumps (rtl_dump_file))
2598 rebuild_jump_labels (insns);
2599 cleanup_cfg (CLEANUP_EXPENSIVE);
2600 delete_trivially_dead_insns (insns, max_reg_num ());
2603 close_dump_file (DFI_bypass, print_rtl_with_bb, insns);
2604 timevar_pop (TV_BYPASS);
2608 #ifdef ENABLE_CHECKING
2609 verify_flow_info ();
2613 /* Handle inlining of functions in rest_of_compilation. Return TRUE
2614 if we must exit rest_of_compilation upon return. */
2616 rest_of_handle_inlining (tree decl)
2623 /* If we are reconsidering an inline function at the end of
2624 compilation, skip the stuff for making it inline. */
2625 if (cfun->rtl_inline_init)
2627 cfun->rtl_inline_init = 1;
2629 /* If this is nested inside an inlined external function, pretend
2630 it was only declared. Since we cannot inline such functions,
2631 generating code for this one is not only not necessary but will
2632 confuse some debugging output writers. */
2633 for (parent = DECL_CONTEXT (current_function_decl);
2634 parent != NULL_TREE;
2635 parent = get_containing_scope (parent))
2636 if (TREE_CODE (parent) == FUNCTION_DECL
2637 && DECL_INLINE (parent) && DECL_EXTERNAL (parent))
2639 DECL_INITIAL (decl) = 0;
2642 else if (TYPE_P (parent))
2643 /* A function in a local class should be treated normally. */
2646 /* If requested, consider whether to make this function inline. */
2647 if ((DECL_INLINE (decl) && !flag_no_inline)
2648 || flag_inline_functions)
2650 timevar_push (TV_INTEGRATION);
2651 lose = function_cannot_inline_p (decl);
2652 timevar_pop (TV_INTEGRATION);
2653 if (lose || ! optimize)
2655 if (warn_inline && lose && DECL_INLINE (decl))
2657 char *msg = concat ("%J", lose, NULL);
2658 warning (msg, decl);
2661 DECL_ABSTRACT_ORIGIN (decl) = 0;
2662 /* Don't really compile an extern inline function.
2663 If we can't make it inline, pretend
2664 it was only declared. */
2665 if (DECL_EXTERNAL (decl))
2667 DECL_INITIAL (decl) = 0;
2672 inlinable = DECL_INLINE (decl) = 1;
2675 insns = get_insns ();
2677 /* Dump the rtl code if we are dumping rtl. */
2679 if (open_dump_file (DFI_rtl, decl))
2681 if (DECL_STRUCT_FUNCTION (decl)
2682 && DECL_STRUCT_FUNCTION (decl)->saved_for_inline)
2683 fprintf (rtl_dump_file, ";; (integrable)\n\n");
2684 close_dump_file (DFI_rtl, print_rtl, insns);
2687 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
2688 sorts of eh initialization. Delay this until after the
2689 initial rtl dump so that we can see the original nesting. */
2690 convert_from_eh_region_ranges ();
2692 /* If function is inline, and we don't yet know whether to
2693 compile it by itself, defer decision till end of compilation.
2694 wrapup_global_declarations will (indirectly) call
2695 rest_of_compilation again for those functions that need to
2696 be output. Also defer those functions that we are supposed
2700 || (DECL_INLINE (decl)
2701 /* Egad. This RTL deferral test conflicts with Fortran assumptions
2702 for unreferenced symbols. See g77.f-torture/execute/980520-1.f.
2703 But removing this line from the check breaks all languages that
2704 use the call graph to output symbols. This hard-coded check is
2705 the least invasive work-around. */
2706 && (flag_inline_functions
2707 || strcmp (lang_hooks.name, "GNU F77") == 0)
2708 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2709 && ! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
2710 && ! flag_keep_inline_functions)
2711 || DECL_EXTERNAL (decl))))
2712 DECL_DEFER_OUTPUT (decl) = 1;
2714 if (DECL_INLINE (decl))
2715 /* DWARF wants separate debugging info for abstract and
2716 concrete instances of all inline functions, including those
2717 declared inline but not inlined, and those inlined even
2718 though they weren't declared inline. Conveniently, that's
2719 what DECL_INLINE means at this point. */
2720 (*debug_hooks->deferred_inline_function) (decl);
2722 if (DECL_DEFER_OUTPUT (decl))
2724 /* If -Wreturn-type, we have to do a bit of compilation. We just
2725 want to call cleanup the cfg to figure out whether or not we can
2726 fall off the end of the function; we do the minimum amount of
2727 work necessary to make that safe. */
2728 if (warn_return_type)
2730 int saved_optimize = optimize;
2733 rebuild_jump_labels (insns);
2734 find_exception_handler_labels ();
2735 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2736 cleanup_cfg (CLEANUP_PRE_SIBCALL | CLEANUP_PRE_LOOP);
2737 optimize = saved_optimize;
2739 /* CFG is no longer maintained up-to-date. */
2740 free_bb_for_insn ();
2743 set_nothrow_function_flags ();
2744 if (current_function_nothrow)
2745 /* Now we know that this can't throw; set the flag for the benefit
2746 of other functions later in this translation unit. */
2747 TREE_NOTHROW (current_function_decl) = 1;
2749 timevar_push (TV_INTEGRATION);
2750 save_for_inline (decl);
2751 timevar_pop (TV_INTEGRATION);
2752 DECL_STRUCT_FUNCTION (decl)->inlinable = inlinable;
2756 /* If specified extern inline but we aren't inlining it, we are
2757 done. This goes for anything that gets here with DECL_EXTERNAL
2758 set, not just things with DECL_INLINE. */
2759 return (bool) DECL_EXTERNAL (decl);
2762 /* Try to identify useless null pointer tests and delete them. */
2764 rest_of_handle_null_pointer (tree decl, rtx insns)
2766 open_dump_file (DFI_null, decl);
2768 dump_flow_info (rtl_dump_file);
2770 if (delete_null_pointer_checks (insns))
2771 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2773 close_dump_file (DFI_null, print_rtl_with_bb, insns);
2776 /* Try combining insns through substitution. */
2778 rest_of_handle_combine (tree decl, rtx insns)
2780 int rebuild_jump_labels_after_combine = 0;
2782 timevar_push (TV_COMBINE);
2783 open_dump_file (DFI_combine, decl);
2785 rebuild_jump_labels_after_combine
2786 = combine_instructions (insns, max_reg_num ());
2788 /* Combining insns may have turned an indirect jump into a
2789 direct jump. Rebuild the JUMP_LABEL fields of jumping
2791 if (rebuild_jump_labels_after_combine)
2793 timevar_push (TV_JUMP);
2794 rebuild_jump_labels (insns);
2795 timevar_pop (TV_JUMP);
2797 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2800 close_dump_file (DFI_combine, print_rtl_with_bb, insns);
2801 timevar_pop (TV_COMBINE);
2806 /* Perform life analysis. */
2808 rest_of_handle_life (tree decl, rtx insns)
2810 open_dump_file (DFI_life, decl);
2813 #ifdef ENABLE_CHECKING
2814 verify_flow_info ();
2816 life_analysis (insns, rtl_dump_file, PROP_FINAL);
2818 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_UPDATE_LIFE
2820 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2821 timevar_pop (TV_FLOW);
2823 if (warn_uninitialized)
2825 uninitialized_vars_warning (DECL_INITIAL (decl));
2827 setjmp_args_warning ();
2832 if (!flag_new_regalloc && initialize_uninitialized_subregs ())
2834 /* Insns were inserted, and possibly pseudos created, so
2835 things might look a bit different. */
2836 insns = get_insns ();
2837 allocate_reg_life_data ();
2838 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
2839 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
2845 close_dump_file (DFI_life, print_rtl_with_bb, insns);
2850 /* Perform common subexpression elimination. Nonzero value from
2851 `cse_main' means that jumps were simplified and some code may now
2852 be unreachable, so do jump optimization again. */
2854 rest_of_handle_cse (tree decl, rtx insns)
2858 open_dump_file (DFI_cse, decl);
2860 dump_flow_info (rtl_dump_file);
2861 timevar_push (TV_CSE);
2863 reg_scan (insns, max_reg_num (), 1);
2865 tem = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2867 rebuild_jump_labels (insns);
2868 if (purge_all_dead_edges (0))
2869 delete_unreachable_blocks ();
2871 delete_trivially_dead_insns (insns, max_reg_num ());
2873 /* If we are not running more CSE passes, then we are no longer
2874 expecting CSE to be run. But always rerun it in a cheap mode. */
2875 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
2877 if (tem || optimize > 1)
2878 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2879 /* Try to identify useless null pointer tests and delete them. */
2880 if (flag_delete_null_pointer_checks)
2882 timevar_push (TV_JUMP);
2884 if (delete_null_pointer_checks (insns))
2885 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2886 timevar_pop (TV_JUMP);
2889 /* The second pass of jump optimization is likely to have
2890 removed a bunch more instructions. */
2891 renumber_insns (rtl_dump_file);
2893 timevar_pop (TV_CSE);
2894 close_dump_file (DFI_cse, print_rtl_with_bb, insns);
2897 /* Run second CSE pass after loop optimizations. */
2899 rest_of_handle_cse2 (tree decl, rtx insns)
2903 timevar_push (TV_CSE2);
2904 open_dump_file (DFI_cse2, decl);
2906 dump_flow_info (rtl_dump_file);
2907 /* CFG is no longer maintained up-to-date. */
2908 tem = cse_main (insns, max_reg_num (), 1, rtl_dump_file);
2910 /* Run a pass to eliminate duplicated assignments to condition code
2911 registers. We have to run this after bypass_jumps, because it
2912 makes it harder for that pass to determine whether a jump can be
2914 cse_condition_code_reg ();
2916 purge_all_dead_edges (0);
2917 delete_trivially_dead_insns (insns, max_reg_num ());
2921 timevar_push (TV_JUMP);
2922 rebuild_jump_labels (insns);
2923 cleanup_cfg (CLEANUP_EXPENSIVE);
2924 timevar_pop (TV_JUMP);
2926 reg_scan (insns, max_reg_num (), 0);
2927 close_dump_file (DFI_cse2, print_rtl_with_bb, insns);
2929 timevar_pop (TV_CSE2);
2932 /* Perform global cse. */
2934 rest_of_handle_gcse (tree decl, rtx insns)
2936 int save_csb, save_cfj;
2939 timevar_push (TV_GCSE);
2940 open_dump_file (DFI_gcse, decl);
2942 tem = gcse_main (insns, rtl_dump_file);
2943 rebuild_jump_labels (insns);
2944 delete_trivially_dead_insns (insns, max_reg_num ());
2946 save_csb = flag_cse_skip_blocks;
2947 save_cfj = flag_cse_follow_jumps;
2948 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
2950 /* Instantiate any remaining CONSTANT_P_RTX nodes. */
2951 if (current_function_calls_constant_p)
2952 purge_builtin_constant_p ();
2954 /* If -fexpensive-optimizations, re-run CSE to clean up things done
2956 if (flag_expensive_optimizations)
2958 timevar_push (TV_CSE);
2959 reg_scan (insns, max_reg_num (), 1);
2960 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2961 purge_all_dead_edges (0);
2962 delete_trivially_dead_insns (insns, max_reg_num ());
2963 timevar_pop (TV_CSE);
2964 cse_not_expected = !flag_rerun_cse_after_loop;
2967 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
2968 things up. Then possibly re-run CSE again. */
2972 timevar_push (TV_JUMP);
2973 rebuild_jump_labels (insns);
2974 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2975 timevar_pop (TV_JUMP);
2977 if (flag_expensive_optimizations)
2979 timevar_push (TV_CSE);
2980 reg_scan (insns, max_reg_num (), 1);
2981 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2982 purge_all_dead_edges (0);
2983 delete_trivially_dead_insns (insns, max_reg_num ());
2984 timevar_pop (TV_CSE);
2988 close_dump_file (DFI_gcse, print_rtl_with_bb, insns);
2989 timevar_pop (TV_GCSE);
2992 flag_cse_skip_blocks = save_csb;
2993 flag_cse_follow_jumps = save_cfj;
2994 #ifdef ENABLE_CHECKING
2995 verify_flow_info ();
2999 /* Move constant computations out of loops. */
3001 rest_of_handle_loop_optimize (tree decl, rtx insns)
3003 int do_unroll, do_prefetch;
3005 timevar_push (TV_LOOP);
3006 delete_dead_jumptables ();
3007 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3008 open_dump_file (DFI_loop, decl);
3010 /* CFG is no longer maintained up-to-date. */
3011 free_bb_for_insn ();
3013 if (flag_unroll_loops)
3014 do_unroll = LOOP_AUTO_UNROLL; /* Having two unrollers is useless. */
3016 do_unroll = flag_old_unroll_loops ? LOOP_UNROLL : LOOP_AUTO_UNROLL;
3017 do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
3019 if (flag_rerun_loop_opt)
3021 cleanup_barriers ();
3023 /* We only want to perform unrolling once. */
3024 loop_optimize (insns, rtl_dump_file, do_unroll);
3027 /* The first call to loop_optimize makes some instructions
3028 trivially dead. We delete those instructions now in the
3029 hope that doing so will make the heuristics in loop work
3030 better and possibly speed up compilation. */
3031 delete_trivially_dead_insns (insns, max_reg_num ());
3033 /* The regscan pass is currently necessary as the alias
3034 analysis code depends on this information. */
3035 reg_scan (insns, max_reg_num (), 1);
3037 cleanup_barriers ();
3038 loop_optimize (insns, rtl_dump_file, do_unroll | LOOP_BCT | do_prefetch);
3040 /* Loop can create trivially dead instructions. */
3041 delete_trivially_dead_insns (insns, max_reg_num ());
3042 close_dump_file (DFI_loop, print_rtl, insns);
3043 timevar_pop (TV_LOOP);
3044 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3049 /* Perform loop optimizations. It might be better to do them a bit
3050 sooner, but we want the profile feedback to work more
3053 rest_of_handle_loop2 (tree decl, rtx insns)
3055 struct loops *loops;
3058 timevar_push (TV_LOOP);
3059 open_dump_file (DFI_loop2, decl);
3061 dump_flow_info (rtl_dump_file);
3063 /* Initialize structures for layout changes. */
3064 cfg_layout_initialize ();
3066 loops = loop_optimizer_init (rtl_dump_file);
3070 /* The optimizations: */
3071 if (flag_unswitch_loops)
3072 unswitch_loops (loops);
3074 if (flag_peel_loops || flag_unroll_loops)
3075 unroll_and_peel_loops (loops,
3076 (flag_peel_loops ? UAP_PEEL : 0) |
3077 (flag_unroll_loops ? UAP_UNROLL : 0) |
3078 (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0));
3080 loop_optimizer_finalize (loops, rtl_dump_file);
3083 /* Finalize layout changes. */
3085 if (bb->next_bb != EXIT_BLOCK_PTR)
3086 bb->rbi->next = bb->next_bb;
3087 cfg_layout_finalize ();
3089 cleanup_cfg (CLEANUP_EXPENSIVE);
3090 delete_trivially_dead_insns (insns, max_reg_num ());
3091 reg_scan (insns, max_reg_num (), 0);
3093 dump_flow_info (rtl_dump_file);
3094 close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
3095 timevar_pop (TV_LOOP);
3099 /* This is called from finish_function (within langhooks.parse_file)
3100 after each top-level definition is parsed.
3101 It is supposed to compile that function or variable
3102 and output the assembler code for it.
3103 After we return, the tree storage is freed. */
3106 rest_of_compilation (tree decl)
3110 timevar_push (TV_REST_OF_COMPILATION);
3112 /* Register rtl specific functions for cfg. */
3113 rtl_register_cfg_hooks ();
3115 /* Now that we're out of the frontend, we shouldn't have any more
3116 CONCATs anywhere. */
3117 generating_concat_p = 0;
3119 /* When processing delayed functions, prepare_function_start() won't
3120 have been run to re-initialize it. */
3121 cse_not_expected = ! optimize;
3123 /* First, make sure that NOTE_BLOCK is set correctly for each
3124 NOTE_INSN_BLOCK_BEG/NOTE_INSN_BLOCK_END note. */
3125 if (!cfun->x_whole_function_mode_p)
3128 /* In function-at-a-time mode, we do not attempt to keep the BLOCK
3129 tree in sensible shape. So, we just recalculate it here. */
3130 if (cfun->x_whole_function_mode_p)
3135 if (rest_of_handle_inlining (decl))
3136 goto exit_rest_of_compilation;
3138 /* If we're emitting a nested function, make sure its parent gets
3139 emitted as well. Doing otherwise confuses debug info. */
3142 for (parent = DECL_CONTEXT (current_function_decl);
3143 parent != NULL_TREE;
3144 parent = get_containing_scope (parent))
3145 if (TREE_CODE (parent) == FUNCTION_DECL)
3146 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
3149 /* We are now committed to emitting code for this function. Do any
3150 preparation, such as emitting abstract debug info for the inline
3151 before it gets mangled by optimization. */
3152 if (cgraph_function_possibly_inlined_p (decl))
3153 (*debug_hooks->outlining_inline_function) (decl);
3155 /* Remove any notes we don't need. That will make iterating
3156 over the instruction sequence faster, and allow the garbage
3157 collector to reclaim the memory used by the notes. */
3158 remove_unnecessary_notes ();
3163 /* Initialize some variables used by the optimizers. */
3164 init_function_for_compilation ();
3166 if (! DECL_DEFER_OUTPUT (decl))
3167 TREE_ASM_WRITTEN (decl) = 1;
3169 /* Now that integrate will no longer see our rtl, we need not
3170 distinguish between the return value of this function and the
3171 return value of called functions. Also, we can remove all SETs
3172 of subregs of hard registers; they are only here because of
3173 integrate. Also, we can now initialize pseudos intended to
3174 carry magic hard reg data throughout the function. */
3175 rtx_equal_function_value_matters = 0;
3176 purge_hard_subreg_sets (get_insns ());
3178 /* Early return if there were errors. We can run afoul of our
3179 consistency checks, and there's not really much point in fixing them.
3180 Don't return yet if -Wreturn-type; we need to do cleanup_cfg. */
3181 if (((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
3182 || errorcount || sorrycount)
3183 goto exit_rest_of_compilation;
3185 timevar_push (TV_JUMP);
3186 open_dump_file (DFI_sibling, decl);
3187 insns = get_insns ();
3188 rebuild_jump_labels (insns);
3189 find_exception_handler_labels ();
3190 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3192 delete_unreachable_blocks ();
3194 /* Turn NOTE_INSN_PREDICTIONs into branch predictions. */
3195 if (flag_guess_branch_prob)
3197 timevar_push (TV_BRANCH_PROB);
3198 note_prediction_to_br_prob ();
3199 timevar_pop (TV_BRANCH_PROB);
3202 if (flag_optimize_sibling_calls)
3203 rest_of_handle_sibling_calls (insns);
3205 /* We have to issue these warnings now already, because CFG cleanups
3206 further down may destroy the required information. However, this
3207 must be done after the sibcall optimization pass because the barrier
3208 emitted for noreturn calls that are candidate for the optimization
3209 is folded into the CALL_PLACEHOLDER until after this pass, so the
3210 CFG is inaccurate. */
3211 check_function_return_warnings ();
3213 timevar_pop (TV_JUMP);
3215 insn_locators_initialize ();
3216 /* Complete generation of exception handling code. */
3219 timevar_push (TV_JUMP);
3220 open_dump_file (DFI_eh, decl);
3222 finish_eh_generation ();
3224 close_dump_file (DFI_eh, print_rtl, get_insns ());
3225 timevar_pop (TV_JUMP);
3228 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
3229 generation, which might create new sets. */
3230 emit_initial_value_sets ();
3233 /* If we are doing position-independent code generation, now
3234 is the time to output special prologues and epilogues.
3235 We do not want to do this earlier, because it just clutters
3236 up inline functions with meaningless insns. */
3241 insns = get_insns ();
3243 /* Copy any shared structure that should not be shared. */
3244 unshare_all_rtl (current_function_decl, insns);
3246 #ifdef SETJMP_VIA_SAVE_AREA
3247 /* This must be performed before virtual register instantiation.
3248 Please be aware the everything in the compiler that can look
3249 at the RTL up to this point must understand that REG_SAVE_AREA
3250 is just like a use of the REG contained inside. */
3251 if (current_function_calls_alloca)
3252 optimize_save_area_alloca (insns);
3255 /* Instantiate all virtual registers. */
3256 instantiate_virtual_regs (current_function_decl, insns);
3258 open_dump_file (DFI_jump, decl);
3260 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3261 are initialized and to compute whether control can drop off the end
3264 timevar_push (TV_JUMP);
3265 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
3266 before jump optimization switches branch directions. */
3267 if (flag_guess_branch_prob)
3268 expected_value_to_br_prob ();
3270 reg_scan (insns, max_reg_num (), 0);
3271 rebuild_jump_labels (insns);
3272 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3273 delete_trivially_dead_insns (insns, max_reg_num ());
3275 dump_flow_info (rtl_dump_file);
3276 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
3277 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
3281 free_bb_for_insn ();
3282 copy_loop_headers (insns);
3283 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3285 purge_line_number_notes (insns);
3287 timevar_pop (TV_JUMP);
3288 close_dump_file (DFI_jump, print_rtl, insns);
3290 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
3291 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
3292 goto exit_rest_of_compilation;
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 || profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
3340 rest_of_handle_branch_prob (decl, insns);
3342 if (flag_branch_probabilities
3343 && flag_profile_values
3344 && flag_value_profile_transformations)
3345 rest_of_handle_value_profile_transformations (decl, insns);
3347 /* Remove the death notes created for vpt. */
3348 if (flag_profile_values)
3349 count_or_remove_death_notes (NULL, 1);
3353 rest_of_handle_if_conversion (decl, insns);
3356 rest_of_handle_tracer (decl, insns);
3359 && (flag_unswitch_loops
3361 || flag_unroll_loops))
3362 rest_of_handle_loop2 (decl, insns);
3365 rest_of_handle_web (decl, insns);
3367 if (flag_rerun_cse_after_loop)
3368 rest_of_handle_cse2 (decl, insns);
3370 cse_not_expected = 1;
3372 rest_of_handle_life (decl, insns);
3375 rest_of_handle_combine (decl, insns);
3377 if (flag_if_conversion)
3378 rest_of_handle_if_after_combine (decl, insns);
3380 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
3381 rest_of_handle_regmove (decl, insns);
3383 /* Do unconditional splitting before register allocation to allow machine
3384 description to add extra information not needed previously. */
3385 split_all_insns (1);
3387 #ifdef OPTIMIZE_MODE_SWITCHING
3388 timevar_push (TV_MODE_SWITCH);
3391 optimize_mode_switching (NULL);
3394 timevar_pop (TV_MODE_SWITCH);
3397 /* Any of the several passes since flow1 will have munged register
3398 lifetime data a bit. We need it to be up to date for scheduling
3399 (see handling of reg_known_equiv in init_alias_analysis). */
3400 recompute_reg_usage (insns, !optimize_size);
3402 #ifdef INSN_SCHEDULING
3403 rest_of_handle_sched (decl, insns);
3406 /* Determine if the current function is a leaf before running reload
3407 since this can impact optimizations done by the prologue and
3408 epilogue thus changing register elimination offsets. */
3409 current_function_is_leaf = leaf_function_p ();
3411 timevar_push (TV_LOCAL_ALLOC);
3412 open_dump_file (DFI_lreg, decl);
3414 if (flag_new_regalloc)
3416 if (rest_of_handle_new_regalloc (decl, insns))
3417 goto exit_rest_of_compilation;
3421 if (rest_of_handle_old_regalloc (decl, insns))
3422 goto exit_rest_of_compilation;
3427 open_dump_file (DFI_postreload, decl);
3429 /* Do a very simple CSE pass over just the hard registers. */
3432 timevar_push (TV_RELOAD_CSE_REGS);
3433 reload_cse_regs (insns);
3434 /* reload_cse_regs can eliminate potentially-trapping MEMs.
3435 Remove any EH edges associated with them. */
3436 if (flag_non_call_exceptions)
3437 purge_all_dead_edges (0);
3438 timevar_pop (TV_RELOAD_CSE_REGS);
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_POSTRELOAD);
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);
3514 open_dump_file (DFI_ce3, decl);
3516 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
3517 splitting possibly introduced more crossjumping opportunities. */
3518 cleanup_cfg (CLEANUP_EXPENSIVE
3519 | CLEANUP_UPDATE_LIFE
3520 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
3521 if (flag_if_conversion2)
3523 timevar_push (TV_IFCVT2);
3527 timevar_pop (TV_IFCVT2);
3529 close_dump_file (DFI_ce3, print_rtl_with_bb, insns);
3533 if (flag_rename_registers || flag_cprop_registers)
3534 rest_of_handle_regrename (decl, insns);
3536 rest_of_handle_reorder_blocks (decl, insns);
3539 if (flag_branch_target_load_optimize2)
3541 /* Leave this a warning for now so that it is possible to experiment
3542 with running this pass twice. In 3.6, we should either make this
3543 an error, or use separate dump files. */
3544 if (flag_branch_target_load_optimize)
3545 warning ("branch target register load optimization is not intended "
3548 open_dump_file (DFI_branch_target_load, decl);
3550 branch_target_load_optimize (insns, true);
3552 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3557 #ifdef INSN_SCHEDULING
3558 if (optimize > 0 && flag_schedule_insns_after_reload)
3559 rest_of_handle_sched2 (decl, insns);
3562 #ifdef LEAF_REGISTERS
3563 current_function_uses_only_leaf_regs
3564 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
3568 rest_of_handle_stack_regs (decl, insns);
3571 compute_alignments ();
3573 if (flag_var_tracking)
3574 rest_of_handle_variable_tracking (decl, insns);
3576 /* CFG is no longer maintained up-to-date. */
3577 free_bb_for_insn ();
3579 if (targetm.machine_dependent_reorg != 0)
3580 rest_of_handle_machine_reorg (decl, insns);
3582 purge_line_number_notes (insns);
3583 cleanup_barriers ();
3586 if (optimize > 0 && flag_delayed_branch)
3587 rest_of_handle_delay_slots (decl, insns);
3590 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3591 timevar_push (TV_SHORTEN_BRANCH);
3592 split_all_insns_noflow ();
3593 timevar_pop (TV_SHORTEN_BRANCH);
3596 convert_to_eh_region_ranges ();
3598 /* Shorten branches. */
3599 timevar_push (TV_SHORTEN_BRANCH);
3600 shorten_branches (get_insns ());
3601 timevar_pop (TV_SHORTEN_BRANCH);
3603 set_nothrow_function_flags ();
3604 if (current_function_nothrow)
3605 /* Now we know that this can't throw; set the flag for the benefit
3606 of other functions later in this translation unit. */
3607 TREE_NOTHROW (current_function_decl) = 1;
3609 rest_of_handle_final (decl, insns);
3611 /* Write DBX symbols if requested. */
3613 /* Note that for those inline functions where we don't initially
3614 know for certain that we will be generating an out-of-line copy,
3615 the first invocation of this routine (rest_of_compilation) will
3616 skip over this code by doing a `goto exit_rest_of_compilation;'.
3617 Later on, wrapup_global_declarations will (indirectly) call
3618 rest_of_compilation again for those inline functions that need
3619 to have out-of-line copies generated. During that call, we
3620 *will* be routed past here. */
3622 timevar_push (TV_SYMOUT);
3623 (*debug_hooks->function_decl) (decl);
3624 timevar_pop (TV_SYMOUT);
3626 exit_rest_of_compilation:
3628 coverage_end_function ();
3630 /* In case the function was not output,
3631 don't leave any temporary anonymous types
3632 queued up for sdb output. */
3633 #ifdef SDB_DEBUGGING_INFO
3634 if (write_symbols == SDB_DEBUG)
3635 sdbout_types (NULL_TREE);
3638 reload_completed = 0;
3639 epilogue_completed = 0;
3640 flow2_completed = 0;
3643 timevar_push (TV_FINAL);
3645 /* Clear out the insn_length contents now that they are no
3647 init_insn_lengths ();
3649 /* Show no temporary slots allocated. */
3652 free_basic_block_vars (0);
3653 free_bb_for_insn ();
3655 timevar_pop (TV_FINAL);
3657 if ((*targetm.binds_local_p) (current_function_decl))
3659 int pref = cfun->preferred_stack_boundary;
3660 if (cfun->recursive_call_emit
3661 && cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
3662 pref = cfun->stack_alignment_needed;
3663 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
3667 /* Make sure volatile mem refs aren't considered valid operands for
3668 arithmetic insns. We must call this here if this is a nested inline
3669 function, since the above code leaves us in the init_recog state
3670 (from final.c), and the function context push/pop code does not
3671 save/restore volatile_ok.
3673 ??? Maybe it isn't necessary for expand_start_function to call this
3674 anymore if we do it here? */
3676 init_recog_no_volatile ();
3678 /* We're done with this function. Free up memory if we can. */
3679 free_after_parsing (cfun);
3680 if (! DECL_DEFER_OUTPUT (decl))
3682 free_after_compilation (cfun);
3683 DECL_STRUCT_FUNCTION (decl) = 0;
3689 timevar_pop (TV_REST_OF_COMPILATION);
3692 /* Display help for target options. */
3694 display_target_options (void)
3697 static bool displayed = false;
3699 /* Avoid double printing for --help --target-help. */
3705 if (ARRAY_SIZE (target_switches) > 1
3706 #ifdef TARGET_OPTIONS
3707 || ARRAY_SIZE (target_options) > 1
3715 printf (_("\nTarget specific options:\n"));
3717 for (i = ARRAY_SIZE (target_switches); i--;)
3719 const char *option = target_switches[i].name;
3720 const char *description = target_switches[i].description;
3722 if (option == NULL || *option == 0)
3724 else if (description == NULL)
3729 printf (_(" -m%-23s [undocumented]\n"), option);
3731 else if (*description != 0)
3732 doc += printf (" -m%-23s %s\n", option, _(description));
3735 #ifdef TARGET_OPTIONS
3736 for (i = ARRAY_SIZE (target_options); i--;)
3738 const char *option = target_options[i].prefix;
3739 const char *description = target_options[i].description;
3741 if (option == NULL || *option == 0)
3743 else if (description == NULL)
3748 printf (_(" -m%-23s [undocumented]\n"), option);
3750 else if (*description != 0)
3751 doc += printf (" -m%-23s %s\n", option, _(description));
3757 printf (_("\nThere are undocumented target specific options as well.\n"));
3759 printf (_(" They exist, but they are not documented.\n"));
3764 /* Parse a -d... command line switch. */
3767 decode_d_option (const char *arg)
3775 for (i = 0; i < (int) DFI_MAX; ++i)
3776 dump_file[i].enabled = 1;
3782 flag_print_asm_name = 1;
3785 flag_dump_rtl_in_asm = 1;
3786 flag_print_asm_name = 1;
3789 graph_dump_format = vcg;
3792 rtl_dump_and_exit = 1;
3797 case 'D': /* These are handled by the preprocessor. */
3801 setup_core_dumping();
3806 for (i = 0; i < (int) DFI_MAX; ++i)
3807 if (c == dump_file[i].debug_switch)
3809 dump_file[i].enabled = 1;
3814 warning ("unrecognized gcc debugging option: %c", c);
3819 /* Indexed by enum debug_info_type. */
3820 const char *const debug_type_names[] =
3822 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
3825 /* Decode -m switches. */
3826 /* Decode the switch -mNAME. */
3829 set_target_switch (const char *name)
3832 int valid_target_option = 0;
3834 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
3835 if (!strcmp (target_switches[j].name, name))
3837 if (target_switches[j].value < 0)
3838 target_flags &= ~-target_switches[j].value;
3840 target_flags |= target_switches[j].value;
3843 if (target_switches[j].value < 0)
3844 target_flags_explicit |= -target_switches[j].value;
3846 target_flags_explicit |= target_switches[j].value;
3848 valid_target_option = 1;
3851 #ifdef TARGET_OPTIONS
3852 if (!valid_target_option)
3853 for (j = 0; j < ARRAY_SIZE (target_options); j++)
3855 int len = strlen (target_options[j].prefix);
3856 if (target_options[j].value)
3858 if (!strcmp (target_options[j].prefix, name))
3860 *target_options[j].variable = target_options[j].value;
3861 valid_target_option = 1;
3866 if (!strncmp (target_options[j].prefix, name, len))
3868 *target_options[j].variable = name + len;
3869 valid_target_option = 1;
3875 if (!valid_target_option)
3876 error ("invalid option `%s'", name);
3879 /* Print version information to FILE.
3880 Each line begins with INDENT (for the case where FILE is the
3881 assembler output file). */
3884 print_version (FILE *file, const char *indent)
3887 #define __VERSION__ "[?]"
3891 "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
3893 "%s%s%s version %s (%s) compiled by CC.\n"
3895 , indent, *indent != 0 ? " " : "",
3896 lang_hooks.name, version_string, TARGET_NAME,
3897 indent, __VERSION__);
3898 fnotice (file, "%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n",
3899 indent, *indent != 0 ? " " : "",
3900 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
3903 /* Print an option value and return the adjusted position in the line.
3904 ??? We don't handle error returns from fprintf (disk full); presumably
3905 other code will catch a disk full though. */
3908 print_single_switch (FILE *file, int pos, int max,
3909 const char *indent, const char *sep, const char *term,
3910 const char *type, const char *name)
3912 /* The ultrix fprintf returns 0 on success, so compute the result we want
3913 here since we need it for the following test. */
3914 int len = strlen (sep) + strlen (type) + strlen (name);
3919 fprintf (file, "%s", term);
3924 fprintf (file, "%s", indent);
3925 pos = strlen (indent);
3927 fprintf (file, "%s%s%s", sep, type, name);
3932 /* Print active target switches to FILE.
3933 POS is the current cursor position and MAX is the size of a "line".
3934 Each line begins with INDENT and ends with TERM.
3935 Each switch is separated from the next by SEP. */
3938 print_switch_values (FILE *file, int pos, int max,
3939 const char *indent, const char *sep, const char *term)
3944 /* Fill in the -frandom-seed option, if the user didn't pass it, so
3945 that it can be printed below. This helps reproducibility. */
3948 /* Print the options as passed. */
3949 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
3950 _("options passed: "), "");
3952 for (p = &save_argv[1]; *p != NULL; p++)
3956 if (strcmp (*p, "-o") == 0)
3962 if (strcmp (*p, "-quiet") == 0)
3964 if (strcmp (*p, "-version") == 0)
3969 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
3972 fprintf (file, "%s", term);
3974 /* Print the -f and -m options that have been enabled.
3975 We don't handle language specific options but printing argv
3978 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
3979 _("options enabled: "), "");
3981 for (j = 0; j < ARRAY_SIZE (f_options); j++)
3982 if (*f_options[j].variable == f_options[j].on_value)
3983 pos = print_single_switch (file, pos, max, indent, sep, term,
3984 "-f", f_options[j].string);
3986 /* Print target specific options. */
3988 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
3989 if (target_switches[j].name[0] != '\0'
3990 && target_switches[j].value > 0
3991 && ((target_switches[j].value & target_flags)
3992 == target_switches[j].value))
3994 pos = print_single_switch (file, pos, max, indent, sep, term,
3995 "-m", target_switches[j].name);
3998 #ifdef TARGET_OPTIONS
3999 for (j = 0; j < ARRAY_SIZE (target_options); j++)
4000 if (*target_options[j].variable != NULL)
4003 sprintf (prefix, "-m%s", target_options[j].prefix);
4004 pos = print_single_switch (file, pos, max, indent, sep, term,
4005 prefix, *target_options[j].variable);
4009 fprintf (file, "%s", term);
4012 /* Open assembly code output file. Do this even if -fsyntax-only is
4013 on, because then the driver will have provided the name of a
4014 temporary file or bit bucket for us. NAME is the file specified on
4015 the command line, possibly NULL. */
4017 init_asm_output (const char *name)
4019 if (name == NULL && asm_file_name == 0)
4020 asm_out_file = stdout;
4023 if (asm_file_name == 0)
4025 int len = strlen (dump_base_name);
4026 char *dumpname = xmalloc (len + 6);
4027 memcpy (dumpname, dump_base_name, len + 1);
4028 strip_off_ending (dumpname, len);
4029 strcat (dumpname, ".s");
4030 asm_file_name = dumpname;
4032 if (!strcmp (asm_file_name, "-"))
4033 asm_out_file = stdout;
4035 asm_out_file = fopen (asm_file_name, "w+");
4036 if (asm_out_file == 0)
4037 fatal_error ("can't open %s for writing: %m", asm_file_name);
4040 #ifdef IO_BUFFER_SIZE
4041 setvbuf (asm_out_file, xmalloc (IO_BUFFER_SIZE),
4042 _IOFBF, IO_BUFFER_SIZE);
4045 if (!flag_syntax_only)
4047 targetm.asm_out.file_start ();
4049 #ifdef ASM_COMMENT_START
4050 if (flag_verbose_asm)
4052 /* Print the list of options in effect. */
4053 print_version (asm_out_file, ASM_COMMENT_START);
4054 print_switch_values (asm_out_file, 0, MAX_LINE,
4055 ASM_COMMENT_START, " ", "\n");
4056 /* Add a blank line here so it appears in assembler output but not
4058 fprintf (asm_out_file, "\n");
4064 /* Default version of get_pch_validity.
4065 By default, every flag difference is fatal; that will be mostly right for
4066 most targets, but completely right for very few. */
4069 default_get_pch_validity (size_t *len)
4071 #ifdef TARGET_OPTIONS
4076 *len = sizeof (target_flags) + 2;
4077 #ifdef TARGET_OPTIONS
4078 for (i = 0; i < ARRAY_SIZE (target_options); i++)
4081 if (*target_options[i].variable)
4082 *len += strlen (*target_options[i].variable);
4086 result = r = xmalloc (*len);
4090 memcpy (r, &target_flags, sizeof (target_flags));
4091 r += sizeof (target_flags);
4093 #ifdef TARGET_OPTIONS
4094 for (i = 0; i < ARRAY_SIZE (target_options); i++)
4096 const char *str = *target_options[i].variable;
4100 l = strlen (str) + 1;
4109 /* Default version of pch_valid_p. */
4112 default_pch_valid_p (const void *data_p, size_t len)
4114 const char *data = (const char *)data_p;
4115 const char *flag_that_differs = NULL;
4118 /* -fpic and -fpie also usually make a PCH invalid. */
4119 if (data[0] != flag_pic)
4120 return _("created and used with different settings of -fpic");
4121 if (data[1] != flag_pie)
4122 return _("created and used with different settings of -fpie");
4125 /* Check target_flags. */
4126 if (memcmp (data, &target_flags, sizeof (target_flags)) != 0)
4128 for (i = 0; i < ARRAY_SIZE (target_switches); i++)
4133 memcpy (&tf, data, sizeof (target_flags));
4135 bits = target_switches[i].value;
4138 if ((target_flags & bits) != (tf & bits))
4140 flag_that_differs = target_switches[i].name;
4146 data += sizeof (target_flags);
4147 len -= sizeof (target_flags);
4149 /* Check string options. */
4150 #ifdef TARGET_OPTIONS
4151 for (i = 0; i < ARRAY_SIZE (target_options); i++)
4153 const char *str = *target_options[i].variable;
4157 l = strlen (str) + 1;
4158 if (len < l || memcmp (data, str, l) != 0)
4160 flag_that_differs = target_options[i].prefix;
4173 asprintf (&r, _("created and used with differing settings of `-m%s'"),
4176 return _("out of memory");
4181 /* Default tree printer. Handles declarations only. */
4183 default_tree_printer (pretty_printer * pp, text_info *text)
4185 switch (*text->format_spec)
4191 tree t = va_arg (*text->args_ptr, tree);
4192 const char *n = DECL_NAME (t)
4193 ? (*lang_hooks.decl_printable_name) (t, 2)
4204 /* Initialization of the front end environment, before command line
4205 options are parsed. Signal handlers, internationalization etc.
4206 ARGV0 is main's argv[0]. */
4208 general_init (const char *argv0)
4212 p = argv0 + strlen (argv0);
4213 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
4217 xmalloc_set_program_name (progname);
4221 gcc_init_libintl ();
4223 /* Initialize the diagnostics reporting machinery, so option parsing
4224 can give warnings and errors. */
4225 diagnostic_initialize (global_dc);
4226 /* Set a default printer. Language specific initializations will
4227 override it later. */
4228 pp_format_decoder (global_dc->printer) = &default_tree_printer;
4230 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
4232 signal (SIGSEGV, crash_signal);
4235 signal (SIGILL, crash_signal);
4238 signal (SIGBUS, crash_signal);
4241 signal (SIGABRT, crash_signal);
4243 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
4244 signal (SIGIOT, crash_signal);
4247 signal (SIGFPE, crash_signal);
4250 /* Other host-specific signal setup. */
4251 (*host_hooks.extra_signals)();
4253 /* Initialize the garbage-collector, string pools and tree type hash
4257 linemap_init (&line_table);
4260 /* Initialize register usage now so switches may override. */
4263 /* Register the language-independent parameters. */
4264 add_params (lang_independent_params, LAST_PARAM);
4266 /* This must be done after add_params but before argument processing. */
4267 init_ggc_heuristics();
4270 /* Process the options that have been parsed. */
4272 process_options (void)
4274 /* Allow the front end to perform consistency checks and do further
4275 initialization based on the command line options. This hook also
4276 sets the original filename if appropriate (e.g. foo.i -> foo.c)
4277 so we can correctly initialize debug output. */
4278 no_backend = (*lang_hooks.post_options) (&main_input_filename);
4279 input_filename = main_input_filename;
4281 #ifdef OVERRIDE_OPTIONS
4282 /* Some machines may reject certain combinations of options. */
4286 /* Set aux_base_name if not already set. */
4289 else if (main_input_filename)
4291 char *name = xstrdup (lbasename (main_input_filename));
4293 strip_off_ending (name, strlen (name));
4294 aux_base_name = name;
4297 aux_base_name = "gccaux";
4299 /* Set up the align_*_log variables, defaulting them to 1 if they
4300 were still unset. */
4301 if (align_loops <= 0) align_loops = 1;
4302 if (align_loops_max_skip > align_loops || !align_loops)
4303 align_loops_max_skip = align_loops - 1;
4304 align_loops_log = floor_log2 (align_loops * 2 - 1);
4305 if (align_jumps <= 0) align_jumps = 1;
4306 if (align_jumps_max_skip > align_jumps || !align_jumps)
4307 align_jumps_max_skip = align_jumps - 1;
4308 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
4309 if (align_labels <= 0) align_labels = 1;
4310 align_labels_log = floor_log2 (align_labels * 2 - 1);
4311 if (align_labels_max_skip > align_labels || !align_labels)
4312 align_labels_max_skip = align_labels - 1;
4313 if (align_functions <= 0) align_functions = 1;
4314 align_functions_log = floor_log2 (align_functions * 2 - 1);
4316 /* Unrolling all loops implies that standard loop unrolling must also
4318 if (flag_unroll_all_loops)
4319 flag_unroll_loops = 1;
4321 if (flag_unroll_loops)
4323 flag_old_unroll_loops = 0;
4324 flag_old_unroll_all_loops = 0;
4327 if (flag_old_unroll_all_loops)
4328 flag_old_unroll_loops = 1;
4330 /* Old loop unrolling requires that strength_reduction be on also. Silently
4331 turn on strength reduction here if it isn't already on. Also, the loop
4332 unrolling code assumes that cse will be run after loop, so that must
4333 be turned on also. */
4334 if (flag_old_unroll_loops)
4336 flag_strength_reduce = 1;
4337 flag_rerun_cse_after_loop = 1;
4339 if (flag_unroll_loops || flag_peel_loops)
4340 flag_rerun_cse_after_loop = 1;
4342 if (flag_non_call_exceptions)
4343 flag_asynchronous_unwind_tables = 1;
4344 if (flag_asynchronous_unwind_tables)
4345 flag_unwind_tables = 1;
4347 /* Disable unit-at-a-time mode for frontends not supporting callgraph
4349 if (flag_unit_at_a_time && ! lang_hooks.callgraph.expand_function)
4350 flag_unit_at_a_time = 0;
4352 if (flag_value_profile_transformations)
4353 flag_profile_values = 1;
4355 /* Warn about options that are not supported on this machine. */
4356 #ifndef INSN_SCHEDULING
4357 if (flag_schedule_insns || flag_schedule_insns_after_reload)
4358 warning ("instruction scheduling not supported on this target machine");
4361 if (flag_delayed_branch)
4362 warning ("this target machine does not have delayed branches");
4365 user_label_prefix = USER_LABEL_PREFIX;
4366 if (flag_leading_underscore != -1)
4368 /* If the default prefix is more complicated than "" or "_",
4369 issue a warning and ignore this option. */
4370 if (user_label_prefix[0] == 0 ||
4371 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
4373 user_label_prefix = flag_leading_underscore ? "_" : "";
4376 warning ("-f%sleading-underscore not supported on this target machine",
4377 flag_leading_underscore ? "" : "no-");
4380 /* If we are in verbose mode, write out the version and maybe all the
4381 option flags in use. */
4384 print_version (stderr, "");
4386 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
4389 if (flag_syntax_only)
4391 write_symbols = NO_DEBUG;
4395 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
4397 if (debug_info_level == DINFO_LEVEL_NONE)
4398 write_symbols = NO_DEBUG;
4400 /* Now we know write_symbols, set up the debug hooks based on it.
4401 By default we do nothing for debug output. */
4402 if (write_symbols == NO_DEBUG)
4403 debug_hooks = &do_nothing_debug_hooks;
4404 #if defined(DBX_DEBUGGING_INFO)
4405 else if (write_symbols == DBX_DEBUG)
4406 debug_hooks = &dbx_debug_hooks;
4408 #if defined(XCOFF_DEBUGGING_INFO)
4409 else if (write_symbols == XCOFF_DEBUG)
4410 debug_hooks = &xcoff_debug_hooks;
4412 #ifdef SDB_DEBUGGING_INFO
4413 else if (write_symbols == SDB_DEBUG)
4414 debug_hooks = &sdb_debug_hooks;
4416 #ifdef DWARF2_DEBUGGING_INFO
4417 else if (write_symbols == DWARF2_DEBUG)
4418 debug_hooks = &dwarf2_debug_hooks;
4420 #ifdef VMS_DEBUGGING_INFO
4421 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
4422 debug_hooks = &vmsdbg_debug_hooks;
4425 error ("target system does not support the \"%s\" debug format",
4426 debug_type_names[write_symbols]);
4428 /* Now we know which debug output will be used so we can set
4429 flag_var_tracking if user has not specified it. */
4430 if (flag_var_tracking == AUTODETECT_FLAG_VAR_TRACKING)
4432 /* User has not specified -f(no-)var-tracking so autodetect it. */
4434 = (optimize >= 1 && debug_info_level >= DINFO_LEVEL_NORMAL
4435 && debug_hooks->var_location != do_nothing_debug_hooks.var_location);
4438 /* If auxiliary info generation is desired, open the output file.
4439 This goes in the same directory as the source file--unlike
4440 all the other output files. */
4441 if (flag_gen_aux_info)
4443 aux_info_file = fopen (aux_info_file_name, "w");
4444 if (aux_info_file == 0)
4445 fatal_error ("can't open %s: %m", aux_info_file_name);
4448 if (! targetm.have_named_sections)
4450 if (flag_function_sections)
4452 warning ("-ffunction-sections not supported for this target");
4453 flag_function_sections = 0;
4455 if (flag_data_sections)
4457 warning ("-fdata-sections not supported for this target");
4458 flag_data_sections = 0;
4462 if (flag_function_sections && profile_flag)
4464 warning ("-ffunction-sections disabled; it makes profiling impossible");
4465 flag_function_sections = 0;
4468 #ifndef HAVE_prefetch
4469 if (flag_prefetch_loop_arrays)
4471 warning ("-fprefetch-loop-arrays not supported for this target");
4472 flag_prefetch_loop_arrays = 0;
4475 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
4477 warning ("-fprefetch-loop-arrays not supported for this target (try -march switches)");
4478 flag_prefetch_loop_arrays = 0;
4482 /* This combination of options isn't handled for i386 targets and doesn't
4483 make much sense anyway, so don't allow it. */
4484 if (flag_prefetch_loop_arrays && optimize_size)
4486 warning ("-fprefetch-loop-arrays is not supported with -Os");
4487 flag_prefetch_loop_arrays = 0;
4490 #ifndef OBJECT_FORMAT_ELF
4491 if (flag_function_sections && write_symbols != NO_DEBUG)
4492 warning ("-ffunction-sections may affect debugging on some targets");
4495 /* The presence of IEEE signaling NaNs, implies all math can trap. */
4496 if (flag_signaling_nans)
4497 flag_trapping_math = 1;
4500 /* Initialize the compiler back end. */
4504 init_adjust_machine_modes ();
4506 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
4507 || debug_info_level == DINFO_LEVEL_VERBOSE
4508 #ifdef VMS_DEBUGGING_INFO
4509 /* Enable line number info for traceback. */
4510 || debug_info_level > DINFO_LEVEL_NONE
4512 || flag_test_coverage
4513 || warn_notreached);
4516 init_fake_stack_mems ();
4520 init_function_once ();
4521 init_varasm_once ();
4523 /* The following initialization functions need to generate rtl, so
4524 provide a dummy function context for them. */
4525 init_dummy_function_start ();
4527 if (flag_caller_saves)
4528 init_caller_save ();
4529 expand_dummy_function_end ();
4532 /* Language-dependent initialization. Returns nonzero on success. */
4534 lang_dependent_init (const char *name)
4536 if (dump_base_name == 0)
4537 dump_base_name = name ? name : "gccdump";
4539 /* Other front-end initialization. */
4540 if ((*lang_hooks.init) () == 0)
4543 init_asm_output (name);
4545 /* These create various _DECL nodes, so need to be called after the
4546 front end is initialized. */
4550 /* The following initialization functions need to generate rtl, so
4551 provide a dummy function context for them. */
4552 init_dummy_function_start ();
4554 expand_dummy_function_end ();
4556 /* If dbx symbol table desired, initialize writing it and output the
4557 predefined types. */
4558 timevar_push (TV_SYMOUT);
4560 #ifdef DWARF2_UNWIND_INFO
4561 if (dwarf2out_do_frame ())
4562 dwarf2out_frame_init ();
4565 /* Now we have the correct original filename, we can initialize
4567 (*debug_hooks->init) (name);
4569 timevar_pop (TV_SYMOUT);
4574 /* Clean up: close opened files, etc. */
4579 /* Close the dump files. */
4580 if (flag_gen_aux_info)
4582 fclose (aux_info_file);
4584 unlink (aux_info_file_name);
4587 /* Close non-debugging input and output files. Take special care to note
4588 whether fclose returns an error, since the pages might still be on the
4589 buffer chain while the file is open. */
4593 if (ferror (asm_out_file) != 0)
4594 fatal_error ("error writing to %s: %m", asm_file_name);
4595 if (fclose (asm_out_file) != 0)
4596 fatal_error ("error closing %s: %m", asm_file_name);
4599 /* Do whatever is necessary to finish printing the graphs. */
4600 if (graph_dump_format != no_graph)
4604 for (i = 0; i < (int) DFI_MAX; ++i)
4605 if (dump_file[i].initialized && dump_file[i].graph_dump_p)
4610 sprintf (seq, DUMPFILE_FORMAT, i);
4611 suffix = concat (seq, dump_file[i].extension, NULL);
4612 finish_graph_dump_file (dump_base_name, suffix);
4619 ggc_print_statistics ();
4620 stringpool_statistics ();
4621 dump_tree_statistics ();
4622 dump_rtx_statistics ();
4623 dump_varray_statistics ();
4624 dump_alloc_pool_statistics ();
4627 /* Free up memory for the benefit of leak detectors. */
4630 /* Language-specific end of compilation actions. */
4631 (*lang_hooks.finish) ();
4634 /* Initialize the compiler, and compile the input file. */
4638 /* Initialize timing first. The C front ends read the main file in
4639 the post_options hook, and C++ does file timings. */
4640 if (time_report || !quiet_flag || flag_detailed_statistics)
4642 timevar_start (TV_TOTAL);
4646 /* Don't do any more if an error has already occurred. */
4649 /* Set up the back-end if requested. */
4653 /* Language-dependent initialization. Returns true on success. */
4654 if (lang_dependent_init (main_input_filename))
4656 if (flag_unit_at_a_time)
4658 open_dump_file (DFI_cgraph, NULL);
4659 cgraph_dump_file = rtl_dump_file;
4660 rtl_dump_file = NULL;
4665 if (flag_unit_at_a_time)
4667 rtl_dump_file = cgraph_dump_file;
4668 cgraph_dump_file = NULL;
4669 close_dump_file (DFI_cgraph, NULL, NULL_RTX);
4676 /* Stop timing and print the times. */
4677 timevar_stop (TV_TOTAL);
4678 timevar_print (stderr);
4681 /* Entry point of cc1, cc1plus, jc1, f771, etc.
4682 Exit code is FATAL_EXIT_CODE if can't open files or if there were
4683 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
4685 It is not safe to call this function more than once. */
4688 toplev_main (unsigned int argc, const char **argv)
4692 /* Initialization of GCC's environment, and diagnostics. */
4693 general_init (argv[0]);
4695 /* Parse the options and do minimal processing; basically just
4696 enough to default flags appropriately. */
4697 decode_options (argc, argv);
4701 /* Exit early if we can (e.g. -help). */
4702 if (!exit_after_options)
4705 if (errorcount || sorrycount)
4706 return (FATAL_EXIT_CODE);
4708 return (SUCCESS_EXIT_CODE);