1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* This is the top level of cc1/c++.
23 It parses command args, opens files, invokes the various passes
24 in the proper order, and counts the time used by each.
25 Error messages and low-level interface to malloc also handled here. */
28 #undef FLOAT /* This is for hpux. They should change hpux. */
29 #undef FFS /* Some systems define this in param.h. */
31 #include "coretypes.h"
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
48 #include "insn-attr.h"
49 #include "insn-config.h"
50 #include "insn-flags.h"
51 #include "hard-reg-set.h"
58 #include "basic-block.h"
65 #include "diagnostic.h"
69 #include "dwarf2asm.h"
70 #include "integrate.h"
74 #include "langhooks.h"
75 #include "cfglayout.h"
77 #include "hosthooks.h"
82 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
83 #include "dwarf2out.h"
86 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
90 #ifdef SDB_DEBUGGING_INFO
94 #ifdef XCOFF_DEBUGGING_INFO
95 #include "xcoffout.h" /* Needed for external data
96 declarations for e.g. AIX 4.x. */
99 /* Carry information from ASM_DECLARE_OBJECT_NAME
100 to ASM_FINISH_DECLARE_OBJECT. */
102 extern int size_directive_output
;
103 extern tree last_assemble_variable_decl
;
105 extern void reg_alloc (void);
107 static void general_init (const char *);
108 static void do_compile (void);
109 static void process_options (void);
110 static void backend_init (void);
111 static int lang_dependent_init (const char *);
112 static void init_asm_output (const char *);
113 static void finalize (void);
115 static void crash_signal (int) ATTRIBUTE_NORETURN
;
116 static void setup_core_dumping (void);
117 static void compile_file (void);
119 static int print_single_switch (FILE *, int, int, const char *,
120 const char *, const char *,
121 const char *, const char *);
122 static void print_switch_values (FILE *, int, int, const char *,
123 const char *, const char *);
125 /* Rest of compilation helper functions. */
126 static bool rest_of_handle_inlining (tree
);
127 static rtx
rest_of_handle_ssa (tree
, rtx
);
128 static void rest_of_handle_cse (tree
, rtx
);
129 static void rest_of_handle_cse2 (tree
, rtx
);
130 static void rest_of_handle_gcse (tree
, rtx
);
131 static void rest_of_handle_life (tree
, rtx
);
132 static void rest_of_handle_loop_optimize (tree
, rtx
);
133 static void rest_of_handle_loop2 (tree
, rtx
);
134 static void rest_of_handle_jump_bypass (tree
, rtx
);
135 static void rest_of_handle_sibling_calls (rtx
);
136 static void rest_of_handle_null_pointer (tree
, rtx
);
137 static void rest_of_handle_addressof (tree
, rtx
);
138 static void rest_of_handle_cfg (tree
, rtx
);
139 static void rest_of_handle_branch_prob (tree
, rtx
);
140 static void rest_of_handle_if_conversion (tree
, rtx
);
141 static void rest_of_handle_if_after_combine (tree
, rtx
);
142 static void rest_of_handle_tracer (tree
, rtx
);
143 static void rest_of_handle_combine (tree
, rtx
);
144 static void rest_of_handle_regmove (tree
, rtx
);
145 #ifdef INSN_SCHEDULING
146 static void rest_of_handle_sched (tree
, rtx
);
147 static void rest_of_handle_sched2 (tree
, rtx
);
149 static bool rest_of_handle_new_regalloc (tree
, rtx
, int *);
150 static bool rest_of_handle_old_regalloc (tree
, rtx
, int *);
151 static void rest_of_handle_regrename (tree
, rtx
);
152 static void rest_of_handle_reorder_blocks (tree
, rtx
);
154 static void rest_of_handle_stack_regs (tree
, rtx
);
156 static void rest_of_handle_machine_reorg (tree
, rtx
);
158 static void rest_of_handle_delay_slots (tree
, rtx
);
160 static void rest_of_handle_final (tree
, rtx
);
162 /* Nonzero to dump debug info whilst parsing (-dy option). */
163 static int set_yydebug
;
165 /* True if we don't need a backend (e.g. preprocessing only). */
166 static bool no_backend
;
168 /* Length of line when printing switch values. */
171 /* Name of program invoked, sans directories. */
173 const char *progname
;
175 /* Copy of argument vector to toplev_main. */
176 static const char **save_argv
;
178 /* Name of top-level original source file (what was input to cpp).
179 This comes from the #-command at the beginning of the actual input.
180 If there isn't any there, then this is the cc1 input file name. */
182 const char *main_input_filename
;
184 /* Current position in real source file. */
186 location_t input_location
;
188 /* Nonzero if it is unsafe to create any new pseudo registers. */
191 /* Stack of currently pending input files. */
193 struct file_stack
*input_file_stack
;
195 /* Incremented on each change to input_file_stack. */
196 int input_file_stack_tick
;
198 /* Name to use as base of names for dump output files. */
200 const char *dump_base_name
;
202 /* Name to use as a base for auxiliary output files. */
204 const char *aux_base_name
;
206 /* Format to use to print dumpfile index value */
207 #ifndef DUMPFILE_FORMAT
208 #define DUMPFILE_FORMAT ".%02d."
211 /* Bit flags that specify the machine subtype we are compiling for.
212 Bits are tested using macros TARGET_... defined in the tm.h file
213 and set by `-m...' switches. Must be defined in rtlanal.c. */
215 extern int target_flags
;
217 /* A mask of target_flags that includes bit X if X was set or cleared
218 on the command line. */
220 int target_flags_explicit
;
222 /* Debug hooks - dependent upon command line options. */
224 const struct gcc_debug_hooks
*debug_hooks
;
226 /* Describes a dump file. */
228 struct dump_file_info
230 /* The unique extension to apply, e.g. ".jump". */
231 const char *const extension
;
233 /* The -d<c> character that enables this dump file. */
234 char const debug_switch
;
236 /* True if there is a corresponding graph dump file. */
237 char const graph_dump_p
;
239 /* True if the user selected this dump. */
242 /* True if the files have been initialized (ie truncated). */
246 /* Enumerate the extant dump files. */
284 DFI_branch_target_load
,
292 /* Describes all the dump files. Should be kept in order of the
293 pass and in sync with dump_file_index above.
295 Remaining -d letters:
301 static struct dump_file_info dump_file
[DFI_MAX
] =
303 { "cgraph", 'U', 0, 0, 0 },
304 { "rtl", 'r', 0, 0, 0 },
305 { "sibling", 'i', 0, 0, 0 },
306 { "eh", 'h', 0, 0, 0 },
307 { "jump", 'j', 0, 0, 0 },
308 { "ssa", 'e', 1, 0, 0 },
309 { "ssaccp", 'W', 1, 0, 0 },
310 { "ssadce", 'X', 1, 0, 0 },
311 { "ussa", 'e', 1, 0, 0 }, /* Yes, duplicate enable switch. */
312 { "null", 'u', 0, 0, 0 },
313 { "cse", 's', 0, 0, 0 },
314 { "addressof", 'F', 0, 0, 0 },
315 { "gcse", 'G', 1, 0, 0 },
316 { "loop", 'L', 1, 0, 0 },
317 { "bypass", 'G', 1, 0, 0 }, /* Yes, duplicate enable switch. */
318 { "cfg", 'f', 1, 0, 0 },
319 { "bp", 'b', 1, 0, 0 },
320 { "ce1", 'C', 1, 0, 0 },
321 { "tracer", 'T', 1, 0, 0 },
322 { "loop2", 'L', 1, 0, 0 },
323 { "cse2", 't', 1, 0, 0 },
324 { "life", 'f', 1, 0, 0 }, /* Yes, duplicate enable switch. */
325 { "combine", 'c', 1, 0, 0 },
326 { "ce2", 'C', 1, 0, 0 },
327 { "regmove", 'N', 1, 0, 0 },
328 { "sched", 'S', 1, 0, 0 },
329 { "lreg", 'l', 1, 0, 0 },
330 { "greg", 'g', 1, 0, 0 },
331 { "postreload", 'o', 1, 0, 0 },
332 { "flow2", 'w', 1, 0, 0 },
333 { "peephole2", 'z', 1, 0, 0 },
334 { "rnreg", 'n', 1, 0, 0 },
335 { "bbro", 'B', 1, 0, 0 },
336 { "ce3", 'E', 1, 0, 0 },
337 { "btl", 'd', 1, 0, 0 }, /* Yes, duplicate enable switch. */
338 { "sched2", 'R', 1, 0, 0 },
339 { "stack", 'k', 1, 0, 0 },
340 { "mach", 'M', 1, 0, 0 },
341 { "dbr", 'd', 0, 0, 0 },
344 static int open_dump_file (enum dump_file_index
, tree
);
345 static void close_dump_file (enum dump_file_index
,
346 void (*) (FILE *, rtx
), rtx
);
348 /* Other flags saying which kinds of debugging dump have been requested. */
350 int rtl_dump_and_exit
;
351 int flag_print_asm_name
;
352 enum graph_dump_types graph_dump_format
;
354 /* Name for output file of assembly code, specified with -o. */
356 const char *asm_file_name
;
358 /* Nonzero means do optimizations. -O.
359 Particular numeric values stand for particular amounts of optimization;
360 thus, -O2 stores 2 here. However, the optimizations beyond the basic
361 ones are not controlled directly by this variable. Instead, they are
362 controlled by individual `flag_...' variables that are defaulted
363 based on this variable. */
367 /* Nonzero means optimize for size. -Os.
368 The only valid values are zero and nonzero. When optimize_size is
369 nonzero, optimize defaults to 2, but certain individual code
370 bloating optimizations are disabled. */
372 int optimize_size
= 0;
374 /* The FUNCTION_DECL for the function currently being compiled,
375 or 0 if between functions. */
376 tree current_function_decl
;
378 /* Set to the FUNC_BEGIN label of the current function, or NULL_TREE
380 tree current_function_func_begin_label
;
382 /* Nonzero if doing dwarf2 duplicate elimination. */
384 int flag_eliminate_dwarf2_dups
= 0;
386 /* Nonzero if doing unused type elimination. */
388 int flag_eliminate_unused_debug_types
= 1;
390 /* Nonzero means emit debugging information only for symbols which are used. */
391 int flag_debug_only_used_symbols
= 0;
393 /* Nonzero if generating code to do profiling. */
395 int profile_flag
= 0;
397 /* Nonzero if generating code to profile program flow graph arcs. */
399 int profile_arc_flag
= 0;
401 /* Nonzero if value histograms should be measured. */
403 int flag_profile_values
= 0;
405 /* Nonzero if generating info for gcov to calculate line test coverage. */
407 int flag_test_coverage
= 0;
409 /* Nonzero indicates that branch taken probabilities should be calculated. */
411 int flag_branch_probabilities
= 0;
413 /* Nonzero if basic blocks should be reordered. */
415 int flag_reorder_blocks
= 0;
417 /* Nonzero if functions should be reordered. */
419 int flag_reorder_functions
= 0;
421 /* Nonzero if registers should be renamed. */
423 int flag_rename_registers
= 0;
424 int flag_cprop_registers
= 0;
426 /* Nonzero for -pedantic switch: warn about anything
427 that standard spec forbids. */
431 /* Temporarily suppress certain warnings.
432 This is set while reading code from a system header file. */
434 int in_system_header
= 0;
436 /* Don't print functions as they are compiled. -quiet. */
440 /* Print times taken by the various passes. -ftime-report. */
444 /* Print memory still in use at end of compilation (which may have little
445 to do with peak memory consumption). -fmem-report. */
449 /* Nonzero means to collect statistics which might be expensive
450 and to print them when we are done. */
451 int flag_detailed_statistics
= 0;
453 /* A random sequence of characters, unless overridden by user. */
454 const char *flag_random_seed
;
456 /* A local time stamp derived from the time of compilation. It will be
457 zero if the system cannot provide a time. It will be -1u, if the
458 user has specified a particular random seed. */
463 /* Nonzero means `char' should be signed. */
465 int flag_signed_char
;
467 /* Nonzero means give an enum type only as many bytes as it needs. */
469 int flag_short_enums
;
471 /* Nonzero for -fcaller-saves: allocate values in regs that need to
472 be saved across function calls, if that produces overall better code.
473 Optional now, so people can test it. */
475 #ifdef DEFAULT_CALLER_SAVES
476 int flag_caller_saves
= 1;
478 int flag_caller_saves
= 0;
481 /* Nonzero if structures and unions should be returned in memory.
483 This should only be defined if compatibility with another compiler or
484 with an ABI is needed, because it results in slower code. */
486 #ifndef DEFAULT_PCC_STRUCT_RETURN
487 #define DEFAULT_PCC_STRUCT_RETURN 1
490 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
492 int flag_pcc_struct_return
= DEFAULT_PCC_STRUCT_RETURN
;
494 /* Nonzero for -fforce-mem: load memory value into a register
495 before arithmetic on it. This makes better cse but slower compilation. */
497 int flag_force_mem
= 0;
499 /* Nonzero for -fforce-addr: load memory address into a register before
500 reference to memory. This makes better cse but slower compilation. */
502 int flag_force_addr
= 0;
504 /* Nonzero for -fdefer-pop: don't pop args after each function call;
505 instead save them up to pop many calls' args with one insns. */
507 int flag_defer_pop
= 0;
509 /* Nonzero for -ffloat-store: don't allocate floats and doubles
510 in extended-precision registers. */
512 int flag_float_store
= 0;
514 /* Nonzero for -fcse-follow-jumps:
515 have cse follow jumps to do a more extensive job. */
517 int flag_cse_follow_jumps
;
519 /* Nonzero for -fcse-skip-blocks:
520 have cse follow a branch around a block. */
521 int flag_cse_skip_blocks
;
523 /* Nonzero for -fexpensive-optimizations:
524 perform miscellaneous relatively-expensive optimizations. */
525 int flag_expensive_optimizations
;
527 /* Nonzero for -fthread-jumps:
528 have jump optimize output of loop. */
530 int flag_thread_jumps
;
532 /* Nonzero enables strength-reduction in loop.c. */
534 int flag_strength_reduce
= 0;
536 /* Nonzero enables loop unrolling in unroll.c. Only loops for which the
537 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
538 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
541 int flag_old_unroll_loops
;
543 /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
544 This is generally not a win. */
546 int flag_old_unroll_all_loops
;
548 /* Enables unrolling of simple loops in loop-unroll.c. */
549 int flag_unroll_loops
;
551 /* Enables unrolling of all loops in loop-unroll.c. */
552 int flag_unroll_all_loops
;
554 /* Nonzero enables loop peeling. */
557 /* Nonzero enables loop unswitching. */
558 int flag_unswitch_loops
;
560 /* Nonzero enables prefetch optimizations for arrays in loops. */
562 int flag_prefetch_loop_arrays
;
564 /* Nonzero forces all invariant computations in loops to be moved
567 int flag_move_all_movables
= 0;
569 /* Nonzero forces all general induction variables in loops to be
572 int flag_reduce_all_givs
= 0;
574 /* Nonzero to perform full register move optimization passes. This is the
577 int flag_regmove
= 0;
579 /* Nonzero for -fwritable-strings:
580 store string constants in data segment and don't uniquize them. */
582 int flag_writable_strings
= 0;
584 /* Nonzero means don't put addresses of constant functions in registers.
585 Used for compiling the Unix kernel, where strange substitutions are
586 done on the assembly output. */
588 int flag_no_function_cse
= 0;
590 /* Nonzero for -fomit-frame-pointer:
591 don't make a frame pointer in simple functions that don't require one. */
593 int flag_omit_frame_pointer
= 0;
595 /* Nonzero means place each function into its own section on those platforms
596 which support arbitrary section names and unlimited numbers of sections. */
598 int flag_function_sections
= 0;
600 /* ... and similar for data. */
602 int flag_data_sections
= 0;
604 /* Nonzero to inhibit use of define_optimization peephole opts. */
606 int flag_no_peephole
= 0;
608 /* Nonzero allows GCC to optimize sibling and tail recursive calls. */
610 int flag_optimize_sibling_calls
= 0;
612 /* Nonzero means the front end generally wants `errno' maintained by math
613 operations, like built-in SQRT. */
615 int flag_errno_math
= 1;
617 /* Nonzero means that unsafe floating-point math optimizations are allowed
618 for the sake of speed. IEEE compliance is not guaranteed, and operations
619 are allowed to assume that their arguments and results are "normal"
620 (e.g., nonnegative for SQRT). */
622 int flag_unsafe_math_optimizations
= 0;
624 /* Nonzero means that no NaNs or +-Infs are expected. */
626 int flag_finite_math_only
= 0;
628 /* Zero means that floating-point math operations cannot generate a
629 (user-visible) trap. This is the case, for example, in nonstop
630 IEEE 754 arithmetic. Trapping conditions include division by zero,
631 overflow, underflow, invalid and inexact, but does not include
632 operations on signaling NaNs (see below). */
634 int flag_trapping_math
= 1;
636 /* Nonzero means disable transformations observable by signaling NaNs.
637 This option implies that any operation on an IEEE signaling NaN can
638 generate a (user-visible) trap. */
640 int flag_signaling_nans
= 0;
642 /* 0 means straightforward implementation of complex divide acceptable.
643 1 means wide ranges of inputs must work for complex divide.
644 2 means C99-like requirements for complex divide (not yet implemented). */
646 int flag_complex_divide_method
= 0;
648 /* Nonzero means just do syntax checking; don't output anything. */
650 int flag_syntax_only
= 0;
652 /* Nonzero means perform loop optimizer. */
654 int flag_loop_optimize
;
656 /* Nonzero means perform crossjumping. */
658 int flag_crossjumping
;
660 /* Nonzero means perform if conversion. */
662 int flag_if_conversion
;
664 /* Nonzero means perform if conversion after reload. */
666 int flag_if_conversion2
;
668 /* Nonzero means to use global dataflow analysis to eliminate
669 useless null pointer tests. */
671 int flag_delete_null_pointer_checks
;
673 /* Nonzero means perform global CSE. */
677 /* Nonzero means to do the enhanced load motion during gcse, which trys
678 to hoist loads by not killing them when a store to the same location
681 int flag_gcse_lm
= 1;
683 /* Nonzero means to perform store motion after gcse, which will try to
684 move stores closer to the exit block. Its not very effective without
687 int flag_gcse_sm
= 1;
689 /* Perform target register optimization before prologue / epilogue
692 int flag_branch_target_load_optimize
= 0;
694 /* Perform target register optimization after prologue / epilogue
695 threading and jump2. */
697 int flag_branch_target_load_optimize2
= 0;
699 /* Nonzero means to rerun cse after loop optimization. This increases
700 compilation time about 20% and picks up a few more common expressions. */
702 int flag_rerun_cse_after_loop
;
704 /* Nonzero means to run loop optimizations twice. */
706 int flag_rerun_loop_opt
;
708 /* Nonzero for -finline-functions: ok to inline functions that look like
709 good inline candidates. */
711 int flag_inline_functions
;
713 /* Nonzero for -fkeep-inline-functions: even if we make a function
714 go inline everywhere, keep its definition around for debugging
717 int flag_keep_inline_functions
;
719 /* Nonzero means that functions will not be inlined. */
721 int flag_no_inline
= 2;
723 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
724 not just because the tree inliner turned us off. */
726 int flag_really_no_inline
= 2;
728 /* Nonzero means that we should emit static const variables
729 regardless of whether or not optimization is turned on. */
731 int flag_keep_static_consts
= 1;
733 /* Nonzero means we should be saving declaration info into a .X file. */
735 int flag_gen_aux_info
= 0;
737 /* Specified name of aux-info file. */
739 const char *aux_info_file_name
;
741 /* Nonzero means make the text shared if supported. */
743 int flag_shared_data
;
745 /* Nonzero means schedule into delayed branch slots if supported. */
747 int flag_delayed_branch
;
749 /* Nonzero if we are compiling pure (sharable) code.
750 Value is 1 if we are doing "small" pic; value is 2 if we're doing
755 /* Nonzero if we are compiling position independent code for executable.
756 The value is 1 if we are doing "small" pic; value is 2 if we're doing
761 /* Nonzero if we are compiling code for a shared library, zero for
766 /* Set to the default thread-local storage (tls) model to use. */
768 enum tls_model flag_tls_default
= TLS_MODEL_GLOBAL_DYNAMIC
;
770 /* Nonzero means generate extra code for exception handling and enable
771 exception handling. */
775 /* Nonzero means generate frame unwind info table when supported. */
777 int flag_unwind_tables
= 0;
779 /* Nonzero means generate frame unwind info table exact at each insn
782 int flag_asynchronous_unwind_tables
= 0;
784 /* Nonzero means don't place uninitialized global data in common storage
789 /* Nonzero means change certain warnings into errors.
790 Usually these are warnings about failure to conform to some standard. */
792 int flag_pedantic_errors
= 0;
794 /* flag_schedule_insns means schedule insns within basic blocks (before
796 flag_schedule_insns_after_reload means schedule insns after
799 int flag_schedule_insns
= 0;
800 int flag_schedule_insns_after_reload
= 0;
802 /* When flag_schedule_insns_after_reload is set, use EBB scheduler. */
803 int flag_sched2_use_superblocks
= 0;
805 /* When flag_schedule_insns_after_reload is set, construct traces and EBB
807 int flag_sched2_use_traces
= 0;
809 /* The following flags have effect only for scheduling before register
812 flag_schedule_interblock means schedule insns across basic blocks.
813 flag_schedule_speculative means allow speculative motion of non-load insns.
814 flag_schedule_speculative_load means allow speculative motion of some
816 flag_schedule_speculative_load_dangerous allows speculative motion of more
819 int flag_schedule_interblock
= 1;
820 int flag_schedule_speculative
= 1;
821 int flag_schedule_speculative_load
= 0;
822 int flag_schedule_speculative_load_dangerous
= 0;
824 int flag_single_precision_constant
;
826 /* flag_branch_on_count_reg means try to replace add-1,compare,branch tupple
827 by a cheaper branch on a count register. */
828 int flag_branch_on_count_reg
= 1;
830 /* -finhibit-size-directive inhibits output of .size for ELF.
831 This is used only for compiling crtstuff.c,
832 and it may be extended to other effects
833 needed for crtstuff.c on other systems. */
834 int flag_inhibit_size_directive
= 0;
836 /* -fverbose-asm causes extra commentary information to be produced in
837 the generated assembly code (to make it more readable). This option
838 is generally only of use to those who actually need to read the
839 generated assembly code (perhaps while debugging the compiler itself).
840 -fno-verbose-asm, the default, causes the extra information
841 to be omitted and is useful when comparing two assembler files. */
843 int flag_verbose_asm
= 0;
845 /* -dA causes debug commentary information to be produced in
846 the generated assembly code (to make it more readable). This option
847 is generally only of use to those who actually need to read the
848 generated assembly code (perhaps while debugging the compiler itself).
849 Currently, this switch is only used by dwarfout.c; however, it is intended
850 to be a catchall for printing debug information in the assembler file. */
852 int flag_debug_asm
= 0;
854 /* -dP causes the rtl to be emitted as a comment in assembly. */
856 int flag_dump_rtl_in_asm
= 0;
858 /* -fgnu-linker specifies use of the GNU linker for initializations.
859 (Or, more generally, a linker that handles initializations.)
860 -fno-gnu-linker says that collect2 will be used. */
862 int flag_gnu_linker
= 0;
864 int flag_gnu_linker
= 1;
867 /* Nonzero means put zero initialized data in the bss section. */
868 int flag_zero_initialized_in_bss
= 1;
873 /* Enable ssa conditional constant propagation. */
874 int flag_ssa_ccp
= 0;
876 /* Enable ssa aggressive dead code elimination. */
877 int flag_ssa_dce
= 0;
879 /* Tag all structures with __attribute__(packed). */
880 int flag_pack_struct
= 0;
882 /* Emit code to check for stack overflow; also may cause large objects
883 to be allocated dynamically. */
884 int flag_stack_check
;
886 /* When non-NULL, indicates that whenever space is allocated on the
887 stack, the resulting stack pointer must not pass this
888 address---that is, for stacks that grow downward, the stack pointer
889 must always be greater than or equal to this address; for stacks
890 that grow upward, the stack pointer must be less than this address.
891 At present, the rtx may be either a REG or a SYMBOL_REF, although
892 the support provided depends on the backend. */
895 /* 0 if pointer arguments may alias each other. True in C.
896 1 if pointer arguments may not alias each other but may alias
898 2 if pointer arguments may not alias each other and may not
899 alias global variables. True in Fortran.
900 This defaults to 0 for C. */
901 int flag_argument_noalias
= 0;
903 /* Nonzero if we should do (language-dependent) alias analysis.
904 Typically, this analysis will assume that expressions of certain
905 types do not alias expressions of certain other types. Only used
906 if alias analysis (in general) is enabled. */
907 int flag_strict_aliasing
= 0;
909 /* Instrument functions with calls at entry and exit, for profiling. */
910 int flag_instrument_function_entry_exit
= 0;
912 /* Nonzero means ignore `#ident' directives. 0 means handle them.
913 On SVR4 targets, it also controls whether or not to emit a
914 string identifying the compiler. */
916 int flag_no_ident
= 0;
918 /* This will perform a peephole pass before sched2. */
919 int flag_peephole2
= 0;
921 /* This will try to guess branch probabilities. */
922 int flag_guess_branch_prob
= 0;
924 /* -fcheck-bounds causes gcc to generate array bounds checks.
925 For C, C++, ObjC: defaults to off.
926 For Java: defaults to on.
927 For Fortran: defaults to off. */
928 int flag_bounds_check
= 0;
930 /* This will attempt to merge constant section constants, if 1 only
931 string constants and constants from constant pool, if 2 also constant
933 int flag_merge_constants
= 1;
935 /* If one, renumber instruction UIDs to reduce the number of
936 unused UIDs if there are a lot of instructions. If greater than
937 one, unconditionally renumber instruction UIDs. */
938 int flag_renumber_insns
= 1;
940 /* If nonzero, use the graph coloring register allocator. */
941 int flag_new_regalloc
= 0;
943 /* Nonzero if we perform superblock formation. */
947 /* Nonzero if we perform whole unit at a time compilation. */
949 int flag_unit_at_a_time
= 0;
951 /* Values of the -falign-* flags: how much to align labels in code.
952 0 means `use default', 1 means `don't align'.
953 For each variable, there is an _log variant which is the power
954 of two not less than the variable, for .align output. */
958 int align_loops_max_skip
;
961 int align_jumps_max_skip
;
963 int align_labels_log
;
964 int align_labels_max_skip
;
966 int align_functions_log
;
968 /* Like align_functions_log above, but used by front-ends to force the
969 minimum function alignment. Zero means no alignment is forced. */
970 int force_align_functions_log
;
974 const char *const string
;
978 lang_independent_options
;
980 /* Nonzero if signed arithmetic overflow should trap. */
983 /* Nonzero if signed arithmetic overflow should wrap around. */
986 /* Add or remove a leading underscore from user symbols. */
987 int flag_leading_underscore
= -1;
989 /* The user symbol prefix after having resolved same. */
990 const char *user_label_prefix
;
992 static const param_info lang_independent_params
[] = {
993 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT) \
994 { OPTION, DEFAULT, HELP },
995 #include "params.def"
1000 /* Table of language-independent -f options.
1001 STRING is the option name. VARIABLE is the address of the variable.
1002 ON_VALUE is the value to store in VARIABLE
1003 if `-fSTRING' is seen as an option.
1004 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
1006 static const lang_independent_options f_options
[] =
1008 {"eliminate-dwarf2-dups", &flag_eliminate_dwarf2_dups
, 1 },
1009 {"eliminate-unused-debug-symbols", &flag_debug_only_used_symbols
, 1 },
1010 {"eliminate-unused-debug-types", &flag_eliminate_unused_debug_types
, 1 },
1011 {"float-store", &flag_float_store
, 1 },
1012 {"defer-pop", &flag_defer_pop
, 1 },
1013 {"omit-frame-pointer", &flag_omit_frame_pointer
, 1 },
1014 {"optimize-sibling-calls", &flag_optimize_sibling_calls
, 1 },
1015 {"tracer", &flag_tracer
, 1 },
1016 {"unit-at-a-time", &flag_unit_at_a_time
, 1 },
1017 {"cse-follow-jumps", &flag_cse_follow_jumps
, 1 },
1018 {"cse-skip-blocks", &flag_cse_skip_blocks
, 1 },
1019 {"expensive-optimizations", &flag_expensive_optimizations
, 1 },
1020 {"thread-jumps", &flag_thread_jumps
, 1 },
1021 {"strength-reduce", &flag_strength_reduce
, 1 },
1022 {"unroll-loops", &flag_unroll_loops
, 1 },
1023 {"unroll-all-loops", &flag_unroll_all_loops
, 1 },
1024 {"old-unroll-loops", &flag_old_unroll_loops
, 1 },
1025 {"old-unroll-all-loops", &flag_old_unroll_all_loops
, 1 },
1026 {"peel-loops", &flag_peel_loops
, 1 },
1027 {"unswitch-loops", &flag_unswitch_loops
, 1 },
1028 {"prefetch-loop-arrays", &flag_prefetch_loop_arrays
, 1 },
1029 {"move-all-movables", &flag_move_all_movables
, 1 },
1030 {"reduce-all-givs", &flag_reduce_all_givs
, 1 },
1031 {"writable-strings", &flag_writable_strings
, 1 },
1032 {"peephole", &flag_no_peephole
, 0 },
1033 {"force-mem", &flag_force_mem
, 1 },
1034 {"force-addr", &flag_force_addr
, 1 },
1035 {"function-cse", &flag_no_function_cse
, 0 },
1036 {"inline-functions", &flag_inline_functions
, 1 },
1037 {"keep-inline-functions", &flag_keep_inline_functions
, 1 },
1038 {"inline", &flag_no_inline
, 0 },
1039 {"keep-static-consts", &flag_keep_static_consts
, 1 },
1040 {"syntax-only", &flag_syntax_only
, 1 },
1041 {"shared-data", &flag_shared_data
, 1 },
1042 {"caller-saves", &flag_caller_saves
, 1 },
1043 {"pcc-struct-return", &flag_pcc_struct_return
, 1 },
1044 {"reg-struct-return", &flag_pcc_struct_return
, 0 },
1045 {"delayed-branch", &flag_delayed_branch
, 1 },
1046 {"gcse", &flag_gcse
, 1 },
1047 {"gcse-lm", &flag_gcse_lm
, 1 },
1048 {"gcse-sm", &flag_gcse_sm
, 1 },
1049 {"branch-target-load-optimize", &flag_branch_target_load_optimize
, 1 },
1050 {"branch-target-load-optimize2", &flag_branch_target_load_optimize2
, 1 },
1051 {"loop-optimize", &flag_loop_optimize
, 1 },
1052 {"crossjumping", &flag_crossjumping
, 1 },
1053 {"if-conversion", &flag_if_conversion
, 1 },
1054 {"if-conversion2", &flag_if_conversion2
, 1 },
1055 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop
, 1 },
1056 {"rerun-loop-opt", &flag_rerun_loop_opt
, 1 },
1057 {"delete-null-pointer-checks", &flag_delete_null_pointer_checks
, 1 },
1058 {"schedule-insns", &flag_schedule_insns
, 1 },
1059 {"schedule-insns2", &flag_schedule_insns_after_reload
, 1 },
1060 {"sched-interblock",&flag_schedule_interblock
, 1 },
1061 {"sched-spec",&flag_schedule_speculative
, 1 },
1062 {"sched-spec-load",&flag_schedule_speculative_load
, 1 },
1063 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous
, 1 },
1064 {"sched2-use-superblocks", &flag_sched2_use_superblocks
, 1 },
1065 {"sched2-use-traces", &flag_sched2_use_traces
, 1 },
1066 {"branch-count-reg",&flag_branch_on_count_reg
, 1 },
1067 {"pic", &flag_pic
, 1 },
1068 {"PIC", &flag_pic
, 2 },
1069 {"pie", &flag_pie
, 1 },
1070 {"PIE", &flag_pie
, 2 },
1071 {"exceptions", &flag_exceptions
, 1 },
1072 {"unwind-tables", &flag_unwind_tables
, 1 },
1073 {"asynchronous-unwind-tables", &flag_asynchronous_unwind_tables
, 1 },
1074 {"non-call-exceptions", &flag_non_call_exceptions
, 1 },
1075 {"profile-arcs", &profile_arc_flag
, 1 },
1076 {"test-coverage", &flag_test_coverage
, 1 },
1077 {"branch-probabilities", &flag_branch_probabilities
, 1 },
1078 {"profile", &profile_flag
, 1 },
1079 {"reorder-blocks", &flag_reorder_blocks
, 1 },
1080 {"reorder-functions", &flag_reorder_functions
, 1 },
1081 {"rename-registers", &flag_rename_registers
, 1 },
1082 {"cprop-registers", &flag_cprop_registers
, 1 },
1083 {"common", &flag_no_common
, 0 },
1084 {"inhibit-size-directive", &flag_inhibit_size_directive
, 1 },
1085 {"function-sections", &flag_function_sections
, 1 },
1086 {"data-sections", &flag_data_sections
, 1 },
1087 {"verbose-asm", &flag_verbose_asm
, 1 },
1088 {"gnu-linker", &flag_gnu_linker
, 1 },
1089 {"regmove", &flag_regmove
, 1 },
1090 {"optimize-register-move", &flag_regmove
, 1 },
1091 {"pack-struct", &flag_pack_struct
, 1 },
1092 {"stack-check", &flag_stack_check
, 1 },
1093 {"argument-alias", &flag_argument_noalias
, 0 },
1094 {"argument-noalias", &flag_argument_noalias
, 1 },
1095 {"argument-noalias-global", &flag_argument_noalias
, 2 },
1096 {"strict-aliasing", &flag_strict_aliasing
, 1 },
1097 {"align-loops", &align_loops
, 0 },
1098 {"align-jumps", &align_jumps
, 0 },
1099 {"align-labels", &align_labels
, 0 },
1100 {"align-functions", &align_functions
, 0 },
1101 {"merge-constants", &flag_merge_constants
, 1 },
1102 {"merge-all-constants", &flag_merge_constants
, 2 },
1103 {"dump-unnumbered", &flag_dump_unnumbered
, 1 },
1104 {"instrument-functions", &flag_instrument_function_entry_exit
, 1 },
1105 {"zero-initialized-in-bss", &flag_zero_initialized_in_bss
, 1 },
1106 {"ssa", &flag_ssa
, 1 },
1107 {"ssa-ccp", &flag_ssa_ccp
, 1 },
1108 {"ssa-dce", &flag_ssa_dce
, 1 },
1109 {"leading-underscore", &flag_leading_underscore
, 1 },
1110 {"ident", &flag_no_ident
, 0 },
1111 { "peephole2", &flag_peephole2
, 1 },
1112 {"finite-math-only", &flag_finite_math_only
, 1 },
1113 { "guess-branch-probability", &flag_guess_branch_prob
, 1 },
1114 {"math-errno", &flag_errno_math
, 1 },
1115 {"trapping-math", &flag_trapping_math
, 1 },
1116 {"unsafe-math-optimizations", &flag_unsafe_math_optimizations
, 1 },
1117 {"signaling-nans", &flag_signaling_nans
, 1 },
1118 {"bounds-check", &flag_bounds_check
, 1 },
1119 {"single-precision-constant", &flag_single_precision_constant
, 1 },
1120 {"time-report", &time_report
, 1 },
1121 {"mem-report", &mem_report
, 1 },
1122 { "trapv", &flag_trapv
, 1 },
1123 { "wrapv", &flag_wrapv
, 1 },
1124 { "new-ra", &flag_new_regalloc
, 1 }
1127 /* Here is a table, controlled by the tm.h file, listing each -m switch
1128 and which bits in `target_switches' it should set or clear.
1129 If VALUE is positive, it is bits to set.
1130 If VALUE is negative, -VALUE is bits to clear.
1131 (The sign bit is not used so there is no confusion.) */
1135 const char *const name
;
1137 const char *const description
;
1139 target_switches
[] = TARGET_SWITCHES
;
1141 /* This table is similar, but allows the switch to have a value. */
1143 #ifdef TARGET_OPTIONS
1146 const char *const prefix
;
1147 const char **const variable
;
1148 const char *const description
;
1149 const char *const value
;
1151 target_options
[] = TARGET_OPTIONS
;
1154 /* Nonzero means warn about function definitions that default the return type
1155 or that use a null return and have a return-type other than void. */
1157 int warn_return_type
;
1159 /* Output files for assembler code (real compiler output)
1160 and debugging dumps. */
1163 FILE *aux_info_file
;
1164 FILE *rtl_dump_file
= NULL
;
1165 FILE *cgraph_dump_file
= NULL
;
1167 /* The current working directory of a translation. It's generally the
1168 directory from which compilation was initiated, but a preprocessed
1169 file may specify the original directory in which it was
1172 static const char *src_pwd
;
1174 /* Initialize src_pwd with the given string, and return true. If it
1175 was already initialized, return false. As a special case, it may
1176 be called with a NULL argument to test whether src_pwd has NOT been
1180 set_src_pwd (const char *pwd
)
1185 src_pwd
= xstrdup (pwd
);
1189 /* Return the directory from which the translation unit was initiated,
1190 in case set_src_pwd() was not called before to assign it a
1197 src_pwd
= getpwd ();
1202 /* Set up a default flag_random_seed and local_tick, unless the user
1203 already specified one. */
1208 if (!flag_random_seed
)
1210 unsigned HOST_WIDE_INT value
;
1211 static char random_seed
[HOST_BITS_PER_WIDE_INT
/ 4 + 3];
1213 /* Get some more or less random data. */
1214 #ifdef HAVE_GETTIMEOFDAY
1218 gettimeofday (&tv
, NULL
);
1219 local_tick
= tv
.tv_sec
* 1000 + tv
.tv_usec
/ 1000;
1223 time_t now
= time (NULL
);
1225 if (now
!= (time_t)-1)
1226 local_tick
= (unsigned) now
;
1229 value
= local_tick
^ getpid ();
1231 sprintf (random_seed
, HOST_WIDE_INT_PRINT_HEX
, value
);
1232 flag_random_seed
= random_seed
;
1234 else if (!local_tick
)
1239 /* Decode the string P as an integral parameter.
1240 If the string is indeed an integer return its numeric value else
1241 issue an Invalid Option error for the option PNAME and return DEFVAL.
1242 If PNAME is zero just return DEFVAL, do not call error. */
1245 read_integral_parameter (const char *p
, const char *pname
, const int defval
)
1247 const char *endp
= p
;
1251 if (ISDIGIT (*endp
))
1260 error ("invalid option argument `%s'", pname
);
1267 /* Return the logarithm of X, base 2, considering X unsigned,
1268 if X is a power of 2. Otherwise, returns -1.
1270 This should be used via the `exact_log2' macro. */
1273 exact_log2_wide (unsigned HOST_WIDE_INT x
)
1276 /* Test for 0 or a power of 2. */
1277 if (x
== 0 || x
!= (x
& -x
))
1279 while ((x
>>= 1) != 0)
1284 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1285 If X is 0, return -1.
1287 This should be used via the floor_log2 macro. */
1290 floor_log2_wide (unsigned HOST_WIDE_INT x
)
1299 /* Handler for fatal signals, such as SIGSEGV. These are transformed
1300 into ICE messages, which is much more user friendly. In case the
1301 error printer crashes, reset the signal to prevent infinite recursion. */
1304 crash_signal (int signo
)
1306 signal (signo
, SIG_DFL
);
1307 internal_error ("%s", strsignal (signo
));
1310 /* Arrange to dump core on error. (The regular error message is still
1311 printed first, except in the case of abort().) */
1314 setup_core_dumping (void)
1317 signal (SIGABRT
, SIG_DFL
);
1319 #if defined(HAVE_SETRLIMIT)
1322 if (getrlimit (RLIMIT_CORE
, &rlim
) != 0)
1323 fatal_error ("getting core file size maximum limit: %m");
1324 rlim
.rlim_cur
= rlim
.rlim_max
;
1325 if (setrlimit (RLIMIT_CORE
, &rlim
) != 0)
1326 fatal_error ("setting core file size limit to maximum: %m");
1329 diagnostic_abort_on_error (global_dc
);
1333 /* Strip off a legitimate source ending from the input string NAME of
1334 length LEN. Rather than having to know the names used by all of
1335 our front ends, we strip off an ending of a period followed by
1336 up to five characters. (Java uses ".class".) */
1339 strip_off_ending (char *name
, int len
)
1342 for (i
= 2; i
< 6 && len
> i
; i
++)
1344 if (name
[len
- i
] == '.')
1346 name
[len
- i
] = '\0';
1352 /* Output a quoted string. */
1355 output_quoted_string (FILE *asm_file
, const char *string
)
1357 #ifdef OUTPUT_QUOTED_STRING
1358 OUTPUT_QUOTED_STRING (asm_file
, string
);
1362 putc ('\"', asm_file
);
1363 while ((c
= *string
++) != 0)
1367 if (c
== '\"' || c
== '\\')
1368 putc ('\\', asm_file
);
1372 fprintf (asm_file
, "\\%03o", (unsigned char) c
);
1374 putc ('\"', asm_file
);
1378 /* Output a file name in the form wanted by System V. */
1381 output_file_directive (FILE *asm_file
, const char *input_name
)
1383 int len
= strlen (input_name
);
1384 const char *na
= input_name
+ len
;
1386 /* NA gets INPUT_NAME sans directory names. */
1387 while (na
> input_name
)
1389 if (IS_DIR_SEPARATOR (na
[-1]))
1394 #ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
1395 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file
, na
);
1397 #ifdef ASM_OUTPUT_SOURCE_FILENAME
1398 ASM_OUTPUT_SOURCE_FILENAME (asm_file
, na
);
1400 fprintf (asm_file
, "\t.file\t");
1401 output_quoted_string (asm_file
, na
);
1402 fputc ('\n', asm_file
);
1407 /* Routine to open a dump file. Return true if the dump file is enabled. */
1410 open_dump_file (enum dump_file_index index
, tree decl
)
1413 const char *open_arg
;
1416 if (! dump_file
[index
].enabled
)
1419 timevar_push (TV_DUMP
);
1420 if (rtl_dump_file
!= NULL
)
1421 fclose (rtl_dump_file
);
1423 sprintf (seq
, DUMPFILE_FORMAT
, index
);
1425 if (! dump_file
[index
].initialized
)
1427 /* If we've not initialized the files, do so now. */
1428 if (graph_dump_format
!= no_graph
1429 && dump_file
[index
].graph_dump_p
)
1431 dump_name
= concat (seq
, dump_file
[index
].extension
, NULL
);
1432 clean_graph_dump_file (dump_base_name
, dump_name
);
1435 dump_file
[index
].initialized
= 1;
1441 dump_name
= concat (dump_base_name
, seq
,
1442 dump_file
[index
].extension
, NULL
);
1444 rtl_dump_file
= fopen (dump_name
, open_arg
);
1445 if (rtl_dump_file
== NULL
)
1446 fatal_error ("can't open %s: %m", dump_name
);
1451 fprintf (rtl_dump_file
, "\n;; Function %s%s\n\n",
1452 (*lang_hooks
.decl_printable_name
) (decl
, 2),
1453 cfun
->function_frequency
== FUNCTION_FREQUENCY_HOT
1455 : cfun
->function_frequency
== FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
1456 ? " (unlikely executed)"
1459 timevar_pop (TV_DUMP
);
1463 /* Routine to close a dump file. */
1466 close_dump_file (enum dump_file_index index
,
1467 void (*func
) (FILE *, rtx
),
1470 if (! rtl_dump_file
)
1473 timevar_push (TV_DUMP
);
1475 && graph_dump_format
!= no_graph
1476 && dump_file
[index
].graph_dump_p
)
1481 sprintf (seq
, DUMPFILE_FORMAT
, index
);
1482 suffix
= concat (seq
, dump_file
[index
].extension
, NULL
);
1483 print_rtl_graph_with_bb (dump_base_name
, suffix
, insns
);
1488 func (rtl_dump_file
, insns
);
1490 fflush (rtl_dump_file
);
1491 fclose (rtl_dump_file
);
1493 rtl_dump_file
= NULL
;
1494 timevar_pop (TV_DUMP
);
1497 /* Do any final processing required for the declarations in VEC, of
1498 which there are LEN. We write out inline functions and variables
1499 that have been deferred until this point, but which are required.
1500 Returns nonzero if anything was put out. */
1503 wrapup_global_declarations (tree
*vec
, int len
)
1508 int output_something
= 0;
1510 for (i
= 0; i
< len
; i
++)
1514 /* We're not deferring this any longer. Assignment is
1515 conditional to avoid needlessly dirtying PCH pages. */
1516 if (DECL_DEFER_OUTPUT (decl
) != 0)
1517 DECL_DEFER_OUTPUT (decl
) = 0;
1519 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_SIZE (decl
) == 0)
1520 (*lang_hooks
.finish_incomplete_decl
) (decl
);
1523 /* Now emit any global variables or functions that we have been
1524 putting off. We need to loop in case one of the things emitted
1525 here references another one which comes earlier in the list. */
1529 for (i
= 0; i
< len
; i
++)
1533 if (TREE_ASM_WRITTEN (decl
) || DECL_EXTERNAL (decl
))
1536 /* Don't write out static consts, unless we still need them.
1538 We also keep static consts if not optimizing (for debugging),
1539 unless the user specified -fno-keep-static-consts.
1540 ??? They might be better written into the debug information.
1541 This is possible when using DWARF.
1543 A language processor that wants static constants to be always
1544 written out (even if it is not used) is responsible for
1545 calling rest_of_decl_compilation itself. E.g. the C front-end
1546 calls rest_of_decl_compilation from finish_decl.
1547 One motivation for this is that is conventional in some
1548 environments to write things like:
1549 static const char rcsid[] = "... version string ...";
1550 intending to force the string to be in the executable.
1552 A language processor that would prefer to have unneeded
1553 static constants "optimized away" would just defer writing
1554 them out until here. E.g. C++ does this, because static
1555 constants are often defined in header files.
1557 ??? A tempting alternative (for both C and C++) would be
1558 to force a constant to be written if and only if it is
1559 defined in a main file, as opposed to an include file. */
1561 if (TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
1565 if (flag_unit_at_a_time
1566 && cgraph_varpool_node (decl
)->finalized
)
1568 else if (flag_unit_at_a_time
1569 && (TREE_USED (decl
)
1570 || TREE_USED (DECL_ASSEMBLER_NAME (decl
))))
1572 else if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
)))
1574 else if (DECL_COMDAT (decl
))
1576 else if (TREE_READONLY (decl
) && !TREE_PUBLIC (decl
)
1577 && (optimize
|| !flag_keep_static_consts
1578 || DECL_ARTIFICIAL (decl
)))
1584 rest_of_decl_compilation (decl
, NULL
, 1, 1);
1588 if (TREE_CODE (decl
) == FUNCTION_DECL
1589 && DECL_INITIAL (decl
) != 0
1590 && DECL_SAVED_INSNS (decl
) != 0
1591 && DECL_SAVED_INSNS (decl
)->saved_for_inline
1592 && (flag_keep_inline_functions
1593 || (TREE_PUBLIC (decl
) && !DECL_COMDAT (decl
))
1594 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))))
1597 output_inline_function (decl
);
1602 output_something
= 1;
1606 return output_something
;
1609 /* Issue appropriate warnings for the global declarations in VEC (of
1610 which there are LEN). Output debugging information for them. */
1613 check_global_declarations (tree
*vec
, int len
)
1618 for (i
= 0; i
< len
; i
++)
1622 if (TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
)
1623 && ! TREE_ASM_WRITTEN (decl
))
1624 /* Cancel the RTL for this decl so that, if debugging info
1625 output for global variables is still to come,
1626 this one will be omitted. */
1627 SET_DECL_RTL (decl
, NULL_RTX
);
1629 /* Warn about any function
1630 declared static but not defined.
1631 We don't warn about variables,
1632 because many programs have static variables
1633 that exist only to get some text into the object file. */
1634 if (TREE_CODE (decl
) == FUNCTION_DECL
1635 && (warn_unused_function
1636 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
)))
1637 && DECL_INITIAL (decl
) == 0
1638 && DECL_EXTERNAL (decl
)
1639 && ! DECL_ARTIFICIAL (decl
)
1640 && ! TREE_PUBLIC (decl
))
1642 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
)))
1643 pedwarn ("%H'%F' used but never defined",
1644 &DECL_SOURCE_LOCATION (decl
), decl
);
1646 warning ("%H'%F' declared `static' but never defined",
1647 &DECL_SOURCE_LOCATION (decl
), decl
);
1648 /* This symbol is effectively an "extern" declaration now. */
1649 TREE_PUBLIC (decl
) = 1;
1650 assemble_external (decl
);
1653 /* Warn about static fns or vars defined but not used. */
1654 if (((warn_unused_function
&& TREE_CODE (decl
) == FUNCTION_DECL
)
1655 || (warn_unused_variable
&& TREE_CODE (decl
) == VAR_DECL
))
1656 && ! TREE_USED (decl
)
1657 /* The TREE_USED bit for file-scope decls is kept in the identifier,
1658 to handle multiple external decls in different scopes. */
1659 && ! TREE_USED (DECL_NAME (decl
))
1660 && ! DECL_EXTERNAL (decl
)
1661 && ! TREE_PUBLIC (decl
)
1662 /* A volatile variable might be used in some non-obvious way. */
1663 && ! TREE_THIS_VOLATILE (decl
)
1664 /* Global register variables must be declared to reserve them. */
1665 && ! (TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
1666 /* Otherwise, ask the language. */
1667 && (*lang_hooks
.decls
.warn_unused_global
) (decl
))
1668 warning ("%H'%D' defined but not used",
1669 &DECL_SOURCE_LOCATION (decl
), decl
);
1671 /* Avoid confusing the debug information machinery when there are
1673 if (errorcount
== 0 && sorrycount
== 0)
1675 timevar_push (TV_SYMOUT
);
1676 (*debug_hooks
->global_decl
) (decl
);
1677 timevar_pop (TV_SYMOUT
);
1682 /* Save the current INPUT_LOCATION on the top entry in the
1683 INPUT_FILE_STACK. Push a new entry for FILE and LINE, and set the
1684 INPUT_LOCATION accordingly. */
1687 push_srcloc (const char *file
, int line
)
1689 struct file_stack
*fs
;
1691 fs
= xmalloc (sizeof (struct file_stack
));
1692 fs
->location
= input_location
;
1693 fs
->next
= input_file_stack
;
1694 input_filename
= file
;
1696 input_file_stack
= fs
;
1697 input_file_stack_tick
++;
1700 /* Pop the top entry off the stack of presently open source files.
1701 Restore the INPUT_LOCATION from the new topmost entry on the
1707 struct file_stack
*fs
;
1709 fs
= input_file_stack
;
1710 input_location
= fs
->location
;
1711 input_file_stack
= fs
->next
;
1713 input_file_stack_tick
++;
1716 /* Compile an entire translation unit. Write a file of assembly
1717 output and various debugging dumps. */
1722 /* Initialize yet another pass. */
1724 init_final (main_input_filename
);
1725 coverage_init (aux_base_name
);
1727 timevar_push (TV_PARSE
);
1729 /* Call the parser, which parses the entire file (calling
1730 rest_of_compilation for each function). */
1731 (*lang_hooks
.parse_file
) (set_yydebug
);
1733 /* In case there were missing block closers,
1734 get us back to the global binding level. */
1735 (*lang_hooks
.clear_binding_stack
) ();
1737 /* Compilation is now finished except for writing
1738 what's left of the symbol table output. */
1739 timevar_pop (TV_PARSE
);
1741 if (flag_syntax_only
)
1744 (*lang_hooks
.decls
.final_write_globals
)();
1746 cgraph_varpool_assemble_pending_decls ();
1748 /* This must occur after the loop to output deferred functions.
1749 Else the coverage initializer would not be emitted if all the
1750 functions in this compilation unit were deferred. */
1753 /* Write out any pending weak symbol declarations. */
1757 /* Do dbx symbols. */
1758 timevar_push (TV_SYMOUT
);
1760 #ifdef DWARF2_UNWIND_INFO
1761 if (dwarf2out_do_frame ())
1762 dwarf2out_frame_finish ();
1765 (*debug_hooks
->finish
) (main_input_filename
);
1766 timevar_pop (TV_SYMOUT
);
1768 /* Output some stuff at end of file if nec. */
1770 dw2_output_indirect_constants ();
1772 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
1774 timevar_push (TV_DUMP
);
1775 open_dump_file (DFI_bp
, NULL
);
1779 close_dump_file (DFI_bp
, NULL
, NULL_RTX
);
1780 timevar_pop (TV_DUMP
);
1783 targetm
.asm_out
.file_end ();
1785 /* Attach a special .ident directive to the end of the file to identify
1786 the version of GCC which compiled this code. The format of the .ident
1787 string is patterned after the ones produced by native SVR4 compilers. */
1790 fprintf (asm_out_file
, "%s\"GCC: (GNU) %s\"\n",
1791 IDENT_ASM_OP
, version_string
);
1794 if (optimize
> 0 && open_dump_file (DFI_combine
, NULL
))
1796 timevar_push (TV_DUMP
);
1797 dump_combine_total_stats (rtl_dump_file
);
1798 close_dump_file (DFI_combine
, NULL
, NULL_RTX
);
1799 timevar_pop (TV_DUMP
);
1803 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
1804 and TYPE_DECL nodes.
1806 This does nothing for local (non-static) variables, unless the
1807 variable is a register variable with an ASMSPEC. In that case, or
1808 if the variable is not an automatic, it sets up the RTL and
1809 outputs any assembler code (label definition, storage allocation
1810 and initialization).
1812 DECL is the declaration. If ASMSPEC is nonzero, it specifies
1813 the assembler symbol name to be used. TOP_LEVEL is nonzero
1814 if this declaration is not within a function. */
1817 rest_of_decl_compilation (tree decl
,
1818 const char *asmspec
,
1822 /* We deferred calling assemble_alias so that we could collect
1823 other attributes such as visibility. Emit the alias now. */
1826 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
1829 alias
= TREE_VALUE (TREE_VALUE (alias
));
1830 alias
= get_identifier (TREE_STRING_POINTER (alias
));
1831 assemble_alias (decl
, alias
);
1835 /* Forward declarations for nested functions are not "external",
1836 but we need to treat them as if they were. */
1837 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
1838 || TREE_CODE (decl
) == FUNCTION_DECL
)
1840 timevar_push (TV_VARCONST
);
1843 make_decl_rtl (decl
, asmspec
);
1845 /* Don't output anything when a tentative file-scope definition
1846 is seen. But at end of compilation, do output code for them. */
1847 if (at_end
|| !DECL_DEFER_OUTPUT (decl
))
1849 if (flag_unit_at_a_time
&& !cgraph_global_info_ready
1850 && TREE_CODE (decl
) != FUNCTION_DECL
&& top_level
)
1851 cgraph_varpool_finalize_decl (decl
);
1853 assemble_variable (decl
, top_level
, at_end
, 0);
1856 #ifdef ASM_FINISH_DECLARE_OBJECT
1857 if (decl
== last_assemble_variable_decl
)
1859 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
1864 timevar_pop (TV_VARCONST
);
1866 else if (DECL_REGISTER (decl
) && asmspec
!= 0)
1868 if (decode_reg_name (asmspec
) >= 0)
1870 SET_DECL_RTL (decl
, NULL_RTX
);
1871 make_decl_rtl (decl
, asmspec
);
1875 error ("invalid register name `%s' for register variable", asmspec
);
1876 DECL_REGISTER (decl
) = 0;
1881 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1882 else if ((write_symbols
== DBX_DEBUG
|| write_symbols
== XCOFF_DEBUG
)
1883 && TREE_CODE (decl
) == TYPE_DECL
)
1885 timevar_push (TV_SYMOUT
);
1886 dbxout_symbol (decl
, 0);
1887 timevar_pop (TV_SYMOUT
);
1890 #ifdef SDB_DEBUGGING_INFO
1891 else if (write_symbols
== SDB_DEBUG
&& top_level
1892 && TREE_CODE (decl
) == TYPE_DECL
)
1894 timevar_push (TV_SYMOUT
);
1895 sdbout_symbol (decl
, 0);
1896 timevar_pop (TV_SYMOUT
);
1899 #ifdef DWARF2_DEBUGGING_INFO
1900 else if ((write_symbols
== DWARF2_DEBUG
1901 || write_symbols
== VMS_AND_DWARF2_DEBUG
)
1903 && TREE_CODE (decl
) == TYPE_DECL
)
1905 timevar_push (TV_SYMOUT
);
1906 dwarf2out_decl (decl
);
1907 timevar_pop (TV_SYMOUT
);
1912 /* Called after finishing a record, union or enumeral type. */
1915 rest_of_type_compilation (
1916 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) \
1917 || defined (SDB_DEBUGGING_INFO) || defined (DWARF2_DEBUGGING_INFO)
1921 tree type ATTRIBUTE_UNUSED
,
1922 int toplev ATTRIBUTE_UNUSED
1926 /* Avoid confusing the debug information machinery when there are
1928 if (errorcount
!= 0 || sorrycount
!= 0)
1931 timevar_push (TV_SYMOUT
);
1932 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1933 if (write_symbols
== DBX_DEBUG
|| write_symbols
== XCOFF_DEBUG
)
1934 dbxout_symbol (TYPE_STUB_DECL (type
), !toplev
);
1936 #ifdef SDB_DEBUGGING_INFO
1937 if (write_symbols
== SDB_DEBUG
)
1938 sdbout_symbol (TYPE_STUB_DECL (type
), !toplev
);
1940 #ifdef DWARF2_DEBUGGING_INFO
1941 if ((write_symbols
== DWARF2_DEBUG
1942 || write_symbols
== VMS_AND_DWARF2_DEBUG
)
1944 dwarf2out_decl (TYPE_STUB_DECL (type
));
1946 timevar_pop (TV_SYMOUT
);
1949 /* Turn the RTL into assembly. */
1951 rest_of_handle_final (tree decl
, rtx insns
)
1953 timevar_push (TV_FINAL
);
1958 /* Get the function's name, as described by its RTL. This may be
1959 different from the DECL_NAME name used in the source file. */
1961 x
= DECL_RTL (decl
);
1962 if (GET_CODE (x
) != MEM
)
1965 if (GET_CODE (x
) != SYMBOL_REF
)
1967 fnname
= XSTR (x
, 0);
1969 assemble_start_function (decl
, fnname
);
1970 final_start_function (insns
, asm_out_file
, optimize
);
1971 final (insns
, asm_out_file
, optimize
, 0);
1972 final_end_function ();
1974 #ifdef IA64_UNWIND_INFO
1975 /* ??? The IA-64 ".handlerdata" directive must be issued before
1976 the ".endp" directive that closes the procedure descriptor. */
1977 output_function_exception_table ();
1980 assemble_end_function (decl
, fnname
);
1982 #ifndef IA64_UNWIND_INFO
1983 /* Otherwise, it feels unclean to switch sections in the middle. */
1984 output_function_exception_table ();
1988 fflush (asm_out_file
);
1990 /* Release all memory allocated by flow. */
1991 free_basic_block_vars (0);
1993 /* Release all memory held by regsets now. */
1994 regset_release_memory ();
1996 timevar_pop (TV_FINAL
);
2002 /* Run delay slot optimization. */
2004 rest_of_handle_delay_slots (tree decl
, rtx insns
)
2006 timevar_push (TV_DBR_SCHED
);
2007 open_dump_file (DFI_dbr
, decl
);
2009 dbr_schedule (insns
, rtl_dump_file
);
2011 close_dump_file (DFI_dbr
, print_rtl
, insns
);
2012 timevar_pop (TV_DBR_SCHED
);
2019 /* Convert register usage from flat register file usage to a stack
2022 rest_of_handle_stack_regs (tree decl
, rtx insns
)
2024 timevar_push (TV_REG_STACK
);
2025 open_dump_file (DFI_stack
, decl
);
2027 if (reg_to_stack (insns
, rtl_dump_file
) && optimize
)
2029 if (cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_POST_REGSTACK
2030 | (flag_crossjumping
? CLEANUP_CROSSJUMP
: 0))
2031 && flag_reorder_blocks
)
2033 reorder_basic_blocks ();
2034 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_POST_REGSTACK
);
2038 close_dump_file (DFI_stack
, print_rtl_with_bb
, insns
);
2039 timevar_pop (TV_REG_STACK
);
2046 /* Machine independent reorg pass. */
2048 rest_of_handle_machine_reorg (tree decl
, rtx insns
)
2050 timevar_push (TV_MACH_DEP
);
2051 open_dump_file (DFI_mach
, decl
);
2053 (*targetm
.machine_dependent_reorg
) ();
2055 close_dump_file (DFI_mach
, print_rtl
, insns
);
2056 timevar_pop (TV_MACH_DEP
);
2062 /* Run new register allocator. Return TRUE if we must exit
2063 rest_of_compilation upon return. */
2065 rest_of_handle_new_regalloc (tree decl
, rtx insns
, int *rebuild_notes
)
2069 delete_trivially_dead_insns (insns
, max_reg_num ());
2072 timevar_pop (TV_LOCAL_ALLOC
);
2073 if (dump_file
[DFI_lreg
].enabled
)
2075 timevar_push (TV_DUMP
);
2077 close_dump_file (DFI_lreg
, NULL
, NULL
);
2078 timevar_pop (TV_DUMP
);
2081 /* XXX clean up the whole mess to bring live info in shape again. */
2082 timevar_push (TV_GLOBAL_ALLOC
);
2083 open_dump_file (DFI_greg
, decl
);
2085 build_insn_chain (insns
);
2086 failure
= reload (insns
, 0);
2088 timevar_pop (TV_GLOBAL_ALLOC
);
2090 if (dump_file
[DFI_greg
].enabled
)
2092 timevar_push (TV_DUMP
);
2094 dump_global_regs (rtl_dump_file
);
2096 close_dump_file (DFI_greg
, print_rtl_with_bb
, insns
);
2097 timevar_pop (TV_DUMP
);
2103 reload_completed
= 1;
2109 /* Run old register allocator. Return TRUE if we must exit
2110 rest_of_compilation upon return. */
2112 rest_of_handle_old_regalloc (tree decl
, rtx insns
, int *rebuild_notes
)
2116 /* Allocate the reg_renumber array. */
2117 allocate_reg_info (max_regno
, FALSE
, TRUE
);
2119 /* And the reg_equiv_memory_loc array. */
2120 reg_equiv_memory_loc
= xcalloc (max_regno
, sizeof (rtx
));
2122 allocate_initial_values (reg_equiv_memory_loc
);
2124 regclass (insns
, max_reg_num (), rtl_dump_file
);
2125 *rebuild_notes
= local_alloc ();
2127 timevar_pop (TV_LOCAL_ALLOC
);
2129 if (dump_file
[DFI_lreg
].enabled
)
2131 timevar_push (TV_DUMP
);
2133 dump_flow_info (rtl_dump_file
);
2134 dump_local_alloc (rtl_dump_file
);
2136 close_dump_file (DFI_lreg
, print_rtl_with_bb
, insns
);
2137 timevar_pop (TV_DUMP
);
2142 timevar_push (TV_GLOBAL_ALLOC
);
2143 open_dump_file (DFI_greg
, decl
);
2145 /* If optimizing, allocate remaining pseudo-regs. Do the reload
2146 pass fixing up any insns that are invalid. */
2149 failure
= global_alloc (rtl_dump_file
);
2152 build_insn_chain (insns
);
2153 failure
= reload (insns
, 0);
2156 timevar_pop (TV_GLOBAL_ALLOC
);
2158 if (dump_file
[DFI_greg
].enabled
)
2160 timevar_push (TV_DUMP
);
2162 dump_global_regs (rtl_dump_file
);
2164 close_dump_file (DFI_greg
, print_rtl_with_bb
, insns
);
2165 timevar_pop (TV_DUMP
);
2171 /* Run the regrename and cprop passes. */
2173 rest_of_handle_regrename (tree decl
, rtx insns
)
2175 timevar_push (TV_RENAME_REGISTERS
);
2176 open_dump_file (DFI_rnreg
, decl
);
2178 if (flag_rename_registers
)
2179 regrename_optimize ();
2180 if (flag_cprop_registers
)
2181 copyprop_hardreg_forward ();
2183 close_dump_file (DFI_rnreg
, print_rtl_with_bb
, insns
);
2184 timevar_pop (TV_RENAME_REGISTERS
);
2187 /* Reorder basic blocks. */
2189 rest_of_handle_reorder_blocks (tree decl
, rtx insns
)
2191 timevar_push (TV_REORDER_BLOCKS
);
2192 open_dump_file (DFI_bbro
, decl
);
2194 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
2195 splitting possibly introduced more crossjumping opportunities. */
2196 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_UPDATE_LIFE
2197 | (flag_crossjumping
? CLEANUP_CROSSJUMP
: 0));
2199 if (flag_sched2_use_traces
&& flag_schedule_insns_after_reload
)
2201 if (flag_reorder_blocks
)
2202 reorder_basic_blocks ();
2203 if (flag_reorder_blocks
2204 || (flag_sched2_use_traces
&& flag_schedule_insns_after_reload
))
2205 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_UPDATE_LIFE
);
2207 close_dump_file (DFI_bbro
, print_rtl_with_bb
, insns
);
2208 timevar_pop (TV_REORDER_BLOCKS
);
2211 #ifdef INSN_SCHEDULING
2212 /* Run instruction scheduler. */
2214 rest_of_handle_sched (tree decl
, rtx insns
)
2216 timevar_push (TV_SCHED
);
2218 /* Print function header into sched dump now
2219 because doing the sched analysis makes some of the dump. */
2220 if (optimize
> 0 && flag_schedule_insns
)
2222 open_dump_file (DFI_sched
, decl
);
2224 /* Do control and data sched analysis,
2225 and write some of the results to dump file. */
2227 schedule_insns (rtl_dump_file
);
2229 close_dump_file (DFI_sched
, print_rtl_with_bb
, insns
);
2231 timevar_pop (TV_SCHED
);
2236 /* Run second scheduling pass after reload. */
2238 rest_of_handle_sched2 (tree decl
, rtx insns
)
2240 timevar_push (TV_SCHED2
);
2241 open_dump_file (DFI_sched2
, decl
);
2243 /* Do control and data sched analysis again,
2244 and write some more of the results to dump file. */
2246 split_all_insns (1);
2248 if (flag_sched2_use_superblocks
|| flag_sched2_use_traces
)
2250 schedule_ebbs (rtl_dump_file
);
2251 /* No liveness updating code yet, but it should be easy to do.
2252 reg-stack recompute the liveness when needed for now. */
2253 count_or_remove_death_notes (NULL
, 1);
2254 cleanup_cfg (CLEANUP_EXPENSIVE
);
2257 schedule_insns (rtl_dump_file
);
2259 close_dump_file (DFI_sched2
, print_rtl_with_bb
, insns
);
2260 timevar_pop (TV_SCHED2
);
2266 /* Register allocation pre-pass, to reduce number of moves necessary
2267 for two-address machines. */
2269 rest_of_handle_regmove (tree decl
, rtx insns
)
2271 timevar_push (TV_REGMOVE
);
2272 open_dump_file (DFI_regmove
, decl
);
2274 regmove_optimize (insns
, max_reg_num (), rtl_dump_file
);
2276 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_UPDATE_LIFE
);
2277 close_dump_file (DFI_regmove
, print_rtl_with_bb
, insns
);
2278 timevar_pop (TV_REGMOVE
);
2285 rest_of_handle_tracer (tree decl
, rtx insns
)
2287 timevar_push (TV_TRACER
);
2288 open_dump_file (DFI_tracer
, decl
);
2290 dump_flow_info (rtl_dump_file
);
2292 cleanup_cfg (CLEANUP_EXPENSIVE
);
2293 reg_scan (insns
, max_reg_num (), 0);
2294 close_dump_file (DFI_tracer
, print_rtl_with_bb
, get_insns ());
2295 timevar_pop (TV_TRACER
);
2298 /* If-conversion and CFG cleanup. */
2300 rest_of_handle_if_conversion (tree decl
, rtx insns
)
2302 open_dump_file (DFI_ce1
, decl
);
2303 if (flag_if_conversion
)
2305 timevar_push (TV_IFCVT
);
2307 dump_flow_info (rtl_dump_file
);
2308 cleanup_cfg (CLEANUP_EXPENSIVE
);
2309 reg_scan (insns
, max_reg_num (), 0);
2311 timevar_pop (TV_IFCVT
);
2313 timevar_push (TV_JUMP
);
2314 cleanup_cfg (CLEANUP_EXPENSIVE
);
2315 reg_scan (insns
, max_reg_num (), 0);
2316 timevar_pop (TV_JUMP
);
2317 close_dump_file (DFI_ce1
, print_rtl_with_bb
, get_insns ());
2320 /* Rerun if-conversion, as combine may have simplified things enough
2321 to now meet sequence length restrictions. */
2323 rest_of_handle_if_after_combine (tree decl
, rtx insns
)
2325 timevar_push (TV_IFCVT
);
2326 open_dump_file (DFI_ce2
, decl
);
2332 close_dump_file (DFI_ce2
, print_rtl_with_bb
, insns
);
2333 timevar_pop (TV_IFCVT
);
2336 /* Do branch profiling and static profile estimation passes. */
2338 rest_of_handle_branch_prob (tree decl
, rtx insns
)
2342 timevar_push (TV_BRANCH_PROB
);
2343 open_dump_file (DFI_bp
, decl
);
2344 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
2347 /* Discover and record the loop depth at the head of each basic
2348 block. The loop infrastructure does the real job for us. */
2349 flow_loops_find (&loops
, LOOP_TREE
);
2352 flow_loops_dump (&loops
, rtl_dump_file
, NULL
, 0);
2354 /* Estimate using heuristics if no profiling info is available. */
2355 if (flag_guess_branch_prob
)
2356 estimate_probability (&loops
);
2358 flow_loops_free (&loops
);
2359 close_dump_file (DFI_bp
, print_rtl_with_bb
, insns
);
2360 timevar_pop (TV_BRANCH_PROB
);
2363 /* Do control and data flow analysis; write some of the results to the
2366 rest_of_handle_cfg (tree decl
, rtx insns
)
2368 open_dump_file (DFI_cfg
, decl
);
2370 dump_flow_info (rtl_dump_file
);
2372 cleanup_cfg (CLEANUP_EXPENSIVE
2373 | (flag_thread_jumps
? CLEANUP_THREADING
: 0));
2375 /* It may make more sense to mark constant functions after dead code is
2376 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
2377 may insert code making function non-constant, but we still must consider
2378 it as constant, otherwise -fbranch-probabilities will not read data back.
2380 life_analysis rarely eliminates modification of external memory.
2383 mark_constant_function ();
2385 close_dump_file (DFI_cfg
, print_rtl_with_bb
, insns
);
2388 /* Purge addressofs. */
2390 rest_of_handle_addressof (tree decl
, rtx insns
)
2392 open_dump_file (DFI_addressof
, decl
);
2394 purge_addressof (insns
);
2395 if (optimize
&& purge_all_dead_edges (0))
2396 delete_unreachable_blocks ();
2397 reg_scan (insns
, max_reg_num (), 1);
2399 close_dump_file (DFI_addressof
, print_rtl
, insns
);
2402 /* We may have potential sibling or tail recursion sites. Select one
2403 (of possibly multiple) methods of performing the call. */
2405 rest_of_handle_sibling_calls (rtx insns
)
2408 optimize_sibling_and_tail_recursive_calls ();
2410 /* Recompute the CFG as sibling optimization clobbers it randomly. */
2411 free_bb_for_insn ();
2412 find_exception_handler_labels ();
2413 rebuild_jump_labels (insns
);
2414 find_basic_blocks (insns
, max_reg_num (), rtl_dump_file
);
2416 /* There is pass ordering problem - we must lower NOTE_INSN_PREDICTION
2417 notes before simplifying cfg and we must do lowering after sibcall
2418 that unhides parts of RTL chain and cleans up the CFG.
2420 Until sibcall is replaced by tree-level optimizer, lets just
2421 sweep away the NOTE_INSN_PREDICTION notes that leaked out. */
2422 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
2423 if (GET_CODE (insn
) == NOTE
2424 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_PREDICTION
)
2427 close_dump_file (DFI_sibling
, print_rtl
, get_insns ());
2430 /* Perform jump bypassing and control flow optimizations. */
2432 rest_of_handle_jump_bypass (tree decl
, rtx insns
)
2434 timevar_push (TV_BYPASS
);
2435 open_dump_file (DFI_bypass
, decl
);
2437 cleanup_cfg (CLEANUP_EXPENSIVE
);
2439 if (bypass_jumps (rtl_dump_file
))
2441 rebuild_jump_labels (insns
);
2442 cleanup_cfg (CLEANUP_EXPENSIVE
);
2443 delete_trivially_dead_insns (insns
, max_reg_num ());
2446 close_dump_file (DFI_bypass
, print_rtl_with_bb
, insns
);
2447 timevar_pop (TV_BYPASS
);
2451 #ifdef ENABLE_CHECKING
2452 verify_flow_info ();
2456 /* Handle inlining of functions in rest_of_compilation. Return TRUE
2457 if we must exit rest_of_compilation upon return. */
2459 rest_of_handle_inlining (tree decl
)
2466 /* If we are reconsidering an inline function at the end of
2467 compilation, skip the stuff for making it inline. */
2468 if (cfun
->rtl_inline_init
)
2470 cfun
->rtl_inline_init
= 1;
2472 /* If this is nested inside an inlined external function, pretend
2473 it was only declared. Since we cannot inline such functions,
2474 generating code for this one is not only not necessary but will
2475 confuse some debugging output writers. */
2476 for (parent
= DECL_CONTEXT (current_function_decl
);
2477 parent
!= NULL_TREE
;
2478 parent
= get_containing_scope (parent
))
2479 if (TREE_CODE (parent
) == FUNCTION_DECL
2480 && DECL_INLINE (parent
) && DECL_EXTERNAL (parent
))
2482 DECL_INITIAL (decl
) = 0;
2485 else if (TYPE_P (parent
))
2486 /* A function in a local class should be treated normally. */
2489 /* If requested, consider whether to make this function inline. */
2490 if ((DECL_INLINE (decl
) && !flag_no_inline
)
2491 || flag_inline_functions
)
2493 timevar_push (TV_INTEGRATION
);
2494 lose
= function_cannot_inline_p (decl
);
2495 timevar_pop (TV_INTEGRATION
);
2496 if (lose
|| ! optimize
)
2498 if (warn_inline
&& lose
&& DECL_INLINE (decl
))
2500 char *msg
= xmalloc (2 + strlen (lose
) + 1);
2503 strcpy(msg
+ 2, lose
);
2504 warning (msg
, &DECL_SOURCE_LOCATION (decl
));
2507 DECL_ABSTRACT_ORIGIN (decl
) = 0;
2508 /* Don't really compile an extern inline function.
2509 If we can't make it inline, pretend
2510 it was only declared. */
2511 if (DECL_EXTERNAL (decl
))
2513 DECL_INITIAL (decl
) = 0;
2518 inlinable
= DECL_INLINE (decl
) = 1;
2521 insns
= get_insns ();
2523 /* Dump the rtl code if we are dumping rtl. */
2525 if (open_dump_file (DFI_rtl
, decl
))
2527 if (DECL_SAVED_INSNS (decl
) && DECL_SAVED_INSNS (decl
)->saved_for_inline
)
2528 fprintf (rtl_dump_file
, ";; (integrable)\n\n");
2529 close_dump_file (DFI_rtl
, print_rtl
, insns
);
2532 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
2533 sorts of eh initialization. Delay this until after the
2534 initial rtl dump so that we can see the original nesting. */
2535 convert_from_eh_region_ranges ();
2537 /* If function is inline, and we don't yet know whether to
2538 compile it by itself, defer decision till end of compilation.
2539 wrapup_global_declarations will (indirectly) call
2540 rest_of_compilation again for those functions that need to
2541 be output. Also defer those functions that we are supposed
2545 || (DECL_INLINE (decl
)
2546 && flag_inline_functions
2547 && ((! TREE_PUBLIC (decl
) && ! TREE_ADDRESSABLE (decl
)
2548 && ! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
2549 && ! flag_keep_inline_functions
)
2550 || DECL_EXTERNAL (decl
))))
2551 DECL_DEFER_OUTPUT (decl
) = 1;
2553 if (DECL_INLINE (decl
))
2554 /* DWARF wants separate debugging info for abstract and
2555 concrete instances of all inline functions, including those
2556 declared inline but not inlined, and those inlined even
2557 though they weren't declared inline. Conveniently, that's
2558 what DECL_INLINE means at this point. */
2559 (*debug_hooks
->deferred_inline_function
) (decl
);
2561 if (DECL_DEFER_OUTPUT (decl
))
2563 /* If -Wreturn-type, we have to do a bit of compilation. We just
2564 want to call cleanup the cfg to figure out whether or not we can
2565 fall off the end of the function; we do the minimum amount of
2566 work necessary to make that safe. */
2567 if (warn_return_type
)
2569 int saved_optimize
= optimize
;
2572 rebuild_jump_labels (insns
);
2573 find_exception_handler_labels ();
2574 find_basic_blocks (insns
, max_reg_num (), rtl_dump_file
);
2575 cleanup_cfg (CLEANUP_PRE_SIBCALL
| CLEANUP_PRE_LOOP
);
2576 optimize
= saved_optimize
;
2578 /* CFG is no longer maintained up-to-date. */
2579 free_bb_for_insn ();
2582 set_nothrow_function_flags ();
2583 if (current_function_nothrow
)
2584 /* Now we know that this can't throw; set the flag for the benefit
2585 of other functions later in this translation unit. */
2586 TREE_NOTHROW (current_function_decl
) = 1;
2588 timevar_push (TV_INTEGRATION
);
2589 save_for_inline (decl
);
2590 timevar_pop (TV_INTEGRATION
);
2591 DECL_SAVED_INSNS (decl
)->inlinable
= inlinable
;
2595 /* If specified extern inline but we aren't inlining it, we are
2596 done. This goes for anything that gets here with DECL_EXTERNAL
2597 set, not just things with DECL_INLINE. */
2598 return (bool) DECL_EXTERNAL (decl
);
2601 /* Rest of compilation helper to convert the rtl to SSA form. */
2603 rest_of_handle_ssa (tree decl
, rtx insns
)
2605 timevar_push (TV_TO_SSA
);
2606 open_dump_file (DFI_ssa
, decl
);
2608 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
2611 close_dump_file (DFI_ssa
, print_rtl_with_bb
, insns
);
2612 timevar_pop (TV_TO_SSA
);
2614 /* Perform sparse conditional constant propagation, if requested. */
2617 timevar_push (TV_SSA_CCP
);
2618 open_dump_file (DFI_ssa_ccp
, decl
);
2622 close_dump_file (DFI_ssa_ccp
, print_rtl_with_bb
, get_insns ());
2623 timevar_pop (TV_SSA_CCP
);
2626 /* It would be useful to cleanup the CFG at this point, but block
2627 merging and possibly other transformations might leave a PHI
2628 node in the middle of a basic block, which is a strict no-no. */
2630 /* The SSA implementation uses basic block numbers in its phi
2631 nodes. Thus, changing the control-flow graph or the basic
2632 blocks, e.g., calling find_basic_blocks () or cleanup_cfg (),
2633 may cause problems. */
2637 /* Remove dead code. */
2639 timevar_push (TV_SSA_DCE
);
2640 open_dump_file (DFI_ssa_dce
, decl
);
2642 insns
= get_insns ();
2643 ssa_eliminate_dead_code ();
2645 close_dump_file (DFI_ssa_dce
, print_rtl_with_bb
, insns
);
2646 timevar_pop (TV_SSA_DCE
);
2649 /* Convert from SSA form. */
2651 timevar_push (TV_FROM_SSA
);
2652 open_dump_file (DFI_ussa
, decl
);
2654 convert_from_ssa ();
2655 /* New registers have been created. Rescan their usage. */
2656 reg_scan (insns
, max_reg_num (), 1);
2658 close_dump_file (DFI_ussa
, print_rtl_with_bb
, insns
);
2659 timevar_pop (TV_FROM_SSA
);
2666 /* Try to identify useless null pointer tests and delete them. */
2668 rest_of_handle_null_pointer (tree decl
, rtx insns
)
2670 open_dump_file (DFI_null
, decl
);
2672 dump_flow_info (rtl_dump_file
);
2674 if (delete_null_pointer_checks (insns
))
2675 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
2677 close_dump_file (DFI_null
, print_rtl_with_bb
, insns
);
2680 /* Try combining insns through substitution. */
2682 rest_of_handle_combine (tree decl
, rtx insns
)
2684 int rebuild_jump_labels_after_combine
= 0;
2686 timevar_push (TV_COMBINE
);
2687 open_dump_file (DFI_combine
, decl
);
2689 rebuild_jump_labels_after_combine
2690 = combine_instructions (insns
, max_reg_num ());
2692 /* Combining insns may have turned an indirect jump into a
2693 direct jump. Rebuild the JUMP_LABEL fields of jumping
2695 if (rebuild_jump_labels_after_combine
)
2697 timevar_push (TV_JUMP
);
2698 rebuild_jump_labels (insns
);
2699 timevar_pop (TV_JUMP
);
2701 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_UPDATE_LIFE
);
2704 close_dump_file (DFI_combine
, print_rtl_with_bb
, insns
);
2705 timevar_pop (TV_COMBINE
);
2710 /* Perform life analysis. */
2712 rest_of_handle_life (tree decl
, rtx insns
)
2714 open_dump_file (DFI_life
, decl
);
2717 #ifdef ENABLE_CHECKING
2718 verify_flow_info ();
2720 life_analysis (insns
, rtl_dump_file
, PROP_FINAL
);
2722 cleanup_cfg ((optimize
? CLEANUP_EXPENSIVE
: 0) | CLEANUP_UPDATE_LIFE
2723 | (flag_thread_jumps
? CLEANUP_THREADING
: 0));
2724 timevar_pop (TV_FLOW
);
2726 if (warn_uninitialized
)
2728 uninitialized_vars_warning (DECL_INITIAL (decl
));
2730 setjmp_args_warning ();
2735 if (!flag_new_regalloc
&& initialize_uninitialized_subregs ())
2737 /* Insns were inserted, and possibly pseudos created, so
2738 things might look a bit different. */
2739 insns
= get_insns ();
2740 allocate_reg_life_data ();
2741 update_life_info (NULL
, UPDATE_LIFE_GLOBAL_RM_NOTES
,
2742 PROP_LOG_LINKS
| PROP_REG_INFO
| PROP_DEATH_NOTES
);
2748 close_dump_file (DFI_life
, print_rtl_with_bb
, insns
);
2753 /* Perform common subexpression elimination. Nonzero value from
2754 `cse_main' means that jumps were simplified and some code may now
2755 be unreachable, so do jump optimization again. */
2757 rest_of_handle_cse (tree decl
, rtx insns
)
2761 open_dump_file (DFI_cse
, decl
);
2763 dump_flow_info (rtl_dump_file
);
2764 timevar_push (TV_CSE
);
2766 reg_scan (insns
, max_reg_num (), 1);
2768 tem
= cse_main (insns
, max_reg_num (), 0, rtl_dump_file
);
2770 rebuild_jump_labels (insns
);
2771 purge_all_dead_edges (0);
2773 delete_trivially_dead_insns (insns
, max_reg_num ());
2775 /* If we are not running more CSE passes, then we are no longer
2776 expecting CSE to be run. But always rerun it in a cheap mode. */
2777 cse_not_expected
= !flag_rerun_cse_after_loop
&& !flag_gcse
;
2779 if (tem
|| optimize
> 1)
2780 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
2781 /* Try to identify useless null pointer tests and delete them. */
2782 if (flag_delete_null_pointer_checks
)
2784 timevar_push (TV_JUMP
);
2786 if (delete_null_pointer_checks (insns
))
2787 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
2788 timevar_pop (TV_JUMP
);
2791 /* The second pass of jump optimization is likely to have
2792 removed a bunch more instructions. */
2793 renumber_insns (rtl_dump_file
);
2795 timevar_pop (TV_CSE
);
2796 close_dump_file (DFI_cse
, print_rtl_with_bb
, insns
);
2799 /* Run second CSE pass after loop optimizations. */
2801 rest_of_handle_cse2 (tree decl
, rtx insns
)
2805 timevar_push (TV_CSE2
);
2806 open_dump_file (DFI_cse2
, decl
);
2808 dump_flow_info (rtl_dump_file
);
2809 /* CFG is no longer maintained up-to-date. */
2810 tem
= cse_main (insns
, max_reg_num (), 1, rtl_dump_file
);
2811 purge_all_dead_edges (0);
2812 delete_trivially_dead_insns (insns
, max_reg_num ());
2816 timevar_push (TV_JUMP
);
2817 rebuild_jump_labels (insns
);
2818 cleanup_cfg (CLEANUP_EXPENSIVE
);
2819 timevar_pop (TV_JUMP
);
2821 reg_scan (insns
, max_reg_num (), 0);
2822 close_dump_file (DFI_cse2
, print_rtl_with_bb
, insns
);
2824 timevar_pop (TV_CSE2
);
2827 /* Perform global cse. */
2829 rest_of_handle_gcse (tree decl
, rtx insns
)
2831 int save_csb
, save_cfj
;
2834 timevar_push (TV_GCSE
);
2835 open_dump_file (DFI_gcse
, decl
);
2837 tem
= gcse_main (insns
, rtl_dump_file
);
2838 rebuild_jump_labels (insns
);
2839 delete_trivially_dead_insns (insns
, max_reg_num ());
2841 save_csb
= flag_cse_skip_blocks
;
2842 save_cfj
= flag_cse_follow_jumps
;
2843 flag_cse_skip_blocks
= flag_cse_follow_jumps
= 0;
2845 /* Instantiate any remaining CONSTANT_P_RTX nodes. */
2846 if (current_function_calls_constant_p
)
2847 purge_builtin_constant_p ();
2849 /* If -fexpensive-optimizations, re-run CSE to clean up things done
2851 if (flag_expensive_optimizations
)
2853 timevar_push (TV_CSE
);
2854 reg_scan (insns
, max_reg_num (), 1);
2855 tem2
= cse_main (insns
, max_reg_num (), 0, rtl_dump_file
);
2856 purge_all_dead_edges (0);
2857 delete_trivially_dead_insns (insns
, max_reg_num ());
2858 timevar_pop (TV_CSE
);
2859 cse_not_expected
= !flag_rerun_cse_after_loop
;
2862 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
2863 things up. Then possibly re-run CSE again. */
2867 timevar_push (TV_JUMP
);
2868 rebuild_jump_labels (insns
);
2869 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
2870 timevar_pop (TV_JUMP
);
2872 if (flag_expensive_optimizations
)
2874 timevar_push (TV_CSE
);
2875 reg_scan (insns
, max_reg_num (), 1);
2876 tem2
= cse_main (insns
, max_reg_num (), 0, rtl_dump_file
);
2877 purge_all_dead_edges (0);
2878 delete_trivially_dead_insns (insns
, max_reg_num ());
2879 timevar_pop (TV_CSE
);
2883 close_dump_file (DFI_gcse
, print_rtl_with_bb
, insns
);
2884 timevar_pop (TV_GCSE
);
2887 flag_cse_skip_blocks
= save_csb
;
2888 flag_cse_follow_jumps
= save_cfj
;
2889 #ifdef ENABLE_CHECKING
2890 verify_flow_info ();
2894 /* Move constant computations out of loops. */
2896 rest_of_handle_loop_optimize (tree decl
, rtx insns
)
2898 int do_unroll
, do_prefetch
;
2900 timevar_push (TV_LOOP
);
2901 delete_dead_jumptables ();
2902 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
2903 open_dump_file (DFI_loop
, decl
);
2905 /* CFG is no longer maintained up-to-date. */
2906 free_bb_for_insn ();
2908 if (flag_unroll_loops
)
2909 do_unroll
= 0; /* Having two unrollers is useless. */
2911 do_unroll
= flag_old_unroll_loops
? LOOP_UNROLL
: LOOP_AUTO_UNROLL
;
2912 do_prefetch
= flag_prefetch_loop_arrays
? LOOP_PREFETCH
: 0;
2914 if (flag_rerun_loop_opt
)
2916 cleanup_barriers ();
2918 /* We only want to perform unrolling once. */
2919 loop_optimize (insns
, rtl_dump_file
, do_unroll
);
2922 /* The first call to loop_optimize makes some instructions
2923 trivially dead. We delete those instructions now in the
2924 hope that doing so will make the heuristics in loop work
2925 better and possibly speed up compilation. */
2926 delete_trivially_dead_insns (insns
, max_reg_num ());
2928 /* The regscan pass is currently necessary as the alias
2929 analysis code depends on this information. */
2930 reg_scan (insns
, max_reg_num (), 1);
2932 cleanup_barriers ();
2933 loop_optimize (insns
, rtl_dump_file
, do_unroll
| LOOP_BCT
| do_prefetch
);
2935 /* Loop can create trivially dead instructions. */
2936 delete_trivially_dead_insns (insns
, max_reg_num ());
2937 close_dump_file (DFI_loop
, print_rtl
, insns
);
2938 timevar_pop (TV_LOOP
);
2939 find_basic_blocks (insns
, max_reg_num (), rtl_dump_file
);
2944 /* Perform loop optimizations. It might be better to do them a bit
2945 sooner, but we want the profile feedback to work more
2948 rest_of_handle_loop2 (tree decl
, rtx insns
)
2950 struct loops
*loops
;
2951 timevar_push (TV_LOOP
);
2952 open_dump_file (DFI_loop2
, decl
);
2954 dump_flow_info (rtl_dump_file
);
2956 loops
= loop_optimizer_init (rtl_dump_file
);
2960 /* The optimizations: */
2961 if (flag_unswitch_loops
)
2962 unswitch_loops (loops
);
2964 if (flag_peel_loops
|| flag_unroll_loops
)
2965 unroll_and_peel_loops (loops
,
2966 (flag_peel_loops
? UAP_PEEL
: 0) |
2967 (flag_unroll_loops
? UAP_UNROLL
: 0) |
2968 (flag_unroll_all_loops
? UAP_UNROLL_ALL
: 0));
2970 loop_optimizer_finalize (loops
, rtl_dump_file
);
2973 cleanup_cfg (CLEANUP_EXPENSIVE
);
2974 delete_trivially_dead_insns (insns
, max_reg_num ());
2975 reg_scan (insns
, max_reg_num (), 0);
2977 dump_flow_info (rtl_dump_file
);
2978 close_dump_file (DFI_loop2
, print_rtl_with_bb
, get_insns ());
2979 timevar_pop (TV_LOOP
);
2983 /* This is called from finish_function (within langhooks.parse_file)
2984 after each top-level definition is parsed.
2985 It is supposed to compile that function or variable
2986 and output the assembler code for it.
2987 After we return, the tree storage is freed. */
2990 rest_of_compilation (tree decl
)
2993 int rebuild_label_notes_after_reload
;
2995 timevar_push (TV_REST_OF_COMPILATION
);
2997 /* Register rtl specific functions for cfg. */
2998 rtl_register_cfg_hooks ();
3000 /* Now that we're out of the frontend, we shouldn't have any more
3001 CONCATs anywhere. */
3002 generating_concat_p
= 0;
3004 /* When processing delayed functions, prepare_function_start() won't
3005 have been run to re-initialize it. */
3006 cse_not_expected
= ! optimize
;
3008 /* First, make sure that NOTE_BLOCK is set correctly for each
3009 NOTE_INSN_BLOCK_BEG/NOTE_INSN_BLOCK_END note. */
3010 if (!cfun
->x_whole_function_mode_p
)
3013 /* In function-at-a-time mode, we do not attempt to keep the BLOCK
3014 tree in sensible shape. So, we just recalculate it here. */
3015 if (cfun
->x_whole_function_mode_p
)
3020 if (rest_of_handle_inlining (decl
))
3021 goto exit_rest_of_compilation
;
3023 /* If we're emitting a nested function, make sure its parent gets
3024 emitted as well. Doing otherwise confuses debug info. */
3027 for (parent
= DECL_CONTEXT (current_function_decl
);
3028 parent
!= NULL_TREE
;
3029 parent
= get_containing_scope (parent
))
3030 if (TREE_CODE (parent
) == FUNCTION_DECL
)
3031 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent
)) = 1;
3034 /* We are now committed to emitting code for this function. Do any
3035 preparation, such as emitting abstract debug info for the inline
3036 before it gets mangled by optimization. */
3037 if (DECL_INLINE (decl
))
3038 (*debug_hooks
->outlining_inline_function
) (decl
);
3040 /* Remove any notes we don't need. That will make iterating
3041 over the instruction sequence faster, and allow the garbage
3042 collector to reclaim the memory used by the notes. */
3043 remove_unnecessary_notes ();
3048 /* Initialize some variables used by the optimizers. */
3049 init_function_for_compilation ();
3051 if (! DECL_DEFER_OUTPUT (decl
))
3052 TREE_ASM_WRITTEN (decl
) = 1;
3054 /* Now that integrate will no longer see our rtl, we need not
3055 distinguish between the return value of this function and the
3056 return value of called functions. Also, we can remove all SETs
3057 of subregs of hard registers; they are only here because of
3058 integrate. Also, we can now initialize pseudos intended to
3059 carry magic hard reg data throughout the function. */
3060 rtx_equal_function_value_matters
= 0;
3061 purge_hard_subreg_sets (get_insns ());
3063 /* Early return if there were errors. We can run afoul of our
3064 consistency checks, and there's not really much point in fixing them.
3065 Don't return yet if -Wreturn-type; we need to do cleanup_cfg. */
3066 if (((rtl_dump_and_exit
|| flag_syntax_only
) && !warn_return_type
)
3067 || errorcount
|| sorrycount
)
3068 goto exit_rest_of_compilation
;
3070 timevar_push (TV_JUMP
);
3071 open_dump_file (DFI_sibling
, decl
);
3072 insns
= get_insns ();
3073 rebuild_jump_labels (insns
);
3074 find_exception_handler_labels ();
3075 find_basic_blocks (insns
, max_reg_num (), rtl_dump_file
);
3077 delete_unreachable_blocks ();
3079 /* We have to issue these warnings now already, because CFG cleanups
3080 further down may destroy the required information. */
3081 check_function_return_warnings ();
3083 /* Turn NOTE_INSN_PREDICTIONs into branch predictions. */
3084 if (flag_guess_branch_prob
)
3086 timevar_push (TV_BRANCH_PROB
);
3087 note_prediction_to_br_prob ();
3088 timevar_pop (TV_BRANCH_PROB
);
3091 if (flag_optimize_sibling_calls
)
3092 rest_of_handle_sibling_calls (insns
);
3094 timevar_pop (TV_JUMP
);
3096 insn_locators_initialize ();
3097 /* Complete generation of exception handling code. */
3100 timevar_push (TV_JUMP
);
3101 open_dump_file (DFI_eh
, decl
);
3103 finish_eh_generation ();
3105 close_dump_file (DFI_eh
, print_rtl
, get_insns ());
3106 timevar_pop (TV_JUMP
);
3109 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
3110 generation, which might create new sets. */
3111 emit_initial_value_sets ();
3114 /* If we are doing position-independent code generation, now
3115 is the time to output special prologues and epilogues.
3116 We do not want to do this earlier, because it just clutters
3117 up inline functions with meaningless insns. */
3122 insns
= get_insns ();
3124 /* Copy any shared structure that should not be shared. */
3125 unshare_all_rtl (current_function_decl
, insns
);
3127 #ifdef SETJMP_VIA_SAVE_AREA
3128 /* This must be performed before virtual register instantiation.
3129 Please be aware the everything in the compiler that can look
3130 at the RTL up to this point must understand that REG_SAVE_AREA
3131 is just like a use of the REG contained inside. */
3132 if (current_function_calls_alloca
)
3133 optimize_save_area_alloca (insns
);
3136 /* Instantiate all virtual registers. */
3137 instantiate_virtual_regs (current_function_decl
, insns
);
3139 open_dump_file (DFI_jump
, decl
);
3141 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3142 are initialized and to compute whether control can drop off the end
3145 timevar_push (TV_JUMP
);
3146 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
3147 before jump optimization switches branch directions. */
3148 if (flag_guess_branch_prob
)
3149 expected_value_to_br_prob ();
3151 reg_scan (insns
, max_reg_num (), 0);
3152 rebuild_jump_labels (insns
);
3153 find_basic_blocks (insns
, max_reg_num (), rtl_dump_file
);
3154 delete_trivially_dead_insns (insns
, max_reg_num ());
3156 dump_flow_info (rtl_dump_file
);
3157 cleanup_cfg ((optimize
? CLEANUP_EXPENSIVE
: 0) | CLEANUP_PRE_LOOP
3158 | (flag_thread_jumps
? CLEANUP_THREADING
: 0));
3162 free_bb_for_insn ();
3163 copy_loop_headers (insns
);
3164 find_basic_blocks (insns
, max_reg_num (), rtl_dump_file
);
3166 purge_line_number_notes (insns
);
3168 timevar_pop (TV_JUMP
);
3169 close_dump_file (DFI_jump
, print_rtl
, insns
);
3171 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
3172 if (rtl_dump_and_exit
|| flag_syntax_only
|| DECL_DEFER_OUTPUT (decl
))
3173 goto exit_rest_of_compilation
;
3175 /* Long term, this should probably move before the jump optimizer too,
3176 but I didn't want to disturb the rtl_dump_and_exit and related
3177 stuff at this time. */
3178 if (optimize
> 0 && flag_ssa
)
3179 insns
= rest_of_handle_ssa (decl
, insns
);
3181 timevar_push (TV_JUMP
);
3184 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
3186 if (flag_delete_null_pointer_checks
)
3187 rest_of_handle_null_pointer (decl
, insns
);
3189 /* Jump optimization, and the removal of NULL pointer checks, may
3190 have reduced the number of instructions substantially. CSE, and
3191 future passes, allocate arrays whose dimensions involve the
3192 maximum instruction UID, so if we can reduce the maximum UID
3193 we'll save big on memory. */
3194 renumber_insns (rtl_dump_file
);
3195 timevar_pop (TV_JUMP
);
3197 close_dump_file (DFI_jump
, print_rtl_with_bb
, insns
);
3202 rest_of_handle_cse (decl
, insns
);
3204 rest_of_handle_addressof (decl
, insns
);
3211 rest_of_handle_gcse (decl
, insns
);
3213 if (flag_loop_optimize
)
3214 rest_of_handle_loop_optimize (decl
, insns
);
3217 rest_of_handle_jump_bypass (decl
, insns
);
3220 timevar_push (TV_FLOW
);
3222 rest_of_handle_cfg (decl
, insns
);
3225 || profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
3226 rest_of_handle_branch_prob (decl
, insns
);
3229 rest_of_handle_if_conversion (decl
, insns
);
3232 rest_of_handle_tracer (decl
, insns
);
3235 && (flag_unswitch_loops
3237 || flag_unroll_loops
))
3238 rest_of_handle_loop2 (decl
, insns
);
3240 if (flag_rerun_cse_after_loop
)
3241 rest_of_handle_cse2 (decl
, insns
);
3243 cse_not_expected
= 1;
3245 rest_of_handle_life (decl
, insns
);
3248 rest_of_handle_combine (decl
, insns
);
3250 if (flag_if_conversion
)
3251 rest_of_handle_if_after_combine (decl
, insns
);
3253 if (optimize
> 0 && (flag_regmove
|| flag_expensive_optimizations
))
3254 rest_of_handle_regmove (decl
, insns
);
3256 /* Do unconditional splitting before register allocation to allow machine
3257 description to add extra information not needed previously. */
3258 split_all_insns (1);
3260 #ifdef OPTIMIZE_MODE_SWITCHING
3261 timevar_push (TV_MODE_SWITCH
);
3264 optimize_mode_switching (NULL
);
3267 timevar_pop (TV_MODE_SWITCH
);
3270 /* Any of the several passes since flow1 will have munged register
3271 lifetime data a bit. We need it to be up to date for scheduling
3272 (see handling of reg_known_equiv in init_alias_analysis). */
3273 recompute_reg_usage (insns
, !optimize_size
);
3275 #ifdef INSN_SCHEDULING
3276 rest_of_handle_sched (decl
, insns
);
3279 /* Determine if the current function is a leaf before running reload
3280 since this can impact optimizations done by the prologue and
3281 epilogue thus changing register elimination offsets. */
3282 current_function_is_leaf
= leaf_function_p ();
3284 timevar_push (TV_LOCAL_ALLOC
);
3285 open_dump_file (DFI_lreg
, decl
);
3287 if (flag_new_regalloc
)
3289 if (rest_of_handle_new_regalloc (decl
, insns
,
3290 &rebuild_label_notes_after_reload
))
3291 goto exit_rest_of_compilation
;
3295 if (rest_of_handle_old_regalloc (decl
, insns
,
3296 &rebuild_label_notes_after_reload
))
3297 goto exit_rest_of_compilation
;
3302 open_dump_file (DFI_postreload
, decl
);
3304 /* Do a very simple CSE pass over just the hard registers. */
3307 timevar_push (TV_RELOAD_CSE_REGS
);
3308 reload_cse_regs (insns
);
3309 timevar_pop (TV_RELOAD_CSE_REGS
);
3312 /* Register allocation and reloading may have turned an indirect jump into
3313 a direct jump. If so, we must rebuild the JUMP_LABEL fields of
3314 jumping instructions. */
3315 if (rebuild_label_notes_after_reload
)
3317 timevar_push (TV_JUMP
);
3319 rebuild_jump_labels (insns
);
3320 purge_all_dead_edges (0);
3322 timevar_pop (TV_JUMP
);
3325 close_dump_file (DFI_postreload
, print_rtl_with_bb
, insns
);
3327 /* Re-create the death notes which were deleted during reload. */
3328 timevar_push (TV_FLOW2
);
3329 open_dump_file (DFI_flow2
, decl
);
3331 #ifdef ENABLE_CHECKING
3332 verify_flow_info ();
3335 /* If optimizing, then go ahead and split insns now. */
3339 split_all_insns (0);
3341 if (flag_branch_target_load_optimize
)
3343 open_dump_file (DFI_branch_target_load
, decl
);
3345 branch_target_load_optimize (insns
, false);
3347 close_dump_file (DFI_branch_target_load
, print_rtl_with_bb
, insns
);
3353 cleanup_cfg (CLEANUP_EXPENSIVE
);
3355 /* On some machines, the prologue and epilogue code, or parts thereof,
3356 can be represented as RTL. Doing so lets us schedule insns between
3357 it and the rest of the code and also allows delayed branch
3358 scheduling to operate in the epilogue. */
3359 thread_prologue_and_epilogue_insns (insns
);
3360 epilogue_completed
= 1;
3364 life_analysis (insns
, rtl_dump_file
, PROP_FINAL
);
3365 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_UPDATE_LIFE
3366 | (flag_crossjumping
? CLEANUP_CROSSJUMP
: 0));
3368 /* This is kind of a heuristic. We need to run combine_stack_adjustments
3369 even for machines with possibly nonzero RETURN_POPS_ARGS
3370 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
3371 push instructions will have popping returns. */
3372 #ifndef PUSH_ROUNDING
3373 if (!ACCUMULATE_OUTGOING_ARGS
)
3375 combine_stack_adjustments ();
3380 flow2_completed
= 1;
3382 close_dump_file (DFI_flow2
, print_rtl_with_bb
, insns
);
3383 timevar_pop (TV_FLOW2
);
3385 #ifdef HAVE_peephole2
3386 if (optimize
> 0 && flag_peephole2
)
3388 timevar_push (TV_PEEPHOLE2
);
3389 open_dump_file (DFI_peephole2
, decl
);
3391 peephole2_optimize (rtl_dump_file
);
3393 close_dump_file (DFI_peephole2
, print_rtl_with_bb
, insns
);
3394 timevar_pop (TV_PEEPHOLE2
);
3400 if (flag_rename_registers
|| flag_cprop_registers
)
3401 rest_of_handle_regrename (decl
, insns
);
3403 rest_of_handle_reorder_blocks (decl
, insns
);
3406 if (flag_if_conversion2
)
3408 timevar_push (TV_IFCVT2
);
3409 open_dump_file (DFI_ce3
, decl
);
3413 close_dump_file (DFI_ce3
, print_rtl_with_bb
, insns
);
3414 timevar_pop (TV_IFCVT2
);
3417 if (flag_branch_target_load_optimize2
)
3419 /* Leave this a warning for now so that it is possible to experiment
3420 with running this pass twice. In 3.6, we should either make this
3421 an error, or use separate dump files. */
3422 if (flag_branch_target_load_optimize
)
3423 warning ("branch target register load optimization is not intended "
3426 open_dump_file (DFI_branch_target_load
, decl
);
3428 branch_target_load_optimize (insns
, true);
3430 close_dump_file (DFI_branch_target_load
, print_rtl_with_bb
, insns
);
3435 #ifdef INSN_SCHEDULING
3436 if (optimize
> 0 && flag_schedule_insns_after_reload
)
3437 rest_of_handle_sched2 (decl
, insns
);
3440 #ifdef LEAF_REGISTERS
3441 current_function_uses_only_leaf_regs
3442 = optimize
> 0 && only_leaf_regs_used () && leaf_function_p ();
3446 rest_of_handle_stack_regs (decl
, insns
);
3449 compute_alignments ();
3451 /* CFG is no longer maintained up-to-date. */
3452 free_bb_for_insn ();
3454 if (targetm
.machine_dependent_reorg
!= 0)
3455 rest_of_handle_machine_reorg (decl
, insns
);
3457 purge_line_number_notes (insns
);
3458 cleanup_barriers ();
3461 if (optimize
> 0 && flag_delayed_branch
)
3462 rest_of_handle_delay_slots (decl
, insns
);
3465 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3466 timevar_push (TV_SHORTEN_BRANCH
);
3467 split_all_insns_noflow ();
3468 timevar_pop (TV_SHORTEN_BRANCH
);
3471 convert_to_eh_region_ranges ();
3473 /* Shorten branches. */
3474 timevar_push (TV_SHORTEN_BRANCH
);
3475 shorten_branches (get_insns ());
3476 timevar_pop (TV_SHORTEN_BRANCH
);
3478 set_nothrow_function_flags ();
3479 if (current_function_nothrow
)
3480 /* Now we know that this can't throw; set the flag for the benefit
3481 of other functions later in this translation unit. */
3482 TREE_NOTHROW (current_function_decl
) = 1;
3484 rest_of_handle_final (decl
, insns
);
3486 /* Write DBX symbols if requested. */
3488 /* Note that for those inline functions where we don't initially
3489 know for certain that we will be generating an out-of-line copy,
3490 the first invocation of this routine (rest_of_compilation) will
3491 skip over this code by doing a `goto exit_rest_of_compilation;'.
3492 Later on, wrapup_global_declarations will (indirectly) call
3493 rest_of_compilation again for those inline functions that need
3494 to have out-of-line copies generated. During that call, we
3495 *will* be routed past here. */
3497 timevar_push (TV_SYMOUT
);
3498 (*debug_hooks
->function_decl
) (decl
);
3499 timevar_pop (TV_SYMOUT
);
3501 exit_rest_of_compilation
:
3503 coverage_end_function ();
3505 /* In case the function was not output,
3506 don't leave any temporary anonymous types
3507 queued up for sdb output. */
3508 #ifdef SDB_DEBUGGING_INFO
3509 if (write_symbols
== SDB_DEBUG
)
3510 sdbout_types (NULL_TREE
);
3513 reload_completed
= 0;
3514 epilogue_completed
= 0;
3515 flow2_completed
= 0;
3518 timevar_push (TV_FINAL
);
3520 /* Clear out the insn_length contents now that they are no
3522 init_insn_lengths ();
3524 /* Show no temporary slots allocated. */
3527 free_basic_block_vars (0);
3528 free_bb_for_insn ();
3530 timevar_pop (TV_FINAL
);
3532 if ((*targetm
.binds_local_p
) (current_function_decl
))
3534 int pref
= cfun
->preferred_stack_boundary
;
3535 if (cfun
->recursive_call_emit
3536 && cfun
->stack_alignment_needed
> cfun
->preferred_stack_boundary
)
3537 pref
= cfun
->stack_alignment_needed
;
3538 cgraph_rtl_info (current_function_decl
)->preferred_incoming_stack_boundary
3542 /* Make sure volatile mem refs aren't considered valid operands for
3543 arithmetic insns. We must call this here if this is a nested inline
3544 function, since the above code leaves us in the init_recog state
3545 (from final.c), and the function context push/pop code does not
3546 save/restore volatile_ok.
3548 ??? Maybe it isn't necessary for expand_start_function to call this
3549 anymore if we do it here? */
3551 init_recog_no_volatile ();
3553 /* We're done with this function. Free up memory if we can. */
3554 free_after_parsing (cfun
);
3555 if (! DECL_DEFER_OUTPUT (decl
))
3557 free_after_compilation (cfun
);
3558 DECL_SAVED_INSNS (decl
) = 0;
3564 timevar_pop (TV_REST_OF_COMPILATION
);
3567 /* Display help for target options. */
3569 display_target_options (void)
3572 static bool displayed
= false;
3574 /* Avoid double printing for --help --target-help. */
3580 if (ARRAY_SIZE (target_switches
) > 1
3581 #ifdef TARGET_OPTIONS
3582 || ARRAY_SIZE (target_options
) > 1
3590 printf (_("\nTarget specific options:\n"));
3592 for (i
= ARRAY_SIZE (target_switches
); i
--;)
3594 const char *option
= target_switches
[i
].name
;
3595 const char *description
= target_switches
[i
].description
;
3597 if (option
== NULL
|| *option
== 0)
3599 else if (description
== NULL
)
3604 printf (_(" -m%-23s [undocumented]\n"), option
);
3606 else if (*description
!= 0)
3607 doc
+= printf (" -m%-23s %s\n", option
, _(description
));
3610 #ifdef TARGET_OPTIONS
3611 for (i
= ARRAY_SIZE (target_options
); i
--;)
3613 const char *option
= target_options
[i
].prefix
;
3614 const char *description
= target_options
[i
].description
;
3616 if (option
== NULL
|| *option
== 0)
3618 else if (description
== NULL
)
3623 printf (_(" -m%-23s [undocumented]\n"), option
);
3625 else if (*description
!= 0)
3626 doc
+= printf (" -m%-23s %s\n", option
, _(description
));
3632 printf (_("\nThere are undocumented target specific options as well.\n"));
3634 printf (_(" They exist, but they are not documented.\n"));
3639 /* Parse a -d... command line switch. */
3642 decode_d_option (const char *arg
)
3650 for (i
= 0; i
< (int) DFI_MAX
; ++i
)
3651 dump_file
[i
].enabled
= 1;
3657 flag_print_asm_name
= 1;
3660 flag_dump_rtl_in_asm
= 1;
3661 flag_print_asm_name
= 1;
3664 graph_dump_format
= vcg
;
3667 rtl_dump_and_exit
= 1;
3672 case 'D': /* These are handled by the preprocessor. */
3676 setup_core_dumping();
3681 for (i
= 0; i
< (int) DFI_MAX
; ++i
)
3682 if (c
== dump_file
[i
].debug_switch
)
3684 dump_file
[i
].enabled
= 1;
3689 warning ("unrecognized gcc debugging option: %c", c
);
3694 /* Indexed by enum debug_info_type. */
3695 const char *const debug_type_names
[] =
3697 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
3700 /* Decode -m switches. */
3701 /* Decode the switch -mNAME. */
3704 set_target_switch (const char *name
)
3707 int valid_target_option
= 0;
3709 for (j
= 0; j
< ARRAY_SIZE (target_switches
); j
++)
3710 if (!strcmp (target_switches
[j
].name
, name
))
3712 if (target_switches
[j
].value
< 0)
3713 target_flags
&= ~-target_switches
[j
].value
;
3715 target_flags
|= target_switches
[j
].value
;
3718 if (target_switches
[j
].value
< 0)
3719 target_flags_explicit
|= -target_switches
[j
].value
;
3721 target_flags_explicit
|= target_switches
[j
].value
;
3723 valid_target_option
= 1;
3726 #ifdef TARGET_OPTIONS
3727 if (!valid_target_option
)
3728 for (j
= 0; j
< ARRAY_SIZE (target_options
); j
++)
3730 int len
= strlen (target_options
[j
].prefix
);
3731 if (target_options
[j
].value
)
3733 if (!strcmp (target_options
[j
].prefix
, name
))
3735 *target_options
[j
].variable
= target_options
[j
].value
;
3736 valid_target_option
= 1;
3741 if (!strncmp (target_options
[j
].prefix
, name
, len
))
3743 *target_options
[j
].variable
= name
+ len
;
3744 valid_target_option
= 1;
3750 if (!valid_target_option
)
3751 error ("invalid option `%s'", name
);
3754 /* Print version information to FILE.
3755 Each line begins with INDENT (for the case where FILE is the
3756 assembler output file). */
3759 print_version (FILE *file
, const char *indent
)
3762 #define __VERSION__ "[?]"
3766 "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
3768 "%s%s%s version %s (%s) compiled by CC.\n"
3770 , indent
, *indent
!= 0 ? " " : "",
3771 lang_hooks
.name
, version_string
, TARGET_NAME
,
3772 indent
, __VERSION__
);
3773 fnotice (file
, "%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n",
3774 indent
, *indent
!= 0 ? " " : "",
3775 PARAM_VALUE (GGC_MIN_EXPAND
), PARAM_VALUE (GGC_MIN_HEAPSIZE
));
3778 /* Print an option value and return the adjusted position in the line.
3779 ??? We don't handle error returns from fprintf (disk full); presumably
3780 other code will catch a disk full though. */
3783 print_single_switch (FILE *file
, int pos
, int max
,
3784 const char *indent
, const char *sep
, const char *term
,
3785 const char *type
, const char *name
)
3787 /* The ultrix fprintf returns 0 on success, so compute the result we want
3788 here since we need it for the following test. */
3789 int len
= strlen (sep
) + strlen (type
) + strlen (name
);
3794 fprintf (file
, "%s", term
);
3799 fprintf (file
, "%s", indent
);
3800 pos
= strlen (indent
);
3802 fprintf (file
, "%s%s%s", sep
, type
, name
);
3807 /* Print active target switches to FILE.
3808 POS is the current cursor position and MAX is the size of a "line".
3809 Each line begins with INDENT and ends with TERM.
3810 Each switch is separated from the next by SEP. */
3813 print_switch_values (FILE *file
, int pos
, int max
,
3814 const char *indent
, const char *sep
, const char *term
)
3819 /* Fill in the -frandom-seed option, if the user didn't pass it, so
3820 that it can be printed below. This helps reproducibility. */
3823 /* Print the options as passed. */
3824 pos
= print_single_switch (file
, pos
, max
, indent
, *indent
? " " : "", term
,
3825 _("options passed: "), "");
3827 for (p
= &save_argv
[1]; *p
!= NULL
; p
++)
3831 if (strcmp (*p
, "-o") == 0)
3837 if (strcmp (*p
, "-quiet") == 0)
3839 if (strcmp (*p
, "-version") == 0)
3844 pos
= print_single_switch (file
, pos
, max
, indent
, sep
, term
, *p
, "");
3847 fprintf (file
, "%s", term
);
3849 /* Print the -f and -m options that have been enabled.
3850 We don't handle language specific options but printing argv
3853 pos
= print_single_switch (file
, 0, max
, indent
, *indent
? " " : "", term
,
3854 _("options enabled: "), "");
3856 for (j
= 0; j
< ARRAY_SIZE (f_options
); j
++)
3857 if (*f_options
[j
].variable
== f_options
[j
].on_value
)
3858 pos
= print_single_switch (file
, pos
, max
, indent
, sep
, term
,
3859 "-f", f_options
[j
].string
);
3861 /* Print target specific options. */
3863 for (j
= 0; j
< ARRAY_SIZE (target_switches
); j
++)
3864 if (target_switches
[j
].name
[0] != '\0'
3865 && target_switches
[j
].value
> 0
3866 && ((target_switches
[j
].value
& target_flags
)
3867 == target_switches
[j
].value
))
3869 pos
= print_single_switch (file
, pos
, max
, indent
, sep
, term
,
3870 "-m", target_switches
[j
].name
);
3873 #ifdef TARGET_OPTIONS
3874 for (j
= 0; j
< ARRAY_SIZE (target_options
); j
++)
3875 if (*target_options
[j
].variable
!= NULL
)
3878 sprintf (prefix
, "-m%s", target_options
[j
].prefix
);
3879 pos
= print_single_switch (file
, pos
, max
, indent
, sep
, term
,
3880 prefix
, *target_options
[j
].variable
);
3884 fprintf (file
, "%s", term
);
3887 /* Open assembly code output file. Do this even if -fsyntax-only is
3888 on, because then the driver will have provided the name of a
3889 temporary file or bit bucket for us. NAME is the file specified on
3890 the command line, possibly NULL. */
3892 init_asm_output (const char *name
)
3894 if (name
== NULL
&& asm_file_name
== 0)
3895 asm_out_file
= stdout
;
3898 if (asm_file_name
== 0)
3900 int len
= strlen (dump_base_name
);
3901 char *dumpname
= xmalloc (len
+ 6);
3902 memcpy (dumpname
, dump_base_name
, len
+ 1);
3903 strip_off_ending (dumpname
, len
);
3904 strcat (dumpname
, ".s");
3905 asm_file_name
= dumpname
;
3907 if (!strcmp (asm_file_name
, "-"))
3908 asm_out_file
= stdout
;
3910 asm_out_file
= fopen (asm_file_name
, "w+");
3911 if (asm_out_file
== 0)
3912 fatal_error ("can't open %s for writing: %m", asm_file_name
);
3915 #ifdef IO_BUFFER_SIZE
3916 setvbuf (asm_out_file
, xmalloc (IO_BUFFER_SIZE
),
3917 _IOFBF
, IO_BUFFER_SIZE
);
3920 if (!flag_syntax_only
)
3922 targetm
.asm_out
.file_start ();
3924 #ifdef ASM_COMMENT_START
3925 if (flag_verbose_asm
)
3927 /* Print the list of options in effect. */
3928 print_version (asm_out_file
, ASM_COMMENT_START
);
3929 print_switch_values (asm_out_file
, 0, MAX_LINE
,
3930 ASM_COMMENT_START
, " ", "\n");
3931 /* Add a blank line here so it appears in assembler output but not
3933 fprintf (asm_out_file
, "\n");
3939 /* Default tree printer. Handles declarations only. */
3941 default_tree_printer (pretty_printer
* pp
, text_info
*text
)
3943 switch (*text
->format_spec
)
3949 tree t
= va_arg (*text
->args_ptr
, tree
);
3950 const char *n
= DECL_NAME (t
)
3951 ? (*lang_hooks
.decl_printable_name
) (t
, 2)
3962 /* Initialization of the front end environment, before command line
3963 options are parsed. Signal handlers, internationalization etc.
3964 ARGV0 is main's argv[0]. */
3966 general_init (const char *argv0
)
3970 p
= argv0
+ strlen (argv0
);
3971 while (p
!= argv0
&& !IS_DIR_SEPARATOR (p
[-1]))
3975 xmalloc_set_program_name (progname
);
3979 gcc_init_libintl ();
3981 /* Initialize the diagnostics reporting machinery, so option parsing
3982 can give warnings and errors. */
3983 diagnostic_initialize (global_dc
);
3984 /* Set a default printer. Language specific initializations will
3985 override it later. */
3986 pp_format_decoder (global_dc
->printer
) = &default_tree_printer
;
3988 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
3990 signal (SIGSEGV
, crash_signal
);
3993 signal (SIGILL
, crash_signal
);
3996 signal (SIGBUS
, crash_signal
);
3999 signal (SIGABRT
, crash_signal
);
4001 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
4002 signal (SIGIOT
, crash_signal
);
4005 signal (SIGFPE
, crash_signal
);
4008 /* Other host-specific signal setup. */
4009 (*host_hooks
.extra_signals
)();
4011 /* Initialize the garbage-collector, string pools and tree type hash
4017 /* Initialize register usage now so switches may override. */
4020 /* Register the language-independent parameters. */
4021 add_params (lang_independent_params
, LAST_PARAM
);
4023 /* This must be done after add_params but before argument processing. */
4024 init_ggc_heuristics();
4027 /* Process the options that have been parsed. */
4029 process_options (void)
4031 /* Allow the front end to perform consistency checks and do further
4032 initialization based on the command line options. This hook also
4033 sets the original filename if appropriate (e.g. foo.i -> foo.c)
4034 so we can correctly initialize debug output. */
4035 no_backend
= (*lang_hooks
.post_options
) (&main_input_filename
);
4036 input_filename
= main_input_filename
;
4038 #ifdef OVERRIDE_OPTIONS
4039 /* Some machines may reject certain combinations of options. */
4043 /* Set aux_base_name if not already set. */
4046 else if (main_input_filename
)
4048 char *name
= xstrdup (lbasename (main_input_filename
));
4050 strip_off_ending (name
, strlen (name
));
4051 aux_base_name
= name
;
4054 aux_base_name
= "gccaux";
4056 /* Set up the align_*_log variables, defaulting them to 1 if they
4057 were still unset. */
4058 if (align_loops
<= 0) align_loops
= 1;
4059 if (align_loops_max_skip
> align_loops
|| !align_loops
)
4060 align_loops_max_skip
= align_loops
- 1;
4061 align_loops_log
= floor_log2 (align_loops
* 2 - 1);
4062 if (align_jumps
<= 0) align_jumps
= 1;
4063 if (align_jumps_max_skip
> align_jumps
|| !align_jumps
)
4064 align_jumps_max_skip
= align_jumps
- 1;
4065 align_jumps_log
= floor_log2 (align_jumps
* 2 - 1);
4066 if (align_labels
<= 0) align_labels
= 1;
4067 align_labels_log
= floor_log2 (align_labels
* 2 - 1);
4068 if (align_labels_max_skip
> align_labels
|| !align_labels
)
4069 align_labels_max_skip
= align_labels
- 1;
4070 if (align_functions
<= 0) align_functions
= 1;
4071 align_functions_log
= floor_log2 (align_functions
* 2 - 1);
4073 /* Unrolling all loops implies that standard loop unrolling must also
4075 if (flag_unroll_all_loops
)
4076 flag_unroll_loops
= 1;
4078 if (flag_unroll_loops
)
4080 flag_old_unroll_loops
= 0;
4081 flag_old_unroll_all_loops
= 0;
4084 if (flag_old_unroll_all_loops
)
4085 flag_old_unroll_loops
= 1;
4087 /* Old loop unrolling requires that strength_reduction be on also. Silently
4088 turn on strength reduction here if it isn't already on. Also, the loop
4089 unrolling code assumes that cse will be run after loop, so that must
4090 be turned on also. */
4091 if (flag_old_unroll_loops
)
4093 flag_strength_reduce
= 1;
4094 flag_rerun_cse_after_loop
= 1;
4096 if (flag_unroll_loops
|| flag_peel_loops
)
4097 flag_rerun_cse_after_loop
= 1;
4099 if (flag_non_call_exceptions
)
4100 flag_asynchronous_unwind_tables
= 1;
4101 if (flag_asynchronous_unwind_tables
)
4102 flag_unwind_tables
= 1;
4104 /* Disable unit-at-a-time mode for frontends not supporting callgraph
4106 if (flag_unit_at_a_time
&& ! lang_hooks
.callgraph
.expand_function
)
4107 flag_unit_at_a_time
= 0;
4109 /* Warn about options that are not supported on this machine. */
4110 #ifndef INSN_SCHEDULING
4111 if (flag_schedule_insns
|| flag_schedule_insns_after_reload
)
4112 warning ("instruction scheduling not supported on this target machine");
4115 if (flag_delayed_branch
)
4116 warning ("this target machine does not have delayed branches");
4119 user_label_prefix
= USER_LABEL_PREFIX
;
4120 if (flag_leading_underscore
!= -1)
4122 /* If the default prefix is more complicated than "" or "_",
4123 issue a warning and ignore this option. */
4124 if (user_label_prefix
[0] == 0 ||
4125 (user_label_prefix
[0] == '_' && user_label_prefix
[1] == 0))
4127 user_label_prefix
= flag_leading_underscore
? "_" : "";
4130 warning ("-f%sleading-underscore not supported on this target machine",
4131 flag_leading_underscore
? "" : "no-");
4134 /* If we are in verbose mode, write out the version and maybe all the
4135 option flags in use. */
4138 print_version (stderr
, "");
4140 print_switch_values (stderr
, 0, MAX_LINE
, "", " ", "\n");
4143 if (flag_syntax_only
)
4145 write_symbols
= NO_DEBUG
;
4149 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
4151 if (debug_info_level
== DINFO_LEVEL_NONE
)
4152 write_symbols
= NO_DEBUG
;
4154 /* Now we know write_symbols, set up the debug hooks based on it.
4155 By default we do nothing for debug output. */
4156 if (write_symbols
== NO_DEBUG
)
4157 debug_hooks
= &do_nothing_debug_hooks
;
4158 #if defined(DBX_DEBUGGING_INFO)
4159 else if (write_symbols
== DBX_DEBUG
)
4160 debug_hooks
= &dbx_debug_hooks
;
4162 #if defined(XCOFF_DEBUGGING_INFO)
4163 else if (write_symbols
== XCOFF_DEBUG
)
4164 debug_hooks
= &xcoff_debug_hooks
;
4166 #ifdef SDB_DEBUGGING_INFO
4167 else if (write_symbols
== SDB_DEBUG
)
4168 debug_hooks
= &sdb_debug_hooks
;
4170 #ifdef DWARF_DEBUGGING_INFO
4171 else if (write_symbols
== DWARF_DEBUG
)
4172 debug_hooks
= &dwarf_debug_hooks
;
4174 #ifdef DWARF2_DEBUGGING_INFO
4175 else if (write_symbols
== DWARF2_DEBUG
)
4176 debug_hooks
= &dwarf2_debug_hooks
;
4178 #ifdef VMS_DEBUGGING_INFO
4179 else if (write_symbols
== VMS_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
4180 debug_hooks
= &vmsdbg_debug_hooks
;
4183 error ("target system does not support the \"%s\" debug format",
4184 debug_type_names
[write_symbols
]);
4186 /* If auxiliary info generation is desired, open the output file.
4187 This goes in the same directory as the source file--unlike
4188 all the other output files. */
4189 if (flag_gen_aux_info
)
4191 aux_info_file
= fopen (aux_info_file_name
, "w");
4192 if (aux_info_file
== 0)
4193 fatal_error ("can't open %s: %m", aux_info_file_name
);
4196 if (! targetm
.have_named_sections
)
4198 if (flag_function_sections
)
4200 warning ("-ffunction-sections not supported for this target");
4201 flag_function_sections
= 0;
4203 if (flag_data_sections
)
4205 warning ("-fdata-sections not supported for this target");
4206 flag_data_sections
= 0;
4210 if (flag_function_sections
&& profile_flag
)
4212 warning ("-ffunction-sections disabled; it makes profiling impossible");
4213 flag_function_sections
= 0;
4216 #ifndef HAVE_prefetch
4217 if (flag_prefetch_loop_arrays
)
4219 warning ("-fprefetch-loop-arrays not supported for this target");
4220 flag_prefetch_loop_arrays
= 0;
4223 if (flag_prefetch_loop_arrays
&& !HAVE_prefetch
)
4225 warning ("-fprefetch-loop-arrays not supported for this target (try -march switches)");
4226 flag_prefetch_loop_arrays
= 0;
4230 /* This combination of options isn't handled for i386 targets and doesn't
4231 make much sense anyway, so don't allow it. */
4232 if (flag_prefetch_loop_arrays
&& optimize_size
)
4234 warning ("-fprefetch-loop-arrays is not supported with -Os");
4235 flag_prefetch_loop_arrays
= 0;
4238 #ifndef OBJECT_FORMAT_ELF
4239 if (flag_function_sections
&& write_symbols
!= NO_DEBUG
)
4240 warning ("-ffunction-sections may affect debugging on some targets");
4243 /* The presence of IEEE signaling NaNs, implies all math can trap. */
4244 if (flag_signaling_nans
)
4245 flag_trapping_math
= 1;
4248 /* Initialize the compiler back end. */
4252 init_emit_once (debug_info_level
== DINFO_LEVEL_NORMAL
4253 || debug_info_level
== DINFO_LEVEL_VERBOSE
4254 #ifdef VMS_DEBUGGING_INFO
4255 /* Enable line number info for traceback. */
4256 || debug_info_level
> DINFO_LEVEL_NONE
4258 || flag_test_coverage
4259 || warn_notreached
);
4262 init_fake_stack_mems ();
4266 init_function_once ();
4267 init_varasm_once ();
4269 /* The following initialization functions need to generate rtl, so
4270 provide a dummy function context for them. */
4271 init_dummy_function_start ();
4273 if (flag_caller_saves
)
4274 init_caller_save ();
4275 expand_dummy_function_end ();
4278 /* Language-dependent initialization. Returns nonzero on success. */
4280 lang_dependent_init (const char *name
)
4282 if (dump_base_name
== 0)
4283 dump_base_name
= name
? name
: "gccdump";
4285 /* Other front-end initialization. */
4286 if ((*lang_hooks
.init
) () == 0)
4289 init_asm_output (name
);
4291 /* These create various _DECL nodes, so need to be called after the
4292 front end is initialized. */
4296 /* The following initialization functions need to generate rtl, so
4297 provide a dummy function context for them. */
4298 init_dummy_function_start ();
4300 expand_dummy_function_end ();
4302 /* If dbx symbol table desired, initialize writing it and output the
4303 predefined types. */
4304 timevar_push (TV_SYMOUT
);
4306 #ifdef DWARF2_UNWIND_INFO
4307 if (dwarf2out_do_frame ())
4308 dwarf2out_frame_init ();
4311 /* Now we have the correct original filename, we can initialize
4313 (*debug_hooks
->init
) (name
);
4315 timevar_pop (TV_SYMOUT
);
4320 /* Clean up: close opened files, etc. */
4325 /* Close the dump files. */
4326 if (flag_gen_aux_info
)
4328 fclose (aux_info_file
);
4330 unlink (aux_info_file_name
);
4333 /* Close non-debugging input and output files. Take special care to note
4334 whether fclose returns an error, since the pages might still be on the
4335 buffer chain while the file is open. */
4339 if (ferror (asm_out_file
) != 0)
4340 fatal_error ("error writing to %s: %m", asm_file_name
);
4341 if (fclose (asm_out_file
) != 0)
4342 fatal_error ("error closing %s: %m", asm_file_name
);
4345 /* Do whatever is necessary to finish printing the graphs. */
4346 if (graph_dump_format
!= no_graph
)
4350 for (i
= 0; i
< (int) DFI_MAX
; ++i
)
4351 if (dump_file
[i
].initialized
&& dump_file
[i
].graph_dump_p
)
4356 sprintf (seq
, DUMPFILE_FORMAT
, i
);
4357 suffix
= concat (seq
, dump_file
[i
].extension
, NULL
);
4358 finish_graph_dump_file (dump_base_name
, suffix
);
4365 ggc_print_statistics ();
4366 stringpool_statistics ();
4367 dump_tree_statistics ();
4370 /* Free up memory for the benefit of leak detectors. */
4373 /* Language-specific end of compilation actions. */
4374 (*lang_hooks
.finish
) ();
4377 /* Initialize the compiler, and compile the input file. */
4381 /* Initialize timing first. The C front ends read the main file in
4382 the post_options hook, and C++ does file timings. */
4383 if (time_report
|| !quiet_flag
|| flag_detailed_statistics
)
4385 timevar_start (TV_TOTAL
);
4389 /* Don't do any more if an error has already occurred. */
4392 /* Set up the back-end if requested. */
4396 /* Language-dependent initialization. Returns true on success. */
4397 if (lang_dependent_init (main_input_filename
))
4399 if (flag_unit_at_a_time
)
4401 open_dump_file (DFI_cgraph
, NULL
);
4402 cgraph_dump_file
= rtl_dump_file
;
4403 rtl_dump_file
= NULL
;
4408 if (flag_unit_at_a_time
)
4410 rtl_dump_file
= cgraph_dump_file
;
4411 cgraph_dump_file
= NULL
;
4412 close_dump_file (DFI_cgraph
, NULL
, NULL_RTX
);
4419 /* Stop timing and print the times. */
4420 timevar_stop (TV_TOTAL
);
4421 timevar_print (stderr
);
4424 /* Entry point of cc1, cc1plus, jc1, f771, etc.
4425 Exit code is FATAL_EXIT_CODE if can't open files or if there were
4426 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
4428 It is not safe to call this function more than once. */
4431 toplev_main (unsigned int argc
, const char **argv
)
4435 /* Initialization of GCC's environment, and diagnostics. */
4436 general_init (argv
[0]);
4438 /* Parse the options and do minimal processing; basically just
4439 enough to default flags appropriately. */
4440 decode_options (argc
, argv
);
4444 /* Exit early if we can (e.g. -help). */
4445 if (!exit_after_options
)
4448 if (errorcount
|| sorrycount
)
4449 return (FATAL_EXIT_CODE
);
4451 return (SUCCESS_EXIT_CODE
);