* cse.c (count_reg_usage): Fix handling of REG_EQUAL notes.
[official-gcc.git] / gcc / toplev.c
blobae068d43472c09c86d6c7afda10013e6a60669db
1 /* Top level of GNU C compiler
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
10 version.
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
15 for more details.
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
20 02111-1307, USA. */
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. */
27 #include "config.h"
28 #undef FLOAT /* This is for hpux. They should change hpux. */
29 #undef FFS /* Some systems define this in param.h. */
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tm.h"
33 #include <signal.h>
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
37 #endif
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
41 #endif
43 #include "input.h"
44 #include "tree.h"
45 #include "rtl.h"
46 #include "tm_p.h"
47 #include "flags.h"
48 #include "insn-attr.h"
49 #include "insn-config.h"
50 #include "insn-flags.h"
51 #include "hard-reg-set.h"
52 #include "recog.h"
53 #include "output.h"
54 #include "except.h"
55 #include "function.h"
56 #include "toplev.h"
57 #include "expr.h"
58 #include "basic-block.h"
59 #include "intl.h"
60 #include "ggc.h"
61 #include "graph.h"
62 #include "loop.h"
63 #include "regs.h"
64 #include "timevar.h"
65 #include "diagnostic.h"
66 #include "ssa.h"
67 #include "params.h"
68 #include "reload.h"
69 #include "dwarf2asm.h"
70 #include "integrate.h"
71 #include "real.h"
72 #include "debug.h"
73 #include "target.h"
74 #include "langhooks.h"
75 #include "cfglayout.h"
76 #include "cfgloop.h"
77 #include "hosthooks.h"
79 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
80 #include "dwarf2out.h"
81 #endif
83 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
84 #include "dbxout.h"
85 #endif
87 #ifdef SDB_DEBUGGING_INFO
88 #include "sdbout.h"
89 #endif
91 #ifdef XCOFF_DEBUGGING_INFO
92 #include "xcoffout.h" /* Needed for external data
93 declarations for e.g. AIX 4.x. */
94 #endif
96 /* Carry information from ASM_DECLARE_OBJECT_NAME
97 to ASM_FINISH_DECLARE_OBJECT. */
99 extern int size_directive_output;
100 extern tree last_assemble_variable_decl;
102 extern void reg_alloc PARAMS ((void));
104 static void general_init PARAMS ((char *));
105 static void parse_options_and_default_flags PARAMS ((int, char **));
106 static void do_compile PARAMS ((void));
107 static void process_options PARAMS ((void));
108 static void backend_init PARAMS ((void));
109 static int lang_dependent_init PARAMS ((const char *));
110 static void init_asm_output PARAMS ((const char *));
111 static void finalize PARAMS ((void));
113 static void set_target_switch PARAMS ((const char *));
115 static void crash_signal PARAMS ((int)) ATTRIBUTE_NORETURN;
116 static void setup_core_dumping PARAMS ((void));
117 static void compile_file PARAMS ((void));
118 static void display_help PARAMS ((void));
119 static void display_target_options PARAMS ((void));
121 static void decode_d_option PARAMS ((const char *));
122 static int decode_f_option PARAMS ((const char *));
123 static int decode_W_option PARAMS ((const char *));
124 static int decode_g_option PARAMS ((const char *));
125 static unsigned int independent_decode_option PARAMS ((int, char **));
127 static void print_version PARAMS ((FILE *, const char *));
128 static int print_single_switch PARAMS ((FILE *, int, int, const char *,
129 const char *, const char *,
130 const char *, const char *));
131 static void print_switch_values PARAMS ((FILE *, int, int, const char *,
132 const char *, const char *));
134 /* Nonzero to dump debug info whilst parsing (-dy option). */
135 static int set_yydebug;
137 /* Length of line when printing switch values. */
138 #define MAX_LINE 75
140 /* Name of program invoked, sans directories. */
142 const char *progname;
144 /* Copy of arguments to toplev_main. */
145 int save_argc;
146 char **save_argv;
148 /* Name of current original source file (what was input to cpp).
149 This comes from each #-command in the actual input. */
151 const char *input_filename;
153 /* Name of top-level original source file (what was input to cpp).
154 This comes from the #-command at the beginning of the actual input.
155 If there isn't any there, then this is the cc1 input file name. */
157 const char *main_input_filename;
159 /* Current line number in real source file. */
161 int lineno;
163 /* Nonzero if it is unsafe to create any new pseudo registers. */
164 int no_new_pseudos;
166 /* Stack of currently pending input files. */
168 struct file_stack *input_file_stack;
170 /* Incremented on each change to input_file_stack. */
171 int input_file_stack_tick;
173 /* Name to use as base of names for dump output files. */
175 const char *dump_base_name;
177 /* Name to use as a base for auxiliary output files. */
179 const char *aux_base_name;
181 /* Format to use to print dumpfile index value */
182 #ifndef DUMPFILE_FORMAT
183 #define DUMPFILE_FORMAT ".%02d."
184 #endif
186 /* Bit flags that specify the machine subtype we are compiling for.
187 Bits are tested using macros TARGET_... defined in the tm.h file
188 and set by `-m...' switches. Must be defined in rtlanal.c. */
190 extern int target_flags;
192 /* A mask of target_flags that includes bit X if X was set or cleared
193 on the command line. */
195 int target_flags_explicit;
197 /* Debug hooks - dependent upon command line options. */
199 const struct gcc_debug_hooks *debug_hooks = &do_nothing_debug_hooks;
201 /* Describes a dump file. */
203 struct dump_file_info
205 /* The unique extension to apply, e.g. ".jump". */
206 const char *const extension;
208 /* The -d<c> character that enables this dump file. */
209 char const debug_switch;
211 /* True if there is a corresponding graph dump file. */
212 char const graph_dump_p;
214 /* True if the user selected this dump. */
215 char enabled;
217 /* True if the files have been initialized (ie truncated). */
218 char initialized;
221 /* Enumerate the extant dump files. */
223 enum dump_file_index
225 DFI_rtl,
226 DFI_sibling,
227 DFI_eh,
228 DFI_jump,
229 DFI_ssa,
230 DFI_ssa_ccp,
231 DFI_ssa_dce,
232 DFI_ussa,
233 DFI_null,
234 DFI_cse,
235 DFI_addressof,
236 DFI_gcse,
237 DFI_loop,
238 DFI_bypass,
239 DFI_cfg,
240 DFI_bp,
241 DFI_ce1,
242 DFI_tracer,
243 DFI_loop2,
244 DFI_cse2,
245 DFI_life,
246 DFI_combine,
247 DFI_ce2,
248 DFI_regmove,
249 DFI_sched,
250 DFI_lreg,
251 DFI_greg,
252 DFI_postreload,
253 DFI_flow2,
254 DFI_peephole2,
255 DFI_rnreg,
256 DFI_ce3,
257 DFI_bbro,
258 DFI_sched2,
259 DFI_stack,
260 DFI_mach,
261 DFI_dbr,
262 DFI_MAX
265 /* Describes all the dump files. Should be kept in order of the
266 pass and in sync with dump_file_index above.
268 Remaining -d letters:
270 " o q "
271 " H JK OPQ TUV YZ"
274 static struct dump_file_info dump_file[DFI_MAX] =
276 { "rtl", 'r', 0, 0, 0 },
277 { "sibling", 'i', 0, 0, 0 },
278 { "eh", 'h', 0, 0, 0 },
279 { "jump", 'j', 0, 0, 0 },
280 { "ssa", 'e', 1, 0, 0 },
281 { "ssaccp", 'W', 1, 0, 0 },
282 { "ssadce", 'X', 1, 0, 0 },
283 { "ussa", 'e', 1, 0, 0 }, /* Yes, duplicate enable switch. */
284 { "null", 'u', 0, 0, 0 },
285 { "cse", 's', 0, 0, 0 },
286 { "addressof", 'F', 0, 0, 0 },
287 { "gcse", 'G', 1, 0, 0 },
288 { "loop", 'L', 1, 0, 0 },
289 { "bypass", 'G', 1, 0, 0 }, /* Yes, duplicate enable switch. */
290 { "cfg", 'f', 1, 0, 0 },
291 { "bp", 'b', 1, 0, 0 },
292 { "ce1", 'C', 1, 0, 0 },
293 { "tracer", 'T', 1, 0, 0 },
294 { "loop2", 'L', 1, 0, 0 },
295 { "cse2", 't', 1, 0, 0 },
296 { "life", 'f', 1, 0, 0 }, /* Yes, duplicate enable switch. */
297 { "combine", 'c', 1, 0, 0 },
298 { "ce2", 'C', 1, 0, 0 },
299 { "regmove", 'N', 1, 0, 0 },
300 { "sched", 'S', 1, 0, 0 },
301 { "lreg", 'l', 1, 0, 0 },
302 { "greg", 'g', 1, 0, 0 },
303 { "postreload", 'o', 1, 0, 0 },
304 { "flow2", 'w', 1, 0, 0 },
305 { "peephole2", 'z', 1, 0, 0 },
306 { "rnreg", 'n', 1, 0, 0 },
307 { "ce3", 'E', 1, 0, 0 },
308 { "bbro", 'B', 1, 0, 0 },
309 { "sched2", 'R', 1, 0, 0 },
310 { "stack", 'k', 1, 0, 0 },
311 { "mach", 'M', 1, 0, 0 },
312 { "dbr", 'd', 0, 0, 0 },
315 static int open_dump_file PARAMS ((enum dump_file_index, tree));
316 static void close_dump_file PARAMS ((enum dump_file_index,
317 void (*) (FILE *, rtx), rtx));
319 /* Other flags saying which kinds of debugging dump have been requested. */
321 int rtl_dump_and_exit;
322 int flag_print_asm_name;
323 static int version_flag;
324 static char *filename;
325 enum graph_dump_types graph_dump_format;
327 /* Name for output file of assembly code, specified with -o. */
329 char *asm_file_name;
331 /* Value of the -G xx switch, and whether it was passed or not. */
332 int g_switch_value;
333 int g_switch_set;
335 /* Type(s) of debugging information we are producing (if any).
336 See flags.h for the definitions of the different possible
337 types of debugging information. */
338 enum debug_info_type write_symbols = NO_DEBUG;
340 /* Level of debugging information we are producing. See flags.h
341 for the definitions of the different possible levels. */
342 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
344 /* Nonzero means use GNU-only extensions in the generated symbolic
345 debugging information. */
346 /* Currently, this only has an effect when write_symbols is set to
347 DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
348 int use_gnu_debug_info_extensions = 0;
350 /* Nonzero means do optimizations. -O.
351 Particular numeric values stand for particular amounts of optimization;
352 thus, -O2 stores 2 here. However, the optimizations beyond the basic
353 ones are not controlled directly by this variable. Instead, they are
354 controlled by individual `flag_...' variables that are defaulted
355 based on this variable. */
357 int optimize = 0;
359 /* Nonzero means optimize for size. -Os.
360 The only valid values are zero and nonzero. When optimize_size is
361 nonzero, optimize defaults to 2, but certain individual code
362 bloating optimizations are disabled. */
364 int optimize_size = 0;
366 /* Nonzero if we should exit after parsing options. */
367 static int exit_after_options = 0;
369 /* The FUNCTION_DECL for the function currently being compiled,
370 or 0 if between functions. */
371 tree current_function_decl;
373 /* Set to the FUNC_BEGIN label of the current function, or NULL_TREE
374 if none. */
375 tree current_function_func_begin_label;
377 /* Nonzero if doing dwarf2 duplicate elimination. */
379 int flag_eliminate_dwarf2_dups = 0;
381 /* Nonzero if generating code to do profiling. */
383 int profile_flag = 0;
385 /* Nonzero if generating code to profile program flow graph arcs. */
387 int profile_arc_flag = 0;
389 /* Nonzero if generating info for gcov to calculate line test coverage. */
391 int flag_test_coverage = 0;
393 /* Nonzero indicates that branch taken probabilities should be calculated. */
395 int flag_branch_probabilities = 0;
397 /* Nonzero if basic blocks should be reordered. */
399 int flag_reorder_blocks = 0;
401 /* Nonzero if functions should be reordered. */
403 int flag_reorder_functions = 0;
405 /* Nonzero if registers should be renamed. */
407 int flag_rename_registers = 0;
408 int flag_cprop_registers = 0;
410 /* Nonzero for -pedantic switch: warn about anything
411 that standard spec forbids. */
413 int pedantic = 0;
415 /* Temporarily suppress certain warnings.
416 This is set while reading code from a system header file. */
418 int in_system_header = 0;
420 /* Don't print functions as they are compiled. -quiet. */
422 int quiet_flag = 0;
424 /* Print times taken by the various passes. -ftime-report. */
426 int time_report = 0;
428 /* Print memory still in use at end of compilation (which may have little
429 to do with peak memory consumption). -fmem-report. */
431 int mem_report = 0;
433 /* Nonzero means to collect statistics which might be expensive
434 and to print them when we are done. */
435 int flag_detailed_statistics = 0;
438 /* -f flags. */
440 /* Nonzero means `char' should be signed. */
442 int flag_signed_char;
444 /* Nonzero means give an enum type only as many bytes as it needs. */
446 int flag_short_enums;
448 /* Nonzero for -fcaller-saves: allocate values in regs that need to
449 be saved across function calls, if that produces overall better code.
450 Optional now, so people can test it. */
452 #ifdef DEFAULT_CALLER_SAVES
453 int flag_caller_saves = 1;
454 #else
455 int flag_caller_saves = 0;
456 #endif
458 /* Nonzero if structures and unions should be returned in memory.
460 This should only be defined if compatibility with another compiler or
461 with an ABI is needed, because it results in slower code. */
463 #ifndef DEFAULT_PCC_STRUCT_RETURN
464 #define DEFAULT_PCC_STRUCT_RETURN 1
465 #endif
467 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
469 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
471 /* Nonzero for -fforce-mem: load memory value into a register
472 before arithmetic on it. This makes better cse but slower compilation. */
474 int flag_force_mem = 0;
476 /* Nonzero for -fforce-addr: load memory address into a register before
477 reference to memory. This makes better cse but slower compilation. */
479 int flag_force_addr = 0;
481 /* Nonzero for -fdefer-pop: don't pop args after each function call;
482 instead save them up to pop many calls' args with one insns. */
484 int flag_defer_pop = 0;
486 /* Nonzero for -ffloat-store: don't allocate floats and doubles
487 in extended-precision registers. */
489 int flag_float_store = 0;
491 /* Nonzero for -fcse-follow-jumps:
492 have cse follow jumps to do a more extensive job. */
494 int flag_cse_follow_jumps;
496 /* Nonzero for -fcse-skip-blocks:
497 have cse follow a branch around a block. */
498 int flag_cse_skip_blocks;
500 /* Nonzero for -fexpensive-optimizations:
501 perform miscellaneous relatively-expensive optimizations. */
502 int flag_expensive_optimizations;
504 /* Nonzero for -fthread-jumps:
505 have jump optimize output of loop. */
507 int flag_thread_jumps;
509 /* Nonzero enables strength-reduction in loop.c. */
511 int flag_strength_reduce = 0;
513 /* Nonzero enables loop unrolling in unroll.c. Only loops for which the
514 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
515 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
516 unrolled. */
518 int flag_old_unroll_loops;
520 /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
521 This is generally not a win. */
523 int flag_old_unroll_all_loops;
525 /* Enables unrolling of simple loops in loop-unroll.c. */
526 int flag_unroll_loops;
528 /* Enables unrolling of all loops in loop-unroll.c. */
529 int flag_unroll_all_loops;
531 /* Nonzero enables loop peeling. */
532 int flag_peel_loops;
534 /* Nonzero enables loop unswitching. */
535 int flag_unswitch_loops;
537 /* Nonzero enables prefetch optimizations for arrays in loops. */
539 int flag_prefetch_loop_arrays;
541 /* Nonzero forces all invariant computations in loops to be moved
542 outside the loop. */
544 int flag_move_all_movables = 0;
546 /* Nonzero forces all general induction variables in loops to be
547 strength reduced. */
549 int flag_reduce_all_givs = 0;
551 /* Nonzero to perform full register move optimization passes. This is the
552 default for -O2. */
554 int flag_regmove = 0;
556 /* Nonzero for -fwritable-strings:
557 store string constants in data segment and don't uniquize them. */
559 int flag_writable_strings = 0;
561 /* Nonzero means don't put addresses of constant functions in registers.
562 Used for compiling the Unix kernel, where strange substitutions are
563 done on the assembly output. */
565 int flag_no_function_cse = 0;
567 /* Nonzero for -fomit-frame-pointer:
568 don't make a frame pointer in simple functions that don't require one. */
570 int flag_omit_frame_pointer = 0;
572 /* Nonzero means place each function into its own section on those platforms
573 which support arbitrary section names and unlimited numbers of sections. */
575 int flag_function_sections = 0;
577 /* ... and similar for data. */
579 int flag_data_sections = 0;
581 /* Nonzero to inhibit use of define_optimization peephole opts. */
583 int flag_no_peephole = 0;
585 /* Nonzero allows GCC to optimize sibling and tail recursive calls. */
587 int flag_optimize_sibling_calls = 0;
589 /* Nonzero means the front end generally wants `errno' maintained by math
590 operations, like built-in SQRT. */
592 int flag_errno_math = 1;
594 /* Nonzero means that unsafe floating-point math optimizations are allowed
595 for the sake of speed. IEEE compliance is not guaranteed, and operations
596 are allowed to assume that their arguments and results are "normal"
597 (e.g., nonnegative for SQRT). */
599 int flag_unsafe_math_optimizations = 0;
601 /* Nonzero means that no NaNs or +-Infs are expected. */
603 int flag_finite_math_only = 0;
605 /* Zero means that floating-point math operations cannot generate a
606 (user-visible) trap. This is the case, for example, in nonstop
607 IEEE 754 arithmetic. Trapping conditions include division by zero,
608 overflow, underflow, invalid and inexact, but does not include
609 operations on signaling NaNs (see below). */
611 int flag_trapping_math = 1;
613 /* Nonzero means disable transformations observable by signaling NaNs.
614 This option implies that any operation on a IEEE signaling NaN can
615 generate a (user-visible) trap. */
617 int flag_signaling_nans = 0;
619 /* 0 means straightforward implementation of complex divide acceptable.
620 1 means wide ranges of inputs must work for complex divide.
621 2 means C99-like requirements for complex divide (not yet implemented). */
623 int flag_complex_divide_method = 0;
625 /* Nonzero means just do syntax checking; don't output anything. */
627 int flag_syntax_only = 0;
629 /* Nonzero means perform loop optimizer. */
631 static int flag_loop_optimize;
633 /* Nonzero means perform crossjumping. */
635 static int flag_crossjumping;
637 /* Nonzero means perform if conversion. */
639 static int flag_if_conversion;
641 /* Nonzero means perform if conversion after reload. */
643 static int flag_if_conversion2;
645 /* Nonzero means to use global dataflow analysis to eliminate
646 useless null pointer tests. */
648 static int flag_delete_null_pointer_checks;
650 /* Nonzero means perform global CSE. */
652 int flag_gcse = 0;
654 /* Nonzero means to do the enhanced load motion during gcse, which trys
655 to hoist loads by not killing them when a store to the same location
656 is seen. */
658 int flag_gcse_lm = 1;
660 /* Nonzero means to perform store motion after gcse, which will try to
661 move stores closer to the exit block. Its not very effective without
662 flag_gcse_lm. */
664 int flag_gcse_sm = 1;
666 /* Nonzero means to rerun cse after loop optimization. This increases
667 compilation time about 20% and picks up a few more common expressions. */
669 static int flag_rerun_cse_after_loop;
671 /* Nonzero means to run loop optimizations twice. */
673 int flag_rerun_loop_opt;
675 /* Nonzero for -finline-functions: ok to inline functions that look like
676 good inline candidates. */
678 int flag_inline_functions;
680 /* Nonzero for -fkeep-inline-functions: even if we make a function
681 go inline everywhere, keep its definition around for debugging
682 purposes. */
684 int flag_keep_inline_functions;
686 /* Nonzero means that functions will not be inlined. */
688 int flag_no_inline = 2;
690 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
691 not just because the tree inliner turned us off. */
693 int flag_really_no_inline = 2;
695 /* Nonzero means that we should emit static const variables
696 regardless of whether or not optimization is turned on. */
698 int flag_keep_static_consts = 1;
700 /* Nonzero means we should be saving declaration info into a .X file. */
702 int flag_gen_aux_info = 0;
704 /* Specified name of aux-info file. */
706 static char *aux_info_file_name;
708 /* Nonzero means make the text shared if supported. */
710 int flag_shared_data;
712 /* Nonzero means schedule into delayed branch slots if supported. */
714 int flag_delayed_branch;
716 /* Nonzero if we are compiling pure (sharable) code.
717 Value is 1 if we are doing "small" pic; value is 2 if we're doing
718 "large" pic. */
720 int flag_pic;
722 /* Set to the default thread-local storage (tls) model to use. */
724 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
726 /* Nonzero means generate extra code for exception handling and enable
727 exception handling. */
729 int flag_exceptions;
731 /* Nonzero means generate frame unwind info table when supported. */
733 int flag_unwind_tables = 0;
735 /* Nonzero means generate frame unwind info table exact at each insn boundary */
737 int flag_asynchronous_unwind_tables = 0;
739 /* Nonzero means don't place uninitialized global data in common storage
740 by default. */
742 int flag_no_common;
744 /* Nonzero means change certain warnings into errors.
745 Usually these are warnings about failure to conform to some standard. */
747 int flag_pedantic_errors = 0;
749 /* flag_schedule_insns means schedule insns within basic blocks (before
750 local_alloc).
751 flag_schedule_insns_after_reload means schedule insns after
752 global_alloc. */
754 int flag_schedule_insns = 0;
755 int flag_schedule_insns_after_reload = 0;
757 /* When flag_schedule_insns_after_reload is set, use EBB scheduler. */
758 int flag_sched2_use_superblocks = 0;
760 /* When flag_schedule_insns_after_reload is set, construct traces and EBB
761 scheduler. */
762 int flag_sched2_use_traces = 0;
764 /* The following flags have effect only for scheduling before register
765 allocation:
767 flag_schedule_interblock means schedule insns across basic blocks.
768 flag_schedule_speculative means allow speculative motion of non-load insns.
769 flag_schedule_speculative_load means allow speculative motion of some
770 load insns.
771 flag_schedule_speculative_load_dangerous allows speculative motion of more
772 load insns. */
774 int flag_schedule_interblock = 1;
775 int flag_schedule_speculative = 1;
776 int flag_schedule_speculative_load = 0;
777 int flag_schedule_speculative_load_dangerous = 0;
779 int flag_single_precision_constant;
781 /* flag_branch_on_count_reg means try to replace add-1,compare,branch tupple
782 by a cheaper branch on a count register. */
783 int flag_branch_on_count_reg = 1;
785 /* -finhibit-size-directive inhibits output of .size for ELF.
786 This is used only for compiling crtstuff.c,
787 and it may be extended to other effects
788 needed for crtstuff.c on other systems. */
789 int flag_inhibit_size_directive = 0;
791 /* -fverbose-asm causes extra commentary information to be produced in
792 the generated assembly code (to make it more readable). This option
793 is generally only of use to those who actually need to read the
794 generated assembly code (perhaps while debugging the compiler itself).
795 -fno-verbose-asm, the default, causes the extra information
796 to be omitted and is useful when comparing two assembler files. */
798 int flag_verbose_asm = 0;
800 /* -dA causes debug commentary information to be produced in
801 the generated assembly code (to make it more readable). This option
802 is generally only of use to those who actually need to read the
803 generated assembly code (perhaps while debugging the compiler itself).
804 Currently, this switch is only used by dwarfout.c; however, it is intended
805 to be a catchall for printing debug information in the assembler file. */
807 int flag_debug_asm = 0;
809 /* -dP causes the rtl to be emitted as a comment in assembly. */
811 int flag_dump_rtl_in_asm = 0;
813 /* -fgnu-linker specifies use of the GNU linker for initializations.
814 (Or, more generally, a linker that handles initializations.)
815 -fno-gnu-linker says that collect2 will be used. */
816 #ifdef USE_COLLECT2
817 int flag_gnu_linker = 0;
818 #else
819 int flag_gnu_linker = 1;
820 #endif
822 /* Nonzero means put zero initialized data in the bss section. */
823 int flag_zero_initialized_in_bss = 1;
825 /* Enable SSA. */
826 int flag_ssa = 0;
828 /* Enable ssa conditional constant propagation. */
829 int flag_ssa_ccp = 0;
831 /* Enable ssa aggressive dead code elimination. */
832 int flag_ssa_dce = 0;
834 /* Tag all structures with __attribute__(packed). */
835 int flag_pack_struct = 0;
837 /* Emit code to check for stack overflow; also may cause large objects
838 to be allocated dynamically. */
839 int flag_stack_check;
841 /* When non-NULL, indicates that whenever space is allocated on the
842 stack, the resulting stack pointer must not pass this
843 address---that is, for stacks that grow downward, the stack pointer
844 must always be greater than or equal to this address; for stacks
845 that grow upward, the stack pointer must be less than this address.
846 At present, the rtx may be either a REG or a SYMBOL_REF, although
847 the support provided depends on the backend. */
848 rtx stack_limit_rtx;
850 /* 0 if pointer arguments may alias each other. True in C.
851 1 if pointer arguments may not alias each other but may alias
852 global variables.
853 2 if pointer arguments may not alias each other and may not
854 alias global variables. True in Fortran.
855 This defaults to 0 for C. */
856 int flag_argument_noalias = 0;
858 /* Nonzero if we should do (language-dependent) alias analysis.
859 Typically, this analysis will assume that expressions of certain
860 types do not alias expressions of certain other types. Only used
861 if alias analysis (in general) is enabled. */
862 int flag_strict_aliasing = 0;
864 /* Instrument functions with calls at entry and exit, for profiling. */
865 int flag_instrument_function_entry_exit = 0;
867 /* Nonzero means ignore `#ident' directives. 0 means handle them.
868 On SVR4 targets, it also controls whether or not to emit a
869 string identifying the compiler. */
871 int flag_no_ident = 0;
873 /* This will perform a peephole pass before sched2. */
874 int flag_peephole2 = 0;
876 /* This will try to guess branch probabilities. */
877 int flag_guess_branch_prob = 0;
879 /* -fcheck-bounds causes gcc to generate array bounds checks.
880 For C, C++, ObjC: defaults to off.
881 For Java: defaults to on.
882 For Fortran: defaults to off. */
883 int flag_bounds_check = 0;
885 /* This will attempt to merge constant section constants, if 1 only
886 string constants and constants from constant pool, if 2 also constant
887 variables. */
888 int flag_merge_constants = 1;
890 /* If one, renumber instruction UIDs to reduce the number of
891 unused UIDs if there are a lot of instructions. If greater than
892 one, unconditionally renumber instruction UIDs. */
893 int flag_renumber_insns = 1;
895 /* If nonzero, use the graph coloring register allocator. */
896 int flag_new_regalloc = 0;
898 /* Nonzero if we perform superblock formation. */
900 int flag_tracer = 0;
902 /* Nonzero if we perform whole unit at a time compilation. */
904 int flag_unit_at_a_time = 0;
906 /* Values of the -falign-* flags: how much to align labels in code.
907 0 means `use default', 1 means `don't align'.
908 For each variable, there is an _log variant which is the power
909 of two not less than the variable, for .align output. */
911 int align_loops;
912 int align_loops_log;
913 int align_loops_max_skip;
914 int align_jumps;
915 int align_jumps_log;
916 int align_jumps_max_skip;
917 int align_labels;
918 int align_labels_log;
919 int align_labels_max_skip;
920 int align_functions;
921 int align_functions_log;
923 /* Like align_functions_log above, but used by front-ends to force the
924 minimum function alignment. Zero means no alignment is forced. */
925 int force_align_functions_log;
927 /* Table of supported debugging formats. */
928 static const struct
930 const char *const arg;
931 /* Since PREFERRED_DEBUGGING_TYPE isn't necessarily a
932 constant expression, we use NO_DEBUG in its place. */
933 const enum debug_info_type debug_type;
934 const int use_extensions_p;
935 const char *const description;
936 } *da,
937 debug_args[] =
939 { "", NO_DEBUG, DEFAULT_GDB_EXTENSIONS,
940 N_("Generate debugging info in default format") },
941 { "gdb", NO_DEBUG, 1, N_("Generate debugging info in default extended format") },
942 #ifdef DBX_DEBUGGING_INFO
943 { "stabs", DBX_DEBUG, 0, N_("Generate STABS format debug info") },
944 { "stabs+", DBX_DEBUG, 1, N_("Generate extended STABS format debug info") },
945 #endif
946 #ifdef DWARF_DEBUGGING_INFO
947 { "dwarf", DWARF_DEBUG, 0, N_("Generate DWARF-1 format debug info") },
948 { "dwarf+", DWARF_DEBUG, 1,
949 N_("Generate extended DWARF-1 format debug info") },
950 #endif
951 #ifdef DWARF2_DEBUGGING_INFO
952 { "dwarf-2", DWARF2_DEBUG, 0, N_("Generate DWARF-2 debug info") },
953 #endif
954 #ifdef XCOFF_DEBUGGING_INFO
955 { "xcoff", XCOFF_DEBUG, 0, N_("Generate XCOFF format debug info") },
956 { "xcoff+", XCOFF_DEBUG, 1, N_("Generate extended XCOFF format debug info") },
957 #endif
958 #ifdef SDB_DEBUGGING_INFO
959 { "coff", SDB_DEBUG, 0, N_("Generate COFF format debug info") },
960 #endif
961 #ifdef VMS_DEBUGGING_INFO
962 { "vms", VMS_DEBUG, 0, N_("Generate VMS format debug info") },
963 #endif
964 { 0, 0, 0, 0 }
967 typedef struct
969 const char *const string;
970 int *const variable;
971 const int on_value;
972 const char *const description;
974 lang_independent_options;
976 int flag_trapv = 0;
978 /* Add or remove a leading underscore from user symbols. */
979 int flag_leading_underscore = -1;
981 /* The user symbol prefix after having resolved same. */
982 const char *user_label_prefix;
984 static const param_info lang_independent_params[] = {
985 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT) \
986 { OPTION, DEFAULT, HELP },
987 #include "params.def"
988 #undef DEFPARAM
989 { NULL, 0, NULL }
992 /* Table of language-independent -f options.
993 STRING is the option name. VARIABLE is the address of the variable.
994 ON_VALUE is the value to store in VARIABLE
995 if `-fSTRING' is seen as an option.
996 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
998 static const lang_independent_options f_options[] =
1000 {"eliminate-dwarf2-dups", &flag_eliminate_dwarf2_dups, 1,
1001 N_("Perform DWARF2 duplicate elimination") },
1002 {"float-store", &flag_float_store, 1,
1003 N_("Do not store floats in registers") },
1004 {"defer-pop", &flag_defer_pop, 1,
1005 N_("Defer popping functions args from stack until later") },
1006 {"omit-frame-pointer", &flag_omit_frame_pointer, 1,
1007 N_("When possible do not generate stack frames") },
1008 {"optimize-sibling-calls", &flag_optimize_sibling_calls, 1,
1009 N_("Optimize sibling and tail recursive calls") },
1010 {"tracer", &flag_tracer, 1,
1011 N_("Perform superblock formation via tail duplication") },
1012 {"unit-at-a-time", &flag_unit_at_a_time, 1,
1013 N_("Compile whole compilation unit at a time") },
1014 {"cse-follow-jumps", &flag_cse_follow_jumps, 1,
1015 N_("When running CSE, follow jumps to their targets") },
1016 {"cse-skip-blocks", &flag_cse_skip_blocks, 1,
1017 N_("When running CSE, follow conditional jumps") },
1018 {"expensive-optimizations", &flag_expensive_optimizations, 1,
1019 N_("Perform a number of minor, expensive optimizations") },
1020 {"thread-jumps", &flag_thread_jumps, 1,
1021 N_("Perform jump threading optimizations") },
1022 {"strength-reduce", &flag_strength_reduce, 1,
1023 N_("Perform strength reduction optimizations") },
1024 {"unroll-loops", &flag_unroll_loops, 1,
1025 N_("Perform loop unrolling when iteration count is known") },
1026 {"unroll-all-loops", &flag_unroll_all_loops, 1,
1027 N_("Perform loop unrolling for all loops") },
1028 {"old-unroll-loops", &flag_old_unroll_loops, 1,
1029 N_("Perform loop unrolling when iteration count is known") },
1030 {"old-unroll-all-loops", &flag_old_unroll_all_loops, 1,
1031 N_("Perform loop unrolling for all loops") },
1032 {"peel-loops", &flag_peel_loops, 1,
1033 N_("Perform loop peeling") },
1034 {"unswitch-loops", &flag_unswitch_loops, 1,
1035 N_("Perform loop unswitching") },
1036 {"prefetch-loop-arrays", &flag_prefetch_loop_arrays, 1,
1037 N_("Generate prefetch instructions, if available, for arrays in loops") },
1038 {"move-all-movables", &flag_move_all_movables, 1,
1039 N_("Force all loop invariant computations out of loops") },
1040 {"reduce-all-givs", &flag_reduce_all_givs, 1,
1041 N_("Strength reduce all loop general induction variables") },
1042 {"writable-strings", &flag_writable_strings, 1,
1043 N_("Store strings in writable data section") },
1044 {"peephole", &flag_no_peephole, 0,
1045 N_("Enable machine specific peephole optimizations") },
1046 {"force-mem", &flag_force_mem, 1,
1047 N_("Copy memory operands into registers before using") },
1048 {"force-addr", &flag_force_addr, 1,
1049 N_("Copy memory address constants into regs before using") },
1050 {"function-cse", &flag_no_function_cse, 0,
1051 N_("Allow function addresses to be held in registers") },
1052 {"inline-functions", &flag_inline_functions, 1,
1053 N_("Integrate simple functions into their callers") },
1054 {"keep-inline-functions", &flag_keep_inline_functions, 1,
1055 N_("Generate code for funcs even if they are fully inlined") },
1056 {"inline", &flag_no_inline, 0,
1057 N_("Pay attention to the 'inline' keyword") },
1058 {"keep-static-consts", &flag_keep_static_consts, 1,
1059 N_("Emit static const variables even if they are not used") },
1060 {"syntax-only", &flag_syntax_only, 1,
1061 N_("Check for syntax errors, then stop") },
1062 {"shared-data", &flag_shared_data, 1,
1063 N_("Mark data as shared rather than private") },
1064 {"caller-saves", &flag_caller_saves, 1,
1065 N_("Enable saving registers around function calls") },
1066 {"pcc-struct-return", &flag_pcc_struct_return, 1,
1067 N_("Return 'short' aggregates in memory, not registers") },
1068 {"reg-struct-return", &flag_pcc_struct_return, 0,
1069 N_("Return 'short' aggregates in registers") },
1070 {"delayed-branch", &flag_delayed_branch, 1,
1071 N_("Attempt to fill delay slots of branch instructions") },
1072 {"gcse", &flag_gcse, 1,
1073 N_("Perform the global common subexpression elimination") },
1074 {"gcse-lm", &flag_gcse_lm, 1,
1075 N_("Perform enhanced load motion during global subexpression elimination") },
1076 {"gcse-sm", &flag_gcse_sm, 1,
1077 N_("Perform store motion after global subexpression elimination") },
1078 {"loop-optimize", &flag_loop_optimize, 1,
1079 N_("Perform the loop optimizations") },
1080 {"crossjumping", &flag_crossjumping, 1,
1081 N_("Perform cross-jumping optimization") },
1082 {"if-conversion", &flag_if_conversion, 1,
1083 N_("Perform conversion of conditional jumps to branchless equivalents") },
1084 {"if-conversion2", &flag_if_conversion2, 1,
1085 N_("Perform conversion of conditional jumps to conditional execution") },
1086 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1,
1087 N_("Run CSE pass after loop optimizations") },
1088 {"rerun-loop-opt", &flag_rerun_loop_opt, 1,
1089 N_("Run the loop optimizer twice") },
1090 {"delete-null-pointer-checks", &flag_delete_null_pointer_checks, 1,
1091 N_("Delete useless null pointer checks") },
1092 {"schedule-insns", &flag_schedule_insns, 1,
1093 N_("Reschedule instructions before register allocation") },
1094 {"schedule-insns2", &flag_schedule_insns_after_reload, 1,
1095 N_("Reschedule instructions after register allocation") },
1096 {"sched-interblock",&flag_schedule_interblock, 1,
1097 N_("Enable scheduling across basic blocks") },
1098 {"sched-spec",&flag_schedule_speculative, 1,
1099 N_("Allow speculative motion of non-loads") },
1100 {"sched-spec-load",&flag_schedule_speculative_load, 1,
1101 N_("Allow speculative motion of some loads") },
1102 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1,
1103 N_("Allow speculative motion of more loads") },
1104 {"sched2-use-superblocks", &flag_sched2_use_superblocks, 1,
1105 N_("If scheduling post reload, do superblock sheduling") },
1106 {"sched2-use-traces", &flag_sched2_use_traces, 1,
1107 N_("If scheduling post reload, do trace sheduling") },
1108 {"branch-count-reg",&flag_branch_on_count_reg, 1,
1109 N_("Replace add,compare,branch with branch on count reg") },
1110 {"pic", &flag_pic, 1,
1111 N_("Generate position independent code, if possible") },
1112 {"PIC", &flag_pic, 2, ""},
1113 {"exceptions", &flag_exceptions, 1,
1114 N_("Enable exception handling") },
1115 {"unwind-tables", &flag_unwind_tables, 1,
1116 N_("Just generate unwind tables for exception handling") },
1117 {"asynchronous-unwind-tables", &flag_asynchronous_unwind_tables, 1,
1118 N_("Generate unwind tables exact at each instruction boundary") },
1119 {"non-call-exceptions", &flag_non_call_exceptions, 1,
1120 N_("Support synchronous non-call exceptions") },
1121 {"profile-arcs", &profile_arc_flag, 1,
1122 N_("Insert arc based program profiling code") },
1123 {"test-coverage", &flag_test_coverage, 1,
1124 N_("Create data files needed by gcov") },
1125 {"branch-probabilities", &flag_branch_probabilities, 1,
1126 N_("Use profiling information for branch probabilities") },
1127 {"profile", &profile_flag, 1,
1128 N_("Enable basic program profiling code") },
1129 {"reorder-blocks", &flag_reorder_blocks, 1,
1130 N_("Reorder basic blocks to improve code placement") },
1131 {"reorder-functions", &flag_reorder_functions, 1,
1132 N_("Reorder functions to improve code placement") },
1133 {"rename-registers", &flag_rename_registers, 1,
1134 N_("Do the register renaming optimization pass") },
1135 {"cprop-registers", &flag_cprop_registers, 1,
1136 N_("Do the register copy-propagation optimization pass") },
1137 {"common", &flag_no_common, 0,
1138 N_("Do not put uninitialized globals in the common section") },
1139 {"inhibit-size-directive", &flag_inhibit_size_directive, 1,
1140 N_("Do not generate .size directives") },
1141 {"function-sections", &flag_function_sections, 1,
1142 N_("place each function into its own section") },
1143 {"data-sections", &flag_data_sections, 1,
1144 N_("place data items into their own section") },
1145 {"verbose-asm", &flag_verbose_asm, 1,
1146 N_("Add extra commentry to assembler output") },
1147 {"gnu-linker", &flag_gnu_linker, 1,
1148 N_("Output GNU ld formatted global initializers") },
1149 {"regmove", &flag_regmove, 1,
1150 N_("Enables a register move optimization") },
1151 {"optimize-register-move", &flag_regmove, 1,
1152 N_("Do the full regmove optimization pass") },
1153 {"pack-struct", &flag_pack_struct, 1,
1154 N_("Pack structure members together without holes") },
1155 {"stack-check", &flag_stack_check, 1,
1156 N_("Insert stack checking code into the program") },
1157 {"argument-alias", &flag_argument_noalias, 0,
1158 N_("Specify that arguments may alias each other & globals") },
1159 {"argument-noalias", &flag_argument_noalias, 1,
1160 N_("Assume arguments may alias globals but not each other") },
1161 {"argument-noalias-global", &flag_argument_noalias, 2,
1162 N_("Assume arguments do not alias each other or globals") },
1163 {"strict-aliasing", &flag_strict_aliasing, 1,
1164 N_("Assume strict aliasing rules apply") },
1165 {"align-loops", &align_loops, 0,
1166 N_("Align the start of loops") },
1167 {"align-jumps", &align_jumps, 0,
1168 N_("Align labels which are only reached by jumping") },
1169 {"align-labels", &align_labels, 0,
1170 N_("Align all labels") },
1171 {"align-functions", &align_functions, 0,
1172 N_("Align the start of functions") },
1173 {"merge-constants", &flag_merge_constants, 1,
1174 N_("Attempt to merge identical constants accross compilation units") },
1175 {"merge-all-constants", &flag_merge_constants, 2,
1176 N_("Attempt to merge identical constants and constant variables") },
1177 {"dump-unnumbered", &flag_dump_unnumbered, 1,
1178 N_("Suppress output of instruction numbers and line number notes in debugging dumps") },
1179 {"instrument-functions", &flag_instrument_function_entry_exit, 1,
1180 N_("Instrument function entry/exit with profiling calls") },
1181 {"zero-initialized-in-bss", &flag_zero_initialized_in_bss, 1,
1182 N_("Put zero initialized data in the bss section") },
1183 {"ssa", &flag_ssa, 1,
1184 N_("Enable SSA optimizations") },
1185 {"ssa-ccp", &flag_ssa_ccp, 1,
1186 N_("Enable SSA conditional constant propagation") },
1187 {"ssa-dce", &flag_ssa_dce, 1,
1188 N_("Enable aggressive SSA dead code elimination") },
1189 {"leading-underscore", &flag_leading_underscore, 1,
1190 N_("External symbols have a leading underscore") },
1191 {"ident", &flag_no_ident, 0,
1192 N_("Process #ident directives") },
1193 { "peephole2", &flag_peephole2, 1,
1194 N_("Enables an rtl peephole pass run before sched2") },
1195 {"finite-math-only", &flag_finite_math_only, 1,
1196 N_("Assume no NaNs or +-Infs are generated") },
1197 { "guess-branch-probability", &flag_guess_branch_prob, 1,
1198 N_("Enables guessing of branch probabilities") },
1199 {"math-errno", &flag_errno_math, 1,
1200 N_("Set errno after built-in math functions") },
1201 {"trapping-math", &flag_trapping_math, 1,
1202 N_("Floating-point operations can trap") },
1203 {"unsafe-math-optimizations", &flag_unsafe_math_optimizations, 1,
1204 N_("Allow math optimizations that may violate IEEE or ANSI standards") },
1205 {"signaling-nans", &flag_signaling_nans, 1,
1206 N_("Disable optimizations observable by IEEE signaling NaNs") },
1207 {"bounds-check", &flag_bounds_check, 1,
1208 N_("Generate code to check bounds before indexing arrays") },
1209 {"single-precision-constant", &flag_single_precision_constant, 1,
1210 N_("Convert floating point constant to single precision constant") },
1211 {"time-report", &time_report, 1,
1212 N_("Report time taken by each compiler pass at end of run") },
1213 {"mem-report", &mem_report, 1,
1214 N_("Report on permanent memory allocation at end of run") },
1215 { "trapv", &flag_trapv, 1,
1216 N_("Trap for signed overflow in addition / subtraction / multiplication") },
1217 { "new-ra", &flag_new_regalloc, 1,
1218 N_("Use graph coloring register allocation.") },
1221 /* Table of language-specific options. */
1223 static const struct lang_opt
1225 const char *const option;
1226 const char *const description;
1228 documented_lang_options[] =
1230 /* In order not to overload the --help output, the convention
1231 used here is to only describe those options which are not
1232 enabled by default. */
1234 { "-ansi",
1235 N_("Compile just for ISO C90") },
1236 { "-std= ",
1237 N_("Determine language standard") },
1239 { "-fsigned-bitfields", "" },
1240 { "-funsigned-bitfields",
1241 N_("Make bit-fields by unsigned by default") },
1242 { "-fno-signed-bitfields", "" },
1243 { "-fno-unsigned-bitfields","" },
1244 { "-fsigned-char",
1245 N_("Make 'char' be signed by default") },
1246 { "-funsigned-char",
1247 N_("Make 'char' be unsigned by default") },
1248 { "-fno-signed-char", "" },
1249 { "-fno-unsigned-char", "" },
1251 { "-fasm", "" },
1252 { "-fno-asm",
1253 N_("Do not recognize the 'asm' keyword") },
1254 { "-fbuiltin", "" },
1255 { "-fno-builtin",
1256 N_("Do not recognize any built in functions") },
1257 { "-fhosted",
1258 N_("Assume normal C execution environment") },
1259 { "-fno-hosted", "" },
1260 { "-ffreestanding",
1261 N_("Assume that standard libraries & main might not exist") },
1262 { "-fno-freestanding", "" },
1263 { "-fcond-mismatch",
1264 N_("Allow different types as args of ? operator") },
1265 { "-fno-cond-mismatch", "" },
1266 { "-fdollars-in-identifiers",
1267 N_("Allow the use of $ inside identifiers") },
1268 { "-fno-dollars-in-identifiers", "" },
1269 { "-fpreprocessed", "" },
1270 { "-fno-preprocessed", "" },
1271 { "-fshort-double",
1272 N_("Use the same size for double as for float") },
1273 { "-fno-short-double", "" },
1274 { "-fshort-enums",
1275 N_("Use the smallest fitting integer to hold enums") },
1276 { "-fno-short-enums", "" },
1277 { "-fshort-wchar",
1278 N_("Override the underlying type for wchar_t to `unsigned short'") },
1279 { "-fno-short-wchar", "" },
1281 { "-Wall",
1282 N_("Enable most warning messages") },
1283 { "-Wbad-function-cast",
1284 N_("Warn about casting functions to incompatible types") },
1285 { "-Wno-bad-function-cast", "" },
1286 { "-Wmissing-format-attribute",
1287 N_("Warn about functions which might be candidates for format attributes") },
1288 { "-Wno-missing-format-attribute", "" },
1289 { "-Wcast-qual",
1290 N_("Warn about casts which discard qualifiers") },
1291 { "-Wno-cast-qual", "" },
1292 { "-Wchar-subscripts",
1293 N_("Warn about subscripts whose type is 'char'") },
1294 { "-Wno-char-subscripts", "" },
1295 { "-Wcomment",
1296 N_("Warn if nested comments are detected") },
1297 { "-Wno-comment", "" },
1298 { "-Wcomments",
1299 N_("Warn if nested comments are detected") },
1300 { "-Wno-comments", "" },
1301 { "-Wconversion",
1302 N_("Warn about possibly confusing type conversions") },
1303 { "-Wno-conversion", "" },
1304 { "-Wdiv-by-zero", "" },
1305 { "-Wno-div-by-zero",
1306 N_("Do not warn about compile-time integer division by zero") },
1307 { "-Wfloat-equal",
1308 N_("Warn about testing equality of floating point numbers") },
1309 { "-Wno-float-equal", "" },
1310 { "-Wformat",
1311 N_("Warn about printf/scanf/strftime/strfmon format anomalies") },
1312 { "-Wno-format", "" },
1313 { "-Wformat-extra-args", "" },
1314 { "-Wno-format-extra-args",
1315 N_("Don't warn about too many arguments to format functions") },
1316 { "-Wformat-nonliteral",
1317 N_("Warn about non-string-literal format strings") },
1318 { "-Wno-format-nonliteral", "" },
1319 { "-Wformat-security",
1320 N_("Warn about possible security problems with format functions") },
1321 { "-Wno-format-security", "" },
1322 { "-Wformat-y2k", "" },
1323 { "-Wno-format-y2k",
1324 N_("Don't warn about strftime formats yielding 2 digit years") },
1325 { "-Wimplicit-function-declaration",
1326 N_("Warn about implicit function declarations") },
1327 { "-Wno-implicit-function-declaration", "" },
1328 { "-Werror-implicit-function-declaration", "" },
1329 { "-Wimplicit-int",
1330 N_("Warn when a declaration does not specify a type") },
1331 { "-Wno-implicit-int", "" },
1332 { "-Wimplicit", "" },
1333 { "-Wno-implicit", "" },
1334 { "-Wimport",
1335 N_("Warn about the use of the #import directive") },
1336 { "-Wno-import", "" },
1337 { "-Winvalid-pch",
1338 N_("Warn about PCH files that are found but not used") },
1339 { "-Wlong-long","" },
1340 { "-Wno-long-long",
1341 N_("Do not warn about using 'long long' when -pedantic") },
1342 { "-Wmain",
1343 N_("Warn about suspicious declarations of main") },
1344 { "-Wno-main", "" },
1345 { "-Wmissing-braces",
1346 N_("Warn about possibly missing braces around initializers") },
1347 { "-Wno-missing-braces", "" },
1348 { "-Wmissing-declarations",
1349 N_("Warn about global funcs without previous declarations") },
1350 { "-Wno-missing-declarations", "" },
1351 { "-Wmissing-prototypes",
1352 N_("Warn about global funcs without prototypes") },
1353 { "-Wno-missing-prototypes", "" },
1354 { "-Wmultichar",
1355 N_("Warn about use of multicharacter literals") },
1356 { "-Wno-multichar", "" },
1357 { "-Wnested-externs",
1358 N_("Warn about externs not at file scope level") },
1359 { "-Wno-nested-externs", "" },
1360 { "-Wparentheses",
1361 N_("Warn about possible missing parentheses") },
1362 { "-Wno-parentheses", "" },
1363 { "-Wpointer-arith",
1364 N_("Warn about function pointer arithmetic") },
1365 { "-Wno-pointer-arith", "" },
1366 { "-Wredundant-decls",
1367 N_("Warn about multiple declarations of the same object") },
1368 { "-Wno-redundant-decls", "" },
1369 { "-Wreturn-type",
1370 N_("Warn whenever a function's return-type defaults to int") },
1371 { "-Wno-return-type", "" },
1372 { "-Wsequence-point",
1373 N_("Warn about possible violations of sequence point rules") },
1374 { "-Wno-sequence-point", "" },
1375 { "-Wsign-compare",
1376 N_("Warn about signed/unsigned comparisons") },
1377 { "-Wno-sign-compare", "" },
1378 { "-Wstrict-prototypes",
1379 N_("Warn about non-prototyped function decls") },
1380 { "-Wno-strict-prototypes", "" },
1381 { "-Wtraditional",
1382 N_("Warn about constructs whose meanings change in ISO C") },
1383 { "-Wno-traditional", "" },
1384 { "-Wtrigraphs",
1385 N_("Warn when trigraphs are encountered") },
1386 { "-Wno-trigraphs", "" },
1387 { "-Wundef", "" },
1388 { "-Wno-undef", "" },
1389 { "-Wunknown-pragmas",
1390 N_("Warn about unrecognized pragmas") },
1391 { "-Wno-unknown-pragmas", "" },
1392 { "-Wwrite-strings",
1393 N_("Mark strings as 'const char *'") },
1394 { "-Wno-write-strings", "" },
1396 #define DEFINE_LANG_NAME(NAME) { NULL, NAME },
1398 #include "options.h"
1402 /* Here is a table, controlled by the tm.h file, listing each -m switch
1403 and which bits in `target_switches' it should set or clear.
1404 If VALUE is positive, it is bits to set.
1405 If VALUE is negative, -VALUE is bits to clear.
1406 (The sign bit is not used so there is no confusion.) */
1408 static const struct
1410 const char *const name;
1411 const int value;
1412 const char *const description;
1414 target_switches[] = TARGET_SWITCHES;
1416 /* This table is similar, but allows the switch to have a value. */
1418 #ifdef TARGET_OPTIONS
1419 static const struct
1421 const char *const prefix;
1422 const char **const variable;
1423 const char *const description;
1425 target_options[] = TARGET_OPTIONS;
1426 #endif
1428 /* Options controlling warnings. */
1430 /* Don't print warning messages. -w. */
1432 int inhibit_warnings = 0;
1434 /* Don't suppress warnings from system headers. -Wsystem-headers. */
1436 int warn_system_headers = 0;
1438 /* Print various extra warnings. -W/-Wextra. */
1440 int extra_warnings = 0;
1442 /* Treat warnings as errors. -Werror. */
1444 int warnings_are_errors = 0;
1446 /* Nonzero to warn about unused variables, functions et.al. */
1448 int warn_unused_function;
1449 int warn_unused_label;
1450 int warn_unused_parameter;
1451 int warn_unused_variable;
1452 int warn_unused_value;
1454 /* Nonzero to warn about code which is never reached. */
1456 int warn_notreached;
1458 /* Nonzero to warn about variables used before they are initialized. */
1460 int warn_uninitialized;
1462 /* Nonzero means warn about all declarations which shadow others. */
1464 int warn_shadow;
1466 /* Warn if a switch on an enum, that does not have a default case,
1467 fails to have a case for every enum value. */
1469 int warn_switch;
1471 /* Warn if a switch does not have a default case. */
1473 int warn_switch_default;
1475 /* Warn if a switch on an enum fails to have a case for every enum
1476 value (regardless of the presence or otherwise of a default case). */
1478 int warn_switch_enum;
1480 /* Nonzero means warn about function definitions that default the return type
1481 or that use a null return and have a return-type other than void. */
1483 int warn_return_type;
1485 /* Nonzero means warn about pointer casts that increase the required
1486 alignment of the target type (and might therefore lead to a crash
1487 due to a misaligned access). */
1489 int warn_cast_align;
1491 /* Nonzero means warn about any objects definitions whose size is larger
1492 than N bytes. Also want about function definitions whose returned
1493 values are larger than N bytes. The value N is in `larger_than_size'. */
1495 int warn_larger_than;
1496 HOST_WIDE_INT larger_than_size;
1498 /* Nonzero means warn if inline function is too large. */
1500 int warn_inline;
1502 /* Warn if a function returns an aggregate,
1503 since there are often incompatible calling conventions for doing this. */
1505 int warn_aggregate_return;
1507 /* Warn if packed attribute on struct is unnecessary and inefficient. */
1509 int warn_packed;
1511 /* Warn when gcc pads a structure to an alignment boundary. */
1513 int warn_padded;
1515 /* Warn when an optimization pass is disabled. */
1517 int warn_disabled_optimization;
1519 /* Warn about functions which might be candidates for attribute noreturn. */
1521 int warn_missing_noreturn;
1523 /* Nonzero means warn about uses of __attribute__((deprecated))
1524 declarations. */
1526 int warn_deprecated_decl = 1;
1528 /* Nonzero means warn about constructs which might not be
1529 strict-aliasing safe. */
1531 int warn_strict_aliasing;
1533 /* Like f_options, but for -W. */
1535 static const lang_independent_options W_options[] =
1537 {"unused-function", &warn_unused_function, 1,
1538 N_("Warn when a function is unused") },
1539 {"unused-label", &warn_unused_label, 1,
1540 N_("Warn when a label is unused") },
1541 {"unused-parameter", &warn_unused_parameter, 1,
1542 N_("Warn when a function parameter is unused") },
1543 {"unused-variable", &warn_unused_variable, 1,
1544 N_("Warn when a variable is unused") },
1545 {"unused-value", &warn_unused_value, 1,
1546 N_("Warn when an expression value is unused") },
1547 {"system-headers", &warn_system_headers, 1,
1548 N_("Do not suppress warnings from system headers") },
1549 {"error", &warnings_are_errors, 1,
1550 N_("Treat all warnings as errors") },
1551 {"shadow", &warn_shadow, 1,
1552 N_("Warn when one local variable shadows another") },
1553 {"switch", &warn_switch, 1,
1554 N_("Warn about enumerated switches, with no default, missing a case") },
1555 {"switch-default", &warn_switch_default, 1,
1556 N_("Warn about enumerated switches missing a default case") },
1557 {"switch-enum", &warn_switch_enum, 1,
1558 N_("Warn about all enumerated switches missing a specific case") },
1559 {"aggregate-return", &warn_aggregate_return, 1,
1560 N_("Warn about returning structures, unions or arrays") },
1561 {"cast-align", &warn_cast_align, 1,
1562 N_("Warn about pointer casts which increase alignment") },
1563 {"unreachable-code", &warn_notreached, 1,
1564 N_("Warn about code that will never be executed") },
1565 {"uninitialized", &warn_uninitialized, 1,
1566 N_("Warn about uninitialized automatic variables") },
1567 {"inline", &warn_inline, 1,
1568 N_("Warn when an inlined function cannot be inlined") },
1569 {"packed", &warn_packed, 1,
1570 N_("Warn when the packed attribute has no effect on struct layout") },
1571 {"padded", &warn_padded, 1,
1572 N_("Warn when padding is required to align struct members") },
1573 {"disabled-optimization", &warn_disabled_optimization, 1,
1574 N_("Warn when an optimization pass is disabled") },
1575 {"deprecated-declarations", &warn_deprecated_decl, 1,
1576 N_("Warn about uses of __attribute__((deprecated)) declarations") },
1577 {"extra", &extra_warnings, 1,
1578 N_("Print extra (possibly unwanted) warnings") },
1579 {"missing-noreturn", &warn_missing_noreturn, 1,
1580 N_("Warn about functions which might be candidates for attribute noreturn") },
1581 {"strict-aliasing", &warn_strict_aliasing, 1,
1582 N_ ("Warn about code which might break the strict aliasing rules") }
1585 void
1586 set_Wunused (setting)
1587 int setting;
1589 warn_unused_function = setting;
1590 warn_unused_label = setting;
1591 /* Unused function parameter warnings are reported when either ``-W
1592 -Wunused'' or ``-Wunused-parameter'' is specified. Differentiate
1593 -Wunused by setting WARN_UNUSED_PARAMETER to -1. */
1594 if (!setting)
1595 warn_unused_parameter = 0;
1596 else if (!warn_unused_parameter)
1597 warn_unused_parameter = -1;
1598 warn_unused_variable = setting;
1599 warn_unused_value = setting;
1602 /* The following routines are useful in setting all the flags that
1603 -ffast-math and -fno-fast-math imply. */
1605 void
1606 set_fast_math_flags (set)
1607 int set;
1609 flag_trapping_math = !set;
1610 flag_unsafe_math_optimizations = set;
1611 flag_finite_math_only = set;
1612 flag_errno_math = !set;
1613 if (set)
1614 flag_signaling_nans = 0;
1617 /* Return true iff flags are set as if -ffast-math. */
1618 bool
1619 fast_math_flags_set_p ()
1621 return (!flag_trapping_math
1622 && flag_unsafe_math_optimizations
1623 && flag_finite_math_only
1624 && !flag_errno_math);
1628 /* Output files for assembler code (real compiler output)
1629 and debugging dumps. */
1631 FILE *asm_out_file;
1632 FILE *aux_info_file;
1633 FILE *rtl_dump_file = NULL;
1635 /* Decode the string P as an integral parameter.
1636 If the string is indeed an integer return its numeric value else
1637 issue an Invalid Option error for the option PNAME and return DEFVAL.
1638 If PNAME is zero just return DEFVAL, do not call error. */
1641 read_integral_parameter (p, pname, defval)
1642 const char *p;
1643 const char *pname;
1644 const int defval;
1646 const char *endp = p;
1648 while (*endp)
1650 if (ISDIGIT (*endp))
1651 endp++;
1652 else
1653 break;
1656 if (*endp != 0)
1658 if (pname != 0)
1659 error ("invalid option `%s'", pname);
1660 return defval;
1663 return atoi (p);
1666 /* This calls abort and is used to avoid problems when abort is a macro.
1667 It is used when we need to pass the address of abort. */
1669 void
1670 do_abort ()
1672 abort ();
1675 /* When `malloc.c' is compiled with `rcheck' defined,
1676 it calls this function to report clobberage. */
1678 void
1679 botch (s)
1680 const char *s ATTRIBUTE_UNUSED;
1682 abort ();
1685 /* Return the logarithm of X, base 2, considering X unsigned,
1686 if X is a power of 2. Otherwise, returns -1.
1688 This should be used via the `exact_log2' macro. */
1691 exact_log2_wide (x)
1692 unsigned HOST_WIDE_INT x;
1694 int log = 0;
1695 /* Test for 0 or a power of 2. */
1696 if (x == 0 || x != (x & -x))
1697 return -1;
1698 while ((x >>= 1) != 0)
1699 log++;
1700 return log;
1703 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1704 If X is 0, return -1.
1706 This should be used via the floor_log2 macro. */
1709 floor_log2_wide (x)
1710 unsigned HOST_WIDE_INT x;
1712 int log = -1;
1713 while (x != 0)
1714 log++,
1715 x >>= 1;
1716 return log;
1719 /* Handler for fatal signals, such as SIGSEGV. These are transformed
1720 into ICE messages, which is much more user friendly. */
1722 static void
1723 crash_signal (signo)
1724 int signo;
1726 internal_error ("%s", strsignal (signo));
1729 /* Arrange to dump core on error. (The regular error message is still
1730 printed first, except in the case of abort().) */
1732 static void
1733 setup_core_dumping ()
1735 #ifdef SIGABRT
1736 signal (SIGABRT, SIG_DFL);
1737 #endif
1738 #if defined(HAVE_SETRLIMIT)
1740 struct rlimit rlim;
1741 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
1742 fatal_io_error ("getting core file size maximum limit");
1743 rlim.rlim_cur = rlim.rlim_max;
1744 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
1745 fatal_io_error ("setting core file size limit to maximum");
1747 #endif
1748 diagnostic_abort_on_error (global_dc);
1752 /* Strip off a legitimate source ending from the input string NAME of
1753 length LEN. Rather than having to know the names used by all of
1754 our front ends, we strip off an ending of a period followed by
1755 up to five characters. (Java uses ".class".) */
1757 void
1758 strip_off_ending (name, len)
1759 char *name;
1760 int len;
1762 int i;
1763 for (i = 2; i < 6 && len > i; i++)
1765 if (name[len - i] == '.')
1767 name[len - i] = '\0';
1768 break;
1773 /* Output a quoted string. */
1775 void
1776 output_quoted_string (asm_file, string)
1777 FILE *asm_file;
1778 const char *string;
1780 #ifdef OUTPUT_QUOTED_STRING
1781 OUTPUT_QUOTED_STRING (asm_file, string);
1782 #else
1783 char c;
1785 putc ('\"', asm_file);
1786 while ((c = *string++) != 0)
1788 if (ISPRINT (c))
1790 if (c == '\"' || c == '\\')
1791 putc ('\\', asm_file);
1792 putc (c, asm_file);
1794 else
1795 fprintf (asm_file, "\\%03o", (unsigned char) c);
1797 putc ('\"', asm_file);
1798 #endif
1801 /* Output NAME into FILE after having turned it into something
1802 usable as an identifier in a target's assembly file. */
1803 void
1804 output_clean_symbol_name (file, name)
1805 FILE *file;
1806 const char *name;
1808 /* Make a copy of NAME. */
1809 char *id = xstrdup (name);
1811 /* Make it look like a valid identifier for an assembler. */
1812 clean_symbol_name (id);
1814 fputs (id, file);
1815 free (id);
1819 /* Output a file name in the form wanted by System V. */
1821 void
1822 output_file_directive (asm_file, input_name)
1823 FILE *asm_file;
1824 const char *input_name;
1826 int len = strlen (input_name);
1827 const char *na = input_name + len;
1829 /* NA gets INPUT_NAME sans directory names. */
1830 while (na > input_name)
1832 if (IS_DIR_SEPARATOR (na[-1]))
1833 break;
1834 na--;
1837 #ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
1838 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
1839 #else
1840 #ifdef ASM_OUTPUT_SOURCE_FILENAME
1841 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
1842 #else
1843 fprintf (asm_file, "\t.file\t");
1844 output_quoted_string (asm_file, na);
1845 fputc ('\n', asm_file);
1846 #endif
1847 #endif
1850 /* Routine to open a dump file. Return true if the dump file is enabled. */
1852 static int
1853 open_dump_file (index, decl)
1854 enum dump_file_index index;
1855 tree decl;
1857 char *dump_name;
1858 const char *open_arg;
1859 char seq[16];
1861 if (! dump_file[index].enabled)
1862 return 0;
1864 timevar_push (TV_DUMP);
1865 if (rtl_dump_file != NULL)
1866 fclose (rtl_dump_file);
1868 sprintf (seq, DUMPFILE_FORMAT, index);
1870 if (! dump_file[index].initialized)
1872 /* If we've not initialized the files, do so now. */
1873 if (graph_dump_format != no_graph
1874 && dump_file[index].graph_dump_p)
1876 dump_name = concat (seq, dump_file[index].extension, NULL);
1877 clean_graph_dump_file (dump_base_name, dump_name);
1878 free (dump_name);
1880 dump_file[index].initialized = 1;
1881 open_arg = "w";
1883 else
1884 open_arg = "a";
1886 dump_name = concat (dump_base_name, seq,
1887 dump_file[index].extension, NULL);
1889 rtl_dump_file = fopen (dump_name, open_arg);
1890 if (rtl_dump_file == NULL)
1891 fatal_io_error ("can't open %s", dump_name);
1893 free (dump_name);
1895 if (decl)
1896 fprintf (rtl_dump_file, "\n;; Function %s%s\n\n",
1897 (*lang_hooks.decl_printable_name) (decl, 2),
1898 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
1899 ? " (hot)"
1900 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
1901 ? " (unlikely executed)"
1902 : "");
1904 timevar_pop (TV_DUMP);
1905 return 1;
1908 /* Routine to close a dump file. */
1910 static void
1911 close_dump_file (index, func, insns)
1912 enum dump_file_index index;
1913 void (*func) PARAMS ((FILE *, rtx));
1914 rtx insns;
1916 if (! rtl_dump_file)
1917 return;
1919 timevar_push (TV_DUMP);
1920 if (insns
1921 && graph_dump_format != no_graph
1922 && dump_file[index].graph_dump_p)
1924 char seq[16];
1925 char *suffix;
1927 sprintf (seq, DUMPFILE_FORMAT, index);
1928 suffix = concat (seq, dump_file[index].extension, NULL);
1929 print_rtl_graph_with_bb (dump_base_name, suffix, insns);
1930 free (suffix);
1933 if (func && insns)
1934 func (rtl_dump_file, insns);
1936 fflush (rtl_dump_file);
1937 fclose (rtl_dump_file);
1939 rtl_dump_file = NULL;
1940 timevar_pop (TV_DUMP);
1943 /* Do any final processing required for the declarations in VEC, of
1944 which there are LEN. We write out inline functions and variables
1945 that have been deferred until this point, but which are required.
1946 Returns nonzero if anything was put out. */
1949 wrapup_global_declarations (vec, len)
1950 tree *vec;
1951 int len;
1953 tree decl;
1954 int i;
1955 int reconsider;
1956 int output_something = 0;
1958 for (i = 0; i < len; i++)
1960 decl = vec[i];
1962 /* We're not deferring this any longer. Assignment is
1963 conditional to avoid needlessly dirtying PCH pages. */
1964 if (DECL_DEFER_OUTPUT (decl) != 0)
1965 DECL_DEFER_OUTPUT (decl) = 0;
1967 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
1968 (*lang_hooks.finish_incomplete_decl) (decl);
1971 /* Now emit any global variables or functions that we have been
1972 putting off. We need to loop in case one of the things emitted
1973 here references another one which comes earlier in the list. */
1976 reconsider = 0;
1977 for (i = 0; i < len; i++)
1979 decl = vec[i];
1981 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
1982 continue;
1984 /* Don't write out static consts, unless we still need them.
1986 We also keep static consts if not optimizing (for debugging),
1987 unless the user specified -fno-keep-static-consts.
1988 ??? They might be better written into the debug information.
1989 This is possible when using DWARF.
1991 A language processor that wants static constants to be always
1992 written out (even if it is not used) is responsible for
1993 calling rest_of_decl_compilation itself. E.g. the C front-end
1994 calls rest_of_decl_compilation from finish_decl.
1995 One motivation for this is that is conventional in some
1996 environments to write things like:
1997 static const char rcsid[] = "... version string ...";
1998 intending to force the string to be in the executable.
2000 A language processor that would prefer to have unneeded
2001 static constants "optimized away" would just defer writing
2002 them out until here. E.g. C++ does this, because static
2003 constants are often defined in header files.
2005 ??? A tempting alternative (for both C and C++) would be
2006 to force a constant to be written if and only if it is
2007 defined in a main file, as opposed to an include file. */
2009 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
2011 bool needed = 1;
2013 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2014 /* needed */;
2015 else if (DECL_COMDAT (decl))
2016 needed = 0;
2017 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
2018 && (optimize || !flag_keep_static_consts
2019 || DECL_ARTIFICIAL (decl)))
2020 needed = 0;
2022 if (needed)
2024 reconsider = 1;
2025 rest_of_decl_compilation (decl, NULL, 1, 1);
2029 if (TREE_CODE (decl) == FUNCTION_DECL
2030 && DECL_INITIAL (decl) != 0
2031 && DECL_SAVED_INSNS (decl) != 0
2032 && (flag_keep_inline_functions
2033 || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
2034 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2036 reconsider = 1;
2037 output_inline_function (decl);
2041 if (reconsider)
2042 output_something = 1;
2044 while (reconsider);
2046 return output_something;
2049 /* Issue appropriate warnings for the global declarations in VEC (of
2050 which there are LEN). Output debugging information for them. */
2052 void
2053 check_global_declarations (vec, len)
2054 tree *vec;
2055 int len;
2057 tree decl;
2058 int i;
2060 for (i = 0; i < len; i++)
2062 decl = vec[i];
2064 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2065 && ! TREE_ASM_WRITTEN (decl))
2066 /* Cancel the RTL for this decl so that, if debugging info
2067 output for global variables is still to come,
2068 this one will be omitted. */
2069 SET_DECL_RTL (decl, NULL_RTX);
2071 /* Warn about any function
2072 declared static but not defined.
2073 We don't warn about variables,
2074 because many programs have static variables
2075 that exist only to get some text into the object file. */
2076 if (TREE_CODE (decl) == FUNCTION_DECL
2077 && (warn_unused_function
2078 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2079 && DECL_INITIAL (decl) == 0
2080 && DECL_EXTERNAL (decl)
2081 && ! DECL_ARTIFICIAL (decl)
2082 && ! TREE_PUBLIC (decl))
2084 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2085 pedwarn_with_decl (decl,
2086 "`%s' used but never defined");
2087 else
2088 warning_with_decl (decl,
2089 "`%s' declared `static' but never defined");
2090 /* This symbol is effectively an "extern" declaration now. */
2091 TREE_PUBLIC (decl) = 1;
2092 assemble_external (decl);
2095 /* Warn about static fns or vars defined but not used. */
2096 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
2097 || (warn_unused_variable && TREE_CODE (decl) == VAR_DECL))
2098 && ! TREE_USED (decl)
2099 /* The TREE_USED bit for file-scope decls is kept in the identifier,
2100 to handle multiple external decls in different scopes. */
2101 && ! TREE_USED (DECL_NAME (decl))
2102 && ! DECL_EXTERNAL (decl)
2103 && ! TREE_PUBLIC (decl)
2104 /* Global register variables must be declared to reserve them. */
2105 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
2106 /* Otherwise, ask the language. */
2107 && (*lang_hooks.decls.warn_unused_global) (decl))
2108 warning_with_decl (decl, "`%s' defined but not used");
2110 /* Avoid confusing the debug information machinery when there are
2111 errors. */
2112 if (errorcount == 0 && sorrycount == 0)
2114 timevar_push (TV_SYMOUT);
2115 (*debug_hooks->global_decl) (decl);
2116 timevar_pop (TV_SYMOUT);
2121 /* Save the current INPUT_FILENAME and LINENO on the top entry in the
2122 INPUT_FILE_STACK. Push a new entry for FILE and LINE, and set the
2123 INPUT_FILENAME and LINENO accordingly. */
2125 void
2126 push_srcloc (file, line)
2127 const char *file;
2128 int line;
2130 struct file_stack *fs;
2132 if (input_file_stack)
2134 input_file_stack->name = input_filename;
2135 input_file_stack->line = lineno;
2138 fs = (struct file_stack *) xmalloc (sizeof (struct file_stack));
2139 fs->name = input_filename = file;
2140 fs->line = lineno = line;
2141 fs->next = input_file_stack;
2142 input_file_stack = fs;
2143 input_file_stack_tick++;
2146 /* Pop the top entry off the stack of presently open source files.
2147 Restore the INPUT_FILENAME and LINENO from the new topmost entry on
2148 the stack. */
2150 void
2151 pop_srcloc ()
2153 struct file_stack *fs;
2155 fs = input_file_stack;
2156 input_file_stack = fs->next;
2157 free (fs);
2158 input_file_stack_tick++;
2159 /* The initial source file is never popped. */
2160 if (!input_file_stack)
2161 abort ();
2162 input_filename = input_file_stack->name;
2163 lineno = input_file_stack->line;
2166 /* Compile an entire translation unit. Write a file of assembly
2167 output and various debugging dumps. */
2169 static void
2170 compile_file ()
2172 /* Initialize yet another pass. */
2174 init_final (main_input_filename);
2175 init_branch_prob (aux_base_name);
2177 timevar_push (TV_PARSE);
2179 /* Call the parser, which parses the entire file (calling
2180 rest_of_compilation for each function). */
2181 (*lang_hooks.parse_file) (set_yydebug);
2183 /* In case there were missing block closers,
2184 get us back to the global binding level. */
2185 (*lang_hooks.clear_binding_stack) ();
2187 /* Compilation is now finished except for writing
2188 what's left of the symbol table output. */
2189 timevar_pop (TV_PARSE);
2191 if (flag_syntax_only)
2192 return;
2194 (*lang_hooks.decls.final_write_globals)();
2196 if (profile_arc_flag)
2197 /* This must occur after the loop to output deferred functions.
2198 Else the profiler initializer would not be emitted if all the
2199 functions in this compilation unit were deferred. */
2200 create_profiler ();
2202 /* Write out any pending weak symbol declarations. */
2204 weak_finish ();
2206 /* Do dbx symbols. */
2207 timevar_push (TV_SYMOUT);
2209 #ifdef DWARF2_UNWIND_INFO
2210 if (dwarf2out_do_frame ())
2211 dwarf2out_frame_finish ();
2212 #endif
2214 (*debug_hooks->finish) (main_input_filename);
2215 timevar_pop (TV_SYMOUT);
2217 /* Output some stuff at end of file if nec. */
2219 dw2_output_indirect_constants ();
2221 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
2223 timevar_push (TV_DUMP);
2224 open_dump_file (DFI_bp, NULL);
2226 end_branch_prob ();
2228 close_dump_file (DFI_bp, NULL, NULL_RTX);
2229 timevar_pop (TV_DUMP);
2232 #ifdef ASM_FILE_END
2233 ASM_FILE_END (asm_out_file);
2234 #endif
2236 /* Attach a special .ident directive to the end of the file to identify
2237 the version of GCC which compiled this code. The format of the .ident
2238 string is patterned after the ones produced by native SVR4 compilers. */
2239 #ifdef IDENT_ASM_OP
2240 if (!flag_no_ident)
2241 fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
2242 IDENT_ASM_OP, version_string);
2243 #endif
2245 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
2247 timevar_push (TV_DUMP);
2248 dump_combine_total_stats (rtl_dump_file);
2249 close_dump_file (DFI_combine, NULL, NULL_RTX);
2250 timevar_pop (TV_DUMP);
2254 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
2255 and TYPE_DECL nodes.
2257 This does nothing for local (non-static) variables, unless the
2258 variable is a register variable with an ASMSPEC. In that case, or
2259 if the variable is not an automatic, it sets up the RTL and
2260 outputs any assembler code (label definition, storage allocation
2261 and initialization).
2263 DECL is the declaration. If ASMSPEC is nonzero, it specifies
2264 the assembler symbol name to be used. TOP_LEVEL is nonzero
2265 if this declaration is not within a function. */
2267 void
2268 rest_of_decl_compilation (decl, asmspec, top_level, at_end)
2269 tree decl;
2270 const char *asmspec;
2271 int top_level;
2272 int at_end;
2274 /* We deferred calling assemble_alias so that we could collect
2275 other attributes such as visibility. Emit the alias now. */
2277 tree alias;
2278 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
2279 if (alias)
2281 alias = TREE_VALUE (TREE_VALUE (alias));
2282 alias = get_identifier (TREE_STRING_POINTER (alias));
2283 assemble_alias (decl, alias);
2287 /* Forward declarations for nested functions are not "external",
2288 but we need to treat them as if they were. */
2289 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
2290 || TREE_CODE (decl) == FUNCTION_DECL)
2292 timevar_push (TV_VARCONST);
2294 if (asmspec)
2295 make_decl_rtl (decl, asmspec);
2297 /* Don't output anything when a tentative file-scope definition
2298 is seen. But at end of compilation, do output code for them. */
2299 if (at_end || !DECL_DEFER_OUTPUT (decl))
2300 assemble_variable (decl, top_level, at_end, 0);
2302 #ifdef ASM_FINISH_DECLARE_OBJECT
2303 if (decl == last_assemble_variable_decl)
2305 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
2306 top_level, at_end);
2308 #endif
2310 timevar_pop (TV_VARCONST);
2312 else if (DECL_REGISTER (decl) && asmspec != 0)
2314 if (decode_reg_name (asmspec) >= 0)
2316 SET_DECL_RTL (decl, NULL_RTX);
2317 make_decl_rtl (decl, asmspec);
2319 else
2321 error ("invalid register name `%s' for register variable", asmspec);
2322 DECL_REGISTER (decl) = 0;
2323 if (!top_level)
2324 expand_decl (decl);
2327 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2328 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2329 && TREE_CODE (decl) == TYPE_DECL)
2331 timevar_push (TV_SYMOUT);
2332 dbxout_symbol (decl, 0);
2333 timevar_pop (TV_SYMOUT);
2335 #endif
2336 #ifdef SDB_DEBUGGING_INFO
2337 else if (write_symbols == SDB_DEBUG && top_level
2338 && TREE_CODE (decl) == TYPE_DECL)
2340 timevar_push (TV_SYMOUT);
2341 sdbout_symbol (decl, 0);
2342 timevar_pop (TV_SYMOUT);
2344 #endif
2345 #ifdef DWARF2_DEBUGGING_INFO
2346 else if ((write_symbols == DWARF2_DEBUG
2347 || write_symbols == VMS_AND_DWARF2_DEBUG)
2348 && top_level
2349 && TREE_CODE (decl) == TYPE_DECL)
2351 timevar_push (TV_SYMOUT);
2352 dwarf2out_decl (decl);
2353 timevar_pop (TV_SYMOUT);
2355 #endif
2358 /* Called after finishing a record, union or enumeral type. */
2360 void
2361 rest_of_type_compilation (type, toplev)
2362 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) \
2363 || defined (SDB_DEBUGGING_INFO) || defined (DWARF2_DEBUGGING_INFO)
2364 tree type;
2365 int toplev;
2366 #else
2367 tree type ATTRIBUTE_UNUSED;
2368 int toplev ATTRIBUTE_UNUSED;
2369 #endif
2371 /* Avoid confusing the debug information machinery when there are
2372 errors. */
2373 if (errorcount != 0 || sorrycount != 0)
2374 return;
2376 timevar_push (TV_SYMOUT);
2377 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2378 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2379 dbxout_symbol (TYPE_STUB_DECL (type), !toplev);
2380 #endif
2381 #ifdef SDB_DEBUGGING_INFO
2382 if (write_symbols == SDB_DEBUG)
2383 sdbout_symbol (TYPE_STUB_DECL (type), !toplev);
2384 #endif
2385 #ifdef DWARF2_DEBUGGING_INFO
2386 if ((write_symbols == DWARF2_DEBUG
2387 || write_symbols == VMS_AND_DWARF2_DEBUG)
2388 && toplev)
2389 dwarf2out_decl (TYPE_STUB_DECL (type));
2390 #endif
2391 timevar_pop (TV_SYMOUT);
2394 /* This is called from finish_function (within langhooks.parse_file)
2395 after each top-level definition is parsed.
2396 It is supposed to compile that function or variable
2397 and output the assembler code for it.
2398 After we return, the tree storage is freed. */
2400 void
2401 rest_of_compilation (decl)
2402 tree decl;
2404 rtx insns;
2405 int tem;
2406 int failure = 0;
2407 int rebuild_label_notes_after_reload;
2409 timevar_push (TV_REST_OF_COMPILATION);
2411 /* Now that we're out of the frontend, we shouldn't have any more
2412 CONCATs anywhere. */
2413 generating_concat_p = 0;
2415 /* When processing delayed functions, prepare_function_start() won't
2416 have been run to re-initialize it. */
2417 cse_not_expected = ! optimize;
2419 /* First, make sure that NOTE_BLOCK is set correctly for each
2420 NOTE_INSN_BLOCK_BEG/NOTE_INSN_BLOCK_END note. */
2421 if (!cfun->x_whole_function_mode_p)
2422 identify_blocks ();
2424 /* In function-at-a-time mode, we do not attempt to keep the BLOCK
2425 tree in sensible shape. So, we just recalculate it here. */
2426 if (cfun->x_whole_function_mode_p)
2427 reorder_blocks ();
2429 init_flow ();
2431 /* If we are reconsidering an inline function
2432 at the end of compilation, skip the stuff for making it inline. */
2434 if (DECL_SAVED_INSNS (decl) == 0)
2436 int inlinable = 0;
2437 tree parent;
2438 const char *lose;
2440 /* If this is nested inside an inlined external function, pretend
2441 it was only declared. Since we cannot inline such functions,
2442 generating code for this one is not only not necessary but will
2443 confuse some debugging output writers. */
2444 for (parent = DECL_CONTEXT (current_function_decl);
2445 parent != NULL_TREE;
2446 parent = get_containing_scope (parent))
2447 if (TREE_CODE (parent) == FUNCTION_DECL
2448 && DECL_INLINE (parent) && DECL_EXTERNAL (parent))
2450 DECL_INITIAL (decl) = 0;
2451 goto exit_rest_of_compilation;
2453 else if (TYPE_P (parent))
2454 /* A function in a local class should be treated normally. */
2455 break;
2457 /* If requested, consider whether to make this function inline. */
2458 if ((DECL_INLINE (decl) && !flag_no_inline)
2459 || flag_inline_functions)
2461 timevar_push (TV_INTEGRATION);
2462 lose = function_cannot_inline_p (decl);
2463 timevar_pop (TV_INTEGRATION);
2464 if (lose || ! optimize)
2466 if (warn_inline && DECL_INLINE (decl))
2467 warning_with_decl (decl, lose);
2468 DECL_ABSTRACT_ORIGIN (decl) = 0;
2469 /* Don't really compile an extern inline function.
2470 If we can't make it inline, pretend
2471 it was only declared. */
2472 if (DECL_EXTERNAL (decl))
2474 DECL_INITIAL (decl) = 0;
2475 goto exit_rest_of_compilation;
2478 else
2479 /* ??? Note that this has the effect of making it look
2480 like "inline" was specified for a function if we choose
2481 to inline it. This isn't quite right, but it's
2482 probably not worth the trouble to fix. */
2483 inlinable = DECL_INLINE (decl) = 1;
2486 insns = get_insns ();
2488 /* Dump the rtl code if we are dumping rtl. */
2490 if (open_dump_file (DFI_rtl, decl))
2492 if (DECL_SAVED_INSNS (decl))
2493 fprintf (rtl_dump_file, ";; (integrable)\n\n");
2494 close_dump_file (DFI_rtl, print_rtl, insns);
2497 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
2498 sorts of eh initialization. Delay this until after the
2499 initial rtl dump so that we can see the original nesting. */
2500 convert_from_eh_region_ranges ();
2502 /* If function is inline, and we don't yet know whether to
2503 compile it by itself, defer decision till end of compilation.
2504 wrapup_global_declarations will (indirectly) call
2505 rest_of_compilation again for those functions that need to
2506 be output. Also defer those functions that we are supposed
2507 to defer. */
2509 if (inlinable
2510 || (DECL_INLINE (decl)
2511 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2512 && ! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
2513 && ! flag_keep_inline_functions)
2514 || DECL_EXTERNAL (decl))))
2515 DECL_DEFER_OUTPUT (decl) = 1;
2517 if (DECL_INLINE (decl))
2518 /* DWARF wants separate debugging info for abstract and
2519 concrete instances of all inline functions, including those
2520 declared inline but not inlined, and those inlined even
2521 though they weren't declared inline. Conveniently, that's
2522 what DECL_INLINE means at this point. */
2523 (*debug_hooks->deferred_inline_function) (decl);
2525 if (DECL_DEFER_OUTPUT (decl))
2527 /* If -Wreturn-type, we have to do a bit of compilation. We just
2528 want to call cleanup the cfg to figure out whether or not we can
2529 fall off the end of the function; we do the minimum amount of
2530 work necessary to make that safe. */
2531 if (warn_return_type)
2533 int saved_optimize = optimize;
2535 optimize = 0;
2536 rebuild_jump_labels (insns);
2537 find_exception_handler_labels ();
2538 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2539 cleanup_cfg (CLEANUP_PRE_SIBCALL | CLEANUP_PRE_LOOP);
2540 optimize = saved_optimize;
2542 /* CFG is no longer maintained up-to-date. */
2543 free_bb_for_insn ();
2546 set_nothrow_function_flags ();
2547 if (current_function_nothrow)
2548 /* Now we know that this can't throw; set the flag for the benefit
2549 of other functions later in this translation unit. */
2550 TREE_NOTHROW (current_function_decl) = 1;
2552 timevar_push (TV_INTEGRATION);
2553 save_for_inline (decl);
2554 timevar_pop (TV_INTEGRATION);
2555 DECL_SAVED_INSNS (decl)->inlinable = inlinable;
2556 goto exit_rest_of_compilation;
2559 /* If specified extern inline but we aren't inlining it, we are
2560 done. This goes for anything that gets here with DECL_EXTERNAL
2561 set, not just things with DECL_INLINE. */
2562 if (DECL_EXTERNAL (decl))
2563 goto exit_rest_of_compilation;
2566 /* If we're emitting a nested function, make sure its parent gets
2567 emitted as well. Doing otherwise confuses debug info. */
2569 tree parent;
2570 for (parent = DECL_CONTEXT (current_function_decl);
2571 parent != NULL_TREE;
2572 parent = get_containing_scope (parent))
2573 if (TREE_CODE (parent) == FUNCTION_DECL)
2574 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
2577 /* We are now committed to emitting code for this function. Do any
2578 preparation, such as emitting abstract debug info for the inline
2579 before it gets mangled by optimization. */
2580 if (DECL_INLINE (decl))
2581 (*debug_hooks->outlining_inline_function) (decl);
2583 /* Remove any notes we don't need. That will make iterating
2584 over the instruction sequence faster, and allow the garbage
2585 collector to reclaim the memory used by the notes. */
2586 remove_unnecessary_notes ();
2587 reorder_blocks ();
2589 ggc_collect ();
2591 /* Initialize some variables used by the optimizers. */
2592 init_function_for_compilation ();
2594 if (! DECL_DEFER_OUTPUT (decl))
2595 TREE_ASM_WRITTEN (decl) = 1;
2597 /* Now that integrate will no longer see our rtl, we need not
2598 distinguish between the return value of this function and the
2599 return value of called functions. Also, we can remove all SETs
2600 of subregs of hard registers; they are only here because of
2601 integrate. Also, we can now initialize pseudos intended to
2602 carry magic hard reg data throughout the function. */
2603 rtx_equal_function_value_matters = 0;
2604 purge_hard_subreg_sets (get_insns ());
2606 /* Early return if there were errors. We can run afoul of our
2607 consistency checks, and there's not really much point in fixing them.
2608 Don't return yet if -Wreturn-type; we need to do cleanup_cfg. */
2609 if (((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
2610 || errorcount || sorrycount)
2611 goto exit_rest_of_compilation;
2613 timevar_push (TV_JUMP);
2614 open_dump_file (DFI_sibling, decl);
2615 insns = get_insns ();
2616 rebuild_jump_labels (insns);
2617 find_exception_handler_labels ();
2618 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2620 delete_unreachable_blocks ();
2622 /* Turn NOTE_INSN_PREDICTIONs into branch predictions. */
2623 if (flag_guess_branch_prob)
2625 timevar_push (TV_BRANCH_PROB);
2626 note_prediction_to_br_prob ();
2627 timevar_pop (TV_BRANCH_PROB);
2630 /* We may have potential sibling or tail recursion sites. Select one
2631 (of possibly multiple) methods of performing the call. */
2632 if (flag_optimize_sibling_calls)
2634 rtx insn;
2635 optimize_sibling_and_tail_recursive_calls ();
2637 /* Recompute the CFG as sibling optimization clobbers it randomly. */
2638 free_bb_for_insn ();
2639 find_exception_handler_labels ();
2640 rebuild_jump_labels (insns);
2641 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2643 /* There is pass ordering problem - we must lower NOTE_INSN_PREDICTION
2644 notes before simplifying cfg and we must do lowering after sibcall
2645 that unhides parts of RTL chain and cleans up the CFG.
2647 Until sibcall is replaced by tree-level optimizer, lets just
2648 sweep away the NOTE_INSN_PREDICTION notes that leaked out. */
2649 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2650 if (GET_CODE (insn) == NOTE
2651 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_PREDICTION)
2652 delete_insn (insn);
2654 close_dump_file (DFI_sibling, print_rtl, get_insns ());
2655 timevar_pop (TV_JUMP);
2657 scope_to_insns_initialize ();
2658 /* Complete generation of exception handling code. */
2659 if (doing_eh (0))
2661 timevar_push (TV_JUMP);
2662 open_dump_file (DFI_eh, decl);
2664 finish_eh_generation ();
2666 close_dump_file (DFI_eh, print_rtl, get_insns ());
2667 timevar_pop (TV_JUMP);
2670 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
2671 generation, which might create new sets. */
2672 emit_initial_value_sets ();
2674 #ifdef FINALIZE_PIC
2675 /* If we are doing position-independent code generation, now
2676 is the time to output special prologues and epilogues.
2677 We do not want to do this earlier, because it just clutters
2678 up inline functions with meaningless insns. */
2679 if (flag_pic)
2680 FINALIZE_PIC;
2681 #endif
2683 insns = get_insns ();
2685 /* Copy any shared structure that should not be shared. */
2686 unshare_all_rtl (current_function_decl, insns);
2688 #ifdef SETJMP_VIA_SAVE_AREA
2689 /* This must be performed before virtual register instantiation.
2690 Please be aware the everything in the compiler that can look
2691 at the RTL up to this point must understand that REG_SAVE_AREA
2692 is just like a use of the REG contained inside. */
2693 if (current_function_calls_alloca)
2694 optimize_save_area_alloca (insns);
2695 #endif
2697 /* Instantiate all virtual registers. */
2698 instantiate_virtual_regs (current_function_decl, insns);
2700 open_dump_file (DFI_jump, decl);
2702 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
2703 are initialized and to compute whether control can drop off the end
2704 of the function. */
2706 timevar_push (TV_JUMP);
2707 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
2708 before jump optimization switches branch directions. */
2709 if (flag_guess_branch_prob)
2710 expected_value_to_br_prob ();
2712 reg_scan (insns, max_reg_num (), 0);
2713 rebuild_jump_labels (insns);
2714 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2715 delete_trivially_dead_insns (insns, max_reg_num ());
2716 if (rtl_dump_file)
2717 dump_flow_info (rtl_dump_file);
2718 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
2719 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2721 if (optimize)
2723 free_bb_for_insn ();
2724 copy_loop_headers (insns);
2725 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2727 purge_line_number_notes (insns);
2729 timevar_pop (TV_JUMP);
2730 close_dump_file (DFI_jump, print_rtl, insns);
2732 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
2733 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
2735 goto exit_rest_of_compilation;
2738 /* Long term, this should probably move before the jump optimizer too,
2739 but I didn't want to disturb the rtl_dump_and_exit and related
2740 stuff at this time. */
2741 if (optimize > 0 && flag_ssa)
2743 /* Convert to SSA form. */
2745 timevar_push (TV_TO_SSA);
2746 open_dump_file (DFI_ssa, decl);
2748 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2749 convert_to_ssa ();
2751 close_dump_file (DFI_ssa, print_rtl_with_bb, insns);
2752 timevar_pop (TV_TO_SSA);
2754 /* Perform sparse conditional constant propagation, if requested. */
2755 if (flag_ssa_ccp)
2757 timevar_push (TV_SSA_CCP);
2758 open_dump_file (DFI_ssa_ccp, decl);
2760 ssa_const_prop ();
2762 close_dump_file (DFI_ssa_ccp, print_rtl_with_bb, get_insns ());
2763 timevar_pop (TV_SSA_CCP);
2766 /* It would be useful to cleanup the CFG at this point, but block
2767 merging and possibly other transformations might leave a PHI
2768 node in the middle of a basic block, which is a strict no-no. */
2770 /* The SSA implementation uses basic block numbers in its phi
2771 nodes. Thus, changing the control-flow graph or the basic
2772 blocks, e.g., calling find_basic_blocks () or cleanup_cfg (),
2773 may cause problems. */
2775 if (flag_ssa_dce)
2777 /* Remove dead code. */
2779 timevar_push (TV_SSA_DCE);
2780 open_dump_file (DFI_ssa_dce, decl);
2782 insns = get_insns ();
2783 ssa_eliminate_dead_code ();
2785 close_dump_file (DFI_ssa_dce, print_rtl_with_bb, insns);
2786 timevar_pop (TV_SSA_DCE);
2789 /* Convert from SSA form. */
2791 timevar_push (TV_FROM_SSA);
2792 open_dump_file (DFI_ussa, decl);
2794 convert_from_ssa ();
2795 /* New registers have been created. Rescan their usage. */
2796 reg_scan (insns, max_reg_num (), 1);
2798 close_dump_file (DFI_ussa, print_rtl_with_bb, insns);
2799 timevar_pop (TV_FROM_SSA);
2801 ggc_collect ();
2804 timevar_push (TV_JUMP);
2805 cleanup_cfg (optimize ? CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP: 0);
2807 /* Try to identify useless null pointer tests and delete them. */
2808 if (flag_delete_null_pointer_checks)
2810 open_dump_file (DFI_null, decl);
2811 if (rtl_dump_file)
2812 dump_flow_info (rtl_dump_file);
2814 if (delete_null_pointer_checks (insns))
2815 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2817 close_dump_file (DFI_null, print_rtl_with_bb, insns);
2820 /* Jump optimization, and the removal of NULL pointer checks, may
2821 have reduced the number of instructions substantially. CSE, and
2822 future passes, allocate arrays whose dimensions involve the
2823 maximum instruction UID, so if we can reduce the maximum UID
2824 we'll save big on memory. */
2825 renumber_insns (rtl_dump_file);
2826 timevar_pop (TV_JUMP);
2828 close_dump_file (DFI_jump, print_rtl_with_bb, insns);
2830 ggc_collect ();
2832 /* Perform common subexpression elimination.
2833 Nonzero value from `cse_main' means that jumps were simplified
2834 and some code may now be unreachable, so do
2835 jump optimization again. */
2837 if (optimize > 0)
2839 open_dump_file (DFI_cse, decl);
2840 if (rtl_dump_file)
2841 dump_flow_info (rtl_dump_file);
2842 timevar_push (TV_CSE);
2844 reg_scan (insns, max_reg_num (), 1);
2846 tem = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2847 if (tem)
2848 rebuild_jump_labels (insns);
2849 purge_all_dead_edges (0);
2851 delete_trivially_dead_insns (insns, max_reg_num ());
2853 /* If we are not running more CSE passes, then we are no longer
2854 expecting CSE to be run. But always rerun it in a cheap mode. */
2855 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
2857 if (tem || optimize > 1)
2858 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2859 /* Try to identify useless null pointer tests and delete them. */
2860 if (flag_delete_null_pointer_checks)
2862 timevar_push (TV_JUMP);
2864 if (delete_null_pointer_checks (insns))
2865 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2866 timevar_pop (TV_JUMP);
2869 /* The second pass of jump optimization is likely to have
2870 removed a bunch more instructions. */
2871 renumber_insns (rtl_dump_file);
2873 timevar_pop (TV_CSE);
2874 close_dump_file (DFI_cse, print_rtl_with_bb, insns);
2877 open_dump_file (DFI_addressof, decl);
2879 purge_addressof (insns);
2880 if (optimize)
2881 purge_all_dead_edges (0);
2882 reg_scan (insns, max_reg_num (), 1);
2884 close_dump_file (DFI_addressof, print_rtl, insns);
2886 ggc_collect ();
2888 /* Perform global cse. */
2890 if (optimize > 0 && flag_gcse)
2892 int save_csb, save_cfj;
2893 int tem2 = 0;
2895 timevar_push (TV_GCSE);
2896 open_dump_file (DFI_gcse, decl);
2898 tem = gcse_main (insns, rtl_dump_file);
2899 rebuild_jump_labels (insns);
2900 delete_trivially_dead_insns (insns, max_reg_num ());
2902 save_csb = flag_cse_skip_blocks;
2903 save_cfj = flag_cse_follow_jumps;
2904 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
2906 /* If -fexpensive-optimizations, re-run CSE to clean up things done
2907 by gcse. */
2908 if (flag_expensive_optimizations)
2910 timevar_push (TV_CSE);
2911 reg_scan (insns, max_reg_num (), 1);
2912 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2913 purge_all_dead_edges (0);
2914 delete_trivially_dead_insns (insns, max_reg_num ());
2915 timevar_pop (TV_CSE);
2916 cse_not_expected = !flag_rerun_cse_after_loop;
2919 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
2920 things up. Then possibly re-run CSE again. */
2921 while (tem || tem2)
2923 tem = tem2 = 0;
2924 timevar_push (TV_JUMP);
2925 rebuild_jump_labels (insns);
2926 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2927 timevar_pop (TV_JUMP);
2929 if (flag_expensive_optimizations)
2931 timevar_push (TV_CSE);
2932 reg_scan (insns, max_reg_num (), 1);
2933 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2934 purge_all_dead_edges (0);
2935 delete_trivially_dead_insns (insns, max_reg_num ());
2936 timevar_pop (TV_CSE);
2940 close_dump_file (DFI_gcse, print_rtl_with_bb, insns);
2941 timevar_pop (TV_GCSE);
2943 ggc_collect ();
2944 flag_cse_skip_blocks = save_csb;
2945 flag_cse_follow_jumps = save_cfj;
2946 #ifdef ENABLE_CHECKING
2947 verify_flow_info ();
2948 #endif
2951 /* Instantiate any remaining CONSTANT_P_RTX nodes. */
2952 if (optimize > 0 && flag_gcse && current_function_calls_constant_p)
2953 purge_builtin_constant_p ();
2955 /* Move constant computations out of loops. */
2957 if (optimize > 0 && flag_loop_optimize)
2959 int do_unroll, do_prefetch;
2961 timevar_push (TV_LOOP);
2962 delete_dead_jumptables ();
2963 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2964 open_dump_file (DFI_loop, decl);
2965 /* CFG is no longer maintained up-to-date. */
2966 free_bb_for_insn ();
2968 if (flag_unroll_loops)
2969 do_unroll = 0; /* Having two unrollers is useless. */
2970 else
2971 do_unroll = flag_old_unroll_loops ? LOOP_UNROLL : LOOP_AUTO_UNROLL;
2972 do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
2973 if (flag_rerun_loop_opt)
2975 cleanup_barriers ();
2977 /* We only want to perform unrolling once. */
2978 loop_optimize (insns, rtl_dump_file, do_unroll);
2979 do_unroll = 0;
2981 /* The first call to loop_optimize makes some instructions
2982 trivially dead. We delete those instructions now in the
2983 hope that doing so will make the heuristics in loop work
2984 better and possibly speed up compilation. */
2985 delete_trivially_dead_insns (insns, max_reg_num ());
2987 /* The regscan pass is currently necessary as the alias
2988 analysis code depends on this information. */
2989 reg_scan (insns, max_reg_num (), 1);
2991 cleanup_barriers ();
2992 loop_optimize (insns, rtl_dump_file, do_unroll | LOOP_BCT | do_prefetch);
2994 /* Loop can create trivially dead instructions. */
2995 delete_trivially_dead_insns (insns, max_reg_num ());
2996 close_dump_file (DFI_loop, print_rtl, insns);
2997 timevar_pop (TV_LOOP);
2998 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3000 ggc_collect ();
3003 /* Perform jump bypassing and control flow optimizations. */
3004 if (optimize > 0 && flag_gcse)
3006 timevar_push (TV_BYPASS);
3007 open_dump_file (DFI_bypass, decl);
3009 cleanup_cfg (CLEANUP_EXPENSIVE);
3010 tem = bypass_jumps (rtl_dump_file);
3012 if (tem)
3014 rebuild_jump_labels (insns);
3015 cleanup_cfg (CLEANUP_EXPENSIVE);
3016 delete_trivially_dead_insns (insns, max_reg_num ());
3019 close_dump_file (DFI_bypass, print_rtl_with_bb, insns);
3020 timevar_pop (TV_BYPASS);
3022 ggc_collect ();
3024 #ifdef ENABLE_CHECKING
3025 verify_flow_info ();
3026 #endif
3029 /* Do control and data flow analysis; wrote some of the results to
3030 the dump file. */
3032 timevar_push (TV_FLOW);
3033 open_dump_file (DFI_cfg, decl);
3034 if (rtl_dump_file)
3035 dump_flow_info (rtl_dump_file);
3036 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0)
3037 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
3039 /* It may make more sense to mark constant functions after dead code is
3040 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
3041 may insert code making function non-constant, but we still must consider
3042 it as constant, otherwise -fbranch-probabilities will not read data back.
3044 life_analysis rarely eliminates modification of external memory.
3046 if (optimize)
3047 mark_constant_function ();
3049 close_dump_file (DFI_cfg, print_rtl_with_bb, insns);
3051 /* Do branch profiling and static profile estimation passes. */
3052 if (optimize > 0 || cfun->arc_profile || flag_branch_probabilities)
3054 struct loops loops;
3056 timevar_push (TV_BRANCH_PROB);
3057 open_dump_file (DFI_bp, decl);
3058 if (cfun->arc_profile || flag_branch_probabilities)
3059 branch_prob ();
3061 /* Discover and record the loop depth at the head of each basic
3062 block. The loop infrastructure does the real job for us. */
3063 flow_loops_find (&loops, LOOP_TREE);
3065 if (rtl_dump_file)
3066 flow_loops_dump (&loops, rtl_dump_file, NULL, 0);
3068 /* Estimate using heuristics if no profiling info is available. */
3069 if (flag_guess_branch_prob)
3070 estimate_probability (&loops);
3072 flow_loops_free (&loops);
3073 close_dump_file (DFI_bp, print_rtl_with_bb, insns);
3074 timevar_pop (TV_BRANCH_PROB);
3076 if (optimize > 0)
3078 open_dump_file (DFI_ce1, decl);
3079 if (flag_if_conversion)
3081 timevar_push (TV_IFCVT);
3082 if (rtl_dump_file)
3083 dump_flow_info (rtl_dump_file);
3084 cleanup_cfg (CLEANUP_EXPENSIVE);
3085 reg_scan (insns, max_reg_num (), 0);
3086 if_convert (0);
3087 timevar_pop (TV_IFCVT);
3089 timevar_push (TV_JUMP);
3090 cleanup_cfg (CLEANUP_EXPENSIVE);
3091 reg_scan (insns, max_reg_num (), 0);
3092 timevar_pop (TV_JUMP);
3093 close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ());
3095 if (flag_tracer)
3097 timevar_push (TV_TRACER);
3098 open_dump_file (DFI_tracer, decl);
3099 if (rtl_dump_file)
3100 dump_flow_info (rtl_dump_file);
3101 tracer ();
3102 cleanup_cfg (CLEANUP_EXPENSIVE);
3103 reg_scan (insns, max_reg_num (), 0);
3104 close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ());
3105 timevar_pop (TV_TRACER);
3108 /* Perform loop optimalizations. It might be better to do them a bit
3109 sooner, but we want the profile feedback to work more efficiently. */
3110 if (optimize > 0
3111 && (flag_unswitch_loops
3112 || flag_peel_loops
3113 || flag_unroll_loops))
3115 struct loops *loops;
3116 timevar_push (TV_LOOP);
3117 open_dump_file (DFI_loop2, decl);
3118 if (rtl_dump_file)
3119 dump_flow_info (rtl_dump_file);
3121 loops = loop_optimizer_init (rtl_dump_file);
3123 if (loops)
3125 /* The optimalizations: */
3126 if (flag_unswitch_loops)
3127 unswitch_loops (loops);
3129 if (flag_peel_loops || flag_unroll_loops)
3130 unroll_and_peel_loops (loops,
3131 (flag_peel_loops ? UAP_PEEL : 0) |
3132 (flag_unroll_loops ? UAP_UNROLL : 0) |
3133 (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0));
3135 loop_optimizer_finalize (loops, rtl_dump_file);
3138 cleanup_cfg (CLEANUP_EXPENSIVE);
3139 delete_trivially_dead_insns (insns, max_reg_num ());
3140 reg_scan (insns, max_reg_num (), 0);
3141 if (rtl_dump_file)
3142 dump_flow_info (rtl_dump_file);
3143 close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
3144 timevar_pop (TV_LOOP);
3145 ggc_collect ();
3148 if (flag_rerun_cse_after_loop)
3150 timevar_push (TV_CSE2);
3151 open_dump_file (DFI_cse2, decl);
3152 if (rtl_dump_file)
3153 dump_flow_info (rtl_dump_file);
3154 /* CFG is no longer maintained up-to-date. */
3155 tem = cse_main (insns, max_reg_num (), 1, rtl_dump_file);
3156 purge_all_dead_edges (0);
3157 delete_trivially_dead_insns (insns, max_reg_num ());
3159 if (tem)
3161 timevar_push (TV_JUMP);
3162 rebuild_jump_labels (insns);
3163 cleanup_cfg (CLEANUP_EXPENSIVE);
3164 timevar_pop (TV_JUMP);
3166 reg_scan (insns, max_reg_num (), 0);
3167 close_dump_file (DFI_cse2, print_rtl_with_bb, insns);
3168 ggc_collect ();
3169 timevar_pop (TV_CSE2);
3172 cse_not_expected = 1;
3174 open_dump_file (DFI_life, decl);
3175 regclass_init ();
3177 check_function_return_warnings ();
3179 #ifdef ENABLE_CHECKING
3180 verify_flow_info ();
3181 #endif
3182 life_analysis (insns, rtl_dump_file, PROP_FINAL);
3183 if (optimize)
3184 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_UPDATE_LIFE
3185 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
3186 timevar_pop (TV_FLOW);
3188 no_new_pseudos = 1;
3190 if (warn_uninitialized || extra_warnings)
3192 uninitialized_vars_warning (DECL_INITIAL (decl));
3193 if (extra_warnings)
3194 setjmp_args_warning ();
3197 if (optimize)
3199 clear_bb_flags ();
3200 if (!flag_new_regalloc && initialize_uninitialized_subregs ())
3202 /* Insns were inserted, so things might look a bit different. */
3203 insns = get_insns ();
3204 update_life_info_in_dirty_blocks (UPDATE_LIFE_GLOBAL_RM_NOTES,
3205 PROP_LOG_LINKS | PROP_REG_INFO
3206 | PROP_DEATH_NOTES);
3210 close_dump_file (DFI_life, print_rtl_with_bb, insns);
3212 ggc_collect ();
3214 /* If -opt, try combining insns through substitution. */
3216 if (optimize > 0)
3218 int rebuild_jump_labels_after_combine = 0;
3220 timevar_push (TV_COMBINE);
3221 open_dump_file (DFI_combine, decl);
3223 rebuild_jump_labels_after_combine
3224 = combine_instructions (insns, max_reg_num ());
3226 /* Combining insns may have turned an indirect jump into a
3227 direct jump. Rebuild the JUMP_LABEL fields of jumping
3228 instructions. */
3229 if (rebuild_jump_labels_after_combine)
3231 timevar_push (TV_JUMP);
3232 rebuild_jump_labels (insns);
3233 timevar_pop (TV_JUMP);
3235 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
3238 close_dump_file (DFI_combine, print_rtl_with_bb, insns);
3239 timevar_pop (TV_COMBINE);
3241 ggc_collect ();
3244 /* Rerun if-conversion, as combine may have simplified things enough to
3245 now meet sequence length restrictions. */
3246 if (flag_if_conversion)
3248 timevar_push (TV_IFCVT);
3249 open_dump_file (DFI_ce2, decl);
3251 no_new_pseudos = 0;
3252 if_convert (1);
3253 no_new_pseudos = 1;
3255 close_dump_file (DFI_ce2, print_rtl_with_bb, insns);
3256 timevar_pop (TV_IFCVT);
3259 /* Register allocation pre-pass, to reduce number of moves
3260 necessary for two-address machines. */
3261 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
3263 timevar_push (TV_REGMOVE);
3264 open_dump_file (DFI_regmove, decl);
3266 regmove_optimize (insns, max_reg_num (), rtl_dump_file);
3268 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
3269 close_dump_file (DFI_regmove, print_rtl_with_bb, insns);
3270 timevar_pop (TV_REGMOVE);
3272 ggc_collect ();
3275 /* Do unconditional splitting before register allocation to allow machine
3276 description to add extra information not needed previously. */
3277 split_all_insns (1);
3279 #ifdef OPTIMIZE_MODE_SWITCHING
3280 timevar_push (TV_MODE_SWITCH);
3282 no_new_pseudos = 0;
3283 optimize_mode_switching (NULL);
3284 no_new_pseudos = 1;
3286 timevar_pop (TV_MODE_SWITCH);
3287 #endif
3289 /* Any of the several passes since flow1 will have munged register
3290 lifetime data a bit. We need it to be up to date for scheduling
3291 (see handling of reg_known_equiv in init_alias_analysis). */
3292 recompute_reg_usage (insns, !optimize_size);
3294 timevar_push (TV_SCHED);
3296 #ifdef INSN_SCHEDULING
3298 /* Print function header into sched dump now
3299 because doing the sched analysis makes some of the dump. */
3300 if (optimize > 0 && flag_schedule_insns)
3302 open_dump_file (DFI_sched, decl);
3304 /* Do control and data sched analysis,
3305 and write some of the results to dump file. */
3307 schedule_insns (rtl_dump_file);
3309 close_dump_file (DFI_sched, print_rtl_with_bb, insns);
3311 #endif
3312 timevar_pop (TV_SCHED);
3314 ggc_collect ();
3316 /* Determine if the current function is a leaf before running reload
3317 since this can impact optimizations done by the prologue and
3318 epilogue thus changing register elimination offsets. */
3319 current_function_is_leaf = leaf_function_p ();
3321 timevar_push (TV_LOCAL_ALLOC);
3322 open_dump_file (DFI_lreg, decl);
3324 /* Allocate pseudo-regs that are used only within 1 basic block.
3326 RUN_JUMP_AFTER_RELOAD records whether or not we need to rerun the
3327 jump optimizer after register allocation and reloading are finished. */
3329 if (flag_new_regalloc)
3331 delete_trivially_dead_insns (insns, max_reg_num ());
3332 reg_alloc ();
3334 timevar_pop (TV_LOCAL_ALLOC);
3335 if (dump_file[DFI_lreg].enabled)
3337 timevar_push (TV_DUMP);
3339 close_dump_file (DFI_lreg, NULL, NULL);
3340 timevar_pop (TV_DUMP);
3343 /* XXX clean up the whole mess to bring live info in shape again. */
3344 timevar_push (TV_GLOBAL_ALLOC);
3345 open_dump_file (DFI_greg, decl);
3347 build_insn_chain (insns);
3348 failure = reload (insns, 0);
3350 timevar_pop (TV_GLOBAL_ALLOC);
3352 if (dump_file[DFI_greg].enabled)
3354 timevar_push (TV_DUMP);
3356 dump_global_regs (rtl_dump_file);
3358 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
3359 timevar_pop (TV_DUMP);
3362 if (failure)
3363 goto exit_rest_of_compilation;
3364 reload_completed = 1;
3365 rebuild_label_notes_after_reload = 0;
3367 else
3369 /* Allocate the reg_renumber array. */
3370 allocate_reg_info (max_regno, FALSE, TRUE);
3372 /* And the reg_equiv_memory_loc array. */
3373 reg_equiv_memory_loc = (rtx *) xcalloc (max_regno, sizeof (rtx));
3375 allocate_initial_values (reg_equiv_memory_loc);
3377 regclass (insns, max_reg_num (), rtl_dump_file);
3378 rebuild_label_notes_after_reload = local_alloc ();
3380 timevar_pop (TV_LOCAL_ALLOC);
3382 if (dump_file[DFI_lreg].enabled)
3384 timevar_push (TV_DUMP);
3386 dump_flow_info (rtl_dump_file);
3387 dump_local_alloc (rtl_dump_file);
3389 close_dump_file (DFI_lreg, print_rtl_with_bb, insns);
3390 timevar_pop (TV_DUMP);
3393 ggc_collect ();
3395 timevar_push (TV_GLOBAL_ALLOC);
3396 open_dump_file (DFI_greg, decl);
3398 /* If optimizing, allocate remaining pseudo-regs. Do the reload
3399 pass fixing up any insns that are invalid. */
3401 if (optimize)
3402 failure = global_alloc (rtl_dump_file);
3403 else
3405 build_insn_chain (insns);
3406 failure = reload (insns, 0);
3409 timevar_pop (TV_GLOBAL_ALLOC);
3411 if (dump_file[DFI_greg].enabled)
3413 timevar_push (TV_DUMP);
3415 dump_global_regs (rtl_dump_file);
3417 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
3418 timevar_pop (TV_DUMP);
3421 if (failure)
3422 goto exit_rest_of_compilation;
3425 ggc_collect ();
3427 open_dump_file (DFI_postreload, decl);
3429 /* Do a very simple CSE pass over just the hard registers. */
3430 if (optimize > 0)
3432 timevar_push (TV_RELOAD_CSE_REGS);
3433 reload_cse_regs (insns);
3434 timevar_pop (TV_RELOAD_CSE_REGS);
3437 /* Register allocation and reloading may have turned an indirect jump into
3438 a direct jump. If so, we must rebuild the JUMP_LABEL fields of
3439 jumping instructions. */
3440 if (rebuild_label_notes_after_reload)
3442 timevar_push (TV_JUMP);
3444 rebuild_jump_labels (insns);
3445 purge_all_dead_edges (0);
3447 timevar_pop (TV_JUMP);
3450 close_dump_file (DFI_postreload, print_rtl_with_bb, insns);
3452 /* Re-create the death notes which were deleted during reload. */
3453 timevar_push (TV_FLOW2);
3454 open_dump_file (DFI_flow2, decl);
3456 #ifdef ENABLE_CHECKING
3457 verify_flow_info ();
3458 #endif
3460 /* If optimizing, then go ahead and split insns now. */
3461 if (optimize > 0)
3462 split_all_insns (0);
3464 cleanup_cfg (optimize ? CLEANUP_EXPENSIVE : 0);
3466 /* On some machines, the prologue and epilogue code, or parts thereof,
3467 can be represented as RTL. Doing so lets us schedule insns between
3468 it and the rest of the code and also allows delayed branch
3469 scheduling to operate in the epilogue. */
3470 thread_prologue_and_epilogue_insns (insns);
3472 if (optimize)
3474 life_analysis (insns, rtl_dump_file, PROP_FINAL);
3475 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
3476 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
3478 /* This is kind of a heuristic. We need to run combine_stack_adjustments
3479 even for machines with possibly nonzero RETURN_POPS_ARGS
3480 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
3481 push instructions will have popping returns. */
3482 #ifndef PUSH_ROUNDING
3483 if (!ACCUMULATE_OUTGOING_ARGS)
3484 #endif
3485 combine_stack_adjustments ();
3487 ggc_collect ();
3490 flow2_completed = 1;
3492 close_dump_file (DFI_flow2, print_rtl_with_bb, insns);
3493 timevar_pop (TV_FLOW2);
3495 #ifdef HAVE_peephole2
3496 if (optimize > 0 && flag_peephole2)
3498 timevar_push (TV_PEEPHOLE2);
3499 open_dump_file (DFI_peephole2, decl);
3501 peephole2_optimize (rtl_dump_file);
3503 close_dump_file (DFI_peephole2, print_rtl_with_bb, insns);
3504 timevar_pop (TV_PEEPHOLE2);
3506 #endif
3508 if (optimize > 0 && (flag_rename_registers || flag_cprop_registers))
3510 timevar_push (TV_RENAME_REGISTERS);
3511 open_dump_file (DFI_rnreg, decl);
3513 if (flag_rename_registers)
3514 regrename_optimize ();
3515 if (flag_cprop_registers)
3516 copyprop_hardreg_forward ();
3518 close_dump_file (DFI_rnreg, print_rtl_with_bb, insns);
3519 timevar_pop (TV_RENAME_REGISTERS);
3522 if (optimize > 0)
3524 timevar_push (TV_REORDER_BLOCKS);
3525 open_dump_file (DFI_bbro, decl);
3527 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
3528 splitting possibly introduced more crossjumping opportunities. */
3529 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
3530 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
3532 if (flag_sched2_use_traces && flag_schedule_insns_after_reload)
3533 tracer ();
3534 if (flag_reorder_blocks)
3535 reorder_basic_blocks ();
3536 if (flag_reorder_blocks
3537 || (flag_sched2_use_traces && flag_schedule_insns_after_reload))
3538 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
3540 close_dump_file (DFI_bbro, print_rtl_with_bb, insns);
3541 timevar_pop (TV_REORDER_BLOCKS);
3544 if (flag_if_conversion2)
3546 timevar_push (TV_IFCVT2);
3547 open_dump_file (DFI_ce3, decl);
3549 if_convert (1);
3551 close_dump_file (DFI_ce3, print_rtl_with_bb, insns);
3552 timevar_pop (TV_IFCVT2);
3554 #ifdef STACK_REGS
3555 if (optimize)
3556 split_all_insns (1);
3557 #endif
3559 #ifdef INSN_SCHEDULING
3560 if (optimize > 0 && flag_schedule_insns_after_reload)
3562 timevar_push (TV_SCHED2);
3563 open_dump_file (DFI_sched2, decl);
3565 /* Do control and data sched analysis again,
3566 and write some more of the results to dump file. */
3568 split_all_insns (1);
3570 if (flag_sched2_use_superblocks || flag_sched2_use_traces)
3572 schedule_ebbs (rtl_dump_file);
3573 /* No liveness updating code yet, but it should be easy to do.
3574 reg-stack recompute the liveness when needed for now. */
3575 count_or_remove_death_notes (NULL, 1);
3576 cleanup_cfg (CLEANUP_EXPENSIVE);
3578 else
3579 schedule_insns (rtl_dump_file);
3581 close_dump_file (DFI_sched2, print_rtl_with_bb, insns);
3582 timevar_pop (TV_SCHED2);
3584 ggc_collect ();
3586 #endif
3588 #ifdef LEAF_REGISTERS
3589 current_function_uses_only_leaf_regs
3590 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
3591 #endif
3593 #ifdef STACK_REGS
3594 timevar_push (TV_REG_STACK);
3595 open_dump_file (DFI_stack, decl);
3597 if (reg_to_stack (insns, rtl_dump_file) && optimize)
3599 if (cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
3600 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0))
3601 && flag_reorder_blocks)
3603 reorder_basic_blocks ();
3604 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
3608 close_dump_file (DFI_stack, print_rtl_with_bb, insns);
3609 timevar_pop (TV_REG_STACK);
3611 ggc_collect ();
3612 #endif
3613 compute_alignments ();
3615 /* CFG is no longer maintained up-to-date. */
3616 free_bb_for_insn ();
3618 /* If a machine dependent reorganization is needed, call it. */
3619 #ifdef MACHINE_DEPENDENT_REORG
3620 timevar_push (TV_MACH_DEP);
3621 open_dump_file (DFI_mach, decl);
3623 MACHINE_DEPENDENT_REORG (insns);
3625 close_dump_file (DFI_mach, print_rtl, insns);
3626 timevar_pop (TV_MACH_DEP);
3628 ggc_collect ();
3629 #endif
3631 purge_line_number_notes (insns);
3632 cleanup_barriers ();
3634 /* If a scheduling pass for delayed branches is to be done,
3635 call the scheduling code. */
3637 #ifdef DELAY_SLOTS
3638 if (optimize > 0 && flag_delayed_branch)
3640 timevar_push (TV_DBR_SCHED);
3641 open_dump_file (DFI_dbr, decl);
3643 dbr_schedule (insns, rtl_dump_file);
3645 close_dump_file (DFI_dbr, print_rtl, insns);
3646 timevar_pop (TV_DBR_SCHED);
3648 ggc_collect ();
3650 #endif
3652 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3653 timevar_push (TV_SHORTEN_BRANCH);
3654 split_all_insns_noflow ();
3655 timevar_pop (TV_SHORTEN_BRANCH);
3656 #endif
3658 convert_to_eh_region_ranges ();
3660 /* Shorten branches. */
3661 timevar_push (TV_SHORTEN_BRANCH);
3662 shorten_branches (get_insns ());
3663 timevar_pop (TV_SHORTEN_BRANCH);
3665 set_nothrow_function_flags ();
3666 if (current_function_nothrow)
3667 /* Now we know that this can't throw; set the flag for the benefit
3668 of other functions later in this translation unit. */
3669 TREE_NOTHROW (current_function_decl) = 1;
3671 /* Now turn the rtl into assembler code. */
3673 timevar_push (TV_FINAL);
3675 rtx x;
3676 const char *fnname;
3678 /* Get the function's name, as described by its RTL. This may be
3679 different from the DECL_NAME name used in the source file. */
3681 x = DECL_RTL (decl);
3682 if (GET_CODE (x) != MEM)
3683 abort ();
3684 x = XEXP (x, 0);
3685 if (GET_CODE (x) != SYMBOL_REF)
3686 abort ();
3687 fnname = XSTR (x, 0);
3689 assemble_start_function (decl, fnname);
3690 final_start_function (insns, asm_out_file, optimize);
3691 final (insns, asm_out_file, optimize, 0);
3692 final_end_function ();
3694 #ifdef IA64_UNWIND_INFO
3695 /* ??? The IA-64 ".handlerdata" directive must be issued before
3696 the ".endp" directive that closes the procedure descriptor. */
3697 output_function_exception_table ();
3698 #endif
3700 assemble_end_function (decl, fnname);
3702 #ifndef IA64_UNWIND_INFO
3703 /* Otherwise, it feels unclean to switch sections in the middle. */
3704 output_function_exception_table ();
3705 #endif
3707 if (! quiet_flag)
3708 fflush (asm_out_file);
3710 /* Release all memory allocated by flow. */
3711 free_basic_block_vars (0);
3713 /* Release all memory held by regsets now. */
3714 regset_release_memory ();
3716 timevar_pop (TV_FINAL);
3718 ggc_collect ();
3720 /* Write DBX symbols if requested. */
3722 /* Note that for those inline functions where we don't initially
3723 know for certain that we will be generating an out-of-line copy,
3724 the first invocation of this routine (rest_of_compilation) will
3725 skip over this code by doing a `goto exit_rest_of_compilation;'.
3726 Later on, wrapup_global_declarations will (indirectly) call
3727 rest_of_compilation again for those inline functions that need
3728 to have out-of-line copies generated. During that call, we
3729 *will* be routed past here. */
3731 timevar_push (TV_SYMOUT);
3732 (*debug_hooks->function_decl) (decl);
3733 timevar_pop (TV_SYMOUT);
3735 exit_rest_of_compilation:
3737 /* In case the function was not output,
3738 don't leave any temporary anonymous types
3739 queued up for sdb output. */
3740 #ifdef SDB_DEBUGGING_INFO
3741 if (write_symbols == SDB_DEBUG)
3742 sdbout_types (NULL_TREE);
3743 #endif
3745 reload_completed = 0;
3746 flow2_completed = 0;
3747 no_new_pseudos = 0;
3749 timevar_push (TV_FINAL);
3751 /* Clear out the insn_length contents now that they are no
3752 longer valid. */
3753 init_insn_lengths ();
3755 /* Show no temporary slots allocated. */
3756 init_temp_slots ();
3758 free_basic_block_vars (0);
3759 free_bb_for_insn ();
3761 timevar_pop (TV_FINAL);
3763 /* Make sure volatile mem refs aren't considered valid operands for
3764 arithmetic insns. We must call this here if this is a nested inline
3765 function, since the above code leaves us in the init_recog state
3766 (from final.c), and the function context push/pop code does not
3767 save/restore volatile_ok.
3769 ??? Maybe it isn't necessary for expand_start_function to call this
3770 anymore if we do it here? */
3772 init_recog_no_volatile ();
3774 /* We're done with this function. Free up memory if we can. */
3775 free_after_parsing (cfun);
3776 if (! DECL_DEFER_OUTPUT (decl))
3778 free_after_compilation (cfun);
3780 /* Clear integrate.c's pointer to the cfun structure we just
3781 destroyed. */
3782 DECL_SAVED_INSNS (decl) = 0;
3784 cfun = 0;
3786 ggc_collect ();
3788 timevar_pop (TV_REST_OF_COMPILATION);
3791 static void
3792 display_help ()
3794 int undoc;
3795 unsigned long i;
3796 const char *lang;
3798 printf (_(" -ffixed-<register> Mark <register> as being unavailable to the compiler\n"));
3799 printf (_(" -fcall-used-<register> Mark <register> as being corrupted by function calls\n"));
3800 printf (_(" -fcall-saved-<register> Mark <register> as being preserved across functions\n"));
3801 printf (_(" -finline-limit=<number> Limits the size of inlined functions to <number>\n"));
3802 printf (_(" -fmessage-length=<number> Limits diagnostics messages lengths to <number> characters per line. 0 suppresses line-wrapping\n"));
3803 printf (_(" -fdiagnostics-show-location=[once | every-line] Indicates how often source location information should be emitted, as prefix, at the beginning of diagnostics when line-wrapping\n"));
3804 printf (_(" -ftls-model=[global-dynamic | local-dynamic | initial-exec | local-exec] Indicates the default thread-local storage code generation model\n"));
3806 for (i = ARRAY_SIZE (f_options); i--;)
3808 const char *description = f_options[i].description;
3810 if (description != NULL && *description != 0)
3811 printf (" -f%-21s %s\n",
3812 f_options[i].string, _(description));
3815 printf (_(" -O[number] Set optimization level to [number]\n"));
3816 printf (_(" -Os Optimize for space rather than speed\n"));
3817 for (i = LAST_PARAM; i--;)
3819 const char *description = compiler_params[i].help;
3820 const int length = 21 - strlen (compiler_params[i].option);
3822 if (description != NULL && *description != 0)
3823 printf (" --param %s=<value>%.*s%s\n",
3824 compiler_params[i].option,
3825 length > 0 ? length : 1, " ",
3826 _(description));
3828 printf (_(" -pedantic Issue warnings needed by strict compliance to ISO C\n"));
3829 printf (_(" -pedantic-errors Like -pedantic except that errors are produced\n"));
3830 printf (_(" -w Suppress warnings\n"));
3832 for (i = ARRAY_SIZE (W_options); i--;)
3834 const char *description = W_options[i].description;
3836 if (description != NULL && *description != 0)
3837 printf (" -W%-21s %s\n",
3838 W_options[i].string, _(description));
3841 printf (_(" -Wunused Enable unused warnings\n"));
3842 printf (_(" -Wlarger-than-<number> Warn if an object is larger than <number> bytes\n"));
3843 printf (_(" -p Enable function profiling\n"));
3844 printf (_(" -o <file> Place output into <file> \n"));
3845 printf (_("\
3846 -G <number> Put global and static data smaller than <number>\n\
3847 bytes into a special section (on some targets)\n"));
3849 for (i = ARRAY_SIZE (debug_args); i--;)
3851 if (debug_args[i].description != NULL)
3852 printf (" -g%-21s %s\n",
3853 debug_args[i].arg, _(debug_args[i].description));
3856 printf (_(" -aux-info <file> Emit declaration info into <file>\n"));
3857 printf (_(" -quiet Do not display functions compiled or elapsed time\n"));
3858 printf (_(" -version Display the compiler's version\n"));
3859 printf (_(" -d[letters] Enable dumps from specific passes of the compiler\n"));
3860 printf (_(" -dumpbase <file> Base name to be used for dumps from specific passes\n"));
3861 #if defined INSN_SCHEDULING
3862 printf (_(" -fsched-verbose=<number> Set the verbosity level of the scheduler\n"));
3863 #endif
3864 printf (_(" --help Display this information\n"));
3866 undoc = 0;
3867 lang = "language";
3869 /* Display descriptions of language specific options.
3870 If there is no description, note that there is an undocumented option.
3871 If the description is empty, do not display anything. (This allows
3872 options to be deliberately undocumented, for whatever reason).
3873 If the option string is missing, then this is a marker, indicating
3874 that the description string is in fact the name of a language, whose
3875 language specific options are to follow. */
3877 if (ARRAY_SIZE (documented_lang_options) > 1)
3879 printf (_("\nLanguage specific options:\n"));
3881 for (i = 0; i < ARRAY_SIZE (documented_lang_options); i++)
3883 const char *description = documented_lang_options[i].description;
3884 const char *option = documented_lang_options[i].option;
3886 if (description == NULL)
3888 undoc = 1;
3890 if (extra_warnings)
3891 printf (_(" %-23.23s [undocumented]\n"), option);
3893 else if (*description == 0)
3894 continue;
3895 else if (option == NULL)
3897 if (undoc)
3898 printf
3899 (_("\nThere are undocumented %s specific options as well.\n"),
3900 lang);
3901 undoc = 0;
3903 printf (_("\n Options for %s:\n"), description);
3905 lang = description;
3907 else
3908 printf (" %-23.23s %s\n", option, _(description));
3912 if (undoc)
3913 printf (_("\nThere are undocumented %s specific options as well.\n"),
3914 lang);
3916 display_target_options ();
3919 static void
3920 display_target_options ()
3922 int undoc, i;
3923 static bool displayed = false;
3925 /* Avoid double printing for --help --target-help. */
3926 if (displayed)
3927 return;
3928 displayed = true;
3930 if (ARRAY_SIZE (target_switches) > 1
3931 #ifdef TARGET_OPTIONS
3932 || ARRAY_SIZE (target_options) > 1
3933 #endif
3936 int doc = 0;
3938 undoc = 0;
3940 printf (_("\nTarget specific options:\n"));
3942 for (i = ARRAY_SIZE (target_switches); i--;)
3944 const char *option = target_switches[i].name;
3945 const char *description = target_switches[i].description;
3947 if (option == NULL || *option == 0)
3948 continue;
3949 else if (description == NULL)
3951 undoc = 1;
3953 if (extra_warnings)
3954 printf (_(" -m%-23.23s [undocumented]\n"), option);
3956 else if (*description != 0)
3957 doc += printf (" -m%-23.23s %s\n", option, _(description));
3960 #ifdef TARGET_OPTIONS
3961 for (i = ARRAY_SIZE (target_options); i--;)
3963 const char *option = target_options[i].prefix;
3964 const char *description = target_options[i].description;
3966 if (option == NULL || *option == 0)
3967 continue;
3968 else if (description == NULL)
3970 undoc = 1;
3972 if (extra_warnings)
3973 printf (_(" -m%-23.23s [undocumented]\n"), option);
3975 else if (*description != 0)
3976 doc += printf (" -m%-23.23s %s\n", option, _(description));
3978 #endif
3979 if (undoc)
3981 if (doc)
3982 printf (_("\nThere are undocumented target specific options as well.\n"));
3983 else
3984 printf (_(" They exist, but they are not documented.\n"));
3989 /* Parse a -d... command line switch. */
3991 static void
3992 decode_d_option (arg)
3993 const char *arg;
3995 int i, c, matched;
3997 while (*arg)
3998 switch (c = *arg++)
4000 case 'a':
4001 for (i = 0; i < (int) DFI_MAX; ++i)
4002 dump_file[i].enabled = 1;
4003 break;
4004 case 'A':
4005 flag_debug_asm = 1;
4006 break;
4007 case 'p':
4008 flag_print_asm_name = 1;
4009 break;
4010 case 'P':
4011 flag_dump_rtl_in_asm = 1;
4012 flag_print_asm_name = 1;
4013 break;
4014 case 'v':
4015 graph_dump_format = vcg;
4016 break;
4017 case 'x':
4018 rtl_dump_and_exit = 1;
4019 break;
4020 case 'y':
4021 set_yydebug = 1;
4022 break;
4023 case 'D': /* These are handled by the preprocessor. */
4024 case 'I':
4025 break;
4026 case 'H':
4027 setup_core_dumping();
4028 break;
4030 default:
4031 matched = 0;
4032 for (i = 0; i < (int) DFI_MAX; ++i)
4033 if (c == dump_file[i].debug_switch)
4035 dump_file[i].enabled = 1;
4036 matched = 1;
4039 if (! matched)
4040 warning ("unrecognized gcc debugging option: %c", c);
4041 break;
4045 /* Parse a -f... command line switch. ARG is the value after the -f.
4046 It is safe to access 'ARG - 2' to generate the full switch name.
4047 Return the number of strings consumed. */
4049 static int
4050 decode_f_option (arg)
4051 const char *arg;
4053 int j;
4054 const char *option_value = NULL;
4056 /* Search for the option in the table of binary f options. */
4057 for (j = ARRAY_SIZE (f_options); j--;)
4059 if (!strcmp (arg, f_options[j].string))
4061 *f_options[j].variable = f_options[j].on_value;
4062 return 1;
4065 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-'
4066 && ! strcmp (arg + 3, f_options[j].string))
4068 *f_options[j].variable = ! f_options[j].on_value;
4069 return 1;
4073 if (!strcmp (arg, "fast-math"))
4074 set_fast_math_flags (1);
4075 else if (!strcmp (arg, "no-fast-math"))
4076 set_fast_math_flags (0);
4077 else if ((option_value = skip_leading_substring (arg, "inline-limit-"))
4078 || (option_value = skip_leading_substring (arg, "inline-limit=")))
4080 int val =
4081 read_integral_parameter (option_value, arg - 2,
4082 MAX_INLINE_INSNS);
4083 set_param_value ("max-inline-insns", val);
4085 else if ((option_value = skip_leading_substring (arg, "tls-model=")))
4087 if (strcmp (option_value, "global-dynamic") == 0)
4088 flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
4089 else if (strcmp (option_value, "local-dynamic") == 0)
4090 flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
4091 else if (strcmp (option_value, "initial-exec") == 0)
4092 flag_tls_default = TLS_MODEL_INITIAL_EXEC;
4093 else if (strcmp (option_value, "local-exec") == 0)
4094 flag_tls_default = TLS_MODEL_LOCAL_EXEC;
4095 else
4096 warning ("`%s': unknown tls-model option", arg - 2);
4098 #ifdef INSN_SCHEDULING
4099 else if ((option_value = skip_leading_substring (arg, "sched-verbose=")))
4100 fix_sched_param ("verbose", option_value);
4101 #endif
4102 else if ((option_value = skip_leading_substring (arg, "fixed-")))
4103 fix_register (option_value, 1, 1);
4104 else if ((option_value = skip_leading_substring (arg, "call-used-")))
4105 fix_register (option_value, 0, 1);
4106 else if ((option_value = skip_leading_substring (arg, "call-saved-")))
4107 fix_register (option_value, 0, 0);
4108 else if ((option_value = skip_leading_substring (arg, "align-loops=")))
4109 align_loops = read_integral_parameter (option_value, arg - 2, align_loops);
4110 else if ((option_value = skip_leading_substring (arg, "align-functions=")))
4111 align_functions
4112 = read_integral_parameter (option_value, arg - 2, align_functions);
4113 else if ((option_value = skip_leading_substring (arg, "align-jumps=")))
4114 align_jumps = read_integral_parameter (option_value, arg - 2, align_jumps);
4115 else if ((option_value = skip_leading_substring (arg, "align-labels=")))
4116 align_labels
4117 = read_integral_parameter (option_value, arg - 2, align_labels);
4118 else if ((option_value
4119 = skip_leading_substring (arg, "stack-limit-register=")))
4121 int reg = decode_reg_name (option_value);
4122 if (reg < 0)
4123 error ("unrecognized register name `%s'", option_value);
4124 else
4125 stack_limit_rtx = gen_rtx_REG (Pmode, reg);
4127 else if ((option_value
4128 = skip_leading_substring (arg, "stack-limit-symbol=")))
4130 const char *nm;
4131 nm = ggc_strdup (option_value);
4132 stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, nm);
4134 else if ((option_value
4135 = skip_leading_substring (arg, "message-length=")))
4136 output_set_maximum_length
4137 (&global_dc->buffer, read_integral_parameter
4138 (option_value, arg - 2, diagnostic_line_cutoff (global_dc)));
4139 else if ((option_value
4140 = skip_leading_substring (arg, "diagnostics-show-location=")))
4142 if (!strcmp (option_value, "once"))
4143 diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
4144 else if (!strcmp (option_value, "every-line"))
4145 diagnostic_prefixing_rule (global_dc)
4146 = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
4147 else
4148 error ("unrecognized option `%s'", arg - 2);
4150 else if (!strcmp (arg, "no-stack-limit"))
4151 stack_limit_rtx = NULL_RTX;
4152 else if (!strcmp (arg, "preprocessed"))
4153 /* Recognize this switch but do nothing. This prevents warnings
4154 about an unrecognized switch if cpplib has not been linked in. */
4156 else
4157 return 0;
4159 return 1;
4162 /* Parse a -W... command line switch. ARG is the value after the -W.
4163 It is safe to access 'ARG - 2' to generate the full switch name.
4164 Return the number of strings consumed. */
4166 static int
4167 decode_W_option (arg)
4168 const char *arg;
4170 const char *option_value = NULL;
4171 int j;
4173 /* Search for the option in the table of binary W options. */
4175 for (j = ARRAY_SIZE (W_options); j--;)
4177 if (!strcmp (arg, W_options[j].string))
4179 *W_options[j].variable = W_options[j].on_value;
4180 return 1;
4183 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-'
4184 && ! strcmp (arg + 3, W_options[j].string))
4186 *W_options[j].variable = ! W_options[j].on_value;
4187 return 1;
4191 if ((option_value = skip_leading_substring (arg, "id-clash-")))
4192 warning ("-Wid-clash-LEN is no longer supported");
4193 else if ((option_value = skip_leading_substring (arg, "larger-than-")))
4195 larger_than_size = read_integral_parameter (option_value, arg - 2, -1);
4197 warn_larger_than = larger_than_size != -1;
4199 else if (!strcmp (arg, "unused"))
4201 set_Wunused (1);
4203 else if (!strcmp (arg, "no-unused"))
4205 set_Wunused (0);
4207 else if (!strcmp (arg, "extra"))
4209 /* We save the value of warn_uninitialized, since if they put
4210 -Wuninitialized on the command line, we need to generate a
4211 warning about not using it without also specifying -O. */
4212 if (warn_uninitialized != 1)
4213 warn_uninitialized = 2;
4215 else
4216 return 0;
4218 return 1;
4221 /* Parse a -g... command line switch. ARG is the value after the -g.
4222 It is safe to access 'ARG - 2' to generate the full switch name.
4223 Return the number of strings consumed. */
4225 static int
4226 decode_g_option (arg)
4227 const char *arg;
4229 static unsigned level = 0;
4230 /* A lot of code assumes write_symbols == NO_DEBUG if the
4231 debugging level is 0 (thus -gstabs1 -gstabs0 would lose track
4232 of what debugging type has been selected). This records the
4233 selected type. It is an error to specify more than one
4234 debugging type. */
4235 static enum debug_info_type selected_debug_type = NO_DEBUG;
4236 /* Nonzero if debugging format has been explicitly set.
4237 -g and -ggdb don't explicitly set the debugging format so
4238 -gdwarf -g3 is equivalent to -gdwarf3. */
4239 static int type_explicitly_set_p = 0;
4240 /* Indexed by enum debug_info_type. */
4241 static const char *const debug_type_names[] =
4243 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
4246 /* The maximum admissible debug level value. */
4247 static const unsigned max_debug_level = 3;
4249 /* Look up ARG in the table. */
4250 for (da = debug_args; da->arg; da++)
4252 const int da_len = strlen (da->arg);
4254 if (da_len == 0 || ! strncmp (arg, da->arg, da_len))
4256 enum debug_info_type type = da->debug_type;
4257 const char *p = arg + da_len;
4259 if (*p && ! ISDIGIT (*p))
4260 continue;
4262 /* A debug flag without a level defaults to level 2.
4263 Note we do not want to call read_integral_parameter
4264 for that case since it will call atoi which
4265 will return zero.
4267 ??? We may want to generalize the interface to
4268 read_integral_parameter to better handle this case
4269 if this case shows up often. */
4270 if (*p)
4271 level = read_integral_parameter (p, 0, max_debug_level + 1);
4272 else
4273 level = (level == 0) ? 2 : level;
4275 if (da_len > 1 && *p && !strncmp (arg, "dwarf", da_len))
4277 error ("use -gdwarf -g%d for DWARF v1, level %d",
4278 level, level);
4279 if (level == 2)
4280 error ("use -gdwarf-2 for DWARF v2");
4283 if (level > max_debug_level)
4285 warning ("\
4286 ignoring option `%s' due to invalid debug level specification",
4287 arg - 2);
4288 level = debug_info_level;
4291 if (type == NO_DEBUG)
4293 type = PREFERRED_DEBUGGING_TYPE;
4295 if (da_len > 1 && strncmp (arg, "gdb", da_len) == 0)
4297 #ifdef DWARF2_DEBUGGING_INFO
4298 type = DWARF2_DEBUG;
4299 #else
4300 #ifdef DBX_DEBUGGING_INFO
4301 type = DBX_DEBUG;
4302 #endif
4303 #endif
4307 if (type == NO_DEBUG)
4308 warning ("`%s': unknown or unsupported -g option", arg - 2);
4310 /* Does it conflict with an already selected type? */
4311 if (type_explicitly_set_p
4312 /* -g/-ggdb don't conflict with anything. */
4313 && da->debug_type != NO_DEBUG
4314 && type != selected_debug_type)
4315 warning ("`%s' ignored, conflicts with `-g%s'",
4316 arg - 2, debug_type_names[(int) selected_debug_type]);
4317 else
4319 /* If the format has already been set, -g/-ggdb
4320 only change the debug level. */
4321 if (type_explicitly_set_p && da->debug_type == NO_DEBUG)
4322 /* Don't change debugging type. */
4324 else
4326 selected_debug_type = type;
4327 type_explicitly_set_p = da->debug_type != NO_DEBUG;
4330 write_symbols = (level == 0
4331 ? NO_DEBUG
4332 : selected_debug_type);
4333 use_gnu_debug_info_extensions = da->use_extensions_p;
4334 debug_info_level = (enum debug_info_level) level;
4337 break;
4341 if (! da->arg)
4342 return 0;
4344 return 1;
4347 /* Decode the first argument in the argv as a language-independent option.
4348 Return the number of strings consumed. */
4350 static unsigned int
4351 independent_decode_option (argc, argv)
4352 int argc;
4353 char **argv;
4355 char *arg = argv[0];
4357 if (arg[0] != '-' || arg[1] == 0)
4359 if (arg[0] == '+')
4360 return 0;
4362 filename = arg;
4364 return 1;
4367 arg++;
4369 if (!strcmp (arg, "-help"))
4371 display_help ();
4372 exit_after_options = 1;
4375 if (!strcmp (arg, "-target-help"))
4377 display_target_options ();
4378 exit_after_options = 1;
4381 if (!strcmp (arg, "-version"))
4383 print_version (stderr, "");
4384 exit_after_options = 1;
4387 /* Handle '--param <name>=<value>'. */
4388 if (strcmp (arg, "-param") == 0)
4390 char *equal;
4392 if (argc == 1)
4394 error ("-param option missing argument");
4395 return 1;
4398 /* Get the '<name>=<value>' parameter. */
4399 arg = argv[1];
4400 /* Look for the `='. */
4401 equal = strchr (arg, '=');
4402 if (!equal)
4403 error ("invalid --param option: %s", arg);
4404 else
4406 int val;
4408 /* Zero out the `=' sign so that we get two separate strings. */
4409 *equal = '\0';
4410 /* Figure out what value is specified. */
4411 val = read_integral_parameter (equal + 1, NULL, INVALID_PARAM_VAL);
4412 if (val != INVALID_PARAM_VAL)
4413 set_param_value (arg, val);
4414 else
4415 error ("invalid parameter value `%s'", equal + 1);
4418 return 2;
4421 if (*arg == 'Y')
4422 arg++;
4424 switch (*arg)
4426 default:
4427 return 0;
4429 case 'O':
4430 /* Already been treated in main (). Do nothing. */
4431 break;
4433 case 'm':
4434 set_target_switch (arg + 1);
4435 break;
4437 case 'f':
4438 return decode_f_option (arg + 1);
4440 case 'g':
4441 return decode_g_option (arg + 1);
4443 case 'd':
4444 if (!strcmp (arg, "dumpbase"))
4446 if (argc == 1)
4447 return 0;
4449 if (argv[1][0])
4450 dump_base_name = argv[1];
4452 return 2;
4454 else
4455 decode_d_option (arg + 1);
4456 break;
4458 case 'p':
4459 if (!strcmp (arg, "pedantic"))
4460 pedantic = 1;
4461 else if (!strcmp (arg, "pedantic-errors"))
4462 flag_pedantic_errors = pedantic = 1;
4463 else if (arg[1] == 0)
4464 profile_flag = 1;
4465 else
4466 return 0;
4467 break;
4469 case 'q':
4470 if (!strcmp (arg, "quiet"))
4471 quiet_flag = 1;
4472 else
4473 return 0;
4474 break;
4476 case 'v':
4477 if (!strcmp (arg, "version"))
4478 version_flag = 1;
4479 else
4480 return 0;
4481 break;
4483 case 'w':
4484 if (arg[1] == 0)
4485 inhibit_warnings = 1;
4486 else
4487 return 0;
4488 break;
4490 case 'W':
4491 if (arg[1] == 0)
4493 extra_warnings = 1;
4494 /* We save the value of warn_uninitialized, since if they put
4495 -Wuninitialized on the command line, we need to generate a
4496 warning about not using it without also specifying -O. */
4497 if (warn_uninitialized != 1)
4498 warn_uninitialized = 2;
4500 else
4501 return decode_W_option (arg + 1);
4502 break;
4504 case 'a':
4505 if (!strncmp (arg, "aux-info", 8))
4507 if (arg[8] == '\0')
4509 if (argc == 1)
4510 return 0;
4512 aux_info_file_name = argv[1];
4513 flag_gen_aux_info = 1;
4514 return 2;
4516 else if (arg[8] == '=')
4518 aux_info_file_name = arg + 9;
4519 flag_gen_aux_info = 1;
4521 else
4522 return 0;
4524 else if (!strcmp (arg, "auxbase"))
4526 if (argc == 1)
4527 return 0;
4529 if (argv[1][0])
4530 aux_base_name = argv[1];
4532 return 2;
4534 else if (!strcmp (arg, "auxbase-strip"))
4536 if (argc == 1)
4537 return 0;
4539 if (argv[1][0])
4541 strip_off_ending (argv[1], strlen (argv[1]));
4542 if (argv[1][0])
4543 aux_base_name = argv[1];
4546 return 2;
4548 else
4549 return 0;
4550 break;
4552 case 'o':
4553 if (arg[1] == 0)
4555 if (argc == 1)
4556 return 0;
4558 asm_file_name = argv[1];
4559 return 2;
4561 return 0;
4563 case 'G':
4565 int g_switch_val;
4566 int return_val;
4568 if (arg[1] == 0)
4570 if (argc == 1)
4571 return 0;
4573 g_switch_val = read_integral_parameter (argv[1], 0, -1);
4574 return_val = 2;
4576 else
4578 g_switch_val = read_integral_parameter (arg + 1, 0, -1);
4579 return_val = 1;
4582 if (g_switch_val == -1)
4583 return_val = 0;
4584 else
4586 g_switch_set = TRUE;
4587 g_switch_value = g_switch_val;
4590 return return_val;
4594 return 1;
4597 /* Decode -m switches. */
4598 /* Decode the switch -mNAME. */
4600 static void
4601 set_target_switch (name)
4602 const char *name;
4604 size_t j;
4605 int valid_target_option = 0;
4607 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
4608 if (!strcmp (target_switches[j].name, name))
4610 if (target_switches[j].value < 0)
4611 target_flags &= ~-target_switches[j].value;
4612 else
4613 target_flags |= target_switches[j].value;
4614 if (name[0] != 0)
4616 if (target_switches[j].value < 0)
4617 target_flags_explicit |= -target_switches[j].value;
4618 else
4619 target_flags_explicit |= target_switches[j].value;
4621 valid_target_option = 1;
4624 #ifdef TARGET_OPTIONS
4625 if (!valid_target_option)
4626 for (j = 0; j < ARRAY_SIZE (target_options); j++)
4628 int len = strlen (target_options[j].prefix);
4629 if (!strncmp (target_options[j].prefix, name, len))
4631 *target_options[j].variable = name + len;
4632 valid_target_option = 1;
4635 #endif
4637 if (!valid_target_option)
4638 error ("invalid option `%s'", name);
4641 /* Print version information to FILE.
4642 Each line begins with INDENT (for the case where FILE is the
4643 assembler output file). */
4645 static void
4646 print_version (file, indent)
4647 FILE *file;
4648 const char *indent;
4650 fnotice (file, "GGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n",
4651 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
4652 #ifndef __VERSION__
4653 #define __VERSION__ "[?]"
4654 #endif
4655 fnotice (file,
4656 #ifdef __GNUC__
4657 "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
4658 #else
4659 "%s%s%s version %s (%s) compiled by CC.\n"
4660 #endif
4661 , indent, *indent != 0 ? " " : "",
4662 lang_hooks.name, version_string, TARGET_NAME,
4663 indent, __VERSION__);
4666 /* Print an option value and return the adjusted position in the line.
4667 ??? We don't handle error returns from fprintf (disk full); presumably
4668 other code will catch a disk full though. */
4670 static int
4671 print_single_switch (file, pos, max, indent, sep, term, type, name)
4672 FILE *file;
4673 int pos, max;
4674 const char *indent, *sep, *term, *type, *name;
4676 /* The ultrix fprintf returns 0 on success, so compute the result we want
4677 here since we need it for the following test. */
4678 int len = strlen (sep) + strlen (type) + strlen (name);
4680 if (pos != 0
4681 && pos + len > max)
4683 fprintf (file, "%s", term);
4684 pos = 0;
4686 if (pos == 0)
4688 fprintf (file, "%s", indent);
4689 pos = strlen (indent);
4691 fprintf (file, "%s%s%s", sep, type, name);
4692 pos += len;
4693 return pos;
4696 /* Print active target switches to FILE.
4697 POS is the current cursor position and MAX is the size of a "line".
4698 Each line begins with INDENT and ends with TERM.
4699 Each switch is separated from the next by SEP. */
4701 static void
4702 print_switch_values (file, pos, max, indent, sep, term)
4703 FILE *file;
4704 int pos, max;
4705 const char *indent, *sep, *term;
4707 size_t j;
4708 char **p;
4710 /* Print the options as passed. */
4712 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
4713 _("options passed: "), "");
4715 for (p = &save_argv[1]; *p != NULL; p++)
4716 if (**p == '-')
4718 /* Ignore these. */
4719 if (strcmp (*p, "-o") == 0)
4721 if (p[1] != NULL)
4722 p++;
4723 continue;
4725 if (strcmp (*p, "-quiet") == 0)
4726 continue;
4727 if (strcmp (*p, "-version") == 0)
4728 continue;
4729 if ((*p)[1] == 'd')
4730 continue;
4732 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
4734 if (pos > 0)
4735 fprintf (file, "%s", term);
4737 /* Print the -f and -m options that have been enabled.
4738 We don't handle language specific options but printing argv
4739 should suffice. */
4741 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
4742 _("options enabled: "), "");
4744 for (j = 0; j < ARRAY_SIZE (f_options); j++)
4745 if (*f_options[j].variable == f_options[j].on_value)
4746 pos = print_single_switch (file, pos, max, indent, sep, term,
4747 "-f", f_options[j].string);
4749 /* Print target specific options. */
4751 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
4752 if (target_switches[j].name[0] != '\0'
4753 && target_switches[j].value > 0
4754 && ((target_switches[j].value & target_flags)
4755 == target_switches[j].value))
4757 pos = print_single_switch (file, pos, max, indent, sep, term,
4758 "-m", target_switches[j].name);
4761 #ifdef TARGET_OPTIONS
4762 for (j = 0; j < ARRAY_SIZE (target_options); j++)
4763 if (*target_options[j].variable != NULL)
4765 char prefix[256];
4766 sprintf (prefix, "-m%s", target_options[j].prefix);
4767 pos = print_single_switch (file, pos, max, indent, sep, term,
4768 prefix, *target_options[j].variable);
4770 #endif
4772 fprintf (file, "%s", term);
4775 /* Open assembly code output file. Do this even if -fsyntax-only is
4776 on, because then the driver will have provided the name of a
4777 temporary file or bit bucket for us. NAME is the file specified on
4778 the command line, possibly NULL. */
4779 static void
4780 init_asm_output (name)
4781 const char *name;
4783 if (name == NULL && asm_file_name == 0)
4784 asm_out_file = stdout;
4785 else
4787 if (asm_file_name == 0)
4789 int len = strlen (dump_base_name);
4790 char *dumpname = (char *) xmalloc (len + 6);
4791 memcpy (dumpname, dump_base_name, len + 1);
4792 strip_off_ending (dumpname, len);
4793 strcat (dumpname, ".s");
4794 asm_file_name = dumpname;
4796 if (!strcmp (asm_file_name, "-"))
4797 asm_out_file = stdout;
4798 else
4799 asm_out_file = fopen (asm_file_name, "w+");
4800 if (asm_out_file == 0)
4801 fatal_io_error ("can't open %s for writing", asm_file_name);
4804 #ifdef IO_BUFFER_SIZE
4805 setvbuf (asm_out_file, (char *) xmalloc (IO_BUFFER_SIZE),
4806 _IOFBF, IO_BUFFER_SIZE);
4807 #endif
4809 if (!flag_syntax_only)
4811 #ifdef ASM_FILE_START
4812 ASM_FILE_START (asm_out_file);
4813 #endif
4815 #ifdef ASM_COMMENT_START
4816 if (flag_verbose_asm)
4818 /* Print the list of options in effect. */
4819 print_version (asm_out_file, ASM_COMMENT_START);
4820 print_switch_values (asm_out_file, 0, MAX_LINE,
4821 ASM_COMMENT_START, " ", "\n");
4822 /* Add a blank line here so it appears in assembler output but not
4823 screen output. */
4824 fprintf (asm_out_file, "\n");
4826 #endif
4830 /* Initialization of the front end environment, before command line
4831 options are parsed. Signal handlers, internationalization etc.
4832 ARGV0 is main's argv[0]. */
4833 static void
4834 general_init (argv0)
4835 char *argv0;
4837 char *p;
4839 p = argv0 + strlen (argv0);
4840 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
4841 --p;
4842 progname = p;
4844 xmalloc_set_program_name (progname);
4846 hex_init ();
4848 gcc_init_libintl ();
4850 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
4851 #ifdef SIGSEGV
4852 signal (SIGSEGV, crash_signal);
4853 #endif
4854 #ifdef SIGILL
4855 signal (SIGILL, crash_signal);
4856 #endif
4857 #ifdef SIGBUS
4858 signal (SIGBUS, crash_signal);
4859 #endif
4860 #ifdef SIGABRT
4861 signal (SIGABRT, crash_signal);
4862 #endif
4863 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
4864 signal (SIGIOT, crash_signal);
4865 #endif
4866 #ifdef SIGFPE
4867 signal (SIGFPE, crash_signal);
4868 #endif
4870 /* Other host-specific signal setup. */
4871 (*host_hooks.extra_signals)();
4873 /* Initialize the diagnostics reporting machinery, so option parsing
4874 can give warnings and errors. */
4875 diagnostic_initialize (global_dc);
4877 /* Initialize the garbage-collector, string pools and tree type hash
4878 table. */
4879 init_ggc ();
4880 init_stringpool ();
4881 init_ttree ();
4884 /* Parse command line options and set default flag values, called
4885 after language-independent option-independent initialization. Do
4886 minimal options processing. Outputting diagnostics is OK, but GC
4887 and identifier hashtables etc. are not initialized yet.
4889 Return nonzero to suppress compiler back end initialization. */
4890 static void
4891 parse_options_and_default_flags (argc, argv)
4892 int argc;
4893 char **argv;
4895 int i;
4897 /* Save in case md file wants to emit args as a comment. */
4898 save_argc = argc;
4899 save_argv = argv;
4901 /* Initialize register usage now so switches may override. */
4902 init_reg_sets ();
4904 /* Register the language-independent parameters. */
4905 add_params (lang_independent_params, LAST_PARAM);
4907 /* This must be done after add_params but before argument processing. */
4908 init_ggc_heuristics();
4910 /* Perform language-specific options initialization. */
4911 (*lang_hooks.init_options) ();
4913 /* Scan to see what optimization level has been specified. That will
4914 determine the default value of many flags. */
4915 for (i = 1; i < argc; i++)
4917 if (!strcmp (argv[i], "-O"))
4919 optimize = 1;
4920 optimize_size = 0;
4922 else if (argv[i][0] == '-' && argv[i][1] == 'O')
4924 /* Handle -Os, -O2, -O3, -O69, ... */
4925 char *p = &argv[i][2];
4927 if ((p[0] == 's') && (p[1] == 0))
4929 optimize_size = 1;
4931 /* Optimizing for size forces optimize to be 2. */
4932 optimize = 2;
4934 else
4936 const int optimize_val = read_integral_parameter (p, p - 2, -1);
4937 if (optimize_val != -1)
4939 optimize = optimize_val;
4940 optimize_size = 0;
4946 if (!optimize)
4948 flag_merge_constants = 0;
4951 if (optimize >= 1)
4953 flag_defer_pop = 1;
4954 flag_thread_jumps = 1;
4955 #ifdef DELAY_SLOTS
4956 flag_delayed_branch = 1;
4957 #endif
4958 #ifdef CAN_DEBUG_WITHOUT_FP
4959 flag_omit_frame_pointer = 1;
4960 #endif
4961 flag_guess_branch_prob = 1;
4962 flag_cprop_registers = 1;
4963 flag_loop_optimize = 1;
4964 flag_crossjumping = 1;
4965 flag_if_conversion = 1;
4966 flag_if_conversion2 = 1;
4969 if (optimize >= 2)
4971 flag_optimize_sibling_calls = 1;
4972 flag_cse_follow_jumps = 1;
4973 flag_cse_skip_blocks = 1;
4974 flag_gcse = 1;
4975 flag_expensive_optimizations = 1;
4976 flag_strength_reduce = 1;
4977 flag_rerun_cse_after_loop = 1;
4978 flag_rerun_loop_opt = 1;
4979 flag_caller_saves = 1;
4980 flag_force_mem = 1;
4981 flag_peephole2 = 1;
4982 #ifdef INSN_SCHEDULING
4983 flag_schedule_insns = 1;
4984 flag_schedule_insns_after_reload = 1;
4985 #endif
4986 flag_regmove = 1;
4987 flag_strict_aliasing = 1;
4988 flag_delete_null_pointer_checks = 1;
4989 flag_reorder_blocks = 1;
4990 flag_reorder_functions = 1;
4993 if (optimize >= 3)
4995 flag_inline_functions = 1;
4996 flag_rename_registers = 1;
4997 flag_unswitch_loops = 1;
5000 if (optimize < 2 || optimize_size)
5002 align_loops = 1;
5003 align_jumps = 1;
5004 align_labels = 1;
5005 align_functions = 1;
5007 /* Don't reorder blocks when optimizing for size because extra
5008 jump insns may be created; also barrier may create extra padding.
5010 More correctly we should have a block reordering mode that tried
5011 to minimize the combined size of all the jumps. This would more
5012 or less automatically remove extra jumps, but would also try to
5013 use more short jumps instead of long jumps. */
5014 flag_reorder_blocks = 0;
5017 /* Initialize whether `char' is signed. */
5018 flag_signed_char = DEFAULT_SIGNED_CHAR;
5019 #ifdef DEFAULT_SHORT_ENUMS
5020 /* Initialize how much space enums occupy, by default. */
5021 flag_short_enums = DEFAULT_SHORT_ENUMS;
5022 #endif
5024 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
5025 modify it. */
5026 target_flags = 0;
5027 set_target_switch ("");
5029 /* Unwind tables are always present in an ABI-conformant IA-64
5030 object file, so the default should be ON. */
5031 #ifdef IA64_UNWIND_INFO
5032 flag_unwind_tables = IA64_UNWIND_INFO;
5033 #endif
5035 #ifdef OPTIMIZATION_OPTIONS
5036 /* Allow default optimizations to be specified on a per-machine basis. */
5037 OPTIMIZATION_OPTIONS (optimize, optimize_size);
5038 #endif
5040 /* Perform normal command line switch decoding. */
5041 for (i = 1; i < argc;)
5043 int lang_processed;
5044 int indep_processed;
5046 /* Give the language a chance to decode the option for itself. */
5047 lang_processed = (*lang_hooks.decode_option) (argc - i, argv + i);
5049 if (lang_processed >= 0)
5050 /* Now see if the option also has a language independent meaning.
5051 Some options are both language specific and language independent,
5052 eg --help. */
5053 indep_processed = independent_decode_option (argc - i, argv + i);
5054 else
5056 lang_processed = -lang_processed;
5057 indep_processed = 0;
5060 if (lang_processed || indep_processed)
5061 i += MAX (lang_processed, indep_processed);
5062 else
5064 const char *option = NULL;
5065 const char *lang = NULL;
5066 unsigned int j;
5068 /* It is possible that the command line switch is not valid for the
5069 current language, but it is valid for another language. In order
5070 to be compatible with previous versions of the compiler (which
5071 did not issue an error message in this case) we check for this
5072 possibility here. If we do find a match, then if extra_warnings
5073 is set we generate a warning message, otherwise we will just
5074 ignore the option. */
5075 for (j = 0; j < ARRAY_SIZE (documented_lang_options); j++)
5077 option = documented_lang_options[j].option;
5079 if (option == NULL)
5080 lang = documented_lang_options[j].description;
5081 else if (! strncmp (argv[i], option, strlen (option)))
5082 break;
5085 if (j != ARRAY_SIZE (documented_lang_options))
5087 if (extra_warnings)
5089 warning ("ignoring command line option '%s'", argv[i]);
5090 if (lang)
5091 warning
5092 ("(it is valid for %s but not the selected language)",
5093 lang);
5096 else if (argv[i][0] == '-' && argv[i][1] == 'g')
5097 warning ("`%s': unknown or unsupported -g option", &argv[i][2]);
5098 else
5099 error ("unrecognized option `%s'", argv[i]);
5101 i++;
5105 if (flag_no_inline == 2)
5106 flag_no_inline = 0;
5107 else
5108 flag_really_no_inline = flag_no_inline;
5110 /* Set flag_no_inline before the post_options () hook. The C front
5111 ends use it to determine tree inlining defaults. FIXME: such
5112 code should be lang-independent when all front ends use tree
5113 inlining, in which case it, and this condition, should be moved
5114 to the top of process_options() instead. */
5115 if (optimize == 0)
5117 /* Inlining does not work if not optimizing,
5118 so force it not to be done. */
5119 flag_no_inline = 1;
5120 warn_inline = 0;
5122 /* The c_decode_option function and decode_option hook set
5123 this to `2' if -Wall is used, so we can avoid giving out
5124 lots of errors for people who don't realize what -Wall does. */
5125 if (warn_uninitialized == 1)
5126 warning ("-Wuninitialized is not supported without -O");
5129 if (flag_really_no_inline == 2)
5130 flag_really_no_inline = flag_no_inline;
5133 /* Process the options that have been parsed. */
5134 static void
5135 process_options ()
5137 #ifdef OVERRIDE_OPTIONS
5138 /* Some machines may reject certain combinations of options. */
5139 OVERRIDE_OPTIONS;
5140 #endif
5142 /* Set up the align_*_log variables, defaulting them to 1 if they
5143 were still unset. */
5144 if (align_loops <= 0) align_loops = 1;
5145 if (align_loops_max_skip > align_loops || !align_loops)
5146 align_loops_max_skip = align_loops - 1;
5147 align_loops_log = floor_log2 (align_loops * 2 - 1);
5148 if (align_jumps <= 0) align_jumps = 1;
5149 if (align_jumps_max_skip > align_jumps || !align_jumps)
5150 align_jumps_max_skip = align_jumps - 1;
5151 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
5152 if (align_labels <= 0) align_labels = 1;
5153 align_labels_log = floor_log2 (align_labels * 2 - 1);
5154 if (align_labels_max_skip > align_labels || !align_labels)
5155 align_labels_max_skip = align_labels - 1;
5156 if (align_functions <= 0) align_functions = 1;
5157 align_functions_log = floor_log2 (align_functions * 2 - 1);
5159 /* Unrolling all loops implies that standard loop unrolling must also
5160 be done. */
5161 if (flag_unroll_all_loops)
5162 flag_unroll_loops = 1;
5164 if (flag_unroll_loops)
5166 flag_old_unroll_loops = 0;
5167 flag_old_unroll_all_loops = 0;
5170 if (flag_old_unroll_all_loops)
5171 flag_old_unroll_loops = 1;
5173 /* Old loop unrolling requires that strength_reduction be on also. Silently
5174 turn on strength reduction here if it isn't already on. Also, the loop
5175 unrolling code assumes that cse will be run after loop, so that must
5176 be turned on also. */
5177 if (flag_old_unroll_loops)
5179 flag_strength_reduce = 1;
5180 flag_rerun_cse_after_loop = 1;
5182 if (flag_unroll_loops || flag_peel_loops)
5183 flag_rerun_cse_after_loop = 1;
5185 if (flag_non_call_exceptions)
5186 flag_asynchronous_unwind_tables = 1;
5187 if (flag_asynchronous_unwind_tables)
5188 flag_unwind_tables = 1;
5190 /* Disable unit-at-a-time mode for frontends not supporting callgraph
5191 interface. */
5192 if (flag_unit_at_a_time && ! lang_hooks.callgraph.expand_function)
5193 flag_unit_at_a_time = 0;
5195 /* Warn about options that are not supported on this machine. */
5196 #ifndef INSN_SCHEDULING
5197 if (flag_schedule_insns || flag_schedule_insns_after_reload)
5198 warning ("instruction scheduling not supported on this target machine");
5199 #endif
5200 #ifndef DELAY_SLOTS
5201 if (flag_delayed_branch)
5202 warning ("this target machine does not have delayed branches");
5203 #endif
5205 user_label_prefix = USER_LABEL_PREFIX;
5206 if (flag_leading_underscore != -1)
5208 /* If the default prefix is more complicated than "" or "_",
5209 issue a warning and ignore this option. */
5210 if (user_label_prefix[0] == 0 ||
5211 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
5213 user_label_prefix = flag_leading_underscore ? "_" : "";
5215 else
5216 warning ("-f%sleading-underscore not supported on this target machine",
5217 flag_leading_underscore ? "" : "no-");
5220 /* If we are in verbose mode, write out the version and maybe all the
5221 option flags in use. */
5222 if (version_flag)
5224 print_version (stderr, "");
5225 if (! quiet_flag)
5226 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
5229 if (! quiet_flag || flag_detailed_statistics)
5230 time_report = 1;
5232 if (flag_syntax_only)
5234 write_symbols = NO_DEBUG;
5235 profile_flag = 0;
5238 /* Now we know write_symbols, set up the debug hooks based on it.
5239 By default we do nothing for debug output. */
5240 #if defined(DBX_DEBUGGING_INFO)
5241 if (write_symbols == DBX_DEBUG)
5242 debug_hooks = &dbx_debug_hooks;
5243 #endif
5244 #if defined(XCOFF_DEBUGGING_INFO)
5245 if (write_symbols == XCOFF_DEBUG)
5246 debug_hooks = &xcoff_debug_hooks;
5247 #endif
5248 #ifdef SDB_DEBUGGING_INFO
5249 if (write_symbols == SDB_DEBUG)
5250 debug_hooks = &sdb_debug_hooks;
5251 #endif
5252 #ifdef DWARF_DEBUGGING_INFO
5253 if (write_symbols == DWARF_DEBUG)
5254 debug_hooks = &dwarf_debug_hooks;
5255 #endif
5256 #ifdef DWARF2_DEBUGGING_INFO
5257 if (write_symbols == DWARF2_DEBUG)
5258 debug_hooks = &dwarf2_debug_hooks;
5259 #endif
5260 #ifdef VMS_DEBUGGING_INFO
5261 if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
5262 debug_hooks = &vmsdbg_debug_hooks;
5263 #endif
5265 /* If auxiliary info generation is desired, open the output file.
5266 This goes in the same directory as the source file--unlike
5267 all the other output files. */
5268 if (flag_gen_aux_info)
5270 aux_info_file = fopen (aux_info_file_name, "w");
5271 if (aux_info_file == 0)
5272 fatal_io_error ("can't open %s", aux_info_file_name);
5275 if (! targetm.have_named_sections)
5277 if (flag_function_sections)
5279 warning ("-ffunction-sections not supported for this target");
5280 flag_function_sections = 0;
5282 if (flag_data_sections)
5284 warning ("-fdata-sections not supported for this target");
5285 flag_data_sections = 0;
5289 if (flag_function_sections && profile_flag)
5291 warning ("-ffunction-sections disabled; it makes profiling impossible");
5292 flag_function_sections = 0;
5295 #ifndef HAVE_prefetch
5296 if (flag_prefetch_loop_arrays)
5298 warning ("-fprefetch-loop-arrays not supported for this target");
5299 flag_prefetch_loop_arrays = 0;
5301 #else
5302 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
5304 warning ("-fprefetch-loop-arrays not supported for this target (try -march switches)");
5305 flag_prefetch_loop_arrays = 0;
5307 #endif
5309 /* This combination of options isn't handled for i386 targets and doesn't
5310 make much sense anyway, so don't allow it. */
5311 if (flag_prefetch_loop_arrays && optimize_size)
5313 warning ("-fprefetch-loop-arrays is not supported with -Os");
5314 flag_prefetch_loop_arrays = 0;
5317 #ifndef OBJECT_FORMAT_ELF
5318 if (flag_function_sections && write_symbols != NO_DEBUG)
5319 warning ("-ffunction-sections may affect debugging on some targets");
5320 #endif
5322 /* The presence of IEEE signaling NaNs, implies all math can trap. */
5323 if (flag_signaling_nans)
5324 flag_trapping_math = 1;
5327 /* Initialize the compiler back end. */
5328 static void
5329 backend_init ()
5331 /* init_emit_once uses reg_raw_mode and therefore must be called
5332 after init_regs which initialized reg_raw_mode. */
5333 init_regs ();
5334 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
5335 || debug_info_level == DINFO_LEVEL_VERBOSE
5336 #ifdef VMS_DEBUGGING_INFO
5337 /* Enable line number info for traceback */
5338 || debug_info_level > DINFO_LEVEL_NONE
5339 #endif
5340 || flag_test_coverage
5341 || warn_notreached);
5342 init_fake_stack_mems ();
5343 init_alias_once ();
5344 init_loop ();
5345 init_reload ();
5346 init_function_once ();
5347 init_varasm_once ();
5349 /* The following initialization functions need to generate rtl, so
5350 provide a dummy function context for them. */
5351 init_dummy_function_start ();
5352 init_expmed ();
5353 if (flag_caller_saves)
5354 init_caller_save ();
5355 expand_dummy_function_end ();
5358 /* Language-dependent initialization. Returns nonzero on success. */
5359 static int
5360 lang_dependent_init (name)
5361 const char *name;
5363 if (dump_base_name == 0)
5364 dump_base_name = name ? name : "gccdump";
5366 /* Front-end initialization. This hook can assume that GC,
5367 identifier hashes etc. are set up, but debug initialization is
5368 not done yet. This routine must return the original filename
5369 (e.g. foo.i -> foo.c) so can correctly initialize debug output. */
5370 name = (*lang_hooks.init) (name);
5371 if (name == NULL)
5372 return 0;
5374 /* Is this duplication necessary? */
5375 name = ggc_strdup (name);
5376 main_input_filename = input_filename = name;
5377 init_asm_output (name);
5379 /* These create various _DECL nodes, so need to be called after the
5380 front end is initialized. */
5381 init_eh ();
5382 init_optabs ();
5384 /* The following initialization functions need to generate rtl, so
5385 provide a dummy function context for them. */
5386 init_dummy_function_start ();
5387 init_expr_once ();
5388 expand_dummy_function_end ();
5390 /* Put an entry on the input file stack for the main input file. */
5391 push_srcloc (input_filename, 0);
5393 /* If dbx symbol table desired, initialize writing it and output the
5394 predefined types. */
5395 timevar_push (TV_SYMOUT);
5397 #ifdef DWARF2_UNWIND_INFO
5398 if (dwarf2out_do_frame ())
5399 dwarf2out_frame_init ();
5400 #endif
5402 /* Now we have the correct original filename, we can initialize
5403 debug output. */
5404 (*debug_hooks->init) (name);
5406 timevar_pop (TV_SYMOUT);
5408 return 1;
5411 /* Clean up: close opened files, etc. */
5413 static void
5414 finalize ()
5416 /* Close the dump files. */
5417 if (flag_gen_aux_info)
5419 fclose (aux_info_file);
5420 if (errorcount)
5421 unlink (aux_info_file_name);
5424 /* Close non-debugging input and output files. Take special care to note
5425 whether fclose returns an error, since the pages might still be on the
5426 buffer chain while the file is open. */
5428 if (asm_out_file)
5430 if (ferror (asm_out_file) != 0)
5431 fatal_io_error ("error writing to %s", asm_file_name);
5432 if (fclose (asm_out_file) != 0)
5433 fatal_io_error ("error closing %s", asm_file_name);
5436 /* Do whatever is necessary to finish printing the graphs. */
5437 if (graph_dump_format != no_graph)
5439 int i;
5441 for (i = 0; i < (int) DFI_MAX; ++i)
5442 if (dump_file[i].initialized && dump_file[i].graph_dump_p)
5444 char seq[16];
5445 char *suffix;
5447 sprintf (seq, DUMPFILE_FORMAT, i);
5448 suffix = concat (seq, dump_file[i].extension, NULL);
5449 finish_graph_dump_file (dump_base_name, suffix);
5450 free (suffix);
5454 if (mem_report)
5456 ggc_print_statistics ();
5457 stringpool_statistics ();
5458 dump_tree_statistics ();
5461 /* Free up memory for the benefit of leak detectors. */
5462 free_reg_info ();
5464 /* Language-specific end of compilation actions. */
5465 (*lang_hooks.finish) ();
5468 /* Initialize the compiler, and compile the input file. */
5469 static void
5470 do_compile ()
5472 /* All command line options have been parsed; allow the front end to
5473 perform consistency checks, etc. */
5474 bool no_backend = (*lang_hooks.post_options) ();
5476 /* The bulk of command line switch processing. */
5477 process_options ();
5479 /* If an error has already occurred, give up. */
5480 if (errorcount)
5481 return;
5483 if (aux_base_name)
5484 /*NOP*/;
5485 else if (filename)
5487 char *name = xstrdup (lbasename (filename));
5489 aux_base_name = name;
5490 strip_off_ending (name, strlen (name));
5492 else
5493 aux_base_name = "gccaux";
5495 /* We cannot start timing until after options are processed since that
5496 says if we run timers or not. */
5497 init_timevar ();
5498 timevar_start (TV_TOTAL);
5500 /* Set up the back-end if requested. */
5501 if (!no_backend)
5502 backend_init ();
5504 /* Language-dependent initialization. Returns true on success. */
5505 if (lang_dependent_init (filename))
5506 compile_file ();
5508 finalize ();
5510 /* Stop timing and print the times. */
5511 timevar_stop (TV_TOTAL);
5512 timevar_print (stderr);
5515 /* Entry point of cc1, cc1plus, jc1, f771, etc.
5516 Decode command args, then call compile_file.
5517 Exit code is FATAL_EXIT_CODE if can't open files or if there were
5518 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
5520 It is not safe to call this function more than once. */
5523 toplev_main (argc, argv)
5524 int argc;
5525 char **argv;
5527 /* Initialization of GCC's environment, and diagnostics. */
5528 general_init (argv[0]);
5530 /* Parse the options and do minimal processing; basically just
5531 enough to default flags appropriately. */
5532 parse_options_and_default_flags (argc, argv);
5534 /* Exit early if we can (e.g. -help). */
5535 if (!exit_after_options)
5536 do_compile ();
5538 if (errorcount || sorrycount)
5539 return (FATAL_EXIT_CODE);
5541 return (SUCCESS_EXIT_CODE);