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