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