2001-11-01 Eric Christopher <echristo@redhat.com>
[official-gcc.git] / gcc / toplev.c
blob11d19e04baa3a003c5c6262be73ee9c752d42516
1 /* Top level of GNU C compiler
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001 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 <signal.h>
32 #include <setjmp.h>
34 #ifdef HAVE_SYS_RESOURCE_H
35 # include <sys/resource.h>
36 #endif
38 #ifdef HAVE_SYS_TIMES_H
39 # include <sys/times.h>
40 #endif
42 #include "input.h"
43 #include "tree.h"
44 #include "rtl.h"
45 #include "tm_p.h"
46 #include "flags.h"
47 #include "insn-attr.h"
48 #include "insn-config.h"
49 #include "hard-reg-set.h"
50 #include "recog.h"
51 #include "output.h"
52 #include "except.h"
53 #include "function.h"
54 #include "toplev.h"
55 #include "expr.h"
56 #include "basic-block.h"
57 #include "intl.h"
58 #include "ggc.h"
59 #include "graph.h"
60 #include "loop.h"
61 #include "regs.h"
62 #include "timevar.h"
63 #include "diagnostic.h"
64 #include "ssa.h"
65 #include "params.h"
66 #include "reload.h"
67 #include "dwarf2asm.h"
68 #include "integrate.h"
69 #include "debug.h"
70 #include "target.h"
72 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
73 #include "dwarf2out.h"
74 #endif
76 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
77 #include "dbxout.h"
78 #endif
80 #ifdef SDB_DEBUGGING_INFO
81 #include "sdbout.h"
82 #endif
84 #ifdef XCOFF_DEBUGGING_INFO
85 #include "xcoffout.h" /* Needed for external data
86 declarations for e.g. AIX 4.x. */
87 #endif
89 #ifdef HALF_PIC_DEBUG
90 #include "halfpic.h"
91 #endif
93 #ifdef VMS
94 /* The extra parameters substantially improve the I/O performance. */
96 static FILE *
97 vms_fopen (fname, type)
98 char *fname;
99 char *type;
101 /* The <stdio.h> in the gcc-vms-1.42 distribution prototypes fopen with two
102 fixed arguments, which matches ANSI's specification but not VAXCRTL's
103 pre-ANSI implementation. This hack circumvents the mismatch problem. */
104 FILE *(*vmslib_fopen)() = (FILE *(*)()) fopen;
106 if (*type == 'w')
107 return (*vmslib_fopen) (fname, type, "mbc=32",
108 "deq=64", "fop=tef", "shr=nil");
109 else
110 return (*vmslib_fopen) (fname, type, "mbc=32");
113 #define fopen vms_fopen
114 #endif /* VMS */
116 #ifndef DEFAULT_GDB_EXTENSIONS
117 #define DEFAULT_GDB_EXTENSIONS 1
118 #endif
120 /* If more than one debugging type is supported, you must define
121 PREFERRED_DEBUGGING_TYPE to choose a format in a system-dependent way.
123 This is one long line cause VAXC can't handle a \-newline. */
124 #if 1 < (defined (DBX_DEBUGGING_INFO) + defined (SDB_DEBUGGING_INFO) + defined (DWARF_DEBUGGING_INFO) + defined (DWARF2_DEBUGGING_INFO) + defined (XCOFF_DEBUGGING_INFO))
125 #ifndef PREFERRED_DEBUGGING_TYPE
126 You Lose! You must define PREFERRED_DEBUGGING_TYPE!
127 #endif /* no PREFERRED_DEBUGGING_TYPE */
128 #else /* Only one debugging format supported. Define PREFERRED_DEBUGGING_TYPE
129 so the following code needn't care. */
130 #ifdef DBX_DEBUGGING_INFO
131 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
132 #endif
133 #ifdef SDB_DEBUGGING_INFO
134 #define PREFERRED_DEBUGGING_TYPE SDB_DEBUG
135 #endif
136 #ifdef DWARF_DEBUGGING_INFO
137 #define PREFERRED_DEBUGGING_TYPE DWARF_DEBUG
138 #endif
139 #ifdef DWARF2_DEBUGGING_INFO
140 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
141 #endif
142 #ifdef XCOFF_DEBUGGING_INFO
143 #define PREFERRED_DEBUGGING_TYPE XCOFF_DEBUG
144 #endif
145 #endif /* More than one debugger format enabled. */
147 /* If still not defined, must have been because no debugging formats
148 are supported. */
149 #ifndef PREFERRED_DEBUGGING_TYPE
150 #define PREFERRED_DEBUGGING_TYPE NO_DEBUG
151 #endif
153 #if defined (HAVE_DECL_ENVIRON) && !HAVE_DECL_ENVIRON
154 extern char **environ;
155 #endif
157 /* Carry information from ASM_DECLARE_OBJECT_NAME
158 to ASM_FINISH_DECLARE_OBJECT. */
160 extern int size_directive_output;
161 extern tree last_assemble_variable_decl;
163 static void set_target_switch PARAMS ((const char *));
164 static const char *decl_name PARAMS ((tree, int));
166 static void float_signal PARAMS ((int)) ATTRIBUTE_NORETURN;
167 static void crash_signal PARAMS ((int)) ATTRIBUTE_NORETURN;
168 static void set_float_handler PARAMS ((jmp_buf));
169 static void compile_file PARAMS ((const char *));
170 static void display_help PARAMS ((void));
171 static void display_target_options PARAMS ((void));
173 static void decode_d_option PARAMS ((const char *));
174 static int decode_f_option PARAMS ((const char *));
175 static int decode_W_option PARAMS ((const char *));
176 static int decode_g_option PARAMS ((const char *));
177 static unsigned int independent_decode_option PARAMS ((int, char **));
179 static void print_version PARAMS ((FILE *, const char *));
180 static int print_single_switch PARAMS ((FILE *, int, int, const char *,
181 const char *, const char *,
182 const char *, const char *));
183 static void print_switch_values PARAMS ((FILE *, int, int, const char *,
184 const char *, const char *));
186 /* Length of line when printing switch values. */
187 #define MAX_LINE 75
189 /* Name of program invoked, sans directories. */
191 const char *progname;
193 /* Copy of arguments to toplev_main. */
194 int save_argc;
195 char **save_argv;
197 /* Name of current original source file (what was input to cpp).
198 This comes from each #-command in the actual input. */
200 const char *input_filename;
202 /* Name of top-level original source file (what was input to cpp).
203 This comes from the #-command at the beginning of the actual input.
204 If there isn't any there, then this is the cc1 input file name. */
206 const char *main_input_filename;
208 /* Current line number in real source file. */
210 int lineno;
212 /* Nonzero if it is unsafe to create any new pseudo registers. */
213 int no_new_pseudos;
215 /* Stack of currently pending input files. */
217 struct file_stack *input_file_stack;
219 /* Incremented on each change to input_file_stack. */
220 int input_file_stack_tick;
222 /* Name to use as base of names for dump output files. */
224 const char *dump_base_name;
226 /* Bit flags that specify the machine subtype we are compiling for.
227 Bits are tested using macros TARGET_... defined in the tm.h file
228 and set by `-m...' switches. Must be defined in rtlanal.c. */
230 extern int target_flags;
232 /* Debug hooks - dependent upon command line options. */
234 struct gcc_debug_hooks *debug_hooks;
236 /* Describes a dump file. */
238 struct dump_file_info
240 /* The unique extension to apply, e.g. ".jump". */
241 const char *const extension;
243 /* The -d<c> character that enables this dump file. */
244 char const debug_switch;
246 /* True if there is a corresponding graph dump file. */
247 char const graph_dump_p;
249 /* True if the user selected this dump. */
250 char enabled;
252 /* True if the files have been initialized (ie truncated). */
253 char initialized;
256 /* Enumerate the extant dump files. */
258 enum dump_file_index
260 DFI_rtl,
261 DFI_sibling,
262 DFI_eh,
263 DFI_jump,
264 DFI_ssa,
265 DFI_ssa_ccp,
266 DFI_ssa_dce,
267 DFI_ussa,
268 DFI_cse,
269 DFI_addressof,
270 DFI_gcse,
271 DFI_loop,
272 DFI_cse2,
273 DFI_cfg,
274 DFI_bp,
275 DFI_life,
276 DFI_combine,
277 DFI_ce,
278 DFI_regmove,
279 DFI_sched,
280 DFI_lreg,
281 DFI_greg,
282 DFI_postreload,
283 DFI_flow2,
284 DFI_peephole2,
285 DFI_rnreg,
286 DFI_ce2,
287 DFI_sched2,
288 DFI_stack,
289 DFI_bbro,
290 DFI_mach,
291 DFI_dbr,
292 DFI_MAX
295 /* Describes all the dump files. Should be kept in order of the
296 pass and in sync with dump_file_index above.
298 Remaining -d letters:
300 " o q u "
301 " H JK OPQ TUV YZ"
304 struct dump_file_info dump_file[DFI_MAX] =
306 { "rtl", 'r', 0, 0, 0 },
307 { "sibling", 'i', 0, 0, 0 },
308 { "eh", 'h', 0, 0, 0 },
309 { "jump", 'j', 0, 0, 0 },
310 { "ssa", 'e', 1, 0, 0 },
311 { "ssaccp", 'W', 1, 0, 0 },
312 { "ssadce", 'X', 1, 0, 0 },
313 { "ussa", 'e', 1, 0, 0 }, /* Yes, duplicate enable switch. */
314 { "cse", 's', 0, 0, 0 },
315 { "addressof", 'F', 0, 0, 0 },
316 { "gcse", 'G', 1, 0, 0 },
317 { "loop", 'L', 1, 0, 0 },
318 { "cse2", 't', 1, 0, 0 },
319 { "cfg", 'f', 1, 0, 0 },
320 { "bp", 'b', 1, 0, 0 },
321 { "life", 'f', 1, 0, 0 }, /* Yes, duplicate enable switch. */
322 { "combine", 'c', 1, 0, 0 },
323 { "ce", 'C', 1, 0, 0 },
324 { "regmove", 'N', 1, 0, 0 },
325 { "sched", 'S', 1, 0, 0 },
326 { "lreg", 'l', 1, 0, 0 },
327 { "greg", 'g', 1, 0, 0 },
328 { "postreload", 'o', 1, 0, 0 },
329 { "flow2", 'w', 1, 0, 0 },
330 { "peephole2", 'z', 1, 0, 0 },
331 { "rnreg", 'n', 1, 0, 0 },
332 { "ce2", 'E', 1, 0, 0 },
333 { "sched2", 'R', 1, 0, 0 },
334 { "stack", 'k', 1, 0, 0 },
335 { "bbro", 'B', 1, 0, 0 },
336 { "mach", 'M', 1, 0, 0 },
337 { "dbr", 'd', 0, 0, 0 },
340 static int open_dump_file PARAMS ((enum dump_file_index, tree));
341 static void close_dump_file PARAMS ((enum dump_file_index,
342 void (*) (FILE *, rtx), rtx));
344 /* Other flags saying which kinds of debugging dump have been requested. */
346 int rtl_dump_and_exit;
347 int flag_print_asm_name;
348 static int version_flag;
349 static char *filename;
350 enum graph_dump_types graph_dump_format;
352 /* Name for output file of assembly code, specified with -o. */
354 char *asm_file_name;
356 /* Value of the -G xx switch, and whether it was passed or not. */
357 int g_switch_value;
358 int g_switch_set;
360 /* Type(s) of debugging information we are producing (if any).
361 See flags.h for the definitions of the different possible
362 types of debugging information. */
363 enum debug_info_type write_symbols = NO_DEBUG;
365 /* Level of debugging information we are producing. See flags.h
366 for the definitions of the different possible levels. */
367 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
369 /* Nonzero means use GNU-only extensions in the generated symbolic
370 debugging information. */
371 /* Currently, this only has an effect when write_symbols is set to
372 DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
373 int use_gnu_debug_info_extensions = 0;
375 /* Nonzero means do optimizations. -O.
376 Particular numeric values stand for particular amounts of optimization;
377 thus, -O2 stores 2 here. However, the optimizations beyond the basic
378 ones are not controlled directly by this variable. Instead, they are
379 controlled by individual `flag_...' variables that are defaulted
380 based on this variable. */
382 int optimize = 0;
384 /* Nonzero means optimize for size. -Os.
385 The only valid values are zero and non-zero. When optimize_size is
386 non-zero, optimize defaults to 2, but certain individual code
387 bloating optimizations are disabled. */
389 int optimize_size = 0;
391 /* Nonzero if we should exit after parsing options. */
392 static int exit_after_options = 0;
394 /* The FUNCTION_DECL for the function currently being compiled,
395 or 0 if between functions. */
396 tree current_function_decl;
398 /* Set to the FUNC_BEGIN label of the current function, or NULL_TREE
399 if none. */
400 tree current_function_func_begin_label;
402 /* Pointer to function to compute the name to use to print a declaration.
403 DECL is the declaration in question.
404 VERBOSITY determines what information will be printed:
405 0: DECL_NAME, demangled as necessary.
406 1: and scope information.
407 2: and any other information that might be interesting, such as function
408 parameter types in C++. */
410 const char *(*decl_printable_name) PARAMS ((tree, int));
412 /* Pointer to function to compute rtl for a language-specific tree code. */
414 typedef rtx (*lang_expand_expr_t)
415 PARAMS ((union tree_node *, rtx, enum machine_mode,
416 enum expand_modifier modifier));
418 lang_expand_expr_t lang_expand_expr = 0;
420 tree (*lang_expand_constant) PARAMS ((tree)) = 0;
422 /* Pointer to function to finish handling an incomplete decl at the
423 end of compilation. */
425 void (*incomplete_decl_finalize_hook) PARAMS ((tree)) = 0;
427 /* Nonzero if doing dwarf2 duplicate elimination. */
429 int flag_eliminate_dwarf2_dups = 0;
431 /* Nonzero if generating code to do profiling. */
433 int profile_flag = 0;
435 /* Nonzero if generating code to do profiling on a line-by-line basis. */
437 int profile_block_flag;
439 /* Nonzero if generating code to profile program flow graph arcs. */
441 int profile_arc_flag = 0;
443 /* Nonzero if generating info for gcov to calculate line test coverage. */
445 int flag_test_coverage = 0;
447 /* Nonzero indicates that branch taken probabilities should be calculated. */
449 int flag_branch_probabilities = 0;
451 /* Nonzero if basic blocks should be reordered. */
453 int flag_reorder_blocks = 0;
455 /* Nonzero if registers should be renamed. */
457 int flag_rename_registers = 0;
459 /* Nonzero for -pedantic switch: warn about anything
460 that standard spec forbids. */
462 int pedantic = 0;
464 /* Temporarily suppress certain warnings.
465 This is set while reading code from a system header file. */
467 int in_system_header = 0;
469 /* Don't print functions as they are compiled. -quiet. */
471 int quiet_flag = 0;
473 /* Print times taken by the various passes. -ftime-report. */
475 int time_report = 0;
477 /* Print memory still in use at end of compilation (which may have little
478 to do with peak memory consumption). -fmem-report. */
480 int mem_report = 0;
482 /* Non-zero means to collect statistics which might be expensive
483 and to print them when we are done. */
484 int flag_detailed_statistics = 0;
487 /* -f flags. */
489 /* Nonzero means `char' should be signed. */
491 int flag_signed_char;
493 /* Nonzero means give an enum type only as many bytes as it needs. */
495 int flag_short_enums;
497 /* Nonzero for -fcaller-saves: allocate values in regs that need to
498 be saved across function calls, if that produces overall better code.
499 Optional now, so people can test it. */
501 #ifdef DEFAULT_CALLER_SAVES
502 int flag_caller_saves = 1;
503 #else
504 int flag_caller_saves = 0;
505 #endif
507 /* Nonzero if structures and unions should be returned in memory.
509 This should only be defined if compatibility with another compiler or
510 with an ABI is needed, because it results in slower code. */
512 #ifndef DEFAULT_PCC_STRUCT_RETURN
513 #define DEFAULT_PCC_STRUCT_RETURN 1
514 #endif
516 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
518 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
520 /* Nonzero for -fforce-mem: load memory value into a register
521 before arithmetic on it. This makes better cse but slower compilation. */
523 int flag_force_mem = 0;
525 /* Nonzero for -fforce-addr: load memory address into a register before
526 reference to memory. This makes better cse but slower compilation. */
528 int flag_force_addr = 0;
530 /* Nonzero for -fdefer-pop: don't pop args after each function call;
531 instead save them up to pop many calls' args with one insns. */
533 int flag_defer_pop = 0;
535 /* Nonzero for -ffloat-store: don't allocate floats and doubles
536 in extended-precision registers. */
538 int flag_float_store = 0;
540 /* Nonzero for -fcse-follow-jumps:
541 have cse follow jumps to do a more extensive job. */
543 int flag_cse_follow_jumps;
545 /* Nonzero for -fcse-skip-blocks:
546 have cse follow a branch around a block. */
547 int flag_cse_skip_blocks;
549 /* Nonzero for -fexpensive-optimizations:
550 perform miscellaneous relatively-expensive optimizations. */
551 int flag_expensive_optimizations;
553 /* Nonzero for -fthread-jumps:
554 have jump optimize output of loop. */
556 int flag_thread_jumps;
558 /* Nonzero enables strength-reduction in loop.c. */
560 int flag_strength_reduce = 0;
562 /* Nonzero enables loop unrolling in unroll.c. Only loops for which the
563 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
564 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
565 unrolled. */
567 int flag_unroll_loops;
569 /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
570 This is generally not a win. */
572 int flag_unroll_all_loops;
574 /* Nonzero forces all invariant computations in loops to be moved
575 outside the loop. */
577 int flag_move_all_movables = 0;
579 /* Nonzero forces all general induction variables in loops to be
580 strength reduced. */
582 int flag_reduce_all_givs = 0;
584 /* Nonzero to perform full register move optimization passes. This is the
585 default for -O2. */
587 int flag_regmove = 0;
589 /* Nonzero for -fwritable-strings:
590 store string constants in data segment and don't uniquize them. */
592 int flag_writable_strings = 0;
594 /* Nonzero means don't put addresses of constant functions in registers.
595 Used for compiling the Unix kernel, where strange substitutions are
596 done on the assembly output. */
598 int flag_no_function_cse = 0;
600 /* Nonzero for -fomit-frame-pointer:
601 don't make a frame pointer in simple functions that don't require one. */
603 int flag_omit_frame_pointer = 0;
605 /* Nonzero means place each function into its own section on those platforms
606 which support arbitrary section names and unlimited numbers of sections. */
608 int flag_function_sections = 0;
610 /* ... and similar for data. */
612 int flag_data_sections = 0;
614 /* Nonzero to inhibit use of define_optimization peephole opts. */
616 int flag_no_peephole = 0;
618 /* Nonzero allows GCC to optimize sibling and tail recursive calls. */
620 int flag_optimize_sibling_calls = 0;
622 /* Nonzero means the front end generally wants `errno' maintained by math
623 operations, like built-in SQRT. */
625 int flag_errno_math = 1;
627 /* Nonzero means that unsafe floating-point math optimizations are allowed
628 for the sake of speed. IEEE compliance is not guaranteed, and operations
629 are allowed to assume that their arguments and results are "normal"
630 (e.g., nonnegative for SQRT). */
632 int flag_unsafe_math_optimizations = 0;
634 /* Zero means that floating-point math operations cannot generate a
635 (user-visible) trap. This is the case, for example, in nonstop
636 IEEE 754 arithmetic. */
638 int flag_trapping_math = 1;
640 /* 0 means straightforward implementation of complex divide acceptable.
641 1 means wide ranges of inputs must work for complex divide.
642 2 means C99-like requirements for complex divide (not yet implemented). */
644 int flag_complex_divide_method = 0;
646 /* Nonzero means all references through pointers are volatile. */
648 int flag_volatile;
650 /* Nonzero means treat all global and extern variables as volatile. */
652 int flag_volatile_global;
654 /* Nonzero means treat all static variables as volatile. */
656 int flag_volatile_static;
658 /* Nonzero means just do syntax checking; don't output anything. */
660 int flag_syntax_only = 0;
662 /* Nonzero means perform global cse. */
664 static int flag_gcse;
666 /* Nonzero means to use global dataflow analysis to eliminate
667 useless null pointer tests. */
669 static int flag_delete_null_pointer_checks;
671 /* Nonzero means to do the enhanced load motion during gcse, which trys
672 to hoist loads by not killing them when a store to the same location
673 is seen. */
675 int flag_gcse_lm = 1;
677 /* Nonzero means to perform store motion after gcse, which will try to
678 move stores closer to the exit block. Its not very effective without
679 flag_gcse_lm. */
681 int flag_gcse_sm = 1;
683 /* Nonzero means to rerun cse after loop optimization. This increases
684 compilation time about 20% and picks up a few more common expressions. */
686 static int flag_rerun_cse_after_loop;
688 /* Nonzero means to run loop optimizations twice. */
690 int flag_rerun_loop_opt;
692 /* Nonzero for -finline-functions: ok to inline functions that look like
693 good inline candidates. */
695 int flag_inline_functions;
697 /* Nonzero for -fkeep-inline-functions: even if we make a function
698 go inline everywhere, keep its definition around for debugging
699 purposes. */
701 int flag_keep_inline_functions;
703 /* Nonzero means that functions will not be inlined. */
705 int flag_no_inline;
707 /* Nonzero means that we should emit static const variables
708 regardless of whether or not optimization is turned on. */
710 int flag_keep_static_consts = 1;
712 /* Nonzero means we should be saving declaration info into a .X file. */
714 int flag_gen_aux_info = 0;
716 /* Specified name of aux-info file. */
718 static char *aux_info_file_name;
720 /* Nonzero means make the text shared if supported. */
722 int flag_shared_data;
724 /* Nonzero means schedule into delayed branch slots if supported. */
726 int flag_delayed_branch;
728 /* Nonzero if we are compiling pure (sharable) code.
729 Value is 1 if we are doing reasonable (i.e. simple
730 offset into offset table) pic. Value is 2 if we can
731 only perform register offsets. */
733 int flag_pic;
735 /* Nonzero means generate extra code for exception handling and enable
736 exception handling. */
738 int flag_exceptions;
740 /* Nonzero means generate frame unwind info table when supported. */
742 int flag_unwind_tables = 0;
744 /* Nonzero means generate frame unwind info table exact at each insn boundary */
746 int flag_asynchronous_unwind_tables = 0;
748 /* Nonzero means don't place uninitialized global data in common storage
749 by default. */
751 int flag_no_common;
753 /* Nonzero means pretend it is OK to examine bits of target floats,
754 even if that isn't true. The resulting code will have incorrect constants,
755 but the same series of instructions that the native compiler would make. */
757 int flag_pretend_float;
759 /* Nonzero means change certain warnings into errors.
760 Usually these are warnings about failure to conform to some standard. */
762 int flag_pedantic_errors = 0;
764 /* flag_schedule_insns means schedule insns within basic blocks (before
765 local_alloc).
766 flag_schedule_insns_after_reload means schedule insns after
767 global_alloc. */
769 int flag_schedule_insns = 0;
770 int flag_schedule_insns_after_reload = 0;
772 /* The following flags have effect only for scheduling before register
773 allocation:
775 flag_schedule_interblock means schedule insns accross basic blocks.
776 flag_schedule_speculative means allow speculative motion of non-load insns.
777 flag_schedule_speculative_load means allow speculative motion of some
778 load insns.
779 flag_schedule_speculative_load_dangerous allows speculative motion of more
780 load insns. */
782 int flag_schedule_interblock = 1;
783 int flag_schedule_speculative = 1;
784 int flag_schedule_speculative_load = 0;
785 int flag_schedule_speculative_load_dangerous = 0;
787 int flag_single_precision_constant;
789 /* flag_branch_on_count_reg means try to replace add-1,compare,branch tupple
790 by a cheaper branch on a count register. */
791 int flag_branch_on_count_reg = 1;
793 /* -finhibit-size-directive inhibits output of .size for ELF.
794 This is used only for compiling crtstuff.c,
795 and it may be extended to other effects
796 needed for crtstuff.c on other systems. */
797 int flag_inhibit_size_directive = 0;
799 /* -fverbose-asm causes extra commentary information to be produced in
800 the generated assembly code (to make it more readable). This option
801 is generally only of use to those who actually need to read the
802 generated assembly code (perhaps while debugging the compiler itself).
803 -fno-verbose-asm, the default, causes the extra information
804 to be omitted and is useful when comparing two assembler files. */
806 int flag_verbose_asm = 0;
808 /* -dA causes debug commentary information to be produced in
809 the generated assembly code (to make it more readable). This option
810 is generally only of use to those who actually need to read the
811 generated assembly code (perhaps while debugging the compiler itself).
812 Currently, this switch is only used by dwarfout.c; however, it is intended
813 to be a catchall for printing debug information in the assembler file. */
815 int flag_debug_asm = 0;
817 /* -dP causes the rtl to be emitted as a comment in assembly. */
819 int flag_dump_rtl_in_asm = 0;
821 /* -fgnu-linker specifies use of the GNU linker for initializations.
822 (Or, more generally, a linker that handles initializations.)
823 -fno-gnu-linker says that collect2 will be used. */
824 #ifdef USE_COLLECT2
825 int flag_gnu_linker = 0;
826 #else
827 int flag_gnu_linker = 1;
828 #endif
830 /* Enable SSA. */
831 int flag_ssa = 0;
833 /* Enable ssa conditional constant propagation. */
834 int flag_ssa_ccp = 0;
836 /* Enable ssa aggressive dead code elimination. */
837 int flag_ssa_dce = 0;
839 /* Tag all structures with __attribute__(packed). */
840 int flag_pack_struct = 0;
842 /* Emit code to check for stack overflow; also may cause large objects
843 to be allocated dynamically. */
844 int flag_stack_check;
846 /* When non-NULL, indicates that whenever space is allocated on the
847 stack, the resulting stack pointer must not pass this
848 address---that is, for stacks that grow downward, the stack pointer
849 must always be greater than or equal to this address; for stacks
850 that grow upward, the stack pointer must be less than this address.
851 At present, the rtx may be either a REG or a SYMBOL_REF, although
852 the support provided depends on the backend. */
853 rtx stack_limit_rtx;
855 /* -fcheck-memory-usage causes extra code to be generated in order to check
856 memory accesses. This is used by a detector of bad memory accesses such
857 as Checker. */
858 int flag_check_memory_usage = 0;
860 /* -fprefix-function-name causes function name to be prefixed. This
861 can be used with -fcheck-memory-usage to isolate code compiled with
862 -fcheck-memory-usage. */
863 int flag_prefix_function_name = 0;
865 /* 0 if pointer arguments may alias each other. True in C.
866 1 if pointer arguments may not alias each other but may alias
867 global variables.
868 2 if pointer arguments may not alias each other and may not
869 alias global variables. True in Fortran.
870 This defaults to 0 for C. */
871 int flag_argument_noalias = 0;
873 /* Nonzero if we should do (language-dependent) alias analysis.
874 Typically, this analysis will assume that expressions of certain
875 types do not alias expressions of certain other types. Only used
876 if alias analysis (in general) is enabled. */
877 int flag_strict_aliasing = 0;
879 /* Instrument functions with calls at entry and exit, for profiling. */
880 int flag_instrument_function_entry_exit = 0;
882 /* Nonzero means ignore `#ident' directives. 0 means handle them.
883 On SVR4 targets, it also controls whether or not to emit a
884 string identifying the compiler. */
886 int flag_no_ident = 0;
888 /* This will perform a peephole pass before sched2. */
889 int flag_peephole2 = 0;
891 /* This will try to guess branch probabilities. */
892 int flag_guess_branch_prob = 0;
894 /* -fbounded-pointers causes gcc to compile pointers as composite
895 objects occupying three words: the pointer value, the base address
896 of the referent object, and the address immediately beyond the end
897 of the referent object. The base and extent allow us to perform
898 runtime bounds checking. -fbounded-pointers implies -fcheck-bounds. */
899 int flag_bounded_pointers = 0;
901 /* -fcheck-bounds causes gcc to generate array bounds checks.
902 For C, C++: defaults to value of flag_bounded_pointers.
903 For ObjC: defaults to off.
904 For Java: defaults to on.
905 For Fortran: defaults to off.
906 For CHILL: defaults to off. */
907 int flag_bounds_check = 0;
909 /* This will attempt to merge constant section constants, if 1 only
910 string constants and constants from constant pool, if 2 also constant
911 variables. */
912 int flag_merge_constants = 1;
914 /* If one, renumber instruction UIDs to reduce the number of
915 unused UIDs if there are a lot of instructions. If greater than
916 one, unconditionally renumber instruction UIDs. */
917 int flag_renumber_insns = 1;
919 /* Values of the -falign-* flags: how much to align labels in code.
920 0 means `use default', 1 means `don't align'.
921 For each variable, there is an _log variant which is the power
922 of two not less than the variable, for .align output. */
924 int align_loops;
925 int align_loops_log;
926 int align_jumps;
927 int align_jumps_log;
928 int align_labels;
929 int align_labels_log;
930 int align_functions;
931 int align_functions_log;
933 /* Table of supported debugging formats. */
934 static const struct
936 const char *const arg;
937 /* Since PREFERRED_DEBUGGING_TYPE isn't necessarily a
938 constant expression, we use NO_DEBUG in its place. */
939 const enum debug_info_type debug_type;
940 const int use_extensions_p;
941 const char *const description;
942 } *da,
943 debug_args[] =
945 { "", NO_DEBUG, DEFAULT_GDB_EXTENSIONS,
946 N_("Generate debugging info in default format") },
947 { "gdb", NO_DEBUG, 1, N_("Generate debugging info in default extended format") },
948 #ifdef DBX_DEBUGGING_INFO
949 { "stabs", DBX_DEBUG, 0, N_("Generate STABS format debug info") },
950 { "stabs+", DBX_DEBUG, 1, N_("Generate extended STABS format debug info") },
951 #endif
952 #ifdef DWARF_DEBUGGING_INFO
953 { "dwarf", DWARF_DEBUG, 0, N_("Generate DWARF-1 format debug info") },
954 { "dwarf+", DWARF_DEBUG, 1,
955 N_("Generate extended DWARF-1 format debug info") },
956 #endif
957 #ifdef DWARF2_DEBUGGING_INFO
958 { "dwarf-2", DWARF2_DEBUG, 0, N_("Generate DWARF-2 debug info") },
959 #endif
960 #ifdef XCOFF_DEBUGGING_INFO
961 { "xcoff", XCOFF_DEBUG, 0, N_("Generate XCOFF format debug info") },
962 { "xcoff+", XCOFF_DEBUG, 1, N_("Generate extended XCOFF format debug info") },
963 #endif
964 #ifdef SDB_DEBUGGING_INFO
965 { "coff", SDB_DEBUG, 0, N_("Generate COFF format debug info") },
966 #endif
967 { 0, 0, 0, 0 }
970 typedef struct
972 const char *string;
973 int *variable;
974 int on_value;
975 const char *description;
977 lang_independent_options;
979 int flag_trapv = 0;
981 /* Add or remove a leading underscore from user symbols. */
982 int flag_leading_underscore = -1;
984 /* The user symbol prefix after having resolved same. */
985 const char *user_label_prefix;
987 static const param_info lang_independent_params[] = {
988 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT) \
989 { OPTION, DEFAULT, HELP },
990 #include "params.def"
991 #undef DEFPARAM
992 { NULL, 0, NULL }
995 /* A default for same. */
996 #ifndef USER_LABEL_PREFIX
997 #define USER_LABEL_PREFIX ""
998 #endif
1000 /* Table of language-independent -f options.
1001 STRING is the option name. VARIABLE is the address of the variable.
1002 ON_VALUE is the value to store in VARIABLE
1003 if `-fSTRING' is seen as an option.
1004 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
1006 lang_independent_options f_options[] =
1008 {"eliminate-dwarf2-dups", &flag_eliminate_dwarf2_dups, 1,
1009 N_("Perform DWARF2 duplicate elimination") },
1010 {"float-store", &flag_float_store, 1,
1011 N_("Do not store floats in registers") },
1012 {"volatile", &flag_volatile, 1,
1013 N_("Consider all mem refs through pointers as volatile") },
1014 {"volatile-global", &flag_volatile_global, 1,
1015 N_("Consider all mem refs to global data to be volatile") },
1016 {"volatile-static", &flag_volatile_static, 1,
1017 N_("Consider all mem refs to static data to be volatile") },
1018 {"defer-pop", &flag_defer_pop, 1,
1019 N_("Defer popping functions args from stack until later") },
1020 {"omit-frame-pointer", &flag_omit_frame_pointer, 1,
1021 N_("When possible do not generate stack frames") },
1022 {"optimize-sibling-calls", &flag_optimize_sibling_calls, 1,
1023 N_("Optimize sibling and tail recursive calls") },
1024 {"cse-follow-jumps", &flag_cse_follow_jumps, 1,
1025 N_("When running CSE, follow jumps to their targets") },
1026 {"cse-skip-blocks", &flag_cse_skip_blocks, 1,
1027 N_("When running CSE, follow conditional jumps") },
1028 {"expensive-optimizations", &flag_expensive_optimizations, 1,
1029 N_("Perform a number of minor, expensive optimisations") },
1030 {"thread-jumps", &flag_thread_jumps, 1,
1031 N_("Perform jump threading optimisations") },
1032 {"strength-reduce", &flag_strength_reduce, 1,
1033 N_("Perform strength reduction optimisations") },
1034 {"unroll-loops", &flag_unroll_loops, 1,
1035 N_("Perform loop unrolling when iteration count is known") },
1036 {"unroll-all-loops", &flag_unroll_all_loops, 1,
1037 N_("Perform loop unrolling for all 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 optimisations") },
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 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1,
1079 N_("Run CSE pass after loop optimisations") },
1080 {"rerun-loop-opt", &flag_rerun_loop_opt, 1,
1081 N_("Run the loop optimiser twice") },
1082 {"delete-null-pointer-checks", &flag_delete_null_pointer_checks, 1,
1083 N_("Delete useless null pointer checks") },
1084 {"pretend-float", &flag_pretend_float, 1,
1085 N_("Pretend that host and target use the same FP format") },
1086 {"schedule-insns", &flag_schedule_insns, 1,
1087 N_("Reschedule instructions before register allocation") },
1088 {"schedule-insns2", &flag_schedule_insns_after_reload, 1,
1089 N_("Reschedule instructions after register allocation") },
1090 {"sched-interblock",&flag_schedule_interblock, 1,
1091 N_("Enable scheduling across basic blocks") },
1092 {"sched-spec",&flag_schedule_speculative, 1,
1093 N_("Allow speculative motion of non-loads") },
1094 {"sched-spec-load",&flag_schedule_speculative_load, 1,
1095 N_("Allow speculative motion of some loads") },
1096 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1,
1097 N_("Allow speculative motion of more loads") },
1098 {"branch-count-reg",&flag_branch_on_count_reg, 1,
1099 N_("Replace add,compare,branch with branch on count reg") },
1100 {"pic", &flag_pic, 1,
1101 N_("Generate position independent code, if possible") },
1102 {"PIC", &flag_pic, 2, ""},
1103 {"exceptions", &flag_exceptions, 1,
1104 N_("Enable exception handling") },
1105 {"unwind-tables", &flag_unwind_tables, 1,
1106 N_("Just generate unwind tables for exception handling") },
1107 {"asynchronous-unwind-tables", &flag_asynchronous_unwind_tables, 1,
1108 N_("Generate unwind tables exact at each instruction boundary") },
1109 {"non-call-exceptions", &flag_non_call_exceptions, 1,
1110 N_("Support synchronous non-call exceptions") },
1111 {"profile-arcs", &profile_arc_flag, 1,
1112 N_("Insert arc based program profiling code") },
1113 {"test-coverage", &flag_test_coverage, 1,
1114 N_("Create data files needed by gcov") },
1115 {"branch-probabilities", &flag_branch_probabilities, 1,
1116 N_("Use profiling information for branch probabilities") },
1117 {"reorder-blocks", &flag_reorder_blocks, 1,
1118 N_("Reorder basic blocks to improve code placement") },
1119 {"rename-registers", &flag_rename_registers, 1,
1120 N_("Do the register renaming optimization pass") },
1121 {"common", &flag_no_common, 0,
1122 N_("Do not put uninitialized globals in the common section") },
1123 {"inhibit-size-directive", &flag_inhibit_size_directive, 1,
1124 N_("Do not generate .size directives") },
1125 {"function-sections", &flag_function_sections, 1,
1126 N_("place each function into its own section") },
1127 {"data-sections", &flag_data_sections, 1,
1128 N_("place data items into their own section") },
1129 {"verbose-asm", &flag_verbose_asm, 1,
1130 N_("Add extra commentry to assembler output") },
1131 {"gnu-linker", &flag_gnu_linker, 1,
1132 N_("Output GNU ld formatted global initialisers") },
1133 {"regmove", &flag_regmove, 1,
1134 N_("Enables a register move optimisation") },
1135 {"optimize-register-move", &flag_regmove, 1,
1136 N_("Do the full regmove optimization pass") },
1137 {"pack-struct", &flag_pack_struct, 1,
1138 N_("Pack structure members together without holes") },
1139 {"stack-check", &flag_stack_check, 1,
1140 N_("Insert stack checking code into the program") },
1141 {"argument-alias", &flag_argument_noalias, 0,
1142 N_("Specify that arguments may alias each other & globals") },
1143 {"argument-noalias", &flag_argument_noalias, 1,
1144 N_("Assume arguments may alias globals but not each other") },
1145 {"argument-noalias-global", &flag_argument_noalias, 2,
1146 N_("Assume arguments do not alias each other or globals") },
1147 {"strict-aliasing", &flag_strict_aliasing, 1,
1148 N_("Assume strict aliasing rules apply") },
1149 {"align-loops", &align_loops, 0,
1150 N_("Align the start of loops") },
1151 {"align-jumps", &align_jumps, 0,
1152 N_("Align labels which are only reached by jumping") },
1153 {"align-labels", &align_labels, 0,
1154 N_("Align all labels") },
1155 {"align-functions", &align_functions, 0,
1156 N_("Align the start of functions") },
1157 {"merge-constants", &flag_merge_constants, 1,
1158 N_("Attempt to merge identical constants accross compilation units") },
1159 {"merge-all-constants", &flag_merge_constants, 2,
1160 N_("Attempt to merge identical constants and constant variables") },
1161 {"check-memory-usage", &flag_check_memory_usage, 1,
1162 N_("Generate code to check every memory access") },
1163 {"prefix-function-name", &flag_prefix_function_name, 1,
1164 N_("Add a prefix to all function names") },
1165 {"dump-unnumbered", &flag_dump_unnumbered, 1,
1166 N_("Suppress output of instruction numbers and line number notes in debugging dumps") },
1167 {"instrument-functions", &flag_instrument_function_entry_exit, 1,
1168 N_("Instrument function entry/exit with profiling calls") },
1169 {"ssa", &flag_ssa, 1,
1170 N_("Enable SSA optimizations") },
1171 {"ssa-ccp", &flag_ssa_ccp, 1,
1172 N_("Enable SSA conditonal constant propagation") },
1173 {"ssa-dce", &flag_ssa_dce, 1,
1174 N_("Enable aggressive SSA dead code elimination") },
1175 {"leading-underscore", &flag_leading_underscore, 1,
1176 N_("External symbols have a leading underscore") },
1177 {"ident", &flag_no_ident, 0,
1178 N_("Process #ident directives") },
1179 { "peephole2", &flag_peephole2, 1,
1180 N_("Enables an rtl peephole pass run before sched2") },
1181 { "guess-branch-probability", &flag_guess_branch_prob, 1,
1182 N_("Enables guessing of branch probabilities") },
1183 {"math-errno", &flag_errno_math, 1,
1184 N_("Set errno after built-in math functions") },
1185 {"trapping-math", &flag_trapping_math, 1,
1186 N_("Floating-point operations can trap") },
1187 {"unsafe-math-optimizations", &flag_unsafe_math_optimizations, 1,
1188 N_("Allow math optimizations that may violate IEEE or ANSI standards") },
1189 {"bounded-pointers", &flag_bounded_pointers, 1,
1190 N_("Compile pointers as triples: value, base & end") },
1191 {"bounds-check", &flag_bounds_check, 1,
1192 N_("Generate code to check bounds before dereferencing pointers and arrays") },
1193 {"single-precision-constant", &flag_single_precision_constant, 1,
1194 N_("Convert floating point constant to single precision constant") },
1195 {"time-report", &time_report, 1,
1196 N_("Report time taken by each compiler pass at end of run") },
1197 {"mem-report", &mem_report, 1,
1198 N_("Report on permanent memory allocation at end of run") },
1199 { "trapv", &flag_trapv, 1,
1200 N_("Trap for signed overflow in addition / subtraction / multiplication.") },
1203 /* Table of language-specific options. */
1205 static const struct lang_opt
1207 const char *const option;
1208 const char *const description;
1210 documented_lang_options[] =
1212 /* In order not to overload the --help output, the convention
1213 used here is to only describe those options which are not
1214 enabled by default. */
1216 { "-ansi",
1217 N_("Compile just for ISO C89") },
1218 { "-fallow-single-precision",
1219 N_("Do not promote floats to double if using -traditional") },
1220 { "-std= ",
1221 N_("Determine language standard") },
1223 { "-fsigned-bitfields", "" },
1224 { "-funsigned-bitfields",
1225 N_("Make bitfields by unsigned by default") },
1226 { "-fno-signed-bitfields", "" },
1227 { "-fno-unsigned-bitfields","" },
1228 { "-fsigned-char",
1229 N_("Make 'char' be signed by default") },
1230 { "-funsigned-char",
1231 N_("Make 'char' be unsigned by default") },
1232 { "-fno-signed-char", "" },
1233 { "-fno-unsigned-char", "" },
1235 { "-ftraditional", "" },
1236 { "-traditional",
1237 N_("Attempt to support traditional K&R style C") },
1238 { "-fnotraditional", "" },
1239 { "-fno-traditional", "" },
1241 { "-fasm", "" },
1242 { "-fno-asm",
1243 N_("Do not recognise the 'asm' keyword") },
1244 { "-fbuiltin", "" },
1245 { "-fno-builtin",
1246 N_("Do not recognise any built in functions") },
1247 { "-fhosted",
1248 N_("Assume normal C execution environment") },
1249 { "-fno-hosted", "" },
1250 { "-ffreestanding",
1251 N_("Assume that standard libraries & main might not exist") },
1252 { "-fno-freestanding", "" },
1253 { "-fcond-mismatch",
1254 N_("Allow different types as args of ? operator") },
1255 { "-fno-cond-mismatch", "" },
1256 { "-fdollars-in-identifiers",
1257 N_("Allow the use of $ inside identifiers") },
1258 { "-fno-dollars-in-identifiers", "" },
1259 { "-fpreprocessed", "" },
1260 { "-fno-preprocessed", "" },
1261 { "-fshort-double",
1262 N_("Use the same size for double as for float") },
1263 { "-fno-short-double", "" },
1264 { "-fshort-enums",
1265 N_("Use the smallest fitting integer to hold enums") },
1266 { "-fno-short-enums", "" },
1267 { "-fshort-wchar",
1268 N_("Override the underlying type for wchar_t to `unsigned short'") },
1269 { "-fno-short-wchar", "" },
1271 { "-Wall",
1272 N_("Enable most warning messages") },
1273 { "-Wbad-function-cast",
1274 N_("Warn about casting functions to incompatible types") },
1275 { "-Wno-bad-function-cast", "" },
1276 { "-Wno-missing-noreturn", "" },
1277 { "-Wmissing-format-attribute",
1278 N_("Warn about functions which might be candidates for format attributes") },
1279 { "-Wno-missing-format-attribute", "" },
1280 { "-Wcast-qual",
1281 N_("Warn about casts which discard qualifiers") },
1282 { "-Wno-cast-qual", "" },
1283 { "-Wchar-subscripts",
1284 N_("Warn about subscripts whose type is 'char'") },
1285 { "-Wno-char-subscripts", "" },
1286 { "-Wcomment",
1287 N_("Warn if nested comments are detected") },
1288 { "-Wno-comment", "" },
1289 { "-Wcomments",
1290 N_("Warn if nested comments are detected") },
1291 { "-Wno-comments", "" },
1292 { "-Wconversion",
1293 N_("Warn about possibly confusing type conversions") },
1294 { "-Wno-conversion", "" },
1295 { "-Wformat",
1296 N_("Warn about printf/scanf/strftime/strfmon format anomalies") },
1297 { "-Wno-format", "" },
1298 { "-Wformat-y2k", "" },
1299 { "-Wno-format-y2k",
1300 N_("Don't warn about strftime formats yielding 2 digit years") },
1301 { "-Wformat-extra-args", "" },
1302 { "-Wno-format-extra-args",
1303 N_("Don't warn about too many arguments to format functions") },
1304 { "-Wformat-nonliteral",
1305 N_("Warn about non-string-literal format strings") },
1306 { "-Wno-format-nonliteral", "" },
1307 { "-Wformat-security",
1308 N_("Warn about possible security problems with format functions") },
1309 { "-Wno-format-security", "" },
1310 { "-Wimplicit-function-declaration",
1311 N_("Warn about implicit function declarations") },
1312 { "-Wno-implicit-function-declaration", "" },
1313 { "-Werror-implicit-function-declaration", "" },
1314 { "-Wimplicit-int",
1315 N_("Warn when a declaration does not specify a type") },
1316 { "-Wno-implicit-int", "" },
1317 { "-Wimplicit", "" },
1318 { "-Wno-implicit", "" },
1319 { "-Wimport",
1320 N_("Warn about the use of the #import directive") },
1321 { "-Wno-import", "" },
1322 { "-Wlong-long","" },
1323 { "-Wno-long-long",
1324 N_("Do not warn about using 'long long' when -pedantic") },
1325 { "-Wmain",
1326 N_("Warn about suspicious declarations of main") },
1327 { "-Wno-main", "" },
1328 { "-Wmissing-braces",
1329 N_("Warn about possibly missing braces around initialisers") },
1330 { "-Wno-missing-braces", "" },
1331 { "-Wmissing-declarations",
1332 N_("Warn about global funcs without previous declarations") },
1333 { "-Wno-missing-declarations", "" },
1334 { "-Wmissing-prototypes",
1335 N_("Warn about global funcs without prototypes") },
1336 { "-Wno-missing-prototypes", "" },
1337 { "-Wmultichar",
1338 N_("Warn about use of multicharacter literals") },
1339 { "-Wno-multichar", "" },
1340 { "-Wnested-externs",
1341 N_("Warn about externs not at file scope level") },
1342 { "-Wno-nested-externs", "" },
1343 { "-Wparentheses",
1344 N_("Warn about possible missing parentheses") },
1345 { "-Wno-parentheses", "" },
1346 { "-Wsequence-point",
1347 N_("Warn about possible violations of sequence point rules") },
1348 { "-Wno-sequence-point", "" },
1349 { "-Wpointer-arith",
1350 N_("Warn about function pointer arithmetic") },
1351 { "-Wno-pointer-arith", "" },
1352 { "-Wredundant-decls",
1353 N_("Warn about multiple declarations of the same object") },
1354 { "-Wno-redundant-decls", "" },
1355 { "-Wsign-compare",
1356 N_("Warn about signed/unsigned comparisons") },
1357 { "-Wno-sign-compare", "" },
1358 { "-Wfloat-equal",
1359 N_("Warn about testing equality of floating point numbers") },
1360 { "-Wno-float-equal", "" },
1361 { "-Wunknown-pragmas",
1362 N_("Warn about unrecognized pragmas") },
1363 { "-Wno-unknown-pragmas", "" },
1364 { "-Wstrict-prototypes",
1365 N_("Warn about non-prototyped function decls") },
1366 { "-Wno-strict-prototypes", "" },
1367 { "-Wtraditional",
1368 N_("Warn about constructs whose meaning change in ISO C") },
1369 { "-Wno-traditional", "" },
1370 { "-Wtrigraphs",
1371 N_("Warn when trigraphs are encountered") },
1372 { "-Wno-trigraphs", "" },
1373 { "-Wundef", "" },
1374 { "-Wno-undef", "" },
1375 { "-Wwrite-strings",
1376 N_("Mark strings as 'const char *'") },
1377 { "-Wno-write-strings", "" },
1379 #define DEFINE_LANG_NAME(NAME) { NULL, NAME },
1381 #include "options.h"
1385 /* Here is a table, controlled by the tm.h file, listing each -m switch
1386 and which bits in `target_switches' it should set or clear.
1387 If VALUE is positive, it is bits to set.
1388 If VALUE is negative, -VALUE is bits to clear.
1389 (The sign bit is not used so there is no confusion.) */
1391 static const struct
1393 const char *const name;
1394 const int value;
1395 const char *const description;
1397 target_switches [] = TARGET_SWITCHES;
1399 /* This table is similar, but allows the switch to have a value. */
1401 #ifdef TARGET_OPTIONS
1402 static const struct
1404 const char *const prefix;
1405 const char **const variable;
1406 const char *const description;
1408 target_options [] = TARGET_OPTIONS;
1409 #endif
1411 /* Options controlling warnings. */
1413 /* Don't print warning messages. -w. */
1415 int inhibit_warnings = 0;
1417 /* Don't suppress warnings from system headers. -Wsystem-headers. */
1419 int warn_system_headers = 0;
1421 /* Print various extra warnings. -W. */
1423 int extra_warnings = 0;
1425 /* Treat warnings as errors. -Werror. */
1427 int warnings_are_errors = 0;
1429 /* Nonzero to warn about unused variables, functions et.al. */
1431 int warn_unused_function;
1432 int warn_unused_label;
1433 int warn_unused_parameter;
1434 int warn_unused_variable;
1435 int warn_unused_value;
1437 void
1438 set_Wunused (setting)
1439 int setting;
1441 warn_unused_function = setting;
1442 warn_unused_label = setting;
1443 /* Unused function parameter warnings are reported when either ``-W
1444 -Wunused'' or ``-Wunused-parameter'' is specified. Differentiate
1445 -Wunused by setting WARN_UNUSED_PARAMETER to -1. */
1446 if (!setting)
1447 warn_unused_parameter = 0;
1448 else if (!warn_unused_parameter)
1449 warn_unused_parameter = -1;
1450 warn_unused_variable = setting;
1451 warn_unused_value = setting;
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 fails to have a case for every enum value. */
1468 int warn_switch;
1470 /* Nonzero means warn about function definitions that default the return type
1471 or that use a null return and have a return-type other than void. */
1473 int warn_return_type;
1475 /* Nonzero means warn about pointer casts that increase the required
1476 alignment of the target type (and might therefore lead to a crash
1477 due to a misaligned access). */
1479 int warn_cast_align;
1481 /* Nonzero means warn about any objects definitions whose size is larger
1482 than N bytes. Also want about function definitions whose returned
1483 values are larger than N bytes. The value N is in `larger_than_size'. */
1485 int warn_larger_than;
1486 HOST_WIDE_INT larger_than_size;
1488 /* Nonzero means warn if inline function is too large. */
1490 int warn_inline;
1492 /* Warn if a function returns an aggregate,
1493 since there are often incompatible calling conventions for doing this. */
1495 int warn_aggregate_return;
1497 /* Warn if packed attribute on struct is unnecessary and inefficient. */
1499 int warn_packed;
1501 /* Warn when gcc pads a structure to an alignment boundary. */
1503 int warn_padded;
1505 /* Warn when an optimization pass is disabled. */
1507 int warn_disabled_optimization;
1509 /* Warn about functions which might be candidates for attribute noreturn. */
1511 int warn_missing_noreturn;
1513 /* Likewise for -W. */
1515 lang_independent_options W_options[] =
1517 {"unused-function", &warn_unused_function, 1,
1518 N_("Warn when a function is unused") },
1519 {"unused-label", &warn_unused_label, 1,
1520 N_("Warn when a label is unused") },
1521 {"unused-parameter", &warn_unused_parameter, 1,
1522 N_("Warn when a function parameter is unused") },
1523 {"unused-variable", &warn_unused_variable, 1,
1524 N_("Warn when a variable is unused") },
1525 {"unused-value", &warn_unused_value, 1,
1526 N_("Warn when an expression value is unused") },
1527 {"system-headers", &warn_system_headers, 1,
1528 N_("Do not suppress warnings from system headers") },
1529 {"error", &warnings_are_errors, 1,
1530 N_("Treat all warnings as errors") },
1531 {"shadow", &warn_shadow, 1,
1532 N_("Warn when one local variable shadows another") },
1533 {"switch", &warn_switch, 1,
1534 N_("Warn about enumerated switches missing a specific case") },
1535 {"aggregate-return", &warn_aggregate_return, 1,
1536 N_("Warn about returning structures, unions or arrays") },
1537 {"cast-align", &warn_cast_align, 1,
1538 N_("Warn about pointer casts which increase alignment") },
1539 {"unreachable-code", &warn_notreached, 1,
1540 N_("Warn about code that will never be executed") },
1541 {"uninitialized", &warn_uninitialized, 1,
1542 N_("Warn about uninitialized automatic variables") },
1543 {"inline", &warn_inline, 1,
1544 N_("Warn when an inlined function cannot be inlined") },
1545 {"packed", &warn_packed, 1,
1546 N_("Warn when the packed attribute has no effect on struct layout") },
1547 {"padded", &warn_padded, 1,
1548 N_("Warn when padding is required to align struct members") },
1549 {"disabled-optimization", &warn_disabled_optimization, 1,
1550 N_("Warn when an optimization pass is disabled") },
1551 {"missing-noreturn", &warn_missing_noreturn, 1,
1552 N_("Warn about functions which might be candidates for attribute noreturn") }
1555 /* The following routines are useful in setting all the flags that
1556 -ffast-math and -fno-fast-math imply. */
1558 void
1559 set_fast_math_flags ()
1561 flag_trapping_math = 0;
1562 flag_unsafe_math_optimizations = 1;
1563 flag_errno_math = 0;
1566 void
1567 set_no_fast_math_flags ()
1569 flag_trapping_math = 1;
1570 flag_unsafe_math_optimizations = 0;
1571 flag_errno_math = 1;
1575 /* Output files for assembler code (real compiler output)
1576 and debugging dumps. */
1578 FILE *asm_out_file;
1579 FILE *aux_info_file;
1580 FILE *rtl_dump_file = NULL;
1582 /* Decode the string P as an integral parameter.
1583 If the string is indeed an integer return its numeric value else
1584 issue an Invalid Option error for the option PNAME and return DEFVAL.
1585 If PNAME is zero just return DEFVAL, do not call error. */
1588 read_integral_parameter (p, pname, defval)
1589 const char *p;
1590 const char *pname;
1591 const int defval;
1593 const char *endp = p;
1595 while (*endp)
1597 if (ISDIGIT (*endp))
1598 endp++;
1599 else
1600 break;
1603 if (*endp != 0)
1605 if (pname != 0)
1606 error ("Invalid option `%s'", pname);
1607 return defval;
1610 return atoi (p);
1614 /* This is the default decl_printable_name function. */
1616 static const char *
1617 decl_name (decl, verbosity)
1618 tree decl;
1619 int verbosity ATTRIBUTE_UNUSED;
1621 return IDENTIFIER_POINTER (DECL_NAME (decl));
1625 /* This calls abort and is used to avoid problems when abort if a macro.
1626 It is used when we need to pass the address of abort. */
1628 void
1629 do_abort ()
1631 abort ();
1634 /* When `malloc.c' is compiled with `rcheck' defined,
1635 it calls this function to report clobberage. */
1637 void
1638 botch (s)
1639 const char *s ATTRIBUTE_UNUSED;
1641 abort ();
1644 /* Return the logarithm of X, base 2, considering X unsigned,
1645 if X is a power of 2. Otherwise, returns -1.
1647 This should be used via the `exact_log2' macro. */
1650 exact_log2_wide (x)
1651 unsigned HOST_WIDE_INT x;
1653 int log = 0;
1654 /* Test for 0 or a power of 2. */
1655 if (x == 0 || x != (x & -x))
1656 return -1;
1657 while ((x >>= 1) != 0)
1658 log++;
1659 return log;
1662 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1663 If X is 0, return -1.
1665 This should be used via the floor_log2 macro. */
1668 floor_log2_wide (x)
1669 unsigned HOST_WIDE_INT x;
1671 int log = -1;
1672 while (x != 0)
1673 log++,
1674 x >>= 1;
1675 return log;
1678 static int float_handler_set;
1679 int float_handled;
1680 jmp_buf float_handler;
1682 /* Signals actually come here. */
1684 static void
1685 float_signal (signo)
1686 /* If this is missing, some compilers complain. */
1687 int signo ATTRIBUTE_UNUSED;
1689 if (float_handled == 0)
1690 crash_signal (signo);
1691 float_handled = 0;
1693 /* On System-V derived systems, we must reinstall the signal handler.
1694 This is harmless on BSD-derived systems. */
1695 signal (SIGFPE, float_signal);
1696 longjmp (float_handler, 1);
1699 /* Specify where to longjmp to when a floating arithmetic error happens.
1700 If HANDLER is 0, it means don't handle the errors any more. */
1702 static void
1703 set_float_handler (handler)
1704 jmp_buf handler;
1706 float_handled = (handler != 0);
1707 if (handler)
1708 memcpy (float_handler, handler, sizeof (float_handler));
1710 if (float_handled && ! float_handler_set)
1712 signal (SIGFPE, float_signal);
1713 float_handler_set = 1;
1717 /* This is a wrapper function for code which might elicit an
1718 arithmetic exception. That code should be passed in as a function
1719 pointer FN, and one argument DATA. DATA is usually a struct which
1720 contains the real input and output for function FN. This function
1721 returns 0 (failure) if longjmp was called (i.e. an exception
1722 occurred.) It returns 1 (success) otherwise. */
1725 do_float_handler (fn, data)
1726 void (*fn) PARAMS ((PTR));
1727 PTR data;
1729 jmp_buf buf;
1731 if (setjmp (buf))
1733 /* We got here via longjmp () caused by an exception in function
1734 fn (). */
1735 set_float_handler (NULL);
1736 return 0;
1739 set_float_handler (buf);
1740 (*fn)(data);
1741 set_float_handler (NULL);
1742 return 1;
1745 /* Handler for fatal signals, such as SIGSEGV. These are transformed
1746 into ICE messages, which is much more user friendly. */
1748 static void
1749 crash_signal (signo)
1750 int signo;
1752 internal_error ("Internal error: %s", strsignal (signo));
1755 /* Strip off a legitimate source ending from the input string NAME of
1756 length LEN. Rather than having to know the names used by all of
1757 our front ends, we strip off an ending of a period followed by
1758 up to five characters. (Java uses ".class".) */
1760 void
1761 strip_off_ending (name, len)
1762 char *name;
1763 int len;
1765 int i;
1766 for (i = 2; i < 6 && len > i; i++)
1768 if (name[len - i] == '.')
1770 name[len - i] = '\0';
1771 break;
1776 /* Output a quoted string. */
1778 void
1779 output_quoted_string (asm_file, string)
1780 FILE *asm_file;
1781 const char *string;
1783 #ifdef OUTPUT_QUOTED_STRING
1784 OUTPUT_QUOTED_STRING (asm_file, string);
1785 #else
1786 char c;
1788 putc ('\"', asm_file);
1789 while ((c = *string++) != 0)
1791 if (c == '\"' || c == '\\')
1792 putc ('\\', asm_file);
1793 putc (c, asm_file);
1795 putc ('\"', asm_file);
1796 #endif
1799 /* Output a file name in the form wanted by System V. */
1801 void
1802 output_file_directive (asm_file, input_name)
1803 FILE *asm_file;
1804 const char *input_name;
1806 int len = strlen (input_name);
1807 const char *na = input_name + len;
1809 /* NA gets INPUT_NAME sans directory names. */
1810 while (na > input_name)
1812 if (IS_DIR_SEPARATOR (na[-1]))
1813 break;
1814 na--;
1817 #ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
1818 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
1819 #else
1820 #ifdef ASM_OUTPUT_SOURCE_FILENAME
1821 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
1822 #else
1823 fprintf (asm_file, "\t.file\t");
1824 output_quoted_string (asm_file, na);
1825 fputc ('\n', asm_file);
1826 #endif
1827 #endif
1830 /* Routine to open a dump file. Return true if the dump file is enabled. */
1832 static int
1833 open_dump_file (index, decl)
1834 enum dump_file_index index;
1835 tree decl;
1837 char *dump_name;
1838 const char *open_arg;
1839 char seq[16];
1841 if (! dump_file[index].enabled)
1842 return 0;
1844 timevar_push (TV_DUMP);
1845 if (rtl_dump_file != NULL)
1846 fclose (rtl_dump_file);
1848 sprintf (seq, ".%02d.", index);
1850 if (! dump_file[index].initialized)
1852 /* If we've not initialized the files, do so now. */
1853 if (graph_dump_format != no_graph
1854 && dump_file[index].graph_dump_p)
1856 dump_name = concat (seq, dump_file[index].extension, NULL);
1857 clean_graph_dump_file (dump_base_name, dump_name);
1858 free (dump_name);
1860 dump_file[index].initialized = 1;
1861 open_arg = "w";
1863 else
1864 open_arg = "a";
1866 dump_name = concat (dump_base_name, seq,
1867 dump_file[index].extension, NULL);
1869 rtl_dump_file = fopen (dump_name, open_arg);
1870 if (rtl_dump_file == NULL)
1871 fatal_io_error ("can't open %s", dump_name);
1873 free (dump_name);
1875 if (decl)
1876 fprintf (rtl_dump_file, "\n;; Function %s\n\n",
1877 decl_printable_name (decl, 2));
1879 timevar_pop (TV_DUMP);
1880 return 1;
1883 /* Routine to close a dump file. */
1885 static void
1886 close_dump_file (index, func, insns)
1887 enum dump_file_index index;
1888 void (*func) PARAMS ((FILE *, rtx));
1889 rtx insns;
1891 if (! rtl_dump_file)
1892 return;
1894 timevar_push (TV_DUMP);
1895 if (insns
1896 && graph_dump_format != no_graph
1897 && dump_file[index].graph_dump_p)
1899 char seq[16];
1900 char *suffix;
1902 sprintf (seq, ".%02d.", index);
1903 suffix = concat (seq, dump_file[index].extension, NULL);
1904 print_rtl_graph_with_bb (dump_base_name, suffix, insns);
1905 free (suffix);
1908 if (func && insns)
1909 func (rtl_dump_file, insns);
1911 fflush (rtl_dump_file);
1912 fclose (rtl_dump_file);
1914 rtl_dump_file = NULL;
1915 timevar_pop (TV_DUMP);
1918 /* Do any final processing required for the declarations in VEC, of
1919 which there are LEN. We write out inline functions and variables
1920 that have been deferred until this point, but which are required.
1921 Returns non-zero if anything was put out. */
1924 wrapup_global_declarations (vec, len)
1925 tree *vec;
1926 int len;
1928 tree decl;
1929 int i;
1930 int reconsider;
1931 int output_something = 0;
1933 for (i = 0; i < len; i++)
1935 decl = vec[i];
1937 /* We're not deferring this any longer. */
1938 DECL_DEFER_OUTPUT (decl) = 0;
1940 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0
1941 && incomplete_decl_finalize_hook != 0)
1942 (*incomplete_decl_finalize_hook) (decl);
1945 /* Now emit any global variables or functions that we have been
1946 putting off. We need to loop in case one of the things emitted
1947 here references another one which comes earlier in the list. */
1950 reconsider = 0;
1951 for (i = 0; i < len; i++)
1953 decl = vec[i];
1955 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
1956 continue;
1958 /* Don't write out static consts, unless we still need them.
1960 We also keep static consts if not optimizing (for debugging),
1961 unless the user specified -fno-keep-static-consts.
1962 ??? They might be better written into the debug information.
1963 This is possible when using DWARF.
1965 A language processor that wants static constants to be always
1966 written out (even if it is not used) is responsible for
1967 calling rest_of_decl_compilation itself. E.g. the C front-end
1968 calls rest_of_decl_compilation from finish_decl.
1969 One motivation for this is that is conventional in some
1970 environments to write things like:
1971 static const char rcsid[] = "... version string ...";
1972 intending to force the string to be in the executable.
1974 A language processor that would prefer to have unneeded
1975 static constants "optimized away" would just defer writing
1976 them out until here. E.g. C++ does this, because static
1977 constants are often defined in header files.
1979 ??? A tempting alternative (for both C and C++) would be
1980 to force a constant to be written if and only if it is
1981 defined in a main file, as opposed to an include file. */
1983 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
1984 && (((! TREE_READONLY (decl) || TREE_PUBLIC (decl))
1985 && !DECL_COMDAT (decl))
1986 || (!optimize
1987 && flag_keep_static_consts
1988 && !DECL_ARTIFICIAL (decl))
1989 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
1991 reconsider = 1;
1992 rest_of_decl_compilation (decl, NULL, 1, 1);
1995 if (TREE_CODE (decl) == FUNCTION_DECL
1996 && DECL_INITIAL (decl) != 0
1997 && DECL_SAVED_INSNS (decl) != 0
1998 && (flag_keep_inline_functions
1999 || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
2000 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2002 reconsider = 1;
2003 output_inline_function (decl);
2007 if (reconsider)
2008 output_something = 1;
2010 while (reconsider);
2012 return output_something;
2015 /* Issue appropriate warnings for the global declarations in VEC (of
2016 which there are LEN). Output debugging information for them. */
2018 void
2019 check_global_declarations (vec, len)
2020 tree *vec;
2021 int len;
2023 tree decl;
2024 int i;
2026 for (i = 0; i < len; i++)
2028 decl = vec[i];
2030 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2031 && ! TREE_ASM_WRITTEN (decl))
2032 /* Cancel the RTL for this decl so that, if debugging info
2033 output for global variables is still to come,
2034 this one will be omitted. */
2035 SET_DECL_RTL (decl, NULL_RTX);
2037 /* Warn about any function
2038 declared static but not defined.
2039 We don't warn about variables,
2040 because many programs have static variables
2041 that exist only to get some text into the object file. */
2042 if (TREE_CODE (decl) == FUNCTION_DECL
2043 && (warn_unused_function
2044 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2045 && DECL_INITIAL (decl) == 0
2046 && DECL_EXTERNAL (decl)
2047 && ! DECL_ARTIFICIAL (decl)
2048 && ! TREE_PUBLIC (decl))
2050 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2051 pedwarn_with_decl (decl,
2052 "`%s' used but never defined");
2053 else
2054 warning_with_decl (decl,
2055 "`%s' declared `static' but never defined");
2056 /* This symbol is effectively an "extern" declaration now. */
2057 TREE_PUBLIC (decl) = 1;
2058 assemble_external (decl);
2061 /* Warn about static fns or vars defined but not used,
2062 but not about inline functions or static consts
2063 since defining those in header files is normal practice. */
2064 if (((warn_unused_function
2065 && TREE_CODE (decl) == FUNCTION_DECL && ! DECL_INLINE (decl))
2066 || (warn_unused_variable
2067 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
2068 && ! DECL_IN_SYSTEM_HEADER (decl)
2069 && ! DECL_EXTERNAL (decl)
2070 && ! TREE_PUBLIC (decl)
2071 && ! TREE_USED (decl)
2072 && (TREE_CODE (decl) == FUNCTION_DECL || ! DECL_REGISTER (decl))
2073 /* The TREE_USED bit for file-scope decls
2074 is kept in the identifier, to handle multiple
2075 external decls in different scopes. */
2076 && ! TREE_USED (DECL_NAME (decl)))
2077 warning_with_decl (decl, "`%s' defined but not used");
2079 timevar_push (TV_SYMOUT);
2080 (*debug_hooks->global_decl) (decl);
2081 timevar_pop (TV_SYMOUT);
2085 /* Save the current INPUT_FILENAME and LINENO on the top entry in the
2086 INPUT_FILE_STACK. Push a new entry for FILE and LINE, and set the
2087 INPUT_FILENAME and LINENO accordingly. */
2089 void
2090 push_srcloc (file, line)
2091 const char *file;
2092 int line;
2094 struct file_stack *fs;
2096 if (input_file_stack)
2098 input_file_stack->name = input_filename;
2099 input_file_stack->line = lineno;
2102 fs = (struct file_stack *) xmalloc (sizeof (struct file_stack));
2103 fs->name = input_filename = file;
2104 fs->line = lineno = line;
2105 fs->indent_level = 0;
2106 fs->next = input_file_stack;
2107 input_file_stack = fs;
2108 input_file_stack_tick++;
2111 /* Pop the top entry off the stack of presently open source files.
2112 Restore the INPUT_FILENAME and LINENO from the new topmost entry on
2113 the stack. */
2115 void
2116 pop_srcloc ()
2118 struct file_stack *fs;
2120 fs = input_file_stack;
2121 input_file_stack = fs->next;
2122 free (fs);
2123 input_file_stack_tick++;
2124 /* The initial source file is never popped. */
2125 if (!input_file_stack)
2126 abort ();
2127 input_filename = input_file_stack->name;
2128 lineno = input_file_stack->line;
2131 /* Compile an entire translation unit, whose primary source file is
2132 named NAME. Write a file of assembly output and various debugging
2133 dumps. */
2135 static void
2136 compile_file (name)
2137 const char *name;
2139 tree globals;
2141 int name_specified = name != 0;
2143 if (dump_base_name == 0)
2144 dump_base_name = name ? name : "gccdump";
2146 if (! quiet_flag)
2147 time_report = 1;
2149 /* Start timing total execution time. */
2151 init_timevar ();
2152 timevar_start (TV_TOTAL);
2154 /* Open assembly code output file. Do this even if -fsyntax-only is on,
2155 because then the driver will have provided the name of a temporary
2156 file or bit bucket for us. */
2158 if (! name_specified && asm_file_name == 0)
2159 asm_out_file = stdout;
2160 else
2162 if (asm_file_name == 0)
2164 int len = strlen (dump_base_name);
2165 char *dumpname = (char *) xmalloc (len + 6);
2166 memcpy (dumpname, dump_base_name, len + 1);
2167 strip_off_ending (dumpname, len);
2168 strcat (dumpname, ".s");
2169 asm_file_name = dumpname;
2171 if (!strcmp (asm_file_name, "-"))
2172 asm_out_file = stdout;
2173 else
2174 asm_out_file = fopen (asm_file_name, "w");
2175 if (asm_out_file == 0)
2176 fatal_io_error ("can't open %s for writing", asm_file_name);
2179 /* Initialize data in various passes. */
2181 init_obstacks ();
2182 name = init_parse (name);
2183 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
2184 || debug_info_level == DINFO_LEVEL_VERBOSE
2185 || flag_test_coverage
2186 || warn_notreached);
2187 init_regs ();
2188 init_alias_once ();
2189 init_decl_processing ();
2190 init_eh ();
2191 init_optabs ();
2192 init_stmt ();
2193 init_loop ();
2194 init_reload ();
2195 init_function_once ();
2196 init_stor_layout_once ();
2197 init_varasm_once ();
2198 init_EXPR_INSN_LIST_cache ();
2200 /* The following initialization functions need to generate rtl, so
2201 provide a dummy function context for them. */
2202 init_dummy_function_start ();
2203 init_expmed ();
2204 init_expr_once ();
2205 if (flag_caller_saves)
2206 init_caller_save ();
2207 expand_dummy_function_end ();
2209 /* If auxiliary info generation is desired, open the output file.
2210 This goes in the same directory as the source file--unlike
2211 all the other output files. */
2212 if (flag_gen_aux_info)
2214 aux_info_file = fopen (aux_info_file_name, "w");
2215 if (aux_info_file == 0)
2216 fatal_io_error ("can't open %s", aux_info_file_name);
2219 #ifdef IO_BUFFER_SIZE
2220 setvbuf (asm_out_file, (char *) xmalloc (IO_BUFFER_SIZE),
2221 _IOFBF, IO_BUFFER_SIZE);
2222 #endif
2224 if (name != 0)
2225 name = ggc_strdup (name);
2227 input_filename = name;
2229 /* Put an entry on the input file stack for the main input file. */
2230 push_srcloc (input_filename, 0);
2232 /* Perform language-specific initialization.
2233 This may set main_input_filename. */
2234 (*lang_hooks.init) ();
2236 /* If the input doesn't start with a #line, use the input name
2237 as the official input file name. */
2238 if (main_input_filename == 0)
2239 main_input_filename = name;
2241 if (flag_syntax_only)
2243 write_symbols = NO_DEBUG;
2244 profile_flag = 0;
2245 profile_block_flag = 0;
2247 else
2249 #ifdef ASM_FILE_START
2250 ASM_FILE_START (asm_out_file);
2251 #endif
2253 #ifdef ASM_COMMENT_START
2254 if (flag_verbose_asm)
2256 /* Print the list of options in effect. */
2257 print_version (asm_out_file, ASM_COMMENT_START);
2258 print_switch_values (asm_out_file, 0, MAX_LINE,
2259 ASM_COMMENT_START, " ", "\n");
2260 /* Add a blank line here so it appears in assembler output but not
2261 screen output. */
2262 fprintf (asm_out_file, "\n");
2264 #endif
2265 } /* ! flag_syntax_only */
2267 /* Set up the debug hooks based on write_symbols. Default to doing
2268 nothing. */
2269 debug_hooks = &do_nothing_debug_hooks;
2270 #if defined(DBX_DEBUGGING_INFO)
2271 if (write_symbols == DBX_DEBUG)
2272 debug_hooks = &dbx_debug_hooks;
2273 #endif
2274 #if defined(XCOFF_DEBUGGING_INFO)
2275 if (write_symbols == XCOFF_DEBUG)
2276 debug_hooks = &xcoff_debug_hooks;
2277 #endif
2278 #ifdef SDB_DEBUGGING_INFO
2279 if (write_symbols == SDB_DEBUG)
2280 debug_hooks = &sdb_debug_hooks;
2281 #endif
2282 #ifdef DWARF_DEBUGGING_INFO
2283 if (write_symbols == DWARF_DEBUG)
2284 debug_hooks = &dwarf_debug_hooks;
2285 #endif
2286 #ifdef DWARF2_DEBUGGING_INFO
2287 if (write_symbols == DWARF2_DEBUG)
2288 debug_hooks = &dwarf2_debug_hooks;
2289 #endif
2291 if (! targetm.have_named_sections)
2293 if (flag_function_sections)
2295 warning ("-ffunction-sections not supported for this target.");
2296 flag_function_sections = 0;
2298 if (flag_data_sections)
2300 warning ("-fdata-sections not supported for this target.");
2301 flag_data_sections = 0;
2305 if (flag_function_sections
2306 && (profile_flag || profile_block_flag))
2308 warning ("-ffunction-sections disabled; it makes profiling impossible.");
2309 flag_function_sections = 0;
2312 #ifndef OBJECT_FORMAT_ELF
2313 if (flag_function_sections && write_symbols != NO_DEBUG)
2314 warning ("-ffunction-sections may affect debugging on some targets.");
2315 #endif
2317 /* If dbx symbol table desired, initialize writing it
2318 and output the predefined types. */
2319 timevar_push (TV_SYMOUT);
2320 #ifdef DWARF2_UNWIND_INFO
2321 if (dwarf2out_do_frame ())
2322 dwarf2out_frame_init ();
2323 #endif
2325 (*debug_hooks->init) (main_input_filename);
2326 timevar_pop (TV_SYMOUT);
2328 /* Initialize yet another pass. */
2330 init_final (main_input_filename);
2331 init_branch_prob (dump_base_name);
2333 timevar_push (TV_PARSE);
2335 /* Call the parser, which parses the entire file
2336 (calling rest_of_compilation for each function). */
2337 yyparse ();
2339 /* In case there were missing block closers,
2340 get us back to the global binding level. */
2341 (*lang_hooks.clear_binding_stack) ();
2343 /* Compilation is now finished except for writing
2344 what's left of the symbol table output. */
2346 timevar_pop (TV_PARSE);
2348 if (flag_syntax_only)
2349 goto finish_syntax;
2351 globals = getdecls ();
2353 /* Really define vars that have had only a tentative definition.
2354 Really output inline functions that must actually be callable
2355 and have not been output so far. */
2358 int len = list_length (globals);
2359 tree *vec = (tree *) xmalloc (sizeof (tree) * len);
2360 int i;
2361 tree decl;
2363 /* Process the decls in reverse order--earliest first.
2364 Put them into VEC from back to front, then take out from front. */
2366 for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
2367 vec[len - i - 1] = decl;
2369 wrapup_global_declarations (vec, len);
2371 /* This must occur after the loop to output deferred functions. Else
2372 the profiler initializer would not be emitted if all the functions
2373 in this compilation unit were deferred.
2375 output_func_start_profiler can not cause any additional functions or
2376 data to need to be output, so it need not be in the deferred function
2377 loop above. */
2378 output_func_start_profiler ();
2380 check_global_declarations (vec, len);
2382 /* Clean up. */
2383 free (vec);
2386 /* Write out any pending weak symbol declarations. */
2388 weak_finish ();
2390 /* Do dbx symbols. */
2391 timevar_push (TV_SYMOUT);
2393 #ifdef DWARF2_UNWIND_INFO
2394 if (dwarf2out_do_frame ())
2395 dwarf2out_frame_finish ();
2396 #endif
2398 (*debug_hooks->finish) (main_input_filename);
2399 timevar_pop (TV_SYMOUT);
2401 /* Output some stuff at end of file if nec. */
2403 dw2_output_indirect_constants ();
2405 end_final (dump_base_name);
2407 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
2409 timevar_push (TV_DUMP);
2410 open_dump_file (DFI_bp, NULL);
2412 end_branch_prob ();
2414 close_dump_file (DFI_bp, NULL, NULL_RTX);
2415 timevar_pop (TV_DUMP);
2418 #ifdef ASM_FILE_END
2419 ASM_FILE_END (asm_out_file);
2420 #endif
2422 /* Attach a special .ident directive to the end of the file to identify
2423 the version of GCC which compiled this code. The format of the .ident
2424 string is patterned after the ones produced by native SVR4 compilers. */
2425 #ifdef IDENT_ASM_OP
2426 if (!flag_no_ident)
2427 fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
2428 IDENT_ASM_OP, version_string);
2429 #endif
2431 /* Language-specific end of compilation actions. */
2432 finish_syntax:
2433 (*lang_hooks.finish) ();
2435 /* Close the dump files. */
2437 if (flag_gen_aux_info)
2439 fclose (aux_info_file);
2440 if (errorcount)
2441 unlink (aux_info_file_name);
2444 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
2446 timevar_push (TV_DUMP);
2447 dump_combine_total_stats (rtl_dump_file);
2448 close_dump_file (DFI_combine, NULL, NULL_RTX);
2449 timevar_pop (TV_DUMP);
2452 /* Close non-debugging input and output files. Take special care to note
2453 whether fclose returns an error, since the pages might still be on the
2454 buffer chain while the file is open. */
2456 finish_parse ();
2458 if (ferror (asm_out_file) != 0)
2459 fatal_io_error ("error writing to %s", asm_file_name);
2460 if (fclose (asm_out_file) != 0)
2461 fatal_io_error ("error closing %s", asm_file_name);
2463 /* Do whatever is necessary to finish printing the graphs. */
2464 if (graph_dump_format != no_graph)
2466 int i;
2468 for (i = 0; i < (int) DFI_MAX; ++i)
2469 if (dump_file[i].initialized && dump_file[i].graph_dump_p)
2471 char seq[16];
2472 char *suffix;
2474 sprintf (seq, ".%02d.", i);
2475 suffix = concat (seq, dump_file[i].extension, NULL);
2476 finish_graph_dump_file (dump_base_name, suffix);
2477 free (suffix);
2481 if (mem_report)
2483 ggc_print_statistics ();
2484 stringpool_statistics ();
2485 dump_tree_statistics ();
2488 /* Free up memory for the benefit of leak detectors. */
2489 free_reg_info ();
2491 /* Stop timing total execution time. */
2492 timevar_stop (TV_TOTAL);
2494 /* Print the times. */
2496 timevar_print (stderr);
2499 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
2500 and TYPE_DECL nodes.
2502 This does nothing for local (non-static) variables, unless the
2503 variable is a register variable with an ASMSPEC. In that case, or
2504 if the variable is not an automatic, it sets up the RTL and
2505 outputs any assembler code (label definition, storage allocation
2506 and initialization).
2508 DECL is the declaration. If ASMSPEC is nonzero, it specifies
2509 the assembler symbol name to be used. TOP_LEVEL is nonzero
2510 if this declaration is not within a function. */
2512 void
2513 rest_of_decl_compilation (decl, asmspec, top_level, at_end)
2514 tree decl;
2515 const char *asmspec;
2516 int top_level;
2517 int at_end;
2519 /* Declarations of variables, and of functions defined elsewhere. */
2521 /* The most obvious approach, to put an #ifndef around where
2522 this macro is used, doesn't work since it's inside a macro call. */
2523 #ifndef ASM_FINISH_DECLARE_OBJECT
2524 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP, END)
2525 #endif
2527 /* Forward declarations for nested functions are not "external",
2528 but we need to treat them as if they were. */
2529 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
2530 || TREE_CODE (decl) == FUNCTION_DECL)
2532 timevar_push (TV_VARCONST);
2533 if (asmspec)
2534 make_decl_rtl (decl, asmspec);
2535 /* Don't output anything
2536 when a tentative file-scope definition is seen.
2537 But at end of compilation, do output code for them. */
2538 if (at_end || !DECL_DEFER_OUTPUT (decl))
2539 assemble_variable (decl, top_level, at_end, 0);
2540 if (decl == last_assemble_variable_decl)
2542 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
2543 top_level, at_end);
2545 timevar_pop (TV_VARCONST);
2547 else if (DECL_REGISTER (decl) && asmspec != 0)
2549 if (decode_reg_name (asmspec) >= 0)
2551 SET_DECL_RTL (decl, NULL_RTX);
2552 make_decl_rtl (decl, asmspec);
2554 else
2556 error ("invalid register name `%s' for register variable", asmspec);
2557 DECL_REGISTER (decl) = 0;
2558 if (!top_level)
2559 expand_decl (decl);
2562 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2563 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2564 && TREE_CODE (decl) == TYPE_DECL)
2566 timevar_push (TV_SYMOUT);
2567 dbxout_symbol (decl, 0);
2568 timevar_pop (TV_SYMOUT);
2570 #endif
2571 #ifdef SDB_DEBUGGING_INFO
2572 else if (write_symbols == SDB_DEBUG && top_level
2573 && TREE_CODE (decl) == TYPE_DECL)
2575 timevar_push (TV_SYMOUT);
2576 sdbout_symbol (decl, 0);
2577 timevar_pop (TV_SYMOUT);
2579 #endif
2582 /* Called after finishing a record, union or enumeral type. */
2584 void
2585 rest_of_type_compilation (type, toplev)
2586 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO) || defined (SDB_DEBUGGING_INFO)
2587 tree type;
2588 int toplev;
2589 #else
2590 tree type ATTRIBUTE_UNUSED;
2591 int toplev ATTRIBUTE_UNUSED;
2592 #endif
2594 timevar_push (TV_SYMOUT);
2595 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2596 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2597 dbxout_symbol (TYPE_STUB_DECL (type), !toplev);
2598 #endif
2599 #ifdef SDB_DEBUGGING_INFO
2600 if (write_symbols == SDB_DEBUG)
2601 sdbout_symbol (TYPE_STUB_DECL (type), !toplev);
2602 #endif
2603 #ifdef DWARF2_DEBUGGING_INFO
2604 if (write_symbols == DWARF2_DEBUG && toplev)
2605 dwarf2out_decl (TYPE_STUB_DECL (type));
2606 #endif
2607 timevar_pop (TV_SYMOUT);
2610 /* This is called from finish_function (within yyparse)
2611 after each top-level definition is parsed.
2612 It is supposed to compile that function or variable
2613 and output the assembler code for it.
2614 After we return, the tree storage is freed. */
2616 void
2617 rest_of_compilation (decl)
2618 tree decl;
2620 rtx insns;
2621 int tem;
2622 int failure = 0;
2623 int rebuild_label_notes_after_reload;
2624 int register_life_up_to_date;
2626 timevar_push (TV_REST_OF_COMPILATION);
2628 /* Now that we're out of the frontend, we shouldn't have any more
2629 CONCATs anywhere. */
2630 generating_concat_p = 0;
2632 /* When processing delayed functions, prepare_function_start() won't
2633 have been run to re-initialize it. */
2634 cse_not_expected = ! optimize;
2636 /* First, make sure that NOTE_BLOCK is set correctly for each
2637 NOTE_INSN_BLOCK_BEG/NOTE_INSN_BLOCK_END note. */
2638 if (!cfun->x_whole_function_mode_p)
2639 identify_blocks ();
2641 /* Then remove any notes we don't need. That will make iterating
2642 over the instruction sequence faster, and allow the garbage
2643 collector to reclaim the memory used by the notes. */
2644 remove_unnecessary_notes ();
2646 /* In function-at-a-time mode, we do not attempt to keep the BLOCK
2647 tree in sensible shape. So, we just recalculate it here. */
2648 if (cfun->x_whole_function_mode_p)
2649 reorder_blocks ();
2651 init_flow ();
2653 /* If we are reconsidering an inline function
2654 at the end of compilation, skip the stuff for making it inline. */
2656 if (DECL_SAVED_INSNS (decl) == 0)
2658 int inlinable = 0;
2659 tree parent;
2660 const char *lose;
2662 /* If this is nested inside an inlined external function, pretend
2663 it was only declared. Since we cannot inline such functions,
2664 generating code for this one is not only not necessary but will
2665 confuse some debugging output writers. */
2666 for (parent = DECL_CONTEXT (current_function_decl);
2667 parent != NULL_TREE;
2668 parent = get_containing_scope (parent))
2669 if (TREE_CODE (parent) == FUNCTION_DECL
2670 && DECL_INLINE (parent) && DECL_EXTERNAL (parent))
2672 DECL_INITIAL (decl) = 0;
2673 goto exit_rest_of_compilation;
2676 /* If requested, consider whether to make this function inline. */
2677 if ((DECL_INLINE (decl) && !flag_no_inline)
2678 || flag_inline_functions)
2680 timevar_push (TV_INTEGRATION);
2681 lose = function_cannot_inline_p (decl);
2682 timevar_pop (TV_INTEGRATION);
2683 if (lose || ! optimize)
2685 if (warn_inline && DECL_INLINE (decl))
2686 warning_with_decl (decl, lose);
2687 DECL_ABSTRACT_ORIGIN (decl) = 0;
2688 /* Don't really compile an extern inline function.
2689 If we can't make it inline, pretend
2690 it was only declared. */
2691 if (DECL_EXTERNAL (decl))
2693 DECL_INITIAL (decl) = 0;
2694 goto exit_rest_of_compilation;
2697 else
2698 /* ??? Note that this has the effect of making it look
2699 like "inline" was specified for a function if we choose
2700 to inline it. This isn't quite right, but it's
2701 probably not worth the trouble to fix. */
2702 inlinable = DECL_INLINE (decl) = 1;
2705 insns = get_insns ();
2707 /* Dump the rtl code if we are dumping rtl. */
2709 if (open_dump_file (DFI_rtl, decl))
2711 if (DECL_SAVED_INSNS (decl))
2712 fprintf (rtl_dump_file, ";; (integrable)\n\n");
2713 close_dump_file (DFI_rtl, print_rtl, insns);
2716 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
2717 sorts of eh initialization. Delay this until after the
2718 initial rtl dump so that we can see the original nesting. */
2719 convert_from_eh_region_ranges ();
2721 /* If function is inline, and we don't yet know whether to
2722 compile it by itself, defer decision till end of compilation.
2723 finish_compilation will call rest_of_compilation again
2724 for those functions that need to be output. Also defer those
2725 functions that we are supposed to defer. */
2727 if (inlinable
2728 || (DECL_INLINE (decl)
2729 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2730 && ! flag_keep_inline_functions)
2731 || DECL_EXTERNAL (decl))))
2732 DECL_DEFER_OUTPUT (decl) = 1;
2734 if (DECL_INLINE (decl))
2735 /* DWARF wants separate debugging info for abstract and
2736 concrete instances of all inline functions, including those
2737 declared inline but not inlined, and those inlined even
2738 though they weren't declared inline. Conveniently, that's
2739 what DECL_INLINE means at this point. */
2740 (*debug_hooks->deferred_inline_function) (decl);
2742 if (DECL_DEFER_OUTPUT (decl))
2744 /* If -Wreturn-type, we have to do a bit of compilation. We just
2745 want to call cleanup the cfg to figure out whether or not we can
2746 fall off the end of the function; we do the minimum amount of
2747 work necessary to make that safe. */
2748 if (warn_return_type)
2750 int saved_optimize = optimize;
2752 optimize = 0;
2753 rebuild_jump_labels (insns);
2754 find_exception_handler_labels ();
2755 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2756 cleanup_cfg (CLEANUP_PRE_SIBCALL | CLEANUP_PRE_LOOP);
2757 optimize = saved_optimize;
2759 /* CFG is no longer maitained up-to-date. */
2760 free_bb_for_insn ();
2763 current_function_nothrow = nothrow_function_p ();
2764 if (current_function_nothrow)
2765 /* Now we know that this can't throw; set the flag for the benefit
2766 of other functions later in this translation unit. */
2767 TREE_NOTHROW (current_function_decl) = 1;
2769 timevar_push (TV_INTEGRATION);
2770 save_for_inline (decl);
2771 timevar_pop (TV_INTEGRATION);
2772 DECL_SAVED_INSNS (decl)->inlinable = inlinable;
2773 goto exit_rest_of_compilation;
2776 /* If specified extern inline but we aren't inlining it, we are
2777 done. This goes for anything that gets here with DECL_EXTERNAL
2778 set, not just things with DECL_INLINE. */
2779 if (DECL_EXTERNAL (decl))
2780 goto exit_rest_of_compilation;
2783 ggc_collect ();
2785 /* Initialize some variables used by the optimizers. */
2786 init_function_for_compilation ();
2788 if (! DECL_DEFER_OUTPUT (decl))
2789 TREE_ASM_WRITTEN (decl) = 1;
2791 /* Now that integrate will no longer see our rtl, we need not
2792 distinguish between the return value of this function and the
2793 return value of called functions. Also, we can remove all SETs
2794 of subregs of hard registers; they are only here because of
2795 integrate. Also, we can now initialize pseudos intended to
2796 carry magic hard reg data throughout the function. */
2797 rtx_equal_function_value_matters = 0;
2798 purge_hard_subreg_sets (get_insns ());
2799 emit_initial_value_sets ();
2801 /* Don't return yet if -Wreturn-type; we need to do cleanup_cfg. */
2802 if ((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
2803 goto exit_rest_of_compilation;
2805 /* We may have potential sibling or tail recursion sites. Select one
2806 (of possibly multiple) methods of performing the call. */
2807 if (flag_optimize_sibling_calls)
2809 timevar_push (TV_JUMP);
2810 open_dump_file (DFI_sibling, decl);
2812 optimize_sibling_and_tail_recursive_calls ();
2814 close_dump_file (DFI_sibling, print_rtl, get_insns ());
2815 timevar_pop (TV_JUMP);
2818 /* Complete generation of exception handling code. */
2819 find_exception_handler_labels ();
2820 if (doing_eh (0))
2822 timevar_push (TV_JUMP);
2823 open_dump_file (DFI_eh, decl);
2825 finish_eh_generation ();
2827 close_dump_file (DFI_eh, print_rtl, get_insns ());
2828 timevar_pop (TV_JUMP);
2831 #ifdef FINALIZE_PIC
2832 /* If we are doing position-independent code generation, now
2833 is the time to output special prologues and epilogues.
2834 We do not want to do this earlier, because it just clutters
2835 up inline functions with meaningless insns. */
2836 if (flag_pic)
2837 FINALIZE_PIC;
2838 #endif
2840 insns = get_insns ();
2842 /* Copy any shared structure that should not be shared. */
2843 unshare_all_rtl (current_function_decl, insns);
2845 #ifdef SETJMP_VIA_SAVE_AREA
2846 /* This must be performed before virtual register instantiation. */
2847 if (current_function_calls_alloca)
2848 optimize_save_area_alloca (insns);
2849 #endif
2851 /* Instantiate all virtual registers. */
2852 instantiate_virtual_regs (current_function_decl, insns);
2854 open_dump_file (DFI_jump, decl);
2856 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
2857 are initialized and to compute whether control can drop off the end
2858 of the function. */
2860 timevar_push (TV_JUMP);
2861 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
2862 before jump optimization switches branch directions. */
2863 expected_value_to_br_prob ();
2865 reg_scan (insns, max_reg_num (), 0);
2866 rebuild_jump_labels (insns);
2867 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2868 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP);
2870 /* CFG is no longer maitained up-to-date. */
2871 free_bb_for_insn ();
2872 copy_loop_headers (insns);
2873 purge_line_number_notes (insns);
2875 timevar_pop (TV_JUMP);
2877 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
2878 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
2880 close_dump_file (DFI_jump, print_rtl, insns);
2881 goto exit_rest_of_compilation;
2884 /* Long term, this should probably move before the jump optimizer too,
2885 but I didn't want to disturb the rtl_dump_and_exit and related
2886 stuff at this time. */
2887 if (optimize > 0 && flag_ssa)
2889 /* Convert to SSA form. */
2891 timevar_push (TV_TO_SSA);
2892 open_dump_file (DFI_ssa, decl);
2894 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2895 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2896 convert_to_ssa ();
2898 close_dump_file (DFI_ssa, print_rtl_with_bb, insns);
2899 timevar_pop (TV_TO_SSA);
2901 /* Perform sparse conditional constant propagation, if requested. */
2902 if (flag_ssa_ccp)
2904 timevar_push (TV_SSA_CCP);
2905 open_dump_file (DFI_ssa_ccp, decl);
2907 ssa_const_prop ();
2909 close_dump_file (DFI_ssa_ccp, print_rtl_with_bb, get_insns ());
2910 timevar_pop (TV_SSA_CCP);
2913 /* It would be useful to cleanup the CFG at this point, but block
2914 merging and possibly other transformations might leave a PHI
2915 node in the middle of a basic block, which is a strict no-no. */
2917 /* The SSA implementation uses basic block numbers in its phi
2918 nodes. Thus, changing the control-flow graph or the basic
2919 blocks, e.g., calling find_basic_blocks () or cleanup_cfg (),
2920 may cause problems. */
2922 if (flag_ssa_dce)
2924 /* Remove dead code. */
2926 timevar_push (TV_SSA_DCE);
2927 open_dump_file (DFI_ssa_dce, decl);
2929 insns = get_insns ();
2930 ssa_eliminate_dead_code();
2932 close_dump_file (DFI_ssa_dce, print_rtl_with_bb, insns);
2933 timevar_pop (TV_SSA_DCE);
2936 /* Convert from SSA form. */
2938 timevar_push (TV_FROM_SSA);
2939 open_dump_file (DFI_ussa, decl);
2941 convert_from_ssa ();
2942 /* New registers have been created. Rescan their usage. */
2943 reg_scan (insns, max_reg_num (), 1);
2945 close_dump_file (DFI_ussa, print_rtl_with_bb, insns);
2946 timevar_pop (TV_FROM_SSA);
2948 ggc_collect ();
2949 /* CFG is no longer maitained up-to-date. */
2950 free_bb_for_insn ();
2953 timevar_push (TV_JUMP);
2955 if (optimize > 0)
2957 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2958 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2960 /* ??? Run if-conversion before delete_null_pointer_checks,
2961 since the later does not preserve the CFG. This should
2962 be changed -- no since converting if's that are going to
2963 be deleted. */
2964 timevar_push (TV_IFCVT);
2965 if_convert (0);
2966 timevar_pop (TV_IFCVT);
2968 /* CFG is no longer maitained up-to-date. */
2969 free_bb_for_insn ();
2970 /* Try to identify useless null pointer tests and delete them. */
2971 if (flag_delete_null_pointer_checks)
2972 delete_null_pointer_checks (insns);
2975 /* Jump optimization, and the removal of NULL pointer checks, may
2976 have reduced the number of instructions substantially. CSE, and
2977 future passes, allocate arrays whose dimensions involve the
2978 maximum instruction UID, so if we can reduce the maximum UID
2979 we'll save big on memory. */
2980 renumber_insns (rtl_dump_file);
2981 timevar_pop (TV_JUMP);
2983 close_dump_file (DFI_jump, print_rtl, insns);
2985 ggc_collect ();
2987 /* Perform common subexpression elimination.
2988 Nonzero value from `cse_main' means that jumps were simplified
2989 and some code may now be unreachable, so do
2990 jump optimization again. */
2992 if (optimize > 0)
2994 open_dump_file (DFI_cse, decl);
2995 timevar_push (TV_CSE);
2997 reg_scan (insns, max_reg_num (), 1);
2999 if (flag_thread_jumps)
3001 timevar_push (TV_JUMP);
3002 thread_jumps (insns, max_reg_num (), 1);
3003 timevar_pop (TV_JUMP);
3006 tem = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
3008 /* If we are not running more CSE passes, then we are no longer
3009 expecting CSE to be run. But always rerun it in a cheap mode. */
3010 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
3012 if (tem || optimize > 1)
3014 timevar_push (TV_JUMP);
3015 rebuild_jump_labels (insns);
3016 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3017 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3018 timevar_pop (TV_JUMP);
3019 /* CFG is no longer maitained up-to-date. */
3020 free_bb_for_insn ();
3023 /* Run this after jump optmizations remove all the unreachable code
3024 so that unreachable code will not keep values live. */
3025 delete_trivially_dead_insns (insns, max_reg_num (), 0);
3027 /* Try to identify useless null pointer tests and delete them. */
3028 if (flag_delete_null_pointer_checks)
3030 timevar_push (TV_JUMP);
3031 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3033 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3035 delete_null_pointer_checks (insns);
3036 /* CFG is no longer maitained up-to-date. */
3037 free_bb_for_insn ();
3038 timevar_pop (TV_JUMP);
3041 /* The second pass of jump optimization is likely to have
3042 removed a bunch more instructions. */
3043 renumber_insns (rtl_dump_file);
3045 timevar_pop (TV_CSE);
3046 close_dump_file (DFI_cse, print_rtl, insns);
3049 open_dump_file (DFI_addressof, decl);
3051 purge_addressof (insns);
3052 reg_scan (insns, max_reg_num (), 1);
3054 close_dump_file (DFI_addressof, print_rtl, insns);
3056 ggc_collect ();
3058 /* Perform global cse. */
3060 if (optimize > 0 && flag_gcse)
3062 int save_csb, save_cfj;
3063 int tem2 = 0;
3065 timevar_push (TV_GCSE);
3066 open_dump_file (DFI_gcse, decl);
3068 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3069 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3070 tem = gcse_main (insns, rtl_dump_file);
3072 save_csb = flag_cse_skip_blocks;
3073 save_cfj = flag_cse_follow_jumps;
3074 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
3076 /* CFG is no longer maitained up-to-date. */
3077 free_bb_for_insn ();
3078 /* If -fexpensive-optimizations, re-run CSE to clean up things done
3079 by gcse. */
3080 if (flag_expensive_optimizations)
3082 timevar_push (TV_CSE);
3083 reg_scan (insns, max_reg_num (), 1);
3084 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
3085 timevar_pop (TV_CSE);
3086 cse_not_expected = !flag_rerun_cse_after_loop;
3089 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
3090 things up. Then possibly re-run CSE again. */
3091 while (tem || tem2)
3093 tem = tem2 = 0;
3094 timevar_push (TV_JUMP);
3095 rebuild_jump_labels (insns);
3096 delete_trivially_dead_insns (insns, max_reg_num (), 0);
3097 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3098 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3099 /* CFG is no longer maitained up-to-date. */
3100 free_bb_for_insn ();
3101 timevar_pop (TV_JUMP);
3103 if (flag_expensive_optimizations)
3105 timevar_push (TV_CSE);
3106 reg_scan (insns, max_reg_num (), 1);
3107 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
3108 timevar_pop (TV_CSE);
3112 close_dump_file (DFI_gcse, print_rtl, insns);
3113 timevar_pop (TV_GCSE);
3115 ggc_collect ();
3116 flag_cse_skip_blocks = save_csb;
3117 flag_cse_follow_jumps = save_cfj;
3120 /* Move constant computations out of loops. */
3122 if (optimize > 0)
3124 timevar_push (TV_LOOP);
3125 open_dump_file (DFI_loop, decl);
3126 free_bb_for_insn ();
3128 if (flag_rerun_loop_opt)
3130 cleanup_barriers ();
3132 /* We only want to perform unrolling once. */
3134 loop_optimize (insns, rtl_dump_file, 0);
3136 /* The first call to loop_optimize makes some instructions
3137 trivially dead. We delete those instructions now in the
3138 hope that doing so will make the heuristics in loop work
3139 better and possibly speed up compilation. */
3140 delete_trivially_dead_insns (insns, max_reg_num (), 0);
3142 /* The regscan pass is currently necessary as the alias
3143 analysis code depends on this information. */
3144 reg_scan (insns, max_reg_num (), 1);
3146 cleanup_barriers ();
3147 loop_optimize (insns, rtl_dump_file,
3148 (flag_unroll_loops ? LOOP_UNROLL : 0) | LOOP_BCT);
3150 close_dump_file (DFI_loop, print_rtl, insns);
3151 timevar_pop (TV_LOOP);
3153 ggc_collect ();
3156 if (optimize > 0)
3158 timevar_push (TV_CSE2);
3159 open_dump_file (DFI_cse2, decl);
3161 if (flag_rerun_cse_after_loop)
3163 /* Running another jump optimization pass before the second
3164 cse pass sometimes simplifies the RTL enough to allow
3165 the second CSE pass to do a better job. Jump_optimize can change
3166 max_reg_num so we must rerun reg_scan afterwards.
3167 ??? Rework to not call reg_scan so often. */
3168 timevar_push (TV_JUMP);
3170 /* The previous call to loop_optimize makes some instructions
3171 trivially dead. We delete those instructions now in the
3172 hope that doing so will make the heuristics in jump work
3173 better and possibly speed up compilation. */
3174 delete_trivially_dead_insns (insns, max_reg_num (), 0);
3176 reg_scan (insns, max_reg_num (), 0);
3178 timevar_push (TV_IFCVT);
3180 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3181 cleanup_cfg (CLEANUP_EXPENSIVE);
3182 if_convert (0);
3184 timevar_pop(TV_IFCVT);
3186 timevar_pop (TV_JUMP);
3188 /* CFG is no longer maitained up-to-date. */
3189 free_bb_for_insn ();
3190 reg_scan (insns, max_reg_num (), 0);
3191 tem = cse_main (insns, max_reg_num (), 1, rtl_dump_file);
3193 if (tem)
3195 timevar_push (TV_JUMP);
3196 rebuild_jump_labels (insns);
3197 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3198 cleanup_cfg (CLEANUP_EXPENSIVE);
3199 /* CFG is no longer maitained up-to-date. */
3200 free_bb_for_insn ();
3201 timevar_pop (TV_JUMP);
3205 if (flag_thread_jumps)
3207 /* This pass of jump threading straightens out code
3208 that was kinked by loop optimization. */
3209 timevar_push (TV_JUMP);
3210 reg_scan (insns, max_reg_num (), 0);
3211 thread_jumps (insns, max_reg_num (), 0);
3212 timevar_pop (TV_JUMP);
3215 close_dump_file (DFI_cse2, print_rtl, insns);
3216 timevar_pop (TV_CSE2);
3218 ggc_collect ();
3221 cse_not_expected = 1;
3223 regclass_init ();
3225 /* Do control and data flow analysis; wrote some of the results to
3226 the dump file. */
3228 timevar_push (TV_FLOW);
3229 open_dump_file (DFI_cfg, decl);
3231 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3232 cleanup_cfg (optimize ? CLEANUP_EXPENSIVE : 0);
3233 check_function_return_warnings ();
3235 /* It may make more sense to mark constant functions after dead code is
3236 eliminated by life_analyzis, but we need to do it early, as -fprofile-arcs
3237 may insert code making function non-constant, but we still must consider
3238 it as constant, otherwise -fbranch-probabilities will not read data back.
3240 life_analyzis rarely eliminates modification of external memory.
3242 mark_constant_function ();
3244 close_dump_file (DFI_cfg, print_rtl_with_bb, insns);
3246 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
3248 timevar_push (TV_BRANCH_PROB);
3249 open_dump_file (DFI_bp, decl);
3251 branch_prob ();
3253 close_dump_file (DFI_bp, print_rtl_with_bb, insns);
3254 timevar_pop (TV_BRANCH_PROB);
3257 open_dump_file (DFI_life, decl);
3258 if (optimize)
3260 struct loops loops;
3262 /* Discover and record the loop depth at the head of each basic
3263 block. The loop infrastructure does the real job for us. */
3264 flow_loops_find (&loops, LOOP_TREE);
3266 /* Estimate using heuristics if no profiling info is available. */
3267 if (flag_guess_branch_prob)
3268 estimate_probability (&loops);
3270 if (rtl_dump_file)
3271 flow_loops_dump (&loops, rtl_dump_file, NULL, 0);
3273 flow_loops_free (&loops);
3275 life_analysis (insns, rtl_dump_file, PROP_FINAL);
3276 timevar_pop (TV_FLOW);
3278 no_new_pseudos = 1;
3280 if (warn_uninitialized || extra_warnings)
3282 uninitialized_vars_warning (DECL_INITIAL (decl));
3283 if (extra_warnings)
3284 setjmp_args_warning ();
3287 close_dump_file (DFI_life, print_rtl_with_bb, insns);
3289 ggc_collect ();
3291 /* If -opt, try combining insns through substitution. */
3293 if (optimize > 0)
3295 int rebuild_jump_labels_after_combine = 0;
3297 timevar_push (TV_COMBINE);
3298 open_dump_file (DFI_combine, decl);
3300 rebuild_jump_labels_after_combine
3301 = combine_instructions (insns, max_reg_num ());
3303 /* Always purge dead edges, as we may eliminate an insn throwing
3304 exception. */
3305 rebuild_jump_labels_after_combine |= purge_all_dead_edges (true);
3307 /* Combining insns may have turned an indirect jump into a
3308 direct jump. Rebuid the JUMP_LABEL fields of jumping
3309 instructions. */
3310 if (rebuild_jump_labels_after_combine)
3312 timevar_push (TV_JUMP);
3313 rebuild_jump_labels (insns);
3314 timevar_pop (TV_JUMP);
3316 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
3319 close_dump_file (DFI_combine, print_rtl_with_bb, insns);
3320 timevar_pop (TV_COMBINE);
3322 ggc_collect ();
3325 /* Rerun if-conversion, as combine may have simplified things enough to
3326 now meet sequence length restrictions. */
3327 if (optimize > 0)
3329 timevar_push (TV_IFCVT);
3330 open_dump_file (DFI_ce, decl);
3332 no_new_pseudos = 0;
3333 if_convert (1);
3334 no_new_pseudos = 1;
3336 close_dump_file (DFI_ce, print_rtl_with_bb, insns);
3337 timevar_pop (TV_IFCVT);
3340 /* Register allocation pre-pass, to reduce number of moves
3341 necessary for two-address machines. */
3342 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
3344 timevar_push (TV_REGMOVE);
3345 open_dump_file (DFI_regmove, decl);
3347 regmove_optimize (insns, max_reg_num (), rtl_dump_file);
3349 close_dump_file (DFI_regmove, print_rtl_with_bb, insns);
3350 timevar_pop (TV_REGMOVE);
3352 ggc_collect ();
3355 /* Do unconditional splitting before register allocation to allow machine
3356 description to add extra information not needed previously. */
3357 split_all_insns (1);
3359 /* Any of the several passes since flow1 will have munged register
3360 lifetime data a bit. */
3361 register_life_up_to_date = 0;
3363 #ifdef OPTIMIZE_MODE_SWITCHING
3364 timevar_push (TV_MODE_SWITCH);
3366 no_new_pseudos = 0;
3367 if (optimize_mode_switching (NULL))
3369 /* We did work, and so had to regenerate global life information.
3370 Take advantage of this and don't re-recompute register life
3371 information below. */
3372 register_life_up_to_date = 1;
3374 no_new_pseudos = 1;
3376 timevar_pop (TV_MODE_SWITCH);
3377 #endif
3379 timevar_push (TV_SCHED);
3381 #ifdef INSN_SCHEDULING
3383 /* Print function header into sched dump now
3384 because doing the sched analysis makes some of the dump. */
3385 if (optimize > 0 && flag_schedule_insns)
3387 open_dump_file (DFI_sched, decl);
3389 /* Do control and data sched analysis,
3390 and write some of the results to dump file. */
3392 schedule_insns (rtl_dump_file);
3394 close_dump_file (DFI_sched, print_rtl_with_bb, insns);
3396 /* Register lifetime information was updated as part of verifying
3397 the schedule. */
3398 register_life_up_to_date = 1;
3400 #endif
3401 timevar_pop (TV_SCHED);
3403 ggc_collect ();
3405 /* Determine if the current function is a leaf before running reload
3406 since this can impact optimizations done by the prologue and
3407 epilogue thus changing register elimination offsets. */
3408 current_function_is_leaf = leaf_function_p ();
3410 timevar_push (TV_LOCAL_ALLOC);
3411 open_dump_file (DFI_lreg, decl);
3413 /* Allocate pseudo-regs that are used only within 1 basic block.
3415 RUN_JUMP_AFTER_RELOAD records whether or not we need to rerun the
3416 jump optimizer after register allocation and reloading are finished. */
3418 if (! register_life_up_to_date)
3419 recompute_reg_usage (insns, ! optimize_size);
3421 /* Allocate the reg_renumber array. */
3422 allocate_reg_info (max_regno, FALSE, TRUE);
3424 /* And the reg_equiv_memory_loc array. */
3425 reg_equiv_memory_loc = (rtx *) xcalloc (max_regno, sizeof (rtx));
3427 allocate_initial_values (reg_equiv_memory_loc);
3429 regclass (insns, max_reg_num (), rtl_dump_file);
3430 rebuild_label_notes_after_reload = local_alloc ();
3432 timevar_pop (TV_LOCAL_ALLOC);
3434 if (dump_file[DFI_lreg].enabled)
3436 timevar_push (TV_DUMP);
3438 dump_flow_info (rtl_dump_file);
3439 dump_local_alloc (rtl_dump_file);
3441 close_dump_file (DFI_lreg, print_rtl_with_bb, insns);
3442 timevar_pop (TV_DUMP);
3445 ggc_collect ();
3447 timevar_push (TV_GLOBAL_ALLOC);
3448 open_dump_file (DFI_greg, decl);
3450 /* If optimizing, allocate remaining pseudo-regs. Do the reload
3451 pass fixing up any insns that are invalid. */
3453 if (optimize)
3454 failure = global_alloc (rtl_dump_file);
3455 else
3457 build_insn_chain (insns);
3458 failure = reload (insns, 0);
3461 timevar_pop (TV_GLOBAL_ALLOC);
3463 if (dump_file[DFI_greg].enabled)
3465 timevar_push (TV_DUMP);
3467 dump_global_regs (rtl_dump_file);
3469 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
3470 timevar_pop (TV_DUMP);
3473 if (failure)
3474 goto exit_rest_of_compilation;
3476 ggc_collect ();
3478 open_dump_file (DFI_postreload, decl);
3480 /* Do a very simple CSE pass over just the hard registers. */
3481 if (optimize > 0)
3483 timevar_push (TV_RELOAD_CSE_REGS);
3484 reload_cse_regs (insns);
3485 timevar_pop (TV_RELOAD_CSE_REGS);
3488 /* Register allocation and reloading may have turned an indirect jump into
3489 a direct jump. If so, we must rebuild the JUMP_LABEL fields of
3490 jumping instructions. */
3491 if (rebuild_label_notes_after_reload)
3493 timevar_push (TV_JUMP);
3495 rebuild_jump_labels (insns);
3497 timevar_pop (TV_JUMP);
3500 close_dump_file (DFI_postreload, print_rtl_with_bb, insns);
3502 /* Re-create the death notes which were deleted during reload. */
3503 timevar_push (TV_FLOW2);
3504 open_dump_file (DFI_flow2, decl);
3506 #ifdef ENABLE_CHECKING
3507 verify_flow_info ();
3508 #endif
3510 /* If optimizing, then go ahead and split insns now. */
3511 if (optimize > 0)
3512 split_all_insns (0);
3514 cleanup_cfg (optimize ? CLEANUP_EXPENSIVE : 0);
3516 /* On some machines, the prologue and epilogue code, or parts thereof,
3517 can be represented as RTL. Doing so lets us schedule insns between
3518 it and the rest of the code and also allows delayed branch
3519 scheduling to operate in the epilogue. */
3520 thread_prologue_and_epilogue_insns (insns);
3522 if (optimize)
3524 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_CROSSJUMP);
3525 life_analysis (insns, rtl_dump_file, PROP_FINAL);
3527 /* This is kind of a heuristic. We need to run combine_stack_adjustments
3528 even for machines with possibly nonzero RETURN_POPS_ARGS
3529 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
3530 push instructions will have popping returns. */
3531 #ifndef PUSH_ROUNDING
3532 if (!ACCUMULATE_OUTGOING_ARGS)
3533 #endif
3534 combine_stack_adjustments ();
3536 ggc_collect ();
3539 flow2_completed = 1;
3541 close_dump_file (DFI_flow2, print_rtl_with_bb, insns);
3542 timevar_pop (TV_FLOW2);
3544 #ifdef HAVE_peephole2
3545 if (optimize > 0 && flag_peephole2)
3547 timevar_push (TV_PEEPHOLE2);
3548 open_dump_file (DFI_peephole2, decl);
3550 peephole2_optimize (rtl_dump_file);
3552 close_dump_file (DFI_peephole2, print_rtl_with_bb, insns);
3553 timevar_pop (TV_PEEPHOLE2);
3555 #endif
3557 if (optimize > 0 && flag_rename_registers)
3559 timevar_push (TV_RENAME_REGISTERS);
3560 open_dump_file (DFI_rnreg, decl);
3562 regrename_optimize ();
3564 close_dump_file (DFI_rnreg, print_rtl_with_bb, insns);
3565 timevar_pop (TV_RENAME_REGISTERS);
3568 if (optimize > 0)
3570 timevar_push (TV_IFCVT2);
3571 open_dump_file (DFI_ce2, decl);
3573 if_convert (1);
3575 close_dump_file (DFI_ce2, print_rtl_with_bb, insns);
3576 timevar_pop (TV_IFCVT2);
3578 #ifdef STACK_REGS
3579 if (optimize)
3580 split_all_insns (1);
3581 #endif
3583 #ifdef INSN_SCHEDULING
3584 if (optimize > 0 && flag_schedule_insns_after_reload)
3586 timevar_push (TV_SCHED2);
3587 open_dump_file (DFI_sched2, decl);
3589 /* Do control and data sched analysis again,
3590 and write some more of the results to dump file. */
3592 split_all_insns (1);
3594 schedule_insns (rtl_dump_file);
3596 close_dump_file (DFI_sched2, print_rtl_with_bb, insns);
3597 timevar_pop (TV_SCHED2);
3599 ggc_collect ();
3601 #endif
3603 #ifdef LEAF_REGISTERS
3604 current_function_uses_only_leaf_regs
3605 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
3606 #endif
3608 #ifdef STACK_REGS
3609 timevar_push (TV_REG_STACK);
3610 open_dump_file (DFI_stack, decl);
3612 reg_to_stack (insns, rtl_dump_file);
3614 close_dump_file (DFI_stack, print_rtl_with_bb, insns);
3615 timevar_pop (TV_REG_STACK);
3617 ggc_collect ();
3618 #endif
3619 if (optimize > 0)
3621 timevar_push (TV_REORDER_BLOCKS);
3622 open_dump_file (DFI_bbro, decl);
3624 /* Last attempt to optimize CFG, as life analyzis possibly removed
3625 some instructions. */
3626 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
3627 | CLEANUP_CROSSJUMP);
3628 if (flag_reorder_blocks)
3630 reorder_basic_blocks ();
3631 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
3634 close_dump_file (DFI_bbro, print_rtl_with_bb, insns);
3635 timevar_pop (TV_REORDER_BLOCKS);
3637 compute_alignments ();
3639 /* CFG is no longer maitained up-to-date. */
3640 free_bb_for_insn ();
3642 /* If a machine dependent reorganization is needed, call it. */
3643 #ifdef MACHINE_DEPENDENT_REORG
3644 timevar_push (TV_MACH_DEP);
3645 open_dump_file (DFI_mach, decl);
3647 MACHINE_DEPENDENT_REORG (insns);
3649 close_dump_file (DFI_mach, print_rtl, insns);
3650 timevar_pop (TV_MACH_DEP);
3652 ggc_collect ();
3653 #endif
3655 purge_line_number_notes (insns);
3656 cleanup_barriers ();
3658 /* If a scheduling pass for delayed branches is to be done,
3659 call the scheduling code. */
3661 #ifdef DELAY_SLOTS
3662 if (optimize > 0 && flag_delayed_branch)
3664 timevar_push (TV_DBR_SCHED);
3665 open_dump_file (DFI_dbr, decl);
3667 dbr_schedule (insns, rtl_dump_file);
3669 close_dump_file (DFI_dbr, print_rtl, insns);
3670 timevar_pop (TV_DBR_SCHED);
3672 ggc_collect ();
3674 #endif
3676 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3677 timevar_push (TV_SHORTEN_BRANCH);
3678 split_all_insns_noflow ();
3679 timevar_pop (TV_SHORTEN_BRANCH);
3680 #endif
3682 convert_to_eh_region_ranges ();
3684 /* Shorten branches. */
3685 timevar_push (TV_SHORTEN_BRANCH);
3686 shorten_branches (get_insns ());
3687 timevar_pop (TV_SHORTEN_BRANCH);
3689 current_function_nothrow = nothrow_function_p ();
3690 if (current_function_nothrow)
3691 /* Now we know that this can't throw; set the flag for the benefit
3692 of other functions later in this translation unit. */
3693 TREE_NOTHROW (current_function_decl) = 1;
3695 /* Now turn the rtl into assembler code. */
3697 timevar_push (TV_FINAL);
3699 rtx x;
3700 const char *fnname;
3702 /* Get the function's name, as described by its RTL. This may be
3703 different from the DECL_NAME name used in the source file. */
3705 x = DECL_RTL (decl);
3706 if (GET_CODE (x) != MEM)
3707 abort ();
3708 x = XEXP (x, 0);
3709 if (GET_CODE (x) != SYMBOL_REF)
3710 abort ();
3711 fnname = XSTR (x, 0);
3713 assemble_start_function (decl, fnname);
3714 final_start_function (insns, asm_out_file, optimize);
3715 final (insns, asm_out_file, optimize, 0);
3716 final_end_function ();
3718 #ifdef IA64_UNWIND_INFO
3719 /* ??? The IA-64 ".handlerdata" directive must be issued before
3720 the ".endp" directive that closes the procedure descriptor. */
3721 output_function_exception_table ();
3722 #endif
3724 assemble_end_function (decl, fnname);
3726 #ifndef IA64_UNWIND_INFO
3727 /* Otherwise, it feels unclean to switch sections in the middle. */
3728 output_function_exception_table ();
3729 #endif
3731 if (! quiet_flag)
3732 fflush (asm_out_file);
3734 /* Release all memory allocated by flow. */
3735 free_basic_block_vars (0);
3737 /* Release all memory held by regsets now. */
3738 regset_release_memory ();
3740 timevar_pop (TV_FINAL);
3742 ggc_collect ();
3744 /* Write DBX symbols if requested. */
3746 /* Note that for those inline functions where we don't initially
3747 know for certain that we will be generating an out-of-line copy,
3748 the first invocation of this routine (rest_of_compilation) will
3749 skip over this code by doing a `goto exit_rest_of_compilation;'.
3750 Later on, finish_compilation will call rest_of_compilation again
3751 for those inline functions that need to have out-of-line copies
3752 generated. During that call, we *will* be routed past here. */
3754 timevar_push (TV_SYMOUT);
3755 (*debug_hooks->function_decl) (decl);
3756 timevar_pop (TV_SYMOUT);
3758 exit_rest_of_compilation:
3760 /* In case the function was not output,
3761 don't leave any temporary anonymous types
3762 queued up for sdb output. */
3763 #ifdef SDB_DEBUGGING_INFO
3764 if (write_symbols == SDB_DEBUG)
3765 sdbout_types (NULL_TREE);
3766 #endif
3768 reload_completed = 0;
3769 flow2_completed = 0;
3770 no_new_pseudos = 0;
3772 timevar_push (TV_FINAL);
3774 /* Clear out the insn_length contents now that they are no
3775 longer valid. */
3776 init_insn_lengths ();
3778 /* Clear out the real_constant_chain before some of the rtx's
3779 it runs through become garbage. */
3780 clear_const_double_mem ();
3782 /* Show no temporary slots allocated. */
3783 init_temp_slots ();
3785 free_basic_block_vars (0);
3787 timevar_pop (TV_FINAL);
3789 /* Make sure volatile mem refs aren't considered valid operands for
3790 arithmetic insns. We must call this here if this is a nested inline
3791 function, since the above code leaves us in the init_recog state
3792 (from final.c), and the function context push/pop code does not
3793 save/restore volatile_ok.
3795 ??? Maybe it isn't necessary for expand_start_function to call this
3796 anymore if we do it here? */
3798 init_recog_no_volatile ();
3800 /* We're done with this function. Free up memory if we can. */
3801 free_after_parsing (cfun);
3802 if (! DECL_DEFER_OUTPUT (decl))
3804 free_after_compilation (cfun);
3806 /* Clear integrate.c's pointer to the cfun structure we just
3807 destroyed. */
3808 DECL_SAVED_INSNS (decl) = 0;
3810 cfun = 0;
3812 ggc_collect ();
3814 timevar_pop (TV_REST_OF_COMPILATION);
3817 static void
3818 display_help ()
3820 int undoc;
3821 unsigned long i;
3822 const char *lang;
3824 printf (_(" -ffixed-<register> Mark <register> as being unavailable to the compiler\n"));
3825 printf (_(" -fcall-used-<register> Mark <register> as being corrupted by function calls\n"));
3826 printf (_(" -fcall-saved-<register> Mark <register> as being preserved across functions\n"));
3827 printf (_(" -finline-limit=<number> Limits the size of inlined functions to <number>\n"));
3828 printf (_(" -fmessage-length=<number> Limits diagnostics messages lengths to <number> characters per line. 0 suppresses line-wrapping\n"));
3829 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"));
3831 for (i = ARRAY_SIZE (f_options); i--;)
3833 const char *description = f_options[i].description;
3835 if (description != NULL && * description != 0)
3836 printf (" -f%-21s %s\n",
3837 f_options[i].string, _(description));
3840 printf (_(" -O[number] Set optimisation level to [number]\n"));
3841 printf (_(" -Os Optimise for space rather than speed\n"));
3842 for (i = LAST_PARAM; i--;)
3844 const char *description = compiler_params[i].help;
3845 const int length = 21-strlen(compiler_params[i].option);
3847 if (description != NULL && * description != 0)
3848 printf (" --param %s=<value>%.*s%s\n",
3849 compiler_params[i].option,
3850 length > 0 ? length : 1, " ",
3851 _(description));
3853 printf (_(" -pedantic Issue warnings needed by strict compliance to ISO C\n"));
3854 printf (_(" -pedantic-errors Like -pedantic except that errors are produced\n"));
3855 printf (_(" -w Suppress warnings\n"));
3856 printf (_(" -W Enable extra warnings\n"));
3858 for (i = ARRAY_SIZE (W_options); i--;)
3860 const char *description = W_options[i].description;
3862 if (description != NULL && * description != 0)
3863 printf (" -W%-21s %s\n",
3864 W_options[i].string, _(description));
3867 printf (_(" -Wunused Enable unused warnings\n"));
3868 printf (_(" -Wlarger-than-<number> Warn if an object is larger than <number> bytes\n"));
3869 printf (_(" -p Enable function profiling\n"));
3870 #if defined (BLOCK_PROFILER) || defined (FUNCTION_BLOCK_PROFILER)
3871 printf (_(" -a Enable block profiling \n"));
3872 #endif
3873 #if defined (BLOCK_PROFILER) || defined (FUNCTION_BLOCK_PROFILER) || defined FUNCTION_BLOCK_PROFILER_EXIT
3874 printf (_(" -ax Enable jump profiling \n"));
3875 #endif
3876 printf (_(" -o <file> Place output into <file> \n"));
3877 printf (_("\
3878 -G <number> Put global and static data smaller than <number>\n\
3879 bytes into a special section (on some targets)\n"));
3881 for (i = ARRAY_SIZE (debug_args); i--;)
3883 if (debug_args[i].description != NULL)
3884 printf (" -g%-21s %s\n",
3885 debug_args[i].arg, _(debug_args[i].description));
3888 printf (_(" -aux-info <file> Emit declaration info into <file>\n"));
3889 printf (_(" -quiet Do not display functions compiled or elapsed time\n"));
3890 printf (_(" -version Display the compiler's version\n"));
3891 printf (_(" -d[letters] Enable dumps from specific passes of the compiler\n"));
3892 printf (_(" -dumpbase <file> Base name to be used for dumps from specific passes\n"));
3893 #if defined INSN_SCHEDULING
3894 printf (_(" -fsched-verbose=<number> Set the verbosity level of the scheduler\n"));
3895 #endif
3896 printf (_(" --help Display this information\n"));
3898 undoc = 0;
3899 lang = "language";
3901 /* Display descriptions of language specific options.
3902 If there is no description, note that there is an undocumented option.
3903 If the description is empty, do not display anything. (This allows
3904 options to be deliberately undocumented, for whatever reason).
3905 If the option string is missing, then this is a marker, indicating
3906 that the description string is in fact the name of a language, whose
3907 language specific options are to follow. */
3909 if (ARRAY_SIZE (documented_lang_options) > 1)
3911 printf (_("\nLanguage specific options:\n"));
3913 for (i = 0; i < ARRAY_SIZE (documented_lang_options); i++)
3915 const char *description = documented_lang_options[i].description;
3916 const char *option = documented_lang_options[i].option;
3918 if (description == NULL)
3920 undoc = 1;
3922 if (extra_warnings)
3923 printf (_(" %-23.23s [undocumented]\n"), option);
3925 else if (*description == 0)
3926 continue;
3927 else if (option == NULL)
3929 if (undoc)
3930 printf
3931 (_("\nThere are undocumented %s specific options as well.\n"),
3932 lang);
3933 undoc = 0;
3935 printf (_("\n Options for %s:\n"), description);
3937 lang = description;
3939 else
3940 printf (" %-23.23s %s\n", option, _(description));
3944 if (undoc)
3945 printf (_("\nThere are undocumented %s specific options as well.\n"),
3946 lang);
3948 display_target_options ();
3951 static void
3952 display_target_options ()
3954 int undoc,i;
3956 if (ARRAY_SIZE (target_switches) > 1
3957 #ifdef TARGET_OPTIONS
3958 || ARRAY_SIZE (target_options) > 1
3959 #endif
3962 int doc = 0;
3964 undoc = 0;
3966 printf (_("\nTarget specific options:\n"));
3968 for (i = ARRAY_SIZE (target_switches); i--;)
3970 const char *option = target_switches[i].name;
3971 const char *description = target_switches[i].description;
3973 if (option == NULL || *option == 0)
3974 continue;
3975 else if (description == NULL)
3977 undoc = 1;
3979 if (extra_warnings)
3980 printf (_(" -m%-23.23s [undocumented]\n"), option);
3982 else if (* description != 0)
3983 doc += printf (" -m%-23.23s %s\n", option, _(description));
3986 #ifdef TARGET_OPTIONS
3987 for (i = ARRAY_SIZE (target_options); i--;)
3989 const char *option = target_options[i].prefix;
3990 const char *description = target_options[i].description;
3992 if (option == NULL || *option == 0)
3993 continue;
3994 else if (description == NULL)
3996 undoc = 1;
3998 if (extra_warnings)
3999 printf (_(" -m%-23.23s [undocumented]\n"), option);
4001 else if (* description != 0)
4002 doc += printf (" -m%-23.23s %s\n", option, _(description));
4004 #endif
4005 if (undoc)
4007 if (doc)
4008 printf (_("\nThere are undocumented target specific options as well.\n"));
4009 else
4010 printf (_(" They exist, but they are not documented.\n"));
4015 /* Parse a -d... command line switch. */
4017 static void
4018 decode_d_option (arg)
4019 const char *arg;
4021 int i, c, matched;
4023 while (*arg)
4024 switch (c = *arg++)
4026 case 'a':
4027 for (i = 0; i < (int) DFI_MAX; ++i)
4028 dump_file[i].enabled = 1;
4029 break;
4030 case 'A':
4031 flag_debug_asm = 1;
4032 break;
4033 case 'p':
4034 flag_print_asm_name = 1;
4035 break;
4036 case 'P':
4037 flag_dump_rtl_in_asm = 1;
4038 flag_print_asm_name = 1;
4039 break;
4040 case 'v':
4041 graph_dump_format = vcg;
4042 break;
4043 case 'x':
4044 rtl_dump_and_exit = 1;
4045 break;
4046 case 'y':
4047 set_yydebug (1);
4048 break;
4049 case 'D': /* These are handled by the preprocessor. */
4050 case 'I':
4051 break;
4053 default:
4054 matched = 0;
4055 for (i = 0; i < (int) DFI_MAX; ++i)
4056 if (c == dump_file[i].debug_switch)
4058 dump_file[i].enabled = 1;
4059 matched = 1;
4062 if (! matched)
4063 warning ("unrecognized gcc debugging option: %c", c);
4064 break;
4068 /* Parse a -f... command line switch. ARG is the value after the -f.
4069 It is safe to access 'ARG - 2' to generate the full switch name.
4070 Return the number of strings consumed. */
4072 static int
4073 decode_f_option (arg)
4074 const char *arg;
4076 int j;
4077 const char *option_value = NULL;
4079 /* Search for the option in the table of binary f options. */
4080 for (j = ARRAY_SIZE (f_options); j--;)
4082 if (!strcmp (arg, f_options[j].string))
4084 *f_options[j].variable = f_options[j].on_value;
4085 return 1;
4088 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-'
4089 && ! strcmp (arg + 3, f_options[j].string))
4091 *f_options[j].variable = ! f_options[j].on_value;
4092 return 1;
4096 if (!strcmp (arg, "fast-math"))
4097 set_fast_math_flags();
4098 else if (!strcmp (arg, "no-fast-math"))
4099 set_no_fast_math_flags();
4100 else if ((option_value = skip_leading_substring (arg, "inline-limit-"))
4101 || (option_value = skip_leading_substring (arg, "inline-limit=")))
4103 int val =
4104 read_integral_parameter (option_value, arg - 2,
4105 MAX_INLINE_INSNS);
4106 set_param_value ("max-inline-insns", val);
4108 #ifdef INSN_SCHEDULING
4109 else if ((option_value = skip_leading_substring (arg, "sched-verbose=")))
4110 fix_sched_param ("verbose", option_value);
4111 #endif
4112 else if ((option_value = skip_leading_substring (arg, "fixed-")))
4113 fix_register (option_value, 1, 1);
4114 else if ((option_value = skip_leading_substring (arg, "call-used-")))
4115 fix_register (option_value, 0, 1);
4116 else if ((option_value = skip_leading_substring (arg, "call-saved-")))
4117 fix_register (option_value, 0, 0);
4118 else if ((option_value = skip_leading_substring (arg, "align-loops=")))
4119 align_loops = read_integral_parameter (option_value, arg - 2, align_loops);
4120 else if ((option_value = skip_leading_substring (arg, "align-functions=")))
4121 align_functions
4122 = read_integral_parameter (option_value, arg - 2, align_functions);
4123 else if ((option_value = skip_leading_substring (arg, "align-jumps=")))
4124 align_jumps = read_integral_parameter (option_value, arg - 2, align_jumps);
4125 else if ((option_value = skip_leading_substring (arg, "align-labels=")))
4126 align_labels
4127 = read_integral_parameter (option_value, arg - 2, align_labels);
4128 else if ((option_value
4129 = skip_leading_substring (arg, "stack-limit-register=")))
4131 int reg = decode_reg_name (option_value);
4132 if (reg < 0)
4133 error ("unrecognized register name `%s'", option_value);
4134 else
4135 stack_limit_rtx = gen_rtx_REG (Pmode, reg);
4137 else if ((option_value
4138 = skip_leading_substring (arg, "stack-limit-symbol=")))
4140 const char *nm;
4141 nm = ggc_strdup (option_value);
4142 stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, nm);
4144 else if ((option_value
4145 = skip_leading_substring (arg, "message-length=")))
4146 output_set_maximum_length
4147 (&global_dc->buffer, read_integral_parameter
4148 (option_value, arg - 2, diagnostic_line_cutoff (global_dc)));
4149 else if ((option_value
4150 = skip_leading_substring (arg, "diagnostics-show-location=")))
4152 if (!strcmp (option_value, "once"))
4153 diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
4154 else if (!strcmp (option_value, "every-line"))
4155 diagnostic_prefixing_rule (global_dc)
4156 = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
4157 else
4158 error ("Unrecognized option `%s'", arg - 2);
4160 else if (!strcmp (arg, "no-stack-limit"))
4161 stack_limit_rtx = NULL_RTX;
4162 else if (!strcmp (arg, "preprocessed"))
4163 /* Recognise this switch but do nothing. This prevents warnings
4164 about an unrecognized switch if cpplib has not been linked in. */
4166 else
4167 return 0;
4169 return 1;
4172 /* Parse a -W... command line switch. ARG is the value after the -W.
4173 It is safe to access 'ARG - 2' to generate the full switch name.
4174 Return the number of strings consumed. */
4176 static int
4177 decode_W_option (arg)
4178 const char *arg;
4180 const char *option_value = NULL;
4181 int j;
4183 /* Search for the option in the table of binary W options. */
4185 for (j = ARRAY_SIZE (W_options); j--;)
4187 if (!strcmp (arg, W_options[j].string))
4189 *W_options[j].variable = W_options[j].on_value;
4190 return 1;
4193 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-'
4194 && ! strcmp (arg + 3, W_options[j].string))
4196 *W_options[j].variable = ! W_options[j].on_value;
4197 return 1;
4201 if ((option_value = skip_leading_substring (arg, "id-clash-")))
4202 warning ("-Wid-clash-LEN is no longer supported");
4203 else if ((option_value = skip_leading_substring (arg, "larger-than-")))
4205 larger_than_size = read_integral_parameter (option_value, arg - 2, -1);
4207 warn_larger_than = larger_than_size != -1;
4209 else if (!strcmp (arg, "unused"))
4211 set_Wunused (1);
4213 else if (!strcmp (arg, "no-unused"))
4215 set_Wunused (0);
4217 else
4218 return 0;
4220 return 1;
4223 /* Parse a -g... command line switch. ARG is the value after the -g.
4224 It is safe to access 'ARG - 2' to generate the full switch name.
4225 Return the number of strings consumed. */
4227 static int
4228 decode_g_option (arg)
4229 const char *arg;
4231 static unsigned level=0;
4232 /* A lot of code assumes write_symbols == NO_DEBUG if the
4233 debugging level is 0 (thus -gstabs1 -gstabs0 would lose track
4234 of what debugging type has been selected). This records the
4235 selected type. It is an error to specify more than one
4236 debugging type. */
4237 static enum debug_info_type selected_debug_type = NO_DEBUG;
4238 /* Non-zero if debugging format has been explicitly set.
4239 -g and -ggdb don't explicitly set the debugging format so
4240 -gdwarf -g3 is equivalent to -gdwarf3. */
4241 static int type_explicitly_set_p = 0;
4242 /* Indexed by enum debug_info_type. */
4243 static const char *const debug_type_names[] =
4245 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff"
4248 /* The maximum admissible debug level value. */
4249 static const unsigned max_debug_level = 3;
4251 /* Look up ARG in the table. */
4252 for (da = debug_args; da->arg; da++)
4254 const int da_len = strlen (da->arg);
4256 if (da_len == 0 || ! strncmp (arg, da->arg, da_len))
4258 enum debug_info_type type = da->debug_type;
4259 const char *p = arg + da_len;
4261 if (*p && ! ISDIGIT (*p))
4262 continue;
4264 /* A debug flag without a level defaults to level 2.
4265 Note we do not want to call read_integral_parameter
4266 for that case since it will call atoi which
4267 will return zero.
4269 ??? We may want to generalize the interface to
4270 read_integral_parameter to better handle this case
4271 if this case shows up often. */
4272 if (*p)
4273 level = read_integral_parameter (p, 0, max_debug_level + 1);
4274 else
4275 level = (level == 0) ? 2 : level;
4277 if (da_len > 1 && *p && !strncmp (arg, "dwarf", da_len))
4279 error ("use -gdwarf -g%d for DWARF v1, level %d",
4280 level, level);
4281 if (level == 2)
4282 error ("use -gdwarf-2 for DWARF v2");
4285 if (level > max_debug_level)
4287 warning ("\
4288 ignoring option `%s' due to invalid debug level specification",
4289 arg - 2);
4290 level = debug_info_level;
4293 if (type == NO_DEBUG)
4295 type = PREFERRED_DEBUGGING_TYPE;
4297 if (da_len > 1 && strncmp (arg, "gdb", da_len) == 0)
4299 #if defined (DWARF2_DEBUGGING_INFO) && !defined (LINKER_DOES_NOT_WORK_WITH_DWARF2)
4300 type = DWARF2_DEBUG;
4301 #else
4302 #ifdef DBX_DEBUGGING_INFO
4303 type = DBX_DEBUG;
4304 #endif
4305 #endif
4309 if (type == NO_DEBUG)
4310 warning ("`%s': unknown or unsupported -g option", arg - 2);
4312 /* Does it conflict with an already selected type? */
4313 if (type_explicitly_set_p
4314 /* -g/-ggdb don't conflict with anything. */
4315 && da->debug_type != NO_DEBUG
4316 && type != selected_debug_type)
4317 warning ("`%s' ignored, conflicts with `-g%s'",
4318 arg - 2, debug_type_names[(int) selected_debug_type]);
4319 else
4321 /* If the format has already been set, -g/-ggdb
4322 only change the debug level. */
4323 if (type_explicitly_set_p && da->debug_type == NO_DEBUG)
4324 /* Don't change debugging type. */
4326 else
4328 selected_debug_type = type;
4329 type_explicitly_set_p = da->debug_type != NO_DEBUG;
4332 write_symbols = (level == 0
4333 ? NO_DEBUG
4334 : selected_debug_type);
4335 use_gnu_debug_info_extensions = da->use_extensions_p;
4336 debug_info_level = (enum debug_info_level) level;
4339 break;
4343 if (! da->arg)
4344 return 0;
4346 return 1;
4349 /* Decode the first argument in the argv as a language-independent option.
4350 Return the number of strings consumed. */
4352 static unsigned int
4353 independent_decode_option (argc, argv)
4354 int argc;
4355 char **argv;
4357 char *arg = argv[0];
4359 if (arg[0] != '-' || arg[1] == 0)
4361 if (arg[0] == '+')
4362 return 0;
4364 filename = arg;
4366 return 1;
4369 arg++;
4371 if (!strcmp (arg, "-help"))
4373 display_help ();
4374 exit_after_options = 1;
4377 if (!strcmp (arg, "-target-help"))
4379 display_target_options ();
4380 exit_after_options = 1;
4383 if (!strcmp (arg, "-version"))
4385 print_version (stderr, "");
4386 exit_after_options = 1;
4389 /* Handle '--param <name>=<value>'. */
4390 if (strcmp (arg, "-param") == 0)
4392 char *equal;
4394 if (argc == 1)
4396 error ("-param option missing argument");
4397 return 1;
4400 /* Get the '<name>=<value>' parameter. */
4401 arg = argv[1];
4402 /* Look for the `='. */
4403 equal = strchr (arg, '=');
4404 if (!equal)
4405 error ("invalid --param option: %s", arg);
4406 else
4408 int val;
4410 /* Zero out the `=' sign so that we get two separate strings. */
4411 *equal = '\0';
4412 /* Figure out what value is specified. */
4413 val = read_integral_parameter (equal + 1, NULL, INVALID_PARAM_VAL);
4414 if (val != INVALID_PARAM_VAL)
4415 set_param_value (arg, val);
4416 else
4417 error ("invalid parameter value `%s'", equal + 1);
4420 return 2;
4423 if (*arg == 'Y')
4424 arg++;
4426 switch (*arg)
4428 default:
4429 return 0;
4431 case 'O':
4432 /* Already been treated in main (). Do nothing. */
4433 break;
4435 case 'm':
4436 set_target_switch (arg + 1);
4437 break;
4439 case 'f':
4440 return decode_f_option (arg + 1);
4442 case 'g':
4443 return decode_g_option (arg + 1);
4445 case 'd':
4446 if (!strcmp (arg, "dumpbase"))
4448 if (argc == 1)
4449 return 0;
4451 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 (arg[1] == 0)
4507 #if !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
4508 warning ("`-a' option (basic block profile) not supported");
4509 #else
4510 profile_block_flag = (profile_block_flag < 2) ? 1 : 3;
4511 #endif
4513 else if (!strcmp (arg, "ax"))
4515 #if !defined (FUNCTION_BLOCK_PROFILER_EXIT) || !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
4516 warning ("`-ax' option (jump profiling) not supported");
4517 #else
4518 profile_block_flag = (!profile_block_flag
4519 || profile_block_flag == 2) ? 2 : 3;
4520 #endif
4522 else if (!strncmp (arg, "aux-info", 8))
4524 if (arg[8] == '\0')
4526 if (argc == 1)
4527 return 0;
4529 aux_info_file_name = argv[1];
4530 flag_gen_aux_info = 1;
4531 return 2;
4533 else if (arg[8] == '=')
4535 aux_info_file_name = arg + 9;
4536 flag_gen_aux_info = 1;
4538 else
4539 return 0;
4541 else
4542 return 0;
4543 break;
4545 case 'o':
4546 if (arg[1] == 0)
4548 if (argc == 1)
4549 return 0;
4551 asm_file_name = argv[1];
4552 return 2;
4554 return 0;
4556 case 'G':
4558 int g_switch_val;
4559 int return_val;
4561 if (arg[1] == 0)
4563 if (argc == 1)
4564 return 0;
4566 g_switch_val = read_integral_parameter (argv[1], 0, -1);
4567 return_val = 2;
4569 else
4571 g_switch_val = read_integral_parameter (arg + 1, 0, -1);
4572 return_val = 1;
4575 if (g_switch_val == -1)
4576 return_val = 0;
4577 else
4579 g_switch_set = TRUE;
4580 g_switch_value = g_switch_val;
4583 return return_val;
4587 return 1;
4590 /* Entry point of cc1, cc1plus, jc1, f771, etc.
4591 Decode command args, then call compile_file.
4592 Exit code is FATAL_EXIT_CODE if can't open files or if there were
4593 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
4595 It is not safe to call this function more than once. */
4598 toplev_main (argc, argv)
4599 int argc;
4600 char **argv;
4602 int i;
4603 char *p;
4605 /* save in case md file wants to emit args as a comment. */
4606 save_argc = argc;
4607 save_argv = argv;
4609 p = argv[0] + strlen (argv[0]);
4610 while (p != argv[0] && !IS_DIR_SEPARATOR (p[-1]))
4611 --p;
4612 progname = p;
4614 xmalloc_set_program_name (progname);
4616 gcc_init_libintl ();
4618 /* Install handler for SIGFPE, which may be received while we do
4619 compile-time floating point arithmetic. */
4620 signal (SIGFPE, float_signal);
4622 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
4623 #ifdef SIGSEGV
4624 signal (SIGSEGV, crash_signal);
4625 #endif
4626 #ifdef SIGILL
4627 signal (SIGILL, crash_signal);
4628 #endif
4629 #ifdef SIGBUS
4630 signal (SIGBUS, crash_signal);
4631 #endif
4632 #ifdef SIGABRT
4633 signal (SIGABRT, crash_signal);
4634 #endif
4635 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
4636 signal (SIGIOT, crash_signal);
4637 #endif
4639 decl_printable_name = decl_name;
4640 lang_expand_expr = (lang_expand_expr_t) do_abort;
4642 /* Initialize whether `char' is signed. */
4643 flag_signed_char = DEFAULT_SIGNED_CHAR;
4644 #ifdef DEFAULT_SHORT_ENUMS
4645 /* Initialize how much space enums occupy, by default. */
4646 flag_short_enums = DEFAULT_SHORT_ENUMS;
4647 #endif
4649 /* Initialize the garbage-collector. */
4650 init_ggc ();
4651 init_stringpool ();
4652 ggc_add_rtx_root (&stack_limit_rtx, 1);
4653 ggc_add_tree_root (&current_function_decl, 1);
4654 ggc_add_tree_root (&current_function_func_begin_label, 1);
4656 /* Initialize the diagnostics reporting machinery. */
4657 diagnostic_initialize (global_dc);
4659 /* Register the language-independent parameters. */
4660 add_params (lang_independent_params, LAST_PARAM);
4662 /* Perform language-specific options intialization. */
4663 (*lang_hooks.init_options) ();
4665 /* Scan to see what optimization level has been specified. That will
4666 determine the default value of many flags. */
4667 for (i = 1; i < argc; i++)
4669 if (!strcmp (argv[i], "-O"))
4671 optimize = 1;
4672 optimize_size = 0;
4674 else if (argv[i][0] == '-' && argv[i][1] == 'O')
4676 /* Handle -Os, -O2, -O3, -O69, ... */
4677 char *p = &argv[i][2];
4679 if ((p[0] == 's') && (p[1] == 0))
4681 optimize_size = 1;
4683 /* Optimizing for size forces optimize to be 2. */
4684 optimize = 2;
4686 else
4688 const int optimize_val = read_integral_parameter (p, p - 2, -1);
4689 if (optimize_val != -1)
4691 optimize = optimize_val;
4692 optimize_size = 0;
4698 if (!optimize)
4700 flag_merge_constants = 0;
4703 if (optimize >= 1)
4705 flag_defer_pop = 1;
4706 flag_thread_jumps = 1;
4707 #ifdef DELAY_SLOTS
4708 flag_delayed_branch = 1;
4709 #endif
4710 #ifdef CAN_DEBUG_WITHOUT_FP
4711 flag_omit_frame_pointer = 1;
4712 #endif
4713 flag_guess_branch_prob = 1;
4716 if (optimize >= 2)
4718 flag_optimize_sibling_calls = 1;
4719 flag_cse_follow_jumps = 1;
4720 flag_cse_skip_blocks = 1;
4721 flag_gcse = 1;
4722 flag_expensive_optimizations = 1;
4723 flag_strength_reduce = 1;
4724 flag_rerun_cse_after_loop = 1;
4725 flag_rerun_loop_opt = 1;
4726 flag_caller_saves = 1;
4727 flag_force_mem = 1;
4728 flag_peephole2 = 1;
4729 #ifdef INSN_SCHEDULING
4730 flag_schedule_insns = 1;
4731 flag_schedule_insns_after_reload = 1;
4732 #endif
4733 flag_regmove = 1;
4734 flag_strict_aliasing = 1;
4735 flag_delete_null_pointer_checks = 1;
4736 flag_reorder_blocks = 1;
4739 if (optimize >= 3)
4741 flag_inline_functions = 1;
4742 flag_rename_registers = 1;
4745 if (optimize < 2 || optimize_size)
4747 align_loops = 1;
4748 align_jumps = 1;
4749 align_labels = 1;
4750 align_functions = 1;
4753 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
4754 modify it. */
4755 target_flags = 0;
4756 set_target_switch ("");
4758 /* Unwind tables are always present in an ABI-conformant IA-64
4759 object file, so the default should be ON. */
4760 #ifdef IA64_UNWIND_INFO
4761 flag_unwind_tables = IA64_UNWIND_INFO;
4762 #endif
4764 #ifdef OPTIMIZATION_OPTIONS
4765 /* Allow default optimizations to be specified on a per-machine basis. */
4766 OPTIMIZATION_OPTIONS (optimize, optimize_size);
4767 #endif
4769 /* Initialize register usage now so switches may override. */
4770 init_reg_sets ();
4772 /* Perform normal command line switch decoding. */
4773 for (i = 1; i < argc;)
4775 int lang_processed;
4776 int indep_processed;
4778 /* Give the language a chance to decode the option for itself. */
4779 lang_processed = (*lang_hooks.decode_option) (argc - i, argv + i);
4781 if (lang_processed >= 0)
4782 /* Now see if the option also has a language independent meaning.
4783 Some options are both language specific and language independent,
4784 eg --help. */
4785 indep_processed = independent_decode_option (argc - i, argv + i);
4786 else
4788 lang_processed = -lang_processed;
4789 indep_processed = 0;
4792 if (lang_processed || indep_processed)
4793 i += MAX (lang_processed, indep_processed);
4794 else
4796 const char *option = NULL;
4797 const char *lang = NULL;
4798 unsigned int j;
4800 /* It is possible that the command line switch is not valid for the
4801 current language, but it is valid for another language. In order
4802 to be compatible with previous versions of the compiler (which
4803 did not issue an error message in this case) we check for this
4804 possibility here. If we do find a match, then if extra_warnings
4805 is set we generate a warning message, otherwise we will just
4806 ignore the option. */
4807 for (j = 0; j < ARRAY_SIZE (documented_lang_options); j++)
4809 option = documented_lang_options[j].option;
4811 if (option == NULL)
4812 lang = documented_lang_options[j].description;
4813 else if (! strncmp (argv[i], option, strlen (option)))
4814 break;
4817 if (j != ARRAY_SIZE (documented_lang_options))
4819 if (extra_warnings)
4821 warning ("Ignoring command line option '%s'", argv[i]);
4822 if (lang)
4823 warning
4824 ("(It is valid for %s but not the selected language)",
4825 lang);
4828 else if (argv[i][0] == '-' && argv[i][1] == 'g')
4829 warning ("`%s': unknown or unsupported -g option", &argv[i][2]);
4830 else
4831 error ("Unrecognized option `%s'", argv[i]);
4833 i++;
4837 /* All command line options have been processed. */
4838 (*lang_hooks.post_options) ();
4840 if (exit_after_options)
4841 exit (0);
4843 /* Checker uses the frame pointer. */
4844 if (flag_check_memory_usage)
4845 flag_omit_frame_pointer = 0;
4847 if (optimize == 0)
4849 /* Inlining does not work if not optimizing,
4850 so force it not to be done. */
4851 flag_no_inline = 1;
4852 warn_inline = 0;
4854 /* The c_decode_option function and decode_option hook set
4855 this to `2' if -Wall is used, so we can avoid giving out
4856 lots of errors for people who don't realize what -Wall does. */
4857 if (warn_uninitialized == 1)
4858 warning ("-Wuninitialized is not supported without -O");
4861 /* We do not currently support sibling-call optimization in the
4862 presence of exceptions. See PR2975 for a test-case that will
4863 fail if we try to combine both of these features. */
4864 if (flag_exceptions)
4865 flag_optimize_sibling_calls = 0;
4867 #ifdef OVERRIDE_OPTIONS
4868 /* Some machines may reject certain combinations of options. */
4869 OVERRIDE_OPTIONS;
4870 #endif
4872 /* Set up the align_*_log variables, defaulting them to 1 if they
4873 were still unset. */
4874 if (align_loops <= 0) align_loops = 1;
4875 align_loops_log = floor_log2 (align_loops * 2 - 1);
4876 if (align_jumps <= 0) align_jumps = 1;
4877 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
4878 if (align_labels <= 0) align_labels = 1;
4879 align_labels_log = floor_log2 (align_labels * 2 - 1);
4880 if (align_functions <= 0) align_functions = 1;
4881 align_functions_log = floor_log2 (align_functions * 2 - 1);
4883 if (profile_block_flag == 3)
4885 warning ("`-ax' and `-a' are conflicting options. `-a' ignored.");
4886 profile_block_flag = 2;
4889 /* Unrolling all loops implies that standard loop unrolling must also
4890 be done. */
4891 if (flag_unroll_all_loops)
4892 flag_unroll_loops = 1;
4893 /* Loop unrolling requires that strength_reduction be on also. Silently
4894 turn on strength reduction here if it isn't already on. Also, the loop
4895 unrolling code assumes that cse will be run after loop, so that must
4896 be turned on also. */
4897 if (flag_unroll_loops)
4899 flag_strength_reduce = 1;
4900 flag_rerun_cse_after_loop = 1;
4903 if (flag_non_call_exceptions)
4904 flag_asynchronous_unwind_tables = 1;
4905 if (flag_asynchronous_unwind_tables)
4906 flag_unwind_tables = 1;
4908 /* Warn about options that are not supported on this machine. */
4909 #ifndef INSN_SCHEDULING
4910 if (flag_schedule_insns || flag_schedule_insns_after_reload)
4911 warning ("instruction scheduling not supported on this target machine");
4912 #endif
4913 #ifndef DELAY_SLOTS
4914 if (flag_delayed_branch)
4915 warning ("this target machine does not have delayed branches");
4916 #endif
4918 /* Some operating systems do not allow profiling without a frame
4919 pointer. */
4920 if (!TARGET_ALLOWS_PROFILING_WITHOUT_FRAME_POINTER
4921 && profile_flag
4922 && flag_omit_frame_pointer)
4924 error ("profiling does not work without a frame pointer");
4925 flag_omit_frame_pointer = 0;
4928 user_label_prefix = USER_LABEL_PREFIX;
4929 if (flag_leading_underscore != -1)
4931 /* If the default prefix is more complicated than "" or "_",
4932 issue a warning and ignore this option. */
4933 if (user_label_prefix[0] == 0 ||
4934 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
4936 user_label_prefix = flag_leading_underscore ? "_" : "";
4938 else
4939 warning ("-f%sleading-underscore not supported on this target machine",
4940 flag_leading_underscore ? "" : "no-");
4943 /* If we are in verbose mode, write out the version and maybe all the
4944 option flags in use. */
4945 if (version_flag)
4947 print_version (stderr, "");
4948 if (! quiet_flag)
4949 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
4952 compile_file (filename);
4954 if (errorcount)
4955 return (FATAL_EXIT_CODE);
4956 if (sorrycount)
4957 return (FATAL_EXIT_CODE);
4958 return (SUCCESS_EXIT_CODE);
4961 /* Decode -m switches. */
4962 /* Decode the switch -mNAME. */
4964 static void
4965 set_target_switch (name)
4966 const char *name;
4968 size_t j;
4969 int valid_target_option = 0;
4971 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
4972 if (!strcmp (target_switches[j].name, name))
4974 if (target_switches[j].value < 0)
4975 target_flags &= ~-target_switches[j].value;
4976 else
4977 target_flags |= target_switches[j].value;
4978 valid_target_option = 1;
4981 #ifdef TARGET_OPTIONS
4982 if (!valid_target_option)
4983 for (j = 0; j < ARRAY_SIZE (target_options); j++)
4985 int len = strlen (target_options[j].prefix);
4986 if (!strncmp (target_options[j].prefix, name, len))
4988 *target_options[j].variable = name + len;
4989 valid_target_option = 1;
4992 #endif
4994 if (!valid_target_option)
4995 error ("Invalid option `%s'", name);
4998 /* Print version information to FILE.
4999 Each line begins with INDENT (for the case where FILE is the
5000 assembler output file). */
5002 static void
5003 print_version (file, indent)
5004 FILE *file;
5005 const char *indent;
5007 #ifndef __VERSION__
5008 #define __VERSION__ "[?]"
5009 #endif
5010 fnotice (file,
5011 #ifdef __GNUC__
5012 "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
5013 #else
5014 "%s%s%s version %s (%s) compiled by CC.\n"
5015 #endif
5016 , indent, *indent != 0 ? " " : "",
5017 language_string, version_string, TARGET_NAME,
5018 indent, __VERSION__);
5021 /* Print an option value and return the adjusted position in the line.
5022 ??? We don't handle error returns from fprintf (disk full); presumably
5023 other code will catch a disk full though. */
5025 static int
5026 print_single_switch (file, pos, max, indent, sep, term, type, name)
5027 FILE *file;
5028 int pos, max;
5029 const char *indent, *sep, *term, *type, *name;
5031 /* The ultrix fprintf returns 0 on success, so compute the result we want
5032 here since we need it for the following test. */
5033 int len = strlen (sep) + strlen (type) + strlen (name);
5035 if (pos != 0
5036 && pos + len > max)
5038 fprintf (file, "%s", term);
5039 pos = 0;
5041 if (pos == 0)
5043 fprintf (file, "%s", indent);
5044 pos = strlen (indent);
5046 fprintf (file, "%s%s%s", sep, type, name);
5047 pos += len;
5048 return pos;
5051 /* Print active target switches to FILE.
5052 POS is the current cursor position and MAX is the size of a "line".
5053 Each line begins with INDENT and ends with TERM.
5054 Each switch is separated from the next by SEP. */
5056 static void
5057 print_switch_values (file, pos, max, indent, sep, term)
5058 FILE *file;
5059 int pos, max;
5060 const char *indent, *sep, *term;
5062 size_t j;
5063 char **p;
5065 /* Print the options as passed. */
5067 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
5068 _("options passed: "), "");
5070 for (p = &save_argv[1]; *p != NULL; p++)
5071 if (**p == '-')
5073 /* Ignore these. */
5074 if (strcmp (*p, "-o") == 0)
5076 if (p[1] != NULL)
5077 p++;
5078 continue;
5080 if (strcmp (*p, "-quiet") == 0)
5081 continue;
5082 if (strcmp (*p, "-version") == 0)
5083 continue;
5084 if ((*p)[1] == 'd')
5085 continue;
5087 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
5089 if (pos > 0)
5090 fprintf (file, "%s", term);
5092 /* Print the -f and -m options that have been enabled.
5093 We don't handle language specific options but printing argv
5094 should suffice. */
5096 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
5097 _("options enabled: "), "");
5099 for (j = 0; j < ARRAY_SIZE (f_options); j++)
5100 if (*f_options[j].variable == f_options[j].on_value)
5101 pos = print_single_switch (file, pos, max, indent, sep, term,
5102 "-f", f_options[j].string);
5104 /* Print target specific options. */
5106 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
5107 if (target_switches[j].name[0] != '\0'
5108 && target_switches[j].value > 0
5109 && ((target_switches[j].value & target_flags)
5110 == target_switches[j].value))
5112 pos = print_single_switch (file, pos, max, indent, sep, term,
5113 "-m", target_switches[j].name);
5116 #ifdef TARGET_OPTIONS
5117 for (j = 0; j < ARRAY_SIZE (target_options); j++)
5118 if (*target_options[j].variable != NULL)
5120 char prefix[256];
5121 sprintf (prefix, "-m%s", target_options[j].prefix);
5122 pos = print_single_switch (file, pos, max, indent, sep, term,
5123 prefix, *target_options[j].variable);
5125 #endif
5127 fprintf (file, "%s", term);