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