loop.c (emit_prefetch_instructions): Properly place the address computation.
[gcc.git] / gcc / toplev.c
1
2 /* Top level of GNU C compiler
3 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 02111-1307, USA. */
22
23 /* This is the top level of cc1/c++.
24 It parses command args, opens files, invokes the various passes
25 in the proper order, and counts the time used by each.
26 Error messages and low-level interface to malloc also handled here. */
27
28 #include "config.h"
29 #undef FLOAT /* This is for hpux. They should change hpux. */
30 #undef FFS /* Some systems define this in param.h. */
31 #include "system.h"
32 #include <signal.h>
33
34 #ifdef HAVE_SYS_RESOURCE_H
35 # include <sys/resource.h>
36 #endif
37
38 #ifdef HAVE_SYS_TIMES_H
39 # include <sys/times.h>
40 #endif
41
42 #include "input.h"
43 #include "tree.h"
44 #include "rtl.h"
45 #include "tm_p.h"
46 #include "flags.h"
47 #include "insn-attr.h"
48 #include "insn-config.h"
49 #include "insn-flags.h"
50 #include "hard-reg-set.h"
51 #include "recog.h"
52 #include "output.h"
53 #include "except.h"
54 #include "function.h"
55 #include "toplev.h"
56 #include "expr.h"
57 #include "basic-block.h"
58 #include "intl.h"
59 #include "ggc.h"
60 #include "graph.h"
61 #include "loop.h"
62 #include "regs.h"
63 #include "timevar.h"
64 #include "diagnostic.h"
65 #include "ssa.h"
66 #include "params.h"
67 #include "reload.h"
68 #include "dwarf2asm.h"
69 #include "integrate.h"
70 #include "debug.h"
71 #include "target.h"
72 #include "langhooks.h"
73
74 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
75 #include "dwarf2out.h"
76 #endif
77
78 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
79 #include "dbxout.h"
80 #endif
81
82 #ifdef SDB_DEBUGGING_INFO
83 #include "sdbout.h"
84 #endif
85
86 #ifdef XCOFF_DEBUGGING_INFO
87 #include "xcoffout.h" /* Needed for external data
88 declarations for e.g. AIX 4.x. */
89 #endif
90
91 #ifdef HALF_PIC_DEBUG
92 #include "halfpic.h"
93 #endif
94 \f
95 /* Carry information from ASM_DECLARE_OBJECT_NAME
96 to ASM_FINISH_DECLARE_OBJECT. */
97
98 extern int size_directive_output;
99 extern tree last_assemble_variable_decl;
100
101 static void general_init PARAMS ((char *));
102 static void parse_options_and_default_flags PARAMS ((int, char **));
103 static void do_compile PARAMS ((void));
104 static void process_options PARAMS ((void));
105 static void lang_independent_init PARAMS ((void));
106 static int lang_dependent_init PARAMS ((const char *));
107 static void init_asm_output PARAMS ((const char *));
108 static void finalize PARAMS ((void));
109
110 static void set_target_switch PARAMS ((const char *));
111
112 static void crash_signal PARAMS ((int)) ATTRIBUTE_NORETURN;
113 static void compile_file PARAMS ((void));
114 static void display_help PARAMS ((void));
115 static void display_target_options PARAMS ((void));
116
117 static void decode_d_option PARAMS ((const char *));
118 static int decode_f_option PARAMS ((const char *));
119 static int decode_W_option PARAMS ((const char *));
120 static int decode_g_option PARAMS ((const char *));
121 static unsigned int independent_decode_option PARAMS ((int, char **));
122
123 static void print_version PARAMS ((FILE *, const char *));
124 static int print_single_switch PARAMS ((FILE *, int, int, const char *,
125 const char *, const char *,
126 const char *, const char *));
127 static void print_switch_values PARAMS ((FILE *, int, int, const char *,
128 const char *, const char *));
129
130 /* Nonzero to dump debug info whilst parsing (-dy option). */
131 static int set_yydebug;
132
133 /* Length of line when printing switch values. */
134 #define MAX_LINE 75
135
136 /* Name of program invoked, sans directories. */
137
138 const char *progname;
139
140 /* Copy of arguments to toplev_main. */
141 int save_argc;
142 char **save_argv;
143 \f
144 /* Name of current original source file (what was input to cpp).
145 This comes from each #-command in the actual input. */
146
147 const char *input_filename;
148
149 /* Name of top-level original source file (what was input to cpp).
150 This comes from the #-command at the beginning of the actual input.
151 If there isn't any there, then this is the cc1 input file name. */
152
153 const char *main_input_filename;
154
155 /* Current line number in real source file. */
156
157 int lineno;
158
159 /* Nonzero if it is unsafe to create any new pseudo registers. */
160 int no_new_pseudos;
161
162 /* Stack of currently pending input files. */
163
164 struct file_stack *input_file_stack;
165
166 /* Incremented on each change to input_file_stack. */
167 int input_file_stack_tick;
168
169 /* Name to use as base of names for dump output files. */
170
171 const char *dump_base_name;
172
173 /* Format to use to print dumpfile index value */
174 #ifndef DUMPFILE_FORMAT
175 #define DUMPFILE_FORMAT ".%02d."
176 #endif
177
178 /* Bit flags that specify the machine subtype we are compiling for.
179 Bits are tested using macros TARGET_... defined in the tm.h file
180 and set by `-m...' switches. Must be defined in rtlanal.c. */
181
182 extern int target_flags;
183
184 /* Debug hooks - dependent upon command line options. */
185
186 const struct gcc_debug_hooks *debug_hooks = &do_nothing_debug_hooks;
187
188 /* Describes a dump file. */
189
190 struct dump_file_info
191 {
192 /* The unique extension to apply, e.g. ".jump". */
193 const char *const extension;
194
195 /* The -d<c> character that enables this dump file. */
196 char const debug_switch;
197
198 /* True if there is a corresponding graph dump file. */
199 char const graph_dump_p;
200
201 /* True if the user selected this dump. */
202 char enabled;
203
204 /* True if the files have been initialized (ie truncated). */
205 char initialized;
206 };
207
208 /* Enumerate the extant dump files. */
209
210 enum dump_file_index
211 {
212 DFI_rtl,
213 DFI_sibling,
214 DFI_eh,
215 DFI_jump,
216 DFI_ssa,
217 DFI_ssa_ccp,
218 DFI_ssa_dce,
219 DFI_ussa,
220 DFI_null,
221 DFI_cse,
222 DFI_addressof,
223 DFI_gcse,
224 DFI_loop,
225 DFI_cfg,
226 DFI_bp,
227 DFI_tracer,
228 DFI_cse2,
229 DFI_life,
230 DFI_combine,
231 DFI_ce,
232 DFI_regmove,
233 DFI_sched,
234 DFI_lreg,
235 DFI_greg,
236 DFI_postreload,
237 DFI_flow2,
238 DFI_peephole2,
239 DFI_rnreg,
240 DFI_ce2,
241 DFI_sched2,
242 DFI_stack,
243 DFI_bbro,
244 DFI_mach,
245 DFI_dbr,
246 DFI_MAX
247 };
248
249 /* Describes all the dump files. Should be kept in order of the
250 pass and in sync with dump_file_index above.
251
252 Remaining -d letters:
253
254 " o q "
255 " H JK OPQ TUV YZ"
256 */
257
258 static struct dump_file_info dump_file[DFI_MAX] =
259 {
260 { "rtl", 'r', 0, 0, 0 },
261 { "sibling", 'i', 0, 0, 0 },
262 { "eh", 'h', 0, 0, 0 },
263 { "jump", 'j', 0, 0, 0 },
264 { "ssa", 'e', 1, 0, 0 },
265 { "ssaccp", 'W', 1, 0, 0 },
266 { "ssadce", 'X', 1, 0, 0 },
267 { "ussa", 'e', 1, 0, 0 }, /* Yes, duplicate enable switch. */
268 { "null", 'u', 0, 0, 0 },
269 { "cse", 's', 0, 0, 0 },
270 { "addressof", 'F', 0, 0, 0 },
271 { "gcse", 'G', 1, 0, 0 },
272 { "loop", 'L', 1, 0, 0 },
273 { "cfg", 'f', 1, 0, 0 },
274 { "bp", 'b', 1, 0, 0 },
275 { "tracer", 'T', 1, 0, 0 },
276 { "cse2", 't', 1, 0, 0 },
277 { "life", 'f', 1, 0, 0 }, /* Yes, duplicate enable switch. */
278 { "combine", 'c', 1, 0, 0 },
279 { "ce", 'C', 1, 0, 0 },
280 { "regmove", 'N', 1, 0, 0 },
281 { "sched", 'S', 1, 0, 0 },
282 { "lreg", 'l', 1, 0, 0 },
283 { "greg", 'g', 1, 0, 0 },
284 { "postreload", 'o', 1, 0, 0 },
285 { "flow2", 'w', 1, 0, 0 },
286 { "peephole2", 'z', 1, 0, 0 },
287 { "rnreg", 'n', 1, 0, 0 },
288 { "ce2", 'E', 1, 0, 0 },
289 { "sched2", 'R', 1, 0, 0 },
290 { "stack", 'k', 1, 0, 0 },
291 { "bbro", 'B', 1, 0, 0 },
292 { "mach", 'M', 1, 0, 0 },
293 { "dbr", 'd', 0, 0, 0 },
294 };
295
296 static int open_dump_file PARAMS ((enum dump_file_index, tree));
297 static void close_dump_file PARAMS ((enum dump_file_index,
298 void (*) (FILE *, rtx), rtx));
299
300 /* Other flags saying which kinds of debugging dump have been requested. */
301
302 int rtl_dump_and_exit;
303 int flag_print_asm_name;
304 static int version_flag;
305 static char *filename;
306 enum graph_dump_types graph_dump_format;
307
308 /* Name for output file of assembly code, specified with -o. */
309
310 char *asm_file_name;
311
312 /* Value of the -G xx switch, and whether it was passed or not. */
313 int g_switch_value;
314 int g_switch_set;
315
316 /* Type(s) of debugging information we are producing (if any).
317 See flags.h for the definitions of the different possible
318 types of debugging information. */
319 enum debug_info_type write_symbols = NO_DEBUG;
320
321 /* Level of debugging information we are producing. See flags.h
322 for the definitions of the different possible levels. */
323 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
324
325 /* Nonzero means use GNU-only extensions in the generated symbolic
326 debugging information. */
327 /* Currently, this only has an effect when write_symbols is set to
328 DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
329 int use_gnu_debug_info_extensions = 0;
330
331 /* Nonzero means do optimizations. -O.
332 Particular numeric values stand for particular amounts of optimization;
333 thus, -O2 stores 2 here. However, the optimizations beyond the basic
334 ones are not controlled directly by this variable. Instead, they are
335 controlled by individual `flag_...' variables that are defaulted
336 based on this variable. */
337
338 int optimize = 0;
339
340 /* Nonzero means optimize for size. -Os.
341 The only valid values are zero and non-zero. When optimize_size is
342 non-zero, optimize defaults to 2, but certain individual code
343 bloating optimizations are disabled. */
344
345 int optimize_size = 0;
346
347 /* Nonzero if we should exit after parsing options. */
348 static int exit_after_options = 0;
349
350 /* The FUNCTION_DECL for the function currently being compiled,
351 or 0 if between functions. */
352 tree current_function_decl;
353
354 /* Set to the FUNC_BEGIN label of the current function, or NULL_TREE
355 if none. */
356 tree current_function_func_begin_label;
357
358 /* Nonzero if doing dwarf2 duplicate elimination. */
359
360 int flag_eliminate_dwarf2_dups = 0;
361
362 /* Nonzero if generating code to do profiling. */
363
364 int profile_flag = 0;
365
366 /* Nonzero if generating code to profile program flow graph arcs. */
367
368 int profile_arc_flag = 0;
369
370 /* Nonzero if we should not attempt to generate thread-safe
371 code to profile program flow graph arcs. */
372
373 int flag_unsafe_profile_arcs = 0;
374
375 /* Nonzero if generating info for gcov to calculate line test coverage. */
376
377 int flag_test_coverage = 0;
378
379 /* Nonzero indicates that branch taken probabilities should be calculated. */
380
381 int flag_branch_probabilities = 0;
382
383 /* Nonzero if basic blocks should be reordered. */
384
385 int flag_reorder_blocks = 0;
386
387 /* Nonzero if functions should be reordered. */
388
389 int flag_reorder_functions = 0;
390
391 /* Nonzero if registers should be renamed. */
392
393 int flag_rename_registers = 0;
394 int flag_cprop_registers = 0;
395
396 /* Nonzero for -pedantic switch: warn about anything
397 that standard spec forbids. */
398
399 int pedantic = 0;
400
401 /* Temporarily suppress certain warnings.
402 This is set while reading code from a system header file. */
403
404 int in_system_header = 0;
405
406 /* Don't print functions as they are compiled. -quiet. */
407
408 int quiet_flag = 0;
409
410 /* Print times taken by the various passes. -ftime-report. */
411
412 int time_report = 0;
413
414 /* Print memory still in use at end of compilation (which may have little
415 to do with peak memory consumption). -fmem-report. */
416
417 int mem_report = 0;
418
419 /* Non-zero means to collect statistics which might be expensive
420 and to print them when we are done. */
421 int flag_detailed_statistics = 0;
422
423 \f
424 /* -f flags. */
425
426 /* Nonzero means `char' should be signed. */
427
428 int flag_signed_char;
429
430 /* Nonzero means give an enum type only as many bytes as it needs. */
431
432 int flag_short_enums;
433
434 /* Nonzero for -fcaller-saves: allocate values in regs that need to
435 be saved across function calls, if that produces overall better code.
436 Optional now, so people can test it. */
437
438 #ifdef DEFAULT_CALLER_SAVES
439 int flag_caller_saves = 1;
440 #else
441 int flag_caller_saves = 0;
442 #endif
443
444 /* Nonzero if structures and unions should be returned in memory.
445
446 This should only be defined if compatibility with another compiler or
447 with an ABI is needed, because it results in slower code. */
448
449 #ifndef DEFAULT_PCC_STRUCT_RETURN
450 #define DEFAULT_PCC_STRUCT_RETURN 1
451 #endif
452
453 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
454
455 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
456
457 /* Nonzero for -fforce-mem: load memory value into a register
458 before arithmetic on it. This makes better cse but slower compilation. */
459
460 int flag_force_mem = 0;
461
462 /* Nonzero for -fforce-addr: load memory address into a register before
463 reference to memory. This makes better cse but slower compilation. */
464
465 int flag_force_addr = 0;
466
467 /* Nonzero for -fdefer-pop: don't pop args after each function call;
468 instead save them up to pop many calls' args with one insns. */
469
470 int flag_defer_pop = 0;
471
472 /* Nonzero for -ffloat-store: don't allocate floats and doubles
473 in extended-precision registers. */
474
475 int flag_float_store = 0;
476
477 /* Nonzero for -fcse-follow-jumps:
478 have cse follow jumps to do a more extensive job. */
479
480 int flag_cse_follow_jumps;
481
482 /* Nonzero for -fcse-skip-blocks:
483 have cse follow a branch around a block. */
484 int flag_cse_skip_blocks;
485
486 /* Nonzero for -fexpensive-optimizations:
487 perform miscellaneous relatively-expensive optimizations. */
488 int flag_expensive_optimizations;
489
490 /* Nonzero for -fthread-jumps:
491 have jump optimize output of loop. */
492
493 int flag_thread_jumps;
494
495 /* Nonzero enables strength-reduction in loop.c. */
496
497 int flag_strength_reduce = 0;
498
499 /* Nonzero enables loop unrolling in unroll.c. Only loops for which the
500 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
501 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
502 unrolled. */
503
504 int flag_unroll_loops;
505
506 /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
507 This is generally not a win. */
508
509 int flag_unroll_all_loops;
510
511 /* Nonzero enables prefetch optimizations for arrays in loops. */
512
513 int flag_prefetch_loop_arrays;
514
515 /* Nonzero forces all invariant computations in loops to be moved
516 outside the loop. */
517
518 int flag_move_all_movables = 0;
519
520 /* Nonzero forces all general induction variables in loops to be
521 strength reduced. */
522
523 int flag_reduce_all_givs = 0;
524
525 /* Nonzero to perform full register move optimization passes. This is the
526 default for -O2. */
527
528 int flag_regmove = 0;
529
530 /* Nonzero for -fwritable-strings:
531 store string constants in data segment and don't uniquize them. */
532
533 int flag_writable_strings = 0;
534
535 /* Nonzero means don't put addresses of constant functions in registers.
536 Used for compiling the Unix kernel, where strange substitutions are
537 done on the assembly output. */
538
539 int flag_no_function_cse = 0;
540
541 /* Nonzero for -fomit-frame-pointer:
542 don't make a frame pointer in simple functions that don't require one. */
543
544 int flag_omit_frame_pointer = 0;
545
546 /* Nonzero means place each function into its own section on those platforms
547 which support arbitrary section names and unlimited numbers of sections. */
548
549 int flag_function_sections = 0;
550
551 /* ... and similar for data. */
552
553 int flag_data_sections = 0;
554
555 /* Nonzero to inhibit use of define_optimization peephole opts. */
556
557 int flag_no_peephole = 0;
558
559 /* Nonzero allows GCC to optimize sibling and tail recursive calls. */
560
561 int flag_optimize_sibling_calls = 0;
562
563 /* Nonzero means the front end generally wants `errno' maintained by math
564 operations, like built-in SQRT. */
565
566 int flag_errno_math = 1;
567
568 /* Nonzero means that unsafe floating-point math optimizations are allowed
569 for the sake of speed. IEEE compliance is not guaranteed, and operations
570 are allowed to assume that their arguments and results are "normal"
571 (e.g., nonnegative for SQRT). */
572
573 int flag_unsafe_math_optimizations = 0;
574
575 /* Zero means that floating-point math operations cannot generate a
576 (user-visible) trap. This is the case, for example, in nonstop
577 IEEE 754 arithmetic. */
578
579 int flag_trapping_math = 1;
580
581 /* 0 means straightforward implementation of complex divide acceptable.
582 1 means wide ranges of inputs must work for complex divide.
583 2 means C99-like requirements for complex divide (not yet implemented). */
584
585 int flag_complex_divide_method = 0;
586
587 /* Nonzero means all references through pointers are volatile. */
588
589 int flag_volatile;
590
591 /* Nonzero means treat all global and extern variables as volatile. */
592
593 int flag_volatile_global;
594
595 /* Nonzero means treat all static variables as volatile. */
596
597 int flag_volatile_static;
598
599 /* Nonzero means just do syntax checking; don't output anything. */
600
601 int flag_syntax_only = 0;
602
603 /* Nonzero means perform global cse. */
604
605 static int flag_gcse;
606
607 /* Nonzero means perform loop optimizer. */
608
609 static int flag_loop_optimize;
610
611 /* Nonzero means perform crossjumping. */
612
613 static int flag_crossjumping;
614
615 /* Nonzero means perform if conversion. */
616
617 static int flag_if_conversion;
618
619 /* Nonzero means perform if conversion after reload. */
620
621 static int flag_if_conversion2;
622
623 /* Nonzero means to use global dataflow analysis to eliminate
624 useless null pointer tests. */
625
626 static int flag_delete_null_pointer_checks;
627
628 /* Nonzero means to do the enhanced load motion during gcse, which trys
629 to hoist loads by not killing them when a store to the same location
630 is seen. */
631
632 int flag_gcse_lm = 1;
633
634 /* Nonzero means to perform store motion after gcse, which will try to
635 move stores closer to the exit block. Its not very effective without
636 flag_gcse_lm. */
637
638 int flag_gcse_sm = 1;
639
640 /* Nonzero means to rerun cse after loop optimization. This increases
641 compilation time about 20% and picks up a few more common expressions. */
642
643 static int flag_rerun_cse_after_loop;
644
645 /* Nonzero means to run loop optimizations twice. */
646
647 int flag_rerun_loop_opt;
648
649 /* Nonzero for -finline-functions: ok to inline functions that look like
650 good inline candidates. */
651
652 int flag_inline_functions;
653
654 /* Nonzero for -fkeep-inline-functions: even if we make a function
655 go inline everywhere, keep its definition around for debugging
656 purposes. */
657
658 int flag_keep_inline_functions;
659
660 /* Nonzero means that functions will not be inlined. */
661
662 int flag_no_inline = 2;
663
664 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
665 not just because the tree inliner turned us off. */
666
667 int flag_really_no_inline = 2;
668
669 /* Nonzero means that we should emit static const variables
670 regardless of whether or not optimization is turned on. */
671
672 int flag_keep_static_consts = 1;
673
674 /* Nonzero means we should be saving declaration info into a .X file. */
675
676 int flag_gen_aux_info = 0;
677
678 /* Specified name of aux-info file. */
679
680 static char *aux_info_file_name;
681
682 /* Nonzero means make the text shared if supported. */
683
684 int flag_shared_data;
685
686 /* Nonzero means schedule into delayed branch slots if supported. */
687
688 int flag_delayed_branch;
689
690 /* Nonzero if we are compiling pure (sharable) code.
691 Value is 1 if we are doing "small" pic; value is 2 if we're doing
692 "large" pic. */
693
694 int flag_pic;
695
696 /* Set to the default thread-local storage (tls) model to use. */
697
698 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
699
700 /* Nonzero means generate extra code for exception handling and enable
701 exception handling. */
702
703 int flag_exceptions;
704
705 /* Nonzero means generate frame unwind info table when supported. */
706
707 int flag_unwind_tables = 0;
708
709 /* Nonzero means generate frame unwind info table exact at each insn boundary */
710
711 int flag_asynchronous_unwind_tables = 0;
712
713 /* Nonzero means don't place uninitialized global data in common storage
714 by default. */
715
716 int flag_no_common;
717
718 /* Nonzero means change certain warnings into errors.
719 Usually these are warnings about failure to conform to some standard. */
720
721 int flag_pedantic_errors = 0;
722
723 /* flag_schedule_insns means schedule insns within basic blocks (before
724 local_alloc).
725 flag_schedule_insns_after_reload means schedule insns after
726 global_alloc. */
727
728 int flag_schedule_insns = 0;
729 int flag_schedule_insns_after_reload = 0;
730
731 /* The following flags have effect only for scheduling before register
732 allocation:
733
734 flag_schedule_interblock means schedule insns accross basic blocks.
735 flag_schedule_speculative means allow speculative motion of non-load insns.
736 flag_schedule_speculative_load means allow speculative motion of some
737 load insns.
738 flag_schedule_speculative_load_dangerous allows speculative motion of more
739 load insns. */
740
741 int flag_schedule_interblock = 1;
742 int flag_schedule_speculative = 1;
743 int flag_schedule_speculative_load = 0;
744 int flag_schedule_speculative_load_dangerous = 0;
745
746 int flag_single_precision_constant;
747
748 /* flag_branch_on_count_reg means try to replace add-1,compare,branch tupple
749 by a cheaper branch on a count register. */
750 int flag_branch_on_count_reg = 1;
751
752 /* -finhibit-size-directive inhibits output of .size for ELF.
753 This is used only for compiling crtstuff.c,
754 and it may be extended to other effects
755 needed for crtstuff.c on other systems. */
756 int flag_inhibit_size_directive = 0;
757
758 /* -fverbose-asm causes extra commentary information to be produced in
759 the generated assembly code (to make it more readable). This option
760 is generally only of use to those who actually need to read the
761 generated assembly code (perhaps while debugging the compiler itself).
762 -fno-verbose-asm, the default, causes the extra information
763 to be omitted and is useful when comparing two assembler files. */
764
765 int flag_verbose_asm = 0;
766
767 /* -dA causes debug commentary information to be produced in
768 the generated assembly code (to make it more readable). This option
769 is generally only of use to those who actually need to read the
770 generated assembly code (perhaps while debugging the compiler itself).
771 Currently, this switch is only used by dwarfout.c; however, it is intended
772 to be a catchall for printing debug information in the assembler file. */
773
774 int flag_debug_asm = 0;
775
776 /* -dP causes the rtl to be emitted as a comment in assembly. */
777
778 int flag_dump_rtl_in_asm = 0;
779
780 /* -fgnu-linker specifies use of the GNU linker for initializations.
781 (Or, more generally, a linker that handles initializations.)
782 -fno-gnu-linker says that collect2 will be used. */
783 #ifdef USE_COLLECT2
784 int flag_gnu_linker = 0;
785 #else
786 int flag_gnu_linker = 1;
787 #endif
788
789 /* Nonzero means put zero initialized data in the bss section. */
790 int flag_zero_initialized_in_bss = 1;
791
792 /* Enable SSA. */
793 int flag_ssa = 0;
794
795 /* Enable ssa conditional constant propagation. */
796 int flag_ssa_ccp = 0;
797
798 /* Enable ssa aggressive dead code elimination. */
799 int flag_ssa_dce = 0;
800
801 /* Tag all structures with __attribute__(packed). */
802 int flag_pack_struct = 0;
803
804 /* Emit code to check for stack overflow; also may cause large objects
805 to be allocated dynamically. */
806 int flag_stack_check;
807
808 /* When non-NULL, indicates that whenever space is allocated on the
809 stack, the resulting stack pointer must not pass this
810 address---that is, for stacks that grow downward, the stack pointer
811 must always be greater than or equal to this address; for stacks
812 that grow upward, the stack pointer must be less than this address.
813 At present, the rtx may be either a REG or a SYMBOL_REF, although
814 the support provided depends on the backend. */
815 rtx stack_limit_rtx;
816
817 /* 0 if pointer arguments may alias each other. True in C.
818 1 if pointer arguments may not alias each other but may alias
819 global variables.
820 2 if pointer arguments may not alias each other and may not
821 alias global variables. True in Fortran.
822 This defaults to 0 for C. */
823 int flag_argument_noalias = 0;
824
825 /* Nonzero if we should do (language-dependent) alias analysis.
826 Typically, this analysis will assume that expressions of certain
827 types do not alias expressions of certain other types. Only used
828 if alias analysis (in general) is enabled. */
829 int flag_strict_aliasing = 0;
830
831 /* Instrument functions with calls at entry and exit, for profiling. */
832 int flag_instrument_function_entry_exit = 0;
833
834 /* Nonzero means ignore `#ident' directives. 0 means handle them.
835 On SVR4 targets, it also controls whether or not to emit a
836 string identifying the compiler. */
837
838 int flag_no_ident = 0;
839
840 /* This will perform a peephole pass before sched2. */
841 int flag_peephole2 = 0;
842
843 /* This will try to guess branch probabilities. */
844 int flag_guess_branch_prob = 0;
845
846 /* -fbounded-pointers causes gcc to compile pointers as composite
847 objects occupying three words: the pointer value, the base address
848 of the referent object, and the address immediately beyond the end
849 of the referent object. The base and extent allow us to perform
850 runtime bounds checking. -fbounded-pointers implies -fcheck-bounds. */
851 int flag_bounded_pointers = 0;
852
853 /* -fcheck-bounds causes gcc to generate array bounds checks.
854 For C, C++: defaults to value of flag_bounded_pointers.
855 For ObjC: defaults to off.
856 For Java: defaults to on.
857 For Fortran: defaults to off.
858 For CHILL: defaults to off. */
859 int flag_bounds_check = 0;
860
861 /* This will attempt to merge constant section constants, if 1 only
862 string constants and constants from constant pool, if 2 also constant
863 variables. */
864 int flag_merge_constants = 1;
865
866 /* If one, renumber instruction UIDs to reduce the number of
867 unused UIDs if there are a lot of instructions. If greater than
868 one, unconditionally renumber instruction UIDs. */
869 int flag_renumber_insns = 1;
870
871 /* Nonzero if we perform superblock formation. */
872
873 int flag_tracer = 0;
874
875 /* Values of the -falign-* flags: how much to align labels in code.
876 0 means `use default', 1 means `don't align'.
877 For each variable, there is an _log variant which is the power
878 of two not less than the variable, for .align output. */
879
880 int align_loops;
881 int align_loops_log;
882 int align_loops_max_skip;
883 int align_jumps;
884 int align_jumps_log;
885 int align_jumps_max_skip;
886 int align_labels;
887 int align_labels_log;
888 int align_labels_max_skip;
889 int align_functions;
890 int align_functions_log;
891
892 /* Table of supported debugging formats. */
893 static const struct
894 {
895 const char *const arg;
896 /* Since PREFERRED_DEBUGGING_TYPE isn't necessarily a
897 constant expression, we use NO_DEBUG in its place. */
898 const enum debug_info_type debug_type;
899 const int use_extensions_p;
900 const char *const description;
901 } *da,
902 debug_args[] =
903 {
904 { "", NO_DEBUG, DEFAULT_GDB_EXTENSIONS,
905 N_("Generate debugging info in default format") },
906 { "gdb", NO_DEBUG, 1, N_("Generate debugging info in default extended format") },
907 #ifdef DBX_DEBUGGING_INFO
908 { "stabs", DBX_DEBUG, 0, N_("Generate STABS format debug info") },
909 { "stabs+", DBX_DEBUG, 1, N_("Generate extended STABS format debug info") },
910 #endif
911 #ifdef DWARF_DEBUGGING_INFO
912 { "dwarf", DWARF_DEBUG, 0, N_("Generate DWARF-1 format debug info") },
913 { "dwarf+", DWARF_DEBUG, 1,
914 N_("Generate extended DWARF-1 format debug info") },
915 #endif
916 #ifdef DWARF2_DEBUGGING_INFO
917 { "dwarf-2", DWARF2_DEBUG, 0, N_("Generate DWARF-2 debug info") },
918 #endif
919 #ifdef XCOFF_DEBUGGING_INFO
920 { "xcoff", XCOFF_DEBUG, 0, N_("Generate XCOFF format debug info") },
921 { "xcoff+", XCOFF_DEBUG, 1, N_("Generate extended XCOFF format debug info") },
922 #endif
923 #ifdef SDB_DEBUGGING_INFO
924 { "coff", SDB_DEBUG, 0, N_("Generate COFF format debug info") },
925 #endif
926 #ifdef VMS_DEBUGGING_INFO
927 { "vms", VMS_DEBUG, 0, N_("Generate VMS format debug info") },
928 #endif
929 { 0, 0, 0, 0 }
930 };
931
932 typedef struct
933 {
934 const char *const string;
935 int *const variable;
936 const int on_value;
937 const char *const description;
938 }
939 lang_independent_options;
940
941 int flag_trapv = 0;
942
943 /* Add or remove a leading underscore from user symbols. */
944 int flag_leading_underscore = -1;
945
946 /* The user symbol prefix after having resolved same. */
947 const char *user_label_prefix;
948
949 static const param_info lang_independent_params[] = {
950 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT) \
951 { OPTION, DEFAULT, HELP },
952 #include "params.def"
953 #undef DEFPARAM
954 { NULL, 0, NULL }
955 };
956
957 /* A default for same. */
958 #ifndef USER_LABEL_PREFIX
959 #define USER_LABEL_PREFIX ""
960 #endif
961
962 /* Table of language-independent -f options.
963 STRING is the option name. VARIABLE is the address of the variable.
964 ON_VALUE is the value to store in VARIABLE
965 if `-fSTRING' is seen as an option.
966 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
967
968 static const lang_independent_options f_options[] =
969 {
970 {"eliminate-dwarf2-dups", &flag_eliminate_dwarf2_dups, 1,
971 N_("Perform DWARF2 duplicate elimination") },
972 {"float-store", &flag_float_store, 1,
973 N_("Do not store floats in registers") },
974 {"volatile", &flag_volatile, 1,
975 N_("Consider all mem refs through pointers as volatile") },
976 {"volatile-global", &flag_volatile_global, 1,
977 N_("Consider all mem refs to global data to be volatile") },
978 {"volatile-static", &flag_volatile_static, 1,
979 N_("Consider all mem refs to static data to be volatile") },
980 {"defer-pop", &flag_defer_pop, 1,
981 N_("Defer popping functions args from stack until later") },
982 {"omit-frame-pointer", &flag_omit_frame_pointer, 1,
983 N_("When possible do not generate stack frames") },
984 {"optimize-sibling-calls", &flag_optimize_sibling_calls, 1,
985 N_("Optimize sibling and tail recursive calls") },
986 {"tracer", &flag_tracer, 1,
987 N_("Perform superblock formation via tail duplication") },
988 {"cse-follow-jumps", &flag_cse_follow_jumps, 1,
989 N_("When running CSE, follow jumps to their targets") },
990 {"cse-skip-blocks", &flag_cse_skip_blocks, 1,
991 N_("When running CSE, follow conditional jumps") },
992 {"expensive-optimizations", &flag_expensive_optimizations, 1,
993 N_("Perform a number of minor, expensive optimizations") },
994 {"thread-jumps", &flag_thread_jumps, 1,
995 N_("Perform jump threading optimizations") },
996 {"strength-reduce", &flag_strength_reduce, 1,
997 N_("Perform strength reduction optimizations") },
998 {"unroll-loops", &flag_unroll_loops, 1,
999 N_("Perform loop unrolling when iteration count is known") },
1000 {"unroll-all-loops", &flag_unroll_all_loops, 1,
1001 N_("Perform loop unrolling for all loops") },
1002 {"prefetch-loop-arrays", &flag_prefetch_loop_arrays, 1,
1003 N_("Generate prefetch instructions, if available, for arrays in loops") },
1004 {"move-all-movables", &flag_move_all_movables, 1,
1005 N_("Force all loop invariant computations out of loops") },
1006 {"reduce-all-givs", &flag_reduce_all_givs, 1,
1007 N_("Strength reduce all loop general induction variables") },
1008 {"writable-strings", &flag_writable_strings, 1,
1009 N_("Store strings in writable data section") },
1010 {"peephole", &flag_no_peephole, 0,
1011 N_("Enable machine specific peephole optimizations") },
1012 {"force-mem", &flag_force_mem, 1,
1013 N_("Copy memory operands into registers before using") },
1014 {"force-addr", &flag_force_addr, 1,
1015 N_("Copy memory address constants into regs before using") },
1016 {"function-cse", &flag_no_function_cse, 0,
1017 N_("Allow function addresses to be held in registers") },
1018 {"inline-functions", &flag_inline_functions, 1,
1019 N_("Integrate simple functions into their callers") },
1020 {"keep-inline-functions", &flag_keep_inline_functions, 1,
1021 N_("Generate code for funcs even if they are fully inlined") },
1022 {"inline", &flag_no_inline, 0,
1023 N_("Pay attention to the 'inline' keyword") },
1024 {"keep-static-consts", &flag_keep_static_consts, 1,
1025 N_("Emit static const variables even if they are not used") },
1026 {"syntax-only", &flag_syntax_only, 1,
1027 N_("Check for syntax errors, then stop") },
1028 {"shared-data", &flag_shared_data, 1,
1029 N_("Mark data as shared rather than private") },
1030 {"caller-saves", &flag_caller_saves, 1,
1031 N_("Enable saving registers around function calls") },
1032 {"pcc-struct-return", &flag_pcc_struct_return, 1,
1033 N_("Return 'short' aggregates in memory, not registers") },
1034 {"reg-struct-return", &flag_pcc_struct_return, 0,
1035 N_("Return 'short' aggregates in registers") },
1036 {"delayed-branch", &flag_delayed_branch, 1,
1037 N_("Attempt to fill delay slots of branch instructions") },
1038 {"gcse", &flag_gcse, 1,
1039 N_("Perform the global common subexpression elimination") },
1040 {"gcse-lm", &flag_gcse_lm, 1,
1041 N_("Perform enhanced load motion during global subexpression elimination") },
1042 {"gcse-sm", &flag_gcse_sm, 1,
1043 N_("Perform store motion after global subexpression elimination") },
1044 {"loop-optimize", &flag_loop_optimize, 1,
1045 N_("Perform the loop optimizations") },
1046 {"crossjumping", &flag_crossjumping, 1,
1047 N_("Perform cross-jumping optimization") },
1048 {"if-conversion", &flag_if_conversion, 1,
1049 N_("Perform conversion of conditional jumps to branchless equivalents") },
1050 {"if-conversion2", &flag_if_conversion2, 1,
1051 N_("Perform conversion of conditional jumps to conditional execution") },
1052 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1,
1053 N_("Run CSE pass after loop optimizations") },
1054 {"rerun-loop-opt", &flag_rerun_loop_opt, 1,
1055 N_("Run the loop optimizer twice") },
1056 {"delete-null-pointer-checks", &flag_delete_null_pointer_checks, 1,
1057 N_("Delete useless null pointer checks") },
1058 {"schedule-insns", &flag_schedule_insns, 1,
1059 N_("Reschedule instructions before register allocation") },
1060 {"schedule-insns2", &flag_schedule_insns_after_reload, 1,
1061 N_("Reschedule instructions after register allocation") },
1062 {"sched-interblock",&flag_schedule_interblock, 1,
1063 N_("Enable scheduling across basic blocks") },
1064 {"sched-spec",&flag_schedule_speculative, 1,
1065 N_("Allow speculative motion of non-loads") },
1066 {"sched-spec-load",&flag_schedule_speculative_load, 1,
1067 N_("Allow speculative motion of some loads") },
1068 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1,
1069 N_("Allow speculative motion of more loads") },
1070 {"branch-count-reg",&flag_branch_on_count_reg, 1,
1071 N_("Replace add,compare,branch with branch on count reg") },
1072 {"pic", &flag_pic, 1,
1073 N_("Generate position independent code, if possible") },
1074 {"PIC", &flag_pic, 2, ""},
1075 {"exceptions", &flag_exceptions, 1,
1076 N_("Enable exception handling") },
1077 {"unwind-tables", &flag_unwind_tables, 1,
1078 N_("Just generate unwind tables for exception handling") },
1079 {"asynchronous-unwind-tables", &flag_asynchronous_unwind_tables, 1,
1080 N_("Generate unwind tables exact at each instruction boundary") },
1081 {"non-call-exceptions", &flag_non_call_exceptions, 1,
1082 N_("Support synchronous non-call exceptions") },
1083 {"profile-arcs", &profile_arc_flag, 1,
1084 N_("Insert arc based program profiling code") },
1085 {"unsafe-profile-arcs", &flag_unsafe_profile_arcs, 1,
1086 N_("Avoid thread safety profiling overhead") },
1087 {"test-coverage", &flag_test_coverage, 1,
1088 N_("Create data files needed by gcov") },
1089 {"branch-probabilities", &flag_branch_probabilities, 1,
1090 N_("Use profiling information for branch probabilities") },
1091 {"profile", &profile_flag, 1,
1092 N_("Enable basic program profiling code") },
1093 {"reorder-blocks", &flag_reorder_blocks, 1,
1094 N_("Reorder basic blocks to improve code placement") },
1095 {"reorder-functions", &flag_reorder_functions, 1,
1096 N_("Reorder functions to improve code placement") },
1097 {"rename-registers", &flag_rename_registers, 1,
1098 N_("Do the register renaming optimization pass") },
1099 {"cprop-registers", &flag_cprop_registers, 1,
1100 N_("Do the register copy-propagation optimization pass") },
1101 {"common", &flag_no_common, 0,
1102 N_("Do not put uninitialized globals in the common section") },
1103 {"inhibit-size-directive", &flag_inhibit_size_directive, 1,
1104 N_("Do not generate .size directives") },
1105 {"function-sections", &flag_function_sections, 1,
1106 N_("place each function into its own section") },
1107 {"data-sections", &flag_data_sections, 1,
1108 N_("place data items into their own section") },
1109 {"verbose-asm", &flag_verbose_asm, 1,
1110 N_("Add extra commentry to assembler output") },
1111 {"gnu-linker", &flag_gnu_linker, 1,
1112 N_("Output GNU ld formatted global initializers") },
1113 {"regmove", &flag_regmove, 1,
1114 N_("Enables a register move optimization") },
1115 {"optimize-register-move", &flag_regmove, 1,
1116 N_("Do the full regmove optimization pass") },
1117 {"pack-struct", &flag_pack_struct, 1,
1118 N_("Pack structure members together without holes") },
1119 {"stack-check", &flag_stack_check, 1,
1120 N_("Insert stack checking code into the program") },
1121 {"argument-alias", &flag_argument_noalias, 0,
1122 N_("Specify that arguments may alias each other & globals") },
1123 {"argument-noalias", &flag_argument_noalias, 1,
1124 N_("Assume arguments may alias globals but not each other") },
1125 {"argument-noalias-global", &flag_argument_noalias, 2,
1126 N_("Assume arguments do not alias each other or globals") },
1127 {"strict-aliasing", &flag_strict_aliasing, 1,
1128 N_("Assume strict aliasing rules apply") },
1129 {"align-loops", &align_loops, 0,
1130 N_("Align the start of loops") },
1131 {"align-jumps", &align_jumps, 0,
1132 N_("Align labels which are only reached by jumping") },
1133 {"align-labels", &align_labels, 0,
1134 N_("Align all labels") },
1135 {"align-functions", &align_functions, 0,
1136 N_("Align the start of functions") },
1137 {"merge-constants", &flag_merge_constants, 1,
1138 N_("Attempt to merge identical constants accross compilation units") },
1139 {"merge-all-constants", &flag_merge_constants, 2,
1140 N_("Attempt to merge identical constants and constant variables") },
1141 {"dump-unnumbered", &flag_dump_unnumbered, 1,
1142 N_("Suppress output of instruction numbers and line number notes in debugging dumps") },
1143 {"instrument-functions", &flag_instrument_function_entry_exit, 1,
1144 N_("Instrument function entry/exit with profiling calls") },
1145 {"zero-initialized-in-bss", &flag_zero_initialized_in_bss, 1,
1146 N_("Put zero initialized data in the bss section") },
1147 {"ssa", &flag_ssa, 1,
1148 N_("Enable SSA optimizations") },
1149 {"ssa-ccp", &flag_ssa_ccp, 1,
1150 N_("Enable SSA conditional constant propagation") },
1151 {"ssa-dce", &flag_ssa_dce, 1,
1152 N_("Enable aggressive SSA dead code elimination") },
1153 {"leading-underscore", &flag_leading_underscore, 1,
1154 N_("External symbols have a leading underscore") },
1155 {"ident", &flag_no_ident, 0,
1156 N_("Process #ident directives") },
1157 { "peephole2", &flag_peephole2, 1,
1158 N_("Enables an rtl peephole pass run before sched2") },
1159 { "guess-branch-probability", &flag_guess_branch_prob, 1,
1160 N_("Enables guessing of branch probabilities") },
1161 {"math-errno", &flag_errno_math, 1,
1162 N_("Set errno after built-in math functions") },
1163 {"trapping-math", &flag_trapping_math, 1,
1164 N_("Floating-point operations can trap") },
1165 {"unsafe-math-optimizations", &flag_unsafe_math_optimizations, 1,
1166 N_("Allow math optimizations that may violate IEEE or ANSI standards") },
1167 {"bounded-pointers", &flag_bounded_pointers, 1,
1168 N_("Compile pointers as triples: value, base & end") },
1169 {"bounds-check", &flag_bounds_check, 1,
1170 N_("Generate code to check bounds before dereferencing pointers and arrays") },
1171 {"single-precision-constant", &flag_single_precision_constant, 1,
1172 N_("Convert floating point constant to single precision constant") },
1173 {"time-report", &time_report, 1,
1174 N_("Report time taken by each compiler pass at end of run") },
1175 {"mem-report", &mem_report, 1,
1176 N_("Report on permanent memory allocation at end of run") },
1177 { "trapv", &flag_trapv, 1,
1178 N_("Trap for signed overflow in addition / subtraction / multiplication") },
1179 };
1180
1181 /* Table of language-specific options. */
1182
1183 static const struct lang_opt
1184 {
1185 const char *const option;
1186 const char *const description;
1187 }
1188 documented_lang_options[] =
1189 {
1190 /* In order not to overload the --help output, the convention
1191 used here is to only describe those options which are not
1192 enabled by default. */
1193
1194 { "-ansi",
1195 N_("Compile just for ISO C89") },
1196 { "-std= ",
1197 N_("Determine language standard") },
1198
1199 { "-fsigned-bitfields", "" },
1200 { "-funsigned-bitfields",
1201 N_("Make bit-fields by unsigned by default") },
1202 { "-fno-signed-bitfields", "" },
1203 { "-fno-unsigned-bitfields","" },
1204 { "-fsigned-char",
1205 N_("Make 'char' be signed by default") },
1206 { "-funsigned-char",
1207 N_("Make 'char' be unsigned by default") },
1208 { "-fno-signed-char", "" },
1209 { "-fno-unsigned-char", "" },
1210
1211 { "-fasm", "" },
1212 { "-fno-asm",
1213 N_("Do not recognize the 'asm' keyword") },
1214 { "-fbuiltin", "" },
1215 { "-fno-builtin",
1216 N_("Do not recognize any built in functions") },
1217 { "-fhosted",
1218 N_("Assume normal C execution environment") },
1219 { "-fno-hosted", "" },
1220 { "-ffreestanding",
1221 N_("Assume that standard libraries & main might not exist") },
1222 { "-fno-freestanding", "" },
1223 { "-fcond-mismatch",
1224 N_("Allow different types as args of ? operator") },
1225 { "-fno-cond-mismatch", "" },
1226 { "-fdollars-in-identifiers",
1227 N_("Allow the use of $ inside identifiers") },
1228 { "-fno-dollars-in-identifiers", "" },
1229 { "-fpreprocessed", "" },
1230 { "-fno-preprocessed", "" },
1231 { "-fshort-double",
1232 N_("Use the same size for double as for float") },
1233 { "-fno-short-double", "" },
1234 { "-fshort-enums",
1235 N_("Use the smallest fitting integer to hold enums") },
1236 { "-fno-short-enums", "" },
1237 { "-fshort-wchar",
1238 N_("Override the underlying type for wchar_t to `unsigned short'") },
1239 { "-fno-short-wchar", "" },
1240
1241 { "-Wall",
1242 N_("Enable most warning messages") },
1243 { "-Wbad-function-cast",
1244 N_("Warn about casting functions to incompatible types") },
1245 { "-Wno-bad-function-cast", "" },
1246 { "-Wmissing-format-attribute",
1247 N_("Warn about functions which might be candidates for format attributes") },
1248 { "-Wno-missing-format-attribute", "" },
1249 { "-Wcast-qual",
1250 N_("Warn about casts which discard qualifiers") },
1251 { "-Wno-cast-qual", "" },
1252 { "-Wchar-subscripts",
1253 N_("Warn about subscripts whose type is 'char'") },
1254 { "-Wno-char-subscripts", "" },
1255 { "-Wcomment",
1256 N_("Warn if nested comments are detected") },
1257 { "-Wno-comment", "" },
1258 { "-Wcomments",
1259 N_("Warn if nested comments are detected") },
1260 { "-Wno-comments", "" },
1261 { "-Wconversion",
1262 N_("Warn about possibly confusing type conversions") },
1263 { "-Wno-conversion", "" },
1264 { "-Wdiv-by-zero", "" },
1265 { "-Wno-div-by-zero",
1266 N_("Do not warn about compile-time integer division by zero") },
1267 { "-Wfloat-equal",
1268 N_("Warn about testing equality of floating point numbers") },
1269 { "-Wno-float-equal", "" },
1270 { "-Wformat",
1271 N_("Warn about printf/scanf/strftime/strfmon format anomalies") },
1272 { "-Wno-format", "" },
1273 { "-Wformat-extra-args", "" },
1274 { "-Wno-format-extra-args",
1275 N_("Don't warn about too many arguments to format functions") },
1276 { "-Wformat-nonliteral",
1277 N_("Warn about non-string-literal format strings") },
1278 { "-Wno-format-nonliteral", "" },
1279 { "-Wformat-security",
1280 N_("Warn about possible security problems with format functions") },
1281 { "-Wno-format-security", "" },
1282 { "-Wformat-y2k", "" },
1283 { "-Wno-format-y2k",
1284 N_("Don't warn about strftime formats yielding 2 digit years") },
1285 { "-Wimplicit-function-declaration",
1286 N_("Warn about implicit function declarations") },
1287 { "-Wno-implicit-function-declaration", "" },
1288 { "-Werror-implicit-function-declaration", "" },
1289 { "-Wimplicit-int",
1290 N_("Warn when a declaration does not specify a type") },
1291 { "-Wno-implicit-int", "" },
1292 { "-Wimplicit", "" },
1293 { "-Wno-implicit", "" },
1294 { "-Wimport",
1295 N_("Warn about the use of the #import directive") },
1296 { "-Wno-import", "" },
1297 { "-Wlong-long","" },
1298 { "-Wno-long-long",
1299 N_("Do not warn about using 'long long' when -pedantic") },
1300 { "-Wmain",
1301 N_("Warn about suspicious declarations of main") },
1302 { "-Wno-main", "" },
1303 { "-Wmissing-braces",
1304 N_("Warn about possibly missing braces around initializers") },
1305 { "-Wno-missing-braces", "" },
1306 { "-Wmissing-declarations",
1307 N_("Warn about global funcs without previous declarations") },
1308 { "-Wno-missing-declarations", "" },
1309 { "-Wmissing-prototypes",
1310 N_("Warn about global funcs without prototypes") },
1311 { "-Wno-missing-prototypes", "" },
1312 { "-Wmultichar",
1313 N_("Warn about use of multicharacter literals") },
1314 { "-Wno-multichar", "" },
1315 { "-Wnested-externs",
1316 N_("Warn about externs not at file scope level") },
1317 { "-Wno-nested-externs", "" },
1318 { "-Wparentheses",
1319 N_("Warn about possible missing parentheses") },
1320 { "-Wno-parentheses", "" },
1321 { "-Wpointer-arith",
1322 N_("Warn about function pointer arithmetic") },
1323 { "-Wno-pointer-arith", "" },
1324 { "-Wredundant-decls",
1325 N_("Warn about multiple declarations of the same object") },
1326 { "-Wno-redundant-decls", "" },
1327 { "-Wreturn-type",
1328 N_("Warn whenever a function's return-type defaults to int") },
1329 { "-Wno-return-type", "" },
1330 { "-Wsequence-point",
1331 N_("Warn about possible violations of sequence point rules") },
1332 { "-Wno-sequence-point", "" },
1333 { "-Wsign-compare",
1334 N_("Warn about signed/unsigned comparisons") },
1335 { "-Wno-sign-compare", "" },
1336 { "-Wstrict-prototypes",
1337 N_("Warn about non-prototyped function decls") },
1338 { "-Wno-strict-prototypes", "" },
1339 { "-Wtraditional",
1340 N_("Warn about constructs whose meanings change in ISO C") },
1341 { "-Wno-traditional", "" },
1342 { "-Wtrigraphs",
1343 N_("Warn when trigraphs are encountered") },
1344 { "-Wno-trigraphs", "" },
1345 { "-Wundef", "" },
1346 { "-Wno-undef", "" },
1347 { "-Wunknown-pragmas",
1348 N_("Warn about unrecognized pragmas") },
1349 { "-Wno-unknown-pragmas", "" },
1350 { "-Wwrite-strings",
1351 N_("Mark strings as 'const char *'") },
1352 { "-Wno-write-strings", "" },
1353
1354 #define DEFINE_LANG_NAME(NAME) { NULL, NAME },
1355
1356 #include "options.h"
1357
1358 };
1359
1360 /* Here is a table, controlled by the tm.h file, listing each -m switch
1361 and which bits in `target_switches' it should set or clear.
1362 If VALUE is positive, it is bits to set.
1363 If VALUE is negative, -VALUE is bits to clear.
1364 (The sign bit is not used so there is no confusion.) */
1365
1366 static const struct
1367 {
1368 const char *const name;
1369 const int value;
1370 const char *const description;
1371 }
1372 target_switches[] = TARGET_SWITCHES;
1373
1374 /* This table is similar, but allows the switch to have a value. */
1375
1376 #ifdef TARGET_OPTIONS
1377 static const struct
1378 {
1379 const char *const prefix;
1380 const char **const variable;
1381 const char *const description;
1382 }
1383 target_options[] = TARGET_OPTIONS;
1384 #endif
1385 \f
1386 /* Options controlling warnings. */
1387
1388 /* Don't print warning messages. -w. */
1389
1390 int inhibit_warnings = 0;
1391
1392 /* Don't suppress warnings from system headers. -Wsystem-headers. */
1393
1394 int warn_system_headers = 0;
1395
1396 /* Print various extra warnings. -W. */
1397
1398 int extra_warnings = 0;
1399
1400 /* Treat warnings as errors. -Werror. */
1401
1402 int warnings_are_errors = 0;
1403
1404 /* Nonzero to warn about unused variables, functions et.al. */
1405
1406 int warn_unused_function;
1407 int warn_unused_label;
1408 int warn_unused_parameter;
1409 int warn_unused_variable;
1410 int warn_unused_value;
1411
1412 /* Nonzero to warn about code which is never reached. */
1413
1414 int warn_notreached;
1415
1416 /* Nonzero to warn about variables used before they are initialized. */
1417
1418 int warn_uninitialized;
1419
1420 /* Nonzero means warn about all declarations which shadow others. */
1421
1422 int warn_shadow;
1423
1424 /* Warn if a switch on an enum, that does not have a default case,
1425 fails to have a case for every enum value. */
1426
1427 int warn_switch;
1428
1429 /* Warn if a switch does not have a default case. */
1430
1431 int warn_switch_default;
1432
1433 /* Warn if a switch on an enum fails to have a case for every enum
1434 value (regardless of the presence or otherwise of a default case). */
1435
1436 int warn_switch_enum;
1437
1438 /* Nonzero means warn about function definitions that default the return type
1439 or that use a null return and have a return-type other than void. */
1440
1441 int warn_return_type;
1442
1443 /* Nonzero means warn about pointer casts that increase the required
1444 alignment of the target type (and might therefore lead to a crash
1445 due to a misaligned access). */
1446
1447 int warn_cast_align;
1448
1449 /* Nonzero means warn about any objects definitions whose size is larger
1450 than N bytes. Also want about function definitions whose returned
1451 values are larger than N bytes. The value N is in `larger_than_size'. */
1452
1453 int warn_larger_than;
1454 HOST_WIDE_INT larger_than_size;
1455
1456 /* Nonzero means warn if inline function is too large. */
1457
1458 int warn_inline;
1459
1460 /* Warn if a function returns an aggregate,
1461 since there are often incompatible calling conventions for doing this. */
1462
1463 int warn_aggregate_return;
1464
1465 /* Warn if packed attribute on struct is unnecessary and inefficient. */
1466
1467 int warn_packed;
1468
1469 /* Warn when gcc pads a structure to an alignment boundary. */
1470
1471 int warn_padded;
1472
1473 /* Warn when an optimization pass is disabled. */
1474
1475 int warn_disabled_optimization;
1476
1477 /* Warn about functions which might be candidates for attribute noreturn. */
1478
1479 int warn_missing_noreturn;
1480
1481 /* Nonzero means warn about uses of __attribute__((deprecated))
1482 declarations. */
1483
1484 int warn_deprecated_decl = 1;
1485
1486 /* Likewise for -W. */
1487
1488 static const lang_independent_options W_options[] =
1489 {
1490 {"unused-function", &warn_unused_function, 1,
1491 N_("Warn when a function is unused") },
1492 {"unused-label", &warn_unused_label, 1,
1493 N_("Warn when a label is unused") },
1494 {"unused-parameter", &warn_unused_parameter, 1,
1495 N_("Warn when a function parameter is unused") },
1496 {"unused-variable", &warn_unused_variable, 1,
1497 N_("Warn when a variable is unused") },
1498 {"unused-value", &warn_unused_value, 1,
1499 N_("Warn when an expression value is unused") },
1500 {"system-headers", &warn_system_headers, 1,
1501 N_("Do not suppress warnings from system headers") },
1502 {"error", &warnings_are_errors, 1,
1503 N_("Treat all warnings as errors") },
1504 {"shadow", &warn_shadow, 1,
1505 N_("Warn when one local variable shadows another") },
1506 {"switch", &warn_switch, 1,
1507 N_("Warn about enumerated switches, with no default, missing a case") },
1508 {"switch-default", &warn_switch_default, 1,
1509 N_("Warn about enumerated switches missing a default case") },
1510 {"switch-enum", &warn_switch_enum, 1,
1511 N_("Warn about all enumerated switches missing a specific case") },
1512 {"aggregate-return", &warn_aggregate_return, 1,
1513 N_("Warn about returning structures, unions or arrays") },
1514 {"cast-align", &warn_cast_align, 1,
1515 N_("Warn about pointer casts which increase alignment") },
1516 {"unreachable-code", &warn_notreached, 1,
1517 N_("Warn about code that will never be executed") },
1518 {"uninitialized", &warn_uninitialized, 1,
1519 N_("Warn about uninitialized automatic variables") },
1520 {"inline", &warn_inline, 1,
1521 N_("Warn when an inlined function cannot be inlined") },
1522 {"packed", &warn_packed, 1,
1523 N_("Warn when the packed attribute has no effect on struct layout") },
1524 {"padded", &warn_padded, 1,
1525 N_("Warn when padding is required to align struct members") },
1526 {"disabled-optimization", &warn_disabled_optimization, 1,
1527 N_("Warn when an optimization pass is disabled") },
1528 {"deprecated-declarations", &warn_deprecated_decl, 1,
1529 N_("Warn about uses of __attribute__((deprecated)) declarations") },
1530 {"missing-noreturn", &warn_missing_noreturn, 1,
1531 N_("Warn about functions which might be candidates for attribute noreturn") }
1532 };
1533
1534 void
1535 set_Wunused (setting)
1536 int setting;
1537 {
1538 warn_unused_function = setting;
1539 warn_unused_label = setting;
1540 /* Unused function parameter warnings are reported when either ``-W
1541 -Wunused'' or ``-Wunused-parameter'' is specified. Differentiate
1542 -Wunused by setting WARN_UNUSED_PARAMETER to -1. */
1543 if (!setting)
1544 warn_unused_parameter = 0;
1545 else if (!warn_unused_parameter)
1546 warn_unused_parameter = -1;
1547 warn_unused_variable = setting;
1548 warn_unused_value = setting;
1549 }
1550
1551 /* The following routines are useful in setting all the flags that
1552 -ffast-math and -fno-fast-math imply. */
1553
1554 void
1555 set_fast_math_flags (int set)
1556 {
1557 flag_trapping_math = !set;
1558 flag_unsafe_math_optimizations = set;
1559 flag_errno_math = !set;
1560 }
1561
1562 /* Return true iff flags are set as if -ffast-math. */
1563 bool
1564 fast_math_flags_set_p ()
1565 {
1566 return (!flag_trapping_math
1567 && flag_unsafe_math_optimizations
1568 && !flag_errno_math);
1569 }
1570
1571 \f
1572 /* Output files for assembler code (real compiler output)
1573 and debugging dumps. */
1574
1575 FILE *asm_out_file;
1576 FILE *aux_info_file;
1577 FILE *rtl_dump_file = NULL;
1578
1579 /* Decode the string P as an integral parameter.
1580 If the string is indeed an integer return its numeric value else
1581 issue an Invalid Option error for the option PNAME and return DEFVAL.
1582 If PNAME is zero just return DEFVAL, do not call error. */
1583
1584 int
1585 read_integral_parameter (p, pname, defval)
1586 const char *p;
1587 const char *pname;
1588 const int defval;
1589 {
1590 const char *endp = p;
1591
1592 while (*endp)
1593 {
1594 if (ISDIGIT (*endp))
1595 endp++;
1596 else
1597 break;
1598 }
1599
1600 if (*endp != 0)
1601 {
1602 if (pname != 0)
1603 error ("invalid option `%s'", pname);
1604 return defval;
1605 }
1606
1607 return atoi (p);
1608 }
1609 \f
1610 /* This calls abort and is used to avoid problems when abort if a macro.
1611 It is used when we need to pass the address of abort. */
1612
1613 void
1614 do_abort ()
1615 {
1616 abort ();
1617 }
1618
1619 /* When `malloc.c' is compiled with `rcheck' defined,
1620 it calls this function to report clobberage. */
1621
1622 void
1623 botch (s)
1624 const char *s ATTRIBUTE_UNUSED;
1625 {
1626 abort ();
1627 }
1628 \f
1629 /* Return the logarithm of X, base 2, considering X unsigned,
1630 if X is a power of 2. Otherwise, returns -1.
1631
1632 This should be used via the `exact_log2' macro. */
1633
1634 int
1635 exact_log2_wide (x)
1636 unsigned HOST_WIDE_INT x;
1637 {
1638 int log = 0;
1639 /* Test for 0 or a power of 2. */
1640 if (x == 0 || x != (x & -x))
1641 return -1;
1642 while ((x >>= 1) != 0)
1643 log++;
1644 return log;
1645 }
1646
1647 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1648 If X is 0, return -1.
1649
1650 This should be used via the floor_log2 macro. */
1651
1652 int
1653 floor_log2_wide (x)
1654 unsigned HOST_WIDE_INT x;
1655 {
1656 int log = -1;
1657 while (x != 0)
1658 log++,
1659 x >>= 1;
1660 return log;
1661 }
1662
1663 /* Handler for fatal signals, such as SIGSEGV. These are transformed
1664 into ICE messages, which is much more user friendly. */
1665
1666 static void
1667 crash_signal (signo)
1668 int signo;
1669 {
1670 internal_error ("internal error: %s", strsignal (signo));
1671 }
1672
1673 /* Strip off a legitimate source ending from the input string NAME of
1674 length LEN. Rather than having to know the names used by all of
1675 our front ends, we strip off an ending of a period followed by
1676 up to five characters. (Java uses ".class".) */
1677
1678 void
1679 strip_off_ending (name, len)
1680 char *name;
1681 int len;
1682 {
1683 int i;
1684 for (i = 2; i < 6 && len > i; i++)
1685 {
1686 if (name[len - i] == '.')
1687 {
1688 name[len - i] = '\0';
1689 break;
1690 }
1691 }
1692 }
1693
1694 /* Output a quoted string. */
1695
1696 void
1697 output_quoted_string (asm_file, string)
1698 FILE *asm_file;
1699 const char *string;
1700 {
1701 #ifdef OUTPUT_QUOTED_STRING
1702 OUTPUT_QUOTED_STRING (asm_file, string);
1703 #else
1704 char c;
1705
1706 putc ('\"', asm_file);
1707 while ((c = *string++) != 0)
1708 {
1709 if (ISPRINT (c))
1710 {
1711 if (c == '\"' || c == '\\')
1712 putc ('\\', asm_file);
1713 putc (c, asm_file);
1714 }
1715 else
1716 fprintf (asm_file, "\\%03o", (unsigned char) c);
1717 }
1718 putc ('\"', asm_file);
1719 #endif
1720 }
1721
1722 /* Output NAME into FILE after having turned it into something
1723 usable as an identifier in a target's assembly file. */
1724 void
1725 output_clean_symbol_name (file, name)
1726 FILE *file;
1727 const char *name;
1728 {
1729 /* Make a copy of NAME. */
1730 char *id = xstrdup (name);
1731
1732 /* Make it look like a valid identifier for an assembler. */
1733 clean_symbol_name (id);
1734
1735 fputs (id, file);
1736 free (id);
1737 }
1738
1739
1740 /* Output a file name in the form wanted by System V. */
1741
1742 void
1743 output_file_directive (asm_file, input_name)
1744 FILE *asm_file;
1745 const char *input_name;
1746 {
1747 int len = strlen (input_name);
1748 const char *na = input_name + len;
1749
1750 /* NA gets INPUT_NAME sans directory names. */
1751 while (na > input_name)
1752 {
1753 if (IS_DIR_SEPARATOR (na[-1]))
1754 break;
1755 na--;
1756 }
1757
1758 #ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
1759 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
1760 #else
1761 #ifdef ASM_OUTPUT_SOURCE_FILENAME
1762 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
1763 #else
1764 fprintf (asm_file, "\t.file\t");
1765 output_quoted_string (asm_file, na);
1766 fputc ('\n', asm_file);
1767 #endif
1768 #endif
1769 }
1770 \f
1771 /* Routine to open a dump file. Return true if the dump file is enabled. */
1772
1773 static int
1774 open_dump_file (index, decl)
1775 enum dump_file_index index;
1776 tree decl;
1777 {
1778 char *dump_name;
1779 const char *open_arg;
1780 char seq[16];
1781
1782 if (! dump_file[index].enabled)
1783 return 0;
1784
1785 timevar_push (TV_DUMP);
1786 if (rtl_dump_file != NULL)
1787 fclose (rtl_dump_file);
1788
1789 sprintf (seq, DUMPFILE_FORMAT, index);
1790
1791 if (! dump_file[index].initialized)
1792 {
1793 /* If we've not initialized the files, do so now. */
1794 if (graph_dump_format != no_graph
1795 && dump_file[index].graph_dump_p)
1796 {
1797 dump_name = concat (seq, dump_file[index].extension, NULL);
1798 clean_graph_dump_file (dump_base_name, dump_name);
1799 free (dump_name);
1800 }
1801 dump_file[index].initialized = 1;
1802 open_arg = "w";
1803 }
1804 else
1805 open_arg = "a";
1806
1807 dump_name = concat (dump_base_name, seq,
1808 dump_file[index].extension, NULL);
1809
1810 rtl_dump_file = fopen (dump_name, open_arg);
1811 if (rtl_dump_file == NULL)
1812 fatal_io_error ("can't open %s", dump_name);
1813
1814 free (dump_name);
1815
1816 if (decl)
1817 fprintf (rtl_dump_file, "\n;; Function %s%s\n\n",
1818 (*lang_hooks.decl_printable_name) (decl, 2),
1819 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
1820 ? " (hot)"
1821 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
1822 ? " (unlikely executed)"
1823 : "");
1824
1825 timevar_pop (TV_DUMP);
1826 return 1;
1827 }
1828
1829 /* Routine to close a dump file. */
1830
1831 static void
1832 close_dump_file (index, func, insns)
1833 enum dump_file_index index;
1834 void (*func) PARAMS ((FILE *, rtx));
1835 rtx insns;
1836 {
1837 if (! rtl_dump_file)
1838 return;
1839
1840 timevar_push (TV_DUMP);
1841 if (insns
1842 && graph_dump_format != no_graph
1843 && dump_file[index].graph_dump_p)
1844 {
1845 char seq[16];
1846 char *suffix;
1847
1848 sprintf (seq, DUMPFILE_FORMAT, index);
1849 suffix = concat (seq, dump_file[index].extension, NULL);
1850 print_rtl_graph_with_bb (dump_base_name, suffix, insns);
1851 free (suffix);
1852 }
1853
1854 if (func && insns)
1855 func (rtl_dump_file, insns);
1856
1857 fflush (rtl_dump_file);
1858 fclose (rtl_dump_file);
1859
1860 rtl_dump_file = NULL;
1861 timevar_pop (TV_DUMP);
1862 }
1863
1864 /* Do any final processing required for the declarations in VEC, of
1865 which there are LEN. We write out inline functions and variables
1866 that have been deferred until this point, but which are required.
1867 Returns non-zero if anything was put out. */
1868
1869 int
1870 wrapup_global_declarations (vec, len)
1871 tree *vec;
1872 int len;
1873 {
1874 tree decl;
1875 int i;
1876 int reconsider;
1877 int output_something = 0;
1878
1879 for (i = 0; i < len; i++)
1880 {
1881 decl = vec[i];
1882
1883 /* We're not deferring this any longer. */
1884 DECL_DEFER_OUTPUT (decl) = 0;
1885
1886 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
1887 (*lang_hooks.finish_incomplete_decl) (decl);
1888 }
1889
1890 /* Now emit any global variables or functions that we have been
1891 putting off. We need to loop in case one of the things emitted
1892 here references another one which comes earlier in the list. */
1893 do
1894 {
1895 reconsider = 0;
1896 for (i = 0; i < len; i++)
1897 {
1898 decl = vec[i];
1899
1900 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
1901 continue;
1902
1903 /* Don't write out static consts, unless we still need them.
1904
1905 We also keep static consts if not optimizing (for debugging),
1906 unless the user specified -fno-keep-static-consts.
1907 ??? They might be better written into the debug information.
1908 This is possible when using DWARF.
1909
1910 A language processor that wants static constants to be always
1911 written out (even if it is not used) is responsible for
1912 calling rest_of_decl_compilation itself. E.g. the C front-end
1913 calls rest_of_decl_compilation from finish_decl.
1914 One motivation for this is that is conventional in some
1915 environments to write things like:
1916 static const char rcsid[] = "... version string ...";
1917 intending to force the string to be in the executable.
1918
1919 A language processor that would prefer to have unneeded
1920 static constants "optimized away" would just defer writing
1921 them out until here. E.g. C++ does this, because static
1922 constants are often defined in header files.
1923
1924 ??? A tempting alternative (for both C and C++) would be
1925 to force a constant to be written if and only if it is
1926 defined in a main file, as opposed to an include file. */
1927
1928 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
1929 {
1930 bool needed = 1;
1931
1932 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1933 /* needed */;
1934 else if (DECL_COMDAT (decl))
1935 needed = 0;
1936 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
1937 && (optimize || !flag_keep_static_consts
1938 || DECL_ARTIFICIAL (decl)))
1939 needed = 0;
1940
1941 if (needed)
1942 {
1943 reconsider = 1;
1944 rest_of_decl_compilation (decl, NULL, 1, 1);
1945 }
1946 }
1947
1948 if (TREE_CODE (decl) == FUNCTION_DECL
1949 && DECL_INITIAL (decl) != 0
1950 && DECL_SAVED_INSNS (decl) != 0
1951 && (flag_keep_inline_functions
1952 || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
1953 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
1954 {
1955 reconsider = 1;
1956 output_inline_function (decl);
1957 }
1958 }
1959
1960 if (reconsider)
1961 output_something = 1;
1962 }
1963 while (reconsider);
1964
1965 return output_something;
1966 }
1967
1968 /* Issue appropriate warnings for the global declarations in VEC (of
1969 which there are LEN). Output debugging information for them. */
1970
1971 void
1972 check_global_declarations (vec, len)
1973 tree *vec;
1974 int len;
1975 {
1976 tree decl;
1977 int i;
1978
1979 for (i = 0; i < len; i++)
1980 {
1981 decl = vec[i];
1982
1983 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
1984 && ! TREE_ASM_WRITTEN (decl))
1985 /* Cancel the RTL for this decl so that, if debugging info
1986 output for global variables is still to come,
1987 this one will be omitted. */
1988 SET_DECL_RTL (decl, NULL_RTX);
1989
1990 /* Warn about any function
1991 declared static but not defined.
1992 We don't warn about variables,
1993 because many programs have static variables
1994 that exist only to get some text into the object file. */
1995 if (TREE_CODE (decl) == FUNCTION_DECL
1996 && (warn_unused_function
1997 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1998 && DECL_INITIAL (decl) == 0
1999 && DECL_EXTERNAL (decl)
2000 && ! DECL_ARTIFICIAL (decl)
2001 && ! TREE_PUBLIC (decl))
2002 {
2003 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2004 pedwarn_with_decl (decl,
2005 "`%s' used but never defined");
2006 else
2007 warning_with_decl (decl,
2008 "`%s' declared `static' but never defined");
2009 /* This symbol is effectively an "extern" declaration now. */
2010 TREE_PUBLIC (decl) = 1;
2011 assemble_external (decl);
2012 }
2013
2014 /* Warn about static fns or vars defined but not used. */
2015 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
2016 || (warn_unused_variable && TREE_CODE (decl) == VAR_DECL))
2017 && ! TREE_USED (decl)
2018 /* The TREE_USED bit for file-scope decls is kept in the identifier,
2019 to handle multiple external decls in different scopes. */
2020 && ! TREE_USED (DECL_NAME (decl))
2021 && ! DECL_EXTERNAL (decl)
2022 && ! TREE_PUBLIC (decl)
2023 /* Global register variables must be declared to reserve them. */
2024 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
2025 /* Otherwise, ask the language. */
2026 && (*lang_hooks.decls.warn_unused_global) (decl))
2027 warning_with_decl (decl, "`%s' defined but not used");
2028
2029 timevar_push (TV_SYMOUT);
2030 (*debug_hooks->global_decl) (decl);
2031 timevar_pop (TV_SYMOUT);
2032 }
2033 }
2034
2035 /* Save the current INPUT_FILENAME and LINENO on the top entry in the
2036 INPUT_FILE_STACK. Push a new entry for FILE and LINE, and set the
2037 INPUT_FILENAME and LINENO accordingly. */
2038
2039 void
2040 push_srcloc (file, line)
2041 const char *file;
2042 int line;
2043 {
2044 struct file_stack *fs;
2045
2046 if (input_file_stack)
2047 {
2048 input_file_stack->name = input_filename;
2049 input_file_stack->line = lineno;
2050 }
2051
2052 fs = (struct file_stack *) xmalloc (sizeof (struct file_stack));
2053 fs->name = input_filename = file;
2054 fs->line = lineno = line;
2055 fs->next = input_file_stack;
2056 input_file_stack = fs;
2057 input_file_stack_tick++;
2058 }
2059
2060 /* Pop the top entry off the stack of presently open source files.
2061 Restore the INPUT_FILENAME and LINENO from the new topmost entry on
2062 the stack. */
2063
2064 void
2065 pop_srcloc ()
2066 {
2067 struct file_stack *fs;
2068
2069 fs = input_file_stack;
2070 input_file_stack = fs->next;
2071 free (fs);
2072 input_file_stack_tick++;
2073 /* The initial source file is never popped. */
2074 if (!input_file_stack)
2075 abort ();
2076 input_filename = input_file_stack->name;
2077 lineno = input_file_stack->line;
2078 }
2079
2080 /* Compile an entire translation unit. Write a file of assembly
2081 output and various debugging dumps. */
2082
2083 static void
2084 compile_file ()
2085 {
2086 tree globals;
2087
2088 /* Initialize yet another pass. */
2089
2090 init_final (main_input_filename);
2091 init_branch_prob (dump_base_name);
2092
2093 timevar_push (TV_PARSE);
2094
2095 /* Call the parser, which parses the entire file (calling
2096 rest_of_compilation for each function). */
2097 (*lang_hooks.parse_file) (set_yydebug);
2098
2099 /* In case there were missing block closers,
2100 get us back to the global binding level. */
2101 (*lang_hooks.clear_binding_stack) ();
2102
2103 /* Compilation is now finished except for writing
2104 what's left of the symbol table output. */
2105 timevar_pop (TV_PARSE);
2106
2107 if (flag_syntax_only)
2108 return;
2109
2110 globals = (*lang_hooks.decls.getdecls) ();
2111
2112 /* Really define vars that have had only a tentative definition.
2113 Really output inline functions that must actually be callable
2114 and have not been output so far. */
2115
2116 {
2117 int len = list_length (globals);
2118 tree *vec = (tree *) xmalloc (sizeof (tree) * len);
2119 int i;
2120 tree decl;
2121
2122 /* Process the decls in reverse order--earliest first.
2123 Put them into VEC from back to front, then take out from front. */
2124
2125 for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
2126 vec[len - i - 1] = decl;
2127
2128 wrapup_global_declarations (vec, len);
2129
2130 /* This must occur after the loop to output deferred functions. Else
2131 the profiler initializer would not be emitted if all the functions
2132 in this compilation unit were deferred.
2133
2134 output_func_start_profiler can not cause any additional functions or
2135 data to need to be output, so it need not be in the deferred function
2136 loop above. */
2137 output_func_start_profiler ();
2138
2139 check_global_declarations (vec, len);
2140
2141 /* Clean up. */
2142 free (vec);
2143 }
2144
2145 /* Write out any pending weak symbol declarations. */
2146
2147 weak_finish ();
2148
2149 /* Do dbx symbols. */
2150 timevar_push (TV_SYMOUT);
2151
2152 #ifdef DWARF2_UNWIND_INFO
2153 if (dwarf2out_do_frame ())
2154 dwarf2out_frame_finish ();
2155 #endif
2156
2157 (*debug_hooks->finish) (main_input_filename);
2158 timevar_pop (TV_SYMOUT);
2159
2160 /* Output some stuff at end of file if nec. */
2161
2162 dw2_output_indirect_constants ();
2163
2164 end_final (dump_base_name);
2165
2166 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
2167 {
2168 timevar_push (TV_DUMP);
2169 open_dump_file (DFI_bp, NULL);
2170
2171 end_branch_prob ();
2172
2173 close_dump_file (DFI_bp, NULL, NULL_RTX);
2174 timevar_pop (TV_DUMP);
2175 }
2176
2177 #ifdef ASM_FILE_END
2178 ASM_FILE_END (asm_out_file);
2179 #endif
2180
2181 /* Attach a special .ident directive to the end of the file to identify
2182 the version of GCC which compiled this code. The format of the .ident
2183 string is patterned after the ones produced by native SVR4 compilers. */
2184 #ifdef IDENT_ASM_OP
2185 if (!flag_no_ident)
2186 fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
2187 IDENT_ASM_OP, version_string);
2188 #endif
2189
2190 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
2191 {
2192 timevar_push (TV_DUMP);
2193 dump_combine_total_stats (rtl_dump_file);
2194 close_dump_file (DFI_combine, NULL, NULL_RTX);
2195 timevar_pop (TV_DUMP);
2196 }
2197 }
2198 \f
2199 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
2200 and TYPE_DECL nodes.
2201
2202 This does nothing for local (non-static) variables, unless the
2203 variable is a register variable with an ASMSPEC. In that case, or
2204 if the variable is not an automatic, it sets up the RTL and
2205 outputs any assembler code (label definition, storage allocation
2206 and initialization).
2207
2208 DECL is the declaration. If ASMSPEC is nonzero, it specifies
2209 the assembler symbol name to be used. TOP_LEVEL is nonzero
2210 if this declaration is not within a function. */
2211
2212 void
2213 rest_of_decl_compilation (decl, asmspec, top_level, at_end)
2214 tree decl;
2215 const char *asmspec;
2216 int top_level;
2217 int at_end;
2218 {
2219 /* Declarations of variables, and of functions defined elsewhere. */
2220
2221 /* The most obvious approach, to put an #ifndef around where
2222 this macro is used, doesn't work since it's inside a macro call. */
2223 #ifndef ASM_FINISH_DECLARE_OBJECT
2224 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP, END)
2225 #endif
2226
2227 /* We deferred calling assemble_alias so that we could collect
2228 other attributes such as visibility. Emit the alias now. */
2229 {
2230 tree alias;
2231 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
2232 if (alias)
2233 {
2234 alias = TREE_VALUE (TREE_VALUE (alias));
2235 alias = get_identifier (TREE_STRING_POINTER (alias));
2236 assemble_alias (decl, alias);
2237 }
2238 }
2239
2240 /* Forward declarations for nested functions are not "external",
2241 but we need to treat them as if they were. */
2242 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
2243 || TREE_CODE (decl) == FUNCTION_DECL)
2244 {
2245 timevar_push (TV_VARCONST);
2246
2247 if (asmspec)
2248 make_decl_rtl (decl, asmspec);
2249
2250 /* Don't output anything when a tentative file-scope definition
2251 is seen. But at end of compilation, do output code for them. */
2252 if (at_end || !DECL_DEFER_OUTPUT (decl))
2253 assemble_variable (decl, top_level, at_end, 0);
2254 if (decl == last_assemble_variable_decl)
2255 {
2256 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
2257 top_level, at_end);
2258 }
2259
2260 timevar_pop (TV_VARCONST);
2261 }
2262 else if (DECL_REGISTER (decl) && asmspec != 0)
2263 {
2264 if (decode_reg_name (asmspec) >= 0)
2265 {
2266 SET_DECL_RTL (decl, NULL_RTX);
2267 make_decl_rtl (decl, asmspec);
2268 }
2269 else
2270 {
2271 error ("invalid register name `%s' for register variable", asmspec);
2272 DECL_REGISTER (decl) = 0;
2273 if (!top_level)
2274 expand_decl (decl);
2275 }
2276 }
2277 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2278 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2279 && TREE_CODE (decl) == TYPE_DECL)
2280 {
2281 timevar_push (TV_SYMOUT);
2282 dbxout_symbol (decl, 0);
2283 timevar_pop (TV_SYMOUT);
2284 }
2285 #endif
2286 #ifdef SDB_DEBUGGING_INFO
2287 else if (write_symbols == SDB_DEBUG && top_level
2288 && TREE_CODE (decl) == TYPE_DECL)
2289 {
2290 timevar_push (TV_SYMOUT);
2291 sdbout_symbol (decl, 0);
2292 timevar_pop (TV_SYMOUT);
2293 }
2294 #endif
2295 }
2296
2297 /* Called after finishing a record, union or enumeral type. */
2298
2299 void
2300 rest_of_type_compilation (type, toplev)
2301 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO) || defined (SDB_DEBUGGING_INFO)
2302 tree type;
2303 int toplev;
2304 #else
2305 tree type ATTRIBUTE_UNUSED;
2306 int toplev ATTRIBUTE_UNUSED;
2307 #endif
2308 {
2309 timevar_push (TV_SYMOUT);
2310 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2311 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2312 dbxout_symbol (TYPE_STUB_DECL (type), !toplev);
2313 #endif
2314 #ifdef SDB_DEBUGGING_INFO
2315 if (write_symbols == SDB_DEBUG)
2316 sdbout_symbol (TYPE_STUB_DECL (type), !toplev);
2317 #endif
2318 #ifdef DWARF2_DEBUGGING_INFO
2319 if ((write_symbols == DWARF2_DEBUG
2320 || write_symbols == VMS_AND_DWARF2_DEBUG)
2321 && toplev)
2322 dwarf2out_decl (TYPE_STUB_DECL (type));
2323 #endif
2324 timevar_pop (TV_SYMOUT);
2325 }
2326
2327 /* This is called from finish_function (within langhooks.parse_file)
2328 after each top-level definition is parsed.
2329 It is supposed to compile that function or variable
2330 and output the assembler code for it.
2331 After we return, the tree storage is freed. */
2332
2333 void
2334 rest_of_compilation (decl)
2335 tree decl;
2336 {
2337 rtx insns;
2338 int tem;
2339 int failure = 0;
2340 int rebuild_label_notes_after_reload;
2341 int register_life_up_to_date;
2342
2343 timevar_push (TV_REST_OF_COMPILATION);
2344
2345 /* Now that we're out of the frontend, we shouldn't have any more
2346 CONCATs anywhere. */
2347 generating_concat_p = 0;
2348
2349 /* When processing delayed functions, prepare_function_start() won't
2350 have been run to re-initialize it. */
2351 cse_not_expected = ! optimize;
2352
2353 /* First, make sure that NOTE_BLOCK is set correctly for each
2354 NOTE_INSN_BLOCK_BEG/NOTE_INSN_BLOCK_END note. */
2355 if (!cfun->x_whole_function_mode_p)
2356 identify_blocks ();
2357
2358 /* In function-at-a-time mode, we do not attempt to keep the BLOCK
2359 tree in sensible shape. So, we just recalculate it here. */
2360 if (cfun->x_whole_function_mode_p)
2361 reorder_blocks ();
2362
2363 init_flow ();
2364
2365 /* If we are reconsidering an inline function
2366 at the end of compilation, skip the stuff for making it inline. */
2367
2368 if (DECL_SAVED_INSNS (decl) == 0)
2369 {
2370 int inlinable = 0;
2371 tree parent;
2372 const char *lose;
2373
2374 /* If this is nested inside an inlined external function, pretend
2375 it was only declared. Since we cannot inline such functions,
2376 generating code for this one is not only not necessary but will
2377 confuse some debugging output writers. */
2378 for (parent = DECL_CONTEXT (current_function_decl);
2379 parent != NULL_TREE;
2380 parent = get_containing_scope (parent))
2381 if (TREE_CODE (parent) == FUNCTION_DECL
2382 && DECL_INLINE (parent) && DECL_EXTERNAL (parent))
2383 {
2384 DECL_INITIAL (decl) = 0;
2385 goto exit_rest_of_compilation;
2386 }
2387
2388 /* If requested, consider whether to make this function inline. */
2389 if ((DECL_INLINE (decl) && !flag_no_inline)
2390 || flag_inline_functions)
2391 {
2392 timevar_push (TV_INTEGRATION);
2393 lose = function_cannot_inline_p (decl);
2394 timevar_pop (TV_INTEGRATION);
2395 if (lose || ! optimize)
2396 {
2397 if (warn_inline && DECL_INLINE (decl))
2398 warning_with_decl (decl, lose);
2399 DECL_ABSTRACT_ORIGIN (decl) = 0;
2400 /* Don't really compile an extern inline function.
2401 If we can't make it inline, pretend
2402 it was only declared. */
2403 if (DECL_EXTERNAL (decl))
2404 {
2405 DECL_INITIAL (decl) = 0;
2406 goto exit_rest_of_compilation;
2407 }
2408 }
2409 else
2410 /* ??? Note that this has the effect of making it look
2411 like "inline" was specified for a function if we choose
2412 to inline it. This isn't quite right, but it's
2413 probably not worth the trouble to fix. */
2414 inlinable = DECL_INLINE (decl) = 1;
2415 }
2416
2417 insns = get_insns ();
2418
2419 /* Dump the rtl code if we are dumping rtl. */
2420
2421 if (open_dump_file (DFI_rtl, decl))
2422 {
2423 if (DECL_SAVED_INSNS (decl))
2424 fprintf (rtl_dump_file, ";; (integrable)\n\n");
2425 close_dump_file (DFI_rtl, print_rtl, insns);
2426 }
2427
2428 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
2429 sorts of eh initialization. Delay this until after the
2430 initial rtl dump so that we can see the original nesting. */
2431 convert_from_eh_region_ranges ();
2432
2433 /* If function is inline, and we don't yet know whether to
2434 compile it by itself, defer decision till end of compilation.
2435 finish_compilation will call rest_of_compilation again
2436 for those functions that need to be output. Also defer those
2437 functions that we are supposed to defer. */
2438
2439 if (inlinable
2440 || (DECL_INLINE (decl)
2441 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2442 && ! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
2443 && ! flag_keep_inline_functions)
2444 || DECL_EXTERNAL (decl))))
2445 DECL_DEFER_OUTPUT (decl) = 1;
2446
2447 if (DECL_INLINE (decl))
2448 /* DWARF wants separate debugging info for abstract and
2449 concrete instances of all inline functions, including those
2450 declared inline but not inlined, and those inlined even
2451 though they weren't declared inline. Conveniently, that's
2452 what DECL_INLINE means at this point. */
2453 (*debug_hooks->deferred_inline_function) (decl);
2454
2455 if (DECL_DEFER_OUTPUT (decl))
2456 {
2457 /* If -Wreturn-type, we have to do a bit of compilation. We just
2458 want to call cleanup the cfg to figure out whether or not we can
2459 fall off the end of the function; we do the minimum amount of
2460 work necessary to make that safe. */
2461 if (warn_return_type)
2462 {
2463 int saved_optimize = optimize;
2464
2465 optimize = 0;
2466 rebuild_jump_labels (insns);
2467 find_exception_handler_labels ();
2468 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2469 cleanup_cfg (CLEANUP_PRE_SIBCALL | CLEANUP_PRE_LOOP);
2470 optimize = saved_optimize;
2471
2472 /* CFG is no longer maintained up-to-date. */
2473 free_bb_for_insn ();
2474 }
2475
2476 current_function_nothrow = nothrow_function_p ();
2477 if (current_function_nothrow)
2478 /* Now we know that this can't throw; set the flag for the benefit
2479 of other functions later in this translation unit. */
2480 TREE_NOTHROW (current_function_decl) = 1;
2481
2482 timevar_push (TV_INTEGRATION);
2483 save_for_inline (decl);
2484 timevar_pop (TV_INTEGRATION);
2485 DECL_SAVED_INSNS (decl)->inlinable = inlinable;
2486 goto exit_rest_of_compilation;
2487 }
2488
2489 /* If specified extern inline but we aren't inlining it, we are
2490 done. This goes for anything that gets here with DECL_EXTERNAL
2491 set, not just things with DECL_INLINE. */
2492 if (DECL_EXTERNAL (decl))
2493 goto exit_rest_of_compilation;
2494 }
2495
2496 /* If we're emitting a nested function, make sure its parent gets
2497 emitted as well. Doing otherwise confuses debug info. */
2498 {
2499 tree parent;
2500 for (parent = DECL_CONTEXT (current_function_decl);
2501 parent != NULL_TREE;
2502 parent = get_containing_scope (parent))
2503 if (TREE_CODE (parent) == FUNCTION_DECL)
2504 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
2505 }
2506
2507 /* We are now committed to emitting code for this function. Do any
2508 preparation, such as emitting abstract debug info for the inline
2509 before it gets mangled by optimization. */
2510 if (DECL_INLINE (decl))
2511 (*debug_hooks->outlining_inline_function) (decl);
2512
2513 /* Remove any notes we don't need. That will make iterating
2514 over the instruction sequence faster, and allow the garbage
2515 collector to reclaim the memory used by the notes. */
2516 remove_unnecessary_notes ();
2517 reorder_blocks ();
2518
2519 ggc_collect ();
2520
2521 /* Initialize some variables used by the optimizers. */
2522 init_function_for_compilation ();
2523
2524 if (! DECL_DEFER_OUTPUT (decl))
2525 TREE_ASM_WRITTEN (decl) = 1;
2526
2527 /* Now that integrate will no longer see our rtl, we need not
2528 distinguish between the return value of this function and the
2529 return value of called functions. Also, we can remove all SETs
2530 of subregs of hard registers; they are only here because of
2531 integrate. Also, we can now initialize pseudos intended to
2532 carry magic hard reg data throughout the function. */
2533 rtx_equal_function_value_matters = 0;
2534 purge_hard_subreg_sets (get_insns ());
2535
2536 /* Early return if there were errors. We can run afoul of our
2537 consistency checks, and there's not really much point in fixing them.
2538 Don't return yet if -Wreturn-type; we need to do cleanup_cfg. */
2539 if (((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
2540 || errorcount || sorrycount)
2541 goto exit_rest_of_compilation;
2542
2543 timevar_push (TV_JUMP);
2544 open_dump_file (DFI_sibling, decl);
2545 insns = get_insns ();
2546 rebuild_jump_labels (insns);
2547 find_exception_handler_labels ();
2548 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2549
2550 delete_unreachable_blocks ();
2551
2552 /* Turn NOTE_INSN_PREDICTIONs into branch predictions. */
2553 note_prediction_to_br_prob ();
2554
2555 /* We may have potential sibling or tail recursion sites. Select one
2556 (of possibly multiple) methods of performing the call. */
2557 if (flag_optimize_sibling_calls)
2558 {
2559 rtx insn;
2560 optimize_sibling_and_tail_recursive_calls ();
2561
2562 /* There is pass ordering problem - we must lower NOTE_INSN_PREDICTION
2563 notes before simplifying cfg and we must do lowering after sibcall
2564 that unhides parts of RTL chain and cleans up the CFG.
2565
2566 Until sibcall is replaced by tree-level optimizer, lets just
2567 sweep away the NOTE_INSN_PREDICTION notes that leaked out. */
2568 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2569 if (GET_CODE (insn) == NOTE
2570 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_PREDICTION)
2571 delete_insn (insn);
2572 }
2573 close_dump_file (DFI_sibling, print_rtl, get_insns ());
2574 timevar_pop (TV_JUMP);
2575
2576 scope_to_insns_initialize ();
2577 /* Complete generation of exception handling code. */
2578 find_exception_handler_labels ();
2579 if (doing_eh (0))
2580 {
2581 timevar_push (TV_JUMP);
2582 open_dump_file (DFI_eh, decl);
2583
2584 finish_eh_generation ();
2585
2586 close_dump_file (DFI_eh, print_rtl, get_insns ());
2587 timevar_pop (TV_JUMP);
2588 }
2589
2590 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
2591 generation, which might create new sets. */
2592 emit_initial_value_sets ();
2593
2594 #ifdef FINALIZE_PIC
2595 /* If we are doing position-independent code generation, now
2596 is the time to output special prologues and epilogues.
2597 We do not want to do this earlier, because it just clutters
2598 up inline functions with meaningless insns. */
2599 if (flag_pic)
2600 FINALIZE_PIC;
2601 #endif
2602
2603 insns = get_insns ();
2604
2605 /* Copy any shared structure that should not be shared. */
2606 unshare_all_rtl (current_function_decl, insns);
2607
2608 #ifdef SETJMP_VIA_SAVE_AREA
2609 /* This must be performed before virtual register instantiation.
2610 Please be aware the everything in the compiler that can look
2611 at the RTL up to this point must understand that REG_SAVE_AREA
2612 is just like a use of the REG contained inside. */
2613 if (current_function_calls_alloca)
2614 optimize_save_area_alloca (insns);
2615 #endif
2616
2617 /* Instantiate all virtual registers. */
2618 instantiate_virtual_regs (current_function_decl, insns);
2619
2620 open_dump_file (DFI_jump, decl);
2621
2622 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
2623 are initialized and to compute whether control can drop off the end
2624 of the function. */
2625
2626 timevar_push (TV_JUMP);
2627 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
2628 before jump optimization switches branch directions. */
2629 expected_value_to_br_prob ();
2630
2631 reg_scan (insns, max_reg_num (), 0);
2632 rebuild_jump_labels (insns);
2633 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2634 if (rtl_dump_file)
2635 dump_flow_info (rtl_dump_file);
2636 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
2637 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2638
2639 /* CFG is no longer maintained up-to-date. */
2640 free_bb_for_insn ();
2641 copy_loop_headers (insns);
2642 purge_line_number_notes (insns);
2643
2644 timevar_pop (TV_JUMP);
2645 close_dump_file (DFI_jump, print_rtl, insns);
2646
2647 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
2648 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
2649 {
2650 goto exit_rest_of_compilation;
2651 }
2652
2653 /* Long term, this should probably move before the jump optimizer too,
2654 but I didn't want to disturb the rtl_dump_and_exit and related
2655 stuff at this time. */
2656 if (optimize > 0 && flag_ssa)
2657 {
2658 /* Convert to SSA form. */
2659
2660 timevar_push (TV_TO_SSA);
2661 open_dump_file (DFI_ssa, decl);
2662
2663 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2664 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2665 convert_to_ssa ();
2666
2667 close_dump_file (DFI_ssa, print_rtl_with_bb, insns);
2668 timevar_pop (TV_TO_SSA);
2669
2670 /* Perform sparse conditional constant propagation, if requested. */
2671 if (flag_ssa_ccp)
2672 {
2673 timevar_push (TV_SSA_CCP);
2674 open_dump_file (DFI_ssa_ccp, decl);
2675
2676 ssa_const_prop ();
2677
2678 close_dump_file (DFI_ssa_ccp, print_rtl_with_bb, get_insns ());
2679 timevar_pop (TV_SSA_CCP);
2680 }
2681
2682 /* It would be useful to cleanup the CFG at this point, but block
2683 merging and possibly other transformations might leave a PHI
2684 node in the middle of a basic block, which is a strict no-no. */
2685
2686 /* The SSA implementation uses basic block numbers in its phi
2687 nodes. Thus, changing the control-flow graph or the basic
2688 blocks, e.g., calling find_basic_blocks () or cleanup_cfg (),
2689 may cause problems. */
2690
2691 if (flag_ssa_dce)
2692 {
2693 /* Remove dead code. */
2694
2695 timevar_push (TV_SSA_DCE);
2696 open_dump_file (DFI_ssa_dce, decl);
2697
2698 insns = get_insns ();
2699 ssa_eliminate_dead_code ();
2700
2701 close_dump_file (DFI_ssa_dce, print_rtl_with_bb, insns);
2702 timevar_pop (TV_SSA_DCE);
2703 }
2704
2705 /* Convert from SSA form. */
2706
2707 timevar_push (TV_FROM_SSA);
2708 open_dump_file (DFI_ussa, decl);
2709
2710 convert_from_ssa ();
2711 /* New registers have been created. Rescan their usage. */
2712 reg_scan (insns, max_reg_num (), 1);
2713
2714 close_dump_file (DFI_ussa, print_rtl_with_bb, insns);
2715 timevar_pop (TV_FROM_SSA);
2716
2717 ggc_collect ();
2718 /* CFG is no longer maintained up-to-date. */
2719 free_bb_for_insn ();
2720 }
2721
2722 timevar_push (TV_JUMP);
2723
2724 if (flag_delete_null_pointer_checks || flag_if_conversion)
2725 {
2726 open_dump_file (DFI_null, decl);
2727 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2728 if (rtl_dump_file)
2729 dump_flow_info (rtl_dump_file);
2730 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2731
2732 /* Try to identify useless null pointer tests and delete them. */
2733 if (flag_delete_null_pointer_checks)
2734 delete_null_pointer_checks (insns);
2735
2736 timevar_push (TV_IFCVT);
2737 if (flag_if_conversion)
2738 if_convert (0);
2739 timevar_pop (TV_IFCVT);
2740 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2741 close_dump_file (DFI_null, print_rtl_with_bb, insns);
2742 }
2743
2744 /* Jump optimization, and the removal of NULL pointer checks, may
2745 have reduced the number of instructions substantially. CSE, and
2746 future passes, allocate arrays whose dimensions involve the
2747 maximum instruction UID, so if we can reduce the maximum UID
2748 we'll save big on memory. */
2749 renumber_insns (rtl_dump_file);
2750 if (optimize)
2751 compute_bb_for_insn (get_max_uid ());
2752 timevar_pop (TV_JUMP);
2753
2754 close_dump_file (DFI_jump, print_rtl_with_bb, insns);
2755
2756 ggc_collect ();
2757
2758 /* Perform common subexpression elimination.
2759 Nonzero value from `cse_main' means that jumps were simplified
2760 and some code may now be unreachable, so do
2761 jump optimization again. */
2762
2763 if (optimize > 0)
2764 {
2765 open_dump_file (DFI_cse, decl);
2766 if (rtl_dump_file)
2767 dump_flow_info (rtl_dump_file);
2768 timevar_push (TV_CSE);
2769
2770 reg_scan (insns, max_reg_num (), 1);
2771
2772 tem = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2773 if (tem)
2774 rebuild_jump_labels (insns);
2775 purge_all_dead_edges (0);
2776
2777 delete_trivially_dead_insns (insns, max_reg_num ());
2778
2779 /* If we are not running more CSE passes, then we are no longer
2780 expecting CSE to be run. But always rerun it in a cheap mode. */
2781 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
2782
2783 if (tem || optimize > 1)
2784 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2785 /* Try to identify useless null pointer tests and delete them. */
2786 if (flag_delete_null_pointer_checks || flag_thread_jumps)
2787 {
2788 timevar_push (TV_JUMP);
2789
2790 if (flag_delete_null_pointer_checks)
2791 delete_null_pointer_checks (insns);
2792 /* CFG is no longer maintained up-to-date. */
2793 timevar_pop (TV_JUMP);
2794 }
2795
2796 /* The second pass of jump optimization is likely to have
2797 removed a bunch more instructions. */
2798 renumber_insns (rtl_dump_file);
2799 compute_bb_for_insn (get_max_uid ());
2800
2801 timevar_pop (TV_CSE);
2802 close_dump_file (DFI_cse, print_rtl_with_bb, insns);
2803 }
2804
2805 open_dump_file (DFI_addressof, decl);
2806
2807 purge_addressof (insns);
2808 if (optimize)
2809 purge_all_dead_edges (0);
2810 reg_scan (insns, max_reg_num (), 1);
2811
2812 close_dump_file (DFI_addressof, print_rtl, insns);
2813
2814 ggc_collect ();
2815
2816 /* Perform global cse. */
2817
2818 if (optimize > 0 && flag_gcse)
2819 {
2820 int save_csb, save_cfj;
2821 int tem2 = 0;
2822
2823 timevar_push (TV_GCSE);
2824 open_dump_file (DFI_gcse, decl);
2825
2826 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2827 tem = gcse_main (insns, rtl_dump_file);
2828 rebuild_jump_labels (insns);
2829 delete_trivially_dead_insns (insns, max_reg_num ());
2830
2831 save_csb = flag_cse_skip_blocks;
2832 save_cfj = flag_cse_follow_jumps;
2833 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
2834
2835 /* If -fexpensive-optimizations, re-run CSE to clean up things done
2836 by gcse. */
2837 if (flag_expensive_optimizations)
2838 {
2839 timevar_push (TV_CSE);
2840 reg_scan (insns, max_reg_num (), 1);
2841 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2842 purge_all_dead_edges (0);
2843 delete_trivially_dead_insns (insns, max_reg_num ());
2844 timevar_pop (TV_CSE);
2845 cse_not_expected = !flag_rerun_cse_after_loop;
2846 }
2847
2848 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
2849 things up. Then possibly re-run CSE again. */
2850 while (tem || tem2)
2851 {
2852 tem = tem2 = 0;
2853 timevar_push (TV_JUMP);
2854 rebuild_jump_labels (insns);
2855 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2856 timevar_pop (TV_JUMP);
2857
2858 if (flag_expensive_optimizations)
2859 {
2860 timevar_push (TV_CSE);
2861 reg_scan (insns, max_reg_num (), 1);
2862 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2863 purge_all_dead_edges (0);
2864 delete_trivially_dead_insns (insns, max_reg_num ());
2865 timevar_pop (TV_CSE);
2866 }
2867 }
2868
2869 close_dump_file (DFI_gcse, print_rtl_with_bb, insns);
2870 timevar_pop (TV_GCSE);
2871
2872 ggc_collect ();
2873 flag_cse_skip_blocks = save_csb;
2874 flag_cse_follow_jumps = save_cfj;
2875 #ifdef ENABLE_CHECKING
2876 verify_flow_info ();
2877 #endif
2878 }
2879
2880 /* Move constant computations out of loops. */
2881
2882 if (optimize > 0 && flag_loop_optimize)
2883 {
2884 timevar_push (TV_LOOP);
2885 delete_dead_jumptables ();
2886 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2887 open_dump_file (DFI_loop, decl);
2888 /* CFG is no longer maintained up-to-date. */
2889 free_bb_for_insn ();
2890
2891 if (flag_rerun_loop_opt)
2892 {
2893 cleanup_barriers ();
2894
2895 /* We only want to perform unrolling once. */
2896 loop_optimize (insns, rtl_dump_file, LOOP_FIRST_PASS);
2897
2898 /* The first call to loop_optimize makes some instructions
2899 trivially dead. We delete those instructions now in the
2900 hope that doing so will make the heuristics in loop work
2901 better and possibly speed up compilation. */
2902 delete_trivially_dead_insns (insns, max_reg_num ());
2903
2904 /* The regscan pass is currently necessary as the alias
2905 analysis code depends on this information. */
2906 reg_scan (insns, max_reg_num (), 1);
2907 }
2908 cleanup_barriers ();
2909 loop_optimize (insns, rtl_dump_file,
2910 (flag_unroll_loops ? LOOP_UNROLL : 0) | LOOP_BCT
2911 | (flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0));
2912
2913 /* Loop can create trivially dead instructions. */
2914 delete_trivially_dead_insns (insns, max_reg_num ());
2915 close_dump_file (DFI_loop, print_rtl, insns);
2916 timevar_pop (TV_LOOP);
2917
2918 ggc_collect ();
2919 }
2920
2921 /* Do control and data flow analysis; wrote some of the results to
2922 the dump file. */
2923
2924 timevar_push (TV_FLOW);
2925 open_dump_file (DFI_cfg, decl);
2926
2927 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2928 if (rtl_dump_file)
2929 dump_flow_info (rtl_dump_file);
2930 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0)
2931 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2932
2933 /* It may make more sense to mark constant functions after dead code is
2934 eliminated by life_analyzis, but we need to do it early, as -fprofile-arcs
2935 may insert code making function non-constant, but we still must consider
2936 it as constant, otherwise -fbranch-probabilities will not read data back.
2937
2938 life_analyzis rarely eliminates modification of external memory.
2939 */
2940 if (optimize)
2941 mark_constant_function ();
2942
2943 close_dump_file (DFI_cfg, print_rtl_with_bb, insns);
2944
2945 /* Do branch profiling and static profile estimation passes. */
2946 if (optimize > 0 || cfun->arc_profile || flag_branch_probabilities)
2947 {
2948 struct loops loops;
2949
2950 timevar_push (TV_BRANCH_PROB);
2951 open_dump_file (DFI_bp, decl);
2952 if (cfun->arc_profile || flag_branch_probabilities)
2953 branch_prob ();
2954
2955 /* Discover and record the loop depth at the head of each basic
2956 block. The loop infrastructure does the real job for us. */
2957 flow_loops_find (&loops, LOOP_TREE);
2958
2959 /* Estimate using heuristics if no profiling info is available. */
2960 if (flag_guess_branch_prob)
2961 estimate_probability (&loops);
2962
2963 if (rtl_dump_file)
2964 flow_loops_dump (&loops, rtl_dump_file, NULL, 0);
2965
2966 flow_loops_free (&loops);
2967 close_dump_file (DFI_bp, print_rtl_with_bb, insns);
2968 timevar_pop (TV_BRANCH_PROB);
2969 }
2970 if (flag_tracer)
2971 {
2972 timevar_push (TV_TRACER);
2973 open_dump_file (DFI_tracer, decl);
2974 if (rtl_dump_file)
2975 dump_flow_info (rtl_dump_file);
2976 cleanup_cfg (CLEANUP_EXPENSIVE);
2977 tracer ();
2978 cleanup_cfg (CLEANUP_EXPENSIVE);
2979 close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ());
2980 timevar_pop (TV_TRACER);
2981 reg_scan (get_insns (), max_reg_num (), 0);
2982 }
2983
2984 if (optimize > 0)
2985 {
2986 timevar_push (TV_CSE2);
2987 open_dump_file (DFI_cse2, decl);
2988 if (rtl_dump_file)
2989 dump_flow_info (rtl_dump_file);
2990
2991 if (flag_rerun_cse_after_loop)
2992 {
2993 timevar_push (TV_JUMP);
2994
2995 reg_scan (insns, max_reg_num (), 0);
2996
2997 timevar_push (TV_IFCVT);
2998 cleanup_cfg (CLEANUP_EXPENSIVE);
2999 if (flag_if_conversion)
3000 if_convert (0);
3001 timevar_pop (TV_IFCVT);
3002
3003 timevar_pop (TV_JUMP);
3004 /* CFG is no longer maintained up-to-date. */
3005 reg_scan (insns, max_reg_num (), 0);
3006 tem = cse_main (insns, max_reg_num (), 1, rtl_dump_file);
3007 purge_all_dead_edges (0);
3008 delete_trivially_dead_insns (insns, max_reg_num ());
3009
3010 if (tem)
3011 {
3012 timevar_push (TV_JUMP);
3013 rebuild_jump_labels (insns);
3014 cleanup_cfg (CLEANUP_EXPENSIVE);
3015 timevar_pop (TV_JUMP);
3016 }
3017 }
3018
3019 close_dump_file (DFI_cse2, print_rtl_with_bb, insns);
3020 timevar_pop (TV_CSE2);
3021
3022 ggc_collect ();
3023 }
3024
3025 cse_not_expected = 1;
3026
3027 open_dump_file (DFI_life, decl);
3028 regclass_init ();
3029
3030 check_function_return_warnings ();
3031
3032 #ifdef ENABLE_CHECKING
3033 verify_flow_info ();
3034 #endif
3035 life_analysis (insns, rtl_dump_file, PROP_FINAL);
3036 if (optimize)
3037 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_UPDATE_LIFE
3038 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
3039 timevar_pop (TV_FLOW);
3040
3041 no_new_pseudos = 1;
3042
3043 if (warn_uninitialized || extra_warnings)
3044 {
3045 uninitialized_vars_warning (DECL_INITIAL (decl));
3046 if (extra_warnings)
3047 setjmp_args_warning ();
3048 }
3049
3050 if (optimize)
3051 {
3052 clear_bb_flags ();
3053 if (initialize_uninitialized_subregs ())
3054 {
3055 /* Insns were inserted, so things might look a bit different. */
3056 insns = get_insns ();
3057 update_life_info_in_dirty_blocks (UPDATE_LIFE_GLOBAL_RM_NOTES,
3058 PROP_LOG_LINKS | PROP_REG_INFO
3059 | PROP_DEATH_NOTES);
3060 }
3061 }
3062
3063 close_dump_file (DFI_life, print_rtl_with_bb, insns);
3064
3065 ggc_collect ();
3066
3067 /* If -opt, try combining insns through substitution. */
3068
3069 if (optimize > 0)
3070 {
3071 int rebuild_jump_labels_after_combine = 0;
3072
3073 timevar_push (TV_COMBINE);
3074 open_dump_file (DFI_combine, decl);
3075
3076 rebuild_jump_labels_after_combine
3077 = combine_instructions (insns, max_reg_num ());
3078
3079 /* Combining insns may have turned an indirect jump into a
3080 direct jump. Rebuid the JUMP_LABEL fields of jumping
3081 instructions. */
3082 if (rebuild_jump_labels_after_combine)
3083 {
3084 timevar_push (TV_JUMP);
3085 rebuild_jump_labels (insns);
3086 timevar_pop (TV_JUMP);
3087
3088 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
3089 }
3090
3091 close_dump_file (DFI_combine, print_rtl_with_bb, insns);
3092 timevar_pop (TV_COMBINE);
3093
3094 ggc_collect ();
3095 }
3096
3097 /* Rerun if-conversion, as combine may have simplified things enough to
3098 now meet sequence length restrictions. */
3099 if (flag_if_conversion)
3100 {
3101 timevar_push (TV_IFCVT);
3102 open_dump_file (DFI_ce, decl);
3103
3104 no_new_pseudos = 0;
3105 if_convert (1);
3106 no_new_pseudos = 1;
3107
3108 close_dump_file (DFI_ce, print_rtl_with_bb, insns);
3109 timevar_pop (TV_IFCVT);
3110 }
3111
3112 /* Register allocation pre-pass, to reduce number of moves
3113 necessary for two-address machines. */
3114 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
3115 {
3116 timevar_push (TV_REGMOVE);
3117 open_dump_file (DFI_regmove, decl);
3118
3119 regmove_optimize (insns, max_reg_num (), rtl_dump_file);
3120
3121 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
3122 close_dump_file (DFI_regmove, print_rtl_with_bb, insns);
3123 timevar_pop (TV_REGMOVE);
3124
3125 ggc_collect ();
3126 }
3127
3128 /* Do unconditional splitting before register allocation to allow machine
3129 description to add extra information not needed previously. */
3130 split_all_insns (1);
3131
3132 /* Any of the several passes since flow1 will have munged register
3133 lifetime data a bit. */
3134 register_life_up_to_date = 0;
3135
3136 #ifdef OPTIMIZE_MODE_SWITCHING
3137 timevar_push (TV_MODE_SWITCH);
3138
3139 no_new_pseudos = 0;
3140 optimize_mode_switching (NULL);
3141 no_new_pseudos = 1;
3142
3143 timevar_pop (TV_MODE_SWITCH);
3144 #endif
3145
3146 timevar_push (TV_SCHED);
3147
3148 #ifdef INSN_SCHEDULING
3149
3150 /* Print function header into sched dump now
3151 because doing the sched analysis makes some of the dump. */
3152 if (optimize > 0 && flag_schedule_insns)
3153 {
3154 open_dump_file (DFI_sched, decl);
3155
3156 /* Do control and data sched analysis,
3157 and write some of the results to dump file. */
3158
3159 schedule_insns (rtl_dump_file);
3160
3161 close_dump_file (DFI_sched, print_rtl_with_bb, insns);
3162
3163 /* Register lifetime information was updated as part of verifying
3164 the schedule. */
3165 register_life_up_to_date = 1;
3166 }
3167 #endif
3168 timevar_pop (TV_SCHED);
3169
3170 ggc_collect ();
3171
3172 /* Determine if the current function is a leaf before running reload
3173 since this can impact optimizations done by the prologue and
3174 epilogue thus changing register elimination offsets. */
3175 current_function_is_leaf = leaf_function_p ();
3176
3177 timevar_push (TV_LOCAL_ALLOC);
3178 open_dump_file (DFI_lreg, decl);
3179
3180 /* Allocate pseudo-regs that are used only within 1 basic block.
3181
3182 RUN_JUMP_AFTER_RELOAD records whether or not we need to rerun the
3183 jump optimizer after register allocation and reloading are finished. */
3184
3185 if (! register_life_up_to_date)
3186 recompute_reg_usage (insns, ! optimize_size);
3187
3188 /* Allocate the reg_renumber array. */
3189 allocate_reg_info (max_regno, FALSE, TRUE);
3190
3191 /* And the reg_equiv_memory_loc array. */
3192 reg_equiv_memory_loc = (rtx *) xcalloc (max_regno, sizeof (rtx));
3193
3194 allocate_initial_values (reg_equiv_memory_loc);
3195
3196 regclass (insns, max_reg_num (), rtl_dump_file);
3197 rebuild_label_notes_after_reload = local_alloc ();
3198
3199 timevar_pop (TV_LOCAL_ALLOC);
3200
3201 if (dump_file[DFI_lreg].enabled)
3202 {
3203 timevar_push (TV_DUMP);
3204
3205 dump_flow_info (rtl_dump_file);
3206 dump_local_alloc (rtl_dump_file);
3207
3208 close_dump_file (DFI_lreg, print_rtl_with_bb, insns);
3209 timevar_pop (TV_DUMP);
3210 }
3211
3212 ggc_collect ();
3213
3214 timevar_push (TV_GLOBAL_ALLOC);
3215 open_dump_file (DFI_greg, decl);
3216
3217 /* If optimizing, allocate remaining pseudo-regs. Do the reload
3218 pass fixing up any insns that are invalid. */
3219
3220 if (optimize)
3221 failure = global_alloc (rtl_dump_file);
3222 else
3223 {
3224 build_insn_chain (insns);
3225 failure = reload (insns, 0);
3226 }
3227
3228 timevar_pop (TV_GLOBAL_ALLOC);
3229
3230 if (dump_file[DFI_greg].enabled)
3231 {
3232 timevar_push (TV_DUMP);
3233
3234 dump_global_regs (rtl_dump_file);
3235
3236 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
3237 timevar_pop (TV_DUMP);
3238 }
3239
3240 if (failure)
3241 goto exit_rest_of_compilation;
3242
3243 ggc_collect ();
3244
3245 open_dump_file (DFI_postreload, decl);
3246
3247 /* Do a very simple CSE pass over just the hard registers. */
3248 if (optimize > 0)
3249 {
3250 timevar_push (TV_RELOAD_CSE_REGS);
3251 reload_cse_regs (insns);
3252 timevar_pop (TV_RELOAD_CSE_REGS);
3253 }
3254
3255 /* Register allocation and reloading may have turned an indirect jump into
3256 a direct jump. If so, we must rebuild the JUMP_LABEL fields of
3257 jumping instructions. */
3258 if (rebuild_label_notes_after_reload)
3259 {
3260 timevar_push (TV_JUMP);
3261
3262 rebuild_jump_labels (insns);
3263 purge_all_dead_edges (0);
3264
3265 timevar_pop (TV_JUMP);
3266 }
3267
3268 close_dump_file (DFI_postreload, print_rtl_with_bb, insns);
3269
3270 /* Re-create the death notes which were deleted during reload. */
3271 timevar_push (TV_FLOW2);
3272 open_dump_file (DFI_flow2, decl);
3273
3274 #ifdef ENABLE_CHECKING
3275 verify_flow_info ();
3276 #endif
3277
3278 /* If optimizing, then go ahead and split insns now. */
3279 if (optimize > 0)
3280 split_all_insns (0);
3281
3282 cleanup_cfg (optimize ? CLEANUP_EXPENSIVE : 0);
3283
3284 /* On some machines, the prologue and epilogue code, or parts thereof,
3285 can be represented as RTL. Doing so lets us schedule insns between
3286 it and the rest of the code and also allows delayed branch
3287 scheduling to operate in the epilogue. */
3288 thread_prologue_and_epilogue_insns (insns);
3289
3290 if (optimize)
3291 {
3292 life_analysis (insns, rtl_dump_file, PROP_FINAL);
3293 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
3294 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
3295
3296 /* This is kind of a heuristic. We need to run combine_stack_adjustments
3297 even for machines with possibly nonzero RETURN_POPS_ARGS
3298 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
3299 push instructions will have popping returns. */
3300 #ifndef PUSH_ROUNDING
3301 if (!ACCUMULATE_OUTGOING_ARGS)
3302 #endif
3303 combine_stack_adjustments ();
3304
3305 ggc_collect ();
3306 }
3307
3308 flow2_completed = 1;
3309
3310 close_dump_file (DFI_flow2, print_rtl_with_bb, insns);
3311 timevar_pop (TV_FLOW2);
3312
3313 #ifdef HAVE_peephole2
3314 if (optimize > 0 && flag_peephole2)
3315 {
3316 timevar_push (TV_PEEPHOLE2);
3317 open_dump_file (DFI_peephole2, decl);
3318
3319 peephole2_optimize (rtl_dump_file);
3320
3321 close_dump_file (DFI_peephole2, print_rtl_with_bb, insns);
3322 timevar_pop (TV_PEEPHOLE2);
3323 }
3324 #endif
3325
3326 if (optimize > 0 && (flag_rename_registers || flag_cprop_registers))
3327 {
3328 timevar_push (TV_RENAME_REGISTERS);
3329 open_dump_file (DFI_rnreg, decl);
3330
3331 if (flag_rename_registers)
3332 regrename_optimize ();
3333 if (flag_cprop_registers)
3334 copyprop_hardreg_forward ();
3335
3336 close_dump_file (DFI_rnreg, print_rtl_with_bb, insns);
3337 timevar_pop (TV_RENAME_REGISTERS);
3338 }
3339
3340 if (flag_if_conversion2)
3341 {
3342 timevar_push (TV_IFCVT2);
3343 open_dump_file (DFI_ce2, decl);
3344
3345 if_convert (1);
3346
3347 close_dump_file (DFI_ce2, print_rtl_with_bb, insns);
3348 timevar_pop (TV_IFCVT2);
3349 }
3350 #ifdef STACK_REGS
3351 if (optimize)
3352 split_all_insns (1);
3353 #endif
3354
3355 #ifdef INSN_SCHEDULING
3356 if (optimize > 0 && flag_schedule_insns_after_reload)
3357 {
3358 timevar_push (TV_SCHED2);
3359 open_dump_file (DFI_sched2, decl);
3360
3361 /* Do control and data sched analysis again,
3362 and write some more of the results to dump file. */
3363
3364 split_all_insns (1);
3365
3366 schedule_insns (rtl_dump_file);
3367
3368 close_dump_file (DFI_sched2, print_rtl_with_bb, insns);
3369 timevar_pop (TV_SCHED2);
3370
3371 ggc_collect ();
3372 }
3373 #endif
3374
3375 #ifdef LEAF_REGISTERS
3376 current_function_uses_only_leaf_regs
3377 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
3378 #endif
3379
3380 #ifdef STACK_REGS
3381 timevar_push (TV_REG_STACK);
3382 open_dump_file (DFI_stack, decl);
3383
3384 reg_to_stack (insns, rtl_dump_file);
3385
3386 close_dump_file (DFI_stack, print_rtl_with_bb, insns);
3387 timevar_pop (TV_REG_STACK);
3388
3389 ggc_collect ();
3390 #endif
3391 if (optimize > 0)
3392 {
3393 timevar_push (TV_REORDER_BLOCKS);
3394 open_dump_file (DFI_bbro, decl);
3395
3396 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
3397 splitting possibly introduced more crossjumping oppurtuntities.
3398 Except that we can't actually run crossjumping without running
3399 another DCE pass, which we can't do after reg-stack. */
3400 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
3401 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
3402 if (flag_reorder_blocks)
3403 {
3404 reorder_basic_blocks ();
3405 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
3406 }
3407
3408 close_dump_file (DFI_bbro, print_rtl_with_bb, insns);
3409 timevar_pop (TV_REORDER_BLOCKS);
3410 }
3411 compute_alignments ();
3412
3413 /* CFG is no longer maintained up-to-date. */
3414 free_bb_for_insn ();
3415
3416 /* If a machine dependent reorganization is needed, call it. */
3417 #ifdef MACHINE_DEPENDENT_REORG
3418 timevar_push (TV_MACH_DEP);
3419 open_dump_file (DFI_mach, decl);
3420
3421 MACHINE_DEPENDENT_REORG (insns);
3422
3423 close_dump_file (DFI_mach, print_rtl, insns);
3424 timevar_pop (TV_MACH_DEP);
3425
3426 ggc_collect ();
3427 #endif
3428
3429 purge_line_number_notes (insns);
3430 cleanup_barriers ();
3431
3432 /* If a scheduling pass for delayed branches is to be done,
3433 call the scheduling code. */
3434
3435 #ifdef DELAY_SLOTS
3436 if (optimize > 0 && flag_delayed_branch)
3437 {
3438 timevar_push (TV_DBR_SCHED);
3439 open_dump_file (DFI_dbr, decl);
3440
3441 dbr_schedule (insns, rtl_dump_file);
3442
3443 close_dump_file (DFI_dbr, print_rtl, insns);
3444 timevar_pop (TV_DBR_SCHED);
3445
3446 ggc_collect ();
3447 }
3448 #endif
3449
3450 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3451 timevar_push (TV_SHORTEN_BRANCH);
3452 split_all_insns_noflow ();
3453 timevar_pop (TV_SHORTEN_BRANCH);
3454 #endif
3455
3456 convert_to_eh_region_ranges ();
3457
3458 /* Shorten branches. */
3459 timevar_push (TV_SHORTEN_BRANCH);
3460 shorten_branches (get_insns ());
3461 timevar_pop (TV_SHORTEN_BRANCH);
3462
3463 current_function_nothrow = nothrow_function_p ();
3464 if (current_function_nothrow)
3465 /* Now we know that this can't throw; set the flag for the benefit
3466 of other functions later in this translation unit. */
3467 TREE_NOTHROW (current_function_decl) = 1;
3468
3469 /* Now turn the rtl into assembler code. */
3470
3471 timevar_push (TV_FINAL);
3472 {
3473 rtx x;
3474 const char *fnname;
3475
3476 /* Get the function's name, as described by its RTL. This may be
3477 different from the DECL_NAME name used in the source file. */
3478
3479 x = DECL_RTL (decl);
3480 if (GET_CODE (x) != MEM)
3481 abort ();
3482 x = XEXP (x, 0);
3483 if (GET_CODE (x) != SYMBOL_REF)
3484 abort ();
3485 fnname = XSTR (x, 0);
3486
3487 assemble_start_function (decl, fnname);
3488 final_start_function (insns, asm_out_file, optimize);
3489 final (insns, asm_out_file, optimize, 0);
3490 final_end_function ();
3491
3492 #ifdef IA64_UNWIND_INFO
3493 /* ??? The IA-64 ".handlerdata" directive must be issued before
3494 the ".endp" directive that closes the procedure descriptor. */
3495 output_function_exception_table ();
3496 #endif
3497
3498 assemble_end_function (decl, fnname);
3499
3500 #ifndef IA64_UNWIND_INFO
3501 /* Otherwise, it feels unclean to switch sections in the middle. */
3502 output_function_exception_table ();
3503 #endif
3504
3505 if (! quiet_flag)
3506 fflush (asm_out_file);
3507
3508 /* Release all memory allocated by flow. */
3509 free_basic_block_vars (0);
3510
3511 /* Release all memory held by regsets now. */
3512 regset_release_memory ();
3513 }
3514 timevar_pop (TV_FINAL);
3515
3516 ggc_collect ();
3517
3518 /* Write DBX symbols if requested. */
3519
3520 /* Note that for those inline functions where we don't initially
3521 know for certain that we will be generating an out-of-line copy,
3522 the first invocation of this routine (rest_of_compilation) will
3523 skip over this code by doing a `goto exit_rest_of_compilation;'.
3524 Later on, finish_compilation will call rest_of_compilation again
3525 for those inline functions that need to have out-of-line copies
3526 generated. During that call, we *will* be routed past here. */
3527
3528 timevar_push (TV_SYMOUT);
3529 (*debug_hooks->function_decl) (decl);
3530 timevar_pop (TV_SYMOUT);
3531
3532 exit_rest_of_compilation:
3533
3534 /* In case the function was not output,
3535 don't leave any temporary anonymous types
3536 queued up for sdb output. */
3537 #ifdef SDB_DEBUGGING_INFO
3538 if (write_symbols == SDB_DEBUG)
3539 sdbout_types (NULL_TREE);
3540 #endif
3541
3542 reload_completed = 0;
3543 flow2_completed = 0;
3544 no_new_pseudos = 0;
3545
3546 timevar_push (TV_FINAL);
3547
3548 /* Clear out the insn_length contents now that they are no
3549 longer valid. */
3550 init_insn_lengths ();
3551
3552 /* Show no temporary slots allocated. */
3553 init_temp_slots ();
3554
3555 free_basic_block_vars (0);
3556 free_bb_for_insn ();
3557
3558 timevar_pop (TV_FINAL);
3559
3560 /* Make sure volatile mem refs aren't considered valid operands for
3561 arithmetic insns. We must call this here if this is a nested inline
3562 function, since the above code leaves us in the init_recog state
3563 (from final.c), and the function context push/pop code does not
3564 save/restore volatile_ok.
3565
3566 ??? Maybe it isn't necessary for expand_start_function to call this
3567 anymore if we do it here? */
3568
3569 init_recog_no_volatile ();
3570
3571 /* We're done with this function. Free up memory if we can. */
3572 free_after_parsing (cfun);
3573 if (! DECL_DEFER_OUTPUT (decl))
3574 {
3575 free_after_compilation (cfun);
3576
3577 /* Clear integrate.c's pointer to the cfun structure we just
3578 destroyed. */
3579 DECL_SAVED_INSNS (decl) = 0;
3580 }
3581 cfun = 0;
3582
3583 ggc_collect ();
3584
3585 timevar_pop (TV_REST_OF_COMPILATION);
3586 }
3587 \f
3588 static void
3589 display_help ()
3590 {
3591 int undoc;
3592 unsigned long i;
3593 const char *lang;
3594
3595 printf (_(" -ffixed-<register> Mark <register> as being unavailable to the compiler\n"));
3596 printf (_(" -fcall-used-<register> Mark <register> as being corrupted by function calls\n"));
3597 printf (_(" -fcall-saved-<register> Mark <register> as being preserved across functions\n"));
3598 printf (_(" -finline-limit=<number> Limits the size of inlined functions to <number>\n"));
3599 printf (_(" -fmessage-length=<number> Limits diagnostics messages lengths to <number> characters per line. 0 suppresses line-wrapping\n"));
3600 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"));
3601 printf (_(" -ftls-model=[global-dynamic | local-dynamic | initial-exec | local-exec] Indicates the default thread-local storage code generation model\n"));
3602
3603 for (i = ARRAY_SIZE (f_options); i--;)
3604 {
3605 const char *description = f_options[i].description;
3606
3607 if (description != NULL && *description != 0)
3608 printf (" -f%-21s %s\n",
3609 f_options[i].string, _(description));
3610 }
3611
3612 printf (_(" -O[number] Set optimization level to [number]\n"));
3613 printf (_(" -Os Optimize for space rather than speed\n"));
3614 for (i = LAST_PARAM; i--;)
3615 {
3616 const char *description = compiler_params[i].help;
3617 const int length = 21 - strlen (compiler_params[i].option);
3618
3619 if (description != NULL && *description != 0)
3620 printf (" --param %s=<value>%.*s%s\n",
3621 compiler_params[i].option,
3622 length > 0 ? length : 1, " ",
3623 _(description));
3624 }
3625 printf (_(" -pedantic Issue warnings needed by strict compliance to ISO C\n"));
3626 printf (_(" -pedantic-errors Like -pedantic except that errors are produced\n"));
3627 printf (_(" -w Suppress warnings\n"));
3628 printf (_(" -W Enable extra warnings\n"));
3629
3630 for (i = ARRAY_SIZE (W_options); i--;)
3631 {
3632 const char *description = W_options[i].description;
3633
3634 if (description != NULL && *description != 0)
3635 printf (" -W%-21s %s\n",
3636 W_options[i].string, _(description));
3637 }
3638
3639 printf (_(" -Wunused Enable unused warnings\n"));
3640 printf (_(" -Wlarger-than-<number> Warn if an object is larger than <number> bytes\n"));
3641 printf (_(" -p Enable function profiling\n"));
3642 printf (_(" -o <file> Place output into <file> \n"));
3643 printf (_("\
3644 -G <number> Put global and static data smaller than <number>\n\
3645 bytes into a special section (on some targets)\n"));
3646
3647 for (i = ARRAY_SIZE (debug_args); i--;)
3648 {
3649 if (debug_args[i].description != NULL)
3650 printf (" -g%-21s %s\n",
3651 debug_args[i].arg, _(debug_args[i].description));
3652 }
3653
3654 printf (_(" -aux-info <file> Emit declaration info into <file>\n"));
3655 printf (_(" -quiet Do not display functions compiled or elapsed time\n"));
3656 printf (_(" -version Display the compiler's version\n"));
3657 printf (_(" -d[letters] Enable dumps from specific passes of the compiler\n"));
3658 printf (_(" -dumpbase <file> Base name to be used for dumps from specific passes\n"));
3659 #if defined INSN_SCHEDULING
3660 printf (_(" -fsched-verbose=<number> Set the verbosity level of the scheduler\n"));
3661 #endif
3662 printf (_(" --help Display this information\n"));
3663
3664 undoc = 0;
3665 lang = "language";
3666
3667 /* Display descriptions of language specific options.
3668 If there is no description, note that there is an undocumented option.
3669 If the description is empty, do not display anything. (This allows
3670 options to be deliberately undocumented, for whatever reason).
3671 If the option string is missing, then this is a marker, indicating
3672 that the description string is in fact the name of a language, whose
3673 language specific options are to follow. */
3674
3675 if (ARRAY_SIZE (documented_lang_options) > 1)
3676 {
3677 printf (_("\nLanguage specific options:\n"));
3678
3679 for (i = 0; i < ARRAY_SIZE (documented_lang_options); i++)
3680 {
3681 const char *description = documented_lang_options[i].description;
3682 const char *option = documented_lang_options[i].option;
3683
3684 if (description == NULL)
3685 {
3686 undoc = 1;
3687
3688 if (extra_warnings)
3689 printf (_(" %-23.23s [undocumented]\n"), option);
3690 }
3691 else if (*description == 0)
3692 continue;
3693 else if (option == NULL)
3694 {
3695 if (undoc)
3696 printf
3697 (_("\nThere are undocumented %s specific options as well.\n"),
3698 lang);
3699 undoc = 0;
3700
3701 printf (_("\n Options for %s:\n"), description);
3702
3703 lang = description;
3704 }
3705 else
3706 printf (" %-23.23s %s\n", option, _(description));
3707 }
3708 }
3709
3710 if (undoc)
3711 printf (_("\nThere are undocumented %s specific options as well.\n"),
3712 lang);
3713
3714 display_target_options ();
3715 }
3716
3717 static void
3718 display_target_options ()
3719 {
3720 int undoc, i;
3721 static bool displayed = false;
3722
3723 /* Avoid double printing for --help --target-help. */
3724 if (displayed)
3725 return;
3726 displayed = true;
3727
3728 if (ARRAY_SIZE (target_switches) > 1
3729 #ifdef TARGET_OPTIONS
3730 || ARRAY_SIZE (target_options) > 1
3731 #endif
3732 )
3733 {
3734 int doc = 0;
3735
3736 undoc = 0;
3737
3738 printf (_("\nTarget specific options:\n"));
3739
3740 for (i = ARRAY_SIZE (target_switches); i--;)
3741 {
3742 const char *option = target_switches[i].name;
3743 const char *description = target_switches[i].description;
3744
3745 if (option == NULL || *option == 0)
3746 continue;
3747 else if (description == NULL)
3748 {
3749 undoc = 1;
3750
3751 if (extra_warnings)
3752 printf (_(" -m%-23.23s [undocumented]\n"), option);
3753 }
3754 else if (*description != 0)
3755 doc += printf (" -m%-23.23s %s\n", option, _(description));
3756 }
3757
3758 #ifdef TARGET_OPTIONS
3759 for (i = ARRAY_SIZE (target_options); i--;)
3760 {
3761 const char *option = target_options[i].prefix;
3762 const char *description = target_options[i].description;
3763
3764 if (option == NULL || *option == 0)
3765 continue;
3766 else if (description == NULL)
3767 {
3768 undoc = 1;
3769
3770 if (extra_warnings)
3771 printf (_(" -m%-23.23s [undocumented]\n"), option);
3772 }
3773 else if (*description != 0)
3774 doc += printf (" -m%-23.23s %s\n", option, _(description));
3775 }
3776 #endif
3777 if (undoc)
3778 {
3779 if (doc)
3780 printf (_("\nThere are undocumented target specific options as well.\n"));
3781 else
3782 printf (_(" They exist, but they are not documented.\n"));
3783 }
3784 }
3785 }
3786 \f
3787 /* Parse a -d... command line switch. */
3788
3789 static void
3790 decode_d_option (arg)
3791 const char *arg;
3792 {
3793 int i, c, matched;
3794
3795 while (*arg)
3796 switch (c = *arg++)
3797 {
3798 case 'a':
3799 for (i = 0; i < (int) DFI_MAX; ++i)
3800 dump_file[i].enabled = 1;
3801 break;
3802 case 'A':
3803 flag_debug_asm = 1;
3804 break;
3805 case 'p':
3806 flag_print_asm_name = 1;
3807 break;
3808 case 'P':
3809 flag_dump_rtl_in_asm = 1;
3810 flag_print_asm_name = 1;
3811 break;
3812 case 'v':
3813 graph_dump_format = vcg;
3814 break;
3815 case 'x':
3816 rtl_dump_and_exit = 1;
3817 break;
3818 case 'y':
3819 set_yydebug = 1;
3820 break;
3821 case 'D': /* These are handled by the preprocessor. */
3822 case 'I':
3823 break;
3824
3825 default:
3826 matched = 0;
3827 for (i = 0; i < (int) DFI_MAX; ++i)
3828 if (c == dump_file[i].debug_switch)
3829 {
3830 dump_file[i].enabled = 1;
3831 matched = 1;
3832 }
3833
3834 if (! matched)
3835 warning ("unrecognized gcc debugging option: %c", c);
3836 break;
3837 }
3838 }
3839
3840 /* Parse a -f... command line switch. ARG is the value after the -f.
3841 It is safe to access 'ARG - 2' to generate the full switch name.
3842 Return the number of strings consumed. */
3843
3844 static int
3845 decode_f_option (arg)
3846 const char *arg;
3847 {
3848 int j;
3849 const char *option_value = NULL;
3850
3851 /* Search for the option in the table of binary f options. */
3852 for (j = ARRAY_SIZE (f_options); j--;)
3853 {
3854 if (!strcmp (arg, f_options[j].string))
3855 {
3856 *f_options[j].variable = f_options[j].on_value;
3857 return 1;
3858 }
3859
3860 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-'
3861 && ! strcmp (arg + 3, f_options[j].string))
3862 {
3863 *f_options[j].variable = ! f_options[j].on_value;
3864 return 1;
3865 }
3866 }
3867
3868 if (!strcmp (arg, "fast-math"))
3869 set_fast_math_flags (1);
3870 else if (!strcmp (arg, "no-fast-math"))
3871 set_fast_math_flags (0);
3872 else if ((option_value = skip_leading_substring (arg, "inline-limit-"))
3873 || (option_value = skip_leading_substring (arg, "inline-limit=")))
3874 {
3875 int val =
3876 read_integral_parameter (option_value, arg - 2,
3877 MAX_INLINE_INSNS);
3878 set_param_value ("max-inline-insns", val);
3879 }
3880 else if ((option_value = skip_leading_substring (arg, "tls-model=")))
3881 {
3882 if (strcmp (option_value, "global-dynamic") == 0)
3883 flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
3884 else if (strcmp (option_value, "local-dynamic") == 0)
3885 flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
3886 else if (strcmp (option_value, "initial-exec") == 0)
3887 flag_tls_default = TLS_MODEL_INITIAL_EXEC;
3888 else if (strcmp (option_value, "local-exec") == 0)
3889 flag_tls_default = TLS_MODEL_LOCAL_EXEC;
3890 else
3891 warning ("`%s': unknown tls-model option", arg - 2);
3892 }
3893 #ifdef INSN_SCHEDULING
3894 else if ((option_value = skip_leading_substring (arg, "sched-verbose=")))
3895 fix_sched_param ("verbose", option_value);
3896 #endif
3897 else if ((option_value = skip_leading_substring (arg, "fixed-")))
3898 fix_register (option_value, 1, 1);
3899 else if ((option_value = skip_leading_substring (arg, "call-used-")))
3900 fix_register (option_value, 0, 1);
3901 else if ((option_value = skip_leading_substring (arg, "call-saved-")))
3902 fix_register (option_value, 0, 0);
3903 else if ((option_value = skip_leading_substring (arg, "align-loops=")))
3904 align_loops = read_integral_parameter (option_value, arg - 2, align_loops);
3905 else if ((option_value = skip_leading_substring (arg, "align-functions=")))
3906 align_functions
3907 = read_integral_parameter (option_value, arg - 2, align_functions);
3908 else if ((option_value = skip_leading_substring (arg, "align-jumps=")))
3909 align_jumps = read_integral_parameter (option_value, arg - 2, align_jumps);
3910 else if ((option_value = skip_leading_substring (arg, "align-labels=")))
3911 align_labels
3912 = read_integral_parameter (option_value, arg - 2, align_labels);
3913 else if ((option_value
3914 = skip_leading_substring (arg, "stack-limit-register=")))
3915 {
3916 int reg = decode_reg_name (option_value);
3917 if (reg < 0)
3918 error ("unrecognized register name `%s'", option_value);
3919 else
3920 stack_limit_rtx = gen_rtx_REG (Pmode, reg);
3921 }
3922 else if ((option_value
3923 = skip_leading_substring (arg, "stack-limit-symbol=")))
3924 {
3925 const char *nm;
3926 nm = ggc_strdup (option_value);
3927 stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, nm);
3928 }
3929 else if ((option_value
3930 = skip_leading_substring (arg, "message-length=")))
3931 output_set_maximum_length
3932 (&global_dc->buffer, read_integral_parameter
3933 (option_value, arg - 2, diagnostic_line_cutoff (global_dc)));
3934 else if ((option_value
3935 = skip_leading_substring (arg, "diagnostics-show-location=")))
3936 {
3937 if (!strcmp (option_value, "once"))
3938 diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
3939 else if (!strcmp (option_value, "every-line"))
3940 diagnostic_prefixing_rule (global_dc)
3941 = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
3942 else
3943 error ("unrecognized option `%s'", arg - 2);
3944 }
3945 else if (!strcmp (arg, "no-stack-limit"))
3946 stack_limit_rtx = NULL_RTX;
3947 else if (!strcmp (arg, "preprocessed"))
3948 /* Recognise this switch but do nothing. This prevents warnings
3949 about an unrecognized switch if cpplib has not been linked in. */
3950 ;
3951 else
3952 return 0;
3953
3954 return 1;
3955 }
3956
3957 /* Parse a -W... command line switch. ARG is the value after the -W.
3958 It is safe to access 'ARG - 2' to generate the full switch name.
3959 Return the number of strings consumed. */
3960
3961 static int
3962 decode_W_option (arg)
3963 const char *arg;
3964 {
3965 const char *option_value = NULL;
3966 int j;
3967
3968 /* Search for the option in the table of binary W options. */
3969
3970 for (j = ARRAY_SIZE (W_options); j--;)
3971 {
3972 if (!strcmp (arg, W_options[j].string))
3973 {
3974 *W_options[j].variable = W_options[j].on_value;
3975 return 1;
3976 }
3977
3978 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-'
3979 && ! strcmp (arg + 3, W_options[j].string))
3980 {
3981 *W_options[j].variable = ! W_options[j].on_value;
3982 return 1;
3983 }
3984 }
3985
3986 if ((option_value = skip_leading_substring (arg, "id-clash-")))
3987 warning ("-Wid-clash-LEN is no longer supported");
3988 else if ((option_value = skip_leading_substring (arg, "larger-than-")))
3989 {
3990 larger_than_size = read_integral_parameter (option_value, arg - 2, -1);
3991
3992 warn_larger_than = larger_than_size != -1;
3993 }
3994 else if (!strcmp (arg, "unused"))
3995 {
3996 set_Wunused (1);
3997 }
3998 else if (!strcmp (arg, "no-unused"))
3999 {
4000 set_Wunused (0);
4001 }
4002 else
4003 return 0;
4004
4005 return 1;
4006 }
4007
4008 /* Parse a -g... command line switch. ARG is the value after the -g.
4009 It is safe to access 'ARG - 2' to generate the full switch name.
4010 Return the number of strings consumed. */
4011
4012 static int
4013 decode_g_option (arg)
4014 const char *arg;
4015 {
4016 static unsigned level = 0;
4017 /* A lot of code assumes write_symbols == NO_DEBUG if the
4018 debugging level is 0 (thus -gstabs1 -gstabs0 would lose track
4019 of what debugging type has been selected). This records the
4020 selected type. It is an error to specify more than one
4021 debugging type. */
4022 static enum debug_info_type selected_debug_type = NO_DEBUG;
4023 /* Non-zero if debugging format has been explicitly set.
4024 -g and -ggdb don't explicitly set the debugging format so
4025 -gdwarf -g3 is equivalent to -gdwarf3. */
4026 static int type_explicitly_set_p = 0;
4027 /* Indexed by enum debug_info_type. */
4028 static const char *const debug_type_names[] =
4029 {
4030 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
4031 };
4032
4033 /* The maximum admissible debug level value. */
4034 static const unsigned max_debug_level = 3;
4035
4036 /* Look up ARG in the table. */
4037 for (da = debug_args; da->arg; da++)
4038 {
4039 const int da_len = strlen (da->arg);
4040
4041 if (da_len == 0 || ! strncmp (arg, da->arg, da_len))
4042 {
4043 enum debug_info_type type = da->debug_type;
4044 const char *p = arg + da_len;
4045
4046 if (*p && ! ISDIGIT (*p))
4047 continue;
4048
4049 /* A debug flag without a level defaults to level 2.
4050 Note we do not want to call read_integral_parameter
4051 for that case since it will call atoi which
4052 will return zero.
4053
4054 ??? We may want to generalize the interface to
4055 read_integral_parameter to better handle this case
4056 if this case shows up often. */
4057 if (*p)
4058 level = read_integral_parameter (p, 0, max_debug_level + 1);
4059 else
4060 level = (level == 0) ? 2 : level;
4061
4062 if (da_len > 1 && *p && !strncmp (arg, "dwarf", da_len))
4063 {
4064 error ("use -gdwarf -g%d for DWARF v1, level %d",
4065 level, level);
4066 if (level == 2)
4067 error ("use -gdwarf-2 for DWARF v2");
4068 }
4069
4070 if (level > max_debug_level)
4071 {
4072 warning ("\
4073 ignoring option `%s' due to invalid debug level specification",
4074 arg - 2);
4075 level = debug_info_level;
4076 }
4077
4078 if (type == NO_DEBUG)
4079 {
4080 type = PREFERRED_DEBUGGING_TYPE;
4081
4082 if (da_len > 1 && strncmp (arg, "gdb", da_len) == 0)
4083 {
4084 #ifdef DWARF2_DEBUGGING_INFO
4085 type = DWARF2_DEBUG;
4086 #else
4087 #ifdef DBX_DEBUGGING_INFO
4088 type = DBX_DEBUG;
4089 #endif
4090 #endif
4091 }
4092 }
4093
4094 if (type == NO_DEBUG)
4095 warning ("`%s': unknown or unsupported -g option", arg - 2);
4096
4097 /* Does it conflict with an already selected type? */
4098 if (type_explicitly_set_p
4099 /* -g/-ggdb don't conflict with anything. */
4100 && da->debug_type != NO_DEBUG
4101 && type != selected_debug_type)
4102 warning ("`%s' ignored, conflicts with `-g%s'",
4103 arg - 2, debug_type_names[(int) selected_debug_type]);
4104 else
4105 {
4106 /* If the format has already been set, -g/-ggdb
4107 only change the debug level. */
4108 if (type_explicitly_set_p && da->debug_type == NO_DEBUG)
4109 /* Don't change debugging type. */
4110 ;
4111 else
4112 {
4113 selected_debug_type = type;
4114 type_explicitly_set_p = da->debug_type != NO_DEBUG;
4115 }
4116
4117 write_symbols = (level == 0
4118 ? NO_DEBUG
4119 : selected_debug_type);
4120 use_gnu_debug_info_extensions = da->use_extensions_p;
4121 debug_info_level = (enum debug_info_level) level;
4122 }
4123
4124 break;
4125 }
4126 }
4127
4128 if (! da->arg)
4129 return 0;
4130
4131 return 1;
4132 }
4133
4134 /* Decode the first argument in the argv as a language-independent option.
4135 Return the number of strings consumed. */
4136
4137 static unsigned int
4138 independent_decode_option (argc, argv)
4139 int argc;
4140 char **argv;
4141 {
4142 char *arg = argv[0];
4143
4144 if (arg[0] != '-' || arg[1] == 0)
4145 {
4146 if (arg[0] == '+')
4147 return 0;
4148
4149 filename = arg;
4150
4151 return 1;
4152 }
4153
4154 arg++;
4155
4156 if (!strcmp (arg, "-help"))
4157 {
4158 display_help ();
4159 exit_after_options = 1;
4160 }
4161
4162 if (!strcmp (arg, "-target-help"))
4163 {
4164 display_target_options ();
4165 exit_after_options = 1;
4166 }
4167
4168 if (!strcmp (arg, "-version"))
4169 {
4170 print_version (stderr, "");
4171 exit_after_options = 1;
4172 }
4173
4174 /* Handle '--param <name>=<value>'. */
4175 if (strcmp (arg, "-param") == 0)
4176 {
4177 char *equal;
4178
4179 if (argc == 1)
4180 {
4181 error ("-param option missing argument");
4182 return 1;
4183 }
4184
4185 /* Get the '<name>=<value>' parameter. */
4186 arg = argv[1];
4187 /* Look for the `='. */
4188 equal = strchr (arg, '=');
4189 if (!equal)
4190 error ("invalid --param option: %s", arg);
4191 else
4192 {
4193 int val;
4194
4195 /* Zero out the `=' sign so that we get two separate strings. */
4196 *equal = '\0';
4197 /* Figure out what value is specified. */
4198 val = read_integral_parameter (equal + 1, NULL, INVALID_PARAM_VAL);
4199 if (val != INVALID_PARAM_VAL)
4200 set_param_value (arg, val);
4201 else
4202 error ("invalid parameter value `%s'", equal + 1);
4203 }
4204
4205 return 2;
4206 }
4207
4208 if (*arg == 'Y')
4209 arg++;
4210
4211 switch (*arg)
4212 {
4213 default:
4214 return 0;
4215
4216 case 'O':
4217 /* Already been treated in main (). Do nothing. */
4218 break;
4219
4220 case 'm':
4221 set_target_switch (arg + 1);
4222 break;
4223
4224 case 'f':
4225 return decode_f_option (arg + 1);
4226
4227 case 'g':
4228 return decode_g_option (arg + 1);
4229
4230 case 'd':
4231 if (!strcmp (arg, "dumpbase"))
4232 {
4233 if (argc == 1)
4234 return 0;
4235
4236 dump_base_name = argv[1];
4237 return 2;
4238 }
4239 else
4240 decode_d_option (arg + 1);
4241 break;
4242
4243 case 'p':
4244 if (!strcmp (arg, "pedantic"))
4245 pedantic = 1;
4246 else if (!strcmp (arg, "pedantic-errors"))
4247 flag_pedantic_errors = pedantic = 1;
4248 else if (arg[1] == 0)
4249 profile_flag = 1;
4250 else
4251 return 0;
4252 break;
4253
4254 case 'q':
4255 if (!strcmp (arg, "quiet"))
4256 quiet_flag = 1;
4257 else
4258 return 0;
4259 break;
4260
4261 case 'v':
4262 if (!strcmp (arg, "version"))
4263 version_flag = 1;
4264 else
4265 return 0;
4266 break;
4267
4268 case 'w':
4269 if (arg[1] == 0)
4270 inhibit_warnings = 1;
4271 else
4272 return 0;
4273 break;
4274
4275 case 'W':
4276 if (arg[1] == 0)
4277 {
4278 extra_warnings = 1;
4279 /* We save the value of warn_uninitialized, since if they put
4280 -Wuninitialized on the command line, we need to generate a
4281 warning about not using it without also specifying -O. */
4282 if (warn_uninitialized != 1)
4283 warn_uninitialized = 2;
4284 }
4285 else
4286 return decode_W_option (arg + 1);
4287 break;
4288
4289 case 'a':
4290 if (!strncmp (arg, "aux-info", 8))
4291 {
4292 if (arg[8] == '\0')
4293 {
4294 if (argc == 1)
4295 return 0;
4296
4297 aux_info_file_name = argv[1];
4298 flag_gen_aux_info = 1;
4299 return 2;
4300 }
4301 else if (arg[8] == '=')
4302 {
4303 aux_info_file_name = arg + 9;
4304 flag_gen_aux_info = 1;
4305 }
4306 else
4307 return 0;
4308 }
4309 else
4310 return 0;
4311 break;
4312
4313 case 'o':
4314 if (arg[1] == 0)
4315 {
4316 if (argc == 1)
4317 return 0;
4318
4319 asm_file_name = argv[1];
4320 return 2;
4321 }
4322 return 0;
4323
4324 case 'G':
4325 {
4326 int g_switch_val;
4327 int return_val;
4328
4329 if (arg[1] == 0)
4330 {
4331 if (argc == 1)
4332 return 0;
4333
4334 g_switch_val = read_integral_parameter (argv[1], 0, -1);
4335 return_val = 2;
4336 }
4337 else
4338 {
4339 g_switch_val = read_integral_parameter (arg + 1, 0, -1);
4340 return_val = 1;
4341 }
4342
4343 if (g_switch_val == -1)
4344 return_val = 0;
4345 else
4346 {
4347 g_switch_set = TRUE;
4348 g_switch_value = g_switch_val;
4349 }
4350
4351 return return_val;
4352 }
4353 }
4354
4355 return 1;
4356 }
4357 \f
4358 /* Decode -m switches. */
4359 /* Decode the switch -mNAME. */
4360
4361 static void
4362 set_target_switch (name)
4363 const char *name;
4364 {
4365 size_t j;
4366 int valid_target_option = 0;
4367
4368 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
4369 if (!strcmp (target_switches[j].name, name))
4370 {
4371 if (target_switches[j].value < 0)
4372 target_flags &= ~-target_switches[j].value;
4373 else
4374 target_flags |= target_switches[j].value;
4375 valid_target_option = 1;
4376 }
4377
4378 #ifdef TARGET_OPTIONS
4379 if (!valid_target_option)
4380 for (j = 0; j < ARRAY_SIZE (target_options); j++)
4381 {
4382 int len = strlen (target_options[j].prefix);
4383 if (!strncmp (target_options[j].prefix, name, len))
4384 {
4385 *target_options[j].variable = name + len;
4386 valid_target_option = 1;
4387 }
4388 }
4389 #endif
4390
4391 if (!valid_target_option)
4392 error ("invalid option `%s'", name);
4393 }
4394 \f
4395 /* Print version information to FILE.
4396 Each line begins with INDENT (for the case where FILE is the
4397 assembler output file). */
4398
4399 static void
4400 print_version (file, indent)
4401 FILE *file;
4402 const char *indent;
4403 {
4404 #ifndef __VERSION__
4405 #define __VERSION__ "[?]"
4406 #endif
4407 fnotice (file,
4408 #ifdef __GNUC__
4409 "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
4410 #else
4411 "%s%s%s version %s (%s) compiled by CC.\n"
4412 #endif
4413 , indent, *indent != 0 ? " " : "",
4414 lang_hooks.name, version_string, TARGET_NAME,
4415 indent, __VERSION__);
4416 }
4417
4418 /* Print an option value and return the adjusted position in the line.
4419 ??? We don't handle error returns from fprintf (disk full); presumably
4420 other code will catch a disk full though. */
4421
4422 static int
4423 print_single_switch (file, pos, max, indent, sep, term, type, name)
4424 FILE *file;
4425 int pos, max;
4426 const char *indent, *sep, *term, *type, *name;
4427 {
4428 /* The ultrix fprintf returns 0 on success, so compute the result we want
4429 here since we need it for the following test. */
4430 int len = strlen (sep) + strlen (type) + strlen (name);
4431
4432 if (pos != 0
4433 && pos + len > max)
4434 {
4435 fprintf (file, "%s", term);
4436 pos = 0;
4437 }
4438 if (pos == 0)
4439 {
4440 fprintf (file, "%s", indent);
4441 pos = strlen (indent);
4442 }
4443 fprintf (file, "%s%s%s", sep, type, name);
4444 pos += len;
4445 return pos;
4446 }
4447
4448 /* Print active target switches to FILE.
4449 POS is the current cursor position and MAX is the size of a "line".
4450 Each line begins with INDENT and ends with TERM.
4451 Each switch is separated from the next by SEP. */
4452
4453 static void
4454 print_switch_values (file, pos, max, indent, sep, term)
4455 FILE *file;
4456 int pos, max;
4457 const char *indent, *sep, *term;
4458 {
4459 size_t j;
4460 char **p;
4461
4462 /* Print the options as passed. */
4463
4464 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
4465 _("options passed: "), "");
4466
4467 for (p = &save_argv[1]; *p != NULL; p++)
4468 if (**p == '-')
4469 {
4470 /* Ignore these. */
4471 if (strcmp (*p, "-o") == 0)
4472 {
4473 if (p[1] != NULL)
4474 p++;
4475 continue;
4476 }
4477 if (strcmp (*p, "-quiet") == 0)
4478 continue;
4479 if (strcmp (*p, "-version") == 0)
4480 continue;
4481 if ((*p)[1] == 'd')
4482 continue;
4483
4484 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
4485 }
4486 if (pos > 0)
4487 fprintf (file, "%s", term);
4488
4489 /* Print the -f and -m options that have been enabled.
4490 We don't handle language specific options but printing argv
4491 should suffice. */
4492
4493 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
4494 _("options enabled: "), "");
4495
4496 for (j = 0; j < ARRAY_SIZE (f_options); j++)
4497 if (*f_options[j].variable == f_options[j].on_value)
4498 pos = print_single_switch (file, pos, max, indent, sep, term,
4499 "-f", f_options[j].string);
4500
4501 /* Print target specific options. */
4502
4503 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
4504 if (target_switches[j].name[0] != '\0'
4505 && target_switches[j].value > 0
4506 && ((target_switches[j].value & target_flags)
4507 == target_switches[j].value))
4508 {
4509 pos = print_single_switch (file, pos, max, indent, sep, term,
4510 "-m", target_switches[j].name);
4511 }
4512
4513 #ifdef TARGET_OPTIONS
4514 for (j = 0; j < ARRAY_SIZE (target_options); j++)
4515 if (*target_options[j].variable != NULL)
4516 {
4517 char prefix[256];
4518 sprintf (prefix, "-m%s", target_options[j].prefix);
4519 pos = print_single_switch (file, pos, max, indent, sep, term,
4520 prefix, *target_options[j].variable);
4521 }
4522 #endif
4523
4524 fprintf (file, "%s", term);
4525 }
4526 \f
4527 /* Open assembly code output file. Do this even if -fsyntax-only is
4528 on, because then the driver will have provided the name of a
4529 temporary file or bit bucket for us. NAME is the file specified on
4530 the command line, possibly NULL. */
4531 static void
4532 init_asm_output (name)
4533 const char *name;
4534 {
4535 if (name == NULL && asm_file_name == 0)
4536 asm_out_file = stdout;
4537 else
4538 {
4539 if (asm_file_name == 0)
4540 {
4541 int len = strlen (dump_base_name);
4542 char *dumpname = (char *) xmalloc (len + 6);
4543 memcpy (dumpname, dump_base_name, len + 1);
4544 strip_off_ending (dumpname, len);
4545 strcat (dumpname, ".s");
4546 asm_file_name = dumpname;
4547 }
4548 if (!strcmp (asm_file_name, "-"))
4549 asm_out_file = stdout;
4550 else
4551 asm_out_file = fopen (asm_file_name, "w");
4552 if (asm_out_file == 0)
4553 fatal_io_error ("can't open %s for writing", asm_file_name);
4554 }
4555
4556 #ifdef IO_BUFFER_SIZE
4557 setvbuf (asm_out_file, (char *) xmalloc (IO_BUFFER_SIZE),
4558 _IOFBF, IO_BUFFER_SIZE);
4559 #endif
4560
4561 if (!flag_syntax_only)
4562 {
4563 #ifdef ASM_FILE_START
4564 ASM_FILE_START (asm_out_file);
4565 #endif
4566
4567 #ifdef ASM_COMMENT_START
4568 if (flag_verbose_asm)
4569 {
4570 /* Print the list of options in effect. */
4571 print_version (asm_out_file, ASM_COMMENT_START);
4572 print_switch_values (asm_out_file, 0, MAX_LINE,
4573 ASM_COMMENT_START, " ", "\n");
4574 /* Add a blank line here so it appears in assembler output but not
4575 screen output. */
4576 fprintf (asm_out_file, "\n");
4577 }
4578 #endif
4579 }
4580 }
4581 \f
4582 /* Initialization of the front end environment, before command line
4583 options are parsed. Signal handlers, internationalization etc.
4584 ARGV0 is main's argv[0]. */
4585 static void
4586 general_init (argv0)
4587 char *argv0;
4588 {
4589 char *p;
4590
4591 p = argv0 + strlen (argv0);
4592 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
4593 --p;
4594 progname = p;
4595
4596 xmalloc_set_program_name (progname);
4597
4598 gcc_init_libintl ();
4599
4600 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
4601 #ifdef SIGSEGV
4602 signal (SIGSEGV, crash_signal);
4603 #endif
4604 #ifdef SIGILL
4605 signal (SIGILL, crash_signal);
4606 #endif
4607 #ifdef SIGBUS
4608 signal (SIGBUS, crash_signal);
4609 #endif
4610 #ifdef SIGABRT
4611 signal (SIGABRT, crash_signal);
4612 #endif
4613 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
4614 signal (SIGIOT, crash_signal);
4615 #endif
4616 #ifdef SIGFPE
4617 signal (SIGFPE, crash_signal);
4618 #endif
4619
4620 /* Initialize the diagnostics reporting machinery, so option parsing
4621 can give warnings and errors. */
4622 diagnostic_initialize (global_dc);
4623 }
4624 \f
4625 /* Parse command line options and set default flag values, called
4626 after language-independent option-independent initialization. Do
4627 minimal options processing. Outputting diagnostics is OK, but GC
4628 and identifier hashtables etc. are not initialized yet. */
4629 static void
4630 parse_options_and_default_flags (argc, argv)
4631 int argc;
4632 char **argv;
4633 {
4634 int i;
4635
4636 /* Save in case md file wants to emit args as a comment. */
4637 save_argc = argc;
4638 save_argv = argv;
4639
4640 /* Initialize register usage now so switches may override. */
4641 init_reg_sets ();
4642
4643 /* Register the language-independent parameters. */
4644 add_params (lang_independent_params, LAST_PARAM);
4645
4646 /* Perform language-specific options initialization. */
4647 (*lang_hooks.init_options) ();
4648
4649 /* Scan to see what optimization level has been specified. That will
4650 determine the default value of many flags. */
4651 for (i = 1; i < argc; i++)
4652 {
4653 if (!strcmp (argv[i], "-O"))
4654 {
4655 optimize = 1;
4656 optimize_size = 0;
4657 }
4658 else if (argv[i][0] == '-' && argv[i][1] == 'O')
4659 {
4660 /* Handle -Os, -O2, -O3, -O69, ... */
4661 char *p = &argv[i][2];
4662
4663 if ((p[0] == 's') && (p[1] == 0))
4664 {
4665 optimize_size = 1;
4666
4667 /* Optimizing for size forces optimize to be 2. */
4668 optimize = 2;
4669 }
4670 else
4671 {
4672 const int optimize_val = read_integral_parameter (p, p - 2, -1);
4673 if (optimize_val != -1)
4674 {
4675 optimize = optimize_val;
4676 optimize_size = 0;
4677 }
4678 }
4679 }
4680 }
4681
4682 if (!optimize)
4683 {
4684 flag_merge_constants = 0;
4685 }
4686
4687 if (optimize >= 1)
4688 {
4689 flag_defer_pop = 1;
4690 flag_thread_jumps = 1;
4691 #ifdef DELAY_SLOTS
4692 flag_delayed_branch = 1;
4693 #endif
4694 #ifdef CAN_DEBUG_WITHOUT_FP
4695 flag_omit_frame_pointer = 1;
4696 #endif
4697 flag_guess_branch_prob = 1;
4698 flag_cprop_registers = 1;
4699 flag_loop_optimize = 1;
4700 flag_crossjumping = 1;
4701 flag_if_conversion = 1;
4702 flag_if_conversion2 = 1;
4703 }
4704
4705 if (optimize >= 2)
4706 {
4707 flag_optimize_sibling_calls = 1;
4708 flag_cse_follow_jumps = 1;
4709 flag_cse_skip_blocks = 1;
4710 flag_gcse = 1;
4711 flag_expensive_optimizations = 1;
4712 flag_strength_reduce = 1;
4713 flag_rerun_cse_after_loop = 1;
4714 flag_rerun_loop_opt = 1;
4715 flag_caller_saves = 1;
4716 flag_force_mem = 1;
4717 flag_peephole2 = 1;
4718 #ifdef INSN_SCHEDULING
4719 flag_schedule_insns = 1;
4720 flag_schedule_insns_after_reload = 1;
4721 #endif
4722 flag_regmove = 1;
4723 flag_strict_aliasing = 1;
4724 flag_delete_null_pointer_checks = 1;
4725 flag_reorder_blocks = 1;
4726 flag_reorder_functions = 1;
4727 }
4728
4729 if (optimize >= 3)
4730 {
4731 flag_inline_functions = 1;
4732 flag_rename_registers = 1;
4733 }
4734
4735 if (optimize < 2 || optimize_size)
4736 {
4737 align_loops = 1;
4738 align_jumps = 1;
4739 align_labels = 1;
4740 align_functions = 1;
4741 }
4742
4743 /* Initialize whether `char' is signed. */
4744 flag_signed_char = DEFAULT_SIGNED_CHAR;
4745 #ifdef DEFAULT_SHORT_ENUMS
4746 /* Initialize how much space enums occupy, by default. */
4747 flag_short_enums = DEFAULT_SHORT_ENUMS;
4748 #endif
4749
4750 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
4751 modify it. */
4752 target_flags = 0;
4753 set_target_switch ("");
4754
4755 /* Unwind tables are always present in an ABI-conformant IA-64
4756 object file, so the default should be ON. */
4757 #ifdef IA64_UNWIND_INFO
4758 flag_unwind_tables = IA64_UNWIND_INFO;
4759 #endif
4760
4761 #ifdef OPTIMIZATION_OPTIONS
4762 /* Allow default optimizations to be specified on a per-machine basis. */
4763 OPTIMIZATION_OPTIONS (optimize, optimize_size);
4764 #endif
4765
4766 /* Perform normal command line switch decoding. */
4767 for (i = 1; i < argc;)
4768 {
4769 int lang_processed;
4770 int indep_processed;
4771
4772 /* Give the language a chance to decode the option for itself. */
4773 lang_processed = (*lang_hooks.decode_option) (argc - i, argv + i);
4774
4775 if (lang_processed >= 0)
4776 /* Now see if the option also has a language independent meaning.
4777 Some options are both language specific and language independent,
4778 eg --help. */
4779 indep_processed = independent_decode_option (argc - i, argv + i);
4780 else
4781 {
4782 lang_processed = -lang_processed;
4783 indep_processed = 0;
4784 }
4785
4786 if (lang_processed || indep_processed)
4787 i += MAX (lang_processed, indep_processed);
4788 else
4789 {
4790 const char *option = NULL;
4791 const char *lang = NULL;
4792 unsigned int j;
4793
4794 /* It is possible that the command line switch is not valid for the
4795 current language, but it is valid for another language. In order
4796 to be compatible with previous versions of the compiler (which
4797 did not issue an error message in this case) we check for this
4798 possibility here. If we do find a match, then if extra_warnings
4799 is set we generate a warning message, otherwise we will just
4800 ignore the option. */
4801 for (j = 0; j < ARRAY_SIZE (documented_lang_options); j++)
4802 {
4803 option = documented_lang_options[j].option;
4804
4805 if (option == NULL)
4806 lang = documented_lang_options[j].description;
4807 else if (! strncmp (argv[i], option, strlen (option)))
4808 break;
4809 }
4810
4811 if (j != ARRAY_SIZE (documented_lang_options))
4812 {
4813 if (extra_warnings)
4814 {
4815 warning ("ignoring command line option '%s'", argv[i]);
4816 if (lang)
4817 warning
4818 ("(it is valid for %s but not the selected language)",
4819 lang);
4820 }
4821 }
4822 else if (argv[i][0] == '-' && argv[i][1] == 'g')
4823 warning ("`%s': unknown or unsupported -g option", &argv[i][2]);
4824 else
4825 error ("unrecognized option `%s'", argv[i]);
4826
4827 i++;
4828 }
4829 }
4830
4831 if (flag_no_inline == 2)
4832 flag_no_inline = 0;
4833 else
4834 flag_really_no_inline = flag_no_inline;
4835
4836 /* Set flag_no_inline before the post_options () hook. The C front
4837 ends use it to determine tree inlining defaults. FIXME: such
4838 code should be lang-independent when all front ends use tree
4839 inlining, in which case it, and this condition, should be moved
4840 to the top of process_options() instead. */
4841 if (optimize == 0)
4842 {
4843 /* Inlining does not work if not optimizing,
4844 so force it not to be done. */
4845 flag_no_inline = 1;
4846 warn_inline = 0;
4847
4848 /* The c_decode_option function and decode_option hook set
4849 this to `2' if -Wall is used, so we can avoid giving out
4850 lots of errors for people who don't realize what -Wall does. */
4851 if (warn_uninitialized == 1)
4852 warning ("-Wuninitialized is not supported without -O");
4853 }
4854
4855 if (flag_really_no_inline == 2)
4856 flag_really_no_inline = flag_no_inline;
4857
4858 /* All command line options have been parsed; allow the front end to
4859 perform consistency checks, etc. */
4860 (*lang_hooks.post_options) ();
4861 }
4862 \f
4863 /* Process the options that have been parsed. */
4864 static void
4865 process_options ()
4866 {
4867 #ifdef OVERRIDE_OPTIONS
4868 /* Some machines may reject certain combinations of options. */
4869 OVERRIDE_OPTIONS;
4870 #endif
4871
4872 /* Set up the align_*_log variables, defaulting them to 1 if they
4873 were still unset. */
4874 if (align_loops <= 0) align_loops = 1;
4875 if (align_loops_max_skip > align_loops || !align_loops)
4876 align_loops_max_skip = align_loops - 1;
4877 align_loops_log = floor_log2 (align_loops * 2 - 1);
4878 if (align_jumps <= 0) align_jumps = 1;
4879 if (align_jumps_max_skip > align_jumps || !align_jumps)
4880 align_jumps_max_skip = align_jumps - 1;
4881 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
4882 if (align_labels <= 0) align_labels = 1;
4883 align_labels_log = floor_log2 (align_labels * 2 - 1);
4884 if (align_labels_max_skip > align_labels || !align_labels)
4885 align_labels_max_skip = align_labels - 1;
4886 if (align_functions <= 0) align_functions = 1;
4887 align_functions_log = floor_log2 (align_functions * 2 - 1);
4888
4889 /* Unrolling all loops implies that standard loop unrolling must also
4890 be done. */
4891 if (flag_unroll_all_loops)
4892 flag_unroll_loops = 1;
4893 /* Loop unrolling requires that strength_reduction be on also. Silently
4894 turn on strength reduction here if it isn't already on. Also, the loop
4895 unrolling code assumes that cse will be run after loop, so that must
4896 be turned on also. */
4897 if (flag_unroll_loops)
4898 {
4899 flag_strength_reduce = 1;
4900 flag_rerun_cse_after_loop = 1;
4901 }
4902
4903 if (flag_non_call_exceptions)
4904 flag_asynchronous_unwind_tables = 1;
4905 if (flag_asynchronous_unwind_tables)
4906 flag_unwind_tables = 1;
4907
4908 /* Warn about options that are not supported on this machine. */
4909 #ifndef INSN_SCHEDULING
4910 if (flag_schedule_insns || flag_schedule_insns_after_reload)
4911 warning ("instruction scheduling not supported on this target machine");
4912 #endif
4913 #ifndef DELAY_SLOTS
4914 if (flag_delayed_branch)
4915 warning ("this target machine does not have delayed branches");
4916 #endif
4917
4918 user_label_prefix = USER_LABEL_PREFIX;
4919 if (flag_leading_underscore != -1)
4920 {
4921 /* If the default prefix is more complicated than "" or "_",
4922 issue a warning and ignore this option. */
4923 if (user_label_prefix[0] == 0 ||
4924 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
4925 {
4926 user_label_prefix = flag_leading_underscore ? "_" : "";
4927 }
4928 else
4929 warning ("-f%sleading-underscore not supported on this target machine",
4930 flag_leading_underscore ? "" : "no-");
4931 }
4932
4933 /* If we are in verbose mode, write out the version and maybe all the
4934 option flags in use. */
4935 if (version_flag)
4936 {
4937 print_version (stderr, "");
4938 if (! quiet_flag)
4939 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
4940 }
4941
4942 if (! quiet_flag)
4943 time_report = 1;
4944
4945 if (flag_syntax_only)
4946 {
4947 write_symbols = NO_DEBUG;
4948 profile_flag = 0;
4949 }
4950
4951 /* Now we know write_symbols, set up the debug hooks based on it.
4952 By default we do nothing for debug output. */
4953 #if defined(DBX_DEBUGGING_INFO)
4954 if (write_symbols == DBX_DEBUG)
4955 debug_hooks = &dbx_debug_hooks;
4956 #endif
4957 #if defined(XCOFF_DEBUGGING_INFO)
4958 if (write_symbols == XCOFF_DEBUG)
4959 debug_hooks = &xcoff_debug_hooks;
4960 #endif
4961 #ifdef SDB_DEBUGGING_INFO
4962 if (write_symbols == SDB_DEBUG)
4963 debug_hooks = &sdb_debug_hooks;
4964 #endif
4965 #ifdef DWARF_DEBUGGING_INFO
4966 if (write_symbols == DWARF_DEBUG)
4967 debug_hooks = &dwarf_debug_hooks;
4968 #endif
4969 #ifdef DWARF2_DEBUGGING_INFO
4970 if (write_symbols == DWARF2_DEBUG)
4971 debug_hooks = &dwarf2_debug_hooks;
4972 #endif
4973 #ifdef VMS_DEBUGGING_INFO
4974 if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
4975 debug_hooks = &vmsdbg_debug_hooks;
4976 #endif
4977
4978 /* If auxiliary info generation is desired, open the output file.
4979 This goes in the same directory as the source file--unlike
4980 all the other output files. */
4981 if (flag_gen_aux_info)
4982 {
4983 aux_info_file = fopen (aux_info_file_name, "w");
4984 if (aux_info_file == 0)
4985 fatal_io_error ("can't open %s", aux_info_file_name);
4986 }
4987
4988 if (! targetm.have_named_sections)
4989 {
4990 if (flag_function_sections)
4991 {
4992 warning ("-ffunction-sections not supported for this target");
4993 flag_function_sections = 0;
4994 }
4995 if (flag_data_sections)
4996 {
4997 warning ("-fdata-sections not supported for this target");
4998 flag_data_sections = 0;
4999 }
5000 }
5001
5002 if (flag_function_sections && profile_flag)
5003 {
5004 warning ("-ffunction-sections disabled; it makes profiling impossible");
5005 flag_function_sections = 0;
5006 }
5007
5008 #ifndef HAVE_prefetch
5009 if (flag_prefetch_loop_arrays)
5010 {
5011 warning ("-fprefetch-loop-arrays not supported for this target");
5012 flag_prefetch_loop_arrays = 0;
5013 }
5014 #else
5015 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
5016 {
5017 warning ("-fprefetch-loop-arrays not supported for this target (try -march switches)");
5018 flag_prefetch_loop_arrays = 0;
5019 }
5020 #endif
5021
5022 /* This combination of options isn't handled for i386 targets and doesn't
5023 make much sense anyway, so don't allow it. */
5024 if (flag_prefetch_loop_arrays && optimize_size)
5025 {
5026 warning ("-fprefetch-loop-arrays is not supported with -Os");
5027 flag_prefetch_loop_arrays = 0;
5028 }
5029
5030 #ifndef OBJECT_FORMAT_ELF
5031 if (flag_function_sections && write_symbols != NO_DEBUG)
5032 warning ("-ffunction-sections may affect debugging on some targets");
5033 #endif
5034 }
5035 \f
5036 /* Language-independent initialization, before language-dependent
5037 initialization. */
5038 static void
5039 lang_independent_init ()
5040 {
5041 /* Initialize the garbage-collector, and string pools. */
5042 init_ggc ();
5043 ggc_add_rtx_root (&stack_limit_rtx, 1);
5044 ggc_add_tree_root (&current_function_decl, 1);
5045 ggc_add_tree_root (&current_function_func_begin_label, 1);
5046
5047 init_stringpool ();
5048 init_obstacks ();
5049
5050 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
5051 || debug_info_level == DINFO_LEVEL_VERBOSE
5052 #ifdef VMS_DEBUGGING_INFO
5053 /* Enable line number info for traceback */
5054 || debug_info_level > DINFO_LEVEL_NONE
5055 #endif
5056 || flag_test_coverage
5057 || warn_notreached);
5058 init_regs ();
5059 init_alias_once ();
5060 init_stmt ();
5061 init_loop ();
5062 init_reload ();
5063 init_function_once ();
5064 init_stor_layout_once ();
5065 init_varasm_once ();
5066 init_EXPR_INSN_LIST_cache ();
5067
5068 /* The following initialization functions need to generate rtl, so
5069 provide a dummy function context for them. */
5070 init_dummy_function_start ();
5071 init_expmed ();
5072 if (flag_caller_saves)
5073 init_caller_save ();
5074 expand_dummy_function_end ();
5075 }
5076 \f
5077 /* Language-dependent initialization. Returns non-zero on success. */
5078 static int
5079 lang_dependent_init (name)
5080 const char *name;
5081 {
5082 if (dump_base_name == 0)
5083 dump_base_name = name ? name : "gccdump";
5084
5085 /* Front-end initialization. This hook can assume that GC,
5086 identifier hashes etc. are set up, but debug initialization is
5087 not done yet. This routine must return the original filename
5088 (e.g. foo.i -> foo.c) so can correctly initialize debug output. */
5089 name = (*lang_hooks.init) (name);
5090 if (name == NULL)
5091 return 0;
5092
5093 /* Is this duplication necessary? */
5094 name = ggc_strdup (name);
5095 main_input_filename = input_filename = name;
5096 init_asm_output (name);
5097
5098 /* These create various _DECL nodes, so need to be called after the
5099 front end is initialized. */
5100 init_eh ();
5101 init_optabs ();
5102 init_expr_once ();
5103
5104 /* Put an entry on the input file stack for the main input file. */
5105 push_srcloc (input_filename, 0);
5106
5107 /* If dbx symbol table desired, initialize writing it and output the
5108 predefined types. */
5109 timevar_push (TV_SYMOUT);
5110
5111 #ifdef DWARF2_UNWIND_INFO
5112 if (dwarf2out_do_frame ())
5113 dwarf2out_frame_init ();
5114 #endif
5115
5116 /* Now we have the correct original filename, we can initialize
5117 debug output. */
5118 (*debug_hooks->init) (name);
5119
5120 timevar_pop (TV_SYMOUT);
5121
5122 return 1;
5123 }
5124 \f
5125 /* Clean up: close opened files, etc. */
5126
5127 static void
5128 finalize ()
5129 {
5130 /* Close the dump files. */
5131 if (flag_gen_aux_info)
5132 {
5133 fclose (aux_info_file);
5134 if (errorcount)
5135 unlink (aux_info_file_name);
5136 }
5137
5138 /* Close non-debugging input and output files. Take special care to note
5139 whether fclose returns an error, since the pages might still be on the
5140 buffer chain while the file is open. */
5141
5142 if (asm_out_file)
5143 {
5144 if (ferror (asm_out_file) != 0)
5145 fatal_io_error ("error writing to %s", asm_file_name);
5146 if (fclose (asm_out_file) != 0)
5147 fatal_io_error ("error closing %s", asm_file_name);
5148 }
5149
5150 /* Do whatever is necessary to finish printing the graphs. */
5151 if (graph_dump_format != no_graph)
5152 {
5153 int i;
5154
5155 for (i = 0; i < (int) DFI_MAX; ++i)
5156 if (dump_file[i].initialized && dump_file[i].graph_dump_p)
5157 {
5158 char seq[16];
5159 char *suffix;
5160
5161 sprintf (seq, DUMPFILE_FORMAT, i);
5162 suffix = concat (seq, dump_file[i].extension, NULL);
5163 finish_graph_dump_file (dump_base_name, suffix);
5164 free (suffix);
5165 }
5166 }
5167
5168 if (mem_report)
5169 {
5170 ggc_print_statistics ();
5171 stringpool_statistics ();
5172 dump_tree_statistics ();
5173 }
5174
5175 /* Free up memory for the benefit of leak detectors. */
5176 free_reg_info ();
5177
5178 /* Language-specific end of compilation actions. */
5179 (*lang_hooks.finish) ();
5180 }
5181 \f
5182 /* Initialize the compiler, and compile the input file. */
5183 static void
5184 do_compile ()
5185 {
5186 /* The bulk of command line switch processing. */
5187 process_options ();
5188
5189 /* We cannot start timing until after options are processed since that
5190 says if we run timers or not. */
5191 init_timevar ();
5192 timevar_start (TV_TOTAL);
5193
5194 /* Language-independent initialization. Also sets up GC, identifier
5195 hashes etc. */
5196 lang_independent_init ();
5197
5198 /* Language-dependent initialization. Returns true on success. */
5199 if (lang_dependent_init (filename))
5200 compile_file ();
5201
5202 finalize ();
5203
5204 /* Stop timing and print the times. */
5205 timevar_stop (TV_TOTAL);
5206 timevar_print (stderr);
5207 }
5208 \f
5209 /* Entry point of cc1, cc1plus, jc1, f771, etc.
5210 Decode command args, then call compile_file.
5211 Exit code is FATAL_EXIT_CODE if can't open files or if there were
5212 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
5213
5214 It is not safe to call this function more than once. */
5215
5216 int
5217 toplev_main (argc, argv)
5218 int argc;
5219 char **argv;
5220 {
5221 hex_init ();
5222
5223 /* Initialization of GCC's environment, and diagnostics. */
5224 general_init (argv[0]);
5225
5226 /* Parse the options and do minimal processing; basically just
5227 enough to default flags appropriately. */
5228 parse_options_and_default_flags (argc, argv);
5229
5230 /* Exit early if we can (e.g. -help). */
5231 if (!errorcount && !exit_after_options)
5232 do_compile ();
5233
5234 if (errorcount || sorrycount)
5235 return (FATAL_EXIT_CODE);
5236
5237 return (SUCCESS_EXIT_CODE);
5238 }