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