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 means don't put addresses of constant functions in registers.
586 Used for compiling the Unix kernel, where strange substitutions are
587 done on the assembly output. */
589 int flag_no_function_cse = 0;
591 /* Nonzero for -fomit-frame-pointer:
592 don't make a frame pointer in simple functions that don't require one. */
594 int flag_omit_frame_pointer = 0;
596 /* Nonzero means place each function into its own section on those platforms
597 which support arbitrary section names and unlimited numbers of sections. */
599 int flag_function_sections = 0;
601 /* ... and similar for data. */
603 int flag_data_sections = 0;
605 /* Nonzero to inhibit use of define_optimization peephole opts. */
607 int flag_no_peephole = 0;
609 /* Nonzero allows GCC to optimize sibling and tail recursive calls. */
611 int flag_optimize_sibling_calls = 0;
613 /* Nonzero means the front end generally wants `errno' maintained by math
614 operations, like built-in SQRT. */
616 int flag_errno_math = 1;
618 /* Nonzero means that unsafe floating-point math optimizations are allowed
619 for the sake of speed. IEEE compliance is not guaranteed, and operations
620 are allowed to assume that their arguments and results are "normal"
621 (e.g., nonnegative for SQRT). */
623 int flag_unsafe_math_optimizations = 0;
625 /* Nonzero means that no NaNs or +-Infs are expected. */
627 int flag_finite_math_only = 0;
629 /* Zero means that floating-point math operations cannot generate a
630 (user-visible) trap. This is the case, for example, in nonstop
631 IEEE 754 arithmetic. Trapping conditions include division by zero,
632 overflow, underflow, invalid and inexact, but does not include
633 operations on signaling NaNs (see below). */
635 int flag_trapping_math = 1;
637 /* Nonzero means disable transformations that assume default floating
638 point rounding behavior. */
640 int flag_rounding_math = 0;
642 /* Nonzero means disable transformations observable by signaling NaNs.
643 This option implies that any operation on an IEEE signaling NaN can
644 generate a (user-visible) trap. */
646 int flag_signaling_nans = 0;
648 /* 0 means straightforward implementation of complex divide acceptable.
649 1 means wide ranges of inputs must work for complex divide.
650 2 means C99-like requirements for complex divide (not yet implemented). */
652 int flag_complex_divide_method = 0;
654 /* Nonzero means just do syntax checking; don't output anything. */
656 int flag_syntax_only = 0;
658 /* Nonzero means performs web construction pass. */
662 /* Nonzero means perform loop optimizer. */
664 int flag_loop_optimize;
666 /* Nonzero means perform crossjumping. */
668 int flag_crossjumping;
670 /* Nonzero means perform if conversion. */
672 int flag_if_conversion;
674 /* Nonzero means perform if conversion after reload. */
676 int flag_if_conversion2;
678 /* Nonzero means to use global dataflow analysis to eliminate
679 useless null pointer tests. */
681 int flag_delete_null_pointer_checks;
683 /* Nonzero means perform global CSE. */
687 /* Nonzero means to do the enhanced load motion during gcse, which trys
688 to hoist loads by not killing them when a store to the same location
691 int flag_gcse_lm = 1;
693 /* Nonzero means to perform store motion after gcse, which will try to
694 move stores closer to the exit block. Its not very effective without
697 int flag_gcse_sm = 1;
699 /* Nonzero if we want to perfrom redundant load after store elimination
702 int flag_gcse_las = 1;
704 /* Perform target register optimization before prologue / epilogue
707 int flag_branch_target_load_optimize = 0;
709 /* Perform target register optimization after prologue / epilogue
710 threading and jump2. */
712 int flag_branch_target_load_optimize2 = 0;
714 /* For the bt-load pass, nonzero means don't re-use branch target registers
715 in any basic block. */
717 int flag_btr_bb_exclusive;
719 /* Nonzero means to rerun cse after loop optimization. This increases
720 compilation time about 20% and picks up a few more common expressions. */
722 int flag_rerun_cse_after_loop;
724 /* Nonzero means to run loop optimizations twice. */
726 int flag_rerun_loop_opt;
728 /* Nonzero for -finline-functions: ok to inline functions that look like
729 good inline candidates. */
731 int flag_inline_functions;
733 /* Nonzero for -fkeep-inline-functions: even if we make a function
734 go inline everywhere, keep its definition around for debugging
737 int flag_keep_inline_functions;
739 /* Nonzero means that functions will not be inlined. */
741 int flag_no_inline = 2;
743 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
744 not just because the tree inliner turned us off. */
746 int flag_really_no_inline = 2;
748 /* Nonzero means that we should emit static const variables
749 regardless of whether or not optimization is turned on. */
751 int flag_keep_static_consts = 1;
753 /* Nonzero means we should be saving declaration info into a .X file. */
755 int flag_gen_aux_info = 0;
757 /* Specified name of aux-info file. */
759 const char *aux_info_file_name;
761 /* Nonzero means make the text shared if supported. */
763 int flag_shared_data;
765 /* Nonzero means schedule into delayed branch slots if supported. */
767 int flag_delayed_branch;
769 /* Nonzero if we are compiling pure (sharable) code.
770 Value is 1 if we are doing "small" pic; value is 2 if we're doing
775 /* Nonzero if we are compiling position independent code for executable.
776 The value is 1 if we are doing "small" pic; value is 2 if we're doing
781 /* Nonzero if we are compiling code for a shared library, zero for
786 /* Set to the default thread-local storage (tls) model to use. */
788 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
790 /* Nonzero means generate extra code for exception handling and enable
791 exception handling. */
795 /* Nonzero means generate frame unwind info table when supported. */
797 int flag_unwind_tables = 0;
799 /* Nonzero means generate frame unwind info table exact at each insn
802 int flag_asynchronous_unwind_tables = 0;
804 /* Nonzero means don't place uninitialized global data in common storage
809 /* Nonzero means change certain warnings into errors.
810 Usually these are warnings about failure to conform to some standard. */
812 int flag_pedantic_errors = 0;
814 /* flag_schedule_insns means schedule insns within basic blocks (before
816 flag_schedule_insns_after_reload means schedule insns after
819 int flag_schedule_insns = 0;
820 int flag_schedule_insns_after_reload = 0;
822 /* When flag_schedule_insns_after_reload is set, use EBB scheduler. */
823 int flag_sched2_use_superblocks = 0;
825 /* When flag_schedule_insns_after_reload is set, construct traces and EBB
827 int flag_sched2_use_traces = 0;
829 /* The following flags have effect only for scheduling before register
832 flag_schedule_interblock means schedule insns across basic blocks.
833 flag_schedule_speculative means allow speculative motion of non-load insns.
834 flag_schedule_speculative_load means allow speculative motion of some
836 flag_schedule_speculative_load_dangerous allows speculative motion of more
839 int flag_schedule_interblock = 1;
840 int flag_schedule_speculative = 1;
841 int flag_schedule_speculative_load = 0;
842 int flag_schedule_speculative_load_dangerous = 0;
844 /* The following flags have an effect during scheduling after register
847 flag_sched_stalled_insns means that insns can be moved prematurely from the queue
848 of stalled insns into the ready list.
850 flag_sched_stalled_insns_dep controls how many insn groups will be examined
851 for a dependency on a stalled insn that is candidate for premature removal
852 from the queue of stalled insns into the ready list (has an effect only if
853 the flag 'sched_stalled_insns' is set). */
855 int flag_sched_stalled_insns = 0;
856 int flag_sched_stalled_insns_dep = 1;
858 int flag_single_precision_constant;
860 /* flag_branch_on_count_reg means try to replace add-1,compare,branch tupple
861 by a cheaper branch on a count register. */
862 int flag_branch_on_count_reg = 1;
864 /* -finhibit-size-directive inhibits output of .size for ELF.
865 This is used only for compiling crtstuff.c,
866 and it may be extended to other effects
867 needed for crtstuff.c on other systems. */
868 int flag_inhibit_size_directive = 0;
870 /* -fverbose-asm causes extra commentary information to be produced in
871 the generated assembly code (to make it more readable). This option
872 is generally only of use to those who actually need to read the
873 generated assembly code (perhaps while debugging the compiler itself).
874 -fno-verbose-asm, the default, causes the extra information
875 to be omitted and is useful when comparing two assembler files. */
877 int flag_verbose_asm = 0;
879 /* -dA causes debug commentary information to be produced in
880 the generated assembly code (to make it more readable). This option
881 is generally only of use to those who actually need to read the
882 generated assembly code (perhaps while debugging the compiler itself).
883 Currently, this switch is only used by dwarfout.c; however, it is intended
884 to be a catchall for printing debug information in the assembler file. */
886 int flag_debug_asm = 0;
888 /* -dP causes the rtl to be emitted as a comment in assembly. */
890 int flag_dump_rtl_in_asm = 0;
892 /* Nonzero means put zero initialized data in the bss section. */
893 int flag_zero_initialized_in_bss = 1;
895 /* Tag all structures with __attribute__(packed). */
896 int flag_pack_struct = 0;
898 /* Emit code to check for stack overflow; also may cause large objects
899 to be allocated dynamically. */
900 int flag_stack_check;
902 /* When non-NULL, indicates that whenever space is allocated on the
903 stack, the resulting stack pointer must not pass this
904 address---that is, for stacks that grow downward, the stack pointer
905 must always be greater than or equal to this address; for stacks
906 that grow upward, the stack pointer must be less than this address.
907 At present, the rtx may be either a REG or a SYMBOL_REF, although
908 the support provided depends on the backend. */
911 /* 0 if pointer arguments may alias each other. True in C.
912 1 if pointer arguments may not alias each other but may alias
914 2 if pointer arguments may not alias each other and may not
915 alias global variables. True in Fortran.
916 This defaults to 0 for C. */
917 int flag_argument_noalias = 0;
919 /* Nonzero if we should do (language-dependent) alias analysis.
920 Typically, this analysis will assume that expressions of certain
921 types do not alias expressions of certain other types. Only used
922 if alias analysis (in general) is enabled. */
923 int flag_strict_aliasing = 0;
925 /* Instrument functions with calls at entry and exit, for profiling. */
926 int flag_instrument_function_entry_exit = 0;
928 /* Nonzero means ignore `#ident' directives. 0 means handle them.
929 On SVR4 targets, it also controls whether or not to emit a
930 string identifying the compiler. */
932 int flag_no_ident = 0;
934 /* This will perform a peephole pass before sched2. */
935 int flag_peephole2 = 0;
937 /* This will try to guess branch probabilities. */
938 int flag_guess_branch_prob = 0;
940 /* -fcheck-bounds causes gcc to generate array bounds checks.
941 For C, C++, ObjC: defaults to off.
942 For Java: defaults to on.
943 For Fortran: defaults to off. */
944 int flag_bounds_check = 0;
946 /* This will attempt to merge constant section constants, if 1 only
947 string constants and constants from constant pool, if 2 also constant
949 int flag_merge_constants = 1;
951 /* If one, renumber instruction UIDs to reduce the number of
952 unused UIDs if there are a lot of instructions. If greater than
953 one, unconditionally renumber instruction UIDs. */
954 int flag_renumber_insns = 1;
956 /* If nonzero, use the graph coloring register allocator. */
957 int flag_new_regalloc = 0;
959 /* Nonzero if we perform superblock formation. */
963 /* Nonzero if we perform whole unit at a time compilation. */
965 int flag_unit_at_a_time = 0;
967 /* Nonzero if we should track variables. When
968 flag_var_tracking == AUTODETECT_FLAG_VAR_TRACKING it will be set according
969 to optimize, debug_info_level and debug_hooks in process_options (). */
971 #define AUTODETECT_FLAG_VAR_TRACKING 2
972 int flag_var_tracking = AUTODETECT_FLAG_VAR_TRACKING;
974 /* Values of the -falign-* flags: how much to align labels in code.
975 0 means `use default', 1 means `don't align'.
976 For each variable, there is an _log variant which is the power
977 of two not less than the variable, for .align output. */
981 int align_loops_max_skip;
984 int align_jumps_max_skip;
986 int align_labels_log;
987 int align_labels_max_skip;
989 int align_functions_log;
991 /* Like align_functions_log above, but used by front-ends to force the
992 minimum function alignment. Zero means no alignment is forced. */
993 int force_align_functions_log;
997 const char *const string;
1001 lang_independent_options;
1003 /* Nonzero if signed arithmetic overflow should trap. */
1006 /* Nonzero if signed arithmetic overflow should wrap around. */
1009 /* Nonzero if subexpressions must be evaluated from left-to-right. */
1010 int flag_evaluation_order = 0;
1012 /* Add or remove a leading underscore from user symbols. */
1013 int flag_leading_underscore = -1;
1015 /* The version of the C++ ABI in use. The following values are
1018 0: The version of the ABI believed most conformant with the
1019 C++ ABI specification. This ABI may change as bugs are
1020 discovered and fixed. Therefore, 0 will not necessarily
1021 indicate the same ABI in different versions of G++.
1023 1: The version of the ABI first used in G++ 3.2.
1025 2: The version of the ABI first used in G++ 3.4.
1027 Additional positive integers will be assigned as new versions of
1028 the ABI become the default version of the ABI. */
1030 int flag_abi_version = 2;
1032 /* The user symbol prefix after having resolved same. */
1033 const char *user_label_prefix;
1035 static const param_info lang_independent_params[] = {
1036 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT) \
1037 { OPTION, DEFAULT, HELP },
1038 #include "params.def"
1043 /* Table of language-independent -f options.
1044 STRING is the option name. VARIABLE is the address of the variable.
1045 ON_VALUE is the value to store in VARIABLE
1046 if `-fSTRING' is seen as an option.
1047 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
1049 static const lang_independent_options f_options[] =
1051 {"eliminate-dwarf2-dups", &flag_eliminate_dwarf2_dups, 1 },
1052 {"eliminate-unused-debug-symbols", &flag_debug_only_used_symbols, 1 },
1053 {"eliminate-unused-debug-types", &flag_eliminate_unused_debug_types, 1 },
1054 {"float-store", &flag_float_store, 1 },
1055 {"defer-pop", &flag_defer_pop, 1 },
1056 {"omit-frame-pointer", &flag_omit_frame_pointer, 1 },
1057 {"optimize-sibling-calls", &flag_optimize_sibling_calls, 1 },
1058 {"tracer", &flag_tracer, 1 },
1059 {"unit-at-a-time", &flag_unit_at_a_time, 1 },
1060 {"cse-follow-jumps", &flag_cse_follow_jumps, 1 },
1061 {"cse-skip-blocks", &flag_cse_skip_blocks, 1 },
1062 {"expensive-optimizations", &flag_expensive_optimizations, 1 },
1063 {"thread-jumps", &flag_thread_jumps, 1 },
1064 {"strength-reduce", &flag_strength_reduce, 1 },
1065 {"unroll-loops", &flag_unroll_loops, 1 },
1066 {"unroll-all-loops", &flag_unroll_all_loops, 1 },
1067 {"old-unroll-loops", &flag_old_unroll_loops, 1 },
1068 {"old-unroll-all-loops", &flag_old_unroll_all_loops, 1 },
1069 {"peel-loops", &flag_peel_loops, 1 },
1070 {"unswitch-loops", &flag_unswitch_loops, 1 },
1071 {"prefetch-loop-arrays", &flag_prefetch_loop_arrays, 1 },
1072 {"move-all-movables", &flag_move_all_movables, 1 },
1073 {"reduce-all-givs", &flag_reduce_all_givs, 1 },
1074 {"peephole", &flag_no_peephole, 0 },
1075 {"force-mem", &flag_force_mem, 1 },
1076 {"force-addr", &flag_force_addr, 1 },
1077 {"function-cse", &flag_no_function_cse, 0 },
1078 {"inline-functions", &flag_inline_functions, 1 },
1079 {"keep-inline-functions", &flag_keep_inline_functions, 1 },
1080 {"inline", &flag_no_inline, 0 },
1081 {"keep-static-consts", &flag_keep_static_consts, 1 },
1082 {"syntax-only", &flag_syntax_only, 1 },
1083 {"shared-data", &flag_shared_data, 1 },
1084 {"caller-saves", &flag_caller_saves, 1 },
1085 {"pcc-struct-return", &flag_pcc_struct_return, 1 },
1086 {"reg-struct-return", &flag_pcc_struct_return, 0 },
1087 {"delayed-branch", &flag_delayed_branch, 1 },
1088 {"web", &flag_web, 1},
1089 {"gcse", &flag_gcse, 1 },
1090 {"gcse-lm", &flag_gcse_lm, 1 },
1091 {"gcse-sm", &flag_gcse_sm, 1 },
1092 {"gcse-las", &flag_gcse_las, 1 },
1093 {"branch-target-load-optimize", &flag_branch_target_load_optimize, 1 },
1094 {"branch-target-load-optimize2", &flag_branch_target_load_optimize2, 1 },
1095 {"btr-bb-exclusive", &flag_btr_bb_exclusive, 1 },
1096 {"loop-optimize", &flag_loop_optimize, 1 },
1097 {"crossjumping", &flag_crossjumping, 1 },
1098 {"if-conversion", &flag_if_conversion, 1 },
1099 {"if-conversion2", &flag_if_conversion2, 1 },
1100 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1 },
1101 {"rerun-loop-opt", &flag_rerun_loop_opt, 1 },
1102 {"delete-null-pointer-checks", &flag_delete_null_pointer_checks, 1 },
1103 {"schedule-insns", &flag_schedule_insns, 1 },
1104 {"schedule-insns2", &flag_schedule_insns_after_reload, 1 },
1105 {"sched-interblock",&flag_schedule_interblock, 1 },
1106 {"sched-spec",&flag_schedule_speculative, 1 },
1107 {"sched-spec-load",&flag_schedule_speculative_load, 1 },
1108 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1 },
1109 {"sched-stalled-insns", &flag_sched_stalled_insns, 0 },
1110 {"sched-stalled-insns-dep", &flag_sched_stalled_insns_dep, 1 },
1111 {"sched2-use-superblocks", &flag_sched2_use_superblocks, 1 },
1112 {"sched2-use-traces", &flag_sched2_use_traces, 1 },
1113 {"branch-count-reg",&flag_branch_on_count_reg, 1 },
1114 {"pic", &flag_pic, 1 },
1115 {"PIC", &flag_pic, 2 },
1116 {"pie", &flag_pie, 1 },
1117 {"PIE", &flag_pie, 2 },
1118 {"exceptions", &flag_exceptions, 1 },
1119 {"unwind-tables", &flag_unwind_tables, 1 },
1120 {"asynchronous-unwind-tables", &flag_asynchronous_unwind_tables, 1 },
1121 {"non-call-exceptions", &flag_non_call_exceptions, 1 },
1122 {"profile-arcs", &profile_arc_flag, 1 },
1123 {"profile-values", &flag_profile_values, 1 },
1124 {"vpt", &flag_value_profile_transformations, 1 },
1125 {"test-coverage", &flag_test_coverage, 1 },
1126 {"branch-probabilities", &flag_branch_probabilities, 1 },
1127 {"profile", &profile_flag, 1 },
1128 {"reorder-blocks", &flag_reorder_blocks, 1 },
1129 {"reorder-functions", &flag_reorder_functions, 1 },
1130 {"rename-registers", &flag_rename_registers, 1 },
1131 {"cprop-registers", &flag_cprop_registers, 1 },
1132 {"common", &flag_no_common, 0 },
1133 {"inhibit-size-directive", &flag_inhibit_size_directive, 1 },
1134 {"function-sections", &flag_function_sections, 1 },
1135 {"data-sections", &flag_data_sections, 1 },
1136 {"verbose-asm", &flag_verbose_asm, 1 },
1137 {"regmove", &flag_regmove, 1 },
1138 {"optimize-register-move", &flag_regmove, 1 },
1139 {"pack-struct", &flag_pack_struct, 1 },
1140 {"stack-check", &flag_stack_check, 1 },
1141 {"argument-alias", &flag_argument_noalias, 0 },
1142 {"argument-noalias", &flag_argument_noalias, 1 },
1143 {"argument-noalias-global", &flag_argument_noalias, 2 },
1144 {"strict-aliasing", &flag_strict_aliasing, 1 },
1145 {"align-loops", &align_loops, 0 },
1146 {"align-jumps", &align_jumps, 0 },
1147 {"align-labels", &align_labels, 0 },
1148 {"align-functions", &align_functions, 0 },
1149 {"merge-constants", &flag_merge_constants, 1 },
1150 {"merge-all-constants", &flag_merge_constants, 2 },
1151 {"dump-unnumbered", &flag_dump_unnumbered, 1 },
1152 {"instrument-functions", &flag_instrument_function_entry_exit, 1 },
1153 {"zero-initialized-in-bss", &flag_zero_initialized_in_bss, 1 },
1154 {"leading-underscore", &flag_leading_underscore, 1 },
1155 {"ident", &flag_no_ident, 0 },
1156 { "peephole2", &flag_peephole2, 1 },
1157 {"finite-math-only", &flag_finite_math_only, 1 },
1158 { "guess-branch-probability", &flag_guess_branch_prob, 1 },
1159 {"math-errno", &flag_errno_math, 1 },
1160 {"trapping-math", &flag_trapping_math, 1 },
1161 {"rounding-math", &flag_rounding_math, 1 },
1162 {"unsafe-math-optimizations", &flag_unsafe_math_optimizations, 1 },
1163 {"signaling-nans", &flag_signaling_nans, 1 },
1164 {"bounds-check", &flag_bounds_check, 1 },
1165 {"single-precision-constant", &flag_single_precision_constant, 1 },
1166 {"time-report", &time_report, 1 },
1167 {"mem-report", &mem_report, 1 },
1168 { "trapv", &flag_trapv, 1 },
1169 { "wrapv", &flag_wrapv, 1 },
1170 { "new-ra", &flag_new_regalloc, 1 },
1171 { "var-tracking", &flag_var_tracking, 1}
1174 /* Here is a table, controlled by the tm.h file, listing each -m switch
1175 and which bits in `target_switches' it should set or clear.
1176 If VALUE is positive, it is bits to set.
1177 If VALUE is negative, -VALUE is bits to clear.
1178 (The sign bit is not used so there is no confusion.) */
1182 const char *const name;
1184 const char *const description;
1186 target_switches[] = TARGET_SWITCHES;
1188 /* This table is similar, but allows the switch to have a value. */
1190 #ifdef TARGET_OPTIONS
1193 const char *const prefix;
1194 const char **const variable;
1195 const char *const description;
1196 const char *const value;
1198 target_options[] = TARGET_OPTIONS;
1201 /* Nonzero means warn about function definitions that default the return type
1202 or that use a null return and have a return-type other than void. */
1204 int warn_return_type;
1206 /* Output files for assembler code (real compiler output)
1207 and debugging dumps. */
1210 FILE *aux_info_file;
1211 FILE *rtl_dump_file = NULL;
1212 FILE *cgraph_dump_file = NULL;
1214 /* The current working directory of a translation. It's generally the
1215 directory from which compilation was initiated, but a preprocessed
1216 file may specify the original directory in which it was
1219 static const char *src_pwd;
1221 /* Initialize src_pwd with the given string, and return true. If it
1222 was already initialized, return false. As a special case, it may
1223 be called with a NULL argument to test whether src_pwd has NOT been
1227 set_src_pwd (const char *pwd)
1232 src_pwd = xstrdup (pwd);
1236 /* Return the directory from which the translation unit was initiated,
1237 in case set_src_pwd() was not called before to assign it a
1244 src_pwd = getpwd ();
1249 /* Called when the start of a function definition is parsed,
1250 this function prints on stderr the name of the function. */
1252 announce_function (tree decl)
1256 if (rtl_dump_and_exit)
1257 verbatim ("%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1259 verbatim (" %s", (*lang_hooks.decl_printable_name) (decl, 2));
1261 pp_needs_newline (global_dc->printer) = true;
1262 diagnostic_set_last_function (global_dc);
1266 /* Set up a default flag_random_seed and local_tick, unless the user
1267 already specified one. */
1272 if (!flag_random_seed)
1274 unsigned HOST_WIDE_INT value;
1275 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
1277 /* Get some more or less random data. */
1278 #ifdef HAVE_GETTIMEOFDAY
1282 gettimeofday (&tv, NULL);
1283 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
1287 time_t now = time (NULL);
1289 if (now != (time_t)-1)
1290 local_tick = (unsigned) now;
1293 value = local_tick ^ getpid ();
1295 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
1296 flag_random_seed = random_seed;
1298 else if (!local_tick)
1303 /* Decode the string P as an integral parameter.
1304 If the string is indeed an integer return its numeric value else
1305 issue an Invalid Option error for the option PNAME and return DEFVAL.
1306 If PNAME is zero just return DEFVAL, do not call error. */
1309 read_integral_parameter (const char *p, const char *pname, const int defval)
1311 const char *endp = p;
1315 if (ISDIGIT (*endp))
1324 error ("invalid option argument `%s'", pname);
1331 /* Return the logarithm of X, base 2, considering X unsigned,
1332 if X is a power of 2. Otherwise, returns -1.
1334 This should be used via the `exact_log2' macro. */
1337 exact_log2_wide (unsigned HOST_WIDE_INT x)
1340 /* Test for 0 or a power of 2. */
1341 if (x == 0 || x != (x & -x))
1343 while ((x >>= 1) != 0)
1348 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1349 If X is 0, return -1.
1351 This should be used via the floor_log2 macro. */
1354 floor_log2_wide (unsigned HOST_WIDE_INT x)
1363 /* Handler for fatal signals, such as SIGSEGV. These are transformed
1364 into ICE messages, which is much more user friendly. In case the
1365 error printer crashes, reset the signal to prevent infinite recursion. */
1368 crash_signal (int signo)
1370 signal (signo, SIG_DFL);
1371 internal_error ("%s", strsignal (signo));
1374 /* Arrange to dump core on error. (The regular error message is still
1375 printed first, except in the case of abort().) */
1378 setup_core_dumping (void)
1381 signal (SIGABRT, SIG_DFL);
1383 #if defined(HAVE_SETRLIMIT)
1386 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
1387 fatal_error ("getting core file size maximum limit: %m");
1388 rlim.rlim_cur = rlim.rlim_max;
1389 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
1390 fatal_error ("setting core file size limit to maximum: %m");
1393 diagnostic_abort_on_error (global_dc);
1397 /* Strip off a legitimate source ending from the input string NAME of
1398 length LEN. Rather than having to know the names used by all of
1399 our front ends, we strip off an ending of a period followed by
1400 up to five characters. (Java uses ".class".) */
1403 strip_off_ending (char *name, int len)
1406 for (i = 2; i < 6 && len > i; i++)
1408 if (name[len - i] == '.')
1410 name[len - i] = '\0';
1416 /* Output a quoted string. */
1419 output_quoted_string (FILE *asm_file, const char *string)
1421 #ifdef OUTPUT_QUOTED_STRING
1422 OUTPUT_QUOTED_STRING (asm_file, string);
1426 putc ('\"', asm_file);
1427 while ((c = *string++) != 0)
1431 if (c == '\"' || c == '\\')
1432 putc ('\\', asm_file);
1436 fprintf (asm_file, "\\%03o", (unsigned char) c);
1438 putc ('\"', asm_file);
1442 /* Output a file name in the form wanted by System V. */
1445 output_file_directive (FILE *asm_file, const char *input_name)
1450 if (input_name == NULL)
1451 input_name = "<stdin>";
1453 len = strlen (input_name);
1454 na = input_name + len;
1456 /* NA gets INPUT_NAME sans directory names. */
1457 while (na > input_name)
1459 if (IS_DIR_SEPARATOR (na[-1]))
1464 #ifdef ASM_OUTPUT_SOURCE_FILENAME
1465 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
1467 fprintf (asm_file, "\t.file\t");
1468 output_quoted_string (asm_file, na);
1469 fputc ('\n', asm_file);
1473 /* Routine to open a dump file. Return true if the dump file is enabled. */
1476 open_dump_file (enum dump_file_index index, tree decl)
1479 const char *open_arg;
1482 if (! dump_file[index].enabled)
1485 timevar_push (TV_DUMP);
1486 if (rtl_dump_file != NULL)
1487 fclose (rtl_dump_file);
1489 sprintf (seq, DUMPFILE_FORMAT, index);
1491 if (! dump_file[index].initialized)
1493 /* If we've not initialized the files, do so now. */
1494 if (graph_dump_format != no_graph
1495 && dump_file[index].graph_dump_p)
1497 dump_name = concat (seq, dump_file[index].extension, NULL);
1498 clean_graph_dump_file (dump_base_name, dump_name);
1501 dump_file[index].initialized = 1;
1507 dump_name = concat (dump_base_name, seq,
1508 dump_file[index].extension, NULL);
1510 rtl_dump_file = fopen (dump_name, open_arg);
1511 if (rtl_dump_file == NULL)
1512 fatal_error ("can't open %s: %m", dump_name);
1517 fprintf (rtl_dump_file, "\n;; Function %s%s\n\n",
1518 (*lang_hooks.decl_printable_name) (decl, 2),
1519 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
1521 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
1522 ? " (unlikely executed)"
1525 timevar_pop (TV_DUMP);
1529 /* Routine to close a dump file. */
1532 close_dump_file (enum dump_file_index index,
1533 void (*func) (FILE *, rtx),
1536 if (! rtl_dump_file)
1539 timevar_push (TV_DUMP);
1541 && graph_dump_format != no_graph
1542 && dump_file[index].graph_dump_p)
1547 sprintf (seq, DUMPFILE_FORMAT, index);
1548 suffix = concat (seq, dump_file[index].extension, NULL);
1549 print_rtl_graph_with_bb (dump_base_name, suffix, insns);
1554 func (rtl_dump_file, insns);
1556 fflush (rtl_dump_file);
1557 fclose (rtl_dump_file);
1559 rtl_dump_file = NULL;
1560 timevar_pop (TV_DUMP);
1563 /* Do any final processing required for the declarations in VEC, of
1564 which there are LEN. We write out inline functions and variables
1565 that have been deferred until this point, but which are required.
1566 Returns nonzero if anything was put out. */
1569 wrapup_global_declarations (tree *vec, int len)
1574 int output_something = 0;
1576 for (i = 0; i < len; i++)
1580 /* We're not deferring this any longer. Assignment is
1581 conditional to avoid needlessly dirtying PCH pages. */
1582 if (DECL_DEFER_OUTPUT (decl) != 0)
1583 DECL_DEFER_OUTPUT (decl) = 0;
1585 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
1586 (*lang_hooks.finish_incomplete_decl) (decl);
1589 /* Now emit any global variables or functions that we have been
1590 putting off. We need to loop in case one of the things emitted
1591 here references another one which comes earlier in the list. */
1595 for (i = 0; i < len; i++)
1599 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
1602 /* Don't write out static consts, unless we still need them.
1604 We also keep static consts if not optimizing (for debugging),
1605 unless the user specified -fno-keep-static-consts.
1606 ??? They might be better written into the debug information.
1607 This is possible when using DWARF.
1609 A language processor that wants static constants to be always
1610 written out (even if it is not used) is responsible for
1611 calling rest_of_decl_compilation itself. E.g. the C front-end
1612 calls rest_of_decl_compilation from finish_decl.
1613 One motivation for this is that is conventional in some
1614 environments to write things like:
1615 static const char rcsid[] = "... version string ...";
1616 intending to force the string to be in the executable.
1618 A language processor that would prefer to have unneeded
1619 static constants "optimized away" would just defer writing
1620 them out until here. E.g. C++ does this, because static
1621 constants are often defined in header files.
1623 ??? A tempting alternative (for both C and C++) would be
1624 to force a constant to be written if and only if it is
1625 defined in a main file, as opposed to an include file. */
1627 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
1631 if (flag_unit_at_a_time
1632 && cgraph_varpool_node (decl)->finalized)
1634 else if ((flag_unit_at_a_time && !cgraph_global_info_ready)
1635 && (TREE_USED (decl)
1636 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
1638 else if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1640 else if (DECL_COMDAT (decl))
1642 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
1643 && (optimize || !flag_keep_static_consts
1644 || DECL_ARTIFICIAL (decl)))
1650 rest_of_decl_compilation (decl, NULL, 1, 1);
1654 if (TREE_CODE (decl) == FUNCTION_DECL
1655 && DECL_INITIAL (decl) != 0
1656 && DECL_STRUCT_FUNCTION (decl) != 0
1657 && DECL_STRUCT_FUNCTION (decl)->saved_for_inline
1658 && (flag_keep_inline_functions
1659 || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
1660 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
1663 output_inline_function (decl);
1668 output_something = 1;
1672 return output_something;
1675 /* Issue appropriate warnings for the global declarations in VEC (of
1676 which there are LEN). Output debugging information for them. */
1679 check_global_declarations (tree *vec, int len)
1684 for (i = 0; i < len; i++)
1688 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
1689 && ! TREE_ASM_WRITTEN (decl))
1690 /* Cancel the RTL for this decl so that, if debugging info
1691 output for global variables is still to come,
1692 this one will be omitted. */
1693 SET_DECL_RTL (decl, NULL_RTX);
1695 /* Warn about any function
1696 declared static but not defined.
1697 We don't warn about variables,
1698 because many programs have static variables
1699 that exist only to get some text into the object file. */
1700 if (TREE_CODE (decl) == FUNCTION_DECL
1701 && (warn_unused_function
1702 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1703 && DECL_INITIAL (decl) == 0
1704 && DECL_EXTERNAL (decl)
1705 && ! DECL_ARTIFICIAL (decl)
1706 && ! TREE_PUBLIC (decl))
1708 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1709 pedwarn ("%J'%F' used but never defined", decl, decl);
1711 warning ("%J'%F' declared `static' but never defined", decl, decl);
1712 /* This symbol is effectively an "extern" declaration now. */
1713 TREE_PUBLIC (decl) = 1;
1714 assemble_external (decl);
1717 /* Warn about static fns or vars defined but not used. */
1718 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
1719 /* We don't warn about "static const" variables because the
1720 "rcs_id" idiom uses that construction. */
1721 || (warn_unused_variable
1722 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
1723 && ! DECL_IN_SYSTEM_HEADER (decl)
1724 && ! TREE_USED (decl)
1725 /* The TREE_USED bit for file-scope decls is kept in the identifier,
1726 to handle multiple external decls in different scopes. */
1727 && ! TREE_USED (DECL_NAME (decl))
1728 && ! DECL_EXTERNAL (decl)
1729 && ! TREE_PUBLIC (decl)
1730 /* A volatile variable might be used in some non-obvious way. */
1731 && ! TREE_THIS_VOLATILE (decl)
1732 /* Global register variables must be declared to reserve them. */
1733 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
1734 /* Otherwise, ask the language. */
1735 && (*lang_hooks.decls.warn_unused_global) (decl))
1736 warning ("%J'%D' defined but not used", decl, decl);
1738 /* Avoid confusing the debug information machinery when there are
1740 if (errorcount == 0 && sorrycount == 0)
1742 timevar_push (TV_SYMOUT);
1743 (*debug_hooks->global_decl) (decl);
1744 timevar_pop (TV_SYMOUT);
1749 /* Warn about a use of an identifier which was marked deprecated. */
1751 warn_deprecated_use (tree node)
1753 if (node == 0 || !warn_deprecated_decl)
1757 warning ("`%s' is deprecated (declared at %s:%d)",
1758 IDENTIFIER_POINTER (DECL_NAME (node)),
1759 DECL_SOURCE_FILE (node), DECL_SOURCE_LINE (node));
1760 else if (TYPE_P (node))
1762 const char *what = NULL;
1763 tree decl = TYPE_STUB_DECL (node);
1765 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
1766 what = IDENTIFIER_POINTER (TYPE_NAME (node));
1767 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
1768 && DECL_NAME (TYPE_NAME (node)))
1769 what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
1774 warning ("`%s' is deprecated (declared at %s:%d)", what,
1775 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1777 warning ("`%s' is deprecated", what);
1780 warning ("type is deprecated (declared at %s:%d)",
1781 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1783 warning ("type is deprecated");
1787 /* Save the current INPUT_LOCATION on the top entry in the
1788 INPUT_FILE_STACK. Push a new entry for FILE and LINE, and set the
1789 INPUT_LOCATION accordingly. */
1792 push_srcloc (const char *file, int line)
1794 struct file_stack *fs;
1796 fs = xmalloc (sizeof (struct file_stack));
1797 fs->location = input_location;
1798 fs->next = input_file_stack;
1799 input_filename = file;
1801 input_file_stack = fs;
1802 input_file_stack_tick++;
1805 /* Pop the top entry off the stack of presently open source files.
1806 Restore the INPUT_LOCATION from the new topmost entry on the
1812 struct file_stack *fs;
1814 fs = input_file_stack;
1815 input_location = fs->location;
1816 input_file_stack = fs->next;
1818 input_file_stack_tick++;
1821 /* Compile an entire translation unit. Write a file of assembly
1822 output and various debugging dumps. */
1827 /* Initialize yet another pass. */
1829 init_final (main_input_filename);
1830 coverage_init (aux_base_name);
1832 timevar_push (TV_PARSE);
1834 /* Call the parser, which parses the entire file (calling
1835 rest_of_compilation for each function). */
1836 (*lang_hooks.parse_file) (set_yydebug);
1838 /* In case there were missing block closers,
1839 get us back to the global binding level. */
1840 (*lang_hooks.clear_binding_stack) ();
1842 /* Compilation is now finished except for writing
1843 what's left of the symbol table output. */
1844 timevar_pop (TV_PARSE);
1846 if (flag_syntax_only)
1849 (*lang_hooks.decls.final_write_globals)();
1851 cgraph_varpool_assemble_pending_decls ();
1853 /* This must occur after the loop to output deferred functions.
1854 Else the coverage initializer would not be emitted if all the
1855 functions in this compilation unit were deferred. */
1858 /* Write out any pending weak symbol declarations. */
1862 /* Do dbx symbols. */
1863 timevar_push (TV_SYMOUT);
1865 #ifdef DWARF2_UNWIND_INFO
1866 if (dwarf2out_do_frame ())
1867 dwarf2out_frame_finish ();
1870 (*debug_hooks->finish) (main_input_filename);
1871 timevar_pop (TV_SYMOUT);
1873 /* Output some stuff at end of file if nec. */
1875 dw2_output_indirect_constants ();
1877 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
1879 timevar_push (TV_DUMP);
1880 open_dump_file (DFI_bp, NULL);
1884 close_dump_file (DFI_bp, NULL, NULL_RTX);
1885 timevar_pop (TV_DUMP);
1888 targetm.asm_out.file_end ();
1890 /* Attach a special .ident directive to the end of the file to identify
1891 the version of GCC which compiled this code. The format of the .ident
1892 string is patterned after the ones produced by native SVR4 compilers. */
1895 fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
1896 IDENT_ASM_OP, version_string);
1899 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
1901 timevar_push (TV_DUMP);
1902 dump_combine_total_stats (rtl_dump_file);
1903 close_dump_file (DFI_combine, NULL, NULL_RTX);
1904 timevar_pop (TV_DUMP);
1908 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
1909 and TYPE_DECL nodes.
1911 This does nothing for local (non-static) variables, unless the
1912 variable is a register variable with an ASMSPEC. In that case, or
1913 if the variable is not an automatic, it sets up the RTL and
1914 outputs any assembler code (label definition, storage allocation
1915 and initialization).
1917 DECL is the declaration. If ASMSPEC is nonzero, it specifies
1918 the assembler symbol name to be used. TOP_LEVEL is nonzero
1919 if this declaration is not within a function. */
1922 rest_of_decl_compilation (tree decl,
1923 const char *asmspec,
1927 /* We deferred calling assemble_alias so that we could collect
1928 other attributes such as visibility. Emit the alias now. */
1931 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
1934 alias = TREE_VALUE (TREE_VALUE (alias));
1935 alias = get_identifier (TREE_STRING_POINTER (alias));
1936 assemble_alias (decl, alias);
1940 /* Forward declarations for nested functions are not "external",
1941 but we need to treat them as if they were. */
1942 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
1943 || TREE_CODE (decl) == FUNCTION_DECL)
1945 timevar_push (TV_VARCONST);
1948 make_decl_rtl (decl, asmspec);
1950 /* Don't output anything when a tentative file-scope definition
1951 is seen. But at end of compilation, do output code for them.
1953 We do output all variables when unit-at-a-time is active and rely on
1954 callgraph code to defer them except for forward declarations
1955 (see gcc.c-torture/compile/920624-1.c) */
1957 || !DECL_DEFER_OUTPUT (decl)
1958 || (flag_unit_at_a_time && DECL_INITIAL (decl)))
1959 && !DECL_EXTERNAL (decl))
1961 if (flag_unit_at_a_time && !cgraph_global_info_ready
1962 && TREE_CODE (decl) != FUNCTION_DECL && top_level)
1963 cgraph_varpool_finalize_decl (decl);
1965 assemble_variable (decl, top_level, at_end, 0);
1968 #ifdef ASM_FINISH_DECLARE_OBJECT
1969 if (decl == last_assemble_variable_decl)
1971 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
1976 timevar_pop (TV_VARCONST);
1978 else if (DECL_REGISTER (decl) && asmspec != 0)
1980 if (decode_reg_name (asmspec) >= 0)
1982 SET_DECL_RTL (decl, NULL_RTX);
1983 make_decl_rtl (decl, asmspec);
1987 error ("invalid register name `%s' for register variable", asmspec);
1988 DECL_REGISTER (decl) = 0;
1993 else if (TREE_CODE (decl) == TYPE_DECL)
1995 timevar_push (TV_SYMOUT);
1996 debug_hooks->type_decl (decl, !top_level);
1997 timevar_pop (TV_SYMOUT);
2001 /* Called after finishing a record, union or enumeral type. */
2004 rest_of_type_compilation (tree type, int toplev)
2006 /* Avoid confusing the debug information machinery when there are
2008 if (errorcount != 0 || sorrycount != 0)
2011 timevar_push (TV_SYMOUT);
2012 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
2013 timevar_pop (TV_SYMOUT);
2016 /* Turn the RTL into assembly. */
2018 rest_of_handle_final (tree decl, rtx insns)
2020 timevar_push (TV_FINAL);
2025 /* Get the function's name, as described by its RTL. This may be
2026 different from the DECL_NAME name used in the source file. */
2028 x = DECL_RTL (decl);
2029 if (GET_CODE (x) != MEM)
2032 if (GET_CODE (x) != SYMBOL_REF)
2034 fnname = XSTR (x, 0);
2036 assemble_start_function (decl, fnname);
2037 final_start_function (insns, asm_out_file, optimize);
2038 final (insns, asm_out_file, optimize, 0);
2039 final_end_function ();
2041 #ifdef IA64_UNWIND_INFO
2042 /* ??? The IA-64 ".handlerdata" directive must be issued before
2043 the ".endp" directive that closes the procedure descriptor. */
2044 output_function_exception_table ();
2047 assemble_end_function (decl, fnname);
2049 #ifndef IA64_UNWIND_INFO
2050 /* Otherwise, it feels unclean to switch sections in the middle. */
2051 output_function_exception_table ();
2055 fflush (asm_out_file);
2057 /* Release all memory allocated by flow. */
2058 free_basic_block_vars (0);
2060 /* Release all memory held by regsets now. */
2061 regset_release_memory ();
2063 timevar_pop (TV_FINAL);
2069 /* Run delay slot optimization. */
2071 rest_of_handle_delay_slots (tree decl, rtx insns)
2073 timevar_push (TV_DBR_SCHED);
2074 open_dump_file (DFI_dbr, decl);
2076 dbr_schedule (insns, rtl_dump_file);
2078 close_dump_file (DFI_dbr, print_rtl, insns);
2079 timevar_pop (TV_DBR_SCHED);
2086 /* Convert register usage from flat register file usage to a stack
2089 rest_of_handle_stack_regs (tree decl, rtx insns)
2091 #if defined (HAVE_ATTR_length)
2092 /* If flow2 creates new instructions which need splitting
2093 and scheduling after reload is not done, they might not be
2094 split until final which doesn't allow splitting
2095 if HAVE_ATTR_length. */
2096 #ifdef INSN_SCHEDULING
2097 if (optimize && !flag_schedule_insns_after_reload)
2102 timevar_push (TV_SHORTEN_BRANCH);
2103 split_all_insns (1);
2104 timevar_pop (TV_SHORTEN_BRANCH);
2108 timevar_push (TV_REG_STACK);
2109 open_dump_file (DFI_stack, decl);
2111 if (reg_to_stack (insns, rtl_dump_file) && optimize)
2113 if (cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
2114 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0))
2115 && flag_reorder_blocks)
2117 reorder_basic_blocks ();
2118 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
2122 close_dump_file (DFI_stack, print_rtl_with_bb, insns);
2123 timevar_pop (TV_REG_STACK);
2129 /* Track the variables, ie. compute where the variable is stored at each position in function. */
2131 rest_of_handle_variable_tracking (tree decl, rtx insns)
2133 timevar_push (TV_VAR_TRACKING);
2134 open_dump_file (DFI_vartrack, decl);
2136 variable_tracking_main ();
2138 close_dump_file (DFI_vartrack, print_rtl_with_bb, insns);
2139 timevar_pop (TV_VAR_TRACKING);
2142 /* Machine independent reorg pass. */
2144 rest_of_handle_machine_reorg (tree decl, rtx insns)
2146 timevar_push (TV_MACH_DEP);
2147 open_dump_file (DFI_mach, decl);
2149 (*targetm.machine_dependent_reorg) ();
2151 close_dump_file (DFI_mach, print_rtl, insns);
2152 timevar_pop (TV_MACH_DEP);
2158 /* Run new register allocator. Return TRUE if we must exit
2159 rest_of_compilation upon return. */
2161 rest_of_handle_new_regalloc (tree decl, rtx insns)
2165 delete_trivially_dead_insns (insns, max_reg_num ());
2168 timevar_pop (TV_LOCAL_ALLOC);
2169 if (dump_file[DFI_lreg].enabled)
2171 timevar_push (TV_DUMP);
2173 close_dump_file (DFI_lreg, NULL, NULL);
2174 timevar_pop (TV_DUMP);
2177 /* XXX clean up the whole mess to bring live info in shape again. */
2178 timevar_push (TV_GLOBAL_ALLOC);
2179 open_dump_file (DFI_greg, decl);
2181 build_insn_chain (insns);
2182 failure = reload (insns, 0);
2184 timevar_pop (TV_GLOBAL_ALLOC);
2186 if (dump_file[DFI_greg].enabled)
2188 timevar_push (TV_DUMP);
2190 dump_global_regs (rtl_dump_file);
2192 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2193 timevar_pop (TV_DUMP);
2199 reload_completed = 1;
2204 /* Run old register allocator. Return TRUE if we must exit
2205 rest_of_compilation upon return. */
2207 rest_of_handle_old_regalloc (tree decl, rtx insns)
2212 /* Allocate the reg_renumber array. */
2213 allocate_reg_info (max_regno, FALSE, TRUE);
2215 /* And the reg_equiv_memory_loc array. */
2216 reg_equiv_memory_loc = xcalloc (max_regno, sizeof (rtx));
2218 allocate_initial_values (reg_equiv_memory_loc);
2220 regclass (insns, max_reg_num (), rtl_dump_file);
2221 rebuild_notes = local_alloc ();
2223 timevar_pop (TV_LOCAL_ALLOC);
2225 /* Local allocation may have turned an indirect jump into a direct
2226 jump. If so, we must rebuild the JUMP_LABEL fields of jumping
2230 timevar_push (TV_JUMP);
2232 rebuild_jump_labels (insns);
2233 purge_all_dead_edges (0);
2235 timevar_pop (TV_JUMP);
2238 if (dump_file[DFI_lreg].enabled)
2240 timevar_push (TV_DUMP);
2242 dump_flow_info (rtl_dump_file);
2243 dump_local_alloc (rtl_dump_file);
2245 close_dump_file (DFI_lreg, print_rtl_with_bb, insns);
2246 timevar_pop (TV_DUMP);
2251 timevar_push (TV_GLOBAL_ALLOC);
2252 open_dump_file (DFI_greg, decl);
2254 /* If optimizing, allocate remaining pseudo-regs. Do the reload
2255 pass fixing up any insns that are invalid. */
2258 failure = global_alloc (rtl_dump_file);
2261 build_insn_chain (insns);
2262 failure = reload (insns, 0);
2265 timevar_pop (TV_GLOBAL_ALLOC);
2267 if (dump_file[DFI_greg].enabled)
2269 timevar_push (TV_DUMP);
2271 dump_global_regs (rtl_dump_file);
2273 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2274 timevar_pop (TV_DUMP);
2280 /* Run the regrename and cprop passes. */
2282 rest_of_handle_regrename (tree decl, rtx insns)
2284 timevar_push (TV_RENAME_REGISTERS);
2285 open_dump_file (DFI_rnreg, decl);
2287 if (flag_rename_registers)
2288 regrename_optimize ();
2289 if (flag_cprop_registers)
2290 copyprop_hardreg_forward ();
2292 close_dump_file (DFI_rnreg, print_rtl_with_bb, insns);
2293 timevar_pop (TV_RENAME_REGISTERS);
2296 /* Reorder basic blocks. */
2298 rest_of_handle_reorder_blocks (tree decl, rtx insns)
2301 open_dump_file (DFI_bbro, decl);
2303 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
2304 splitting possibly introduced more crossjumping opportunities. */
2305 changed = cleanup_cfg (CLEANUP_EXPENSIVE
2306 | (!HAVE_conditional_execution
2307 ? CLEANUP_UPDATE_LIFE : 0));
2309 if (flag_sched2_use_traces && flag_schedule_insns_after_reload)
2311 if (flag_reorder_blocks)
2312 reorder_basic_blocks ();
2313 if (flag_reorder_blocks
2314 || (flag_sched2_use_traces && flag_schedule_insns_after_reload))
2315 changed |= cleanup_cfg (CLEANUP_EXPENSIVE
2316 | (!HAVE_conditional_execution
2317 ? CLEANUP_UPDATE_LIFE : 0));
2319 /* On conditional execution targets we can not update the life cheaply, so
2320 we deffer the updating to after both cleanups. This may lose some cases
2321 but should not be terribly bad. */
2322 if (changed && HAVE_conditional_execution)
2323 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
2325 close_dump_file (DFI_bbro, print_rtl_with_bb, insns);
2328 #ifdef INSN_SCHEDULING
2329 /* Run instruction scheduler. */
2331 rest_of_handle_sched (tree decl, rtx insns)
2333 timevar_push (TV_SCHED);
2335 /* Print function header into sched dump now
2336 because doing the sched analysis makes some of the dump. */
2337 if (optimize > 0 && flag_schedule_insns)
2339 open_dump_file (DFI_sched, decl);
2341 /* Do control and data sched analysis,
2342 and write some of the results to dump file. */
2344 schedule_insns (rtl_dump_file);
2346 close_dump_file (DFI_sched, print_rtl_with_bb, insns);
2348 timevar_pop (TV_SCHED);
2353 /* Run second scheduling pass after reload. */
2355 rest_of_handle_sched2 (tree decl, rtx insns)
2357 timevar_push (TV_SCHED2);
2358 open_dump_file (DFI_sched2, decl);
2360 /* Do control and data sched analysis again,
2361 and write some more of the results to dump file. */
2363 split_all_insns (1);
2365 if (flag_sched2_use_superblocks || flag_sched2_use_traces)
2367 schedule_ebbs (rtl_dump_file);
2368 /* No liveness updating code yet, but it should be easy to do.
2369 reg-stack recompute the liveness when needed for now. */
2370 count_or_remove_death_notes (NULL, 1);
2371 cleanup_cfg (CLEANUP_EXPENSIVE);
2374 schedule_insns (rtl_dump_file);
2376 close_dump_file (DFI_sched2, print_rtl_with_bb, insns);
2377 timevar_pop (TV_SCHED2);
2383 /* Register allocation pre-pass, to reduce number of moves necessary
2384 for two-address machines. */
2386 rest_of_handle_regmove (tree decl, rtx insns)
2388 timevar_push (TV_REGMOVE);
2389 open_dump_file (DFI_regmove, decl);
2391 regmove_optimize (insns, max_reg_num (), rtl_dump_file);
2393 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2394 close_dump_file (DFI_regmove, print_rtl_with_bb, insns);
2395 timevar_pop (TV_REGMOVE);
2402 rest_of_handle_tracer (tree decl, rtx insns)
2404 open_dump_file (DFI_tracer, decl);
2406 dump_flow_info (rtl_dump_file);
2408 cleanup_cfg (CLEANUP_EXPENSIVE);
2409 reg_scan (insns, max_reg_num (), 0);
2410 close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ());
2413 /* If-conversion and CFG cleanup. */
2415 rest_of_handle_if_conversion (tree decl, rtx insns)
2417 open_dump_file (DFI_ce1, decl);
2418 if (flag_if_conversion)
2420 timevar_push (TV_IFCVT);
2422 dump_flow_info (rtl_dump_file);
2423 cleanup_cfg (CLEANUP_EXPENSIVE);
2424 reg_scan (insns, max_reg_num (), 0);
2426 timevar_pop (TV_IFCVT);
2428 timevar_push (TV_JUMP);
2429 cleanup_cfg (CLEANUP_EXPENSIVE);
2430 reg_scan (insns, max_reg_num (), 0);
2431 timevar_pop (TV_JUMP);
2432 close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ());
2435 /* Rerun if-conversion, as combine may have simplified things enough
2436 to now meet sequence length restrictions. */
2438 rest_of_handle_if_after_combine (tree decl, rtx insns)
2440 timevar_push (TV_IFCVT);
2441 open_dump_file (DFI_ce2, decl);
2447 close_dump_file (DFI_ce2, print_rtl_with_bb, insns);
2448 timevar_pop (TV_IFCVT);
2452 rest_of_handle_web (tree decl, rtx insns)
2454 open_dump_file (DFI_web, decl);
2455 timevar_push (TV_WEB);
2457 delete_trivially_dead_insns (insns, max_reg_num ());
2458 cleanup_cfg (CLEANUP_EXPENSIVE);
2460 timevar_pop (TV_WEB);
2461 close_dump_file (DFI_web, print_rtl_with_bb, insns);
2462 reg_scan (get_insns (), max_reg_num (), 0);
2465 /* Do branch profiling and static profile estimation passes. */
2467 rest_of_handle_branch_prob (tree decl, rtx insns)
2471 timevar_push (TV_BRANCH_PROB);
2472 open_dump_file (DFI_bp, decl);
2474 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
2477 /* Discover and record the loop depth at the head of each basic
2478 block. The loop infrastructure does the real job for us. */
2479 flow_loops_find (&loops, LOOP_TREE);
2482 flow_loops_dump (&loops, rtl_dump_file, NULL, 0);
2484 /* Estimate using heuristics if no profiling info is available. */
2485 if (flag_guess_branch_prob)
2486 estimate_probability (&loops);
2488 flow_loops_free (&loops);
2489 free_dominance_info (CDI_DOMINATORS);
2490 close_dump_file (DFI_bp, print_rtl_with_bb, insns);
2491 timevar_pop (TV_BRANCH_PROB);
2494 /* Do optimizations based on expression value profiles. */
2496 rest_of_handle_value_profile_transformations (tree decl, rtx insns)
2498 open_dump_file (DFI_vpt, decl);
2499 timevar_push (TV_VPT);
2501 if (value_profile_transformations ())
2502 cleanup_cfg (CLEANUP_EXPENSIVE);
2504 timevar_pop (TV_VPT);
2505 close_dump_file (DFI_vpt, print_rtl_with_bb, insns);
2508 /* Do control and data flow analysis; write some of the results to the
2511 rest_of_handle_cfg (tree decl, rtx insns)
2513 open_dump_file (DFI_cfg, decl);
2515 dump_flow_info (rtl_dump_file);
2517 cleanup_cfg (CLEANUP_EXPENSIVE
2518 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2520 /* It may make more sense to mark constant functions after dead code is
2521 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
2522 may insert code making function non-constant, but we still must consider
2523 it as constant, otherwise -fbranch-probabilities will not read data back.
2525 life_analysis rarely eliminates modification of external memory.
2529 /* Alias analysis depends on this information and mark_constant_function
2530 depends on alias analysis. */
2531 reg_scan (insns, max_reg_num (), 1);
2532 mark_constant_function ();
2535 close_dump_file (DFI_cfg, print_rtl_with_bb, insns);
2538 /* Purge addressofs. */
2540 rest_of_handle_addressof (tree decl, rtx insns)
2542 open_dump_file (DFI_addressof, decl);
2544 purge_addressof (insns);
2545 if (optimize && purge_all_dead_edges (0))
2546 delete_unreachable_blocks ();
2547 reg_scan (insns, max_reg_num (), 1);
2549 close_dump_file (DFI_addressof, print_rtl, insns);
2552 /* We may have potential sibling or tail recursion sites. Select one
2553 (of possibly multiple) methods of performing the call. */
2555 rest_of_handle_sibling_calls (rtx insns)
2558 optimize_sibling_and_tail_recursive_calls ();
2560 /* Recompute the CFG as sibling optimization clobbers it randomly. */
2561 free_bb_for_insn ();
2562 find_exception_handler_labels ();
2563 rebuild_jump_labels (insns);
2564 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2566 /* There is pass ordering problem - we must lower NOTE_INSN_PREDICTION
2567 notes before simplifying cfg and we must do lowering after sibcall
2568 that unhides parts of RTL chain and cleans up the CFG.
2570 Until sibcall is replaced by tree-level optimizer, lets just
2571 sweep away the NOTE_INSN_PREDICTION notes that leaked out. */
2572 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2573 if (GET_CODE (insn) == NOTE
2574 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_PREDICTION)
2577 close_dump_file (DFI_sibling, print_rtl, get_insns ());
2580 /* Perform jump bypassing and control flow optimizations. */
2582 rest_of_handle_jump_bypass (tree decl, rtx insns)
2584 timevar_push (TV_BYPASS);
2585 open_dump_file (DFI_bypass, decl);
2587 cleanup_cfg (CLEANUP_EXPENSIVE);
2588 reg_scan (insns, max_reg_num (), 1);
2590 if (bypass_jumps (rtl_dump_file))
2592 rebuild_jump_labels (insns);
2593 cleanup_cfg (CLEANUP_EXPENSIVE);
2594 delete_trivially_dead_insns (insns, max_reg_num ());
2597 close_dump_file (DFI_bypass, print_rtl_with_bb, insns);
2598 timevar_pop (TV_BYPASS);
2602 #ifdef ENABLE_CHECKING
2603 verify_flow_info ();
2607 /* Handle inlining of functions in rest_of_compilation. Return TRUE
2608 if we must exit rest_of_compilation upon return. */
2610 rest_of_handle_inlining (tree decl)
2617 /* If we are reconsidering an inline function at the end of
2618 compilation, skip the stuff for making it inline. */
2619 if (cfun->rtl_inline_init)
2621 cfun->rtl_inline_init = 1;
2623 /* If this is nested inside an inlined external function, pretend
2624 it was only declared. Since we cannot inline such functions,
2625 generating code for this one is not only not necessary but will
2626 confuse some debugging output writers. */
2627 for (parent = DECL_CONTEXT (current_function_decl);
2628 parent != NULL_TREE;
2629 parent = get_containing_scope (parent))
2630 if (TREE_CODE (parent) == FUNCTION_DECL
2631 && DECL_INLINE (parent) && DECL_EXTERNAL (parent))
2633 DECL_INITIAL (decl) = 0;
2636 else if (TYPE_P (parent))
2637 /* A function in a local class should be treated normally. */
2640 /* If requested, consider whether to make this function inline. */
2641 if ((DECL_INLINE (decl) && !flag_no_inline)
2642 || flag_inline_functions)
2644 timevar_push (TV_INTEGRATION);
2645 lose = function_cannot_inline_p (decl);
2646 timevar_pop (TV_INTEGRATION);
2647 if (lose || ! optimize)
2649 if (warn_inline && lose && DECL_INLINE (decl))
2651 char *msg = concat ("%J", lose, NULL);
2652 warning (msg, decl);
2655 DECL_ABSTRACT_ORIGIN (decl) = 0;
2656 /* Don't really compile an extern inline function.
2657 If we can't make it inline, pretend
2658 it was only declared. */
2659 if (DECL_EXTERNAL (decl))
2661 DECL_INITIAL (decl) = 0;
2666 inlinable = DECL_INLINE (decl) = 1;
2669 insns = get_insns ();
2671 /* Dump the rtl code if we are dumping rtl. */
2673 if (open_dump_file (DFI_rtl, decl))
2675 if (DECL_STRUCT_FUNCTION (decl)
2676 && DECL_STRUCT_FUNCTION (decl)->saved_for_inline)
2677 fprintf (rtl_dump_file, ";; (integrable)\n\n");
2678 close_dump_file (DFI_rtl, print_rtl, insns);
2681 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
2682 sorts of eh initialization. Delay this until after the
2683 initial rtl dump so that we can see the original nesting. */
2684 convert_from_eh_region_ranges ();
2686 /* If function is inline, and we don't yet know whether to
2687 compile it by itself, defer decision till end of compilation.
2688 wrapup_global_declarations will (indirectly) call
2689 rest_of_compilation again for those functions that need to
2690 be output. Also defer those functions that we are supposed
2694 || (DECL_INLINE (decl)
2695 /* Egad. This RTL deferral test conflicts with Fortran assumptions
2696 for unreferenced symbols. See g77.f-torture/execute/980520-1.f.
2697 But removing this line from the check breaks all languages that
2698 use the call graph to output symbols. This hard-coded check is
2699 the least invasive work-around. */
2700 && (flag_inline_functions
2701 || strcmp (lang_hooks.name, "GNU F77") == 0)
2702 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2703 && ! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
2704 && ! flag_keep_inline_functions)
2705 || DECL_EXTERNAL (decl))))
2706 DECL_DEFER_OUTPUT (decl) = 1;
2708 if (DECL_INLINE (decl))
2709 /* DWARF wants separate debugging info for abstract and
2710 concrete instances of all inline functions, including those
2711 declared inline but not inlined, and those inlined even
2712 though they weren't declared inline. Conveniently, that's
2713 what DECL_INLINE means at this point. */
2714 (*debug_hooks->deferred_inline_function) (decl);
2716 if (DECL_DEFER_OUTPUT (decl))
2718 /* If -Wreturn-type, we have to do a bit of compilation. We just
2719 want to call cleanup the cfg to figure out whether or not we can
2720 fall off the end of the function; we do the minimum amount of
2721 work necessary to make that safe. */
2722 if (warn_return_type)
2724 int saved_optimize = optimize;
2727 rebuild_jump_labels (insns);
2728 find_exception_handler_labels ();
2729 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2730 cleanup_cfg (CLEANUP_PRE_SIBCALL | CLEANUP_PRE_LOOP);
2731 optimize = saved_optimize;
2733 /* CFG is no longer maintained up-to-date. */
2734 free_bb_for_insn ();
2737 set_nothrow_function_flags ();
2738 if (current_function_nothrow)
2739 /* Now we know that this can't throw; set the flag for the benefit
2740 of other functions later in this translation unit. */
2741 TREE_NOTHROW (current_function_decl) = 1;
2743 timevar_push (TV_INTEGRATION);
2744 save_for_inline (decl);
2745 timevar_pop (TV_INTEGRATION);
2746 DECL_STRUCT_FUNCTION (decl)->inlinable = inlinable;
2750 /* If specified extern inline but we aren't inlining it, we are
2751 done. This goes for anything that gets here with DECL_EXTERNAL
2752 set, not just things with DECL_INLINE. */
2753 return (bool) DECL_EXTERNAL (decl);
2756 /* Try to identify useless null pointer tests and delete them. */
2758 rest_of_handle_null_pointer (tree decl, rtx insns)
2760 open_dump_file (DFI_null, decl);
2762 dump_flow_info (rtl_dump_file);
2764 if (delete_null_pointer_checks (insns))
2765 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2767 close_dump_file (DFI_null, print_rtl_with_bb, insns);
2770 /* Try combining insns through substitution. */
2772 rest_of_handle_combine (tree decl, rtx insns)
2774 int rebuild_jump_labels_after_combine = 0;
2776 timevar_push (TV_COMBINE);
2777 open_dump_file (DFI_combine, decl);
2779 rebuild_jump_labels_after_combine
2780 = combine_instructions (insns, max_reg_num ());
2782 /* Combining insns may have turned an indirect jump into a
2783 direct jump. Rebuild the JUMP_LABEL fields of jumping
2785 if (rebuild_jump_labels_after_combine)
2787 timevar_push (TV_JUMP);
2788 rebuild_jump_labels (insns);
2789 timevar_pop (TV_JUMP);
2791 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2794 close_dump_file (DFI_combine, print_rtl_with_bb, insns);
2795 timevar_pop (TV_COMBINE);
2800 /* Perform life analysis. */
2802 rest_of_handle_life (tree decl, rtx insns)
2804 open_dump_file (DFI_life, decl);
2807 #ifdef ENABLE_CHECKING
2808 verify_flow_info ();
2810 life_analysis (insns, rtl_dump_file, PROP_FINAL);
2812 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_UPDATE_LIFE
2814 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2815 timevar_pop (TV_FLOW);
2817 if (warn_uninitialized)
2819 uninitialized_vars_warning (DECL_INITIAL (decl));
2821 setjmp_args_warning ();
2826 if (!flag_new_regalloc && initialize_uninitialized_subregs ())
2828 /* Insns were inserted, and possibly pseudos created, so
2829 things might look a bit different. */
2830 insns = get_insns ();
2831 allocate_reg_life_data ();
2832 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
2833 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
2839 close_dump_file (DFI_life, print_rtl_with_bb, insns);
2844 /* Perform common subexpression elimination. Nonzero value from
2845 `cse_main' means that jumps were simplified and some code may now
2846 be unreachable, so do jump optimization again. */
2848 rest_of_handle_cse (tree decl, rtx insns)
2852 open_dump_file (DFI_cse, decl);
2854 dump_flow_info (rtl_dump_file);
2855 timevar_push (TV_CSE);
2857 reg_scan (insns, max_reg_num (), 1);
2859 tem = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2861 rebuild_jump_labels (insns);
2862 if (purge_all_dead_edges (0))
2863 delete_unreachable_blocks ();
2865 delete_trivially_dead_insns (insns, max_reg_num ());
2867 /* If we are not running more CSE passes, then we are no longer
2868 expecting CSE to be run. But always rerun it in a cheap mode. */
2869 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
2871 if (tem || optimize > 1)
2872 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2873 /* Try to identify useless null pointer tests and delete them. */
2874 if (flag_delete_null_pointer_checks)
2876 timevar_push (TV_JUMP);
2878 if (delete_null_pointer_checks (insns))
2879 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2880 timevar_pop (TV_JUMP);
2883 /* The second pass of jump optimization is likely to have
2884 removed a bunch more instructions. */
2885 renumber_insns (rtl_dump_file);
2887 timevar_pop (TV_CSE);
2888 close_dump_file (DFI_cse, print_rtl_with_bb, insns);
2891 /* Run second CSE pass after loop optimizations. */
2893 rest_of_handle_cse2 (tree decl, rtx insns)
2897 timevar_push (TV_CSE2);
2898 open_dump_file (DFI_cse2, decl);
2900 dump_flow_info (rtl_dump_file);
2901 /* CFG is no longer maintained up-to-date. */
2902 tem = cse_main (insns, max_reg_num (), 1, rtl_dump_file);
2904 /* Run a pass to eliminate duplicated assignments to condition code
2905 registers. We have to run this after bypass_jumps, because it
2906 makes it harder for that pass to determine whether a jump can be
2908 cse_condition_code_reg ();
2910 purge_all_dead_edges (0);
2911 delete_trivially_dead_insns (insns, max_reg_num ());
2915 timevar_push (TV_JUMP);
2916 rebuild_jump_labels (insns);
2917 cleanup_cfg (CLEANUP_EXPENSIVE);
2918 timevar_pop (TV_JUMP);
2920 reg_scan (insns, max_reg_num (), 0);
2921 close_dump_file (DFI_cse2, print_rtl_with_bb, insns);
2923 timevar_pop (TV_CSE2);
2926 /* Perform global cse. */
2928 rest_of_handle_gcse (tree decl, rtx insns)
2930 int save_csb, save_cfj;
2933 timevar_push (TV_GCSE);
2934 open_dump_file (DFI_gcse, decl);
2936 tem = gcse_main (insns, rtl_dump_file);
2937 rebuild_jump_labels (insns);
2938 delete_trivially_dead_insns (insns, max_reg_num ());
2940 save_csb = flag_cse_skip_blocks;
2941 save_cfj = flag_cse_follow_jumps;
2942 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
2944 /* Instantiate any remaining CONSTANT_P_RTX nodes. */
2945 if (current_function_calls_constant_p)
2946 purge_builtin_constant_p ();
2948 /* If -fexpensive-optimizations, re-run CSE to clean up things done
2950 if (flag_expensive_optimizations)
2952 timevar_push (TV_CSE);
2953 reg_scan (insns, max_reg_num (), 1);
2954 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2955 purge_all_dead_edges (0);
2956 delete_trivially_dead_insns (insns, max_reg_num ());
2957 timevar_pop (TV_CSE);
2958 cse_not_expected = !flag_rerun_cse_after_loop;
2961 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
2962 things up. Then possibly re-run CSE again. */
2966 timevar_push (TV_JUMP);
2967 rebuild_jump_labels (insns);
2968 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2969 timevar_pop (TV_JUMP);
2971 if (flag_expensive_optimizations)
2973 timevar_push (TV_CSE);
2974 reg_scan (insns, max_reg_num (), 1);
2975 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2976 purge_all_dead_edges (0);
2977 delete_trivially_dead_insns (insns, max_reg_num ());
2978 timevar_pop (TV_CSE);
2982 close_dump_file (DFI_gcse, print_rtl_with_bb, insns);
2983 timevar_pop (TV_GCSE);
2986 flag_cse_skip_blocks = save_csb;
2987 flag_cse_follow_jumps = save_cfj;
2988 #ifdef ENABLE_CHECKING
2989 verify_flow_info ();
2993 /* Move constant computations out of loops. */
2995 rest_of_handle_loop_optimize (tree decl, rtx insns)
2997 int do_unroll, do_prefetch;
2999 timevar_push (TV_LOOP);
3000 delete_dead_jumptables ();
3001 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3002 open_dump_file (DFI_loop, decl);
3004 /* CFG is no longer maintained up-to-date. */
3005 free_bb_for_insn ();
3007 if (flag_unroll_loops)
3008 do_unroll = LOOP_AUTO_UNROLL; /* Having two unrollers is useless. */
3010 do_unroll = flag_old_unroll_loops ? LOOP_UNROLL : LOOP_AUTO_UNROLL;
3011 do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
3013 if (flag_rerun_loop_opt)
3015 cleanup_barriers ();
3017 /* We only want to perform unrolling once. */
3018 loop_optimize (insns, rtl_dump_file, do_unroll);
3021 /* The first call to loop_optimize makes some instructions
3022 trivially dead. We delete those instructions now in the
3023 hope that doing so will make the heuristics in loop work
3024 better and possibly speed up compilation. */
3025 delete_trivially_dead_insns (insns, max_reg_num ());
3027 /* The regscan pass is currently necessary as the alias
3028 analysis code depends on this information. */
3029 reg_scan (insns, max_reg_num (), 1);
3031 cleanup_barriers ();
3032 loop_optimize (insns, rtl_dump_file, do_unroll | LOOP_BCT | do_prefetch);
3034 /* Loop can create trivially dead instructions. */
3035 delete_trivially_dead_insns (insns, max_reg_num ());
3036 close_dump_file (DFI_loop, print_rtl, insns);
3037 timevar_pop (TV_LOOP);
3038 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3043 /* Perform loop optimizations. It might be better to do them a bit
3044 sooner, but we want the profile feedback to work more
3047 rest_of_handle_loop2 (tree decl, rtx insns)
3049 struct loops *loops;
3052 timevar_push (TV_LOOP);
3053 open_dump_file (DFI_loop2, decl);
3055 dump_flow_info (rtl_dump_file);
3057 /* Initialize structures for layout changes. */
3058 cfg_layout_initialize ();
3060 loops = loop_optimizer_init (rtl_dump_file);
3064 /* The optimizations: */
3065 if (flag_unswitch_loops)
3066 unswitch_loops (loops);
3068 if (flag_peel_loops || flag_unroll_loops)
3069 unroll_and_peel_loops (loops,
3070 (flag_peel_loops ? UAP_PEEL : 0) |
3071 (flag_unroll_loops ? UAP_UNROLL : 0) |
3072 (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0));
3074 loop_optimizer_finalize (loops, rtl_dump_file);
3077 /* Finalize layout changes. */
3079 if (bb->next_bb != EXIT_BLOCK_PTR)
3080 bb->rbi->next = bb->next_bb;
3081 cfg_layout_finalize ();
3083 cleanup_cfg (CLEANUP_EXPENSIVE);
3084 delete_trivially_dead_insns (insns, max_reg_num ());
3085 reg_scan (insns, max_reg_num (), 0);
3087 dump_flow_info (rtl_dump_file);
3088 close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
3089 timevar_pop (TV_LOOP);
3093 /* This is called from finish_function (within langhooks.parse_file)
3094 after each top-level definition is parsed.
3095 It is supposed to compile that function or variable
3096 and output the assembler code for it.
3097 After we return, the tree storage is freed. */
3100 rest_of_compilation (tree decl)
3104 timevar_push (TV_REST_OF_COMPILATION);
3106 /* Register rtl specific functions for cfg. */
3107 rtl_register_cfg_hooks ();
3109 /* Now that we're out of the frontend, we shouldn't have any more
3110 CONCATs anywhere. */
3111 generating_concat_p = 0;
3113 /* When processing delayed functions, prepare_function_start() won't
3114 have been run to re-initialize it. */
3115 cse_not_expected = ! optimize;
3117 /* First, make sure that NOTE_BLOCK is set correctly for each
3118 NOTE_INSN_BLOCK_BEG/NOTE_INSN_BLOCK_END note. */
3119 if (!cfun->x_whole_function_mode_p)
3122 /* In function-at-a-time mode, we do not attempt to keep the BLOCK
3123 tree in sensible shape. So, we just recalculate it here. */
3124 if (cfun->x_whole_function_mode_p)
3129 if (rest_of_handle_inlining (decl))
3130 goto exit_rest_of_compilation;
3132 /* If we're emitting a nested function, make sure its parent gets
3133 emitted as well. Doing otherwise confuses debug info. */
3136 for (parent = DECL_CONTEXT (current_function_decl);
3137 parent != NULL_TREE;
3138 parent = get_containing_scope (parent))
3139 if (TREE_CODE (parent) == FUNCTION_DECL)
3140 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
3143 /* We are now committed to emitting code for this function. Do any
3144 preparation, such as emitting abstract debug info for the inline
3145 before it gets mangled by optimization. */
3146 if (cgraph_function_possibly_inlined_p (decl))
3147 (*debug_hooks->outlining_inline_function) (decl);
3149 /* Remove any notes we don't need. That will make iterating
3150 over the instruction sequence faster, and allow the garbage
3151 collector to reclaim the memory used by the notes. */
3152 remove_unnecessary_notes ();
3157 /* Initialize some variables used by the optimizers. */
3158 init_function_for_compilation ();
3160 if (! DECL_DEFER_OUTPUT (decl))
3161 TREE_ASM_WRITTEN (decl) = 1;
3163 /* Now that integrate will no longer see our rtl, we need not
3164 distinguish between the return value of this function and the
3165 return value of called functions. Also, we can remove all SETs
3166 of subregs of hard registers; they are only here because of
3167 integrate. Also, we can now initialize pseudos intended to
3168 carry magic hard reg data throughout the function. */
3169 rtx_equal_function_value_matters = 0;
3170 purge_hard_subreg_sets (get_insns ());
3172 /* Early return if there were errors. We can run afoul of our
3173 consistency checks, and there's not really much point in fixing them.
3174 Don't return yet if -Wreturn-type; we need to do cleanup_cfg. */
3175 if (((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
3176 || errorcount || sorrycount)
3177 goto exit_rest_of_compilation;
3179 timevar_push (TV_JUMP);
3180 open_dump_file (DFI_sibling, decl);
3181 insns = get_insns ();
3182 rebuild_jump_labels (insns);
3183 find_exception_handler_labels ();
3184 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3186 delete_unreachable_blocks ();
3188 /* Turn NOTE_INSN_PREDICTIONs into branch predictions. */
3189 if (flag_guess_branch_prob)
3191 timevar_push (TV_BRANCH_PROB);
3192 note_prediction_to_br_prob ();
3193 timevar_pop (TV_BRANCH_PROB);
3196 if (flag_optimize_sibling_calls)
3197 rest_of_handle_sibling_calls (insns);
3199 /* We have to issue these warnings now already, because CFG cleanups
3200 further down may destroy the required information. However, this
3201 must be done after the sibcall optimization pass because the barrier
3202 emitted for noreturn calls that are candidate for the optimization
3203 is folded into the CALL_PLACEHOLDER until after this pass, so the
3204 CFG is inaccurate. */
3205 check_function_return_warnings ();
3207 timevar_pop (TV_JUMP);
3209 insn_locators_initialize ();
3210 /* Complete generation of exception handling code. */
3213 timevar_push (TV_JUMP);
3214 open_dump_file (DFI_eh, decl);
3216 finish_eh_generation ();
3218 close_dump_file (DFI_eh, print_rtl, get_insns ());
3219 timevar_pop (TV_JUMP);
3222 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
3223 generation, which might create new sets. */
3224 emit_initial_value_sets ();
3227 /* If we are doing position-independent code generation, now
3228 is the time to output special prologues and epilogues.
3229 We do not want to do this earlier, because it just clutters
3230 up inline functions with meaningless insns. */
3235 insns = get_insns ();
3237 /* Copy any shared structure that should not be shared. */
3238 unshare_all_rtl (current_function_decl, insns);
3240 #ifdef SETJMP_VIA_SAVE_AREA
3241 /* This must be performed before virtual register instantiation.
3242 Please be aware the everything in the compiler that can look
3243 at the RTL up to this point must understand that REG_SAVE_AREA
3244 is just like a use of the REG contained inside. */
3245 if (current_function_calls_alloca)
3246 optimize_save_area_alloca (insns);
3249 /* Instantiate all virtual registers. */
3250 instantiate_virtual_regs (current_function_decl, insns);
3252 open_dump_file (DFI_jump, decl);
3254 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3255 are initialized and to compute whether control can drop off the end
3258 timevar_push (TV_JUMP);
3259 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
3260 before jump optimization switches branch directions. */
3261 if (flag_guess_branch_prob)
3262 expected_value_to_br_prob ();
3264 reg_scan (insns, max_reg_num (), 0);
3265 rebuild_jump_labels (insns);
3266 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3267 delete_trivially_dead_insns (insns, max_reg_num ());
3269 dump_flow_info (rtl_dump_file);
3270 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
3271 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
3275 free_bb_for_insn ();
3276 copy_loop_headers (insns);
3277 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3279 purge_line_number_notes (insns);
3281 timevar_pop (TV_JUMP);
3282 close_dump_file (DFI_jump, print_rtl, insns);
3284 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
3285 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
3286 goto exit_rest_of_compilation;
3288 timevar_push (TV_JUMP);
3291 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3293 if (flag_delete_null_pointer_checks)
3294 rest_of_handle_null_pointer (decl, insns);
3296 /* Jump optimization, and the removal of NULL pointer checks, may
3297 have reduced the number of instructions substantially. CSE, and
3298 future passes, allocate arrays whose dimensions involve the
3299 maximum instruction UID, so if we can reduce the maximum UID
3300 we'll save big on memory. */
3301 renumber_insns (rtl_dump_file);
3302 timevar_pop (TV_JUMP);
3304 close_dump_file (DFI_jump, print_rtl_with_bb, insns);
3309 rest_of_handle_cse (decl, insns);
3311 rest_of_handle_addressof (decl, insns);
3318 rest_of_handle_gcse (decl, insns);
3320 if (flag_loop_optimize)
3321 rest_of_handle_loop_optimize (decl, insns);
3324 rest_of_handle_jump_bypass (decl, insns);
3327 timevar_push (TV_FLOW);
3329 rest_of_handle_cfg (decl, insns);
3332 || profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
3334 rest_of_handle_branch_prob (decl, insns);
3336 if (flag_branch_probabilities
3337 && flag_profile_values
3338 && flag_value_profile_transformations)
3339 rest_of_handle_value_profile_transformations (decl, insns);
3341 /* Remove the death notes created for vpt. */
3342 if (flag_profile_values)
3343 count_or_remove_death_notes (NULL, 1);
3347 rest_of_handle_if_conversion (decl, insns);
3350 rest_of_handle_tracer (decl, insns);
3353 && (flag_unswitch_loops
3355 || flag_unroll_loops))
3356 rest_of_handle_loop2 (decl, insns);
3359 rest_of_handle_web (decl, insns);
3361 if (flag_rerun_cse_after_loop)
3362 rest_of_handle_cse2 (decl, insns);
3364 cse_not_expected = 1;
3366 rest_of_handle_life (decl, insns);
3369 rest_of_handle_combine (decl, insns);
3371 if (flag_if_conversion)
3372 rest_of_handle_if_after_combine (decl, insns);
3374 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
3375 rest_of_handle_regmove (decl, insns);
3377 /* Do unconditional splitting before register allocation to allow machine
3378 description to add extra information not needed previously. */
3379 split_all_insns (1);
3381 #ifdef OPTIMIZE_MODE_SWITCHING
3382 timevar_push (TV_MODE_SWITCH);
3385 optimize_mode_switching (NULL);
3388 timevar_pop (TV_MODE_SWITCH);
3391 /* Any of the several passes since flow1 will have munged register
3392 lifetime data a bit. We need it to be up to date for scheduling
3393 (see handling of reg_known_equiv in init_alias_analysis). */
3394 recompute_reg_usage (insns, !optimize_size);
3396 #ifdef INSN_SCHEDULING
3397 rest_of_handle_sched (decl, insns);
3400 /* Determine if the current function is a leaf before running reload
3401 since this can impact optimizations done by the prologue and
3402 epilogue thus changing register elimination offsets. */
3403 current_function_is_leaf = leaf_function_p ();
3405 timevar_push (TV_LOCAL_ALLOC);
3406 open_dump_file (DFI_lreg, decl);
3408 if (flag_new_regalloc)
3410 if (rest_of_handle_new_regalloc (decl, insns))
3411 goto exit_rest_of_compilation;
3415 if (rest_of_handle_old_regalloc (decl, insns))
3416 goto exit_rest_of_compilation;
3421 open_dump_file (DFI_postreload, decl);
3423 /* Do a very simple CSE pass over just the hard registers. */
3426 timevar_push (TV_RELOAD_CSE_REGS);
3427 reload_cse_regs (insns);
3428 /* reload_cse_regs can eliminate potentially-trapping MEMs.
3429 Remove any EH edges associated with them. */
3430 if (flag_non_call_exceptions)
3431 purge_all_dead_edges (0);
3432 timevar_pop (TV_RELOAD_CSE_REGS);
3435 close_dump_file (DFI_postreload, print_rtl_with_bb, insns);
3437 /* Re-create the death notes which were deleted during reload. */
3438 timevar_push (TV_FLOW2);
3439 open_dump_file (DFI_flow2, decl);
3441 #ifdef ENABLE_CHECKING
3442 verify_flow_info ();
3445 /* If optimizing, then go ahead and split insns now. */
3449 split_all_insns (0);
3451 if (flag_branch_target_load_optimize)
3453 open_dump_file (DFI_branch_target_load, decl);
3455 branch_target_load_optimize (insns, false);
3457 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3463 cleanup_cfg (CLEANUP_EXPENSIVE);
3465 /* On some machines, the prologue and epilogue code, or parts thereof,
3466 can be represented as RTL. Doing so lets us schedule insns between
3467 it and the rest of the code and also allows delayed branch
3468 scheduling to operate in the epilogue. */
3469 thread_prologue_and_epilogue_insns (insns);
3470 epilogue_completed = 1;
3474 life_analysis (insns, rtl_dump_file, PROP_POSTRELOAD);
3475 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
3476 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
3478 /* This is kind of a heuristic. We need to run combine_stack_adjustments
3479 even for machines with possibly nonzero RETURN_POPS_ARGS
3480 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
3481 push instructions will have popping returns. */
3482 #ifndef PUSH_ROUNDING
3483 if (!ACCUMULATE_OUTGOING_ARGS)
3485 combine_stack_adjustments ();
3490 flow2_completed = 1;
3492 close_dump_file (DFI_flow2, print_rtl_with_bb, insns);
3493 timevar_pop (TV_FLOW2);
3495 #ifdef HAVE_peephole2
3496 if (optimize > 0 && flag_peephole2)
3498 timevar_push (TV_PEEPHOLE2);
3499 open_dump_file (DFI_peephole2, decl);
3501 peephole2_optimize (rtl_dump_file);
3503 close_dump_file (DFI_peephole2, print_rtl_with_bb, insns);
3504 timevar_pop (TV_PEEPHOLE2);
3508 open_dump_file (DFI_ce3, decl);
3510 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
3511 splitting possibly introduced more crossjumping opportunities. */
3512 cleanup_cfg (CLEANUP_EXPENSIVE
3513 | CLEANUP_UPDATE_LIFE
3514 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
3515 if (flag_if_conversion2)
3517 timevar_push (TV_IFCVT2);
3521 timevar_pop (TV_IFCVT2);
3523 close_dump_file (DFI_ce3, print_rtl_with_bb, insns);
3527 if (flag_rename_registers || flag_cprop_registers)
3528 rest_of_handle_regrename (decl, insns);
3530 rest_of_handle_reorder_blocks (decl, insns);
3533 if (flag_branch_target_load_optimize2)
3535 /* Leave this a warning for now so that it is possible to experiment
3536 with running this pass twice. In 3.6, we should either make this
3537 an error, or use separate dump files. */
3538 if (flag_branch_target_load_optimize)
3539 warning ("branch target register load optimization is not intended "
3542 open_dump_file (DFI_branch_target_load, decl);
3544 branch_target_load_optimize (insns, true);
3546 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3551 #ifdef INSN_SCHEDULING
3552 if (optimize > 0 && flag_schedule_insns_after_reload)
3553 rest_of_handle_sched2 (decl, insns);
3556 #ifdef LEAF_REGISTERS
3557 current_function_uses_only_leaf_regs
3558 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
3562 rest_of_handle_stack_regs (decl, insns);
3565 compute_alignments ();
3567 if (flag_var_tracking)
3568 rest_of_handle_variable_tracking (decl, insns);
3570 /* CFG is no longer maintained up-to-date. */
3571 free_bb_for_insn ();
3573 if (targetm.machine_dependent_reorg != 0)
3574 rest_of_handle_machine_reorg (decl, insns);
3576 purge_line_number_notes (insns);
3577 cleanup_barriers ();
3580 if (optimize > 0 && flag_delayed_branch)
3581 rest_of_handle_delay_slots (decl, insns);
3584 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3585 timevar_push (TV_SHORTEN_BRANCH);
3586 split_all_insns_noflow ();
3587 timevar_pop (TV_SHORTEN_BRANCH);
3590 convert_to_eh_region_ranges ();
3592 /* Shorten branches. */
3593 timevar_push (TV_SHORTEN_BRANCH);
3594 shorten_branches (get_insns ());
3595 timevar_pop (TV_SHORTEN_BRANCH);
3597 set_nothrow_function_flags ();
3598 if (current_function_nothrow)
3599 /* Now we know that this can't throw; set the flag for the benefit
3600 of other functions later in this translation unit. */
3601 TREE_NOTHROW (current_function_decl) = 1;
3603 rest_of_handle_final (decl, insns);
3605 /* Write DBX symbols if requested. */
3607 /* Note that for those inline functions where we don't initially
3608 know for certain that we will be generating an out-of-line copy,
3609 the first invocation of this routine (rest_of_compilation) will
3610 skip over this code by doing a `goto exit_rest_of_compilation;'.
3611 Later on, wrapup_global_declarations will (indirectly) call
3612 rest_of_compilation again for those inline functions that need
3613 to have out-of-line copies generated. During that call, we
3614 *will* be routed past here. */
3616 timevar_push (TV_SYMOUT);
3617 (*debug_hooks->function_decl) (decl);
3618 timevar_pop (TV_SYMOUT);
3620 exit_rest_of_compilation:
3622 coverage_end_function ();
3624 /* In case the function was not output,
3625 don't leave any temporary anonymous types
3626 queued up for sdb output. */
3627 #ifdef SDB_DEBUGGING_INFO
3628 if (write_symbols == SDB_DEBUG)
3629 sdbout_types (NULL_TREE);
3632 reload_completed = 0;
3633 epilogue_completed = 0;
3634 flow2_completed = 0;
3637 timevar_push (TV_FINAL);
3639 /* Clear out the insn_length contents now that they are no
3641 init_insn_lengths ();
3643 /* Show no temporary slots allocated. */
3646 free_basic_block_vars (0);
3647 free_bb_for_insn ();
3649 timevar_pop (TV_FINAL);
3651 if ((*targetm.binds_local_p) (current_function_decl))
3653 int pref = cfun->preferred_stack_boundary;
3654 if (cfun->recursive_call_emit
3655 && cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
3656 pref = cfun->stack_alignment_needed;
3657 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
3661 /* Make sure volatile mem refs aren't considered valid operands for
3662 arithmetic insns. We must call this here if this is a nested inline
3663 function, since the above code leaves us in the init_recog state
3664 (from final.c), and the function context push/pop code does not
3665 save/restore volatile_ok.
3667 ??? Maybe it isn't necessary for expand_start_function to call this
3668 anymore if we do it here? */
3670 init_recog_no_volatile ();
3672 /* We're done with this function. Free up memory if we can. */
3673 free_after_parsing (cfun);
3674 if (! DECL_DEFER_OUTPUT (decl))
3676 free_after_compilation (cfun);
3677 DECL_STRUCT_FUNCTION (decl) = 0;
3683 timevar_pop (TV_REST_OF_COMPILATION);
3686 /* Display help for target options. */
3688 display_target_options (void)
3691 static bool displayed = false;
3693 /* Avoid double printing for --help --target-help. */
3699 if (ARRAY_SIZE (target_switches) > 1
3700 #ifdef TARGET_OPTIONS
3701 || ARRAY_SIZE (target_options) > 1
3709 printf (_("\nTarget specific options:\n"));
3711 for (i = ARRAY_SIZE (target_switches); i--;)
3713 const char *option = target_switches[i].name;
3714 const char *description = target_switches[i].description;
3716 if (option == NULL || *option == 0)
3718 else if (description == NULL)
3723 printf (_(" -m%-23s [undocumented]\n"), option);
3725 else if (*description != 0)
3726 doc += printf (" -m%-23s %s\n", option, _(description));
3729 #ifdef TARGET_OPTIONS
3730 for (i = ARRAY_SIZE (target_options); i--;)
3732 const char *option = target_options[i].prefix;
3733 const char *description = target_options[i].description;
3735 if (option == NULL || *option == 0)
3737 else if (description == NULL)
3742 printf (_(" -m%-23s [undocumented]\n"), option);
3744 else if (*description != 0)
3745 doc += printf (" -m%-23s %s\n", option, _(description));
3751 printf (_("\nThere are undocumented target specific options as well.\n"));
3753 printf (_(" They exist, but they are not documented.\n"));
3758 /* Parse a -d... command line switch. */
3761 decode_d_option (const char *arg)
3769 for (i = 0; i < (int) DFI_MAX; ++i)
3770 dump_file[i].enabled = 1;
3776 flag_print_asm_name = 1;
3779 flag_dump_rtl_in_asm = 1;
3780 flag_print_asm_name = 1;
3783 graph_dump_format = vcg;
3786 rtl_dump_and_exit = 1;
3791 case 'D': /* These are handled by the preprocessor. */
3795 setup_core_dumping();
3800 for (i = 0; i < (int) DFI_MAX; ++i)
3801 if (c == dump_file[i].debug_switch)
3803 dump_file[i].enabled = 1;
3808 warning ("unrecognized gcc debugging option: %c", c);
3813 /* Indexed by enum debug_info_type. */
3814 const char *const debug_type_names[] =
3816 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
3819 /* Decode -m switches. */
3820 /* Decode the switch -mNAME. */
3823 set_target_switch (const char *name)
3826 int valid_target_option = 0;
3828 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
3829 if (!strcmp (target_switches[j].name, name))
3831 if (target_switches[j].value < 0)
3832 target_flags &= ~-target_switches[j].value;
3834 target_flags |= target_switches[j].value;
3837 if (target_switches[j].value < 0)
3838 target_flags_explicit |= -target_switches[j].value;
3840 target_flags_explicit |= target_switches[j].value;
3842 valid_target_option = 1;
3845 #ifdef TARGET_OPTIONS
3846 if (!valid_target_option)
3847 for (j = 0; j < ARRAY_SIZE (target_options); j++)
3849 int len = strlen (target_options[j].prefix);
3850 if (target_options[j].value)
3852 if (!strcmp (target_options[j].prefix, name))
3854 *target_options[j].variable = target_options[j].value;
3855 valid_target_option = 1;
3860 if (!strncmp (target_options[j].prefix, name, len))
3862 *target_options[j].variable = name + len;
3863 valid_target_option = 1;
3869 if (!valid_target_option)
3870 error ("invalid option `%s'", name);
3873 /* Print version information to FILE.
3874 Each line begins with INDENT (for the case where FILE is the
3875 assembler output file). */
3878 print_version (FILE *file, const char *indent)
3881 #define __VERSION__ "[?]"
3885 "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
3887 "%s%s%s version %s (%s) compiled by CC.\n"
3889 , indent, *indent != 0 ? " " : "",
3890 lang_hooks.name, version_string, TARGET_NAME,
3891 indent, __VERSION__);
3892 fnotice (file, "%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n",
3893 indent, *indent != 0 ? " " : "",
3894 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
3897 /* Print an option value and return the adjusted position in the line.
3898 ??? We don't handle error returns from fprintf (disk full); presumably
3899 other code will catch a disk full though. */
3902 print_single_switch (FILE *file, int pos, int max,
3903 const char *indent, const char *sep, const char *term,
3904 const char *type, const char *name)
3906 /* The ultrix fprintf returns 0 on success, so compute the result we want
3907 here since we need it for the following test. */
3908 int len = strlen (sep) + strlen (type) + strlen (name);
3913 fprintf (file, "%s", term);
3918 fprintf (file, "%s", indent);
3919 pos = strlen (indent);
3921 fprintf (file, "%s%s%s", sep, type, name);
3926 /* Print active target switches to FILE.
3927 POS is the current cursor position and MAX is the size of a "line".
3928 Each line begins with INDENT and ends with TERM.
3929 Each switch is separated from the next by SEP. */
3932 print_switch_values (FILE *file, int pos, int max,
3933 const char *indent, const char *sep, const char *term)
3938 /* Fill in the -frandom-seed option, if the user didn't pass it, so
3939 that it can be printed below. This helps reproducibility. */
3942 /* Print the options as passed. */
3943 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
3944 _("options passed: "), "");
3946 for (p = &save_argv[1]; *p != NULL; p++)
3950 if (strcmp (*p, "-o") == 0)
3956 if (strcmp (*p, "-quiet") == 0)
3958 if (strcmp (*p, "-version") == 0)
3963 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
3966 fprintf (file, "%s", term);
3968 /* Print the -f and -m options that have been enabled.
3969 We don't handle language specific options but printing argv
3972 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
3973 _("options enabled: "), "");
3975 for (j = 0; j < ARRAY_SIZE (f_options); j++)
3976 if (*f_options[j].variable == f_options[j].on_value)
3977 pos = print_single_switch (file, pos, max, indent, sep, term,
3978 "-f", f_options[j].string);
3980 /* Print target specific options. */
3982 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
3983 if (target_switches[j].name[0] != '\0'
3984 && target_switches[j].value > 0
3985 && ((target_switches[j].value & target_flags)
3986 == target_switches[j].value))
3988 pos = print_single_switch (file, pos, max, indent, sep, term,
3989 "-m", target_switches[j].name);
3992 #ifdef TARGET_OPTIONS
3993 for (j = 0; j < ARRAY_SIZE (target_options); j++)
3994 if (*target_options[j].variable != NULL)
3997 sprintf (prefix, "-m%s", target_options[j].prefix);
3998 pos = print_single_switch (file, pos, max, indent, sep, term,
3999 prefix, *target_options[j].variable);
4003 fprintf (file, "%s", term);
4006 /* Open assembly code output file. Do this even if -fsyntax-only is
4007 on, because then the driver will have provided the name of a
4008 temporary file or bit bucket for us. NAME is the file specified on
4009 the command line, possibly NULL. */
4011 init_asm_output (const char *name)
4013 if (name == NULL && asm_file_name == 0)
4014 asm_out_file = stdout;
4017 if (asm_file_name == 0)
4019 int len = strlen (dump_base_name);
4020 char *dumpname = xmalloc (len + 6);
4021 memcpy (dumpname, dump_base_name, len + 1);
4022 strip_off_ending (dumpname, len);
4023 strcat (dumpname, ".s");
4024 asm_file_name = dumpname;
4026 if (!strcmp (asm_file_name, "-"))
4027 asm_out_file = stdout;
4029 asm_out_file = fopen (asm_file_name, "w+");
4030 if (asm_out_file == 0)
4031 fatal_error ("can't open %s for writing: %m", asm_file_name);
4034 #ifdef IO_BUFFER_SIZE
4035 setvbuf (asm_out_file, xmalloc (IO_BUFFER_SIZE),
4036 _IOFBF, IO_BUFFER_SIZE);
4039 if (!flag_syntax_only)
4041 targetm.asm_out.file_start ();
4043 #ifdef ASM_COMMENT_START
4044 if (flag_verbose_asm)
4046 /* Print the list of options in effect. */
4047 print_version (asm_out_file, ASM_COMMENT_START);
4048 print_switch_values (asm_out_file, 0, MAX_LINE,
4049 ASM_COMMENT_START, " ", "\n");
4050 /* Add a blank line here so it appears in assembler output but not
4052 fprintf (asm_out_file, "\n");
4058 /* Default version of get_pch_validity.
4059 By default, every flag difference is fatal; that will be mostly right for
4060 most targets, but completely right for very few. */
4063 default_get_pch_validity (size_t *len)
4065 #ifdef TARGET_OPTIONS
4070 *len = sizeof (target_flags) + 2;
4071 #ifdef TARGET_OPTIONS
4072 for (i = 0; i < ARRAY_SIZE (target_options); i++)
4075 if (*target_options[i].variable)
4076 *len += strlen (*target_options[i].variable);
4080 result = r = xmalloc (*len);
4084 memcpy (r, &target_flags, sizeof (target_flags));
4085 r += sizeof (target_flags);
4087 #ifdef TARGET_OPTIONS
4088 for (i = 0; i < ARRAY_SIZE (target_options); i++)
4090 const char *str = *target_options[i].variable;
4094 l = strlen (str) + 1;
4103 /* Default version of pch_valid_p. */
4106 default_pch_valid_p (const void *data_p, size_t len)
4108 const char *data = (const char *)data_p;
4109 const char *flag_that_differs = NULL;
4112 /* -fpic and -fpie also usually make a PCH invalid. */
4113 if (data[0] != flag_pic)
4114 return _("created and used with different settings of -fpic");
4115 if (data[1] != flag_pie)
4116 return _("created and used with different settings of -fpie");
4119 /* Check target_flags. */
4120 if (memcmp (data, &target_flags, sizeof (target_flags)) != 0)
4122 for (i = 0; i < ARRAY_SIZE (target_switches); i++)
4127 memcpy (&tf, data, sizeof (target_flags));
4129 bits = target_switches[i].value;
4132 if ((target_flags & bits) != (tf & bits))
4134 flag_that_differs = target_switches[i].name;
4140 data += sizeof (target_flags);
4141 len -= sizeof (target_flags);
4143 /* Check string options. */
4144 #ifdef TARGET_OPTIONS
4145 for (i = 0; i < ARRAY_SIZE (target_options); i++)
4147 const char *str = *target_options[i].variable;
4151 l = strlen (str) + 1;
4152 if (len < l || memcmp (data, str, l) != 0)
4154 flag_that_differs = target_options[i].prefix;
4167 asprintf (&r, _("created and used with differing settings of `-m%s'"),
4170 return _("out of memory");
4175 /* Default tree printer. Handles declarations only. */
4177 default_tree_printer (pretty_printer * pp, text_info *text)
4179 switch (*text->format_spec)
4185 tree t = va_arg (*text->args_ptr, tree);
4186 const char *n = DECL_NAME (t)
4187 ? (*lang_hooks.decl_printable_name) (t, 2)
4198 /* Initialization of the front end environment, before command line
4199 options are parsed. Signal handlers, internationalization etc.
4200 ARGV0 is main's argv[0]. */
4202 general_init (const char *argv0)
4206 p = argv0 + strlen (argv0);
4207 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
4211 xmalloc_set_program_name (progname);
4215 gcc_init_libintl ();
4217 /* Initialize the diagnostics reporting machinery, so option parsing
4218 can give warnings and errors. */
4219 diagnostic_initialize (global_dc);
4220 /* Set a default printer. Language specific initializations will
4221 override it later. */
4222 pp_format_decoder (global_dc->printer) = &default_tree_printer;
4224 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
4226 signal (SIGSEGV, crash_signal);
4229 signal (SIGILL, crash_signal);
4232 signal (SIGBUS, crash_signal);
4235 signal (SIGABRT, crash_signal);
4237 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
4238 signal (SIGIOT, crash_signal);
4241 signal (SIGFPE, crash_signal);
4244 /* Other host-specific signal setup. */
4245 (*host_hooks.extra_signals)();
4247 /* Initialize the garbage-collector, string pools and tree type hash
4251 linemap_init (&line_table);
4254 /* Initialize register usage now so switches may override. */
4257 /* Register the language-independent parameters. */
4258 add_params (lang_independent_params, LAST_PARAM);
4260 /* This must be done after add_params but before argument processing. */
4261 init_ggc_heuristics();
4264 /* Process the options that have been parsed. */
4266 process_options (void)
4268 /* Allow the front end to perform consistency checks and do further
4269 initialization based on the command line options. This hook also
4270 sets the original filename if appropriate (e.g. foo.i -> foo.c)
4271 so we can correctly initialize debug output. */
4272 no_backend = (*lang_hooks.post_options) (&main_input_filename);
4273 input_filename = main_input_filename;
4275 #ifdef OVERRIDE_OPTIONS
4276 /* Some machines may reject certain combinations of options. */
4280 /* Set aux_base_name if not already set. */
4283 else if (main_input_filename)
4285 char *name = xstrdup (lbasename (main_input_filename));
4287 strip_off_ending (name, strlen (name));
4288 aux_base_name = name;
4291 aux_base_name = "gccaux";
4293 /* Set up the align_*_log variables, defaulting them to 1 if they
4294 were still unset. */
4295 if (align_loops <= 0) align_loops = 1;
4296 if (align_loops_max_skip > align_loops || !align_loops)
4297 align_loops_max_skip = align_loops - 1;
4298 align_loops_log = floor_log2 (align_loops * 2 - 1);
4299 if (align_jumps <= 0) align_jumps = 1;
4300 if (align_jumps_max_skip > align_jumps || !align_jumps)
4301 align_jumps_max_skip = align_jumps - 1;
4302 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
4303 if (align_labels <= 0) align_labels = 1;
4304 align_labels_log = floor_log2 (align_labels * 2 - 1);
4305 if (align_labels_max_skip > align_labels || !align_labels)
4306 align_labels_max_skip = align_labels - 1;
4307 if (align_functions <= 0) align_functions = 1;
4308 align_functions_log = floor_log2 (align_functions * 2 - 1);
4310 /* Unrolling all loops implies that standard loop unrolling must also
4312 if (flag_unroll_all_loops)
4313 flag_unroll_loops = 1;
4315 if (flag_unroll_loops)
4317 flag_old_unroll_loops = 0;
4318 flag_old_unroll_all_loops = 0;
4321 if (flag_old_unroll_all_loops)
4322 flag_old_unroll_loops = 1;
4324 /* Old loop unrolling requires that strength_reduction be on also. Silently
4325 turn on strength reduction here if it isn't already on. Also, the loop
4326 unrolling code assumes that cse will be run after loop, so that must
4327 be turned on also. */
4328 if (flag_old_unroll_loops)
4330 flag_strength_reduce = 1;
4331 flag_rerun_cse_after_loop = 1;
4333 if (flag_unroll_loops || flag_peel_loops)
4334 flag_rerun_cse_after_loop = 1;
4336 if (flag_non_call_exceptions)
4337 flag_asynchronous_unwind_tables = 1;
4338 if (flag_asynchronous_unwind_tables)
4339 flag_unwind_tables = 1;
4341 /* Disable unit-at-a-time mode for frontends not supporting callgraph
4343 if (flag_unit_at_a_time && ! lang_hooks.callgraph.expand_function)
4344 flag_unit_at_a_time = 0;
4346 if (flag_value_profile_transformations)
4347 flag_profile_values = 1;
4349 /* Warn about options that are not supported on this machine. */
4350 #ifndef INSN_SCHEDULING
4351 if (flag_schedule_insns || flag_schedule_insns_after_reload)
4352 warning ("instruction scheduling not supported on this target machine");
4355 if (flag_delayed_branch)
4356 warning ("this target machine does not have delayed branches");
4359 user_label_prefix = USER_LABEL_PREFIX;
4360 if (flag_leading_underscore != -1)
4362 /* If the default prefix is more complicated than "" or "_",
4363 issue a warning and ignore this option. */
4364 if (user_label_prefix[0] == 0 ||
4365 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
4367 user_label_prefix = flag_leading_underscore ? "_" : "";
4370 warning ("-f%sleading-underscore not supported on this target machine",
4371 flag_leading_underscore ? "" : "no-");
4374 /* If we are in verbose mode, write out the version and maybe all the
4375 option flags in use. */
4378 print_version (stderr, "");
4380 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
4383 if (flag_syntax_only)
4385 write_symbols = NO_DEBUG;
4389 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
4391 if (debug_info_level == DINFO_LEVEL_NONE)
4392 write_symbols = NO_DEBUG;
4394 /* Now we know write_symbols, set up the debug hooks based on it.
4395 By default we do nothing for debug output. */
4396 if (write_symbols == NO_DEBUG)
4397 debug_hooks = &do_nothing_debug_hooks;
4398 #if defined(DBX_DEBUGGING_INFO)
4399 else if (write_symbols == DBX_DEBUG)
4400 debug_hooks = &dbx_debug_hooks;
4402 #if defined(XCOFF_DEBUGGING_INFO)
4403 else if (write_symbols == XCOFF_DEBUG)
4404 debug_hooks = &xcoff_debug_hooks;
4406 #ifdef SDB_DEBUGGING_INFO
4407 else if (write_symbols == SDB_DEBUG)
4408 debug_hooks = &sdb_debug_hooks;
4410 #ifdef DWARF2_DEBUGGING_INFO
4411 else if (write_symbols == DWARF2_DEBUG)
4412 debug_hooks = &dwarf2_debug_hooks;
4414 #ifdef VMS_DEBUGGING_INFO
4415 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
4416 debug_hooks = &vmsdbg_debug_hooks;
4419 error ("target system does not support the \"%s\" debug format",
4420 debug_type_names[write_symbols]);
4422 /* Now we know which debug output will be used so we can set
4423 flag_var_tracking if user has not specified it. */
4424 if (flag_var_tracking == AUTODETECT_FLAG_VAR_TRACKING)
4426 /* User has not specified -f(no-)var-tracking so autodetect it. */
4428 = (optimize >= 1 && debug_info_level >= DINFO_LEVEL_NORMAL
4429 && debug_hooks->var_location != do_nothing_debug_hooks.var_location);
4432 /* If auxiliary info generation is desired, open the output file.
4433 This goes in the same directory as the source file--unlike
4434 all the other output files. */
4435 if (flag_gen_aux_info)
4437 aux_info_file = fopen (aux_info_file_name, "w");
4438 if (aux_info_file == 0)
4439 fatal_error ("can't open %s: %m", aux_info_file_name);
4442 if (! targetm.have_named_sections)
4444 if (flag_function_sections)
4446 warning ("-ffunction-sections not supported for this target");
4447 flag_function_sections = 0;
4449 if (flag_data_sections)
4451 warning ("-fdata-sections not supported for this target");
4452 flag_data_sections = 0;
4456 if (flag_function_sections && profile_flag)
4458 warning ("-ffunction-sections disabled; it makes profiling impossible");
4459 flag_function_sections = 0;
4462 #ifndef HAVE_prefetch
4463 if (flag_prefetch_loop_arrays)
4465 warning ("-fprefetch-loop-arrays not supported for this target");
4466 flag_prefetch_loop_arrays = 0;
4469 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
4471 warning ("-fprefetch-loop-arrays not supported for this target (try -march switches)");
4472 flag_prefetch_loop_arrays = 0;
4476 /* This combination of options isn't handled for i386 targets and doesn't
4477 make much sense anyway, so don't allow it. */
4478 if (flag_prefetch_loop_arrays && optimize_size)
4480 warning ("-fprefetch-loop-arrays is not supported with -Os");
4481 flag_prefetch_loop_arrays = 0;
4484 #ifndef OBJECT_FORMAT_ELF
4485 if (flag_function_sections && write_symbols != NO_DEBUG)
4486 warning ("-ffunction-sections may affect debugging on some targets");
4489 /* The presence of IEEE signaling NaNs, implies all math can trap. */
4490 if (flag_signaling_nans)
4491 flag_trapping_math = 1;
4494 /* Initialize the compiler back end. */
4498 init_adjust_machine_modes ();
4500 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
4501 || debug_info_level == DINFO_LEVEL_VERBOSE
4502 #ifdef VMS_DEBUGGING_INFO
4503 /* Enable line number info for traceback. */
4504 || debug_info_level > DINFO_LEVEL_NONE
4506 || flag_test_coverage
4507 || warn_notreached);
4510 init_fake_stack_mems ();
4514 init_function_once ();
4515 init_varasm_once ();
4517 /* The following initialization functions need to generate rtl, so
4518 provide a dummy function context for them. */
4519 init_dummy_function_start ();
4521 if (flag_caller_saves)
4522 init_caller_save ();
4523 expand_dummy_function_end ();
4526 /* Language-dependent initialization. Returns nonzero on success. */
4528 lang_dependent_init (const char *name)
4530 if (dump_base_name == 0)
4531 dump_base_name = name ? name : "gccdump";
4533 /* Other front-end initialization. */
4534 if ((*lang_hooks.init) () == 0)
4537 init_asm_output (name);
4539 /* These create various _DECL nodes, so need to be called after the
4540 front end is initialized. */
4544 /* The following initialization functions need to generate rtl, so
4545 provide a dummy function context for them. */
4546 init_dummy_function_start ();
4548 expand_dummy_function_end ();
4550 /* If dbx symbol table desired, initialize writing it and output the
4551 predefined types. */
4552 timevar_push (TV_SYMOUT);
4554 #ifdef DWARF2_UNWIND_INFO
4555 if (dwarf2out_do_frame ())
4556 dwarf2out_frame_init ();
4559 /* Now we have the correct original filename, we can initialize
4561 (*debug_hooks->init) (name);
4563 timevar_pop (TV_SYMOUT);
4568 /* Clean up: close opened files, etc. */
4573 /* Close the dump files. */
4574 if (flag_gen_aux_info)
4576 fclose (aux_info_file);
4578 unlink (aux_info_file_name);
4581 /* Close non-debugging input and output files. Take special care to note
4582 whether fclose returns an error, since the pages might still be on the
4583 buffer chain while the file is open. */
4587 if (ferror (asm_out_file) != 0)
4588 fatal_error ("error writing to %s: %m", asm_file_name);
4589 if (fclose (asm_out_file) != 0)
4590 fatal_error ("error closing %s: %m", asm_file_name);
4593 /* Do whatever is necessary to finish printing the graphs. */
4594 if (graph_dump_format != no_graph)
4598 for (i = 0; i < (int) DFI_MAX; ++i)
4599 if (dump_file[i].initialized && dump_file[i].graph_dump_p)
4604 sprintf (seq, DUMPFILE_FORMAT, i);
4605 suffix = concat (seq, dump_file[i].extension, NULL);
4606 finish_graph_dump_file (dump_base_name, suffix);
4613 ggc_print_statistics ();
4614 stringpool_statistics ();
4615 dump_tree_statistics ();
4616 dump_rtx_statistics ();
4617 dump_varray_statistics ();
4618 dump_alloc_pool_statistics ();
4621 /* Free up memory for the benefit of leak detectors. */
4624 /* Language-specific end of compilation actions. */
4625 (*lang_hooks.finish) ();
4628 /* Initialize the compiler, and compile the input file. */
4632 /* Initialize timing first. The C front ends read the main file in
4633 the post_options hook, and C++ does file timings. */
4634 if (time_report || !quiet_flag || flag_detailed_statistics)
4636 timevar_start (TV_TOTAL);
4640 /* Don't do any more if an error has already occurred. */
4643 /* Set up the back-end if requested. */
4647 /* Language-dependent initialization. Returns true on success. */
4648 if (lang_dependent_init (main_input_filename))
4650 if (flag_unit_at_a_time)
4652 open_dump_file (DFI_cgraph, NULL);
4653 cgraph_dump_file = rtl_dump_file;
4654 rtl_dump_file = NULL;
4659 if (flag_unit_at_a_time)
4661 rtl_dump_file = cgraph_dump_file;
4662 cgraph_dump_file = NULL;
4663 close_dump_file (DFI_cgraph, NULL, NULL_RTX);
4670 /* Stop timing and print the times. */
4671 timevar_stop (TV_TOTAL);
4672 timevar_print (stderr);
4675 /* Entry point of cc1, cc1plus, jc1, f771, etc.
4676 Exit code is FATAL_EXIT_CODE if can't open files or if there were
4677 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
4679 It is not safe to call this function more than once. */
4682 toplev_main (unsigned int argc, const char **argv)
4686 /* Initialization of GCC's environment, and diagnostics. */
4687 general_init (argv[0]);
4689 /* Parse the options and do minimal processing; basically just
4690 enough to default flags appropriately. */
4691 decode_options (argc, argv);
4695 /* Exit early if we can (e.g. -help). */
4696 if (!exit_after_options)
4699 if (errorcount || sorrycount)
4700 return (FATAL_EXIT_CODE);
4702 return (SUCCESS_EXIT_CODE);