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