allow all arm targets to use -mstructure-size-boundary=XX
[official-gcc.git] / gcc / toplev.c
blob35f88d062f7df04a1461d3dc0e1fe5c43d770db8
1 /* Top level of GNU C compiler
2 Copyright (C) 1987, 88, 89, 92-98, 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* This is the top level of cc1/c++.
22 It parses command args, opens files, invokes the various passes
23 in the proper order, and counts the time used by each.
24 Error messages and low-level interface to malloc also handled here. */
26 #include "config.h"
27 #undef FLOAT /* This is for hpux. They should change hpux. */
28 #undef FFS /* Some systems define this in param.h. */
29 #include "system.h"
30 #include <signal.h>
31 #include <setjmp.h>
33 #ifdef HAVE_SYS_RESOURCE_H
34 # include <sys/resource.h>
35 #endif
37 #ifdef HAVE_SYS_TIMES_H
38 # include <sys/times.h>
39 #endif
41 #include "input.h"
42 #include "tree.h"
43 #include "rtl.h"
44 #include "tm_p.h"
45 #include "flags.h"
46 #include "insn-attr.h"
47 #include "insn-codes.h"
48 #include "insn-config.h"
49 #include "recog.h"
50 #include "defaults.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"
61 #ifdef DWARF_DEBUGGING_INFO
62 #include "dwarfout.h"
63 #endif
65 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
66 #include "dwarf2out.h"
67 #endif
69 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
70 #include "dbxout.h"
71 #endif
73 #ifdef SDB_DEBUGGING_INFO
74 #include "sdbout.h"
75 #endif
77 #ifdef XCOFF_DEBUGGING_INFO
78 #include "xcoffout.h"
79 #endif
81 #ifdef VMS
82 /* The extra parameters substantially improve the I/O performance. */
83 static FILE *
84 vms_fopen (fname, type)
85 char * fname;
86 char * type;
88 /* The <stdio.h> in the gcc-vms-1.42 distribution prototypes fopen with two
89 fixed arguments, which matches ANSI's specification but not VAXCRTL's
90 pre-ANSI implementation. This hack circumvents the mismatch problem. */
91 FILE *(*vmslib_fopen)() = (FILE *(*)()) fopen;
93 if (*type == 'w')
94 return (*vmslib_fopen) (fname, type, "mbc=32",
95 "deq=64", "fop=tef", "shr=nil");
96 else
97 return (*vmslib_fopen) (fname, type, "mbc=32");
99 #define fopen vms_fopen
100 #endif /* VMS */
102 #ifndef DEFAULT_GDB_EXTENSIONS
103 #define DEFAULT_GDB_EXTENSIONS 1
104 #endif
106 /* If more than one debugging type is supported, you must define
107 PREFERRED_DEBUGGING_TYPE to choose a format in a system-dependent way.
109 This is one long line cause VAXC can't handle a \-newline. */
110 #if 1 < (defined (DBX_DEBUGGING_INFO) + defined (SDB_DEBUGGING_INFO) + defined (DWARF_DEBUGGING_INFO) + defined (DWARF2_DEBUGGING_INFO) + defined (XCOFF_DEBUGGING_INFO))
111 #ifndef PREFERRED_DEBUGGING_TYPE
112 You Lose! You must define PREFERRED_DEBUGGING_TYPE!
113 #endif /* no PREFERRED_DEBUGGING_TYPE */
114 #else /* Only one debugging format supported. Define PREFERRED_DEBUGGING_TYPE
115 so the following code needn't care. */
116 #ifdef DBX_DEBUGGING_INFO
117 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
118 #endif
119 #ifdef SDB_DEBUGGING_INFO
120 #define PREFERRED_DEBUGGING_TYPE SDB_DEBUG
121 #endif
122 #ifdef DWARF_DEBUGGING_INFO
123 #define PREFERRED_DEBUGGING_TYPE DWARF_DEBUG
124 #endif
125 #ifdef DWARF2_DEBUGGING_INFO
126 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
127 #endif
128 #ifdef XCOFF_DEBUGGING_INFO
129 #define PREFERRED_DEBUGGING_TYPE XCOFF_DEBUG
130 #endif
131 #endif /* More than one debugger format enabled. */
133 /* If still not defined, must have been because no debugging formats
134 are supported. */
135 #ifndef PREFERRED_DEBUGGING_TYPE
136 #define PREFERRED_DEBUGGING_TYPE NO_DEBUG
137 #endif
139 #ifndef DIR_SEPARATOR
140 #define DIR_SEPARATOR '/'
141 #endif
143 #if ! (defined (VMS) || defined (OS2))
144 extern char **environ;
145 #endif
146 extern char *version_string;
148 /* Carry information from ASM_DECLARE_OBJECT_NAME
149 to ASM_FINISH_DECLARE_OBJECT. */
151 extern int size_directive_output;
152 extern tree last_assemble_variable_decl;
154 static void notice PVPROTO((const char *s, ...)) ATTRIBUTE_PRINTF_1;
155 static void set_target_switch PROTO((const char *));
156 static const char *decl_name PROTO((tree, int));
157 static void vmessage PROTO((const char *, const char *, va_list));
158 static void v_message_with_file_and_line PROTO((const char *, int, int,
159 const char *, va_list));
160 static void v_message_with_decl PROTO((tree, int, const char *, va_list));
161 static void file_and_line_for_asm PROTO((rtx, char **, int *));
162 static void v_error_with_file_and_line PROTO((const char *, int,
163 const char *, va_list));
164 static void v_error_with_decl PROTO((tree, const char *, va_list));
165 static void v_error_for_asm PROTO((rtx, const char *, va_list));
166 static void verror PROTO((const char *, va_list));
167 static void vfatal PROTO((const char *, va_list)) ATTRIBUTE_NORETURN;
168 static void v_warning_with_file_and_line PROTO ((const char *, int,
169 const char *, va_list));
170 static void v_warning_with_decl PROTO((tree, const char *, va_list));
171 static void v_warning_for_asm PROTO((rtx, const char *, va_list));
172 static void vwarning PROTO((const char *, va_list));
173 static void vpedwarn PROTO((const char *, va_list));
174 static void v_pedwarn_with_decl PROTO((tree, const char *, va_list));
175 static void v_pedwarn_with_file_and_line PROTO((const char *, int,
176 const char *, va_list));
177 static void vsorry PROTO((const char *, va_list));
178 extern void set_fatal_function PROTO((void (*)(const char *, va_list)));
179 static void float_signal PROTO((int)) ATTRIBUTE_NORETURN;
180 static void pipe_closed PROTO((int)) ATTRIBUTE_NORETURN;
181 #ifdef ASM_IDENTIFY_LANGUAGE
182 /* This might or might not be used in ASM_IDENTIFY_LANGUAGE. */
183 static void output_lang_identify PROTO((FILE *)) ATTRIBUTE_UNUSED;
184 #endif
185 static void open_dump_file PROTO((const char *, const char *));
186 static void close_dump_file PROTO((void (*) (FILE *, rtx), rtx));
187 static void dump_rtl PROTO((const char *, tree, void (*) (FILE *, rtx), rtx));
188 static void clean_dump_file PROTO((const char *));
189 static void compile_file PROTO((char *));
190 static void display_help PROTO ((void));
191 static void report_file_and_line PROTO ((const char *, int, int));
192 static void vnotice PROTO ((FILE *, const char *, va_list));
193 static void mark_file_stack PROTO ((void *));
195 static void decode_d_option PROTO ((const char *));
196 static int decode_f_option PROTO ((const char *));
197 static int decode_W_option PROTO ((const char *));
198 static int decode_g_option PROTO ((const char *));
199 static unsigned independent_decode_option PROTO ((int, char **, unsigned));
201 static void print_version PROTO((FILE *, const char *));
202 static int print_single_switch PROTO((FILE *, int, int, const char *,
203 const char *, const char *,
204 const char *, const char *));
205 static void print_switch_values PROTO((FILE *, int, int, const char *,
206 const char *, const char *));
208 /* Length of line when printing switch values. */
209 #define MAX_LINE 75
211 /* Name of program invoked, sans directories. */
213 const char *progname;
215 /* Copy of arguments to main. */
216 int save_argc;
217 char **save_argv;
219 /* Name of current original source file (what was input to cpp).
220 This comes from each #-command in the actual input. */
222 char *input_filename;
224 /* Name of top-level original source file (what was input to cpp).
225 This comes from the #-command at the beginning of the actual input.
226 If there isn't any there, then this is the cc1 input file name. */
228 char *main_input_filename;
230 /* Current line number in real source file. */
232 int lineno;
234 /* Nonzero if it is unsafe to create any new pseudo registers. */
235 int no_new_pseudos;
237 /* Stack of currently pending input files. */
239 struct file_stack *input_file_stack;
241 /* Incremented on each change to input_file_stack. */
242 int input_file_stack_tick;
244 /* Name to use as base of names for dump output files. */
246 const char *dump_base_name;
248 /* Bit flags that specify the machine subtype we are compiling for.
249 Bits are tested using macros TARGET_... defined in the tm.h file
250 and set by `-m...' switches. Must be defined in rtlanal.c. */
252 extern int target_flags;
254 /* Flags saying which kinds of debugging dump have been requested. */
256 int rtl_dump = 0;
257 int rtl_dump_and_exit = 0;
258 int jump_opt_dump = 0;
259 int addressof_dump = 0;
260 int cse_dump = 0;
261 int gcse_dump = 0;
262 int loop_dump = 0;
263 int cse2_dump = 0;
264 int branch_prob_dump = 0;
265 int flow_dump = 0;
266 int combine_dump = 0;
267 int regmove_dump = 0;
268 int sched_dump = 0;
269 int local_reg_dump = 0;
270 int global_reg_dump = 0;
271 int flow2_dump = 0;
272 int peephole2_dump = 0;
273 int sched2_dump = 0;
274 int jump2_opt_dump = 0;
275 #ifdef DELAY_SLOTS
276 int dbr_sched_dump = 0;
277 #endif
278 int flag_print_asm_name = 0;
279 #ifdef STACK_REGS
280 int stack_reg_dump = 0;
281 #endif
282 #ifdef MACHINE_DEPENDENT_REORG
283 int mach_dep_reorg_dump = 0;
284 #endif
285 static int flag_print_mem = 0;
286 static int version_flag = 0;
287 static char * filename = 0;
288 enum graph_dump_types graph_dump_format;
290 /* Name for output file of assembly code, specified with -o. */
292 char *asm_file_name;
294 /* Value of the -G xx switch, and whether it was passed or not. */
295 int g_switch_value;
296 int g_switch_set;
298 /* Type(s) of debugging information we are producing (if any).
299 See flags.h for the definitions of the different possible
300 types of debugging information. */
301 enum debug_info_type write_symbols = NO_DEBUG;
303 /* Level of debugging information we are producing. See flags.h
304 for the definitions of the different possible levels. */
305 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
307 /* Nonzero means use GNU-only extensions in the generated symbolic
308 debugging information. */
309 /* Currently, this only has an effect when write_symbols is set to
310 DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
311 int use_gnu_debug_info_extensions = 0;
313 /* Nonzero means do optimizations. -O.
314 Particular numeric values stand for particular amounts of optimization;
315 thus, -O2 stores 2 here. However, the optimizations beyond the basic
316 ones are not controlled directly by this variable. Instead, they are
317 controlled by individual `flag_...' variables that are defaulted
318 based on this variable. */
320 int optimize = 0;
322 /* Nonzero means optimize for size. -Os.
323 The only valid values are zero and non-zero. When optimize_size is
324 non-zero, optimize defaults to 2, but certain individual code
325 bloating optimizations are disabled. */
327 int optimize_size = 0;
329 /* Number of error messages and warning messages so far. */
331 int errorcount = 0;
332 int warningcount = 0;
333 int sorrycount = 0;
335 /* Pointer to function to compute the name to use to print a declaration.
336 DECL is the declaration in question.
337 VERBOSITY determines what information will be printed:
338 0: DECL_NAME, demangled as necessary.
339 1: and scope information.
340 2: and any other information that might be interesting, such as function
341 parameter types in C++. */
343 const char *(*decl_printable_name) PROTO ((tree, int));
345 /* Pointer to function to compute rtl for a language-specific tree code. */
347 typedef rtx (*lang_expand_expr_t)
348 PROTO ((union tree_node *, rtx, enum machine_mode,
349 enum expand_modifier modifier));
351 lang_expand_expr_t lang_expand_expr = 0;
353 tree (*lang_expand_constant) PROTO((tree)) = 0;
355 /* Pointer to function to finish handling an incomplete decl at the
356 end of compilation. */
358 void (*incomplete_decl_finalize_hook) PROTO((tree)) = 0;
360 /* Nonzero if generating code to do profiling. */
362 int profile_flag = 0;
364 /* Nonzero if generating code to do profiling on a line-by-line basis. */
366 int profile_block_flag;
368 /* Nonzero if generating code to profile program flow graph arcs. */
370 int profile_arc_flag = 0;
372 /* Nonzero if generating info for gcov to calculate line test coverage. */
374 int flag_test_coverage = 0;
376 /* Nonzero indicates that branch taken probabilities should be calculated. */
378 int flag_branch_probabilities = 0;
380 /* Nonzero for -pedantic switch: warn about anything
381 that standard spec forbids. */
383 int pedantic = 0;
385 /* Temporarily suppress certain warnings.
386 This is set while reading code from a system header file. */
388 int in_system_header = 0;
390 /* Nonzero means do stupid register allocation.
391 Currently, this is 1 if `optimize' is 0. */
393 int obey_regdecls = 0;
395 /* Don't print functions as they are compiled and don't print
396 times taken by the various passes. -quiet. */
398 int quiet_flag = 0;
400 /* -f flags. */
402 /* Nonzero means `char' should be signed. */
404 int flag_signed_char;
406 /* Nonzero means give an enum type only as many bytes as it needs. */
408 int flag_short_enums;
410 /* Nonzero for -fcaller-saves: allocate values in regs that need to
411 be saved across function calls, if that produces overall better code.
412 Optional now, so people can test it. */
414 #ifdef DEFAULT_CALLER_SAVES
415 int flag_caller_saves = 1;
416 #else
417 int flag_caller_saves = 0;
418 #endif
420 /* Nonzero if structures and unions should be returned in memory.
422 This should only be defined if compatibility with another compiler or
423 with an ABI is needed, because it results in slower code. */
425 #ifndef DEFAULT_PCC_STRUCT_RETURN
426 #define DEFAULT_PCC_STRUCT_RETURN 1
427 #endif
429 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
431 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
433 /* Nonzero for -fforce-mem: load memory value into a register
434 before arithmetic on it. This makes better cse but slower compilation. */
436 int flag_force_mem = 0;
438 /* Nonzero for -fforce-addr: load memory address into a register before
439 reference to memory. This makes better cse but slower compilation. */
441 int flag_force_addr = 0;
443 /* Nonzero for -fdefer-pop: don't pop args after each function call;
444 instead save them up to pop many calls' args with one insns. */
446 int flag_defer_pop = 0;
448 /* Nonzero for -ffloat-store: don't allocate floats and doubles
449 in extended-precision registers. */
451 int flag_float_store = 0;
453 /* Nonzero for -fcse-follow-jumps:
454 have cse follow jumps to do a more extensive job. */
456 int flag_cse_follow_jumps;
458 /* Nonzero for -fcse-skip-blocks:
459 have cse follow a branch around a block. */
460 int flag_cse_skip_blocks;
462 /* Nonzero for -fexpensive-optimizations:
463 perform miscellaneous relatively-expensive optimizations. */
464 int flag_expensive_optimizations;
466 /* Nonzero for -fthread-jumps:
467 have jump optimize output of loop. */
469 int flag_thread_jumps;
471 /* Nonzero enables strength-reduction in loop.c. */
473 int flag_strength_reduce = 0;
475 /* Nonzero enables loop unrolling in unroll.c. Only loops for which the
476 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
477 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
478 unrolled. */
480 int flag_unroll_loops;
482 /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
483 This is generally not a win. */
485 int flag_unroll_all_loops;
487 /* Nonzero forces all invariant computations in loops to be moved
488 outside the loop. */
490 int flag_move_all_movables = 0;
492 /* Nonzero forces all general induction variables in loops to be
493 strength reduced. */
495 int flag_reduce_all_givs = 0;
497 /* Nonzero to perform full register move optimization passes. This is the
498 default for -O2. */
500 int flag_regmove = 0;
502 /* Nonzero for -fwritable-strings:
503 store string constants in data segment and don't uniquize them. */
505 int flag_writable_strings = 0;
507 /* Nonzero means don't put addresses of constant functions in registers.
508 Used for compiling the Unix kernel, where strange substitutions are
509 done on the assembly output. */
511 int flag_no_function_cse = 0;
513 /* Nonzero for -fomit-frame-pointer:
514 don't make a frame pointer in simple functions that don't require one. */
516 int flag_omit_frame_pointer = 0;
518 /* Nonzero means place each function into its own section on those platforms
519 which support arbitrary section names and unlimited numbers of sections. */
521 int flag_function_sections = 0;
523 /* ... and similar for data. */
525 int flag_data_sections = 0;
527 /* Nonzero to inhibit use of define_optimization peephole opts. */
529 int flag_no_peephole = 0;
531 /* Nonzero allows GCC to violate some IEEE or ANSI rules regarding math
532 operations in the interest of optimization. For example it allows
533 GCC to assume arguments to sqrt are nonnegative numbers, allowing
534 faster code for sqrt to be generated. */
536 int flag_fast_math = 0;
538 /* Nonzero means the front end generally wants `errno' maintained by math
539 operations, like built-in SQRT, unless overridden by flag_fast_math. */
541 int flag_errno_math = 1;
543 /* 0 means straightforward implementation of complex divide acceptable.
544 1 means wide ranges of inputs must work for complex divide.
545 2 means C9X-like requirements for complex divide (not yet implemented). */
547 int flag_complex_divide_method = 0;
549 /* Nonzero means all references through pointers are volatile. */
551 int flag_volatile;
553 /* Nonzero means treat all global and extern variables as volatile. */
555 int flag_volatile_global;
557 /* Nonzero means treat all static variables as volatile. */
559 int flag_volatile_static;
561 /* Nonzero means just do syntax checking; don't output anything. */
563 int flag_syntax_only = 0;
565 /* Nonzero means perform global cse. */
567 static int flag_gcse;
569 /* Nonzero means to use global dataflow analysis to eliminate
570 useless null pointer tests. */
572 static int flag_delete_null_pointer_checks;
574 /* Nonzero means to rerun cse after loop optimization. This increases
575 compilation time about 20% and picks up a few more common expressions. */
577 static int flag_rerun_cse_after_loop;
579 /* Nonzero means to run loop optimizations twice. */
581 int flag_rerun_loop_opt;
583 /* Nonzero for -finline-functions: ok to inline functions that look like
584 good inline candidates. */
586 int flag_inline_functions;
588 /* Nonzero for -fkeep-inline-functions: even if we make a function
589 go inline everywhere, keep its definition around for debugging
590 purposes. */
592 int flag_keep_inline_functions;
594 /* Nonzero means that functions will not be inlined. */
596 int flag_no_inline;
598 /* Nonzero means that we should emit static const variables
599 regardless of whether or not optimization is turned on. */
601 int flag_keep_static_consts = 1;
603 /* Nonzero means we should be saving declaration info into a .X file. */
605 int flag_gen_aux_info = 0;
607 /* Specified name of aux-info file. */
609 static char *aux_info_file_name;
611 /* Nonzero means make the text shared if supported. */
613 int flag_shared_data;
615 /* Nonzero means schedule into delayed branch slots if supported. */
617 int flag_delayed_branch;
619 /* Nonzero if we are compiling pure (sharable) code.
620 Value is 1 if we are doing reasonable (i.e. simple
621 offset into offset table) pic. Value is 2 if we can
622 only perform register offsets. */
624 int flag_pic;
626 /* Nonzero means generate extra code for exception handling and enable
627 exception handling. */
629 int flag_exceptions;
631 /* Nonzero means use the new model for exception handling. Replaces
632 -DNEW_EH_MODEL as a compile option. */
634 int flag_new_exceptions = 1;
636 /* Nonzero means don't place uninitialized global data in common storage
637 by default. */
639 int flag_no_common;
641 /* Nonzero means pretend it is OK to examine bits of target floats,
642 even if that isn't true. The resulting code will have incorrect constants,
643 but the same series of instructions that the native compiler would make. */
645 int flag_pretend_float;
647 /* Nonzero means change certain warnings into errors.
648 Usually these are warnings about failure to conform to some standard. */
650 int flag_pedantic_errors = 0;
652 /* flag_schedule_insns means schedule insns within basic blocks (before
653 local_alloc).
654 flag_schedule_insns_after_reload means schedule insns after
655 global_alloc. */
657 int flag_schedule_insns = 0;
658 int flag_schedule_insns_after_reload = 0;
660 /* The following flags have effect only for scheduling before register
661 allocation:
663 flag_schedule_interblock means schedule insns accross basic blocks.
664 flag_schedule_speculative means allow speculative motion of non-load insns.
665 flag_schedule_speculative_load means allow speculative motion of some
666 load insns.
667 flag_schedule_speculative_load_dangerous allows speculative motion of more
668 load insns. */
670 int flag_schedule_interblock = 1;
671 int flag_schedule_speculative = 1;
672 int flag_schedule_speculative_load = 0;
673 int flag_schedule_speculative_load_dangerous = 0;
675 /* flag_on_branch_count_reg means try to replace add-1,compare,branch tupple
676 by a cheaper branch, on a count register. */
677 int flag_branch_on_count_reg;
679 /* -finhibit-size-directive inhibits output of .size for ELF.
680 This is used only for compiling crtstuff.c,
681 and it may be extended to other effects
682 needed for crtstuff.c on other systems. */
683 int flag_inhibit_size_directive = 0;
685 /* -fverbose-asm causes extra commentary information to be produced in
686 the generated assembly code (to make it more readable). This option
687 is generally only of use to those who actually need to read the
688 generated assembly code (perhaps while debugging the compiler itself).
689 -fno-verbose-asm, the default, causes the extra information
690 to be omitted and is useful when comparing two assembler files. */
692 int flag_verbose_asm = 0;
694 /* -dA causes debug commentary information to be produced in
695 the generated assembly code (to make it more readable). This option
696 is generally only of use to those who actually need to read the
697 generated assembly code (perhaps while debugging the compiler itself).
698 Currently, this switch is only used by dwarfout.c; however, it is intended
699 to be a catchall for printing debug information in the assembler file. */
701 int flag_debug_asm = 0;
703 /* -fgnu-linker specifies use of the GNU linker for initializations.
704 (Or, more generally, a linker that handles initializations.)
705 -fno-gnu-linker says that collect2 will be used. */
706 #ifdef USE_COLLECT2
707 int flag_gnu_linker = 0;
708 #else
709 int flag_gnu_linker = 1;
710 #endif
712 /* Tag all structures with __attribute__(packed) */
713 int flag_pack_struct = 0;
715 /* Emit code to check for stack overflow; also may cause large objects
716 to be allocated dynamically. */
717 int flag_stack_check;
719 /* -fcheck-memory-usage causes extra code to be generated in order to check
720 memory accesses. This is used by a detector of bad memory accesses such
721 as Checker. */
722 int flag_check_memory_usage = 0;
724 /* -fprefix-function-name causes function name to be prefixed. This
725 can be used with -fcheck-memory-usage to isolate code compiled with
726 -fcheck-memory-usage. */
727 int flag_prefix_function_name = 0;
729 /* 0 if pointer arguments may alias each other. True in C.
730 1 if pointer arguments may not alias each other but may alias
731 global variables.
732 2 if pointer arguments may not alias each other and may not
733 alias global variables. True in Fortran.
734 This defaults to 0 for C. */
735 int flag_argument_noalias = 0;
737 /* Nonzero if we should do (language-dependent) alias analysis.
738 Typically, this analysis will assume that expressions of certain
739 types do not alias expressions of certain other types. Only used
740 if alias analysis (in general) is enabled. */
741 int flag_strict_aliasing = 0;
743 /* Instrument functions with calls at entry and exit, for profiling. */
744 int flag_instrument_function_entry_exit = 0;
746 /* Nonzero means ignore `#ident' directives. 0 means handle them.
747 On SVR4 targets, it also controls whether or not to emit a
748 string identifying the compiler. */
750 int flag_no_ident = 0;
752 /* This will perform a peephole pass before sched2. */
753 int flag_peephole2 = 0;
755 /* -fbounded-pointers causes gcc to compile pointers as composite
756 objects occupying three words: the pointer value, the base address
757 of the referent object, and the address immediately beyond the end
758 of the referent object. The base and extent allow us to perform
759 runtime bounds checking. -fbounded-pointers implies -fcheck-bounds. */
760 int flag_bounded_pointers = 0;
762 /* -fcheck-bounds causes gcc to generate array bounds checks.
763 For C, C++: defaults to value of flag_bounded_pointers.
764 For ObjC: defaults to off.
765 For Java: defaults to on.
766 For Fortran: defaults to off.
767 For CHILL: defaults to off. */
768 int flag_bounds_check = 0;
770 /* Values of the -falign-* flags: how much to align labels in code.
771 0 means `use default', 1 means `don't align'.
772 For each variable, there is an _log variant which is the power
773 of two not less than the variable, for .align output. */
775 int align_loops;
776 int align_loops_log;
777 int align_jumps;
778 int align_jumps_log;
779 int align_labels;
780 int align_labels_log;
781 int align_functions;
782 int align_functions_log;
784 /* Table of supported debugging formats. */
785 static struct
787 const char * arg;
788 /* Since PREFERRED_DEBUGGING_TYPE isn't necessarily a
789 constant expression, we use NO_DEBUG in its place. */
790 enum debug_info_type debug_type;
791 int use_extensions_p;
792 const char * description;
793 } *da,
794 debug_args[] =
796 { "", NO_DEBUG, DEFAULT_GDB_EXTENSIONS,
797 "Generate default debug format output" },
798 { "gdb", NO_DEBUG, 1, "Generate default extended debug format output" },
799 #ifdef DBX_DEBUGGING_INFO
800 { "stabs", DBX_DEBUG, 0, "Generate STABS format debug output" },
801 { "stabs+", DBX_DEBUG, 1, "Generate extended STABS format debug output" },
802 #endif
803 #ifdef DWARF_DEBUGGING_INFO
804 { "dwarf", DWARF_DEBUG, 0, "Generate DWARF-1 format debug output"},
805 { "dwarf+", DWARF_DEBUG, 1,
806 "Generated extended DWARF-1 format debug output" },
807 #endif
808 #ifdef DWARF2_DEBUGGING_INFO
809 { "dwarf-2", DWARF2_DEBUG, 0, "Enable DWARF-2 debug output" },
810 #endif
811 #ifdef XCOFF_DEBUGGING_INFO
812 { "xcoff", XCOFF_DEBUG, 0, "Generate XCOFF format debug output" },
813 { "xcoff+", XCOFF_DEBUG, 1, "Generate extended XCOFF format debug output" },
814 #endif
815 #ifdef SDB_DEBUGGING_INFO
816 { "coff", SDB_DEBUG, 0, "Generate COFF format debug output" },
817 #endif
818 { 0, 0, 0, 0 }
821 typedef struct
823 const char * string;
824 int * variable;
825 int on_value;
826 const char * description;
828 lang_independent_options;
830 /* Add or remove a leading underscore from user symbols. */
831 int flag_leading_underscore = -1;
833 /* The user symbol prefix after having resolved same. */
834 const char *user_label_prefix;
836 /* A default for same. */
837 #ifndef USER_LABEL_PREFIX
838 #define USER_LABEL_PREFIX ""
839 #endif
841 /* Table of language-independent -f options.
842 STRING is the option name. VARIABLE is the address of the variable.
843 ON_VALUE is the value to store in VARIABLE
844 if `-fSTRING' is seen as an option.
845 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
847 lang_independent_options f_options[] =
849 {"float-store", &flag_float_store, 1,
850 "Do not store floats in registers" },
851 {"volatile", &flag_volatile, 1,
852 "Consider all mem refs through pointers as volatile"},
853 {"volatile-global", &flag_volatile_global, 1,
854 "Consider all mem refs to global data to be volatile" },
855 {"volatile-static", &flag_volatile_static, 1,
856 "Consider all mem refs to static data to be volatile" },
857 {"defer-pop", &flag_defer_pop, 1,
858 "Defer popping functions args from stack until later" },
859 {"omit-frame-pointer", &flag_omit_frame_pointer, 1,
860 "When possible do not generate stack frames"},
861 {"cse-follow-jumps", &flag_cse_follow_jumps, 1,
862 "When running CSE, follow jumps to their targets" },
863 {"cse-skip-blocks", &flag_cse_skip_blocks, 1,
864 "When running CSE, follow conditional jumps" },
865 {"expensive-optimizations", &flag_expensive_optimizations, 1,
866 "Perform a number of minor, expensive optimisations" },
867 {"thread-jumps", &flag_thread_jumps, 1,
868 "Perform jump threading optimisations"},
869 {"strength-reduce", &flag_strength_reduce, 1,
870 "Perform strength reduction optimisations" },
871 {"unroll-loops", &flag_unroll_loops, 1,
872 "Perform loop unrolling when iteration count is known" },
873 {"unroll-all-loops", &flag_unroll_all_loops, 1,
874 "Perform loop unrolling for all loops" },
875 {"move-all-movables", &flag_move_all_movables, 1,
876 "Force all loop invariant computations out of loops" },
877 {"reduce-all-givs", &flag_reduce_all_givs, 1,
878 "Strength reduce all loop general induction variables" },
879 {"writable-strings", &flag_writable_strings, 1,
880 "Store strings in writable data section" },
881 {"peephole", &flag_no_peephole, 0,
882 "Enable machine specific peephole optimisations" },
883 {"force-mem", &flag_force_mem, 1,
884 "Copy memory operands into registers before using" },
885 {"force-addr", &flag_force_addr, 1,
886 "Copy memory address constants into regs before using" },
887 {"function-cse", &flag_no_function_cse, 0,
888 "Allow function addresses to be held in registers" },
889 {"inline-functions", &flag_inline_functions, 1,
890 "Integrate simple functions into their callers" },
891 {"keep-inline-functions", &flag_keep_inline_functions, 1,
892 "Generate code for funcs even if they are fully inlined" },
893 {"inline", &flag_no_inline, 0,
894 "Pay attention to the 'inline' keyword"},
895 {"keep-static-consts", &flag_keep_static_consts, 1,
896 "Emit static const variables even if they are not used" },
897 {"syntax-only", &flag_syntax_only, 1,
898 "Check for syntax errors, then stop" },
899 {"shared-data", &flag_shared_data, 1,
900 "Mark data as shared rather than private" },
901 {"caller-saves", &flag_caller_saves, 1,
902 "Enable saving registers around function calls" },
903 {"pcc-struct-return", &flag_pcc_struct_return, 1,
904 "Return 'short' aggregates in memory, not registers" },
905 {"reg-struct-return", &flag_pcc_struct_return, 0,
906 "Return 'short' aggregates in registers" },
907 {"delayed-branch", &flag_delayed_branch, 1,
908 "Attempt to fill delay slots of branch instructions" },
909 {"gcse", &flag_gcse, 1,
910 "Perform the global common subexpression elimination" },
911 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1,
912 "Run CSE pass after loop optimisations"},
913 {"rerun-loop-opt", &flag_rerun_loop_opt, 1,
914 "Run the loop optimiser twice"},
915 {"delete-null-pointer-checks", &flag_delete_null_pointer_checks, 1,
916 "Delete useless null pointer checks" },
917 {"pretend-float", &flag_pretend_float, 1,
918 "Pretend that host and target use the same FP format"},
919 {"schedule-insns", &flag_schedule_insns, 1,
920 "Reschedule instructions to avoid pipeline stalls"},
921 {"schedule-insns2", &flag_schedule_insns_after_reload, 1,
922 "Run two passes of the instruction scheduler"},
923 {"sched-interblock",&flag_schedule_interblock, 1,
924 "Enable scheduling across basic blocks" },
925 {"sched-spec",&flag_schedule_speculative, 1,
926 "Allow speculative motion of non-loads" },
927 {"sched-spec-load",&flag_schedule_speculative_load, 1,
928 "Allow speculative motion of some loads" },
929 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1,
930 "Allow speculative motion of more loads" },
931 {"branch-count-reg",&flag_branch_on_count_reg, 1,
932 "Replace add,compare,branch with branch on count reg"},
933 {"pic", &flag_pic, 1,
934 "Generate position independent code, if possible"},
935 {"PIC", &flag_pic, 2, ""},
936 {"exceptions", &flag_exceptions, 1,
937 "Enable exception handling" },
938 {"new-exceptions", &flag_new_exceptions, 1,
939 "Use the new model for exception handling" },
940 {"sjlj-exceptions", &exceptions_via_longjmp, 1,
941 "Use setjmp/longjmp to handle exceptions" },
942 {"asynchronous-exceptions", &asynchronous_exceptions, 1,
943 "Support asynchronous exceptions" },
944 {"profile-arcs", &profile_arc_flag, 1,
945 "Insert arc based program profiling code" },
946 {"test-coverage", &flag_test_coverage, 1,
947 "Create data files needed by gcov" },
948 {"branch-probabilities", &flag_branch_probabilities, 1,
949 "Use profiling information for branch probabilities" },
950 {"fast-math", &flag_fast_math, 1,
951 "Improve FP speed by violating ANSI & IEEE rules" },
952 {"common", &flag_no_common, 0,
953 "Do not put unitialised globals in the common section" },
954 {"inhibit-size-directive", &flag_inhibit_size_directive, 1,
955 "Do not generate .size directives" },
956 {"function-sections", &flag_function_sections, 1,
957 "place each function into its own section" },
958 {"data-sections", &flag_data_sections, 1,
959 "place data items into their own section" },
960 {"verbose-asm", &flag_verbose_asm, 1,
961 "Add extra commentry to assembler output"},
962 {"gnu-linker", &flag_gnu_linker, 1,
963 "Output GNU ld formatted global initialisers"},
964 {"regmove", &flag_regmove, 1,
965 "Enables a register move optimisation"},
966 {"optimize-register-move", &flag_regmove, 1,
967 "Do the full regmove optimization pass"},
968 {"pack-struct", &flag_pack_struct, 1,
969 "Pack structure members together without holes" },
970 {"stack-check", &flag_stack_check, 1,
971 "Insert stack checking code into the program" },
972 {"argument-alias", &flag_argument_noalias, 0,
973 "Specify that arguments may alias each other & globals"},
974 {"argument-noalias", &flag_argument_noalias, 1,
975 "Assume arguments may alias globals but not each other"},
976 {"argument-noalias-global", &flag_argument_noalias, 2,
977 "Assume arguments do not alias each other or globals" },
978 {"strict-aliasing", &flag_strict_aliasing, 1,
979 "Assume strict aliasing rules apply" },
980 {"align-loops", &align_loops, 0,
981 "Align the start of loops" },
982 {"align-jumps", &align_jumps, 0,
983 "Align labels which are only reached by jumping" },
984 {"align-labels", &align_labels, 0,
985 "Align all labels" },
986 {"align-functions", &align_functions, 0,
987 "Align the start of functions" },
988 {"check-memory-usage", &flag_check_memory_usage, 1,
989 "Generate code to check every memory access" },
990 {"prefix-function-name", &flag_prefix_function_name, 1,
991 "Add a prefix to all function names" },
992 {"dump-unnumbered", &flag_dump_unnumbered, 1,
993 "Suppress output of instruction numbers and line number notes in debugging dumps"},
994 {"instrument-functions", &flag_instrument_function_entry_exit, 1,
995 "Instrument function entry/exit with profiling calls"},
996 {"leading-underscore", &flag_leading_underscore, 1,
997 "External symbols have a leading underscore" },
998 {"ident", &flag_no_ident, 0,
999 "Process #ident directives"},
1000 { "peephole2", &flag_peephole2, 1,
1001 "Enables an rtl peephole pass run before sched2" },
1002 {"math-errno", &flag_errno_math, 1,
1003 "Set errno after built-in math functions"},
1004 {"bounded-pointers", &flag_bounded_pointers, 1,
1005 "Compile pointers as triples: value, base & end" },
1006 {"bounds-check", &flag_bounds_check, 1,
1007 "Generate code to check bounds before dereferencing pointers and arrays" }
1010 #define NUM_ELEM(a) (sizeof (a) / sizeof ((a)[0]))
1012 /* Table of language-specific options. */
1014 static struct lang_opt
1016 const char * option;
1017 const char * description;
1019 documented_lang_options[] =
1021 /* In order not to overload the --help output, the convention
1022 used here is to only describe those options which are not
1023 enabled by default. */
1025 { "-ansi", "Compile just for ANSI C" },
1026 { "-fallow-single-precision",
1027 "Do not promote floats to double if using -traditional" },
1028 { "-std= ", "Determine language standard"},
1030 { "-fsigned-bitfields", "" },
1031 { "-funsigned-bitfields","Make bitfields by unsigned by default" },
1032 { "-fno-signed-bitfields", "" },
1033 { "-fno-unsigned-bitfields","" },
1034 { "-fsigned-char", "Make 'char' be signed by default"},
1035 { "-funsigned-char", "Make 'char' be unsigned by default"},
1036 { "-fno-signed-char", "" },
1037 { "-fno-unsigned-char", "" },
1039 { "-ftraditional", "" },
1040 { "-traditional", "Attempt to support traditional K&R style C"},
1041 { "-fnotraditional", "" },
1042 { "-fno-traditional", "" },
1044 { "-fasm", "" },
1045 { "-fno-asm", "Do not recognise the 'asm' keyword" },
1046 { "-fbuiltin", "" },
1047 { "-fno-builtin", "Do not recognise any built in functions" },
1048 { "-fhosted", "Assume normal C execution environment" },
1049 { "-fno-hosted", "" },
1050 { "-ffreestanding",
1051 "Assume that standard libraries & main might not exist" },
1052 { "-fno-freestanding", "" },
1053 { "-fcond-mismatch", "Allow different types as args of ? operator"},
1054 { "-fno-cond-mismatch", "" },
1055 { "-fdollars-in-identifiers", "Allow the use of $ inside identifiers" },
1056 { "-fno-dollars-in-identifiers", "" },
1057 { "-fpreprocessed", "" },
1058 { "-fno-preprocessed", "" },
1059 { "-fshort-double", "Use the same size for double as for float" },
1060 { "-fno-short-double", "" },
1061 { "-fshort-enums", "Use the smallest fitting integer to hold enums"},
1062 { "-fno-short-enums", "" },
1063 { "-fshort-wchar", "Override the underlying type for wchar_t to `unsigned short'" },
1064 { "-fno-short-wchar", "" },
1066 { "-Wall", "Enable most warning messages" },
1067 { "-Wbad-function-cast",
1068 "Warn about casting functions to incompatible types" },
1069 { "-Wno-bad-function-cast", "" },
1070 { "-Wmissing-noreturn",
1071 "Warn about functions which might be candidates for attribute noreturn" },
1072 { "-Wno-missing-noreturn", "" },
1073 { "-Wcast-qual", "Warn about casts which discard qualifiers"},
1074 { "-Wno-cast-qual", "" },
1075 { "-Wchar-subscripts", "Warn about subscripts whose type is 'char'"},
1076 { "-Wno-char-subscripts", "" },
1077 { "-Wcomment", "Warn if nested comments are detected" },
1078 { "-Wno-comment", "" },
1079 { "-Wcomments", "Warn if nested comments are detected" },
1080 { "-Wno-comments", "" },
1081 { "-Wconversion", "Warn about possibly confusing type conversions" },
1082 { "-Wno-conversion", "" },
1083 { "-Wformat", "Warn about printf format anomalies" },
1084 { "-Wno-format", "" },
1085 { "-Wimplicit-function-declaration",
1086 "Warn about implicit function declarations" },
1087 { "-Wno-implicit-function-declaration", "" },
1088 { "-Werror-implicit-function-declaration", "" },
1089 { "-Wimplicit-int", "Warn when a declaration does not specify a type" },
1090 { "-Wno-implicit-int", "" },
1091 { "-Wimplicit", "" },
1092 { "-Wno-implicit", "" },
1093 { "-Wimport", "Warn about the use of the #import directive" },
1094 { "-Wno-import", "" },
1095 { "-Wlong-long","" },
1096 { "-Wno-long-long", "Do not warn about using 'long long' when -pedantic" },
1097 { "-Wmain", "Warn about suspicious declarations of main" },
1098 { "-Wno-main", "" },
1099 { "-Wmissing-braces",
1100 "Warn about possibly missing braces around initialisers" },
1101 { "-Wno-missing-braces", "" },
1102 { "-Wmissing-declarations",
1103 "Warn about global funcs without previous declarations"},
1104 { "-Wno-missing-declarations", "" },
1105 { "-Wmissing-prototypes", "Warn about global funcs without prototypes" },
1106 { "-Wno-missing-prototypes", "" },
1107 { "-Wmultichar", "Warn about use of multicharacter literals"},
1108 { "-Wno-multichar", "" },
1109 { "-Wnested-externs", "Warn about externs not at file scope level" },
1110 { "-Wno-nested-externs", "" },
1111 { "-Wparentheses", "Warn about possible missing parentheses" },
1112 { "-Wno-parentheses", "" },
1113 { "-Wpointer-arith", "Warn about function pointer arithmetic" },
1114 { "-Wno-pointer-arith", "" },
1115 { "-Wredundant-decls",
1116 "Warn about multiple declarations of the same object" },
1117 { "-Wno-redundant-decls", "" },
1118 { "-Wsign-compare", "Warn about signed/unsigned comparisons" },
1119 { "-Wno-sign-compare", "" },
1120 { "-Wfloat-equal", "Warn about testing equality of floating point numbers" },
1121 { "-Wno-float-equal", "" },
1122 { "-Wunknown-pragmas", "Warn about unrecognised pragmas" },
1123 { "-Wno-unknown-pragmas", "" },
1124 { "-Wstrict-prototypes", "Warn about non-prototyped function decls" },
1125 { "-Wno-strict-prototypes", "" },
1126 { "-Wtraditional", "Warn about constructs whose meaning change in ANSI C"},
1127 { "-Wno-traditional", "" },
1128 { "-Wtrigraphs", "Warn when trigraphs are encountered" },
1129 { "-Wno-trigraphs", "" },
1130 { "-Wundef", "" },
1131 { "-Wno-undef", "" },
1132 { "-Wwrite-strings", "Mark strings as 'const char *'"},
1133 { "-Wno-write-strings", "" },
1135 #define DEFINE_LANG_NAME(NAME) { NULL, NAME },
1137 /* These are for Objective C. */
1138 DEFINE_LANG_NAME ("Objective C")
1140 { "-lang-objc", "" },
1141 { "-gen-decls", "Dump decls to a .decl file" },
1142 { "-fgnu-runtime", "Generate code for GNU runtime environment" },
1143 { "-fno-gnu-runtime", "" },
1144 { "-fnext-runtime", "Generate code for NeXT runtime environment" },
1145 { "-fno-next-runtime", "" },
1146 { "-Wselector", "Warn if a selector has multiple methods" },
1147 { "-Wno-selector", "" },
1148 { "-Wprotocol", "" },
1149 { "-Wno-protocol", "Do not warn if inherited methods are unimplemented"},
1150 { "-print-objc-runtime-info",
1151 "Generate C header of platform specific features" },
1153 #include "options.h"
1157 /* Here is a table, controlled by the tm.h file, listing each -m switch
1158 and which bits in `target_switches' it should set or clear.
1159 If VALUE is positive, it is bits to set.
1160 If VALUE is negative, -VALUE is bits to clear.
1161 (The sign bit is not used so there is no confusion.) */
1163 struct
1165 const char * name;
1166 int value;
1167 const char * description;
1169 target_switches [] = TARGET_SWITCHES;
1171 /* This table is similar, but allows the switch to have a value. */
1173 #ifdef TARGET_OPTIONS
1174 struct
1176 const char * prefix;
1177 const char ** variable;
1178 const char * description;
1180 target_options [] = TARGET_OPTIONS;
1181 #endif
1183 /* Options controlling warnings */
1185 /* Don't print warning messages. -w. */
1187 int inhibit_warnings = 0;
1189 /* Print various extra warnings. -W. */
1191 int extra_warnings = 0;
1193 /* Treat warnings as errors. -Werror. */
1195 int warnings_are_errors = 0;
1197 /* Nonzero to warn about unused local variables. */
1199 int warn_unused;
1201 /* Nonzero to warn about code which is never reached. */
1203 int warn_notreached;
1205 /* Nonzero to warn about variables used before they are initialized. */
1207 int warn_uninitialized;
1209 /* Nonzero means warn about all declarations which shadow others. */
1211 int warn_shadow;
1213 /* Warn if a switch on an enum fails to have a case for every enum value. */
1215 int warn_switch;
1217 /* Nonzero means warn about function definitions that default the return type
1218 or that use a null return and have a return-type other than void. */
1220 int warn_return_type;
1222 /* Nonzero means warn about pointer casts that increase the required
1223 alignment of the target type (and might therefore lead to a crash
1224 due to a misaligned access). */
1226 int warn_cast_align;
1228 /* Nonzero means warn about any identifiers that match in the first N
1229 characters. The value N is in `id_clash_len'. */
1231 int warn_id_clash;
1232 unsigned id_clash_len;
1234 /* Nonzero means warn about any objects definitions whose size is larger
1235 than N bytes. Also want about function definitions whose returned
1236 values are larger than N bytes. The value N is in `larger_than_size'. */
1238 int warn_larger_than;
1239 unsigned larger_than_size;
1241 /* Nonzero means warn if inline function is too large. */
1243 int warn_inline;
1245 /* Warn if a function returns an aggregate,
1246 since there are often incompatible calling conventions for doing this. */
1248 int warn_aggregate_return;
1250 /* Likewise for -W. */
1252 lang_independent_options W_options[] =
1254 {"unused", &warn_unused, 1, "Warn when a variable is unused" },
1255 {"error", &warnings_are_errors, 1, ""},
1256 {"shadow", &warn_shadow, 1, "Warn when one local variable shadows another" },
1257 {"switch", &warn_switch, 1,
1258 "Warn about enumerated switches missing a specific case" },
1259 {"aggregate-return", &warn_aggregate_return, 1,
1260 "Warn about returning structures, unions or arrays" },
1261 {"cast-align", &warn_cast_align, 1,
1262 "Warn about pointer casts which increase alignment" },
1263 {"unreachable-code", &warn_notreached, 1,
1264 "Warn about code that will never be executed" },
1265 {"uninitialized", &warn_uninitialized, 1,
1266 "Warn about unitialized automatic variables"},
1267 {"inline", &warn_inline, 1,
1268 "Warn when an inlined function cannot be inlined"}
1271 /* Output files for assembler code (real compiler output)
1272 and debugging dumps. */
1274 FILE *asm_out_file;
1275 FILE *aux_info_file;
1276 FILE *rtl_dump_file = NULL;
1278 /* Decode the string P as an integral parameter.
1279 If the string is indeed an integer return its numeric value else
1280 issue an Invalid Option error for the option PNAME and return DEFVAL.
1281 If PNAME is zero just return DEFVAL, do not call error. */
1284 read_integral_parameter (p, pname, defval)
1285 const char *p;
1286 const char *pname;
1287 const int defval;
1289 const char *endp = p;
1291 while (*endp)
1293 if (*endp >= '0' && *endp <= '9')
1294 endp++;
1295 else
1296 break;
1299 if (*endp != 0)
1301 if (pname != 0)
1302 error ("Invalid option `%s'", pname);
1303 return defval;
1306 return atoi (p);
1310 /* Time accumulators, to count the total time spent in various passes. */
1312 int parse_time;
1313 int varconst_time;
1314 int integration_time;
1315 int jump_time;
1316 int cse_time;
1317 int gcse_time;
1318 int loop_time;
1319 int cse2_time;
1320 int branch_prob_time;
1321 int flow_time;
1322 int combine_time;
1323 int regmove_time;
1324 int sched_time;
1325 int local_alloc_time;
1326 int global_alloc_time;
1327 int flow2_time;
1328 int peephole2_time;
1329 int sched2_time;
1330 int dbr_sched_time;
1331 int shorten_branch_time;
1332 int stack_reg_time;
1333 int final_time;
1334 int symout_time;
1335 int dump_time;
1336 int gc_time;
1337 int all_time;
1339 /* Return time used so far, in microseconds. */
1341 long
1342 get_run_time ()
1344 if (quiet_flag)
1345 return 0;
1347 #ifdef __BEOS__
1348 return 0;
1349 #else /* not BeOS */
1350 #if defined (_WIN32) && !defined (__CYGWIN__)
1351 if (clock() < 0)
1352 return 0;
1353 else
1354 return (clock() * 1000);
1355 #else /* not _WIN32 */
1356 #ifdef _SC_CLK_TCK
1358 static int tick;
1359 struct tms tms;
1360 if (tick == 0)
1361 tick = 1000000 / sysconf(_SC_CLK_TCK);
1362 times (&tms);
1363 return (tms.tms_utime + tms.tms_stime) * tick;
1365 #else
1366 #ifdef USG
1368 struct tms tms;
1369 # if HAVE_SYSCONF && defined _SC_CLK_TCK
1370 # define TICKS_PER_SECOND sysconf (_SC_CLK_TCK) /* POSIX 1003.1-1996 */
1371 # else
1372 # ifdef CLK_TCK
1373 # define TICKS_PER_SECOND CLK_TCK /* POSIX 1003.1-1988; obsolescent */
1374 # else
1375 # define TICKS_PER_SECOND HZ /* traditional UNIX */
1376 # endif
1377 # endif
1378 times (&tms);
1379 return (tms.tms_utime + tms.tms_stime) * (1000000 / TICKS_PER_SECOND);
1381 #else
1382 #ifndef VMS
1384 struct rusage rusage;
1385 getrusage (0, &rusage);
1386 return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
1387 + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
1389 #else /* VMS */
1391 struct
1393 int proc_user_time;
1394 int proc_system_time;
1395 int child_user_time;
1396 int child_system_time;
1397 } vms_times;
1398 times ((void *) &vms_times);
1399 return (vms_times.proc_user_time + vms_times.proc_system_time) * 10000;
1401 #endif /* VMS */
1402 #endif /* USG */
1403 #endif /* _SC_CLK_TCK */
1404 #endif /* _WIN32 */
1405 #endif /* __BEOS__ */
1408 #define TIMEVAR(VAR, BODY) \
1409 do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
1411 void
1412 print_time (str, total)
1413 const char *str;
1414 int total;
1416 fprintf (stderr,
1417 "time in %s: %d.%06d (%.0f%%)\n",
1418 str, total / 1000000, total % 1000000,
1419 (double)total / (double)all_time * 100.0);
1422 /* Count an error or warning. Return 1 if the message should be printed. */
1425 count_error (warningp)
1426 int warningp;
1428 if (warningp && inhibit_warnings)
1429 return 0;
1431 if (warningp && !warnings_are_errors)
1432 warningcount++;
1433 else
1435 static int warning_message = 0;
1437 if (warningp && !warning_message)
1439 notice ("%s: warnings being treated as errors\n", progname);
1440 warning_message = 1;
1442 errorcount++;
1445 return 1;
1448 /* Print a fatal error message. NAME is the text.
1449 Also include a system error message based on `errno'. */
1451 void
1452 pfatal_with_name (name)
1453 const char *name;
1455 fprintf (stderr, "%s: ", progname);
1456 perror (name);
1457 exit (FATAL_EXIT_CODE);
1460 void
1461 fatal_io_error (name)
1462 const char *name;
1464 notice ("%s: %s: I/O error\n", progname, name);
1465 exit (FATAL_EXIT_CODE);
1468 /* This is the default decl_printable_name function. */
1470 static const char *
1471 decl_name (decl, verbosity)
1472 tree decl;
1473 int verbosity ATTRIBUTE_UNUSED;
1475 return IDENTIFIER_POINTER (DECL_NAME (decl));
1478 /* Mark P for GC. Also mark main_input_filename and input_filename. */
1479 static void
1480 mark_file_stack (p)
1481 void *p;
1483 struct file_stack *stack = *(struct file_stack **)p;
1485 /* We're only called for input_file_stack, so we can mark the current
1486 input_filename here as well. */
1487 ggc_mark_string (main_input_filename);
1488 ggc_mark_string (input_filename);
1490 while (stack)
1492 ggc_mark_string (stack->name);
1493 stack = stack->next;
1497 static int need_error_newline;
1499 /* Function of last error message;
1500 more generally, function such that if next error message is in it
1501 then we don't have to mention the function name. */
1502 static tree last_error_function = NULL;
1504 /* Used to detect when input_file_stack has changed since last described. */
1505 static int last_error_tick;
1507 /* Called when the start of a function definition is parsed,
1508 this function prints on stderr the name of the function. */
1510 void
1511 announce_function (decl)
1512 tree decl;
1514 if (! quiet_flag)
1516 if (rtl_dump_and_exit)
1517 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1518 else
1519 fprintf (stderr, " %s", (*decl_printable_name) (decl, 2));
1520 fflush (stderr);
1521 need_error_newline = 1;
1522 last_error_function = current_function_decl;
1526 /* The default function to print out name of current function that caused
1527 an error. */
1529 void
1530 default_print_error_function (file)
1531 const char *file;
1533 if (last_error_function != current_function_decl)
1535 if (file)
1536 fprintf (stderr, "%s: ", file);
1538 if (current_function_decl == NULL)
1539 notice ("At top level:\n");
1540 else
1541 notice ((TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE
1542 ? "In method `%s':\n"
1543 : "In function `%s':\n"),
1544 (*decl_printable_name) (current_function_decl, 2));
1546 last_error_function = current_function_decl;
1550 /* Called by report_error_function to print out function name.
1551 * Default may be overridden by language front-ends. */
1553 void (*print_error_function) PROTO((const char *)) =
1554 default_print_error_function;
1556 /* Prints out, if necessary, the name of the current function
1557 that caused an error. Called from all error and warning functions.
1558 We ignore the FILE parameter, as it cannot be relied upon. */
1560 void
1561 report_error_function (file)
1562 const char *file ATTRIBUTE_UNUSED;
1564 struct file_stack *p;
1566 if (need_error_newline)
1568 fprintf (stderr, "\n");
1569 need_error_newline = 0;
1572 if (input_file_stack && input_file_stack->next != 0
1573 && input_file_stack_tick != last_error_tick)
1575 for (p = input_file_stack->next; p; p = p->next)
1576 notice ((p == input_file_stack->next
1577 ? "In file included from %s:%d"
1578 : ",\n from %s:%d"),
1579 p->name, p->line);
1580 fprintf (stderr, ":\n");
1581 last_error_tick = input_file_stack_tick;
1584 (*print_error_function) (input_filename);
1587 /* Print a message. */
1589 static void
1590 vnotice (file, msgid, ap)
1591 FILE *file;
1592 const char *msgid;
1593 va_list ap;
1595 vfprintf (file, _(msgid), ap);
1598 static void
1599 notice VPROTO((const char *msgid, ...))
1601 #ifndef ANSI_PROTOTYPES
1602 char *msgid;
1603 #endif
1604 va_list ap;
1606 VA_START (ap, msgid);
1608 #ifndef ANSI_PROTOTYPES
1609 msgid = va_arg (ap, char *);
1610 #endif
1612 vnotice (stderr, msgid, ap);
1613 va_end (ap);
1616 void
1617 fnotice VPROTO((FILE *file, const char *msgid, ...))
1619 #ifndef ANSI_PROTOTYPES
1620 FILE *file;
1621 const char *msgid;
1622 #endif
1623 va_list ap;
1625 VA_START (ap, msgid);
1627 #ifndef ANSI_PROTOTYPES
1628 file = va_arg (ap, FILE *);
1629 msgid = va_arg (ap, const char *);
1630 #endif
1632 vnotice (file, msgid, ap);
1633 va_end (ap);
1636 /* Report FILE and LINE (or program name), and optionally just WARN. */
1638 static void
1639 report_file_and_line (file, line, warn)
1640 const char *file;
1641 int line;
1642 int warn;
1644 if (file)
1645 fprintf (stderr, "%s:%d: ", file, line);
1646 else
1647 fprintf (stderr, "%s: ", progname);
1649 if (warn)
1650 notice ("warning: ");
1653 /* Print a message. */
1655 static void
1656 vmessage (prefix, msgid, ap)
1657 const char *prefix;
1658 const char *msgid;
1659 va_list ap;
1661 if (prefix)
1662 fprintf (stderr, "%s: ", prefix);
1664 vfprintf (stderr, msgid, ap);
1667 /* Print a message relevant to line LINE of file FILE. */
1669 static void
1670 v_message_with_file_and_line (file, line, warn, msgid, ap)
1671 const char *file;
1672 int line;
1673 int warn;
1674 const char *msgid;
1675 va_list ap;
1677 report_file_and_line (file, line, warn);
1678 vnotice (stderr, msgid, ap);
1679 fputc ('\n', stderr);
1682 /* Print a message relevant to the given DECL. */
1684 static void
1685 v_message_with_decl (decl, warn, msgid, ap)
1686 tree decl;
1687 int warn;
1688 const char *msgid;
1689 va_list ap;
1691 const char *p;
1693 report_file_and_line (DECL_SOURCE_FILE (decl),
1694 DECL_SOURCE_LINE (decl), warn);
1696 /* Do magic to get around lack of varargs support for insertion
1697 of arguments into existing list. We know that the decl is first;
1698 we ass_u_me that it will be printed with "%s". */
1700 for (p = _(msgid); *p; ++p)
1702 if (*p == '%')
1704 if (*(p + 1) == '%')
1705 ++p;
1706 else if (*(p + 1) != 's')
1707 abort ();
1708 else
1709 break;
1713 if (p > _(msgid)) /* Print the left-hand substring. */
1715 char fmt[sizeof "%.255s"];
1716 long width = p - _(msgid);
1718 if (width > 255L) width = 255L; /* arbitrary */
1719 sprintf (fmt, "%%.%lds", width);
1720 fprintf (stderr, fmt, _(msgid));
1723 if (*p == '%') /* Print the name. */
1725 const char *n = (DECL_NAME (decl)
1726 ? (*decl_printable_name) (decl, 2)
1727 : "((anonymous))");
1728 fputs (n, stderr);
1729 while (*p)
1731 ++p;
1732 if (ISALPHA (*(p - 1) & 0xFF))
1733 break;
1737 if (*p) /* Print the rest of the message. */
1738 vmessage ((char *)NULL, p, ap);
1740 fputc ('\n', stderr);
1743 /* Figure file and line of the given INSN. */
1745 static void
1746 file_and_line_for_asm (insn, pfile, pline)
1747 rtx insn;
1748 char **pfile;
1749 int *pline;
1751 rtx body = PATTERN (insn);
1752 rtx asmop;
1754 /* Find the (or one of the) ASM_OPERANDS in the insn. */
1755 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1756 asmop = SET_SRC (body);
1757 else if (GET_CODE (body) == ASM_OPERANDS)
1758 asmop = body;
1759 else if (GET_CODE (body) == PARALLEL
1760 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
1761 asmop = SET_SRC (XVECEXP (body, 0, 0));
1762 else if (GET_CODE (body) == PARALLEL
1763 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1764 asmop = XVECEXP (body, 0, 0);
1765 else
1766 asmop = NULL;
1768 if (asmop)
1770 *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
1771 *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
1773 else
1775 *pfile = input_filename;
1776 *pline = lineno;
1780 /* Report an error at line LINE of file FILE. */
1782 static void
1783 v_error_with_file_and_line (file, line, msgid, ap)
1784 const char *file;
1785 int line;
1786 const char *msgid;
1787 va_list ap;
1789 count_error (0);
1790 report_error_function (file);
1791 v_message_with_file_and_line (file, line, 0, msgid, ap);
1794 void
1795 error_with_file_and_line VPROTO((const char *file, int line,
1796 const char *msgid, ...))
1798 #ifndef ANSI_PROTOTYPES
1799 const char *file;
1800 int line;
1801 const char *msgid;
1802 #endif
1803 va_list ap;
1805 VA_START (ap, msgid);
1807 #ifndef ANSI_PROTOTYPES
1808 file = va_arg (ap, const char *);
1809 line = va_arg (ap, int);
1810 msgid = va_arg (ap, const char *);
1811 #endif
1813 v_error_with_file_and_line (file, line, msgid, ap);
1814 va_end (ap);
1817 /* Report an error at the declaration DECL.
1818 MSGID is a format string which uses %s to substitute the declaration
1819 name; subsequent substitutions are a la printf. */
1821 static void
1822 v_error_with_decl (decl, msgid, ap)
1823 tree decl;
1824 const char *msgid;
1825 va_list ap;
1827 count_error (0);
1828 report_error_function (DECL_SOURCE_FILE (decl));
1829 v_message_with_decl (decl, 0, msgid, ap);
1832 void
1833 error_with_decl VPROTO((tree decl, const char *msgid, ...))
1835 #ifndef ANSI_PROTOTYPES
1836 tree decl;
1837 const char *msgid;
1838 #endif
1839 va_list ap;
1841 VA_START (ap, msgid);
1843 #ifndef ANSI_PROTOTYPES
1844 decl = va_arg (ap, tree);
1845 msgid = va_arg (ap, const char *);
1846 #endif
1848 v_error_with_decl (decl, msgid, ap);
1849 va_end (ap);
1852 /* Report an error at the line number of the insn INSN.
1853 This is used only when INSN is an `asm' with operands,
1854 and each ASM_OPERANDS records its own source file and line. */
1856 static void
1857 v_error_for_asm (insn, msgid, ap)
1858 rtx insn;
1859 const char *msgid;
1860 va_list ap;
1862 char *file;
1863 int line;
1865 count_error (0);
1866 file_and_line_for_asm (insn, &file, &line);
1867 report_error_function (file);
1868 v_message_with_file_and_line (file, line, 0, msgid, ap);
1871 void
1872 error_for_asm VPROTO((rtx insn, const char *msgid, ...))
1874 #ifndef ANSI_PROTOTYPES
1875 rtx insn;
1876 const char *msgid;
1877 #endif
1878 va_list ap;
1880 VA_START (ap, msgid);
1882 #ifndef ANSI_PROTOTYPES
1883 insn = va_arg (ap, rtx);
1884 msgid = va_arg (ap, const char *);
1885 #endif
1887 v_error_for_asm (insn, msgid, ap);
1888 va_end (ap);
1891 /* Report an error at the current line number. */
1893 static void
1894 verror (msgid, ap)
1895 const char *msgid;
1896 va_list ap;
1898 v_error_with_file_and_line (input_filename, lineno, msgid, ap);
1901 void
1902 error VPROTO((const char *msgid, ...))
1904 #ifndef ANSI_PROTOTYPES
1905 const char *msgid;
1906 #endif
1907 va_list ap;
1909 VA_START (ap, msgid);
1911 #ifndef ANSI_PROTOTYPES
1912 msgid = va_arg (ap, const char *);
1913 #endif
1915 verror (msgid, ap);
1916 va_end (ap);
1919 /* Report a fatal error at the current line number. Allow a front end to
1920 intercept the message. */
1922 static void (*fatal_function) PROTO ((const char *, va_list));
1924 /* Set the function to call when a fatal error occurs. */
1926 void
1927 set_fatal_function (f)
1928 void (*f) PROTO ((const char *, va_list));
1930 fatal_function = f;
1933 static void
1934 vfatal (msgid, ap)
1935 const char *msgid;
1936 va_list ap;
1938 if (fatal_function != 0)
1939 (*fatal_function) (_(msgid), ap);
1941 verror (msgid, ap);
1942 exit (FATAL_EXIT_CODE);
1945 void
1946 fatal VPROTO((const char *msgid, ...))
1948 #ifndef ANSI_PROTOTYPES
1949 const char *msgid;
1950 #endif
1951 va_list ap;
1953 VA_START (ap, msgid);
1955 #ifndef ANSI_PROTOTYPES
1956 msgid = va_arg (ap, const char *);
1957 #endif
1959 vfatal (msgid, ap);
1960 va_end (ap);
1963 void
1964 _fatal_insn (msgid, insn, file, line, function)
1965 const char *msgid;
1966 rtx insn;
1967 const char *file;
1968 int line;
1969 const char *function;
1971 error (msgid);
1972 debug_rtx (insn);
1973 fancy_abort (file, line, function);
1976 void
1977 _fatal_insn_not_found (insn, file, line, function)
1978 rtx insn;
1979 const char *file;
1980 int line;
1981 const char *function;
1983 if (INSN_CODE (insn) < 0)
1984 _fatal_insn ("Unrecognizable insn:", insn, file, line, function);
1985 else
1986 _fatal_insn ("Insn does not satisfy its constraints:",
1987 insn, file, line, function);
1990 /* Report a warning at line LINE of file FILE. */
1992 static void
1993 v_warning_with_file_and_line (file, line, msgid, ap)
1994 const char *file;
1995 int line;
1996 const char *msgid;
1997 va_list ap;
1999 if (count_error (1))
2001 report_error_function (file);
2002 v_message_with_file_and_line (file, line, 1, msgid, ap);
2006 void
2007 warning_with_file_and_line VPROTO((const char *file, int line,
2008 const char *msgid, ...))
2010 #ifndef ANSI_PROTOTYPES
2011 const char *file;
2012 int line;
2013 const char *msgid;
2014 #endif
2015 va_list ap;
2017 VA_START (ap, msgid);
2019 #ifndef ANSI_PROTOTYPES
2020 file = va_arg (ap, const char *);
2021 line = va_arg (ap, int);
2022 msgid = va_arg (ap, const char *);
2023 #endif
2025 v_warning_with_file_and_line (file, line, msgid, ap);
2026 va_end (ap);
2029 /* Report a warning at the declaration DECL.
2030 MSGID is a format string which uses %s to substitute the declaration
2031 name; subsequent substitutions are a la printf. */
2033 static void
2034 v_warning_with_decl (decl, msgid, ap)
2035 tree decl;
2036 const char *msgid;
2037 va_list ap;
2039 if (count_error (1))
2041 report_error_function (DECL_SOURCE_FILE (decl));
2042 v_message_with_decl (decl, 1, msgid, ap);
2046 void
2047 warning_with_decl VPROTO((tree decl, const char *msgid, ...))
2049 #ifndef ANSI_PROTOTYPES
2050 tree decl;
2051 const char *msgid;
2052 #endif
2053 va_list ap;
2055 VA_START (ap, msgid);
2057 #ifndef ANSI_PROTOTYPES
2058 decl = va_arg (ap, tree);
2059 msgid = va_arg (ap, const char *);
2060 #endif
2062 v_warning_with_decl (decl, msgid, ap);
2063 va_end (ap);
2066 /* Report a warning at the line number of the insn INSN.
2067 This is used only when INSN is an `asm' with operands,
2068 and each ASM_OPERANDS records its own source file and line. */
2070 static void
2071 v_warning_for_asm (insn, msgid, ap)
2072 rtx insn;
2073 const char *msgid;
2074 va_list ap;
2076 if (count_error (1))
2078 char *file;
2079 int line;
2081 file_and_line_for_asm (insn, &file, &line);
2082 report_error_function (file);
2083 v_message_with_file_and_line (file, line, 1, msgid, ap);
2087 void
2088 warning_for_asm VPROTO((rtx insn, const char *msgid, ...))
2090 #ifndef ANSI_PROTOTYPES
2091 rtx insn;
2092 const char *msgid;
2093 #endif
2094 va_list ap;
2096 VA_START (ap, msgid);
2098 #ifndef ANSI_PROTOTYPES
2099 insn = va_arg (ap, rtx);
2100 msgid = va_arg (ap, const char *);
2101 #endif
2103 v_warning_for_asm (insn, msgid, ap);
2104 va_end (ap);
2107 /* Report a warning at the current line number. */
2109 static void
2110 vwarning (msgid, ap)
2111 const char *msgid;
2112 va_list ap;
2114 v_warning_with_file_and_line (input_filename, lineno, msgid, ap);
2117 void
2118 warning VPROTO((const char *msgid, ...))
2120 #ifndef ANSI_PROTOTYPES
2121 const char *msgid;
2122 #endif
2123 va_list ap;
2125 VA_START (ap, msgid);
2127 #ifndef ANSI_PROTOTYPES
2128 msgid = va_arg (ap, const char *);
2129 #endif
2131 vwarning (msgid, ap);
2132 va_end (ap);
2135 /* These functions issue either warnings or errors depending on
2136 -pedantic-errors. */
2138 static void
2139 vpedwarn (msgid, ap)
2140 const char *msgid;
2141 va_list ap;
2143 if (flag_pedantic_errors)
2144 verror (msgid, ap);
2145 else
2146 vwarning (msgid, ap);
2149 void
2150 pedwarn VPROTO((const char *msgid, ...))
2152 #ifndef ANSI_PROTOTYPES
2153 const char *msgid;
2154 #endif
2155 va_list ap;
2157 VA_START (ap, msgid);
2159 #ifndef ANSI_PROTOTYPES
2160 msgid = va_arg (ap, const char *);
2161 #endif
2163 vpedwarn (msgid, ap);
2164 va_end (ap);
2167 static void
2168 v_pedwarn_with_decl (decl, msgid, ap)
2169 tree decl;
2170 const char *msgid;
2171 va_list ap;
2173 /* We don't want -pedantic-errors to cause the compilation to fail from
2174 "errors" in system header files. Sometimes fixincludes can't fix what's
2175 broken (eg: unsigned char bitfields - fixing it may change the alignment
2176 which will cause programs to mysteriously fail because the C library
2177 or kernel uses the original layout). There's no point in issuing a
2178 warning either, it's just unnecessary noise. */
2180 if (! DECL_IN_SYSTEM_HEADER (decl))
2182 if (flag_pedantic_errors)
2183 v_error_with_decl (decl, msgid, ap);
2184 else
2185 v_warning_with_decl (decl, msgid, ap);
2189 void
2190 pedwarn_with_decl VPROTO((tree decl, const char *msgid, ...))
2192 #ifndef ANSI_PROTOTYPES
2193 tree decl;
2194 const char *msgid;
2195 #endif
2196 va_list ap;
2198 VA_START (ap, msgid);
2200 #ifndef ANSI_PROTOTYPES
2201 decl = va_arg (ap, tree);
2202 msgid = va_arg (ap, const char *);
2203 #endif
2205 v_pedwarn_with_decl (decl, msgid, ap);
2206 va_end (ap);
2209 static void
2210 v_pedwarn_with_file_and_line (file, line, msgid, ap)
2211 const char *file;
2212 int line;
2213 const char *msgid;
2214 va_list ap;
2216 if (flag_pedantic_errors)
2217 v_error_with_file_and_line (file, line, msgid, ap);
2218 else
2219 v_warning_with_file_and_line (file, line, msgid, ap);
2222 void
2223 pedwarn_with_file_and_line VPROTO((const char *file, int line,
2224 const char *msgid, ...))
2226 #ifndef ANSI_PROTOTYPES
2227 const char *file;
2228 int line;
2229 const char *msgid;
2230 #endif
2231 va_list ap;
2233 VA_START (ap, msgid);
2235 #ifndef ANSI_PROTOTYPES
2236 file = va_arg (ap, const char *);
2237 line = va_arg (ap, int);
2238 msgid = va_arg (ap, const char *);
2239 #endif
2241 v_pedwarn_with_file_and_line (file, line, msgid, ap);
2242 va_end (ap);
2245 /* Apologize for not implementing some feature. */
2247 static void
2248 vsorry (msgid, ap)
2249 const char *msgid;
2250 va_list ap;
2252 sorrycount++;
2253 if (input_filename)
2254 fprintf (stderr, "%s:%d: ", input_filename, lineno);
2255 else
2256 fprintf (stderr, "%s: ", progname);
2257 notice ("sorry, not implemented: ");
2258 vnotice (stderr, msgid, ap);
2259 fputc ('\n', stderr);
2262 void
2263 sorry VPROTO((const char *msgid, ...))
2265 #ifndef ANSI_PROTOTYPES
2266 const char *msgid;
2267 #endif
2268 va_list ap;
2270 VA_START (ap, msgid);
2272 #ifndef ANSI_PROTOTYPES
2273 msgid = va_arg (ap, const char *);
2274 #endif
2276 vsorry (msgid, ap);
2277 va_end (ap);
2281 /* This calls abort and is used to avoid problems when abort if a macro.
2282 It is used when we need to pass the address of abort. */
2284 void
2285 do_abort ()
2287 abort ();
2290 /* When `malloc.c' is compiled with `rcheck' defined,
2291 it calls this function to report clobberage. */
2293 void
2294 botch (s)
2295 const char * s ATTRIBUTE_UNUSED;
2297 abort ();
2300 /* Return the logarithm of X, base 2, considering X unsigned,
2301 if X is a power of 2. Otherwise, returns -1.
2303 This should be used via the `exact_log2' macro. */
2306 exact_log2_wide (x)
2307 register unsigned HOST_WIDE_INT x;
2309 register int log = 0;
2310 /* Test for 0 or a power of 2. */
2311 if (x == 0 || x != (x & -x))
2312 return -1;
2313 while ((x >>= 1) != 0)
2314 log++;
2315 return log;
2318 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
2319 If X is 0, return -1.
2321 This should be used via the floor_log2 macro. */
2324 floor_log2_wide (x)
2325 register unsigned HOST_WIDE_INT x;
2327 register int log = -1;
2328 while (x != 0)
2329 log++,
2330 x >>= 1;
2331 return log;
2334 static int float_handler_set;
2335 int float_handled;
2336 jmp_buf float_handler;
2338 /* Signals actually come here. */
2340 static void
2341 float_signal (signo)
2342 /* If this is missing, some compilers complain. */
2343 int signo ATTRIBUTE_UNUSED;
2345 if (float_handled == 0)
2346 abort ();
2347 #if defined (USG) || defined (hpux)
2348 signal (SIGFPE, float_signal); /* re-enable the signal catcher */
2349 #endif
2350 float_handled = 0;
2351 signal (SIGFPE, float_signal);
2352 longjmp (float_handler, 1);
2355 /* Specify where to longjmp to when a floating arithmetic error happens.
2356 If HANDLER is 0, it means don't handle the errors any more. */
2358 void
2359 set_float_handler (handler)
2360 jmp_buf handler;
2362 float_handled = (handler != 0);
2363 if (handler)
2364 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
2366 if (float_handled && ! float_handler_set)
2368 signal (SIGFPE, float_signal);
2369 float_handler_set = 1;
2373 /* This is a wrapper function for code which might elicit an
2374 arithmetic exception. That code should be passed in as a function
2375 pointer FN, and one argument DATA. DATA is usually a struct which
2376 contains the real input and output for function FN. This function
2377 returns 0 (failure) if longjmp was called (i.e. an exception
2378 occured.) It returns 1 (success) otherwise. */
2381 do_float_handler (fn, data)
2382 void (*fn) PROTO ((PTR));
2383 PTR data;
2385 jmp_buf buf;
2387 if (setjmp (buf))
2389 /* We got here via longjmp() caused by an exception in function fn() */
2390 set_float_handler (NULL);
2391 return 0;
2394 set_float_handler (buf);
2395 (*fn)(data);
2396 set_float_handler (NULL);
2397 return 1;
2400 /* Specify, in HANDLER, where to longjmp to when a floating arithmetic
2401 error happens, pushing the previous specification into OLD_HANDLER.
2402 Return an indication of whether there was a previous handler in effect. */
2405 push_float_handler (handler, old_handler)
2406 jmp_buf handler, old_handler;
2408 int was_handled = float_handled;
2410 float_handled = 1;
2411 if (was_handled)
2412 memcpy ((char *) old_handler, (char *) float_handler,
2413 sizeof (float_handler));
2415 memcpy ((char *) float_handler, (char *) handler, sizeof (float_handler));
2416 return was_handled;
2419 /* Restore the previous specification of whether and where to longjmp to
2420 when a floating arithmetic error happens. */
2422 void
2423 pop_float_handler (handled, handler)
2424 int handled;
2425 jmp_buf handler;
2427 float_handled = handled;
2428 if (handled)
2429 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
2432 /* Handler for SIGPIPE. */
2434 static void
2435 pipe_closed (signo)
2436 /* If this is missing, some compilers complain. */
2437 int signo ATTRIBUTE_UNUSED;
2439 fatal ("output pipe has been closed");
2442 /* Strip off a legitimate source ending from the input string NAME of
2443 length LEN. Rather than having to know the names used by all of
2444 our front ends, we strip off an ending of a period followed by
2445 up to five characters. (Java uses ".class".) */
2447 void
2448 strip_off_ending (name, len)
2449 char *name;
2450 int len;
2452 int i;
2453 for (i = 2; i < 6 && len > i; i++)
2455 if (name[len - i] == '.')
2457 name[len - i] = '\0';
2458 break;
2463 /* Output a quoted string. */
2465 void
2466 output_quoted_string (asm_file, string)
2467 FILE *asm_file;
2468 const char *string;
2470 #ifdef OUTPUT_QUOTED_STRING
2471 OUTPUT_QUOTED_STRING (asm_file, string);
2472 #else
2473 char c;
2475 putc ('\"', asm_file);
2476 while ((c = *string++) != 0)
2478 if (c == '\"' || c == '\\')
2479 putc ('\\', asm_file);
2480 putc (c, asm_file);
2482 putc ('\"', asm_file);
2483 #endif
2486 /* Output a file name in the form wanted by System V. */
2488 void
2489 output_file_directive (asm_file, input_name)
2490 FILE *asm_file;
2491 const char *input_name;
2493 int len = strlen (input_name);
2494 const char *na = input_name + len;
2496 /* NA gets INPUT_NAME sans directory names. */
2497 while (na > input_name)
2499 if (na[-1] == '/')
2500 break;
2501 #ifdef DIR_SEPARATOR
2502 if (na[-1] == DIR_SEPARATOR)
2503 break;
2504 #endif
2505 na--;
2508 #ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
2509 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
2510 #else
2511 #ifdef ASM_OUTPUT_SOURCE_FILENAME
2512 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
2513 #else
2514 fprintf (asm_file, "\t.file\t");
2515 output_quoted_string (asm_file, na);
2516 fputc ('\n', asm_file);
2517 #endif
2518 #endif
2521 #ifdef ASM_IDENTIFY_LANGUAGE
2522 /* Routine to build language identifier for object file. */
2523 static void
2524 output_lang_identify (asm_out_file)
2525 FILE *asm_out_file;
2527 int len = strlen (lang_identify ()) + sizeof ("__gnu_compiled_") + 1;
2528 char *s = (char *) alloca (len);
2529 sprintf (s, "__gnu_compiled_%s", lang_identify ());
2530 ASM_OUTPUT_LABEL (asm_out_file, s);
2532 #endif
2534 /* Routine to open a dump file. */
2535 static void
2536 open_dump_file (suffix, function_name)
2537 const char *suffix;
2538 const char *function_name;
2540 char *dumpname;
2542 TIMEVAR
2543 (dump_time,
2545 dumpname = concat (dump_base_name, suffix, NULL);
2547 if (rtl_dump_file != NULL)
2548 fclose (rtl_dump_file);
2550 rtl_dump_file = fopen (dumpname, "a");
2552 if (rtl_dump_file == NULL)
2553 pfatal_with_name (dumpname);
2555 free (dumpname);
2557 if (function_name)
2558 fprintf (rtl_dump_file, "\n;; Function %s\n\n", function_name);
2561 return;
2564 /* Routine to close a dump file. */
2565 static void
2566 close_dump_file (func, insns)
2567 void (*func) PROTO ((FILE *, rtx));
2568 rtx insns;
2570 TIMEVAR
2571 (dump_time,
2573 if (func)
2574 func (rtl_dump_file, insns);
2576 fflush (rtl_dump_file);
2577 fclose (rtl_dump_file);
2579 rtl_dump_file = NULL;
2582 return;
2585 /* Routine to dump rtl into a file. */
2586 static void
2587 dump_rtl (suffix, decl, func, insns)
2588 const char *suffix;
2589 tree decl;
2590 void (*func) PROTO ((FILE *, rtx));
2591 rtx insns;
2593 open_dump_file (suffix, decl_printable_name (decl, 2));
2594 close_dump_file (func, insns);
2597 /* Routine to empty a dump file. */
2598 static void
2599 clean_dump_file (suffix)
2600 const char *suffix;
2602 char * const dumpname = concat (dump_base_name, suffix, NULL);
2604 rtl_dump_file = fopen (dumpname, "w");
2606 if (rtl_dump_file == NULL)
2607 pfatal_with_name (dumpname);
2609 free (dumpname);
2611 fclose (rtl_dump_file);
2612 rtl_dump_file = NULL;
2614 return;
2617 /* Do any final processing required for the declarations in VEC, of
2618 which there are LEN. We write out inline functions and variables
2619 that have been deferred until this point, but which are required.
2620 Returns non-zero if anything was put out. */
2622 wrapup_global_declarations (vec, len)
2623 tree *vec;
2624 int len;
2626 tree decl;
2627 int i;
2628 int reconsider;
2629 int output_something = 0;
2631 for (i = 0; i < len; i++)
2633 decl = vec[i];
2635 /* We're not deferring this any longer. */
2636 DECL_DEFER_OUTPUT (decl) = 0;
2638 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0
2639 && incomplete_decl_finalize_hook != 0)
2640 (*incomplete_decl_finalize_hook) (decl);
2643 /* Now emit any global variables or functions that we have been
2644 putting off. We need to loop in case one of the things emitted
2645 here references another one which comes earlier in the list. */
2648 reconsider = 0;
2649 for (i = 0; i < len; i++)
2651 decl = vec[i];
2653 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
2654 continue;
2656 /* Don't write out static consts, unless we still need them.
2658 We also keep static consts if not optimizing (for debugging),
2659 unless the user specified -fno-keep-static-consts.
2660 ??? They might be better written into the debug information.
2661 This is possible when using DWARF.
2663 A language processor that wants static constants to be always
2664 written out (even if it is not used) is responsible for
2665 calling rest_of_decl_compilation itself. E.g. the C front-end
2666 calls rest_of_decl_compilation from finish_decl.
2667 One motivation for this is that is conventional in some
2668 environments to write things like:
2669 static const char rcsid[] = "... version string ...";
2670 intending to force the string to be in the executable.
2672 A language processor that would prefer to have unneeded
2673 static constants "optimized away" would just defer writing
2674 them out until here. E.g. C++ does this, because static
2675 constants are often defined in header files.
2677 ??? A tempting alternative (for both C and C++) would be
2678 to force a constant to be written if and only if it is
2679 defined in a main file, as opposed to an include file. */
2681 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2682 && (! TREE_READONLY (decl)
2683 || TREE_PUBLIC (decl)
2684 || (!optimize && flag_keep_static_consts)
2685 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2687 reconsider = 1;
2688 rest_of_decl_compilation (decl, NULL_PTR, 1, 1);
2691 if (TREE_CODE (decl) == FUNCTION_DECL
2692 && DECL_INITIAL (decl) != 0
2693 && DECL_SAVED_INSNS (decl) != 0
2694 && (flag_keep_inline_functions
2695 || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
2696 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2698 reconsider = 1;
2699 temporary_allocation ();
2700 output_inline_function (decl);
2701 permanent_allocation (1);
2705 if (reconsider)
2706 output_something = 1;
2708 while (reconsider);
2710 return output_something;
2713 /* Issue appropriate warnings for the global declarations in VEC (of
2714 which there are LEN). Output debugging information for them. */
2715 void
2716 check_global_declarations (vec, len)
2717 tree *vec;
2718 int len;
2720 tree decl;
2721 int i;
2723 for (i = 0; i < len; i++)
2725 decl = vec[i];
2727 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2728 && ! TREE_ASM_WRITTEN (decl))
2729 /* Cancel the RTL for this decl so that, if debugging info
2730 output for global variables is still to come,
2731 this one will be omitted. */
2732 DECL_RTL (decl) = NULL;
2734 /* Warn about any function
2735 declared static but not defined.
2736 We don't warn about variables,
2737 because many programs have static variables
2738 that exist only to get some text into the object file. */
2739 if (TREE_CODE (decl) == FUNCTION_DECL
2740 && (warn_unused
2741 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2742 && DECL_INITIAL (decl) == 0
2743 && DECL_EXTERNAL (decl)
2744 && ! DECL_ARTIFICIAL (decl)
2745 && ! TREE_PUBLIC (decl))
2747 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2748 pedwarn_with_decl (decl,
2749 "`%s' used but never defined");
2750 else
2751 warning_with_decl (decl,
2752 "`%s' declared `static' but never defined");
2753 /* This symbol is effectively an "extern" declaration now. */
2754 TREE_PUBLIC (decl) = 1;
2755 assemble_external (decl);
2758 /* Warn about static fns or vars defined but not used,
2759 but not about inline functions or static consts
2760 since defining those in header files is normal practice. */
2761 if (warn_unused
2762 && ((TREE_CODE (decl) == FUNCTION_DECL && ! DECL_INLINE (decl))
2763 || (TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
2764 && ! DECL_IN_SYSTEM_HEADER (decl)
2765 && ! DECL_EXTERNAL (decl)
2766 && ! TREE_PUBLIC (decl)
2767 && ! TREE_USED (decl)
2768 && (TREE_CODE (decl) == FUNCTION_DECL || ! DECL_REGISTER (decl))
2769 /* The TREE_USED bit for file-scope decls
2770 is kept in the identifier, to handle multiple
2771 external decls in different scopes. */
2772 && ! TREE_USED (DECL_NAME (decl)))
2773 warning_with_decl (decl, "`%s' defined but not used");
2775 #ifdef SDB_DEBUGGING_INFO
2776 /* The COFF linker can move initialized global vars to the end.
2777 And that can screw up the symbol ordering.
2778 By putting the symbols in that order to begin with,
2779 we avoid a problem. mcsun!unido!fauern!tumuc!pes@uunet.uu.net. */
2780 if (write_symbols == SDB_DEBUG && TREE_CODE (decl) == VAR_DECL
2781 && TREE_PUBLIC (decl) && DECL_INITIAL (decl)
2782 && ! DECL_EXTERNAL (decl)
2783 && DECL_RTL (decl) != 0)
2784 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
2786 /* Output COFF information for non-global
2787 file-scope initialized variables. */
2788 if (write_symbols == SDB_DEBUG
2789 && TREE_CODE (decl) == VAR_DECL
2790 && DECL_INITIAL (decl)
2791 && ! DECL_EXTERNAL (decl)
2792 && DECL_RTL (decl) != 0
2793 && GET_CODE (DECL_RTL (decl)) == MEM)
2794 TIMEVAR (symout_time, sdbout_toplevel_data (decl));
2795 #endif /* SDB_DEBUGGING_INFO */
2796 #ifdef DWARF_DEBUGGING_INFO
2797 /* Output DWARF information for file-scope tentative data object
2798 declarations, file-scope (extern) function declarations (which
2799 had no corresponding body) and file-scope tagged type declarations
2800 and definitions which have not yet been forced out. */
2802 if (write_symbols == DWARF_DEBUG
2803 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
2804 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 1));
2805 #endif
2806 #ifdef DWARF2_DEBUGGING_INFO
2807 /* Output DWARF2 information for file-scope tentative data object
2808 declarations, file-scope (extern) function declarations (which
2809 had no corresponding body) and file-scope tagged type declarations
2810 and definitions which have not yet been forced out. */
2812 if (write_symbols == DWARF2_DEBUG
2813 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
2814 TIMEVAR (symout_time, dwarf2out_decl (decl));
2815 #endif
2819 /* Compile an entire file of output from cpp, named NAME.
2820 Write a file of assembly output and various debugging dumps. */
2822 static void
2823 compile_file (name)
2824 char *name;
2826 tree globals;
2827 int start_time;
2829 int name_specified = name != 0;
2831 if (dump_base_name == 0)
2832 dump_base_name = name ? name : "gccdump";
2834 parse_time = 0;
2835 varconst_time = 0;
2836 integration_time = 0;
2837 jump_time = 0;
2838 cse_time = 0;
2839 gcse_time = 0;
2840 loop_time = 0;
2841 cse2_time = 0;
2842 branch_prob_time = 0;
2843 flow_time = 0;
2844 combine_time = 0;
2845 regmove_time = 0;
2846 sched_time = 0;
2847 local_alloc_time = 0;
2848 global_alloc_time = 0;
2849 flow2_time = 0;
2850 peephole2_time = 0;
2851 sched2_time = 0;
2852 dbr_sched_time = 0;
2853 shorten_branch_time = 0;
2854 stack_reg_time = 0;
2855 final_time = 0;
2856 symout_time = 0;
2857 dump_time = 0;
2859 /* Initialize data in various passes. */
2861 init_obstacks ();
2862 init_tree_codes ();
2863 name = init_parse (name);
2864 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
2865 || debug_info_level == DINFO_LEVEL_VERBOSE
2866 || flag_test_coverage
2867 || warn_notreached);
2868 init_regs ();
2869 init_decl_processing ();
2870 init_optabs ();
2871 init_stmt ();
2872 init_eh ();
2873 init_loop ();
2874 init_reload ();
2875 init_alias_once ();
2876 init_function_once ();
2877 init_stor_layout_once ();
2878 init_varasm_once ();
2880 /* The following initialization functions need to generate rtl, so
2881 provide a dummy function context for them. */
2882 init_dummy_function_start ();
2883 init_expmed ();
2884 init_expr_once ();
2885 if (flag_caller_saves)
2886 init_caller_save ();
2887 expand_dummy_function_end ();
2889 /* If auxiliary info generation is desired, open the output file.
2890 This goes in the same directory as the source file--unlike
2891 all the other output files. */
2892 if (flag_gen_aux_info)
2894 aux_info_file = fopen (aux_info_file_name, "w");
2895 if (aux_info_file == 0)
2896 pfatal_with_name (aux_info_file_name);
2899 /* Clear the dump files. */
2900 if (rtl_dump)
2901 clean_dump_file (".00.rtl");
2902 if (jump_opt_dump)
2904 clean_dump_file (".01.jump");
2905 if (graph_dump_format != no_graph)
2906 clean_graph_dump_file (dump_base_name, ".01.jump");
2908 if (cse_dump)
2910 clean_dump_file (".02.cse");
2911 if (graph_dump_format != no_graph)
2912 clean_graph_dump_file (dump_base_name, ".02.cse");
2914 if (addressof_dump)
2916 clean_dump_file (".03.addressof");
2917 if (graph_dump_format != no_graph)
2918 clean_graph_dump_file (dump_base_name, ".03.addressof");
2920 if (gcse_dump)
2922 clean_dump_file (".04.gcse");
2923 if (graph_dump_format != no_graph)
2924 clean_graph_dump_file (dump_base_name, ".04.gcse");
2926 if (loop_dump)
2928 clean_dump_file (".05.loop");
2929 if (graph_dump_format != no_graph)
2930 clean_graph_dump_file (dump_base_name, ".05.loop");
2932 if (cse2_dump)
2934 clean_dump_file (".06.cse2");
2935 if (graph_dump_format != no_graph)
2936 clean_graph_dump_file (dump_base_name, ".06.cse2");
2938 if (branch_prob_dump)
2940 clean_dump_file (".07.bp");
2941 if (graph_dump_format != no_graph)
2942 clean_graph_dump_file (dump_base_name, ".07.bp");
2944 if (flow_dump)
2946 clean_dump_file (".08.flow");
2947 if (graph_dump_format != no_graph)
2948 clean_graph_dump_file (dump_base_name, ".08.flow");
2950 if (combine_dump)
2952 clean_dump_file (".09.combine");
2953 if (graph_dump_format != no_graph)
2954 clean_graph_dump_file (dump_base_name, ".09.combine");
2956 if (regmove_dump)
2958 clean_dump_file (".10.regmove");
2959 if (graph_dump_format != no_graph)
2960 clean_graph_dump_file (dump_base_name, ".10.regmove");
2962 #ifdef INSN_SCHEDULING
2963 if (sched_dump)
2965 clean_dump_file (".11.sched");
2966 if (graph_dump_format != no_graph)
2967 clean_graph_dump_file (dump_base_name, ".11.sched");
2969 #endif
2970 if (local_reg_dump)
2972 clean_dump_file (".12.lreg");
2973 if (graph_dump_format != no_graph)
2974 clean_graph_dump_file (dump_base_name, ".12.lreg");
2976 if (global_reg_dump)
2978 clean_dump_file (".13.greg");
2979 if (graph_dump_format != no_graph)
2980 clean_graph_dump_file (dump_base_name, ".13.greg");
2982 if (flow2_dump)
2984 clean_dump_file (".14.flow2");
2985 if (graph_dump_format != no_graph)
2986 clean_graph_dump_file (dump_base_name, ".14.flow2");
2988 #ifdef HAVE_peephole2
2989 if (peephole2_dump)
2991 clean_dump_file (".15.peephole2");
2992 if (graph_dump_format != no_graph)
2993 clean_graph_dump_file (dump_base_name, ".15.peephole2");
2995 #endif
2996 #ifdef INSN_SCHEDULING
2997 if (sched2_dump)
2999 clean_dump_file (".16.sched2");
3000 if (graph_dump_format != no_graph)
3001 clean_graph_dump_file (dump_base_name, ".16.sched2");
3003 #endif
3004 if (jump2_opt_dump)
3006 clean_dump_file (".17.jump2");
3007 if (graph_dump_format != no_graph)
3008 clean_graph_dump_file (dump_base_name, ".17.jump2");
3010 #ifdef MACHINE_DEPENDENT_REORG
3011 if (mach_dep_reorg_dump)
3013 clean_dump_file (".18.mach");
3014 if (graph_dump_format != no_graph)
3015 clean_graph_dump_file (dump_base_name, ".18.mach");
3017 #endif
3018 #ifdef DELAY_SLOTS
3019 if (dbr_sched_dump)
3021 clean_dump_file (".19.dbr");
3022 if (graph_dump_format != no_graph)
3023 clean_graph_dump_file (dump_base_name, ".19.dbr");
3025 #endif
3026 #ifdef STACK_REGS
3027 if (stack_reg_dump)
3029 clean_dump_file (".20.stack");
3030 if (graph_dump_format != no_graph)
3031 clean_graph_dump_file (dump_base_name, ".20.stack");
3033 #endif
3035 /* Open assembler code output file. */
3037 if (flag_syntax_only)
3038 asm_out_file = NULL;
3039 else
3041 if (! name_specified && asm_file_name == 0)
3042 asm_out_file = stdout;
3043 else
3045 int len = strlen (dump_base_name);
3046 register char *dumpname = (char *) xmalloc (len + 6);
3047 strcpy (dumpname, dump_base_name);
3048 strip_off_ending (dumpname, len);
3049 strcat (dumpname, ".s");
3050 if (asm_file_name == 0)
3051 asm_file_name = xstrdup (dumpname);
3052 if (!strcmp (asm_file_name, "-"))
3053 asm_out_file = stdout;
3054 else
3055 asm_out_file = fopen (asm_file_name, "w");
3056 if (asm_out_file == 0)
3057 pfatal_with_name (asm_file_name);
3060 #ifdef IO_BUFFER_SIZE
3061 setvbuf (asm_out_file, (char *) xmalloc (IO_BUFFER_SIZE),
3062 _IOFBF, IO_BUFFER_SIZE);
3063 #endif
3066 if (ggc_p)
3067 name = ggc_alloc_string (name, strlen (name));
3068 input_filename = name;
3070 /* Put an entry on the input file stack for the main input file. */
3071 input_file_stack
3072 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
3073 input_file_stack->next = 0;
3074 input_file_stack->name = input_filename;
3076 /* Perform language-specific initialization.
3077 This may set main_input_filename. */
3078 lang_init ();
3080 /* If the input doesn't start with a #line, use the input name
3081 as the official input file name. */
3082 if (main_input_filename == 0)
3083 main_input_filename = name;
3085 if (flag_syntax_only)
3087 write_symbols = NO_DEBUG;
3088 profile_flag = 0;
3089 profile_block_flag = 0;
3091 else
3093 ASM_FILE_START (asm_out_file);
3095 #ifdef ASM_COMMENT_START
3096 if (flag_verbose_asm)
3098 /* Print the list of options in effect. */
3099 print_version (asm_out_file, ASM_COMMENT_START);
3100 print_switch_values (asm_out_file, 0, MAX_LINE,
3101 ASM_COMMENT_START, " ", "\n");
3102 /* Add a blank line here so it appears in assembler output but not
3103 screen output. */
3104 fprintf (asm_out_file, "\n");
3106 #endif
3108 /* Output something to inform GDB that this compilation was by GCC. */
3109 #ifndef ASM_IDENTIFY_GCC
3110 fprintf (asm_out_file, "gcc2_compiled.:\n");
3111 #else
3112 ASM_IDENTIFY_GCC (asm_out_file);
3113 #endif
3115 /* Output something to identify which front-end produced this file. */
3116 #ifdef ASM_IDENTIFY_LANGUAGE
3117 ASM_IDENTIFY_LANGUAGE (asm_out_file);
3118 #endif
3119 } /* ! flag_syntax_only */
3121 #ifndef ASM_OUTPUT_SECTION_NAME
3122 if (flag_function_sections)
3124 warning ("-ffunction-sections not supported for this target.");
3125 flag_function_sections = 0;
3127 if (flag_data_sections)
3129 warning ("-fdata-sections not supported for this target.");
3130 flag_data_sections = 0;
3132 #endif
3134 if (flag_function_sections
3135 && (profile_flag || profile_block_flag))
3137 warning ("-ffunction-sections disabled; it makes profiling impossible.");
3138 flag_function_sections = 0;
3141 #ifndef OBJECT_FORMAT_ELF
3142 if (flag_function_sections && write_symbols != NO_DEBUG)
3143 warning ("-ffunction-sections may affect debugging on some targets.");
3144 #endif
3146 /* ??? Note: There used to be a conditional here
3147 to call assemble_zeros without fail if DBX_DEBUGGING_INFO is defined.
3148 This was to guarantee separation between gcc_compiled. and
3149 the first function, for the sake of dbx on Suns.
3150 However, having the extra zero here confused the Emacs
3151 code for unexec, and might confuse other programs too.
3152 Therefore, I took out that change.
3153 In future versions we should find another way to solve
3154 that dbx problem. -- rms, 23 May 93. */
3156 /* Don't let the first function fall at the same address
3157 as gcc_compiled., if profiling. */
3158 if (profile_flag || profile_block_flag)
3160 /* It's best if we can write a nop here since some
3161 assemblers don't tolerate zeros in the text section. */
3162 output_asm_insn (get_insn_template (CODE_FOR_nop, NULL), NULL_PTR);
3165 /* If dbx symbol table desired, initialize writing it
3166 and output the predefined types. */
3167 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3168 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3169 TIMEVAR (symout_time, dbxout_init (asm_out_file, main_input_filename,
3170 getdecls ()));
3171 #endif
3172 #ifdef SDB_DEBUGGING_INFO
3173 if (write_symbols == SDB_DEBUG)
3174 TIMEVAR (symout_time, sdbout_init (asm_out_file, main_input_filename,
3175 getdecls ()));
3176 #endif
3177 #ifdef DWARF_DEBUGGING_INFO
3178 if (write_symbols == DWARF_DEBUG)
3179 TIMEVAR (symout_time, dwarfout_init (asm_out_file, main_input_filename));
3180 #endif
3181 #ifdef DWARF2_UNWIND_INFO
3182 if (dwarf2out_do_frame ())
3183 dwarf2out_frame_init ();
3184 #endif
3185 #ifdef DWARF2_DEBUGGING_INFO
3186 if (write_symbols == DWARF2_DEBUG)
3187 TIMEVAR (symout_time, dwarf2out_init (asm_out_file, main_input_filename));
3188 #endif
3190 /* Initialize yet another pass. */
3192 init_final (main_input_filename);
3193 init_branch_prob (dump_base_name);
3195 start_time = get_run_time ();
3197 /* Call the parser, which parses the entire file
3198 (calling rest_of_compilation for each function). */
3200 if (yyparse () != 0)
3202 if (errorcount == 0)
3203 notice ("Errors detected in input file (your bison.simple is out of date)\n");
3205 /* In case there were missing closebraces,
3206 get us back to the global binding level. */
3207 while (! global_bindings_p ())
3208 poplevel (0, 0, 0);
3211 /* Compilation is now finished except for writing
3212 what's left of the symbol table output. */
3214 parse_time += get_run_time () - start_time;
3216 parse_time -= integration_time;
3217 parse_time -= varconst_time;
3219 if (flag_syntax_only)
3220 goto finish_syntax;
3222 globals = getdecls ();
3224 /* Really define vars that have had only a tentative definition.
3225 Really output inline functions that must actually be callable
3226 and have not been output so far. */
3229 int len = list_length (globals);
3230 tree *vec = (tree *) alloca (sizeof (tree) * len);
3231 int i;
3232 tree decl;
3234 /* Process the decls in reverse order--earliest first.
3235 Put them into VEC from back to front, then take out from front. */
3237 for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
3238 vec[len - i - 1] = decl;
3240 wrapup_global_declarations (vec, len);
3242 /* This must occur after the loop to output deferred functions. Else
3243 the profiler initializer would not be emitted if all the functions
3244 in this compilation unit were deferred.
3246 output_func_start_profiler can not cause any additional functions or
3247 data to need to be output, so it need not be in the deferred function
3248 loop above. */
3249 output_func_start_profiler ();
3251 /* Now that all possible functions have been output, we can dump
3252 the exception table. */
3254 output_exception_table ();
3256 check_global_declarations (vec, len);
3259 /* Write out any pending weak symbol declarations. */
3261 weak_finish ();
3263 /* Do dbx symbols */
3264 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3265 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3266 TIMEVAR (symout_time,
3268 dbxout_finish (asm_out_file, main_input_filename);
3270 #endif
3272 #ifdef DWARF_DEBUGGING_INFO
3273 if (write_symbols == DWARF_DEBUG)
3274 TIMEVAR (symout_time,
3276 dwarfout_finish ();
3278 #endif
3280 #ifdef DWARF2_UNWIND_INFO
3281 if (dwarf2out_do_frame ())
3282 dwarf2out_frame_finish ();
3283 #endif
3285 #ifdef DWARF2_DEBUGGING_INFO
3286 if (write_symbols == DWARF2_DEBUG)
3287 TIMEVAR (symout_time,
3289 dwarf2out_finish ();
3291 #endif
3293 /* Output some stuff at end of file if nec. */
3295 end_final (dump_base_name);
3297 if (branch_prob_dump)
3298 open_dump_file (".07.bp", NULL);
3300 TIMEVAR (dump_time, end_branch_prob (rtl_dump_file));
3302 if (branch_prob_dump)
3303 close_dump_file (NULL, NULL_RTX);
3305 #ifdef ASM_FILE_END
3306 ASM_FILE_END (asm_out_file);
3307 #endif
3310 /* Language-specific end of compilation actions. */
3311 finish_syntax:
3312 lang_finish ();
3314 /* Close the dump files. */
3316 if (flag_gen_aux_info)
3318 fclose (aux_info_file);
3319 if (errorcount)
3320 unlink (aux_info_file_name);
3323 if (combine_dump)
3325 open_dump_file (".09.combine", NULL);
3326 TIMEVAR (dump_time, dump_combine_total_stats (rtl_dump_file));
3327 close_dump_file (NULL, NULL_RTX);
3330 /* Close non-debugging input and output files. Take special care to note
3331 whether fclose returns an error, since the pages might still be on the
3332 buffer chain while the file is open. */
3334 finish_parse ();
3336 if (! flag_syntax_only
3337 && (ferror (asm_out_file) != 0 || fclose (asm_out_file) != 0))
3338 fatal_io_error (asm_file_name);
3340 /* Do whatever is necessary to finish printing the graphs. */
3341 if (graph_dump_format != no_graph)
3343 if (jump_opt_dump)
3344 finish_graph_dump_file (dump_base_name, ".01.jump");
3345 if (cse_dump)
3346 finish_graph_dump_file (dump_base_name, ".02.cse");
3347 if (addressof_dump)
3348 finish_graph_dump_file (dump_base_name, ".03.addressof");
3349 if (gcse_dump)
3350 finish_graph_dump_file (dump_base_name, ".04.gcse");
3351 if (loop_dump)
3352 finish_graph_dump_file (dump_base_name, ".05.loop");
3353 if (cse2_dump)
3354 finish_graph_dump_file (dump_base_name, ".06.cse2");
3355 if (branch_prob_dump)
3356 finish_graph_dump_file (dump_base_name, ".07.bp");
3357 if (flow_dump)
3358 finish_graph_dump_file (dump_base_name, ".08.flow");
3359 if (combine_dump)
3360 finish_graph_dump_file (dump_base_name, ".09.combine");
3361 if (regmove_dump)
3362 finish_graph_dump_file (dump_base_name, ".10.regmove");
3363 #ifdef INSN_SCHEDULING
3364 if (sched_dump)
3365 finish_graph_dump_file (dump_base_name, ".11.sched");
3366 #endif
3367 if (local_reg_dump)
3368 finish_graph_dump_file (dump_base_name, ".12.lreg");
3369 if (global_reg_dump)
3370 finish_graph_dump_file (dump_base_name, ".13.greg");
3371 if (flow2_dump)
3372 finish_graph_dump_file (dump_base_name, ".14.flow2");
3373 #ifdef HAVE_peephole2
3374 if (flow2_dump)
3375 finish_graph_dump_file (dump_base_name, ".15.peephole2");
3376 #endif
3377 #ifdef INSN_SCHEDULING
3378 if (sched2_dump)
3379 finish_graph_dump_file (dump_base_name, ".16.sched2");
3380 #endif
3381 if (jump2_opt_dump)
3382 finish_graph_dump_file (dump_base_name, ".17.jump2");
3383 #ifdef MACHINE_DEPENDENT_REORG
3384 if (mach_dep_reorg_dump)
3385 finish_graph_dump_file (dump_base_name, ".18.mach");
3386 #endif
3387 #ifdef DELAY_SLOTS
3388 if (dbr_sched_dump)
3389 finish_graph_dump_file (dump_base_name, ".19.dbr");
3390 #endif
3391 #ifdef STACK_REGS
3392 if (stack_reg_dump)
3393 finish_graph_dump_file (dump_base_name, ".20.stack");
3394 #endif
3397 /* Free up memory for the benefit of leak detectors. */
3398 free_reg_info ();
3400 /* Print the times. */
3402 if (! quiet_flag)
3404 all_time = get_run_time ();
3406 fprintf (stderr,"\n");
3408 print_time ("parse", parse_time);
3409 print_time ("integration", integration_time);
3410 print_time ("jump", jump_time);
3411 print_time ("cse", cse_time);
3412 print_time ("gcse", gcse_time);
3413 print_time ("loop", loop_time);
3414 print_time ("cse2", cse2_time);
3415 print_time ("branch-prob", branch_prob_time);
3416 print_time ("flow", flow_time);
3417 print_time ("combine", combine_time);
3418 print_time ("regmove", regmove_time);
3419 #ifdef INSN_SCHEDULING
3420 print_time ("sched", sched_time);
3421 #endif
3422 print_time ("local-alloc", local_alloc_time);
3423 print_time ("global-alloc", global_alloc_time);
3424 print_time ("flow2", flow2_time);
3425 #ifdef HAVE_peephole2
3426 print_time ("peephole2", peephole2_time);
3427 #endif
3428 #ifdef INSN_SCHEDULING
3429 print_time ("sched2", sched2_time);
3430 #endif
3431 #ifdef DELAY_SLOTS
3432 print_time ("dbranch", dbr_sched_time);
3433 #endif
3434 print_time ("shorten-branch", shorten_branch_time);
3435 #ifdef STACK_REGS
3436 print_time ("stack-reg", stack_reg_time);
3437 #endif
3438 print_time ("final", final_time);
3439 print_time ("varconst", varconst_time);
3440 print_time ("symout", symout_time);
3441 print_time ("dump", dump_time);
3442 if (ggc_p)
3443 print_time ("gc", gc_time);
3447 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
3448 and TYPE_DECL nodes.
3450 This does nothing for local (non-static) variables, unless the
3451 variable is a register variable with an ASMSPEC. In that case, or
3452 if the variable is not an automatice, it sets up the RTL and
3453 outputs any assembler code (label definition, storage allocation
3454 and initialization).
3456 DECL is the declaration. If ASMSPEC is nonzero, it specifies
3457 the assembler symbol name to be used. TOP_LEVEL is nonzero
3458 if this declaration is not within a function. */
3460 void
3461 rest_of_decl_compilation (decl, asmspec, top_level, at_end)
3462 tree decl;
3463 const char *asmspec;
3464 int top_level;
3465 int at_end;
3467 /* Declarations of variables, and of functions defined elsewhere. */
3469 /* The most obvious approach, to put an #ifndef around where
3470 this macro is used, doesn't work since it's inside a macro call. */
3471 #ifndef ASM_FINISH_DECLARE_OBJECT
3472 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP, END)
3473 #endif
3475 /* Forward declarations for nested functions are not "external",
3476 but we need to treat them as if they were. */
3477 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
3478 || TREE_CODE (decl) == FUNCTION_DECL)
3479 TIMEVAR (varconst_time,
3481 make_decl_rtl (decl, asmspec, top_level);
3482 /* Initialized extern variable exists to be replaced
3483 with its value, or represents something that will be
3484 output in another file. */
3485 if (! (TREE_CODE (decl) == VAR_DECL
3486 && DECL_EXTERNAL (decl) && TREE_READONLY (decl)
3487 && DECL_INITIAL (decl) != 0
3488 && DECL_INITIAL (decl) != error_mark_node))
3489 /* Don't output anything
3490 when a tentative file-scope definition is seen.
3491 But at end of compilation, do output code for them. */
3492 if (! (! at_end && top_level
3493 && (DECL_INITIAL (decl) == 0
3494 || DECL_INITIAL (decl) == error_mark_node)))
3495 assemble_variable (decl, top_level, at_end, 0);
3496 if (decl == last_assemble_variable_decl)
3498 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
3499 top_level, at_end);
3502 else if (DECL_REGISTER (decl) && asmspec != 0)
3504 if (decode_reg_name (asmspec) >= 0)
3506 DECL_RTL (decl) = 0;
3507 make_decl_rtl (decl, asmspec, top_level);
3509 else
3510 error ("invalid register name `%s' for register variable", asmspec);
3512 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3513 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3514 && TREE_CODE (decl) == TYPE_DECL)
3515 TIMEVAR (symout_time, dbxout_symbol (decl, 0));
3516 #endif
3517 #ifdef SDB_DEBUGGING_INFO
3518 else if (write_symbols == SDB_DEBUG && top_level
3519 && TREE_CODE (decl) == TYPE_DECL)
3520 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
3521 #endif
3524 /* Called after finishing a record, union or enumeral type. */
3526 void
3527 rest_of_type_compilation (type, toplev)
3528 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO) || defined (SDB_DEBUGGING_INFO)
3529 tree type;
3530 int toplev;
3531 #else
3532 tree type ATTRIBUTE_UNUSED;
3533 int toplev ATTRIBUTE_UNUSED;
3534 #endif
3536 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3537 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3538 TIMEVAR (symout_time, dbxout_symbol (TYPE_STUB_DECL (type), !toplev));
3539 #endif
3540 #ifdef SDB_DEBUGGING_INFO
3541 if (write_symbols == SDB_DEBUG)
3542 TIMEVAR (symout_time, sdbout_symbol (TYPE_STUB_DECL (type), !toplev));
3543 #endif
3546 /* This is called from finish_function (within yyparse)
3547 after each top-level definition is parsed.
3548 It is supposed to compile that function or variable
3549 and output the assembler code for it.
3550 After we return, the tree storage is freed. */
3552 void
3553 rest_of_compilation (decl)
3554 tree decl;
3556 register rtx insns;
3557 int start_time = get_run_time ();
3558 int tem;
3559 /* Nonzero if we have saved the original DECL_INITIAL of the function,
3560 to be restored after we finish compiling the function
3561 (for use when compiling inline calls to this function). */
3562 tree saved_block_tree = 0;
3563 /* Likewise, for DECL_ARGUMENTS. */
3564 tree saved_arguments = 0;
3565 int failure = 0;
3566 int rebuild_label_notes_after_reload;
3568 /* If we are reconsidering an inline function
3569 at the end of compilation, skip the stuff for making it inline. */
3571 if (DECL_SAVED_INSNS (decl) == 0)
3573 int inlinable = 0;
3574 const char *lose;
3576 /* If requested, consider whether to make this function inline. */
3577 if (DECL_INLINE (decl) || flag_inline_functions)
3578 TIMEVAR (integration_time,
3580 lose = function_cannot_inline_p (decl);
3581 if (lose || ! optimize)
3583 if (warn_inline && DECL_INLINE (decl))
3584 warning_with_decl (decl, lose);
3585 DECL_ABSTRACT_ORIGIN (decl) = 0;
3586 /* Don't really compile an extern inline function.
3587 If we can't make it inline, pretend
3588 it was only declared. */
3589 if (DECL_EXTERNAL (decl))
3591 DECL_INITIAL (decl) = 0;
3592 goto exit_rest_of_compilation;
3595 else
3596 /* ??? Note that this has the effect of making it look
3597 like "inline" was specified for a function if we choose
3598 to inline it. This isn't quite right, but it's
3599 probably not worth the trouble to fix. */
3600 inlinable = DECL_INLINE (decl) = 1;
3603 insns = get_insns ();
3605 /* Dump the rtl code if we are dumping rtl. */
3607 if (rtl_dump)
3609 open_dump_file (".00.rtl", decl_printable_name (decl, 2));
3611 if (DECL_SAVED_INSNS (decl))
3612 fprintf (rtl_dump_file, ";; (integrable)\n\n");
3614 close_dump_file (print_rtl, insns);
3617 /* If function is inline, and we don't yet know whether to
3618 compile it by itself, defer decision till end of compilation.
3619 finish_compilation will call rest_of_compilation again
3620 for those functions that need to be output. Also defer those
3621 functions that we are supposed to defer. */
3623 if (inlinable)
3624 DECL_DEFER_OUTPUT (decl) = 1;
3626 if (DECL_DEFER_OUTPUT (decl)
3627 || (DECL_INLINE (decl)
3628 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
3629 && ! flag_keep_inline_functions)
3630 || DECL_EXTERNAL (decl))))
3632 DECL_DEFER_OUTPUT (decl) = 1;
3634 /* If -Wreturn-type, we have to do a bit of compilation.
3635 However, if we just fall through we will call
3636 save_for_inline_copying() which results in excessive
3637 memory use. Instead, we just want to call
3638 jump_optimize() to figure out whether or not we can fall
3639 off the end of the function; we do the minimum amount of
3640 work necessary to make that safe. And, we set optimize
3641 to zero to keep jump_optimize from working too hard. */
3642 if (warn_return_type)
3644 int saved_optimize = optimize;
3645 optimize = 0;
3646 find_exception_handler_labels ();
3647 jump_optimize (get_insns(), !JUMP_CROSS_JUMP, !JUMP_NOOP_MOVES,
3648 !JUMP_AFTER_REGSCAN);
3649 optimize = saved_optimize;
3652 #ifdef DWARF_DEBUGGING_INFO
3653 /* Generate the DWARF info for the "abstract" instance
3654 of a function which we may later generate inlined and/or
3655 out-of-line instances of. */
3656 if (write_symbols == DWARF_DEBUG)
3658 set_decl_abstract_flags (decl, 1);
3659 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
3660 set_decl_abstract_flags (decl, 0);
3662 #endif
3663 #ifdef DWARF2_DEBUGGING_INFO
3664 /* Generate the DWARF2 info for the "abstract" instance
3665 of a function which we may later generate inlined and/or
3666 out-of-line instances of. */
3667 if (write_symbols == DWARF2_DEBUG)
3669 set_decl_abstract_flags (decl, 1);
3670 TIMEVAR (symout_time, dwarf2out_decl (decl));
3671 set_decl_abstract_flags (decl, 0);
3673 #endif
3674 TIMEVAR (integration_time, save_for_inline_nocopy (decl));
3675 DECL_SAVED_INSNS (decl)->inlinable = inlinable;
3676 goto exit_rest_of_compilation;
3679 /* If specified extern inline but we aren't inlining it, we are
3680 done. This goes for anything that gets here with DECL_EXTERNAL
3681 set, not just things with DECL_INLINE. */
3682 if (DECL_EXTERNAL (decl))
3683 goto exit_rest_of_compilation;
3686 /* Initialize some variables used by the optimizers. */
3687 init_function_for_compilation ();
3689 if (! DECL_DEFER_OUTPUT (decl))
3690 TREE_ASM_WRITTEN (decl) = 1;
3692 /* Now that integrate will no longer see our rtl, we need not distinguish
3693 between the return value of this function and the return value of called
3694 functions. */
3695 rtx_equal_function_value_matters = 0;
3697 /* Don't return yet if -Wreturn-type; we need to do jump_optimize. */
3698 if ((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
3700 goto exit_rest_of_compilation;
3703 /* Emit code to get eh context, if needed. */
3704 emit_eh_context ();
3706 #ifdef FINALIZE_PIC
3707 /* If we are doing position-independent code generation, now
3708 is the time to output special prologues and epilogues.
3709 We do not want to do this earlier, because it just clutters
3710 up inline functions with meaningless insns. */
3711 if (flag_pic)
3712 FINALIZE_PIC;
3713 #endif
3715 /* From now on, allocate rtl in current_obstack, not in saveable_obstack.
3716 Note that that may have been done above, in save_for_inline_copying.
3717 The call to resume_temporary_allocation near the end of this function
3718 goes back to the usual state of affairs. This must be done after
3719 we've built up any unwinders for exception handling, and done
3720 the FINALIZE_PIC work, if necessary. */
3722 rtl_in_current_obstack ();
3724 insns = get_insns ();
3726 /* Copy any shared structure that should not be shared. */
3728 unshare_all_rtl (insns);
3730 init_EXPR_INSN_LIST_cache ();
3732 #ifdef SETJMP_VIA_SAVE_AREA
3733 /* This must be performed before virutal register instantiation. */
3734 if (current_function_calls_alloca)
3735 optimize_save_area_alloca (insns);
3736 #endif
3738 /* Instantiate all virtual registers. */
3740 instantiate_virtual_regs (current_function_decl, get_insns ());
3742 /* See if we have allocated stack slots that are not directly addressable.
3743 If so, scan all the insns and create explicit address computation
3744 for all references to such slots. */
3745 /* fixup_stack_slots (); */
3747 /* Find all the EH handlers. */
3748 find_exception_handler_labels ();
3750 if (jump_opt_dump)
3751 open_dump_file (".01.jump", decl_printable_name (decl, 2));
3753 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3754 are initialized and to compute whether control can drop off the end
3755 of the function. */
3756 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3757 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP, !JUMP_NOOP_MOVES,
3758 JUMP_AFTER_REGSCAN));
3760 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
3761 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
3762 goto exit_rest_of_compilation;
3764 /* Try to identify useless null pointer tests and delete them. */
3765 if (flag_delete_null_pointer_checks)
3766 TIMEVAR (jump_time, delete_null_pointer_checks (get_insns ()));
3768 /* Dump rtl code after jump, if we are doing that. */
3769 if (jump_opt_dump)
3770 close_dump_file (print_rtl, insns);
3772 if (ggc_p)
3773 ggc_collect ();
3775 /* Perform common subexpression elimination.
3776 Nonzero value from `cse_main' means that jumps were simplified
3777 and some code may now be unreachable, so do
3778 jump optimization again. */
3780 if (optimize > 0)
3782 if (cse_dump)
3783 open_dump_file (".02.cse", decl_printable_name (decl, 2));
3785 TIMEVAR (cse_time, reg_scan (insns, max_reg_num (), 1));
3787 if (flag_thread_jumps)
3788 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 1));
3790 TIMEVAR (cse_time, tem = cse_main (insns, max_reg_num (),
3791 0, rtl_dump_file));
3792 /* If we are not running the second CSE pass, then we are no longer
3793 expecting CSE to be run. */
3794 cse_not_expected = !flag_rerun_cse_after_loop;
3796 if (tem || optimize > 1)
3797 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3798 !JUMP_NOOP_MOVES,
3799 !JUMP_AFTER_REGSCAN));
3801 /* Run this after jump optmizations remove all the unreachable code
3802 so that unreachable code will not keep values live. */
3803 TIMEVAR (cse_time, delete_trivially_dead_insns (insns, max_reg_num ()));
3805 /* Try to identify useless null pointer tests and delete them. */
3806 if (flag_delete_null_pointer_checks)
3807 TIMEVAR (jump_time, delete_null_pointer_checks (get_insns ()));
3809 /* Dump rtl code after cse, if we are doing that. */
3811 if (cse_dump)
3813 close_dump_file (print_rtl, insns);
3814 if (graph_dump_format != no_graph)
3815 print_rtl_graph_with_bb (dump_base_name, ".02.cse", insns);
3819 purge_addressof (insns);
3820 reg_scan (insns, max_reg_num (), 1);
3822 if (addressof_dump)
3824 dump_rtl (".03.addressof", decl, print_rtl, insns);
3825 if (graph_dump_format != no_graph)
3826 print_rtl_graph_with_bb (dump_base_name, ".03.addressof", insns);
3829 if (ggc_p)
3830 ggc_collect ();
3832 /* Perform global cse. */
3834 if (optimize > 0 && flag_gcse)
3836 if (gcse_dump)
3837 open_dump_file (".04.gcse", decl_printable_name (decl, 2));
3839 TIMEVAR (gcse_time, tem = gcse_main (insns, rtl_dump_file));
3841 /* If gcse altered any jumps, rerun jump optimizations to clean
3842 things up. */
3843 if (tem)
3845 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3846 !JUMP_NOOP_MOVES,
3847 !JUMP_AFTER_REGSCAN));
3850 if (gcse_dump)
3852 close_dump_file (print_rtl, insns);
3853 if (graph_dump_format != no_graph)
3854 print_rtl_graph_with_bb (dump_base_name, ".04.gcse", insns);
3857 if (ggc_p)
3858 ggc_collect ();
3860 /* Move constant computations out of loops. */
3862 if (optimize > 0)
3864 if (loop_dump)
3865 open_dump_file (".05.loop", decl_printable_name (decl, 2));
3867 TIMEVAR
3868 (loop_time,
3870 if (flag_rerun_loop_opt)
3872 /* We only want to perform unrolling once. */
3874 loop_optimize (insns, rtl_dump_file, 0, 0);
3877 /* The first call to loop_optimize makes some instructions
3878 trivially dead. We delete those instructions now in the
3879 hope that doing so will make the heuristics in loop work
3880 better and possibly speed up compilation. */
3881 delete_trivially_dead_insns (insns, max_reg_num ());
3883 /* The regscan pass is currently necessary as the alias
3884 analysis code depends on this information. */
3885 reg_scan (insns, max_reg_num (), 1);
3887 loop_optimize (insns, rtl_dump_file, flag_unroll_loops, 1);
3890 /* Dump rtl code after loop opt, if we are doing that. */
3892 if (loop_dump)
3894 close_dump_file (print_rtl, insns);
3895 if (graph_dump_format != no_graph)
3896 print_rtl_graph_with_bb (dump_base_name, ".05.loop", insns);
3899 if (ggc_p)
3900 ggc_collect ();
3903 /* ??? Well, nearly. If HAVE_conditional_arithmetic, jump_optimize
3904 has put off all if-conversion until "after CSE". If we put this
3905 off any longer we may miss out doing if-conversion entirely. */
3906 cse_not_expected = 1;
3908 if (optimize > 0)
3910 if (cse2_dump)
3911 open_dump_file (".06.cse2", decl_printable_name (decl, 2));
3913 if (flag_rerun_cse_after_loop)
3915 /* Running another jump optimization pass before the second
3916 cse pass sometimes simplifies the RTL enough to allow
3917 the second CSE pass to do a better job. Jump_optimize can change
3918 max_reg_num so we must rerun reg_scan afterwards.
3919 ??? Rework to not call reg_scan so often. */
3920 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3921 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3922 !JUMP_NOOP_MOVES,
3923 JUMP_AFTER_REGSCAN));
3925 TIMEVAR (cse2_time, reg_scan (insns, max_reg_num (), 0));
3926 TIMEVAR (cse2_time, tem = cse_main (insns, max_reg_num (),
3927 1, rtl_dump_file));
3928 if (tem)
3929 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3930 !JUMP_NOOP_MOVES,
3931 !JUMP_AFTER_REGSCAN));
3934 if (flag_thread_jumps)
3936 /* This pass of jump threading straightens out code
3937 that was kinked by loop optimization. */
3938 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3939 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 0));
3942 /* Dump rtl code after cse, if we are doing that. */
3944 if (cse2_dump)
3946 close_dump_file (print_rtl, insns);
3947 if (graph_dump_format != no_graph)
3948 print_rtl_graph_with_bb (dump_base_name, ".06.cse2", insns);
3951 if (ggc_p)
3952 ggc_collect ();
3955 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
3957 if (branch_prob_dump)
3958 open_dump_file (".07.bp", decl_printable_name (decl, 2));
3960 TIMEVAR
3961 (branch_prob_time,
3963 branch_prob (insns, rtl_dump_file);
3966 if (branch_prob_dump)
3968 close_dump_file (print_rtl, insns);
3969 if (graph_dump_format != no_graph)
3970 print_rtl_graph_with_bb (dump_base_name, ".07.bp", insns);
3973 if (ggc_p)
3974 ggc_collect ();
3977 /* Now we choose between stupid (pcc-like) register allocation
3978 (if we got the -noreg switch and not -opt)
3979 and smart register allocation. */
3981 if (optimize > 0) /* Stupid allocation probably won't work */
3982 obey_regdecls = 0; /* if optimizations being done. */
3984 regclass_init ();
3986 /* Print function header into flow dump now
3987 because doing the flow analysis makes some of the dump. */
3989 if (flow_dump)
3990 open_dump_file (".08.flow", decl_printable_name (decl, 2));
3992 if (obey_regdecls)
3994 TIMEVAR (flow_time,
3996 regclass (insns, max_reg_num ());
3997 stupid_life_analysis (insns, max_reg_num (),
3998 rtl_dump_file);
4001 else
4003 /* Do control and data flow analysis,
4004 and write some of the results to dump file. */
4006 TIMEVAR
4007 (flow_time,
4009 find_basic_blocks (insns, max_reg_num (), rtl_dump_file, 1);
4010 life_analysis (insns, max_reg_num (), rtl_dump_file, 1);
4013 if (warn_uninitialized)
4015 uninitialized_vars_warning (DECL_INITIAL (decl));
4016 setjmp_args_warning ();
4020 /* Dump rtl after flow analysis. */
4022 if (flow_dump)
4024 close_dump_file (print_rtl_with_bb, insns);
4025 if (graph_dump_format != no_graph)
4026 print_rtl_graph_with_bb (dump_base_name, ".08.flow", insns);
4029 if (ggc_p)
4030 ggc_collect ();
4032 /* The first life analysis pass has finished. From now on we can not
4033 generate any new pseudos. */
4034 no_new_pseudos = 1;
4036 /* If -opt, try combining insns through substitution. */
4038 if (optimize > 0)
4040 TIMEVAR (combine_time, combine_instructions (insns, max_reg_num ()));
4042 /* Dump rtl code after insn combination. */
4044 if (combine_dump)
4046 dump_rtl (".09.combine", decl, print_rtl_with_bb, insns);
4047 if (graph_dump_format != no_graph)
4048 print_rtl_graph_with_bb (dump_base_name, ".09.combine", insns);
4051 if (ggc_p)
4052 ggc_collect ();
4055 /* Register allocation pre-pass, to reduce number of moves
4056 necessary for two-address machines. */
4057 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
4059 if (regmove_dump)
4060 open_dump_file (".10.regmove", decl_printable_name (decl, 2));
4062 TIMEVAR (regmove_time, regmove_optimize (insns, max_reg_num (),
4063 rtl_dump_file));
4065 if (regmove_dump)
4067 close_dump_file (print_rtl_with_bb, insns);
4068 if (graph_dump_format != no_graph)
4069 print_rtl_graph_with_bb (dump_base_name, ".10.regmove", insns);
4072 if (ggc_p)
4073 ggc_collect ();
4076 /* Print function header into sched dump now
4077 because doing the sched analysis makes some of the dump. */
4079 #ifdef INSN_SCHEDULING
4080 if (optimize > 0 && flag_schedule_insns)
4082 if (sched_dump)
4083 open_dump_file (".11.sched", decl_printable_name (decl, 2));
4085 /* Do control and data sched analysis,
4086 and write some of the results to dump file. */
4088 TIMEVAR (sched_time, schedule_insns (rtl_dump_file));
4090 /* Dump rtl after instruction scheduling. */
4092 if (sched_dump)
4094 close_dump_file (print_rtl_with_bb, insns);
4095 if (graph_dump_format != no_graph)
4096 print_rtl_graph_with_bb (dump_base_name, ".11.sched", insns);
4099 if (ggc_p)
4100 ggc_collect ();
4102 #endif
4104 /* Determine if the current function is a leaf before running reload
4105 since this can impact optimizations done by the prologue and
4106 epilogue thus changing register elimination offsets. */
4107 current_function_is_leaf = leaf_function_p ();
4109 /* Unless we did stupid register allocation,
4110 allocate pseudo-regs that are used only within 1 basic block.
4112 RUN_JUMP_AFTER_RELOAD records whether or not we need to rerun the
4113 jump optimizer after register allocation and reloading are finished. */
4115 if (!obey_regdecls)
4116 TIMEVAR (local_alloc_time,
4118 /* We recomputed reg usage as part of updating the rest
4119 of life info during sched. */
4120 if (! flag_schedule_insns)
4121 recompute_reg_usage (insns, ! optimize_size);
4122 regclass (insns, max_reg_num ());
4123 rebuild_label_notes_after_reload = local_alloc ();
4125 else
4126 rebuild_label_notes_after_reload = 0;
4128 /* Dump rtl code after allocating regs within basic blocks. */
4130 if (local_reg_dump)
4132 open_dump_file (".12.lreg", decl_printable_name (decl, 2));
4134 TIMEVAR (dump_time, dump_flow_info (rtl_dump_file));
4135 TIMEVAR (dump_time, dump_local_alloc (rtl_dump_file));
4137 close_dump_file (print_rtl_with_bb, insns);
4138 if (graph_dump_format != no_graph)
4139 print_rtl_graph_with_bb (dump_base_name, ".12.lreg", insns);
4142 if (ggc_p)
4143 ggc_collect ();
4145 if (global_reg_dump)
4146 open_dump_file (".13.greg", decl_printable_name (decl, 2));
4148 /* Unless we did stupid register allocation,
4149 allocate remaining pseudo-regs, then do the reload pass
4150 fixing up any insns that are invalid. */
4152 TIMEVAR (global_alloc_time,
4154 if (!obey_regdecls)
4155 failure = global_alloc (rtl_dump_file);
4156 else
4157 failure = reload (insns, 0, rtl_dump_file);
4161 if (failure)
4162 goto exit_rest_of_compilation;
4164 if (ggc_p)
4165 ggc_collect ();
4167 /* Do a very simple CSE pass over just the hard registers. */
4168 if (optimize > 0)
4169 reload_cse_regs (insns);
4171 /* Register allocation and reloading may have turned an indirect jump into
4172 a direct jump. If so, we must rebuild the JUMP_LABEL fields of
4173 jumping instructions. */
4174 if (rebuild_label_notes_after_reload)
4175 TIMEVAR (jump_time, rebuild_jump_labels (insns));
4177 /* On some machines, the prologue and epilogue code, or parts thereof,
4178 can be represented as RTL. Doing so lets us schedule insns between
4179 it and the rest of the code and also allows delayed branch
4180 scheduling to operate in the epilogue. */
4182 thread_prologue_and_epilogue_insns (insns);
4184 /* If optimizing and we are performing instruction scheduling after
4185 reload, then go ahead and split insns now since we are about to
4186 recompute flow information anyway.
4188 reload_cse_regs may expose more splitting opportunities, expecially
4189 for double-word operations. */
4190 if (optimize > 0 && flag_schedule_insns_after_reload)
4191 split_all_insns (0);
4193 if (global_reg_dump)
4195 TIMEVAR (dump_time, dump_global_regs (rtl_dump_file));
4196 close_dump_file (print_rtl_with_bb, insns);
4197 if (graph_dump_format != no_graph)
4198 print_rtl_graph_with_bb (dump_base_name, ".13.greg", insns);
4201 /* Re-create the death notes which were deleted during reload. */
4202 if (flow2_dump)
4203 open_dump_file (".14.flow2", decl_printable_name (decl, 2));
4205 if (optimize)
4207 TIMEVAR
4208 (flow2_time,
4210 find_basic_blocks (insns, max_reg_num (), rtl_dump_file, 1);
4211 life_analysis (insns, max_reg_num (), rtl_dump_file, 1);
4214 if (ggc_p)
4215 ggc_collect ();
4218 flow2_completed = 1;
4220 if (flow2_dump)
4222 close_dump_file (print_rtl_with_bb, insns);
4223 if (graph_dump_format != no_graph)
4224 print_rtl_graph_with_bb (dump_base_name, ".14.flow2", insns);
4227 #ifdef HAVE_peephole2
4228 if (optimize > 0 && flag_peephole2)
4230 if (peephole2_dump)
4231 open_dump_file (".15.peephole2", decl_printable_name (decl, 2));
4233 TIMEVAR (peephole2_time, peephole2_optimize (rtl_dump_file));
4235 if (peephole2_dump)
4237 close_dump_file (print_rtl_with_bb, insns);
4238 if (graph_dump_format != no_graph)
4239 print_rtl_graph_with_bb (dump_base_name, ".15.peephole2", insns);
4242 #endif
4244 #ifdef INSN_SCHEDULING
4245 if (optimize > 0 && flag_schedule_insns_after_reload)
4247 if (sched2_dump)
4248 open_dump_file (".16.sched2", decl_printable_name (decl, 2));
4250 /* Do control and data sched analysis again,
4251 and write some more of the results to dump file. */
4253 TIMEVAR (sched2_time, schedule_insns (rtl_dump_file));
4255 /* Dump rtl after post-reorder instruction scheduling. */
4257 if (sched2_dump)
4259 close_dump_file (print_rtl_with_bb, insns);
4260 if (graph_dump_format != no_graph)
4261 print_rtl_graph_with_bb (dump_base_name, ".16.sched2", insns);
4264 if (ggc_p)
4265 ggc_collect ();
4267 #endif
4269 #ifdef LEAF_REGISTERS
4270 current_function_uses_only_leaf_regs
4271 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
4272 #endif
4274 /* One more attempt to remove jumps to .+1
4275 left by dead-store-elimination.
4276 Also do cross-jumping this time
4277 and delete no-op move insns. */
4279 if (optimize > 0)
4281 TIMEVAR (jump_time, jump_optimize (insns, JUMP_CROSS_JUMP,
4282 JUMP_NOOP_MOVES,
4283 !JUMP_AFTER_REGSCAN));
4285 /* Dump rtl code after jump, if we are doing that. */
4287 if (jump2_opt_dump)
4289 dump_rtl (".17.jump2", decl, print_rtl_with_bb, insns);
4290 if (graph_dump_format != no_graph)
4291 print_rtl_graph_with_bb (dump_base_name, ".17.jump2", insns);
4295 /* If a machine dependent reorganization is needed, call it. */
4296 #ifdef MACHINE_DEPENDENT_REORG
4297 if (mach_dep_reorg_dump)
4298 open_dump_file (".18.mach", decl_printable_name (decl, 2));
4300 MACHINE_DEPENDENT_REORG (insns);
4302 if (mach_dep_reorg_dump)
4304 close_dump_file (print_rtl_with_bb, insns);
4305 if (graph_dump_format != no_graph)
4306 print_rtl_graph_with_bb (dump_base_name, ".18.mach", insns);
4309 if (ggc_p)
4310 ggc_collect ();
4311 #endif
4313 /* If a scheduling pass for delayed branches is to be done,
4314 call the scheduling code. */
4316 #ifdef DELAY_SLOTS
4317 if (optimize > 0 && flag_delayed_branch)
4319 if (dbr_sched_dump)
4320 open_dump_file (".19.dbr", decl_printable_name (decl, 2));
4322 TIMEVAR (dbr_sched_time, dbr_schedule (insns, rtl_dump_file));
4324 if (dbr_sched_dump)
4326 close_dump_file (print_rtl_with_bb, insns);
4327 if (graph_dump_format != no_graph)
4328 print_rtl_graph_with_bb (dump_base_name, ".19.dbr", insns);
4332 if (ggc_p)
4333 ggc_collect ();
4334 #endif
4336 /* Shorten branches. */
4337 TIMEVAR (shorten_branch_time,
4339 shorten_branches (get_insns ());
4342 #ifdef STACK_REGS
4343 if (stack_reg_dump)
4344 open_dump_file (".20.stack", decl_printable_name (decl, 2));
4346 TIMEVAR (stack_reg_time, reg_to_stack (insns, rtl_dump_file));
4348 if (stack_reg_dump)
4350 close_dump_file (print_rtl_with_bb, insns);
4351 if (graph_dump_format != no_graph)
4352 print_rtl_graph_with_bb (dump_base_name, ".20.stack", insns);
4355 if (ggc_p)
4356 ggc_collect ();
4357 #endif
4359 /* Now turn the rtl into assembler code. */
4361 TIMEVAR (final_time,
4363 rtx x;
4364 char *fnname;
4366 /* Get the function's name, as described by its RTL.
4367 This may be different from the DECL_NAME name used
4368 in the source file. */
4370 x = DECL_RTL (decl);
4371 if (GET_CODE (x) != MEM)
4372 abort ();
4373 x = XEXP (x, 0);
4374 if (GET_CODE (x) != SYMBOL_REF)
4375 abort ();
4376 fnname = XSTR (x, 0);
4378 assemble_start_function (decl, fnname);
4379 final_start_function (insns, asm_out_file, optimize);
4380 final (insns, asm_out_file, optimize, 0);
4381 final_end_function (insns, asm_out_file, optimize);
4382 assemble_end_function (decl, fnname);
4383 if (! quiet_flag)
4384 fflush (asm_out_file);
4386 /* Release all memory allocated by flow. */
4387 free_basic_block_vars (0);
4389 /* Release all memory held by regsets now */
4390 regset_release_memory ();
4393 if (ggc_p)
4394 ggc_collect ();
4396 /* Write DBX symbols if requested */
4398 /* Note that for those inline functions where we don't initially
4399 know for certain that we will be generating an out-of-line copy,
4400 the first invocation of this routine (rest_of_compilation) will
4401 skip over this code by doing a `goto exit_rest_of_compilation;'.
4402 Later on, finish_compilation will call rest_of_compilation again
4403 for those inline functions that need to have out-of-line copies
4404 generated. During that call, we *will* be routed past here. */
4406 #ifdef DBX_DEBUGGING_INFO
4407 if (write_symbols == DBX_DEBUG)
4408 TIMEVAR (symout_time, dbxout_function (decl));
4409 #endif
4411 #ifdef DWARF_DEBUGGING_INFO
4412 if (write_symbols == DWARF_DEBUG)
4413 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
4414 #endif
4416 #ifdef DWARF2_DEBUGGING_INFO
4417 if (write_symbols == DWARF2_DEBUG)
4418 TIMEVAR (symout_time, dwarf2out_decl (decl));
4419 #endif
4421 exit_rest_of_compilation:
4423 free_bb_mem ();
4425 /* In case the function was not output,
4426 don't leave any temporary anonymous types
4427 queued up for sdb output. */
4428 #ifdef SDB_DEBUGGING_INFO
4429 if (write_symbols == SDB_DEBUG)
4430 sdbout_types (NULL_TREE);
4431 #endif
4433 /* Put back the tree of subblocks and list of arguments
4434 from before we copied them.
4435 Code generation and the output of debugging info may have modified
4436 the copy, but the original is unchanged. */
4438 if (saved_block_tree != 0)
4440 DECL_INITIAL (decl) = saved_block_tree;
4441 DECL_ARGUMENTS (decl) = saved_arguments;
4442 DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE;
4445 reload_completed = 0;
4446 flow2_completed = 0;
4447 no_new_pseudos = 0;
4449 TIMEVAR (final_time,
4451 /* Clear out the insn_length contents now that they are no
4452 longer valid. */
4453 init_insn_lengths ();
4455 /* Clear out the real_constant_chain before some of the rtx's
4456 it runs through become garbage. */
4457 clear_const_double_mem ();
4459 /* Cancel the effect of rtl_in_current_obstack. */
4460 resume_temporary_allocation ();
4462 /* Show no temporary slots allocated. */
4463 init_temp_slots ();
4465 free_basic_block_vars (0);
4468 /* Make sure volatile mem refs aren't considered valid operands for
4469 arithmetic insns. We must call this here if this is a nested inline
4470 function, since the above code leaves us in the init_recog state
4471 (from final.c), and the function context push/pop code does not
4472 save/restore volatile_ok.
4474 ??? Maybe it isn't necessary for expand_start_function to call this
4475 anymore if we do it here? */
4477 init_recog_no_volatile ();
4479 /* We're done with this function. Free up memory if we can. */
4480 free_after_parsing (current_function);
4481 if (! DECL_DEFER_OUTPUT (decl))
4482 free_after_compilation (current_function);
4483 current_function = 0;
4485 if (ggc_p)
4486 ggc_collect ();
4488 /* The parsing time is all the time spent in yyparse
4489 *except* what is spent in this function. */
4491 parse_time -= get_run_time () - start_time;
4494 static void
4495 display_help ()
4497 int undoc;
4498 unsigned long i;
4499 const char * lang;
4501 #ifndef USE_CPPLIB
4502 printf ("Usage: %s input [switches]\n", progname);
4503 printf ("Switches:\n");
4504 #endif
4505 printf (" -ffixed-<register> Mark <register> as being unavailable to the compiler\n");
4506 printf (" -fcall-used-<register> Mark <register> as being corrupted by function calls\n");
4507 printf (" -fcall-saved-<register> Mark <register> as being preserved across functions\n");
4508 printf (" -finline-limit=<number> Limits the size of inlined functions to <number>\n");
4510 for (i = NUM_ELEM (f_options); i--;)
4512 const char * description = f_options[i].description;
4514 if (description != NULL && * description != 0)
4515 printf (" -f%-21s %s\n",
4516 f_options[i].string, description);
4519 printf (" -O[number] Set optimisation level to [number]\n");
4520 printf (" -Os Optimise for space rather than speed\n");
4521 printf (" -pedantic Issue warnings needed by strict compliance to ANSI C\n");
4522 printf (" -pedantic-errors Like -pedantic except that errors are produced\n");
4523 printf (" -w Suppress warnings\n");
4524 printf (" -W Enable extra warnings\n");
4526 for (i = NUM_ELEM (W_options); i--;)
4528 const char * description = W_options[i].description;
4530 if (description != NULL && * description != 0)
4531 printf (" -W%-21s %s\n",
4532 W_options[i].string, description);
4535 printf (" -Wid-clash-<num> Warn if 2 identifiers have the same first <num> chars\n");
4536 printf (" -Wlarger-than-<number> Warn if an object is larger than <number> bytes\n");
4537 printf (" -p Enable function profiling\n");
4538 #if defined (BLOCK_PROFILER) || defined (FUNCTION_BLOCK_PROFILER)
4539 printf (" -a Enable block profiling \n");
4540 #endif
4541 #if defined (BLOCK_PROFILER) || defined (FUNCTION_BLOCK_PROFILER) || defined FUNCTION_BLOCK_PROFILER_EXIT
4542 printf (" -ax Enable jump profiling \n");
4543 #endif
4544 printf (" -o <file> Place output into <file> \n");
4545 printf (" -G <number> Put global and static data smaller than <number>\n");
4546 printf (" bytes into a special section (on some targets)\n");
4548 for (i = NUM_ELEM (debug_args); i--;)
4550 if (debug_args[i].description != NULL)
4551 printf (" -g%-21s %s\n", debug_args[i].arg, debug_args[i].description);
4554 printf (" -aux-info <file> Emit declaration info into <file>.X\n");
4555 printf (" -quiet Do not display functions compiled or elapsed time\n");
4556 printf (" -version Display the compiler's version\n");
4557 printf (" -d[letters] Enable dumps from specific passes of the compiler\n");
4558 printf (" -dumpbase <file> Base name to be used for dumps from specific passes\n");
4559 #if defined INSN_SCHEDULING
4560 printf (" -sched-verbose=<number> Set the verbosity level of the scheduler\n");
4561 #endif
4562 printf (" --help Display this information\n");
4564 undoc = 0;
4565 lang = "language";
4567 /* Display descriptions of language specific options.
4568 If there is no description, note that there is an undocumented option.
4569 If the description is empty, do not display anything. (This allows
4570 options to be deliberately undocumented, for whatever reason).
4571 If the option string is missing, then this is a marker, indicating
4572 that the description string is in fact the name of a language, whose
4573 language specific options are to follow. */
4575 if (NUM_ELEM (documented_lang_options) > 1)
4577 printf ("\nLanguage specific options:\n");
4579 for (i = 0; i < NUM_ELEM (documented_lang_options); i++)
4581 const char * description = documented_lang_options[i].description;
4582 const char * option = documented_lang_options[i].option;
4584 if (description == NULL)
4586 undoc = 1;
4588 if (extra_warnings)
4589 printf (" %-23.23s [undocumented]\n", option);
4591 else if (* description == 0)
4592 continue;
4593 else if (option == NULL)
4595 if (undoc)
4596 printf
4597 ("\nThere are undocumented %s specific options as well.\n",
4598 lang);
4599 undoc = 0;
4601 printf ("\n Options for %s:\n", description);
4603 lang = description;
4605 else
4606 printf (" %-23.23s %s\n", option, description);
4610 if (undoc)
4611 printf ("\nThere are undocumented %s specific options as well.\n", lang);
4613 if (NUM_ELEM (target_switches) > 1
4614 #ifdef TARGET_OPTIONS
4615 || NUM_ELEM (target_options) > 1
4616 #endif
4619 int doc = 0;
4621 undoc = 0;
4623 printf ("\nTarget specific options:\n");
4625 for (i = NUM_ELEM (target_switches); i--;)
4627 const char * option = target_switches[i].name;
4628 const char * description = target_switches[i].description;
4630 if (option == NULL || * option == 0)
4631 continue;
4632 else if (description == NULL)
4634 undoc = 1;
4636 if (extra_warnings)
4637 printf (" -m%-21.21s [undocumented]\n", option);
4639 else if (* description != 0)
4640 doc += printf (" -m%-21.21s %s\n", option, description);
4643 #ifdef TARGET_OPTIONS
4644 for (i = NUM_ELEM (target_options); i--;)
4646 const char * option = target_options[i].prefix;
4647 const char * description = target_options[i].description;
4649 if (option == NULL || * option == 0)
4650 continue;
4651 else if (description == NULL)
4653 undoc = 1;
4655 if (extra_warnings)
4656 printf (" -m%-21.21s [undocumented]\n", option);
4658 else if (* description != 0)
4659 doc += printf (" -m%-21.21s %s\n", option, description);
4661 #endif
4662 if (undoc)
4664 if (doc)
4665 printf ("\nThere are undocumented target specific options as well.\n");
4666 else
4667 printf (" They exist, but they are not documented.\n");
4672 /* Parse a -d... comand line switch. */
4674 static void
4675 decode_d_option (arg)
4676 const char * arg;
4678 while (* arg)
4679 switch (* arg ++)
4681 case 'a':
4682 branch_prob_dump = 1;
4683 combine_dump = 1;
4684 #ifdef DELAY_SLOTS
4685 dbr_sched_dump = 1;
4686 #endif
4687 flow_dump = 1;
4688 flow2_dump = 1;
4689 global_reg_dump = 1;
4690 jump_opt_dump = 1;
4691 addressof_dump = 1;
4692 jump2_opt_dump = 1;
4693 local_reg_dump = 1;
4694 loop_dump = 1;
4695 regmove_dump = 1;
4696 rtl_dump = 1;
4697 cse_dump = 1;
4698 cse2_dump = 1;
4699 gcse_dump = 1;
4700 sched_dump = 1;
4701 sched2_dump = 1;
4702 #ifdef STACK_REGS
4703 stack_reg_dump = 1;
4704 #endif
4705 #ifdef MACHINE_DEPENDENT_REORG
4706 mach_dep_reorg_dump = 1;
4707 #endif
4708 peephole2_dump = 1;
4709 break;
4710 case 'A':
4711 flag_debug_asm = 1;
4712 break;
4713 case 'b':
4714 branch_prob_dump = 1;
4715 break;
4716 case 'c':
4717 combine_dump = 1;
4718 break;
4719 #ifdef DELAY_SLOTS
4720 case 'd':
4721 dbr_sched_dump = 1;
4722 break;
4723 #endif
4724 case 'f':
4725 flow_dump = 1;
4726 break;
4727 case 'F':
4728 addressof_dump = 1;
4729 break;
4730 case 'g':
4731 global_reg_dump = 1;
4732 break;
4733 case 'G':
4734 gcse_dump = 1;
4735 break;
4736 case 'j':
4737 jump_opt_dump = 1;
4738 break;
4739 case 'J':
4740 jump2_opt_dump = 1;
4741 break;
4742 #ifdef STACK_REGS
4743 case 'k':
4744 stack_reg_dump = 1;
4745 break;
4746 #endif
4747 case 'l':
4748 local_reg_dump = 1;
4749 break;
4750 case 'L':
4751 loop_dump = 1;
4752 break;
4753 case 'm':
4754 flag_print_mem = 1;
4755 break;
4756 #ifdef MACHINE_DEPENDENT_REORG
4757 case 'M':
4758 mach_dep_reorg_dump = 1;
4759 break;
4760 #endif
4761 case 'p':
4762 flag_print_asm_name = 1;
4763 break;
4764 case 'r':
4765 rtl_dump = 1;
4766 break;
4767 case 'R':
4768 sched2_dump = 1;
4769 break;
4770 case 's':
4771 cse_dump = 1;
4772 break;
4773 case 'S':
4774 sched_dump = 1;
4775 break;
4776 case 't':
4777 cse2_dump = 1;
4778 break;
4779 case 'N':
4780 regmove_dump = 1;
4781 break;
4782 case 'v':
4783 graph_dump_format = vcg;
4784 break;
4785 case 'w':
4786 flow2_dump = 1;
4787 break;
4788 case 'x':
4789 rtl_dump_and_exit = 1;
4790 break;
4791 case 'y':
4792 set_yydebug (1);
4793 break;
4794 case 'z':
4795 peephole2_dump = 1;
4796 break;
4797 case 'D': /* These are handled by the preprocessor. */
4798 case 'I':
4799 break;
4800 default:
4801 warning ("unrecognised gcc debugging option: %c", arg[-1]);
4802 break;
4806 /* Parse a -f... comand line switch. ARG is the value after the -f.
4807 It is safe to access 'ARG - 2' to generate the full switch name.
4808 Return the number of strings consumed. */
4810 static int
4811 decode_f_option (arg)
4812 const char * arg;
4814 int j;
4816 /* Search for the option in the table of binary f options. */
4817 for (j = sizeof (f_options) / sizeof (f_options[0]); j--;)
4819 if (!strcmp (arg, f_options[j].string))
4821 *f_options[j].variable = f_options[j].on_value;
4822 return 1;
4825 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-'
4826 && ! strcmp (arg + 3, f_options[j].string))
4828 *f_options[j].variable = ! f_options[j].on_value;
4829 return 1;
4833 if (!strncmp (arg, "inline-limit-", 13)
4834 || !strncmp (arg, "inline-limit=", 13))
4835 inline_max_insns =
4836 read_integral_parameter (arg + 13, arg - 2, inline_max_insns);
4837 #ifdef INSN_SCHEDULING
4838 else if (!strncmp (arg, "sched-verbose=", 14))
4839 fix_sched_param ("verbose", (const char *)(arg + 14));
4840 #endif
4841 else if (!strncmp (arg, "fixed-", 6))
4842 fix_register ((const char *)(arg + 6), 1, 1);
4843 else if (!strncmp (arg, "call-used-", 10))
4844 fix_register ((const char *)(arg + 10), 0, 1);
4845 else if (!strncmp (arg, "call-saved-", 11))
4846 fix_register ((const char *)(arg + 11), 0, 0);
4847 else if (!strncmp (arg, "align-loops=", 12))
4848 align_loops = read_integral_parameter (arg + 12, arg - 2, align_loops);
4849 else if (!strncmp (arg, "align-functions=", 16))
4850 align_functions =
4851 read_integral_parameter (arg + 16, arg - 2, align_functions);
4852 else if (!strncmp (arg, "align-jumps=", 12))
4853 align_jumps = read_integral_parameter (arg + 12, arg - 2, align_jumps);
4854 else if (!strncmp (arg, "align-labels=", 13))
4855 align_labels = read_integral_parameter (arg + 13, arg - 2, align_labels);
4856 else if (!strcmp (arg, "preprocessed"))
4857 /* Recognise this switch but do nothing. This prevents warnings
4858 about an unrecognised switch if cpplib has not been linked in. */
4860 else
4861 return 0;
4863 return 1;
4866 /* Parse a -W... comand line switch. ARG is the value after the -W.
4867 It is safe to access 'ARG - 2' to generate the full switch name.
4868 Return the number of strings consumed. */
4869 static int
4870 decode_W_option (arg)
4871 const char * arg;
4873 int j;
4875 /* Search for the option in the table of binary W options. */
4877 for (j = sizeof (W_options) / sizeof (W_options[0]); j--;)
4879 if (!strcmp (arg, W_options[j].string))
4881 *W_options[j].variable = W_options[j].on_value;
4882 return 1;
4885 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-'
4886 && ! strcmp (arg + 3, W_options[j].string))
4888 *W_options[j].variable = ! W_options[j].on_value;
4889 return 1;
4893 if (!strncmp (arg, "id-clash-", 9))
4895 const int id_clash_val = read_integral_parameter (arg + 9, arg - 2, -1);
4897 if (id_clash_val != -1)
4899 id_clash_len = id_clash_val;
4900 warn_id_clash = 1;
4903 else if (!strncmp (arg, "larger-than-", 12))
4905 const int larger_than_val =
4906 read_integral_parameter (arg + 12, arg - 2, -1);
4907 if (larger_than_val != -1)
4909 larger_than_size = larger_than_val;
4910 warn_larger_than = 1;
4913 else
4914 return 0;
4916 return 1;
4919 /* Parse a -g... comand line switch. ARG is the value after the -g.
4920 It is safe to access 'ARG - 2' to generate the full switch name.
4921 Return the number of strings consumed. */
4922 static int
4923 decode_g_option (arg)
4924 const char * arg;
4926 unsigned level;
4927 /* A lot of code assumes write_symbols == NO_DEBUG if the
4928 debugging level is 0 (thus -gstabs1 -gstabs0 would lose track
4929 of what debugging type has been selected). This records the
4930 selected type. It is an error to specify more than one
4931 debugging type. */
4932 static enum debug_info_type selected_debug_type = NO_DEBUG;
4933 /* Non-zero if debugging format has been explicitly set.
4934 -g and -ggdb don't explicitly set the debugging format so
4935 -gdwarf -g3 is equivalent to -gdwarf3. */
4936 static int type_explicitly_set_p = 0;
4937 /* Indexed by enum debug_info_type. */
4938 static const char * debug_type_names[] =
4940 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff"
4943 /* The maximum admissible debug level value. */
4944 static const unsigned max_debug_level = 3;
4946 /* Look up ARG in the table. */
4947 for (da = debug_args; da->arg; da++)
4949 const int da_len = strlen (da->arg);
4951 if (da_len == 0 || ! strncmp (arg, da->arg, da_len))
4953 enum debug_info_type type = da->debug_type;
4954 const char * p = arg + da_len;
4956 if (*p && (*p < '0' || *p > '9'))
4957 continue;
4959 /* A debug flag without a level defaults to level 2.
4960 Note we do not want to call read_integral_parameter
4961 for that case since it will call atoi which
4962 will return zero.
4964 ??? We may want to generalize the interface to
4965 read_integral_parameter to better handle this case
4966 if this case shows up often. */
4967 if (*p)
4968 level = read_integral_parameter (p, 0, max_debug_level + 1);
4969 else
4970 level = 2;
4972 if (da_len > 1 && *p && !strncmp (arg, "dwarf", da_len))
4974 error ("use -gdwarf -g%d for DWARF v1, level %d",
4975 level, level);
4976 if (level == 2)
4977 error ("use -gdwarf-2 for DWARF v2");
4980 if (level > max_debug_level)
4982 warning ("\
4983 ignoring option `%s' due to invalid debug level specification",
4984 arg - 2);
4985 level = debug_info_level;
4988 if (type == NO_DEBUG)
4990 type = PREFERRED_DEBUGGING_TYPE;
4992 if (da_len > 1 && strncmp (arg, "gdb", da_len) == 0)
4994 #if defined (DWARF2_DEBUGGING_INFO) && !defined (LINKER_DOES_NOT_WORK_WITH_DWARF2)
4995 type = DWARF2_DEBUG;
4996 #else
4997 #ifdef DBX_DEBUGGING_INFO
4998 type = DBX_DEBUG;
4999 #endif
5000 #endif
5004 if (type == NO_DEBUG)
5005 warning ("`%s' not supported by this configuration of GCC",
5006 arg - 2);
5008 /* Does it conflict with an already selected type? */
5009 if (type_explicitly_set_p
5010 /* -g/-ggdb don't conflict with anything */
5011 && da->debug_type != NO_DEBUG
5012 && type != selected_debug_type)
5013 warning ("`%s' ignored, conflicts with `-g%s'",
5014 arg - 2, debug_type_names[(int) selected_debug_type]);
5015 else
5017 /* If the format has already been set, -g/-ggdb
5018 only change the debug level. */
5019 if (type_explicitly_set_p && da->debug_type == NO_DEBUG)
5020 ; /* don't change debugging type */
5021 else
5023 selected_debug_type = type;
5024 type_explicitly_set_p = da->debug_type != NO_DEBUG;
5027 write_symbols = (level == 0
5028 ? NO_DEBUG
5029 : selected_debug_type);
5030 use_gnu_debug_info_extensions = da->use_extensions_p;
5031 debug_info_level = (enum debug_info_level) level;
5034 break;
5038 if (! da->arg)
5039 warning ("`%s' not supported by this configuration of GCC", arg - 2);
5041 return 1;
5044 /* Decode the first argument in the argv as a language-independent option.
5045 Return the number of strings consumed. 'strings_processed' is the
5046 number of strings that have already been decoded in a language
5047 specific fashion before this function was invoked. */
5049 static unsigned
5050 independent_decode_option (argc, argv, strings_processed)
5051 int argc;
5052 char ** argv;
5053 unsigned strings_processed ATTRIBUTE_UNUSED;
5055 char * arg = argv[0];
5057 if (arg[0] != '-' || arg[1] == 0)
5059 if (arg[0] == '+')
5060 return 0;
5062 filename = arg;
5064 return 1;
5067 arg ++;
5069 if (!strcmp (arg, "-help"))
5071 display_help ();
5072 exit (0);
5075 if (* arg == 'Y')
5076 arg ++;
5078 switch (* arg)
5080 default:
5081 return 0;
5083 case 'O':
5084 /* Already been treated in main (). Do nothing. */
5085 break;
5087 case 'm':
5088 set_target_switch (arg + 1);
5089 break;
5091 case 'f':
5092 return decode_f_option (arg + 1);
5094 case 'g':
5095 return decode_g_option (arg + 1);
5097 case 'd':
5098 if (!strcmp (arg, "dumpbase"))
5100 if (argc == 1)
5101 return 0;
5103 dump_base_name = argv[1];
5104 return 2;
5106 else
5107 decode_d_option (arg + 1);
5108 break;
5110 case 'p':
5111 if (!strcmp (arg, "pedantic"))
5112 pedantic = 1;
5113 else if (!strcmp (arg, "pedantic-errors"))
5114 flag_pedantic_errors = pedantic = 1;
5115 else if (arg[1] == 0)
5116 profile_flag = 1;
5117 else
5118 return 0;
5119 break;
5121 case 'q':
5122 if (!strcmp (arg, "quiet"))
5123 quiet_flag = 1;
5124 else
5125 return 0;
5126 break;
5128 case 'v':
5129 if (!strcmp (arg, "version"))
5130 version_flag = 1;
5131 else
5132 return 0;
5133 break;
5135 case 'w':
5136 if (arg[1] == 0)
5137 inhibit_warnings = 1;
5138 else
5139 return 0;
5140 break;
5142 case 'W':
5143 if (arg[1] == 0)
5145 extra_warnings = 1;
5146 /* We save the value of warn_uninitialized, since if they put
5147 -Wuninitialized on the command line, we need to generate a
5148 warning about not using it without also specifying -O. */
5149 if (warn_uninitialized != 1)
5150 warn_uninitialized = 2;
5152 else
5153 return decode_W_option (arg + 1);
5154 break;
5156 case 'a':
5157 if (arg[1] == 0)
5159 #if !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
5160 warning ("`-a' option (basic block profile) not supported");
5161 #else
5162 profile_block_flag = (profile_block_flag < 2) ? 1 : 3;
5163 #endif
5165 else if (!strcmp (arg, "ax"))
5167 #if !defined (FUNCTION_BLOCK_PROFILER_EXIT) || !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
5168 warning ("`-ax' option (jump profiling) not supported");
5169 #else
5170 profile_block_flag = (!profile_block_flag
5171 || profile_block_flag == 2) ? 2 : 3;
5172 #endif
5174 else if (!strncmp (arg, "aux-info", 8))
5176 flag_gen_aux_info = 1;
5177 if (arg[8] == '\0')
5179 if (argc == 1)
5180 return 0;
5182 aux_info_file_name = argv[1];
5183 return 2;
5185 else
5186 aux_info_file_name = arg + 8;
5188 else
5189 return 0;
5190 break;
5192 case 'o':
5193 if (arg[1] == 0)
5195 if (argc == 1)
5196 return 0;
5198 asm_file_name = argv[1];
5199 return 2;
5201 return 0;
5203 case 'G':
5205 int g_switch_val;
5206 int return_val;
5208 if (arg[1] == 0)
5210 if (argc == 1)
5211 return 0;
5213 g_switch_val = read_integral_parameter (argv[1], 0, -1);
5214 return_val = 2;
5216 else
5218 g_switch_val = read_integral_parameter (arg + 1, 0, -1);
5219 return_val = 1;
5222 if (g_switch_val == -1)
5223 return_val = 0;
5224 else
5226 g_switch_set = TRUE;
5227 g_switch_value = g_switch_val;
5230 return return_val;
5234 return 1;
5237 /* Entry point of cc1/c++. Decode command args, then call compile_file.
5238 Exit code is 35 if can't open files, 34 if fatal error,
5239 33 if had nonfatal errors, else success. */
5241 extern int main PROTO ((int, char **));
5244 main (argc, argv)
5245 int argc;
5246 char **argv;
5248 register int i;
5249 char *p;
5251 /* save in case md file wants to emit args as a comment. */
5252 save_argc = argc;
5253 save_argv = argv;
5255 p = argv[0] + strlen (argv[0]);
5256 while (p != argv[0] && p[-1] != '/'
5257 #ifdef DIR_SEPARATOR
5258 && p[-1] != DIR_SEPARATOR
5259 #endif
5261 --p;
5262 progname = p;
5264 #if defined (RLIMIT_STACK) && defined (HAVE_GETRLIMIT) && defined (HAVE_SETRLIMIT)
5265 /* Get rid of any avoidable limit on stack size. */
5267 struct rlimit rlim;
5269 /* Set the stack limit huge so that alloca does not fail. */
5270 getrlimit (RLIMIT_STACK, &rlim);
5271 rlim.rlim_cur = rlim.rlim_max;
5272 setrlimit (RLIMIT_STACK, &rlim);
5274 #endif
5276 #ifdef HAVE_LC_MESSAGES
5277 setlocale (LC_MESSAGES, "");
5278 #endif
5279 (void) bindtextdomain (PACKAGE, localedir);
5280 (void) textdomain (PACKAGE);
5282 signal (SIGFPE, float_signal);
5284 #ifdef SIGPIPE
5285 signal (SIGPIPE, pipe_closed);
5286 #endif
5288 decl_printable_name = decl_name;
5289 lang_expand_expr = (lang_expand_expr_t) do_abort;
5291 /* Initialize whether `char' is signed. */
5292 flag_signed_char = DEFAULT_SIGNED_CHAR;
5293 #ifdef DEFAULT_SHORT_ENUMS
5294 /* Initialize how much space enums occupy, by default. */
5295 flag_short_enums = DEFAULT_SHORT_ENUMS;
5296 #endif
5298 /* Initialize the garbage-collector. */
5299 init_ggc ();
5300 ggc_add_root (&input_file_stack, 1, sizeof input_file_stack,
5301 &mark_file_stack);
5303 /* Perform language-specific options intialization. */
5304 lang_init_options ();
5306 /* Scan to see what optimization level has been specified. That will
5307 determine the default value of many flags. */
5308 for (i = 1; i < argc; i++)
5310 if (!strcmp (argv[i], "-O"))
5312 optimize = 1;
5313 optimize_size = 0;
5315 else if (argv[i][0] == '-' && argv[i][1] == 'O')
5317 /* Handle -Os, -O2, -O3, -O69, ... */
5318 char *p = &argv[i][2];
5320 if ((p[0] == 's') && (p[1] == 0))
5322 optimize_size = 1;
5324 /* Optimizing for size forces optimize to be 2. */
5325 optimize = 2;
5327 else
5329 const int optimize_val = read_integral_parameter (p, p - 2, -1);
5330 if (optimize_val != -1)
5332 optimize = optimize_val;
5333 optimize_size = 0;
5339 obey_regdecls = (optimize == 0);
5341 if (optimize >= 1)
5343 flag_defer_pop = 1;
5344 flag_thread_jumps = 1;
5345 #ifdef DELAY_SLOTS
5346 flag_delayed_branch = 1;
5347 #endif
5348 #ifdef CAN_DEBUG_WITHOUT_FP
5349 flag_omit_frame_pointer = 1;
5350 #endif
5353 if (optimize >= 2)
5355 flag_cse_follow_jumps = 1;
5356 flag_cse_skip_blocks = 1;
5357 flag_gcse = 1;
5358 flag_expensive_optimizations = 1;
5359 flag_strength_reduce = 1;
5360 flag_rerun_cse_after_loop = 1;
5361 flag_rerun_loop_opt = 1;
5362 flag_caller_saves = 1;
5363 flag_force_mem = 1;
5364 flag_peephole2 = 1;
5365 #ifdef INSN_SCHEDULING
5366 flag_schedule_insns = 1;
5367 flag_schedule_insns_after_reload = 1;
5368 #endif
5369 flag_regmove = 1;
5370 flag_strict_aliasing = 1;
5371 flag_delete_null_pointer_checks = 1;
5374 if (optimize >= 3)
5376 flag_inline_functions = 1;
5379 if (optimize < 2 || optimize_size)
5381 align_loops = 1;
5382 align_jumps = 1;
5383 align_labels = 1;
5384 align_functions = 1;
5387 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
5388 modify it. */
5389 target_flags = 0;
5390 set_target_switch ("");
5392 #ifdef OPTIMIZATION_OPTIONS
5393 /* Allow default optimizations to be specified on a per-machine basis. */
5394 OPTIMIZATION_OPTIONS (optimize, optimize_size);
5395 #endif
5397 /* Initialize register usage now so switches may override. */
5398 init_reg_sets ();
5400 /* Perform normal command line switch decoding. */
5401 for (i = 1; i < argc;)
5403 unsigned lang_processed;
5404 unsigned indep_processed;
5406 /* Give the language a chance to decode the option for itself. */
5407 lang_processed = lang_decode_option (argc - i, argv + i);
5409 /* Now see if the option also has a language independent meaning.
5410 Some options are both language specific and language independent,
5411 eg --help. It is possible that there might be options that should
5412 only be decoded in a language independent way if the were not
5413 decoded in a langauge specific way, which is why 'lang_processed'
5414 is passed in. */
5415 indep_processed = independent_decode_option (argc - i, argv + i,
5416 lang_processed);
5418 if (lang_processed || indep_processed)
5419 i += (lang_processed > indep_processed
5420 ? lang_processed : indep_processed);
5421 else
5423 const char * option = NULL;
5424 const char * lang = NULL;
5425 unsigned int j;
5427 /* It is possible that the command line switch is not valid for the
5428 current language, but it is valid for another language. In order
5429 to be compatible with previous versions of the compiler (which
5430 did not issue an error message in this case) we check for this
5431 possibilty here. If we do find a match, then if extra_warnings
5432 is set we generate a warning message, otherwise we will just
5433 ignore the option. */
5434 for (j = 0; j < NUM_ELEM (documented_lang_options); j++)
5436 option = documented_lang_options[j].option;
5438 if (option == NULL)
5439 lang = documented_lang_options[j].description;
5440 else if (! strncmp (argv[i], option, strlen (option)))
5441 break;
5444 if (option)
5446 if (extra_warnings)
5448 warning ("Ignoring command line option '%s'", argv[i]);
5449 if (lang)
5450 warning ("\
5451 (It is valid for %s but not the selected langauge)", lang);
5454 else
5455 error ("Unrecognised option `%s'", argv[i]);
5457 i++;
5461 /* Checker uses the frame pointer. */
5462 if (flag_check_memory_usage)
5463 flag_omit_frame_pointer = 0;
5465 if (optimize == 0)
5467 /* Inlining does not work if not optimizing,
5468 so force it not to be done. */
5469 flag_no_inline = 1;
5470 warn_inline = 0;
5472 /* The c_decode_option and lang_decode_option functions set
5473 this to `2' if -Wall is used, so we can avoid giving out
5474 lots of errors for people who don't realize what -Wall does. */
5475 if (warn_uninitialized == 1)
5476 warning ("-Wuninitialized is not supported without -O");
5479 #ifdef OVERRIDE_OPTIONS
5480 /* Some machines may reject certain combinations of options. */
5481 OVERRIDE_OPTIONS;
5482 #endif
5484 if (exceptions_via_longjmp == 2)
5486 #ifdef DWARF2_UNWIND_INFO
5487 exceptions_via_longjmp = ! DWARF2_UNWIND_INFO;
5488 #else
5489 exceptions_via_longjmp = 1;
5490 #endif
5493 /* Set up the align_*_log variables, defaulting them to 1 if they
5494 were still unset. */
5495 if (align_loops <= 0) align_loops = 1;
5496 align_loops_log = floor_log2 (align_loops*2-1);
5497 if (align_jumps <= 0) align_jumps = 1;
5498 align_jumps_log = floor_log2 (align_jumps*2-1);
5499 if (align_labels <= 0) align_labels = 1;
5500 align_labels_log = floor_log2 (align_labels*2-1);
5501 if (align_functions <= 0) align_functions = 1;
5502 align_functions_log = floor_log2 (align_functions*2-1);
5504 if (profile_block_flag == 3)
5506 warning ("`-ax' and `-a' are conflicting options. `-a' ignored.");
5507 profile_block_flag = 2;
5510 /* Unrolling all loops implies that standard loop unrolling must also
5511 be done. */
5512 if (flag_unroll_all_loops)
5513 flag_unroll_loops = 1;
5514 /* Loop unrolling requires that strength_reduction be on also. Silently
5515 turn on strength reduction here if it isn't already on. Also, the loop
5516 unrolling code assumes that cse will be run after loop, so that must
5517 be turned on also. */
5518 if (flag_unroll_loops)
5520 flag_strength_reduce = 1;
5521 flag_rerun_cse_after_loop = 1;
5524 /* Warn about options that are not supported on this machine. */
5525 #ifndef INSN_SCHEDULING
5526 if (flag_schedule_insns || flag_schedule_insns_after_reload)
5527 warning ("instruction scheduling not supported on this target machine");
5528 #endif
5529 #ifndef DELAY_SLOTS
5530 if (flag_delayed_branch)
5531 warning ("this target machine does not have delayed branches");
5532 #endif
5534 user_label_prefix = USER_LABEL_PREFIX;
5535 if (flag_leading_underscore != -1)
5537 /* If the default prefix is more complicated than "" or "_",
5538 issue a warning and ignore this option. */
5539 if (user_label_prefix[0] == 0 ||
5540 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
5542 user_label_prefix = flag_leading_underscore ? "_" : "";
5544 else
5545 warning ("-f%sleading-underscore not supported on this target machine",
5546 flag_leading_underscore ? "" : "no-");
5549 /* If we are in verbose mode, write out the version and maybe all the
5550 option flags in use. */
5551 if (version_flag)
5553 print_version (stderr, "");
5554 if (! quiet_flag)
5555 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
5558 compile_file (filename);
5560 #if !defined(OS2) && !defined(VMS) && (!defined(_WIN32) || defined (__CYGWIN__)) && !defined(__INTERIX)
5561 if (flag_print_mem)
5563 char *lim = (char *) sbrk (0);
5565 notice ("Data size %ld.\n", (long) (lim - (char *) &environ));
5566 fflush (stderr);
5568 #ifndef __MSDOS__
5569 #ifdef USG
5570 system ("ps -l 1>&2");
5571 #else /* not USG */
5572 system ("ps v");
5573 #endif /* not USG */
5574 #endif
5576 #endif /* ! OS2 && ! VMS && (! _WIN32 || CYGWIN) && ! __INTERIX */
5578 if (errorcount)
5579 return (FATAL_EXIT_CODE);
5580 if (sorrycount)
5581 return (FATAL_EXIT_CODE);
5582 return (SUCCESS_EXIT_CODE);
5585 /* Decode -m switches. */
5586 /* Decode the switch -mNAME. */
5588 static void
5589 set_target_switch (name)
5590 const char *name;
5592 register size_t j;
5593 int valid_target_option = 0;
5595 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
5596 if (!strcmp (target_switches[j].name, name))
5598 if (target_switches[j].value < 0)
5599 target_flags &= ~-target_switches[j].value;
5600 else
5601 target_flags |= target_switches[j].value;
5602 valid_target_option = 1;
5605 #ifdef TARGET_OPTIONS
5606 if (!valid_target_option)
5607 for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
5609 int len = strlen (target_options[j].prefix);
5610 if (!strncmp (target_options[j].prefix, name, len))
5612 *target_options[j].variable = name + len;
5613 valid_target_option = 1;
5616 #endif
5618 if (!valid_target_option)
5619 error ("Invalid option `%s'", name);
5622 /* Print version information to FILE.
5623 Each line begins with INDENT (for the case where FILE is the
5624 assembler output file). */
5626 static void
5627 print_version (file, indent)
5628 FILE *file;
5629 const char *indent;
5631 #ifndef __VERSION__
5632 #define __VERSION__ "[?]"
5633 #endif
5634 fnotice (file,
5635 #ifdef __GNUC__
5636 "%s%s%s version %s (%s) compiled by GNU C version %s.\n"
5637 #else
5638 "%s%s%s version %s (%s) compiled by CC.\n"
5639 #endif
5640 , indent, *indent != 0 ? " " : "",
5641 language_string, version_string, TARGET_NAME, __VERSION__);
5644 /* Print an option value and return the adjusted position in the line.
5645 ??? We don't handle error returns from fprintf (disk full); presumably
5646 other code will catch a disk full though. */
5648 static int
5649 print_single_switch (file, pos, max, indent, sep, term, type, name)
5650 FILE *file;
5651 int pos, max;
5652 const char *indent, *sep, *term, *type, *name;
5654 /* The ultrix fprintf returns 0 on success, so compute the result we want
5655 here since we need it for the following test. */
5656 int len = strlen (sep) + strlen (type) + strlen (name);
5658 if (pos != 0
5659 && pos + len > max)
5661 fprintf (file, "%s", term);
5662 pos = 0;
5664 if (pos == 0)
5666 fprintf (file, "%s", indent);
5667 pos = strlen (indent);
5669 fprintf (file, "%s%s%s", sep, type, name);
5670 pos += len;
5671 return pos;
5674 /* Print active target switches to FILE.
5675 POS is the current cursor position and MAX is the size of a "line".
5676 Each line begins with INDENT and ends with TERM.
5677 Each switch is separated from the next by SEP. */
5679 static void
5680 print_switch_values (file, pos, max, indent, sep, term)
5681 FILE *file;
5682 int pos, max;
5683 const char *indent, *sep, *term;
5685 size_t j;
5686 char **p;
5688 /* Print the options as passed. */
5690 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
5691 _("options passed: "), "");
5693 for (p = &save_argv[1]; *p != NULL; p++)
5694 if (**p == '-')
5696 /* Ignore these. */
5697 if (strcmp (*p, "-o") == 0)
5699 if (p[1] != NULL)
5700 p++;
5701 continue;
5703 if (strcmp (*p, "-quiet") == 0)
5704 continue;
5705 if (strcmp (*p, "-version") == 0)
5706 continue;
5707 if ((*p)[1] == 'd')
5708 continue;
5710 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
5712 if (pos > 0)
5713 fprintf (file, "%s", term);
5715 /* Print the -f and -m options that have been enabled.
5716 We don't handle language specific options but printing argv
5717 should suffice. */
5719 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
5720 _("options enabled: "), "");
5722 for (j = 0; j < sizeof f_options / sizeof f_options[0]; j++)
5723 if (*f_options[j].variable == f_options[j].on_value)
5724 pos = print_single_switch (file, pos, max, indent, sep, term,
5725 "-f", f_options[j].string);
5727 /* Print target specific options. */
5729 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
5730 if (target_switches[j].name[0] != '\0'
5731 && target_switches[j].value > 0
5732 && ((target_switches[j].value & target_flags)
5733 == target_switches[j].value))
5735 pos = print_single_switch (file, pos, max, indent, sep, term,
5736 "-m", target_switches[j].name);
5739 #ifdef TARGET_OPTIONS
5740 for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
5741 if (*target_options[j].variable != NULL)
5743 char prefix[256];
5744 sprintf (prefix, "-m%s", target_options[j].prefix);
5745 pos = print_single_switch (file, pos, max, indent, sep, term,
5746 prefix, *target_options[j].variable);
5748 #endif
5750 fprintf (file, "%s", term);
5753 /* Record the beginning of a new source file, named FILENAME. */
5755 void
5756 debug_start_source_file (filename)
5757 register char *filename ATTRIBUTE_UNUSED;
5759 #ifdef DBX_DEBUGGING_INFO
5760 if (write_symbols == DBX_DEBUG)
5761 dbxout_start_new_source_file (filename);
5762 #endif
5763 #ifdef DWARF_DEBUGGING_INFO
5764 if (debug_info_level == DINFO_LEVEL_VERBOSE
5765 && write_symbols == DWARF_DEBUG)
5766 dwarfout_start_new_source_file (filename);
5767 #endif /* DWARF_DEBUGGING_INFO */
5768 #ifdef DWARF2_DEBUGGING_INFO
5769 if (debug_info_level == DINFO_LEVEL_VERBOSE
5770 && write_symbols == DWARF2_DEBUG)
5771 dwarf2out_start_source_file (filename);
5772 #endif /* DWARF2_DEBUGGING_INFO */
5773 #ifdef SDB_DEBUGGING_INFO
5774 if (write_symbols == SDB_DEBUG)
5775 sdbout_start_new_source_file (filename);
5776 #endif
5779 /* Record the resumption of a source file. LINENO is the line number in
5780 the source file we are returning to. */
5782 void
5783 debug_end_source_file (lineno)
5784 register unsigned lineno ATTRIBUTE_UNUSED;
5786 #ifdef DBX_DEBUGGING_INFO
5787 if (write_symbols == DBX_DEBUG)
5788 dbxout_resume_previous_source_file ();
5789 #endif
5790 #ifdef DWARF_DEBUGGING_INFO
5791 if (debug_info_level == DINFO_LEVEL_VERBOSE
5792 && write_symbols == DWARF_DEBUG)
5793 dwarfout_resume_previous_source_file (lineno);
5794 #endif /* DWARF_DEBUGGING_INFO */
5795 #ifdef DWARF2_DEBUGGING_INFO
5796 if (debug_info_level == DINFO_LEVEL_VERBOSE
5797 && write_symbols == DWARF2_DEBUG)
5798 dwarf2out_end_source_file ();
5799 #endif /* DWARF2_DEBUGGING_INFO */
5800 #ifdef SDB_DEBUGGING_INFO
5801 if (write_symbols == SDB_DEBUG)
5802 sdbout_resume_previous_source_file ();
5803 #endif
5806 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
5807 the tail part of the directive line, i.e. the part which is past the
5808 initial whitespace, #, whitespace, directive-name, whitespace part. */
5810 void
5811 debug_define (lineno, buffer)
5812 register unsigned lineno ATTRIBUTE_UNUSED;
5813 register char *buffer ATTRIBUTE_UNUSED;
5815 #ifdef DWARF_DEBUGGING_INFO
5816 if (debug_info_level == DINFO_LEVEL_VERBOSE
5817 && write_symbols == DWARF_DEBUG)
5818 dwarfout_define (lineno, buffer);
5819 #endif /* DWARF_DEBUGGING_INFO */
5820 #ifdef DWARF2_DEBUGGING_INFO
5821 if (debug_info_level == DINFO_LEVEL_VERBOSE
5822 && write_symbols == DWARF2_DEBUG)
5823 dwarf2out_define (lineno, buffer);
5824 #endif /* DWARF2_DEBUGGING_INFO */
5827 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
5828 the tail part of the directive line, i.e. the part which is past the
5829 initial whitespace, #, whitespace, directive-name, whitespace part. */
5831 void
5832 debug_undef (lineno, buffer)
5833 register unsigned lineno ATTRIBUTE_UNUSED;
5834 register char *buffer ATTRIBUTE_UNUSED;
5836 #ifdef DWARF_DEBUGGING_INFO
5837 if (debug_info_level == DINFO_LEVEL_VERBOSE
5838 && write_symbols == DWARF_DEBUG)
5839 dwarfout_undef (lineno, buffer);
5840 #endif /* DWARF_DEBUGGING_INFO */
5841 #ifdef DWARF2_DEBUGGING_INFO
5842 if (debug_info_level == DINFO_LEVEL_VERBOSE
5843 && write_symbols == DWARF2_DEBUG)
5844 dwarf2out_undef (lineno, buffer);
5845 #endif /* DWARF2_DEBUGGING_INFO */