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