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