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