Fix typo in my last entry.
[official-gcc.git] / gcc / toplev.c
blob259765f8e865bf874be24787896a9531f5ce55fb
1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
22 /* This is the top level of cc1/c++.
23 It parses command args, opens files, invokes the various passes
24 in the proper order, and counts the time used by each.
25 Error messages and low-level interface to malloc also handled here. */
27 #include "config.h"
28 #undef FLOAT /* This is for hpux. They should change hpux. */
29 #undef FFS /* Some systems define this in param.h. */
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tm.h"
33 #include <signal.h>
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
37 #endif
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
41 #endif
43 #include "input.h"
44 #include "tree.h"
45 #include "rtl.h"
46 #include "tm_p.h"
47 #include "flags.h"
48 #include "insn-attr.h"
49 #include "insn-config.h"
50 #include "insn-flags.h"
51 #include "hard-reg-set.h"
52 #include "recog.h"
53 #include "output.h"
54 #include "except.h"
55 #include "function.h"
56 #include "toplev.h"
57 #include "expr.h"
58 #include "basic-block.h"
59 #include "intl.h"
60 #include "ggc.h"
61 #include "graph.h"
62 #include "loop.h"
63 #include "regs.h"
64 #include "timevar.h"
65 #include "diagnostic.h"
66 #include "ssa.h"
67 #include "params.h"
68 #include "reload.h"
69 #include "dwarf2asm.h"
70 #include "integrate.h"
71 #include "real.h"
72 #include "debug.h"
73 #include "target.h"
74 #include "langhooks.h"
75 #include "cfglayout.h"
76 #include "cfgloop.h"
77 #include "hosthooks.h"
78 #include "cgraph.h"
79 #include "opts.h"
80 #include "coverage.h"
82 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
83 #include "dwarf2out.h"
84 #endif
86 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
87 #include "dbxout.h"
88 #endif
90 #ifdef SDB_DEBUGGING_INFO
91 #include "sdbout.h"
92 #endif
94 #ifdef XCOFF_DEBUGGING_INFO
95 #include "xcoffout.h" /* Needed for external data
96 declarations for e.g. AIX 4.x. */
97 #endif
99 /* Carry information from ASM_DECLARE_OBJECT_NAME
100 to ASM_FINISH_DECLARE_OBJECT. */
102 extern int size_directive_output;
103 extern tree last_assemble_variable_decl;
105 extern void reg_alloc (void);
107 static void general_init (char *);
108 static void parse_options_and_default_flags (int, char **);
109 static void do_compile (void);
110 static void process_options (void);
111 static void backend_init (void);
112 static int lang_dependent_init (const char *);
113 static void init_asm_output (const char *);
114 static void finalize (void);
116 static void crash_signal (int) ATTRIBUTE_NORETURN;
117 static void setup_core_dumping (void);
118 static void compile_file (void);
120 static int decode_f_option (const char *);
121 static int decode_W_option (const char *);
122 static int decode_g_option (const char *);
123 static unsigned int independent_decode_option (char **);
125 static int print_single_switch (FILE *, int, int, const char *,
126 const char *, const char *,
127 const char *, const char *);
128 static void print_switch_values (FILE *, int, int, const char *,
129 const char *, const char *);
131 /* Rest of compilation helper functions. */
132 static bool rest_of_handle_inlining (tree);
133 static rtx rest_of_handle_ssa (tree, rtx);
134 static void rest_of_handle_cse (tree, rtx);
135 static void rest_of_handle_cse2 (tree, rtx);
136 static void rest_of_handle_gcse (tree, rtx);
137 static void rest_of_handle_life (tree, rtx);
138 static void rest_of_handle_loop_optimize (tree, rtx);
139 static void rest_of_handle_loop2 (tree, rtx);
140 static void rest_of_handle_jump_bypass (tree, rtx);
141 static void rest_of_handle_sibling_calls (rtx);
142 static void rest_of_handle_null_pointer (tree, rtx);
143 static void rest_of_handle_addresof (tree, rtx);
144 static void rest_of_handle_cfg (tree, rtx);
145 static void rest_of_handle_branch_prob (tree, rtx);
146 static void rest_of_handle_if_conversion (tree, rtx);
147 static void rest_of_handle_if_after_combine (tree, rtx);
148 static void rest_of_handle_tracer (tree, rtx);
149 static void rest_of_handle_combine (tree, rtx);
150 static void rest_of_handle_regmove (tree, rtx);
151 #ifdef INSN_SCHEDULING
152 static void rest_of_handle_sched (tree, rtx);
153 static void rest_of_handle_sched2 (tree, rtx);
154 #endif
155 static bool rest_of_handle_new_regalloc (tree, rtx, int *);
156 static bool rest_of_handle_old_regalloc (tree, rtx, int *);
157 static void rest_of_handle_regrename (tree, rtx);
158 static void rest_of_handle_reorder_blocks (tree, rtx);
159 #ifdef STACK_REGS
160 static void rest_of_handle_stack_regs (tree, rtx);
161 #endif
162 static void rest_of_handle_machine_reorg (tree, rtx);
163 #ifdef DELAY_SLOTS
164 static void rest_of_handle_delay_slots (tree, rtx);
165 #endif
166 static void rest_of_handle_final (tree, rtx);
168 /* Nonzero to dump debug info whilst parsing (-dy option). */
169 static int set_yydebug;
171 /* True if we don't need a backend (e.g. preprocessing only). */
172 static bool no_backend;
174 /* Length of line when printing switch values. */
175 #define MAX_LINE 75
177 /* Name of program invoked, sans directories. */
179 const char *progname;
181 /* Copy of arguments to toplev_main. */
182 int save_argc;
183 char **save_argv;
185 /* Name of top-level original source file (what was input to cpp).
186 This comes from the #-command at the beginning of the actual input.
187 If there isn't any there, then this is the cc1 input file name. */
189 const char *main_input_filename;
191 /* Current position in real source file. */
193 location_t input_location;
195 /* Nonzero if it is unsafe to create any new pseudo registers. */
196 int no_new_pseudos;
198 /* Stack of currently pending input files. */
200 struct file_stack *input_file_stack;
202 /* Incremented on each change to input_file_stack. */
203 int input_file_stack_tick;
205 /* Name to use as base of names for dump output files. */
207 const char *dump_base_name;
209 /* Name to use as a base for auxiliary output files. */
211 const char *aux_base_name;
213 /* Format to use to print dumpfile index value */
214 #ifndef DUMPFILE_FORMAT
215 #define DUMPFILE_FORMAT ".%02d."
216 #endif
218 /* Bit flags that specify the machine subtype we are compiling for.
219 Bits are tested using macros TARGET_... defined in the tm.h file
220 and set by `-m...' switches. Must be defined in rtlanal.c. */
222 extern int target_flags;
224 /* A mask of target_flags that includes bit X if X was set or cleared
225 on the command line. */
227 int target_flags_explicit;
229 /* Debug hooks - dependent upon command line options. */
231 const struct gcc_debug_hooks *debug_hooks = &do_nothing_debug_hooks;
233 /* Describes a dump file. */
235 struct dump_file_info
237 /* The unique extension to apply, e.g. ".jump". */
238 const char *const extension;
240 /* The -d<c> character that enables this dump file. */
241 char const debug_switch;
243 /* True if there is a corresponding graph dump file. */
244 char const graph_dump_p;
246 /* True if the user selected this dump. */
247 char enabled;
249 /* True if the files have been initialized (ie truncated). */
250 char initialized;
253 /* Enumerate the extant dump files. */
255 enum dump_file_index
257 DFI_rtl,
258 DFI_sibling,
259 DFI_eh,
260 DFI_jump,
261 DFI_ssa,
262 DFI_ssa_ccp,
263 DFI_ssa_dce,
264 DFI_ussa,
265 DFI_null,
266 DFI_cse,
267 DFI_addressof,
268 DFI_gcse,
269 DFI_loop,
270 DFI_bypass,
271 DFI_cfg,
272 DFI_bp,
273 DFI_ce1,
274 DFI_tracer,
275 DFI_loop2,
276 DFI_cse2,
277 DFI_life,
278 DFI_combine,
279 DFI_ce2,
280 DFI_regmove,
281 DFI_sched,
282 DFI_lreg,
283 DFI_greg,
284 DFI_postreload,
285 DFI_flow2,
286 DFI_peephole2,
287 DFI_rnreg,
288 DFI_bbro,
289 DFI_ce3,
290 DFI_branch_target_load,
291 DFI_sched2,
292 DFI_stack,
293 DFI_mach,
294 DFI_dbr,
295 DFI_MAX
298 /* Describes all the dump files. Should be kept in order of the
299 pass and in sync with dump_file_index above.
301 Remaining -d letters:
303 " m q "
304 " JK O Q UV YZ"
307 static struct dump_file_info dump_file[DFI_MAX] =
309 { "rtl", 'r', 0, 0, 0 },
310 { "sibling", 'i', 0, 0, 0 },
311 { "eh", 'h', 0, 0, 0 },
312 { "jump", 'j', 0, 0, 0 },
313 { "ssa", 'e', 1, 0, 0 },
314 { "ssaccp", 'W', 1, 0, 0 },
315 { "ssadce", 'X', 1, 0, 0 },
316 { "ussa", 'e', 1, 0, 0 }, /* Yes, duplicate enable switch. */
317 { "null", 'u', 0, 0, 0 },
318 { "cse", 's', 0, 0, 0 },
319 { "addressof", 'F', 0, 0, 0 },
320 { "gcse", 'G', 1, 0, 0 },
321 { "loop", 'L', 1, 0, 0 },
322 { "bypass", 'G', 1, 0, 0 }, /* Yes, duplicate enable switch. */
323 { "cfg", 'f', 1, 0, 0 },
324 { "bp", 'b', 1, 0, 0 },
325 { "ce1", 'C', 1, 0, 0 },
326 { "tracer", 'T', 1, 0, 0 },
327 { "loop2", 'L', 1, 0, 0 },
328 { "cse2", 't', 1, 0, 0 },
329 { "life", 'f', 1, 0, 0 }, /* Yes, duplicate enable switch. */
330 { "combine", 'c', 1, 0, 0 },
331 { "ce2", 'C', 1, 0, 0 },
332 { "regmove", 'N', 1, 0, 0 },
333 { "sched", 'S', 1, 0, 0 },
334 { "lreg", 'l', 1, 0, 0 },
335 { "greg", 'g', 1, 0, 0 },
336 { "postreload", 'o', 1, 0, 0 },
337 { "flow2", 'w', 1, 0, 0 },
338 { "peephole2", 'z', 1, 0, 0 },
339 { "rnreg", 'n', 1, 0, 0 },
340 { "bbro", 'B', 1, 0, 0 },
341 { "ce3", 'E', 1, 0, 0 },
342 { "btl", 'd', 1, 0, 0 }, /* Yes, duplicate enable switch. */
343 { "sched2", 'R', 1, 0, 0 },
344 { "stack", 'k', 1, 0, 0 },
345 { "mach", 'M', 1, 0, 0 },
346 { "dbr", 'd', 0, 0, 0 },
349 static int open_dump_file (enum dump_file_index, tree);
350 static void close_dump_file (enum dump_file_index,
351 void (*) (FILE *, rtx), rtx);
353 /* Other flags saying which kinds of debugging dump have been requested. */
355 int rtl_dump_and_exit;
356 int flag_print_asm_name;
357 enum graph_dump_types graph_dump_format;
359 /* Name for output file of assembly code, specified with -o. */
361 const char *asm_file_name;
363 /* Type(s) of debugging information we are producing (if any).
364 See flags.h for the definitions of the different possible
365 types of debugging information. */
366 enum debug_info_type write_symbols = NO_DEBUG;
368 /* Level of debugging information we are producing. See flags.h
369 for the definitions of the different possible levels. */
370 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
372 /* Nonzero means use GNU-only extensions in the generated symbolic
373 debugging information. */
374 /* Currently, this only has an effect when write_symbols is set to
375 DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
376 int use_gnu_debug_info_extensions = 0;
378 /* Nonzero means do optimizations. -O.
379 Particular numeric values stand for particular amounts of optimization;
380 thus, -O2 stores 2 here. However, the optimizations beyond the basic
381 ones are not controlled directly by this variable. Instead, they are
382 controlled by individual `flag_...' variables that are defaulted
383 based on this variable. */
385 int optimize = 0;
387 /* Nonzero means optimize for size. -Os.
388 The only valid values are zero and nonzero. When optimize_size is
389 nonzero, optimize defaults to 2, but certain individual code
390 bloating optimizations are disabled. */
392 int optimize_size = 0;
394 /* The FUNCTION_DECL for the function currently being compiled,
395 or 0 if between functions. */
396 tree current_function_decl;
398 /* Set to the FUNC_BEGIN label of the current function, or NULL_TREE
399 if none. */
400 tree current_function_func_begin_label;
402 /* Nonzero if doing dwarf2 duplicate elimination. */
404 int flag_eliminate_dwarf2_dups = 0;
406 /* Nonzero if doing unused type elimination. */
408 int flag_eliminate_unused_debug_types = 1;
410 /* Nonzero if generating code to do profiling. */
412 int profile_flag = 0;
414 /* Nonzero if generating code to profile program flow graph arcs. */
416 int profile_arc_flag = 0;
418 /* Nonzero if generating info for gcov to calculate line test coverage. */
420 int flag_test_coverage = 0;
422 /* Nonzero indicates that branch taken probabilities should be calculated. */
424 int flag_branch_probabilities = 0;
426 /* Nonzero if basic blocks should be reordered. */
428 int flag_reorder_blocks = 0;
430 /* Nonzero if functions should be reordered. */
432 int flag_reorder_functions = 0;
434 /* Nonzero if registers should be renamed. */
436 int flag_rename_registers = 0;
437 int flag_cprop_registers = 0;
439 /* Nonzero for -pedantic switch: warn about anything
440 that standard spec forbids. */
442 int pedantic = 0;
444 /* Temporarily suppress certain warnings.
445 This is set while reading code from a system header file. */
447 int in_system_header = 0;
449 /* Don't print functions as they are compiled. -quiet. */
451 int quiet_flag = 0;
453 /* Print times taken by the various passes. -ftime-report. */
455 static int time_report = 0;
457 /* Print memory still in use at end of compilation (which may have little
458 to do with peak memory consumption). -fmem-report. */
460 int mem_report = 0;
462 /* Nonzero means to collect statistics which might be expensive
463 and to print them when we are done. */
464 int flag_detailed_statistics = 0;
466 /* -f flags. */
468 /* Nonzero means `char' should be signed. */
470 int flag_signed_char;
472 /* Nonzero means give an enum type only as many bytes as it needs. */
474 int flag_short_enums;
476 /* Nonzero for -fcaller-saves: allocate values in regs that need to
477 be saved across function calls, if that produces overall better code.
478 Optional now, so people can test it. */
480 #ifdef DEFAULT_CALLER_SAVES
481 int flag_caller_saves = 1;
482 #else
483 int flag_caller_saves = 0;
484 #endif
486 /* Nonzero if structures and unions should be returned in memory.
488 This should only be defined if compatibility with another compiler or
489 with an ABI is needed, because it results in slower code. */
491 #ifndef DEFAULT_PCC_STRUCT_RETURN
492 #define DEFAULT_PCC_STRUCT_RETURN 1
493 #endif
495 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
497 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
499 /* Nonzero for -fforce-mem: load memory value into a register
500 before arithmetic on it. This makes better cse but slower compilation. */
502 int flag_force_mem = 0;
504 /* Nonzero for -fforce-addr: load memory address into a register before
505 reference to memory. This makes better cse but slower compilation. */
507 int flag_force_addr = 0;
509 /* Nonzero for -fdefer-pop: don't pop args after each function call;
510 instead save them up to pop many calls' args with one insns. */
512 int flag_defer_pop = 0;
514 /* Nonzero for -ffloat-store: don't allocate floats and doubles
515 in extended-precision registers. */
517 int flag_float_store = 0;
519 /* Nonzero for -fcse-follow-jumps:
520 have cse follow jumps to do a more extensive job. */
522 int flag_cse_follow_jumps;
524 /* Nonzero for -fcse-skip-blocks:
525 have cse follow a branch around a block. */
526 int flag_cse_skip_blocks;
528 /* Nonzero for -fexpensive-optimizations:
529 perform miscellaneous relatively-expensive optimizations. */
530 int flag_expensive_optimizations;
532 /* Nonzero for -fthread-jumps:
533 have jump optimize output of loop. */
535 int flag_thread_jumps;
537 /* Nonzero enables strength-reduction in loop.c. */
539 int flag_strength_reduce = 0;
541 /* Nonzero enables loop unrolling in unroll.c. Only loops for which the
542 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
543 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
544 unrolled. */
546 int flag_old_unroll_loops;
548 /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
549 This is generally not a win. */
551 int flag_old_unroll_all_loops;
553 /* Enables unrolling of simple loops in loop-unroll.c. */
554 int flag_unroll_loops;
556 /* Enables unrolling of all loops in loop-unroll.c. */
557 int flag_unroll_all_loops;
559 /* Nonzero enables loop peeling. */
560 int flag_peel_loops;
562 /* Nonzero enables loop unswitching. */
563 int flag_unswitch_loops;
565 /* Nonzero enables prefetch optimizations for arrays in loops. */
567 int flag_prefetch_loop_arrays;
569 /* Nonzero forces all invariant computations in loops to be moved
570 outside the loop. */
572 int flag_move_all_movables = 0;
574 /* Nonzero forces all general induction variables in loops to be
575 strength reduced. */
577 int flag_reduce_all_givs = 0;
579 /* Nonzero to perform full register move optimization passes. This is the
580 default for -O2. */
582 int flag_regmove = 0;
584 /* Nonzero for -fwritable-strings:
585 store string constants in data segment and don't uniquize them. */
587 int flag_writable_strings = 0;
589 /* Nonzero means don't put addresses of constant functions in registers.
590 Used for compiling the Unix kernel, where strange substitutions are
591 done on the assembly output. */
593 int flag_no_function_cse = 0;
595 /* Nonzero for -fomit-frame-pointer:
596 don't make a frame pointer in simple functions that don't require one. */
598 int flag_omit_frame_pointer = 0;
600 /* Nonzero means place each function into its own section on those platforms
601 which support arbitrary section names and unlimited numbers of sections. */
603 int flag_function_sections = 0;
605 /* ... and similar for data. */
607 int flag_data_sections = 0;
609 /* Nonzero to inhibit use of define_optimization peephole opts. */
611 int flag_no_peephole = 0;
613 /* Nonzero allows GCC to optimize sibling and tail recursive calls. */
615 int flag_optimize_sibling_calls = 0;
617 /* Nonzero means the front end generally wants `errno' maintained by math
618 operations, like built-in SQRT. */
620 int flag_errno_math = 1;
622 /* Nonzero means that unsafe floating-point math optimizations are allowed
623 for the sake of speed. IEEE compliance is not guaranteed, and operations
624 are allowed to assume that their arguments and results are "normal"
625 (e.g., nonnegative for SQRT). */
627 int flag_unsafe_math_optimizations = 0;
629 /* Nonzero means that no NaNs or +-Infs are expected. */
631 int flag_finite_math_only = 0;
633 /* Zero means that floating-point math operations cannot generate a
634 (user-visible) trap. This is the case, for example, in nonstop
635 IEEE 754 arithmetic. Trapping conditions include division by zero,
636 overflow, underflow, invalid and inexact, but does not include
637 operations on signaling NaNs (see below). */
639 int flag_trapping_math = 1;
641 /* Nonzero means disable transformations observable by signaling NaNs.
642 This option implies that any operation on a IEEE signaling NaN can
643 generate a (user-visible) trap. */
645 int flag_signaling_nans = 0;
647 /* 0 means straightforward implementation of complex divide acceptable.
648 1 means wide ranges of inputs must work for complex divide.
649 2 means C99-like requirements for complex divide (not yet implemented). */
651 int flag_complex_divide_method = 0;
653 /* Nonzero means just do syntax checking; don't output anything. */
655 int flag_syntax_only = 0;
657 /* Nonzero means perform loop optimizer. */
659 static int flag_loop_optimize;
661 /* Nonzero means perform crossjumping. */
663 static int flag_crossjumping;
665 /* Nonzero means perform if conversion. */
667 static int flag_if_conversion;
669 /* Nonzero means perform if conversion after reload. */
671 static int flag_if_conversion2;
673 /* Nonzero means to use global dataflow analysis to eliminate
674 useless null pointer tests. */
676 static int flag_delete_null_pointer_checks;
678 /* Nonzero means perform global CSE. */
680 int flag_gcse = 0;
682 /* Nonzero means to do the enhanced load motion during gcse, which trys
683 to hoist loads by not killing them when a store to the same location
684 is seen. */
686 int flag_gcse_lm = 1;
688 /* Nonzero means to perform store motion after gcse, which will try to
689 move stores closer to the exit block. Its not very effective without
690 flag_gcse_lm. */
692 int flag_gcse_sm = 1;
694 /* Perform target register optimization before prologue / epilogue
695 threading. */
697 int flag_branch_target_load_optimize = 0;
699 /* Perform target register optimization after prologue / epilogue
700 threading and jump2. */
702 int flag_branch_target_load_optimize2 = 0;
704 /* Nonzero means to rerun cse after loop optimization. This increases
705 compilation time about 20% and picks up a few more common expressions. */
707 static int flag_rerun_cse_after_loop;
709 /* Nonzero means to run loop optimizations twice. */
711 int flag_rerun_loop_opt;
713 /* Nonzero for -finline-functions: ok to inline functions that look like
714 good inline candidates. */
716 int flag_inline_functions;
718 /* Nonzero for -fkeep-inline-functions: even if we make a function
719 go inline everywhere, keep its definition around for debugging
720 purposes. */
722 int flag_keep_inline_functions;
724 /* Nonzero means that functions will not be inlined. */
726 int flag_no_inline = 2;
728 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
729 not just because the tree inliner turned us off. */
731 int flag_really_no_inline = 2;
733 /* Nonzero means that we should emit static const variables
734 regardless of whether or not optimization is turned on. */
736 int flag_keep_static_consts = 1;
738 /* Nonzero means we should be saving declaration info into a .X file. */
740 int flag_gen_aux_info = 0;
742 /* Specified name of aux-info file. */
744 const char *aux_info_file_name;
746 /* Nonzero means make the text shared if supported. */
748 int flag_shared_data;
750 /* Nonzero means schedule into delayed branch slots if supported. */
752 int flag_delayed_branch;
754 /* Nonzero if we are compiling pure (sharable) code.
755 Value is 1 if we are doing "small" pic; value is 2 if we're doing
756 "large" pic. */
758 int flag_pic;
760 /* Nonzero if we are compiling position independent code for executable.
761 The value is 1 if we are doing "small" pic; value is 2 if we're doing
762 "large" pic. */
764 int flag_pie;
766 /* Nonzero if we are compiling code for a shared library, zero for
767 executable. */
769 int flag_shlib;
771 /* Set to the default thread-local storage (tls) model to use. */
773 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
775 /* Nonzero means generate extra code for exception handling and enable
776 exception handling. */
778 int flag_exceptions;
780 /* Nonzero means generate frame unwind info table when supported. */
782 int flag_unwind_tables = 0;
784 /* Nonzero means generate frame unwind info table exact at each insn boundary */
786 int flag_asynchronous_unwind_tables = 0;
788 /* Nonzero means don't place uninitialized global data in common storage
789 by default. */
791 int flag_no_common;
793 /* Nonzero means change certain warnings into errors.
794 Usually these are warnings about failure to conform to some standard. */
796 int flag_pedantic_errors = 0;
798 /* flag_schedule_insns means schedule insns within basic blocks (before
799 local_alloc).
800 flag_schedule_insns_after_reload means schedule insns after
801 global_alloc. */
803 int flag_schedule_insns = 0;
804 int flag_schedule_insns_after_reload = 0;
806 /* When flag_schedule_insns_after_reload is set, use EBB scheduler. */
807 int flag_sched2_use_superblocks = 0;
809 /* When flag_schedule_insns_after_reload is set, construct traces and EBB
810 scheduler. */
811 int flag_sched2_use_traces = 0;
813 /* The following flags have effect only for scheduling before register
814 allocation:
816 flag_schedule_interblock means schedule insns across basic blocks.
817 flag_schedule_speculative means allow speculative motion of non-load insns.
818 flag_schedule_speculative_load means allow speculative motion of some
819 load insns.
820 flag_schedule_speculative_load_dangerous allows speculative motion of more
821 load insns. */
823 int flag_schedule_interblock = 1;
824 int flag_schedule_speculative = 1;
825 int flag_schedule_speculative_load = 0;
826 int flag_schedule_speculative_load_dangerous = 0;
828 int flag_single_precision_constant;
830 /* flag_branch_on_count_reg means try to replace add-1,compare,branch tupple
831 by a cheaper branch on a count register. */
832 int flag_branch_on_count_reg = 1;
834 /* -finhibit-size-directive inhibits output of .size for ELF.
835 This is used only for compiling crtstuff.c,
836 and it may be extended to other effects
837 needed for crtstuff.c on other systems. */
838 int flag_inhibit_size_directive = 0;
840 /* -fverbose-asm causes extra commentary information to be produced in
841 the generated assembly code (to make it more readable). This option
842 is generally only of use to those who actually need to read the
843 generated assembly code (perhaps while debugging the compiler itself).
844 -fno-verbose-asm, the default, causes the extra information
845 to be omitted and is useful when comparing two assembler files. */
847 int flag_verbose_asm = 0;
849 /* -dA causes debug commentary information to be produced in
850 the generated assembly code (to make it more readable). This option
851 is generally only of use to those who actually need to read the
852 generated assembly code (perhaps while debugging the compiler itself).
853 Currently, this switch is only used by dwarfout.c; however, it is intended
854 to be a catchall for printing debug information in the assembler file. */
856 int flag_debug_asm = 0;
858 /* -dP causes the rtl to be emitted as a comment in assembly. */
860 int flag_dump_rtl_in_asm = 0;
862 /* -fgnu-linker specifies use of the GNU linker for initializations.
863 (Or, more generally, a linker that handles initializations.)
864 -fno-gnu-linker says that collect2 will be used. */
865 #ifdef USE_COLLECT2
866 int flag_gnu_linker = 0;
867 #else
868 int flag_gnu_linker = 1;
869 #endif
871 /* Nonzero means put zero initialized data in the bss section. */
872 int flag_zero_initialized_in_bss = 1;
874 /* Enable SSA. */
875 int flag_ssa = 0;
877 /* Enable ssa conditional constant propagation. */
878 int flag_ssa_ccp = 0;
880 /* Enable ssa aggressive dead code elimination. */
881 int flag_ssa_dce = 0;
883 /* Tag all structures with __attribute__(packed). */
884 int flag_pack_struct = 0;
886 /* Emit code to check for stack overflow; also may cause large objects
887 to be allocated dynamically. */
888 int flag_stack_check;
890 /* When non-NULL, indicates that whenever space is allocated on the
891 stack, the resulting stack pointer must not pass this
892 address---that is, for stacks that grow downward, the stack pointer
893 must always be greater than or equal to this address; for stacks
894 that grow upward, the stack pointer must be less than this address.
895 At present, the rtx may be either a REG or a SYMBOL_REF, although
896 the support provided depends on the backend. */
897 rtx stack_limit_rtx;
899 /* 0 if pointer arguments may alias each other. True in C.
900 1 if pointer arguments may not alias each other but may alias
901 global variables.
902 2 if pointer arguments may not alias each other and may not
903 alias global variables. True in Fortran.
904 This defaults to 0 for C. */
905 int flag_argument_noalias = 0;
907 /* Nonzero if we should do (language-dependent) alias analysis.
908 Typically, this analysis will assume that expressions of certain
909 types do not alias expressions of certain other types. Only used
910 if alias analysis (in general) is enabled. */
911 int flag_strict_aliasing = 0;
913 /* Instrument functions with calls at entry and exit, for profiling. */
914 int flag_instrument_function_entry_exit = 0;
916 /* Nonzero means ignore `#ident' directives. 0 means handle them.
917 On SVR4 targets, it also controls whether or not to emit a
918 string identifying the compiler. */
920 int flag_no_ident = 0;
922 /* This will perform a peephole pass before sched2. */
923 int flag_peephole2 = 0;
925 /* This will try to guess branch probabilities. */
926 int flag_guess_branch_prob = 0;
928 /* -fcheck-bounds causes gcc to generate array bounds checks.
929 For C, C++, ObjC: defaults to off.
930 For Java: defaults to on.
931 For Fortran: defaults to off. */
932 int flag_bounds_check = 0;
934 /* This will attempt to merge constant section constants, if 1 only
935 string constants and constants from constant pool, if 2 also constant
936 variables. */
937 int flag_merge_constants = 1;
939 /* If one, renumber instruction UIDs to reduce the number of
940 unused UIDs if there are a lot of instructions. If greater than
941 one, unconditionally renumber instruction UIDs. */
942 int flag_renumber_insns = 1;
944 /* If nonzero, use the graph coloring register allocator. */
945 int flag_new_regalloc = 0;
947 /* Nonzero if we perform superblock formation. */
949 int flag_tracer = 0;
951 /* Nonzero if we perform whole unit at a time compilation. */
953 int flag_unit_at_a_time = 0;
955 /* Values of the -falign-* flags: how much to align labels in code.
956 0 means `use default', 1 means `don't align'.
957 For each variable, there is an _log variant which is the power
958 of two not less than the variable, for .align output. */
960 int align_loops;
961 int align_loops_log;
962 int align_loops_max_skip;
963 int align_jumps;
964 int align_jumps_log;
965 int align_jumps_max_skip;
966 int align_labels;
967 int align_labels_log;
968 int align_labels_max_skip;
969 int align_functions;
970 int align_functions_log;
972 /* Like align_functions_log above, but used by front-ends to force the
973 minimum function alignment. Zero means no alignment is forced. */
974 int force_align_functions_log;
976 /* Table of supported debugging formats. */
977 static const struct
979 const char *const arg;
980 /* Since PREFERRED_DEBUGGING_TYPE isn't necessarily a
981 constant expression, we use NO_DEBUG in its place. */
982 const enum debug_info_type debug_type;
983 const int use_extensions_p;
984 const char *const description;
985 } *da,
986 debug_args[] =
988 { "", NO_DEBUG, DEFAULT_GDB_EXTENSIONS,
989 N_("Generate debugging info in default format") },
990 { "gdb", NO_DEBUG, 1, N_("Generate debugging info in default extended format") },
991 #ifdef DBX_DEBUGGING_INFO
992 { "stabs", DBX_DEBUG, 0, N_("Generate STABS format debug info") },
993 { "stabs+", DBX_DEBUG, 1, N_("Generate extended STABS format debug info") },
994 #endif
995 #ifdef DWARF_DEBUGGING_INFO
996 { "dwarf", DWARF_DEBUG, 0, N_("Generate DWARF-1 format debug info") },
997 { "dwarf+", DWARF_DEBUG, 1,
998 N_("Generate extended DWARF-1 format debug info") },
999 #endif
1000 #ifdef DWARF2_DEBUGGING_INFO
1001 { "dwarf-2", DWARF2_DEBUG, 0, N_("Generate DWARF-2 debug info") },
1002 #endif
1003 #ifdef XCOFF_DEBUGGING_INFO
1004 { "xcoff", XCOFF_DEBUG, 0, N_("Generate XCOFF format debug info") },
1005 { "xcoff+", XCOFF_DEBUG, 1, N_("Generate extended XCOFF format debug info") },
1006 #endif
1007 #ifdef SDB_DEBUGGING_INFO
1008 { "coff", SDB_DEBUG, 0, N_("Generate COFF format debug info") },
1009 #endif
1010 #ifdef VMS_DEBUGGING_INFO
1011 { "vms", VMS_DEBUG, 0, N_("Generate VMS format debug info") },
1012 #endif
1013 { 0, 0, 0, 0 }
1016 typedef struct
1018 const char *const string;
1019 int *const variable;
1020 const int on_value;
1021 const char *const description;
1023 lang_independent_options;
1025 /* Nonzero if signed arithmetic overflow should trap. */
1026 int flag_trapv = 0;
1028 /* Nonzero if signed arithmetic overflow should wrap around. */
1029 int flag_wrapv = 0;
1031 /* Add or remove a leading underscore from user symbols. */
1032 int flag_leading_underscore = -1;
1034 /* The user symbol prefix after having resolved same. */
1035 const char *user_label_prefix;
1037 static const param_info lang_independent_params[] = {
1038 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT) \
1039 { OPTION, DEFAULT, HELP },
1040 #include "params.def"
1041 #undef DEFPARAM
1042 { NULL, 0, NULL }
1045 /* Table of language-independent -f options.
1046 STRING is the option name. VARIABLE is the address of the variable.
1047 ON_VALUE is the value to store in VARIABLE
1048 if `-fSTRING' is seen as an option.
1049 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
1051 static const lang_independent_options f_options[] =
1053 {"eliminate-dwarf2-dups", &flag_eliminate_dwarf2_dups, 1,
1054 N_("Perform DWARF2 duplicate elimination") },
1055 {"eliminate-unused-debug-types", &flag_eliminate_unused_debug_types, 1,
1056 N_("Perform unused type elimination in debug info") },
1057 {"float-store", &flag_float_store, 1,
1058 N_("Do not store floats in registers") },
1059 {"defer-pop", &flag_defer_pop, 1,
1060 N_("Defer popping functions args from stack until later") },
1061 {"omit-frame-pointer", &flag_omit_frame_pointer, 1,
1062 N_("When possible do not generate stack frames") },
1063 {"optimize-sibling-calls", &flag_optimize_sibling_calls, 1,
1064 N_("Optimize sibling and tail recursive calls") },
1065 {"tracer", &flag_tracer, 1,
1066 N_("Perform superblock formation via tail duplication") },
1067 {"unit-at-a-time", &flag_unit_at_a_time, 1,
1068 N_("Compile whole compilation unit at a time") },
1069 {"cse-follow-jumps", &flag_cse_follow_jumps, 1,
1070 N_("When running CSE, follow jumps to their targets") },
1071 {"cse-skip-blocks", &flag_cse_skip_blocks, 1,
1072 N_("When running CSE, follow conditional jumps") },
1073 {"expensive-optimizations", &flag_expensive_optimizations, 1,
1074 N_("Perform a number of minor, expensive optimizations") },
1075 {"thread-jumps", &flag_thread_jumps, 1,
1076 N_("Perform jump threading optimizations") },
1077 {"strength-reduce", &flag_strength_reduce, 1,
1078 N_("Perform strength reduction optimizations") },
1079 {"unroll-loops", &flag_unroll_loops, 1,
1080 N_("Perform loop unrolling when iteration count is known") },
1081 {"unroll-all-loops", &flag_unroll_all_loops, 1,
1082 N_("Perform loop unrolling for all loops") },
1083 {"old-unroll-loops", &flag_old_unroll_loops, 1,
1084 N_("Perform loop unrolling when iteration count is known") },
1085 {"old-unroll-all-loops", &flag_old_unroll_all_loops, 1,
1086 N_("Perform loop unrolling for all loops") },
1087 {"peel-loops", &flag_peel_loops, 1,
1088 N_("Perform loop peeling") },
1089 {"unswitch-loops", &flag_unswitch_loops, 1,
1090 N_("Perform loop unswitching") },
1091 {"prefetch-loop-arrays", &flag_prefetch_loop_arrays, 1,
1092 N_("Generate prefetch instructions, if available, for arrays in loops") },
1093 {"move-all-movables", &flag_move_all_movables, 1,
1094 N_("Force all loop invariant computations out of loops") },
1095 {"reduce-all-givs", &flag_reduce_all_givs, 1,
1096 N_("Strength reduce all loop general induction variables") },
1097 {"writable-strings", &flag_writable_strings, 1,
1098 N_("Store strings in writable data section") },
1099 {"peephole", &flag_no_peephole, 0,
1100 N_("Enable machine specific peephole optimizations") },
1101 {"force-mem", &flag_force_mem, 1,
1102 N_("Copy memory operands into registers before using") },
1103 {"force-addr", &flag_force_addr, 1,
1104 N_("Copy memory address constants into regs before using") },
1105 {"function-cse", &flag_no_function_cse, 0,
1106 N_("Allow function addresses to be held in registers") },
1107 {"inline-functions", &flag_inline_functions, 1,
1108 N_("Integrate simple functions into their callers") },
1109 {"keep-inline-functions", &flag_keep_inline_functions, 1,
1110 N_("Generate code for funcs even if they are fully inlined") },
1111 {"inline", &flag_no_inline, 0,
1112 N_("Pay attention to the 'inline' keyword") },
1113 {"keep-static-consts", &flag_keep_static_consts, 1,
1114 N_("Emit static const variables even if they are not used") },
1115 {"syntax-only", &flag_syntax_only, 1,
1116 N_("Check for syntax errors, then stop") },
1117 {"shared-data", &flag_shared_data, 1,
1118 N_("Mark data as shared rather than private") },
1119 {"caller-saves", &flag_caller_saves, 1,
1120 N_("Enable saving registers around function calls") },
1121 {"pcc-struct-return", &flag_pcc_struct_return, 1,
1122 N_("Return 'short' aggregates in memory, not registers") },
1123 {"reg-struct-return", &flag_pcc_struct_return, 0,
1124 N_("Return 'short' aggregates in registers") },
1125 {"delayed-branch", &flag_delayed_branch, 1,
1126 N_("Attempt to fill delay slots of branch instructions") },
1127 {"gcse", &flag_gcse, 1,
1128 N_("Perform the global common subexpression elimination") },
1129 {"gcse-lm", &flag_gcse_lm, 1,
1130 N_("Perform enhanced load motion during global subexpression elimination") },
1131 {"gcse-sm", &flag_gcse_sm, 1,
1132 N_("Perform store motion after global subexpression elimination") },
1133 {"branch-target-load-optimize", &flag_branch_target_load_optimize, 1,
1134 N_("Perform branch target load optimization before prologue / epilogue threading") },
1135 {"branch-target-load-optimize2", &flag_branch_target_load_optimize2, 1,
1136 N_("Perform branch target load optimization after prologue / epilogue threading") },
1137 {"loop-optimize", &flag_loop_optimize, 1,
1138 N_("Perform the loop optimizations") },
1139 {"crossjumping", &flag_crossjumping, 1,
1140 N_("Perform cross-jumping optimization") },
1141 {"if-conversion", &flag_if_conversion, 1,
1142 N_("Perform conversion of conditional jumps to branchless equivalents") },
1143 {"if-conversion2", &flag_if_conversion2, 1,
1144 N_("Perform conversion of conditional jumps to conditional execution") },
1145 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1,
1146 N_("Run CSE pass after loop optimizations") },
1147 {"rerun-loop-opt", &flag_rerun_loop_opt, 1,
1148 N_("Run the loop optimizer twice") },
1149 {"delete-null-pointer-checks", &flag_delete_null_pointer_checks, 1,
1150 N_("Delete useless null pointer checks") },
1151 {"schedule-insns", &flag_schedule_insns, 1,
1152 N_("Reschedule instructions before register allocation") },
1153 {"schedule-insns2", &flag_schedule_insns_after_reload, 1,
1154 N_("Reschedule instructions after register allocation") },
1155 {"sched-interblock",&flag_schedule_interblock, 1,
1156 N_("Enable scheduling across basic blocks") },
1157 {"sched-spec",&flag_schedule_speculative, 1,
1158 N_("Allow speculative motion of non-loads") },
1159 {"sched-spec-load",&flag_schedule_speculative_load, 1,
1160 N_("Allow speculative motion of some loads") },
1161 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1,
1162 N_("Allow speculative motion of more loads") },
1163 {"sched2-use-superblocks", &flag_sched2_use_superblocks, 1,
1164 N_("If scheduling post reload, do superblock scheduling") },
1165 {"sched2-use-traces", &flag_sched2_use_traces, 1,
1166 N_("If scheduling post reload, do trace scheduling") },
1167 {"branch-count-reg",&flag_branch_on_count_reg, 1,
1168 N_("Replace add,compare,branch with branch on count reg") },
1169 {"pic", &flag_pic, 1,
1170 N_("Generate position independent code, if possible") },
1171 {"PIC", &flag_pic, 2, ""},
1172 {"pie", &flag_pie, 1,
1173 N_("Generate position independent code for executables, if possible") },
1174 {"PIE", &flag_pie, 2, ""},
1175 {"exceptions", &flag_exceptions, 1,
1176 N_("Enable exception handling") },
1177 {"unwind-tables", &flag_unwind_tables, 1,
1178 N_("Just generate unwind tables for exception handling") },
1179 {"asynchronous-unwind-tables", &flag_asynchronous_unwind_tables, 1,
1180 N_("Generate unwind tables exact at each instruction boundary") },
1181 {"non-call-exceptions", &flag_non_call_exceptions, 1,
1182 N_("Support synchronous non-call exceptions") },
1183 {"profile-arcs", &profile_arc_flag, 1,
1184 N_("Insert arc based program profiling code") },
1185 {"test-coverage", &flag_test_coverage, 1,
1186 N_("Create data files needed by gcov") },
1187 {"branch-probabilities", &flag_branch_probabilities, 1,
1188 N_("Use profiling information for branch probabilities") },
1189 {"profile", &profile_flag, 1,
1190 N_("Enable basic program profiling code") },
1191 {"reorder-blocks", &flag_reorder_blocks, 1,
1192 N_("Reorder basic blocks to improve code placement") },
1193 {"reorder-functions", &flag_reorder_functions, 1,
1194 N_("Reorder functions to improve code placement") },
1195 {"rename-registers", &flag_rename_registers, 1,
1196 N_("Do the register renaming optimization pass") },
1197 {"cprop-registers", &flag_cprop_registers, 1,
1198 N_("Do the register copy-propagation optimization pass") },
1199 {"common", &flag_no_common, 0,
1200 N_("Do not put uninitialized globals in the common section") },
1201 {"inhibit-size-directive", &flag_inhibit_size_directive, 1,
1202 N_("Do not generate .size directives") },
1203 {"function-sections", &flag_function_sections, 1,
1204 N_("place each function into its own section") },
1205 {"data-sections", &flag_data_sections, 1,
1206 N_("place data items into their own section") },
1207 {"verbose-asm", &flag_verbose_asm, 1,
1208 N_("Add extra commentary to assembler output") },
1209 {"gnu-linker", &flag_gnu_linker, 1,
1210 N_("Output GNU ld formatted global initializers") },
1211 {"regmove", &flag_regmove, 1,
1212 N_("Enables a register move optimization") },
1213 {"optimize-register-move", &flag_regmove, 1,
1214 N_("Do the full regmove optimization pass") },
1215 {"pack-struct", &flag_pack_struct, 1,
1216 N_("Pack structure members together without holes") },
1217 {"stack-check", &flag_stack_check, 1,
1218 N_("Insert stack checking code into the program") },
1219 {"argument-alias", &flag_argument_noalias, 0,
1220 N_("Specify that arguments may alias each other & globals") },
1221 {"argument-noalias", &flag_argument_noalias, 1,
1222 N_("Assume arguments may alias globals but not each other") },
1223 {"argument-noalias-global", &flag_argument_noalias, 2,
1224 N_("Assume arguments do not alias each other or globals") },
1225 {"strict-aliasing", &flag_strict_aliasing, 1,
1226 N_("Assume strict aliasing rules apply") },
1227 {"align-loops", &align_loops, 0,
1228 N_("Align the start of loops") },
1229 {"align-jumps", &align_jumps, 0,
1230 N_("Align labels which are only reached by jumping") },
1231 {"align-labels", &align_labels, 0,
1232 N_("Align all labels") },
1233 {"align-functions", &align_functions, 0,
1234 N_("Align the start of functions") },
1235 {"merge-constants", &flag_merge_constants, 1,
1236 N_("Attempt to merge identical constants across compilation units") },
1237 {"merge-all-constants", &flag_merge_constants, 2,
1238 N_("Attempt to merge identical constants and constant variables") },
1239 {"dump-unnumbered", &flag_dump_unnumbered, 1,
1240 N_("Suppress output of instruction numbers and line number notes in debugging dumps") },
1241 {"instrument-functions", &flag_instrument_function_entry_exit, 1,
1242 N_("Instrument function entry/exit with profiling calls") },
1243 {"zero-initialized-in-bss", &flag_zero_initialized_in_bss, 1,
1244 N_("Put zero initialized data in the bss section") },
1245 {"ssa", &flag_ssa, 1,
1246 N_("Enable SSA optimizations") },
1247 {"ssa-ccp", &flag_ssa_ccp, 1,
1248 N_("Enable SSA conditional constant propagation") },
1249 {"ssa-dce", &flag_ssa_dce, 1,
1250 N_("Enable aggressive SSA dead code elimination") },
1251 {"leading-underscore", &flag_leading_underscore, 1,
1252 N_("External symbols have a leading underscore") },
1253 {"ident", &flag_no_ident, 0,
1254 N_("Process #ident directives") },
1255 { "peephole2", &flag_peephole2, 1,
1256 N_("Enables an rtl peephole pass run before sched2") },
1257 {"finite-math-only", &flag_finite_math_only, 1,
1258 N_("Assume no NaNs or +-Infs are generated") },
1259 { "guess-branch-probability", &flag_guess_branch_prob, 1,
1260 N_("Enables guessing of branch probabilities") },
1261 {"math-errno", &flag_errno_math, 1,
1262 N_("Set errno after built-in math functions") },
1263 {"trapping-math", &flag_trapping_math, 1,
1264 N_("Floating-point operations can trap") },
1265 {"unsafe-math-optimizations", &flag_unsafe_math_optimizations, 1,
1266 N_("Allow math optimizations that may violate IEEE or ANSI standards") },
1267 {"signaling-nans", &flag_signaling_nans, 1,
1268 N_("Disable optimizations observable by IEEE signaling NaNs") },
1269 {"bounds-check", &flag_bounds_check, 1,
1270 N_("Generate code to check bounds before indexing arrays") },
1271 {"single-precision-constant", &flag_single_precision_constant, 1,
1272 N_("Convert floating point constant to single precision constant") },
1273 {"time-report", &time_report, 1,
1274 N_("Report time taken by each compiler pass at end of run") },
1275 {"mem-report", &mem_report, 1,
1276 N_("Report on permanent memory allocation at end of run") },
1277 { "trapv", &flag_trapv, 1,
1278 N_("Trap for signed overflow in addition / subtraction / multiplication") },
1279 { "wrapv", &flag_wrapv, 1,
1280 N_("Assume signed arithmetic overflow wraps around") },
1281 { "new-ra", &flag_new_regalloc, 1,
1282 N_("Use graph coloring register allocation.") },
1285 /* Table of language-specific options. */
1287 static const struct lang_opt
1289 const char *const option;
1290 const char *const description;
1292 documented_lang_options[] =
1294 /* In order not to overload the --help output, the convention
1295 used here is to only describe those options which are not
1296 enabled by default. */
1298 { "-ansi",
1299 N_("Compile just for ISO C90") },
1300 { "-std= ",
1301 N_("Determine language standard") },
1303 { "-fsigned-bitfields", "" },
1304 { "-funsigned-bitfields",
1305 N_("Make bit-fields by unsigned by default") },
1306 { "-fno-signed-bitfields", "" },
1307 { "-fno-unsigned-bitfields","" },
1308 { "-fsigned-char",
1309 N_("Make 'char' be signed by default") },
1310 { "-funsigned-char",
1311 N_("Make 'char' be unsigned by default") },
1312 { "-fno-signed-char", "" },
1313 { "-fno-unsigned-char", "" },
1315 { "-fasm", "" },
1316 { "-fno-asm",
1317 N_("Do not recognize the 'asm' keyword") },
1318 { "-fbuiltin", "" },
1319 { "-fno-builtin",
1320 N_("Do not recognize any built in functions") },
1321 { "-fhosted",
1322 N_("Assume normal C execution environment") },
1323 { "-fno-hosted", "" },
1324 { "-ffreestanding",
1325 N_("Assume that standard libraries & main might not exist") },
1326 { "-fno-freestanding", "" },
1327 { "-fcond-mismatch",
1328 N_("Allow different types as args of ? operator") },
1329 { "-fno-cond-mismatch", "" },
1330 { "-fdollars-in-identifiers",
1331 N_("Allow the use of $ inside identifiers") },
1332 { "-fno-dollars-in-identifiers", "" },
1333 { "-fpreprocessed", "" },
1334 { "-fno-preprocessed", "" },
1335 { "-fshort-double",
1336 N_("Use the same size for double as for float") },
1337 { "-fno-short-double", "" },
1338 { "-fshort-enums",
1339 N_("Use the smallest fitting integer to hold enums") },
1340 { "-fno-short-enums", "" },
1341 { "-fshort-wchar",
1342 N_("Override the underlying type for wchar_t to `unsigned short'") },
1343 { "-fno-short-wchar", "" },
1345 { "-Wall",
1346 N_("Enable most warning messages") },
1347 { "-Wbad-function-cast",
1348 N_("Warn about casting functions to incompatible types") },
1349 { "-Wno-bad-function-cast", "" },
1350 { "-Wmissing-format-attribute",
1351 N_("Warn about functions which might be candidates for format attributes") },
1352 { "-Wno-missing-format-attribute", "" },
1353 { "-Wcast-qual",
1354 N_("Warn about casts which discard qualifiers") },
1355 { "-Wno-cast-qual", "" },
1356 { "-Wchar-subscripts",
1357 N_("Warn about subscripts whose type is 'char'") },
1358 { "-Wno-char-subscripts", "" },
1359 { "-Wcomment",
1360 N_("Warn if nested comments are detected") },
1361 { "-Wno-comment", "" },
1362 { "-Wcomments",
1363 N_("Warn if nested comments are detected") },
1364 { "-Wno-comments", "" },
1365 { "-Wconversion",
1366 N_("Warn about possibly confusing type conversions") },
1367 { "-Wno-conversion", "" },
1368 { "-Wdiv-by-zero", "" },
1369 { "-Wno-div-by-zero",
1370 N_("Do not warn about compile-time integer division by zero") },
1371 { "-Wfloat-equal",
1372 N_("Warn about testing equality of floating point numbers") },
1373 { "-Wno-float-equal", "" },
1374 { "-Wformat",
1375 N_("Warn about printf/scanf/strftime/strfmon format anomalies") },
1376 { "-Wno-format", "" },
1377 { "-Wformat-extra-args", "" },
1378 { "-Wno-format-extra-args",
1379 N_("Don't warn about too many arguments to format functions") },
1380 { "-Wformat-nonliteral",
1381 N_("Warn about non-string-literal format strings") },
1382 { "-Wno-format-nonliteral", "" },
1383 { "-Wformat-security",
1384 N_("Warn about possible security problems with format functions") },
1385 { "-Wno-format-security", "" },
1386 { "-Wformat-y2k", "" },
1387 { "-Wno-format-y2k",
1388 N_("Don't warn about strftime formats yielding 2 digit years") },
1389 { "-Wimplicit-function-declaration",
1390 N_("Warn about implicit function declarations") },
1391 { "-Wno-implicit-function-declaration", "" },
1392 { "-Werror-implicit-function-declaration", "" },
1393 { "-Wimplicit-int",
1394 N_("Warn when a declaration does not specify a type") },
1395 { "-Wno-implicit-int", "" },
1396 { "-Wimplicit", "" },
1397 { "-Wno-implicit", "" },
1398 { "-Wimport",
1399 N_("Warn about the use of the #import directive") },
1400 { "-Wno-import", "" },
1401 { "-Winvalid-pch",
1402 N_("Warn about PCH files that are found but not used") },
1403 { "-Wlong-long","" },
1404 { "-Wno-long-long",
1405 N_("Do not warn about using 'long long' when -pedantic") },
1406 { "-Wmain",
1407 N_("Warn about suspicious declarations of main") },
1408 { "-Wno-main", "" },
1409 { "-Wmissing-braces",
1410 N_("Warn about possibly missing braces around initializers") },
1411 { "-Wno-missing-braces", "" },
1412 { "-Wmissing-declarations",
1413 N_("Warn about global funcs without previous declarations") },
1414 { "-Wno-missing-declarations", "" },
1415 { "-Wmissing-prototypes",
1416 N_("Warn about global funcs without prototypes") },
1417 { "-Wno-missing-prototypes", "" },
1418 { "-Wmultichar",
1419 N_("Warn about use of multicharacter literals") },
1420 { "-Wno-multichar", "" },
1421 { "-Wnested-externs",
1422 N_("Warn about externs not at file scope level") },
1423 { "-Wno-nested-externs", "" },
1424 { "-Wparentheses",
1425 N_("Warn about possible missing parentheses") },
1426 { "-Wno-parentheses", "" },
1427 { "-Wpointer-arith",
1428 N_("Warn about function pointer arithmetic") },
1429 { "-Wno-pointer-arith", "" },
1430 { "-Wredundant-decls",
1431 N_("Warn about multiple declarations of the same object") },
1432 { "-Wno-redundant-decls", "" },
1433 { "-Wreturn-type",
1434 N_("Warn whenever a function's return-type defaults to int") },
1435 { "-Wno-return-type", "" },
1436 { "-Wsequence-point",
1437 N_("Warn about possible violations of sequence point rules") },
1438 { "-Wno-sequence-point", "" },
1439 { "-Wsign-compare",
1440 N_("Warn about signed/unsigned comparisons") },
1441 { "-Wno-sign-compare", "" },
1442 { "-Wstrict-prototypes",
1443 N_("Warn about non-prototyped function decls") },
1444 { "-Wno-strict-prototypes", "" },
1445 { "-Wtraditional",
1446 N_("Warn about constructs whose meanings change in ISO C") },
1447 { "-Wno-traditional", "" },
1448 { "-Wtrigraphs",
1449 N_("Warn when trigraphs are encountered") },
1450 { "-Wno-trigraphs", "" },
1451 { "-Wundef", "" },
1452 { "-Wno-undef", "" },
1453 { "-Wunknown-pragmas",
1454 N_("Warn about unrecognized pragmas") },
1455 { "-Wno-unknown-pragmas", "" },
1456 { "-Wwrite-strings",
1457 N_("Mark strings as 'const char *'") },
1458 { "-Wno-write-strings", "" },
1460 #define DEFINE_LANG_NAME(NAME) { NULL, NAME },
1462 #include "options_.h"
1466 /* Here is a table, controlled by the tm.h file, listing each -m switch
1467 and which bits in `target_switches' it should set or clear.
1468 If VALUE is positive, it is bits to set.
1469 If VALUE is negative, -VALUE is bits to clear.
1470 (The sign bit is not used so there is no confusion.) */
1472 static const struct
1474 const char *const name;
1475 const int value;
1476 const char *const description;
1478 target_switches[] = TARGET_SWITCHES;
1480 /* This table is similar, but allows the switch to have a value. */
1482 #ifdef TARGET_OPTIONS
1483 static const struct
1485 const char *const prefix;
1486 const char **const variable;
1487 const char *const description;
1488 const char *const value;
1490 target_options[] = TARGET_OPTIONS;
1491 #endif
1493 /* Options controlling warnings. */
1495 /* Don't print warning messages. -w. */
1497 int inhibit_warnings = 0;
1499 /* Don't suppress warnings from system headers. -Wsystem-headers. */
1501 int warn_system_headers = 0;
1503 /* Print various extra warnings. -W/-Wextra. */
1505 int extra_warnings = 0;
1507 /* Treat warnings as errors. -Werror. */
1509 int warnings_are_errors = 0;
1511 /* Nonzero to warn about unused variables, functions et.al. */
1513 int warn_unused_function;
1514 int warn_unused_label;
1515 int warn_unused_parameter;
1516 int warn_unused_variable;
1517 int warn_unused_value;
1519 /* Nonzero to warn about code which is never reached. */
1521 int warn_notreached;
1523 /* Nonzero to warn about variables used before they are initialized. */
1525 int warn_uninitialized;
1527 /* Nonzero means warn about all declarations which shadow others. */
1529 int warn_shadow;
1531 /* Warn if a switch on an enum, that does not have a default case,
1532 fails to have a case for every enum value. */
1534 int warn_switch;
1536 /* Warn if a switch does not have a default case. */
1538 int warn_switch_default;
1540 /* Warn if a switch on an enum fails to have a case for every enum
1541 value (regardless of the presence or otherwise of a default case). */
1543 int warn_switch_enum;
1545 /* Nonzero means warn about function definitions that default the return type
1546 or that use a null return and have a return-type other than void. */
1548 int warn_return_type;
1550 /* Nonzero means warn about pointer casts that increase the required
1551 alignment of the target type (and might therefore lead to a crash
1552 due to a misaligned access). */
1554 int warn_cast_align;
1556 /* Nonzero means warn about any objects definitions whose size is larger
1557 than N bytes. Also want about function definitions whose returned
1558 values are larger than N bytes. The value N is in `larger_than_size'. */
1560 int warn_larger_than;
1561 HOST_WIDE_INT larger_than_size;
1563 /* Nonzero means warn if inline function is too large. */
1565 int warn_inline;
1567 /* Warn if a function returns an aggregate,
1568 since there are often incompatible calling conventions for doing this. */
1570 int warn_aggregate_return;
1572 /* Warn if packed attribute on struct is unnecessary and inefficient. */
1574 int warn_packed;
1576 /* Warn when gcc pads a structure to an alignment boundary. */
1578 int warn_padded;
1580 /* Warn when an optimization pass is disabled. */
1582 int warn_disabled_optimization;
1584 /* Warn about functions which might be candidates for attribute noreturn. */
1586 int warn_missing_noreturn;
1588 /* Nonzero means warn about uses of __attribute__((deprecated))
1589 declarations. */
1591 int warn_deprecated_decl = 1;
1593 /* Nonzero means warn about constructs which might not be
1594 strict-aliasing safe. */
1596 int warn_strict_aliasing;
1598 /* Like f_options, but for -W. */
1600 static const lang_independent_options W_options[] =
1602 {"unused-function", &warn_unused_function, 1,
1603 N_("Warn when a function is unused") },
1604 {"unused-label", &warn_unused_label, 1,
1605 N_("Warn when a label is unused") },
1606 {"unused-parameter", &warn_unused_parameter, 1,
1607 N_("Warn when a function parameter is unused") },
1608 {"unused-variable", &warn_unused_variable, 1,
1609 N_("Warn when a variable is unused") },
1610 {"unused-value", &warn_unused_value, 1,
1611 N_("Warn when an expression value is unused") },
1612 {"system-headers", &warn_system_headers, 1,
1613 N_("Do not suppress warnings from system headers") },
1614 {"error", &warnings_are_errors, 1,
1615 N_("Treat all warnings as errors") },
1616 {"shadow", &warn_shadow, 1,
1617 N_("Warn when one local variable shadows another") },
1618 {"switch", &warn_switch, 1,
1619 N_("Warn about enumerated switches, with no default, missing a case") },
1620 {"switch-default", &warn_switch_default, 1,
1621 N_("Warn about enumerated switches missing a default case") },
1622 {"switch-enum", &warn_switch_enum, 1,
1623 N_("Warn about all enumerated switches missing a specific case") },
1624 {"aggregate-return", &warn_aggregate_return, 1,
1625 N_("Warn about returning structures, unions or arrays") },
1626 {"cast-align", &warn_cast_align, 1,
1627 N_("Warn about pointer casts which increase alignment") },
1628 {"unreachable-code", &warn_notreached, 1,
1629 N_("Warn about code that will never be executed") },
1630 {"uninitialized", &warn_uninitialized, 1,
1631 N_("Warn about uninitialized automatic variables") },
1632 {"inline", &warn_inline, 1,
1633 N_("Warn when an inlined function cannot be inlined") },
1634 {"packed", &warn_packed, 1,
1635 N_("Warn when the packed attribute has no effect on struct layout") },
1636 {"padded", &warn_padded, 1,
1637 N_("Warn when padding is required to align struct members") },
1638 {"disabled-optimization", &warn_disabled_optimization, 1,
1639 N_("Warn when an optimization pass is disabled") },
1640 {"deprecated-declarations", &warn_deprecated_decl, 1,
1641 N_("Warn about uses of __attribute__((deprecated)) declarations") },
1642 {"missing-noreturn", &warn_missing_noreturn, 1,
1643 N_("Warn about functions which might be candidates for attribute noreturn") },
1644 {"strict-aliasing", &warn_strict_aliasing, 1,
1645 N_ ("Warn about code which might break the strict aliasing rules") }
1648 /* The following routines are useful in setting all the flags that
1649 -ffast-math and -fno-fast-math imply. */
1651 void
1652 set_fast_math_flags (int set)
1654 flag_trapping_math = !set;
1655 flag_unsafe_math_optimizations = set;
1656 flag_finite_math_only = set;
1657 flag_errno_math = !set;
1658 if (set)
1659 flag_signaling_nans = 0;
1662 /* Return true iff flags are set as if -ffast-math. */
1663 bool
1664 fast_math_flags_set_p (void)
1666 return (!flag_trapping_math
1667 && flag_unsafe_math_optimizations
1668 && flag_finite_math_only
1669 && !flag_errno_math);
1672 /* Output files for assembler code (real compiler output)
1673 and debugging dumps. */
1675 FILE *asm_out_file;
1676 FILE *aux_info_file;
1677 FILE *rtl_dump_file = NULL;
1679 /* Decode the string P as an integral parameter.
1680 If the string is indeed an integer return its numeric value else
1681 issue an Invalid Option error for the option PNAME and return DEFVAL.
1682 If PNAME is zero just return DEFVAL, do not call error. */
1685 read_integral_parameter (const char *p, const char *pname, const int defval)
1687 const char *endp = p;
1689 while (*endp)
1691 if (ISDIGIT (*endp))
1692 endp++;
1693 else
1694 break;
1697 if (*endp != 0)
1699 if (pname != 0)
1700 error ("invalid option argument `%s'", pname);
1701 return defval;
1704 return atoi (p);
1707 /* Return the logarithm of X, base 2, considering X unsigned,
1708 if X is a power of 2. Otherwise, returns -1.
1710 This should be used via the `exact_log2' macro. */
1713 exact_log2_wide (unsigned HOST_WIDE_INT x)
1715 int log = 0;
1716 /* Test for 0 or a power of 2. */
1717 if (x == 0 || x != (x & -x))
1718 return -1;
1719 while ((x >>= 1) != 0)
1720 log++;
1721 return log;
1724 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1725 If X is 0, return -1.
1727 This should be used via the floor_log2 macro. */
1730 floor_log2_wide (unsigned HOST_WIDE_INT x)
1732 int log = -1;
1733 while (x != 0)
1734 log++,
1735 x >>= 1;
1736 return log;
1739 /* Handler for fatal signals, such as SIGSEGV. These are transformed
1740 into ICE messages, which is much more user friendly. In case the
1741 error printer crashes, reset the signal to prevent infinite recursion. */
1743 static void
1744 crash_signal (int signo)
1746 signal (signo, SIG_DFL);
1747 internal_error ("%s", strsignal (signo));
1750 /* Arrange to dump core on error. (The regular error message is still
1751 printed first, except in the case of abort().) */
1753 static void
1754 setup_core_dumping (void)
1756 #ifdef SIGABRT
1757 signal (SIGABRT, SIG_DFL);
1758 #endif
1759 #if defined(HAVE_SETRLIMIT)
1761 struct rlimit rlim;
1762 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
1763 fatal_error ("getting core file size maximum limit: %m");
1764 rlim.rlim_cur = rlim.rlim_max;
1765 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
1766 fatal_error ("setting core file size limit to maximum: %m");
1768 #endif
1769 diagnostic_abort_on_error (global_dc);
1773 /* Strip off a legitimate source ending from the input string NAME of
1774 length LEN. Rather than having to know the names used by all of
1775 our front ends, we strip off an ending of a period followed by
1776 up to five characters. (Java uses ".class".) */
1778 void
1779 strip_off_ending (char *name, int len)
1781 int i;
1782 for (i = 2; i < 6 && len > i; i++)
1784 if (name[len - i] == '.')
1786 name[len - i] = '\0';
1787 break;
1792 /* Output a quoted string. */
1794 void
1795 output_quoted_string (FILE *asm_file, const char *string)
1797 #ifdef OUTPUT_QUOTED_STRING
1798 OUTPUT_QUOTED_STRING (asm_file, string);
1799 #else
1800 char c;
1802 putc ('\"', asm_file);
1803 while ((c = *string++) != 0)
1805 if (ISPRINT (c))
1807 if (c == '\"' || c == '\\')
1808 putc ('\\', asm_file);
1809 putc (c, asm_file);
1811 else
1812 fprintf (asm_file, "\\%03o", (unsigned char) c);
1814 putc ('\"', asm_file);
1815 #endif
1818 /* Output NAME into FILE after having turned it into something
1819 usable as an identifier in a target's assembly file. */
1820 void
1821 output_clean_symbol_name (FILE *file, const char *name)
1823 /* Make a copy of NAME. */
1824 char *id = xstrdup (name);
1826 /* Make it look like a valid identifier for an assembler. */
1827 clean_symbol_name (id);
1829 fputs (id, file);
1830 free (id);
1834 /* Output a file name in the form wanted by System V. */
1836 void
1837 output_file_directive (FILE *asm_file, const char *input_name)
1839 int len = strlen (input_name);
1840 const char *na = input_name + len;
1842 /* NA gets INPUT_NAME sans directory names. */
1843 while (na > input_name)
1845 if (IS_DIR_SEPARATOR (na[-1]))
1846 break;
1847 na--;
1850 #ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
1851 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
1852 #else
1853 #ifdef ASM_OUTPUT_SOURCE_FILENAME
1854 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
1855 #else
1856 fprintf (asm_file, "\t.file\t");
1857 output_quoted_string (asm_file, na);
1858 fputc ('\n', asm_file);
1859 #endif
1860 #endif
1863 /* Routine to open a dump file. Return true if the dump file is enabled. */
1865 static int
1866 open_dump_file (enum dump_file_index index, tree decl)
1868 char *dump_name;
1869 const char *open_arg;
1870 char seq[16];
1872 if (! dump_file[index].enabled)
1873 return 0;
1875 timevar_push (TV_DUMP);
1876 if (rtl_dump_file != NULL)
1877 fclose (rtl_dump_file);
1879 sprintf (seq, DUMPFILE_FORMAT, index);
1881 if (! dump_file[index].initialized)
1883 /* If we've not initialized the files, do so now. */
1884 if (graph_dump_format != no_graph
1885 && dump_file[index].graph_dump_p)
1887 dump_name = concat (seq, dump_file[index].extension, NULL);
1888 clean_graph_dump_file (dump_base_name, dump_name);
1889 free (dump_name);
1891 dump_file[index].initialized = 1;
1892 open_arg = "w";
1894 else
1895 open_arg = "a";
1897 dump_name = concat (dump_base_name, seq,
1898 dump_file[index].extension, NULL);
1900 rtl_dump_file = fopen (dump_name, open_arg);
1901 if (rtl_dump_file == NULL)
1902 fatal_error ("can't open %s: %m", dump_name);
1904 free (dump_name);
1906 if (decl)
1907 fprintf (rtl_dump_file, "\n;; Function %s%s\n\n",
1908 (*lang_hooks.decl_printable_name) (decl, 2),
1909 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
1910 ? " (hot)"
1911 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
1912 ? " (unlikely executed)"
1913 : "");
1915 timevar_pop (TV_DUMP);
1916 return 1;
1919 /* Routine to close a dump file. */
1921 static void
1922 close_dump_file (enum dump_file_index index,
1923 void (*func) (FILE *, rtx),
1924 rtx insns)
1926 if (! rtl_dump_file)
1927 return;
1929 timevar_push (TV_DUMP);
1930 if (insns
1931 && graph_dump_format != no_graph
1932 && dump_file[index].graph_dump_p)
1934 char seq[16];
1935 char *suffix;
1937 sprintf (seq, DUMPFILE_FORMAT, index);
1938 suffix = concat (seq, dump_file[index].extension, NULL);
1939 print_rtl_graph_with_bb (dump_base_name, suffix, insns);
1940 free (suffix);
1943 if (func && insns)
1944 func (rtl_dump_file, insns);
1946 fflush (rtl_dump_file);
1947 fclose (rtl_dump_file);
1949 rtl_dump_file = NULL;
1950 timevar_pop (TV_DUMP);
1953 /* Do any final processing required for the declarations in VEC, of
1954 which there are LEN. We write out inline functions and variables
1955 that have been deferred until this point, but which are required.
1956 Returns nonzero if anything was put out. */
1959 wrapup_global_declarations (tree *vec, int len)
1961 tree decl;
1962 int i;
1963 int reconsider;
1964 int output_something = 0;
1966 for (i = 0; i < len; i++)
1968 decl = vec[i];
1970 /* We're not deferring this any longer. Assignment is
1971 conditional to avoid needlessly dirtying PCH pages. */
1972 if (DECL_DEFER_OUTPUT (decl) != 0)
1973 DECL_DEFER_OUTPUT (decl) = 0;
1975 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
1976 (*lang_hooks.finish_incomplete_decl) (decl);
1979 /* Now emit any global variables or functions that we have been
1980 putting off. We need to loop in case one of the things emitted
1981 here references another one which comes earlier in the list. */
1984 reconsider = 0;
1985 for (i = 0; i < len; i++)
1987 decl = vec[i];
1989 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
1990 continue;
1992 /* Don't write out static consts, unless we still need them.
1994 We also keep static consts if not optimizing (for debugging),
1995 unless the user specified -fno-keep-static-consts.
1996 ??? They might be better written into the debug information.
1997 This is possible when using DWARF.
1999 A language processor that wants static constants to be always
2000 written out (even if it is not used) is responsible for
2001 calling rest_of_decl_compilation itself. E.g. the C front-end
2002 calls rest_of_decl_compilation from finish_decl.
2003 One motivation for this is that is conventional in some
2004 environments to write things like:
2005 static const char rcsid[] = "... version string ...";
2006 intending to force the string to be in the executable.
2008 A language processor that would prefer to have unneeded
2009 static constants "optimized away" would just defer writing
2010 them out until here. E.g. C++ does this, because static
2011 constants are often defined in header files.
2013 ??? A tempting alternative (for both C and C++) would be
2014 to force a constant to be written if and only if it is
2015 defined in a main file, as opposed to an include file. */
2017 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
2019 bool needed = 1;
2021 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2022 /* needed */;
2023 else if (DECL_COMDAT (decl))
2024 needed = 0;
2025 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
2026 && (optimize || !flag_keep_static_consts
2027 || DECL_ARTIFICIAL (decl)))
2028 needed = 0;
2030 if (needed)
2032 reconsider = 1;
2033 rest_of_decl_compilation (decl, NULL, 1, 1);
2037 if (TREE_CODE (decl) == FUNCTION_DECL
2038 && DECL_INITIAL (decl) != 0
2039 && DECL_SAVED_INSNS (decl) != 0
2040 && (flag_keep_inline_functions
2041 || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
2042 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2044 reconsider = 1;
2045 output_inline_function (decl);
2049 if (reconsider)
2050 output_something = 1;
2052 while (reconsider);
2054 return output_something;
2057 /* Issue appropriate warnings for the global declarations in VEC (of
2058 which there are LEN). Output debugging information for them. */
2060 void
2061 check_global_declarations (tree *vec, int len)
2063 tree decl;
2064 int i;
2066 for (i = 0; i < len; i++)
2068 decl = vec[i];
2070 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2071 && ! TREE_ASM_WRITTEN (decl))
2072 /* Cancel the RTL for this decl so that, if debugging info
2073 output for global variables is still to come,
2074 this one will be omitted. */
2075 SET_DECL_RTL (decl, NULL_RTX);
2077 /* Warn about any function
2078 declared static but not defined.
2079 We don't warn about variables,
2080 because many programs have static variables
2081 that exist only to get some text into the object file. */
2082 if (TREE_CODE (decl) == FUNCTION_DECL
2083 && (warn_unused_function
2084 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2085 && DECL_INITIAL (decl) == 0
2086 && DECL_EXTERNAL (decl)
2087 && ! DECL_ARTIFICIAL (decl)
2088 && ! TREE_PUBLIC (decl))
2090 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2091 pedwarn_with_decl (decl,
2092 "`%s' used but never defined");
2093 else
2094 warning_with_decl (decl,
2095 "`%s' declared `static' but never defined");
2096 /* This symbol is effectively an "extern" declaration now. */
2097 TREE_PUBLIC (decl) = 1;
2098 assemble_external (decl);
2101 /* Warn about static fns or vars defined but not used. */
2102 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
2103 || (warn_unused_variable && TREE_CODE (decl) == VAR_DECL))
2104 && ! TREE_USED (decl)
2105 /* The TREE_USED bit for file-scope decls is kept in the identifier,
2106 to handle multiple external decls in different scopes. */
2107 && ! TREE_USED (DECL_NAME (decl))
2108 && ! DECL_EXTERNAL (decl)
2109 && ! TREE_PUBLIC (decl)
2110 /* A volatile variable might be used in some non-obvious way. */
2111 && ! TREE_THIS_VOLATILE (decl)
2112 /* Global register variables must be declared to reserve them. */
2113 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
2114 /* Otherwise, ask the language. */
2115 && (*lang_hooks.decls.warn_unused_global) (decl))
2116 warning_with_decl (decl, "`%s' defined but not used");
2118 /* Avoid confusing the debug information machinery when there are
2119 errors. */
2120 if (errorcount == 0 && sorrycount == 0)
2122 timevar_push (TV_SYMOUT);
2123 (*debug_hooks->global_decl) (decl);
2124 timevar_pop (TV_SYMOUT);
2129 /* Save the current INPUT_LOCATION on the top entry in the
2130 INPUT_FILE_STACK. Push a new entry for FILE and LINE, and set the
2131 INPUT_LOCATION accordingly. */
2133 void
2134 push_srcloc (const char *file, int line)
2136 struct file_stack *fs;
2138 fs = (struct file_stack *) xmalloc (sizeof (struct file_stack));
2139 fs->location = input_location;
2140 fs->next = input_file_stack;
2141 input_filename = file;
2142 input_line = line;
2143 input_file_stack = fs;
2144 input_file_stack_tick++;
2147 /* Pop the top entry off the stack of presently open source files.
2148 Restore the INPUT_LOCATION from the new topmost entry on the
2149 stack. */
2151 void
2152 pop_srcloc (void)
2154 struct file_stack *fs;
2156 fs = input_file_stack;
2157 input_location = fs->location;
2158 input_file_stack = fs->next;
2159 free (fs);
2160 input_file_stack_tick++;
2163 /* Compile an entire translation unit. Write a file of assembly
2164 output and various debugging dumps. */
2166 static void
2167 compile_file (void)
2169 /* Initialize yet another pass. */
2171 init_final (main_input_filename);
2172 coverage_init (aux_base_name);
2174 timevar_push (TV_PARSE);
2176 /* Call the parser, which parses the entire file (calling
2177 rest_of_compilation for each function). */
2178 (*lang_hooks.parse_file) (set_yydebug);
2180 /* In case there were missing block closers,
2181 get us back to the global binding level. */
2182 (*lang_hooks.clear_binding_stack) ();
2184 /* Compilation is now finished except for writing
2185 what's left of the symbol table output. */
2186 timevar_pop (TV_PARSE);
2188 if (flag_syntax_only)
2189 return;
2191 (*lang_hooks.decls.final_write_globals)();
2193 /* This must occur after the loop to output deferred functions.
2194 Else the coverage initializer would not be emitted if all the
2195 functions in this compilation unit were deferred. */
2196 coverage_finish ();
2198 /* Write out any pending weak symbol declarations. */
2200 weak_finish ();
2202 /* Do dbx symbols. */
2203 timevar_push (TV_SYMOUT);
2205 #ifdef DWARF2_UNWIND_INFO
2206 if (dwarf2out_do_frame ())
2207 dwarf2out_frame_finish ();
2208 #endif
2210 (*debug_hooks->finish) (main_input_filename);
2211 timevar_pop (TV_SYMOUT);
2213 /* Output some stuff at end of file if nec. */
2215 dw2_output_indirect_constants ();
2217 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
2219 timevar_push (TV_DUMP);
2220 open_dump_file (DFI_bp, NULL);
2222 end_branch_prob ();
2224 close_dump_file (DFI_bp, NULL, NULL_RTX);
2225 timevar_pop (TV_DUMP);
2228 targetm.asm_out.file_end ();
2230 /* Attach a special .ident directive to the end of the file to identify
2231 the version of GCC which compiled this code. The format of the .ident
2232 string is patterned after the ones produced by native SVR4 compilers. */
2233 #ifdef IDENT_ASM_OP
2234 if (!flag_no_ident)
2235 fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
2236 IDENT_ASM_OP, version_string);
2237 #endif
2239 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
2241 timevar_push (TV_DUMP);
2242 dump_combine_total_stats (rtl_dump_file);
2243 close_dump_file (DFI_combine, NULL, NULL_RTX);
2244 timevar_pop (TV_DUMP);
2248 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
2249 and TYPE_DECL nodes.
2251 This does nothing for local (non-static) variables, unless the
2252 variable is a register variable with an ASMSPEC. In that case, or
2253 if the variable is not an automatic, it sets up the RTL and
2254 outputs any assembler code (label definition, storage allocation
2255 and initialization).
2257 DECL is the declaration. If ASMSPEC is nonzero, it specifies
2258 the assembler symbol name to be used. TOP_LEVEL is nonzero
2259 if this declaration is not within a function. */
2261 void
2262 rest_of_decl_compilation (tree decl,
2263 const char *asmspec,
2264 int top_level,
2265 int at_end)
2267 /* We deferred calling assemble_alias so that we could collect
2268 other attributes such as visibility. Emit the alias now. */
2270 tree alias;
2271 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
2272 if (alias)
2274 alias = TREE_VALUE (TREE_VALUE (alias));
2275 alias = get_identifier (TREE_STRING_POINTER (alias));
2276 assemble_alias (decl, alias);
2280 /* Forward declarations for nested functions are not "external",
2281 but we need to treat them as if they were. */
2282 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
2283 || TREE_CODE (decl) == FUNCTION_DECL)
2285 timevar_push (TV_VARCONST);
2287 if (asmspec)
2288 make_decl_rtl (decl, asmspec);
2290 /* Don't output anything when a tentative file-scope definition
2291 is seen. But at end of compilation, do output code for them. */
2292 if (at_end || !DECL_DEFER_OUTPUT (decl))
2293 assemble_variable (decl, top_level, at_end, 0);
2295 #ifdef ASM_FINISH_DECLARE_OBJECT
2296 if (decl == last_assemble_variable_decl)
2298 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
2299 top_level, at_end);
2301 #endif
2303 timevar_pop (TV_VARCONST);
2305 else if (DECL_REGISTER (decl) && asmspec != 0)
2307 if (decode_reg_name (asmspec) >= 0)
2309 SET_DECL_RTL (decl, NULL_RTX);
2310 make_decl_rtl (decl, asmspec);
2312 else
2314 error ("invalid register name `%s' for register variable", asmspec);
2315 DECL_REGISTER (decl) = 0;
2316 if (!top_level)
2317 expand_decl (decl);
2320 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2321 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2322 && TREE_CODE (decl) == TYPE_DECL)
2324 timevar_push (TV_SYMOUT);
2325 dbxout_symbol (decl, 0);
2326 timevar_pop (TV_SYMOUT);
2328 #endif
2329 #ifdef SDB_DEBUGGING_INFO
2330 else if (write_symbols == SDB_DEBUG && top_level
2331 && TREE_CODE (decl) == TYPE_DECL)
2333 timevar_push (TV_SYMOUT);
2334 sdbout_symbol (decl, 0);
2335 timevar_pop (TV_SYMOUT);
2337 #endif
2338 #ifdef DWARF2_DEBUGGING_INFO
2339 else if ((write_symbols == DWARF2_DEBUG
2340 || write_symbols == VMS_AND_DWARF2_DEBUG)
2341 && top_level
2342 && TREE_CODE (decl) == TYPE_DECL)
2344 timevar_push (TV_SYMOUT);
2345 dwarf2out_decl (decl);
2346 timevar_pop (TV_SYMOUT);
2348 #endif
2351 /* Called after finishing a record, union or enumeral type. */
2353 void
2354 rest_of_type_compilation (
2355 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) \
2356 || defined (SDB_DEBUGGING_INFO) || defined (DWARF2_DEBUGGING_INFO)
2357 tree type,
2358 int toplev
2359 #else
2360 tree type ATTRIBUTE_UNUSED,
2361 int toplev ATTRIBUTE_UNUSED
2362 #endif
2365 /* Avoid confusing the debug information machinery when there are
2366 errors. */
2367 if (errorcount != 0 || sorrycount != 0)
2368 return;
2370 timevar_push (TV_SYMOUT);
2371 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2372 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2373 dbxout_symbol (TYPE_STUB_DECL (type), !toplev);
2374 #endif
2375 #ifdef SDB_DEBUGGING_INFO
2376 if (write_symbols == SDB_DEBUG)
2377 sdbout_symbol (TYPE_STUB_DECL (type), !toplev);
2378 #endif
2379 #ifdef DWARF2_DEBUGGING_INFO
2380 if ((write_symbols == DWARF2_DEBUG
2381 || write_symbols == VMS_AND_DWARF2_DEBUG)
2382 && toplev)
2383 dwarf2out_decl (TYPE_STUB_DECL (type));
2384 #endif
2385 timevar_pop (TV_SYMOUT);
2388 /* Turn the RTL into assembly. */
2389 static void
2390 rest_of_handle_final (tree decl, rtx insns)
2392 timevar_push (TV_FINAL);
2394 rtx x;
2395 const char *fnname;
2397 /* Get the function's name, as described by its RTL. This may be
2398 different from the DECL_NAME name used in the source file. */
2400 x = DECL_RTL (decl);
2401 if (GET_CODE (x) != MEM)
2402 abort ();
2403 x = XEXP (x, 0);
2404 if (GET_CODE (x) != SYMBOL_REF)
2405 abort ();
2406 fnname = XSTR (x, 0);
2408 assemble_start_function (decl, fnname);
2409 final_start_function (insns, asm_out_file, optimize);
2410 final (insns, asm_out_file, optimize, 0);
2411 final_end_function ();
2413 #ifdef IA64_UNWIND_INFO
2414 /* ??? The IA-64 ".handlerdata" directive must be issued before
2415 the ".endp" directive that closes the procedure descriptor. */
2416 output_function_exception_table ();
2417 #endif
2419 assemble_end_function (decl, fnname);
2421 #ifndef IA64_UNWIND_INFO
2422 /* Otherwise, it feels unclean to switch sections in the middle. */
2423 output_function_exception_table ();
2424 #endif
2426 if (! quiet_flag)
2427 fflush (asm_out_file);
2429 /* Release all memory allocated by flow. */
2430 free_basic_block_vars (0);
2432 /* Release all memory held by regsets now. */
2433 regset_release_memory ();
2435 timevar_pop (TV_FINAL);
2437 ggc_collect ();
2440 #ifdef DELAY_SLOTS
2441 /* Run delay slot optimization. */
2442 static void
2443 rest_of_handle_delay_slots (tree decl, rtx insns)
2445 timevar_push (TV_DBR_SCHED);
2446 open_dump_file (DFI_dbr, decl);
2448 dbr_schedule (insns, rtl_dump_file);
2450 close_dump_file (DFI_dbr, print_rtl, insns);
2451 timevar_pop (TV_DBR_SCHED);
2453 ggc_collect ();
2455 #endif
2457 #ifdef STACK_REGS
2458 /* Convert register usage from flat register file usage to a stack
2459 register file. */
2460 static void
2461 rest_of_handle_stack_regs (tree decl, rtx insns)
2463 timevar_push (TV_REG_STACK);
2464 open_dump_file (DFI_stack, decl);
2466 if (reg_to_stack (insns, rtl_dump_file) && optimize)
2468 if (cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
2469 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0))
2470 && flag_reorder_blocks)
2472 reorder_basic_blocks ();
2473 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
2477 close_dump_file (DFI_stack, print_rtl_with_bb, insns);
2478 timevar_pop (TV_REG_STACK);
2480 ggc_collect ();
2482 #endif
2485 /* Machine independent reorg pass. */
2486 static void
2487 rest_of_handle_machine_reorg (tree decl, rtx insns)
2489 timevar_push (TV_MACH_DEP);
2490 open_dump_file (DFI_mach, decl);
2492 (*targetm.machine_dependent_reorg) ();
2494 close_dump_file (DFI_mach, print_rtl, insns);
2495 timevar_pop (TV_MACH_DEP);
2497 ggc_collect ();
2501 /* Run new register allocator. Return TRUE if we must exit
2502 rest_of_compilation upon return. */
2503 static bool
2504 rest_of_handle_new_regalloc (tree decl, rtx insns, int *rebuild_notes)
2506 int failure;
2508 delete_trivially_dead_insns (insns, max_reg_num ());
2509 reg_alloc ();
2511 timevar_pop (TV_LOCAL_ALLOC);
2512 if (dump_file[DFI_lreg].enabled)
2514 timevar_push (TV_DUMP);
2516 close_dump_file (DFI_lreg, NULL, NULL);
2517 timevar_pop (TV_DUMP);
2520 /* XXX clean up the whole mess to bring live info in shape again. */
2521 timevar_push (TV_GLOBAL_ALLOC);
2522 open_dump_file (DFI_greg, decl);
2524 build_insn_chain (insns);
2525 failure = reload (insns, 0);
2527 timevar_pop (TV_GLOBAL_ALLOC);
2529 if (dump_file[DFI_greg].enabled)
2531 timevar_push (TV_DUMP);
2533 dump_global_regs (rtl_dump_file);
2535 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2536 timevar_pop (TV_DUMP);
2539 if (failure)
2540 return true;
2542 reload_completed = 1;
2543 *rebuild_notes = 0;
2545 return false;
2548 /* Run old register allocator. Return TRUE if we must exit
2549 rest_of_compilation upon return. */
2550 static bool
2551 rest_of_handle_old_regalloc (tree decl, rtx insns, int *rebuild_notes)
2553 int failure;
2555 /* Allocate the reg_renumber array. */
2556 allocate_reg_info (max_regno, FALSE, TRUE);
2558 /* And the reg_equiv_memory_loc array. */
2559 reg_equiv_memory_loc = (rtx *) xcalloc (max_regno, sizeof (rtx));
2561 allocate_initial_values (reg_equiv_memory_loc);
2563 regclass (insns, max_reg_num (), rtl_dump_file);
2564 *rebuild_notes = local_alloc ();
2566 timevar_pop (TV_LOCAL_ALLOC);
2568 if (dump_file[DFI_lreg].enabled)
2570 timevar_push (TV_DUMP);
2572 dump_flow_info (rtl_dump_file);
2573 dump_local_alloc (rtl_dump_file);
2575 close_dump_file (DFI_lreg, print_rtl_with_bb, insns);
2576 timevar_pop (TV_DUMP);
2579 ggc_collect ();
2581 timevar_push (TV_GLOBAL_ALLOC);
2582 open_dump_file (DFI_greg, decl);
2584 /* If optimizing, allocate remaining pseudo-regs. Do the reload
2585 pass fixing up any insns that are invalid. */
2587 if (optimize)
2588 failure = global_alloc (rtl_dump_file);
2589 else
2591 build_insn_chain (insns);
2592 failure = reload (insns, 0);
2595 timevar_pop (TV_GLOBAL_ALLOC);
2597 if (dump_file[DFI_greg].enabled)
2599 timevar_push (TV_DUMP);
2601 dump_global_regs (rtl_dump_file);
2603 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2604 timevar_pop (TV_DUMP);
2607 return failure;
2610 /* Run the regrename and cprop passes. */
2611 static void
2612 rest_of_handle_regrename (tree decl, rtx insns)
2614 timevar_push (TV_RENAME_REGISTERS);
2615 open_dump_file (DFI_rnreg, decl);
2617 if (flag_rename_registers)
2618 regrename_optimize ();
2619 if (flag_cprop_registers)
2620 copyprop_hardreg_forward ();
2622 close_dump_file (DFI_rnreg, print_rtl_with_bb, insns);
2623 timevar_pop (TV_RENAME_REGISTERS);
2626 /* Reorder basic blocks. */
2627 static void
2628 rest_of_handle_reorder_blocks (tree decl, rtx insns)
2630 timevar_push (TV_REORDER_BLOCKS);
2631 open_dump_file (DFI_bbro, decl);
2633 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
2634 splitting possibly introduced more crossjumping opportunities. */
2635 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
2636 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
2638 if (flag_sched2_use_traces && flag_schedule_insns_after_reload)
2639 tracer ();
2640 if (flag_reorder_blocks)
2641 reorder_basic_blocks ();
2642 if (flag_reorder_blocks
2643 || (flag_sched2_use_traces && flag_schedule_insns_after_reload))
2644 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2646 close_dump_file (DFI_bbro, print_rtl_with_bb, insns);
2647 timevar_pop (TV_REORDER_BLOCKS);
2650 #ifdef INSN_SCHEDULING
2651 /* Run instruction scheduler. */
2652 static void
2653 rest_of_handle_sched (tree decl, rtx insns)
2655 timevar_push (TV_SCHED);
2657 /* Print function header into sched dump now
2658 because doing the sched analysis makes some of the dump. */
2659 if (optimize > 0 && flag_schedule_insns)
2661 open_dump_file (DFI_sched, decl);
2663 /* Do control and data sched analysis,
2664 and write some of the results to dump file. */
2666 schedule_insns (rtl_dump_file);
2668 close_dump_file (DFI_sched, print_rtl_with_bb, insns);
2670 timevar_pop (TV_SCHED);
2672 ggc_collect ();
2675 /* Run second scheduling pass after reload. */
2676 static void
2677 rest_of_handle_sched2 (tree decl, rtx insns)
2679 timevar_push (TV_SCHED2);
2680 open_dump_file (DFI_sched2, decl);
2682 /* Do control and data sched analysis again,
2683 and write some more of the results to dump file. */
2685 split_all_insns (1);
2687 if (flag_sched2_use_superblocks || flag_sched2_use_traces)
2689 schedule_ebbs (rtl_dump_file);
2690 /* No liveness updating code yet, but it should be easy to do.
2691 reg-stack recompute the liveness when needed for now. */
2692 count_or_remove_death_notes (NULL, 1);
2693 cleanup_cfg (CLEANUP_EXPENSIVE);
2695 else
2696 schedule_insns (rtl_dump_file);
2698 close_dump_file (DFI_sched2, print_rtl_with_bb, insns);
2699 timevar_pop (TV_SCHED2);
2701 ggc_collect ();
2703 #endif
2705 /* Register allocation pre-pass, to reduce number of moves necessary
2706 for two-address machines. */
2707 static void
2708 rest_of_handle_regmove (tree decl, rtx insns)
2710 timevar_push (TV_REGMOVE);
2711 open_dump_file (DFI_regmove, decl);
2713 regmove_optimize (insns, max_reg_num (), rtl_dump_file);
2715 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2716 close_dump_file (DFI_regmove, print_rtl_with_bb, insns);
2717 timevar_pop (TV_REGMOVE);
2719 ggc_collect ();
2722 /* Run tracer. */
2723 static void
2724 rest_of_handle_tracer (tree decl, rtx insns)
2726 timevar_push (TV_TRACER);
2727 open_dump_file (DFI_tracer, decl);
2728 if (rtl_dump_file)
2729 dump_flow_info (rtl_dump_file);
2730 tracer ();
2731 cleanup_cfg (CLEANUP_EXPENSIVE);
2732 reg_scan (insns, max_reg_num (), 0);
2733 close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ());
2734 timevar_pop (TV_TRACER);
2737 /* If-conversion and CFG cleanup. */
2738 static void
2739 rest_of_handle_if_conversion (tree decl, rtx insns)
2741 open_dump_file (DFI_ce1, decl);
2742 if (flag_if_conversion)
2744 timevar_push (TV_IFCVT);
2745 if (rtl_dump_file)
2746 dump_flow_info (rtl_dump_file);
2747 cleanup_cfg (CLEANUP_EXPENSIVE);
2748 reg_scan (insns, max_reg_num (), 0);
2749 if_convert (0);
2750 timevar_pop (TV_IFCVT);
2752 timevar_push (TV_JUMP);
2753 cleanup_cfg (CLEANUP_EXPENSIVE);
2754 reg_scan (insns, max_reg_num (), 0);
2755 timevar_pop (TV_JUMP);
2756 close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ());
2759 /* Rerun if-conversion, as combine may have simplified things enough
2760 to now meet sequence length restrictions. */
2761 static void
2762 rest_of_handle_if_after_combine (tree decl, rtx insns)
2764 timevar_push (TV_IFCVT);
2765 open_dump_file (DFI_ce2, decl);
2767 no_new_pseudos = 0;
2768 if_convert (1);
2769 no_new_pseudos = 1;
2771 close_dump_file (DFI_ce2, print_rtl_with_bb, insns);
2772 timevar_pop (TV_IFCVT);
2775 /* Do branch profiling and static profile estimation passes. */
2776 static void
2777 rest_of_handle_branch_prob (tree decl, rtx insns)
2779 struct loops loops;
2781 timevar_push (TV_BRANCH_PROB);
2782 open_dump_file (DFI_bp, decl);
2783 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
2784 branch_prob ();
2786 /* Discover and record the loop depth at the head of each basic
2787 block. The loop infrastructure does the real job for us. */
2788 flow_loops_find (&loops, LOOP_TREE);
2790 if (rtl_dump_file)
2791 flow_loops_dump (&loops, rtl_dump_file, NULL, 0);
2793 /* Estimate using heuristics if no profiling info is available. */
2794 if (flag_guess_branch_prob)
2795 estimate_probability (&loops);
2797 flow_loops_free (&loops);
2798 close_dump_file (DFI_bp, print_rtl_with_bb, insns);
2799 timevar_pop (TV_BRANCH_PROB);
2802 /* Do control and data flow analysis; write some of the results to the
2803 dump file. */
2804 static void
2805 rest_of_handle_cfg (tree decl, rtx insns)
2807 open_dump_file (DFI_cfg, decl);
2808 if (rtl_dump_file)
2809 dump_flow_info (rtl_dump_file);
2810 if (optimize)
2811 cleanup_cfg (CLEANUP_EXPENSIVE
2812 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2814 /* It may make more sense to mark constant functions after dead code is
2815 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
2816 may insert code making function non-constant, but we still must consider
2817 it as constant, otherwise -fbranch-probabilities will not read data back.
2819 life_analysis rarely eliminates modification of external memory.
2821 if (optimize)
2822 mark_constant_function ();
2824 close_dump_file (DFI_cfg, print_rtl_with_bb, insns);
2827 /* Purge addressofs. */
2828 static void
2829 rest_of_handle_addresof (tree decl, rtx insns)
2831 open_dump_file (DFI_addressof, decl);
2833 purge_addressof (insns);
2834 if (optimize)
2835 purge_all_dead_edges (0);
2836 reg_scan (insns, max_reg_num (), 1);
2838 close_dump_file (DFI_addressof, print_rtl, insns);
2841 /* We may have potential sibling or tail recursion sites. Select one
2842 (of possibly multiple) methods of performing the call. */
2843 static void
2844 rest_of_handle_sibling_calls (rtx insns)
2846 rtx insn;
2847 optimize_sibling_and_tail_recursive_calls ();
2849 /* Recompute the CFG as sibling optimization clobbers it randomly. */
2850 free_bb_for_insn ();
2851 find_exception_handler_labels ();
2852 rebuild_jump_labels (insns);
2853 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2855 /* There is pass ordering problem - we must lower NOTE_INSN_PREDICTION
2856 notes before simplifying cfg and we must do lowering after sibcall
2857 that unhides parts of RTL chain and cleans up the CFG.
2859 Until sibcall is replaced by tree-level optimizer, lets just
2860 sweep away the NOTE_INSN_PREDICTION notes that leaked out. */
2861 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2862 if (GET_CODE (insn) == NOTE
2863 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_PREDICTION)
2864 delete_insn (insn);
2866 close_dump_file (DFI_sibling, print_rtl, get_insns ());
2869 /* Perform jump bypassing and control flow optimizations. */
2870 static void
2871 rest_of_handle_jump_bypass (tree decl, rtx insns)
2873 timevar_push (TV_BYPASS);
2874 open_dump_file (DFI_bypass, decl);
2876 cleanup_cfg (CLEANUP_EXPENSIVE);
2878 if (bypass_jumps (rtl_dump_file))
2880 rebuild_jump_labels (insns);
2881 cleanup_cfg (CLEANUP_EXPENSIVE);
2882 delete_trivially_dead_insns (insns, max_reg_num ());
2885 close_dump_file (DFI_bypass, print_rtl_with_bb, insns);
2886 timevar_pop (TV_BYPASS);
2888 ggc_collect ();
2890 #ifdef ENABLE_CHECKING
2891 verify_flow_info ();
2892 #endif
2895 /* Handle inlining of functions in rest_of_compilation. Return TRUE
2896 if we must exit rest_of_compilation upon return. */
2897 static bool
2898 rest_of_handle_inlining (tree decl)
2900 rtx insns;
2901 int inlinable = 0;
2902 tree parent;
2903 const char *lose;
2905 /* If we are reconsidering an inline function at the end of
2906 compilation, skip the stuff for making it inline. */
2907 if (DECL_SAVED_INSNS (decl) != 0)
2908 return 0;
2910 /* If this is nested inside an inlined external function, pretend
2911 it was only declared. Since we cannot inline such functions,
2912 generating code for this one is not only not necessary but will
2913 confuse some debugging output writers. */
2914 for (parent = DECL_CONTEXT (current_function_decl);
2915 parent != NULL_TREE;
2916 parent = get_containing_scope (parent))
2917 if (TREE_CODE (parent) == FUNCTION_DECL
2918 && DECL_INLINE (parent) && DECL_EXTERNAL (parent))
2920 DECL_INITIAL (decl) = 0;
2921 return true;
2923 else if (TYPE_P (parent))
2924 /* A function in a local class should be treated normally. */
2925 break;
2927 /* If requested, consider whether to make this function inline. */
2928 if ((DECL_INLINE (decl) && !flag_no_inline)
2929 || flag_inline_functions)
2931 timevar_push (TV_INTEGRATION);
2932 lose = function_cannot_inline_p (decl);
2933 timevar_pop (TV_INTEGRATION);
2934 if (lose || ! optimize)
2936 if (warn_inline && DECL_INLINE (decl))
2937 warning_with_decl (decl, lose);
2938 DECL_ABSTRACT_ORIGIN (decl) = 0;
2939 /* Don't really compile an extern inline function.
2940 If we can't make it inline, pretend
2941 it was only declared. */
2942 if (DECL_EXTERNAL (decl))
2944 DECL_INITIAL (decl) = 0;
2945 return true;
2948 else {
2949 /* ??? Note that we used to just make it look like if
2950 the "inline" keyword was specified when we decide
2951 to inline it (because of -finline-functions).
2952 garloff@suse.de, 2002-04-24: Add another flag to
2953 actually record this piece of information. */
2954 if (!DECL_INLINE (decl))
2955 DID_INLINE_FUNC (decl) = 1;
2956 inlinable = DECL_INLINE (decl) = 1;
2960 insns = get_insns ();
2962 /* Dump the rtl code if we are dumping rtl. */
2964 if (open_dump_file (DFI_rtl, decl))
2966 if (DECL_SAVED_INSNS (decl))
2967 fprintf (rtl_dump_file, ";; (integrable)\n\n");
2968 close_dump_file (DFI_rtl, print_rtl, insns);
2971 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
2972 sorts of eh initialization. Delay this until after the
2973 initial rtl dump so that we can see the original nesting. */
2974 convert_from_eh_region_ranges ();
2976 /* If function is inline, and we don't yet know whether to
2977 compile it by itself, defer decision till end of compilation.
2978 wrapup_global_declarations will (indirectly) call
2979 rest_of_compilation again for those functions that need to
2980 be output. Also defer those functions that we are supposed
2981 to defer. */
2983 if (inlinable
2984 || (DECL_INLINE (decl)
2985 && flag_inline_functions
2986 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2987 && ! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
2988 && ! flag_keep_inline_functions)
2989 || DECL_EXTERNAL (decl))))
2990 DECL_DEFER_OUTPUT (decl) = 1;
2992 if (DECL_INLINE (decl))
2993 /* DWARF wants separate debugging info for abstract and
2994 concrete instances of all inline functions, including those
2995 declared inline but not inlined, and those inlined even
2996 though they weren't declared inline. Conveniently, that's
2997 what DECL_INLINE means at this point. */
2998 (*debug_hooks->deferred_inline_function) (decl);
3000 if (DECL_DEFER_OUTPUT (decl))
3002 /* If -Wreturn-type, we have to do a bit of compilation. We just
3003 want to call cleanup the cfg to figure out whether or not we can
3004 fall off the end of the function; we do the minimum amount of
3005 work necessary to make that safe. */
3006 if (warn_return_type)
3008 int saved_optimize = optimize;
3010 optimize = 0;
3011 rebuild_jump_labels (insns);
3012 find_exception_handler_labels ();
3013 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3014 cleanup_cfg (CLEANUP_PRE_SIBCALL | CLEANUP_PRE_LOOP);
3015 optimize = saved_optimize;
3017 /* CFG is no longer maintained up-to-date. */
3018 free_bb_for_insn ();
3021 set_nothrow_function_flags ();
3022 if (current_function_nothrow)
3023 /* Now we know that this can't throw; set the flag for the benefit
3024 of other functions later in this translation unit. */
3025 TREE_NOTHROW (current_function_decl) = 1;
3027 timevar_push (TV_INTEGRATION);
3028 save_for_inline (decl);
3029 timevar_pop (TV_INTEGRATION);
3030 DECL_SAVED_INSNS (decl)->inlinable = inlinable;
3031 return true;
3034 /* If specified extern inline but we aren't inlining it, we are
3035 done. This goes for anything that gets here with DECL_EXTERNAL
3036 set, not just things with DECL_INLINE. */
3037 return (bool) DECL_EXTERNAL (decl);
3040 /* Rest of compilation helper to convert the rtl to SSA form. */
3041 static rtx
3042 rest_of_handle_ssa (tree decl, rtx insns)
3044 timevar_push (TV_TO_SSA);
3045 open_dump_file (DFI_ssa, decl);
3047 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3048 convert_to_ssa ();
3050 close_dump_file (DFI_ssa, print_rtl_with_bb, insns);
3051 timevar_pop (TV_TO_SSA);
3053 /* Perform sparse conditional constant propagation, if requested. */
3054 if (flag_ssa_ccp)
3056 timevar_push (TV_SSA_CCP);
3057 open_dump_file (DFI_ssa_ccp, decl);
3059 ssa_const_prop ();
3061 close_dump_file (DFI_ssa_ccp, print_rtl_with_bb, get_insns ());
3062 timevar_pop (TV_SSA_CCP);
3065 /* It would be useful to cleanup the CFG at this point, but block
3066 merging and possibly other transformations might leave a PHI
3067 node in the middle of a basic block, which is a strict no-no. */
3069 /* The SSA implementation uses basic block numbers in its phi
3070 nodes. Thus, changing the control-flow graph or the basic
3071 blocks, e.g., calling find_basic_blocks () or cleanup_cfg (),
3072 may cause problems. */
3074 if (flag_ssa_dce)
3076 /* Remove dead code. */
3078 timevar_push (TV_SSA_DCE);
3079 open_dump_file (DFI_ssa_dce, decl);
3081 insns = get_insns ();
3082 ssa_eliminate_dead_code ();
3084 close_dump_file (DFI_ssa_dce, print_rtl_with_bb, insns);
3085 timevar_pop (TV_SSA_DCE);
3088 /* Convert from SSA form. */
3090 timevar_push (TV_FROM_SSA);
3091 open_dump_file (DFI_ussa, decl);
3093 convert_from_ssa ();
3094 /* New registers have been created. Rescan their usage. */
3095 reg_scan (insns, max_reg_num (), 1);
3097 close_dump_file (DFI_ussa, print_rtl_with_bb, insns);
3098 timevar_pop (TV_FROM_SSA);
3100 ggc_collect ();
3102 return insns;
3105 /* Try to identify useless null pointer tests and delete them. */
3106 static void
3107 rest_of_handle_null_pointer (tree decl, rtx insns)
3109 open_dump_file (DFI_null, decl);
3110 if (rtl_dump_file)
3111 dump_flow_info (rtl_dump_file);
3113 if (delete_null_pointer_checks (insns))
3114 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3116 close_dump_file (DFI_null, print_rtl_with_bb, insns);
3119 /* Try combining insns through substitution. */
3120 static void
3121 rest_of_handle_combine (tree decl, rtx insns)
3123 int rebuild_jump_labels_after_combine = 0;
3125 timevar_push (TV_COMBINE);
3126 open_dump_file (DFI_combine, decl);
3128 rebuild_jump_labels_after_combine
3129 = combine_instructions (insns, max_reg_num ());
3131 /* Combining insns may have turned an indirect jump into a
3132 direct jump. Rebuild the JUMP_LABEL fields of jumping
3133 instructions. */
3134 if (rebuild_jump_labels_after_combine)
3136 timevar_push (TV_JUMP);
3137 rebuild_jump_labels (insns);
3138 timevar_pop (TV_JUMP);
3140 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
3143 close_dump_file (DFI_combine, print_rtl_with_bb, insns);
3144 timevar_pop (TV_COMBINE);
3146 ggc_collect ();
3149 /* Perform life analysis. */
3150 static void
3151 rest_of_handle_life (tree decl, rtx insns)
3153 open_dump_file (DFI_life, decl);
3154 regclass_init ();
3156 #ifdef ENABLE_CHECKING
3157 verify_flow_info ();
3158 #endif
3159 life_analysis (insns, rtl_dump_file, PROP_FINAL);
3160 if (optimize)
3161 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_UPDATE_LIFE
3162 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
3163 timevar_pop (TV_FLOW);
3165 if (warn_uninitialized)
3167 uninitialized_vars_warning (DECL_INITIAL (decl));
3168 if (extra_warnings)
3169 setjmp_args_warning ();
3172 if (optimize)
3174 if (!flag_new_regalloc && initialize_uninitialized_subregs ())
3176 /* Insns were inserted, and possibly pseudos created, so
3177 things might look a bit different. */
3178 insns = get_insns ();
3179 allocate_reg_life_data ();
3180 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
3181 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
3185 no_new_pseudos = 1;
3187 close_dump_file (DFI_life, print_rtl_with_bb, insns);
3189 ggc_collect ();
3192 /* Perform common subexpression elimination. Nonzero value from
3193 `cse_main' means that jumps were simplified and some code may now
3194 be unreachable, so do jump optimization again. */
3195 static void
3196 rest_of_handle_cse (tree decl, rtx insns)
3198 int tem;
3200 open_dump_file (DFI_cse, decl);
3201 if (rtl_dump_file)
3202 dump_flow_info (rtl_dump_file);
3203 timevar_push (TV_CSE);
3205 reg_scan (insns, max_reg_num (), 1);
3207 tem = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
3208 if (tem)
3209 rebuild_jump_labels (insns);
3210 purge_all_dead_edges (0);
3212 delete_trivially_dead_insns (insns, max_reg_num ());
3214 /* If we are not running more CSE passes, then we are no longer
3215 expecting CSE to be run. But always rerun it in a cheap mode. */
3216 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
3218 if (tem || optimize > 1)
3219 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3220 /* Try to identify useless null pointer tests and delete them. */
3221 if (flag_delete_null_pointer_checks)
3223 timevar_push (TV_JUMP);
3225 if (delete_null_pointer_checks (insns))
3226 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3227 timevar_pop (TV_JUMP);
3230 /* The second pass of jump optimization is likely to have
3231 removed a bunch more instructions. */
3232 renumber_insns (rtl_dump_file);
3234 timevar_pop (TV_CSE);
3235 close_dump_file (DFI_cse, print_rtl_with_bb, insns);
3238 /* Run second CSE pass after loop optimizations. */
3239 static void
3240 rest_of_handle_cse2 (tree decl, rtx insns)
3242 int tem;
3244 timevar_push (TV_CSE2);
3245 open_dump_file (DFI_cse2, decl);
3246 if (rtl_dump_file)
3247 dump_flow_info (rtl_dump_file);
3248 /* CFG is no longer maintained up-to-date. */
3249 tem = cse_main (insns, max_reg_num (), 1, rtl_dump_file);
3250 purge_all_dead_edges (0);
3251 delete_trivially_dead_insns (insns, max_reg_num ());
3253 if (tem)
3255 timevar_push (TV_JUMP);
3256 rebuild_jump_labels (insns);
3257 cleanup_cfg (CLEANUP_EXPENSIVE);
3258 timevar_pop (TV_JUMP);
3260 reg_scan (insns, max_reg_num (), 0);
3261 close_dump_file (DFI_cse2, print_rtl_with_bb, insns);
3262 ggc_collect ();
3263 timevar_pop (TV_CSE2);
3266 /* Perform global cse. */
3267 static void
3268 rest_of_handle_gcse (tree decl, rtx insns)
3270 int save_csb, save_cfj;
3271 int tem2 = 0, tem;
3273 timevar_push (TV_GCSE);
3274 open_dump_file (DFI_gcse, decl);
3276 tem = gcse_main (insns, rtl_dump_file);
3277 rebuild_jump_labels (insns);
3278 delete_trivially_dead_insns (insns, max_reg_num ());
3280 save_csb = flag_cse_skip_blocks;
3281 save_cfj = flag_cse_follow_jumps;
3282 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
3284 /* Instantiate any remaining CONSTANT_P_RTX nodes. */
3285 if (current_function_calls_constant_p)
3286 purge_builtin_constant_p ();
3288 /* If -fexpensive-optimizations, re-run CSE to clean up things done
3289 by gcse. */
3290 if (flag_expensive_optimizations)
3292 timevar_push (TV_CSE);
3293 reg_scan (insns, max_reg_num (), 1);
3294 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
3295 purge_all_dead_edges (0);
3296 delete_trivially_dead_insns (insns, max_reg_num ());
3297 timevar_pop (TV_CSE);
3298 cse_not_expected = !flag_rerun_cse_after_loop;
3301 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
3302 things up. Then possibly re-run CSE again. */
3303 while (tem || tem2)
3305 tem = tem2 = 0;
3306 timevar_push (TV_JUMP);
3307 rebuild_jump_labels (insns);
3308 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3309 timevar_pop (TV_JUMP);
3311 if (flag_expensive_optimizations)
3313 timevar_push (TV_CSE);
3314 reg_scan (insns, max_reg_num (), 1);
3315 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
3316 purge_all_dead_edges (0);
3317 delete_trivially_dead_insns (insns, max_reg_num ());
3318 timevar_pop (TV_CSE);
3322 close_dump_file (DFI_gcse, print_rtl_with_bb, insns);
3323 timevar_pop (TV_GCSE);
3325 ggc_collect ();
3326 flag_cse_skip_blocks = save_csb;
3327 flag_cse_follow_jumps = save_cfj;
3328 #ifdef ENABLE_CHECKING
3329 verify_flow_info ();
3330 #endif
3333 /* Move constant computations out of loops. */
3334 static void
3335 rest_of_handle_loop_optimize (tree decl, rtx insns)
3337 int do_unroll, do_prefetch;
3339 timevar_push (TV_LOOP);
3340 delete_dead_jumptables ();
3341 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3342 open_dump_file (DFI_loop, decl);
3344 /* CFG is no longer maintained up-to-date. */
3345 free_bb_for_insn ();
3347 if (flag_unroll_loops)
3348 do_unroll = 0; /* Having two unrollers is useless. */
3349 else
3350 do_unroll = flag_old_unroll_loops ? LOOP_UNROLL : LOOP_AUTO_UNROLL;
3351 do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
3353 if (flag_rerun_loop_opt)
3355 cleanup_barriers ();
3357 /* We only want to perform unrolling once. */
3358 loop_optimize (insns, rtl_dump_file, do_unroll);
3359 do_unroll = 0;
3361 /* The first call to loop_optimize makes some instructions
3362 trivially dead. We delete those instructions now in the
3363 hope that doing so will make the heuristics in loop work
3364 better and possibly speed up compilation. */
3365 delete_trivially_dead_insns (insns, max_reg_num ());
3367 /* The regscan pass is currently necessary as the alias
3368 analysis code depends on this information. */
3369 reg_scan (insns, max_reg_num (), 1);
3371 cleanup_barriers ();
3372 loop_optimize (insns, rtl_dump_file, do_unroll | LOOP_BCT | do_prefetch);
3374 /* Loop can create trivially dead instructions. */
3375 delete_trivially_dead_insns (insns, max_reg_num ());
3376 close_dump_file (DFI_loop, print_rtl, insns);
3377 timevar_pop (TV_LOOP);
3378 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3380 ggc_collect ();
3383 /* Perform loop optimalizations. It might be better to do them a bit
3384 sooner, but we want the profile feedback to work more
3385 efficiently. */
3386 static void
3387 rest_of_handle_loop2 (tree decl, rtx insns)
3389 struct loops *loops;
3390 timevar_push (TV_LOOP);
3391 open_dump_file (DFI_loop2, decl);
3392 if (rtl_dump_file)
3393 dump_flow_info (rtl_dump_file);
3395 loops = loop_optimizer_init (rtl_dump_file);
3397 if (loops)
3399 /* The optimalizations: */
3400 if (flag_unswitch_loops)
3401 unswitch_loops (loops);
3403 if (flag_peel_loops || flag_unroll_loops)
3404 unroll_and_peel_loops (loops,
3405 (flag_peel_loops ? UAP_PEEL : 0) |
3406 (flag_unroll_loops ? UAP_UNROLL : 0) |
3407 (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0));
3409 loop_optimizer_finalize (loops, rtl_dump_file);
3412 cleanup_cfg (CLEANUP_EXPENSIVE);
3413 delete_trivially_dead_insns (insns, max_reg_num ());
3414 reg_scan (insns, max_reg_num (), 0);
3415 if (rtl_dump_file)
3416 dump_flow_info (rtl_dump_file);
3417 close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
3418 timevar_pop (TV_LOOP);
3419 ggc_collect ();
3422 /* This is called from finish_function (within langhooks.parse_file)
3423 after each top-level definition is parsed.
3424 It is supposed to compile that function or variable
3425 and output the assembler code for it.
3426 After we return, the tree storage is freed. */
3428 void
3429 rest_of_compilation (tree decl)
3431 rtx insns;
3432 int rebuild_label_notes_after_reload;
3434 timevar_push (TV_REST_OF_COMPILATION);
3436 /* Register rtl specific functions for cfg. */
3437 rtl_register_cfg_hooks ();
3439 /* Now that we're out of the frontend, we shouldn't have any more
3440 CONCATs anywhere. */
3441 generating_concat_p = 0;
3443 /* When processing delayed functions, prepare_function_start() won't
3444 have been run to re-initialize it. */
3445 cse_not_expected = ! optimize;
3447 /* First, make sure that NOTE_BLOCK is set correctly for each
3448 NOTE_INSN_BLOCK_BEG/NOTE_INSN_BLOCK_END note. */
3449 if (!cfun->x_whole_function_mode_p)
3450 identify_blocks ();
3452 /* In function-at-a-time mode, we do not attempt to keep the BLOCK
3453 tree in sensible shape. So, we just recalculate it here. */
3454 if (cfun->x_whole_function_mode_p)
3455 reorder_blocks ();
3457 init_flow ();
3459 if (rest_of_handle_inlining (decl))
3460 goto exit_rest_of_compilation;
3462 /* If we're emitting a nested function, make sure its parent gets
3463 emitted as well. Doing otherwise confuses debug info. */
3465 tree parent;
3466 for (parent = DECL_CONTEXT (current_function_decl);
3467 parent != NULL_TREE;
3468 parent = get_containing_scope (parent))
3469 if (TREE_CODE (parent) == FUNCTION_DECL)
3470 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
3473 /* We are now committed to emitting code for this function. Do any
3474 preparation, such as emitting abstract debug info for the inline
3475 before it gets mangled by optimization. */
3476 if (DECL_INLINE (decl))
3477 (*debug_hooks->outlining_inline_function) (decl);
3479 /* Remove any notes we don't need. That will make iterating
3480 over the instruction sequence faster, and allow the garbage
3481 collector to reclaim the memory used by the notes. */
3482 remove_unnecessary_notes ();
3483 reorder_blocks ();
3485 ggc_collect ();
3487 /* Initialize some variables used by the optimizers. */
3488 init_function_for_compilation ();
3490 if (! DECL_DEFER_OUTPUT (decl))
3491 TREE_ASM_WRITTEN (decl) = 1;
3493 /* Now that integrate will no longer see our rtl, we need not
3494 distinguish between the return value of this function and the
3495 return value of called functions. Also, we can remove all SETs
3496 of subregs of hard registers; they are only here because of
3497 integrate. Also, we can now initialize pseudos intended to
3498 carry magic hard reg data throughout the function. */
3499 rtx_equal_function_value_matters = 0;
3500 purge_hard_subreg_sets (get_insns ());
3502 /* Early return if there were errors. We can run afoul of our
3503 consistency checks, and there's not really much point in fixing them.
3504 Don't return yet if -Wreturn-type; we need to do cleanup_cfg. */
3505 if (((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
3506 || errorcount || sorrycount)
3507 goto exit_rest_of_compilation;
3509 timevar_push (TV_JUMP);
3510 open_dump_file (DFI_sibling, decl);
3511 insns = get_insns ();
3512 rebuild_jump_labels (insns);
3513 find_exception_handler_labels ();
3514 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3516 delete_unreachable_blocks ();
3518 /* We have to issue these warnings now already, because CFG cleanups
3519 further down may destroy the required information. */
3520 check_function_return_warnings ();
3522 /* Turn NOTE_INSN_PREDICTIONs into branch predictions. */
3523 if (flag_guess_branch_prob)
3525 timevar_push (TV_BRANCH_PROB);
3526 note_prediction_to_br_prob ();
3527 timevar_pop (TV_BRANCH_PROB);
3530 if (flag_optimize_sibling_calls)
3531 rest_of_handle_sibling_calls (insns);
3533 timevar_pop (TV_JUMP);
3535 insn_locators_initialize ();
3536 /* Complete generation of exception handling code. */
3537 if (doing_eh (0))
3539 timevar_push (TV_JUMP);
3540 open_dump_file (DFI_eh, decl);
3542 finish_eh_generation ();
3544 close_dump_file (DFI_eh, print_rtl, get_insns ());
3545 timevar_pop (TV_JUMP);
3548 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
3549 generation, which might create new sets. */
3550 emit_initial_value_sets ();
3552 #ifdef FINALIZE_PIC
3553 /* If we are doing position-independent code generation, now
3554 is the time to output special prologues and epilogues.
3555 We do not want to do this earlier, because it just clutters
3556 up inline functions with meaningless insns. */
3557 if (flag_pic)
3558 FINALIZE_PIC;
3559 #endif
3561 insns = get_insns ();
3563 /* Copy any shared structure that should not be shared. */
3564 unshare_all_rtl (current_function_decl, insns);
3566 #ifdef SETJMP_VIA_SAVE_AREA
3567 /* This must be performed before virtual register instantiation.
3568 Please be aware the everything in the compiler that can look
3569 at the RTL up to this point must understand that REG_SAVE_AREA
3570 is just like a use of the REG contained inside. */
3571 if (current_function_calls_alloca)
3572 optimize_save_area_alloca (insns);
3573 #endif
3575 /* Instantiate all virtual registers. */
3576 instantiate_virtual_regs (current_function_decl, insns);
3578 open_dump_file (DFI_jump, decl);
3580 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3581 are initialized and to compute whether control can drop off the end
3582 of the function. */
3584 timevar_push (TV_JUMP);
3585 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
3586 before jump optimization switches branch directions. */
3587 if (flag_guess_branch_prob)
3588 expected_value_to_br_prob ();
3590 reg_scan (insns, max_reg_num (), 0);
3591 rebuild_jump_labels (insns);
3592 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3593 delete_trivially_dead_insns (insns, max_reg_num ());
3594 if (rtl_dump_file)
3595 dump_flow_info (rtl_dump_file);
3596 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
3597 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
3599 if (optimize)
3601 free_bb_for_insn ();
3602 copy_loop_headers (insns);
3603 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3605 purge_line_number_notes (insns);
3607 timevar_pop (TV_JUMP);
3608 close_dump_file (DFI_jump, print_rtl, insns);
3610 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
3611 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
3612 goto exit_rest_of_compilation;
3614 /* Long term, this should probably move before the jump optimizer too,
3615 but I didn't want to disturb the rtl_dump_and_exit and related
3616 stuff at this time. */
3617 if (optimize > 0 && flag_ssa)
3618 insns = rest_of_handle_ssa (decl, insns);
3620 timevar_push (TV_JUMP);
3622 if (optimize)
3623 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3625 if (flag_delete_null_pointer_checks)
3626 rest_of_handle_null_pointer (decl, insns);
3628 /* Jump optimization, and the removal of NULL pointer checks, may
3629 have reduced the number of instructions substantially. CSE, and
3630 future passes, allocate arrays whose dimensions involve the
3631 maximum instruction UID, so if we can reduce the maximum UID
3632 we'll save big on memory. */
3633 renumber_insns (rtl_dump_file);
3634 timevar_pop (TV_JUMP);
3636 close_dump_file (DFI_jump, print_rtl_with_bb, insns);
3638 ggc_collect ();
3640 if (optimize > 0)
3641 rest_of_handle_cse (decl, insns);
3643 rest_of_handle_addresof (decl, insns);
3645 ggc_collect ();
3647 if (optimize > 0)
3649 if (flag_gcse)
3650 rest_of_handle_gcse (decl, insns);
3652 if (flag_loop_optimize)
3653 rest_of_handle_loop_optimize (decl, insns);
3655 if (flag_gcse)
3656 rest_of_handle_jump_bypass (decl, insns);
3659 timevar_push (TV_FLOW);
3661 rest_of_handle_cfg (decl, insns);
3663 if (optimize > 0
3664 || profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
3665 rest_of_handle_branch_prob (decl, insns);
3667 if (optimize > 0)
3668 rest_of_handle_if_conversion (decl, insns);
3670 if (flag_tracer)
3671 rest_of_handle_tracer (decl, insns);
3673 if (optimize > 0
3674 && (flag_unswitch_loops
3675 || flag_peel_loops
3676 || flag_unroll_loops))
3677 rest_of_handle_loop2 (decl, insns);
3679 if (flag_rerun_cse_after_loop)
3680 rest_of_handle_cse2 (decl, insns);
3682 cse_not_expected = 1;
3684 rest_of_handle_life (decl, insns);
3686 if (optimize > 0)
3687 rest_of_handle_combine (decl, insns);
3689 if (flag_if_conversion)
3690 rest_of_handle_if_after_combine (decl, insns);
3692 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
3693 rest_of_handle_regmove (decl, insns);
3695 /* Do unconditional splitting before register allocation to allow machine
3696 description to add extra information not needed previously. */
3697 split_all_insns (1);
3699 #ifdef OPTIMIZE_MODE_SWITCHING
3700 timevar_push (TV_MODE_SWITCH);
3702 no_new_pseudos = 0;
3703 optimize_mode_switching (NULL);
3704 no_new_pseudos = 1;
3706 timevar_pop (TV_MODE_SWITCH);
3707 #endif
3709 /* Any of the several passes since flow1 will have munged register
3710 lifetime data a bit. We need it to be up to date for scheduling
3711 (see handling of reg_known_equiv in init_alias_analysis). */
3712 recompute_reg_usage (insns, !optimize_size);
3714 #ifdef INSN_SCHEDULING
3715 rest_of_handle_sched (decl, insns);
3716 #endif
3718 /* Determine if the current function is a leaf before running reload
3719 since this can impact optimizations done by the prologue and
3720 epilogue thus changing register elimination offsets. */
3721 current_function_is_leaf = leaf_function_p ();
3723 timevar_push (TV_LOCAL_ALLOC);
3724 open_dump_file (DFI_lreg, decl);
3726 if (flag_new_regalloc)
3728 if (rest_of_handle_new_regalloc (decl, insns,
3729 &rebuild_label_notes_after_reload))
3730 goto exit_rest_of_compilation;
3732 else
3734 if (rest_of_handle_old_regalloc (decl, insns,
3735 &rebuild_label_notes_after_reload))
3736 goto exit_rest_of_compilation;
3739 ggc_collect ();
3741 open_dump_file (DFI_postreload, decl);
3743 /* Do a very simple CSE pass over just the hard registers. */
3744 if (optimize > 0)
3746 timevar_push (TV_RELOAD_CSE_REGS);
3747 reload_cse_regs (insns);
3748 timevar_pop (TV_RELOAD_CSE_REGS);
3751 /* Register allocation and reloading may have turned an indirect jump into
3752 a direct jump. If so, we must rebuild the JUMP_LABEL fields of
3753 jumping instructions. */
3754 if (rebuild_label_notes_after_reload)
3756 timevar_push (TV_JUMP);
3758 rebuild_jump_labels (insns);
3759 purge_all_dead_edges (0);
3761 timevar_pop (TV_JUMP);
3764 close_dump_file (DFI_postreload, print_rtl_with_bb, insns);
3766 /* Re-create the death notes which were deleted during reload. */
3767 timevar_push (TV_FLOW2);
3768 open_dump_file (DFI_flow2, decl);
3770 #ifdef ENABLE_CHECKING
3771 verify_flow_info ();
3772 #endif
3774 /* If optimizing, then go ahead and split insns now. */
3775 #ifndef STACK_REGS
3776 if (optimize > 0)
3777 #endif
3778 split_all_insns (0);
3780 if (flag_branch_target_load_optimize)
3782 open_dump_file (DFI_branch_target_load, decl);
3784 branch_target_load_optimize (insns, false);
3786 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3788 ggc_collect ();
3791 if (optimize)
3792 cleanup_cfg (CLEANUP_EXPENSIVE);
3794 /* On some machines, the prologue and epilogue code, or parts thereof,
3795 can be represented as RTL. Doing so lets us schedule insns between
3796 it and the rest of the code and also allows delayed branch
3797 scheduling to operate in the epilogue. */
3798 thread_prologue_and_epilogue_insns (insns);
3799 epilogue_completed = 1;
3801 if (optimize)
3803 life_analysis (insns, rtl_dump_file, PROP_FINAL);
3804 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
3805 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
3807 /* This is kind of a heuristic. We need to run combine_stack_adjustments
3808 even for machines with possibly nonzero RETURN_POPS_ARGS
3809 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
3810 push instructions will have popping returns. */
3811 #ifndef PUSH_ROUNDING
3812 if (!ACCUMULATE_OUTGOING_ARGS)
3813 #endif
3814 combine_stack_adjustments ();
3816 ggc_collect ();
3819 flow2_completed = 1;
3821 close_dump_file (DFI_flow2, print_rtl_with_bb, insns);
3822 timevar_pop (TV_FLOW2);
3824 #ifdef HAVE_peephole2
3825 if (optimize > 0 && flag_peephole2)
3827 timevar_push (TV_PEEPHOLE2);
3828 open_dump_file (DFI_peephole2, decl);
3830 peephole2_optimize (rtl_dump_file);
3832 close_dump_file (DFI_peephole2, print_rtl_with_bb, insns);
3833 timevar_pop (TV_PEEPHOLE2);
3835 #endif
3837 if (optimize > 0)
3839 if (flag_rename_registers || flag_cprop_registers)
3840 rest_of_handle_regrename (decl, insns);
3842 rest_of_handle_reorder_blocks (decl, insns);
3845 if (flag_if_conversion2)
3847 timevar_push (TV_IFCVT2);
3848 open_dump_file (DFI_ce3, decl);
3850 if_convert (1);
3852 close_dump_file (DFI_ce3, print_rtl_with_bb, insns);
3853 timevar_pop (TV_IFCVT2);
3856 if (flag_branch_target_load_optimize2)
3858 /* Leave this a warning for now so that it is possible to experiment
3859 with running this pass twice. In 3.6, we should either make this
3860 an error, or use separate dump files. */
3861 if (flag_branch_target_load_optimize)
3862 warning ("branch target register load optimization is not intended "
3863 "to be run twice");
3865 open_dump_file (DFI_branch_target_load, decl);
3867 branch_target_load_optimize (insns, true);
3869 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3871 ggc_collect ();
3874 #ifdef INSN_SCHEDULING
3875 if (optimize > 0 && flag_schedule_insns_after_reload)
3876 rest_of_handle_sched2 (decl, insns);
3877 #endif
3879 #ifdef LEAF_REGISTERS
3880 current_function_uses_only_leaf_regs
3881 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
3882 #endif
3884 #ifdef STACK_REGS
3885 rest_of_handle_stack_regs (decl, insns);
3886 #endif
3888 compute_alignments ();
3890 /* CFG is no longer maintained up-to-date. */
3891 free_bb_for_insn ();
3893 if (targetm.machine_dependent_reorg != 0)
3894 rest_of_handle_machine_reorg (decl, insns);
3896 purge_line_number_notes (insns);
3897 cleanup_barriers ();
3899 #ifdef DELAY_SLOTS
3900 if (optimize > 0 && flag_delayed_branch)
3901 rest_of_handle_delay_slots (decl, insns);
3902 #endif
3904 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3905 timevar_push (TV_SHORTEN_BRANCH);
3906 split_all_insns_noflow ();
3907 timevar_pop (TV_SHORTEN_BRANCH);
3908 #endif
3910 convert_to_eh_region_ranges ();
3912 /* Shorten branches. */
3913 timevar_push (TV_SHORTEN_BRANCH);
3914 shorten_branches (get_insns ());
3915 timevar_pop (TV_SHORTEN_BRANCH);
3917 set_nothrow_function_flags ();
3918 if (current_function_nothrow)
3919 /* Now we know that this can't throw; set the flag for the benefit
3920 of other functions later in this translation unit. */
3921 TREE_NOTHROW (current_function_decl) = 1;
3923 rest_of_handle_final (decl, insns);
3925 /* Write DBX symbols if requested. */
3927 /* Note that for those inline functions where we don't initially
3928 know for certain that we will be generating an out-of-line copy,
3929 the first invocation of this routine (rest_of_compilation) will
3930 skip over this code by doing a `goto exit_rest_of_compilation;'.
3931 Later on, wrapup_global_declarations will (indirectly) call
3932 rest_of_compilation again for those inline functions that need
3933 to have out-of-line copies generated. During that call, we
3934 *will* be routed past here. */
3936 timevar_push (TV_SYMOUT);
3937 (*debug_hooks->function_decl) (decl);
3938 timevar_pop (TV_SYMOUT);
3940 exit_rest_of_compilation:
3942 coverage_end_function ();
3944 /* In case the function was not output,
3945 don't leave any temporary anonymous types
3946 queued up for sdb output. */
3947 #ifdef SDB_DEBUGGING_INFO
3948 if (write_symbols == SDB_DEBUG)
3949 sdbout_types (NULL_TREE);
3950 #endif
3952 reload_completed = 0;
3953 epilogue_completed = 0;
3954 flow2_completed = 0;
3955 no_new_pseudos = 0;
3957 timevar_push (TV_FINAL);
3959 /* Clear out the insn_length contents now that they are no
3960 longer valid. */
3961 init_insn_lengths ();
3963 /* Show no temporary slots allocated. */
3964 init_temp_slots ();
3966 free_basic_block_vars (0);
3967 free_bb_for_insn ();
3969 timevar_pop (TV_FINAL);
3971 if ((*targetm.binds_local_p) (current_function_decl))
3973 int pref = cfun->preferred_stack_boundary;
3974 if (cfun->recursive_call_emit
3975 && cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
3976 pref = cfun->stack_alignment_needed;
3977 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
3978 = pref;
3981 /* Make sure volatile mem refs aren't considered valid operands for
3982 arithmetic insns. We must call this here if this is a nested inline
3983 function, since the above code leaves us in the init_recog state
3984 (from final.c), and the function context push/pop code does not
3985 save/restore volatile_ok.
3987 ??? Maybe it isn't necessary for expand_start_function to call this
3988 anymore if we do it here? */
3990 init_recog_no_volatile ();
3992 /* We're done with this function. Free up memory if we can. */
3993 free_after_parsing (cfun);
3994 if (! DECL_DEFER_OUTPUT (decl))
3996 free_after_compilation (cfun);
3998 /* Clear integrate.c's pointer to the cfun structure we just
3999 destroyed. */
4000 DECL_SAVED_INSNS (decl) = 0;
4002 cfun = 0;
4004 ggc_collect ();
4006 timevar_pop (TV_REST_OF_COMPILATION);
4009 /* Display help for generic options. */
4010 void
4011 display_help (void)
4013 int undoc;
4014 unsigned long i;
4015 const char *lang;
4017 printf (_(" -ffixed-<register> Mark <register> as being unavailable to the compiler\n"));
4018 printf (_(" -fcall-used-<register> Mark <register> as being corrupted by function calls\n"));
4019 printf (_(" -fcall-saved-<register> Mark <register> as being preserved across functions\n"));
4020 printf (_(" -finline-limit=<number> Limits the size of inlined functions to <number>\n"));
4021 printf (_(" -fmessage-length=<number> Limits diagnostics messages lengths to <number> characters per line. 0 suppresses line-wrapping\n"));
4022 printf (_(" -fdiagnostics-show-location=[once | every-line] Indicates how often source location information should be emitted, as prefix, at the beginning of diagnostics when line-wrapping\n"));
4023 printf (_(" -ftls-model=[global-dynamic | local-dynamic | initial-exec | local-exec] Indicates the default thread-local storage code generation model\n"));
4024 printf (_(" -fstack-limit-register=<register> Trap if the stack goes past <register>\n"));
4025 printf (_(" -fstack-limit-symbol=<name> Trap if the stack goes past symbol <name>\n"));
4026 printf (_(" -frandom-seed=<string> Make compile reproducible using <string>\n"));
4029 for (i = ARRAY_SIZE (f_options); i--;)
4031 const char *description = f_options[i].description;
4033 if (description != NULL && *description != 0)
4034 printf (" -f%-21s %s\n",
4035 f_options[i].string, _(description));
4038 printf (_(" -O[number] Set optimization level to [number]\n"));
4039 printf (_(" -Os Optimize for space rather than speed\n"));
4040 for (i = LAST_PARAM; i--;)
4042 const char *description = compiler_params[i].help;
4043 const int length = 21 - strlen (compiler_params[i].option);
4045 if (description != NULL && *description != 0)
4046 printf (" --param %s=<value>%.*s%s\n",
4047 compiler_params[i].option,
4048 length > 0 ? length : 1, " ",
4049 _(description));
4051 printf (_(" -pedantic Issue warnings needed by strict compliance to ISO C\n"));
4052 printf (_(" -pedantic-errors Like -pedantic except that errors are produced\n"));
4053 printf (_(" -w Suppress warnings\n"));
4055 for (i = ARRAY_SIZE (W_options); i--;)
4057 const char *description = W_options[i].description;
4059 if (description != NULL && *description != 0)
4060 printf (" -W%-21s %s\n",
4061 W_options[i].string, _(description));
4064 printf (_(" -Wextra Print extra (possibly unwanted) warnings\n"));
4065 printf (_(" -Wunused Enable unused warnings\n"));
4066 printf (_(" -Wlarger-than-<number> Warn if an object is larger than <number> bytes\n"));
4067 printf (_(" -p Enable function profiling\n"));
4068 printf (_(" -o <file> Place output into <file> \n"));
4069 printf (_("\
4070 -G <number> Put global and static data smaller than <number>\n\
4071 bytes into a special section (on some targets)\n"));
4073 for (i = ARRAY_SIZE (debug_args); i--;)
4075 if (debug_args[i].description != NULL)
4076 printf (" -g%-21s %s\n",
4077 debug_args[i].arg, _(debug_args[i].description));
4080 printf (_(" -aux-info <file> Emit declaration info into <file>\n"));
4081 printf (_(" -quiet Do not display functions compiled or elapsed time\n"));
4082 printf (_(" -version Display the compiler's version\n"));
4083 printf (_(" -d[letters] Enable dumps from specific passes of the compiler\n"));
4084 printf (_(" -dumpbase <file> Base name to be used for dumps from specific passes\n"));
4085 #if defined INSN_SCHEDULING
4086 printf (_(" -fsched-verbose=<number> Set the verbosity level of the scheduler\n"));
4087 #endif
4088 printf (_(" --help Display this information\n"));
4090 undoc = 0;
4091 lang = "language";
4093 /* Display descriptions of language specific options.
4094 If there is no description, note that there is an undocumented option.
4095 If the description is empty, do not display anything. (This allows
4096 options to be deliberately undocumented, for whatever reason).
4097 If the option string is missing, then this is a marker, indicating
4098 that the description string is in fact the name of a language, whose
4099 language specific options are to follow. */
4101 if (ARRAY_SIZE (documented_lang_options) > 1)
4103 printf (_("\nLanguage specific options:\n"));
4105 for (i = 0; i < ARRAY_SIZE (documented_lang_options); i++)
4107 const char *description = documented_lang_options[i].description;
4108 const char *option = documented_lang_options[i].option;
4110 if (description == NULL)
4112 undoc = 1;
4114 if (extra_warnings)
4115 printf (_(" %-23.23s [undocumented]\n"), option);
4117 else if (*description == 0)
4118 continue;
4119 else if (option == NULL)
4121 if (undoc)
4122 printf
4123 (_("\nThere are undocumented %s specific options as well.\n"),
4124 lang);
4125 undoc = 0;
4127 printf (_("\n Options for %s:\n"), description);
4129 lang = description;
4131 else
4132 printf (" %-23.23s %s\n", option, _(description));
4136 if (undoc)
4137 printf (_("\nThere are undocumented %s specific options as well.\n"),
4138 lang);
4140 display_target_options ();
4143 /* Display help for target options. */
4144 void
4145 display_target_options (void)
4147 int undoc, i;
4148 static bool displayed = false;
4150 /* Avoid double printing for --help --target-help. */
4151 if (displayed)
4152 return;
4154 displayed = true;
4156 if (ARRAY_SIZE (target_switches) > 1
4157 #ifdef TARGET_OPTIONS
4158 || ARRAY_SIZE (target_options) > 1
4159 #endif
4162 int doc = 0;
4164 undoc = 0;
4166 printf (_("\nTarget specific options:\n"));
4168 for (i = ARRAY_SIZE (target_switches); i--;)
4170 const char *option = target_switches[i].name;
4171 const char *description = target_switches[i].description;
4173 if (option == NULL || *option == 0)
4174 continue;
4175 else if (description == NULL)
4177 undoc = 1;
4179 if (extra_warnings)
4180 printf (_(" -m%-23.23s [undocumented]\n"), option);
4182 else if (*description != 0)
4183 doc += printf (" -m%-23.23s %s\n", option, _(description));
4186 #ifdef TARGET_OPTIONS
4187 for (i = ARRAY_SIZE (target_options); i--;)
4189 const char *option = target_options[i].prefix;
4190 const char *description = target_options[i].description;
4192 if (option == NULL || *option == 0)
4193 continue;
4194 else if (description == NULL)
4196 undoc = 1;
4198 if (extra_warnings)
4199 printf (_(" -m%-23.23s [undocumented]\n"), option);
4201 else if (*description != 0)
4202 doc += printf (" -m%-23.23s %s\n", option, _(description));
4204 #endif
4205 if (undoc)
4207 if (doc)
4208 printf (_("\nThere are undocumented target specific options as well.\n"));
4209 else
4210 printf (_(" They exist, but they are not documented.\n"));
4215 /* Parse a -d... command line switch. */
4217 void
4218 decode_d_option (const char *arg)
4220 int i, c, matched;
4222 while (*arg)
4223 switch (c = *arg++)
4225 case 'a':
4226 for (i = 0; i < (int) DFI_MAX; ++i)
4227 dump_file[i].enabled = 1;
4228 break;
4229 case 'A':
4230 flag_debug_asm = 1;
4231 break;
4232 case 'p':
4233 flag_print_asm_name = 1;
4234 break;
4235 case 'P':
4236 flag_dump_rtl_in_asm = 1;
4237 flag_print_asm_name = 1;
4238 break;
4239 case 'v':
4240 graph_dump_format = vcg;
4241 break;
4242 case 'x':
4243 rtl_dump_and_exit = 1;
4244 break;
4245 case 'y':
4246 set_yydebug = 1;
4247 break;
4248 case 'D': /* These are handled by the preprocessor. */
4249 case 'I':
4250 break;
4251 case 'H':
4252 setup_core_dumping();
4253 break;
4255 default:
4256 matched = 0;
4257 for (i = 0; i < (int) DFI_MAX; ++i)
4258 if (c == dump_file[i].debug_switch)
4260 dump_file[i].enabled = 1;
4261 matched = 1;
4264 if (! matched)
4265 warning ("unrecognized gcc debugging option: %c", c);
4266 break;
4270 /* Parse a -f... command line switch. ARG is the value after the -f.
4271 It is safe to access 'ARG - 2' to generate the full switch name.
4272 Return the number of strings consumed. */
4274 static int
4275 decode_f_option (const char *arg)
4277 int j;
4278 const char *option_value = NULL;
4280 /* Search for the option in the table of binary f options. */
4281 for (j = ARRAY_SIZE (f_options); j--;)
4283 if (!strcmp (arg, f_options[j].string))
4285 *f_options[j].variable = f_options[j].on_value;
4286 return 1;
4289 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-'
4290 && ! strcmp (arg + 3, f_options[j].string))
4292 *f_options[j].variable = ! f_options[j].on_value;
4293 return 1;
4297 if (!strcmp (arg, "fast-math"))
4298 set_fast_math_flags (1);
4299 else if (!strcmp (arg, "no-fast-math"))
4300 set_fast_math_flags (0);
4301 else if ((option_value = skip_leading_substring (arg, "inline-limit-"))
4302 || (option_value = skip_leading_substring (arg, "inline-limit=")))
4304 int val =
4305 read_integral_parameter (option_value, arg - 2,
4306 MAX_INLINE_INSNS);
4307 set_param_value ("max-inline-insns", val);
4308 set_param_value ("max-inline-insns-single", val/2);
4309 set_param_value ("max-inline-insns-auto", val/2);
4310 set_param_value ("max-inline-insns-rtl", val);
4311 if (val/4 < MIN_INLINE_INSNS)
4313 if (val/4 > 10)
4314 set_param_value ("min-inline-insns", val/4);
4315 else
4316 set_param_value ("min-inline-insns", 10);
4319 else if ((option_value = skip_leading_substring (arg, "tls-model=")))
4321 if (strcmp (option_value, "global-dynamic") == 0)
4322 flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
4323 else if (strcmp (option_value, "local-dynamic") == 0)
4324 flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
4325 else if (strcmp (option_value, "initial-exec") == 0)
4326 flag_tls_default = TLS_MODEL_INITIAL_EXEC;
4327 else if (strcmp (option_value, "local-exec") == 0)
4328 flag_tls_default = TLS_MODEL_LOCAL_EXEC;
4329 else
4330 warning ("`%s': unknown tls-model option", arg - 2);
4332 #ifdef INSN_SCHEDULING
4333 else if ((option_value = skip_leading_substring (arg, "sched-verbose=")))
4334 fix_sched_param ("verbose", option_value);
4335 #endif
4336 else if ((option_value = skip_leading_substring (arg, "fixed-")))
4337 fix_register (option_value, 1, 1);
4338 else if ((option_value = skip_leading_substring (arg, "call-used-")))
4339 fix_register (option_value, 0, 1);
4340 else if ((option_value = skip_leading_substring (arg, "call-saved-")))
4341 fix_register (option_value, 0, 0);
4342 else if ((option_value = skip_leading_substring (arg, "align-loops=")))
4343 align_loops = read_integral_parameter (option_value, arg - 2, align_loops);
4344 else if ((option_value = skip_leading_substring (arg, "align-functions=")))
4345 align_functions
4346 = read_integral_parameter (option_value, arg - 2, align_functions);
4347 else if ((option_value = skip_leading_substring (arg, "align-jumps=")))
4348 align_jumps = read_integral_parameter (option_value, arg - 2, align_jumps);
4349 else if ((option_value = skip_leading_substring (arg, "align-labels=")))
4350 align_labels
4351 = read_integral_parameter (option_value, arg - 2, align_labels);
4352 else if ((option_value
4353 = skip_leading_substring (arg, "stack-limit-register=")))
4355 int reg = decode_reg_name (option_value);
4356 if (reg < 0)
4357 error ("unrecognized register name `%s'", option_value);
4358 else
4359 stack_limit_rtx = gen_rtx_REG (Pmode, reg);
4361 else if ((option_value
4362 = skip_leading_substring (arg, "stack-limit-symbol=")))
4364 const char *nm;
4365 nm = ggc_strdup (option_value);
4366 stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, nm);
4368 else if ((option_value
4369 = skip_leading_substring (arg, "message-length=")))
4370 output_set_maximum_length
4371 (&global_dc->buffer, read_integral_parameter
4372 (option_value, arg - 2, diagnostic_line_cutoff (global_dc)));
4373 else if ((option_value
4374 = skip_leading_substring (arg, "diagnostics-show-location=")))
4376 if (!strcmp (option_value, "once"))
4377 diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
4378 else if (!strcmp (option_value, "every-line"))
4379 diagnostic_prefixing_rule (global_dc)
4380 = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
4381 else
4382 error ("unrecognized option `%s'", arg - 2);
4384 else if (!strcmp (arg, "no-stack-limit"))
4385 stack_limit_rtx = NULL_RTX;
4386 else if ((option_value = skip_leading_substring (arg, "random-seed=")))
4387 flag_random_seed = option_value;
4388 else if (!strcmp (arg, "no-random-seed"))
4389 flag_random_seed = NULL;
4390 else if (!strcmp (arg, "preprocessed"))
4391 /* Recognize this switch but do nothing. This prevents warnings
4392 about an unrecognized switch if cpplib has not been linked in. */
4394 else
4395 return 0;
4397 return 1;
4400 /* Parse a -W... command line switch. ARG is the value after the -W.
4401 It is safe to access 'ARG - 2' to generate the full switch name.
4402 Return the number of strings consumed. */
4404 static int
4405 decode_W_option (const char *arg)
4407 const char *option_value = NULL;
4408 int j;
4410 /* Search for the option in the table of binary W options. */
4412 for (j = ARRAY_SIZE (W_options); j--;)
4414 if (!strcmp (arg, W_options[j].string))
4416 *W_options[j].variable = W_options[j].on_value;
4417 return 1;
4420 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-'
4421 && ! strcmp (arg + 3, W_options[j].string))
4423 *W_options[j].variable = ! W_options[j].on_value;
4424 return 1;
4428 if ((option_value = skip_leading_substring (arg, "id-clash-")))
4429 warning ("-Wid-clash-LEN is no longer supported");
4430 else if ((option_value = skip_leading_substring (arg, "larger-than-")))
4432 larger_than_size = read_integral_parameter (option_value, arg - 2, -1);
4434 warn_larger_than = larger_than_size != -1;
4436 else
4437 return 0;
4439 return 1;
4442 /* Indexed by enum debug_info_type. */
4443 const char *const debug_type_names[] =
4445 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
4448 /* Parse a -g... command line switch. ARG is the value after the -g.
4449 It is safe to access 'ARG - 2' to generate the full switch name.
4450 Return the number of strings consumed. */
4452 static int
4453 decode_g_option (const char *arg)
4455 static unsigned level = 0;
4456 /* A lot of code assumes write_symbols == NO_DEBUG if the
4457 debugging level is 0 (thus -gstabs1 -gstabs0 would lose track
4458 of what debugging type has been selected). This records the
4459 selected type. It is an error to specify more than one
4460 debugging type. */
4461 static enum debug_info_type selected_debug_type = NO_DEBUG;
4462 /* Nonzero if debugging format has been explicitly set.
4463 -g and -ggdb don't explicitly set the debugging format so
4464 -gdwarf -g3 is equivalent to -gdwarf3. */
4465 static int type_explicitly_set_p = 0;
4467 /* The maximum admissible debug level value. */
4468 static const unsigned max_debug_level = 3;
4470 /* Look up ARG in the table. */
4471 for (da = debug_args; da->arg; da++)
4473 const int da_len = strlen (da->arg);
4475 if (da_len == 0 || ! strncmp (arg, da->arg, da_len))
4477 enum debug_info_type type = da->debug_type;
4478 const char *p = arg + da_len;
4480 if (*p && ! ISDIGIT (*p))
4481 continue;
4483 /* A debug flag without a level defaults to level 2.
4484 Note we do not want to call read_integral_parameter
4485 for that case since it will call atoi which
4486 will return zero.
4488 ??? We may want to generalize the interface to
4489 read_integral_parameter to better handle this case
4490 if this case shows up often. */
4491 if (*p)
4492 level = read_integral_parameter (p, 0, max_debug_level + 1);
4493 else
4494 level = (level == 0) ? 2 : level;
4496 if (da_len > 1 && *p && !strncmp (arg, "dwarf", da_len))
4498 error ("use -gdwarf -g%d for DWARF v1, level %d",
4499 level, level);
4500 if (level == 2)
4501 error ("use -gdwarf-2 for DWARF v2");
4504 if (level > max_debug_level)
4506 warning ("\
4507 ignoring option `%s' due to invalid debug level specification",
4508 arg - 2);
4509 level = debug_info_level;
4512 if (type == NO_DEBUG)
4514 type = PREFERRED_DEBUGGING_TYPE;
4516 if (da_len > 1 && strncmp (arg, "gdb", da_len) == 0)
4518 #ifdef DWARF2_DEBUGGING_INFO
4519 type = DWARF2_DEBUG;
4520 #else
4521 #ifdef DBX_DEBUGGING_INFO
4522 type = DBX_DEBUG;
4523 #endif
4524 #endif
4528 if (type == NO_DEBUG)
4529 warning ("`%s': unknown or unsupported -g option", arg - 2);
4531 /* Does it conflict with an already selected type? */
4532 if (type_explicitly_set_p
4533 /* -g/-ggdb don't conflict with anything. */
4534 && da->debug_type != NO_DEBUG
4535 && type != selected_debug_type)
4536 warning ("`%s' ignored, conflicts with `-g%s'",
4537 arg - 2, debug_type_names[(int) selected_debug_type]);
4538 else
4540 /* If the format has already been set, -g/-ggdb
4541 only change the debug level. */
4542 if (type_explicitly_set_p && da->debug_type == NO_DEBUG)
4543 /* Don't change debugging type. */
4545 else
4547 selected_debug_type = type;
4548 type_explicitly_set_p = da->debug_type != NO_DEBUG;
4551 write_symbols = (level == 0
4552 ? NO_DEBUG
4553 : selected_debug_type);
4554 use_gnu_debug_info_extensions = da->use_extensions_p;
4555 debug_info_level = (enum debug_info_level) level;
4558 break;
4562 if (! da->arg)
4563 return 0;
4565 return 1;
4568 /* Decode the first argument in the argv as a language-independent option.
4569 Return the number of strings consumed. */
4571 static unsigned int
4572 independent_decode_option (char **argv)
4574 char *arg = argv[0];
4576 if (arg[0] != '-' || arg[1] == 0)
4577 return 1;
4579 arg++;
4581 switch (*arg)
4583 default:
4584 return 0;
4586 case 'f':
4587 return decode_f_option (arg + 1);
4589 case 'g':
4590 return decode_g_option (arg + 1);
4592 case 'W':
4593 return decode_W_option (arg + 1);
4597 /* Decode -m switches. */
4598 /* Decode the switch -mNAME. */
4600 void
4601 set_target_switch (const char *name)
4603 size_t j;
4604 int valid_target_option = 0;
4606 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
4607 if (!strcmp (target_switches[j].name, name))
4609 if (target_switches[j].value < 0)
4610 target_flags &= ~-target_switches[j].value;
4611 else
4612 target_flags |= target_switches[j].value;
4613 if (name[0] != 0)
4615 if (target_switches[j].value < 0)
4616 target_flags_explicit |= -target_switches[j].value;
4617 else
4618 target_flags_explicit |= target_switches[j].value;
4620 valid_target_option = 1;
4623 #ifdef TARGET_OPTIONS
4624 if (!valid_target_option)
4625 for (j = 0; j < ARRAY_SIZE (target_options); j++)
4627 int len = strlen (target_options[j].prefix);
4628 if (target_options[j].value)
4630 if (!strcmp (target_options[j].prefix, name))
4632 *target_options[j].variable = target_options[j].value;
4633 valid_target_option = 1;
4636 else
4638 if (!strncmp (target_options[j].prefix, name, len))
4640 *target_options[j].variable = name + len;
4641 valid_target_option = 1;
4645 #endif
4647 if (!valid_target_option)
4648 error ("invalid option `%s'", name);
4651 /* Print version information to FILE.
4652 Each line begins with INDENT (for the case where FILE is the
4653 assembler output file). */
4655 void
4656 print_version (FILE *file, const char *indent)
4658 #ifndef __VERSION__
4659 #define __VERSION__ "[?]"
4660 #endif
4661 fnotice (file,
4662 #ifdef __GNUC__
4663 "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
4664 #else
4665 "%s%s%s version %s (%s) compiled by CC.\n"
4666 #endif
4667 , indent, *indent != 0 ? " " : "",
4668 lang_hooks.name, version_string, TARGET_NAME,
4669 indent, __VERSION__);
4670 fnotice (file, "%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n",
4671 indent, *indent != 0 ? " " : "",
4672 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
4675 /* Print an option value and return the adjusted position in the line.
4676 ??? We don't handle error returns from fprintf (disk full); presumably
4677 other code will catch a disk full though. */
4679 static int
4680 print_single_switch (FILE *file, int pos, int max,
4681 const char *indent, const char *sep, const char *term,
4682 const char *type, const char *name)
4684 /* The ultrix fprintf returns 0 on success, so compute the result we want
4685 here since we need it for the following test. */
4686 int len = strlen (sep) + strlen (type) + strlen (name);
4688 if (pos != 0
4689 && pos + len > max)
4691 fprintf (file, "%s", term);
4692 pos = 0;
4694 if (pos == 0)
4696 fprintf (file, "%s", indent);
4697 pos = strlen (indent);
4699 fprintf (file, "%s%s%s", sep, type, name);
4700 pos += len;
4701 return pos;
4704 /* Print active target switches to FILE.
4705 POS is the current cursor position and MAX is the size of a "line".
4706 Each line begins with INDENT and ends with TERM.
4707 Each switch is separated from the next by SEP. */
4709 static void
4710 print_switch_values (FILE *file, int pos, int max,
4711 const char *indent, const char *sep, const char *term)
4713 size_t j;
4714 char **p;
4716 /* Fill in the -frandom-seed option, if the user didn't pass it, so
4717 that it can be printed below. This helps reproducibility. Of
4718 course, the string may never be used, but we can't tell that at
4719 this point in the compile. */
4720 default_flag_random_seed ();
4722 /* Print the options as passed. */
4724 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
4725 _("options passed: "), "");
4727 for (p = &save_argv[1]; *p != NULL; p++)
4728 if (**p == '-')
4730 /* Ignore these. */
4731 if (strcmp (*p, "-o") == 0)
4733 if (p[1] != NULL)
4734 p++;
4735 continue;
4737 if (strcmp (*p, "-quiet") == 0)
4738 continue;
4739 if (strcmp (*p, "-version") == 0)
4740 continue;
4741 if ((*p)[1] == 'd')
4742 continue;
4744 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
4746 if (pos > 0)
4747 fprintf (file, "%s", term);
4749 /* Print the -f and -m options that have been enabled.
4750 We don't handle language specific options but printing argv
4751 should suffice. */
4753 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
4754 _("options enabled: "), "");
4756 for (j = 0; j < ARRAY_SIZE (f_options); j++)
4757 if (*f_options[j].variable == f_options[j].on_value)
4758 pos = print_single_switch (file, pos, max, indent, sep, term,
4759 "-f", f_options[j].string);
4761 /* Print target specific options. */
4763 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
4764 if (target_switches[j].name[0] != '\0'
4765 && target_switches[j].value > 0
4766 && ((target_switches[j].value & target_flags)
4767 == target_switches[j].value))
4769 pos = print_single_switch (file, pos, max, indent, sep, term,
4770 "-m", target_switches[j].name);
4773 #ifdef TARGET_OPTIONS
4774 for (j = 0; j < ARRAY_SIZE (target_options); j++)
4775 if (*target_options[j].variable != NULL)
4777 char prefix[256];
4778 sprintf (prefix, "-m%s", target_options[j].prefix);
4779 pos = print_single_switch (file, pos, max, indent, sep, term,
4780 prefix, *target_options[j].variable);
4782 #endif
4784 fprintf (file, "%s", term);
4787 /* Open assembly code output file. Do this even if -fsyntax-only is
4788 on, because then the driver will have provided the name of a
4789 temporary file or bit bucket for us. NAME is the file specified on
4790 the command line, possibly NULL. */
4791 static void
4792 init_asm_output (const char *name)
4794 if (name == NULL && asm_file_name == 0)
4795 asm_out_file = stdout;
4796 else
4798 if (asm_file_name == 0)
4800 int len = strlen (dump_base_name);
4801 char *dumpname = (char *) xmalloc (len + 6);
4802 memcpy (dumpname, dump_base_name, len + 1);
4803 strip_off_ending (dumpname, len);
4804 strcat (dumpname, ".s");
4805 asm_file_name = dumpname;
4807 if (!strcmp (asm_file_name, "-"))
4808 asm_out_file = stdout;
4809 else
4810 asm_out_file = fopen (asm_file_name, "w+");
4811 if (asm_out_file == 0)
4812 fatal_error ("can't open %s for writing: %m", asm_file_name);
4815 #ifdef IO_BUFFER_SIZE
4816 setvbuf (asm_out_file, (char *) xmalloc (IO_BUFFER_SIZE),
4817 _IOFBF, IO_BUFFER_SIZE);
4818 #endif
4820 if (!flag_syntax_only)
4822 #ifdef ASM_FILE_START
4823 ASM_FILE_START (asm_out_file);
4824 #endif
4826 #ifdef ASM_COMMENT_START
4827 if (flag_verbose_asm)
4829 /* Print the list of options in effect. */
4830 print_version (asm_out_file, ASM_COMMENT_START);
4831 print_switch_values (asm_out_file, 0, MAX_LINE,
4832 ASM_COMMENT_START, " ", "\n");
4833 /* Add a blank line here so it appears in assembler output but not
4834 screen output. */
4835 fprintf (asm_out_file, "\n");
4837 #endif
4841 /* Initialization of the front end environment, before command line
4842 options are parsed. Signal handlers, internationalization etc.
4843 ARGV0 is main's argv[0]. */
4844 static void
4845 general_init (char *argv0)
4847 char *p;
4849 p = argv0 + strlen (argv0);
4850 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
4851 --p;
4852 progname = p;
4854 xmalloc_set_program_name (progname);
4856 hex_init ();
4858 gcc_init_libintl ();
4860 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
4861 #ifdef SIGSEGV
4862 signal (SIGSEGV, crash_signal);
4863 #endif
4864 #ifdef SIGILL
4865 signal (SIGILL, crash_signal);
4866 #endif
4867 #ifdef SIGBUS
4868 signal (SIGBUS, crash_signal);
4869 #endif
4870 #ifdef SIGABRT
4871 signal (SIGABRT, crash_signal);
4872 #endif
4873 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
4874 signal (SIGIOT, crash_signal);
4875 #endif
4876 #ifdef SIGFPE
4877 signal (SIGFPE, crash_signal);
4878 #endif
4880 /* Other host-specific signal setup. */
4881 (*host_hooks.extra_signals)();
4883 /* Initialize the diagnostics reporting machinery, so option parsing
4884 can give warnings and errors. */
4885 diagnostic_initialize (global_dc);
4887 /* Initialize the garbage-collector, string pools and tree type hash
4888 table. */
4889 init_ggc ();
4890 init_stringpool ();
4891 init_ttree ();
4894 /* Parse command line options and set default flag values, called
4895 after language-independent option-independent initialization. Do
4896 minimal options processing. Outputting diagnostics is OK, but GC
4897 and identifier hashtables etc. are not initialized yet.
4899 Return nonzero to suppress compiler back end initialization. */
4900 static void
4901 parse_options_and_default_flags (int argc, char **argv)
4903 int i, lang_mask;
4905 /* Save in case md file wants to emit args as a comment. */
4906 save_argc = argc;
4907 save_argv = argv;
4909 /* Initialize register usage now so switches may override. */
4910 init_reg_sets ();
4912 /* Register the language-independent parameters. */
4913 add_params (lang_independent_params, LAST_PARAM);
4915 /* This must be done after add_params but before argument processing. */
4916 init_ggc_heuristics();
4918 /* Perform language-specific options initialization. */
4919 lang_mask = (*lang_hooks.init_options) ();
4921 /* Scan to see what optimization level has been specified. That will
4922 determine the default value of many flags. */
4923 for (i = 1; i < argc; i++)
4925 if (!strcmp (argv[i], "-O"))
4927 optimize = 1;
4928 optimize_size = 0;
4930 else if (argv[i][0] == '-' && argv[i][1] == 'O')
4932 /* Handle -Os, -O2, -O3, -O69, ... */
4933 char *p = &argv[i][2];
4935 if ((p[0] == 's') && (p[1] == 0))
4937 optimize_size = 1;
4939 /* Optimizing for size forces optimize to be 2. */
4940 optimize = 2;
4942 else
4944 const int optimize_val = read_integral_parameter (p, p - 2, -1);
4945 if (optimize_val != -1)
4947 optimize = optimize_val;
4948 optimize_size = 0;
4954 if (!optimize)
4956 flag_merge_constants = 0;
4959 if (optimize >= 1)
4961 flag_defer_pop = 1;
4962 flag_thread_jumps = 1;
4963 #ifdef DELAY_SLOTS
4964 flag_delayed_branch = 1;
4965 #endif
4966 #ifdef CAN_DEBUG_WITHOUT_FP
4967 flag_omit_frame_pointer = 1;
4968 #endif
4969 flag_guess_branch_prob = 1;
4970 flag_cprop_registers = 1;
4971 flag_loop_optimize = 1;
4972 flag_crossjumping = 1;
4973 flag_if_conversion = 1;
4974 flag_if_conversion2 = 1;
4977 if (optimize >= 2)
4979 flag_optimize_sibling_calls = 1;
4980 flag_cse_follow_jumps = 1;
4981 flag_cse_skip_blocks = 1;
4982 flag_gcse = 1;
4983 flag_expensive_optimizations = 1;
4984 flag_strength_reduce = 1;
4985 flag_rerun_cse_after_loop = 1;
4986 flag_rerun_loop_opt = 1;
4987 flag_caller_saves = 1;
4988 flag_force_mem = 1;
4989 flag_peephole2 = 1;
4990 #ifdef INSN_SCHEDULING
4991 flag_schedule_insns = 1;
4992 flag_schedule_insns_after_reload = 1;
4993 #endif
4994 flag_regmove = 1;
4995 flag_strict_aliasing = 1;
4996 flag_delete_null_pointer_checks = 1;
4997 flag_reorder_blocks = 1;
4998 flag_reorder_functions = 1;
5001 if (optimize >= 3)
5003 flag_inline_functions = 1;
5004 flag_rename_registers = 1;
5005 flag_unswitch_loops = 1;
5006 flag_unit_at_a_time = 1;
5009 if (optimize < 2 || optimize_size)
5011 align_loops = 1;
5012 align_jumps = 1;
5013 align_labels = 1;
5014 align_functions = 1;
5016 /* Don't reorder blocks when optimizing for size because extra
5017 jump insns may be created; also barrier may create extra padding.
5019 More correctly we should have a block reordering mode that tried
5020 to minimize the combined size of all the jumps. This would more
5021 or less automatically remove extra jumps, but would also try to
5022 use more short jumps instead of long jumps. */
5023 flag_reorder_blocks = 0;
5026 /* Initialize whether `char' is signed. */
5027 flag_signed_char = DEFAULT_SIGNED_CHAR;
5028 #ifdef DEFAULT_SHORT_ENUMS
5029 /* Initialize how much space enums occupy, by default. */
5030 flag_short_enums = DEFAULT_SHORT_ENUMS;
5031 #endif
5033 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
5034 modify it. */
5035 target_flags = 0;
5036 set_target_switch ("");
5038 /* Unwind tables are always present in an ABI-conformant IA-64
5039 object file, so the default should be ON. */
5040 #ifdef IA64_UNWIND_INFO
5041 flag_unwind_tables = IA64_UNWIND_INFO;
5042 #endif
5044 #ifdef OPTIMIZATION_OPTIONS
5045 /* Allow default optimizations to be specified on a per-machine basis. */
5046 OPTIMIZATION_OPTIONS (optimize, optimize_size);
5047 #endif
5049 /* Perform normal command line switch decoding. */
5050 for (i = 1; i < argc;)
5052 int lang_processed;
5053 int indep_processed;
5055 /* Give the language a chance to decode the option for itself. */
5056 lang_processed = handle_option (argc - i, argv + i, lang_mask);
5058 if (lang_processed >= 0)
5059 /* Now see if the option also has a language independent meaning.
5060 Some options are both language specific and language independent,
5061 eg --help. */
5062 indep_processed = independent_decode_option (argv + i);
5063 else
5065 lang_processed = -lang_processed;
5066 indep_processed = 0;
5069 if (lang_processed || indep_processed)
5070 i += MAX (lang_processed, indep_processed);
5071 else
5073 const char *option = NULL;
5074 const char *lang = NULL;
5075 unsigned int j;
5077 /* It is possible that the command line switch is not valid for the
5078 current language, but it is valid for another language. In order
5079 to be compatible with previous versions of the compiler (which
5080 did not issue an error message in this case) we check for this
5081 possibility here. If we do find a match, then if extra_warnings
5082 is set we generate a warning message, otherwise we will just
5083 ignore the option. */
5084 for (j = 0; j < ARRAY_SIZE (documented_lang_options); j++)
5086 option = documented_lang_options[j].option;
5088 if (option == NULL)
5089 lang = documented_lang_options[j].description;
5090 else if (! strncmp (argv[i], option, strlen (option)))
5091 break;
5094 if (j != ARRAY_SIZE (documented_lang_options))
5096 if (extra_warnings)
5098 warning ("ignoring command line option '%s'", argv[i]);
5099 if (lang)
5100 warning
5101 ("(it is valid for %s but not the selected language)",
5102 lang);
5105 else if (argv[i][0] == '-' && argv[i][1] == 'g')
5106 warning ("`%s': unknown or unsupported -g option", &argv[i][2]);
5107 else
5108 error ("unrecognized option `%s'", argv[i]);
5110 i++;
5114 if (flag_pie)
5115 flag_pic = flag_pie;
5116 if (flag_pic && !flag_pie)
5117 flag_shlib = 1;
5119 if (flag_no_inline == 2)
5120 flag_no_inline = 0;
5121 else
5122 flag_really_no_inline = flag_no_inline;
5124 /* Set flag_no_inline before the post_options () hook. The C front
5125 ends use it to determine tree inlining defaults. FIXME: such
5126 code should be lang-independent when all front ends use tree
5127 inlining, in which case it, and this condition, should be moved
5128 to the top of process_options() instead. */
5129 if (optimize == 0)
5131 /* Inlining does not work if not optimizing,
5132 so force it not to be done. */
5133 flag_no_inline = 1;
5134 warn_inline = 0;
5136 /* The c_decode_option function and decode_option hook set
5137 this to `2' if -Wall is used, so we can avoid giving out
5138 lots of errors for people who don't realize what -Wall does. */
5139 if (warn_uninitialized == 1)
5140 warning ("-Wuninitialized is not supported without -O");
5143 if (flag_really_no_inline == 2)
5144 flag_really_no_inline = flag_no_inline;
5147 /* Process the options that have been parsed. */
5148 static void
5149 process_options (void)
5151 /* Allow the front end to perform consistency checks and do further
5152 initialization based on the command line options. This hook also
5153 sets the original filename if appropriate (e.g. foo.i -> foo.c)
5154 so we can correctly initialize debug output. */
5155 no_backend = (*lang_hooks.post_options) (&main_input_filename);
5156 input_filename = main_input_filename;
5158 #ifdef OVERRIDE_OPTIONS
5159 /* Some machines may reject certain combinations of options. */
5160 OVERRIDE_OPTIONS;
5161 #endif
5163 /* Set aux_base_name if not already set. */
5164 if (aux_base_name)
5166 else if (main_input_filename)
5168 char *name = xstrdup (lbasename (main_input_filename));
5170 strip_off_ending (name, strlen (name));
5171 aux_base_name = name;
5173 else
5174 aux_base_name = "gccaux";
5176 /* Set up the align_*_log variables, defaulting them to 1 if they
5177 were still unset. */
5178 if (align_loops <= 0) align_loops = 1;
5179 if (align_loops_max_skip > align_loops || !align_loops)
5180 align_loops_max_skip = align_loops - 1;
5181 align_loops_log = floor_log2 (align_loops * 2 - 1);
5182 if (align_jumps <= 0) align_jumps = 1;
5183 if (align_jumps_max_skip > align_jumps || !align_jumps)
5184 align_jumps_max_skip = align_jumps - 1;
5185 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
5186 if (align_labels <= 0) align_labels = 1;
5187 align_labels_log = floor_log2 (align_labels * 2 - 1);
5188 if (align_labels_max_skip > align_labels || !align_labels)
5189 align_labels_max_skip = align_labels - 1;
5190 if (align_functions <= 0) align_functions = 1;
5191 align_functions_log = floor_log2 (align_functions * 2 - 1);
5193 /* Unrolling all loops implies that standard loop unrolling must also
5194 be done. */
5195 if (flag_unroll_all_loops)
5196 flag_unroll_loops = 1;
5198 if (flag_unroll_loops)
5200 flag_old_unroll_loops = 0;
5201 flag_old_unroll_all_loops = 0;
5204 if (flag_old_unroll_all_loops)
5205 flag_old_unroll_loops = 1;
5207 /* Old loop unrolling requires that strength_reduction be on also. Silently
5208 turn on strength reduction here if it isn't already on. Also, the loop
5209 unrolling code assumes that cse will be run after loop, so that must
5210 be turned on also. */
5211 if (flag_old_unroll_loops)
5213 flag_strength_reduce = 1;
5214 flag_rerun_cse_after_loop = 1;
5216 if (flag_unroll_loops || flag_peel_loops)
5217 flag_rerun_cse_after_loop = 1;
5219 if (flag_non_call_exceptions)
5220 flag_asynchronous_unwind_tables = 1;
5221 if (flag_asynchronous_unwind_tables)
5222 flag_unwind_tables = 1;
5224 /* Disable unit-at-a-time mode for frontends not supporting callgraph
5225 interface. */
5226 if (flag_unit_at_a_time && ! lang_hooks.callgraph.expand_function)
5227 flag_unit_at_a_time = 0;
5229 /* Warn about options that are not supported on this machine. */
5230 #ifndef INSN_SCHEDULING
5231 if (flag_schedule_insns || flag_schedule_insns_after_reload)
5232 warning ("instruction scheduling not supported on this target machine");
5233 #endif
5234 #ifndef DELAY_SLOTS
5235 if (flag_delayed_branch)
5236 warning ("this target machine does not have delayed branches");
5237 #endif
5239 user_label_prefix = USER_LABEL_PREFIX;
5240 if (flag_leading_underscore != -1)
5242 /* If the default prefix is more complicated than "" or "_",
5243 issue a warning and ignore this option. */
5244 if (user_label_prefix[0] == 0 ||
5245 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
5247 user_label_prefix = flag_leading_underscore ? "_" : "";
5249 else
5250 warning ("-f%sleading-underscore not supported on this target machine",
5251 flag_leading_underscore ? "" : "no-");
5254 /* If we are in verbose mode, write out the version and maybe all the
5255 option flags in use. */
5256 if (version_flag)
5258 print_version (stderr, "");
5259 if (! quiet_flag)
5260 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
5263 if (flag_syntax_only)
5265 write_symbols = NO_DEBUG;
5266 profile_flag = 0;
5269 /* Now we know write_symbols, set up the debug hooks based on it.
5270 By default we do nothing for debug output. */
5271 #if defined(DBX_DEBUGGING_INFO)
5272 if (write_symbols == DBX_DEBUG)
5273 debug_hooks = &dbx_debug_hooks;
5274 #endif
5275 #if defined(XCOFF_DEBUGGING_INFO)
5276 if (write_symbols == XCOFF_DEBUG)
5277 debug_hooks = &xcoff_debug_hooks;
5278 #endif
5279 #ifdef SDB_DEBUGGING_INFO
5280 if (write_symbols == SDB_DEBUG)
5281 debug_hooks = &sdb_debug_hooks;
5282 #endif
5283 #ifdef DWARF_DEBUGGING_INFO
5284 if (write_symbols == DWARF_DEBUG)
5285 debug_hooks = &dwarf_debug_hooks;
5286 #endif
5287 #ifdef DWARF2_DEBUGGING_INFO
5288 if (write_symbols == DWARF2_DEBUG)
5289 debug_hooks = &dwarf2_debug_hooks;
5290 #endif
5291 #ifdef VMS_DEBUGGING_INFO
5292 if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
5293 debug_hooks = &vmsdbg_debug_hooks;
5294 #endif
5296 /* If auxiliary info generation is desired, open the output file.
5297 This goes in the same directory as the source file--unlike
5298 all the other output files. */
5299 if (flag_gen_aux_info)
5301 aux_info_file = fopen (aux_info_file_name, "w");
5302 if (aux_info_file == 0)
5303 fatal_error ("can't open %s: %m", aux_info_file_name);
5306 if (! targetm.have_named_sections)
5308 if (flag_function_sections)
5310 warning ("-ffunction-sections not supported for this target");
5311 flag_function_sections = 0;
5313 if (flag_data_sections)
5315 warning ("-fdata-sections not supported for this target");
5316 flag_data_sections = 0;
5320 if (flag_function_sections && profile_flag)
5322 warning ("-ffunction-sections disabled; it makes profiling impossible");
5323 flag_function_sections = 0;
5326 #ifndef HAVE_prefetch
5327 if (flag_prefetch_loop_arrays)
5329 warning ("-fprefetch-loop-arrays not supported for this target");
5330 flag_prefetch_loop_arrays = 0;
5332 #else
5333 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
5335 warning ("-fprefetch-loop-arrays not supported for this target (try -march switches)");
5336 flag_prefetch_loop_arrays = 0;
5338 #endif
5340 /* This combination of options isn't handled for i386 targets and doesn't
5341 make much sense anyway, so don't allow it. */
5342 if (flag_prefetch_loop_arrays && optimize_size)
5344 warning ("-fprefetch-loop-arrays is not supported with -Os");
5345 flag_prefetch_loop_arrays = 0;
5348 #ifndef OBJECT_FORMAT_ELF
5349 if (flag_function_sections && write_symbols != NO_DEBUG)
5350 warning ("-ffunction-sections may affect debugging on some targets");
5351 #endif
5353 /* The presence of IEEE signaling NaNs, implies all math can trap. */
5354 if (flag_signaling_nans)
5355 flag_trapping_math = 1;
5358 /* Initialize the compiler back end. */
5359 static void
5360 backend_init (void)
5362 /* init_emit_once uses reg_raw_mode and therefore must be called
5363 after init_regs which initialized reg_raw_mode. */
5364 init_regs ();
5365 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
5366 || debug_info_level == DINFO_LEVEL_VERBOSE
5367 #ifdef VMS_DEBUGGING_INFO
5368 /* Enable line number info for traceback */
5369 || debug_info_level > DINFO_LEVEL_NONE
5370 #endif
5371 || flag_test_coverage
5372 || warn_notreached);
5373 init_fake_stack_mems ();
5374 init_alias_once ();
5375 init_loop ();
5376 init_reload ();
5377 init_function_once ();
5378 init_varasm_once ();
5380 /* The following initialization functions need to generate rtl, so
5381 provide a dummy function context for them. */
5382 init_dummy_function_start ();
5383 init_expmed ();
5384 if (flag_caller_saves)
5385 init_caller_save ();
5386 expand_dummy_function_end ();
5389 /* Language-dependent initialization. Returns nonzero on success. */
5390 static int
5391 lang_dependent_init (const char *name)
5393 if (dump_base_name == 0)
5394 dump_base_name = name ? name : "gccdump";
5396 /* Other front-end initialization. */
5397 if ((*lang_hooks.init) () == 0)
5398 return 0;
5400 init_asm_output (name);
5402 /* These create various _DECL nodes, so need to be called after the
5403 front end is initialized. */
5404 init_eh ();
5405 init_optabs ();
5407 /* The following initialization functions need to generate rtl, so
5408 provide a dummy function context for them. */
5409 init_dummy_function_start ();
5410 init_expr_once ();
5411 expand_dummy_function_end ();
5413 /* If dbx symbol table desired, initialize writing it and output the
5414 predefined types. */
5415 timevar_push (TV_SYMOUT);
5417 #ifdef DWARF2_UNWIND_INFO
5418 if (dwarf2out_do_frame ())
5419 dwarf2out_frame_init ();
5420 #endif
5422 /* Now we have the correct original filename, we can initialize
5423 debug output. */
5424 (*debug_hooks->init) (name);
5426 timevar_pop (TV_SYMOUT);
5428 return 1;
5431 /* Clean up: close opened files, etc. */
5433 static void
5434 finalize (void)
5436 /* Close the dump files. */
5437 if (flag_gen_aux_info)
5439 fclose (aux_info_file);
5440 if (errorcount)
5441 unlink (aux_info_file_name);
5444 /* Close non-debugging input and output files. Take special care to note
5445 whether fclose returns an error, since the pages might still be on the
5446 buffer chain while the file is open. */
5448 if (asm_out_file)
5450 if (ferror (asm_out_file) != 0)
5451 fatal_error ("error writing to %s: %m", asm_file_name);
5452 if (fclose (asm_out_file) != 0)
5453 fatal_error ("error closing %s: %m", asm_file_name);
5456 /* Do whatever is necessary to finish printing the graphs. */
5457 if (graph_dump_format != no_graph)
5459 int i;
5461 for (i = 0; i < (int) DFI_MAX; ++i)
5462 if (dump_file[i].initialized && dump_file[i].graph_dump_p)
5464 char seq[16];
5465 char *suffix;
5467 sprintf (seq, DUMPFILE_FORMAT, i);
5468 suffix = concat (seq, dump_file[i].extension, NULL);
5469 finish_graph_dump_file (dump_base_name, suffix);
5470 free (suffix);
5474 if (mem_report)
5476 ggc_print_statistics ();
5477 stringpool_statistics ();
5478 dump_tree_statistics ();
5481 /* Free up memory for the benefit of leak detectors. */
5482 free_reg_info ();
5484 /* Language-specific end of compilation actions. */
5485 (*lang_hooks.finish) ();
5488 /* Initialize the compiler, and compile the input file. */
5489 static void
5490 do_compile (void)
5492 /* Initialize timing first. The C front ends read the main file in
5493 the post_options hook, and C++ does file timings. */
5494 if (time_report || !quiet_flag || flag_detailed_statistics)
5495 timevar_init ();
5496 timevar_start (TV_TOTAL);
5498 process_options ();
5500 /* Don't do any more if an error has already occurred. */
5501 if (!errorcount)
5503 /* Set up the back-end if requested. */
5504 if (!no_backend)
5505 backend_init ();
5507 /* Language-dependent initialization. Returns true on success. */
5508 if (lang_dependent_init (main_input_filename))
5509 compile_file ();
5511 finalize ();
5514 /* Stop timing and print the times. */
5515 timevar_stop (TV_TOTAL);
5516 timevar_print (stderr);
5519 /* Entry point of cc1, cc1plus, jc1, f771, etc.
5520 Decode command args, then call compile_file.
5521 Exit code is FATAL_EXIT_CODE if can't open files or if there were
5522 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
5524 It is not safe to call this function more than once. */
5527 toplev_main (int argc, char **argv)
5529 /* Initialization of GCC's environment, and diagnostics. */
5530 general_init (argv[0]);
5532 /* Parse the options and do minimal processing; basically just
5533 enough to default flags appropriately. */
5534 parse_options_and_default_flags (argc, argv);
5536 /* Exit early if we can (e.g. -help). */
5537 if (!exit_after_options)
5538 do_compile ();
5540 if (errorcount || sorrycount)
5541 return (FATAL_EXIT_CODE);
5543 return (SUCCESS_EXIT_CODE);